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.

110 lines
3.0KB

  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 OSSClient
  24. {
  25. public:
  26. static OSSClient *Get() { if(!m_Singleton) m_Singleton=new OSSClient; return m_Singleton; }
  27. static void PackUpAndGoHome() { if(m_Singleton) { delete m_Singleton; m_Singleton=NULL; } }
  28. ~OSSClient();
  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. short *GetBuffer() {return m_Buffer[m_WriteBufferNum];}
  39. bool OpenReadWrite();
  40. bool OpenWrite();
  41. bool OpenRead();
  42. bool Close();
  43. void Kill() { m_IsDead = true; m_OutputOk=false; PackUpAndGoHome(); }
  44. private:
  45. static OSSClient* m_Singleton;
  46. OSSClient();
  47. short *m_Buffer[2];
  48. short *m_InBuffer[2];
  49. int m_BufSizeBytes;
  50. int m_Dspfd;
  51. float m_Amp;
  52. int m_Channels;
  53. int m_ReadBufferNum;
  54. int m_WriteBufferNum;
  55. bool m_OutputOk;
  56. bool m_IsDead;
  57. };
  58. class OutputPlugin : public AudioDriver
  59. {
  60. public:
  61. enum Mode {NO_MODE,INPUT,OUTPUT,DUPLEX,CLOSED};
  62. OutputPlugin();
  63. virtual ~OutputPlugin();
  64. virtual PluginInfo& Initialise(const HostInfo *Host);
  65. virtual SpiralGUIType* CreateGUI();
  66. /* General Plugin Function */
  67. virtual void Execute();
  68. virtual void ExecuteCommands();
  69. virtual bool Kill();
  70. virtual void Reset();
  71. /* Audio Driver Specific Functions */
  72. virtual bool IsAudioDriver() { return true; }
  73. virtual AudioProcessType ProcessType() { return AudioDriver::ALWAYS; }
  74. virtual void ProcessAudio();
  75. /* OSS Plugin Specific Functions */
  76. enum GUICommands {NONE, OPENREAD, OPENWRITE, OPENDUPLEX, CLOSE, SET_VOLUME, CLEAR_NOTIFY};
  77. float m_Volume;
  78. Mode GetMode() { return m_Mode; }
  79. /* OSS Plugin Streaming - soon to be obsolete and for backward compatibility only*/
  80. virtual void StreamOut(std::ostream &s) {}
  81. virtual void StreamIn(std::istream &s) {}
  82. private:
  83. static int m_RefCount;
  84. static int m_NoExecuted;
  85. static Mode m_Mode;
  86. bool m_NotifyOpenOut;
  87. bool m_CheckedAlready;
  88. };
  89. #endif