I2S Fade #17833
Replies: 1 comment
-
This is a matter of multiplying each sample by a factor. This needs to be done in real time, so efficiency is important. The factor only needs to be calculated once, when the volume level is changed. If you assume full volume is 0dB then attenuation is in multiples of -1dB: this corresponds to a voltage ratio of 0.89. The factor for an attenuation of def set_atten(db):
f = 0.89**db
for s in samples:
s = round(f * s) # scaling The best way of doing this depends on factors such as the source of the data, the sample size and the sample rate. The RP2040 does not have hardware floating point: it is possible to rearrange the scaling to use integer arithmetic. This might be necessary for performance reasons. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I use RP2040 / I2S functionality to add sounds to my mp controlled model trains. Examples created by Mike Teachman gave me a very good start; created a pcb with two RP2040's for two "streams" each, using asyncio).
I2S includes a way to control the volume, however only in steps of a plus or minus of 6dB.
Anybody who has implemented a more refined way or even a "fader"? Or are more advanced sample manipulations whilst maintaining a constant data flow too much of load to the mcu ? Thx .
Beta Was this translation helpful? Give feedback.
All reactions