mirror of https://github.com/probonopd/MiniDexed
parent
154cf690cb
commit
2542be1148
@ -0,0 +1,98 @@ |
|||||||
|
#include "fx_orbitone.h" |
||||||
|
|
||||||
|
#include <cmath> |
||||||
|
|
||||||
|
OrbitoneParameter::OrbitoneParameter(float32_t sampling_rate, float32_t feedback) : |
||||||
|
FXBase(sampling_rate), |
||||||
|
feedback_(feedback) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
OrbitoneParameter::~OrbitoneParameter() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void OrbitoneParameter::setFeedback(float32_t feedback) |
||||||
|
{ |
||||||
|
this->feedback_ = constrain(feedback, 0.0f, 1.0f); |
||||||
|
} |
||||||
|
|
||||||
|
float32_t OrbitoneParameter::getFeedback() const |
||||||
|
{ |
||||||
|
return this->feedback_; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// OrbitoneStage implementation
|
||||||
|
OrbitoneStage::OrbitoneStage(float32_t sampling_rate, OrbitoneParameter* params, float32_t frequency) : |
||||||
|
FXElement(sampling_rate), |
||||||
|
params_(params), |
||||||
|
frequency_(frequency), |
||||||
|
phase_(0.0f) |
||||||
|
{ |
||||||
|
this->phase_increment_ = 2.0f * PI * frequency / this->getSamplingRate(); |
||||||
|
} |
||||||
|
|
||||||
|
void OrbitoneStage::processSample(float32_t inL, float32_t inR, float32_t& outL, float32_t& outR) |
||||||
|
{ |
||||||
|
// Generate a sine wave using the stage's oscillator
|
||||||
|
float32_t osc = sin(this->phase_); |
||||||
|
|
||||||
|
// Update the phase of the oscillator
|
||||||
|
this->phase_ += this->phase_increment_; |
||||||
|
if(this->phase_ > 2.0f * PI) { |
||||||
|
this->phase_ -= 2.0f * PI; |
||||||
|
} |
||||||
|
|
||||||
|
// Apply feedback to the stage's input
|
||||||
|
outL = inL + osc * this->params_->getFeedback(); |
||||||
|
outR = inR + osc * this->params_->getFeedback(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Orbitone implementation
|
||||||
|
Orbitone::Orbitone(float32_t sampling_rate, float32_t feedback) :
|
||||||
|
FXElement(sampling_rate), |
||||||
|
params_(sampling_rate, feedback) |
||||||
|
{ |
||||||
|
for(unsigned i = 0; i < NUM_ORBITONR_STAGES; ++i) |
||||||
|
{ |
||||||
|
float32_t frequency = 440.0 * pow(2.0f, (i - 1) / 12.0f); // Sets the frequency of each stage to be a multiple of 440 Hz
|
||||||
|
this->stages_[i] = new OrbitoneStage(sampling_rate, &this->params_, frequency); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Orbitone::~Orbitone() |
||||||
|
{ |
||||||
|
for(unsigned i = 0; i < NUM_ORBITONR_STAGES; ++i) |
||||||
|
{ |
||||||
|
delete this->stages_[i]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void Orbitone::processSample(float32_t inL, float32_t inR, float32_t& outL, float32_t& outR) |
||||||
|
{ |
||||||
|
// Process the input sample through each stage of the phaser
|
||||||
|
float32_t sampleL = inL; |
||||||
|
float32_t sampleR = inR; |
||||||
|
for(unsigned s = 0; s < NUM_ORBITONR_STAGES; ++s) |
||||||
|
{ |
||||||
|
this->stages_[s]->processSample(sampleL, sampleR, sampleL, sampleR); |
||||||
|
} |
||||||
|
|
||||||
|
// Modulate the output of the phaser using the LFO
|
||||||
|
outL = sampleL; |
||||||
|
outR = sampleR; |
||||||
|
} |
||||||
|
|
||||||
|
void Orbitone::setFeedback(float32_t feedback) |
||||||
|
{ |
||||||
|
this->params_.setFeedback(feedback); |
||||||
|
} |
||||||
|
|
||||||
|
float32_t Orbitone::getFeedback() const |
||||||
|
{ |
||||||
|
return this->params_.getFeedback(); |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//
|
||||||
|
// fx_orbitone.h
|
||||||
|
//
|
||||||
|
// Stereo Orbitone audio effects proposed in the context of the MiniDexed project
|
||||||
|
//
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "fx.h" |
||||||
|
|
||||||
|
class OrbitoneStage; |
||||||
|
|
||||||
|
class OrbitoneParameter : public FXBase |
||||||
|
{ |
||||||
|
friend class OrbitoneStage; |
||||||
|
DISALLOW_COPY_AND_ASSIGN(OrbitoneParameter); |
||||||
|
|
||||||
|
public: |
||||||
|
OrbitoneParameter(float32_t sampling_rate, float32_t feedback = 0.5f); |
||||||
|
virtual ~OrbitoneParameter(); |
||||||
|
|
||||||
|
void setFeedback(float32_t feedback); |
||||||
|
inline float32_t getFeedback() const; |
||||||
|
|
||||||
|
private: |
||||||
|
float32_t feedback_; // Amount of feedback to apply to the stage's input
|
||||||
|
}; |
||||||
|
|
||||||
|
class OrbitoneStage : public FXElement |
||||||
|
{ |
||||||
|
DISALLOW_COPY_AND_ASSIGN(OrbitoneStage); |
||||||
|
|
||||||
|
public: |
||||||
|
OrbitoneStage(float32_t sampling_rate, OrbitoneParameter* params, float32_t frequency); |
||||||
|
|
||||||
|
virtual void processSample(float32_t inL, float32_t inR, float32_t& outL, float32_t& outR) override; |
||||||
|
|
||||||
|
private: |
||||||
|
OrbitoneParameter* params_; |
||||||
|
float32_t frequency_; // Frequency of the stage oscillator in Hz
|
||||||
|
float32_t phase_; // Phase of the stage's oscillator
|
||||||
|
float32_t phase_increment_; // Amount to increment the phase at each sample
|
||||||
|
}; |
||||||
|
|
||||||
|
#define NUM_ORBITONR_STAGES 4 |
||||||
|
|
||||||
|
class Orbitone : public FXElement |
||||||
|
{ |
||||||
|
DISALLOW_COPY_AND_ASSIGN(Orbitone); |
||||||
|
|
||||||
|
public: |
||||||
|
Orbitone(float32_t sampling_rate, float32_t feedback = 0.5f); |
||||||
|
virtual ~Orbitone(); |
||||||
|
|
||||||
|
virtual void processSample(float32_t inL, float32_t inR, float32_t& outL, float32_t& outR) override; |
||||||
|
|
||||||
|
void setFeedback(float32_t feedback); |
||||||
|
inline float32_t getFeedback() const; |
||||||
|
|
||||||
|
private: |
||||||
|
OrbitoneParameter params_; |
||||||
|
OrbitoneStage* stages_[NUM_ORBITONR_STAGES]; |
||||||
|
}; |
Loading…
Reference in new issue