Merge pull request #321 from ahall99/spiral-bitcrush

Add Spiral Bit Crush Effect
pull/323/head
James H Ball 2025-09-11 20:53:44 +01:00 zatwierdzone przez GitHub
commit 32f741d471
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
4 zmienionych plików z 85 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M120-380q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Zm0-160q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Zm120 340q-17 0-28.5-11.5T200-240q0-17 11.5-28.5T240-280q17 0 28.5 11.5T280-240q0 17-11.5 28.5T240-200Zm0-160q-17 0-28.5-11.5T200-400q0-17 11.5-28.5T240-440q17 0 28.5 11.5T280-400q0 17-11.5 28.5T240-360Zm0-160q-17 0-28.5-11.5T200-560q0-17 11.5-28.5T240-600q17 0 28.5 11.5T280-560q0 17-11.5 28.5T240-520Zm0-160q-17 0-28.5-11.5T200-720q0-17 11.5-28.5T240-760q17 0 28.5 11.5T280-720q0 17-11.5 28.5T240-680Zm160 340q-25 0-42.5-17.5T340-400q0-25 17.5-42.5T400-460q25 0 42.5 17.5T460-400q0 25-17.5 42.5T400-340Zm0-160q-25 0-42.5-17.5T340-560q0-25 17.5-42.5T400-620q25 0 42.5 17.5T460-560q0 25-17.5 42.5T400-500Zm0 300q-17 0-28.5-11.5T360-240q0-17 11.5-28.5T400-280q17 0 28.5 11.5T440-240q0 17-11.5 28.5T400-200Zm0-480q-17 0-28.5-11.5T360-720q0-17 11.5-28.5T400-760q17 0 28.5 11.5T440-720q0 17-11.5 28.5T400-680Zm0 580q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Zm0-720q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Zm160 480q-25 0-42.5-17.5T500-400q0-25 17.5-42.5T560-460q25 0 42.5 17.5T620-400q0 25-17.5 42.5T560-340Zm0-160q-25 0-42.5-17.5T500-560q0-25 17.5-42.5T560-620q25 0 42.5 17.5T620-560q0 25-17.5 42.5T560-500Zm0 300q-17 0-28.5-11.5T520-240q0-17 11.5-28.5T560-280q17 0 28.5 11.5T600-240q0 17-11.5 28.5T560-200Zm0-480q-17 0-28.5-11.5T520-720q0-17 11.5-28.5T560-760q17 0 28.5 11.5T600-720q0 17-11.5 28.5T560-680Zm0 580q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Zm0-720q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Zm160 620q-17 0-28.5-11.5T680-240q0-17 11.5-28.5T720-280q17 0 28.5 11.5T760-240q0 17-11.5 28.5T720-200Zm0-160q-17 0-28.5-11.5T680-400q0-17 11.5-28.5T720-440q17 0 28.5 11.5T760-400q0 17-11.5 28.5T720-360Zm0-160q-17 0-28.5-11.5T680-560q0-17 11.5-28.5T720-600q17 0 28.5 11.5T760-560q0 17-11.5 28.5T720-520Zm0-160q-17 0-28.5-11.5T680-720q0-17 11.5-28.5T720-760q17 0 28.5 11.5T760-720q0 17-11.5 28.5T720-680Zm120 300q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Zm0-160q-8 0-14-6t-6-14q0-8 6-14t14-6q8 0 14 6t6 14q0 8-6 14t-14 6Z"/></svg>

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 2.2 KiB

Wyświetl plik

@ -12,6 +12,7 @@
#include "audio/BitCrushEffect.h"
#include "audio/BulgeEffect.h"
#include "audio/TwistEffect.h"
#include "audio/SpiralBitCrushEffect.h"
#include "audio/DistortEffect.h"
#include "audio/KaleidoscopeEffect.h"
#include "audio/MultiplexEffect.h"
@ -58,6 +59,7 @@ OscirenderAudioProcessor::OscirenderAudioProcessor() : CommonAudioProcessor(Buse
toggleableEffects.push_back(BounceEffect().build());
toggleableEffects.push_back(TwistEffect().build());
toggleableEffects.push_back(SkewEffect().build());
toggleableEffects.push_back(SpiralBitCrushEffect().build());
#endif
auto scaleEffect = ScaleEffectApp().build();

Wyświetl plik

@ -0,0 +1,78 @@
#pragma once
#include <JuceHeader.h>
class SpiralBitCrushEffect : public osci::EffectApplication {
public:
osci::Point apply(int index, osci::Point input, const std::vector<std::atomic<double>> &values, double sampleRate) override {
// Completing one revolution in input space traverses the hypotenuse of one "domain" in log-polar space
double effectScale = juce::jlimit(0.0, 1.0, values[0].load());
double domainX = juce::jmax(2.0, std::floor(values[1].load() + 0.001));
double domainY = std::round(domainX * values[2].load());
double zoom = values[3].load() * juce::MathConstants<double>::twoPi; // Use same scale as angle
double rotation = values[4].load() * juce::MathConstants<double>::twoPi;
double domainHypot = std::hypot(domainX, domainY);
double domainTheta = std::atan2(domainY, domainX);
double scale = domainHypot / juce::MathConstants<double>::twoPi;
osci::Point output(0);
// Round to log-polar grid
if (input.x != 0 || input.y != 0) {
// Convert input point to log-polar coordinates transformed based on domain and offset
// Note 90 degree rotation: Theta is treated relative to -Y rather than +X
double r = std::hypot(input.x, input.y);
double logR = std::log(r);
double theta = std::atan2(input.x, -input.y);
osci::Point logPolarCoords(theta - rotation, logR - zoom);
logPolarCoords.rotate(0, 0, domainTheta);
logPolarCoords = logPolarCoords * scale;
// Round this point to the center of the log-polar cell the input lies in, convert back to Cartesian
logPolarCoords.x = std::round(logPolarCoords.x);
logPolarCoords.y = std::round(logPolarCoords.y);
logPolarCoords = logPolarCoords / scale;
logPolarCoords.rotate(0, 0, -domainTheta);
double outR = std::exp(logPolarCoords.y + zoom);
double outTheta = logPolarCoords.x + rotation;
output.x = outR * std::sin(outTheta);
output.y = outR * -std::cos(outTheta);
}
// Round z in log space using same spacing as xy log-polar grid
// Use same offset as xy's radial offset to be consistent with the appearance of zooming
if (input.z != 0) {
double signZ = input.z > 0 ? 1.0 : -1.0;
double logZ = std::log(std::abs(input.z));
logZ = (logZ - zoom) * scale;
logZ = std::round(logZ);
logZ = logZ / scale + zoom;
output.z = signZ * std::exp(logZ);
}
return (1 - effectScale) * input + effectScale * output;
}
std::shared_ptr<osci::Effect> build() const override {
auto eff = std::make_shared<osci::Effect>(
std::make_shared<SpiralBitCrushEffect>(),
std::vector<osci::EffectParameter*>{
new osci::EffectParameter("Spiral Bit Crush",
"Constrains points to a spiral pattern.",
"spiralBitCrush", VERSION_HINT, 0.4, 0.0, 1.0),
new osci::EffectParameter("Spiral Density",
"Controls the density of the spiral pattern.",
"spiralBitCrushDensity", VERSION_HINT, 13.0, 3.0, 30.0, 1.0),
new osci::EffectParameter("Spiral Twist",
"Controls how much the spiral pattern twists.",
"spiralBitCrushTwist", VERSION_HINT, 0.6, -1.0, 1.0),
new osci::EffectParameter("Zoom",
"Zooms the spiral pattern.",
"spiralBitCrushZoom", VERSION_HINT, 0.0, 0.0, 1.0, 0.0001, osci::LfoType::Sawtooth, 0.1),
new osci::EffectParameter("Rotation",
"Rotates the spiral pattern.",
"spiralBitCrushRotation", VERSION_HINT, 0.0, 0.0, 1.0, 0.0001, osci::LfoType::ReverseSawtooth, 0.02)
}
);
eff->setIcon(BinaryData::spiral_bitcrush_svg);
return eff;
}
};

Wyświetl plik

@ -142,6 +142,8 @@
<FILE id="OiOWD6" name="skull.svg" compile="0" resource="1" file="Resources/svg/skull.svg"/>
<FILE id="ZPUNcg" name="smoothing.svg" compile="0" resource="1" file="Resources/svg/smoothing.svg"/>
<FILE id="XxYNOy" name="snowflake.svg" compile="0" resource="1" file="Resources/svg/snowflake.svg"/>
<FILE id="iZMino" name="spiral_bitcrush.svg" compile="0" resource="1"
file="Resources/svg/spiral_bitcrush.svg"/>
<FILE id="yiDo4s" name="spout.svg" compile="0" resource="1" file="Resources/svg/spout.svg"/>
<FILE id="EOWhGi" name="stop.svg" compile="0" resource="1" file="Resources/svg/stop.svg"/>
<FILE id="Z3yYJU" name="swirl.svg" compile="0" resource="1" file="Resources/svg/swirl.svg"/>
@ -170,6 +172,8 @@
<FILE id="tU2pQl" name="SkewEffect.h" compile="0" resource="0" file="Source/audio/SkewEffect.h"/>
<FILE id="yxWOsR" name="DuplicatorEffect.h" compile="0" resource="0"
file="Source/audio/DuplicatorEffect.h"/>
<FILE id="GbAmhn" name="SpiralBitCrushEffect.h" compile="0" resource="0"
file="Source/audio/SpiralBitCrushEffect.h"/>
<FILE id="HE3dFE" name="AudioRecorder.h" compile="0" resource="0" file="Source/audio/AudioRecorder.h"/>
<FILE id="Bc8UeW" name="BitCrushEffect.h" compile="0" resource="0"
file="Source/audio/BitCrushEffect.h"/>