diff options
author | Jean-Yves Avenard <[email protected]> | 2018-09-12 16:44:09 +0200 |
---|---|---|
committer | Jean-Yves Avenard <[email protected]> | 2018-09-12 16:44:09 +0200 |
commit | c3b504510f278fd4a579fe044ccf9fbdabcb4c78 (patch) | |
tree | a24bb6c8548007125195c4ae6ad80c3a177f073e /src/cubeb_audiounit.cpp | |
parent | ad0d1c1c73722457e0f7f1bd5be4860ec6d691ec (diff) | |
download | cubeb-c3b504510f278fd4a579fe044ccf9fbdabcb4c78.tar.gz cubeb-c3b504510f278fd4a579fe044ccf9fbdabcb4c78.zip |
Properly adjust the number of frames left to be processed by the resampler.
After calling the resampler, we would reduce the number of frames in the input buffer correctly by the number of frames used, but would always fully clear the input buffer after.
Resulting with a input_buffer and its frame counters to be potentially out of sync
Diffstat (limited to 'src/cubeb_audiounit.cpp')
-rw-r--r-- | src/cubeb_audiounit.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cubeb_audiounit.cpp b/src/cubeb_audiounit.cpp index 007e411..e020e5c 100644 --- a/src/cubeb_audiounit.cpp +++ b/src/cubeb_audiounit.cpp @@ -621,6 +621,7 @@ audiounit_output_callback(void * user_ptr, input_frames = stm->input_linear_buffer->length() / stm->input_desc.mChannelsPerFrame; // Number of input frames pushed inside resampler. input_frames_before_fill = input_frames; + assert(input_frames == stm->available_input_frames); } /* Call user callback through resampler. */ @@ -634,10 +635,11 @@ audiounit_output_callback(void * user_ptr, output_frames); if (input_buffer) { + // Pop from the buffer the frames used by the the resampler. + stm->input_linear_buffer->pop(input_frames * stm->input_desc.mChannelsPerFrame); // Decrease counter by the number of frames used by resampler + assert(stm->available_input_frames >= input_frames); stm->available_input_frames -= input_frames; - // Pop from the buffer the frames pushed to the resampler. - stm->input_linear_buffer->pop(input_frames_before_fill * stm->input_desc.mChannelsPerFrame); } if (outframes < 0 || outframes > output_frames) { |