Merge pull request #467 from diizy/effects

Amplifier plugin
This commit is contained in:
Tobias Doerffel
2014-03-16 09:03:31 +01:00
10 changed files with 458 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
/*
* Amplifier.cpp - A native amplifier effect plugin with sample-exact amplification
*
* Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 "Amplifier.h"
#include "embed.cpp"
extern "C"
{
Plugin::Descriptor PLUGIN_EXPORT amplifier_plugin_descriptor =
{
STRINGIFY( PLUGIN_NAME ),
"Amplifier",
QT_TRANSLATE_NOOP( "pluginBrowser", "A native amplifier plugin" ),
"Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>",
0x0100,
Plugin::Effect,
new PluginPixmapLoader( "logo" ),
NULL,
NULL
} ;
}
AmplifierEffect::AmplifierEffect( Model* parent, const Descriptor::SubPluginFeatures::Key* key ) :
Effect( &amplifier_plugin_descriptor, parent, key ),
m_ampControls( this )
{
}
AmplifierEffect::~AmplifierEffect()
{
}
bool AmplifierEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
if( !isEnabled() || !isRunning () )
{
return( false );
}
double outSum = 0.0;
const float d = dryLevel();
const float w = wetLevel();
for( fpp_t f = 0; f < frames; ++f )
{
// qDebug( "offset %d, value %f", f, m_ampControls.m_volumeModel.value( f ) );
sample_t s[2] = { buf[f][0], buf[f][1] };
// convert vol/pan values to left/right values
const float left1 = m_ampControls.m_volumeModel.value( f ) *
( m_ampControls.m_panModel.value( f ) <= 0
? 1.0
: 1.0 - m_ampControls.m_panModel.value( f ) / 100.0 );
const float right1 = m_ampControls.m_volumeModel.value( f ) *
( m_ampControls.m_panModel.value( f ) >= 0
? 1.0
: 1.0 + m_ampControls.m_panModel.value( f ) / 100.0 );
// first stage amplification
s[0] *= ( left1 / 100.0 );
s[1] *= ( right1 / 100.0 );
// second stage amplification
s[0] *= ( m_ampControls.m_leftModel.value( f ) / 100.0 );
s[1] *= ( m_ampControls.m_rightModel.value( f ) / 100.0 );
buf[f][0] = d * buf[f][0] + w * s[0];
buf[f][1] = d * buf[f][1] + w * s[1];
outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];
}
checkGate( outSum / frames );
return isRunning();
}
extern "C"
{
// necessary for getting instance out of shared lib
Plugin * PLUGIN_EXPORT lmms_plugin_main( Model* parent, void* data )
{
return new AmplifierEffect( parent, static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>( data ) );
}
}

View File

@@ -0,0 +1,54 @@
/*
* Amplifier.h - amplifier-effect-plugin
*
* Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 AMPLIFIER_H
#define AMPLIFIER_H
#include "Effect.h"
#include "AmplifierControls.h"
class AmplifierEffect : public Effect
{
public:
AmplifierEffect( Model* parent, const Descriptor::SubPluginFeatures::Key* key );
virtual ~AmplifierEffect();
virtual bool processAudioBuffer( sampleFrame* buf, const fpp_t frames );
virtual EffectControls* controls()
{
return &m_ampControls;
}
private:
AmplifierControls m_ampControls;
friend class AmplifierControls;
} ;
#endif

View File

@@ -0,0 +1,69 @@
/*
* AmplifierControlDialog.cpp - control dialog for amplifier effect
*
* Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 <QtGui/QLayout>
#include "AmplifierControlDialog.h"
#include "AmplifierControls.h"
#include "embed.h"
AmplifierControlDialog::AmplifierControlDialog( AmplifierControls* controls ) :
EffectControlDialog( controls )
{
setAutoFillBackground( true );
QPalette pal;
pal.setBrush( backgroundRole(), PLUGIN_NAME::getIconPixmap( "artwork" ) );
setPalette( pal );
setFixedSize( 100, 125 );
knob * volumeKnob = new knob( knobBright_26, this);
volumeKnob -> move( 20, 30 );
volumeKnob -> setVolumeKnob( true );
volumeKnob->setModel( &controls->m_volumeModel );
volumeKnob->setLabel( tr( "VOL" ) );
volumeKnob->setHintText( tr( "Volume:" ) + " ", "%" );
knob * panKnob = new knob( knobBright_26, this);
panKnob -> move( 60, 30 );
panKnob->setModel( &controls->m_panModel );
panKnob->setLabel( tr( "PAN" ) );
panKnob->setHintText( tr( "Panning:" ) + " ", "" );
knob * leftKnob = new knob( knobBright_26, this);
leftKnob -> move( 20, 80 );
leftKnob -> setVolumeKnob( true );
leftKnob->setModel( &controls->m_leftModel );
leftKnob->setLabel( tr( "LEFT" ) );
leftKnob->setHintText( tr( "Left gain:" ) + " ", "%" );
knob * rightKnob = new knob( knobBright_26, this);
rightKnob -> move( 60, 80 );
rightKnob -> setVolumeKnob( true );
rightKnob->setModel( &controls->m_rightModel );
rightKnob->setLabel( tr( "RIGHT" ) );
rightKnob->setHintText( tr( "Right gain:" ) + " ", "%" );
}

View File

@@ -0,0 +1,45 @@
/*
* AmplifierControlDialog.h - control dialog for amplifier effect
*
* Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 AMPLIFIER_CONTROL_DIALOG_H
#define AMPLIFIER_CONTROL_DIALOG_H
#include "EffectControlDialog.h"
class AmplifierControls;
class AmplifierControlDialog : public EffectControlDialog
{
public:
AmplifierControlDialog( AmplifierControls* controls );
virtual ~AmplifierControlDialog()
{
}
} ;
#endif

View File

@@ -0,0 +1,82 @@
/*
* AmplifierControls.cpp - controls for amplifier effect
*
* Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
* Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 <QtXml/QDomElement>
#include "AmplifierControls.h"
#include "Amplifier.h"
#include "engine.h"
#include "song.h"
AmplifierControls::AmplifierControls( AmplifierEffect* effect ) :
EffectControls( effect ),
m_effect( effect ),
m_volumeModel( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Volume" ) ),
m_panModel( 0.0f, -100.0f, 100.0f, 0.1f, this, tr( "Panning" ) ),
m_leftModel( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Left gain" ) ),
m_rightModel( 100.0f, 0.0f, 200.0f, 0.1f, this, tr( "Right gain" ) )
{
connect( &m_volumeModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_panModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_leftModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
connect( &m_rightModel, SIGNAL( dataChanged() ), this, SLOT( changeControl() ) );
}
void AmplifierControls::changeControl()
{
engine::getSong()->setModified();
}
void AmplifierControls::loadSettings( const QDomElement& _this )
{
m_volumeModel.loadSettings( _this, "volume" );
m_panModel.loadSettings( _this, "pan" );
m_leftModel.loadSettings( _this, "left" );
m_rightModel.loadSettings( _this, "right" );
}
void AmplifierControls::saveSettings( QDomDocument& doc, QDomElement& _this )
{
m_volumeModel.saveSettings( doc, _this, "volume" );
m_panModel.saveSettings( doc, _this, "pan" );
m_leftModel.saveSettings( doc, _this, "left" );
m_rightModel.saveSettings( doc, _this, "right" );
}
#include "moc_AmplifierControls.cxx"

View File

@@ -0,0 +1,79 @@
/*
* AmplifierControls.h - controls for bassboosterx -effect
*
* Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
* Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* 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 AMPLIFIER_CONTROLS_H
#define AMPLIFIER_CONTROLS_H
#include "EffectControls.h"
#include "AmplifierControlDialog.h"
#include "knob.h"
class AmplifierEffect;
class AmplifierControls : public EffectControls
{
Q_OBJECT
public:
AmplifierControls( AmplifierEffect* effect );
virtual ~AmplifierControls()
{
}
virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
virtual void loadSettings( const QDomElement & _this );
inline virtual QString nodeName() const
{
return "AmplifierControls";
}
virtual int controlCount()
{
return 4;
}
virtual EffectControlDialog* createView()
{
return new AmplifierControlDialog( this );
}
private slots:
void changeControl();
private:
AmplifierEffect* m_effect;
FloatModel m_volumeModel;
FloatModel m_panModel;
FloatModel m_leftModel;
FloatModel m_rightModel;
friend class AmplifierControlDialog;
friend class AmplifierEffect;
} ;
#endif

View File

@@ -0,0 +1,3 @@
INCLUDE(BuildPlugin)
BUILD_PLUGIN(amplifier Amplifier.cpp AmplifierControls.cpp AmplifierControlDialog.cpp MOCFILES AmplifierControls.h EMBEDDED_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.png")

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
plugins/Amplifier/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -1,3 +1,4 @@
ADD_SUBDIRECTORY(Amplifier)
ADD_SUBDIRECTORY(audio_file_processor)
ADD_SUBDIRECTORY(BassBooster)
ADD_SUBDIRECTORY(bit_invader)