PDM function rename and PDM buffer tidy

This commit is contained in:
Ross Owen
2016-04-21 18:23:18 +01:00
parent 8e1b71f70c
commit f3819eeee3
2 changed files with 58 additions and 65 deletions

View File

@@ -14,7 +14,7 @@
#include <stdint.h> #include <stdint.h>
#include "mic_array.h" #include "mic_array.h"
#include "pcm_pdm_mic.h" #include "xua_pdm_mic.h"
#define MAX_DECIMATION_FACTOR 12 #define MAX_DECIMATION_FACTOR 12
@@ -30,14 +30,15 @@ int data_1[4*THIRD_STAGE_COEFS_PER_STAGE * MAX_DECIMATION_FACTOR] = {0};
mic_array_frame_time_domain mic_audio[2]; mic_array_frame_time_domain mic_audio[2];
[[combinable]] [[combinable]]
void pdm_process(streaming chanend c_ds_output[2], chanend c_audio void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
, client mic_process_if i_mic_process , client mic_process_if i_mic_process
#endif #endif
) )
{ {
unsigned buffer = 1; // Buffer index unsigned buffer;
int output[NUM_PDM_MICS]; int output[NUM_PDM_MICS];
unsigned samplerate;
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
i_mic_process.init(); i_mic_process.init();
@@ -50,13 +51,10 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
mic_array_frame_time_domain * unsafe current; mic_array_frame_time_domain * unsafe current;
mic_array_decimator_config_t dc[2]; mic_array_decimator_config_t dc[2];
unsigned samplerate; /* Get initial sample-rate and compute decimation factor */
c_audio :> samplerate; c_audio :> samplerate;
unsigned decimationfactor = 96000/samplerate; unsigned decimationfactor = 96000/samplerate;
unsafe unsafe
{ {
fir_coefs[0] = 0; fir_coefs[0] = 0;
@@ -117,6 +115,7 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
{ {
case c_audio :> req: case c_audio :> req:
/* Audio IO core requests samples */
if(req) if(req)
unsafe{ unsafe{
for(int i = 0; i < NUM_PDM_MICS; i++) for(int i = 0; i < NUM_PDM_MICS; i++)
@@ -124,10 +123,10 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
c_audio <: output[i]; c_audio <: output[i];
} }
/* 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, 2, buffer, mic_audio, dc);
/* Run user code */
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
i_mic_process.transfer_buffers(current, output); i_mic_process.transfer_buffers(current, output);
#else #else
@@ -138,15 +137,19 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
unsafe{ unsafe{
/* Sample rate change */ /* Sample rate change */
c_audio :> samplerate; c_audio :> samplerate;
/* Re-config the mic decimators for the new sample-rate */
decimationfactor = 96000/samplerate; decimationfactor = 96000/samplerate;
dcc.output_decimation_factor = decimationfactor; dcc.output_decimation_factor = decimationfactor;
dcc.coefs=fir_coefs[decimationfactor/2]; dcc.coefs=fir_coefs[decimationfactor/2];
mic_array_decimator_configure(c_ds_output, 2, dc);
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_init_time_domain_frame(c_ds_output, 2, 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, 2, buffer, mic_audio, dc);
/* Run user code */
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
i_mic_process.transfer_buffers(current, output); i_mic_process.transfer_buffers(current, output);
#else #else
@@ -154,15 +157,15 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
#endif #endif
} }
break; break;
} } /* select */
} } /* while(1) */
} }
#if MAX_FREQ > 48000 #if MAX_FREQ > 48000
#error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED #error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED
#endif #endif
void pcm_pdm_mic(streaming chanend c_ds_output[2]) 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, c_4x_pdm_mic_1;
@@ -172,20 +175,12 @@ void pcm_pdm_mic(streaming chanend c_ds_output[2])
configure_in_port(p_pdm_mics, pdmclk); configure_in_port(p_pdm_mics, pdmclk);
start_clock(pdmclk); start_clock(pdmclk);
unsafe
{
par par
{ {
mic_array_pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1); 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]); mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic_0, c_ds_output[0]);
mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic_1, c_ds_output[1]); mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic_1, c_ds_output[1]);
//#ifdef MIC_PROCESSING_USE_INTERFACE }
// pdm_process(c_ds_output, c_pcm_out, i_mic_process);
/// /* Note: user_pdm process is included in main.xc to allow maximum flexibilty for customisation/distribution etc */
//#else
// pdm_process(c_ds_output, c_pcm_out);
//#endif
}}
} }
#endif #endif

View File

@@ -5,16 +5,13 @@
/* Interface based user processing */ /* Interface based user processing */
typedef interface mic_process_if typedef interface mic_process_if
{ {
//[[guarded]]
//void transfer_buffers(int * unsafe in_mic_buf, int * unsafe in_spk_buf, int * unsafe out_mic_buf, int * unsafe out_spk_buf);
void transfer_buffers(mic_array_frame_time_domain * unsafe audio, int output[]); void transfer_buffers(mic_array_frame_time_domain * unsafe audio, int output[]);
void init(); void init();
} mic_process_if; } mic_process_if;
[[combinable]] [[combinable]]
void pdm_process(streaming chanend c_ds_output[2], chanend c_audio void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio
#ifdef MIC_PROCESSING_USE_INTERFACE #ifdef MIC_PROCESSING_USE_INTERFACE
, client mic_process_if i_mic_process , client mic_process_if i_mic_process
#endif #endif
@@ -23,8 +20,8 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
[[combinable]] [[combinable]]
void user_pdm_process(server mic_process_if i_mic_data); void user_pdm_process(server mic_process_if i_mic_data);
/* PDM interface and decimation cores */
void pcm_pdm_mic(streaming chanend c_ds_output[2]); void pdm_mic(streaming chanend c_ds_output[2]);
#else #else
@@ -33,7 +30,8 @@ unsafe void user_pdm_process(mic_array_frame_time_domain * unsafe audio, int out
void user_pdm_init(); void user_pdm_init();
void pcm_pdm_mic(streaming chanend c_ds_output[2]); /* PDM interface and decimation cores */
void pdm_mic(streaming chanend c_ds_output[2]);
#endif #endif