/*
* ip_functions.c
*
* Contains all functions which pertain to setup and use of IP periperals.
*/
#include "adventures_with_ip.h"
/* ---------------------------------------------------------------------------- *
* lms_filter() *
* ---------------------------------------------------------------------------- *
* This function adds a tonal noise component to the sampled audio from the
* audio codec by passing a step size to the input of an NCO component in the
* PL. A sinusoidal signal is received back from the NCO which is then scaled
* and added to the sampled audio. The audio + noise sample can then be
* adaptively filtered using an LMS filter in the PL. The resulting audio,
* filtered or not, is then output to the audio codec.
*
* The main menu can be accessed by entering 'q' on the keyboard.
* ---------------------------------------------------------------------------- */
void lms_filter()
{
u32 nco_in, nco_out, in_left, in_right, out_left, out_right, step, \
prevL, prevR, prevTone, temp;
/* Read step size value from DIP switches */
step = XGpio_DiscreteRead(&Gpio, SWITCH_CHANNEL);
/* Write step size value to the LEDs */
Xil_Out32(LED_BASE, step);
/* Scale the step size */
nco_in = step;
xil_printf("Step = %d, nco_in = %d\r\n",step, nco_in);
while (!XUartPs_IsReceiveData(UART_BASEADDR)){
/* Input step size to the NCO core */
XNco_SetStep_size_v(&Nco, nco_in);
/* Receive sinusoidal sample from NCO core */
nco_out = XNco_GetSine_sample_v(&Nco);
if(nco_out!=prevTone) { /* New sinusoidal sample? */
temp = nco_out;
}
/* Sample L+R audio from the codec */
in_left = Xil_In32(I2S_DATA_RX_L_REG);
in_right = Xil_In32(I2S_DATA_RX_R_REG);
/* -------------------------------------------------------------------------------- *
* --------------------------------- LEFT CHANNEL --------------------------------- *
* -------------------------------------------------------------------------------- */
if(in_left != prevL) /* New left sample? */
{
/* Add noise component to the L+R audio samples */
out_left = (temp + in_left);
Xil_Out32(LMS_D, out_left >> SCALE); // Input audio+noise as desired signal
Xil_Out32(LMS_X, temp >> SCALE); // Input noise as input
Xil_Out32(LMS_STROBE, 0x01); // Stobe LMS to signal inputs are finished
/* If any button is pressed */
if(XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL)>0){
/* Wait until output data is ready */
out_left = (Xil_In32(LMS_E) << (SCALE-1)); // Output filtered audio
}
/* Output audio to the codec */
Xil_Out32(I2S_DATA_TX_L_REG, out_left);
}
/* -------------------------------------------------------------------------------- *
* --------------------------------- RIGHT CHANNEL -------------------------------- *
* -------------------------------------------------------------------------------- */
if(in_right != prevR) /* New right sample? */
{
/* Add scaled noise component to the L+R audio samples */
out_right = (temp + in_right);
Xil_Out32(LMS_D, out_right >> SCALE); // Input audio+noise as desired signal
Xil_Out32(LMS_X, temp >> SCALE); // Input noise as input
Xil_Out32(LMS_STROBE, 0x01); // Stobe LMS to signal inputs are finished
/* If any button is pressed */
if(XGpio_DiscreteRead(&Gpio, BUTTON_CHANNEL)>0){
out_right = (Xil_In32(LMS_E) << (SCALE-1)); // output filtered audio
}
/* Output audio to the codec */
Xil_Out32(I2S_DATA_TX_R_REG, out_right);
}
/* Update previous input values */
prevL = in_left;
prevR = in_right;
prevTone = nco_out;
/* If the DIP switch values have changed, break from while
* loop to allow the step size value to update.
*/
if(step != XGpio_DiscreteRead(&Gpio, SWITCH_CHANNEL)) break;
} // while
/* If input from the terminal is 'q', then return to menu.
* Else, continue. */
if(XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET)=='q') menu();
else lms_filter();
} // LMS filtering
/* ---------------------------------------------------------------------------- *
* tonal_noise() *
* ---------------------------------------------------------------------------- *
* This function adds a tonal noise component to the sampled audio from the
* audio codec by passing a step size to the input of an NCO component in the
* PL. A sinusoidal signal is received back from the NCO which is then scaled
* and added to the sampled audio. The audio + noise sample is then sent to
* the audio codec for output.
*
* The main menu can be accessed by entering 'q' on the keyboard.
* ---------------------------------------------------------------------------- */
void tonal_noise(void)
{
u32 nco_in, nco_out, in_left, in_right, out_left, out_right, step, temp;
/* Read step size value from DIP switches */
step = XGpio_DiscreteRead(&Gpio, SWITCH_CHANNEL);
/* Write step size value to the LEDs */
Xil_Out32(LED_BASE, step);
/* Scale the step size */
nco_in = step;
xil_printf("Step = %d, nco_in = %d\r\n",step, nco_in);
while (!XUartPs_IsReceiveData(UART_BASEADDR)){
/* Input scaled step size to the NCO core */
XNco_SetStep_size_v(&Nco, nco_in);
/* Receive sinusoidal sample from NCO core */
nco_out = XNco_GetSine_sample_v(&Nco);
//temp = (((double)nco_out+16384)/32768)*(2^3); // Scaling for audio codec
temp = nco_out;
/* Sample L+R audio from the codec */
in_left = Xil_In32(I2S_DATA_RX_L_REG);
in_right = Xil_In32(I2S_DATA_RX_R_REG);
/* Add scaled noise component to the L+R audio samples */
out_left = temp + in_left;
out_right = temp + in_right;
/* Output corrupted audio to the codec */
Xil_Out32(I2S_DATA_TX_L_REG, out_left);
Xil_Out32(I2S_DATA_TX_R_REG, out_right);
/* If the DIP switch values have changed, break from while
* loop to allow the step size value to update.
*/
if(step != XGpio_DiscreteRead(&Gpio, SWITCH_CHANNEL)) break;
} // while
/* If input from the terminal is 'q', then return to menu.
* Else, continue. */
if(XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET) == 'q') menu();
else tonal_noise();
} // tonal_noise()
/* ---------------------------------------------------------------------------- *
* audio_stream() *
* ---------------------------------------------------------------------------- *
* This function performs audio loopback streaming by sampling the input audio
* from the codec and then immediately passing the sample to the output of the
* codec.
*
* The main menu can be accessed by entering 'q' on the keyboard.
* ---------------------------------------------------------------------------- */
void audio_stream(){
u32 in_left, in_right;
while (!XUartPs_IsReceiveData(UART_BASEADDR)){
// Read audio input from codec
in_left = Xil_In32(I2S_DATA_RX_L_REG);
in_right = Xil_In32(I2S_DATA_RX_R_REG);
// Write audio output to codec
Xil_Out32(I2S_DATA_TX_L_REG, in_left);
Xil_Out32(I2S_DATA_TX_R_REG, in_right);
}
/* If input from the terminal is 'q', then return to menu.
* Else, continue streaming. */
if(XUartPs_ReadReg(UART_BASEADDR, XUARTPS_FIFO_OFFSET) == 'q') menu();
else audio_stream();
} // audio_stream()
/* ---------------------------------------------------------------------------- *
* gpio_initi() *
* ---------------------------------------------------------------------------- *
* Initialises the GPIO driver for the push buttons and switches.
* ---------------------------------------------------------------------------- */
unsigned char gpio_init()
{
int Status;
Status = XGpio_Initialize(&Gpio, BUTTON_SWITCH_ID);
if(Status != XST_SUCCESS) return XST_FAILURE;
XGpio_SetDataDirection(&Gpio, SWITCH_CHANNEL, 0xFF);
XGpio_SetDataDirection(&Gpio
没有合适的资源?快使用搜索试试~ 我知道了~
The_Zynq_Book实例教程资料
共36个文件
cpp:8个
c:7个
h:5个
需积分: 13 24 下载量 168 浏览量
2016-07-12
11:56:57
上传
评论 1
收藏 6MB ZIP 举报
温馨提示
The_Zynq_Book实例教程资料,是zynq入门的好例子,手把手一步一步地教您,带您步入zynq的殿堂。
资源推荐
资源详情
资源评论
收起资源包目录
The_Zynq_Book实例教程资料.zip (36个子文件)
led_controller
led_controller_test_tut_4A.c 2KB
led_controller_v1_0.vhd 4KB
led_constraints.xdc 928B
led_controller_v1_0_S00_AXI.vhd 15KB
hdl_coder_lms
setup.m 208B
playback.m 309B
lms.slx 15KB
original_speech.wav 3.79MB
hls_nco
nco.cpp 76KB
nco_tb.cpp 1KB
first_zynq_design
LED_test_tut_1C.c 3KB
hls
tut3C
matrix_mult.h 544B
matrix_mult.cpp 585B
matrix_mult_test.cpp 2KB
run_hls.tcl 801B
tut3B
matrix_mult.h 544B
matrix_mult.cpp 585B
matrix_mult_test.cpp 2KB
run_hls.tcl 801B
tut3A
matrix_mult.h 544B
matrix_mult.cpp 585B
matrix_mult_test.cpp 2KB
run_hls.tcl 801B
zynq_interrupts
interrupt_counter_tut_2B.c 4KB
interrupt_counter_tut_2D.c 6KB
adventures_with_ip_integrator
drivers
audio.h 3KB
constraints
adventures_with_ip.xdc 2KB
ip
xilinx.com_user_lms_pcore_1.0.zip 85KB
zed_audio_ctrl.zip 66KB
xilinx.com_user_led_controller_1.0.zip 12KB
xilinx_com_hls_nco_1_0.zip 29KB
software
ip_functions.c 9KB
adventures_with_ip.h 3KB
adventures_with_ip.c 3KB
audio.c 8KB
original_speech.wav 3.79MB
共 36 条
- 1
资源评论
wenchang_c
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功