xMega / XPLAIN music output

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

Hi there!
I want to output some music/sound on XPLAIN board using speaker on it. As I understand, I need use built-in SDRAM (stores data), DMA (to transfer data from SDRAM into DAC) and DAC to generate wave by speaker.
Is there is missed sometng? How to write data into SDRAM on XPLAIN board and how to convert some mp3/wav for it can be played on XPLAIN board?
Thank )

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

Why does the data need to exist in SDRAM? Why is DMA required?

You can play tunes on a Tiny2313 simply by feeding PCM data from code flash to a timer doing PWM. True the Xmega now has a luxury of DAC so you don't need to waste time/effort with PWM but other than that there's no real difference between the two. You certainly don't need to buffer the data in SDRAM and you don't need anything as fancy as DMA (in fact a DAC makes it much easier than timer/PWM - you'll have tons of CPU time between audio samples.

I guess the key question is where is the audio stored? You could use SDRAM but but how does it get there - maybe use a UART link to a PC and Xmodem/Ymodem/Zmodem WAV files from the PC to the SDRAM? But you can just as easily build them in as data in the code flash of the program image (though it makes changing the data more difficult). At 8Khz in 128K you can store about 16 seconds of sampled audio. I'd guess a better idea is a simple MIDI or other "note storage" method and a phase accumulator? With that you could get many minutes of tunes into a 128K Xmega.

Cliff

EDIT:

http://elm-chan.org/works/mxb/re...
https://www.avrfreaks.net/index.p...

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

mp3 is compressed format, work on something easier first, like wav format which is not compressed. You need to calculate the amount of RAM you need, based on the what resolution you want 8 bit? 16 bit? what sampling frequency you use and so on...and how long you want to play your music.

This website give you a good start, why dont you read the website then only come back here?

http://dev.emcelettronica.com/ho...

Note: the website is using PIC though, but the concept is the same anyway.

I think you problem is a general one, not specific to Xplain board yet, once you understand and know what you are doing, then you can start to implement in XPLAIN board (which I have no idea what it is).

Wow, cliff posted few secs earlier than me, haha

cs

I'm happy ytd, today, and tmr :)

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

Quote:

like wav format which is not compressed.

WAV is not a format it's a container. There can be about one of 50 different audio formats within it, some uncompressed (raw PCM) some compressed (uLaw, aLaw, G.729, etc. etc.). But the idea is to use a program that can read all the audio formats that might be within the WAV (like Audacity or CoolEdit) and then have it output raw PCM samples. Strip off the 62 byte .WAV header and you are left with just audio samples. Start with 8 bit, mono at about 8KHz (fine for "radio/telephone" quality). Convert that into C source using a tool such as "xxd -i" and then build that C array into your program and just output it to the DAC at the sample rate.

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

I would like play not only MIDI, but full music songs with speach (2-3 minutes). Sound quality 8 bit will be ok.

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

Quote:

but full music songs with speach (2-3 minutes).

Like I say 8K data per second will be quite acceptable. So you need 1.44MB of storage. With "notes" (like MIDI) you get to store the tune in a very compressive format then the audio generator just needs a table full of sine samples to feed the phase accumulator. But for speech etc you have no option but to store raw PCM. An AVR does have enough overhead (at 8kHz samples) to do a simple compression like ADPCM on sampled data but you cannot decompress more complex things like MP3 or AAC or G.729 (GSM mobile audio compression) in realtime on an AVR without silicon support.

As the Xplain has 8MB of Dataflash it would seem to be the obvious place to store the audio samples.

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

Stealing Proteus doesn't make you an engineer.

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

The demo sounds on the Xplain board are 8-bit linear PCM mono with 32 kHz sampling rate, played from flash using DMA (just for comparison, attached as WAV files). Using sample-and-hold (S/H) mode allows for pretty accurate timing (together with a timer and/or DMA off by max. 1 clock cycle if a refresh collision occurs, I think).

Using μ-law encoding is probably worth it (land line telephone uses it at 8 kHz sampling rate).

Attachment(s):