Mercurial > audlegacy
diff src/audlegacy/equalizer_flow.c @ 4849:123b35cd71ab
Heal the equalizer's clipping prevention of insanity
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Sun, 12 Apr 2009 23:52:38 -0400 |
parents | 7bf7f83a217e |
children | d3af4699043f |
line wrap: on
line diff
--- a/src/audlegacy/equalizer_flow.c Sun Apr 12 23:03:39 2009 -0400 +++ b/src/audlegacy/equalizer_flow.c Sun Apr 12 23:52:38 2009 -0400 @@ -70,7 +70,7 @@ eq_rate = context->srate; bands_changed = FALSE; } - + data.nch = context->channels; data.audio = context->data; data.len = context->len; @@ -82,27 +82,23 @@ { int i; af_control_ext_t ctl; - gfloat b[10]; - gfloat adj = 0.0; - AUDDBG("\n"); - + gfloat highest; + gfloat adjusted [10]; + if(eq == NULL) { eq = g_malloc(sizeof(af_instance_t)); equalizer_open(eq); } - for(i = 0; i < 10; i++) - b[i] = bands[i] + pre; - - for(i = 0; i < 10; i++) - if(fabsf(b[i]) > fabsf(adj)) adj = b[i]; + highest = - EQUALIZER_MAX_GAIN; + for (i = 0; i < 10; i ++) { + if (bands [i] > highest) + highest = bands [i]; + } + for (i = 0; i < 10; i ++) + adjusted [i] = pre + bands [i] - highest; - if(fabsf(adj) > EQUALIZER_MAX_GAIN) { - adj = adj > 0.0 ? EQUALIZER_MAX_GAIN - adj : -EQUALIZER_MAX_GAIN - adj; - for(i = 0; i < 10; i++) b[i] += adj; - } - - ctl.arg = b; + ctl.arg = adjusted; for(i = 0; i < AF_NCH; i++) { ctl.ch = i; eq->control(eq, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &ctl);