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.

142 lines
3.3KB

  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 "DelayPlugin.h"
  19. #include "DelayPluginGUI.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 DelayPlugin;
  27. }
  28. char** GetIcon()
  29. {
  30. return SpiralIcon_xpm;
  31. }
  32. int GetID()
  33. {
  34. return 0x000f;
  35. }
  36. }
  37. ///////////////////////////////////////////////////////
  38. DelayPlugin::DelayPlugin() :
  39. m_Delay(0.75),
  40. m_Mix(0.4),
  41. m_ReadHeadPos(0),
  42. m_WriteHeadPos(0)
  43. {
  44. m_PluginInfo.Name="Delay";
  45. m_PluginInfo.Width=120;
  46. m_PluginInfo.Height=110;
  47. m_PluginInfo.NumInputs=3;
  48. m_PluginInfo.NumOutputs=1;
  49. m_PluginInfo.PortTips.push_back("Input");
  50. m_PluginInfo.PortTips.push_back("Delay CV");
  51. m_PluginInfo.PortTips.push_back("ReadHead CV");
  52. m_PluginInfo.PortTips.push_back("Output");
  53. }
  54. DelayPlugin::~DelayPlugin()
  55. {
  56. }
  57. PluginInfo &DelayPlugin::Initialise(const HostInfo *Host)
  58. {
  59. PluginInfo& Info = SpiralPlugin::Initialise(Host);
  60. m_Buffer.Allocate((int)(m_HostInfo->SAMPLERATE*MAX_DELAY));
  61. return Info;
  62. }
  63. SpiralGUIType *DelayPlugin::CreateGUI()
  64. {
  65. m_GUI = new DelayPluginGUI(m_PluginInfo.Width,
  66. m_PluginInfo.Height,
  67. this,m_HostInfo);
  68. m_GUI->hide();
  69. return m_GUI;
  70. }
  71. void DelayPlugin::Execute()
  72. {
  73. int Delay;
  74. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  75. {
  76. Delay=(int)((m_Delay+GetInput(1,n)*0.5f)*(float)m_HostInfo->SAMPLERATE);
  77. if (Delay>=MAX_DELAY*m_HostInfo->SAMPLERATE)
  78. {
  79. Delay=(int)(MAX_DELAY*m_HostInfo->SAMPLERATE)-1;
  80. }
  81. if (Delay<0) Delay=0;
  82. if (m_ReadHeadPos<0 || m_ReadHeadPos>=MAX_DELAY*m_HostInfo->SAMPLERATE)
  83. cerr<<"read agh! "<<m_ReadHeadPos<<endl;
  84. if (m_WriteHeadPos<0 || m_WriteHeadPos>=MAX_DELAY*m_HostInfo->SAMPLERATE)
  85. cerr<<"write agh! "<<m_WriteHeadPos<<endl;
  86. // Read from the buffer
  87. SetOutput(0,n,m_Buffer[m_ReadHeadPos]+m_Mix*GetInput(0,n));
  88. // Write to the buffer
  89. m_Buffer.Set((int)m_WriteHeadPos,GetInput(0,n));
  90. m_WriteHeadPos++;
  91. m_ReadHeadPos=m_WriteHeadPos+GetInput(2,n)*Delay;
  92. if (m_ReadHeadPos<0) m_ReadHeadPos=Delay+m_ReadHeadPos;
  93. if (m_WriteHeadPos<0) m_WriteHeadPos=Delay+m_WriteHeadPos;
  94. if (Delay>0)
  95. {
  96. if (m_ReadHeadPos>=Delay) m_ReadHeadPos=m_ReadHeadPos-Delay;
  97. if (m_WriteHeadPos>=Delay) m_WriteHeadPos=m_WriteHeadPos-Delay;
  98. }
  99. else
  100. {
  101. m_ReadHeadPos=0;
  102. m_WriteHeadPos=0;
  103. }
  104. }
  105. }
  106. void DelayPlugin::Randomise()
  107. {
  108. }
  109. void DelayPlugin::StreamOut(ostream &s)
  110. {
  111. s<<m_Version<<" "<<m_Delay<<" "<<m_Mix<<" ";
  112. }
  113. void DelayPlugin::StreamIn(istream &s)
  114. {
  115. int version;
  116. s>>version;
  117. s>>m_Delay>>m_Mix;
  118. }