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.

147 lines
3.2KB

  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. static const HostInfo* host;
  34. #define CHECK_AND_REPORT_ERROR if (result<0) \
  35. { \
  36. perror("Sound device did not accept settings"); \
  37. m_OutputOk=false; \
  38. return false; \
  39. }
  40. extern "C"
  41. {
  42. SpiralPlugin* CreateInstance()
  43. {
  44. return new DiskWriterPlugin;
  45. }
  46. char** GetIcon()
  47. {
  48. return SpiralIcon_xpm;
  49. }
  50. int GetID()
  51. {
  52. return 41;
  53. }
  54. }
  55. ///////////////////////////////////////////////////////
  56. DiskWriterPlugin::DiskWriterPlugin() :
  57. m_Recording(false)
  58. {
  59. m_PluginInfo.Name="DiskWriter";
  60. m_PluginInfo.Width=100;
  61. m_PluginInfo.Height=60;
  62. m_PluginInfo.NumInputs=3;
  63. m_PluginInfo.NumOutputs=0;
  64. m_PluginInfo.PortTips.push_back("Left Out");
  65. m_PluginInfo.PortTips.push_back("Right Out");
  66. m_PluginInfo.PortTips.push_back("Record Controller");
  67. m_AudioCH->RegisterData("Filename",ChannelHandler::INPUT,m_GUIArgs.Name,256);
  68. }
  69. DiskWriterPlugin::~DiskWriterPlugin()
  70. {
  71. }
  72. PluginInfo &DiskWriterPlugin::Initialise(const HostInfo *Host)
  73. {
  74. PluginInfo& Info= SpiralPlugin::Initialise(Host);
  75. host=Host;
  76. return Info;
  77. }
  78. SpiralGUIType *DiskWriterPlugin::CreateGUI()
  79. {
  80. return new DiskWriterPluginGUI(m_PluginInfo.Width,
  81. m_PluginInfo.Height,
  82. this,
  83. m_AudioCH,
  84. m_HostInfo);
  85. }
  86. void DiskWriterPlugin::Execute()
  87. {
  88. if(m_Recording && m_Wav.IsOpen())
  89. {
  90. int on=0;
  91. float t;
  92. short Buffer[host->BUFSIZE*2];
  93. for (int n=0; n<host->BUFSIZE; n++)
  94. {
  95. // stereo channels - interleave
  96. t=GetInput(0,n);
  97. if (t>1) t=1;
  98. if (t<-1) t=-1;
  99. Buffer[on]=lrintf(t*SHRT_MAX);
  100. on++;
  101. t=GetInput(1,n);
  102. if (t>1) t=1;
  103. if (t<-1) t=-1;
  104. Buffer[on]=lrintf(t*SHRT_MAX);
  105. on++;
  106. }
  107. // stereo 16bit * bufsize
  108. m_Wav.Save(Buffer,host->BUFSIZE*2*2);
  109. }
  110. }
  111. void DiskWriterPlugin::ExecuteCommands()
  112. {
  113. if (m_AudioCH->IsCommandWaiting())
  114. {
  115. switch(m_AudioCH->GetCommand())
  116. {
  117. case OPENWAV :
  118. m_Wav.Open(m_GUIArgs.Name,WavFile::WRITE, WavFile::STEREO);
  119. break;
  120. case CLOSEWAV : m_Wav.Close(); break;
  121. case RECORD : m_Recording=true; break;
  122. case STOP : m_Recording=false; break;
  123. default : break;
  124. }
  125. }
  126. }