diff --git a/module_usb_audio/audio.xc b/module_usb_audio/audio.xc index 5ec45615..b850ea84 100755 --- a/module_usb_audio/audio.xc +++ b/module_usb_audio/audio.xc @@ -698,7 +698,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if (NUM_PDM_MICS > 0) - /* Get samples from PDM->PCM comverter */ + /* Get samples from PDM->PCM comverter */ + c_pdm_pcm <: 1; #pragma loop unroll for(int i = 0; i < NUM_PDM_MICS; i++) { @@ -1180,6 +1181,10 @@ chanend ?c_config, chanend ?c outuint(c_spdif_out, mClk); #endif +#if NUM_PDM_MICS > 0 + /* Send decimation factor to PDM task(s) */ + c_pdm_in <: curSamFreq; +#endif #ifdef ADAT_TX // Configure ADAT parameters ... @@ -1256,9 +1261,14 @@ chanend ?c_config, chanend ?c } } #ifdef SPDIF_TX - /* Notify S/PDIF thread of impending new freq... */ + /* Notify S/PDIF task of impending new freq... */ outct(c_spdif_out, XS1_CT_END); #endif + +#if NUM_PDM_MICS > 0 + c_pdm_in <: 0; +#endif + #ifdef ADAT_TX #ifdef ADAT_TX_USE_SHARED_BUFF /* Take out-standing handshake from ADAT core */ diff --git a/module_usb_audio/pdm_mics/pcm_pdm_mic.xc b/module_usb_audio/pdm_mics/pcm_pdm_mic.xc index 35c243e8..846004c8 100644 --- a/module_usb_audio/pdm_mics/pcm_pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pcm_pdm_mic.xc @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -17,8 +16,6 @@ #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; @@ -29,8 +26,8 @@ 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}; +int data_0[4*COEFS_PER_PHASE*MAX_DECIMATION_FACTOR] = {0}; +int data_1[4*COEFS_PER_PHASE*MAX_DECIMATION_FACTOR] = {0}; void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_1, chanend c_audio) { @@ -40,38 +37,53 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_ int output[NUM_PDM_MICS]; 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) - { - frame_audio * unsafe current = decimator_get_next_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio); + { + unsigned samplerate; + + c_audio :> samplerate; + unsigned decimationfactor = 48000/samplerate; + unsafe { - user_pdm_process(current, output); - - for(int i = 0; i < NUM_PDM_MICS; i++) - { - c_audio <: output[i]; - } + decimator_config_common dcc = {FRAME_SIZE_LOG2, 1, 0, 0, decimationfactor, fir_coefs[decimationfactor], 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) + { + frame_audio * unsafe current = decimator_get_next_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio); + + unsafe + { + int req; + user_pdm_process(current, output); + + c_audio :> req; + + if(req) + { + for(int i = 0; i < NUM_PDM_MICS; i++) + { + c_audio <: output[i]; + } + } + else + { + break; + } + } + } } } -#if MAX_FREQ != 48000 -#error NOT CURRENTLY SUPPORTED -#endif -#if MIN_FREQ != 48000 +#if MAX_FREQ > 48000 #error NOT CURRENTLY SUPPORTED #endif @@ -80,13 +92,13 @@ 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; streaming chan c_ds_output_0, c_ds_output_1; streaming chan c_buffer_mic0, c_buffer_mic1; - + + /* TODO, always run mics at 3MHz */ configure_clock_src_divide(pdmclk, p_mclk, 2); configure_port_clock_output(p_pdm_clk, pdmclk); configure_in_port(p_pdm_mics, pdmclk); start_clock(pdmclk); - par { pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1);