Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixing 8bit WAVs produces DC bias, clipping and clicks #648

Open
positron96 opened this issue Sep 1, 2023 · 0 comments
Open

Mixing 8bit WAVs produces DC bias, clipping and clicks #648

positron96 opened this issue Sep 1, 2023 · 0 comments

Comments

@positron96
Copy link

positron96 commented Sep 1, 2023

Hello and thanks for a wonderful library.

Here is a bug report.
8bit WAVs have unsigned samples. The library seems aware of this, but shifting the sample to signed 16bit happens in AudioOutput classes by calling MakeSampleStereo16 function. However, this happens too late in the pipeline in case the file is first mixed with another file, or its gain is changed by AudioMixer class. In this case the sequence of events is the following:

  1. Sample is loaded and stored as u8 in i16 buffer in AudioGeneratorWAV, its 0 amplitude is value 128.
  2. Sample is passed to AudioMixer class where it is scaled by applying gain (0 amplitude is not 128 anymore) or added to other channels (DC bias is added to bias of other channels).
  3. Resulting sample is passed to final output class (e.g. AudioOutputI2S) where it is unbiased by MakeSampleStereo16, but it is only subtracting 128 from value, so the DC bias is modified but still remains.

I propose the change to convert the sample to signed when loading it in GeneratorWAV class, and use it as such from then on. MakeSampleStereo16 function should not do the shifting, but only scaling.

PS Not sure, but this might be the cause of some reports of people having clicks and pops in sound output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant