CSL  6.0
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 
13 #define USE_FFTW
14 #include "FFT_Wrapper.h"
15 
16 namespace csl {
17 
18 ///
19 /// Forward FFT unit generator is an Effect because it handles an input
20 /// It puts spectral frames in the output buffer and then broadcasts a change message, so clients are expected to observe it.
21 ///
22 
23 class FFT : public Effect {
24 
25 public:
26  /// Default size to the buffer size and flags to measure
28  ~FFT();
29  /// we override the general-case version because this needs a mono input
30  void nextBuffer(Buffer & outputBuffer) throw (CException);
31 
32  int fftSize() { return mFFTSize; } /// no setter -- create a new FFT to change size
33 
34  bool mOverwriteOutput; ///< whether to replace the output with the input (or the spectrum) after signalling observers
35 
36 protected:
37  int mFFTSize; ///< This should be unsigned, but is signed for compatability with FFTW
38  FFT_Wrapper mWrapper; ///< actual FFT wrapper object
39  Buffer mInBuf; ///< input buffer
40  SampleBuffer mWindowBuffer; ///< Buffer to store window
41 };
42 
43 ///
44 /// Inverse FFT
45 ///
46 
47 class IFFT : public UnitGenerator {
48 
49 public:
50  /// Default size to the buffer size and flags to measure
52  ~IFFT();
53  /// no setter -- create a new IFFT to change size
54  int fftSize() { return mFFTSize; }
55  /// getter methods
56  void binValue(int binNumber, float * outRealPart, float * outComplexPart);
57  void binValueMagPhase(int binNumber, float * outMag, float * outPhase);
58 
59  // set the values in the specified bin
60  void setBin(int binNumber, float realPart, float imagPart);
61  void setBins(float * real, float * imag);
62  void setBins(SampleComplexVector cmplxSpectrum);
63  void setBins(SampleBuffer cmplxSpectrum);
64  void setBins(int lower, int upper, float* real, float* imag);
65  void setBinMagPhase(int binNumber, float mag, float phase);
66  void setBinsMagPhase(float* mags, float* phases);
67 
68  void nextBuffer(Buffer & outputBuffer) throw (CException);
69 
70 protected:
71  int mFFTSize; ///< This should be unsigned, but is signed for compatability with FFTW
72  FFT_Wrapper mWrapper; ///< actual FFT wrapper object
73  Buffer mInBuf; ///< input buffer
74  SampleComplexPtr mSpectrum; ///< spectral data I accumulate
75 };
76 
77 }
78 
79 #endif
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
void setBin(int binNumber, float realPart, float imagPart)
Definition: Spectral.cpp:81
SampleComplex * SampleComplexVector
complex vector
Definition: CSL_Types.h:202
void binValueMagPhase(int binNumber, float *outMag, float *outPhase)
Definition: Spectral.cpp:74
void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
Definition: Spectral.cpp:137
SampleBuffer mWindowBuffer
Buffer to store window.
Definition: Spectral.h:40
CSL_FFTType
real/complex flag (determines results from forward FFT)
Definition: FFT_Wrapper.h:55
Inverse FFT.
Definition: Spectral.h:47
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
Effect – mix-in for classes that have unit generators as inputs (like filters).
Definition: CSL_Core.h:466
FFT(UnitGenerator &in, int size=CGestalt::blockSize(), CSL_FFTType type=CSL_FFT_COMPLEX)
Default size to the buffer size and flags to measure.
Definition: Spectral.cpp:19
void setBinsMagPhase(float *mags, float *phases)
Definition: Spectral.cpp:128
void binValue(int binNumber, float *outRealPart, float *outComplexPart)
getter methods
Definition: Spectral.cpp:69
void setBinMagPhase(int binNumber, float mag, float phase)
Definition: Spectral.cpp:121
FFT_Wrapper mWrapper
actual FFT wrapper object
Definition: Spectral.h:38
Buffer mInBuf
input buffer
Definition: Spectral.h:73
static unsigned blockSize()
the default block size
Definition: CGestalt.cpp:57
void nextBuffer(Buffer &outputBuffer)
we override the general-case version because this needs a mono input
Definition: Spectral.cpp:36
int mFFTSize
This should be unsigned, but is signed for compatability with FFTW.
Definition: Spectral.h:71
int fftSize()
Definition: Spectral.h:32
static size_t size
Definition: fft_N.c:40
void setBins(float *real, float *imag)
Definition: Spectral.cpp:89
Forward FFT unit generator is an Effect because it handles an input It puts spectral frames in the ou...
Definition: Spectral.h:23
IFFT(int size=CGestalt::blockSize(), CSL_FFTType type=CSL_FFT_COMPLEX)
Default size to the buffer size and flags to measure.
Definition: Spectral.cpp:59
int mFFTSize
This should be unsigned, but is signed for compatability with FFTW.
Definition: Spectral.h:37
FFT_Wrapper mWrapper
actual FFT wrapper object
Definition: Spectral.h:72
SampleComplex * SampleComplexPtr
complex pointer
Definition: CSL_Types.h:203
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
Buffer mInBuf
input buffer
Definition: Spectral.h:39
bool mOverwriteOutput
no setter – create a new FFT to change size
Definition: Spectral.h:34
forward declaration
Definition: CSL_Core.h:241
int fftSize()
no setter – create a new IFFT to change size
Definition: Spectral.h:54
SampleComplexPtr mSpectrum
spectral data I accumulate
Definition: Spectral.h:74
Base class of CSL exceptions (written upper-case). Has a string message.