All pastes #386442 Raw Edit

Stuff

public cpp v1 · immutable
·published 2007-03-08 16:40 UTC
rendered paste body
// Dither implementations// No dither, just return sampleinline float Dither::NoDither(float sample){    return sample;}// Rectangle dithering, apply one-step noiseinline float Dither::RectangleDither(float sample){    return sample - DITHER_NOISE;}// Triangle ditherinline float Dither::TriangleDither(float sample){    float r = DITHER_NOISE * 2.0f - 1.0f;    float result = sample + r - mTriangleState;    mTriangleState = r;        return result;}// Shaped ditherinline float Dither::ShapedDither(float sample){    float r = DITHER_NOISE * 2.0f - 1.0f;        // Run FIR    float xe = sample + mBuffer[mPhase] * SHAPED_BS[0]        + mBuffer[(mPhase - 1) & BUF_MASK] * SHAPED_BS[1]        + mBuffer[(mPhase - 2) & BUF_MASK] * SHAPED_BS[2]        + mBuffer[(mPhase - 3) & BUF_MASK] * SHAPED_BS[3]        + mBuffer[(mPhase - 4) & BUF_MASK] * SHAPED_BS[4];        // Accumulate FIR and triangular noise    float result = xe + r - mTriangleState;    mTriangleState = r;        // Roll buffer and store last error    mPhase = (mPhase + 1) & BUF_MASK;    mBuffer[mPhase] = xe - lrintf(result);        return result;}