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.

123 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 "NoisePlugin.h"
  19. #include "NoisePluginGUI.h"
  20. #include <FL/Fl_Button.h>
  21. #include <limits.h>
  22. #include "SpiralIcon.xpm"
  23. using namespace std;
  24. extern "C" {
  25. SpiralPlugin* SpiralPlugin_CreateInstance()
  26. {
  27. return new NoisePlugin;
  28. }
  29. char** SpiralPlugin_GetIcon()
  30. {
  31. return SpiralIcon_xpm;
  32. }
  33. int SpiralPlugin_GetID()
  34. {
  35. return 49;
  36. }
  37. string SpiralPlugin_GetGroupName()
  38. {
  39. return "Oscillators";
  40. }
  41. }
  42. ///////////////////////////////////////////////////////
  43. NoisePlugin::NoisePlugin() :
  44. m_Type(WHITE)
  45. {
  46. m_PluginInfo.Name="Noise";
  47. m_PluginInfo.Width=80;
  48. m_PluginInfo.Height=60;
  49. m_PluginInfo.NumInputs=0;
  50. m_PluginInfo.NumOutputs=1;
  51. m_PluginInfo.PortTips.push_back("Output");
  52. b0=b1=b2=b3=b4=b5=b6=0;
  53. m_AudioCH->Register("Type",(char*)&m_Type);
  54. }
  55. NoisePlugin::~NoisePlugin()
  56. {
  57. }
  58. PluginInfo &NoisePlugin::Initialise(const HostInfo *Host)
  59. {
  60. return SpiralPlugin::Initialise(Host);
  61. }
  62. SpiralGUIType *NoisePlugin::CreateGUI()
  63. {
  64. return new NoisePluginGUI(m_PluginInfo.Width,
  65. m_PluginInfo.Height,
  66. this,m_AudioCH,m_HostInfo);
  67. }
  68. void NoisePlugin::Execute()
  69. {
  70. float White,Pink;
  71. if (m_Type==PINK)
  72. {
  73. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  74. {
  75. White=(1.0f-((rand()%INT_MAX)/(float)INT_MAX)*2.0)*0.2f;
  76. b0 = 0.99886f * b0 + White * 0.0555179f;
  77. b1 = 0.99332f * b1 + White * 0.0750759f;
  78. b2 = 0.96900f * b2 + White * 0.1538520f;
  79. b3 = 0.86650f * b3 + White * 0.3104856f;
  80. b4 = 0.55000f * b4 + White * 0.5329522f;
  81. b5 = -0.7616f * b5 - White * 0.0168980f;
  82. Pink = b0 + b1 + b2 + b3 + b4 + b5 + b6 + White * 0.5362f;
  83. b6 = White * 0.115926f;
  84. SetOutput(0,n,Pink);
  85. }
  86. }
  87. else
  88. {
  89. for (int n=0; n<m_HostInfo->BUFSIZE; n++)
  90. {
  91. SetOutput(0,n,1.0f-((rand()%INT_MAX)/(float)INT_MAX)*2.0);
  92. }
  93. }
  94. }
  95. void NoisePlugin::StreamOut(ostream &s)
  96. {
  97. s<<m_Version<<" "<<(char)m_Type;
  98. }
  99. void NoisePlugin::StreamIn(istream &s)
  100. {
  101. int version;
  102. char t;
  103. s>>version>>t;
  104. m_Type=(Type)t;
  105. }