You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
2.7KB

  1. /* SpiralSound
  2. * Copyleft (C) 2001 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "EchoPlugin.h"
  19. #include "EchoPluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include "SpiralIcon.xpm"
  22. static const float MAX_DELAY=1.0f;
  23. extern "C" {
  24. SpiralPlugin* CreateInstance()
  25. {
  26. return new EchoPlugin;
  27. }
  28. char** GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int GetID()
  33. {
  34. return 0x000e;
  35. }
  36. }
  37. ///////////////////////////////////////////////////////
  38. EchoPlugin::EchoPlugin() :
  39. m_Delay(0.75),
  40. m_Feedback(0.4),
  41. m_HeadPos(0)
  42. {
  43. m_PluginInfo.Name="Echo";
  44. m_PluginInfo.Width=120;
  45. m_PluginInfo.Height=110;
  46. m_PluginInfo.NumInputs=3;
  47. m_PluginInfo.NumOutputs=1;
  48. m_PluginInfo.PortTips.push_back("Input");
  49. m_PluginInfo.PortTips.push_back("Delay CV");
  50. m_PluginInfo.PortTips.push_back("Feedback CV");
  51. m_PluginInfo.PortTips.push_back("Output");
  52. m_AudioCH->Register("Delay",&m_Delay);
  53. m_AudioCH->Register("Feedback",&m_Feedback);
  54. }
  55. EchoPlugin::~EchoPlugin()
  56. {
  57. }
  58. PluginInfo &EchoPlugin::Initialise(const HostInfo *Host)
  59. {
  60. PluginInfo& Info = SpiralPlugin::Initialise(Host);
  61. m_Buffer.Allocate((int)(m_HostInfo->SAMPLERATE*MAX_DELAY));
  62. return Info;
  63. }
  64. SpiralGUIType *EchoPlugin::CreateGUI()
  65. {
  66. return new EchoPluginGUI(m_PluginInfo.Width,
  67. m_PluginInfo.Height,
  68. this,m_AudioCH,m_HostInfo);
  69. }
  70. void EchoPlugin::Execute()
  71. {
  72. float Delay;
  73. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  74. {
  75. Delay=(m_Delay+GetInput(1,n)*0.5)*(float)m_HostInfo->SAMPLERATE-1;
  76. if (Delay>=MAX_DELAY*m_HostInfo->SAMPLERATE)
  77. {
  78. Delay=(MAX_DELAY*m_HostInfo->SAMPLERATE)-1;
  79. }
  80. if (Delay<0) Delay=0;
  81. if (m_HeadPos>Delay)
  82. {
  83. m_HeadPos=0;
  84. }
  85. // Write to the buffer
  86. m_Buffer.Set(m_HeadPos,GetInput(0,n)+(m_Buffer[m_HeadPos]*(m_Feedback+GetInput(2,n))));
  87. // Read from the buffer
  88. SetOutput(0,n,m_Buffer[m_HeadPos]);
  89. m_HeadPos++;
  90. }
  91. }
  92. void EchoPlugin::Randomise()
  93. {
  94. }
  95. void EchoPlugin::StreamOut(ostream &s)
  96. {
  97. s<<m_Version<<" "<<m_Delay<<" "<<m_Feedback<<" ";
  98. }
  99. void EchoPlugin::StreamIn(istream &s)
  100. {
  101. int version;
  102. s>>version;
  103. s>>m_Delay>>m_Feedback;
  104. }