diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4f4a668e7..bb028b49e 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -8,6 +8,7 @@ ADD_SUBDIRECTORY(carlarack) ADD_SUBDIRECTORY(delay) ADD_SUBDIRECTORY(DualFilter) ADD_SUBDIRECTORY(dynamics_processor) +ADD_SUBDIRECTORY(flanger) ADD_SUBDIRECTORY(flp_import) ADD_SUBDIRECTORY(HydrogenImport) ADD_SUBDIRECTORY(kicker) diff --git a/plugins/flanger/CMakeLists.txt b/plugins/flanger/CMakeLists.txt new file mode 100644 index 000000000..bb3579e73 --- /dev/null +++ b/plugins/flanger/CMakeLists.txt @@ -0,0 +1,3 @@ +INCLUDE(BuildPlugin) + +BUILD_PLUGIN(flanger flangereffect.cpp flangercontrols.cpp flangercontrolsdialog.cpp noise.cpp quadraturelfo.cpp monodelay.cpp MOCFILES flangercontrols.h EMBEDDED_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.png") diff --git a/plugins/flanger/artwork.png b/plugins/flanger/artwork.png new file mode 100644 index 000000000..239bc219e Binary files /dev/null and b/plugins/flanger/artwork.png differ diff --git a/plugins/flanger/flangercontrols.cpp b/plugins/flanger/flangercontrols.cpp new file mode 100644 index 000000000..d7271c833 --- /dev/null +++ b/plugins/flanger/flangercontrols.cpp @@ -0,0 +1,83 @@ +/* + * flangercontrols.cpp - defination of FlangerControls class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include + +#include "flangercontrols.h" +#include "flangereffect.h" +#include "Engine.h" +#include "Song.h" + + + +FlangerControls::FlangerControls( FlangerEffect *effect ) : + EffectControls ( effect ), + m_effect ( effect ), + m_delayTimeModel(0.001, 0.0001, 0.050, 0.0001, this, tr( "Delay Samples" ) ) , + m_lfoFrequencyModel( 0.25, 0.01, 5, 0.0001, this, tr( "Lfo Frequency" ) ), + m_lfoAmountModel( 0.1, 0.0, 1.0 , 0.001 , this , tr( "Amount" ) ), + m_feedbackModel( 0.0 , 0.0 , 1.0 , 0.0001, this, tr( "Regen" ) ), + m_whiteNoiseAmountModel( 0.0 , 0.0 , 0.05 , 0.0001, this, tr( "Noise" ) ), + m_invertFeedbackModel ( false , this, tr( "Invert" ) ) + +{ + connect( Engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( changedSampleRate() ) ); +} + + + + +void FlangerControls::loadSettings( const QDomElement &_this ) +{ + m_delayTimeModel.loadSettings( _this, "DelayTimeSamples" ); + m_lfoFrequencyModel.loadSettings( _this, "LfoFrequency" ); + m_lfoAmountModel.loadSettings( _this, "LfoAmount" ); + m_feedbackModel.loadSettings( _this, "Feedback" ); + m_whiteNoiseAmountModel.loadSettings( _this, "WhiteNoise" ); + m_invertFeedbackModel.loadSettings( _this, "Invert" ); + +} + + + + +void FlangerControls::saveSettings( QDomDocument &doc, QDomElement &parent ) +{ + m_delayTimeModel.saveSettings( doc , parent, "DelayTimeSamples" ); + m_lfoFrequencyModel.saveSettings( doc, parent , "LfoFrequency" ); + m_lfoAmountModel.saveSettings( doc, parent , "LfoAmount" ); + m_feedbackModel.saveSettings( doc, parent, "Feedback" ) ; + m_whiteNoiseAmountModel.saveSettings( doc, parent , "WhiteNoise" ) ; + m_invertFeedbackModel.saveSettings( doc, parent, "Invert" ); +} + + + + +void FlangerControls::changedSampleRate() +{ + m_effect->changeSampleRate(); +} + + diff --git a/plugins/flanger/flangercontrols.h b/plugins/flanger/flangercontrols.h new file mode 100644 index 000000000..864119678 --- /dev/null +++ b/plugins/flanger/flangercontrols.h @@ -0,0 +1,75 @@ +/* + * flangercontrols.h - defination of StereoDelay class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#ifndef FLANGERCONTROLS_H +#define FLANGERCONTROLS_H + +#include "EffectControls.h" +#include "Knob.h" +#include "flangercontrolsdialog.h" + + +class FlangerEffect; + +class FlangerControls : public EffectControls +{ + Q_OBJECT +public: + FlangerControls( FlangerEffect* effect ); + virtual ~FlangerControls() + { + } + virtual void saveSettings ( QDomDocument& doc, QDomElement& parent ); + virtual void loadSettings ( const QDomElement &_this ); + inline virtual QString nodeName() const + { + return "Flanger"; + } + virtual int controlCount() + { + return 5; + } + virtual EffectControlDialog* createView() + { + return new FlangerControlsDialog( this ); + } + +private slots: + void changedSampleRate(); + +private: + FlangerEffect* m_effect; + FloatModel m_delayTimeModel; + FloatModel m_lfoFrequencyModel; + FloatModel m_lfoAmountModel; + FloatModel m_feedbackModel; + FloatModel m_whiteNoiseAmountModel; + BoolModel m_invertFeedbackModel; + + friend class FlangerControlsDialog; + friend class FlangerEffect; + +}; + +#endif // FLANGERCONTROLS_H diff --git a/plugins/flanger/flangercontrolsdialog.cpp b/plugins/flanger/flangercontrolsdialog.cpp new file mode 100644 index 000000000..a00e524f5 --- /dev/null +++ b/plugins/flanger/flangercontrolsdialog.cpp @@ -0,0 +1,82 @@ +/* + * flangercontrolsdialog.cpp - defination of FlangerControlsDialog class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include "flangercontrolsdialog.h" +#include "flangercontrols.h" +#include "embed.h" +#include "LedCheckbox.h" + + + + +FlangerControlsDialog::FlangerControlsDialog( FlangerControls *controls ) : + EffectControlDialog( controls ) +{ + setAutoFillBackground( true ); + QPalette pal; + pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) ); + setPalette( pal ); + setFixedSize( 200, 75 ); + + Knob* delayKnob = new Knob( knobBright_26, this ); + delayKnob->move( 20,10 ); + delayKnob->setVolumeKnob( false ); + delayKnob->setModel( &controls->m_delayTimeModel ); + delayKnob->setLabel( tr( "Delay" ) ); + delayKnob->setHintText( tr( "Delay Time :" ) + " ", "" ); + + Knob * lfoFreqKnob = new Knob( knobBright_26, this ); + lfoFreqKnob->move( 53,10 ); + lfoFreqKnob->setVolumeKnob( false ); + lfoFreqKnob->setModel( &controls->m_lfoFrequencyModel ); + lfoFreqKnob->setLabel( tr( "Lfo Hz" ) ); + lfoFreqKnob->setHintText( tr ( "Lfo Hz:" ) + " ", "" ); + + Knob * lfoAmtKnob = new Knob( knobBright_26, this ); + lfoAmtKnob->move( 86,10 ); + lfoAmtKnob->setVolumeKnob( false ); + lfoAmtKnob->setModel( &controls->m_lfoAmountModel ); + lfoAmtKnob->setLabel( tr( "Amt" ) ); + lfoAmtKnob->setHintText( tr ( "Amt" ) + " ", "" ); + + Knob * feedbackKnob = new Knob( knobBright_26, this ); + feedbackKnob->move( 119,10 ); + feedbackKnob->setVolumeKnob( true) ; + feedbackKnob->setModel( &controls->m_feedbackModel ); + feedbackKnob->setLabel( tr( "Regen" ) ); + feedbackKnob->setHintText( tr ( "Feedback Amount:" ) + " ", "" ); + + Knob * whiteNoiseKnob = new Knob( knobBright_26, this ); + whiteNoiseKnob->move( 150,10 ); + whiteNoiseKnob->setVolumeKnob( true) ; + whiteNoiseKnob->setModel( &controls->m_whiteNoiseAmountModel ); + whiteNoiseKnob->setLabel( tr( "Noise" ) ); + whiteNoiseKnob->setHintText( tr ( "White Noise Amount:" ) + " ", "" ); + + LedCheckBox* invertCb = new LedCheckBox( tr( "" ), this ); + invertCb->move( 15,55 ); + + + +} diff --git a/plugins/flanger/flangercontrolsdialog.h b/plugins/flanger/flangercontrolsdialog.h new file mode 100644 index 000000000..bdfa90d45 --- /dev/null +++ b/plugins/flanger/flangercontrolsdialog.h @@ -0,0 +1,41 @@ +/* + * flangercontrolsdialog.h - defination of FlangerControlsDialog class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#ifndef FLANGERCONTROLSDIALOG_H +#define FLANGERCONTROLSDIALOG_H + +#include "EffectControlDialog.h" + +class FlangerControls; + +class FlangerControlsDialog : public EffectControlDialog +{ +public: + FlangerControlsDialog( FlangerControls* controls ); + virtual ~FlangerControlsDialog() + { + } +}; + +#endif // FLANGERCONTROLSDIALOG_H diff --git a/plugins/flanger/flangereffect.cpp b/plugins/flanger/flangereffect.cpp new file mode 100644 index 000000000..70ac8c0df --- /dev/null +++ b/plugins/flanger/flangereffect.cpp @@ -0,0 +1,150 @@ +/* + * flangereffect.cpp - defination of FlangerEffect class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include "flangereffect.h" +#include "Engine.h" +#include "embed.cpp" + +extern "C" +{ + +Plugin::Descriptor PLUGIN_EXPORT flanger_plugin_descriptor = +{ + STRINGIFY( PLUGIN_NAME ), + "Flanger", + QT_TRANSLATE_NOOP( "pluginBrowser", "A native flanger plugin" ), + "Dave French ", + 0x0100, + Plugin::Effect, + new PluginPixmapLoader( "logo" ), + NULL, + NULL +} ; + + + + +FlangerEffect::FlangerEffect( Model *parent, const Plugin::Descriptor::SubPluginFeatures::Key *key ) : + Effect( &flanger_plugin_descriptor, parent, key ), + m_flangerControls( this ) +{ + m_lfo = new QuadratureLfo( Engine::mixer()->processingSampleRate() ); + m_lDelay = new MonoDelay( 1, Engine::mixer()->processingSampleRate() ); + m_rDelay = new MonoDelay( 1, Engine::mixer()->processingSampleRate() ); + m_noise = new Noise; +} + + + + +FlangerEffect::~FlangerEffect() +{ + if(m_lDelay ) + { + delete m_lDelay; + } + if( m_rDelay ) + { + delete m_rDelay; + } + if(m_lfo ) + { + delete m_lfo; + } + if(m_noise) + { + delete m_noise; + } +} + + + + +bool FlangerEffect::processAudioBuffer( sampleFrame *buf, const fpp_t frames ) +{ + if( !isEnabled() || !isRunning () ) + { + return( false ); + } + double outSum = 0.0; + const float d = dryLevel(); + const float w = wetLevel(); + const float length = m_flangerControls.m_delayTimeModel.value() * Engine::mixer()->processingSampleRate(); + const float noise = m_flangerControls.m_whiteNoiseAmountModel.value(); + m_lfo->setAmplitude( m_flangerControls.m_lfoAmountModel.value() ); + m_lfo->setFrequency( m_flangerControls.m_lfoFrequencyModel.value() ); + m_lDelay->setFeedback( m_flangerControls.m_feedbackModel.value() ); + m_rDelay->setFeedback( m_flangerControls.m_feedbackModel.value() ); + sample_t dryS[2]; + float leftLfo; + float rightLfo; + for( fpp_t f = 0; f < frames; ++f ) + { + buf[f][0] += m_noise->tick() * noise; + buf[f][1] += m_noise->tick() * noise; + dryS[0] = buf[f][0]; + dryS[1] = buf[f][1]; + m_lfo->tick(&leftLfo, &rightLfo); + m_lDelay->setLength( ( float )length * leftLfo ); + m_rDelay->setLength( ( float )length * rightLfo ); + if(m_flangerControls.m_invertFeedbackModel.value()) + { + m_lDelay->tick( &buf[f][1] ); + m_rDelay->tick(&buf[f][0] ); + } else + { + m_lDelay->tick( &buf[f][0] ); + m_rDelay->tick( &buf[f][1] ); + } + + buf[f][0] = ( d * dryS[0] ) + ( w * buf[f][0] ); + buf[f][1] = ( d * dryS[1] ) + ( w * buf[f][1] ); + outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1]; + } + checkGate( outSum / frames ); + return isRunning(); +} + + + + +void FlangerEffect::changeSampleRate() +{ + m_lfo->setSampleRate( Engine::mixer()->processingSampleRate() ); + m_lDelay->setSampleRate( Engine::mixer()->processingSampleRate() ); + m_rDelay->setSampleRate( Engine::mixer()->processingSampleRate() ); +} + + + +extern "C" +{ + +//needed for getting plugin out of shared lib +Plugin * PLUGIN_EXPORT lmms_plugin_main( Model* parent, void* data ) +{ + return new FlangerEffect( parent , static_cast( data ) ); +} + +}} diff --git a/plugins/flanger/flangereffect.h b/plugins/flanger/flangereffect.h new file mode 100644 index 000000000..d476a056a --- /dev/null +++ b/plugins/flanger/flangereffect.h @@ -0,0 +1,57 @@ +/* + * flangereffect.h - defination of FlangerEffect class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + + +#ifndef FLANGEREFFECT_H +#define FLANGEREFFECT_H + +#include "Effect.h" +#include "flangercontrols.h" +#include "quadraturelfo.h" +#include "monodelay.h" +#include "noise.h" + + +class FlangerEffect : public Effect +{ +public: + FlangerEffect( Model* parent , const Descriptor::SubPluginFeatures::Key* key ); + virtual ~FlangerEffect(); + virtual bool processAudioBuffer( sampleFrame *buf, const fpp_t frames ); + virtual EffectControls* controls() + { + return &m_flangerControls; + } + void changeSampleRate(); + +private: + FlangerControls m_flangerControls; + MonoDelay* m_lDelay; + MonoDelay* m_rDelay; + QuadratureLfo* m_lfo; + Noise* m_noise; + +}; + +#endif // FLANGEREFFECT_H diff --git a/plugins/flanger/logo.png b/plugins/flanger/logo.png new file mode 100644 index 000000000..89e9f3680 Binary files /dev/null and b/plugins/flanger/logo.png differ diff --git a/plugins/flanger/monodelay.cpp b/plugins/flanger/monodelay.cpp new file mode 100644 index 000000000..4d1fdaa4c --- /dev/null +++ b/plugins/flanger/monodelay.cpp @@ -0,0 +1,89 @@ +/* + * monodelay.cpp - defination of MonoDelay class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include "monodelay.h" +#include "interpolation.h" +#include "lmms_math.h" + +MonoDelay::MonoDelay( int maxTime , int sampleRate ) +{ + m_buffer = 0; + m_maxTime = maxTime; + m_maxLength = maxTime * sampleRate; + m_length = m_maxLength; + + m_index = 0; + m_feedback = 0.0f; + setSampleRate( sampleRate ); +} + + + + +MonoDelay::~MonoDelay() +{ + if( m_buffer ) + { + delete m_buffer; + } +} + + + + +void MonoDelay::tick( sample_t* sample ) +{ + m_buffer[m_index] = *sample; + int readIndex = m_index - ( int )m_length; + if(readIndex < 0) + { + readIndex += m_maxLength; + } + float fract = fraction( m_length ); + if(readIndex != m_maxLength-1 ) + { + *sample = linearInterpolate(m_buffer[readIndex] , + m_buffer[readIndex+1], fract ); + } else + { + *sample = linearInterpolate(m_buffer[readIndex] , + m_buffer[0], fract ); + } + m_buffer[m_index] += *sample * m_feedback; + m_index = ( m_index +1 ) % m_maxLength; +} + + + + +void MonoDelay::setSampleRate( int sampleRate ) +{ + if( m_buffer ) + { + delete m_buffer; + } + + + m_buffer = new sample_t[( int )( sampleRate * m_maxTime )]; +} diff --git a/plugins/flanger/monodelay.h b/plugins/flanger/monodelay.h new file mode 100644 index 000000000..8c544fd6c --- /dev/null +++ b/plugins/flanger/monodelay.h @@ -0,0 +1,60 @@ +/* + * monodelay.h - defination of MonoDelay class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#ifndef MONODELAY_H +#define MONODELAY_H + +#include "lmms_basics.h" + +class MonoDelay +{ +public: + MonoDelay( int maxTime , int sampleRate ); + ~MonoDelay(); + inline void setLength( float length ) + { + if( length <= m_maxLength && length >= 0 ) + { + m_length = length; + } + } + + inline void setFeedback( float feedback ) + { + m_feedback = feedback; + } + + void tick( sample_t* sample ); + void setSampleRate( int sampleRate ); + +private: + sample_t* m_buffer; + int m_maxLength; + float m_length; + int m_index; + float m_feedback; + float m_maxTime; +}; + +#endif // MONODELAY_H diff --git a/plugins/flanger/noise.cpp b/plugins/flanger/noise.cpp new file mode 100644 index 000000000..d7e7423a5 --- /dev/null +++ b/plugins/flanger/noise.cpp @@ -0,0 +1,39 @@ +/* + * noise.cpp - defination of Noise class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include "noise.h" +#include "lmms_math.h" + +Noise::Noise() +{ + inv_randmax = 1.0/RAND_MAX; /* for range of 0 - 1.0 */ +} + + + + +float Noise::tick() +{ + return (float) ((2.0 * rand() * inv_randmax) - 1.0); +} diff --git a/plugins/flanger/noise.h b/plugins/flanger/noise.h new file mode 100644 index 000000000..008700ed7 --- /dev/null +++ b/plugins/flanger/noise.h @@ -0,0 +1,37 @@ +/* + * noise.h - defination of Noise class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#ifndef NOISE_H +#define NOISE_H + +class Noise +{ +public: + Noise(); + float tick(); +private: + double inv_randmax; +}; + +#endif // NOISE_H diff --git a/plugins/flanger/quadraturelfo.cpp b/plugins/flanger/quadraturelfo.cpp new file mode 100644 index 000000000..b11850bec --- /dev/null +++ b/plugins/flanger/quadraturelfo.cpp @@ -0,0 +1,49 @@ +/* + * quadraturelfo.cpp - defination of QuadratureLfo class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include "quadraturelfo.h" + +QuadratureLfo::QuadratureLfo( int sampleRate ) +{ + setSampleRate(sampleRate); +} + +void QuadratureLfo::tick( float *s, float *c ) +{ + *s = sinf( m_phase ); + *c = cosf( m_phase ); + m_phase += m_increment; + + if( m_amplitude < 0.0001 ) + { + *s = 1; + *c = 1; + } else + { + *s = ( ( *s * m_amplitude + 1.0 ) * 0.5 ); + *c = ( ( *c * m_amplitude + 1.0 ) * 0.5 ); + } + + +} diff --git a/plugins/flanger/quadraturelfo.h b/plugins/flanger/quadraturelfo.h new file mode 100644 index 000000000..0a3c6c823 --- /dev/null +++ b/plugins/flanger/quadraturelfo.h @@ -0,0 +1,81 @@ +/* + * quadraturelfo.h - defination of QuadratureLfo class. + * + * Copyright (c) 2014 David French + * + * This file is part of LMMS - http://lmms.io + * + * 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 2 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 (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#ifndef QUADRATURELFO_H +#define QUADRATURELFO_H + +#include "lmms_math.h" + +class QuadratureLfo +{ +public: + QuadratureLfo( int sampleRate ); + ~QuadratureLfo() + { + } + + inline void setFrequency( double frequency ) + { + if( frequency < 0 || frequency > ( m_samplerate / 2.0 ) || frequency == m_frequency ) + { + return; + } + m_frequency = frequency; + m_increment = m_frequency * m_twoPiOverSr; + + if( m_phase >= F_2PI ) + { + m_phase -= F_2PI; + } + } + + inline void setAmplitude( float amplitude ) + { + if( amplitude < 0.0 || amplitude > 1.0 ) + { + return; + } + m_amplitude = amplitude; + } + + inline void setSampleRate ( int samplerate ) + { + m_samplerate = samplerate; + m_twoPiOverSr = F_2PI / samplerate; + m_increment = m_frequency * m_twoPiOverSr; + } + + void tick( float *s, float *c ); + +private: + double m_frequency; + double m_phase; + double m_increment; + double m_amplitude; + double m_twoPiOverSr; + int m_samplerate; + +}; + +#endif // QUADRATURELFO_H