|
| 1 | +from ctypes import * |
| 2 | +import ctypes.util |
| 3 | + |
| 4 | +from CoreFoundation import * |
| 5 | + |
| 6 | +_at = CDLL(ctypes.util.find_library("AudioToolbox")) |
| 7 | + |
| 8 | +OpaqueAUGraph = c_void_p |
| 9 | +AUGraph = POINTER(OpaqueAUGraph) # typedef struct OpaqueAUGraph *AUGraph; |
| 10 | +AUNode = c_int32 # typedef SInt32 AUNode; |
| 11 | +AudioComponentInstance = c_void_p # typedef struct ComponentInstanceRecord *AudioComponentInstance; |
| 12 | +AudioUnit = AudioComponentInstance # typedef AudioComponentInstance AudioUnit; |
| 13 | +MusicDeviceComponent = AudioComponentInstance # typedef AudioComponentInstance MusicDeviceComponent; |
| 14 | +AudioUnitParameterID = c_uint32 # typedef UInt32 AudioUnitParameterID; |
| 15 | +AudioUnitScope = c_uint32 # typedef UInt32 AudioUnitScope; |
| 16 | +AudioUnitElement = c_uint32 # typedef UInt32 AudioUnitElement; |
| 17 | +AudioUnitParameterValue = c_float # typedef Float32 AudioUnitParameterValue; |
| 18 | + |
| 19 | +kMusicDeviceParam_Volume = AudioUnitParameterID(1) |
| 20 | +kAudioUnitScope_Global = AudioUnitScope(0) |
| 21 | + |
| 22 | +def FOUR_CHAR_CODE(code): |
| 23 | + value = 0 |
| 24 | + for i in range(4): |
| 25 | + value += ord(code[i]) << (3 - i) * 8 |
| 26 | + return value |
| 27 | + |
| 28 | +kAudioUnitManufacturer_Apple = FOUR_CHAR_CODE('appl') |
| 29 | +kAudioUnitType_MusicDevice = FOUR_CHAR_CODE('aumu') |
| 30 | +kAudioUnitSubType_DLSSynth = FOUR_CHAR_CODE('dls ') |
| 31 | +kAudioUnitType_Effect = FOUR_CHAR_CODE('aufx') |
| 32 | +kAudioUnitSubType_PeakLimiter = FOUR_CHAR_CODE('lmtr') |
| 33 | +kAudioUnitType_Output = FOUR_CHAR_CODE('auou') |
| 34 | +kAudioUnitSubType_DefaultOutput = FOUR_CHAR_CODE('def ') |
| 35 | + |
| 36 | +class AudioComponentDescription(Structure): |
| 37 | + _fields_ = [("componentType", OSType), # OSType componentType; |
| 38 | + ("componentSubType", OSType), # OSType componentSubType; |
| 39 | + ("componentManufacturer", OSType), # OSType componentManufacturer; |
| 40 | + ("componentFlags", c_uint32), # UInt32 componentFlags; |
| 41 | + ("componentFlagsMask", c_uint32)] # UInt32 componentFlagsMask; |
| 42 | + |
| 43 | +# OSStatus NewAUGraph(AUGraph _Nullable *outGraph); |
| 44 | +_at.NewAUGraph.argtypes = [POINTER(AUGraph)] |
| 45 | +_at.NewAUGraph.restype = OSStatus |
| 46 | +NewAUGraph = _at.NewAUGraph |
| 47 | + |
| 48 | +# OSStatus AUGraphAddNode(AUGraph inGraph, const AudioComponentDescription *inDescription, AUNode *outNode); |
| 49 | +_at.AUGraphAddNode.argtypes = [AUGraph, POINTER(AudioComponentDescription), POINTER(AUNode)] |
| 50 | +_at.AUGraphAddNode.restype = OSStatus |
| 51 | +AUGraphAddNode = _at.AUGraphAddNode |
| 52 | + |
| 53 | +# OSStatus AUGraphOpen(AUGraph inGraph); |
| 54 | +_at.AUGraphOpen.argtypes = [AUGraph] |
| 55 | +_at.AUGraphOpen.restype = OSStatus |
| 56 | +AUGraphOpen = _at.AUGraphOpen |
| 57 | + |
| 58 | +# OSStatus AUGraphConnectNodeInput(AUGraph inGraph, AUNode inSourceNode, UInt32 inSourceOutputNumber, AUNode inDestNode, UInt32 inDestInputNumber); |
| 59 | +_at.AUGraphConnectNodeInput.argtypes = [AUGraph, AUNode, c_uint32, AUNode, c_uint32] |
| 60 | +_at.AUGraphConnectNodeInput.restype = OSStatus |
| 61 | +AUGraphConnectNodeInput = _at.AUGraphConnectNodeInput |
| 62 | + |
| 63 | +# OSStatus AUGraphNodeInfo(AUGraph inGraph, AUNode inNode, AudioComponentDescription *outDescription, AudioUnit _Nullable *outAudioUnit); |
| 64 | +_at.AUGraphNodeInfo.argtypes = [AUGraph, AUNode, POINTER(AudioComponentDescription), POINTER(AudioUnit)] |
| 65 | +_at.AUGraphNodeInfo.restype = OSStatus |
| 66 | +AUGraphNodeInfo = _at.AUGraphNodeInfo |
| 67 | + |
| 68 | +# OSStatus AUGraphInitialize(AUGraph inGraph); |
| 69 | +_at.AUGraphInitialize.argtypes = [AUGraph] |
| 70 | +_at.AUGraphInitialize.restype = OSStatus |
| 71 | +AUGraphInitialize = _at.AUGraphInitialize |
| 72 | + |
| 73 | +# OSStatus AUGraphStart(AUGraph inGraph); |
| 74 | +_at.AUGraphStart.argtypes = [AUGraph] |
| 75 | +_at.AUGraphStart.restype = OSStatus |
| 76 | +AUGraphStart = _at.AUGraphStart |
| 77 | + |
| 78 | +# OSStatus AudioUnitGetParameter(AudioUnit inUnit, AudioUnitParameterID inID, AudioUnitScope inScope, AudioUnitElement inElement, AudioUnitParameterValue *outValue); |
| 79 | +_at.AudioUnitGetParameter.argtypes = [AudioUnit, AudioUnitParameterID, AudioUnitScope, AudioUnitElement, POINTER(AudioUnitParameterValue)] |
| 80 | +_at.AudioUnitGetParameter.restype = OSStatus |
| 81 | +AudioUnitGetParameter = _at.AudioUnitGetParameter |
| 82 | + |
| 83 | +# OSStatus AudioUnitSetParameter(AudioUnit inUnit, AudioUnitParameterID inID, AudioUnitScope inScope, AudioUnitElement inElement, AudioUnitParameterValue inValue, UInt32 inBufferOffsetInFrames); |
| 84 | +_at.AudioUnitSetParameter.argtypes = [AudioUnit, AudioUnitParameterID, AudioUnitScope, AudioUnitElement, AudioUnitParameterValue, c_uint32] |
| 85 | +_at.AudioUnitSetParameter.restype = OSStatus |
| 86 | +AudioUnitSetParameter = _at.AudioUnitSetParameter |
| 87 | + |
| 88 | +# OSStatus MusicDeviceMIDIEvent(MusicDeviceComponent inUnit, UInt32 inStatus, UInt32 inData1, UInt32 inData2, UInt32 inOffsetSampleFrame); |
| 89 | +_at.MusicDeviceMIDIEvent.argtypes = [MusicDeviceComponent, c_uint32, c_uint32, c_uint32, c_uint32] |
| 90 | +_at.MusicDeviceMIDIEvent.restype = OSStatus |
| 91 | +MusicDeviceMIDIEvent = _at.MusicDeviceMIDIEvent |
| 92 | + |
| 93 | +# void CAShow(void *inObject); |
| 94 | +_at.CAShow.argtypes = [c_void_p] |
| 95 | +CAShow = _at.CAShow |
0 commit comments