osci-render/Source/audio/SmoothEffect.cpp

34 wiersze
889 B
C++
Czysty Zwykły widok Historia

2023-03-28 14:52:51 +00:00
#include "SmoothEffect.h"
SmoothEffect::SmoothEffect() {
this->window = std::vector<Vector2>(MAX_WINDOW_SIZE);
}
SmoothEffect::~SmoothEffect() {}
Vector2 SmoothEffect::apply(int index, Vector2 input, std::vector<EffectDetails> details, double frequency, double sampleRate) {
double value = details[0].value;
2023-03-28 14:52:51 +00:00
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);
}