Skip to content

Commit

Permalink
PDM: fix setGain() for dfsdm
Browse files Browse the repository at this point in the history
If the gain was too high, the right bit shift
  RecBuff[i] >> attenuation
would result in undefined behaviour
https://www.iso-9899.info/n1570.html#6.5.7

Take the chance to also fix the (approximate) conversion from gain (in dB) to bit shift
  • Loading branch information
facchinm committed Sep 2, 2024
1 parent a77715f commit 2bb5b88
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libraries/PDM/src/STM32H747_dfsdm/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ int py_audio_init(size_t channels, uint32_t frequency)

void py_audio_gain_set(int gain_db)
{
attenuation = 8 - gain_db;
attenuation = 8 - (gain_db / 3);
if (attenuation < 0) {
attenuation = 0;
}
}

void py_audio_deinit()
Expand Down

0 comments on commit 2bb5b88

Please sign in to comment.