18 float y_adjust = getHeight() / 2.0f;
19 float width = getWidth();
24 int memory_index = memory_spot;
25 float remainder = memory_spot - memory_index;
26 float from = memory_[memory_index][index];
27 float to = memory_[memory_index + 1][index];
42 float fill_fade = 0.0f;
45 setFillColors(fill_color.withMultipliedAlpha(1.0f - fill_fade), fill_color);
53 left_amps_(), right_amps_(), transform_(kBits) {
54 static constexpr float kDefaultAmp = 0.000001f;
56 paint_background_lines_ =
true;
59 oversample_amount_ = 1;
67 left_amps_[i] = kDefaultAmp;
68 right_amps_[i] = kDefaultAmp;
76void Spectrogram::applyWindow() {
82 double real_mult = cos(kRadianIncrement);
83 double imag_mult = sin(kRadianIncrement);
86 transform_buffer_[i] *= 0.5f * (real + 1.0f);
88 double next_real = real * real_mult - imag * imag_mult;
89 double next_imag = imag * real_mult + real * imag_mult;
95void Spectrogram::updateAmplitudes(
int index,
int offset) {
96 static constexpr float kMinAmp = 0.000001f;
97 static constexpr float kStartScaleAmp = 0.001f;
98 static constexpr float kMinDecay = 0.06f;
100 if (memory_ ==
nullptr)
103 float min_frequency = min_frequency_ / oversample_amount_;
104 float max_frequency = max_frequency_ / oversample_amount_;
105 float* amps = index == 0 ? left_amps_ : right_amps_;
106 float sample_hz = (1.0f * sample_rate_) /
kAudioSize;
107 float start_octave = log2f(min_frequency / sample_hz);
108 float end_octave = std::min<float>(
kBits - start_octave + 1.0f, log2f(max_frequency / sample_hz));
109 float num_octaves = end_octave - start_octave;
114 std::complex<float>* frequency_data = (std::complex<float>*)transform_buffer_;
116 float last_bin = powf(2.0f, start_octave);
119 float octave = num_octaves * t + start_octave;
120 float bin = powf(2.0f, octave);
122 int bin_index = last_bin;
123 float bin_t = last_bin - bin_index;
124 float prev_amplitude = std::abs(frequency_data[bin_index]);
125 float next_amplitude = std::abs(frequency_data[bin_index + 1]);
127 if (bin - last_bin > 1.0f) {
128 for (
int j = last_bin + 1; j < bin; ++j)
129 amplitude = std::max(amplitude, std::abs(frequency_data[j]));
133 amplitude = std::max(kMinAmp, 2.0f * amplitude /
kAudioSize);
136 float decay = std::max(kMinDecay, std::min(1.0f,
kDecayMult * db));
141void Spectrogram::updateAmplitudes(
int index) {
142 updateAmplitudes(index, 0);
146 float* amps = index == 0 ? left_amps_ : right_amps_;
147 float height = getHeight();
148 float width = getWidth();
149 float range_mult = 1.0f / (max_db_ - min_db_);
150 float num_octaves = log2f(max_frequency_ / min_frequency_);
156 float y = (db - min_db_) * range_mult;
158 setYAt(i, height - y * height);
164 SynthGuiInterface* synth_interface = findParentComponentOfClass<SynthGuiInterface>();
165 if (synth_interface ==
nullptr)
179 float fill_fade = 0.0f;
182 setFillColors(fill_color.withMultipliedAlpha(1.0f - fill_fade), fill_color);
189 static constexpr int kLineSpacing = 10;
192 if (!paint_background_lines_)
195 int height = getHeight();
196 float max_octave = log2f(max_frequency_ / min_frequency_);
198 float frequency = 0.0f;
199 float increment = 1.0f;
202 while (frequency < max_frequency_) {
203 for (
int i = 0; i < kLineSpacing; ++i) {
204 frequency += increment;
205 float t = log2f(frequency / min_frequency_) / max_octave;
206 x = std::round(t * getWidth());
207 g.fillRect(x, 0, 1, height);
209 g.fillRect(x, 0, 1, height);
210 increment *= kLineSpacing;
void addRoundedCorners()
Adds rounded corners to the component's edges.
Definition open_gl_component.cpp:138
void renderCorners(OpenGlWrapper &open_gl, bool animate, Colour color, float rounding)
Renders the corner shapes using the given color and rounding amount.
Definition open_gl_component.cpp:153
float findValue(Skin::ValueId value_id)
Finds a float value from the skin associated with this component's parent.
Definition open_gl_component.cpp:173
virtual void paintBackground(Graphics &g)
Paints a standard background for the component.
Definition open_gl_component.cpp:105
const SynthSection * parent_
Pointer to parent SynthSection for skin lookups.
Definition open_gl_component.h:256
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
force_inline void setFillCenter(float fill_center)
Sets the vertical center for the fill area.
Definition open_gl_line_renderer.h:138
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the line using OpenGL.
Definition open_gl_line_renderer.cpp:464
force_inline void setYAt(int index, float val)
Sets the y-coordinate of a point, marking data as dirty.
Definition open_gl_line_renderer.h:98
force_inline void setFill(bool fill)
Enables or disables filling below the line.
Definition open_gl_line_renderer.h:124
force_inline void setXAt(int index, float val)
Sets the x-coordinate of a point, marking data as dirty.
Definition open_gl_line_renderer.h:105
force_inline void setFillColors(Colour fill_color_from, Colour fill_color_to)
Sets a gradient fill from one color to another.
Definition open_gl_line_renderer.h:132
force_inline void setLineWidth(float width)
Sets the line width in pixels.
Definition open_gl_line_renderer.h:66
force_inline void setColor(Colour color)
Sets the line color.
Definition open_gl_line_renderer.h:63
force_inline Colour color() const
Gets the current line color.
Definition open_gl_line_renderer.h:189
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
@ kWidgetLineWidth
Definition skin.h:105
@ kWidgetFillCenter
Definition skin.h:107
@ kWidgetFillFade
Definition skin.h:108
@ kWidgetPrimary2
Definition skin.h:166
@ kWidgetPrimary1
Definition skin.h:165
@ kLightenScreen
Definition skin.h:141
virtual ~Spectrogram()
Destructor.
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 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
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
int getSampleRate()
Retrieves the current audio sample rate used by the engine.
Definition synth_base.cpp:286
An interface class linking the Vital synthesizer backend (SynthBase) with a GUI.
Definition synth_gui_interface.h:56
SynthBase * getSynth()
Returns the SynthBase instance this interface is managing.
Definition synth_gui_interface.h:85
float findValue(Skin::ValueId value_id) const
Finds a value in the skin overrides or from the parent if not found locally.
Definition synth_section.cpp:18
void readSamples(mono_float *output, int num_samples, int offset, int channel) const
Reads samples from the memory into an output buffer.
Definition memory.h:123
force_inline poly_float magnitudeToDb(poly_float value)
Converts a magnitude value to decibels (vectorized).
Definition poly_utils.h:144
force_inline poly_float interpolate(poly_float from, poly_float to, mono_float t)
Performs a linear interpolation between two poly_floats using a scalar t in [0..1].
Definition poly_utils.h:182
constexpr int kOscilloscopeMemoryResolution
Resolution (number of samples) in the oscilloscope memory buffer.
Definition synth_constants.h:55
constexpr mono_float kPi
Pi constant.
Definition common.h:36
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...