slight improvement to Testron

portability/boost
zetaPRIME 2019-01-04 15:08:32 -05:00
parent f06679d221
commit 3dba27fb81
2 changed files with 16 additions and 8 deletions

View File

@ -29,6 +29,21 @@ namespace {
PluginRegistry::registerPlugin(i);
//inf = i;
});
const double PI = std::atan(1)*4;
const double SEMI = std::pow(2.0, 1.0/12.0);
double fOsc(double& time) {
time = std::fmod(time, 2.0);
auto a = 0.0;
a += std::sin(time * PI*2);
a += std::sin(time * PI) * std::pow(.75, 4);
a += std::sin(time * PI*4) * std::pow(.75, 4);
a += std::sin(time * PI*8) * std::pow(.25, 4);
return a;
}
}
TestSynth::TestSynth() {
@ -68,9 +83,6 @@ void TestSynth::process() {
mi += 5 + cp->data[mi+4];
}
const double PI = std::atan(1)*4;
const double SEMI = std::pow(2.0, 1.0/12.0);
size_t ts = audioEngine->curTickSize();
for (size_t s = 0; s < ts; s++) {
@ -78,14 +90,11 @@ void TestSynth::process() {
else if (tvol < cvol) cvol -= 16.0 / audioEngine->curSampleRate();
cvol = std::clamp(cvol, 0.0, 1.0);
if (cvol == 0.0) { osc = osc2 = 0.0; }
float oscV = static_cast<float>((std::sin(osc * PI*2) + std::sin(osc2 * PI*2) * std::pow(.75, 4)) * std::pow(cvol*.5, 4));
float oscV = static_cast<float>(fOsc(osc) * std::pow(cvol*.5, 4));
double enote = note + std::sin(lfo * PI*2) * 0.1;
double freq = 440.0 * std::pow(SEMI, enote - (45+12));
osc += freq / audioEngine->curSampleRate();
osc = std::fmod(osc, 1.0);
osc2 += (freq * .5) / audioEngine->curSampleRate();
osc2 = std::fmod(osc2, 1.0);
lfo += 3.0 / audioEngine->curSampleRate();
lfo = std::fmod(lfo, 1.0);

View File

@ -6,7 +6,6 @@ namespace Xybrid::Gadgets {
class TestSynth : public Data::Node {
//
double osc = 0;
double osc2 = 0;
double note = 45+12;
double lfo = 0;