hal: Fix input buffer size for fractional rate 24bit capture

The input buffer size from ADSP must be a multiple of 32 bytes and a
multiple of the frame_size. For fractional sample rates (eg. 44.1kHz)
with 24bit packed samples, 32 is not the smallest common multiple.

Change-Id: Ifcef1daa4f43e90fdb30873192c0047677ae3c00
This commit is contained in:
Ralf Herz 2018-09-28 15:50:49 +02:00
parent 6225a27083
commit bd08d63c19
1 changed files with 14 additions and 4 deletions

View File

@ -3289,6 +3289,8 @@ static size_t get_input_buffer_size(uint32_t sample_rate,
int channel_count,
bool is_low_latency)
{
int i = 0;
size_t frame_size = 0;
size_t size = 0;
if (check_input_parameters(sample_rate, format, channel_count) != 0)
@ -3298,15 +3300,23 @@ static size_t get_input_buffer_size(uint32_t sample_rate,
if (is_low_latency)
size = configured_low_latency_capture_period_size;
size *= audio_bytes_per_sample(format) * channel_count;
frame_size = audio_bytes_per_sample(format) * channel_count;
size *= frame_size;
/* make sure the size is multiple of 32 bytes
/* make sure the size is multiple of 32 bytes and additionally multiple of
* the frame_size (required for 24bit samples and non-power-of-2 channel counts)
* At 48 kHz mono 16-bit PCM:
* 5.000 ms = 240 frames = 15*16*1*2 = 480, a whole multiple of 32 (15)
* 3.333 ms = 160 frames = 10*16*1*2 = 320, a whole multiple of 32 (10)
*
* The loop reaches result within 32 iterations, as initial size is
* already a multiple of frame_size
*/
size += 0x1f;
size &= ~0x1f;
for (i=0; i<32; i++) {
if ((size & 0x1f) == 0)
break;
size += frame_size;
}
return size;
}