summaryrefslogtreecommitdiff
path: root/06_performance/src/FFTOctaveAnalyzer.h
diff options
context:
space:
mode:
authorTim <tim@Admins-Mac-Pro-2.local>2013-06-19 20:03:17 +0100
committerTim <tim@Admins-Mac-Pro-2.local>2013-06-19 20:03:17 +0100
commitcdd0e0b630bd3a5a8ba15dbce7f5e03221b72f92 (patch)
tree4ada26f9bf3d4e0bdb97889472e95729433518a6 /06_performance/src/FFTOctaveAnalyzer.h
parent4fdd082d9a5657b0f9c613d47c2c58cea366a2e6 (diff)
working on performance version
Diffstat (limited to '06_performance/src/FFTOctaveAnalyzer.h')
-rw-r--r--06_performance/src/FFTOctaveAnalyzer.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/06_performance/src/FFTOctaveAnalyzer.h b/06_performance/src/FFTOctaveAnalyzer.h
new file mode 100644
index 0000000..8fef773
--- /dev/null
+++ b/06_performance/src/FFTOctaveAnalyzer.h
@@ -0,0 +1,45 @@
+
+#ifndef _FFTANALYZER
+#define _FFTANALYZER
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846 /* pi */
+#endif
+
+
+class FFTOctaveAnalyzer {
+
+public:
+
+ //FFT fft; // a reference to the FFT instance
+
+ float samplingRate; // sampling rate in Hz (needed to calculate frequency spans)
+ int nSpectrum; // number of spectrum bins in the fft
+ int nAverages; // number of averaging bins here
+ int nAveragesPerOctave; // number of averages per octave as requested by user
+ float spectrumFrequencySpan; // the "width" of an fft spectrum bin in Hz
+ float firstOctaveFrequency; // the "top" of the first averaging bin here in Hz
+ float averageFrequencyIncrement; // the root-of-two multiplier between averaging bin frequencies
+ float * averages; // the actual averages
+ float * peaks; // peaks of the averages, aka "maxAverages" in other implementations
+ int * peakHoldTimes; // how long to hold THIS peak meter? decay if == 0
+ int peakHoldTime; // how long do we hold peaks? (in fft frames)
+ float peakDecayRate; // how quickly the peaks decay: 0f=instantly .. 1f=not at all
+ int * spe2avg; // the mapping between spectrum[] indices and averages[] indices
+ // the fft's log equalizer() is no longer of any use (it would be nonsense to log scale
+ // the spectrum values into log-sized average bins) so here's a quick-and-dirty linear
+ // equalizer instead:
+ float linearEQSlope; // the rate of linear eq
+ float linearEQIntercept; // the base linear scaling used at the first averaging bin
+ // the formula is: spectrum[i] * (linearEQIntercept + i * linearEQSlope)
+ // so.. note that clever use of it can also provide a "gain" control of sorts
+ // (fe: set intercept to 2f and slope to 0f to double gain)
+
+ void setup(float samplingRate, int nBandsInTheFFT, int nAveragesPerOctave);
+
+ void calculate(float * fftData);
+
+};
+
+
+#endif