forked from gen2brain/malgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_info.go
52 lines (44 loc) · 1.14 KB
/
device_info.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
package malgo
// #include "malgo.h"
import "C"
import (
"encoding/hex"
"fmt"
"unsafe"
)
// DeviceID type.
type DeviceID [unsafe.Sizeof(C.mal_device_id{})]byte
// String returns the string representation of the identifier.
// It is the hexadecimal form of the underlying bytes of a minimum length of 2 digits, with trailing zeroes removed.
func (d DeviceID) String() string {
displayLen := len(d)
for (displayLen > 1) && (d[displayLen-1] == 0) {
displayLen--
}
return hex.EncodeToString(d[:displayLen])
}
func (d *DeviceID) cptr() *C.mal_device_id {
return (*C.mal_device_id)(unsafe.Pointer(d))
}
// DeviceInfo type.
type DeviceInfo struct {
ID DeviceID
name [256]byte
FormatCount uint32
Formats [6]uint32
MinChannels uint32
MaxChannels uint32
MinSampleRate uint32
MaxSampleRate uint32
}
// Name returns the name of the device.
func (d *DeviceInfo) Name() string {
return string(d.name[:])
}
// String returns string.
func (d *DeviceInfo) String() string {
return fmt.Sprintf("{ID: [%v], Name: %s}", d.ID, d.Name())
}
func deviceInfoFromPointer(ptr unsafe.Pointer) DeviceInfo {
return *(*DeviceInfo)(ptr)
}