stereo_matrix.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * stereo_matrix.cpp - stereo-matrix-effect-plugin
  3. *
  4. * Copyright (c) 2008 Paul Giblock <drfaygo/at/gmail/dot/com>
  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 "stereo_matrix.h"
  25. #include "embed.h"
  26. #include "plugin_export.h"
  27. extern "C"
  28. {
  29. Plugin::Descriptor PLUGIN_EXPORT stereomatrix_plugin_descriptor =
  30. {
  31. STRINGIFY( PLUGIN_NAME ),
  32. "Stereo Matrix",
  33. QT_TRANSLATE_NOOP( "PluginBrowser",
  34. "Plugin for freely manipulating stereo output" ),
  35. "Paul Giblock <drfaygo/at/gmail.com>",
  36. 0x0100,
  37. Plugin::Effect,
  38. new PluginPixmapLoader("logo"),
  39. NULL,
  40. NULL
  41. } ;
  42. }
  43. stereoMatrixEffect::stereoMatrixEffect(
  44. Model * _parent,
  45. const Descriptor::SubPluginFeatures::Key * _key ) :
  46. Effect( &stereomatrix_plugin_descriptor, _parent, _key ),
  47. m_smControls( this )
  48. {
  49. }
  50. stereoMatrixEffect::~stereoMatrixEffect()
  51. {
  52. }
  53. bool stereoMatrixEffect::processAudioBuffer( sampleFrame * _buf,
  54. const fpp_t _frames )
  55. {
  56. // This appears to be used for determining whether or not to continue processing
  57. // audio with this effect
  58. if( !isEnabled() || !isRunning() )
  59. {
  60. return( false );
  61. }
  62. double out_sum = 0.0;
  63. for( fpp_t f = 0; f < _frames; ++f )
  64. {
  65. const float d = dryLevel();
  66. const float w = wetLevel();
  67. sample_t l = _buf[f][0];
  68. sample_t r = _buf[f][1];
  69. // Init with dry-mix
  70. _buf[f][0] = l * d;
  71. _buf[f][1] = r * d;
  72. // Add it wet
  73. _buf[f][0] += ( m_smControls.m_llModel.value( f ) * l +
  74. m_smControls.m_rlModel.value( f ) * r ) * w;
  75. _buf[f][1] += ( m_smControls.m_lrModel.value( f ) * l +
  76. m_smControls.m_rrModel.value( f ) * r ) * w;
  77. out_sum += _buf[f][0]*_buf[f][0] + _buf[f][1]*_buf[f][1];
  78. }
  79. checkGate( out_sum / _frames );
  80. return( isRunning() );
  81. }
  82. extern "C"
  83. {
  84. // necessary for getting instance out of shared lib
  85. PLUGIN_EXPORT Plugin * lmms_plugin_main( Model * _parent, void * _data )
  86. {
  87. return( new stereoMatrixEffect( _parent,
  88. static_cast<const Plugin::Descriptor::SubPluginFeatures::Key *>(
  89. _data ) ) );
  90. }
  91. }