SoDaRadio-5.0.3-master:8901fb5
Spectrogram.hxx
Go to the documentation of this file.
1 /*
2 Copyright (c) 2012,2013,2014 Matthew H. Reilly (kb1vc)
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef SPECTROGRAM_HDR
30 #define SPECTROGRAM_HDR
31 #include <fstream>
32 #include <complex>
33 #include <fftw3.h>
34 
35 namespace SoDa {
39  class Spectrogram {
40  public:
46  Spectrogram(unsigned int fftlen);
47 
57  void apply_acc(std::complex<float> * invec, unsigned int inveclen,
58  float * outvec,
59  float accumulation_gain = 0.0);
60 
70  void apply_max(std::complex<float> * invec, unsigned int inveclen,
71  float * outvec, bool first = true);
72 
73 
74  private:
75 
79  float * initBlackmanHarris();
80 
87  void apply_common(std::complex<float> * invec, unsigned int inveclen);
88 
89  fftwf_plan fftplan;
90  float * window;
91  std::complex<float> * win_samp;
92  std::complex<float> * fft_out;
93  float * result;
94  unsigned int fft_len;
95  };
96 }
97 
98 #endif
float * initBlackmanHarris()
all spectrograms are under a blackman harris window
Definition: Spectrogram.cxx:55
void apply_acc(std::complex< float > *invec, unsigned int inveclen, float *outvec, float accumulation_gain=0.0)
Calculate the spectrogram from an input vector – add it to an accumulation buffer.
fftwf_plan fftplan
Definition: Spectrogram.hxx:89
Spectrogram(unsigned int fftlen)
Constructor.
Definition: Spectrogram.cxx:34
std::complex< float > * win_samp
Definition: Spectrogram.hxx:91
unsigned int fft_len
Definition: Spectrogram.hxx:94
std::complex< float > * fft_out
Definition: Spectrogram.hxx:92
Spectrogram generates magnitude buffers from input sample stream.
Definition: Spectrogram.hxx:39
void apply_max(std::complex< float > *invec, unsigned int inveclen, float *outvec, bool first=true)
Calculate the spectrogram from an input vector – add it to an accumulation buffer.
void apply_common(std::complex< float > *invec, unsigned int inveclen)
this is the common spectrogram calculation (window + fft + mag)
Definition: Spectrogram.cxx:74