Jack2  1.9.10
JackOSSAdapter.h
00001 /*
00002 Copyright (C) 2008 Grame & RTL 2008
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 __JackOSSAdapter__
00021 #define __JackOSSAdapter__
00022 
00023 #include <math.h>
00024 #include <limits.h>
00025 #include <assert.h>
00026 #include "JackAudioAdapterInterface.h"
00027 #include "JackPlatformPlug.h"
00028 #include "JackError.h"
00029 #include "jack.h"
00030 #include "jslist.h"
00031 
00032 namespace Jack
00033 {
00034 
00035 typedef jack_default_audio_sample_t jack_sample_t;
00036 
00037 #define OSS_DRIVER_DEF_DEV      "/dev/dsp"
00038 #define OSS_DRIVER_DEF_FS       48000
00039 #define OSS_DRIVER_DEF_BLKSIZE  1024
00040 #define OSS_DRIVER_DEF_NPERIODS 2
00041 #define OSS_DRIVER_DEF_BITS     16
00042 #define OSS_DRIVER_DEF_INS      2
00043 #define OSS_DRIVER_DEF_OUTS     2
00044 
00049 class JackOSSAdapter : public JackAudioAdapterInterface, public JackRunnableInterface
00050 {
00051 
00052     enum { kRead = 1, kWrite = 2, kReadWrite = 3 };
00053 
00054     private:
00055 
00056         JackThread fThread;
00057 
00058         char fCaptureDriverName[JACK_CLIENT_NAME_SIZE + 1];
00059         char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE + 1];
00060 
00061         int fInFD;
00062         int fOutFD;
00063 
00064         int fBits;
00065         int fSampleFormat;
00066         int fNperiods;
00067         unsigned int fSampleSize;
00068         int     fRWMode;
00069         bool fIgnoreHW;
00070         bool fExcl;
00071 
00072         unsigned int fInputBufferSize;
00073         unsigned int fOutputBufferSize;
00074 
00075         void* fInputBuffer;
00076         void* fOutputBuffer;
00077 
00078         float** fInputSampleBuffer;
00079         float** fOutputSampleBuffer;
00080 
00081         bool fFirstCycle;
00082 
00083         int OpenInput();
00084         int OpenOutput();
00085         void CloseAux();
00086         void SetSampleFormat();
00087         void DisplayDeviceInfo();
00088 
00089     public:
00090 
00091         JackOSSAdapter(jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params);
00092         ~JackOSSAdapter()
00093         {}
00094 
00095         int Open();
00096         int Close();
00097 
00098         int Read();
00099         int Write();
00100 
00101         int SetBufferSize(jack_nframes_t buffer_size);
00102 
00103         bool Execute();
00104 };
00105 
00106 }
00107 
00108 #ifdef __cplusplus
00109 extern "C"
00110 {
00111 #endif
00112 
00113 #include "JackCompilerDeps.h"
00114 #include "driver_interface.h"
00115 
00116 SERVER_EXPORT jack_driver_desc_t* jack_get_descriptor();
00117 
00118 #ifdef __cplusplus
00119 }
00120 #endif
00121 
00122 #endif