forked from PAWPAW-Mirror/lib_xua
PDM/Mic code can now handle rate changes.
This commit is contained in:
@@ -698,7 +698,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (NUM_PDM_MICS > 0)
|
#if (NUM_PDM_MICS > 0)
|
||||||
/* Get samples from PDM->PCM comverter */
|
/* Get samples from PDM->PCM comverter */
|
||||||
|
c_pdm_pcm <: 1;
|
||||||
#pragma loop unroll
|
#pragma loop unroll
|
||||||
for(int i = 0; i < NUM_PDM_MICS; i++)
|
for(int i = 0; i < NUM_PDM_MICS; i++)
|
||||||
{
|
{
|
||||||
@@ -1180,6 +1181,10 @@ chanend ?c_config, chanend ?c
|
|||||||
outuint(c_spdif_out, mClk);
|
outuint(c_spdif_out, mClk);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if NUM_PDM_MICS > 0
|
||||||
|
/* Send decimation factor to PDM task(s) */
|
||||||
|
c_pdm_in <: curSamFreq;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ADAT_TX
|
#ifdef ADAT_TX
|
||||||
// Configure ADAT parameters ...
|
// Configure ADAT parameters ...
|
||||||
@@ -1256,9 +1261,14 @@ chanend ?c_config, chanend ?c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef SPDIF_TX
|
#ifdef SPDIF_TX
|
||||||
/* Notify S/PDIF thread of impending new freq... */
|
/* Notify S/PDIF task of impending new freq... */
|
||||||
outct(c_spdif_out, XS1_CT_END);
|
outct(c_spdif_out, XS1_CT_END);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if NUM_PDM_MICS > 0
|
||||||
|
c_pdm_in <: 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ADAT_TX
|
#ifdef ADAT_TX
|
||||||
#ifdef ADAT_TX_USE_SHARED_BUFF
|
#ifdef ADAT_TX_USE_SHARED_BUFF
|
||||||
/* Take out-standing handshake from ADAT core */
|
/* Take out-standing handshake from ADAT core */
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <xs1.h>
|
#include <xs1.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <print.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <xclib.h>
|
#include <xclib.h>
|
||||||
@@ -17,8 +16,6 @@
|
|||||||
#include "fir_decimator.h"
|
#include "fir_decimator.h"
|
||||||
#include "mic_array.h"
|
#include "mic_array.h"
|
||||||
|
|
||||||
#define DF 1
|
|
||||||
|
|
||||||
/* Hardware resources */
|
/* Hardware resources */
|
||||||
in port p_pdm_clk = PORT_PDM_CLK;
|
in port p_pdm_clk = PORT_PDM_CLK;
|
||||||
in buffered port:32 p_pdm_mics = PORT_PDM_DATA;
|
in buffered port:32 p_pdm_mics = PORT_PDM_DATA;
|
||||||
@@ -29,8 +26,8 @@ clock pdmclk = on tile[PDM_TILE]: XS1_CLKBLK_3;
|
|||||||
unsafe void user_pdm_process(frame_audio * unsafe audio, int output[]);
|
unsafe void user_pdm_process(frame_audio * unsafe audio, int output[]);
|
||||||
void user_pdm_init();
|
void user_pdm_init();
|
||||||
|
|
||||||
int data_0[4*COEFS_PER_PHASE*DF] = {0};
|
int data_0[4*COEFS_PER_PHASE*MAX_DECIMATION_FACTOR] = {0};
|
||||||
int data_1[4*COEFS_PER_PHASE*DF] = {0};
|
int data_1[4*COEFS_PER_PHASE*MAX_DECIMATION_FACTOR] = {0};
|
||||||
|
|
||||||
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_0, streaming chanend c_ds_output_1, chanend c_audio)
|
||||||
{
|
{
|
||||||
@@ -40,38 +37,53 @@ void pdm_process(streaming chanend c_ds_output_0, streaming chanend c_ds_output_
|
|||||||
int output[NUM_PDM_MICS];
|
int output[NUM_PDM_MICS];
|
||||||
|
|
||||||
user_pdm_init();
|
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)
|
while(1)
|
||||||
{
|
{
|
||||||
frame_audio * unsafe current = decimator_get_next_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio);
|
unsigned samplerate;
|
||||||
|
|
||||||
|
c_audio :> samplerate;
|
||||||
|
|
||||||
|
unsigned decimationfactor = 48000/samplerate;
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
user_pdm_process(current, output);
|
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}};
|
||||||
for(int i = 0; i < NUM_PDM_MICS; i++)
|
decimator_config dc1 = {&dcc, data_1, {0, 0, 0, 0}};
|
||||||
{
|
decimator_configure(c_ds_output_0, c_ds_output_1, dc0, dc1);
|
||||||
c_audio <: output[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decimator_init_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio);
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
frame_audio * unsafe current = decimator_get_next_audio_frame(c_ds_output_0, c_ds_output_1, buffer, audio);
|
||||||
|
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
int req;
|
||||||
|
user_pdm_process(current, output);
|
||||||
|
|
||||||
|
c_audio :> req;
|
||||||
|
|
||||||
|
if(req)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < NUM_PDM_MICS; i++)
|
||||||
|
{
|
||||||
|
c_audio <: output[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MAX_FREQ != 48000
|
#if MAX_FREQ > 48000
|
||||||
#error NOT CURRENTLY SUPPORTED
|
|
||||||
#endif
|
|
||||||
#if MIN_FREQ != 48000
|
|
||||||
#error NOT CURRENTLY SUPPORTED
|
#error NOT CURRENTLY SUPPORTED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -80,13 +92,13 @@ 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;
|
streaming chan c_multi_channel_pdm, c_sync, 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_0, c_ds_output_1;
|
||||||
streaming chan c_buffer_mic0, c_buffer_mic1;
|
streaming chan c_buffer_mic0, c_buffer_mic1;
|
||||||
|
|
||||||
|
/* TODO, always run mics at 3MHz */
|
||||||
configure_clock_src_divide(pdmclk, p_mclk, 2);
|
configure_clock_src_divide(pdmclk, p_mclk, 2);
|
||||||
configure_port_clock_output(p_pdm_clk, pdmclk);
|
configure_port_clock_output(p_pdm_clk, pdmclk);
|
||||||
configure_in_port(p_pdm_mics, pdmclk);
|
configure_in_port(p_pdm_mics, pdmclk);
|
||||||
start_clock(pdmclk);
|
start_clock(pdmclk);
|
||||||
|
|
||||||
|
|
||||||
par
|
par
|
||||||
{
|
{
|
||||||
pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1);
|
pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, c_4x_pdm_mic_1);
|
||||||
|
|||||||
Reference in New Issue
Block a user