osci-render/Source/audio/DashedLineEffect.h

35 wiersze
861 B
C
Czysty Zwykły widok Historia

2024-02-20 14:14:24 +00:00
#pragma once
#include <JuceHeader.h>
2024-02-20 14:14:24 +00:00
class DashedLineEffect : public osci::EffectApplication {
2024-02-20 14:14:24 +00:00
public:
osci::Point apply(int index, osci::Point vector, const std::vector<std::atomic<double>>& values, double sampleRate) override {
// dash length in seconds
double dashLength = values[0] / 400;
int dashLengthSamples = (int)(dashLength * sampleRate);
dashLengthSamples = juce::jmin(dashLengthSamples, MAX_BUFFER);
if (dashIndex >= dashLengthSamples) {
dashIndex = 0;
bufferIndex = 0;
}
2024-02-20 14:14:24 +00:00
buffer[bufferIndex] = vector;
bufferIndex++;
vector = buffer[dashIndex];
if (index % 2 == 0) {
dashIndex++;
}
return vector;
}
2024-02-20 14:14:24 +00:00
private:
const static int MAX_BUFFER = 192000;
std::vector<osci::Point> buffer = std::vector<osci::Point>(MAX_BUFFER);
2024-02-20 14:14:24 +00:00
int dashIndex = 0;
int bufferIndex = 0;
};