mozilla / cubeb-coreaudio-rs

The audio backend of Firefox on Mac OS X.
ISC License
25 stars 10 forks source link

Correct input buffer for the resampler #92

Closed ChunMinChang closed 4 years ago

ChunMinChang commented 4 years ago

The change here fixes #91 and complete what we want to do in #86.

The assert(destination && source) in [1] will be hit in the following scenario:

  1. audiounit_output_callback comes before audiounit_input_callback
  2. audiounit_input_callback is never called before 1
  3. input_buffer_manager.available_samples() is 0 since no buffered input data
  4. the input_frame_count of the first ffi::cubeb_resampler_fill would be 0

The silent frames needs to be fed as the input buffer to the resampler.

[1] https://github.com/kinetiknz/cubeb/blob/35190a8da650be297edb91d2db778bed622d8691/src/cubeb_utils.h#L31

padenot commented 4 years ago

Won't this reintroduce the problems of https://github.com/ChunMinChang/cubeb-coreaudio-rs/pull/79 ?

ChunMinChang commented 4 years ago

Won't this reintroduce the problems of #79 ?

I am unable to reproduce the glitch that #79 tried to fix. It's better to create a regression test to prevent that glitch otherwise that problem might popup again.

However, from the code we used to have in #79, the silent frames would be appended to the buffer_manager in the following case: https://github.com/ChunMinChang/cubeb-coreaudio-rs/blob/27cf89ef920d1968c06e45f2a7903725d6b635cd/src/backend/mod.rs#L609-L615 and then the corrected buffer (with newly added silent frames) would be fed to the resampler: https://github.com/ChunMinChang/cubeb-coreaudio-rs/blob/27cf89ef920d1968c06e45f2a7903725d6b635cd/src/backend/mod.rs#L631-L635

This is same as what the current change does here. The difference is that this patch would append the silent frames by get_linear_data implicitly instead of calling push_silent_data and then using get_linear_data (push_silent_data is removed). Thus, if the fix in #79 doesn't cause the glitch, the change here won't cause the glitch as well (however I am not able to test the glitch).

ChunMinChang commented 4 years ago

https://github.com/ChunMinChang/cubeb-coreaudio-rs/issues/91#issuecomment-625489253: Another approach is allowing push 0 frames to the resampler once it's initialized.