I would like your suggestion on a project I am working on. I already purchased a microphone break out board with max output +5V, combined it with a 2nd order sallen key topology sallen key filter and I am using the ADC of arduino to convert the analog into digital, my question is : in what kind of form should I store the data into a SD card module I have?
Storing the data in a form of array or .txt file in general will it be ok?
There are many questions you need to ask. What is the desired bit resolution of the audio and the samples per second that you plan to record?
Sounds like you know this already if you’re talking about using an ADC, but for the sake of it… Remember that a Mic gives you AC voltage. Sound pushes the diaphragm back and forth which generates very small negative and positive voltages. In order to read those on an analog pin on an Arduino, you need to level shift the signal so that negative voltage is read as 0, null voltage is read as 512, and full positive voltage is read as 1023. If you don’t do that, you won’t capture the audio properly. You’ll only get half the waveform and it won’t sound right.
The analog input pins on an Arduino will only give you a range of 0-1023 which is a 10-bit number. You would need to 2 bytes to store each sample. If you only need 8-bit audio, you could map the 10-bit number to an 8-bit number and only store a single byte per sample.
Now for the samples per second… 8kHz is 8000 samples per second. So if you were recording 8-bit audio, 1 second of audio would be 8000 bytes. If you are doing 10-bit audio, that would be 16,000 bytes for 1 second of audio!
As for file format… the most common would be a .wav file. A .wav file is basically just a header describing how may channels of audio, the sample rate, etc, followed by the raw stream of samples. You can find documentation explaining how to create .wav files on the Internet. The added bonus here is if you do it right, you can test your recordings on a computer to verify you are actually capturing the audio correctly.
As for playback… there are lots of different ways to about this. I’d look at using an SPI DAC (digital to analog converter) chip. Since you’re already reading the .wav file back in via SPI, why not output the raw samples to the DAC?
You could of course pulse digital I/O pins with an added circuit to approximate the sound on a speaker, or you could try using the analog pins and level shift the voltage. In either case, you’ll likely need an amplifier.
Thanks for response and your time to answer!
So far I am using a breakout board with a microphone and an amplifier on it (SparkFun Electret Microphone Breakout - BOB-12758 - SparkFun Electronics)
I already took care about the ADC shifting to avoid negative voltages, fortunatelly I have learnt how to use it.
Due to the lack of pins I will purchase an Arduino Mega 2560 and 2 DAC breakout boards (Breakout Board for MCP4725 I2C DAC)
of course later on the DAC will be connected with an amplifier and speakers.My next few steps will be investigating how to store data into a .wav format and not into a .txt
Thanks again for your response, it really helped me!