ESP8266Audio icon indicating copy to clipboard operation
ESP8266Audio copied to clipboard

Don't SetRate() if hz already matches, fixes noisy click

Open ChuckMash opened this issue 2 years ago • 4 comments

Addresses #655 and likely others.

I tracked down a nasty click sound when using mixer to mix 2 stubs with MP3s , one is an long ongoing background track and the other is various sound clips played at various times.

The issue is that there is a audible click each time the second stub with the sound clip is used.

The issue seems to be related ultimately with calling i2s_set_sample_rates((i2s_port_t)portNo, AdjustI2SRate(hz)); for the second stub while the first stub is still running.

This PR adds a quick check to see if rate actually needs updating or if it matches what is currently set, eliminating the above issue as long as rates match.

ChuckMash avatar Dec 16 '23 09:12 ChuckMash

Might also be useful in AudioOutputPWM.cpp and AudioOutputSPDIF.cpp, but I am unable to check those at the moment.

ChuckMash avatar Dec 16 '23 18:12 ChuckMash

The patch will likely have negative effect for 44100 Hz sample rate setting: https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L48

SetRate() will ignore to apply 44100 Hz sample rate setting upon very first run.

lyusupov avatar Dec 17 '23 10:12 lyusupov

The patch will likely have negative effect for 44100 Hz sample rate setting

I am using 44100 Hz sample rate, with no ill-effects. In this case, the default i2s sample rate might already match 44100, but I suppose that may not always be the case.

I can add check for if i2s rate has ever been set, and allow the initial set to occur.

ChuckMash avatar Dec 17 '23 13:12 ChuckMash

https://github.com/earlephilhower/ESP8266Audio/issues/406#issuecomment-1736466226 is relevant. This user also suggests not calling SetRate unnecessarily to avoid a noisy click.

ChuckMash avatar Dec 17 '23 15:12 ChuckMash