1 /*
2 * BassBooster.cpp - bass booster effect plugin
3 *
4 * Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
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.
12 *
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.
17 *
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.
22 *
23 */
24
25 #include "BassBooster.h"
26
27 #include "embed.cpp"
28
29
30 extern "C"
31 {
32
33 Plugin::Descriptor PLUGIN_EXPORT bassbooster_plugin_descriptor =
34 {
35 STRINGIFY( PLUGIN_NAME ),
36 "BassBooster",
37 QT_TRANSLATE_NOOP( "pluginBrowser", "Boost your bass the fast and simple way" ),
38 "Tobias Doerffel <tobydox/at/users.sf.net>",
39 0x0100,
40 Plugin::Effect,
41 new PluginPixmapLoader( "logo" ),
42 NULL,
43 NULL
44 } ;
45
46 }
47
48
49
BassBoosterEffect(Model * parent,const Descriptor::SubPluginFeatures::Key * key)50 BassBoosterEffect::BassBoosterEffect( Model* parent, const Descriptor::SubPluginFeatures::Key* key ) :
51 Effect( &bassbooster_plugin_descriptor, parent, key ),
52 m_frequencyChangeNeeded( false ),
53 m_bbFX( DspEffectLibrary::FastBassBoost( 70.0f, 1.0f, 2.8f ) ),
54 m_bbControls( this )
55 {
56 changeFrequency();
57 changeGain();
58 changeRatio();
59 }
60
61
62
63
~BassBoosterEffect()64 BassBoosterEffect::~BassBoosterEffect()
65 {
66 }
67
68
69
70
processAudioBuffer(sampleFrame * buf,const fpp_t frames)71 bool BassBoosterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
72 {
73 if( !isEnabled() || !isRunning () )
74 {
75 return( false );
76 }
77 // check out changed controls
78 if( m_frequencyChangeNeeded || m_bbControls.m_freqModel.isValueChanged() )
79 {
80 changeFrequency();
81 m_frequencyChangeNeeded = false;
82 }
83 if( m_bbControls.m_gainModel.isValueChanged() ) { changeGain(); }
84 if( m_bbControls.m_ratioModel.isValueChanged() ) { changeRatio(); }
85
86 const float const_gain = m_bbControls.m_gainModel.value();
87 const ValueBuffer *gainBuffer = m_bbControls.m_gainModel.valueBuffer();
88
89 double outSum = 0.0;
90 const float d = dryLevel();
91 const float w = wetLevel();
92
93 for( fpp_t f = 0; f < frames; ++f )
94 {
95 float gain = const_gain;
96 if (gainBuffer) {
97 //process period using sample exact data
98 gain = gainBuffer->value( f );
99 }
100 //float gain = gainBuffer ? gainBuffer[f] : gain;
101 m_bbFX.leftFX().setGain( gain );
102 m_bbFX.rightFX().setGain( gain);
103
104 sample_t s[2] = { buf[f][0], buf[f][1] };
105 m_bbFX.nextSample( s[0], s[1] );
106
107 buf[f][0] = d * buf[f][0] + w * s[0];
108 buf[f][1] = d * buf[f][1] + w * s[1];
109 outSum += buf[f][0] * buf[f][0] + buf[f][1] * buf[f][1];
110 }
111
112 checkGate( outSum / frames );
113
114 return isRunning();
115 }
116
117
changeFrequency()118 inline void BassBoosterEffect::changeFrequency()
119 {
120 const sample_t fac = Engine::mixer()->processingSampleRate() / 44100.0f;
121
122 m_bbFX.leftFX().setFrequency( m_bbControls.m_freqModel.value() * fac );
123 m_bbFX.rightFX().setFrequency( m_bbControls.m_freqModel.value() * fac );
124 }
125
126
127
128
changeGain()129 inline void BassBoosterEffect::changeGain()
130 {
131 m_bbFX.leftFX().setGain( m_bbControls.m_gainModel.value() );
132 m_bbFX.rightFX().setGain( m_bbControls.m_gainModel.value() );
133 }
134
135
136
137
changeRatio()138 inline void BassBoosterEffect::changeRatio()
139 {
140 m_bbFX.leftFX().setRatio( m_bbControls.m_ratioModel.value() );
141 m_bbFX.rightFX().setRatio( m_bbControls.m_ratioModel.value() );
142 }
143
144
145
146
147 extern "C"
148 {
149
150 // necessary for getting instance out of shared lib
lmms_plugin_main(Model * parent,void * data)151 Plugin * PLUGIN_EXPORT lmms_plugin_main( Model* parent, void* data )
152 {
153 return new BassBoosterEffect( parent, static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>( data ) );
154 }
155
156 }
157
158