|
|
|
|
@@ -16,6 +16,8 @@
|
|
|
|
|
#include "fir_decimator.h"
|
|
|
|
|
#include "mic_array.h"
|
|
|
|
|
|
|
|
|
|
#define MAX_DECIMATION_FACTOR 12
|
|
|
|
|
|
|
|
|
|
/* Hardware resources */
|
|
|
|
|
in port p_pdm_clk = PORT_PDM_CLK;
|
|
|
|
|
in buffered port:32 p_pdm_mics = PORT_PDM_DATA;
|
|
|
|
|
@@ -26,12 +28,12 @@ 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*MAX_DECIMATION_FACTOR] = {0};
|
|
|
|
|
int data_1[4*COEFS_PER_PHASE*MAX_DECIMATION_FACTOR] = {0};
|
|
|
|
|
int data_0[4*THIRD_STAGE_COEFS_PER_STAGE * MAX_DECIMATION_FACTOR] = {0};
|
|
|
|
|
int data_1[4*THIRD_STAGE_COEFS_PER_STAGE * MAX_DECIMATION_FACTOR] = {0};
|
|
|
|
|
|
|
|
|
|
frame_audio mic_audio[2];
|
|
|
|
|
|
|
|
|
|
void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_1, chanend c_audio)
|
|
|
|
|
void pdm_process(streaming chanend c_ds_output[2], chanend c_audio)
|
|
|
|
|
{
|
|
|
|
|
unsigned buffer = 1; // Buffer index
|
|
|
|
|
memset(mic_audio, sizeof(frame_audio), 0);
|
|
|
|
|
@@ -45,21 +47,21 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_
|
|
|
|
|
|
|
|
|
|
c_audio :> samplerate;
|
|
|
|
|
|
|
|
|
|
unsigned decimationfactor = 48000/samplerate;
|
|
|
|
|
unsigned decimationfactor = 96000/samplerate;
|
|
|
|
|
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
const int * unsafe fir_coefs[7] = {0, g_third_stage_div_2_fir, g_third_stage_div_4_fir, g_third_stage_div_6_fir, g_third_stage_div_8_fir, 0, g_third_stage_div_12_fir};
|
|
|
|
|
|
|
|
|
|
decimator_init_audio_frame(c_ds_output_0, c_ds_output_1, buffer, mic_audio, DECIMATOR_NO_FRAME_OVERLAP);
|
|
|
|
|
decimator_config_common dcc = {MAX_FRAME_SIZE_LOG2, 1, 0, 0, decimationfactor, fir_coefs[decimationfactor/2], 0, 0, DECIMATOR_NO_FRAME_OVERLAP, 2};
|
|
|
|
|
decimator_config dc[2] = {{&dcc, data_0, {0, 0, 0, 0}, 4}, {&dcc, data_1, {0, 0, 0, 0}, 4}};
|
|
|
|
|
decimator_configure(c_ds_output, 2, dc);
|
|
|
|
|
|
|
|
|
|
decimator_init_audio_frame(c_ds_output, 2, buffer, mic_audio, dcc);
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
frame_audio * unsafe current = decimator_get_next_audio_frame(c_ds_output_0, c_ds_output_1, buffer, mic_audio);
|
|
|
|
|
frame_audio * unsafe current = decimator_get_next_audio_frame(c_ds_output, 2, buffer, mic_audio, dcc);
|
|
|
|
|
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
@@ -80,6 +82,7 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -91,7 +94,7 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_
|
|
|
|
|
void pcm_pdm_mic(chanend c_pcm_out)
|
|
|
|
|
{
|
|
|
|
|
streaming chan c_4x_pdm_mic_0, c_4x_pdm_mic_1;
|
|
|
|
|
streaming chan c_ds_output_0, c_ds_output_1;
|
|
|
|
|
streaming chan c_ds_output[2];
|
|
|
|
|
|
|
|
|
|
/* TODO, always run mics at 3MHz */
|
|
|
|
|
configure_clock_src_divide(pdmclk, p_mclk, 2);
|
|
|
|
|
@@ -102,9 +105,9 @@ void pcm_pdm_mic(chanend 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);
|
|
|
|
|
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, c_pcm_out);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|