浏览代码

prevent clipping

async input: default constructor arguments for noise-shaping and dither set to false
example: comment updated
dds
awalch6679 4 年前
父节点
当前提交
1db760614e
共有 3 个文件被更改,包括 18 次插入3 次删除
  1. +16
    -1
      Quantizer.cpp
  2. +1
    -1
      async_input_spdif3.h
  3. +1
    -1
      examples/HardwareTesting/PassThroughAsyncSpdif/PassThroughAsyncSpdif.ino

+ 16
- 1
Quantizer.cpp 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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);

正在加载...
取消
保存