Made 0.4.12 release
[lmms/mlankhorst.git] / plugins / stereo_enhancer / stereo_enhancer.cpp
blobb9c75b3fe97dc4819488970192f7fdfdd561d6da
1 /*
2 * stereo_enhancer.cpp - stereo-enhancer-effect-plugin
4 * Copyright (c) 2006-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
26 #include "stereo_enhancer.h"
28 #include "embed.cpp"
31 extern "C"
34 Plugin::Descriptor PLUGIN_EXPORT stereoenhancer_plugin_descriptor =
36 STRINGIFY( PLUGIN_NAME ),
37 "StereoEnhancer Effect",
38 QT_TRANSLATE_NOOP( "pluginBrowser",
39 "Plugin for enhancing stereo separation of a stereo input file" ),
40 "Lou Herard <lherard/at/gmail.com>",
41 0x0100,
42 Plugin::Effect,
43 new PluginPixmapLoader( "logo" ),
44 NULL,
45 NULL
46 } ;
52 stereoEnhancerEffect::stereoEnhancerEffect(
53 Model * _parent,
54 const Descriptor::SubPluginFeatures::Key * _key ) :
55 Effect( &stereoenhancer_plugin_descriptor, _parent, _key ),
56 m_seFX( effectLib::stereoEnhancer( 0.0f ) ),
57 m_delayBuffer( new sampleFrame[DEFAULT_BUFFER_SIZE] ),
58 m_currFrame( 0 ),
59 m_bbControls( this )
61 // TODO: Make m_delayBuffer customizable?
62 clearMyBuffer();
68 stereoEnhancerEffect::~stereoEnhancerEffect()
70 if( m_delayBuffer )
72 //delete [] m_delayBuffer;
73 delete m_delayBuffer;
76 m_currFrame = 0;
82 bool stereoEnhancerEffect::processAudioBuffer( sampleFrame * _buf,
83 const fpp_t _frames )
86 // This appears to be used for determining whether or not to continue processing
87 // audio with this effect
88 double out_sum = 0.0;
90 float width;
91 int frameIndex = 0;
94 if( !isEnabled() || !isRunning() )
96 return( false );
99 const float d = dryLevel();
100 const float w = wetLevel();
102 for( fpp_t f = 0; f < _frames; ++f )
105 // copy samples into the delay buffer
106 m_delayBuffer[m_currFrame][0] = _buf[f][0];
107 m_delayBuffer[m_currFrame][1] = _buf[f][1];
109 // Get the width knob value from the Stereo Enhancer effect
110 width = m_seFX.getWideCoeff();
112 // Calculate the correct sample frame for processing
113 frameIndex = m_currFrame - width;
115 if( frameIndex < 0 )
117 // e.g. difference = -10, frameIndex = DBS - 10
118 frameIndex += DEFAULT_BUFFER_SIZE;
121 //sample_t s[2] = { _buf[f][0], _buf[f][1] }; //Vanilla
122 sample_t s[2] = { _buf[f][0], m_delayBuffer[frameIndex][1] }; //Chocolate
124 m_seFX.nextSample( s[0], s[1] );
126 _buf[f][0] = d * _buf[f][0] + w * s[0];
127 _buf[f][1] = d * _buf[f][1] + w * s[1];
128 out_sum += _buf[f][0]*_buf[f][0] + _buf[f][1]*_buf[f][1];
130 // Update currFrame
131 m_currFrame += 1;
132 m_currFrame %= DEFAULT_BUFFER_SIZE;
135 checkGate( out_sum / _frames );
136 if( !isRunning() )
138 clearMyBuffer();
141 return( isRunning() );
147 void stereoEnhancerEffect::clearMyBuffer()
149 int i;
150 for (i = 0; i < DEFAULT_BUFFER_SIZE; i++)
152 m_delayBuffer[i][0] = 0.0f;
153 m_delayBuffer[i][1] = 0.0f;
156 m_currFrame = 0;
163 extern "C"
166 // necessary for getting instance out of shared lib
167 Plugin * PLUGIN_EXPORT lmms_plugin_main( Model * _parent, void * _data )
169 return( new stereoEnhancerEffect( _parent,
170 static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>(
171 _data ) ) );