drivers: audio: mpxxdtyy: Handle PCM block sizes of more than 1 ms
The Open_PDM_Filter_64/128() functions of the third-party OpenPDMFilter library are designed to handle a fixed PCM block size of 1 ms of audio. Allow the MPxxDTyy drivers to use a block size of more than 1 ms by calling the filtering function multiple times, once for each ms of audio. Fixes zephyrproject-rtos/zephyr#69447 Signed-off-by: Petar Susac <petar.susac@byte-lab.com>
This commit is contained in:
parent
701b6aed4b
commit
e3cacf7390
|
@ -90,7 +90,8 @@ int sw_filter_lib_run(TPDMFilter_InitStruct *pdm_filter,
|
|||
void *pdm_block, void *pcm_block,
|
||||
size_t pdm_size, size_t pcm_size)
|
||||
{
|
||||
int i;
|
||||
int i, j;
|
||||
int pdm_offset;
|
||||
uint8_t a, b;
|
||||
|
||||
if (pdm_block == NULL || pcm_block == NULL || pdm_filter == NULL) {
|
||||
|
@ -118,26 +119,36 @@ int sw_filter_lib_run(TPDMFilter_InitStruct *pdm_filter,
|
|||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < pcm_size / 2; j += pdm_filter[0].Fs / 1000) {
|
||||
/*
|
||||
* The number of PDM bytes per PCM sample is the decimation factor
|
||||
* divided by the number of bits per byte (8). We need to skip a number of
|
||||
* PDM bytes equivalent to the number of PCM samples, times the number of
|
||||
* channels.
|
||||
*/
|
||||
pdm_offset = j * (pdm_filter[0].Decimation / 8) * pdm_filter[0].In_MicChannels;
|
||||
|
||||
for (i = 0; i < pdm_filter[0].In_MicChannels; i++) {
|
||||
switch (pdm_filter[0].Decimation) {
|
||||
case 64:
|
||||
for (i = 0; i < pdm_filter[0].In_MicChannels; i++) {
|
||||
Open_PDM_Filter_64(&((uint8_t *) pdm_block)[i],
|
||||
&((uint16_t *) pcm_block)[i],
|
||||
Open_PDM_Filter_64(&((uint8_t *) pdm_block)[pdm_offset + i],
|
||||
&((uint16_t *) pcm_block)[j + i],
|
||||
pdm_filter->MaxVolume,
|
||||
&pdm_filter[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 128:
|
||||
for (i = 0; i < pdm_filter[0].In_MicChannels; i++) {
|
||||
Open_PDM_Filter_128(&((uint8_t *) pdm_block)[i],
|
||||
&((uint16_t *) pcm_block)[i],
|
||||
Open_PDM_Filter_128(&((uint8_t *) pdm_block)[pdm_offset + i],
|
||||
&((uint16_t *) pcm_block)[j + i],
|
||||
pdm_filter->MaxVolume,
|
||||
&pdm_filter[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue