Loopback audio working (no feedback calc yet)

This commit is contained in:
Ed Clarke
2018-10-26 12:20:38 +01:00
parent 35042e742f
commit 6fbbbedc28
4 changed files with 20 additions and 19 deletions

View File

@@ -3,7 +3,7 @@ APP_NAME =
TARGET = RPI_HAT_60QFN.xn
# The flags passed to xcc when building the application
XCC_FLAGS = -fcomment-asm -Xmapper --map -Xmapper MAPFILE -O3 -report \
XCC_FLAGS = -fcomment-asm -Xmapper --map -Xmapper MAPFILE -Os -report \
-g -Wno-unused-function -Wno-timing -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[1]
#-DSDA_HIGH=2 -DSCL_HIGH=1 -fxscope

View File

@@ -75,7 +75,6 @@ int main()
{
on tile[0]: {
par {
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, null, i_gpio[0]);
[[distribute]]output_gpio(i_gpio, 1, p_gpio, null);
@@ -87,6 +86,7 @@ int main()
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 and then return so we do not use a thread
par{
i2c_master(i_i2c, 1, p_scl, p_sda, 100);
AudioHwConfigure(DEFAULT_FREQ, i_i2c[0]);
@@ -104,9 +104,9 @@ int main()
XUA_Endpoint0(c_ep_out[0], c_ep_in[0], c_aud_ctl, null, null, null, null);
// Buffering cores - handles audio data to/from EP's and gives/gets data to/from the audio I/O core
XUA_Buffer_lite(c_ep_out[1], c_ep_in[2], c_ep_in[1], c_sof, c_aud_ctl, p_for_mclk_count, c_audio);
XUA_Buffer_lite(c_ep_out[1], c_ep_in[1], c_ep_in[2], c_sof, c_aud_ctl, p_for_mclk_count, c_audio);
}
}//Tile[1]
}//Tile[1] par
}//Top level par
return 0;

View File

@@ -89,10 +89,8 @@ static inline void pack_samples_to_buff(int input[], const unsigned n_samples, c
}
}
//Shared memory buffers between buffer task and audio side
int asrc_to_host_sample_buffer[MAX_IN_SAMPLES_PER_SOF_PERIOD] = {0};
void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, chanend c_sof, chanend c_aud_ctl, in port p_for_mclk_count, chanend c_aud_host){
void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, chanend c_sof, chanend c_aud_ctl, in port p_for_mclk_count, chanend c_audio_hub){
debug_printf("%d\n", MAX_OUT_SAMPLES_PER_SOF_PERIOD);
@@ -100,7 +98,9 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
unsigned char buffer_aud_out[OUT_AUDIO_BUFFER_SIZE_BYTES];
unsigned char buffer_aud_in[IN_AUDIO_BUFFER_SIZE_BYTES];
unsigned char buffer_feedback[4];
#define FEEDBACK_BUFF_SIZE 4
unsigned char buffer_feedback[FEEDBACK_BUFF_SIZE];
unsigned in_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES;
@@ -122,11 +122,13 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out);
XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in, num_samples_to_send_to_host);
XUD_SetReady_InPtr(ep_feedback, (unsigned)buffer_feedback, 4);
XUD_SetReady_InPtr(ep_feedback, (unsigned)buffer_feedback, FEEDBACK_BUFF_SIZE);
// printintln(OUT_AUDIO_BUFFER_SIZE_BYTES);
// printintln(MAX_OUT_SAMPLES_PER_SOF_PERIOD);
int loopback_samples[MAX_OUT_SAMPLES_PER_SOF_PERIOD] = {0};
while(1){
XUD_Result_t result;
unsigned length = 0;
@@ -250,13 +252,10 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
num_samples_received_from_host = length / out_subslot_size;
//debug_printf("out samps: %d\n", num_samples_received_from_host);
outstanding_samples_to_host += num_samples_received_from_host;
int samples[MAX_OUT_SAMPLES_PER_SOF_PERIOD];
unpack_buff_to_samples(buffer_aud_out, num_samples_received_from_host, out_subslot_size, samples);
unpack_buff_to_samples(buffer_aud_out, num_samples_received_from_host, out_subslot_size, loopback_samples);
//Tell ASRC manager what we have just sent
//outuint(c_aud_host, num_samples_received_from_host); //We assume this will not block and other side always consumes
//num_samples_to_send_to_host = inuint(c_aud_host); //get number of return samples for sending back to host
num_samples_to_send_to_host = num_samples_received_from_host;
//Mark EP as ready for next frame from host
XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out);
@@ -264,8 +263,8 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
//Send feedback
case XUD_SetData_Select(c_feedback, ep_feedback, result):
debug_printf("ep_feedback\n");
XUD_SetReady_InPtr(ep_feedback, (unsigned)buffer_feedback, 4);
//debug_printf("ep_feedback\n");
XUD_SetReady_InPtr(ep_feedback, (unsigned)buffer_feedback, FEEDBACK_BUFF_SIZE);
break;
//Send samples to host
@@ -273,8 +272,9 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
//debug_printf("sent data\n");
//Populate the input buffer ready for the next read
pack_samples_to_buff(asrc_to_host_sample_buffer, 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;
XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in, input_buffer_size); //loopback
num_samples_to_send_to_host = 0;

View File

@@ -16,12 +16,13 @@
#define VENDOR_STR "XMOS"
#define VENDOR_ID 0x20B1
#define PRODUCT_STR_A2 "XUA Example"
#define PRODUCT_STR_A1 "XUA Example"
#define PRODUCT_STR_A2 "XUA Lite"
#define PRODUCT_STR_A1 "XUA Lite"
#define PID_AUDIO_1 1
#define PID_AUDIO_2 2
#define XUA_DFU_EN 0 /* Disable DFU (for simplicity of example */
#define UAC_FORCE_FEEDBACK_EP 1
#define XUA_LITE 1
#endif