aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_resampler.cpp
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2016-01-13 17:16:50 +0100
committerPaul Adenot <[email protected]>2016-01-13 17:36:53 +0100
commit46e32bdac90233b0a4e59d9b7d4319a28bf496ae (patch)
tree0e7d58fc9709e8a0d2e59d1a00ea7158e29e9a0c /src/cubeb_resampler.cpp
parent23a17cb4f9ed2de78a0df5ecdfefbbe47dc83c35 (diff)
downloadcubeb-46e32bdac90233b0a4e59d9b7d4319a28bf496ae.tar.gz
cubeb-46e32bdac90233b0a4e59d9b7d4319a28bf496ae.zip
Preparatory work for the input and duplex code
This is changing all the signatures of the `cubeb_stream_init` implementations, the signature of the `data_callback` type, so that cubeb can support audio input. `cubeb_stream_init` now has two `cubeb_stream_params` pointers, one for input, one for output. If two pointers are passed, a "duplex" stream is opened. If only one pointer is passed, an input-only or output-only stream is created. Duplex streams have the same sample rate, and sample type. They don't have to have the same number of channels. `data_callback` now has two pointers to audio buffers: an input buffer (`NULL` if this is an output-only stream) containing input data (e.g. a microphone), and an output buffer, to be filled, as usual, with the audio frames to play. The two buffers always have the exact same number of audio frames, and are temporally correlated in a way that ensures the minimal loop-back latency on the system if one directly copies the input buffer to the output buffer. No functionnal changes are present in this patch, just signature changes. Asserts have been added to prevent users to try to use the input code path for now. Actual implementations with the input code for different platforms will follow. Green `mozilla-central` push: <https://treeherder.mozilla.org/#/jobs?repo=try&revision=15b4dd3cbbe8>
Diffstat (limited to 'src/cubeb_resampler.cpp')
-rw-r--r--src/cubeb_resampler.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/cubeb_resampler.cpp b/src/cubeb_resampler.cpp
index 682650a..e8fd7a1 100644
--- a/src/cubeb_resampler.cpp
+++ b/src/cubeb_resampler.cpp
@@ -72,7 +72,7 @@ to_speex_quality(cubeb_resampler_quality q)
} // end of anonymous namespace
struct cubeb_resampler {
- virtual long fill(void * buffer, long frames_needed) = 0;
+ virtual long fill(void * input_buffer, void * output_buffer, long frames_needed) = 0;
virtual ~cubeb_resampler() {}
};
@@ -87,9 +87,9 @@ public:
{
}
- virtual long fill(void * buffer, long frames_needed)
+ virtual long fill(void * input_buffer, void * output_buffer, long frames_needed)
{
- long got = data_callback(stream, user_ptr, buffer, frames_needed);
+ long got = data_callback(stream, user_ptr, input_buffer, output_buffer, frames_needed);
assert(got <= frames_needed);
return got;
}
@@ -109,7 +109,7 @@ public:
virtual ~cubeb_resampler_speex();
- virtual long fill(void * buffer, long frames_needed);
+ virtual long fill(void * input_buffer, void * output_buffer, long frames_needed);
private:
SpeexResamplerState * const speex_resampler;
@@ -164,7 +164,7 @@ cubeb_resampler_speex::~cubeb_resampler_speex()
}
long
-cubeb_resampler_speex::fill(void * buffer, long frames_needed)
+cubeb_resampler_speex::fill(void * input_buffer, void * output_buffer, long frames_needed)
{
// Use more input frames than strictly necessary, so in the worst case,
// we have leftover unresampled frames at the end, that we can use
@@ -178,7 +178,7 @@ cubeb_resampler_speex::fill(void * buffer, long frames_needed)
memcpy(resampling_src_buffer.get(), leftover_frames_buffer.get(), leftover_bytes);
uint8_t * buffer_start = resampling_src_buffer.get() + leftover_bytes;
- long got = data_callback(stream, user_ptr, buffer_start, frames_requested);
+ long got = data_callback(stream, user_ptr, NULL, buffer_start, frames_requested);
assert(got <= frames_requested);
if (got < 0) {
@@ -191,12 +191,12 @@ cubeb_resampler_speex::fill(void * buffer, long frames_needed)
if (stream_params.format == CUBEB_SAMPLE_FLOAT32NE) {
float * in_buffer = reinterpret_cast<float *>(resampling_src_buffer.get());
- float * out_buffer = reinterpret_cast<float *>(buffer);
+ float * out_buffer = reinterpret_cast<float *>(output_buffer);
speex_resampler_process_interleaved_float(speex_resampler, in_buffer, &in_frames,
out_buffer, &out_frames);
} else {
short * in_buffer = reinterpret_cast<short *>(resampling_src_buffer.get());
- short * out_buffer = reinterpret_cast<short *>(buffer);
+ short * out_buffer = reinterpret_cast<short *>(output_buffer);
speex_resampler_process_interleaved_int(speex_resampler, in_buffer, &in_frames,
out_buffer, &out_frames);
}
@@ -242,9 +242,11 @@ cubeb_resampler_create(cubeb_stream * stream,
long
cubeb_resampler_fill(cubeb_resampler * resampler,
- void * buffer, long frames_needed)
+ void * input_buffer,
+ void * output_buffer,
+ long frames_needed)
{
- return resampler->fill(buffer, frames_needed);
+ return resampler->fill(input_buffer, output_buffer, frames_needed);
}
void