audio input and output

[I realize that a micro-controller is not meant for audio processing]

I've wrote a simple program to do an analogRead and then pass that value to analogWrite. I expected to get a lo-fi version of input. I also tried to first divide the analogRead value by 4 to keep in in the range of values that analogWrite can output.

Neither gives me what I expect.

I get a lot of noise and a constant tone through-out.

Should this be working?

I dont think this will work.

if the tone you hear is around 500Hz it is most likely the PWM frequency.

How fast are you reading / writing the analog pins ? If i'm not wrong, it would have to be several 1000 times a second to achieve something that would remotely resemble the input, and then there is the whole issue with scaling the values (divide by 4). Add to that the fact that the analog out is PWM.

You can actually sample fast enough to get audio in (although 1k or RAM is going to fill up in .25 seconds at 4k sampling rate), with PROGMEM you might get 1 or 2 seconds of sound.

As mentioned analogWrite is going to be useless for output though and you'll have to do some AVR coding to make this work.

David F at uchobby was working on this. You might email him and see if he has any code he could share.


hey tr909,

if you don't need recording seacrh the forum for "resistor ladder". if got satisfying 4-bit audio thruput using 4 arduino pins hooked to 4 digital pins. i amplify the mic input with a single transistor. I tried doing audio recording but paul is totally right: 1k is nothing. i didn't get very far doing any kind of "real-time" manipulation, but something should be possible.


And the PROGMEM is read-only, I think, although I've not tried writing to it. You probably want external storage, e.g. using the dataflash library (though I haven't tried it, so I don't know if it would work well in this application). You can also get chips that do audio recording and playback, and I'm sure there are lots that do signal manipulation.