Optimisations to xud select cases
This commit is contained in:
@@ -43,6 +43,24 @@ static inline fifo_ret_t fifo_block_push(volatile mem_fifo_t * unsafe fifo, int
|
||||
}
|
||||
}
|
||||
|
||||
#pragma unsafe arrays
|
||||
static inline fifo_ret_t fifo_block_push_short_pairs(volatile mem_fifo_t * unsafe fifo, short data[], unsigned n) {
|
||||
unsafe{
|
||||
//check there is a block of space large enough
|
||||
unsigned space_remaining = fifo->size - fifo_get_fill(fifo) - 1;
|
||||
if (n > space_remaining) {
|
||||
return FIFO_FULL;
|
||||
}
|
||||
for (int i = 0; i < n; i++){
|
||||
unsigned next_idx = fifo->write_idx + 1;
|
||||
if (next_idx == fifo->size) next_idx = 0; //Check for wrap
|
||||
fifo->data_base_ptr[fifo->write_idx] = data[i] << 16;
|
||||
fifo->write_idx = next_idx;
|
||||
}
|
||||
return FIFO_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma unsafe arrays
|
||||
static inline fifo_ret_t fifo_block_pop(volatile mem_fifo_t * unsafe fifo, int data[], unsigned n) {
|
||||
unsafe{
|
||||
@@ -59,6 +77,21 @@ static inline fifo_ret_t fifo_block_pop(volatile mem_fifo_t * unsafe fifo, int d
|
||||
}
|
||||
}
|
||||
|
||||
#pragma unsafe arrays
|
||||
static inline fifo_ret_t fifo_block_pop_short_pairs(volatile mem_fifo_t * unsafe fifo, short data[], unsigned n) {
|
||||
unsafe{
|
||||
//Check we have a block big enough to send
|
||||
if (n > fifo_get_fill(fifo)){
|
||||
return FIFO_EMPTY;
|
||||
}
|
||||
for (int i = 0; i < n; i++){
|
||||
data[i] = fifo->data_base_ptr[fifo->read_idx] >> 16;
|
||||
fifo->read_idx++;
|
||||
if (fifo->read_idx == fifo->size) fifo->read_idx = 0; //Check for wrap
|
||||
}
|
||||
return FIFO_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//Version of above that returns fill level relative to half full
|
||||
static inline int fifo_get_fill_relative_half(volatile mem_fifo_t * unsafe fifo){
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#define IN_AUDIO_BUFFER_SIZE_BYTES (MAX_IN_SAMPLES_PER_SOF_PERIOD * MAX_INPUT_SLOT_SIZE)
|
||||
|
||||
//Helper to disassemble USB packets into 32b left aligned audio samples
|
||||
#pragma unsafe arrays
|
||||
static inline void unpack_buff_to_samples(unsigned char input[], const unsigned n_samples, const unsigned slot_size, int output[]){
|
||||
switch(slot_size){
|
||||
case 4:
|
||||
@@ -57,6 +58,7 @@ static inline void unpack_buff_to_samples(unsigned char input[], const unsigned
|
||||
}
|
||||
|
||||
//Helper to assemble USB packets from 32b left aligned audio samples
|
||||
#pragma unsafe arrays
|
||||
static inline void pack_samples_to_buff(int input[], const unsigned n_samples, const unsigned slot_size, unsigned char output[]){
|
||||
switch(slot_size){
|
||||
case 4:
|
||||
@@ -213,7 +215,7 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
XUD_SetReady_Out(ep0_out, sbuffer);
|
||||
|
||||
//Send initial samples so audiohub is not blocked
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT * 5; i++) outuint(c_audio_hub, 0);
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT * 6; i++) c_audio_hub <: 0;
|
||||
|
||||
|
||||
//Unsafe to allow us to use fifo API
|
||||
@@ -260,9 +262,10 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
num_samples_received_from_host = length / out_subslot_size;
|
||||
//debug_printf("out samps: %d\n", num_samples_received_from_host);
|
||||
|
||||
unpack_buff_to_samples(buffer_aud_out, num_samples_received_from_host, out_subslot_size, loopback_samples);
|
||||
//unpack_buff_to_samples(buffer_aud_out, num_samples_received_from_host, out_subslot_size, loopback_samples);
|
||||
|
||||
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(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");
|
||||
num_samples_to_send_to_host = num_samples_received_from_host;
|
||||
|
||||
@@ -298,16 +301,18 @@ void XUA_Buffer_lite(chanend c_ep0_out, chanend c_ep0_in, chanend c_aud_out, cha
|
||||
break;
|
||||
|
||||
//Exchange samples with audiohub. Note we are using channel buffering here to act as a FIFO
|
||||
case inuint_byref(c_audio_hub, u_tmp):
|
||||
samples_in[0] = (int)u_tmp;
|
||||
case c_audio_hub :> samples_in[0]:
|
||||
timer tmr; int t0, t1; tmr :> t0;
|
||||
|
||||
for (int i = 1; i < NUM_USB_CHAN_IN; i++){
|
||||
u_tmp = inuint(c_audio_hub);
|
||||
samples_in[i] = (int)u_tmp;
|
||||
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);
|
||||
//if (ret != FIFO_SUCCESS) debug_printf("empty\n");
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) outuint(c_audio_hub, (unsigned) out_samps[i]);
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: out_samps[i];
|
||||
tmr :> t1; debug_printf("a%d\n", t1 - t0);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user