changeset 12930:33935a6320b8

[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 <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 18 Jan 2006 23:42:17 +0000
parents 918a91c73930
children d954186cd1c6
files src/gtksound.c
diffstat 1 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;