BassBooster.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #include "BassBooster.h"
  25. #include "embed.cpp"
  26. extern "C"
  27. {
  28. Plugin::Descriptor PLUGIN_EXPORT bassbooster_plugin_descriptor =
  29. {
  30. STRINGIFY( PLUGIN_NAME ),
  31. "BassBooster",
  32. QT_TRANSLATE_NOOP( "pluginBrowser", "Boost your bass the fast and simple way" ),
  33. "Tobias Doerffel <tobydox/at/users.sf.net>",
  34. 0x0100,
  35. Plugin::Effect,
  36. new PluginPixmapLoader( "logo" ),
  37. NULL,
  38. NULL
  39. } ;
  40. }
  41. BassBoosterEffect::BassBoosterEffect( Model* parent, const Descriptor::SubPluginFeatures::Key* key ) :
  42. Effect( &bassbooster_plugin_descriptor, parent, key ),
  43. m_frequencyChangeNeeded( false ),
  44. m_bbFX( DspEffectLibrary::FastBassBoost( 70.0f, 1.0f, 2.8f ) ),
  45. m_bbControls( this )
  46. {
  47. changeFrequency();
  48. changeGain();
  49. changeRatio();
  50. }
  51. BassBoosterEffect::~BassBoosterEffect()
  52. {
  53. }
  54. bool BassBoosterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
  55. {
  56. if( !isEnabled() || !isRunning () )
  57. {
  58. return( false );
  59. }
  60. // check out changed controls
  61. if( m_frequencyChangeNeeded || m_bbControls.m_freqModel.isValueChanged() )
  62. {
  63. changeFrequency();
  64. m_frequencyChangeNeeded = false;
  65. }
  66. if( m_bbControls.m_gainModel.isValueChanged() ) { changeGain(); }
  67. if( m_bbControls.m_ratioModel.isValueChanged() ) { changeRatio(); }
  68. const float const_gain = m_bbControls.m_gainModel.value();
  69. const ValueBuffer *gainBuffer = m_bbControls.m_gainModel.valueBuffer();
  70. double outSum = 0.0;
  71. const float d = dryLevel();
  72. const float w = wetLevel();
  73. for( fpp_t f = 0; f < frames; ++f )
  74. {
  75. float gain = const_gain;
  76. if (gainBuffer) {
  77. //process period using sample exact data
  78. gain = gainBuffer->value( f );
  79. }
  80. //float gain = gainBuffer ? gainBuffer[f] : gain;
  81. m_bbFX.leftFX().setGain( gain );
  82. m_bbFX.rightFX().setGain( gain);
  83. outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];
  84. sample_t s[2] = { buf[f][0], buf[f][1] };
  85. m_bbFX.nextSample( s[0], s[1] );
  86. buf[f][0] = d * buf[f][0] + w * s[0];
  87. buf[f][1] = d * buf[f][1] + w * s[1];
  88. }
  89. checkGate( outSum / frames );
  90. return isRunning();
  91. }
  92. inline void BassBoosterEffect::changeFrequency()
  93. {
  94. const sample_t fac = Engine::mixer()->processingSampleRate() / 44100.0f;
  95. m_bbFX.leftFX().setFrequency( m_bbControls.m_freqModel.value() * fac );
  96. m_bbFX.rightFX().setFrequency( m_bbControls.m_freqModel.value() * fac );
  97. }
  98. inline void BassBoosterEffect::changeGain()
  99. {
  100. m_bbFX.leftFX().setGain( m_bbControls.m_gainModel.value() );
  101. m_bbFX.rightFX().setGain( m_bbControls.m_gainModel.value() );
  102. }
  103. inline void BassBoosterEffect::changeRatio()
  104. {
  105. m_bbFX.leftFX().setRatio( m_bbControls.m_ratioModel.value() );
  106. m_bbFX.rightFX().setRatio( m_bbControls.m_ratioModel.value() );
  107. }
  108. extern "C"
  109. {
  110. // necessary for getting instance out of shared lib
  111. Plugin * PLUGIN_EXPORT lmms_plugin_main( Model* parent, void* data )
  112. {
  113. return new BassBoosterEffect( parent, static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>( data ) );
  114. }
  115. }