From 2c16a0f7e769605a8af3c275f12889dd90c2ad23 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 5 Nov 2015 15:28:45 +0000 Subject: [PATCH] Updated PDM Mic integration for latest version of lib_mic_array --- module_usb_audio/pdm_mics/pcm_pdm_mic.xc | 42 +++++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/module_usb_audio/pdm_mics/pcm_pdm_mic.xc b/module_usb_audio/pdm_mics/pcm_pdm_mic.xc index 3f959b47..fdb2eea2 100644 --- a/module_usb_audio/pdm_mics/pcm_pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pcm_pdm_mic.xc @@ -1,8 +1,9 @@ -#include "devicedefines.h" #if (NUM_PDM_MICS > 0) +#include "devicedefines.h" + /* This file includes an example integration of lib_array_mic into USB Audio */ #include @@ -17,6 +18,8 @@ #include "fir_decimator.h" #include "mic_array.h" +#define DF 1 + /* Hardware resources */ in port p_pdm_clk = PORT_PDM_CLK; in buffered port:32 p_pdm_mics = PORT_PDM_DATA; @@ -27,6 +30,9 @@ clock pdmclk = on tile[PDM_TILE]: XS1_CLKBLK_3; unsafe void user_pdm_process(frame_audio * unsafe audio, int output[]); void user_pdm_init(); +int data_0[4*COEFS_PER_PHASE*DF] = {0}; +int data_1[4*COEFS_PER_PHASE*DF] = {0}; + void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_1, chanend c_audio) { unsigned buffer = 1; // Buffer index @@ -36,6 +42,15 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_ user_pdm_init(); + unsigned decimation_factor=DF; + unsafe + { + decimator_config_common dcc = {FRAME_SIZE_LOG2, 1, 0, 0, decimation_factor, fir_coefs[decimation_factor], 0}; + decimator_config dc0 = {&dcc, data_0, {0, 0, 0, 0}}; + decimator_config dc1 = {&dcc, data_1, {0, 0, 0, 0}}; + decimator_configure(c_ds_output_0, c_ds_output_1, dc0, dc1); + } + decimator_init_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio); while(1) @@ -54,10 +69,6 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_ } } -#define DF 1 - -#define OUTPUT_SAMPLE_RATE (48000/DF) - #if MAX_FREQ != 48000 #error NOT CURRENTLY SUPPORTED #endif @@ -65,10 +76,6 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_ #error NOT CURRENTLY SUPPORTED #endif -//TODO make these not global -int data_0[4*COEFS_PER_PHASE*DF] = {0}; -int data_1[4*COEFS_PER_PHASE*DF] = {0}; - void pcm_pdm_mic(chanend c_pcm_out) { streaming chan c_multi_channel_pdm, c_sync, c_4x_pdm_mic_0, c_4x_pdm_mic_1; @@ -80,18 +87,13 @@ void pcm_pdm_mic(chanend c_pcm_out) configure_in_port(p_pdm_mics, pdmclk); start_clock(pdmclk); - unsafe - { - decimator_config dc0 = {FRAME_SIZE_LOG2, 1, 0, 0, DF, FIR_LUT(DF), data_0, 0, {0,0, 0, 0}}; - decimator_config dc1 = {FRAME_SIZE_LOG2, 1, 0, 0, DF, FIR_LUT(DF), data_1, 0, {0,0, 0, 0}}; - par - { - pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1); - decimate_to_pcm_4ch(c_4x_pdm_mic_0, c_ds_output_0, dc0); - decimate_to_pcm_4ch(c_4x_pdm_mic_1, c_ds_output_1, dc1); - pdm_process(c_ds_output_0, c_ds_output_1, c_pcm_out); - } + par + { + pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1); + decimate_to_pcm_4ch(c_4x_pdm_mic_0, c_ds_output_0); + decimate_to_pcm_4ch(c_4x_pdm_mic_1, c_ds_output_1); + pdm_process(c_ds_output_0, c_ds_output_1, c_pcm_out); } }