From 04a6a7a370a0adcfcb4105adbdef168debb288cd Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Thu, 19 Jan 2017 17:46:40 +0000 Subject: [PATCH 1/4] Revert "Merge add_i2s_out_ds3 into master" a58b8c3bb9f00f8b052cc7fd89415e92674a644a --- module_usb_audio/audio_io/audio_io.xc | 56 +++++++++------------------ module_usb_audio/devicedefines.h | 20 ---------- 2 files changed, 19 insertions(+), 57 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index c002d218..57512d1b 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -58,27 +58,16 @@ static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)]; #endif static int inDownsamplingCounter = 0; -static int outDownsamplingCounter = 0; -#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) || (I2S_DOWNSAMPLE_FACTOR_OUT > 1) +#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) #include "src.h" static union ds3Data { long long doubleWordAlignmentEnsured; - /* delay lines = [Number of I2S channels][Number of samples/phases][Taps per phase] */ -#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) + /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ int32_t inputDelayLine[I2S_DOWNSAMPLE_CHANS_IN][I2S_DOWNSAMPLE_FACTOR_IN][24]; -#endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) -#if (I2S_DOWNSAMPLE_FACTOR_OUT > 1) - int32_t outputDelayLine[I2S_DOWNSAMPLE_CHANS_OUT][I2S_DOWNSAMPLE_FACTOR_OUT][24]; -#endif // (I2S_DOWNSAMPLE_FACTOR_OUT > 1) } ds3Data; -#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) static int64_t inputDs3Sum[I2S_DOWNSAMPLE_CHANS_IN]; #endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) -#if (I2S_DOWNSAMPLE_FACTOR_OUT > 1) -static int64_t outputDs3Sum[I2S_DOWNSAMPLE_CHANS_OUT]; -#endif // (I2S_DOWNSAMPLE_FACTOR_OUT > 1) -#endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) || (I2S_DOWNSAMPLE_FACTOR_OUT > 1) #if (DSD_CHANS_DAC != 0) extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; @@ -734,22 +723,20 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #pragma xta endpoint "i2s_output_l" #if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) - if ((I2S_DOWNSAMPLE_FACTOR_OUT - 1) == outDownsamplingCounter) - { - index = 0; + index = 0; #pragma loop unroll - /* Output "even" channel to DAC (i.e. left) */ - for(int i = 0; i < I2S_CHANS_DAC; i+=I2S_CHANS_PER_FRAME) - { - p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]); - } + /* Output "even" channel to DAC (i.e. left) */ + for(int i = 0; i < I2S_CHANS_DAC; i+=I2S_CHANS_PER_FRAME) + { + p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]); + } #endif #ifndef CODEC_MASTER - /* Clock out the LR Clock, the DAC data and Clock in the next sample into ADC */ - doI2SClocks(divide); + /* Clock out the LR Clock, the DAC data and Clock in the next sample into ADC */ + doI2SClocks(divide); #endif - } + #ifdef ADAT_TX TransferAdatTxSamples(c_adat_out, samplesOut, adatSmuxMode, 1); #endif @@ -870,24 +857,19 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, index = 0; #pragma xta endpoint "i2s_output_r" #if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) - if ((I2S_DOWNSAMPLE_FACTOR_OUT - 1) == outDownsamplingCounter) - { - /* Output "odd" channel to DAC (i.e. right) */ + /* Output "odd" channel to DAC (i.e. right) */ #pragma loop unroll - for(int i = 1; i < I2S_CHANS_DAC; i+=I2S_CHANS_PER_FRAME) - { - p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]); - } + for(int i = 1; i < I2S_CHANS_DAC; i+=I2S_CHANS_PER_FRAME) + { + p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]); + } #endif #ifndef CODEC_MASTER - doI2SClocks(divide); + doI2SClocks(divide); #endif - } - else - { - ++outDownsamplingCounter; - } + + } // !dsdMode #if (DSD_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT > 0) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 4ea7137f..b88d334b 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -134,19 +134,6 @@ #endif #endif -/** - * @brief Output I2S (host to device) channels can be downsampled by a factor of 3. - * - * Default: 1 i.e. downsampling is disabled. - */ -#ifndef I2S_DOWNSAMPLE_FACTOR_OUT -#define I2S_DOWNSAMPLE_FACTOR_OUT (1) -#else - #if (I2S_DOWNSAMPLE_FACTOR_OUT != 3) && (I2S_DOWNSAMPLE_FACTOR_OUT != 1) - #error Unsupported I2S output downsampling configuration - #endif -#endif - /** * @brief Only downsample one channel per input I2S frame. * @@ -170,13 +157,6 @@ #define I2S_DOWNSAMPLE_CHANS_IN I2S_CHANS_ADC #endif -/** - * @brief Number of output (host to device) I2S channels to downsample. - * - * Default: The number of I2S output channels. - */ -#define I2S_DOWNSAMPLE_CHANS_OUT I2S_CHANS_ADC - /** * @brief Max supported sample frequency for device (Hz). Default: 192000 */ From ca44477c3d39c4763dec5e73bdfe611f997d0bde Mon Sep 17 00:00:00 2001 From: Ross Owen Date: Fri, 20 Jan 2017 11:38:50 +0000 Subject: [PATCH 2/4] Comments only: UAC1 Descriptors --- module_usb_audio/endpoint0/descriptors.h | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index 4848825b..dd7d1347 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -2320,24 +2320,24 @@ unsigned char cfgDesc_Audio1[] = AC_LENGTH, UAC_CS_DESCTYPE_INTERFACE, 0x01, /* HEADER */ - 0x00, 0x01, /* Class spec revision - 1.0 */ + 0x00, 0x01, /* bcdADC */ (AC_TOTAL_LENGTH & 0xFF), /* wTotallength (Combined length of this descriptor and all Unit and Terminal Descriptors) */ (AC_TOTAL_LENGTH >> 8), /* wTotalLength */ - STREAMING_INTERFACES, /* Num streaming interfaces */ + STREAMING_INTERFACES, /* bInCollection (Num streaming interfaces) */ #if (NUM_USB_CHAN_OUT > 0) - 0x01, /* AudioStreaming interface 1 belongs to AC interface */ + 0x01, /* baInterfaceNr(1) AudioStreaming interface 1 belongs to AC interface */ #endif #if (NUM_USB_CHAN_IN > 0) - (OUTPUT_INTERFACES_A1 + 1), /* AudioStreaming interface 2 belongs to AC interface */ + (OUTPUT_INTERFACES_A1 + 1), /* baInterfaceNr(2) AudioStreaming interface 2 belongs to AC interface */ #endif #if (NUM_USB_CHAN_OUT > 0) /* CS_Interface Input Terminal 1 Descriptor - USB streaming Host to Device */ 0x0C, - UAC_CS_DESCTYPE_INTERFACE, /* UAC_CS_DESCTYPE_INTERFACE */ - 0x02, /* INPUT_TERMINAL */ - 0x01, /* Terminal ID */ - 0x01, 0x01, /* Type - streaming */ + UAC_CS_DESCTYPE_INTERFACE, /* bDescriptorType (UAC_CS_DESCTYPE_INTERFACE) */ + 0x02, /* bDescriptiorSubtype (INPUT_TERMINAL) */ + 0x01, /* bTerminalID */ + 0x01, 0x01, /* wTerminalType (USB Streaming) */ 0x00, /* Associated terminal - unused */ NUM_USB_CHAN_OUT_FS, /* bNrChannels */ 0x03, 0x00, /* wChannelConfig */ @@ -2481,16 +2481,16 @@ unsigned char cfgDesc_Audio1[] = /* Standard As Interface Descriptor (4.5.1) */ 0x09, 0x04, /* INTERFACE */ - 0x01, /* Interface no */ - 0x01, /* AlternateSetting */ + 0x01, /* bInterfaceNumber */ + 0x01, /* bAlternateSetting */ #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) 0x02, /* bNumEndpoints 2: audio EP and feedback EP */ #else 0x01, /* bNumEndpoints */ #endif - 0x01, /* Interface class - AUDIO */ - 0x02, /* subclass - AUDIO_STREAMING */ - 0x00, /* Unused */ + 0x01, /* bInterfaceClas - AUDIO */ + 0x02, /* bInterfaceSubclass - AUDIO_STREAMING */ + 0x00, /* bInterface Protocol - Unused */ offsetof(StringDescTable_t, outputInterfaceStr_Audio1)/sizeof(char *), /* iInterface */ /* Class-Specific AS Interface Descriptor (4.5.2) */ From 82f351cdae1a196ef91ad9ce379b41ba26552b5c Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Fri, 20 Jan 2017 15:51:03 +0000 Subject: [PATCH 3/4] Add comments to #endifs --- module_usb_audio/audio_io/audio_io.xc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index f24f7200..95ff988c 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -513,7 +513,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) memset(&ds3Data.inputDelayLine, 0, sizeof ds3Data); -#endif +#endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) unsigned command = DoSampleTransfer(c_out, readBuffNo, underflowWord, i_audMan); @@ -666,7 +666,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, { memset(&inputDs3Sum, 0, sizeof inputDs3Sum); } -#endif +#endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) #if (I2S_CHANS_ADC != 0) /* Input previous L sample into L in buffer */ index = 0; @@ -740,12 +740,12 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, { p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]); } -#endif +#endif // (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) #ifndef CODEC_MASTER /* Clock out the LR Clock, the DAC data and Clock in the next sample into ADC */ doI2SClocks(divide); -#endif +#endif // !CODEC_MASTER #ifdef ADAT_TX TransferAdatTxSamples(c_adat_out, samplesOut, adatSmuxMode, 1); @@ -873,11 +873,11 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, { p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]); } -#endif +#endif // (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) #ifndef CODEC_MASTER doI2SClocks(divide); -#endif +#endif // !CODEC_MASTER From d7743edda01ac61ffa84375d882f43c3df88d74e Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Fri, 20 Jan 2017 17:32:33 +0000 Subject: [PATCH 4/4] Move DS3 data into deliver() rather than being global --- module_usb_audio/audio_io/audio_io.xc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 95ff988c..2bc876c7 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -60,13 +60,6 @@ static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)]; static int inDownsamplingCounter = 0; #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) #include "src.h" -static union ds3Data -{ - long long doubleWordAlignmentEnsured; - /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ - int32_t inputDelayLine[I2S_DOWNSAMPLE_CHANS_IN][I2S_DOWNSAMPLE_FACTOR_IN][24]; -} ds3Data; -static int64_t inputDs3Sum[I2S_DOWNSAMPLE_CHANS_IN]; #endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) #if (DSD_CHANS_DAC != 0) @@ -512,7 +505,14 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) - memset(&ds3Data.inputDelayLine, 0, sizeof ds3Data); + union ds3Data + { + long long doubleWordAlignmentEnsured; + /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ + int32_t inputDelayLine[I2S_DOWNSAMPLE_CHANS_IN][I2S_DOWNSAMPLE_FACTOR_IN][24]; + } ds3Data; + memset(&ds3Data.inputDelayLine, 0, sizeof ds3Data.inputDelayLine); + int64_t inputDs3Sum[I2S_DOWNSAMPLE_CHANS_IN]; #endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) unsigned command = DoSampleTransfer(c_out, readBuffNo, underflowWord, i_audMan);