Audacity  2.2.0
Dither.cpp File Reference
#include "float_cast.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <wx/defs.h>
#include "Dither.h"

Macros

#define DITHER_NOISE   (rand() / (float)RAND_MAX - 0.5f)
 
#define CONVERT_DIV16   float(1<<15)
 
#define CONVERT_DIV24   float(1<<23)
 
#define FROM_INT16(ptr)   (*((short*)(ptr)) / CONVERT_DIV16)
 
#define FROM_INT24(ptr)   (*(( int*)(ptr)) / CONVERT_DIV24)
 
#define FROM_FLOAT(ptr)
 
#define PROMOTE_TO_INT16(sample)   ((sample) * CONVERT_DIV16)
 
#define PROMOTE_TO_INT24(sample)   ((sample) * CONVERT_DIV24)
 
#define IMPLEMENT_STORE(ptr, sample, ptr_type, min_bound, max_bound)
 
#define STORE_INT16(ptr, sample)   IMPLEMENT_STORE((ptr), (sample), short, -32768, 32767)
 
#define STORE_INT24(ptr, sample)   IMPLEMENT_STORE((ptr), (sample), int, -8388608, 8388607)
 
#define DITHER_TO_INT16(dither, dst, sample)   STORE_INT16((dst), dither(PROMOTE_TO_INT16(sample)))
 
#define DITHER_TO_INT24(dither, dst, sample)   STORE_INT24((dst), dither(PROMOTE_TO_INT24(sample)))
 
#define DITHER_STEP(dither, store, load, dst, src)   store(dither, (dst), load(src))
 
#define DITHER_LOOP(dither, store, load, dst, dstFormat, dstStride, src, srcFormat, srcStride, len)
 
#define DITHER_INT24_TO_INT16(dither, dst, dstStride, src, srcStride, len)   DITHER_LOOP(dither, DITHER_TO_INT16, FROM_INT24, dst, int16Sample, dstStride, src, int24Sample, srcStride, len)
 
#define DITHER_FLOAT_TO_INT16(dither, dst, dstStride, src, srcStride, len)   DITHER_LOOP(dither, DITHER_TO_INT16, FROM_FLOAT, dst, int16Sample, dstStride, src, floatSample, srcStride, len)
 
#define DITHER_FLOAT_TO_INT24(dither, dst, dstStride, src, srcStride, len)   DITHER_LOOP(dither, DITHER_TO_INT24, FROM_FLOAT, dst, int24Sample, dstStride, src, floatSample, srcStride, len)
 
#define DITHER(dither, dst, dstFormat, dstStride, src, srcFormat, srcStride, len)
 

Macro Definition Documentation

#define CONVERT_DIV16   float(1<<15)
#define CONVERT_DIV24   float(1<<23)
#define DITHER (   dither,
  dst,
  dstFormat,
  dstStride,
  src,
  srcFormat,
  srcStride,
  len 
)
Value:
do { if (srcFormat == int24Sample && dstFormat == int16Sample) \
DITHER_INT24_TO_INT16(dither, dst, dstStride, src, srcStride, len); \
else if (srcFormat == floatSample && dstFormat == int16Sample) \
DITHER_FLOAT_TO_INT16(dither, dst, dstStride, src, srcStride, len); \
else if (srcFormat == floatSample && dstFormat == int24Sample) \
DITHER_FLOAT_TO_INT24(dither, dst, dstStride, src, srcStride, len); \
else { wxASSERT(false); } \
} while (0)
#define DITHER_INT24_TO_INT16(dither, dst, dstStride, src, srcStride, len)
Definition: Dither.cpp:187
#define DITHER_FLOAT_TO_INT16(dither, dst, dstStride, src, srcStride, len)
Definition: Dither.cpp:189
#define DITHER_FLOAT_TO_INT24(dither, dst, dstStride, src, srcStride, len)
Definition: Dither.cpp:191

Referenced by Dither::Apply().

#define DITHER_FLOAT_TO_INT16 (   dither,
  dst,
  dstStride,
  src,
  srcStride,
  len 
)    DITHER_LOOP(dither, DITHER_TO_INT16, FROM_FLOAT, dst, int16Sample, dstStride, src, floatSample, srcStride, len)
#define DITHER_FLOAT_TO_INT24 (   dither,
  dst,
  dstStride,
  src,
  srcStride,
  len 
)    DITHER_LOOP(dither, DITHER_TO_INT24, FROM_FLOAT, dst, int24Sample, dstStride, src, floatSample, srcStride, len)
#define DITHER_INT24_TO_INT16 (   dither,
  dst,
  dstStride,
  src,
  srcStride,
  len 
)    DITHER_LOOP(dither, DITHER_TO_INT16, FROM_INT24, dst, int16Sample, dstStride, src, int24Sample, srcStride, len)
#define DITHER_LOOP (   dither,
  store,
  load,
  dst,
  dstFormat,
  dstStride,
  src,
  srcFormat,
  srcStride,
  len 
)
Value:
do { \
char *d, *s; \
unsigned int i; \
int x; \
for (d = (char*)dst, s = (char*)src, i = 0; \
i < len; \
i++, d += SAMPLE_SIZE(dstFormat) * dstStride, \
s += SAMPLE_SIZE(srcFormat) * srcStride) \
DITHER_STEP(dither, store, load, d, s); \
} while (0)
#define DITHER_STEP(dither, store, load, dst, src)
Definition: Dither.cpp:169
#define DITHER_NOISE   (rand() / (float)RAND_MAX - 0.5f)
#define DITHER_STEP (   dither,
  store,
  load,
  dst,
  src 
)    store(dither, (dst), load(src))
#define DITHER_TO_INT16 (   dither,
  dst,
  sample 
)    STORE_INT16((dst), dither(PROMOTE_TO_INT16(sample)))
#define DITHER_TO_INT24 (   dither,
  dst,
  sample 
)    STORE_INT24((dst), dither(PROMOTE_TO_INT24(sample)))
#define FROM_FLOAT (   ptr)
Value:
(*((float*)(ptr)) > 1.0 ? 1.0 : \
*((float*)(ptr)) < -1.0 ? -1.0 : \
*((float*)(ptr)))
#define FROM_INT16 (   ptr)    (*((short*)(ptr)) / CONVERT_DIV16)

Referenced by Dither::Apply().

#define FROM_INT24 (   ptr)    (*(( int*)(ptr)) / CONVERT_DIV24)

Referenced by Dither::Apply().

#define IMPLEMENT_STORE (   ptr,
  sample,
  ptr_type,
  min_bound,
  max_bound 
)
Value:
do { \
x = lrintf(sample); \
if (x>(max_bound)) *((ptr_type*)(ptr))=(max_bound); \
else if (x<(min_bound)) *((ptr_type*)(ptr))=(min_bound); \
else *((ptr_type*)(ptr))=(ptr_type)x; } while (0)
#define lrintf(flt)
Definition: float_cast.h:137
#define PROMOTE_TO_INT16 (   sample)    ((sample) * CONVERT_DIV16)
#define PROMOTE_TO_INT24 (   sample)    ((sample) * CONVERT_DIV24)
#define STORE_INT16 (   ptr,
  sample 
)    IMPLEMENT_STORE((ptr), (sample), short, -32768, 32767)
#define STORE_INT24 (   ptr,
  sample 
)    IMPLEMENT_STORE((ptr), (sample), int, -8388608, 8388607)