forked from lexesv/gobass.dll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.go
82 lines (75 loc) · 2.13 KB
/
record.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
package bass
/*
#include "bass.h"
#include "stdlib.h"
*/
import "C"
import (
"unsafe"
)
type Record struct {
Channel
}
func (self Record) ToError() (Record, error) {
_, err := self.Channel.ToError()
return self, err
}
/* RECORD */
/*
RecordInit
BOOL BASSDEF(BASS_RecordInit)(int device);
*/
func RecordInit(device int) error {
return boolToError(C.BASS_RecordInit(C.int(device)))
}
/*
RecordFree
BOOL BASSDEF(BASS_RecordFree)();
*/
func RecordFree() error {
return boolToError(C.BASS_RecordFree())
}
func RecordStartCCallback(freq, chans int, flags Flags, streamproc *C.RECORDPROC, userdata unsafe.Pointer) (Record, error) {
channel := C.BASS_RecordStart(cuint(freq), cuint(chans), cuint(flags), streamproc, userdata)
return Record{Channel: ChannelFromHandle(uint32(channel))}.ToError()
}
func RecordGetDeviceInfo(device int) (DeviceInfo, error) {
var info C.BASS_DEVICEINFO
err := boolToError(C.BASS_RecordGetDeviceInfo(C.DWORD(device), &info))
if err!=nil {
return DeviceInfo{}, err
} else {
return DeviceInfo{Name: C.GoString(info.name), Driver: C.GoString(info.driver), Flags: Flags(info.flags), Kind: getHighWord(info.flags)}, nil
}
}
func RecordGetDeviceInfoFlags(device int) (Flags, error) {
var info C.BASS_DEVICEINFO
err := boolToError(C.BASS_RecordGetDeviceInfo(C.DWORD(device), &info))
if err!=nil {
return 0, err
} else {
return Flags(info.flags), nil
}
}
type RecordInfo struct {
Flags, Formats, Inputs, Freq, Channels int
SingleIn bool
}
func RecordGetInfo() (RecordInfo, error) {
var info C.BASS_RECORDINFO
err := boolToError(C.BASS_RecordGetInfo(&info))
if err!=nil {
return RecordInfo{}, err
} else {
// For some reason the channels are stored in the last byte of formats
formats := info.formats>>8
ptr := (*uint8)(unsafe.Pointer(&formats))
return RecordInfo{Flags: int(info.flags), Formats: int(info.formats), Inputs: int(info.inputs), SingleIn: info.singlein!=0, Freq: int(info.freq), Channels: int(*ptr)}, nil
}
}
func RecordSetDevice(device int) error {
return boolToError(C.BASS_RecordSetDevice(C.DWORD(device)))
}
func RecordGetDevice() (int, error) {
return intPairToError(C.BASS_RecordGetDevice())
}