fluid-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [fluid-dev] Purpose of dither?


From: Mihail Zenkov
Subject: Re: [fluid-dev] Purpose of dither?
Date: Tue, 8 May 2007 12:52:11 +0300

On Tue, 8 May 2007 01:22:45 +0200
"Miguel Lobo" <address@hidden> wrote:

> Hi list,
> 
> We have this code in fluid_synth.c:
> 
> #define DITHER_SIZE 48000
> #define DITHER_CHANNELS 2
> 
> static float rand_table[DITHER_CHANNELS][DITHER_SIZE];
> 
> static void init_dither(void)
> {
>   float d, dp;
>   int c, i;
> 
>   for (c = 0; c < DITHER_CHANNELS; c++) {
>     dp = 0;
>     for (i = 0; i < DITHER_SIZE-1; i++) {
>       d = rand() / (float)RAND_MAX - 0.5f;
>       rand_table[c][i] = d - dp;
>       dp = d;
>     }
>     rand_table[c][DITHER_SIZE-1] = 0 - dp;
>   }
> }
> 
> This creates two tables of length 48000 with random floating point numbers
> between -1.0 and 1.0 (the probability distribution is not uniform).
> 
> And in the same file, in function fluid_synth_write_s16 (which converts the
> result of synthesis from floating point to signed 16-bit format):
> 
>     left_sample = roundi (left_in[cur] * 32766.0f + rand_table[0][di]);
>     right_sample = roundi (right_in[cur] * 32766.0f + rand_table[1][di]);
> 
>     di++;
>     if (di >= DITHER_SIZE) di = 0;
> 
> For each output sample, one of the previously generated random values is
> added to the result, which has now been scaled and varies between -32766.0and
> 32766.0.
> 
> I don't understand the purpose of all this.  The effect of adding the random
> values surely is increasing the noise in the output, and that by such a
> small amount that seems sure to be inaudible.
> 
> I'm no audio expert, however, so does anyone think that this code serves any
> useful purpose?
> 
> Regards,
> Miguel
> 

http://en.wikipedia.org/wiki/Dither
In our case we have TPDF.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]