From a997f39237b34df321e53b11021b38a808da11bb Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 9 Jan 2017 15:39:03 +0000 Subject: [PATCH 01/10] Rename I2S_DOWNSAMPLE_MONO to I2S_DOWNSAMPLE_MONO_IN --- module_usb_audio/audio_io/audio_io.xc | 4 ++-- module_usb_audio/devicedefines.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 368c6ebf..15406aed 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -819,7 +819,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif // CODEC_MASTER samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. -#if ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO) +#if ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO_IN) if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) { samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = @@ -838,7 +838,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ff3v_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } -#endif // ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO) +#endif // ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO_IN) } #endif diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 61bbbb51..0b133f75 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -135,12 +135,12 @@ #endif /** - * @brief Only downsample one channel per I2S frame. + * @brief Only downsample one channel per input I2S frame. * - * Default: 0 i.e. mono mode is disabled, all channels will be downsampled. + * Default: 0 i.e. mono mode is disabled, all input channels will be downsampled. */ -#ifndef I2S_DOWNSAMPLE_MONO -#define I2S_DOWNSAMPLE_MONO (0) +#ifndef I2S_DOWNSAMPLE_MONO_IN +#define I2S_DOWNSAMPLE_MONO_IN (0) #endif /** @@ -148,7 +148,7 @@ * * Default: The number of I2S incoming channels, or half this if mono downsampling is enabled. */ -#if (I2S_DOWNSAMPLE_MONO == 1) +#if (I2S_DOWNSAMPLE_MONO_IN == 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 From 46a11d869ffd675b595e9306d819ece696bf4e65 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 9 Jan 2017 15:44:41 +0000 Subject: [PATCH 02/10] Rename I2S_DOWNSAMPLE_FACTOR to I2S_DOWNSAMPLE_FACTOR_IN --- CHANGELOG.rst | 2 +- module_usb_audio/audio_io/audio_io.xc | 34 +++++++++++++-------------- module_usb_audio/devicedefines.h | 12 +++++----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ae65e58f..f742557f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,7 +3,7 @@ sc_usb_audio Change Log 7.0.0 ------ - - ADDED: I2S down-sampling (I2S_DOWNSAMPLE_FACTOR) + - ADDED: I2S down-sampling (I2S_DOWNSAMPLE_FACTOR_IN) - ADDED: I2S resynchronisation when in slave mode (CODEC_MASTER=1) - CHANGE: Various memory optimisations when MAX_FREQ = MIN_FREQ - CHANGE: Memory optimisations in audio buffering diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 15406aed..d6621459 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -58,13 +58,13 @@ static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)]; #endif static int downsamplingCounter = 0; -#if (I2S_DOWNSAMPLE_FACTOR > 1) +#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 delayLine[I2S_DOWNSAMPLE_CHANS][I2S_DOWNSAMPLE_FACTOR][24]; + int32_t delayLine[I2S_DOWNSAMPLE_CHANS][I2S_DOWNSAMPLE_FACTOR_IN][24]; } ds3Data; static int64_t ds3Sum[I2S_DOWNSAMPLE_CHANS]; #endif @@ -501,7 +501,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, } #endif -#if (I2S_DOWNSAMPLE_FACTOR > 1) +#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) memset(&ds3Data.delayLine, 0, sizeof ds3Data); #endif @@ -651,7 +651,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, else #endif { -#if (I2S_DOWNSAMPLE_FACTOR > 1) +#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) if (0 == downsamplingCounter) { memset(&ds3Sum, 0, sizeof ds3Sum); @@ -683,8 +683,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, /* 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. -#if (I2S_DOWNSAMPLE_FACTOR > 1) - if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) +#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) { samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = src_ds3_voice_add_final_sample( @@ -702,7 +702,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ff3v_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } -#endif // (I2S_DOWNSAMPLE_FACTOR > 1) +#endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) } #endif @@ -776,7 +776,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if (NUM_PDM_MICS > 0) - if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) { /* Get samples from PDM->PCM comverter */ c_pdm_pcm <: 1; @@ -819,8 +819,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif // CODEC_MASTER samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. -#if ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO_IN) - if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) +#if ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && !I2S_DOWNSAMPLE_MONO_IN) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) { samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = src_ds3_voice_add_final_sample( @@ -838,7 +838,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, src_ff3v_ds3_voice_coefs[downsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } -#endif // ((I2S_DOWNSAMPLE_FACTOR > 1) && !I2S_DOWNSAMPLE_MONO_IN) +#endif // ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && !I2S_DOWNSAMPLE_MONO_IN) } #endif @@ -924,7 +924,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, if(frameCount == I2S_CHANS_PER_FRAME) #endif { - if ((I2S_DOWNSAMPLE_FACTOR - 1) == downsamplingCounter) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) { /* Do samples transfer */ /* The below looks a bit odd but forces the compiler to inline twice */ @@ -1063,7 +1063,7 @@ chanend ?c_config, chanend ?c unsigned adatMultiple = 0; #endif - unsigned curSamFreq = DEFAULT_FREQ * I2S_DOWNSAMPLE_FACTOR; + unsigned curSamFreq = DEFAULT_FREQ * I2S_DOWNSAMPLE_FACTOR_IN; 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; @@ -1218,7 +1218,7 @@ chanend ?c_config, chanend ?c { /* TODO wait for good mclk instead of delay */ /* No delay for DFU modes */ - if (((curSamFreq / I2S_DOWNSAMPLE_FACTOR) != AUDIO_REBOOT_FROM_DFU) && ((curSamFreq / I2S_DOWNSAMPLE_FACTOR) != AUDIO_STOP_FOR_DFU) && command) + if (((curSamFreq / I2S_DOWNSAMPLE_FACTOR_IN) != AUDIO_REBOOT_FROM_DFU) && ((curSamFreq / I2S_DOWNSAMPLE_FACTOR_IN) != AUDIO_STOP_FOR_DFU) && command) { #if 0 /* User should ensure MCLK is stable in AudioHwConfig */ @@ -1261,7 +1261,7 @@ chanend ?c_config, chanend ?c #if NUM_PDM_MICS > 0 /* Send decimation factor to PDM task(s) */ - c_pdm_in <: curSamFreq / I2S_DOWNSAMPLE_FACTOR; + c_pdm_in <: curSamFreq / I2S_DOWNSAMPLE_FACTOR_IN; #endif #ifdef ADAT_TX @@ -1299,7 +1299,7 @@ chanend ?c_config, chanend ?c if(command == SET_SAMPLE_FREQ) { - curSamFreq = inuint(c_mix_out) * I2S_DOWNSAMPLE_FACTOR; + curSamFreq = inuint(c_mix_out) * I2S_DOWNSAMPLE_FACTOR_IN; } else if(command == SET_STREAM_FORMAT_OUT) { @@ -1312,7 +1312,7 @@ chanend ?c_config, chanend ?c } /* Currently no more audio will happen after this point */ - if ((curSamFreq / I2S_DOWNSAMPLE_FACTOR) == AUDIO_STOP_FOR_DFU) + if ((curSamFreq / I2S_DOWNSAMPLE_FACTOR_IN) == AUDIO_STOP_FOR_DFU) { outct(c_mix_out, XS1_CT_END); diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 0b133f75..aa978fde 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -126,11 +126,11 @@ * * Default: 1 i.e. downsampling is disabled. */ -#ifndef I2S_DOWNSAMPLE_FACTOR -#define I2S_DOWNSAMPLE_FACTOR (1) +#ifndef I2S_DOWNSAMPLE_FACTOR_IN +#define I2S_DOWNSAMPLE_FACTOR_IN (1) #else - #if (I2S_DOWNSAMPLE_FACTOR != 3) && (I2S_DOWNSAMPLE_FACTOR != 1) - #error Unsupported I2S downsampling configuration + #if (I2S_DOWNSAMPLE_FACTOR_IN != 3) && (I2S_DOWNSAMPLE_FACTOR_IN != 1) + #error Unsupported I2S input downsampling configuration #endif #endif @@ -150,8 +150,8 @@ */ #if (I2S_DOWNSAMPLE_MONO_IN == 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 + #if ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && (I2S_MODE_TDM == 1)) + #error Mono I2S input downsampling is not avaliable in TDM mode #endif #else #define I2S_DOWNSAMPLE_CHANS I2S_CHANS_ADC From 80e9feb5461d351c4b76983f4e761065569503a1 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 9 Jan 2017 15:46:29 +0000 Subject: [PATCH 03/10] Rename I2S_DOWNSAMPLE_CHANS to I2S_DOWNSAMPLE_CHANS_IN --- module_usb_audio/audio_io/audio_io.xc | 4 ++-- module_usb_audio/devicedefines.h | 4 ++-- 2 files 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 d6621459..4e00b6b0 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -64,9 +64,9 @@ static union ds3Data { long long doubleWordAlignmentEnsured; /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ - int32_t delayLine[I2S_DOWNSAMPLE_CHANS][I2S_DOWNSAMPLE_FACTOR_IN][24]; + int32_t delayLine[I2S_DOWNSAMPLE_CHANS_IN][I2S_DOWNSAMPLE_FACTOR_IN][24]; } ds3Data; -static int64_t ds3Sum[I2S_DOWNSAMPLE_CHANS]; +static int64_t ds3Sum[I2S_DOWNSAMPLE_CHANS_IN]; #endif #if (DSD_CHANS_DAC != 0) diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index aa978fde..b88d334b 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -149,12 +149,12 @@ * Default: The number of I2S incoming channels, or half this if mono downsampling is enabled. */ #if (I2S_DOWNSAMPLE_MONO_IN == 1) - #define I2S_DOWNSAMPLE_CHANS (I2S_CHANS_ADC / 2) + #define I2S_DOWNSAMPLE_CHANS_IN (I2S_CHANS_ADC / 2) #if ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && (I2S_MODE_TDM == 1)) #error Mono I2S input downsampling is not avaliable in TDM mode #endif #else -#define I2S_DOWNSAMPLE_CHANS I2S_CHANS_ADC +#define I2S_DOWNSAMPLE_CHANS_IN I2S_CHANS_ADC #endif /** From 6ed6497a6ba891a48a383e8e6143b04c59cbf83b Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 9 Jan 2017 16:34:01 +0000 Subject: [PATCH 04/10] Rename downsamplingCounter to inDownsamplingCounter --- module_usb_audio/audio_io/audio_io.xc | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 4e00b6b0..831c22f0 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -57,7 +57,7 @@ static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)]; #undef SPDIF_RX #endif -static int downsamplingCounter = 0; +static int inDownsamplingCounter = 0; #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) #include "src.h" static union ds3Data @@ -519,7 +519,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, return command; } - downsamplingCounter = 0; + inDownsamplingCounter = 0; InitPorts(divide); @@ -652,7 +652,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif { #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) - if (0 == downsamplingCounter) + if (0 == inDownsamplingCounter) { memset(&ds3Sum, 0, sizeof ds3Sum); } @@ -684,13 +684,13 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, /* 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. #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) - if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == inDownsamplingCounter) { samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = 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_ff3v_ds3_voice_coefs[downsamplingCounter], + ds3Data.delayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], + src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } else @@ -698,8 +698,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, 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_ff3v_ds3_voice_coefs[downsamplingCounter], + ds3Data.delayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], + src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } #endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) @@ -776,7 +776,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if (NUM_PDM_MICS > 0) - if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == inDownsamplingCounter) { /* Get samples from PDM->PCM comverter */ c_pdm_pcm <: 1; @@ -820,13 +820,13 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, samplesIn[buffIndex][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i] = bitrev(sample); // channels 1, 3, 5.. on each line. #if ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && !I2S_DOWNSAMPLE_MONO_IN) - if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == inDownsamplingCounter) { 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_ff3v_ds3_voice_coefs[downsamplingCounter], + ds3Data.delayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], + src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } else @@ -834,8 +834,8 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, 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_ff3v_ds3_voice_coefs[downsamplingCounter], + ds3Data.delayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], + src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } #endif // ((I2S_DOWNSAMPLE_FACTOR_IN > 1) && !I2S_DOWNSAMPLE_MONO_IN) @@ -924,7 +924,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, if(frameCount == I2S_CHANS_PER_FRAME) #endif { - if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == downsamplingCounter) + if ((I2S_DOWNSAMPLE_FACTOR_IN - 1) == inDownsamplingCounter) { /* Do samples transfer */ /* The below looks a bit odd but forces the compiler to inline twice */ @@ -940,13 +940,13 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, } /* Reset frame counter and flip the ADC buffer */ - downsamplingCounter = 0; + inDownsamplingCounter = 0; frameCount = 0; readBuffNo = !readBuffNo; } else { - ++downsamplingCounter; + ++inDownsamplingCounter; } } } From e87ad032376ec0630961a0e2037eb0ae1eb6222a Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 9 Jan 2017 16:43:21 +0000 Subject: [PATCH 05/10] Rename delayLine to inputDelayLine --- 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 831c22f0..d7122282 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -64,7 +64,7 @@ static union ds3Data { long long doubleWordAlignmentEnsured; /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ - int32_t delayLine[I2S_DOWNSAMPLE_CHANS_IN][I2S_DOWNSAMPLE_FACTOR_IN][24]; + int32_t inputDelayLine[I2S_DOWNSAMPLE_CHANS_IN][I2S_DOWNSAMPLE_FACTOR_IN][24]; } ds3Data; static int64_t ds3Sum[I2S_DOWNSAMPLE_CHANS_IN]; #endif @@ -502,7 +502,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #endif #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) - memset(&ds3Data.delayLine, 0, sizeof ds3Data); + memset(&ds3Data.inputDelayLine, 0, sizeof ds3Data); #endif unsigned command = DoSampleTransfer(c_out, readBuffNo, underflowWord, i_audMan); @@ -689,7 +689,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = 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][inDownsamplingCounter], + ds3Data.inputDelayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } @@ -698,7 +698,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, 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][inDownsamplingCounter], + ds3Data.inputDelayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } @@ -825,7 +825,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, 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][inDownsamplingCounter], + ds3Data.inputDelayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } @@ -834,7 +834,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, 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][inDownsamplingCounter], + ds3Data.inputDelayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } From 066905f66194186be05359a66f3a2659cb1363b7 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 9 Jan 2017 16:50:12 +0000 Subject: [PATCH 06/10] Rename ds3Sum to inputDs3Sum --- module_usb_audio/audio_io/audio_io.xc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index d7122282..57512d1b 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -66,8 +66,8 @@ static union ds3Data /* [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 ds3Sum[I2S_DOWNSAMPLE_CHANS_IN]; -#endif +static int64_t inputDs3Sum[I2S_DOWNSAMPLE_CHANS_IN]; +#endif // (I2S_DOWNSAMPLE_FACTOR_IN > 1) #if (DSD_CHANS_DAC != 0) extern buffered out port:32 p_dsd_dac[DSD_CHANS_DAC]; @@ -654,7 +654,7 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, #if (I2S_DOWNSAMPLE_FACTOR_IN > 1) if (0 == inDownsamplingCounter) { - memset(&ds3Sum, 0, sizeof ds3Sum); + memset(&inputDs3Sum, 0, sizeof inputDs3Sum); } #endif #if (I2S_CHANS_ADC != 0) @@ -688,16 +688,16 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, { samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))] = src_ds3_voice_add_final_sample( - ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], + inputDs3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.inputDelayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); } else { - ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = + inputDs3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = src_ds3_voice_add_sample( - ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], + inputDs3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.inputDelayLine[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-2)&(I2S_CHANS_PER_FRAME-1))]); @@ -824,16 +824,16 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out, { 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], + inputDs3Sum[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.inputDelayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); } else { - ds3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = + inputDs3Sum[((frameCount-2)&(I2S_CHANS_PER_FRAME-1))+i] = src_ds3_voice_add_sample( - ds3Sum[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i], + inputDs3Sum[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i], ds3Data.inputDelayLine[((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i][inDownsamplingCounter], src_ff3v_ds3_voice_coefs[inDownsamplingCounter], samplesIn[readBuffNo][((frameCount-1)&(I2S_CHANS_PER_FRAME-1))+i]); From 491ec6697ea0c039780afd5272f765c32e2a58a7 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Wed, 11 Jan 2017 17:02:08 +0000 Subject: [PATCH 07/10] Add DS3 support to I2S output path (USB->DS3->I2S) --- module_usb_audio/audio_io/audio_io.xc | 56 ++++++++++++++++++--------- module_usb_audio/devicedefines.h | 20 ++++++++++ 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/module_usb_audio/audio_io/audio_io.xc b/module_usb_audio/audio_io/audio_io.xc index 57512d1b..c002d218 100755 --- a/module_usb_audio/audio_io/audio_io.xc +++ b/module_usb_audio/audio_io/audio_io.xc @@ -58,16 +58,27 @@ static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)]; #endif static int inDownsamplingCounter = 0; -#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) +static int outDownsamplingCounter = 0; +#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) || (I2S_DOWNSAMPLE_FACTOR_OUT > 1) #include "src.h" static union ds3Data { long long doubleWordAlignmentEnsured; - /* [Number of I2S channels][Number of samples/phases][Taps per phase] */ + /* delay lines = [Number of I2S channels][Number of samples/phases][Taps per phase] */ +#if (I2S_DOWNSAMPLE_FACTOR_IN > 1) 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]; @@ -723,20 +734,22 @@ 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) - 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) + if ((I2S_DOWNSAMPLE_FACTOR_OUT - 1) == outDownsamplingCounter) { - p_i2s_dac[index++] <: bitrev(samplesOut[frameCount +i]); - } + 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]); + } #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 @@ -857,19 +870,24 @@ 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) - /* Output "odd" channel to DAC (i.e. right) */ -#pragma loop unroll - for(int i = 1; i < I2S_CHANS_DAC; i+=I2S_CHANS_PER_FRAME) + if ((I2S_DOWNSAMPLE_FACTOR_OUT - 1) == outDownsamplingCounter) { - p_i2s_dac[index++] <: bitrev(samplesOut[frameCount + i]); - } + /* 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]); + } #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 b88d334b..4ea7137f 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -134,6 +134,19 @@ #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. * @@ -157,6 +170,13 @@ #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 c67ae39157109e6e978bb73406b1ff9af3559f76 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Fri, 13 Jan 2017 12:28:09 +0000 Subject: [PATCH 08/10] Fix CHANGELOG typos --- CHANGELOG.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ca8943e6..c60a76cd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,7 +3,7 @@ sc_usb_audio Change Log 7.0.1 ----- - - RESOLVED: PDM microphone decimation issue at some samplerates caused by integration + - RESOLVED: PDM microphone decimation issue at some sample rates caused by integration 7.0.0 ------ @@ -14,7 +14,7 @@ sc_usb_audio Change Log - CHANGE: Various memory optimisations in UAC1 mode - CHANGE: user_pdm_process() API change - CHANGE: PDM Mic decimator table now related to MIN_FREQ (memory optimisation) - - RESOLVED: Audio request interrupt handler properly elminated + - RESOLVED: Audio request interrupt handler properly eliminated 6.30.0 ------ From b9998088c3cc21329cc6f5b936a845bb77231791 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Fri, 13 Jan 2017 12:31:50 +0000 Subject: [PATCH 09/10] Remove trailing whitespace --- CHANGELOG.rst | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c60a76cd..b53f39c5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -25,7 +25,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: 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 @@ -51,7 +51,7 @@ sc_usb_audio Change Log ------ - ADDED: Call to UserBufferManagement() - ADDED: PDM_MIC_INDEX in devicedefines.h and usage - - CHANGE: pdm_buffer() task now combinable + - CHANGE: pdm_buffer() task now combinable - CHANGE: Audio I/O task now takes i_dsp interface as a parameter - CHANGE: Removed built-in support for A/U series internal ADC - CHANGE: User PDM Microphone processing now uses an interface (previously function call) @@ -67,45 +67,45 @@ sc_usb_audio Change Log 6.15.0 ------ - - - RESOLVED: UAC 1.0 descriptors now support multi-channel volume control (previously were + + - RESOLVED: UAC 1.0 descriptors now support multi-channel volume control (previously were hard-coded as stereo) - CHANGE: Removed 32kHz sample-rate support when PDM microphones enabled (lib_mic_array currently does not support non-integer decimation factors) 6.14.0 ------ - - ADDED: Support for for master-clock/sample-rate divides that are not a power of 2 - (i.e. 32kHz from 24.567MHz) - - ADDED: Extended available sample-rate/master-clock ratios. Previous restriction was <= - 512x (i.e. could not support 1024x and above e.g. 49.152MHz MCLK for Sample Rates + - ADDED: Support for for master-clock/sample-rate divides that are not a power of 2 + (i.e. 32kHz from 24.567MHz) + - ADDED: Extended available sample-rate/master-clock ratios. Previous restriction was <= + 512x (i.e. could not support 1024x and above e.g. 49.152MHz MCLK for Sample Rates below 96kHz) (#13893) - ADDED: Support for various "low" sample rates (i.e. < 44100) into UAC 2.0 sample rate list and UAC 1.0 descriptors - - ADDED: Support for the use and integration of PDM microphones (including PDM to PCM - conversion) via lib_mic_array + - ADDED: Support for the use and integration of PDM microphones (including PDM to PCM + conversion) via lib_mic_array - RESOLVED: MIDI data not accepted after "sleep" in OSX 10.11 (El Capitan) - related to sc_xud issue #17092 - CHANGE: Asynchronous feedback system re-implemented to allow for the first two ADDED - changelog items - - CHANGE: Hardware divider used to generate bit-clock from master clock (xCORE-200 only). + changelog items + - CHANGE: Hardware divider used to generate bit-clock from master clock (xCORE-200 only). Allows easy support for greater number of master-clock to sample-rate ratios. - CHANGE: module_queue no longer uses any assert module/lib 6.13.0 ------ - ADDED: Device now uses implicit feedback when input stream is available (previously explicit - feedback pipe always used). This saves chanend/EP resources and means less processing + feedback pipe always used). This saves chanend/EP resources and means less processing burden for the host. Previous behaviour available by enabling UAC_FORCE_FEEDBACK_EP - RESOLVED: Exception when SPDIF_TX and ADAT_TX both enabled due to clock-block being configured after already started. Caused by SPDIF_TX define check typo - - RESOLVED: DFU flag address changed to properly conform to memory address range allocated to + - RESOLVED: DFU flag address changed to properly conform to memory address range allocated to apps by tools - RESOLVED: Build failure when DFU disabled - RESOLVED: Build issue when I2S_CHANS_ADC/DAC set to 0 and CODEC_MASTER enabled - RESOLVED: Typo in MCLK_441 checking for MIN_FREQ define - CHANGE: Mixer and non-mixer channel comms scheme (decouple <-> audio path) now identical - - CHANGE: Input stream buffering modified such that during overflow older samples are removed + - CHANGE: Input stream buffering modified such that during overflow older samples are removed rather than ignoring most recent samples. Removes any chance of stale input packets being sent to host - CHANGE: module_queue (in sc_usb_audio) now uses lib_xassert rather than module_xassert @@ -116,17 +116,17 @@ sc_usb_audio Change Log - RESOLVED: Build error when I2S_CHANS_ADC or I2S_CHANS_DAC set to 0 and CODEC_MASTER enabled 6.12.5 ------- +------ - RESOLVED: Stream issue when NUM_USB_CHAN_IN < I2S_CHANS_ADC 6.12.4 ------- +------ - RESOLVED: DFU fail when DSD enabled and USB library not running on tile[0] 6.12.3 ------ - - RESOLVED: Method for storing persistent state over a DFU reboot modified to improve resilience - against code-base and tools changes + - RESOLVED: Method for storing persistent state over a DFU reboot modified to improve resilience + against code-base and tools changes 6.12.2 ------ From 7f0d104a37b7ddb9619a9b970c59406f6671a1b0 Mon Sep 17 00:00:00 2001 From: Sam Chesney Date: Mon, 16 Jan 2017 17:16:35 +0000 Subject: [PATCH 10/10] Bump version and update CHANGELOG after merge --- CHANGELOG.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c5158083..e0825b85 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,13 +1,18 @@ sc_usb_audio Change Log ======================= +7.0.2 +----- + - ADDED: I2S output down-sampling (I2S_DOWNSAMPLE_FACTOR_OUT) + - CHANGE: Rename I2S input down-sampling (I2S_DOWNSAMPLE_FACTOR to I2S_DOWNSAMPLE_FACTOR_IN) + 7.0.1 ----- - RESOLVED: PDM microphone decimation issue at some sample rates caused by integration 7.0.0 ------ - - ADDED: I2S down-sampling (I2S_DOWNSAMPLE_FACTOR_IN) + - ADDED: I2S down-sampling (I2S_DOWNSAMPLE_FACTOR) - ADDED: I2S resynchronisation when in slave mode (CODEC_MASTER=1) - CHANGE: Various memory optimisations when MAX_FREQ = MIN_FREQ - CHANGE: Memory optimisations in audio buffering