@@ -35,6 +35,8 @@ static uint32_t HAL_RCC_DFSDM1_CLK_ENABLED=0;
35
35
36
36
static uint32_t DFSDM1_Init = 0 ;
37
37
38
+ static int attenuation = 5 ;
39
+
38
40
ALIGN_32BYTES (int32_t RecBuff [PDM_BUFFER_SIZE ]);
39
41
40
42
#define SaturaLH (N , L , H ) (((N)<(L))?(L):(((N)>(H))?(H):(N)))
@@ -391,6 +393,7 @@ int py_audio_init(size_t channels, uint32_t frequency)
391
393
392
394
void py_audio_gain_set (int gain_db )
393
395
{
396
+ attenuation = 8 - gain_db ;
394
397
}
395
398
396
399
void py_audio_deinit ()
@@ -414,15 +417,15 @@ void audio_pendsv_callback(void)
414
417
xfer_status &= ~(DMA_XFER_HALF );
415
418
416
419
for (int i = 0 ; i < PDM_BUFFER_SIZE /2 ; i ++ ) {
417
- ((int16_t * )g_pcmbuf )[i ] = SaturaLH ((RecBuff [i ] >> 8 ), -32768 , 32767 );
420
+ ((int16_t * )g_pcmbuf )[i ] = SaturaLH ((RecBuff [i ] >> attenuation ), -32768 , 32767 );
418
421
}
419
422
} else if ((xfer_status & DMA_XFER_FULL )) { // Check for transfer complete.
420
423
// Clear buffer state.
421
424
xfer_status &= ~(DMA_XFER_FULL );
422
425
423
426
for (int i = 0 ; i < PDM_BUFFER_SIZE /2 ; i ++ )
424
427
{
425
- ((int16_t * )g_pcmbuf )[i ] = SaturaLH ((RecBuff [PDM_BUFFER_SIZE /2 + i ] >> 8 ), -32768 , 32767 );
428
+ ((int16_t * )g_pcmbuf )[i ] = SaturaLH ((RecBuff [PDM_BUFFER_SIZE /2 + i ] >> attenuation ), -32768 , 32767 );
426
429
}
427
430
}
428
431
}
0 commit comments