UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer alejandro910
Observer
15,595 Views
Registered: ‎02-19-2014

Sound Stream to Virtex 5 ML505 with AC97

Hi, I'm using a Xilinx ML505-V5LX110T.

 

Let me describe the full datapath before I state my problem:

 

I've written an application in C# that sends UPD packets, containing PCM data from my soundcard (16bit,48KHz).

 

I can read UDP packets properly (I respond to ARP requests) and I have tested the FPGA by sending a specific series of bytes that I can properly read on my FPGA.

 

Then I store every UDP data I receive to a block memory. I'm also using an AC97 interaface to communicate with the controller. Every time the interface informs me that I can send sound data to the controller, I read values from my block memory and send them to the controller. I've tested the module that stores all these bytes and it works correctly.

 

I adjusted the AC97 registers to get the PCM data to line out or headphones, and I can hear the sound stream. But the sound is clipping. I've tried many different settings in the AC97 volume registers but every time the sound stream seems to be too loud for the controller. I've even tried to cut off bits from the 16bit values I send to the controller for each channel.

 

Any ideas on how to make the clipping go away?


If you suspect any problem in my datapath, I can give more details of the procedure. Thank you in advance for any answers and sorry for the length of my post! (and my english)

0 Kudos
16 Replies
Advisor eilert
Advisor
15,575 Views
Registered: ‎08-14-2007

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

the volume and attenuation settings of the AC97 controll the output and mixer amplifiers.

If your input data somehow generates clipping effects, the amplifiers can not eliminate these.

 

Do you have some simple example of the vaveform values that you are sending and the Waveform that appears at the HP output? (e.g. measured with an oscilloscope)

 

The signal shape might give a hint what's going wrong.

 

Have a nice synthesis

  Eilert

 

0 Kudos
Observer alejandro910
Observer
15,558 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi, and thank you for the reply!

 

Unfortunately, I cant measure the headphones output, but I can test the input I'm sending.

 

Actually, I recorded the samples I'm sending to a wav file, and it sounds perfect! Combined with the fact that I actually receive the samples correctly to the FPGA, I believe the problem is at the controller settings.

 

Today it occured to me that the samples I'm sending, might be little-endian format, so I reversed the signal I'm sending to the controller, but I still get the clipping noise.

 

If I want to cut off some bites from the samples to lower the volume, from which side of the vector will I have to do it? And from which side will I concat zero bits? Or shall I concat ones? I think the controller stuffs the samples with zeros on the right side of the vector so I guess the samples are little endian format.

0 Kudos
Advisor eilert
Advisor
15,522 Views
Registered: ‎08-14-2007

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

the signal input to the AC97 controller should be sth. like this:

 

signal audio_data : std_logic_vector(17 downto 0); -- MSB ...LSB

 

This will be mapped somewhere to the 20 bit channels like this:

 

AC_Link_Channel_x <= audio_data & "00";

 

So if you want to reduce the volume of the audio data you have to manipulate the audio_data signal.

The data might be in two's complement (signed) format.

so with the help of numeric_std you can do sth. like this:

 

audio_data <= std_logic_vector( signed(audio_data) /2); -- dividend must be 2^n value like 2, 4, 8, 16 etc.

 

Still, even if you reduce the signal this way, there will be clipping noise, since the distortion of the signal will not be repaired by this. The AC 97 device can handle 18 bits full scale.

If you are sending 16 bit you need to apply them to the AC97 chip like this:

 

    audio_data <= your_pcm16 & "00"; -- given that your_pcm16 is some slv(16:0) value

or you can do some sign extension:

    audio_data <= your_pcm16(15)&your_pcm16(15)&your_pcm16; -- this keeps the volume low and preserves the sign.

 

btw: which kind of AC97 controller are you using? There are several available.

(filename, author, link ?)

 

Have a nice synthesis

  Eilert

 

 

 

0 Kudos
Observer alejandro910
Observer
15,520 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

The author of the controller I'm using is Mike Wirthlin. I can attach the files if you want. I used this controller some years ago to make a simple loopback, microphone to headphones.

 

The controller asks for 16bit input PCM data. Somewhere in the code, I found this:

 

slot3((20 - C_PCM_DATA_WIDTH-1) downto 0) <= (others => '0');
slot3(19 downto (20 - C_PCM_DATA_WIDTH)) <= PCM_Playback_Left;

 

With C_PCM_DATA_WIDTH = 16, the result is something like this: slot3 <= input_data & "0000";

 

I will try to reduce the volume using sign extention to the input_data and hear the new result.

 

Also, I have to mention that before I send the WAV data to the FPGA, I adjust their volume to 0.005 out of 1. If I send the data without any change, all I can hear is a constant noise. I believe that I need to be sending the data the way they're stored, and do the manipulation on the FPGA, but I didn't have any luck with that.

0 Kudos
Observer alejandro910
Observer
15,512 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

I just tried the sign extension, but it's not working either. I had to adjust the volume before I send the data to the FPGA and still I could hear the clipping.

I tried also to provide the two's complement of the PCM data to the controller. Somehow I could still hear the sound stream, but the clipping it's there.

Any "ideal" settings for the volume registers of the AC97?
0 Kudos
Advisor eilert
Advisor
15,505 Views
Registered: ‎08-14-2007

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

the mixer settings should not be able to produce clipping.

 

It seems suspicious that you have to reduce the amplitude of the WAV file by 200.

Can you attach the original WAV file for some analysis?

 

Kind regards

 Eilert

0 Kudos
Observer alejandro910
Observer
15,503 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

I'm using an API (Naudio) to capture every sound my PC plays at the moment with the WASAPI feature. It provides me with the WAV data I'm sending to the FPGA. I have already recorded these WAV data to a .wav file using the same API and the generated stream, sounds perfect.

 

I'm also using Wireshark to capture the packets I'm sending to the FPGA, and I didn't observe any "weird" values when I'm streaming at max volume. With all this clipping at full volume, I'd expected to see a stream of X'FFFF values (max 16bit values), but no.

0 Kudos
Observer alejandro910
Observer
15,502 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

Should I record a .wav file with my app and attach it? I forgot to mention that I compress the data size from 32bit to 16bit, but still, when I record, it sounds perfect.
0 Kudos
Advisor eilert
Advisor
15,404 Views
Registered: ‎08-14-2007

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

yes please send a short example.

Providing both versions (32bit and 16 bit) might be a good idea too.

And another thing that can be done is recording the audio output of the AC97playing this example that has the clipping noise.

That would help to understand what you are hearing and analyze the cause.

 

Kind regards

 Eilert

0 Kudos
Observer alejandro910
Observer
13,307 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi, I recorded five samples.

 

Sample32 is a .wav file as I record from my app in 32bit format, 48KHz.

Sample16 has 2 versions. One with Volume = 1, and one with volume = 0.01. Both are 16bit - 48KHz, and that's the sound stream I'm sending to the FPGA.

 

I don't have a Line-In or Microphone port on my Laptop, so I had to record what FPGA was playing with my WebCamera. The sound is pretty decent, no background noise. But I think they can only be examined acoustically.

 

Attached are the five samples I described above.

0 Kudos
Advisor eilert
Advisor
13,280 Views
Registered: ‎08-14-2007

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

thanks for the data.

I think there's more behind it than just some clipping effect.

Consider this:

The original sound files play very well with any PC player software.

Only that the sample16_min is so reduced that it becomes inaudible.

 

Now in your recording of the FPGA sound output you are using the file that contains signals below the audible level.

With min volume these become audible with some distortions, but at max volume you have just some rambling noise.

The music can not be heared.

 

You already identified the little endian problem, which means you have to swap the byte values.

 

 

One hint:

Instead of taking data from the soundcard, why dont you calculate some test values using your C# program.

e.g. some simple sine waves.

This way you have perfect control over the data and format that you are transfering, and you can change these fast and easy within the C# program to hear the difference.

Even some strange misalignment in the hardware (UDP->AC97) might be discovered this way. Needs some clever test patterns, though.

 

Have a nice synthesis

  Eilert

 

0 Kudos
Observer alejandro910
Observer
13,248 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

 

Sorry it took me so long to answer!!

 

I've have already modified my c# app to send some specific byte values, in this format:

0 1 2 3 4 5 6 7   0 1 2 3 4 5 6 7   0 1 2 3 4 5 6 7 ...

 

After the first UDP packet has arrived in the FPGA, I begin checking the byte values that reach the AC97 controller. Because the samples are 16bit long, the data I should be providing to the controller are:

 

left_channel = 0 1          right_channel = 2 3     (first sample)

left_channel = 4 5          right_channel = 6 7     (second sample)

left_channel = 0 1          right_channel = 2 3     (third sample)

etc

 

I think it is the only stream of data that arrives on my controller, so I dont believe there's a problem in the UDP->AC97 "translation".

 

I'm a bit confused with the little endian format. Don't I just change the order of bits?

 

For example:   Big Endian     00101

                           Little Endian  10100

 

Or should only consider bytes?

 

For example:   Big Endian     byte1 byte2

                           Litle Endian   byte2 byte1

 


If it's the second case, I'll just try and swap the byte values so that the controller sees:

 

left_channel = 1 0          right_channel = 3 2     (first sample)

left_channel = 5 4          right_channel = 7 6     (second sample)

left_channel = 1 0          right_channel = 3 2     (third sample)

etc

 

If it's the first, shall I apply the transform to the whole 16bit value, or at each byte seperatly?

This: 10001000_00100000  -> 00000100_00010001

Or this: 10001000_00100000 -> 00010001_00000100

 

I'm sorry for my basic lack of knowledge on the subject, and thank you for your help!!

0 Kudos
Observer alejandro910
Observer
13,247 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

OK, the "change bits order" was stupid! Endian format are about bytes.

I'll just try and swap them and hear the new result!
0 Kudos
Observer alejandro910
Observer
13,242 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

I just finished testing. I swaped the byte order, so now I get this signal from the UDP packets:

 
{byte1 byte2 byte3 byte4} {byte5 byte6...} etc

 
and I give the AC97 controller this:


{byte2 byte1 byte4 byte3} {byte6 byte5...} etc

 
I don't know if wav files store data differently but I just swapped the bytes that way.

 
The sound is definently more audible than before, but I still get a clipping effect. Also, I'm now sending the sound from the c# app at full volume, with no problems. There has to be an error on my design that I cant track down.

I recorded 3 samples. First is just with the byte swap. In the second and third recording I tried to reduced the sound volume by shifting the signal that connects to the AC97 controller.

I shifted this way: { left_channel[15:2] , 2'b00}

and that way: { left_channel[13:0] , 2'b00}

I think after all these tests I can hear some other issues with the sound too, except from the clipping noise.

I'll try testing the way I read bytes from UDP, store them, and then sending them to the controller.

 
If you have any suggestions, let me know! Thank you!   

0 Kudos
Advisor eilert
Advisor
13,226 Views
Registered: ‎08-14-2007

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

are you sending the whole WAV file?

You know that there are non audio data parts in WAV files:

See this for details (or any other page about the wav file format):

http://en.wikipedia.org/wiki/WAV#Non-audio_data

 

As you can see there are many items that are not intended to be sent to the AC97 decoder and would create short distortions in that case.

 

Does your C# program take care of the non audi data parts?

 

Have a nice synthesis.


   Eilert

0 Kudos
Observer alejandro910
Observer
13,221 Views
Registered: ‎02-19-2014

Re: Sound Stream to Virtex 5 ML505 with AC97

Hi,

 

The source of my data isn't a wav file. I'm just saving the audio data to a wav file so I can verify the record process.

 

The source is from WasapiLoopbackCapture, a function from Naudio Library that provides me the data stream I'm sending to the FPGA. I hope that these data won't be pure audio, so I can finally find the source of my problem!! I'll have a look at the Naudio documentation and I'll let you know the results of my research.

 

Thank you very much,

Alex

0 Kudos