Mercurial > pidgin.yaz
changeset 13046:1becdaf72e6d
[gaim-migrate @ 15405]
SF Patch #1415168 from charkins
This makes the volume adjustment range center on the middle of the slider
again. It also improves the volume control in a couple of other ways.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 26 Jan 2006 05:43:27 +0000 |
parents | 704dc95d0198 |
children | 473d3a454615 |
files | src/gtkprefs.c src/gtksound.c |
diffstat | 2 files changed, 36 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkprefs.c Thu Jan 26 05:30:39 2006 +0000 +++ b/src/gtkprefs.c Thu Jan 26 05:43:27 2006 +0000 @@ -1447,14 +1447,20 @@ #ifdef USE_AO static gchar* prefs_sound_volume_format(GtkScale *scale, gdouble val) { - if(val == 0) { - return g_strdup_printf("Silent"); - } else if(val < 35) { - return g_strdup_printf("Quiet"); - } else if(val > 65) { - return g_strdup_printf("Loud"); + if(val < 15) { + return g_strdup_printf(_("Quietest")); + } else if(val < 30) { + return g_strdup_printf(_("Quieter")); + } else if(val < 45) { + return g_strdup_printf(_("Quiet")); + } else if(val < 55) { + return g_strdup_printf(_("Normal")); + } else if(val < 70) { + return g_strdup_printf(_("Loud")); + } else if(val < 85) { + return g_strdup_printf(_("Louder")); } else { - return g_strdup_printf("Normal"); + return g_strdup_printf(_("Loudest")); } }
--- a/src/gtksound.c Thu Jan 26 05:30:39 2006 +0000 +++ b/src/gtksound.c Thu Jan 26 05:43:27 2006 +0000 @@ -398,7 +398,7 @@ /* #define DEBUG_CLIPPING */ static void -scale_pcm_data(char *data, int nframes, ao_sample_format *format, +scale_pcm_data(char *data, int nframes, int bits, int channels, double intercept, double minclip, double maxclip, float scale) { @@ -410,24 +410,28 @@ gint64 *data64 = (gint64*)data; #endif - switch(format->bits) { + switch(bits) { case 16: - for(i = 0; i < nframes * format->channels; i++) { + for(i = 0; i < nframes * channels; i++) { v = ((data16[i] - intercept) * scale) + intercept; #ifdef DEBUG_CLIPPING if (v > maxclip) printf("Clipping detected!\n"); + else if (v < minclip) + printf("Clipping detected!\n"); #endif v = CLAMP(v, minclip, maxclip); data16[i]=(gint16)v; } break; case 32: - for(i = 0; i < nframes * format->channels; i++) { + for(i = 0; i < nframes * channels; i++) { v = ((data32[i] - intercept) * scale) + intercept; #ifdef DEBUG_CLIPPING if (v > maxclip) printf("Clipping detected!\n"); + else if (v < minclip) + printf("Clipping detected!\n"); #endif v = CLAMP(v, minclip, maxclip); data32[i]=(gint32)v; @@ -435,11 +439,13 @@ break; #ifdef G_HAVE_GINT64 case 64: - for(i = 0; i < nframes * format->channels; i++) { + for(i = 0; i < nframes * channels; i++) { v = ((data64[i] - intercept) * scale) + intercept; #ifdef DEBUG_CLIPPING if (v > maxclip) printf("Clipping detected!\n"); + else if (v < minclip) + printf("Clipping detected!\n"); #endif v = CLAMP(v, minclip, maxclip); data64[i]=(gint64)v; @@ -447,7 +453,7 @@ break; #endif default: - gaim_debug_warning("gtksound", "Cannot scale %d bit pcm data.\n", format->bits); + gaim_debug_warning("gtksound", "Scaling of %d bit pcm data not supported.\n", bits); break; } } @@ -526,9 +532,13 @@ else if (pid == 0) { /* Child process */ - /* 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; + /* calculating the scaling factor: + * scale(x) = (x+30)^2 / 6400 + * scale(0) = 0.1406 (quiet) + * scale(50) = 1.0 (no scaling, normal volume) + * scale(100) = 2.6406 (roughly maximized without clipping) + */ + float scale = ( ((float)volume + 30) * ((float)volume + 30) ) / 6400; file = afOpenFile(filename, "rb", NULL); if(file) { ao_device *device; @@ -576,8 +586,10 @@ while((frames_read = afReadFrames(file, AF_DEFAULT_TRACK, buf, buf_frames))) { - scale_pcm_data(buf, frames_read, &format, intercept, - minclip, maxclip, scale); + /* no need to scale at volume == 50 */ + if(volume != 50) + scale_pcm_data(buf, frames_read, format.bits, format.channels, + intercept, minclip, maxclip, scale); if(!ao_play(device, buf, frames_read * bytes_per_frame)) break; }