-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spectrum.h
52 lines (41 loc) · 1.03 KB
/
Spectrum.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <cstddef>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <memory>
#include <fftw3.h>
#include "util.h"
class Spectrum {
public:
Spectrum(const size_t size);
~Spectrum();
// input windowing
void UseHanningWindow();
void UseHammingWindow();
void UseBlackmanWindow();
// output windowing (normalisation)
void UseFlatNormalisation();
void UseLinearNormalisation(float start, float end);
void Update(const float data[]);
float BarDataAt(float i) const;
void GetData(
float freq_min,
float freq_max,
float sample_rate,
float output[],
size_t output_size
) const;
// configurables
float scale = 1;
float average_weight = 0.6;
std::unique_ptr<float[]> wave_window;
std::unique_ptr<float[]> normalisation_window;
// output
std::unique_ptr<float[]> bar_data;
private:
size_t size, bar_data_size;
std::unique_ptr<double[]> fft_in;
fftw_complex *fft_out;
fftw_plan plan;
};