int main(void) { long max,min; int i; for( i=0; i<10000; i++ ) { long dither = PaConvert_TriangularDither(); // printf("dither = 0x%08X\n", dither ); if( dither < min ) min = dither; else if( dither > max ) max = dither; } printf("min = 0x%08X = %d, max = 0x%08X = %d\n", min, min, max, max ); }
static void PaConvert_Float32_Int16_Dither( float *sourceBuffer, int sourceStride, short *targetBuffer, int targetStride, int numSamples ) { int i; for( i=0; i<numSamples; i++ ) { /* use smaller scaler to prevent overflow when we add the dither */ float dither = PaConvert_TriangularDither() * PA_DITHER_SCALE; float dithered = (*sourceBuffer * (32766.0f)) + dither; *targetBuffer = (short) dithered; sourceBuffer += sourceStride; targetBuffer += targetStride; } }
static void PaConvert_Float32_Int8_Dither( float *sourceBuffer, int sourceStride, char *targetBuffer, int targetStride, int numSamples ) { int i; for( i=0; i<numSamples; i++ ) { /* use smaller scaler to prevent overflow when we add the dither */ float dither = PaConvert_TriangularDither() * PA_DITHER_SCALE; /* FIXME */ float dithered = (*sourceBuffer * (126.0f)) + dither; long samp = (long) dithered; *targetBuffer = (char) samp; sourceBuffer += sourceStride; targetBuffer += targetStride; } }