Updated PDM Mic integration for latest version of lib_mic_array

This commit is contained in:
Ross Owen
2015-11-05 15:28:45 +00:00
parent 0dc7c0fd60
commit 2c16a0f7e7

View File

@@ -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 <platform.h>
@@ -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);
}
}