Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: Razor Concepts on January 11, 2009, 12:40:16 PM

Title: AVR WAV player
Post by: Razor Concepts on January 11, 2009, 12:40:16 PM
I've been interested in playing sounds but those $100 mp3 player boards were a little too much. Then I stumbled across the adafruit wave sheild, which plays WAV files with the arduino.
(http://www.adafruit.com/images/medium/waveshield_MED.jpg)
Since I don't have an arduino I'll be wiring it up to work on the Axon. Hope this will be a great cheap way to play sounds.
Title: Re: AVR WAV player
Post by: izua on January 11, 2009, 01:35:33 PM
you can make a 16 bit R2R ladder using a bunch of resistors (well, a bigger bunch) and spitting the samples on the avr's port. i'm planning do to the same thing, but using cmos latches instead, so i have a better current source.
Title: Re: AVR WAV player
Post by: Soeren on January 11, 2009, 02:36:20 PM
Hi,

you can make a 16 bit R2R ladder using a bunch of resistors
And where are you gonna find resistors with 0.0015% precision? ;)
8 bit should be fine for this kind of stuff.
Title: Re: AVR WAV player
Post by: izua on January 11, 2009, 04:33:12 PM
you don't need that kind of precision. resistors from the same batch are precise enough to be used for such a purpose (try testing them with a good multimeter and see for yourself) ;)
8 bit is fine for some stuff, but it's not fine for music. For example, in a drumbeat, you need crashes and cymbals, which are white noise with a timbre, so to say. With only 8 bits of resolution, a cymbal will sound very bad - try it.

This wave shield is interesting. The sampling frequency is kind of misleading though: is the 20k the sampling frequency (meaning a max of 10k - thus, not very different from ISD chips, which adafruit bashes) or is the 20k the max rendered frequency (and thus, the sampling frequency is 40k ) ?
Title: Re: AVR WAV player
Post by: airman00 on January 11, 2009, 04:45:39 PM
Theres got to be a cheaper approach to even the one RazorConcepts presented.
Maybe just hack one of those el-cheapo MP3 players - http://www.geeks.com/details.asp?invtid=XE689G&cat=MP3

Another option : get a sound recorder IC and record the audio onto it. Then playback. I remember I used to play around with a sound recorder IC - a circuit that you press a button to record, and another button to play back.

I'm actually thinking of fabricating ( and maybe selling) an alarm clock that plays this song as the alarm tone - http://www.youtube.com/watch?v=PAbwMGZtIsY .I'll definitely need some sort of MP3/WAV playback device.
Title: Re: AVR WAV player
Post by: Dscrimager on January 11, 2009, 05:07:41 PM
Well,  there is a cheaper serial controllable MP3 player. I'm thinking of switching to this:

http://www.mouser.com/search/ProductDetail.aspx?R=VMUSIC2virtualkey62130000virtualkey895-VMUSIC2

The uMP3 players from Rogue are really nice ( I have one for Halloween and 1 on my current large robot project).
I have one of the VMusic2s now and hope to start testing with it in the next week or so (it's for my Halloween show....).

Cheaper than the Rogue, it's slightly larger but I guess you could break the board out of the case if you needed it smaller. Many of Halloween builders are switching over because of the price (about $40)

Doug
Title: Re: AVR WAV player
Post by: izua on January 11, 2009, 05:36:28 PM
Theres got to be a cheaper approach to even the one RazorConcepts presented.

As I said earlier, a homemade DAC, R2R ladder style. You won't get 100% linearity, matching resistors for MSB positions will do good.
Title: Re: AVR WAV player
Post by: Admin on January 11, 2009, 11:53:52 PM
Just thought I'd post this:
http://www.societyofrobots.com/robotforum/index.php?topic=3365.0
Title: Re: AVR WAV player
Post by: Webbot on January 12, 2009, 06:31:42 AM
The other way to do it:-

1. Set up a high frequency PWM signal - say around 20kHz to 30kHz

2. Use the WAV values to change the duty-cycle of the PWM between 0% and 50%

3. Use an RC filter to filter out the higher frequency PWM signal

Feed the result through an amplifier.

The benefit is that you only need one IO pin.

Title: Re: AVR WAV player
Post by: izua on January 12, 2009, 06:41:38 AM
The drawback is that you can't get high pitches. If you go with high sample rate (20khz), you'll need a pwm frequency of 40khz, and that limits your available resolution to 4-5 bits. So you will be able to generate high pitches, but they will sound distorted because of the low headroom.
If you go with 16 bits, you won't be able to go above 400hz for pwm, so that's 200hz, upper limit of your signal.,
Title: Re: AVR WAV player
Post by: Soeren on January 12, 2009, 01:14:20 PM
Hi,

you don't need that kind of precision.
Then why do you specify 16 bit?
That's just plain and unneeded overhead then.


resistors from the same batch are precise enough to be used for such a purpose (try testing them with a good multimeter and see for yourself) ;)
Oh well, did that numerous times over the years and there's quite a variance.

But anyway, let's say you use something like a BK Precision 2831D, a 4½ digit meter (at more than $300, way out of reach of the average hobbyist), you get a precision in the resistance ranges of +/-(0.2% + 6 digits) - assuming that it is recently calibrated.

A 10k resistor measuring 10.000 on the kOhm scale will then be between 9,974 Ohm and 10,026 Ohm, ie. a tolerance of +/- 0.26% or 0.52% total!
In other words, a precision that can be handled in 7.6 bits, so 8 bits is ample.

Besides, if you ever tried it, you would know - there's a reason you pay good money for a 16 bit converter.


8 bit is fine for some stuff, but it's not fine for music. For example, in a drumbeat, you need crashes and cymbals, which are white noise with a timbre, so to say. With only 8 bits of resolution, a cymbal will sound very bad - try it.
Been there, done that, got that T-shirt decades ago. And... Being an ee with experience from pro broadcasting as well as audiology, I sort of know a wee bit about dynamic range (DR) - but go ahead with your home made 16 bit (or even 8 bit) R/2R converter and get some experience in inferior sound yourself ;)
Btw. Do you know the DR of your hearing? (Hint: Unless you've been tested at a clinic in a sound proofed box by an audiologist recently, the answer is no).

The module in question (why does people call extension modules for shields nowadays? A shield has a very different meaning for me) is ment for a certain kind of apps. which doesn't include 7.1 surround on a $10k+ set up, but rather an easy to use sound clip player for automation projects and similar.


This wave shield is interesting. The sampling frequency is kind of misleading though: is the 20k the sampling frequency (meaning a max of 10k - thus, not very different from ISD chips, which adafruit bashes) or is the 20k the max rendered frequency (and thus, the sampling frequency is 40k ) ?
Even if it was the sample freq. it would be much more versatile than the ISD chips (number of sound clips, possible length of sound clips and with extra SD cards, you can have limitless clips) - whether the sound quality would be better depends on the hardware and how it's designed - like cheap MP3 players that sounds horrible, even if the files are of the best quality.

As far as I read it, it's the max. useable frequency though.
Title: Re: AVR WAV player
Post by: Soeren on January 12, 2009, 01:19:18 PM
Hi,

The drawback is that you can't get high pitches. If you go with high sample rate (20khz), you'll need a pwm frequency of 40khz,
To use a sample rate of eg. 44.1 kHz, you need at least 300 kHz "carrier" to get a reasonable quality for music.

PWM from a µC is good for advanced beeps and simple (horrible) voice messages.
Title: Re: AVR WAV player
Post by: Webbot on January 12, 2009, 01:41:56 PM
Hmmm - as well as the 'output stage' of your MP3 player - I would suggest there are other physical considerations to think about.

If we are talking about 16 bit samples at 44.1kHz sample rate - then thats going to be a 'shed load' of data (88kb per second per channel).

Obviously WAV is just a packaging format - the actual codec used to hold the sound data may already have some compression applied depending on which of the plethora of the available formats you want to support. Are you going to support all these codecs (do they require licenses) or are you just going for uncompressed WAV files. Are you only going to support Mono or Stereo (ie double the amount of data)?

Where are you storing all this data? eg microSD card? I believe these are accessed via I2C so: Can you retrieve the data from the card at 44.1kHz per channel?

The answers may all be 'Yes - Its fine' but just food for thought..