diff --git a/plugins/waveshaper/artwork.png b/plugins/waveshaper/artwork.png index 23e2be7b3..ba6d952ea 100644 Binary files a/plugins/waveshaper/artwork.png and b/plugins/waveshaper/artwork.png differ diff --git a/plugins/waveshaper/waveshaper.cpp b/plugins/waveshaper/waveshaper.cpp index 9ac55de81..16e3ced56 100644 --- a/plugins/waveshaper/waveshaper.cpp +++ b/plugins/waveshaper/waveshaper.cpp @@ -1,7 +1,7 @@ /* - * bass_booster.cpp - bass-booster-effect-plugin + * waveshaper.cpp - waveshaper effect-plugin * - * * Copyright * (c) 2006-2008 Vesa Kivimäki + * * Copyright * (c) 2014 Vesa Kivimäki * Copyright (c) 2006-2009 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net @@ -24,8 +24,8 @@ */ -#include "bass_booster.h" - +#include "waveshaper.h" +#include #include "embed.cpp" @@ -35,10 +35,10 @@ extern "C" Plugin::Descriptor PLUGIN_EXPORT waveshaper_plugin_descriptor = { STRINGIFY( PLUGIN_NAME ), - "BassBooster Effect", + "Waveshaper Effect", QT_TRANSLATE_NOOP( "pluginBrowser", - "plugin for boosting bass" ), - "Tobias Doerffel ", + "plugin for waveshaping" ), + "Vesa Kivimäki ", 0x0100, Plugin::Effect, new PluginPixmapLoader( "logo" ), @@ -50,25 +50,24 @@ Plugin::Descriptor PLUGIN_EXPORT waveshaper_plugin_descriptor = -bassBoosterEffect::bassBoosterEffect( Model * _parent, +waveShaperEffect::waveShaperEffect( Model * _parent, const Descriptor::SubPluginFeatures::Key * _key ) : Effect( &waveshaper_plugin_descriptor, _parent, _key ), - m_bbFX( effectLib::fastBassBoost( 70.0f, 1.0f, 2.8f ) ), - m_bbControls( this ) + m_wsControls( this ) { } -bassBoosterEffect::~bassBoosterEffect() +waveShaperEffect::~waveShaperEffect() { } -bool bassBoosterEffect::processAudioBuffer( sampleFrame * _buf, +bool waveShaperEffect::processAudioBuffer( sampleFrame * _buf, const fpp_t _frames ) { if( !isEnabled() || !isRunning () ) @@ -76,14 +75,55 @@ bool bassBoosterEffect::processAudioBuffer( sampleFrame * _buf, return( false ); } +// variables for effect + int i = 0; + float lookup; + float frac; + float posneg; + double out_sum = 0.0; const float d = dryLevel(); const float w = wetLevel(); for( fpp_t f = 0; f < _frames; ++f ) { sample_t s[2] = { _buf[f][0], _buf[f][1] }; - m_bbFX.nextSample( s[0], s[1] ); +// apply input gain + s[0] *= m_wsControls.m_inputModel.value(); + s[1] *= m_wsControls.m_inputModel.value(); + +// start effect + + for ( i=0; i <= 1; ++i ) + { + lookup = fabsf( s[i] ) * 100.0f; + posneg = s[i] < 0 ? -1.0f : 1.0f; + + if ( lookup < 1 ) + { + frac = lookup - truncf(lookup); + s[i] = frac * m_wsControls.m_wavegraphModel.samples()[0] * posneg; + } + else + if ( lookup < 100 ) + { + frac = lookup - truncf(lookup); + s[i] = + (( (1.0f-frac) * m_wsControls.m_wavegraphModel.samples()[ (int)truncf(lookup) - 1 ] ) + + ( frac * m_wsControls.m_wavegraphModel.samples()[ (int)truncf(lookup) ] )) + * posneg; + } + else + { + s[i] *= m_wsControls.m_wavegraphModel.samples()[99]; + } + } + +// apply output gain + s[0] *= m_wsControls.m_outputModel.value(); + s[1] *= m_wsControls.m_outputModel.value(); + +// mix wet/dry signals _buf[f][0] = d * _buf[f][0] + w * s[0]; _buf[f][1] = d * _buf[f][1] + w * s[1]; @@ -105,7 +145,7 @@ extern "C" // necessary for getting instance out of shared lib Plugin * PLUGIN_EXPORT lmms_plugin_main( Model * _parent, void * _data ) { - return( new bassBoosterEffect( _parent, + return( new waveShaperEffect( _parent, static_cast( _data ) ) ); } diff --git a/plugins/waveshaper/waveshaper.h b/plugins/waveshaper/waveshaper.h index 90d8f2a55..016cab4de 100644 --- a/plugins/waveshaper/waveshaper.h +++ b/plugins/waveshaper/waveshaper.h @@ -1,7 +1,7 @@ /* - * bass_booster.h - bass-booster-effect-plugin + * waveshaper.h - bass-booster-effect-plugin * - * * Copyright * (c) 2006-2008 Vesa Kivimäki + * * Copyright * (c) 2014 Vesa Kivimäki * Copyright (c) 2006-2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net @@ -24,8 +24,8 @@ */ -#ifndef _BASS_BOOSTER_H -#define _BASS_BOOSTER_H +#ifndef _WAVESHAPER_H +#define _WAVESHAPER_H #include "Effect.h" #include "effect_lib.h" @@ -33,27 +33,26 @@ -class bassBoosterEffect : public Effect +class waveShaperEffect : public Effect { public: - bassBoosterEffect( Model * _parent, + waveShaperEffect( Model * _parent, const Descriptor::SubPluginFeatures::Key * _key ); - virtual ~bassBoosterEffect(); + virtual ~waveShaperEffect(); virtual bool processAudioBuffer( sampleFrame * _buf, const fpp_t _frames ); virtual EffectControls * controls() { - return( &m_bbControls ); + return( &m_wsControls ); } private: - effectLib::monoToStereoAdaptor m_bbFX; + + waveShaperControls m_wsControls; - bassBoosterControls m_bbControls; - - friend class bassBoosterControls; + friend class waveShaperControls; } ; diff --git a/plugins/waveshaper/waveshaper_control_dialog.cpp b/plugins/waveshaper/waveshaper_control_dialog.cpp index d7b16b232..b00dc3cd8 100644 --- a/plugins/waveshaper/waveshaper_control_dialog.cpp +++ b/plugins/waveshaper/waveshaper_control_dialog.cpp @@ -1,7 +1,7 @@ /* * waveshaper_control_dialog.cpp - control-dialog for waveshaper-effect * - * Copyright * (c) 2006-2008 Vesa Kivimäki + * Copyright * (c) 2014 Vesa Kivimäki * Copyright * (c) 2006-2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net @@ -29,11 +29,12 @@ #include "waveshaper_control_dialog.h" #include "waveshaper_controls.h" #include "embed.h" +#include "graph.h" -bassBoosterControlDialog::bassBoosterControlDialog( - bassBoosterControls * _controls ) : +waveShaperControlDialog::waveShaperControlDialog( + waveShaperControls * _controls ) : EffectControlDialog( _controls ) { setAutoFillBackground( true ); @@ -41,34 +42,33 @@ bassBoosterControlDialog::bassBoosterControlDialog( pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) ); setPalette( pal ); - setFixedSize( 120, 104 ); + setFixedSize( 120, 200 ); QVBoxLayout * tl = new QVBoxLayout( this ); tl->addSpacing( 30 ); + graph * waveGraph = new graph( this, graph::LinearStyle ); + waveGraph -> setModel( &_controls -> m_wavegraphModel ); + waveGraph -> setAutoFillBackground( true ); + + tl -> addWidget( waveGraph ); + QHBoxLayout * l = new QHBoxLayout; - knob * freqKnob = new knob( knobBright_26, this); - freqKnob->setModel( &_controls->m_freqModel ); - freqKnob->setLabel( tr( "FREQ" ) ); - freqKnob->setHintText( tr( "Frequency:" ) + " ", "Hz" ); + knob * inputKnob = new knob( knobBright_26, this); + inputKnob->setModel( &_controls->m_inputModel ); + inputKnob->setLabel( tr( "INPUT" ) ); + inputKnob->setHintText( tr( "Input gain:" ) + " ", "" ); - knob * gainKnob = new knob( knobBright_26, this ); - gainKnob->setModel( &_controls->m_gainModel ); - gainKnob->setLabel( tr( "GAIN" ) ); - gainKnob->setHintText( tr( "Gain:" ) + " ", "" ); + knob * outputKnob = new knob( knobBright_26, this ); + outputKnob->setModel( &_controls->m_outputModel ); + outputKnob->setLabel( tr( "OUTPUT" ) ); + outputKnob->setHintText( tr( "Output gain:" ) + " ", "" ); - knob * ratioKnob = new knob( knobBright_26, this ); - ratioKnob->setModel( &_controls->m_ratioModel ); - ratioKnob->setLabel( tr( "RATIO" ) ); - ratioKnob->setHintText( tr( "Ratio:" ) + " ", "" ); - - l->addWidget( freqKnob ); - l->addWidget( gainKnob ); - l->addWidget( ratioKnob ); + l->addWidget( inputKnob ); + l->addWidget( outputKnob ); tl->addLayout( l ); setLayout( tl ); } - diff --git a/plugins/waveshaper/waveshaper_control_dialog.h b/plugins/waveshaper/waveshaper_control_dialog.h index fe11fd5e0..6fb974ebf 100644 --- a/plugins/waveshaper/waveshaper_control_dialog.h +++ b/plugins/waveshaper/waveshaper_control_dialog.h @@ -1,7 +1,7 @@ /* * waveshaper_control_dialog.h - control-dialog for waveshaper-effect * - * * Copyright * (c) 2006-2008 Vesa Kivimäki + * * Copyright * (c) 2014 Vesa Kivimäki * Copyright (c) 2006-2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net @@ -29,17 +29,19 @@ #include "EffectControlDialog.h" -class bassBoosterControls; +class waveShaperControls; -class bassBoosterControlDialog : public EffectControlDialog +class waveShaperControlDialog : public EffectControlDialog { public: - bassBoosterControlDialog( bassBoosterControls * _controls ); - virtual ~bassBoosterControlDialog() + waveShaperControlDialog( waveShaperControls * _controls ); + virtual ~waveShaperControlDialog() { } +private: + } ; #endif diff --git a/plugins/waveshaper/waveshaper_controls.cpp b/plugins/waveshaper/waveshaper_controls.cpp index c675ea044..6455c9653 100644 --- a/plugins/waveshaper/waveshaper_controls.cpp +++ b/plugins/waveshaper/waveshaper_controls.cpp @@ -1,7 +1,7 @@ /* * waveshaper_controls.cpp - controls for waveshaper-effect * - * Copyright * (c) 2006-2008 Vesa Kivimäki + * Copyright * (c) 2014 Vesa Kivimäki * Copyright (c) 2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net @@ -27,84 +27,103 @@ #include #include "waveshaper_controls.h" -#include "bass_booster.h" +#include "waveshaper.h" +#include "graph.h" -bassBoosterControls::bassBoosterControls( bassBoosterEffect * _eff ) : +waveShaperControls::waveShaperControls( waveShaperEffect * _eff ) : EffectControls( _eff ), m_effect( _eff ), - m_freqModel( 100.0f, 50.0f, 200.0f, 1.0f, this, tr( "Frequency" ) ), - m_gainModel( 1.0f, 0.1f, 5.0f, 0.05f, this, tr( "Gain" ) ), - m_ratioModel( 2.0f, 0.1f, 10.0f, 0.1f, this, tr( "Ratio" ) ) + m_inputModel( 1.0f, 0.0f, 2.0f, 0.01f, this, tr( "Input gain" ) ), + m_outputModel( 1.0f, 0.0f, 2.0f, 0.01f, this, tr( "Output gain" ) ), + m_wavegraphModel( 0.0f, 1.0f, 100, this ) { - connect( &m_freqModel, SIGNAL( dataChanged() ), - this, SLOT( changeFrequency() ) ); + connect( &m_inputModel, SIGNAL( dataChanged() ), + this, SLOT( changeInput() ) ); - connect( &m_gainModel, SIGNAL( dataChanged() ), - this, SLOT( changeGain() ) ); + connect( &m_outputModel, SIGNAL( dataChanged() ), + this, SLOT( changeOutput() ) ); - connect( &m_ratioModel, SIGNAL( dataChanged() ), - this, SLOT( changeRatio() ) ); + connect( &m_wavegraphModel, SIGNAL( samplesChanged( int, int ) ), + this, SLOT( samplesChanged( int, int ) ) ); - connect( engine::mixer(), SIGNAL( sampleRateChanged() ), - this, SLOT( changeFrequency() ) ); - changeFrequency(); - changeGain(); - changeRatio(); + changeInput(); + changeOutput(); + setDefaultShape(); + } -void bassBoosterControls::changeFrequency() +void waveShaperControls::changeInput() { - const sample_t fac = engine::mixer()->processingSampleRate() / - 44100.0f; - m_effect->m_bbFX.leftFX().setFrequency( m_freqModel.value() * fac ); - m_effect->m_bbFX.rightFX().setFrequency( m_freqModel.value() * fac ); } -void bassBoosterControls::changeGain() +void waveShaperControls::changeOutput() { - m_effect->m_bbFX.leftFX().setGain( m_gainModel.value() ); - m_effect->m_bbFX.rightFX().setGain( m_gainModel.value() ); } -void bassBoosterControls::changeRatio() -{ - m_effect->m_bbFX.leftFX().setRatio( m_ratioModel.value() ); - m_effect->m_bbFX.rightFX().setRatio( m_ratioModel.value() ); +void waveShaperControls::samplesChanged( int _begin, int _end) +{ } -void bassBoosterControls::loadSettings( const QDomElement & _this ) +void waveShaperControls::loadSettings( const QDomElement & _this ) { - m_freqModel.setValue( _this.attribute( "freq" ).toFloat() ); - m_gainModel.setValue( _this.attribute( "gain" ).toFloat() ); - m_ratioModel.setValue( _this.attribute( "ratio" ).toFloat() ); +//load input, output knobs + m_inputModel.setValue( _this.attribute( "inputGain" ).toFloat() ); + m_outputModel.setValue( _this.attribute( "outputGain" ).toFloat() ); + +//load waveshape + int size = 0; + char * dst = 0; + base64::decode( _this.attribute( "waveShape"), &dst, &size ); + + m_wavegraphModel.setSamples( (float*) dst ); + delete[] dst; + } -void bassBoosterControls::saveSettings( QDomDocument & _doc, +void waveShaperControls::saveSettings( QDomDocument & _doc, QDomElement & _this ) { - _this.setAttribute( "freq", m_freqModel.value() ); - _this.setAttribute( "gain", m_gainModel.value() ); - _this.setAttribute( "ratio", m_ratioModel.value() ); +//save input, output knobs + _this.setAttribute( "inputGain", m_inputModel.value() ); + _this.setAttribute( "outputGain", m_outputModel.value() ); + +//save waveshape + QString sampleString; + base64::encode( (const char *)m_wavegraphModel.samples(), + m_wavegraphModel.length() * sizeof(float), sampleString ); + _this.setAttribute( "waveShape", sampleString ); + } +void waveShaperControls::setDefaultShape() +{ + float shp [100] = { }; + for ( int i = 0; i<100; i++) + { + shp[i] = ((float)i + 1.0f) / 100.0f; + } + + m_wavegraphModel.setLength( 100 ); + m_wavegraphModel.setSamples( (float*)&shp ); +} #include "moc_waveshaper_controls.cxx" diff --git a/plugins/waveshaper/waveshaper_controls.h b/plugins/waveshaper/waveshaper_controls.h index f8b818939..e69436b7c 100644 --- a/plugins/waveshaper/waveshaper_controls.h +++ b/plugins/waveshaper/waveshaper_controls.h @@ -1,7 +1,7 @@ /* * waveshaper_controls.h - controls for waveshaper-effect * - * Copyright * (c) 2006-2008 Vesa Kivimäki + * Copyright * (c) 2014 Vesa Kivimäki * Copyright (c) 2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net @@ -29,17 +29,17 @@ #include "EffectControls.h" #include "waveshaper_control_dialog.h" #include "knob.h" +#include "graph.h" + +class waveShaperEffect; -class bassBoosterEffect; - - -class bassBoosterControls : public EffectControls +class waveShaperControls : public EffectControls { Q_OBJECT public: - bassBoosterControls( bassBoosterEffect * _eff ); - virtual ~bassBoosterControls() + waveShaperControls( waveShaperEffect * _eff ); + virtual ~waveShaperControls() { } @@ -49,6 +49,8 @@ public: { return( "waveshapercontrols" ); } + + virtual void setDefaultShape(); virtual int controlCount() { @@ -57,23 +59,23 @@ public: virtual EffectControlDialog * createView() { - return( new bassBoosterControlDialog( this ) ); + return( new waveShaperControlDialog( this ) ); } private slots: - void changeFrequency(); - void changeGain(); - void changeRatio(); - + void changeInput(); + void changeOutput(); + void samplesChanged( int, int ); private: - bassBoosterEffect * m_effect; - FloatModel m_freqModel; - FloatModel m_gainModel; - FloatModel m_ratioModel; + waveShaperEffect * m_effect; + FloatModel m_inputModel; + FloatModel m_outputModel; + graphModel m_wavegraphModel; - friend class bassBoosterControlDialog; + friend class waveShaperControlDialog; + friend class waveShaperEffect; } ;