aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_resampler.cpp
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2017-02-06 16:11:37 +0100
committerGitHub <[email protected]>2017-02-06 16:11:37 +0100
commit81fc5c70aa554f86e9988308fcb17bbcef84fce3 (patch)
treec7efe169118cb50930e89724dcd74ad4781e9188 /src/cubeb_resampler.cpp
parent47ae853e6f967f30ac925e4e8153e2aac09847ce (diff)
downloadcubeb-81fc5c70aa554f86e9988308fcb17bbcef84fce3.tar.gz
cubeb-81fc5c70aa554f86e9988308fcb17bbcef84fce3.zip
Allow buffering some input when using a noop resampler, and rename it because it's not strictly no-op anymore (#223)
* Allow buffering some input when using a noop resampler, and rename it because it's not strictly no-op anymore. * Fix build on windows * fix build harder, and check that the buffers are correct * Address achronop's comments. * Silence a scan-build error. This is caused by the fact that gtest assertions are not fatal, so scan-build things the pointer is checked against null, and that we dereference it later.
Diffstat (limited to 'src/cubeb_resampler.cpp')
-rw-r--r--src/cubeb_resampler.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/cubeb_resampler.cpp b/src/cubeb_resampler.cpp
index 91fa35f..12de294 100644
--- a/src/cubeb_resampler.cpp
+++ b/src/cubeb_resampler.cpp
@@ -35,29 +35,46 @@ to_speex_quality(cubeb_resampler_quality q)
}
}
-long noop_resampler::fill(void * input_buffer, long * input_frames_count,
- void * output_buffer, long output_frames)
+template<typename T>
+passthrough_resampler<T>::passthrough_resampler(cubeb_stream * s,
+ cubeb_data_callback cb,
+ void * ptr,
+ uint32_t input_channels)
+ : processor(input_channels)
+ , stream(s)
+ , data_callback(cb)
+ , user_ptr(ptr)
+{
+}
+
+template<typename T>
+long passthrough_resampler<T>::fill(void * input_buffer, long * input_frames_count,
+ void * output_buffer, long output_frames)
{
if (input_buffer) {
assert(input_frames_count);
}
assert((input_buffer && output_buffer &&
- *input_frames_count >= output_frames) ||
- (!input_buffer && (!input_frames_count || *input_frames_count == 0)) ||
- (!output_buffer && output_frames == 0));
+ *input_frames_count + static_cast<int>(samples_to_frames(internal_input_buffer.length())) >= output_frames) ||
+ (output_buffer && !input_buffer && (!input_frames_count || *input_frames_count == 0)) ||
+ (input_buffer && !output_buffer && output_frames == 0));
- if (output_buffer == nullptr) {
- assert(input_buffer);
- output_frames = *input_frames_count;
+ if (input_buffer) {
+ if (!output_buffer) {
+ output_frames = *input_frames_count;
+ }
+ internal_input_buffer.push(static_cast<T*>(input_buffer),
+ frames_to_samples(*input_frames_count));
}
- if (input_buffer && *input_frames_count != output_frames) {
- assert(*input_frames_count > output_frames);
- *input_frames_count = output_frames;
+ long rv = data_callback(stream, user_ptr, internal_input_buffer.data(),
+ output_buffer, output_frames);
+
+ if (input_buffer) {
+ internal_input_buffer.pop(nullptr, frames_to_samples(output_frames));
}
- return data_callback(stream, user_ptr,
- input_buffer, output_buffer, output_frames);
+ return rv;
}
template<typename T, typename InputProcessor, typename OutputProcessor>