Skip to content

Commit

Permalink
Merge pull request #1 from arkadijs/master
Browse files Browse the repository at this point in the history
Alias C type to allow for external WebRtcVadInst type reference
  • Loading branch information
baabaaox committed Feb 17, 2024
2 parents 6a18123 + a3cfd22 commit 55552f5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions vad.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ import (
"unsafe"
)

type VadInst *C.struct_WebRtcVadInst

// Create Creates an instance to the VAD structure.
func Create() *C.struct_WebRtcVadInst {
return C.WebRtcVad_Create()
func Create() VadInst {
return VadInst(C.WebRtcVad_Create())
}

// Free Frees the dynamic memory of a specified VAD instance.
func Free(vadInst *C.struct_WebRtcVadInst) {
func Free(vadInst VadInst) {
C.WebRtcVad_Free(vadInst)
}

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

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

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

0 comments on commit 55552f5

Please sign in to comment.