diff options
Diffstat (limited to 'servers/audio/effects/eq.cpp')
-rw-r--r-- | servers/audio/effects/eq.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/servers/audio/effects/eq.cpp b/servers/audio/effects/eq.cpp index 426f178dcb..08a6cf55fa 100644 --- a/servers/audio/effects/eq.cpp +++ b/servers/audio/effects/eq.cpp @@ -42,48 +42,45 @@ static int solve_quadratic(double a, double b, double c, double *r1, double *r2) //solves quadractic and returns number of roots double base = 2 * a; - if (base == 0.0f) + if (base == 0.0f) { return 0; + } double squared = b * b - 4 * a * c; - if (squared < 0.0) + if (squared < 0.0) { return 0; + } squared = sqrt(squared); *r1 = (-b + squared) / base; *r2 = (-b - squared) / base; - if (*r1 == *r2) + if (*r1 == *r2) { return 1; - else + } else { return 2; + } } EQ::BandProcess::BandProcess() { - c1 = c2 = c3 = history.a1 = history.a2 = history.a3 = 0; history.b1 = history.b2 = history.b3 = 0; } void EQ::recalculate_band_coefficients() { - #define BAND_LOG(m_f) (log((m_f)) / log(2.)) for (int i = 0; i < band.size(); i++) { - double octave_size; double frq = band[i].freq; if (i == 0) { - octave_size = BAND_LOG(band[1].freq) - BAND_LOG(frq); } else if (i == (band.size() - 1)) { - octave_size = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq); } else { - double next = BAND_LOG(band[i + 1].freq) - BAND_LOG(frq); double prev = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq); octave_size = (next + prev) / 2.0; @@ -118,27 +115,24 @@ void EQ::recalculate_band_coefficients() { } void EQ::set_preset_band_mode(Preset p_preset) { - band.clear(); #define PUSH_BANDS(m_bands) \ for (int i = 0; i < m_bands; i++) { \ Band b; \ b.freq = bands[i]; \ + b.c1 = b.c2 = b.c3 = 0; \ band.push_back(b); \ } switch (p_preset) { - case PRESET_6_BANDS: { - static const double bands[] = { 32, 100, 320, 1e3, 3200, 10e3 }; PUSH_BANDS(6); } break; case PRESET_8_BANDS: { - static const double bands[] = { 32, 72, 192, 512, 1200, 3000, 7500, 16e3 }; PUSH_BANDS(8); @@ -152,14 +146,12 @@ void EQ::set_preset_band_mode(Preset p_preset) { } break; case PRESET_21_BANDS: { - static const double bands[] = { 22, 32, 44, 63, 90, 125, 175, 250, 350, 500, 700, 1e3, 1400, 2e3, 2800, 4e3, 5600, 8e3, 11e3, 16e3, 22e3 }; PUSH_BANDS(21); } break; case PRESET_31_BANDS: { - static const double bands[] = { 20, 25, 31.5, 40, 50, 63, 80, 100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1e3, 1250, 1600, 2e3, 2500, 3150, 4e3, 5e3, 6300, 8e3, 10e3, 12500, 16e3, 20e3 }; PUSH_BANDS(31); } break; @@ -169,19 +161,17 @@ void EQ::set_preset_band_mode(Preset p_preset) { } int EQ::get_band_count() const { - return band.size(); } -float EQ::get_band_frequency(int p_band) { +float EQ::get_band_frequency(int p_band) { ERR_FAIL_INDEX_V(p_band, band.size(), 0); return band[p_band].freq; } -void EQ::set_bands(const Vector<float> &p_bands) { +void EQ::set_bands(const Vector<float> &p_bands) { band.resize(p_bands.size()); for (int i = 0; i < p_bands.size(); i++) { - band.write[i].freq = p_bands[i]; } @@ -189,13 +179,11 @@ void EQ::set_bands(const Vector<float> &p_bands) { } void EQ::set_mix_rate(float p_mix_rate) { - mix_rate = p_mix_rate; recalculate_band_coefficients(); } EQ::BandProcess EQ::get_band_processor(int p_band) const { - EQ::BandProcess band_proc; ERR_FAIL_INDEX_V(p_band, band.size(), band_proc); |