--- Mihail Zenkov <[EMAIL PROTECTED]> wrote: > On Tue, 8 May 2007 01:22:45 +0200 > "Miguel Lobo" <[EMAIL PROTECTED]> 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. >
Just a few comments. First of all I do not understand why dithering is needed at all. 1.Do you mean that 16-bit accuracy is not enough and a human ear can hear the truncation/round-off artefacts? I have serious doubts that this is true. 2.The wiki web page states that this is done when audio CDs are written which, as far as I know is 16 bit resolution. If the answer on the first question above is yes, than I am sorry to hear how stupid sound engineers are. The job of dithering should be on the cd playing hardware, not on cdwriting one... but fluid can not fix that... 3. I am not familiar with the fluid code, but I hope if the answer on the first question is "yes" this dithering should be done as the last stage of data processing before the data is pushed into the audio card. Also, note if digital output is used, no dithering is needed. It is needed only if the data goes directly to DAC!! Even in this latter case, see my last comment. 4. I do not know how imporant it is and my feeling that dithering should not be applied at all, but the code above does not implement TPDF dithering. As I said, I do not think it is needed at all, but if someone wants to implement TPDF than two calls to uniform random generator are needed per entery in the table. Only one call is made by the code above. This leads to dithering which is different from TPDF. And finaly my opnion. Unless some one can show that the answer to the first question is yes, dithering should be removed as it damages the signal. If indeed, the answer to the #1 is yes, it is the job of the audio player to add dither. In other words, it should be as close to the speaker as possible. Since any audio producing equipment has analog components at the end of its chain (we can only hear analog, not digital), unavoidable analog noise in that part will do the dithering for you. Any additional dithering is not needed. Wires in the walls do the dithering... just my thoughts... ZF ____________________________________________________________________________________ Finding fabulous fares is fun. Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains. http://farechase.yahoo.com/promo-generic-14795097 _______________________________________________ fluid-dev mailing list fluid-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/fluid-dev