Arduino project for Audio for learning purposes - codec

Hello Everyone,

I am trying to build up a small arduino project as one excuse for my personal learning about electronics and the sound processing.

I woud like to record sound from a microphone and record it using some digital format, then play it from a speaker or a PC, both the speaker and the microphone are connected to the Arduino, I would like use the Analog Input for recording and the PMW for output.

I have bought one microphone , this one :

And I have got a decent speaker :

I am able to read from the analog zero values 0-1023 and using the FHT library I am able to obtain frequencies - I followed some tutorial I am not really in with Furier - now I would like move on storing the signal in some digital format .. and I am lost and looking for suggestions ...

Does someone know how can I make progesses ? I would like use a very simple digital format to store the audio data, simple because it has to run on an Arduino board which lacks of computing power and because I would like be able to fully understand it .

I am also confused about the process I could use to play the sound I recorded on an PWM: recording from a microphone I get Volts value which can be
translated in frequencies using the FHT, but if I want to use PWM using the function (which as far as I am aware it is the only function I can use) :

tone(pin , Frequency, time);

From FHT I don't get a single frequency but a spectrum! Some physic and math could come in handy here I guess .. some good resources where
point me to ? Can't I play using .. Volt ? :~

I don't mind about sound quality .. I mind just to understand the key concepts.

Thanks in advance,

What board do you have? AFAIK the simplest codec requires at least 20+ kB memory to run, so only DUE is capable up to task.
If you trying to invent your own compression algorithm, than I'd suggest you should study FFT, it has reversible counterpart - iFFT, to recreate waveform back from frequency domain.

The FFT creates and explosion of data - double the number of samples in memory use because for every sample, you are storing a real and imaginary component - 2:1 ratio. I wouldn't recommend trying to come up with your own encoding scheme for the audio data, but rather use something someone else has already developed if possible. You wouldn't just have to study the FFT, you would have to study Perceptual Coding.

Your simplest and most direct solution is likely with DPCM - differential pulse code modulation for the purpose of storage. Instead of storing a full sample value, you store the difference between the sample and the previous sample, so rather than full 16, 24, or 32 bit words, you can compact and store bytes. It is not the highest quality audio, but for purpose of limited memory it goes a long way.

The FFT is not useful in the context of PWM unless you have enough PWMs to create a bank of oscillators out of them, or as someone suggested use the IFFT to re-construct your original signal and use the PWM to output sample by sample. For audio quality you're much better off using something with a DAC, like Teensy. If you're going to use PWM to construct audio, you don't output frequencies, you output sample values that vary over time the same as your voltage does in order reproduce your audio waveform.

It seems like you need to back away from the FFT for a minute and gain an understanding of how digital audio works in general.
For a plain English explanation of sampling and the FFT read Appendix C of my thesis or some of the basics outlined in the second paper:

You can also google Julius O. Smith III, who has tons of resources on general audio processing - especially Spectral Audio Processing.

Yes, actually I knew I would need to read some theory about this, thanks bosleymusic for the sources I will keep you posted, I do not think I could come out with my own encoding scheme, it is too complicated for me now !

I was reading from the teacher website :

Do you think I can find the pdf version of the "PHYSICAL AUDIO SIGNAL PROCESSING" and "PECTRAL AUDIO SIGNAL PROCESSING" ? I found heavy to read at the PC, I tried to quicky google the problem buu I did not find them.


Hey Pietro. Here is a link to a really god resource for real time audio using the UNO. It explains how to get audio in through the ADC and out through PWM and adds some synthesis and effects as well. There are also some good examples. For the audio input and output some minimal electronics is required but I found this to be one of the best resources when I started out learning about audio and Arduino. :slight_smile:
Arduino Audio lab.