From 81437ed87a9e88aaa686ff1b2546e3d5c20cda16 Mon Sep 17 00:00:00 2001 From: Anthony Hall Date: Wed, 13 Aug 2025 00:41:13 -0700 Subject: [PATCH] Add twist effect, normalize smooth effect --- Source/PluginProcessor.cpp | 9 ++++++++- Source/PluginProcessor.h | 3 --- Source/audio/SmoothEffect.h | 2 +- Source/audio/TwistEffect.h | 13 +++++++++++++ Source/audio/WobbleEffect.cpp | 14 -------------- Source/audio/WobbleEffect.h | 13 +++++++++---- osci-render.jucer | 3 +-- 7 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 Source/audio/TwistEffect.h delete mode 100644 Source/audio/WobbleEffect.cpp diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 535f7e94..43c1f6e8 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -11,9 +11,11 @@ #include "PluginEditor.h" #include "audio/BitCrushEffect.h" #include "audio/BulgeEffect.h" +#include "audio/TwistEffect.h" #include "audio/DistortEffect.h" #include "audio/MultiplexEffect.h" #include "audio/SmoothEffect.h" +#include "audio/WobbleEffect.h" #include "audio/VectorCancellingEffect.h" #include "parser/FileParser.h" #include "parser/FrameProducer.h" @@ -121,11 +123,16 @@ OscirenderAudioProcessor::OscirenderAudioProcessor() : CommonAudioProcessor(Buse std::vector{ new osci::EffectParameter("Swirl", "Swirls the image in a spiral pattern.", "swirl", VERSION_HINT, 0.3, -1.0, 1.0), })); + toggleableEffects.push_back(std::make_shared( + std::make_shared(), + std::vector{ + new osci::EffectParameter("Twist", "Twists the image in a corkscrew pattern.", "twist", VERSION_HINT, 0.5, -1.0, 1.0), + })); toggleableEffects.push_back(std::make_shared( std::make_shared(), new osci::EffectParameter("Smoothing", "This works as a low-pass frequency filter that removes high frequencies, making the image look smoother, and audio sound less harsh.", "smoothing", VERSION_HINT, 0.75, 0.0, 1.0))); std::shared_ptr wobble = std::make_shared( - wobbleEffect, + std::make_shared(*this), std::vector{ new osci::EffectParameter("Wobble Amount", "Adds a sine wave of the prominent frequency in the audio currently playing. The sine wave's frequency is slightly offset to create a subtle 'wobble' in the image. Increasing the slider increases the strength of the wobble.", "wobble", VERSION_HINT, 0.3, 0.0, 1.0), new osci::EffectParameter("Wobble Phase", "Controls the phase of the wobble.", "wobblePhase", VERSION_HINT, 0.0, -1.0, 1.0), diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 5609ff99..18730f75 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -25,7 +25,6 @@ #include "audio/SampleRateManager.h" #include "audio/ShapeSound.h" #include "audio/ShapeVoice.h" -#include "audio/WobbleEffect.h" #include "obj/ObjectServer.h" #if (JUCE_MAC || JUCE_WINDOWS) && OSCI_PREMIUM @@ -172,8 +171,6 @@ public: std::atomic animationFrame = 0.f; - std::shared_ptr wobbleEffect = std::make_shared(*this); - const double FONT_SIZE = 1.0f; juce::Font font = juce::Font(juce::Font::getDefaultSansSerifFontName(), FONT_SIZE, juce::Font::plain); diff --git a/Source/audio/SmoothEffect.h b/Source/audio/SmoothEffect.h index a286c2c0..5698eb30 100644 --- a/Source/audio/SmoothEffect.h +++ b/Source/audio/SmoothEffect.h @@ -8,7 +8,7 @@ public: weight *= 0.95; double strength = 10; weight = std::log(strength * weight + 1) / std::log(strength + 1); - // TODO: This doesn't consider the sample rate! + weight = std::pow(weight, 48000 / sampleRate); avg = weight * avg + (1 - weight) * input; return avg; diff --git a/Source/audio/TwistEffect.h b/Source/audio/TwistEffect.h new file mode 100644 index 00000000..b4754c12 --- /dev/null +++ b/Source/audio/TwistEffect.h @@ -0,0 +1,13 @@ +#pragma once +#include +#include + +class TwistEffect : public osci::EffectApplication { +public: + osci::Point apply(int index, osci::Point input, const std::vector> &values, double sampleRate) override { + double twistStrength = values[0] * 4 * std::numbers::pi; + double twistTheta = twistStrength * input.y; + input.rotate(0.0, twistTheta, 0.0); + return input; + } +}; \ No newline at end of file diff --git a/Source/audio/WobbleEffect.cpp b/Source/audio/WobbleEffect.cpp deleted file mode 100644 index ebcc42f0..00000000 --- a/Source/audio/WobbleEffect.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "WobbleEffect.h" -#include "../PluginProcessor.h" - -WobbleEffect::WobbleEffect(OscirenderAudioProcessor& p) : audioProcessor(p) {} - -WobbleEffect::~WobbleEffect() {} - -osci::Point WobbleEffect::apply(int index, osci::Point input, const std::vector>& values, double sampleRate) { - double wobblePhase = values[1] * std::numbers::pi; - double theta = nextPhase(audioProcessor.frequency, sampleRate) + wobblePhase; - double delta = 0.5 * values[0] * std::sin(theta); - - return input + delta; -} diff --git a/Source/audio/WobbleEffect.h b/Source/audio/WobbleEffect.h index 0e113545..c82e853a 100644 --- a/Source/audio/WobbleEffect.h +++ b/Source/audio/WobbleEffect.h @@ -1,13 +1,18 @@ #pragma once #include +#include "../PluginProcessor.h" -class OscirenderAudioProcessor; class WobbleEffect : public osci::EffectApplication { public: - WobbleEffect(OscirenderAudioProcessor& p); - ~WobbleEffect(); + WobbleEffect(OscirenderAudioProcessor &p) : audioProcessor(p) {} - osci::Point apply(int index, osci::Point input, const std::vector>& values, double sampleRate) override; + osci::Point apply(int index, osci::Point input, const std::vector>& values, double sampleRate) override { + double wobblePhase = values[1] * std::numbers::pi; + double theta = nextPhase(audioProcessor.frequency, sampleRate) + wobblePhase; + double delta = 0.5 * values[0] * std::sin(theta); + + return input + delta; + } private: OscirenderAudioProcessor& audioProcessor; diff --git a/osci-render.jucer b/osci-render.jucer index be38c779..4d8b34ab 100644 --- a/osci-render.jucer +++ b/osci-render.jucer @@ -104,10 +104,9 @@ + -