forked from PAWPAW-Mirror/lib_xua
PDM function rename and PDM buffer tidy
This commit is contained in:
@@ -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();
|
||||||
@@ -49,14 +50,11 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
|
|||||||
const int * unsafe fir_coefs[7];
|
const int * unsafe fir_coefs[7];
|
||||||
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;
|
||||||
@@ -104,65 +102,70 @@ void pdm_process(streaming chanend c_ds_output[2], chanend c_audio
|
|||||||
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, 2, buffer, mic_audio, dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run user code */
|
/* 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
|
||||||
user_pdm_process(current, output);
|
user_pdm_process(current, output);
|
||||||
#endif
|
#endif
|
||||||
int req;
|
int req;
|
||||||
while(1)
|
while(1)
|
||||||
|
{
|
||||||
|
select
|
||||||
{
|
{
|
||||||
select
|
case c_audio :> req:
|
||||||
{
|
|
||||||
case c_audio :> req:
|
|
||||||
|
|
||||||
if(req)
|
/* Audio IO core requests samples */
|
||||||
unsafe{
|
if(req)
|
||||||
for(int i = 0; i < NUM_PDM_MICS; i++)
|
unsafe{
|
||||||
{
|
for(int i = 0; i < NUM_PDM_MICS; i++)
|
||||||
c_audio <: output[i];
|
{
|
||||||
}
|
c_audio <: output[i];
|
||||||
|
|
||||||
|
|
||||||
mic_array_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef MIC_PROCESSING_USE_INTERFACE
|
|
||||||
i_mic_process.transfer_buffers(current, output);
|
|
||||||
#else
|
|
||||||
user_pdm_process(current, output);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
unsafe{
|
|
||||||
/* Sample rate change */
|
|
||||||
c_audio :> samplerate;
|
|
||||||
decimationfactor = 96000/samplerate;
|
|
||||||
dcc.output_decimation_factor = decimationfactor;
|
|
||||||
dcc.coefs=fir_coefs[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_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc);
|
/* 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);
|
||||||
|
|
||||||
|
/* 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
|
||||||
user_pdm_process(current, output);
|
user_pdm_process(current, output);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
else
|
||||||
}
|
unsafe{
|
||||||
}
|
/* Sample rate change */
|
||||||
|
c_audio :> samplerate;
|
||||||
|
|
||||||
|
/* Re-config the mic decimators for the new sample-rate */
|
||||||
|
decimationfactor = 96000/samplerate;
|
||||||
|
dcc.output_decimation_factor = decimationfactor;
|
||||||
|
dcc.coefs=fir_coefs[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);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
/* Run user code */
|
||||||
|
#ifdef MIC_PROCESSING_USE_INTERFACE
|
||||||
|
i_mic_process.transfer_buffers(current, output);
|
||||||
|
#else
|
||||||
|
user_pdm_process(current, output);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user