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.

103 lines
2.8KB

  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 "../SpiralPlugin.h"
  19. #include "../../RiffWav.h"
  20. #include <FL/Fl_Pixmap.H>
  21. #ifndef OutputPLUGIN
  22. #define OutputPLUGIN
  23. class OSSOutput
  24. {
  25. public:
  26. static OSSOutput *Get() { if(!m_Singleton) m_Singleton=new OSSOutput; return m_Singleton; }
  27. static void PackUpAndGoHome() { if(m_Singleton) { delete m_Singleton; m_Singleton=NULL; } }
  28. ~OSSOutput();
  29. void AllocateBuffer();
  30. void DeallocateBuffer();
  31. void SendStereo(const Sample *ldata,const Sample *rdata);
  32. void GetStereo(Sample *ldata,Sample *rdata);
  33. void SetVolume(float s) {m_Amp=s;}
  34. void SetNumChannels(int s) {m_Channels=s;}
  35. float GetVolume() {return m_Amp;}
  36. void Play();
  37. void Read();
  38. void WavOpen(char* name) {m_Wav.Open(name,WavFile::WRITE, WavFile::STEREO);}
  39. void WavClose() {m_Wav.Close();}
  40. short *GetBuffer() {return m_Buffer[m_WriteBufferNum];}
  41. bool OpenReadWrite();
  42. bool OpenWrite();
  43. bool OpenRead();
  44. bool Close();
  45. void Kill() { m_IsDead = true; m_OutputOk=false; PackUpAndGoHome(); }
  46. private:
  47. static OSSOutput* m_Singleton;
  48. OSSOutput();
  49. short *m_Buffer[2];
  50. short *m_InBuffer[2];
  51. int m_BufSizeBytes;
  52. int m_Dspfd;
  53. float m_Amp;
  54. int m_Channels;
  55. WavFile m_Wav;
  56. int m_ReadBufferNum;
  57. int m_WriteBufferNum;
  58. bool m_OutputOk;
  59. bool m_IsDead;
  60. };
  61. class OutputPlugin : public SpiralPlugin
  62. {
  63. public:
  64. enum Mode {NO_MODE,INPUT,OUTPUT,DUPLEX,CLOSED};
  65. OutputPlugin();
  66. virtual ~OutputPlugin();
  67. virtual PluginInfo& Initialise(const HostInfo *Host);
  68. virtual SpiralGUIType* CreateGUI();
  69. virtual void Execute();
  70. virtual bool Kill();
  71. virtual void Reset();
  72. virtual void ExecuteCommands();
  73. virtual void StreamOut(std::ostream &s) {}
  74. virtual void StreamIn(std::istream &s) {}
  75. enum GUICommands {NONE, OPENREAD, OPENWRITE, OPENDUPLEX, CLOSE, SET_VOLUME, CLEAR_NOTIFY};
  76. float m_Volume;
  77. Mode GetMode() { return m_Mode; }
  78. private:
  79. static int m_RefCount;
  80. static int m_NoExecuted;
  81. static Mode m_Mode;
  82. bool m_NotifyOpenOut;
  83. bool m_CheckedAlready;
  84. bool m_Recmode;
  85. };
  86. #endif