Nsound  0.9.4
FFTChunk.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: FFTChunk.h 874 2014-09-08 02:21:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2008-Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_FFT_CHUNK_H_
34 #define _NSOUND_FFT_CHUNK_H_
35 
36 #include <Nsound/Nsound.h>
37 
38 #include <cmath>
39 #include <iostream>
40 #include <vector>
41 
42 namespace Nsound
43 {
44 
45 // forward declare
46 class Buffer;
47 
49 class FFTChunk
50 {
51  public:
52 
53  FFTChunk(uint32 size=32, uint32 sample_rate=44100, uint32 original_size = 0);
54 
55  FFTChunk(const FFTChunk & copy);
56 
57  ~FFTChunk();
58 
59  Buffer
60  getFrequencyAxis() const;
61 
62  Buffer
63  getReal() const;
64 
65  Buffer
66  getImaginary() const;
67 
68  Buffer
69  getMagnitude() const;
70 
71  uint32
72  getOriginalSize() const { return original_size_; };
73 
74  Buffer
75  getPhase() const;
76 
77  boolean
78  isPolar() const { return is_polar_; };
79 
80  FFTChunk &
81  operator=(const FFTChunk & rhs);
82 
83  void
84  plot(
85  const std::string & title = "",
86  boolean dB = true,
87  boolean show_phase = false) const;
88 
90  void
91  setCartesian(const Buffer & real, const Buffer & imaginary);
92 
94  void
95  setPolar(const Buffer & magnitude, const Buffer & phase);
96 
98  void
99  toPolar();
100 
102  void
103  toCartesian();
104 
107 
108  uint32 getSampleRate() const {return sample_rate_;};
109 
110  protected:
111 
114  boolean is_polar_;
115 
116 
117 }; // class FFTChunk
118 
119 typedef std::vector< FFTChunk > FFTChunkVector;
120 
121 } // namespace Nsound
122 
123 // :mode=c++: jEdit modeline
124 #endif
unsigned int uint32
Definition: Nsound.h:153
Buffer getFrequencyAxis() const
Definition: FFTChunk.cc:109
Buffer getImaginary() const
Definition: FFTChunk.cc:87
FFTChunk & operator=(const FFTChunk &rhs)
Definition: FFTChunk.cc:214
Results of performing an FFT are stored in this class.
Definition: FFTChunk.h:49
void toCartesian()
convertes the magnitude & phase to cartesian form: real & imaginary
Definition: FFTChunk.cc:340
Buffer getReal() const
Definition: FFTChunk.cc:127
Buffer * imag_
Definition: FFTChunk.h:106
void plot(const std::string &title="", boolean dB=true, boolean show_phase=false) const
Definition: FFTChunk.cc:232
void setPolar(const Buffer &magnitude, const Buffer &phase)
Sets up an FFTChunk to use the provided magnitude & phase.
Definition: FFTChunk.cc:325
void toPolar()
convertes the real & imaginary unit to plor form: magnitude & phase
Definition: FFTChunk.cc:362
Buffer getMagnitude() const
Definition: FFTChunk.cc:149
Buffer getPhase() const
Definition: FFTChunk.cc:175
uint32 getSampleRate() const
Definition: FFTChunk.h:108
uint32 original_size_
Definition: FFTChunk.h:113
boolean is_polar_
Definition: FFTChunk.h:114
uint32 sample_rate_
Definition: FFTChunk.h:108
FFTChunk(uint32 size=32, uint32 sample_rate=44100, uint32 original_size=0)
Definition: FFTChunk.cc:46
Buffer * real_
Definition: FFTChunk.h:105
A Buffer for storing audio samples.
Definition: Buffer.h:60
boolean isPolar() const
Definition: FFTChunk.h:78
void setCartesian(const Buffer &real, const Buffer &imaginary)
Sets up an FFTChunk to use the provided real & imaginary.
Definition: FFTChunk.cc:310
std::vector< FFTChunk > FFTChunkVector
Definition: FFTChunk.h:119
uint32 getOriginalSize() const
Definition: FFTChunk.h:72