Help playing wave files?

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anyone know an easy way to play a .wav file in an embedded system?

Thanks,
Paul

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are several flavors of wave file.... easiest to play would be an 8 bit mono about 22khz... might need to resave it in this format... use 8 bit fast pwm 62500 khz and a 10k R and a .1C (1/2piRC should be about 11K). Use a timer interrupt to get the 22khz (45usecs). Stuff a byte in the OCRx every interrupt.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This gives me a clue. I'm not an expert on .wav files.

Can anyone point to an example?

Thanks,
Paul

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is a 44byte header that has the sample rate and whether its mono or stereo.. wave editors like 'cooledit' let you save the raw data without the header, or you can use a binary editor to stript it, or just play it.. there will be a bzzzt of static at the beginning as it tries to play the header. You can record 'testing 1 2 3' using the windows recorder, but then you need a utility to convert the binary file full of bytes to something like an initialized array in c that can be included and compiled.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, Bob. This gives me a starting point.

Regards,
Paul

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've done this. I just prepare my .wav files by first recording on the PC at 44.1KHz mono with 16 bit samples. I then down-convert it to a suitable sample rate for an AVr to play (7.2KHz in my case allowing for about a 3.6KHz audio range). I also use FFT and bandpass filters to get rid of the extreme high/low stuff. Finally I write the file (from Cooledit) as raw 8 bit PCM samples.

I then Xmodem-CRC these data bytes across to the AVR where they are stored in AT45, SPI connected Dataflash and finally, to play back, I user timer 1 in PWM mode and use the samples to adjust the OCR1A and the audio comes out of the OC1A pin.

There's an Atmel app note (335 I seem to recall) about using PWM to play audio that makes a good basis for this kind of stuff.

One additional thing I did was to write an ADPCM encoder on the PC side and an ADPCM decoder on the AVR side to allow me to compress/decompress the audio data to get more into the AT45 Dataflash. (this is part of the reason that my sample/play frequency is as low as 7.2Khz and not the 22KHz that Bob suggests above)

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I didnt know if he was shooting for speech or music or sound effects... wonder how many mips it would take to sw decode low bit rate mono mp3s and play the reconstructed samples on a pwm channel? What is the lowest bitrate mp3? 64kbps? 32kbps?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well for encoded audio (OGG not MP3) I guess the easy answer is the VS1000 in fact. I know it adds $10 to the design (one off) but it saves an awful lot more than $10 of effort:

http://www.sparkfun.com/commerce...

Jesper also has the VS1001 alternative for MP3 though it's obviously more expensive:

http://www.myplace.nu/mp3/
http://www.jelu.se/shop/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
an easy way to play a .wav file in an embedded system
You bring the seashell to your ear and you will hear the...wave...and yes you can do it even if you are in bed. :lol:

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Must be a water bed...