add wavefolder
This commit is contained in:
38
clip/wavefolder.h
Normal file
38
clip/wavefolder.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace trnr {
|
||||||
|
class wavefolder {
|
||||||
|
public:
|
||||||
|
float amount = 1.f;
|
||||||
|
|
||||||
|
float process_sample(float& _sample)
|
||||||
|
{
|
||||||
|
if (amount > 1.f) { return fold(_sample * amount); }
|
||||||
|
|
||||||
|
return 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
float fold(float _sample)
|
||||||
|
{
|
||||||
|
// fold positive values
|
||||||
|
if (_sample > 1.0) {
|
||||||
|
_sample = 2.0 - _sample;
|
||||||
|
|
||||||
|
if (_sample < 0.0) { _sample = -_sample; }
|
||||||
|
|
||||||
|
return fold(_sample);
|
||||||
|
}
|
||||||
|
// fold negative values
|
||||||
|
else if (_sample < -1.0) {
|
||||||
|
_sample = -2.0 - _sample;
|
||||||
|
|
||||||
|
if (_sample > 0.0) { _sample = -_sample; }
|
||||||
|
|
||||||
|
return fold(_sample);
|
||||||
|
} else {
|
||||||
|
return _sample;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}; // namespace trnr
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "tx_envelope.h"
|
#include "tx_envelope.h"
|
||||||
#include "tx_sineosc.h"
|
#include "tx_sineosc.h"
|
||||||
|
#include "../clip/wavefolder.h"
|
||||||
|
|
||||||
namespace trnr {
|
namespace trnr {
|
||||||
class tx_operator {
|
class tx_operator {
|
||||||
@@ -13,18 +14,19 @@ public:
|
|||||||
|
|
||||||
tx_envelope envelope;
|
tx_envelope envelope;
|
||||||
tx_sineosc oscillator;
|
tx_sineosc oscillator;
|
||||||
|
wavefolder wavefolding;
|
||||||
float ratio;
|
float ratio;
|
||||||
float amplitude;
|
float amplitude;
|
||||||
|
|
||||||
float process_sample(const bool& gate, const bool& trigger, const float& frequency, const float& velocity,
|
float process_sample(const bool& gate, const bool& trigger, const float& frequency, const float& velocity,
|
||||||
const float& pm = 0)
|
const float& pm = 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
float env = envelope.process_sample(gate, trigger);
|
float env = envelope.process_sample(gate, trigger);
|
||||||
|
|
||||||
// drifts and sounds better!
|
// drifts and sounds better!
|
||||||
if (envelope.is_busy()) {
|
if (envelope.is_busy()) {
|
||||||
double osc = oscillator.process_sample(trigger, frequency, pm);
|
float osc = oscillator.process_sample(trigger, frequency, pm);
|
||||||
|
osc = wavefolding.process_sample(osc);
|
||||||
return osc * env * velocity;
|
return osc * env * velocity;
|
||||||
} else {
|
} else {
|
||||||
return 0.;
|
return 0.;
|
||||||
|
|||||||
Reference in New Issue
Block a user