Jack2  1.9.10
JackBoomerDriver.h
00001 /*
00002 Copyright (C) 2009 Grame
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #ifndef __JackBoomerDriver__
00021 #define __JackBoomerDriver__
00022 
00023 #include "JackAudioDriver.h"
00024 #include "JackPlatformPlug.h"
00025 #include "ringbuffer.h"
00026 #include <semaphore.h>
00027 
00028 namespace Jack
00029 {
00030 
00031 typedef jack_default_audio_sample_t jack_sample_t;
00032 
00033 #define OSS_DRIVER_DEF_DEV      "/dev/dsp"
00034 #define OSS_DRIVER_DEF_FS       48000
00035 #define OSS_DRIVER_DEF_BLKSIZE  1024
00036 #define OSS_DRIVER_DEF_NPERIODS 1
00037 #define OSS_DRIVER_DEF_BITS     16
00038 #define OSS_DRIVER_DEF_INS      2
00039 #define OSS_DRIVER_DEF_OUTS     2
00040 
00045 class JackBoomerDriver : public JackAudioDriver
00046 {
00047 
00048     enum { kRead = 1, kWrite = 2, kReadWrite = 3 };
00049 
00050     private:
00051 
00052         class JackBoomerDriverInput : public JackRunnableInterface {
00053 
00054             private:
00055     
00056                 JackBoomerDriver* fDriver;
00057 
00058             public:
00059 
00060                 JackBoomerDriverInput(JackBoomerDriver* driver): fDriver(driver)
00061                 {}
00062                 ~JackBoomerDriverInput()
00063                 {}
00064 
00065                 bool Init();
00066                 bool Execute();
00067         };
00068 
00069         class JackBoomerDriverOutput : public JackRunnableInterface {
00070 
00071             private:
00072     
00073                 JackBoomerDriver* fDriver;
00074 
00075             public:
00076 
00077                 JackBoomerDriverOutput(JackBoomerDriver* driver): fDriver(driver)
00078                 {}
00079                 ~JackBoomerDriverOutput()
00080                 {}
00081 
00082                 bool Init();
00083                 bool Execute();
00084         };
00085 
00086         int fInFD;
00087         int fOutFD;
00088         
00089         int fBits;
00090         int fSampleFormat;
00091         int fNperiods;
00092         unsigned int fSampleSize;
00093         unsigned int fFragmentSize;
00094         int fRWMode;
00095         bool fExcl;
00096         bool fSyncIO;
00097        
00098         unsigned int fInputBufferSize;
00099         unsigned int fOutputBufferSize;
00100         
00101         void* fInputBuffer;
00102         void* fOutputBuffer;
00103   
00104         sem_t fReadSema;
00105         sem_t fWriteSema;
00106 
00107         JackThread fInputThread;
00108         JackThread fOutputThread;
00109      
00110         JackBoomerDriverInput fInputHandler;
00111         JackBoomerDriverOutput fOutputHandler;
00112          
00113         int OpenInput();
00114         int OpenOutput();
00115         int OpenAux();
00116         void CloseAux();
00117         void SetSampleFormat();
00118         void DisplayDeviceInfo();
00119         void SynchronizeRead();
00120         void SynchronizeWrite();
00121 
00122     public:
00123 
00124         JackBoomerDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
00125         virtual ~JackBoomerDriver();
00126  
00127         int Open(jack_nframes_t frames_per_cycle,
00128                  int user_nperiods, 
00129                  jack_nframes_t rate,
00130                  bool capturing,
00131                  bool playing,
00132                  int chan_in,
00133                  int chan_out,
00134                  bool excl,
00135                  bool monitor,
00136                  const char* capture_driver_name,
00137                  const char* playback_driver_name,
00138                  jack_nframes_t capture_latency,
00139                  jack_nframes_t playback_latency,
00140                  int bits, bool syncio);
00141 
00142         int Close();
00143 
00144         int Start();
00145         int Stop();
00146 
00147         // BufferSize can be changed
00148         bool IsFixedBufferSize()
00149         {
00150             return false;
00151         }
00152 
00153         int SetBufferSize(jack_nframes_t buffer_size);
00154   
00155 };
00156 
00157 } // end of namespace
00158 
00159 #endif