SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
Spectrogram.hxx
Go to the documentation of this file.
1/*
2Copyright (c) 2012,2013,2014,2025 Matthew H. Reilly (kb1vc)
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are
7met:
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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#pragma once
30
31#include <fstream>
32#include <complex>
33#include <fftw3.h>
34#include "SoDaBase.hxx"
35
36namespace SoDa {
40
41 class Spectrogram;
42 typedef std::shared_ptr<Spectrogram> SpectrogramPtr;
43
44
45
46 class Spectrogram : public Base {
47 protected:
53 Spectrogram(unsigned int fftlen);
54
55 public:
56 static SpectrogramPtr make(unsigned int fftlen) {
57 auto ret = std::shared_ptr<Spectrogram>(new Spectrogram(fftlen));
58 ret->registerSelf(ret);
59 return ret;
60 }
61
70 void apply_acc(std::vector<std::complex<float>> & invec,
71 std::vector<float> & outvec,
72 float accumulation_gain = 0.0);
73
82 void apply_max(std::vector<std::complex<float>> & invec,
83 std::vector<float> & outvec, bool first = true);
84
85
86 private:
87
92
98 void apply_common(std::vector<std::complex<float>> & invec);
99
100 fftwf_plan fftplan;
101 float * window;
102 std::complex<float> * win_samp;
103 std::complex<float> * fft_out;
104 float * result;
105 unsigned int fft_len;
106 };
107}
108
The Baseclass for all SoDa objects, and useful commonly used classes.
Base(const std::string &oname)
The constructor – pass a name for the object.
std::complex< float > * win_samp
void apply_acc(std::vector< std::complex< float > > &invec, std::vector< float > &outvec, float accumulation_gain=0.0)
Calculate the spectrogram from an input vector – add it to an accumulation buffer.
static SpectrogramPtr make(unsigned int fftlen)
unsigned int fft_len
Spectrogram(unsigned int fftlen)
Constructor.
std::complex< float > * fft_out
void apply_common(std::vector< std::complex< float > > &invec)
this is the common spectrogram calculation (window + fft + mag)
float * initBlackmanHarris()
all spectrograms are under a blackman harris window
void apply_max(std::vector< std::complex< float > > &invec, std::vector< float > &outvec, bool first=true)
Calculate the spectrogram from an input vector – add it to an accumulation buffer.
std::shared_ptr< Spectrogram > SpectrogramPtr