Audio lib envelope.sustain

Yes. Its nice. I use AudioSynthWaveformDc in to audio mixer and it works perfectly (y)

Screenshot 2026-05-23 162330.png


DCoffset.png
 
I had the same exact issue with the PCM5102A.

In most of my processing I use floats that I translate into int16 and insert in AudioPlayQueues -> AudioOutputI2S.

I have created a small utility NoiseShaper object that does quantification error dithering.
Which is nice but i still had the PCM5102A

So I added a safeguard :
If the output is zero with a little +1 -1 injection to ensure that the signal is never zero.

noiseshaper.h

C++:
// an efficient noise shaper to get the maximum from low cost I2S DACs
// even if using 16 bit mode. 
class NoiseShaper{
    public:
  float dc=0;
    int32_t rnd=0;
  float e=0;
  int16_t s=1;
 
  int16_t quands(float x) {
    // DC remove
    dc+=0.00261f*(x-dc);
    x-=dc;
    // saturation [-1 +1]
    if(x>1) x=1;
    else if(x<-1) x=-1;
    //pseudo random generator
    rnd=rnd*69069+1;
    // 16bit scaling
        float v=x*32760;
    // error feedback + slight random dithering
    // to avoid repetitive patterns
    float vFbDither = v - e + 0.06f*q_to_float(rnd,32);
    int16_t iv=float_to_s16(vFbDither,0);
    // safe guard against clicky silence detectors when using PCM5102 <-----------------------------------
    if(iv==0) {
      iv=s;
      s=-s;
    }
    // error used for feedback dithering
    e=iv-v;
    return iv;
    }
};
 
Back
Top