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.

157 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. // 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=100;
  66. m_PluginInfo.Height=66;
  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_AudioCH->RegisterData("Filename",ChannelHandler::INPUT,m_GUIArgs.Name,256);
  73. }
  74. DiskWriterPlugin::~DiskWriterPlugin()
  75. {
  76. }
  77. PluginInfo &DiskWriterPlugin::Initialise(const HostInfo *Host)
  78. {
  79. PluginInfo& Info= SpiralPlugin::Initialise(Host);
  80. host=Host;
  81. return Info;
  82. }
  83. SpiralGUIType *DiskWriterPlugin::CreateGUI()
  84. {
  85. return new DiskWriterPluginGUI(m_PluginInfo.Width,
  86. m_PluginInfo.Height,
  87. this,
  88. m_AudioCH,
  89. m_HostInfo);
  90. }
  91. void DiskWriterPlugin::Execute()
  92. {
  93. if(m_Recording && m_Wav.IsOpen())
  94. {
  95. int on=0;
  96. float t;
  97. short Buffer[host->BUFSIZE*2];
  98. for (int n=0; n<host->BUFSIZE; n++)
  99. {
  100. // stereo channels - interleave
  101. t=GetInput(0,n);
  102. if (t>1) t=1;
  103. if (t<-1) t=-1;
  104. Buffer[on]=lrintf(t*SHRT_MAX);
  105. on++;
  106. t=GetInput(1,n);
  107. if (t>1) t=1;
  108. if (t<-1) t=-1;
  109. Buffer[on]=lrintf(t*SHRT_MAX);
  110. on++;
  111. }
  112. // stereo 16bit * bufsize
  113. m_Wav.Save(Buffer,host->BUFSIZE*2*2);
  114. }
  115. }
  116. void DiskWriterPlugin::ExecuteCommands()
  117. {
  118. if (m_AudioCH->IsCommandWaiting())
  119. {
  120. switch(m_AudioCH->GetCommand())
  121. {
  122. case OPENWAV :
  123. if (m_Wav.GetSamplerate() != GetHostInfo()->SAMPLERATE) {
  124. m_Wav.SetSamplerate(GetHostInfo()->SAMPLERATE);
  125. }
  126. m_Wav.Open(m_GUIArgs.Name,WavFile::WRITE, WavFile::STEREO);
  127. break;
  128. case CLOSEWAV : m_Wav.Close(); break;
  129. case RECORD : m_Recording=true; break;
  130. case STOP : m_Recording=false; break;
  131. default : break;
  132. }
  133. }
  134. }