Skip to content

Commit a3cfd22

Browse files
committed
Alias C type to allow for external WebRtcVadInst type reference
To use VAD instance in some context, for example: a struct field, `sync.Pool`, etc. it's necessary to reference the type explicitly. golang/go#13467 Signed-off-by: Arkadi Shishlov <[email protected]>
1 parent 6a18123 commit a3cfd22

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

vad.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ import (
1212
"unsafe"
1313
)
1414

15+
type VadInst *C.struct_WebRtcVadInst
16+
1517
// Create Creates an instance to the VAD structure.
16-
func Create() *C.struct_WebRtcVadInst {
17-
return C.WebRtcVad_Create()
18+
func Create() VadInst {
19+
return VadInst(C.WebRtcVad_Create())
1820
}
1921

2022
// Free Frees the dynamic memory of a specified VAD instance.
21-
func Free(vadInst *C.struct_WebRtcVadInst) {
23+
func Free(vadInst VadInst) {
2224
C.WebRtcVad_Free(vadInst)
2325
}
2426

2527
// Init Initializes a VAD instance.
26-
func Init(vadInst *C.struct_WebRtcVadInst) (err error) {
28+
func Init(vadInst VadInst) (err error) {
2729
result := C.WebRtcVad_Init(vadInst)
2830
if result == -1 {
2931
err = errors.New("null pointer or Default mode could not be set")
@@ -32,7 +34,7 @@ func Init(vadInst *C.struct_WebRtcVadInst) (err error) {
3234
}
3335

3436
// SetMode Sets the VAD operating mode.
35-
func SetMode(vadInst *C.struct_WebRtcVadInst, mode int) (err error) {
37+
func SetMode(vadInst VadInst, mode int) (err error) {
3638
result := C.WebRtcVad_set_mode(vadInst, C.int(mode))
3739
if result == -1 {
3840
err = errors.New("mode could not be set or the VAD instance has not been initialized")
@@ -41,7 +43,7 @@ func SetMode(vadInst *C.struct_WebRtcVadInst, mode int) (err error) {
4143
}
4244

4345
// Process Sets the VAD operating mode.
44-
func Process(vadInst *C.struct_WebRtcVadInst, fs int, audioFrame []byte, frameLength int) (active bool, err error) {
46+
func Process(vadInst VadInst, fs int, audioFrame []byte, frameLength int) (active bool, err error) {
4547
result := C.WebRtcVad_Process(vadInst, C.int(fs), (*C.short)(unsafe.Pointer(&audioFrame[0])), C.size_t(frameLength))
4648
if result == 1 {
4749
active = true

0 commit comments

Comments
 (0)