SVF library element

master
zetaPRIME 2022-03-15 22:22:23 -04:00
parent e1e4089b88
commit 6b126db234
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#include "svfilter.h"
#include <cmath>
#include "nodelib/basics.h"
#include "audio/audioengine.h"
using Xybrid::NodeLib::SVFilter;
using Xybrid::Data::AudioFrame;
using namespace Xybrid::Audio;
void SVFilter::process(AudioFrame in, double freq, double res, int ovs) {
if (poles <= 0) return;
double f = freq / (audioEngine->curSampleRate() * ovs);
double q = sqrt(1.0 - atan(sqrt(res)) * 2.0 / PI);
double damp = sqrt(q);
for (int i = 0; i < ovs; i++) {
low += band*f;
high = in*damp - low - band*q;
band += high*f;
}
notch = high+low;
}

24
xybrid/nodelib/svfilter.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include <cstring>
#include "data/audioframe.h"
namespace Xybrid::NodeLib {
class SVFilter {
//
public:
Data::AudioFrame low = 0.0;
Data::AudioFrame high = 0.0;
Data::AudioFrame band = 0.0;
Data::AudioFrame notch = 0.0;
SVFilter() = default;
~SVFilter() = default;
inline SVFilter(const SVFilter& o) { std::memcpy(this, &o, sizeof(SVFilter)); } // trivial enough contents
inline SVFilter& operator=(const SVFilter& o) { std::memcpy(this, &o, sizeof(SVFilter)); return *this; } // same
void process(Data::AudioFrame in, double freq, double res, int oversamp = 2);
inline void reset() { low = 0.0; high = 0.0; band = 0.0; notch = 0.0; }
};
}