Mercurial > audlegacy
comparison 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 |
comparison
equal
deleted
inserted
replaced
4848:b2ee645f3e59 | 4849:123b35cd71ab |
---|---|
68 equalizer_flow_reinit(context->srate, context->channels); | 68 equalizer_flow_reinit(context->srate, context->channels); |
69 eq_nch = context->channels; | 69 eq_nch = context->channels; |
70 eq_rate = context->srate; | 70 eq_rate = context->srate; |
71 bands_changed = FALSE; | 71 bands_changed = FALSE; |
72 } | 72 } |
73 | 73 |
74 data.nch = context->channels; | 74 data.nch = context->channels; |
75 data.audio = context->data; | 75 data.audio = context->data; |
76 data.len = context->len; | 76 data.len = context->len; |
77 eq->play(eq, &data); | 77 eq->play(eq, &data); |
78 } | 78 } |
80 void | 80 void |
81 equalizer_flow_set_bands(gfloat pre, gfloat *bands) | 81 equalizer_flow_set_bands(gfloat pre, gfloat *bands) |
82 { | 82 { |
83 int i; | 83 int i; |
84 af_control_ext_t ctl; | 84 af_control_ext_t ctl; |
85 gfloat b[10]; | 85 gfloat highest; |
86 gfloat adj = 0.0; | 86 gfloat adjusted [10]; |
87 AUDDBG("\n"); | 87 |
88 | |
89 if(eq == NULL) { | 88 if(eq == NULL) { |
90 eq = g_malloc(sizeof(af_instance_t)); | 89 eq = g_malloc(sizeof(af_instance_t)); |
91 equalizer_open(eq); | 90 equalizer_open(eq); |
92 } | 91 } |
93 | 92 |
94 for(i = 0; i < 10; i++) | 93 highest = - EQUALIZER_MAX_GAIN; |
95 b[i] = bands[i] + pre; | 94 for (i = 0; i < 10; i ++) { |
95 if (bands [i] > highest) | |
96 highest = bands [i]; | |
97 } | |
98 for (i = 0; i < 10; i ++) | |
99 adjusted [i] = pre + bands [i] - highest; | |
96 | 100 |
97 for(i = 0; i < 10; i++) | 101 ctl.arg = adjusted; |
98 if(fabsf(b[i]) > fabsf(adj)) adj = b[i]; | |
99 | |
100 if(fabsf(adj) > EQUALIZER_MAX_GAIN) { | |
101 adj = adj > 0.0 ? EQUALIZER_MAX_GAIN - adj : -EQUALIZER_MAX_GAIN - adj; | |
102 for(i = 0; i < 10; i++) b[i] += adj; | |
103 } | |
104 | |
105 ctl.arg = b; | |
106 for(i = 0; i < AF_NCH; i++) { | 102 for(i = 0; i < AF_NCH; i++) { |
107 ctl.ch = i; | 103 ctl.ch = i; |
108 eq->control(eq, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &ctl); | 104 eq->control(eq, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &ctl); |
109 } | 105 } |
110 | 106 |