Mercurial > hg > flattendynamics
comparison flattendynamics-ladspa.cpp @ 3:12d364f12d37
delete/delete[] fix; max gain
author | Chris Cannam |
---|---|
date | Thu, 17 Jul 2014 16:23:17 +0100 |
parents | 57990edc441b |
children | e36fe9312ad4 |
comparison
equal
deleted
inserted
replaced
2:57990edc441b | 3:12d364f12d37 |
---|---|
9 using std::endl; | 9 using std::endl; |
10 | 10 |
11 const float historySeconds = 4.f; | 11 const float historySeconds = 4.f; |
12 const float catchUpSeconds = 0.5f; | 12 const float catchUpSeconds = 0.5f; |
13 const float targetRMS = 0.1f; | 13 const float targetRMS = 0.1f; |
14 const float maxGain = 20.f; | |
14 | 15 |
15 const char *const | 16 const char *const |
16 FlattenDynamics::portNames[PortCount] = | 17 FlattenDynamics::portNames[PortCount] = |
17 { | 18 { |
18 "Input", | 19 "Input", |
86 reset(); | 87 reset(); |
87 } | 88 } |
88 | 89 |
89 FlattenDynamics::~FlattenDynamics() | 90 FlattenDynamics::~FlattenDynamics() |
90 { | 91 { |
91 delete m_history; | 92 delete[] m_history; |
92 } | 93 } |
93 | 94 |
94 LADSPA_Handle | 95 LADSPA_Handle |
95 FlattenDynamics::instantiate(const LADSPA_Descriptor *, unsigned long rate) | 96 FlattenDynamics::instantiate(const LADSPA_Descriptor *, unsigned long rate) |
96 { | 97 { |
140 } | 141 } |
141 | 142 |
142 void | 143 void |
143 FlattenDynamics::reset() | 144 FlattenDynamics::reset() |
144 { | 145 { |
145 delete m_history; | 146 delete[] m_history; |
146 m_histlen = int(round(m_sampleRate * historySeconds)); | 147 m_histlen = int(round(m_sampleRate * historySeconds)); |
147 if (m_histlen < 1) m_histlen = 1; | 148 if (m_histlen < 1) m_histlen = 1; |
148 m_history = new float[m_histlen]; | 149 m_history = new float[m_histlen]; |
149 m_histwrite = 0; | 150 m_histwrite = 0; |
150 m_histread = 0; | 151 m_histread = 0; |
184 if (m_rms == 0.f) { | 185 if (m_rms == 0.f) { |
185 return f; | 186 return f; |
186 } | 187 } |
187 | 188 |
188 float targetGain = targetRMS / m_rms; | 189 float targetGain = targetRMS / m_rms; |
190 if (targetGain > maxGain) { | |
191 targetGain = maxGain; | |
192 } | |
189 float catchUpSamples = catchUpSeconds * m_sampleRate; | 193 float catchUpSamples = catchUpSeconds * m_sampleRate; |
190 // asymptotic, could improve? | 194 // asymptotic, could improve? |
191 m_gain = m_gain + (targetGain - m_gain) / catchUpSamples; | 195 m_gain = m_gain + (targetGain - m_gain) / catchUpSamples; |
192 if (fabsf(f) * m_gain > 1.f) { | 196 if (fabsf(f) * m_gain > 1.f) { |
193 m_gain = 1.f / fabsf(f); | 197 m_gain = 1.f / fabsf(f); |