From eda913b203cf0a2fc55346f12d89a995273ebe43 Mon Sep 17 00:00:00 2001 From: Ville Viinikka Date: Tue, 13 Feb 2024 23:12:17 +0200 Subject: [PATCH] Use correct sample bit width snd_pcm_hw_params_get_sbits gives the number of significant bits, not the actual number of bits stored. Change to snd_pcm_format_physical_width. This fixes a bug where, for example on my hardware: format = 'S32_LE' significant bits = 24 physical bits = 32 the program will segfault because the allocated buffer is too small. --- alsaaudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alsaaudio.c b/alsaaudio.c index 6a2b98c..d3c15f2 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -403,7 +403,7 @@ static int alsapcm_setup(alsapcm_t *self) snd_pcm_hw_params_get_period_size(hwparams, &self->periodsize, &dir); snd_pcm_hw_params_get_periods(hwparams, &self->periods, &dir); - self->framesize = self->channels * snd_pcm_hw_params_get_sbits(hwparams)/8; + self->framesize = self->channels * snd_pcm_format_physical_width(self->format)/8; return res; }