forked from PAWPAW-Mirror/lib_xua
Tidy up mic integration task
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
/* This file includes an integration of lib_array_mic into USB Audio */
|
||||
|
||||
#include "devicedefines.h"
|
||||
|
||||
#if (NUM_PDM_MICS > 0)
|
||||
|
||||
/* This file includes an example integration of lib_array_mic into USB Audio */
|
||||
|
||||
#include <platform.h>
|
||||
#include <xs1.h>
|
||||
@@ -8,58 +13,43 @@
|
||||
#include <string.h>
|
||||
#include <xclib.h>
|
||||
#include <stdint.h>
|
||||
#include "devicedefines.h"
|
||||
|
||||
#include "fir_decimator.h"
|
||||
#include "mic_array.h"
|
||||
#include "mic_array_board_support.h"
|
||||
|
||||
#define FORM_BEAM 1
|
||||
|
||||
#if 1
|
||||
/* Hardware resources */
|
||||
in port p_pdm_clk = PORT_PDM_CLK;
|
||||
in buffered port:32 p_pdm_mics = PORT_PDM_DATA;
|
||||
in port p_mclk = PORT_PDM_MCLK;
|
||||
clock pdmclk = on tile[PDM_TILE]: XS1_CLKBLK_3;
|
||||
|
||||
in port p_mclk = PORT_PDM_MCLK;
|
||||
clock mclk = on tile[PDM_TILE]: XS1_CLKBLK_1;
|
||||
clock pdmclk = on tile[PDM_TILE]: XS1_CLKBLK_3;
|
||||
|
||||
void user_pdm_process(frame_audio *audio)
|
||||
{
|
||||
static unsigned gain = 8*4096*8;
|
||||
|
||||
for(unsigned i=0;i<7;i++)
|
||||
{
|
||||
unsigned output = audio->data[i][0];
|
||||
audio->data[i][0] = ((uint64_t)output*gain)>>8;
|
||||
}
|
||||
}
|
||||
|
||||
/* User hooks */
|
||||
unsafe void user_pdm_process(frame_audio * unsafe audio, int output[]);
|
||||
void user_pdm_init();
|
||||
|
||||
void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_1, chanend c_audio)
|
||||
{
|
||||
|
||||
unsigned buffer = 1; //buffer index
|
||||
frame_audio audio[2]; //double buffered
|
||||
unsigned buffer = 1; // Buffer index
|
||||
frame_audio audio[2]; // Double buffered
|
||||
memset(audio, sizeof(frame_audio), 0);
|
||||
int output[NUM_PDM_MICS];
|
||||
|
||||
user_pdm_init();
|
||||
|
||||
decimator_init_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio);
|
||||
|
||||
unsafe
|
||||
while(1)
|
||||
{
|
||||
while(1)
|
||||
frame_audio * unsafe current = decimator_get_next_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio);
|
||||
|
||||
unsafe
|
||||
{
|
||||
frame_audio * current = decimator_get_next_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio);
|
||||
|
||||
user_pdm_process(current);
|
||||
|
||||
/* Send out the individual mics */
|
||||
for(unsigned i=0;i<7;i++)
|
||||
user_pdm_process(current, output);
|
||||
|
||||
for(int i = 0; i < NUM_PDM_MICS; i++)
|
||||
{
|
||||
unsigned output = current->data[i][0];
|
||||
c_audio <: output;
|
||||
c_audio <: output[i];
|
||||
}
|
||||
c_audio <: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +57,13 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_
|
||||
#define DF 1
|
||||
|
||||
#define OUTPUT_SAMPLE_RATE (48000/DF)
|
||||
#define MASTER_CLOCK_FREQUENCY 24576000
|
||||
|
||||
#if MAX_FREQ != 48000
|
||||
#error NOT CURRENTLY SUPPORTED
|
||||
#endif
|
||||
#if MIN_FREQ != 48000
|
||||
#error NOT CURRENTLY SUPPORTED
|
||||
#endif
|
||||
|
||||
//TODO make these not global
|
||||
int data_0[4*COEFS_PER_PHASE*DF] = {0};
|
||||
@@ -79,11 +75,9 @@ void pcm_pdm_mic(chanend c_pcm_out)
|
||||
streaming chan c_ds_output_0, c_ds_output_1;
|
||||
streaming chan c_buffer_mic0, c_buffer_mic1;
|
||||
|
||||
configure_clock_src(mclk, p_mclk);
|
||||
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(mclk);
|
||||
start_clock(pdmclk);
|
||||
|
||||
unsafe
|
||||
@@ -98,7 +92,6 @@ void pcm_pdm_mic(chanend c_pcm_out)
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user