From 71f55b183b599a1bbdaf67cbf7f8182f36b7ef8c Mon Sep 17 00:00:00 2001 From: Andrew Stanford-Jason Date: Tue, 22 Sep 2015 13:41:25 +0100 Subject: [PATCH] added agc --- module_usb_audio/pcm_pdm_mic.xc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/module_usb_audio/pcm_pdm_mic.xc b/module_usb_audio/pcm_pdm_mic.xc index fae744ea..6890d6bb 100644 --- a/module_usb_audio/pcm_pdm_mic.xc +++ b/module_usb_audio/pcm_pdm_mic.xc @@ -6,7 +6,7 @@ #include #include #include - +#include #include "static_constants.h" #if 1 on tile[0]: in port p_pdm_clk = XS1_PORT_1E; @@ -45,6 +45,8 @@ void example(streaming chanend c_ds_output_0, streaming chanend c_ds_output_1, s int prev_x[7] = {0}; int prev_y[7] = {0}; + int max = 0; + unsafe { c_ds_output_0 <: (synchronised_audio * unsafe)audio[0].data[0]; @@ -66,12 +68,21 @@ void example(streaming chanend c_ds_output_0, streaming chanend c_ds_output_1, s int a = dc_offset_removal( audio[buffer].data[1][0].ch_a, prev_x[0], prev_y[0]); int b = dc_offset_removal( audio[buffer].data[1][0].ch_b, prev_x[1], prev_y[1]); - xscope_int(0,a); - xscope_int(1,b); + //xscope_int(0,a); + //xscope_int(1,b); + + if((-a) > max) max = (-a); + if(a > max) max = a; + if((-b) > max) max = (-b); + if(b > max) max = b; + int output_a = a<<(clz(max)-1); + int output_b = b<<(clz(max)-1); + + max = max - (max>>17); c_pcm_out :> unsigned req; - c_pcm_out <: (a>>14); - c_pcm_out <: (b>>14); + c_pcm_out <: output_a; + c_pcm_out <: output_b; } } }