Nsound  0.9.4
Spectrogram.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: Spectrogram.h 878 2014-11-23 04:51:23Z 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_SPECTROGRAM_H_
34 #define _NSOUND_SPECTROGRAM_H_
35 
36 #include <Nsound/WindowType.h>
37 
38 #include <string>
39 
40 namespace Nsound
41 {
42 
43 class AudioStream;
44 class Buffer;
45 
48 {
49  public:
50 
52  const Buffer & x,
53  const float64 & sample_rate,
54  const float64 & time_window,
55  const float64 & time_step,
56  const WindowType & type);
57 
58  Spectrogram(const Spectrogram & copy);
59 
60  ~Spectrogram();
61 
62  Buffer
63  getFrequencyAxis() const;
64 
66  getMagnitude() const;
67 
68  Buffer
69  getTimeAxis() const;
70 
71  Spectrogram &
72  operator=(const Spectrogram & rhs);
73 
74  void
75  plot(
76  const std::string & title = "",
77  const boolean & use_dB = true,
78  const float64 & squash = 0.5) const;
79 
80  // For use in a real-time loop, computes one-time slice from the last
81  // n samples and returns the frequency magnitude.
82  Buffer computeMagnitude(const Buffer & x);
83 
84  protected:
85 
87 
90 
91  AudioStream * real_; // Using an AudioStream as a 2D matrix
92  AudioStream * imag_; // Using an AudioStream as a 2D matrix
93 
98 
99 }; // class Spectrogram
100 
101 } // namespace Nsound
102 
103 // :mode=c++: jEdit modeline
104 #endif
unsigned int uint32
Definition: Nsound.h:153
Buffer computeMagnitude(const Buffer &x)
Definition: Spectrogram.cc:342
Buffer * frequency_axis_
Definition: Spectrogram.h:88
Buffer getTimeAxis() const
Definition: Spectrogram.cc:272
Spectrogram & operator=(const Spectrogram &rhs)
Definition: Spectrogram.cc:279
double float64
Definition: Nsound.h:146
The result from an STFT.
Definition: Spectrogram.h:47
uint32 n_window_samples_
Definition: Spectrogram.h:96
AudioStream * imag_
Definition: Spectrogram.h:92
Buffer getFrequencyAxis() const
Definition: Spectrogram.cc:258
AudioStream * real_
Definition: Spectrogram.h:91
A Class that performes the Fast Fouier Transfrom on a Buffer.
Definition: FFTransform.h:57
Buffer * fft_window_
Definition: Spectrogram.h:94
A Buffer for storing audio samples.
Definition: Buffer.h:60
FFTransform * fft_
Definition: Spectrogram.h:97
void plot(const std::string &title="", const boolean &use_dB=true, const float64 &squash=0.5) const
Definition: Spectrogram.cc:301
Spectrogram(const Buffer &x, const float64 &sample_rate, const float64 &time_window, const float64 &time_step, const WindowType &type)
Definition: Spectrogram.cc:44
AudioStream getMagnitude() const
Definition: Spectrogram.cc:265
WindowType
Definition: WindowType.h:39