2017-07-03 07:05:08 -05:00
|
|
|
package audio
|
|
|
|
|
|
|
|
// SampleRate is the number of audio samples a Streamer should produce per one second of audio.
|
|
|
|
//
|
2017-07-03 10:28:54 -05:00
|
|
|
// This value should be set at most once before using audio package. It is safe to assume that this
|
|
|
|
// value does not change during runtime.
|
2017-07-03 11:55:27 -05:00
|
|
|
var SampleRate float64 = 48000
|
2017-07-03 07:05:08 -05:00
|
|
|
|
|
|
|
// Streamer is able to stream a finite or infinite sequence of audio samples.
|
|
|
|
type Streamer interface {
|
|
|
|
// Stream copies at most len(samples) next audio samples to the samples slice.
|
|
|
|
//
|
|
|
|
// The sample rate of the samples is specified by the global SampleRate variable/constant.
|
|
|
|
// The value at samples[i][0] is the value of the left channel of the i-th sample.
|
|
|
|
// Similarly, samples[i][1] is the value of the right channel of the i-th sample.
|
|
|
|
//
|
|
|
|
// Stream returns the number of streamed samples. If the Streamer is drained and no more
|
|
|
|
// samples will be produced, it returns 0 and false. Stream must not touch any samples
|
|
|
|
// outside samples[:n].
|
|
|
|
//
|
|
|
|
// There are 3 valid return pattterns of the Stream method:
|
|
|
|
//
|
|
|
|
// 1. n == len(samples) && ok
|
|
|
|
//
|
|
|
|
// Stream streamed all of the requested samples. Cases 1, 2 and 3 may occur in the following
|
|
|
|
// calls.
|
|
|
|
//
|
|
|
|
// 2. 0 < n && n < len(samples) && ok
|
|
|
|
//
|
|
|
|
// Stream streamed n samples and drained the Streamer. Only case 3 may occur in the
|
|
|
|
// following calls.
|
|
|
|
//
|
|
|
|
// 3. n == 0 && !ok
|
|
|
|
//
|
2017-07-03 10:37:55 -05:00
|
|
|
// The Streamer is drained and no more samples will come. Only this case may occur in the
|
2017-07-03 07:05:08 -05:00
|
|
|
// following calls.
|
|
|
|
Stream(samples [][2]float64) (n int, ok bool)
|
|
|
|
}
|