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.

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