-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpectrogram.h
236 lines (196 loc) · 5.91 KB
/
Spectrogram.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
* @file Spectrogram.h
* @author J. Bitzer @ TGM@ Jade Hochschule
* @brief This classes implements a spectrogram and a view to the data in the JUCE framework
* @version 0.1
* @date 2021-06-05
*
* @copyright Copyright (c) 2021
*
*/
#pragma once
#include <vector>
#include "SynchronBlockProcessor.h"
#include "FFT.h"
#include "CColorpalette.h"
#include "PlugInGUISettings.h"
class JadeSpectrogramAudioProcessorEditor;
const struct
{
const std::string ID = "MinFreq";
std::string name = "MinFreq";
std::string unitName = "Hz";
float minValue = log(1.f);
float maxValue = log(10000.f);
float defaultValue = log(1.f);
}paramDisplayMinFreq;
const struct
{
const std::string ID = "MaxFreq";
std::string name = "MaxFreq";
std::string unitName = "Hz";
float minValue = log(500.f);
float maxValue = log(20000.f);
float defaultValue = log(20000.f);
}paramDisplayMaxFreq;
const struct
{
const std::string ID = "MinColor";
std::string name = "MinColor";
std::string unitName = "";
float minValue = g_minColorVal;
float maxValue = g_maxColorVal;
float defaultValue = g_minColorVal;
}paramDisplayMinColor;
const struct
{
const std::string ID = "MaxColor";
std::string name = "MaxColor";
std::string unitName = "";
float minValue = g_minColorVal;
float maxValue = g_maxColorVal;
float defaultValue =g_maxColorVal;
}paramDisplayMaxColor;
class SpectrogramParameter
{
public:
SpectrogramParameter(){};
int addParameter(std::vector < std::unique_ptr<RangedAudioParameter>>& paramVector);
public:
std::atomic<float>* m_DisplayMinFreq;
float m_DisplayMinFreqOld;
std::atomic<float>* m_DisplayMaxFreq;
float m_DisplayMaxFreqOld;
std::atomic<float>* m_DisplayMinColor;
float m_DisplayMinColorOld;
std::atomic<float>* m_DisplayMaxColor;
float m_DisplayMaxColorOld;
};
class Spectrogram : public SynchronBlockProcessor
{
public:
enum class ChannelMixMode
{
AbsMean,
Max,
Min,
Left,
Right
};
enum class Windows
{
Rect,
Hann,
Hamming,
BlackmanHarris,
FlatTop,
HannPoisson
};
enum class FeedPercentage
{
perc100,
perc50,
perc25,
perc10
};
Spectrogram();
// void prepareToPlay();
virtual int processSynchronBlock(std::vector <std::vector<float>>&, juce::MidiBuffer& midiMessages);
void prepareParameter(std::unique_ptr<AudioProcessorValueTreeState>& vts);
// setter
void setSamplerate(float samplerate);
void setchannels(size_t newchannels);
void setFFTSize(size_t newFFTSize);
void setclosestFFTSize_ms(float fftsize_ms);
void setmemoryTime_s (float memsize_s);
void setfeed_percent (FeedPercentage feed);
void setPauseMode (bool mode){m_PauseMode = mode;};
void setWindow (Spectrogram::Windows win){m_windowChoice = win;setWindowFkt();};
size_t getnextpowerof2(float fftsize_ms);
int getSpectrumSize(){return m_freqsize;};
int getMemorySize(){return m_memsize_blocks;};
int getMem(std::vector<std::vector<float >>& mem, int& pos);
float getSamplerate(){return m_fs;};
private:
CriticalSection m_protect;
float m_fs;
size_t m_channels;
float m_feed_percent;
int m_feed_samples;
int m_feedblocks;
float m_memsize_s;
int m_memsize_blocks;
size_t m_freqsize;
size_t m_fftsize;
ChannelMixMode m_mode;
std::vector<std::vector<float >> m_mem;
int m_newEntryCounter;
int m_memCounter;
std::vector<float> m_intime;
std::vector<std::vector<float>> m_indatamem;
int m_feedcounter;
int m_inCounter;
std::vector<std::vector<float>> m_power;
std::vector<float> m_powerfinal;
spectrum m_fft;
Windows m_windowChoice;
std::vector<float> m_window;
void buildmem();
void computePowerSpectrum(std::vector<float>& in, std::vector<float>& power);
void setWindowFkt();
SpectrogramParameter m_SpecParameter;
bool m_PauseMode;
};
class SpectrogramComponent : public Component, public Timer
{
public:
SpectrogramComponent(AudioProcessorValueTreeState& vts, Spectrogram& spectrogram, JadeSpectrogramAudioProcessorEditor& editor);
~SpectrogramComponent(){stopTimer();};
void paint(Graphics& g) override;
void resized() override;
void setScaleFactor(float newscale){m_scaleFactor = newscale;};
void timerCallback() override;
std::function<void()> somethingChanged;
void mouseMove (const MouseEvent& event);
private:
float m_scaleFactor;
Spectrogram& m_spectrogram;
std::vector<std::vector<float >> m_displaymem;
Image m_internalImg;
Image m_ColorbarImg;
int m_internalWidth;
int m_internalHeight;
bool m_recomputeAll;
float m_maxColorVal;
float m_minColorVal;
CColorPalette m_colorpalette;
float m_maxDisplayFreq;
float m_minDisplayFreq;
// Othe UI Elements
AudioProcessorValueTreeState& m_vts;
Label m_DisplayMinFreqLabel;
Slider m_DisplayMinFreqSlider;
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> m_DisplayMinFreqAttachment;
Label m_DisplayMaxFreqLabel;
Slider m_DisplayMaxFreqSlider;
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> m_DisplayMaxFreqAttachment;
Label m_DisplayMinColorLabel;
Slider m_DisplayMinColorSlider;
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> m_DisplayMinColorAttachment;
Label m_DisplayMaxColorLabel;
Slider m_DisplayMaxColorSlider;
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> m_DisplayMaxColorAttachment;
TextButton m_runModeButton;
TextButton m_pauseButton;
void pauseClicked();
void runClicked();
bool m_isPaused;
bool m_isRunningDisplay;
ComboBox m_colorScheme;
ComboBox m_windowFktCombo;
JadeSpectrogramAudioProcessorEditor& m_editor;
ComboBox m_fftSizeCombo;
bool m_hideFFTSizeCombobox;
void changeFFTSize();
Label m_FreqLabel;
};