Vital
Loading...
Searching...
No Matches
oscilloscope.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "memory.h"
5#include "fourier_transform.h"
7
16public:
18 static constexpr int kResolution = 512;
19
27 virtual ~Oscilloscope();
28
34 void drawWaveform(OpenGlWrapper& open_gl, int index);
35
41 void render(OpenGlWrapper& open_gl, bool animate) override;
42
47 void setOscilloscopeMemory(const vital::poly_float* memory) { memory_ = memory; }
48
49private:
50 const vital::poly_float* memory_;
51
52 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Oscilloscope)
53};
54
65public:
66 static constexpr int kResolution = 300;
67 static constexpr float kDecayMult = 0.008f;
68 static constexpr int kBits = 14;
69 static constexpr int kAudioSize = 1 << kBits;
70 static constexpr float kDefaultMaxDb = 0.0f;
71 static constexpr float kDefaultMinDb = -50.0f;
72 static constexpr float kDefaultMinFrequency = 9.2f;
73 static constexpr float kDefaultMaxFrequency = 21000.0f;
74 static constexpr float kDbSlopePerOctave = 3.0f;
75
80
84 virtual ~Spectrogram();
85
91 void drawWaveform(OpenGlWrapper& open_gl, int index);
92
98 void render(OpenGlWrapper& open_gl, bool animate) override;
99
104 void setAudioMemory(const vital::StereoMemory* memory) { memory_ = memory; }
105
110 void paintBackground(Graphics& g) override;
111
116 void setOversampleAmount(int oversample) { oversample_amount_ = oversample; }
117
122 void setMinFrequency(float frequency) { min_frequency_ = frequency; }
123
128 void setMaxFrequency(float frequency) { max_frequency_ = frequency; }
129
134 void setMinDb(float db) { min_db_ = db; }
135
140 void setMaxDb(float db) { max_db_ = db; }
141
146 void paintBackgroundLines(bool paint) { paint_background_lines_ = paint; }
147
148private:
154 void updateAmplitudes(int index, int offset);
155
160 void updateAmplitudes(int index);
161
165 void applyWindow();
166
167 int sample_rate_;
168 int oversample_amount_;
169 float min_frequency_;
170 float max_frequency_;
171 float min_db_;
172 float max_db_;
173 bool paint_background_lines_;
174
175 float transform_buffer_[2 * kAudioSize];
176 float left_amps_[kAudioSize];
177 float right_amps_[kAudioSize];
178 const vital::StereoMemory* memory_;
179 vital::FourierTransform transform_;
180
181 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Spectrogram)
182};
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
Renders a time-domain waveform using OpenGL.
Definition oscilloscope.h:15
void setOscilloscopeMemory(const vital::poly_float *memory)
Sets the memory buffer that the oscilloscope reads from.
Definition oscilloscope.h:47
virtual ~Oscilloscope()
Destructor.
Definition oscilloscope.cpp:15
static constexpr int kResolution
The number of points used to represent the waveform.
Definition oscilloscope.h:18
Oscilloscope()
Constructs the Oscilloscope and sets up fill and corners.
Definition oscilloscope.cpp:9
void drawWaveform(OpenGlWrapper &open_gl, int index)
Draws the waveform line for a given channel index.
Definition oscilloscope.cpp:17
void render(OpenGlWrapper &open_gl, bool animate) override
Renders the oscilloscope line for both channels.
Definition oscilloscope.cpp:35
Renders a frequency-domain representation (spectrogram) using OpenGL.
Definition oscilloscope.h:64
virtual ~Spectrogram()
Destructor.
void setMinDb(float db)
Sets the minimum dB level displayed.
Definition oscilloscope.h:134
void setAudioMemory(const vital::StereoMemory *memory)
Sets the StereoMemory from which audio data is read for the FFT.
Definition oscilloscope.h:104
void setMaxFrequency(float frequency)
Sets the maximum frequency displayed in the spectrogram.
Definition oscilloscope.h:128
static constexpr float kDefaultMaxDb
Default maximum dB level displayed.
Definition oscilloscope.h:70
static constexpr int kResolution
Number of points in the frequency line.
Definition oscilloscope.h:66
static constexpr float kDefaultMaxFrequency
Default maximum frequency.
Definition oscilloscope.h:73
static constexpr float kDefaultMinFrequency
Default minimum frequency.
Definition oscilloscope.h:72
static constexpr float kDecayMult
Decay multiplier for amplitude smoothing.
Definition oscilloscope.h:67
void paintBackgroundLines(bool paint)
Enables or disables painting background frequency lines.
Definition oscilloscope.h:146
void setMinFrequency(float frequency)
Sets the minimum frequency displayed in the spectrogram.
Definition oscilloscope.h:122
void drawWaveform(OpenGlWrapper &open_gl, int index)
Draws the frequency-domain waveform (spectrogram line) for a given channel index.
Definition oscilloscope.cpp:145
static constexpr float kDefaultMinDb
Default minimum dB level displayed.
Definition oscilloscope.h:71
void setOversampleAmount(int oversample)
Sets the oversampling amount used for adjusting frequency scaling.
Definition oscilloscope.h:116
static constexpr int kAudioSize
Size of audio block for the FFT.
Definition oscilloscope.h:69
static constexpr int kBits
Number of bits, defining the transform size (2^kBits).
Definition oscilloscope.h:68
void paintBackground(Graphics &g) override
Paints a background using JUCE's Graphics (e.g., frequency lines).
Definition oscilloscope.cpp:188
static constexpr float kDbSlopePerOctave
dB slope per octave for visualization.
Definition oscilloscope.h:74
Spectrogram()
Constructs the Spectrogram with default parameters.
Definition oscilloscope.cpp:52
void render(OpenGlWrapper &open_gl, bool animate) override
Renders the spectrogram for both channels.
Definition oscilloscope.cpp:163
void setMaxDb(float db)
Sets the maximum dB level displayed.
Definition oscilloscope.h:140
A Fourier transform implementation using KissFFT for platforms where other accelerations are unavaila...
Definition fourier_transform.h:210
A specialized MemoryTemplate for two-channel (stereo) audio.
Definition memory.h:216
Declares classes for time-domain memory storage and retrieval with cubic interpolation.
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600