-
Notifications
You must be signed in to change notification settings - Fork 135
/
api_darwin.go
95 lines (75 loc) · 3.15 KB
/
api_darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2022 The Oto Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package oto
import (
"unsafe"
"github.com/ebitengine/purego"
)
const (
avAudioSessionErrorCodeCannotStartPlaying = 0x21706c61 // '!pla'
avAudioSessionErrorCodeCannotInterruptOthers = 0x21696e74 // '!int'
avAudioSessionErrorCodeSiriIsRecording = 0x73697269 // 'siri'
)
const (
kAudioFormatLinearPCM = 0x6C70636D //'lpcm'
)
const (
kAudioFormatFlagIsFloat = 1 << 0 // 0x1
)
type _AudioStreamBasicDescription struct {
mSampleRate float64
mFormatID uint32
mFormatFlags uint32
mBytesPerPacket uint32
mFramesPerPacket uint32
mBytesPerFrame uint32
mChannelsPerFrame uint32
mBitsPerChannel uint32
mReserved uint32
}
type _AudioQueueRef uintptr
type _AudioTimeStamp uintptr
type _AudioStreamPacketDescription struct {
mStartOffset int64
mVariableFramesInPacket uint32
mDataByteSize uint32
}
type _AudioQueueBufferRef *_AudioQueueBuffer
type _AudioQueueBuffer struct {
mAudioDataBytesCapacity uint32
mAudioData uintptr // void*
mAudioDataByteSize uint32
mUserData uintptr // void*
mPacketDescriptionCapacity uint32
mPacketDescriptions *_AudioStreamPacketDescription
mPacketDescriptionCount uint32
}
type _AudioQueueOutputCallback func(inUserData unsafe.Pointer, inAQ _AudioQueueRef, inBuffer _AudioQueueBufferRef)
func initializeAPI() error {
toolbox, err := purego.Dlopen("/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox", purego.RTLD_LAZY|purego.RTLD_GLOBAL)
if err != nil {
return err
}
purego.RegisterLibFunc(&_AudioQueueNewOutput, toolbox, "AudioQueueNewOutput")
purego.RegisterLibFunc(&_AudioQueueAllocateBuffer, toolbox, "AudioQueueAllocateBuffer")
purego.RegisterLibFunc(&_AudioQueueEnqueueBuffer, toolbox, "AudioQueueEnqueueBuffer")
purego.RegisterLibFunc(&_AudioQueueStart, toolbox, "AudioQueueStart")
purego.RegisterLibFunc(&_AudioQueuePause, toolbox, "AudioQueuePause")
return nil
}
var _AudioQueueNewOutput func(inFormat *_AudioStreamBasicDescription, inCallbackProc _AudioQueueOutputCallback, inUserData unsafe.Pointer, inCallbackRunLoop uintptr, inCallbackRunLoopMod uintptr, inFlags uint32, outAQ *_AudioQueueRef) uintptr
var _AudioQueueAllocateBuffer func(inAQ _AudioQueueRef, inBufferByteSize uint32, outBuffer *_AudioQueueBufferRef) uintptr
var _AudioQueueEnqueueBuffer func(inAQ _AudioQueueRef, inBuffer _AudioQueueBufferRef, inNumPacketDescs uint32, inPackets []_AudioStreamPacketDescription) uintptr
var _AudioQueueStart func(inAQ _AudioQueueRef, inStartTime *_AudioTimeStamp) uintptr
var _AudioQueuePause func(inAQ _AudioQueueRef) uintptr