Showing the changes to Spectacle/SpectEQ.cpp (1 of 32 files). Show all
Unified · Split
| @@ -0,0 +1,117 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2007 John Gibson | |
| 3 | + * | |
| 4 | + * This program is free software; you can redistribute it and/or modify | |
| 5 | + * it under the terms of the GNU General Public License, version 2, as | |
| 6 | + * published by the Free Software Foundation. | |
| 7 | + * | |
| 8 | + * This program is distributed in the hope that it will be useful, | |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 | + * GNU General Public License for more details. | |
| 12 | + */ | |
| 13 | + | |
| 14 | +// derived from RTcmix SPECTEQ2.cpp, (C) John Gibson 2005. | |
| 15 | + | |
| 16 | +//#define DEBUG | |
| 17 | +#include "SpectEQ.h" | |
| 18 | +#include <cstdlib> | |
| 19 | + | |
| 20 | +// ------------------------------------------------------------------ SpectEQ -- | |
| 21 | +SpectEQ::SpectEQ() | |
| 22 | + : _eqconst(0.0f), _eqtable(NULL) | |
| 23 | +{ | |
| 24 | +} | |
| 25 | + | |
| 26 | + | |
| 27 | +// ----------------------------------------------------------------- ~SpectEQ -- | |
| 28 | +SpectEQ::~SpectEQ() | |
| 29 | +{ | |
| 30 | + // We don't own eq table. | |
| 31 | +} | |
| 32 | + | |
| 33 | + | |
| 34 | +// --------------------------------------------------------------------- init -- | |
| 35 | +// Invoke base init, and perform any initialization specific to this subclass. | |
| 36 | +// Return 0 if okay, -1 if not. | |
| 37 | + | |
| 38 | +int SpectEQ::init(int fftlen, int windowlen, int overlap, float srate) | |
| 39 | +{ | |
| 40 | + return SpectacleBase::init(fftlen, windowlen, overlap, srate); | |
| 41 | +} | |
| 42 | + | |
| 43 | + | |
| 44 | +// ---------------------------------------------------------------- set_srate -- | |
| 45 | +void SpectEQ::set_srate(float srate) | |
| 46 | +{ | |
| 47 | + SpectacleBase::set_srate(srate); | |
| 48 | +} | |
| 49 | + | |
| 50 | + | |
| 51 | +// -------------------------------------------------------------- set_eqtable -- | |
| 52 | +void SpectEQ::set_eqtable(float *table, int len) | |
| 53 | +{ | |
| 54 | + if (len == 0) { // no table set yet by caller | |
| 55 | + _eqconst = 0.0; | |
| 56 | + _eqtable = NULL; | |
| 57 | + _control_table_size = 0; | |
| 58 | + } | |
| 59 | + else if (len == 1) { | |
| 60 | + _eqconst = table[0]; | |
| 61 | + _eqtable = NULL; | |
| 62 | + _control_table_size = 0; | |
| 63 | + } | |
| 64 | + else { | |
| 65 | + _eqconst = 0.0; | |
| 66 | + _eqtable = table; | |
| 67 | + if (len != _control_table_size) { | |
| 68 | + _control_table_size = len; | |
| 69 | + update_bin_groups(_bin_groups, NULL, get_minfreq(), get_maxfreq(), | |
| 70 | + _control_table_size); | |
| 71 | + } | |
| 72 | + } | |
| 73 | +} | |
| 74 | + | |
| 75 | + | |
| 76 | +// --------------------------------------------------------- set_binmap_table -- | |
| 77 | +// Set pointer to externally allocated table. Pass table=NULL for no table. | |
| 78 | +// <len> must be the same as the current control table size, or else we use | |
| 79 | +// no table, without warning -- responsibility of caller to handle this. | |
| 80 | + | |
| 81 | +void SpectEQ::set_binmap_table(int *table, int len) | |
| 82 | +{ | |
| 83 | + if (len != _control_table_size) | |
| 84 | + _binmaptable = NULL; | |
| 85 | + else | |
| 86 | + _binmaptable = table; | |
| 87 | + update_bin_groups(_bin_groups, NULL, get_minfreq(), get_maxfreq(), | |
| 88 | + _control_table_size); | |
| 89 | +} | |
| 90 | + | |
| 91 | + | |
| 92 | +// ---------------------------------------------------------- modify_analysis -- | |
| 93 | +void SpectEQ::modify_analysis(bool) | |
| 94 | +{ | |
| 95 | + DPRINT("modify_analysis: ....................."); | |
| 96 | + | |
| 97 | + // NB: check EQ table size, rather than table pointer, to determine whether | |
| 98 | + // we should use an EQ constant. Otherwise, there's a danger we could read | |
| 99 | + // a null EQ table pointer, if set_eqtable called by non-perf thread. | |
| 100 | + if (_control_table_size == 0) { // constant gain across bins | |
| 101 | + const float eq = _ampdb(_eqconst); | |
| 102 | + const int len = get_fftlen(); | |
| 103 | + for (int i = 0; i < len; i++) | |
| 104 | + _fft_buf[i] *= eq; | |
| 105 | + } | |
| 106 | + else { | |
| 107 | + for (int i = 0; i < _half_fftlen; i++) { | |
| 108 | + const float eq = _ampdb(_eqtable[_bin_groups[i]]); | |
| 109 | + const int index = i << 1; | |
| 110 | + _fft_buf[index] *= eq; // real | |
| 111 | + _fft_buf[index + 1] *= eq; // imag | |
| 112 | + } | |
| 113 | + } | |
| 114 | + _fft_buf[1] = 0.0f; // clear Nyquist real value | |
| 115 | +} | |
| 116 | + | |
| 117 | + | |