-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
audio.go
118 lines (96 loc) · 3.95 KB
/
audio.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package vz
/*
#cgo darwin CFLAGS: -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization.h"
*/
import "C"
import "runtime"
// AudioDeviceConfiguration interface for an audio device configuration.
type AudioDeviceConfiguration interface {
NSObject
audioDeviceConfiguration()
}
type baseAudioDeviceConfiguration struct{}
func (*baseAudioDeviceConfiguration) audioDeviceConfiguration() {}
// VirtioSoundDeviceConfiguration is a struct that defines a Virtio sound device configuration.
//
// Use a VirtioSoundDeviceConfiguration to configure an audio device for your VM. After creating
// this struct, assign appropriate values via the SetStreams method which defines the behaviors of
// the underlying audio streams for this audio device.
//
// After creating and configuring a VirtioSoundDeviceConfiguration struct, assign it to the
// SetAudioDevicesVirtualMachineConfiguration method of your VM’s configuration.
type VirtioSoundDeviceConfiguration struct {
pointer
*baseAudioDeviceConfiguration
}
var _ AudioDeviceConfiguration = (*VirtioSoundDeviceConfiguration)(nil)
// NewVirtioSoundDeviceConfiguration creates a new sound device configuration.
func NewVirtioSoundDeviceConfiguration() *VirtioSoundDeviceConfiguration {
config := &VirtioSoundDeviceConfiguration{
pointer: pointer{
ptr: C.newVZVirtioSoundDeviceConfiguration(),
},
}
runtime.SetFinalizer(config, func(self *VirtioSoundDeviceConfiguration) {
self.Release()
})
return config
}
// SetStreams sets the list of audio streams exposed by this device.
func (v *VirtioSoundDeviceConfiguration) SetStreams(streams ...VirtioSoundDeviceStreamConfiguration) {
ptrs := make([]NSObject, len(streams))
for i, val := range streams {
ptrs[i] = val
}
array := convertToNSMutableArray(ptrs)
C.setStreamsVZVirtioSoundDeviceConfiguration(v.Ptr(), array.Ptr())
}
// VirtioSoundDeviceStreamConfiguration interface for Virtio Sound Device Stream Configuration.
type VirtioSoundDeviceStreamConfiguration interface {
NSObject
virtioSoundDeviceStreamConfiguration()
}
type baseVirtioSoundDeviceStreamConfiguration struct{}
func (*baseVirtioSoundDeviceStreamConfiguration) virtioSoundDeviceStreamConfiguration() {}
// VirtioSoundDeviceHostInputStreamConfiguration is a PCM stream of input audio data,
// such as from a microphone via host.
type VirtioSoundDeviceHostInputStreamConfiguration struct {
pointer
*baseVirtioSoundDeviceStreamConfiguration
}
var _ VirtioSoundDeviceStreamConfiguration = (*VirtioSoundDeviceHostInputStreamConfiguration)(nil)
// NewVirtioSoundDeviceHostInputStreamConfiguration creates a new PCM stream configuration of input audio data from host.
func NewVirtioSoundDeviceHostInputStreamConfiguration() *VirtioSoundDeviceHostInputStreamConfiguration {
config := &VirtioSoundDeviceHostInputStreamConfiguration{
pointer: pointer{
ptr: C.newVZVirtioSoundDeviceHostInputStreamConfiguration(),
},
}
runtime.SetFinalizer(config, func(self *VirtioSoundDeviceHostInputStreamConfiguration) {
self.Release()
})
return config
}
// VirtioSoundDeviceHostOutputStreamConfiguration is a struct that
// defines a Virtio host sound device output stream configuration.
//
// A PCM stream of output audio data, such as to a speaker from host.
type VirtioSoundDeviceHostOutputStreamConfiguration struct {
pointer
*baseVirtioSoundDeviceStreamConfiguration
}
var _ VirtioSoundDeviceStreamConfiguration = (*VirtioSoundDeviceHostOutputStreamConfiguration)(nil)
// NewVirtioSoundDeviceHostOutputStreamConfiguration creates a new sounds device output stream configuration.
func NewVirtioSoundDeviceHostOutputStreamConfiguration() *VirtioSoundDeviceHostOutputStreamConfiguration {
config := &VirtioSoundDeviceHostOutputStreamConfiguration{
pointer: pointer{
ptr: C.newVZVirtioSoundDeviceHostOutputStreamConfiguration(),
},
}
runtime.SetFinalizer(config, func(self *VirtioSoundDeviceHostOutputStreamConfiguration) {
self.Release()
})
return config
}