PortAudio  2.0
Macros | Functions

Functions for generating dither noise. More...

#include "pa_types.h"
#include "pa_dither.h"

Macros

#define PA_DITHER_BITS_   (15)
 
#define DITHER_SHIFT_   ((sizeof(PaInt32)*8 - PA_DITHER_BITS_) + 1)
 
#define PA_FLOAT_DITHER_SCALE_   (1.0f / ((1<<PA_DITHER_BITS_)-1))
 

Functions

void PaUtil_InitializeTriangularDitherState (PaUtilTriangularDitherGenerator *state)
 Initialize dither state. More...
 
PaInt32 PaUtil_Generate16BitTriangularDither (PaUtilTriangularDitherGenerator *state)
 Calculate 2 LSB dither signal with a triangular distribution. Ranged for adding to a 1 bit right-shifted 32 bit integer prior to >>15. eg: More...
 
float PaUtil_GenerateFloatTriangularDither (PaUtilTriangularDitherGenerator *state)
 Calculate 2 LSB dither signal with a triangular distribution. Ranged for adding to a pre-scaled float. More...
 

Detailed Description

Functions for generating dither noise.

Macro Definition Documentation

#define DITHER_SHIFT_   ((sizeof(PaInt32)*8 - PA_DITHER_BITS_) + 1)
#define PA_DITHER_BITS_   (15)
#define PA_FLOAT_DITHER_SCALE_   (1.0f / ((1<<PA_DITHER_BITS_)-1))

Function Documentation

PaInt32 PaUtil_Generate16BitTriangularDither ( PaUtilTriangularDitherGenerator ditherState)

Calculate 2 LSB dither signal with a triangular distribution. Ranged for adding to a 1 bit right-shifted 32 bit integer prior to >>15. eg:

    signed long in = *
    signed long dither = PaUtil_Generate16BitTriangularDither( ditherState );
    signed short out = (signed short)(((in>>1) + dither) >> 15);
Returns
A signed 32-bit integer with a range of +32767 to -32768

References DITHER_SHIFT_, PaUtilTriangularDitherGenerator::previous, PaUtilTriangularDitherGenerator::randSeed1, and PaUtilTriangularDitherGenerator::randSeed2.

float PaUtil_GenerateFloatTriangularDither ( PaUtilTriangularDitherGenerator ditherState)

Calculate 2 LSB dither signal with a triangular distribution. Ranged for adding to a pre-scaled float.

    float in = *
    float dither = PaUtil_GenerateFloatTriangularDither( ditherState );
    // use smaller scaler to prevent overflow when we add the dither
    signed short out = (signed short)(in*(32766.0f) + dither );
Returns
A float with a range of -2.0 to +1.99999.

References DITHER_SHIFT_, PaUtilTriangularDitherGenerator::previous, PaUtilTriangularDitherGenerator::randSeed1, and PaUtilTriangularDitherGenerator::randSeed2.

void PaUtil_InitializeTriangularDitherState ( PaUtilTriangularDitherGenerator state)