diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index 331e345e..4399f20b 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -49,6 +49,12 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) user_pdm_init(); #endif +#if NUM_PDM_MICS > 4 + unsigned decimatorCount = 2; +#else + unsigned decimatorCount = 1; +#endif + mic_array_decimator_conf_common_t dcc; const int * unsafe fir_coefs[7]; mic_array_frame_time_domain * unsafe current; @@ -106,13 +112,13 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) dc[1].mic_gain_compensation[3]=0; dc[1].channel_count = 4; - mic_array_decimator_configure(c_ds_output, 2, dc); + mic_array_decimator_configure(c_ds_output, decimatorCount, dc); - mic_array_init_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc); + mic_array_init_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); /* Grab a first frame of mic data */ /* Note, loop is unrolled once - allows for while(1) select {} and thus combinable */ - current = mic_array_get_next_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc); + current = mic_array_get_next_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); } /* Run user code */ @@ -141,7 +147,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) } /* Get a new frame of mic data */ - mic_array_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc); + mic_array_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); /* Run user code */ #ifdef MIC_PROCESSING_USE_INTERFACE @@ -160,11 +166,11 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) dcc.output_decimation_factor = decimationfactor; dcc.coefs=fir_coefs[decimationfactor/2]; dcc.fir_gain_compensation = fir_gain_compen[decimationfactor/2]; - mic_array_decimator_configure(c_ds_output, 2, dc); - mic_array_init_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc); + mic_array_decimator_configure(c_ds_output, decimatorCount, dc); + mic_array_init_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); /* Get a new mic data frame */ - mic_array_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc); + mic_array_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); /* Run user code */ #ifdef MIC_PROCESSING_USE_INTERFACE @@ -186,14 +192,19 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) void pdm_mic(streaming chanend c_ds_output[2]) { - streaming chan c_4x_pdm_mic_0, c_4x_pdm_mic_1; + streaming chan c_4x_pdm_mic_0; +#if (NUM_PDM_MICS > 4) + streaming chan c_4x_pdm_mic_1; +#else + #define c_4x_pdm_mic_1 null +#endif /* Mics expect a clock in the 3Mhz range, calculate the divide based on mclk */ /* e.g. For a 48kHz range mclk we expect a 3072000Hz mic clock */ /* e.g. For a 44.1kHz range mclk we expect a 2822400Hz mic clock */ /* Note, codebase currently does not handle a different divide for each clock */ - assert((MCLK_48 % 3072000) == (MCLK_441 % 2822400)); + assert((MCLK_48 / 3072000) == (MCLK_441 / 2822400)); unsigned micDiv = MCLK_48/3072000; @@ -206,7 +217,9 @@ void pdm_mic(streaming chanend c_ds_output[2]) { mic_array_pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1); mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic_0, c_ds_output[0]); +#if (NUM_PDM_MICS > 4) mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic_1, c_ds_output[1]); +#endif } } #endif