Jack2 1.9.6
|
00001 /* 00002 Copyright (C) 2008 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 __JackCoreAudioAdapter__ 00021 #define __JackCoreAudioAdapter__ 00022 00023 #include "JackAudioAdapterInterface.h" 00024 #include "jack.h" 00025 #include "jslist.h" 00026 #include <AudioToolbox/AudioConverter.h> 00027 #include <CoreAudio/CoreAudio.h> 00028 #include <AudioUnit/AudioUnit.h> 00029 00030 #include <vector> 00031 00032 using namespace std; 00033 00034 namespace Jack 00035 { 00036 00037 typedef UInt8 CAAudioHardwareDeviceSectionID; 00038 #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01) 00039 #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00) 00040 #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00) 00041 #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF) 00042 00043 #define WAIT_COUNTER 60 00044 00049 class JackCoreAudioAdapter : public JackAudioAdapterInterface 00050 { 00051 00052 private: 00053 00054 AudioUnit fAUHAL; 00055 AudioBufferList* fInputData; 00056 00057 char fCaptureUID[256]; 00058 char fPlaybackUID[256]; 00059 00060 bool fCapturing; 00061 bool fPlaying; 00062 00063 AudioDeviceID fDeviceID; // Used "duplex" device 00064 AudioObjectID fPluginID; // Used for aggregate device 00065 00066 bool fState; 00067 00068 AudioUnitRenderActionFlags* fActionFags; 00069 AudioTimeStamp* fCurrentTime; 00070 bool fClockDriftCompensate; 00071 00072 static OSStatus Render(void *inRefCon, 00073 AudioUnitRenderActionFlags *ioActionFlags, 00074 const AudioTimeStamp *inTimeStamp, 00075 UInt32 inBusNumber, 00076 UInt32 inNumberFrames, 00077 AudioBufferList *ioData); 00078 00079 static OSStatus SRNotificationCallback(AudioDeviceID inDevice, 00080 UInt32 inChannel, 00081 Boolean isInput, 00082 AudioDevicePropertyID inPropertyID, 00083 void* inClientData); 00084 static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice, 00085 UInt32 inChannel, 00086 Boolean isInput, 00087 AudioDevicePropertyID inPropertyID, 00088 void* inClientData); 00089 00090 OSStatus GetDefaultDevice(AudioDeviceID* id); 00091 OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput); 00092 OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id); 00093 OSStatus GetDefaultInputDevice(AudioDeviceID* id); 00094 OSStatus GetDefaultOutputDevice(AudioDeviceID* id); 00095 OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name); 00096 00097 // Setup 00098 OSStatus CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice); 00099 OSStatus CreateAggregateDeviceAux(vector<AudioDeviceID> captureDeviceID, vector<AudioDeviceID> playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice); 00100 OSStatus DestroyAggregateDevice(); 00101 bool IsAggregateDevice(AudioDeviceID device); 00102 00103 int SetupDevices(const char* capture_driver_uid, 00104 const char* playback_driver_uid, 00105 char* capture_driver_name, 00106 char* playback_driver_name, 00107 jack_nframes_t samplerate); 00108 00109 int SetupChannels(bool capturing, 00110 bool playing, 00111 int& inchannels, 00112 int& outchannels, 00113 int& in_nChannels, 00114 int& out_nChannels, 00115 bool strict); 00116 00117 int OpenAUHAL(bool capturing, 00118 bool playing, 00119 int inchannels, 00120 int outchannels, 00121 int in_nChannels, 00122 int out_nChannels, 00123 jack_nframes_t buffer_size, 00124 jack_nframes_t samplerate); 00125 00126 int SetupBufferSize(jack_nframes_t buffer_size); 00127 int SetupSampleRate(jack_nframes_t samplerate); 00128 int SetupSampleRateAux(AudioDeviceID inDevice, jack_nframes_t samplerate); 00129 00130 int SetupBuffers(int inchannels); 00131 void DisposeBuffers(); 00132 void CloseAUHAL(); 00133 00134 int AddListeners(); 00135 void RemoveListeners(); 00136 00137 public: 00138 00139 JackCoreAudioAdapter( jack_nframes_t buffer_size, jack_nframes_t sample_rate, const JSList* params); 00140 ~JackCoreAudioAdapter() 00141 {} 00142 00143 virtual int Open(); 00144 virtual int Close(); 00145 00146 virtual int SetSampleRate(jack_nframes_t sample_rate); 00147 virtual int SetBufferSize(jack_nframes_t buffer_size); 00148 00149 }; 00150 } 00151 00152 #ifdef __cplusplus 00153 extern "C" 00154 { 00155 #endif 00156 00157 #include "JackCompilerDeps.h" 00158 #include "driver_interface.h" 00159 00160 SERVER_EXPORT jack_driver_desc_t* jack_get_descriptor(); 00161 00162 #ifdef __cplusplus 00163 } 00164 #endif 00165 00166 #endif