Bladeren bron

Merge pull request #364 from alex6679/master

AsyncAudioInputSPDIF3 minor bug fix/clipping prevention
dds
Paul Stoffregen 3 jaren geleden
bovenliggende
commit
021ac025d5
No account linked to committer's email address
3 gewijzigde bestanden met toevoegingen van 18 en 3 verwijderingen
  1. +16
    -1
      Quantizer.cpp
  2. +1
    -1
      async_input_spdif3.h
  3. +1
    -1
      examples/HardwareTesting/PassThroughAsyncSpdif/PassThroughAsyncSpdif.ino

+ 16
- 1
Quantizer.cpp Bestand weergeven

@@ -82,6 +82,21 @@ void Quantizer::configure(bool noiseShaping, bool dither, float factor){
_noiseShaping=noiseShaping;
_dither=dither;
_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();
}
void Quantizer::reset(){
@@ -141,7 +156,7 @@ void Quantizer::quantize(float* input, int16_t* output, uint16_t length){
*output=(int16_t)_factor;
}
else if (xnDR < -_factor){
*output=(int16_t)_factor;
*output=-(int16_t)_factor;
}
else {
*output=(int16_t)xnDR;

+ 1
- 1
async_input_spdif3.h Bestand weergeven

@@ -43,7 +43,7 @@ public:
///@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 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();
void begin();
virtual void update(void);

+ 1
- 1
examples/HardwareTesting/PassThroughAsyncSpdif/PassThroughAsyncSpdif.ino Bestand weergeven

@@ -1,7 +1,7 @@

#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;

AudioConnection patchCord1(spdifIn, 0, spdifOut, 0);

Laden…
Annuleren
Opslaan