From a84c3a0146989e08a29c78646b4cdd142ba3ebb7 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Mon, 4 Nov 2019 20:23:03 +0100 Subject: [PATCH] Add AudioSource interface --- rhubarb/src/main/kotlin/audio/AudioSource.kt | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 rhubarb/src/main/kotlin/audio/AudioSource.kt diff --git a/rhubarb/src/main/kotlin/audio/AudioSource.kt b/rhubarb/src/main/kotlin/audio/AudioSource.kt new file mode 100644 index 0000000..d0f9b49 --- /dev/null +++ b/rhubarb/src/main/kotlin/audio/AudioSource.kt @@ -0,0 +1,25 @@ +package com.rhubarb_lip_sync.audio + +typealias SampleArray = FloatArray + +/** A sampled monaural audio signal with a fixed duration */ +interface AudioSource { + /** The sample rate in Hz */ + val sampleRate: Int + + /** The number of samples */ + val size: Int + + /** + * Returns a new sample array containing the specified audio segment. + * + * @param start The index of the first sample to be included + * @param end The index of the first sample *not* to be included + * + * @throws IllegalArgumentException if [start] < 0 or [start] > [end] or [end] > [size] + */ + suspend fun getSamples(start: Int, end: Int): SampleArray +} + +/** An audio source that requires closing to free resources */ +interface AutoCloseableAudioSource : AudioSource, AutoCloseable