async input: default constructor arguments for noise-shaping and dither set to false example: comment updateddds
_noiseShaping=noiseShaping; | _noiseShaping=noiseShaping; | ||||
_dither=dither; | _dither=dither; | ||||
_factor=factor; | _factor=factor; | ||||
if (_dither){ | |||||
_factor-=1.f; | |||||
} | |||||
if (_noiseShaping){ | |||||
// the maximum rounding error is 0.5 | |||||
// Assuming the rounding errors of the last NOISE_SHAPE_F_LENGTH samples was 0.5 at the positive noise-shaping-coefficients and -0.5 at the negative coefficients, | |||||
// the maximum added value can be computed as follows: | |||||
float* f=_noiseSFilter; | |||||
float maxAddedVal=0.f; | |||||
for (uint16_t j =0; j< NOISE_SHAPE_F_LENGTH; j++){ | |||||
maxAddedVal+=abs(*f++); | |||||
} | |||||
maxAddedVal/=2.f; | |||||
_factor-=maxAddedVal; | |||||
} | |||||
reset(); | reset(); | ||||
} | } | ||||
void Quantizer::reset(){ | void Quantizer::reset(){ | ||||
*output=(int16_t)_factor; | *output=(int16_t)_factor; | ||||
} | } | ||||
else if (xnDR < -_factor){ | else if (xnDR < -_factor){ | ||||
*output=(int16_t)_factor; | |||||
*output=-(int16_t)_factor; | |||||
} | } | ||||
else { | else { | ||||
*output=(int16_t)xnDR; | *output=(int16_t)xnDR; |
///@param attenuation target attenuation [dB] of the anti-aliasing filter. Only used if AUDIO_SAMPLE_RATE_EXACT < input sample rate (input fs). The attenuation can't be reached if the needed filter length exceeds 2*MAX_FILTER_SAMPLES+1 | ///@param attenuation target attenuation [dB] of the anti-aliasing filter. Only used if AUDIO_SAMPLE_RATE_EXACT < input sample rate (input fs). The attenuation can't be reached if the needed filter length exceeds 2*MAX_FILTER_SAMPLES+1 | ||||
///@param minHalfFilterLength If AUDIO_SAMPLE_RATE_EXACT >= input fs), the filter length of the resampling filter is 2*minHalfFilterLength+1. If AUDIO_SAMPLE_RATE_EXACT < input fs the filter is maybe longer to reach the desired attenuation | ///@param minHalfFilterLength If AUDIO_SAMPLE_RATE_EXACT >= input fs), the filter length of the resampling filter is 2*minHalfFilterLength+1. If AUDIO_SAMPLE_RATE_EXACT < input fs the filter is maybe longer to reach the desired attenuation | ||||
///@param maxHalfFilterLength Can be used to restrict the maximum filter length at the cost of a lower attenuation | ///@param maxHalfFilterLength Can be used to restrict the maximum filter length at the cost of a lower attenuation | ||||
AsyncAudioInputSPDIF3(bool dither=true, bool noiseshaping=true,float attenuation=100, int32_t minHalfFilterLength=20, int32_t maxHalfFilterLength=80); | |||||
AsyncAudioInputSPDIF3(bool dither=false, bool noiseshaping=false,float attenuation=100, int32_t minHalfFilterLength=20, int32_t maxHalfFilterLength=80); | |||||
~AsyncAudioInputSPDIF3(); | ~AsyncAudioInputSPDIF3(); | ||||
void begin(); | void begin(); | ||||
virtual void update(void); | virtual void update(void); |
#include <Audio.h> | #include <Audio.h> | ||||
AsyncAudioInputSPDIF3 spdifIn(false, false, 100, 20, 80); //dither = true, noiseshaping = true, anti-aliasing attenuation=100dB, minimum half resampling filter length=20, maximum half resampling filter length=80 | |||||
AsyncAudioInputSPDIF3 spdifIn(false, false, 100, 20, 80); //dither = false, noiseshaping = false, anti-aliasing attenuation=100dB, minimum half resampling filter length=20, maximum half resampling filter length=80 | |||||
AudioOutputSPDIF3 spdifOut; | AudioOutputSPDIF3 spdifOut; | ||||
AudioConnection patchCord1(spdifIn, 0, spdifOut, 0); | AudioConnection patchCord1(spdifIn, 0, spdifOut, 0); |