Gin
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Dither Class Reference

Dither and noise shaping for bit depth reduction. More...

#include <gin_dither.h>

Public Types

enum  NoiseType { none = 0 , rectangular , triangular , gaussian }
 Probability distribution of the dither noise. More...
 
enum  Shaping { flat = 0 , highpass }
 Spectrum of the dither noise itself. More...
 

Public Member Functions

 Dither ()=default
 
 ~Dither ()=default
 
void setBitDepth (int bits)
 Target bit depth.
 
void setNoiseType (NoiseType t)
 
void setShaping (Shaping s)
 
void setAmount (float lsbs)
 Dither depth in LSBs.
 
void setNoiseShaping (float ns)
 Error feedback noise shaping, 0 to 1.
 
void reset ()
 
void process (juce::AudioSampleBuffer &buffer)
 

Detailed Description

Dither and noise shaping for bit depth reduction.

Truncating to a lower bit depth correlates the error with the signal, which is what makes quiet fades sound grainy and reverb tails turn to gravel rather than simply getting quieter. Adding a small amount of noise before quantising decorrelates it: the error becomes hiss, which is far less objectionable than distortion that tracks the music.

Noise shaping goes further and feeds the quantisation error back through a second order filter, pushing the noise out of the midrange where the ear is most sensitive.

Key Features:

Usage:

dither.setBitDepth (16);
dither.setNoiseType (Dither::triangular); // the usual choice
dither.setNoiseShaping (0.5f);
dither.process (buffer);
Dither and noise shaping for bit depth reduction.
Definition gin_dither.h:56
@ triangular
Definition gin_dither.h:74
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25

Note: TPDF (triangular) at 2 LSB is the standard, safe default - it fully decorrelates the error at the cost of a little more noise than RPDF.

See also
BitCrusher

Member Enumeration Documentation

◆ NoiseType

Probability distribution of the dither noise.

  • none: no dither, straight truncation - included for comparison
  • rectangular: RPDF, one random value. Quietest, but the error is not fully decorrelated and the noise floor still moves with the signal
  • triangular: TPDF, sum of two. The standard choice
  • gaussian: sum of ten, approaching a normal distribution
Enumerator
none 
rectangular 
triangular 
gaussian 

◆ Shaping

Spectrum of the dither noise itself.

  • flat: white
  • highpass: the difference of successive values, tilting the noise up and away from where the ear is most sensitive
Enumerator
flat 
highpass 

Constructor & Destructor Documentation

◆ Dither()

Dither::Dither ( )
default

◆ ~Dither()

Dither::~Dither ( )
default

Member Function Documentation

◆ setBitDepth()

void Dither::setBitDepth ( int  bits)

Target bit depth.

16 for CD, 8 for something lo-fi on purpose.

◆ setNoiseType()

void Dither::setNoiseType ( NoiseType  t)

◆ setShaping()

void Dither::setShaping ( Shaping  s)

◆ setAmount()

void Dither::setAmount ( float  lsbs)

Dither depth in LSBs.

2 is the usual amount for TPDF.

◆ setNoiseShaping()

void Dither::setNoiseShaping ( float  ns)

Error feedback noise shaping, 0 to 1.

◆ reset()

void Dither::reset ( )

◆ process()

void Dither::process ( juce::AudioSampleBuffer &  buffer)

References highpass.


The documentation for this class was generated from the following file: