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.

151 lines
3.6KB

  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. // for lrintf()
  19. #define _ISOC9X_SOURCE 1
  20. #define _ISOC99_SOURCE 1
  21. #include <math.h>
  22. #include <sys/types.h>
  23. #include <stdio.h>
  24. #include <fcntl.h>
  25. #include <unistd.h>
  26. #include <limits.h>
  27. #include <sys/ioctl.h>
  28. #include <limits.h>
  29. #include "DiskWriterPlugin.h"
  30. #include "DiskWriterPluginGUI.h"
  31. #include <FL/fl_file_chooser.H>
  32. #include "SpiralIcon.xpm"
  33. using namespace std;
  34. static const HostInfo* host;
  35. #define CHECK_AND_REPORT_ERROR if (result<0) \
  36. { \
  37. perror("Sound device did not accept settings"); \
  38. m_OutputOk=false; \
  39. return false; \
  40. }
  41. extern "C"
  42. {
  43. SpiralPlugin* SpiralPlugin_CreateInstance()
  44. {
  45. return new DiskWriterPlugin;
  46. }
  47. char** SpiralPlugin_GetIcon()
  48. {
  49. return SpiralIcon_xpm;
  50. }
  51. int SpiralPlugin_GetID()
  52. {
  53. return 41;
  54. }
  55. string SpiralPlugin_GetGroupName()
  56. {
  57. return "InputOutput";
  58. }
  59. }
  60. ///////////////////////////////////////////////////////
  61. DiskWriterPlugin::DiskWriterPlugin() :
  62. m_Recording(false)
  63. {
  64. m_PluginInfo.Name="DiskWriter";
  65. m_PluginInfo.Width=140;
  66. m_PluginInfo.Height=90;
  67. m_PluginInfo.NumInputs=3;
  68. m_PluginInfo.NumOutputs=0;
  69. m_PluginInfo.PortTips.push_back("Left Out");
  70. m_PluginInfo.PortTips.push_back("Right Out");
  71. m_PluginInfo.PortTips.push_back("Record Controller");
  72. m_GUIArgs.BitsPerSample = 16;
  73. m_AudioCH->RegisterData("Filename",ChannelHandler::INPUT,m_GUIArgs.Name,256);
  74. m_AudioCH->Register("BitsPerSample",&m_GUIArgs.BitsPerSample,ChannelHandler::INPUT);
  75. }
  76. DiskWriterPlugin::~DiskWriterPlugin()
  77. {
  78. }
  79. PluginInfo &DiskWriterPlugin::Initialise(const HostInfo *Host)
  80. {
  81. PluginInfo& Info= SpiralPlugin::Initialise(Host);
  82. host=Host;
  83. return Info;
  84. }
  85. SpiralGUIType *DiskWriterPlugin::CreateGUI()
  86. {
  87. return new DiskWriterPluginGUI(m_PluginInfo.Width,
  88. m_PluginInfo.Height,
  89. this,
  90. m_AudioCH,
  91. m_HostInfo);
  92. }
  93. void DiskWriterPlugin::Execute()
  94. {
  95. if(m_Recording && m_Wav.IsOpen())
  96. {
  97. int on=0;
  98. float LeftBuffer[host->BUFSIZE], RightBuffer[host->BUFSIZE];
  99. for (int n=0; n<host->BUFSIZE; n++)
  100. {
  101. // stereo channels - interleave
  102. LeftBuffer[n]=GetInput(0,n);
  103. RightBuffer[n]=GetInput(1,n);
  104. }
  105. m_Wav.Save(LeftBuffer, RightBuffer, host->BUFSIZE);
  106. }
  107. }
  108. void DiskWriterPlugin::ExecuteCommands()
  109. {
  110. if (m_AudioCH->IsCommandWaiting())
  111. {
  112. switch(m_AudioCH->GetCommand())
  113. {
  114. case OPENWAV :
  115. if (m_Wav.GetSamplerate() != GetHostInfo()->SAMPLERATE) {
  116. m_Wav.SetSamplerate(GetHostInfo()->SAMPLERATE);
  117. }
  118. if (m_Wav.GetBitsPerSample() != m_GUIArgs.BitsPerSample) {
  119. m_Wav.SetBitsPerSample(m_GUIArgs.BitsPerSample);
  120. }
  121. m_Wav.Open(m_GUIArgs.Name,WavFile::WRITE, WavFile::STEREO);
  122. break;
  123. case CLOSEWAV : m_Wav.Close(); break;
  124. case RECORD : m_Recording=true; break;
  125. case STOP : m_Recording=false; break;
  126. default : break;
  127. }
  128. }
  129. }