Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
1174 Discussions

Audio Codec Problems DE2 Board

Altera_Forum
Honored Contributor II
2,398 Views

Hi, 

 

I've been having some problems using the Audio Codec on the DE2 board. I've configured the board using I2C, to use the DAC at 8kHz sampling frequency, 16 bits sample size, to use Left-Justified output mode, and to be in Master mode (so I don't have to bother generating BCLK and DACLRC). 

 

To play samples through the audio codec, I first store LDATA (data for the left channel) in a register, and do the same with the RDATA. On the falling edge of BCLK, I shift LDATA if DACLRC is high, or I shift RDATA if DACLRC is low. My AUD_DAT either sends the MSB of LDATA or RDATA depending on if DACLRC is high or low. When I encounter a rising edge on DACLRC, I know that the current LDATA and RDATA has finished shifting, and I assert a signal which lets the outside world know that a new sample should be loaded into the LDATA and RDATA inputs. Once these inputs are loaded, I again begin the shifting process until the next rising edge of DACLRC. 

 

This process works for a simple ramp, where I feed LDATA and RDATA that simply start from 0x0000 and go to 0xFFFF. I've taken a few 8kHz .wav files, extracted the first non-header 2048 16-bit words with some simple C, and stored them in a ROM, and try to play new values. But whenever I do this, I just get garbage for sound. Am I doing something really wrong here?
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
932 Views

Perhaps you have an endianess issue with the data from the WAV file? A WAV file is usually little endian.

0 Kudos
Altera_Forum
Honored Contributor II
932 Views

No beans. :(

0 Kudos
Altera_Forum
Honored Contributor II
932 Views

When testing with a ramp, were you reading the values from ROM similar to your WAV data? If not, you may want to try this to prove that your routines for reading the data from the ROM are working correctly.  

 

If after testing your ROM routines you still have a problem, the issue is most likely your WAV conversion. I already suggested double checking the endianness. Perhaps your conversion is not handling two's complement correctly? 

 

What WAV files are you testing with? Maybe you could generate some simple WAV files of your own with a program such as Audacity so that you can more easily verify the results.
0 Kudos
Altera_Forum
Honored Contributor II
932 Views

Thanks for the help so far. I put the ramp within my rom, and it played out fine -- so the rom isn't really the problem. My wav file comes from the Altera DE2 Demonstrations music stuff. I took music.wav, deleted the right channel and made it mono, downsampled it to 8 kHz, cut out a chunk of it, and then took the first 2048 samples of this. My cut, downsampled version plays fine in most audio players including Audacity. I still dunno what's going on. The only thing I'm thinking is that, DACLRCK has a period of 1/fs, so each channel has 1/(2*fs) to play, which means each individual channel is actually playing at 16 kHz and not 8? Could that be the problem?

0 Kudos
Altera_Forum
Honored Contributor II
932 Views

As Kevin said above, the data in a 16bit wav file is in little endian format, so you have to swap the bytes of each word around before you feed them to your DAC. I've made the same mistake myself in the past, with the same results.

0 Kudos
Altera_Forum
Honored Contributor II
932 Views

I did have some nice code for swapping between little-big Endian, can't for the life of me find it :) 

Anyway, a simple Google search yields the following results: 

 

- http://www.gdargaud.net/hack/sourcecode.html (Scroll down to Swapping Endian Byte Order) 

- http://www.dreamincode.net/code/snippet4548.htm
0 Kudos
Altera_Forum
Honored Contributor II
932 Views

 

--- Quote Start ---  

Hi, 

 

I've been having some problems using the Audio Codec on the DE2 board. I've configured the board using I2C, to use the DAC at 8kHz sampling frequency, 16 bits sample size, to use Left-Justified output mode, and to be in Master mode (so I don't have to bother generating BCLK and DACLRC). 

 

--- Quote End ---  

 

 

Hi i just started vhdl few days back, and have to create this audio recorder on a de1. Can u help guide me through? 

 

Firstly, my doubt is on the audio codec initiating part, how is it done? If possible, can you give a sample vhdl.
0 Kudos
Reply