For my application, I only need about five seconds of audio to play from a speaker, but it has to be high quality, so I don't want to use a cheap microcontroller with a low sampling rate. It seems like the higher sampling rate microcontrollers that are good for audio have more capability than I need, and I want the microcontroller to be as cheap as possible. Any suggestions?
design help for choosing AVR for audio project
it has to be high quality
So what, exactly, does that mean?
The way to approach this is to define what you require in terms of storage, code, speed, cost, etc - and then look for parts which fit those requirements.
By high quality I mean at least a 32 kHz sampling rate...
By "sampling" do you mean the micro will be recording? (presumably using an ADC?).
Or are you just going to play pre-recorded samples that were captured using something else?
In either case the playback could be an issue - the temptation with AVRs is to fake a DAC using PWM through a filter but it's difficult to hit the sample rates you are talking of. So you probably need an R2R or a real DAC.
Another alternative is Xmega - they have DACs in silicon and can do reasonably high rates.
EDIT sorry, just realised this is in "General Electronics" - so it might not even be Atmel you were looking at?
The audio will be a short duration, pre-recorded sound. I'm looking at Atmel but I'm not sure what the best option is and I'm open to anything that would be good for this application.
By high quality I mean at least a 32 kHz sampling rate...
That's still not saying much:
- How many bits per sample ?
- How many channels ?
- Any MP3 or suchlike processing ?
- etc, etc
I think 16 bits would be sufficient, single channel, the format doesn't matter...I'm looking for a general direction to know where to start, it doesn't have to be precise.
Is your gizmo recording the sound, then replaying, or is the sound clip canned, from some outside source?
Jim
I'm looking for a general direction to know where to start
So why are you even thinking about a specific chip at this stage?
The choice of chip is an implementation detail - you have a whole lot of analysis & design to do before you reach that point!
The audio will be a short duration, pre-recorded sound.
Now, this may not fit into your parameters. But in several apps, we use an "answering machine" chip. In our experience, it gives very acceptable voice playback in applications such as restaurant drive-up window greetings.
Search the forums for "nuvoton" or "winbond", and look for threads discussing the "isd" product line. Also "chipcorder".
Playback of 44KHz is easy with almost any micro. Doing it at 16 bits resolution ( and being meaningful) is a whole different ball game... 10 or 12 bits is fairly simple and will give good results and be relatively easy to achieve. There's plenty of 10/12 bit SPI DACs out there, along with single chip digital filters. As said above, there's more to this than simply choosing a processor...
The gizmo will not record or do voice playback. It will just play a nature sound (to be determined, leaves rustling for example!) for about five seconds. It seems so simple it would be nice if just a single microcontroller could accomplish this, so if this is possible then the choice of chip would be the implementation...would a separate DAC really be necessary?
Try using only 8-bit samples. Even at 15,000 samples per second, it should sound fine on a small speaker. Where are you planning to store this 75,000 bytes of audio? On a couple of serial EEPROMs?
I don't have experience with this, so I'm not sure how to answer! I guess my question is whether there is a cheap Atmel chip (or another suggestion) that is well suited for audio, and whether an external DAC is necessary...
Since its a 'nature sound', a 1 second loop could be played forever it you edited the loop cleverly. An Arduino mega has 256K of flash, so you could have a 6k playback program and 250k of data to play back in the flash. 8 bit sounds played back at 11KHz sample rate lets you have 22 sec of stuff to play back. Got an example of a couple of the sounds? If they don't have a lot of hi freq content, you don't need a hi playback sample rate.
Sorry I don't have sounds yet. As for the Arduino Mega, it seems overboard to have 54 I/O pins and 16 analog inputs since I only want to use about four pins in the project. I found this tutorial about playing sound from an Arduino: http://highlowtech.org/?p=1963 is there a better way to do this?
http://elm-chan.org/works/sd8p/report.html
I built one in a few minutes using ATtiny45 and SD card adapter as socket for uSD.
So lets argue about processor selection based on these requirements: enough flash to hold and play several sounds at some bit depth and playback sample rate. Mega2560: good! has 256K of flash! Smaller AVR with an SD card: also good, if you can get the sd working. Much more complicated in my opinion, since I havent been able to get one working yet. (different compiler. Baaaaah.). You dont like the mega2560 because you are 'wasting' all those IOs and analog ins. I would agree if this was a commercial product idea where the cost of 10000+ AVRs gets pricy. Is this R&D and proof of concept or, almost ready for production phase? Adafruit has a music card that plays stereo 12bit at 44.1 I think on an uno. http://www.adafruit.com/product/94
The above suggestions are all good ones.
Another option, which would be my approach, would be t use an Xmega E5 with its built-in DAC.
I'd get the DAC up and running with some simple audio signals, (software sin wave, for example), and then look at the audio sample storage, (SD, EEPROM, etc.).
Know that getting "clean" audio on a small PCB next to a uC has a few underlying challenges.
You will need to pay close attention to your power supply, signal routing, and the layout of the amplifier.
I think 16 bits on a small, inexpensive, PCB is a bit over the top.
Start with the DAC on the Xmega and listen to the sound quality you obtain.
It doesn't sound like your project will require 16 bit quality.
JC
Ok, thank you for the suggestions!! I'll have to try things out...I can never seem to get away from Arduino! Right now I want a proof of concept, but I was thinking that it would be good to have something suited for production.
You're really going to have to start with hammering out this statement:
but it has to be high quality
Who is your audience? What is the purpose of the device? What precisely will the sound be? My 'Music and Technology' professor back at school used the phrase 'Good enough to fool the cat' in reference to playback systems.
Who is the 'cat' here? If he is a listener wearing studio-quality over-the-ear headphones fed by your gizmo, then 'high quality' will mean something very different from the 'cat' who is casually walking by motion-activated exhibit with a 2-inch speaker in a noisy art gallery opening.
I've hacked one of these by replacing the stock pcb with a custom pcb holding only a 328p and a 2n2222 to drive the built-in speaker. Wrote code to convert any arbitrary WAV file into a C array to be included into my project code. Sample-rate was computed based upon the length of the audio clip. I could get about 4 seconds of 8 ksps 8-bit audio. The quality was 'high enough' for 'my needs'.
So, what are 'your needs'? Simply saying 'at least 32ksps' has no direct relationship to 'high quality'.
The gizmo will not record or do voice playback. It will just play a nature sound (to be determined, leaves rustling for example!) for about five seconds. It seems so simple it would be nice if just a single microcontroller could accomplish this, so if this is possible then the choice of chip would be the implementation...would a separate DAC really be necessary?
The various Atmel (and others) ARMs support the I2S digital-audio interface, which is what pretty much all audio converters use. It's a simple three-wire interface. The processor may also be able to generate the modulator clock required by the converters, too. Trailing-edge DACs are probably a buck apiece, too.
Start with the DAC on the Xmega and listen to the sound quality you obtain.
An alternate is to add an audio board on an Xplained Pro header.
Not much options with a std. AVR. Sigma-delta sounds a more realistic approach.
With a bit of creativity, you may also emulate a fast PWM with a SPI stream and look-up tables.
You may also use oversampling and dithering to emulate a 13 or 14-bit ADC, but I doubt the AVR will be fast enough for that.
Get ready for some in-line assembly.