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.

132 lines
3.5KB

  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* SpiralPlugin_CreateInstance()
  25. {
  26. return new EchoPlugin;
  27. }
  28. char** SpiralPlugin_GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int SpiralPlugin_GetID()
  33. {
  34. return 0x000e;
  35. }
  36. string SpiralPlugin_GetGroupName()
  37. {
  38. return "Delay/Sampling";
  39. }
  40. }
  41. ///////////////////////////////////////////////////////
  42. EchoPlugin::EchoPlugin() :
  43. m_Delay (0.75),
  44. m_Feedback (0.4),
  45. m_Bounce (false),
  46. m_HeadPos (0),
  47. m_Buf0 (0),
  48. m_Buf1 (1)
  49. {
  50. m_Version = 2;
  51. m_PluginInfo.Name = "Echo";
  52. m_PluginInfo.Width = 120;
  53. m_PluginInfo.Height = 132;
  54. m_PluginInfo.NumInputs = 3;
  55. m_PluginInfo.NumOutputs = 2;
  56. m_PluginInfo.PortTips.push_back ("Input");
  57. m_PluginInfo.PortTips.push_back ("Delay CV");
  58. m_PluginInfo.PortTips.push_back ("Feedback CV");
  59. m_PluginInfo.PortTips.push_back ("Left/Mono Out");
  60. m_PluginInfo.PortTips.push_back ("Right Out");
  61. m_AudioCH->Register ("Delay", &m_Delay);
  62. m_AudioCH->Register ("Feedback", &m_Feedback);
  63. m_AudioCH->Register ("Bounce", &m_Bounce);
  64. }
  65. EchoPlugin::~EchoPlugin()
  66. {
  67. }
  68. PluginInfo &EchoPlugin::Initialise (const HostInfo *Host)
  69. {
  70. PluginInfo& Info = SpiralPlugin::Initialise (Host);
  71. m_Buffer[0].Allocate ((int)(m_HostInfo->SAMPLERATE * MAX_DELAY));
  72. m_Buffer[1].Allocate ((int)(m_HostInfo->SAMPLERATE * MAX_DELAY));
  73. return Info;
  74. }
  75. SpiralGUIType *EchoPlugin::CreateGUI()
  76. {
  77. return new EchoPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
  78. }
  79. void EchoPlugin::Execute()
  80. {
  81. float Delay;
  82. for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
  83. Delay=( m_Delay+GetInput (1,n)*0.5 ) * (float)m_HostInfo->SAMPLERATE-1;
  84. if (Delay >= MAX_DELAY*m_HostInfo->SAMPLERATE)
  85. Delay = (MAX_DELAY*m_HostInfo->SAMPLERATE)-1;
  86. if (Delay<0) Delay=0;
  87. if (m_HeadPos>Delay) m_HeadPos=0;
  88. if (m_Bounce && m_HeadPos==0) {
  89. int c=m_Buf0;
  90. m_Buf0=m_Buf1;
  91. m_Buf1=c;
  92. }
  93. // Write to the buffer
  94. m_Buffer[m_Buf0].Set (m_HeadPos, GetInput (0,n)+(m_Buffer[m_Buf0][m_HeadPos]*(m_Feedback+GetInput (2,n))));
  95. if (!m_Bounce) m_Buffer[m_Buf1].Set (m_HeadPos, 0);
  96. // Read from the buffer
  97. SetOutput(0, n, m_Buffer[m_Buf0][m_HeadPos]);
  98. SetOutput(1, n, m_Buffer[m_Buf1][m_HeadPos]);
  99. m_HeadPos++;
  100. }
  101. }
  102. //void EchoPlugin::Randomise()
  103. //{
  104. //}
  105. void EchoPlugin::StreamOut(ostream &s)
  106. {
  107. s << m_Version << " " << m_Delay << " " << m_Feedback << " " << m_Bounce << " ";
  108. }
  109. void EchoPlugin::StreamIn(istream &s)
  110. {
  111. int version;
  112. s >> version;
  113. s >> m_Delay >> m_Feedback;
  114. if (version>1) s >> m_Bounce; else m_Bounce = false;
  115. }