Basically, i intend to have a sensor that triggers a wav file to play from an SD card, however I'm struggling to understand how to process audio with an arduino.
As I understand it you can't simply use an arduino to output audio as it's processor isn't good enough and likewise it's PWM doesn't pulse fast enough. So you need to use a Digital to analogue converter to return the PWM signal to a smooth wave and then amplify it to audible quality. The programming is something I could work on but hardware wise, I'm stumped. What I'm asking is; Is my reasoning for not being able to use an arduino correct? and what else do I need other than a DAC and arduino?
you need to use a Digital to analogue converter to return the PWM signal to a smooth wave and then amplify it to audible quality.
No PWM has absolutely nothing to do with it.
You need an SD card, D/A converter, low pass filter and audio amplifier.
All these can come together in a wave shield. Look at the one from AdaFruit, it is open source and you can get the schematics and build it yourself if you want to but it is easier to buy it. There is sample software on their site that does almost exactly what you want to do.
As I understand it you can't simply use an arduino to output audio as it's processor isn't good enough and likewise it's PWM doesn't pulse fast enough.
Sure you can. That's exactly the approach we take with our BeatVox shield. The DAC+filter is the common solution but you can get pretty good results by putting the PWM on the Arduino.
--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons
I'm doing something like this, too. Is an I2C DAC too slow, or would a parallel one be necessary? Also, could the SDfatlib be used, or is that too slow?
Hack the library and run it at 400KHz
Or get one with an SPI interface.
Parallel ones are not good with the arduino due to lack of a whole port with all the pins free. However it is fine on a Mega.
Fair enough. I have the I2C DAC mentioned above, and just ordered the parallel one for the purpose of playing wav files. I plan on hooking it up to port B, but could I do the very same with my I2C one? How do I put it in fast mode? Also, is the SDfatlib fast enough to retrieve the DAC values from the SD card?
You are better off using direct port access for that sort of thing, it doesn't get any faster. Or did you maen I2C? Just look at the libary codenand you will see the commented out instructions.
Yes an SD card is fast enough to play samples, look at the lady ada wave shield software for an example.
Typing, yes sorry I am on an iPad at the moment and if you don't watch it it is fond of putting an n in place of a space and also auto correcting words. I can't seem to turn that off.
Yes that is what to change, remember you need external pull ups on the I2C line.
Do you think that the SD lib included with Arduino 022 is fast enough for audio playback? Also, should I get a buffer chip to buffer the SD lines (MOSI, SCK, SS)?
I just did some research on the I2C DAC: If in fast mode (400kbps), I can clock out one value (2 bytes) in 40us, giving an ideal maximum sample rate of 25khz. This is just enough for 22khz sample rate wav. However, in high-speed mode (3.4Mbps), one cycle is only ~5us, giving a max sample rate of 212kHz(!) Is this to fast for the arduino? If not, I would love to use the high speed mode and free up some pins...
Also, do I need a buffer on the SD card? is 40mA enough?
However, in high-speed mode (3.4Mbps), one cycle is only ~5us, giving a max sample rate of 212kHz(!) Is this to fast for the arduino?
Remember that the I2C bus is dependent on the clock rate you send it. We are just talking about the maximum rates here. There is no problem with sending data at any rate up to the maximum. With the arduino running at 16MHz I think the maximum clock rate for the I2C bus will be 4MHz but you would have to check the data sheet.
do I need a buffer on the SD card?
What do you mean by this? You defiantly need some logic level converters resistive potential dividers don't always work.
Current requirements for SD cards vary so you are better off regulating down to 3V3 from 5V.
I am running this whole setup from 3.3V (everything...) so no converters are needed... I'm just wondering about an actual buffer if the AVR i/o pins can't handle the sd card requirements.