# HG changeset patch # User Richard Laager # Date 1137627737 0 # Node ID 33935a6320b85df55deec61655fd4cd6ce52184d # Parent 918a91c73930dc57c0f6eb4660d2f8ebc71e7437 [gaim-migrate @ 15283] Apply a linear correction across the volume adjustment scale to prevent the default sounds from clipping. If someone has a better algorithm to prevent the clipping, I'm all for it. committer: Tailor Script diff -r 918a91c73930 -r 33935a6320b8 src/gtksound.c --- a/src/gtksound.c Wed Jan 18 23:10:26 2006 +0000 +++ b/src/gtksound.c Wed Jan 18 23:42:17 2006 +0000 @@ -394,6 +394,9 @@ return FALSE; /* do not run again */ } +/* Uncomment the following line to enable debugging of clipping in the scaling. */ +/* #define DEBUG_CLIPPING */ + static void scale_pcm_data(char *data, int nframes, ao_sample_format *format, double intercept, double minclip, double maxclip, @@ -411,6 +414,10 @@ case 16: for(i = 0; i < nframes * format->channels; i++) { v = ((data16[i] - intercept) * scale) + intercept; +#ifdef DEBUG_CLIPPING + if (v > maxclip) + printf("Clipping detected!\n"); +#endif v = CLAMP(v, minclip, maxclip); data16[i]=(gint16)v; } @@ -418,6 +425,10 @@ case 32: for(i = 0; i < nframes * format->channels; i++) { v = ((data32[i] - intercept) * scale) + intercept; +#ifdef DEBUG_CLIPPING + if (v > maxclip) + printf("Clipping detected!\n"); +#endif v = CLAMP(v, minclip, maxclip); data32[i]=(gint32)v; } @@ -426,6 +437,10 @@ case 64: for(i = 0; i < nframes * format->channels; i++) { v = ((data64[i] - intercept) * scale) + intercept; +#ifdef DEBUG_CLIPPING + if (v > maxclip) + printf("Clipping detected!\n"); +#endif v = CLAMP(v, minclip, maxclip); data64[i]=(gint64)v; } @@ -510,7 +525,10 @@ return; else if (pid == 0) { /* Child process */ - float scale = ((float) volume * volume) / 2500; + + /* 0.6561 = 0.81 ^ 2, because the sounds we ship clip if the + * volume is greater than 81 (without this scale factor). */ + float scale = ((float) volume * volume) * 0.6561 / 2500; file = afOpenFile(filename, "rb", NULL); if(file) { ao_device *device;