Enable USB input path (from mics)
This commit is contained in:
@@ -96,24 +96,22 @@ int main()
|
||||
i2s_frame_master(i_i2s, p_i2s_dac, 1, p_i2s_adc, 1, p_bclk, p_lrclk, p_mclk_in, clk_audio_bclk);
|
||||
[[distribute]]AudioHub(i_i2s, c_audio, c_ds_output);
|
||||
pdm_mic(c_ds_output[0], p_pdm_mics);
|
||||
|
||||
}
|
||||
}
|
||||
on tile[1]:{
|
||||
// Connect master-clock clock-block to clock-block pin
|
||||
// Connect master-clock input clock-block to clock-block pin
|
||||
set_clock_src(clk_usb_mclk, p_mclk_in_usb); // Clock clock-block from mclk pin
|
||||
set_port_clock(p_for_mclk_count, clk_usb_mclk); // Clock the "count" port from the clock block
|
||||
start_clock(clk_usb_mclk); // Set the clock off running
|
||||
|
||||
//Setup DAC over i2c and then return so we do not use a thread
|
||||
c_audio :> int _; //Wait for reset asserted from other tile to complete
|
||||
c_audio :> int _; //Wait for reset to be asserted/deasserted by other tile
|
||||
par{
|
||||
i2c_master(i_i2c, 1, p_scl, p_sda, 100);
|
||||
AudioHwConfigure(DEFAULT_FREQ, i_i2c[0]);
|
||||
}
|
||||
c_audio <: 0; //Signal to tile[0] that clock is good
|
||||
c_audio <: 0; //Signal to tile[0] that mclk is now good
|
||||
|
||||
debug_printf("XUD SPEED: %d\n", (AUDIO_CLASS == 1) ? XUD_SPEED_FS : XUD_SPEED_HS); //FS = 1, HS = 2
|
||||
par{
|
||||
// Low level USB device layer core
|
||||
XUD_Main(c_ep_out, 2, c_ep_in, 3,
|
||||
@@ -121,7 +119,7 @@ int main()
|
||||
null, null, -1 ,
|
||||
(AUDIO_CLASS == 1) ? XUD_SPEED_FS : XUD_SPEED_HS, XUD_PWR_BUS);
|
||||
|
||||
// Buffering cores - handles audio and control data to/from EP's and gives/gets data to/from the audio I/O core
|
||||
// Buffering core - handles audio and control data to/from EP's and gives/gets data to/from the audio I/O core
|
||||
XUA_Buffer_lite(c_ep_out[0], c_ep_in[0], c_ep_out[1], c_ep_in[1], c_ep_in[2], c_sof, p_for_mclk_count, c_audio);
|
||||
}
|
||||
}//Tile[1] par
|
||||
|
||||
@@ -34,7 +34,7 @@ void AudioHub(server i2s_frame_callback_if i2s,
|
||||
|
||||
#if XUA_NUM_PDM_MICS > 0
|
||||
unsigned buffer;
|
||||
int output[XUA_NUM_PDM_MICS] = {0};
|
||||
int raw_mics[XUA_NUM_PDM_MICS] = {0};
|
||||
const unsigned decimatorCount = 1; // Supports up to 4 mics
|
||||
mic_array_decimator_conf_common_t dcc;
|
||||
int * unsafe fir_coefs[7];
|
||||
@@ -68,15 +68,15 @@ void AudioHub(server i2s_frame_callback_if i2s,
|
||||
case i2s.restart_check() -> i2s_restart_t restart:
|
||||
restart = I2S_NO_RESTART; // Keep on looping
|
||||
timer tmr; int t0, t1; tmr :> t0;
|
||||
// for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio :> samples_out[i];
|
||||
// for (int i = 0; i < NUM_USB_CHAN_IN; i++) c_audio <: samples_in[i];
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio :> samples_out[i];
|
||||
for (int i = 0; i < NUM_USB_CHAN_IN; i++) c_audio <: raw_mics[i];
|
||||
//tmr :> t1; debug_printf("%d\n", t1 - t0);
|
||||
//delay_microseconds(15); //Test backpressure tolerance
|
||||
|
||||
current = mic_array_get_next_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio_frame, dc);
|
||||
unsafe {
|
||||
samples_out[0] = current->data[0][0];
|
||||
samples_out[1] = current->data[1][0];
|
||||
raw_mics[0] = current->data[0][0];
|
||||
raw_mics[1] = current->data[1][0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ void mic_array_decimator_set_samprate(const unsigned samplerate, int fir_gain_co
|
||||
void pdm_mic(streaming chanend c_ds_output, in buffered port:32 p_pdm_mics)
|
||||
{
|
||||
streaming chan c_4x_pdm_mic_0;
|
||||
assert((MCLK_48 / 3072000) == (MCLK_441 / 2822400));
|
||||
assert((MCLK_48 / 3072000) == (MCLK_441 / 2822400)); //Make sure mic clock is achievable from MCLK
|
||||
par
|
||||
{
|
||||
mic_array_pdm_rx(p_pdm_mics, c_4x_pdm_mic_0, null);
|
||||
|
||||
@@ -195,9 +195,8 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
unsigned num_samples_received_from_host = 0;
|
||||
unsigned num_samples_to_send_to_host = 0;
|
||||
|
||||
int loopback_samples[MAX_OUT_SAMPLES_PER_SOF_PERIOD] = {0};
|
||||
int32_t samples_out[NUM_USB_CHAN_OUT] = {0};
|
||||
int32_t samples_in[NUM_USB_CHAN_IN] = {0};
|
||||
int samples_out[NUM_USB_CHAN_OUT] = {0};
|
||||
int samples_in[NUM_USB_CHAN_IN] = {0};
|
||||
|
||||
#define c_audioControl null
|
||||
#define dfuInterface null
|
||||
@@ -221,9 +220,13 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
//Unsafe to allow us to use fifo API
|
||||
unsafe{
|
||||
|
||||
//FIFOs from EP buffers to audio
|
||||
int host_to_device_fifo_storage[MAX_OUT_SAMPLES_PER_SOF_PERIOD * 2];
|
||||
int device_to_host_fifo_storage[MAX_IN_SAMPLES_PER_SOF_PERIOD * 2];
|
||||
mem_fifo_t host_to_device_fifo = {sizeof(host_to_device_fifo_storage)/sizeof(host_to_device_fifo_storage[0]), host_to_device_fifo_storage, 0, 0};
|
||||
mem_fifo_t device_to_host_fifo = {sizeof(device_to_host_fifo_storage)/sizeof(device_to_host_fifo_storage[0]), device_to_host_fifo_storage, 0, 0};
|
||||
volatile mem_fifo_t * unsafe host_to_device_fifo_ptr = &host_to_device_fifo;
|
||||
volatile mem_fifo_t * unsafe device_to_host_fifo_ptr = &device_to_host_fifo;
|
||||
|
||||
//XUD transaction variables passed in by reference
|
||||
XUD_Result_t result;
|
||||
@@ -266,7 +269,7 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
|
||||
//fifo_ret_t ret = fifo_block_push(host_to_device_fifo_ptr, loopback_samples, num_samples_received_from_host);
|
||||
fifo_ret_t ret = fifo_block_push_short_pairs(host_to_device_fifo_ptr, (short *)buffer_aud_out, num_samples_received_from_host);
|
||||
if (ret != FIFO_SUCCESS) debug_printf("h2f full\n");
|
||||
if (ret != FIFO_SUCCESS) debug_printf("h2d full\n");
|
||||
num_samples_to_send_to_host = num_samples_received_from_host;
|
||||
|
||||
//Mark EP as ready for next frame from host
|
||||
@@ -289,8 +292,11 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
case XUD_SetData_Select(c_aud_in, ep_aud_in, result):
|
||||
timer tmr; int t0, t1; tmr :> t0;
|
||||
|
||||
fifo_ret_t ret = fifo_block_pop_short_pairs(device_to_host_fifo_ptr, (short *)buffer_aud_in, num_samples_received_from_host);
|
||||
if (ret != FIFO_SUCCESS) debug_printf("d2h empty\n");
|
||||
|
||||
//Populate the input buffer ready for the next read
|
||||
pack_samples_to_buff(loopback_samples, num_samples_to_send_to_host, in_subslot_size, buffer_aud_in);
|
||||
//pack_samples_to_buff(loopback_samples, num_samples_to_send_to_host, in_subslot_size, buffer_aud_in);
|
||||
//Use the number of samples we received last time so we are always balanced (assumes same in/out count)
|
||||
|
||||
unsigned input_buffer_size = num_samples_to_send_to_host * in_subslot_size;
|
||||
@@ -307,11 +313,11 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
for (int i = 1; i < NUM_USB_CHAN_IN; i++){
|
||||
c_audio_hub :> samples_in[i];
|
||||
}
|
||||
int out_samps[NUM_USB_CHAN_OUT];
|
||||
fifo_ret_t ret = fifo_block_pop(host_to_device_fifo_ptr, out_samps, NUM_USB_CHAN_OUT);
|
||||
fifo_ret_t ret = fifo_block_pop(host_to_device_fifo_ptr, samples_out, NUM_USB_CHAN_OUT);
|
||||
//if (ret != FIFO_SUCCESS) debug_printf("empty\n");
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: out_samps[i];
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: samples_out[i];
|
||||
tmr :> t1; debug_printf("a%d\n", t1 - t0);
|
||||
ret = fifo_block_push(device_to_host_fifo_ptr, samples_in, NUM_USB_CHAN_IN);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user