diff options
author | Cooper Harasyn <charasyn@outlook.com> | 2020-11-27 16:05:59 -0500 |
---|---|---|
committer | Cooper Harasyn <charasyn@outlook.com> | 2020-11-27 16:05:59 -0500 |
commit | 25b2f82ccfe98ec06f730813e818443df0e10972 (patch) | |
tree | 291fab37d2dc9274d37384710c36d5edef541fc8 | |
parent | 828d1ea59eb95edc840ca25de5f8c594fd9b584e (diff) |
Prevent ALSA audio corruption
When using the ALSA driver, corruption would occur if `snd_pcm_writei`
was unable to consume the entire sound buffer. This would occur
frequently on the Raspberry Pi 3 which uses the `snd_bcm2835` audio
driver.
This bug resulted from incorrect pointer math on line 187, resulting in
the sample source pointer being advanced by `total * ad->channels` bytes
instead of `total * ad->channels` samples. In my opinion, the best fix
is to change `*src` to type `int16_t`, since that is the sample type in
use.
Fixes #43927.
-rw-r--r-- | drivers/alsa/audio_driver_alsa.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp index 488fd4b468..7aa3787ced 100644 --- a/drivers/alsa/audio_driver_alsa.cpp +++ b/drivers/alsa/audio_driver_alsa.cpp @@ -183,7 +183,7 @@ void AudioDriverALSA::thread_func(void *p_udata) { int total = 0; while (todo && !ad->exit_thread) { - uint8_t *src = (uint8_t *)ad->samples_out.ptr(); + int16_t *src = (int16_t *)ad->samples_out.ptr(); int wrote = snd_pcm_writei(ad->pcm_handle, (void *)(src + (total * ad->channels)), todo); if (wrote > 0) { |