From c67f5e454de2d44f7494fea86d661327f3a9b044 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 2 Aug 2016 16:19:38 -0400 Subject: [PATCH 01/59] BCD_DEVICE version bump --- module_usb_audio/audio_io/audio_io.xc | 4 +- module_usb_audio/devicedefines.h | 3 +- module_usb_audio/endpoint0/audiorequests.xc | 7 ++-- module_usb_audio/endpoint0/descriptors.h | 4 +- module_usb_audio/ports/audioports.xc | 43 ++++++++++++++++++++- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index a804857b..1e7c2f28 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -394,7 +394,7 @@ static inline void InitPorts(unsigned divide) p_lrclk when pinseq(0) :> void @ tmp; #endif - tmp += (I2S_CHANS_PER_FRAME * 32) - 32 + 1 ; + tmp += (I2S_CHANS_PER_FRAME * 32) - 32 + 1 + (I2S_CHANS_PER_FRAME *32) - 2; /* E.g. 2 * 32 - 32 + 1 = 33 for stereo */ /* E.g. 8 * 32 - 32 + 1 = 225 for 8 chan TDM */ @@ -410,7 +410,7 @@ static inline void InitPorts(unsigned divide) #pragma loop unroll for(int i = 0; i < I2S_WIRES_ADC; i++) { - asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1)); + asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp)); } #endif #endif diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 981146bf..a39af3c9 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -475,7 +475,7 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_M -#define BCD_DEVICE_M 18 +#define BCD_DEVICE_M 19 #endif /** @@ -1146,6 +1146,7 @@ enum USBEndpointNumber_In enum USBEndpointNumber_Out { ENDPOINT_NUMBER_OUT_CONTROL, /* Endpoint 0 */ + XXXX, ENDPOINT_NUMBER_OUT_AUDIO, #ifdef MIDI ENDPOINT_NUMBER_OUT_MIDI, diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 591d36fb..483acef4 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -886,8 +886,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } /* Just keep doubling for standard freqs >= 44.1/48kHz */ - currentFreq44 = 44100; - currentFreq48 = 48000; + currentFreq44 = MIN_FREQ_44; + currentFreq48 = MIN_FREQ_48; while(1) { if((currentFreq44 <= maxFreq) && (currentFreq44 >= MIN_FREQ)) @@ -897,7 +897,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c currentFreq44*=2; } - if((currentFreq48 <= maxFreq)) + if((currentFreq48 <= maxFreq) && (currentFreq48 >= MIN_FREQ)) + { /* Note i passed byref here */ storeFreq(buffer, i, currentFreq48); diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index aa2d1037..eb95dd80 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -562,7 +562,7 @@ unsigned char hidReportDescriptor[] = #error #endif -#define FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES) +#define FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES)*2 #define FS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES) #define FS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES) @@ -2268,7 +2268,7 @@ const unsigned num_freqs_a1 = MAX(3, (0 #define CHARIFY_SR(x) (x & 0xff),((x & 0xff00)>> 8),((x & 0xff0000)>> 16) #if (MIN_FREQ_FS < 12000) && (MAX_FREQ_FS > 48000) -#error SAMPLE RATE RANGE TO GREAT FOR UAC1 ON WINDOWS +#error SAMPLE RATE RANGE TOO GREAT FOR UAC1 ON WINDOWS #endif unsigned char cfgDesc_Audio1[] = diff --git a/module_usb_audio/ports/audioports.xc b/module_usb_audio/ports/audioports.xc index 3786ae8b..a635226e 100644 --- a/module_usb_audio/ports/audioports.xc +++ b/module_usb_audio/ports/audioports.xc @@ -59,6 +59,13 @@ unsigned int divide, unsigned curSamFreq) /* Clock bitclock clock block from master clock pin (divided) */ configure_clock_src_divide(clk_audio_bclk, p_mclk_in, (divide/2)); configure_port_clock_output(p_bclk, clk_audio_bclk); + + if(divide == 1) + { + + } + + #else /* For a divide of one (i.e. bitclock == master-clock) BClk is set to clock_output mode. * In this mode it outputs an edge clock on every tick of itsassociated clock_block. @@ -83,7 +90,39 @@ unsigned int divide, unsigned curSamFreq) } #endif + stop_clock(clk_audio_mclk); + set_clock_fall_delay(clk_audio_mclk, 0); + start_clock(clk_audio_mclk); +if(divide == 1) +{ + + stop_clock(clk_audio_mclk); + set_clock_fall_delay(clk_audio_mclk, 10); if(!isnull(p_lrclk)) + { + /* Clock LR clock from bit clock-block */ + configure_out_port_no_ready(p_lrclk, clk_audio_mclk, 0); + } + +#if (I2S_CHANS_DAC != 0) + /* Clock I2S output data ports from clock block */ + for(int i = 0; i < numPortsDac; i++) + { + configure_out_port_no_ready(p_i2s_dac[i], clk_audio_mclk, 0); + } +#endif + +#if (I2S_CHANS_ADC != 0) + /* Clock I2S input data ports from clock block */ + for(int i = 0; i < numPortsAdc; i++) + { + configure_in_port_no_ready(p_i2s_adc[i], clk_audio_mclk); + } +#endif + start_clock(clk_audio_mclk); +} +else +{if(!isnull(p_lrclk)) { /* Clock LR clock from bit clock-block */ configure_out_port_no_ready(p_lrclk, clk_audio_bclk, 0); @@ -104,6 +143,8 @@ unsigned int divide, unsigned curSamFreq) configure_in_port_no_ready(p_i2s_adc[i], clk_audio_bclk); } #endif +} + /* Start clock blocks ticking */ start_clock(clk_audio_bclk); @@ -126,7 +167,7 @@ unsigned int divide, unsigned curSamFreq) bClkDelay_fall = 18; } - set_clock_fall_delay(clk_audio_bclk, bClkDelay_fall); + //set_clock_fall_delay(clk_audio_bclk, bClkDelay_fall); #if (I2S_CHANS_DAC != 0) /* Clock I2S output data ports from b-clock clock block */ From c49133723ecd8ed921c196b90133bf2ee0305b6d Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 2 Aug 2016 18:08:35 -0400 Subject: [PATCH 02/59] Revert "BCD_DEVICE version bump" This reverts commit c67f5e454de2d44f7494fea86d661327f3a9b044. --- module_usb_audio/audio_io/audio_io.xc | 4 +- module_usb_audio/devicedefines.h | 3 +- module_usb_audio/endpoint0/audiorequests.xc | 7 ++-- module_usb_audio/endpoint0/descriptors.h | 4 +- module_usb_audio/ports/audioports.xc | 43 +-------------------- 5 files changed, 9 insertions(+), 52 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 1e7c2f28..a804857b 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -394,7 +394,7 @@ static inline void InitPorts(unsigned divide) p_lrclk when pinseq(0) :> void @ tmp; #endif - tmp += (I2S_CHANS_PER_FRAME * 32) - 32 + 1 + (I2S_CHANS_PER_FRAME *32) - 2; + tmp += (I2S_CHANS_PER_FRAME * 32) - 32 + 1 ; /* E.g. 2 * 32 - 32 + 1 = 33 for stereo */ /* E.g. 8 * 32 - 32 + 1 = 225 for 8 chan TDM */ @@ -410,7 +410,7 @@ static inline void InitPorts(unsigned divide) #pragma loop unroll for(int i = 0; i < I2S_WIRES_ADC; i++) { - asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp)); + asm("setpt res[%0], %1"::"r"(p_i2s_adc[i]),"r"(tmp-1)); } #endif #endif diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index a39af3c9..981146bf 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -475,7 +475,7 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_M -#define BCD_DEVICE_M 19 +#define BCD_DEVICE_M 18 #endif /** @@ -1146,7 +1146,6 @@ enum USBEndpointNumber_In enum USBEndpointNumber_Out { ENDPOINT_NUMBER_OUT_CONTROL, /* Endpoint 0 */ - XXXX, ENDPOINT_NUMBER_OUT_AUDIO, #ifdef MIDI ENDPOINT_NUMBER_OUT_MIDI, diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 483acef4..591d36fb 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -886,8 +886,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } /* Just keep doubling for standard freqs >= 44.1/48kHz */ - currentFreq44 = MIN_FREQ_44; - currentFreq48 = MIN_FREQ_48; + currentFreq44 = 44100; + currentFreq48 = 48000; while(1) { if((currentFreq44 <= maxFreq) && (currentFreq44 >= MIN_FREQ)) @@ -897,8 +897,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c currentFreq44*=2; } - if((currentFreq48 <= maxFreq) && (currentFreq48 >= MIN_FREQ)) - + if((currentFreq48 <= maxFreq)) { /* Note i passed byref here */ storeFreq(buffer, i, currentFreq48); diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index eb95dd80..aa2d1037 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -562,7 +562,7 @@ unsigned char hidReportDescriptor[] = #error #endif -#define FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES)*2 +#define FS_STREAM_FORMAT_OUTPUT_1_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES) #define FS_STREAM_FORMAT_OUTPUT_2_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES) #define FS_STREAM_FORMAT_OUTPUT_3_MAXPACKETSIZE (MAX_PACKET_SIZE_MULT_OUT_FS * FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES) @@ -2268,7 +2268,7 @@ const unsigned num_freqs_a1 = MAX(3, (0 #define CHARIFY_SR(x) (x & 0xff),((x & 0xff00)>> 8),((x & 0xff0000)>> 16) #if (MIN_FREQ_FS < 12000) && (MAX_FREQ_FS > 48000) -#error SAMPLE RATE RANGE TOO GREAT FOR UAC1 ON WINDOWS +#error SAMPLE RATE RANGE TO GREAT FOR UAC1 ON WINDOWS #endif unsigned char cfgDesc_Audio1[] = diff --git a/module_usb_audio/ports/audioports.xc b/module_usb_audio/ports/audioports.xc index a635226e..3786ae8b 100644 --- a/module_usb_audio/ports/audioports.xc +++ b/module_usb_audio/ports/audioports.xc @@ -59,13 +59,6 @@ unsigned int divide, unsigned curSamFreq) /* Clock bitclock clock block from master clock pin (divided) */ configure_clock_src_divide(clk_audio_bclk, p_mclk_in, (divide/2)); configure_port_clock_output(p_bclk, clk_audio_bclk); - - if(divide == 1) - { - - } - - #else /* For a divide of one (i.e. bitclock == master-clock) BClk is set to clock_output mode. * In this mode it outputs an edge clock on every tick of itsassociated clock_block. @@ -90,39 +83,7 @@ unsigned int divide, unsigned curSamFreq) } #endif - stop_clock(clk_audio_mclk); - set_clock_fall_delay(clk_audio_mclk, 0); - start_clock(clk_audio_mclk); -if(divide == 1) -{ - - stop_clock(clk_audio_mclk); - set_clock_fall_delay(clk_audio_mclk, 10); if(!isnull(p_lrclk)) - { - /* Clock LR clock from bit clock-block */ - configure_out_port_no_ready(p_lrclk, clk_audio_mclk, 0); - } - -#if (I2S_CHANS_DAC != 0) - /* Clock I2S output data ports from clock block */ - for(int i = 0; i < numPortsDac; i++) - { - configure_out_port_no_ready(p_i2s_dac[i], clk_audio_mclk, 0); - } -#endif - -#if (I2S_CHANS_ADC != 0) - /* Clock I2S input data ports from clock block */ - for(int i = 0; i < numPortsAdc; i++) - { - configure_in_port_no_ready(p_i2s_adc[i], clk_audio_mclk); - } -#endif - start_clock(clk_audio_mclk); -} -else -{if(!isnull(p_lrclk)) { /* Clock LR clock from bit clock-block */ configure_out_port_no_ready(p_lrclk, clk_audio_bclk, 0); @@ -143,8 +104,6 @@ else configure_in_port_no_ready(p_i2s_adc[i], clk_audio_bclk); } #endif -} - /* Start clock blocks ticking */ start_clock(clk_audio_bclk); @@ -167,7 +126,7 @@ else bClkDelay_fall = 18; } - //set_clock_fall_delay(clk_audio_bclk, bClkDelay_fall); + set_clock_fall_delay(clk_audio_bclk, bClkDelay_fall); #if (I2S_CHANS_DAC != 0) /* Clock I2S output data ports from b-clock clock block */ From cd588b507bcf9ce5c86b3e8cff6928d2168ab386 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 2 Aug 2016 18:09:38 -0400 Subject: [PATCH 03/59] BCD_DEVICE version bump (corrected without additional changes) --- module_usb_audio/devicedefines.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 981146bf..b1269782 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -475,14 +475,14 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_M -#define BCD_DEVICE_M 18 +#define BCD_DEVICE_M 19 #endif /** * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_N -#define BCD_DEVICE_N 1 +#define BCD_DEVICE_N 0 #endif /** From 5a92aaecb054e7bb9064fbb2233d9859301bb52a Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 2 Aug 2016 18:14:21 -0400 Subject: [PATCH 04/59] Error typo --- module_usb_audio/endpoint0/descriptors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index aa2d1037..ea699628 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -2268,7 +2268,7 @@ const unsigned num_freqs_a1 = MAX(3, (0 #define CHARIFY_SR(x) (x & 0xff),((x & 0xff00)>> 8),((x & 0xff0000)>> 16) #if (MIN_FREQ_FS < 12000) && (MAX_FREQ_FS > 48000) -#error SAMPLE RATE RANGE TO GREAT FOR UAC1 ON WINDOWS +#error SAMPLE RATE RANGE TOO GREAT FOR UAC1 ON WINDOWS #endif unsigned char cfgDesc_Audio1[] = From c3cae7fe525f1470ffae49e1f0955324924a1947 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 3 Aug 2016 10:41:17 -0400 Subject: [PATCH 05/59] Added 6.19 to changelog --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b56f8eb0..fc04543d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ sc_usb_audio Change Log ======================= +6.19.0 +------ + - CHANGE: BCD_DEVICE version increment only + 6.18.1 ------ - ADDED: Vendor Specific control interface added to UAC1 descriptors to allow control of From e7c954ba63f496c41cbbd90bfcb7b9c3f14ee79c Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 3 Aug 2016 10:41:39 -0400 Subject: [PATCH 06/59] 'Release: 6.19.0alpha0' --- README.rst | 2 +- xpd.xml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 3e501ac5..6d13ed99 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ USB Audio Shared ................ -:Latest release: 6.18.1alpha0 +:Latest release: 6.19.0alpha0 :Maintainer: xross :Description: USB Audio Shared Components. For use in the XMOS USB Audio Refererence Designs. diff --git a/xpd.xml b/xpd.xml index 266f4360..2a6788db 100644 --- a/xpd.xml +++ b/xpd.xml @@ -15,7 +15,7 @@ - module_queue + module_queue MIDI @@ -104,7 +104,8 @@ - + + XM-004720-SM XMOS From ae3b5437690f20b8caa93967247507c9dbf45c9f Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 10 Aug 2016 15:01:21 +0100 Subject: [PATCH 07/59] IN_VOLUME_MIXER enabled by default (was commented out) --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index b1269782..09bcee37 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -1067,7 +1067,7 @@ #else #if defined(MIXER) /* Enabled by default */ -//#define IN_VOLUME_IN_MIXER +#define IN_VOLUME_IN_MIXER #endif #endif From 4edc96942736b2d99980c946f015b59503ece4d4 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 11 Aug 2016 12:50:22 +0100 Subject: [PATCH 08/59] Added EXCLUDE_USB_AUDIO_MAIN (used by i2s_loopbacktest) --- module_usb_audio/main.xc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index ba5c232c..7def523d 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -485,6 +485,8 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc, #define USER_MAIN_CORES #endif +#ifndef EXCLUDE_USB_AUDIO_MAIN + /* Main for USB Audio Applications */ int main() { @@ -682,3 +684,4 @@ int main() return 0; } +#endif From e7a08e9e0c07114bea3b8b5fcdd0e74b7393f32a Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 11 Aug 2016 12:58:32 +0100 Subject: [PATCH 09/59] Fixed issues in xud_audio breaking i2s_loopback test --- module_usb_audio/audio_io/xua_audio.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/module_usb_audio/audio_io/xua_audio.h b/module_usb_audio/audio_io/xua_audio.h index 473dfe9a..1a98601a 100644 --- a/module_usb_audio/audio_io/xua_audio.h +++ b/module_usb_audio/audio_io/xua_audio.h @@ -1,10 +1,8 @@ #ifndef __audio_h__ #define __audio_h__ -//#include "devicedefines.h" +#include "devicedefines.h" #include "dfu_interface.h" -//#include "xua_dsp.h" - typedef interface audManage_if { @@ -46,9 +44,7 @@ void audio(chanend c_in, #if (NUM_PDM_MICS > 0) , chanend c_pdm_in #endif -//#ifdef RUN_DSP_TASK , client audManage_if i_audMan -//#endif ); void SpdifTxWrapper(chanend c_spdif_tx); From b882c35f0f17b94fabf212028c868bdf12aa1fc7 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 11 Aug 2016 13:32:25 +0100 Subject: [PATCH 10/59] Re-disabled IN_VOLUME_IN_MIXER - regression fails. Updated comment(s) --- module_usb_audio/devicedefines.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 09bcee37..15c575d6 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -1046,7 +1046,7 @@ #undef OUT_VOLUME_IN_MIXER #else #if defined(MIXER) -// Enabled by default +// Disabled by default //#define OUT_VOLUME_IN_MIXER #endif #endif @@ -1066,8 +1066,8 @@ #undef IN_VOLUME_IN_MIXER #else #if defined(MIXER) -/* Enabled by default */ -#define IN_VOLUME_IN_MIXER +/* Disabled by default */ +//#define IN_VOLUME_IN_MIXER #endif #endif From 236bf6dba88bf042cebf44f0b54d8d73b8af3b6b Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 11 Aug 2016 20:05:54 +0100 Subject: [PATCH 11/59] Include file fixups (build fail) --- module_usb_audio/audio_io/audio_io.xc | 7 +------ module_usb_audio/audio_io/xua_audio.h | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index a804857b..203f884e 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -13,9 +13,7 @@ #include #include -#include "devicedefines.h" - -#include "dfu_interface.h" +#include "xua_audio.h" #include "audioports.h" #include "audiohw.h" #ifdef SPDIF_TX @@ -23,14 +21,11 @@ #endif #ifdef ADAT_TX #include "adat_tx.h" - #ifndef ADAT_TX_USE_SHARED_BUFF #error Designed for ADAT tx shared buffer mode ONLY #endif #endif -#include "xua_audio.h" - #include "commands.h" #include "xc_ptr.h" diff --git a/module_usb_audio/audio_io/xua_audio.h b/module_usb_audio/audio_io/xua_audio.h index 1a98601a..8472537d 100644 --- a/module_usb_audio/audio_io/xua_audio.h +++ b/module_usb_audio/audio_io/xua_audio.h @@ -16,8 +16,6 @@ typedef interface audManage_if } audManage_if; - - /** The audio driver thread. * * This function drives I2S ports and handles samples to/from other digital From b7c11788d517b1f48d775a17fc25b3f4cbc05ce9 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 11 Aug 2016 20:38:45 +0100 Subject: [PATCH 12/59] More include fixes. --- module_usb_audio/audio_io/audio_io.xc | 2 ++ module_usb_audio/audio_io/xua_audio.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 203f884e..90568e17 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -13,6 +13,8 @@ #include #include +#include "devicedefines.h" + #include "xua_audio.h" #include "audioports.h" #include "audiohw.h" diff --git a/module_usb_audio/audio_io/xua_audio.h b/module_usb_audio/audio_io/xua_audio.h index 8472537d..f2a65f6b 100644 --- a/module_usb_audio/audio_io/xua_audio.h +++ b/module_usb_audio/audio_io/xua_audio.h @@ -1,7 +1,6 @@ #ifndef __audio_h__ #define __audio_h__ -#include "devicedefines.h" #include "dfu_interface.h" typedef interface audManage_if From e270729960e0118f0b5a47728ca30607741a6901 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 16 Aug 2016 14:57:14 +0100 Subject: [PATCH 13/59] BCD_DEVICE version bump --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 15c575d6..3b3d399a 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -475,7 +475,7 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_M -#define BCD_DEVICE_M 19 +#define BCD_DEVICE_M 20 #endif /** From 09764eb62764e303306b5dbda4a304184946770b Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 17 Aug 2016 11:10:10 +0100 Subject: [PATCH 14/59] Intra-frame sample delay (ADC/TDM) --- CHANGELOG.rst | 4 ++++ module_usb_audio/audio_io/audio_io.xc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fc04543d..6f5056bb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ sc_usb_audio Change Log ======================= +6.20.0 +------ + - RESOLVED: Intra-frame sample delays of 1/2 samples on input streaming in TDM mode + 6.19.0 ------ - CHANGE: BCD_DEVICE version increment only diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 90568e17..66b01e02 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -598,7 +598,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, /* Input previous L sample into L in buffer */ index = 0; /* First input (i.e. frameCount == 0) we read last ADC channel of previous frame.. */ - unsigned buffIndex = (frameCount < 3) ? !readBuffNo : readBuffNo; + unsigned buffIndex = (frameCount > 1) ? !readBuffNo : readBuffNo; #pragma loop unroll /* First time around we get channel 7 of TDM8 */ From d123fd09381705507bde56673d50691ac17ae776 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 1 Sep 2016 14:39:08 +0100 Subject: [PATCH 15/59] Resolved build issue when NUM_USB_CHAN_OUT set to 0 and MIXER enabled. --- module_usb_audio/mixer/mixer.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc index e251e401..aa4f3f51 100644 --- a/module_usb_audio/mixer/mixer.xc +++ b/module_usb_audio/mixer/mixer.xc @@ -241,10 +241,10 @@ static inline void GetSamplesFromHost(chanend c) write_via_xc_ptr_indexed(samples_array, i, h); #else ptr_samples[i] = sample; -#endif #endif } } +#endif } #pragma unsafe arrays From ecf5e669d08f981c6dbadb2580288df83b939070 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 1 Sep 2016 14:40:18 +0100 Subject: [PATCH 16/59] Changelog update --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6f5056bb..b3c780ef 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,7 @@ sc_usb_audio Change Log 6.20.0 ------ - RESOLVED: Intra-frame sample delays of 1/2 samples on input streaming in TDM mode + - RESOLVED: Build issue with NUM_USB_CHAN_OUT set to 0 and MIXER enabled 6.19.0 ------ From 415ea3db52bf9b27361cbc36dc1b1ab5e99c3da3 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 15 Jul 2016 15:13:39 +0100 Subject: [PATCH 17/59] Cherrypick DFU fix when input vol disabled --- CHANGELOG.rst | 2 ++ module_usb_audio/usb_buffer/usb_buffer.xc | 7 ++++--- module_usb_audio/warnings.xc | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b3c780ef..e9c876e1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,8 @@ sc_usb_audio Change Log ------ - RESOLVED: Intra-frame sample delays of 1/2 samples on input streaming in TDM mode - RESOLVED: Build issue with NUM_USB_CHAN_OUT set to 0 and MIXER enabled + - RESOLVED: SPDIF_TX_INDEX not defined build warning only emitted when SPDIF_TX defined + - RESOLVED: Input volume disabled breaks going into DFU mode 6.19.0 ------ diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 274af50b..72b85491 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -307,11 +307,12 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, if(cmd == SET_SAMPLE_FREQ) { - sampleFreq = inuint(c_aud_ctl); + unsigned receivedSampleFreq = inuint(c_aud_ctl); /* Don't update things for DFU command.. */ - if(sampleFreq != AUDIO_STOP_FOR_DFU) + if(receivedSampleFreq != AUDIO_STOP_FOR_DFU) { + sampleFreq = receivedSampleFreq; #ifdef FB_TOLERANCE_TEST expected_fb = ((sampleFreq * 0x2000) / frameTime); #endif @@ -341,7 +342,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, /* Ideally we want to wait for handshake (and pass back up) here. But we cannot keep this * core locked, it must stay responsive to packets (MIDI etc) and SOFs. So, set a flag and check for * handshake elsewhere */ - SET_SHARED_GLOBAL(g_freqChange_sampFreq, sampleFreq); + SET_SHARED_GLOBAL(g_freqChange_sampFreq, receivedSampleFreq); } else if(cmd == SET_STREAM_FORMAT_IN) { diff --git a/module_usb_audio/warnings.xc b/module_usb_audio/warnings.xc index 5cbab76f..10b859ac 100644 --- a/module_usb_audio/warnings.xc +++ b/module_usb_audio/warnings.xc @@ -19,9 +19,11 @@ Warnings relating to configuration defines located in this XC source file rather #warning MAX_FREQ not defined. Using 192000 #endif +#ifdef SPDIF_TX #ifndef SPDIF_TX_INDEX #warning SPDIF_TX_INDEX not defined! Using 0 #endif +#endif #ifndef VENDOR_STR #warning VENDOR_STR not defined. Using "XMOS" From 2a36c3722a34bf50d42bfb7aa655ff2e1d3ce59b Mon Sep 17 00:00:00 2001 From: Larry Snizek Date: Thu, 1 Sep 2016 16:08:13 +0100 Subject: [PATCH 18/59] Cherry picked changelog update --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e9c876e1..5bd5411d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,7 +6,7 @@ sc_usb_audio Change Log - RESOLVED: Intra-frame sample delays of 1/2 samples on input streaming in TDM mode - RESOLVED: Build issue with NUM_USB_CHAN_OUT set to 0 and MIXER enabled - RESOLVED: SPDIF_TX_INDEX not defined build warning only emitted when SPDIF_TX defined - - RESOLVED: Input volume disabled breaks going into DFU mode + - RESOLVED: Failure to enter DFU mode when configured without input volume control 6.19.0 ------ From ad791c28064ae3374bca832cf1171dcdc7be654e Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 5 Oct 2016 12:56:00 +0100 Subject: [PATCH 19/59] PDM microphone clock divide now based MCLK defines (previously hard-coded) --- module_usb_audio/pdm_mics/pdm_mic.xc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index 6bc4ab83..331e345e 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -12,6 +12,7 @@ #include #include #include +#include #include "mic_array.h" #include "xua_pdm_mic.h" @@ -181,12 +182,22 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED #endif +#include "print.h" + void pdm_mic(streaming chanend c_ds_output[2]) { streaming chan c_4x_pdm_mic_0, c_4x_pdm_mic_1; - /* Note, this divide should be based on master clock freq */ - configure_clock_src_divide(pdmclk, p_mclk, 2); + /* Mics expect a clock in the 3Mhz range, calculate the divide based on mclk */ + /* e.g. For a 48kHz range mclk we expect a 3072000Hz mic clock */ + /* e.g. For a 44.1kHz range mclk we expect a 2822400Hz mic clock */ + + /* Note, codebase currently does not handle a different divide for each clock */ + assert((MCLK_48 % 3072000) == (MCLK_441 % 2822400)); + + unsigned micDiv = MCLK_48/3072000; + + configure_clock_src_divide(pdmclk, p_mclk, micDiv/2); configure_port_clock_output(p_pdm_clk, pdmclk); configure_in_port(p_pdm_mics, pdmclk); start_clock(pdmclk); From 24e79e4c22249565bac2b0d1d8b8847a4c2efa89 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 5 Oct 2016 12:56:25 +0100 Subject: [PATCH 20/59] Added 6.21 to changelog (BCD_DEVICE bump) --- CHANGELOG.rst | 6 +++++- module_usb_audio/devicedefines.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5bd5411d..d58a13ce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,12 +1,16 @@ sc_usb_audio Change Log ======================= +6.21.0 +------ + - RESOLVED: PDM microphone clock divide now based MCLK defines (previously hard-coded) + 6.20.0 ------ - RESOLVED: Intra-frame sample delays of 1/2 samples on input streaming in TDM mode - RESOLVED: Build issue with NUM_USB_CHAN_OUT set to 0 and MIXER enabled - RESOLVED: SPDIF_TX_INDEX not defined build warning only emitted when SPDIF_TX defined - - RESOLVED: Failure to enter DFU mode when configured without input volume control + - RESOLVED: Failure to enter DFU mode when configured without input volume control 6.19.0 ------ diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 3b3d399a..2b109713 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -482,7 +482,7 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_N -#define BCD_DEVICE_N 0 +#define BCD_DEVICE_N 1 #endif /** From 17e27a8c09277ab372d44cf589ef4cc6cb2d8c58 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 5 Oct 2016 14:37:46 +0100 Subject: [PATCH 21/59] 6.21.0 -> 6.30.0 inline with sw_usb_audio --- CHANGELOG.rst | 2 +- module_usb_audio/devicedefines.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d58a13ce..8e0231e0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ sc_usb_audio Change Log ======================= -6.21.0 +6.30.0 ------ - RESOLVED: PDM microphone clock divide now based MCLK defines (previously hard-coded) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 2b109713..ffc11fde 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -475,14 +475,14 @@ * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_M -#define BCD_DEVICE_M 20 +#define BCD_DEVICE_M 30 #endif /** * @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number. */ #ifndef BCD_DEVICE_N -#define BCD_DEVICE_N 1 +#define BCD_DEVICE_N 0 #endif /** From 1e8ea9a771dbfe858eb34c3adcf775f25350f1fa Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 6 Oct 2016 12:48:37 +0100 Subject: [PATCH 22/59] Fixed FS input channel count warning text --- module_usb_audio/warnings.xc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/warnings.xc b/module_usb_audio/warnings.xc index 10b859ac..c1646213 100644 --- a/module_usb_audio/warnings.xc +++ b/module_usb_audio/warnings.xc @@ -65,11 +65,11 @@ Warnings relating to configuration defines located in this XC source file rather /* Sanity check on FS channel counts */ #if (NUM_USB_CHAN_OUT_FS > NUM_USB_CHAN_OUT) -#error NUM_USB_CHAN_OUT expected to be less than or equal to NUM_USB_CHAN_OUT +#error NUM_USB_CHAN_OUT_FS expected to be less than or equal to NUM_USB_CHAN_OUT #endif #if (NUM_USB_CHAN_IN_FS > NUM_USB_CHAN_IN) -#error NUM_USB_CHAN_IN expected to be less than or equal to NUM_USB_CHAN_IN +#error NUM_USB_CHAN_IN_FS expected to be less than or equal to NUM_USB_CHAN_IN #endif From a6a860694cf4bcacc9751d02839a1a844caddccc Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 6 Oct 2016 13:43:57 +0100 Subject: [PATCH 23/59] Second decimator core only run if NUM_PDM_MICS>4 --- module_usb_audio/pdm_mics/pdm_mic.xc | 31 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index 331e345e..4399f20b 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -49,6 +49,12 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) user_pdm_init(); #endif +#if NUM_PDM_MICS > 4 + unsigned decimatorCount = 2; +#else + unsigned decimatorCount = 1; +#endif + mic_array_decimator_conf_common_t dcc; const int * unsafe fir_coefs[7]; mic_array_frame_time_domain * unsafe current; @@ -106,13 +112,13 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) dc[1].mic_gain_compensation[3]=0; dc[1].channel_count = 4; - mic_array_decimator_configure(c_ds_output, 2, dc); + mic_array_decimator_configure(c_ds_output, decimatorCount, dc); - mic_array_init_time_domain_frame(c_ds_output, 2, buffer, mic_audio, dc); + mic_array_init_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); /* Grab a first frame of mic data */ /* Note, loop is unrolled once - allows for while(1) select {} and thus combinable */ - 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, decimatorCount, buffer, mic_audio, dc); } /* Run user code */ @@ -141,7 +147,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) } /* 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); + mic_array_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); /* Run user code */ #ifdef MIC_PROCESSING_USE_INTERFACE @@ -160,11 +166,11 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) dcc.output_decimation_factor = decimationfactor; dcc.coefs=fir_coefs[decimationfactor/2]; dcc.fir_gain_compensation = fir_gain_compen[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_decimator_configure(c_ds_output, decimatorCount, dc); + mic_array_init_time_domain_frame(c_ds_output, decimatorCount, 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); + mic_array_frame_time_domain * unsafe current = mic_array_get_next_time_domain_frame(c_ds_output, decimatorCount, buffer, mic_audio, dc); /* Run user code */ #ifdef MIC_PROCESSING_USE_INTERFACE @@ -186,14 +192,19 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) 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; +#if (NUM_PDM_MICS > 4) + streaming chan c_4x_pdm_mic_1; +#else + #define c_4x_pdm_mic_1 null +#endif /* Mics expect a clock in the 3Mhz range, calculate the divide based on mclk */ /* e.g. For a 48kHz range mclk we expect a 3072000Hz mic clock */ /* e.g. For a 44.1kHz range mclk we expect a 2822400Hz mic clock */ /* Note, codebase currently does not handle a different divide for each clock */ - assert((MCLK_48 % 3072000) == (MCLK_441 % 2822400)); + assert((MCLK_48 / 3072000) == (MCLK_441 / 2822400)); unsigned micDiv = MCLK_48/3072000; @@ -206,7 +217,9 @@ void pdm_mic(streaming chanend c_ds_output[2]) { 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]); +#if (NUM_PDM_MICS > 4) mic_array_decimate_to_pcm_4ch(c_4x_pdm_mic_1, c_ds_output[1]); +#endif } } #endif From b5f786e6bb88b7b590cc2c9f8d638cc0c45ffd15 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 6 Oct 2016 13:47:45 +0100 Subject: [PATCH 24/59] changelog update --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8e0231e0..2c92a4e2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,7 @@ sc_usb_audio Change Log 6.30.0 ------ - RESOLVED: PDM microphone clock divide now based MCLK defines (previously hard-coded) + - CHANGE: Second microphone decimation core only run if NUM_PDM_MICS > 4 6.20.0 ------ From f164eeae5a01c67a7b365543db358b53ba12f355 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 27 Oct 2016 12:58:37 +0100 Subject: [PATCH 25/59] Renamed i_dsp -> i_audMan --- module_usb_audio/audio_io/userbuffermanagement.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/audio_io/userbuffermanagement.c b/module_usb_audio/audio_io/userbuffermanagement.c index 25cddcc7..fa4b07b7 100644 --- a/module_usb_audio/audio_io/userbuffermanagement.c +++ b/module_usb_audio/audio_io/userbuffermanagement.c @@ -4,10 +4,10 @@ /* Default implentation for UserBufferManagement() */ void UserBufferManagement(unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[] - , unsigned i_dsp + , unsigned i_audMan ) __attribute__ ((weak)); void UserBufferManagement(unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[] - , unsigned i_dsp + , unsigned i_audMan ) { /* Do nothing */ From ca4ce77e87bd87b44bc275dc609b533f27097aba Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 27 Oct 2016 12:58:46 +0100 Subject: [PATCH 26/59] Comment typo only. --- module_usb_audio/mixer/mixer.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc index aa4f3f51..44e4b54b 100644 --- a/module_usb_audio/mixer/mixer.xc +++ b/module_usb_audio/mixer/mixer.xc @@ -366,7 +366,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) /* Forward on Request for data to decouple thread */ outuint(c_host, request); - /* Between request to decouple and respose ~ 400nS latency for interrupt to fire */ + /* Between request to decouple and response ~ 400nS latency for interrupt to fire */ select { case inuint_byref(c_mix_ctl, cmd): From 75b9ae177baf72687aefd6166ac4bf540b6a81e8 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 27 Oct 2016 12:58:54 +0100 Subject: [PATCH 27/59] Comment only. --- module_usb_audio/pdm_mics/pdm_mic.xc | 1 + 1 file changed, 1 insertion(+) diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index 4399f20b..6c856cc0 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -122,6 +122,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) } /* Run user code */ + /* TODO ideally processing done inplace - it then doesn't matter if it is run or not */ #ifdef MIC_PROCESSING_USE_INTERFACE i_mic_process.transfer_buffers(current, output); #else From 88a1dc0e80bb6842e7e5577fd19ab3b40c694fa5 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 2 Nov 2016 13:50:27 +0000 Subject: [PATCH 28/59] Fix configuration of lib_mic_array with < 8 mics --- CHANGELOG.rst | 2 ++ module_usb_audio/pdm_mics/mic_array_conf.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2c92a4e2..3acb245d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,6 +3,8 @@ sc_usb_audio Change Log 6.30.0 ------ + - RESOLVED: Number of PDM microphone channels configured now based on + NUM_PDM_MICS define (previously hard-coded) - RESOLVED: PDM microphone clock divide now based MCLK defines (previously hard-coded) - CHANGE: Second microphone decimation core only run if NUM_PDM_MICS > 4 diff --git a/module_usb_audio/pdm_mics/mic_array_conf.h b/module_usb_audio/pdm_mics/mic_array_conf.h index a57e7753..e894cd10 100644 --- a/module_usb_audio/pdm_mics/mic_array_conf.h +++ b/module_usb_audio/pdm_mics/mic_array_conf.h @@ -1,7 +1,9 @@ #ifndef MIC_ARRAY_CONF_H_ #define MIC_ARRAY_CONF_H_ +#include "customdefines.h" + #define MIC_ARRAY_MAX_FRAME_SIZE_LOG2 0 -#define MIC_ARRAY_NUM_MICS 8 +#define MIC_ARRAY_NUM_MICS (NUM_PDM_MICS) #endif /* MIC_ARRAY_CONF_H_ */ From 0901194f5c83da661912af4f451610ce5f20bf50 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 9 Nov 2016 15:40:00 +0000 Subject: [PATCH 29/59] Remove duplicate header -> use xua_pdm_mic.h --- module_usb_audio/pdm_mics/pdm_mic.h | 37 ----------------------------- 1 file changed, 37 deletions(-) delete mode 100644 module_usb_audio/pdm_mics/pdm_mic.h diff --git a/module_usb_audio/pdm_mics/pdm_mic.h b/module_usb_audio/pdm_mics/pdm_mic.h deleted file mode 100644 index cf6f0e6d..00000000 --- a/module_usb_audio/pdm_mics/pdm_mic.h +++ /dev/null @@ -1,37 +0,0 @@ - -#include "mic_array.h" - -#ifdef MIC_PROCESSING_USE_INTERFACE -/* Interface based user processing */ -typedef interface mic_process_if -{ - void transfer_buffers(mic_array_frame_time_domain * unsafe audio, int output[]); - void init(); -} mic_process_if; - - -[[combinable]] -void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio -#ifdef MIC_PROCESSING_USE_INTERFACE - , client mic_process_if i_mic_process -#endif -); - -[[combinable]] -void user_pdm_process(server mic_process_if i_mic_data); - -/* PDM interface and decimation cores */ -void pdm_mic(streaming chanend c_ds_output[2]); - -#else - -/* Simple user hooks/call-backs */ -unsafe void user_pdm_process(mic_array_frame_time_domain * unsafe audio, int output[]); - -void user_pdm_init(); - -/* PDM interface and decimation cores */ -void pdm_mic(streaming chanend c_ds_output[2]); - -#endif - From 4956a4c67350fc12a4588053ecbee08c53634ad2 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 16 Nov 2016 12:22:55 +0000 Subject: [PATCH 30/59] Added default implementation of user_pdm_process and user_pdm_init (weak symbols) --- module_usb_audio/pdm_mics/pdm_mic_user.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 module_usb_audio/pdm_mics/pdm_mic_user.c diff --git a/module_usb_audio/pdm_mics/pdm_mic_user.c b/module_usb_audio/pdm_mics/pdm_mic_user.c new file mode 100644 index 00000000..d676857f --- /dev/null +++ b/module_usb_audio/pdm_mics/pdm_mic_user.c @@ -0,0 +1,24 @@ + +#include "devicedefines.h" +#include "mic_array_frame.h" + +/* Deafult implementations of user_pdm_init() and user_pdm_process(). Both can be over-ridden */ +void user_pdm_init() __attribute__ ((weak)); +void user_pdm_init() +{ + return; +} + + +void user_pdm_process() __attribute__ ((weak)); +void user_pdm_process(mic_array_frame_time_domain * audio, int output[]) +{ + + for(unsigned i=0; idata[i][0]; + } + + return; +} From ff8520af673e3d709b801a677f3aef940807eff3 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 16 Nov 2016 12:45:16 +0000 Subject: [PATCH 31/59] Attempts to fix non-mic builds --- module_usb_audio/pdm_mics/pdm_mic_user.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module_usb_audio/pdm_mics/pdm_mic_user.c b/module_usb_audio/pdm_mics/pdm_mic_user.c index d676857f..76e43877 100644 --- a/module_usb_audio/pdm_mics/pdm_mic_user.c +++ b/module_usb_audio/pdm_mics/pdm_mic_user.c @@ -1,5 +1,8 @@ #include "devicedefines.h" + +#if (NUM_PDM_MICS > 0) + #include "mic_array_frame.h" /* Deafult implementations of user_pdm_init() and user_pdm_process(). Both can be over-ridden */ @@ -22,3 +25,5 @@ void user_pdm_process(mic_array_frame_time_domain * audio, int output[]) return; } + +#endif From 124bee80b46aaae1b0e9c46cfe89025722ace189 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 16 Nov 2016 13:15:54 +0000 Subject: [PATCH 32/59] Additional build fix for default mic processing imps --- module_usb_audio/pdm_mics/pdm_mic_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/pdm_mics/pdm_mic_user.c b/module_usb_audio/pdm_mics/pdm_mic_user.c index 76e43877..1be80fee 100644 --- a/module_usb_audio/pdm_mics/pdm_mic_user.c +++ b/module_usb_audio/pdm_mics/pdm_mic_user.c @@ -1,7 +1,7 @@ #include "devicedefines.h" -#if (NUM_PDM_MICS > 0) +#if (NUM_PDM_MICS > 0) && !defined(MIC_PROCESSING_USE_INTERFACE) #include "mic_array_frame.h" From 7aca281d5cc241decde4d5a94dd70a0e70143f82 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 21 Nov 2016 17:03:15 +0000 Subject: [PATCH 33/59] Moved USER_MAIN_CORES to top or par{} - helps when external uses function ptrs etc --- module_usb_audio/main.xc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 7def523d..ed2aa341 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -560,6 +560,8 @@ int main() USER_MAIN_DECLARATIONS par { + USER_MAIN_CORES + on tile[XUD_TILE]: par { @@ -674,12 +676,11 @@ int main() #endif #endif - USER_MAIN_CORES - } #ifdef SU1_ADC_ENABLE xs1_su_adc_service(c_adc); #endif + } return 0; } From 22ee710f018218b5215d091e4182905d4aeb3ac6 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 23 Nov 2016 16:29:54 +0000 Subject: [PATCH 34/59] Fix typo --- module_usb_audio/audio_io/audio_io.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 66b01e02..671cd911 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -219,7 +219,7 @@ static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samp } #endif -/* sampsFromUsbToAudio: The sample frame the device has recived from the host and is going to play to the output audio interfaces */ +/* sampsFromUsbToAudio: The sample frame the device has received from the host and is going to play to the output audio interfaces */ /* sampsFromAudioToUsb: The sample frame that was received from the audio interfaces and that the device is going to send to the host */ void UserBufferManagement(unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[], client audManage_if i_audMan); From 2c5020d6d302a2cd157a4f7e18372aadee5c26b8 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 23 Nov 2016 16:29:54 +0000 Subject: [PATCH 35/59] Fix typo --- module_usb_audio/audio_io/audio_io.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 66b01e02..671cd911 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -219,7 +219,7 @@ static inline void TransferAdatTxSamples(chanend c_adat_out, const unsigned samp } #endif -/* sampsFromUsbToAudio: The sample frame the device has recived from the host and is going to play to the output audio interfaces */ +/* sampsFromUsbToAudio: The sample frame the device has received from the host and is going to play to the output audio interfaces */ /* sampsFromAudioToUsb: The sample frame that was received from the audio interfaces and that the device is going to send to the host */ void UserBufferManagement(unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[], client audManage_if i_audMan); From 020cf2dad79e713d9aec0c5f2d09e9aadb1a4ddf Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Fri, 11 Nov 2016 17:10:27 +0000 Subject: [PATCH 36/59] Add DS3 to I2S input - I2S downsampling is disabled by default. - I2S rate is always scaled up: The host may not issue a SET_SAMPLE_FREQ command so always scale up, and back down where the value may be a another command. --- module_usb_audio/audio_io/audio_io.xc | 108 ++++++++++++++++++-------- 1 file changed, 74 insertions(+), 34 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 671cd911..45eab08c 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -31,11 +31,31 @@ #include "commands.h" #include "xc_ptr.h" +#ifndef I2S_DOWNSAMPLE_FACTOR +#define I2S_DOWNSAMPLE_FACTOR (1) +#endif +#define I2S_RATE_SCALING (I2S_DOWNSAMPLE_FACTOR) + +#if I2S_RATE_SCALING != I2S_DOWNSAMPLE_FACTOR +#error "Unsupported I2S rate scaling and downsampling configuration" +#endif + +// I2S channels for stereo AEC reference input +#define I2S_CHANS_DIGI_IN (2) +// The PDM mic channels start after the I2S AEC reference channels +#define PDM_RX_INDEX (I2S_CHANS_DIGI_IN) + +#if (NUM_USB_CHAN_IN < (I2S_CHANS_DIGI_IN + NUM_PDM_MICS)) +#error "Not enough USB input channels to support number of I2S and PDM inputs" +#endif + /* TODO 32 is max expected channels */ static unsigned samplesOut[32]; /* Two buffers for ADC data to allow for DAC and ADC ports being offset */ -static unsigned samplesIn[2][32]; +static unsigned samplesIn[2][I2S_DOWNSAMPLE_FACTOR][32]; + +static int downsamplingCounter = 0; #if (DSD_CHANS_DAC != 0) extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; @@ -266,16 +286,24 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con #else inuint(c_out); #endif - UserBufferManagement(samplesOut, samplesIn[readBuffNo], i_audMan); + } + unsigned downsampledI2S[2]; + // TODO: run ds3 here + // Pass samplesIn[readBuffNo][0,I2S_DOWNSAMPLE_FACTOR][i]) to ds3() + UserBufferManagement(samplesOut, samplesIn[readBuffNo][downsamplingCounter], i_audMan); #if NUM_USB_CHAN_IN > 0 #pragma loop unroll - for(int i = 0; i < NUM_USB_CHAN_IN; i++) - { - outuint(c_out, samplesIn[readBuffNo][i]); - } -#endif + for(int i = 0; i < I2S_CHANS_DIGI_IN; i++) + { + outuint(c_out, downsampledI2S[i]); } +#pragma loop unroll + for (int i = PDM_RX_INDEX; i < (NUM_PDM_MICS + PDM_RX_INDEX); i++) + { + outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); + } +#endif return 0; } @@ -479,6 +507,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, return command; } + downsamplingCounter = 0; + InitPorts(divide); /* TODO In master mode, the i/o loop assumes L/RCLK = 32bit clocks. We should check this every interation @@ -684,20 +714,22 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if (NUM_PDM_MICS > 0) - /* Get samples from PDM->PCM comverter */ - c_pdm_pcm <: 1; - master + if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) { + /* Get samples from PDM->PCM comverter */ + c_pdm_pcm <: 1; + master + { #pragma loop unroll - for(int i = 0; i < NUM_PDM_MICS; i++) - { - c_pdm_pcm :> samplesIn[readBuffNo][i]; - } + for(int i = PDM_RX_INDEX; i < (NUM_PDM_MICS + PDM_RX_INDEX); i++) + { + c_pdm_pcm :> samplesIn[readBuffNo][downsamplingCounter][i]; + } + } } #endif } - #if (I2S_CHANS_ADC != 0) index = 0; /* Channels 0, 2, 4.. on each line */ @@ -794,22 +826,30 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, if(frameCount == I2S_CHANS_PER_FRAME) #endif { - /* Do samples transfer */ - /* The below looks a bit odd but forces the compiler to inline twice */ - unsigned command; - if(readBuffNo) - command = DoSampleTransfer(c_out, 1, underflowWord, i_audMan); - else - command = DoSampleTransfer(c_out, 0, underflowWord, i_audMan); - - if(command) + if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) { - return command; - } + /* Do samples transfer */ + /* The below looks a bit odd but forces the compiler to inline twice */ + unsigned command; + if(readBuffNo) + command = DoSampleTransfer(c_out, 1, underflowWord, i_audMan); + else + command = DoSampleTransfer(c_out, 0, underflowWord, i_audMan); - /* Reset frame counter and flip the ADC buffer */ - frameCount = 0; - readBuffNo = !readBuffNo; + if(command) + { + return command; + } + + /* Reset frame counter and flip the ADC buffer */ + downsamplingCounter = 0; + frameCount = 0; + readBuffNo = !readBuffNo; + } + else + { + ++downsamplingCounter; + } } } @@ -924,7 +964,7 @@ chanend ?c_config, chanend ?c unsigned adatMultiple = 0; #endif - unsigned curSamFreq = DEFAULT_FREQ; + unsigned curSamFreq = DEFAULT_FREQ * I2S_RATE_SCALING; unsigned curSamRes_DAC = STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS; /* Default to something reasonable */ unsigned curSamRes_ADC = STREAM_FORMAT_INPUT_1_RESOLUTION_BITS; /* Default to something reasonable - note, currently this never changes*/ unsigned command; @@ -1079,7 +1119,7 @@ chanend ?c_config, chanend ?c { /* TODO wait for good mclk instead of delay */ /* No delay for DFU modes */ - if ((curSamFreq != AUDIO_REBOOT_FROM_DFU) && (curSamFreq != AUDIO_STOP_FOR_DFU) && command) + if (((curSamFreq / I2S_RATE_SCALING) != AUDIO_REBOOT_FROM_DFU) && ((curSamFreq / I2S_RATE_SCALING) != AUDIO_STOP_FOR_DFU) && command) { #if 0 /* User should ensure MCLK is stable in AudioHwConfig */ @@ -1122,7 +1162,7 @@ chanend ?c_config, chanend ?c #if NUM_PDM_MICS > 0 /* Send decimation factor to PDM task(s) */ - c_pdm_in <: curSamFreq; + c_pdm_in <: curSamFreq / I2S_DOWNSAMPLE_FACTOR; #endif #ifdef ADAT_TX @@ -1163,7 +1203,7 @@ chanend ?c_config, chanend ?c if(command == SET_SAMPLE_FREQ) { - curSamFreq = inuint(c_mix_out); + curSamFreq = inuint(c_mix_out) * I2S_RATE_SCALING; } else if(command == SET_STREAM_FORMAT_OUT) { @@ -1176,7 +1216,7 @@ chanend ?c_config, chanend ?c } /* Currently no more audio will happen after this point */ - if (curSamFreq == AUDIO_STOP_FOR_DFU) + if ((curSamFreq / I2S_RATE_SCALING) == AUDIO_STOP_FOR_DFU) { outct(c_mix_out, XS1_CT_END); From dde838c9407a9bba9f6572dcb06f5ac6c0388e05 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 30 Nov 2016 10:12:26 +0000 Subject: [PATCH 37/59] Update I2S input buffering to support downsampling scheme Also: - Replace defines added for I2S downsampling with existing defines. - Remove downsampledI2S[] buffer until DS3 API is finalised. Samples from samplesIn[] are output instead for now. --- module_usb_audio/audio_io/audio_io.xc | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 45eab08c..5fab6eee 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -40,15 +40,14 @@ #error "Unsupported I2S rate scaling and downsampling configuration" #endif -// I2S channels for stereo AEC reference input -#define I2S_CHANS_DIGI_IN (2) -// The PDM mic channels start after the I2S AEC reference channels -#define PDM_RX_INDEX (I2S_CHANS_DIGI_IN) - -#if (NUM_USB_CHAN_IN < (I2S_CHANS_DIGI_IN + NUM_PDM_MICS)) +#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) #error "Not enough USB input channels to support number of I2S and PDM inputs" #endif +#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (NUM_PDM_MICS + PDM_MIC_INDEX))) +#error "PDM mic inputs mapping exceeds bounds of USB input channel" +#endif + /* TODO 32 is max expected channels */ static unsigned samplesOut[32]; @@ -287,19 +286,18 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con inuint(c_out); #endif } - unsigned downsampledI2S[2]; // TODO: run ds3 here // Pass samplesIn[readBuffNo][0,I2S_DOWNSAMPLE_FACTOR][i]) to ds3() UserBufferManagement(samplesOut, samplesIn[readBuffNo][downsamplingCounter], i_audMan); #if NUM_USB_CHAN_IN > 0 #pragma loop unroll - for(int i = 0; i < I2S_CHANS_DIGI_IN; i++) + for(int i = 0; i < I2S_CHANS_ADC; i++) { - outuint(c_out, downsampledI2S[i]); + outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); } #pragma loop unroll - for (int i = PDM_RX_INDEX; i < (NUM_PDM_MICS + PDM_RX_INDEX); i++) + for (int i = PDM_MIC_INDEX; i < (NUM_PDM_MICS + PDM_MIC_INDEX); i++) { outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); } @@ -640,7 +638,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++])); /* Note the use of readBuffNo changes based on frameCount */ - samplesIn[buffIndex][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 0, 2, 4.. on each line. + samplesIn[buffIndex][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 0, 2, 4.. on each line. } #endif @@ -721,7 +719,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, master { #pragma loop unroll - for(int i = PDM_RX_INDEX; i < (NUM_PDM_MICS + PDM_RX_INDEX); i++) + for(int i = PDM_MIC_INDEX; i < (NUM_PDM_MICS + PDM_MIC_INDEX); i++) { c_pdm_pcm :> samplesIn[readBuffNo][downsamplingCounter][i]; } @@ -740,7 +738,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, unsigned sample; asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++])); - samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. + samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. } #endif From fe6f795e5a9ad52db0ac017cf458b42f6759f2f2 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 30 Nov 2016 10:18:57 +0000 Subject: [PATCH 38/59] Fix brace placement Broken in commit 020cf2dad79e713d9aec0c5f2d09e9aadb1a4ddf. Fix to ensure that samples are not output to USB layer on receipt of a command. --- module_usb_audio/audio_io/audio_io.xc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 5fab6eee..6b20ecf8 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -285,23 +285,23 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con #else inuint(c_out); #endif - } - // TODO: run ds3 here - // Pass samplesIn[readBuffNo][0,I2S_DOWNSAMPLE_FACTOR][i]) to ds3() - UserBufferManagement(samplesOut, samplesIn[readBuffNo][downsamplingCounter], i_audMan); + // TODO: run ds3 here + // Pass samplesIn[readBuffNo][0,I2S_DOWNSAMPLE_FACTOR][i]) to ds3() + UserBufferManagement(samplesOut, samplesIn[readBuffNo][downsamplingCounter], i_audMan); #if NUM_USB_CHAN_IN > 0 #pragma loop unroll - for(int i = 0; i < I2S_CHANS_ADC; i++) - { - outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); - } + for(int i = 0; i < I2S_CHANS_ADC; i++) + { + outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); + } #pragma loop unroll - for (int i = PDM_MIC_INDEX; i < (NUM_PDM_MICS + PDM_MIC_INDEX); i++) - { - outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); - } + for (int i = PDM_MIC_INDEX; i < (NUM_PDM_MICS + PDM_MIC_INDEX); i++) + { + outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); + } #endif + } return 0; } From ca1925db7ac91671b3cc0d94e3554855e6f4f909 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Mon, 5 Dec 2016 19:26:14 +0000 Subject: [PATCH 39/59] Opts for fitting beclear --- module_dfu/src/dfu.xc | 6 +- module_usb_audio/audio_io/audio_io.xc | 32 +++-- module_usb_audio/devicedefines.h | 4 + module_usb_audio/endpoint0/audiorequests.xc | 41 +++--- module_usb_audio/endpoint0/descriptors.h | 56 +++++--- module_usb_audio/endpoint0/endpoint0.c | 12 +- module_usb_audio/flashlib_user.c | 10 ++ module_usb_audio/main.xc | 5 +- module_usb_audio/module_build_info | 5 +- module_usb_audio/pdm_mics/pdm_mic.xc | 12 +- module_usb_audio/pdm_mics/pdm_mic_user.c | 9 +- module_usb_audio/pdm_mics/xua_pdm_mic.h | 3 +- module_usb_audio/usb_buffer/decouple.xc | 135 +++++++++++++------- module_usb_audio/usb_buffer/interrupt.h | 6 +- module_usb_audio/usb_buffer/usb_buffer.xc | 9 +- 15 files changed, 224 insertions(+), 121 deletions(-) diff --git a/module_dfu/src/dfu.xc b/module_dfu/src/dfu.xc index 559842be..5a528334 100644 --- a/module_dfu/src/dfu.xc +++ b/module_dfu/src/dfu.xc @@ -203,7 +203,7 @@ static int DFU_Dnload(unsigned int request_len, unsigned int block_num, const un static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned data_out[16], unsigned &DFU_state) { - unsigned int cmd_data[16]; + unsigned int cmd_data[1]; unsigned int firstRead = 0; // Start at flash address 0 @@ -236,8 +236,8 @@ static int DFU_Upload(unsigned int request_len, unsigned int block_num, unsigned { cmd_data[0] = !firstRead; - // Read whole (256bytes) page from the image on the flash - flash_cmd_read_page((cmd_data, unsigned char[64])); + // Read whole (256bytes) page from the image on the flash into a memory buffer + flash_cmd_read_page((cmd_data, unsigned char[1])); subPagesLeft = 4; // If address out of range, terminate! diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 671cd911..27319704 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -31,11 +31,30 @@ #include "commands.h" #include "xc_ptr.h" -/* TODO 32 is max expected channels */ -static unsigned samplesOut[32]; +#define MAX(x,y) ((x)>(y) ? (x) : (y)) -/* Two buffers for ADC data to allow for DAC and ADC ports being offset */ -static unsigned samplesIn[2][32]; +static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)]; + +#ifndef ADAT_RX +#define ADAT_RX 0 +#endif + +#ifndef SPDIF_RX +#define SPDIF_RX 0 +#endif + +/* Two buffers for ADC data to allow for DAC and ADC I2S ports being offset */ +#define IN_CHAN_COUNT (I2S_CHANS_ADC + NUM_PDM_MICS + (8*ADAT_RX) + (2*SPDIF_RX)) + +static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)]; + +#if defined(ADAT_RX) && (ADAT_RX ==0) +#undef ADAT_RX +#endif + +#if defined(SPDIF_RX) && (SPDIF_RX ==0) +#undef SPDIF_RX +#endif #if (DSD_CHANS_DAC != 0) extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; @@ -1155,10 +1174,7 @@ chanend ?c_config, chanend ?c #if (NUM_PDM_MICS > 0) c_pdm_in, #endif - null -//#ifdef RUN_DSP_TASK - , i_audMan -//#endif + null, i_audMan ); if(command == SET_SAMPLE_FREQ) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index ffc11fde..111fa918 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -1218,7 +1218,11 @@ enum USBEndpointNumber_Out #define DFU_VENDOR_ID VENDOR_ID #define DFU_BCD_DEVICE BCD_DEVICE #define DFU_MANUFACTURER_STR_INDEX offsetof(StringDescTable_t, vendorStr)/sizeof(char *) +#if (AUDIO_CLASS == 2) #define DFU_PRODUCT_STR_INDEX offsetof(StringDescTable_t, productStr_Audio2)/sizeof(char *) +#else +#define DFU_PRODUCT_STR_INDEX offsetof(StringDescTable_t, productStr_Audio1)/sizeof(char *) +#endif #endif /* USB test mode support enabled by default (Required for compliance testing) */ diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 591d36fb..7a09bfa5 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -45,9 +45,9 @@ extern unsigned char mixSel[MAX_MIX_COUNT][MIX_INPUTS]; /* Global var for current frequency, set to default freq */ unsigned int g_curSamFreq = DEFAULT_FREQ; -//unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0; - #if 0 +unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0; + /* Original feedback implementation */ long long g_curSamFreqMultiplier = (DEFAULT_FREQ * 512 * 4) / (DEFAULT_MCLK_FREQ); #endif @@ -131,6 +131,7 @@ static void setG_curSamFreqMultiplier(unsigned x) } #endif +#if (OUTPUT_VOLUME_CONTROL == 1) || (INPUT_VOLUME_CONTROL == 1) /* Update master volume i.e. i.e update weights for all channels */ static void updateMasterVol( int unitID, chanend ?c_mix_ctl) { @@ -266,6 +267,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) } } } +#endif /* Handles the audio class specific requests * returns: XUD_RES_OKAY if request dealt with successfully without error, @@ -275,7 +277,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl ) { - unsigned char buffer[512]; + unsigned char buffer[128]; int unitID; XUD_Result_t result; unsigned datalength; @@ -312,6 +314,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c return result; } +#if MAX_FREQ != MIN_FREQ if(datalength == 4) { /* Re-construct Sample Freq */ @@ -369,7 +372,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c /* Allow time for our feedback to stabilise*/ FeedbackStabilityDelay(); } - +#endif /* MAX_FREQ != MIN_FREQ */ /* Send 0 Length as status stage */ XUD_DoSetRequestStatus(ep0_in); } @@ -514,6 +517,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c break; } +#if (OUTPUT_VOLUME_CONTROL == 1) || (INPUT_VOLUME_CONTROL == 1) /* Feature Units */ case FU_USBOUT: case FU_USBIN: @@ -629,6 +633,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c } break; /* FU_USBIN */ +#endif #if defined(MIXER) && (MAX_MIX_COUNT > 0) case ID_XU_OUT: @@ -1076,7 +1081,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp */ XUD_Result_t result; - unsigned char buffer[1024]; + unsigned char buffer[128]; unsigned length; /* Host to Device */ @@ -1094,7 +1099,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp { return result; } - +#if (MAX_FREQ != MIN_FREQ) if(controlSelector == SAMPLING_FREQ_CONTROL) { /* Expect length 3 for sample rate */ @@ -1116,22 +1121,6 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp if(curSamFreq48000Family || curSamFreq44100Family) { g_curSamFreq = newSampleRate; -#if 0 - /* Original feedback implementation */ - - int newMasterClock; - - if(g_curSamFreq48000Family) - { - newMasterClock = MCLK_48; - } - else - { - newMasterClock = MCLK_441; - } - - setG_curSamFreqMultiplier((g_curSamFreq*512*4)/newMasterClock); -#endif /* Instruct audio thread to change sample freq */ outuint(c_audioControl, SET_SAMPLE_FREQ); @@ -1147,6 +1136,9 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp return XUD_SetBuffer(ep0_in, buffer, 0); } } +#else + return XUD_SetBuffer(ep0_in, buffer, 0); +#endif } break; } @@ -1171,12 +1163,13 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl ) { - unsigned char buffer[1024]; + unsigned char buffer[128]; unsigned unitID; XUD_Result_t result; /* Inspect request */ /* Note we could check sp.bmRequestType.Direction if we wanted to be really careful */ +#if (OUTPUT_VOLUME_CONTROL == 1) || (INPUT_VOLUME_CONTROL == 1) switch(sp.bRequest) { case UAC_B_REQ_SET_CUR: @@ -1288,7 +1281,7 @@ int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c buffer[1] = (VOLUME_RES_MIXER >> 8); return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength); } - +#endif return 1; } #endif diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index ea699628..866bf029 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -35,13 +35,14 @@ typedef struct STR_TABLE_ENTRY(vendorStr); STR_TABLE_ENTRY(serialStr); +#if (AUDIO_CLASS == 2) /* Audio 2.0 Strings */ STR_TABLE_ENTRY(productStr_Audio2); /* Product string for Audio 2 */ STR_TABLE_ENTRY(outputInterfaceStr_Audio2); /* iInterface for streaming intefaces */ STR_TABLE_ENTRY(inputInterfaceStr_Audio2); /* iInterface for streaming intefaces */ STR_TABLE_ENTRY(usbInputTermStr_Audio2); /* Users sees as output from host */ STR_TABLE_ENTRY(usbOutputTermStr_Audio2); /* User sees as input to host */ - +#endif #if defined (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) /* Audio 1.0 Strings */ STR_TABLE_ENTRY(productStr_Audio1); /* Product string for Audio 1 */ @@ -50,6 +51,7 @@ typedef struct STR_TABLE_ENTRY(usbInputTermStr_Audio1); /* Users sees as output from host */ STR_TABLE_ENTRY(usbOutputTermStr_Audio1); /* User sees as input to host */ #endif +#if (AUDIO_CLASS == 2) STR_TABLE_ENTRY(clockSelectorStr); /* iClockSel */ STR_TABLE_ENTRY(internalClockSourceStr); /* iClockSource for internal clock */ #ifdef SPDIF_RX @@ -58,6 +60,7 @@ typedef struct #ifdef ADAT_RX STR_TABLE_ENTRY(adatClockSourceStr); /* iClockSource for external S/PDIF clock */ #endif +#endif #ifdef DFU STR_TABLE_ENTRY(dfuStr); /* iInterface for DFU interface */ #endif @@ -291,7 +294,9 @@ typedef struct #if defined(MIXER) && (MAX_MIX_COUNT > 7) STR_TABLE_ENTRY(mixOutStr_8); #endif +#ifdef IAP STR_TABLE_ENTRY(iAPInterfaceStr); +#endif #ifdef IAP_EA_NATIVE_TRANS STR_TABLE_ENTRY(iAP_EANativeTransport_InterfaceStr); #endif @@ -302,12 +307,13 @@ StringDescTable_t g_strTable = .langID = "\x09\x04", /* US English */ .vendorStr = VENDOR_STR, .serialStr = "", +#if (AUDIO_CLASS == 2) .productStr_Audio2 = PRODUCT_STR_A2, .outputInterfaceStr_Audio2 = APPEND_PRODUCT_STR_A2(), .inputInterfaceStr_Audio2 = APPEND_PRODUCT_STR_A2(), .usbInputTermStr_Audio2 = APPEND_PRODUCT_STR_A2(), .usbOutputTermStr_Audio2 = APPEND_PRODUCT_STR_A2(), - +#endif #if defined (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1) .productStr_Audio1 = PRODUCT_STR_A1, .outputInterfaceStr_Audio1 = APPEND_PRODUCT_STR_A1(), @@ -315,6 +321,7 @@ StringDescTable_t g_strTable = .usbInputTermStr_Audio1 = APPEND_PRODUCT_STR_A1(), .usbOutputTermStr_Audio1 = APPEND_PRODUCT_STR_A1(), #endif +#if (AUDIO_CLASS == 2) .clockSelectorStr = APPEND_VENDOR_STR(Clock Selector), .internalClockSourceStr = APPEND_VENDOR_STR(Internal Clock), #ifdef SPDIF_RX @@ -323,6 +330,7 @@ StringDescTable_t g_strTable = #ifdef ADAT_RX .adatClockSourceStr = APPEND_VENDOR_STR(ADAT Clock), #endif +#endif #ifdef DFU .dfuStr = APPEND_VENDOR_STR(DFU), #endif @@ -368,7 +376,9 @@ StringDescTable_t g_strTable = #if defined(MIXER) && (MAX_MIX_COUNT > 8) #error #endif +#ifdef IAP .iAPInterfaceStr = "iAP Interface", +#endif #ifdef IAP_EA_NATIVE_TRANS .iAP_EANativeTransport_InterfaceStr = IAP2_EA_NATIVE_TRANS_PROTOCOL_NAME, #endif @@ -397,6 +407,7 @@ USB_Descriptor_Device_t devDesc_Audio1 = }; #endif +#if (AUDIO_CLASS == 2) /* Device Descriptor for Audio Class 2.0 (Assumes High-Speed ) */ USB_Descriptor_Device_t devDesc_Audio2 = { @@ -438,7 +449,7 @@ unsigned char devDesc_Null[] = 0, /* 16 iSerialNumber : Index of serial number decriptor */ 0x01 /* 17 bNumConfigurations : Number of possible configs */ }; - +#endif /****** Device Qualifier Descriptors *****/ @@ -751,7 +762,7 @@ typedef struct }__attribute__((packed)) USB_Config_Descriptor_Audio2_t; -#if 1 +#if (AUDIO_CLASS == 2) USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= { .Config = @@ -2252,7 +2263,10 @@ const unsigned num_freqs_a1 = MAX(3, (0 #define NUM_CONTROL_INTERFACES 0 #endif -#define AC_TOTAL_LENGTH (AC_LENGTH + (INPUT_INTERFACES_A1 * (17 + NUM_USB_CHAN_IN_FS + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (17 + NUM_USB_CHAN_OUT_FS + (num_freqs_a1 *3)))) +#define AC_TOTAL_LENGTH (AC_LENGTH + \ + (INPUT_INTERFACES_A1 * (9 + (7* INPUT_VOLUME_CONTROL) + (NUM_USB_CHAN_IN_FS * INPUT_VOLUME_CONTROL) + num_freqs_a1 * 3)) +\ + (OUTPUT_INTERFACES_A1 * (9 + (7 * OUTPUT_VOLUME_CONTROL) + (NUM_USB_CHAN_OUT_FS * OUTPUT_VOLUME_CONTROL) + (num_freqs_a1 *3)))) + #define STREAMING_INTERFACES (INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1) /* Number of interfaces for Audio 1.0 (+1 for control ) */ @@ -2297,7 +2311,7 @@ unsigned char cfgDesc_Audio1[] = USB_CLASS_AUDIO, UAC_INT_SUBCLASS_AUDIOCONTROL, 0x00, /* Unused */ - 8, /* iInterface - re-use iProduct */ + offsetof(StringDescTable_t, productStr_Audio1)/sizeof(char *), /* iInterface - re-use iProduct */ /* CS (Class Specific) AudioControl interface header descriptor (4.3.2) */ AC_LENGTH, @@ -2325,8 +2339,9 @@ unsigned char cfgDesc_Audio1[] = NUM_USB_CHAN_OUT_FS, /* bNrChannels */ 0x03, 0x00, /* wChannelConfig */ offsetof(StringDescTable_t, outputChanStr_1)/sizeof(char *), /* iChannelNames */ - 11, /* iTerminal */ + offsetof(StringDescTable_t, usbInputTermStr_Audio1)/sizeof(char *), /* iTerminal */ +#if (OUTPUT_VOLUME_CONTROL == 1) /* CS_Interface class specific AC interface feature unit descriptor - mute & volume for dac */ (8 + NUM_USB_CHAN_OUT_FS), UAC_CS_DESCTYPE_INTERFACE, @@ -2364,6 +2379,7 @@ unsigned char cfgDesc_Audio1[] = #error NUM_USB_CHAN_OUT_FS > 8 currently supported #endif 0x00, /* String table index */ +#endif /* CS_Interface Output Terminal Descriptor - Analogue out to speaker */ 0x09, @@ -2372,7 +2388,11 @@ unsigned char cfgDesc_Audio1[] = 0x06, /* Terminal ID */ 0x01, 0x03, /* Type - streaming out, speaker */ 0x00, /* Associated terminal - unused */ - 0x0A, /* sourceID */ +#if (OUTPUT_VOLUME_CONTROL == 1) + 0x0A, /* sourceID - FU */ +#else + 0x01, /* sourceID - IT */ +#endif 0x00, /* Unused */ #endif @@ -2387,7 +2407,7 @@ unsigned char cfgDesc_Audio1[] = NUM_USB_CHAN_IN_FS, /* bNrChannels */ 0x03, 0x00, /* wChannelConfigs */ offsetof(StringDescTable_t, inputChanStr_1)/sizeof(char *), /* iChannelNames */ - 12, /* iTerminal */ + offsetof(StringDescTable_t, usbOutputTermStr_Audio1)/sizeof(char *), /* iTerminal */ /* CS_Interface Output Terminal Descriptor - USB Streaming Device to Host*/ 0x09, @@ -2396,9 +2416,14 @@ unsigned char cfgDesc_Audio1[] = 0x07, /* Terminal ID */ 0x01, 0x01, /* Type - streaming */ 0x01, /* Associated terminal - unused */ - 0x0B, /* sourceID - from selector unit ?? */ +#if INPUT_VOLUME_CONTROL + 0x0B, /* sourceID - FU */ +#else + 0x02, /* sourceID - IT */ +#endif 0x00, /* Unused */ +#if (INPUT_VOLUME_CONTROL == 1) /* CS_Interface class specific AC interface feature unit descriptor - mute & volume for adc */ (8 + NUM_USB_CHAN_IN_FS), UAC_CS_DESCTYPE_INTERFACE, @@ -2436,6 +2461,7 @@ unsigned char cfgDesc_Audio1[] = #endif 0x00, /* String table index */ #endif +#endif #if (NUM_USB_CHAN_OUT > 0) /* Standard AS Interface Descriptor (4.5.1) */ @@ -2447,7 +2473,7 @@ unsigned char cfgDesc_Audio1[] = 0x01, /* bInterfaceClass - AUDIO */ 0x02, /* bInterfaceSubclass - AUDIO_STREAMING */ 0x00, /* bInterfaceProtocol - Not used */ - 0x09, /* iInterface */ + offsetof(StringDescTable_t, outputInterfaceStr_Audio1)/sizeof(char *), /* iInterface */ /* Standard As Interface Descriptor (4.5.1) */ 0x09, @@ -2462,7 +2488,7 @@ unsigned char cfgDesc_Audio1[] = 0x01, /* Interface class - AUDIO */ 0x02, /* subclass - AUDIO_STREAMING */ 0x00, /* Unused */ - 0x09, /* String table index */ + offsetof(StringDescTable_t, outputInterfaceStr_Audio1)/sizeof(char *), /* iInterface */ /* Class-Specific AS Interface Descriptor (4.5.2) */ 0x07, @@ -2580,7 +2606,7 @@ unsigned char cfgDesc_Audio1[] = 0x01, /* Interface class - AUDIO */ 0x02, /* subclass - AUDIO_STREAMING */ 0x00, /* Unused */ - 0x0A, /* iInterface */ + offsetof(StringDescTable_t, inputInterfaceStr_Audio1)/sizeof(char *), /* Standard Interface Descriptor - Audio streaming IN */ 0x09, @@ -2591,7 +2617,7 @@ unsigned char cfgDesc_Audio1[] = 0x01, /* Interface class - AUDIO */ 0x02, /* Subclass - AUDIO_STREAMING */ 0x00, /* Unused */ - 0x0A, /* iInterface*/ + offsetof(StringDescTable_t, inputInterfaceStr_Audio1)/sizeof(char *), /* CS_Interface AC interface header descriptor */ 0x07, @@ -2688,7 +2714,7 @@ unsigned char cfgDesc_Audio1[] = #ifdef XVSM /* Standard DFU class Interface descriptor */ - 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ + 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */ (OUTPUT_INTERFACES_A1 + 2), /* bInterfaceNumber */ 0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */ diff --git a/module_usb_audio/endpoint0/endpoint0.c b/module_usb_audio/endpoint0/endpoint0.c index 981fccd3..fee7055f 100755 --- a/module_usb_audio/endpoint0/endpoint0.c +++ b/module_usb_audio/endpoint0/endpoint0.c @@ -206,6 +206,8 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, XUD_ep ep0_out = XUD_InitEp(c_ep0_out); XUD_ep ep0_in = XUD_InitEp(c_ep0_in); +#if 0 + /* Dont need to init globals.. */ /* Init tables for volumes (+ 1 for master) */ for(int i = 0; i < NUM_USB_CHAN_OUT + 1; i++) { @@ -218,7 +220,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, volsIn[i] = 0; mutesIn[i] = 0; } - +#endif VendorRequests_Init(VENDOR_REQUESTS_PARAMS); #ifdef MIXER @@ -295,7 +297,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, { /* Returns XUD_RES_OKAY for success, XUD_RES_RST for bus reset */ XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, &sp); - + if (result == XUD_RES_OKAY) { result = XUD_RES_ERR; @@ -311,7 +313,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, switch (sp.wIndex) { /* Check for audio stream from host start/stop */ -#if (NUM_USB_CHAN_OUT > 0) +#if (NUM_USB_CHAN_OUT > 0) && (AUDIO_CLASS == 2) case INTERFACE_NUMBER_AUDIO_OUTPUT: /* Check the alt is in range */ if(sp.wValue <= OUTPUT_FORMAT_COUNT) @@ -346,7 +348,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, break; #endif -#if (NUM_USB_CHAN_IN > 0) +#if (NUM_USB_CHAN_IN > 0) && (AUDIO_CLASS == 2) case INTERFACE_NUMBER_AUDIO_INPUT: /* Check the alt is in range */ if(sp.wValue <= INPUT_FORMAT_COUNT) @@ -641,6 +643,8 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, if (!DFU_mode_active) { #endif + + printintln(2); #ifdef AUDIO_CLASS_FALLBACK /* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */ result = USB_StandardRequests(ep0_out, ep0_in, diff --git a/module_usb_audio/flashlib_user.c b/module_usb_audio/flashlib_user.c index ac8387b0..834adee7 100644 --- a/module_usb_audio/flashlib_user.c +++ b/module_usb_audio/flashlib_user.c @@ -19,9 +19,15 @@ #define portout(a,b) {__asm__ __volatile__("out res[%0], %1": : "r" (a) , "r" (b));} #ifdef DFU_FLASH_DEVICE + +#ifdef QUAD_SPI_FLASH +/* Using specified flash device rather than all supported in tools */ +fl_QuadDeviceSpec flash_devices[] = {DFU_FLASH_DEVICE}; +#else /* Using specified flash device rather than all supported in tools */ fl_DeviceSpec flash_devices[] = {DFU_FLASH_DEVICE}; #endif +#endif #ifdef QUAD_SPI_FLASH /* @@ -83,7 +89,11 @@ int flash_cmd_enable_ports() #endif #ifdef DFU_FLASH_DEVICE +#ifdef QUAD_SPI_FLASH + result = fl_connectToDevice(&p_qflash, flash_devices, 1); +#else result = fl_connectToDevice(&p_flash, flash_devices, 1); +#endif #else /* Use default flash list */ #ifdef QUAD_SPI_FLASH diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index ed2aa341..da81c579 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -317,9 +317,12 @@ VENDOR_REQUESTS_PARAMS_DEC_ c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, clk, 1, XUD_SPEED_HS, XUD_PWR_CFG); #else + { +//set_core_high_priority_on(); XUD_Manager(c_xud_out, ENDPOINT_COUNT_OUT, c_xud_in, ENDPOINT_COUNT_IN, c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, clk, 1, XUD_SPEED_FS, XUD_PWR_CFG); + } #endif /* USB Packet buffering Core */ @@ -672,7 +675,7 @@ int main() #ifdef MIC_PROCESSING_USE_INTERFACE on stdcore[PDM_TILE].core[0]: pdm_buffer(c_ds_output, c_pdm_pcm, i_mic_process); #else - on stdcore[PDM_TILE]: pdm_buffer(c_ds_output, c_pdm_pcm); + on stdcore[PDM_TILE].core[0]: pdm_buffer(c_ds_output, c_pdm_pcm); #endif #endif diff --git a/module_usb_audio/module_build_info b/module_usb_audio/module_build_info index 2872a33f..7c62a880 100644 --- a/module_usb_audio/module_build_info +++ b/module_usb_audio/module_build_info @@ -29,4 +29,7 @@ # EXCLUDE_FILES += descriptors_2.rst -MODULE_XCC_FLAGS += $(XCC_FLAGS) -falways-inline +#MODULE_XCC_FLAGS += $(XCC_FLAGS) -falways-inline + +XCC_FLAGS_endpoint0.c = -Os -mno-dual-issue $(XCC_FLAGS) +XCC_FLAGS_dbcalc.xc = -Os -mno-dual-issue $(XCC_FLAGS) diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index 6c856cc0..a2c5d4e3 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -17,7 +17,7 @@ #include "mic_array.h" #include "xua_pdm_mic.h" -#define MAX_DECIMATION_FACTOR 12 +#define MAX_DECIMATION_FACTOR (96000/MIN_FREQ) /* Hardware resources */ in port p_pdm_clk = PORT_PDM_CLK; @@ -36,11 +36,11 @@ mic_array_frame_time_domain mic_audio[2]; void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio, client mic_process_if i_mic_process) #else #pragma unsafe arrays +[[combinable]] void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #endif { unsigned buffer; - int output[NUM_PDM_MICS]; unsigned samplerate; #ifdef MIC_PROCESSING_USE_INTERFACE @@ -126,7 +126,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #ifdef MIC_PROCESSING_USE_INTERFACE i_mic_process.transfer_buffers(current, output); #else - user_pdm_process(current, output); + user_pdm_process(current); #endif int req; while(1) @@ -143,7 +143,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #pragma loop unroll for(int i = 0; i < NUM_PDM_MICS; i++) { - c_audio <: output[i]; + c_audio <: current->data[i][0]; } } @@ -154,7 +154,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #ifdef MIC_PROCESSING_USE_INTERFACE i_mic_process.transfer_buffers(current, output); #else - user_pdm_process(current, output); + user_pdm_process(current); #endif } else @@ -177,7 +177,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #ifdef MIC_PROCESSING_USE_INTERFACE i_mic_process.transfer_buffers(current, output); #else - user_pdm_process(current, output); + user_pdm_process(current); #endif } break; diff --git a/module_usb_audio/pdm_mics/pdm_mic_user.c b/module_usb_audio/pdm_mics/pdm_mic_user.c index 1be80fee..13870738 100644 --- a/module_usb_audio/pdm_mics/pdm_mic_user.c +++ b/module_usb_audio/pdm_mics/pdm_mic_user.c @@ -14,15 +14,8 @@ void user_pdm_init() void user_pdm_process() __attribute__ ((weak)); -void user_pdm_process(mic_array_frame_time_domain * audio, int output[]) +void user_pdm_process(mic_array_frame_time_domain * audio) { - - for(unsigned i=0; idata[i][0]; - } - return; } diff --git a/module_usb_audio/pdm_mics/xua_pdm_mic.h b/module_usb_audio/pdm_mics/xua_pdm_mic.h index 69e52d5c..525122c5 100644 --- a/module_usb_audio/pdm_mics/xua_pdm_mic.h +++ b/module_usb_audio/pdm_mics/xua_pdm_mic.h @@ -26,11 +26,12 @@ void pdm_mic(streaming chanend c_ds_output[2]); #else /* Simple user hooks/call-backs */ -void user_pdm_process(mic_array_frame_time_domain * unsafe audio, int output[]); +void user_pdm_process(mic_array_frame_time_domain * unsafe audio); void user_pdm_init(); /* PDM interface and decimation cores */ +[[combinable]] void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio); /* PDM interface and decimation cores */ diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index ee279499..a49e016e 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -14,25 +14,52 @@ #endif #define MAX(x,y) ((x)>(y) ? (x) : (y)) -#define HS_PACKET_SIZE ((((MAX_FREQ+7999)/8000))+3) // Samples per channel -#define FS_PACKET_SIZE ((((MAX_FREQ_FS+999)/1000))+3) // Samples per channel - /* TODO use SLOTSIZE to potentially save memory */ -#define BUFF_SIZE_OUT MAX(4 * HS_PACKET_SIZE * NUM_USB_CHAN_OUT, 4 * FS_PACKET_SIZE * NUM_USB_CHAN_OUT_FS) -#define BUFF_SIZE_IN MAX(4 * HS_PACKET_SIZE * NUM_USB_CHAN_IN, 4 * FS_PACKET_SIZE * NUM_USB_CHAN_IN_FS) +/* Note we could improve on this, for one subslot is set to 4 */ +/* The *4 is conversion to bytes, note we're assuming a slotsize of 4 here whic is potentially as waste */ +#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS ((MAX_FREQ/8000+1)*4) +#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS ((MAX_FREQ_FS/1000+1)*4) + +/*** IN PACKET SIZES ***/ +/* Max packet sizes in bytes. Note the +4 is because we store packet lengths in the buffer */ +#define MAX_DEVICE_AUD_PACKET_SIZE_IN_HS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * NUM_USB_CHAN_IN + 4) +#define MAX_DEVICE_AUD_PACKET_SIZE_IN_FS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * NUM_USB_CHAN_IN_FS + 4) + +#define MAX_DEVICE_AUD_PACKET_SIZE_IN (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_FS, MAX_DEVICE_AUD_PACKET_SIZE_IN_HS)) + +/*** OUT PACKET SIZES ***/ +#define MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * NUM_USB_CHAN_OUT + 4) +#define MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * NUM_USB_CHAN_OUT_FS + 4) + +#define MAX_DEVICE_AUD_PACKET_SIZE_OUT (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS)) + +/*** BUFFER SIZES ***/ + +#define BUFFER_PACKET_COUNT 3 /* How many packets too allow for in buffer - minimum is 3! */ + +#define BUFF_SIZE_OUT_HS MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS * BUFFER_PACKET_COUNT +#define BUFF_SIZE_OUT_FS MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS * BUFFER_PACKET_COUNT + +#define BUFF_SIZE_IN_HS MAX_DEVICE_AUD_PACKET_SIZE_IN_HS * BUFFER_PACKET_COUNT +#define BUFF_SIZE_IN_FS MAX_DEVICE_AUD_PACKET_SIZE_IN_FS * BUFFER_PACKET_COUNT + +#define BUFF_SIZE_OUT MAX(BUFF_SIZE_OUT_HS, BUFF_SIZE_OUT_FS) +#define BUFF_SIZE_IN MAX(BUFF_SIZE_IN_HS, BUFF_SIZE_IN_FS) + +//#define OUT_BUFFER_PREFILL (MAX(NUM_USB_CHAN_OUT_FS*FS_PACKET_SIZE*3+4,NUM_USB_CHAN_OUT*HS_PACKET_SIZE*4+4)*1) +//#define IN_BUFFER_PREFILL (MAX(FS_PACKET_SIZE*2+4, HS_PACKET_SIZE*4+4)*2) +#define OUT_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS)) +#define IN_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_HS, MAX_DEVICE_AUD_PACKET_SIZE_IN_FS)*2) + -/* Maximum USB buffer size (1024 bytes + 1 word to store length) */ -#define MAX_USB_AUD_PACKET_SIZE 1028 -#define OUT_BUFFER_PREFILL (MAX(NUM_USB_CHAN_OUT_FS*FS_PACKET_SIZE*3+4,NUM_USB_CHAN_OUT*HS_PACKET_SIZE*4+4)*1) -#define IN_BUFFER_PREFILL (MAX(FS_PACKET_SIZE*2+4, HS_PACKET_SIZE*4+4)*2) /* Volume and mute tables */ -#ifndef OUT_VOLUME_IN_MIXER +#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1) unsigned int multOut[NUM_USB_CHAN_OUT + 1]; static xc_ptr p_multOut; #endif -#ifndef IN_VOLUME_IN_MIXER +#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1) unsigned int multIn[NUM_USB_CHAN_IN + 1]; static xc_ptr p_multIn; #endif @@ -41,20 +68,12 @@ static xc_ptr p_multIn; unsigned g_numUsbChan_Out = NUM_USB_CHAN_OUT; unsigned g_numUsbChan_In = NUM_USB_CHAN_IN; -/* Note we could improve on this, for one subslot is set to 4 */ -#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS ((MAX_FREQ/8000+1)*4) -#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS ((MAX_FREQ_FS/1000+1)*4) - -#define MAX_DEVICE_AUD_PACKET_SIZE_HS ((MAX_FREQ/8000+1)*NUM_USB_CHAN_IN*4) -#define MAX_DEVICE_AUD_PACKET_SIZE_FS ((MAX_FREQ_FS/1000+1)*NUM_USB_CHAN_IN_FS*4) - -#define MAX_DEVICE_AUD_PACKET_SIZE (MAX(MAX_DEVICE_AUD_PACKET_SIZE_FS, MAX_DEVICE_AUD_PACKET_SIZE_HS)) - /* Circular audio buffers */ -unsigned outAudioBuff[BUFF_SIZE_OUT + (MAX_USB_AUD_PACKET_SIZE>>2) + 4]; -unsigned audioBuffIn[BUFF_SIZE_IN + (MAX_DEVICE_AUD_PACKET_SIZE>>2) + 4]; +unsigned outAudioBuff[(BUFF_SIZE_OUT >> 2)+ (MAX_DEVICE_AUD_PACKET_SIZE_OUT >> 0)]; +unsigned audioBuffIn[(BUFF_SIZE_IN >> 2)+ (MAX_DEVICE_AUD_PACKET_SIZE_IN >> 0)]; -unsigned inZeroBuff[(MAX_DEVICE_AUD_PACKET_SIZE>>2)+4]; +/* Shift down accounts for bytes -> words */ +unsigned inZeroBuff[(MAX_DEVICE_AUD_PACKET_SIZE_IN >> 2)]; void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max); @@ -91,8 +110,13 @@ xc_ptr g_aud_to_host_wrptr; xc_ptr g_aud_to_host_dptr; xc_ptr g_aud_to_host_rdptr; xc_ptr g_aud_to_host_zeros; +#if (AUDIO_CLASS == 2) int sampsToWrite = DEFAULT_FREQ/8000; /* HS assumed here. Expect to be junked during a overflow before stream start */ int totalSampsToWrite = DEFAULT_FREQ/8000; +#else +int sampsToWrite = DEFAULT_FREQ/1000; /* HS assumed here. Expect to be junked during a overflow before stream start */ +int totalSampsToWrite = DEFAULT_FREQ/1000; +#endif int aud_data_remaining_to_device = 0; /* Audio over/under flow flags */ @@ -109,15 +133,21 @@ unsigned unpackData = 0; unsigned packState = 0; unsigned packData = 0; -/* Default to something sensible but the following are setup at stream start: */ +/* Default to something sensible but the following are setup at stream start (unless UAC1 only..) */ +#if (AUDIO_CLASS == 2) unsigned g_curSubSlot_Out = HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; unsigned g_curSubSlot_In = HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; - -/* Init to something sensible, but expect to be re-set before stream start */ -#if (AUDIO_CLASS==2) -int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_HS; #else -int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_FS; +unsigned g_curSubSlot_Out = FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; +unsigned g_curSubSlot_In = FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; +#endif + + +/* IN packet size. Init to something sensible, but expect to be re-set before stream start */ +#if (AUDIO_CLASS==2) +int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_IN_HS; +#else +int g_maxPacketSize = MAX_DEVICE_AUD_PACKET_SIZE_IN_FS; #endif #pragma select handler @@ -146,7 +176,7 @@ void handle_audio_request(chanend c_mix_out) outSamps = g_aud_from_host_wrptr - g_aud_from_host_rdptr; if (outSamps < 0) { - outSamps += BUFF_SIZE_OUT*4; + outSamps += BUFF_SIZE_OUT; } /* If we have a decent number of samples, come out of underflow cond */ @@ -170,7 +200,6 @@ __builtin_unreachable(); { #pragma xta endpoint "mixer_request" int sample; - int mult; int h; unsigned l; @@ -505,7 +534,7 @@ __builtin_unreachable(); space_left += datalength; SET_SHARED_GLOBAL(g_aud_to_host_rdptr, rdPtr); - } while(space_left < (BUFF_SIZE_IN*4/2)); + } while(space_left < (BUFF_SIZE_IN/2)); } sampsToWrite = totalSampsToWrite; @@ -594,22 +623,22 @@ void decouple(chanend c_mix_out int t = array_to_xc_ptr(outAudioBuff); -#ifndef OUT_VOLUME_IN_MIXER +#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1) p_multOut = array_to_xc_ptr(multOut); #endif -#ifndef IN_VOLUME_IN_MIXER +#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1) p_multIn = array_to_xc_ptr(multIn); #endif aud_from_host_fifo_start = t; - aud_from_host_fifo_end = aud_from_host_fifo_start + BUFF_SIZE_OUT*4; + aud_from_host_fifo_end = aud_from_host_fifo_start + BUFF_SIZE_OUT; g_aud_from_host_wrptr = aud_from_host_fifo_start; g_aud_from_host_rdptr = aud_from_host_fifo_start; t = array_to_xc_ptr(audioBuffIn); aud_to_host_fifo_start = t; - aud_to_host_fifo_end = aud_to_host_fifo_start + BUFF_SIZE_IN*4; + aud_to_host_fifo_end = aud_to_host_fifo_start + BUFF_SIZE_IN; g_aud_to_host_wrptr = aud_to_host_fifo_start; g_aud_to_host_rdptr = aud_to_host_fifo_start; g_aud_to_host_dptr = aud_to_host_fifo_start + 4; @@ -622,14 +651,14 @@ void decouple(chanend c_mix_out g_aud_to_host_zeros = t; /* Init vol mult tables */ -#ifndef OUT_VOLUME_IN_MIXER +#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1) for (int i = 0; i < NUM_USB_CHAN_OUT + 1; i++) { asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multOut),"r"(i)); } #endif -#ifndef IN_VOLUME_IN_MIXER +#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1) for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++) { asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multIn),"r"(i)); @@ -664,10 +693,16 @@ void decouple(chanend c_mix_out aud_to_host_flag = 0; SET_SHARED_GLOBAL(g_aud_to_host_flag, aud_to_host_flag); - /* NOTE: IN EP not marked ready at this point - Initial size of zero buffer not known + /* NOTE: For UAC2 IN EP not marked ready at this point - Initial size of zero buffer not known * since we don't know the USB bus-speed yet. * The host will send a SetAltInterface before streaming which will lead to this core * getting a SET_CHANNEL_COUNT_IN. This will setup the EP for the first packet */ +#if (AUDIO_CLASS == 1) + /* For UAC1 we know we only run at FS */ + /* Set buffer back to zeros buffer */ + SET_SHARED_GLOBAL(g_aud_to_host_buffer, g_aud_to_host_zeros); + SetupZerosSendBuffer(aud_to_host_usb_ep, sampFreq, g_curSubSlot_In); +#endif #endif while(1) @@ -687,6 +722,7 @@ void decouple(chanend c_mix_out /* Check for freq change or other update */ GET_SHARED_GLOBAL(tmp, g_freqChange_flag); +#if MIN_FREQ != MAX_FREQ if (tmp == SET_SAMPLE_FREQ) { SET_SHARED_GLOBAL(g_freqChange_flag, 0); @@ -734,7 +770,10 @@ void decouple(chanend c_mix_out speedRem = 0; continue; } - else if(tmp == SET_STREAM_FORMAT_IN) + else +#endif +#if (AUDIO_CLASS == 2) + if(tmp == SET_STREAM_FORMAT_IN) { unsigned dataFormat, usbSpeed; @@ -790,6 +829,7 @@ void decouple(chanend c_mix_out SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start); + /* NOTE, this is potentially usefull for UAC1 */ unpackState = 0; outUnderflow = 1; @@ -819,6 +859,7 @@ void decouple(chanend c_mix_out SET_SHARED_GLOBAL(g_freqChange, 0); ENABLE_INTERRUPTS(); } +#endif } #if (NUM_USB_CHAN_OUT > 0) @@ -865,7 +906,7 @@ void decouple(chanend c_mix_out space_left = aud_from_host_fifo_end - g_aud_from_host_wrptr; } - if (space_left <= 0 || space_left >= MAX_USB_AUD_PACKET_SIZE) + if (space_left <= 0 || space_left >= MAX_DEVICE_AUD_PACKET_SIZE_OUT) { SET_SHARED_GLOBAL(g_aud_from_host_buffer, aud_from_host_wrptr); XUD_SetReady_OutPtr(aud_from_host_usb_ep, aud_from_host_wrptr+4); @@ -890,8 +931,8 @@ void decouple(chanend c_mix_out GET_SHARED_GLOBAL(aud_from_host_rdptr, g_aud_from_host_rdptr); space_left = aud_from_host_rdptr - aud_from_host_wrptr; if (space_left <= 0) - space_left += BUFF_SIZE_OUT*4; - if (space_left >= (BUFF_SIZE_OUT*4/2)) + space_left += BUFF_SIZE_OUT; + if (space_left >= (BUFF_SIZE_OUT/2)) { /* Come out of OUT overflow state */ outOverflow = 0; @@ -907,10 +948,10 @@ void decouple(chanend c_mix_out #if (NUM_USB_CHAN_IN > 0) { /* Check if buffer() has sent a packet to host - uses shared mem flag to save chanends */ - int tmp; - GET_SHARED_GLOBAL(tmp, g_aud_to_host_flag); + int sentPkt; + GET_SHARED_GLOBAL(sentPkt, g_aud_to_host_flag); //case inuint_byref(c_buf_in, tmp): - if (tmp) + if (sentPkt) { /* Signals that the IN endpoint has sent data from the passed buffer */ /* Reset flag */ @@ -928,7 +969,7 @@ void decouple(chanend c_mix_out fill_level = aud_to_host_wrptr - aud_to_host_rdptr; if (fill_level < 0) - fill_level += BUFF_SIZE_IN*4; + fill_level += BUFF_SIZE_IN; if (fill_level >= IN_BUFFER_PREFILL) { diff --git a/module_usb_audio/usb_buffer/interrupt.h b/module_usb_audio/usb_buffer/interrupt.h index a65a9ad4..477d55e7 100644 --- a/module_usb_audio/usb_buffer/interrupt.h +++ b/module_usb_audio/usb_buffer/interrupt.h @@ -81,6 +81,7 @@ #define do_interrupt_handler(f,args) \ asm(ISSUE_MODE_SINGLE\ ".align 4\n" \ + ".cc_top __"#f"_handler.function,__"#f"_handler\n" \ "__" #f "_handler:\n" \ "ENTSP_lu6 0\n" \ "kentsp " #args "/2*2 + 20\n" \ @@ -91,7 +92,8 @@ restore_state(f,args) \ "krestsp " #args "/2*2 + 20 \n" \ "__kret:\n" \ - "kret\n"); + "kret\n" \ + ".cc_bottom __"#f"_handler.function"); #define register_interrupt_handler(f, args, nstackwords) \ asm (" .section .dp.data, \"adw\", @progbits\n" \ @@ -99,7 +101,7 @@ " .globl __" #f "_handler\n" \ " .align 8\n" \ "__" #f "_kernel_stack:\n" \ - " .space " #nstackwords ", 0\n" \ + " .space " #nstackwords ", 0\n" \ "__" #f "_kernel_stack_end:\n" \ " .space 4\n"\ " .text\n"); \ diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 72b85491..98cd678f 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -305,6 +305,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, { unsigned cmd = inuint(c_aud_ctl); +#if MAX_FREQ != MIN_FREQ if(cmd == SET_SAMPLE_FREQ) { unsigned receivedSampleFreq = inuint(c_aud_ctl); @@ -344,7 +345,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, * handshake elsewhere */ SET_SHARED_GLOBAL(g_freqChange_sampFreq, receivedSampleFreq); } - else if(cmd == SET_STREAM_FORMAT_IN) + else +#endif +#if (AUDIO_CLASS == 2) + if(cmd == SET_STREAM_FORMAT_IN) { unsigned formatChange_DataFormat = inuint(c_aud_ctl); unsigned formatChange_NumChans = inuint(c_aud_ctl); @@ -356,8 +360,10 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, SET_SHARED_GLOBAL(g_formatChange_DataFormat, formatChange_DataFormat); SET_SHARED_GLOBAL(g_formatChange_SampRes, formatChange_SampRes); } + /* FIXME when FB EP is enabled there is no inital XUD_SetReady */ else if (cmd == SET_STREAM_FORMAT_OUT) { + XUD_BusSpeed_t busSpeed; unsigned formatChange_DataFormat = inuint(c_aud_ctl); unsigned formatChange_NumChans = inuint(c_aud_ctl); @@ -385,6 +391,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, } #endif } +#endif /* Pass on sample freq change to decouple() via global flag (saves a chanend) */ /* Note: freqChange flags now used to communicate other commands also */ SET_SHARED_GLOBAL0(g_freqChange, cmd); /* Set command */ From 6ab9bef80c48c33915a6a3a08aeee35fe2f1daa5 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Tue, 6 Dec 2016 14:41:46 +0000 Subject: [PATCH 40/59] Remove I2S_RATE_SCALING define Just use the I2S_DOWNSAMPLE_FACTOR define now. --- module_usb_audio/audio_io/audio_io.xc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 6b20ecf8..562e607e 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -34,11 +34,6 @@ #ifndef I2S_DOWNSAMPLE_FACTOR #define I2S_DOWNSAMPLE_FACTOR (1) #endif -#define I2S_RATE_SCALING (I2S_DOWNSAMPLE_FACTOR) - -#if I2S_RATE_SCALING != I2S_DOWNSAMPLE_FACTOR -#error "Unsupported I2S rate scaling and downsampling configuration" -#endif #if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) #error "Not enough USB input channels to support number of I2S and PDM inputs" @@ -962,7 +957,7 @@ chanend ?c_config, chanend ?c unsigned adatMultiple = 0; #endif - unsigned curSamFreq = DEFAULT_FREQ * I2S_RATE_SCALING; + unsigned curSamFreq = DEFAULT_FREQ * I2S_DOWNSAMPLE_FACTOR; unsigned curSamRes_DAC = STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS; /* Default to something reasonable */ unsigned curSamRes_ADC = STREAM_FORMAT_INPUT_1_RESOLUTION_BITS; /* Default to something reasonable - note, currently this never changes*/ unsigned command; @@ -1117,7 +1112,7 @@ chanend ?c_config, chanend ?c { /* TODO wait for good mclk instead of delay */ /* No delay for DFU modes */ - if (((curSamFreq / I2S_RATE_SCALING) != AUDIO_REBOOT_FROM_DFU) && ((curSamFreq / I2S_RATE_SCALING) != AUDIO_STOP_FOR_DFU) && command) + if (((curSamFreq / I2S_DOWNSAMPLE_FACTOR) != AUDIO_REBOOT_FROM_DFU) && ((curSamFreq / I2S_DOWNSAMPLE_FACTOR) != AUDIO_STOP_FOR_DFU) && command) { #if 0 /* User should ensure MCLK is stable in AudioHwConfig */ @@ -1201,7 +1196,7 @@ chanend ?c_config, chanend ?c if(command == SET_SAMPLE_FREQ) { - curSamFreq = inuint(c_mix_out) * I2S_RATE_SCALING; + curSamFreq = inuint(c_mix_out) * I2S_DOWNSAMPLE_FACTOR; } else if(command == SET_STREAM_FORMAT_OUT) { @@ -1214,7 +1209,7 @@ chanend ?c_config, chanend ?c } /* Currently no more audio will happen after this point */ - if ((curSamFreq / I2S_RATE_SCALING) == AUDIO_STOP_FOR_DFU) + if ((curSamFreq / I2S_DOWNSAMPLE_FACTOR) == AUDIO_STOP_FOR_DFU) { outct(c_mix_out, XS1_CT_END); From c5eb740637012a8b704b02ce16774782d2d34af7 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Tue, 6 Dec 2016 14:30:15 +0000 Subject: [PATCH 41/59] Call DS3 functions on incoming I2S samples Downsampling is enabled only when I2S_DOWNSAMPLE_FACTOR is defined as> 1 (must be 3). --- module_usb_audio/audio_io/audio_io.xc | 92 ++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 562e607e..13b5565e 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -12,6 +12,8 @@ #include #include #include +#include +#include "xassert.h" #include "devicedefines.h" @@ -35,6 +37,14 @@ #define I2S_DOWNSAMPLE_FACTOR (1) #endif +#if (I2S_DOWNSAMPLE_FACTOR != 1) && (I2S_DOWNSAMPLE_FACTOR != 3) +#error "Unsupported I2S downsampling configuration" +#endif + +#if (I2S_DOWNSAMPLE_FACTOR > 1) && (I2S_CHANS_DAC > 2) +#error "I2S downsampling only supports stereo I2S" +#endif + #if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) #error "Not enough USB input channels to support number of I2S and PDM inputs" #endif @@ -50,6 +60,15 @@ static unsigned samplesOut[32]; static unsigned samplesIn[2][I2S_DOWNSAMPLE_FACTOR][32]; static int downsamplingCounter = 0; +#if (I2S_DOWNSAMPLE_FACTOR > 1) +#include "src.h" +/* [Number of I2S channels][Number of samples/phases][Taps per phase] */ +static union ds3Data +{ + long long doubleWordAlignmentEnsured; + int32_t delayLine[PDM_MIC_INDEX][I2S_DOWNSAMPLE_FACTOR][24]; +} ds3Data; +#endif #if (DSD_CHANS_DAC != 0) extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; @@ -280,8 +299,6 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con #else inuint(c_out); #endif - // TODO: run ds3 here - // Pass samplesIn[readBuffNo][0,I2S_DOWNSAMPLE_FACTOR][i]) to ds3() UserBufferManagement(samplesOut, samplesIn[readBuffNo][downsamplingCounter], i_audMan); #if NUM_USB_CHAN_IN > 0 @@ -486,6 +503,11 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, } #endif +#if (I2S_DOWNSAMPLE_FACTOR > 1) + const int ds3DelayLine_zero = {0}; + memcpy(&ds3Data.delayLine, &ds3DelayLine_zero, sizeof ds3DelayLine_zero); +#endif + unsigned command = DoSampleTransfer(c_out, readBuffNo, underflowWord, i_audMan); #ifdef ADAT_TX @@ -635,6 +657,39 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, /* Note the use of readBuffNo changes based on frameCount */ samplesIn[buffIndex][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 0, 2, 4.. on each line. } +#if (I2S_DOWNSAMPLE_FACTOR > 1) + switch (downsamplingCounter) + { + case 0: + samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = 0; + samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = + src_ds3_voice_add_sample( + samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], + ds3Data.delayLine[0][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); + break; + case 1: + samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = + src_ds3_voice_add_sample( + samplesIn[readBuffNo][0][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], + ds3Data.delayLine[0][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); + break; + case 2: + samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = + src_ds3_voice_add_final_sample( + samplesIn[readBuffNo][1][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], + ds3Data.delayLine[0][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); + break; + default: + unreachable("downsamplingCounter out of range"); + break; + } +#endif // (I2S_DOWNSAMPLE_FACTOR > 1) #endif @@ -736,6 +791,39 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. } +#if (I2S_DOWNSAMPLE_FACTOR > 1) + switch (downsamplingCounter) + { + case 0: + samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = 0; + samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))] = + src_ds3_voice_add_sample( + samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], + ds3Data.delayLine[1][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))]); + break; + case 1: + samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))] = + src_ds3_voice_add_sample( + samplesIn[readBuffNo][0][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], + ds3Data.delayLine[1][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))]); + break; + case 2: + samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))] = + src_ds3_voice_add_final_sample( + samplesIn[readBuffNo][1][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], + ds3Data.delayLine[1][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))]); + break; + default: + unreachable("downsamplingCounter out of range"); + break; + } +#endif // (I2S_DOWNSAMPLE_FACTOR > 1) #endif #ifndef CODEC_MASTER From 6a4c998585e28b90e1ffcf535247899785706e26 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 6 Dec 2016 16:17:16 +0000 Subject: [PATCH 42/59] Rm print --- module_usb_audio/endpoint0/endpoint0.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/module_usb_audio/endpoint0/endpoint0.c b/module_usb_audio/endpoint0/endpoint0.c index fee7055f..f7a46f81 100755 --- a/module_usb_audio/endpoint0/endpoint0.c +++ b/module_usb_audio/endpoint0/endpoint0.c @@ -643,8 +643,6 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, if (!DFU_mode_active) { #endif - - printintln(2); #ifdef AUDIO_CLASS_FALLBACK /* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */ result = USB_StandardRequests(ep0_out, ep0_in, From a454308ac1999b8f3efec6fa7c2d19ca4dfaeac9 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 6 Dec 2016 16:17:41 +0000 Subject: [PATCH 43/59] Fixed build issue (missing var) --- module_usb_audio/usb_buffer/decouple.xc | 1 + 1 file changed, 1 insertion(+) diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index a49e016e..54aaefe2 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -200,6 +200,7 @@ __builtin_unreachable(); { #pragma xta endpoint "mixer_request" int sample; + int mult; int h; unsigned l; From 56935a7ff2eb1cdb5935a0bbe185f757b510e835 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Tue, 6 Dec 2016 16:17:56 +0000 Subject: [PATCH 44/59] XUD in HP --- module_usb_audio/main.xc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index da81c579..868011c1 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -318,7 +318,7 @@ VENDOR_REQUESTS_PARAMS_DEC_ clk, 1, XUD_SPEED_HS, XUD_PWR_CFG); #else { -//set_core_high_priority_on(); + set_core_high_priority_on(); XUD_Manager(c_xud_out, ENDPOINT_COUNT_OUT, c_xud_in, ENDPOINT_COUNT_IN, c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, clk, 1, XUD_SPEED_FS, XUD_PWR_CFG); From bcc9c23a71803532863bafc53dc463ee83f184ec Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Tue, 6 Dec 2016 17:29:11 +0000 Subject: [PATCH 45/59] Memory optimisation of I2S DS3 integration --- module_usb_audio/audio_io/audio_io.xc | 132 +++++++++++--------------- 1 file changed, 54 insertions(+), 78 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 13b5565e..65bd1b48 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -41,10 +41,6 @@ #error "Unsupported I2S downsampling configuration" #endif -#if (I2S_DOWNSAMPLE_FACTOR > 1) && (I2S_CHANS_DAC > 2) -#error "I2S downsampling only supports stereo I2S" -#endif - #if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) #error "Not enough USB input channels to support number of I2S and PDM inputs" #endif @@ -57,17 +53,18 @@ static unsigned samplesOut[32]; /* Two buffers for ADC data to allow for DAC and ADC ports being offset */ -static unsigned samplesIn[2][I2S_DOWNSAMPLE_FACTOR][32]; +static unsigned samplesIn[2][32]; static int downsamplingCounter = 0; #if (I2S_DOWNSAMPLE_FACTOR > 1) #include "src.h" -/* [Number of I2S channels][Number of samples/phases][Taps per phase] */ static union ds3Data { long long doubleWordAlignmentEnsured; - int32_t delayLine[PDM_MIC_INDEX][I2S_DOWNSAMPLE_FACTOR][24]; + /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ + int32_t delayLine[I2S_CHANS_DAC][I2S_DOWNSAMPLE_FACTOR][24]; } ds3Data; +static int64_t ds3Sum[I2S_CHANS_DAC]; #endif #if (DSD_CHANS_DAC != 0) @@ -299,18 +296,18 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con #else inuint(c_out); #endif - UserBufferManagement(samplesOut, samplesIn[readBuffNo][downsamplingCounter], i_audMan); + UserBufferManagement(samplesOut, samplesIn[readBuffNo], i_audMan); #if NUM_USB_CHAN_IN > 0 #pragma loop unroll for(int i = 0; i < I2S_CHANS_ADC; i++) { - outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); + outuint(c_out, samplesIn[readBuffNo][i]); } #pragma loop unroll for (int i = PDM_MIC_INDEX; i < (NUM_PDM_MICS + PDM_MIC_INDEX); i++) { - outuint(c_out, samplesIn[readBuffNo][downsamplingCounter][i]); + outuint(c_out, samplesIn[readBuffNo][i]); } #endif } @@ -504,8 +501,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if (I2S_DOWNSAMPLE_FACTOR > 1) - const int ds3DelayLine_zero = {0}; - memcpy(&ds3Data.delayLine, &ds3DelayLine_zero, sizeof ds3DelayLine_zero); + memset(&ds3Data.delayLine, 0, sizeof ds3Data); #endif unsigned command = DoSampleTransfer(c_out, readBuffNo, underflowWord, i_audMan); @@ -639,6 +635,12 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, else #endif { +#if (I2S_DOWNSAMPLE_FACTOR > 1) + if (0 == downsamplingCounter) + { + memset(&ds3Sum, 0, sizeof ds3Sum); + } +#endif #if (I2S_CHANS_ADC != 0) /* Input previous L sample into L in buffer */ index = 0; @@ -655,41 +657,28 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++])); /* Note the use of readBuffNo changes based on frameCount */ - samplesIn[buffIndex][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 0, 2, 4.. on each line. - } + samplesIn[buffIndex][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 0, 2, 4.. on each line. #if (I2S_DOWNSAMPLE_FACTOR > 1) - switch (downsamplingCounter) - { - case 0: - samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = 0; - samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = - src_ds3_voice_add_sample( - samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], - ds3Data.delayLine[0][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], - samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); - break; - case 1: - samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = - src_ds3_voice_add_sample( - samplesIn[readBuffNo][0][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], - ds3Data.delayLine[0][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], - samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); - break; - case 2: - samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = + if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) + { + samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = src_ds3_voice_add_final_sample( - samplesIn[readBuffNo][1][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], - ds3Data.delayLine[0][downsamplingCounter], + ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], + ds3Data.delayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], src_ds3_voice_coefs[downsamplingCounter], - samplesIn[readBuffNo][downsamplingCounter][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); - break; - default: - unreachable("downsamplingCounter out of range"); - break; - } + samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); + } + else + { + ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = + src_ds3_voice_add_sample( + ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], + ds3Data.delayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); + } #endif // (I2S_DOWNSAMPLE_FACTOR > 1) + } #endif @@ -771,7 +760,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #pragma loop unroll for(int i = PDM_MIC_INDEX; i < (NUM_PDM_MICS + PDM_MIC_INDEX); i++) { - c_pdm_pcm :> samplesIn[readBuffNo][downsamplingCounter][i]; + c_pdm_pcm :> samplesIn[readBuffNo][i]; } } } @@ -788,42 +777,29 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, unsigned sample; asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++])); - samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. + samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. +#if (I2S_DOWNSAMPLE_FACTOR > 1) + if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) + { + samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = + src_ds3_voice_add_final_sample( + ds3Sum[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i], + ds3Data.delayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); + } + else + { + ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = + src_ds3_voice_add_sample( + ds3Sum[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i], + ds3Data.delayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], + src_ds3_voice_coefs[downsamplingCounter], + samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); + } +#endif // (I2S_DOWNSAMPLE_FACTOR > 1) } -#if (I2S_DOWNSAMPLE_FACTOR > 1) - switch (downsamplingCounter) - { - case 0: - samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = 0; - samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))] = - src_ds3_voice_add_sample( - samplesIn[readBuffNo][2][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], - ds3Data.delayLine[1][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], - samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))]); - break; - case 1: - samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))] = - src_ds3_voice_add_sample( - samplesIn[readBuffNo][0][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], - ds3Data.delayLine[1][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], - samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))]); - break; - case 2: - samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))] = - src_ds3_voice_add_final_sample( - samplesIn[readBuffNo][1][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))], - ds3Data.delayLine[1][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], - samplesIn[buffIndex][downsamplingCounter][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))]); - break; - default: - unreachable("downsamplingCounter out of range"); - break; - } -#endif // (I2S_DOWNSAMPLE_FACTOR > 1) #endif #ifndef CODEC_MASTER From 3fe1a6e8cc5a49d4b4461d03e2bbcd73c3b0229e Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 7 Dec 2016 10:11:47 +0000 Subject: [PATCH 46/59] Allow mono downsampling mode Allows for reduced resource usage when I2S is used as an input to a mono AEC. --- module_usb_audio/audio_io/audio_io.xc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 65bd1b48..cf442ea9 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -37,6 +37,16 @@ #define I2S_DOWNSAMPLE_FACTOR (1) #endif +#ifndef I2S_DOWNSAMPLE_MONO +#define I2S_DOWNSAMPLE_MONO (0) +#endif + +#if (I2S_DOWNSAMPLE_MONO == 1) +#define I2S_DOWNSAMPLE_CHANS (I2S_CHANS_DAC/2) +#else +#define I2S_DOWNSAMPLE_CHANS I2S_CHANS_DAC +#endif + #if (I2S_DOWNSAMPLE_FACTOR != 1) && (I2S_DOWNSAMPLE_FACTOR != 3) #error "Unsupported I2S downsampling configuration" #endif @@ -62,9 +72,9 @@ static union ds3Data { long long doubleWordAlignmentEnsured; /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ - int32_t delayLine[I2S_CHANS_DAC][I2S_DOWNSAMPLE_FACTOR][24]; + int32_t delayLine[I2S_DOWNSAMPLE_CHANS][I2S_DOWNSAMPLE_FACTOR][24]; } ds3Data; -static int64_t ds3Sum[I2S_CHANS_DAC]; +static int64_t ds3Sum[I2S_DOWNSAMPLE_CHANS]; #endif #if (DSD_CHANS_DAC != 0) @@ -778,7 +788,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, asm volatile("in %0, res[%1]" : "=r"(sample) : "r"(p_i2s_adc[index++])); samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. -#if (I2S_DOWNSAMPLE_FACTOR > 1) +#if ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO) if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) { samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = @@ -797,7 +807,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } -#endif // (I2S_DOWNSAMPLE_FACTOR > 1) +#endif // ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO) } #endif From 5e09197c158bd84bc79dcf2237120cb9813f1a1d Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 7 Dec 2016 10:14:51 +0000 Subject: [PATCH 47/59] Remove unused include --- module_usb_audio/audio_io/audio_io.xc | 1 - 1 file changed, 1 deletion(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index cf442ea9..2f6fb0e2 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -13,7 +13,6 @@ #include #include #include -#include "xassert.h" #include "devicedefines.h" From b0451af03b44d59d8a3069c4b0445056e438e9f0 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 7 Dec 2016 11:30:19 +0000 Subject: [PATCH 48/59] Resolved issue with not starting up FB pipe in UAC1 mode --- module_usb_audio/usb_buffer/usb_buffer.xc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 98cd678f..10026471 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -258,6 +258,11 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, XUD_SetReady_In(ep_hid, g_hidData, 1); #endif +#if (AUDIO_CLASS == 1) + /* In UAC1 we dont use a stream start event (and we are always FS) so mark FB EP ready now */ + XUD_SetReady_In(ep_aud_fb, fb_clocks, 3); +#endif + while(1) { XUD_Result_t result; From 4b9e3235931ba3c3a144f43fffa9eec9c3644779 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 7 Dec 2016 11:41:05 +0000 Subject: [PATCH 49/59] Move defines and checks to expected places --- module_usb_audio/audio_io/audio_io.xc | 26 -------------------- module_usb_audio/devicedefines.h | 35 +++++++++++++++++++++++++++ module_usb_audio/warnings.xc | 6 +++++ 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 2f6fb0e2..ba067156 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -32,32 +32,6 @@ #include "commands.h" #include "xc_ptr.h" -#ifndef I2S_DOWNSAMPLE_FACTOR -#define I2S_DOWNSAMPLE_FACTOR (1) -#endif - -#ifndef I2S_DOWNSAMPLE_MONO -#define I2S_DOWNSAMPLE_MONO (0) -#endif - -#if (I2S_DOWNSAMPLE_MONO == 1) -#define I2S_DOWNSAMPLE_CHANS (I2S_CHANS_DAC/2) -#else -#define I2S_DOWNSAMPLE_CHANS I2S_CHANS_DAC -#endif - -#if (I2S_DOWNSAMPLE_FACTOR != 1) && (I2S_DOWNSAMPLE_FACTOR != 3) -#error "Unsupported I2S downsampling configuration" -#endif - -#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) -#error "Not enough USB input channels to support number of I2S and PDM inputs" -#endif - -#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (NUM_PDM_MICS + PDM_MIC_INDEX))) -#error "PDM mic inputs mapping exceeds bounds of USB input channel" -#endif - /* TODO 32 is max expected channels */ static unsigned samplesOut[32]; diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index ffc11fde..ca7ac85c 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -121,6 +121,41 @@ #define I2S_WIRES_ADC (I2S_CHANS_ADC / I2S_CHANS_PER_FRAME) #endif +/** + * @brief Incoming I2S (device to host) channels can be downsampled by a factor of 3. + * + * Default: 1 i.e. downsampling is disabled. + */ +#ifndef I2S_DOWNSAMPLE_FACTOR +#define I2S_DOWNSAMPLE_FACTOR (1) +#else + #if (I2S_DOWNSAMPLE_FACTOR != 3) + #error Unsupported I2S downsampling configuration + #endif +#endif + +/** + * @brief Only downsample one channel per I2S frame. + * + * Default: 0 i.e. mono mode is disabled, all channels will be downsampled. + */ +#ifndef I2S_DOWNSAMPLE_MONO +#define I2S_DOWNSAMPLE_MONO (0) +#endif + +/** + * @brief Number of incoming (device to host) I2S channels to downsample. + * + * Default: The number of I2S incoming channels, or half this if mono downsampling is enabled. + */ +#if (I2S_DOWNSAMPLE_MONO == 1) + #define I2S_DOWNSAMPLE_CHANS (I2S_CHANS_ADC / 2) + #if ((I2S_DOWNSAMPLE_FACTOR > 1) && (I2S_MODE_TDM == 1)) + #error Mono I2S downsampling is not avaliable in TDM mode + #endif +#else +#define I2S_DOWNSAMPLE_CHANS I2S_CHANS_ADC +#endif /** * @brief Max supported sample frequency for device (Hz). Default: 192000 diff --git a/module_usb_audio/warnings.xc b/module_usb_audio/warnings.xc index c1646213..7c0f753d 100644 --- a/module_usb_audio/warnings.xc +++ b/module_usb_audio/warnings.xc @@ -72,4 +72,10 @@ Warnings relating to configuration defines located in this XC source file rather #error NUM_USB_CHAN_IN_FS expected to be less than or equal to NUM_USB_CHAN_IN #endif +#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) +#error Not enough USB input channels to support number of I2S and PDM inputs +#endif +#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (NUM_PDM_MICS + PDM_MIC_INDEX))) +#error PDM mic inputs mapping exceeds bounds of USB input channel +#endif From 16e75552d8a811b9f0d27948699a3c3783090ab3 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 7 Dec 2016 13:01:26 +0000 Subject: [PATCH 50/59] removed print inc --- module_usb_audio/pdm_mics/pdm_mic.xc | 2 -- 1 file changed, 2 deletions(-) diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index a2c5d4e3..1e9c2147 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -189,8 +189,6 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) #error MAX_FREQ > 48000 NOT CURRENTLY SUPPORTED #endif -#include "print.h" - void pdm_mic(streaming chanend c_ds_output[2]) { streaming chan c_4x_pdm_mic_0; From 4132c6989aab6b3a9a6eb98734624a238c2e98df Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 7 Dec 2016 15:19:01 +0000 Subject: [PATCH 51/59] Resolved build issue with UAC1 builds when MAX_FREQ != MIN_FREQ --- module_usb_audio/usb_buffer/decouple.xc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index 54aaefe2..2cae8e87 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -771,9 +771,11 @@ void decouple(chanend c_mix_out speedRem = 0; continue; } - else #endif #if (AUDIO_CLASS == 2) +#if (MIN_FREQ != MAX_FREQ) + else +#endif if(tmp == SET_STREAM_FORMAT_IN) { unsigned dataFormat, usbSpeed; From 798e5b07f020df8b127249f7336ec7841e84280d Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 7 Dec 2016 16:55:49 +0000 Subject: [PATCH 52/59] Fixed up I2S_DOWNSAMPLE_FACTOR error check --- module_usb_audio/devicedefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 7ddc27be..6df08a43 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -129,7 +129,7 @@ #ifndef I2S_DOWNSAMPLE_FACTOR #define I2S_DOWNSAMPLE_FACTOR (1) #else - #if (I2S_DOWNSAMPLE_FACTOR != 3) + #if (I2S_DOWNSAMPLE_FACTOR != 3) && (I2S_DOWNSAMPLE_FACTOR != 1) #error Unsupported I2S downsampling configuration #endif #endif From f1b7ee13ba0d0b3d1721b12f328f3cd1a7481dea Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Wed, 7 Dec 2016 17:25:38 +0000 Subject: [PATCH 53/59] Fixed non-streaming issue on some builds after merge --- module_usb_audio/audio_io/audio_io.xc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 90001519..26431949 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -302,12 +302,7 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con #if NUM_USB_CHAN_IN > 0 #pragma loop unroll - for(int i = 0; i < I2S_CHANS_ADC; i++) - { - outuint(c_out, samplesIn[readBuffNo][i]); - } -#pragma loop unroll - for (int i = PDM_MIC_INDEX; i < (NUM_PDM_MICS + PDM_MIC_INDEX); i++) + for(int i = 0; i < NUM_USB_CHAN_IN; i++) { outuint(c_out, samplesIn[readBuffNo][i]); } From 10efbb709eda99b1469751e80b56380f221cfeb3 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 8 Dec 2016 11:50:38 +0000 Subject: [PATCH 54/59] Removed erroneous error msgs --- module_usb_audio/warnings.xc | 7 ------- 1 file changed, 7 deletions(-) diff --git a/module_usb_audio/warnings.xc b/module_usb_audio/warnings.xc index 7c0f753d..ee85a3ca 100644 --- a/module_usb_audio/warnings.xc +++ b/module_usb_audio/warnings.xc @@ -72,10 +72,3 @@ Warnings relating to configuration defines located in this XC source file rather #error NUM_USB_CHAN_IN_FS expected to be less than or equal to NUM_USB_CHAN_IN #endif -#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (I2S_CHANS_ADC + NUM_PDM_MICS))) -#error Not enough USB input channels to support number of I2S and PDM inputs -#endif - -#if (NUM_USB_CHAN_IN && (NUM_USB_CHAN_IN < (NUM_PDM_MICS + PDM_MIC_INDEX))) -#error PDM mic inputs mapping exceeds bounds of USB input channel -#endif From a699c51075ab67580e0c51e8648d142dfe860a80 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 8 Dec 2016 11:51:11 +0000 Subject: [PATCH 55/59] Tidy up MIN/MAX freq checks --- module_usb_audio/usb_buffer/decouple.xc | 3 +-- module_usb_audio/usb_buffer/usb_buffer.xc | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index 2cae8e87..d683508e 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -723,13 +723,12 @@ void decouple(chanend c_mix_out /* Check for freq change or other update */ GET_SHARED_GLOBAL(tmp, g_freqChange_flag); -#if MIN_FREQ != MAX_FREQ +#if (MIN_FREQ != MAX_FREQ) if (tmp == SET_SAMPLE_FREQ) { SET_SHARED_GLOBAL(g_freqChange_flag, 0); GET_SHARED_GLOBAL(sampFreq, g_freqChange_sampFreq); - /* Pass on to mixer */ DISABLE_INTERRUPTS(); inuint(c_mix_out); diff --git a/module_usb_audio/usb_buffer/usb_buffer.xc b/module_usb_audio/usb_buffer/usb_buffer.xc index 10026471..754f9e55 100644 --- a/module_usb_audio/usb_buffer/usb_buffer.xc +++ b/module_usb_audio/usb_buffer/usb_buffer.xc @@ -310,7 +310,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, { unsigned cmd = inuint(c_aud_ctl); -#if MAX_FREQ != MIN_FREQ +#if (MAX_FREQ != MIN_FREQ) if(cmd == SET_SAMPLE_FREQ) { unsigned receivedSampleFreq = inuint(c_aud_ctl); From b70dab153231597a8626edbfeb0ad8a06955d13d Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 8 Dec 2016 11:51:29 +0000 Subject: [PATCH 56/59] Fixed mic processing calls --- module_usb_audio/pdm_mics/pdm_mic.xc | 6 +++--- module_usb_audio/pdm_mics/xua_pdm_mic.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index 1e9c2147..2e3d7b7c 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -124,7 +124,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) /* Run user code */ /* TODO ideally processing done inplace - it then doesn't matter if it is run or not */ #ifdef MIC_PROCESSING_USE_INTERFACE - i_mic_process.transfer_buffers(current, output); + i_mic_process.transfer_buffers(current); #else user_pdm_process(current); #endif @@ -152,7 +152,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) /* Run user code */ #ifdef MIC_PROCESSING_USE_INTERFACE - i_mic_process.transfer_buffers(current, output); + i_mic_process.transfer_buffers(current); #else user_pdm_process(current); #endif @@ -175,7 +175,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio) /* Run user code */ #ifdef MIC_PROCESSING_USE_INTERFACE - i_mic_process.transfer_buffers(current, output); + i_mic_process.transfer_buffers(current); #else user_pdm_process(current); #endif diff --git a/module_usb_audio/pdm_mics/xua_pdm_mic.h b/module_usb_audio/pdm_mics/xua_pdm_mic.h index 525122c5..e962c6bb 100644 --- a/module_usb_audio/pdm_mics/xua_pdm_mic.h +++ b/module_usb_audio/pdm_mics/xua_pdm_mic.h @@ -5,7 +5,7 @@ /* Interface based user processing */ typedef interface mic_process_if { - void transfer_buffers(mic_array_frame_time_domain * unsafe audio, int output[]); + void transfer_buffers(mic_array_frame_time_domain * unsafe audio); void init(); } mic_process_if; From 5c46cc476d3753aea373fbea9e222ada7c91e564 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Thu, 8 Dec 2016 13:01:47 +0000 Subject: [PATCH 57/59] Update DS3 library calls to use new API --- module_usb_audio/audio_io/audio_io.xc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 26431949..b685b508 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -662,7 +662,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ds3_voice_add_final_sample( ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.delayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], + src_ff3v_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } else @@ -671,7 +671,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ds3_voice_add_sample( ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.delayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], + src_ff3v_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } #endif // (I2S_DOWNSAMPLE_FACTOR > 1) @@ -782,7 +782,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ds3_voice_add_final_sample( ds3Sum[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.delayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], + src_ff3v_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } else @@ -791,7 +791,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ds3_voice_add_sample( ds3Sum[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.delayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][downsamplingCounter], - src_ds3_voice_coefs[downsamplingCounter], + src_ff3v_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } #endif // ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO) From 94d54f992d0d76f970b252d0efbbab4df4667fed Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Thu, 8 Dec 2016 13:23:23 +0000 Subject: [PATCH 58/59] Moved to lib_mic_array v3 API --- module_usb_audio/pdm_mics/pdm_mic.xc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/pdm_mics/pdm_mic.xc b/module_usb_audio/pdm_mics/pdm_mic.xc index 2e3d7b7c..37953754 100644 --- a/module_usb_audio/pdm_mics/pdm_mic.xc +++ b/module_usb_audio/pdm_mics/pdm_mic.xc @@ -215,9 +215,9 @@ void pdm_mic(streaming chanend c_ds_output[2]) par { 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_NO_INTERNAL_CHANS); #if (NUM_PDM_MICS > 4) - 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], MIC_ARRAY_NO_INTERNAL_CHANS); #endif } } From 409b4c668aadaf995603584657099515f59f0706 Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 9 Dec 2016 15:03:17 +0000 Subject: [PATCH 59/59] Fixed USB Audio buffer size (word/byte) --- module_usb_audio/usb_buffer/decouple.xc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_usb_audio/usb_buffer/decouple.xc b/module_usb_audio/usb_buffer/decouple.xc index d683508e..d5e82184 100644 --- a/module_usb_audio/usb_buffer/decouple.xc +++ b/module_usb_audio/usb_buffer/decouple.xc @@ -69,8 +69,8 @@ unsigned g_numUsbChan_Out = NUM_USB_CHAN_OUT; unsigned g_numUsbChan_In = NUM_USB_CHAN_IN; /* Circular audio buffers */ -unsigned outAudioBuff[(BUFF_SIZE_OUT >> 2)+ (MAX_DEVICE_AUD_PACKET_SIZE_OUT >> 0)]; -unsigned audioBuffIn[(BUFF_SIZE_IN >> 2)+ (MAX_DEVICE_AUD_PACKET_SIZE_IN >> 0)]; +unsigned outAudioBuff[(BUFF_SIZE_OUT >> 2)+ (MAX_DEVICE_AUD_PACKET_SIZE_OUT >> 2)]; +unsigned audioBuffIn[(BUFF_SIZE_IN >> 2)+ (MAX_DEVICE_AUD_PACKET_SIZE_IN >> 2)]; /* Shift down accounts for bytes -> words */ unsigned inZeroBuff[(MAX_DEVICE_AUD_PACKET_SIZE_IN >> 2)];