Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12589 Discussions

I get a big noise when I echo the audio data from microphone

Altera_Forum
Honored Contributor II
1,232 Views

I designed a audio system in Qsys. I read the fifo data from the microphone input and write it to the audio write fifo. Although I can hear the microphone echo, it also generate a very big noise. I can't figure out why it will generate so much noise. Dose anyone have any idea why it is happened? I am not sure the setting of the audio codec is correct or not. Another problem is that how can I generate the sound with specific frequency? 

 

I think the design in Qsys is correct. I generate the correct clock frequency to the audio and av_config core. I am using de2-115 board. 

 

 

I use these functions :  

alt_up_audio_read_fifo  

alt_up_audio_write_fifo  

 

Here is my c code to achieve the echo system. 

int main(){ alt_up_audio_dev * audio_dev = alt_up_audio_open_dev ("/dev/audio"); alt_up_av_config_dev* av_config_dev = alt_up_av_config_open_dev("/dev/audio_and_video_config"); /* used for audio record/playback */ unsigned int l_buf ; unsigned int r_buf ; // initialize the audio core alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x00, 0b000011000); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x01, 0b000011000); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x02, 0b000111100); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x03, 0b000111100); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x04, 0b000010100); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x05, 0b000000110); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x06, 0b000000000); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x07, 0b001001101); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x08, 0b000000000); alt_up_av_config_write_audio_cfg_register(av_config_dev, 0x09, 0b000000001); while(1) { // read audio buffer alt_up_audio_read_fifo (audio_dev, &(r_buf), 80, ALT_UP_AUDIO_RIGHT); alt_up_audio_read_fifo (audio_dev, &(l_buf), 80, ALT_UP_AUDIO_LEFT); // write audio buffer alt_up_audio_write_fifo (audio_dev, &(r_buf), 80, ALT_UP_AUDIO_RIGHT); alt_up_audio_write_fifo (audio_dev, &(l_buf), 80, ALT_UP_AUDIO_LEFT); } } }
0 Kudos
9 Replies
Altera_Forum
Honored Contributor II
490 Views

I would first suggest that you figure out if your problem is in audio input or output. Generate a synthetic audio signal and see if it comes out clean. Feed a test signal to the audio input and look at the data read.

0 Kudos
Altera_Forum
Honored Contributor II
490 Views

Thank you for the reply! 

 

How can I generate a synthetic audio signal? Since I don't have the line in cable... 

 

I try to do this, but it doesn't work... I think this two lines will generate the sound of "l_buf = 30000"? 

unsigned int l_buf = 30000; 

alt_up_audio_write_fifo (audio_dev, &(l_buf), 80, ALT_UP_AUDIO_LEFT); 

 

Many Thanks
0 Kudos
Altera_Forum
Honored Contributor II
490 Views

Lookup table with a sine wave in it.

0 Kudos
Altera_Forum
Honored Contributor II
490 Views

A simple counter that increments and is reset to zero results in a triangle wave. A counter that alternates between the min and max values gives you a square wave. Make sure a complete cycle runs in about 400-500 Hz for the most audible tone on cheap speakers.

0 Kudos
Altera_Forum
Honored Contributor II
490 Views

If I choose 16 bits as my audio data bit length, the max value becomes 65535 and min value becomes 0? 

 

I am not sure the C program is running under 50MHz or not.. If it is, i think my synthetic audio signal is: 

 

 

// for tri wave int tri_signal = 0; while (1){ for(int n = 0; n<12500; n++){ tri_signal = tri_signal + 5; } tri_signal = 0 } // for sine wave (not smooth) int sine_signal = 32767; while (1){ for(int n = 0; n<3125; n++){ sine_signal = sine_signal + 10; } for(int n = 0; n < 6250; n++){ sine_signal = sine_signal - 10; } for(int n = 0; n < 3125; n++){ sine_signal = sine_signal + 10; } }
0 Kudos
Altera_Forum
Honored Contributor II
490 Views

Check your data sheet. You must use a word length that matches the audio output chip. Most but not all are 16 bits. However, you cannot assume it is 0 to 64K. Min and max might be +/- 32K. Again check the data sheet.

0 Kudos
Altera_Forum
Honored Contributor II
490 Views

I can now generate a simple sine wave signal by a lookup table and send it to the line out now. I can hear very clear sound from the earphone. Thus I think the problem is not in the output. How should I send the sine signal to the input?  

 

Here is the code to test the output. 

for(n = 0; n<256; n++){ alt_up_audio_write_fifo (audio_dev, &(sine), 16, ALT_UP_AUDIO_LEFT); }
0 Kudos
Altera_Forum
Honored Contributor II
490 Views

Verilog is *not* a procedural language. For loops don't do things one by one, they infer hardware for each instance of the loop - so that will not do what you want. 

 

You need to create a counter (always @ ... counter <= counter+ 1), and use that to read from your fifo. 

 

EDIT: 

 

Never mind, that was C code, I misread. Ignore the above.
0 Kudos
Altera_Forum
Honored Contributor II
490 Views

I recommend using a triangle wave to test your input function. It is easier to verify that the received data is correct. You should use a function generator connected to the ADC input. Don't forget to get the impedance matched. Once you have a clean triangle wave going to your audio input you should be able to test your data input function.

0 Kudos
Reply