Audacity  2.2.0
Dither Class Reference

This class implements various functions for dithering and is derived from the dither code in the Ardour project, written by Steve Harris. More...

#include <Dither.h>

Public Types

enum  DitherType { none = 0, rectangle = 1, triangle = 2, shaped = 3 }
 These ditherers are currently available: More...
 

Public Member Functions

 Dither ()
 Default constructor. More...
 
void Reset ()
 Reset state of the dither. More...
 
void Apply (DitherType ditherType, const samplePtr source, sampleFormat sourceFormat, samplePtr dest, sampleFormat destFormat, unsigned int len, unsigned int sourceStride=1, unsigned int destStride=1)
 

Private Member Functions

float NoDither (float sample)
 
float RectangleDither (float sample)
 
float TriangleDither (float sample)
 
float ShapedDither (float sample)
 

Private Attributes

int mPhase
 
float mTriangleState
 
float mBuffer [8]
 

Static Private Attributes

static const int BUF_SIZE = 8
 
static const int BUF_MASK = 7
 
static const float SHAPED_BS [] = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f }
 

Detailed Description

This class implements various functions for dithering and is derived from the dither code in the Ardour project, written by Steve Harris.

Dithering is only done if it really is necessary. Otherwise (e.g. when the source and destination format of the samples is the same), the samples are only copied or converted. However, copied samples are always checked for out-of-bounds values and possibly clipped accordingly.

These dither algorithms are currently implemented:

  • No dithering at all
  • Rectangle dithering
  • Triangle dithering
  • Noise-shaped dithering

Dither class. You must construct an instance because it keeps state. Call Dither::Apply() to apply the dither. You can call Reset() between subsequent dithers to reset the dither state and get deterministic behaviour.

Member Enumeration Documentation

These ditherers are currently available:

Enumerator
none 
rectangle 
triangle 
shaped 

Constructor & Destructor Documentation

Dither::Dither ( )

Default constructor.

References Reset().

Member Function Documentation

void Dither::Apply ( DitherType  ditherType,
const samplePtr  source,
sampleFormat  sourceFormat,
samplePtr  dest,
sampleFormat  destFormat,
unsigned int  len,
unsigned int  sourceStride = 1,
unsigned int  destStride = 1 
)

Apply the actual dithering. Expects the source sample in the 'source' variable, the destination sample in the 'dest' variable, and hints to the formats of the samples. Even if the sample formats are the same, samples are clipped, if necessary.

References DITHER, FROM_INT16, FROM_INT24, NoDither(), none, rectangle, RectangleDither(), Reset(), shaped, ShapedDither(), triangle, and TriangleDither().

Referenced by CopySamples(), and CopySamplesNoDither().

float Dither::NoDither ( float  sample)
inlineprivate

Referenced by Apply().

float Dither::RectangleDither ( float  sample)
inlineprivate

References DITHER_NOISE.

Referenced by Apply().

void Dither::Reset ( )

Reset state of the dither.

References BUF_SIZE, mBuffer, mPhase, and mTriangleState.

Referenced by Apply(), and Dither().

float Dither::ShapedDither ( float  sample)
inlineprivate

References BUF_MASK, DITHER_NOISE, lrintf, mBuffer, mPhase, and SHAPED_BS.

Referenced by Apply().

float Dither::TriangleDither ( float  sample)
inlineprivate

References DITHER_NOISE, and mTriangleState.

Referenced by Apply().

Member Data Documentation

const int Dither::BUF_MASK = 7
staticprivate

Referenced by ShapedDither().

const int Dither::BUF_SIZE = 8
staticprivate

Referenced by Reset().

float Dither::mBuffer[8]
private

Referenced by Reset(), and ShapedDither().

int Dither::mPhase
private

Referenced by Reset(), and ShapedDither().

float Dither::mTriangleState
private

Referenced by Reset(), and TriangleDither().

const float Dither::SHAPED_BS = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f }
staticprivate

Referenced by ShapedDither().


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