-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpectrum.h
More file actions
161 lines (140 loc) · 4.13 KB
/
Copy pathSpectrum.h
File metadata and controls
161 lines (140 loc) · 4.13 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
SignalView LV2 analysis plugin
Copyright (C) 2025 Timothy William Krause
mailto:tmkrs4482@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
==============================================================================
Spectrum.h
Created: 18 Jan 2024 8:50:34pm
Author: tim
==============================================================================
*/
#pragma once
#include <complex>
#include <fftw3.h>
#include <memory>
#include <iostream>
#include <deque>
#include "TGraph.h"
#include "LGraph.h"
#include "GraphFill.h"
#include "Waterfall.h"
#include "Grid.h"
#include "Semaphore.h"
struct PtrFifo
{
private:
std::deque<int> fifo;
Semaphore sem;
public:
PtrFifo() : sem(1)
{
}
void Push(int i)
{
sem.wait();
fifo.push_back(i);
sem.post();
}
int Pop(void)
{
sem.wait();
int r = fifo.front();
fifo.pop_front();
sem.post();
return r;
}
int GetNumReady(void)
{
return fifo.size();
}
};
class Spectrum
{
public:
Spectrum(
int Nfft,
double fsamplerate,
float frame_rate,
int Ncopy,
const char* bundle_path);
~Spectrum();
void GLInit(void);
void GLDestroy(void);
void Render(void);
void EvaluateSample(float xl, float xr);
void SetdBLimits(float dB_min, float dB_max);
void SetWidth(float frequency);
void SetColors(float hue_left);
void SetFrequency(bool log=false);
private:
int Nfft;
int Nfft_draw;
int Ndx_draw;
int Npoints;
int Npoints_p;
int Ncopy;
const char* bundle_path;
int index_last;
int i_buffer;
int i_sample;
int Ncount;
int count;
int i_draw_front;
int i_draw_back;
bool log;
bool log_last;
float alpha_width;
glm::vec4 time_color_l0;
glm::vec4 time_color_l1;
glm::vec4 time_color_r0;
glm::vec4 time_color_r1;
glm::vec4 freq_color_l0;
glm::vec4 freq_color_l1;
glm::vec4 freq_color_r0;
glm::vec4 freq_color_r1;
glm::vec4 fill_color_l;
glm::vec4 fill_color_r;
double fsamplerate;
float frame_rate;
std::unique_ptr<float[]> x_cyclic_in_l;
std::unique_ptr<float[]> x_cyclic_in_r;
std::unique_ptr<std::unique_ptr<float[]>[]> x_draw_l_raw;
std::unique_ptr<std::unique_ptr<float[]>[]> x_draw_r_raw;
std::unique_ptr<float[]> dx_draw_raw;
std::unique_ptr<float[]> x_draw;
std::unique_ptr<float[]> v_draw;
std::unique_ptr<std::unique_ptr<float[]>[]> x_in_l;
std::unique_ptr<std::unique_ptr<float[]>[]> x_in_r;
std::unique_ptr<double[]> x_fft;
bool dataReady;
std::unique_ptr<std::complex<double>[]> X_fft;
fftw_plan x_plan;
std::unique_ptr<float[]> X_db_l;
std::unique_ptr<float[]> X_db_r;
std::unique_ptr<float[]> x_points;
std::unique_ptr<float[]> X_db_l_p;
std::unique_ptr<float[]> X_db_r_p;
std::unique_ptr<float[]> x_points_p;
PtrFifo ptrFifo;
std::unique_ptr<LGraph> lgraph;
std::unique_ptr<TGraph> tgraph;
std::unique_ptr<GraphFill> fill;
std::unique_ptr<Waterfall> waterfall;
std::unique_ptr<Grid> grid;
void ComputeSpectrum(float *x, std::unique_ptr<float[]> &X_db);
void InitializeFrequency(void);
void CoalescePoints(int pix_width);
void ShadeGraph(std::unique_ptr<float[]> &x_raw, int width_pix, int height_pix);
};