Hi all. I am trying to make an audio player that will fade in and out depending on an analog input data stream from a sensor. I have got the audio to play out of the DAC0 pin from the SD card successfully but cant find anything in the AudioZero library to let me change the volume. Does anyone have any ideas on how I could do this? It's possible to take the voltage from the DAC and feed it into another arduino but the Uno etc dont have a high enough read rate on the analog pins to reproduce the higher frequencies. I could take the voltage straight into an analog pin on the MKRZero but then I dont have another DAC to output the signal. Any ideas greatly appreciated!
Why? You have the digital data from the memory card. In my opinion it is sufficient to multiply or divide the values before feeding them to the DAC. For example if you multiply by 1.2 you have a 20% increase in DAC output voltage and if you divide by 2 you get half. Just watch out for overflow because you will have clipping.
This would be ideal but I cant see how to access the data stream inside the code. Having done some more reading it looks like the AudioZero library doesnt allow for any other code to be executed whilst the audio is running, so I cant even read my sensor data from the analog pins.
Maybe you need a 2nd microcontroller controlling a digital potentiometer?
Or a DFPlayer (or similar). It takes care of the audio and the Arduino just has to send some control messages, telling it what file to play, when to start/stop, and what volume to play at, etc.
I don't know anything about the library, but that makes sense. You'd have to do all of your other processing in-between audio samples. That probably means the audio has to run from an interrupt timer so it gets priority.
(Computers have an audio buffer and an independent audio clock to allow for multitasking.)
Ah the DFplayer looks ideal! Thanks for the tip.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.