kopia lustrzana https://github.com/jameshball/osci-render
Add smooth effect
rodzic
e6c9cee6b1
commit
4cf64c9654
|
@ -13,6 +13,7 @@
|
||||||
#include "audio/RotateEffect.h"
|
#include "audio/RotateEffect.h"
|
||||||
#include "audio/VectorCancellingEffect.h"
|
#include "audio/VectorCancellingEffect.h"
|
||||||
#include "audio/DistortEffect.h"
|
#include "audio/DistortEffect.h"
|
||||||
|
#include "audio/SmoothEffect.h"
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
OscirenderAudioProcessor::OscirenderAudioProcessor()
|
OscirenderAudioProcessor::OscirenderAudioProcessor()
|
||||||
|
@ -35,6 +36,7 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
|
||||||
allEffects.push_back(std::make_shared<Effect>(std::make_unique<VectorCancellingEffect>(), "Vector cancelling", "vectorCancelling"));
|
allEffects.push_back(std::make_shared<Effect>(std::make_unique<VectorCancellingEffect>(), "Vector cancelling", "vectorCancelling"));
|
||||||
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(true), "Vertical shift", "verticalDistort"));
|
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(true), "Vertical shift", "verticalDistort"));
|
||||||
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(false), "Horizontal shift", "horizontalDistort"));
|
allEffects.push_back(std::make_shared<Effect>(std::make_unique<DistortEffect>(false), "Horizontal shift", "horizontalDistort"));
|
||||||
|
allEffects.push_back(std::make_shared<Effect>(std::make_unique<SmoothEffect>(), "Smoothing", "smoothing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
OscirenderAudioProcessor::~OscirenderAudioProcessor()
|
OscirenderAudioProcessor::~OscirenderAudioProcessor()
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include "SmoothEffect.h"
|
||||||
|
|
||||||
|
SmoothEffect::SmoothEffect() {
|
||||||
|
this->window = std::vector<Vector2>(MAX_WINDOW_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
SmoothEffect::~SmoothEffect() {}
|
||||||
|
|
||||||
|
Vector2 SmoothEffect::apply(int index, Vector2 input, double value, double frequency, double sampleRate) {
|
||||||
|
int newWindowSize = (int)(256 * value);
|
||||||
|
windowSize = std::max(1, std::min(MAX_WINDOW_SIZE, newWindowSize));
|
||||||
|
|
||||||
|
window[head++] = input;
|
||||||
|
if (head >= MAX_WINDOW_SIZE) {
|
||||||
|
head = 0;
|
||||||
|
}
|
||||||
|
double totalX = 0;
|
||||||
|
double totalY = 0;
|
||||||
|
int newHead = head - 1;
|
||||||
|
for (int i = 0; i < windowSize; i++) {
|
||||||
|
if (newHead < 0) {
|
||||||
|
newHead = MAX_WINDOW_SIZE - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalX += window[newHead].x;
|
||||||
|
totalY += window[newHead].y;
|
||||||
|
|
||||||
|
newHead--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vector2(totalX / windowSize, totalY / windowSize);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#pragma once
|
||||||
|
#include "EffectApplication.h"
|
||||||
|
#include "../shape/Vector2.h"
|
||||||
|
|
||||||
|
class SmoothEffect : public EffectApplication {
|
||||||
|
public:
|
||||||
|
SmoothEffect();
|
||||||
|
~SmoothEffect();
|
||||||
|
|
||||||
|
Vector2 apply(int index, Vector2 input, double value, double frequency, double sampleRate) override;
|
||||||
|
private:
|
||||||
|
const int MAX_WINDOW_SIZE = 2048;
|
||||||
|
std::vector<Vector2> window;
|
||||||
|
int windowSize = 1;
|
||||||
|
int head = 0;
|
||||||
|
};
|
|
@ -36,6 +36,9 @@
|
||||||
<FILE id="PbbNqz" name="RotateEffect.cpp" compile="1" resource="0"
|
<FILE id="PbbNqz" name="RotateEffect.cpp" compile="1" resource="0"
|
||||||
file="Source/audio/RotateEffect.cpp"/>
|
file="Source/audio/RotateEffect.cpp"/>
|
||||||
<FILE id="tUwNZV" name="RotateEffect.h" compile="0" resource="0" file="Source/audio/RotateEffect.h"/>
|
<FILE id="tUwNZV" name="RotateEffect.h" compile="0" resource="0" file="Source/audio/RotateEffect.h"/>
|
||||||
|
<FILE id="iUEfwT" name="SmoothEffect.cpp" compile="1" resource="0"
|
||||||
|
file="Source/audio/SmoothEffect.cpp"/>
|
||||||
|
<FILE id="Vwjht7" name="SmoothEffect.h" compile="0" resource="0" file="Source/audio/SmoothEffect.h"/>
|
||||||
<FILE id="VBskjq" name="VectorCancellingEffect.cpp" compile="1" resource="0"
|
<FILE id="VBskjq" name="VectorCancellingEffect.cpp" compile="1" resource="0"
|
||||||
file="Source/audio/VectorCancellingEffect.cpp"/>
|
file="Source/audio/VectorCancellingEffect.cpp"/>
|
||||||
<FILE id="Be21D0" name="VectorCancellingEffect.h" compile="0" resource="0"
|
<FILE id="Be21D0" name="VectorCancellingEffect.h" compile="0" resource="0"
|
||||||
|
|
Ładowanie…
Reference in New Issue