CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Spectral.h
Go to the documentation of this file.
1 //
2 // Spectral.h -- UnitGenerator for going to/from the spectral domain
3 // These classes use the CSL 5 FFT wrapper for FFTs.
4 //
5 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
6 //
7
8 #ifndef CSL_Spectral_H
9 #define CSL_Spectral_H
10
11 #include "CSL_Core.h"
12 #include "FFT_Wrapper.h"
13
14 namespace csl {
15
16 ///
17 /// Forward FFT unit generator is an Effect because it handles an input
18 /// It puts spectral frames in the output buffer and then broadcasts a change message, so clients are expected to observe it.
19 ///
20
21 class FFT : public Effect {
22
23 public:
24 /// Default size to the buffer size and flags to measure
25 FFT(UnitGenerator & in, int size = CGestalt::blockSize(), CSL_FFTType type = CSL_FFT_COMPLEX);
26 ~FFT();
27 /// we override the general-case version because this needs a mono input
28 void nextBuffer(Buffer & outputBuffer) throw (CException);
29
30 int fftSize() { return mFFTSize; } /// no setter -- create a new FFT to change size
31
32 bool mOverwriteOutput; ///< whether to replace the output with the input (or the spectrum) after signalling observers
33
34 protected:
35 int mFFTSize; ///< This should be unsigned, but is signed for compatability with FFTW
36 FFTWrapper mWrapper; ///< actual FFT wrapper object
37 Buffer mInBuf; ///< input buffer
38 SampleBuffer mWindowBuffer; ///< Buffer to store window
39 };
40
41 ///
42 /// Inverse FFT
43 ///
44
45 class IFFT : public UnitGenerator {
46
47 public:
48 /// Default size to the buffer size and flags to measure
49 IFFT(int size = CGestalt::blockSize(), CSL_FFTType type = CSL_FFT_COMPLEX);
50 ~IFFT();
51 /// no setter -- create a new IFFT to change size
52 int fftSize() { return mFFTSize; }
53 /// getter methods
54 void binValue(int binNumber, float * outRealPart, float * outComplexPart);
55 void binValueMagPhase(int binNumber, float * outMag, float * outPhase);
56
57 // set the values in the specified bin
58 void setBin(int binNumber, float realPart, float imagPart);
59 void setBins(float * real, float * imag);
60 void setBins(SampleComplexVector cmplxSpectrum);
61 void setBins(SampleBuffer cmplxSpectrum);
62 void setBins(int lower, int upper, float* real, float* imag);
63 void setBinMagPhase(int binNumber, float mag, float phase);
64 void setBinsMagPhase(float* mags, float* phases);
65
66 void nextBuffer(Buffer & outputBuffer) throw (CException);
67
68 protected:
69 int mFFTSize; ///< This should be unsigned, but is signed for compatability with FFTW
70 FFTWrapper mWrapper; ///< actual FFT wrapper object
71 Buffer mInBuf; ///< input buffer
72 SampleComplexPtr mSpectrum; ///< spectral data I accumulate
73 };
74
75 }
76
77 #endif