Merge pull request #475 from JupiterRider/audiostream_processor
fix purego version of DetachAudioStreamProcessor and DetachAudioMixedProcessor
This commit is contained in:
commit
078d0bec34
1 changed files with 14 additions and 8 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/ebitengine/purego"
|
"github.com/ebitengine/purego"
|
||||||
|
@ -17,6 +18,10 @@ import (
|
||||||
var (
|
var (
|
||||||
// raylibDll is the pointer to the shared library
|
// raylibDll is the pointer to the shared library
|
||||||
raylibDll uintptr
|
raylibDll uintptr
|
||||||
|
|
||||||
|
// audioCallbacks is needed to have a reference between Go functions (keys) created by the user
|
||||||
|
// and C function pointers (values) created by purego.NewCallback
|
||||||
|
audioCallbacks map[uintptr]uintptr
|
||||||
)
|
)
|
||||||
|
|
||||||
var initWindow func(width int32, height int32, title string)
|
var initWindow func(width int32, height int32, title string)
|
||||||
|
@ -532,6 +537,7 @@ var detachAudioMixedProcessor func(processor uintptr)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
raylibDll = loadLibrary()
|
raylibDll = loadLibrary()
|
||||||
|
audioCallbacks = make(map[uintptr]uintptr)
|
||||||
|
|
||||||
initRlglPurego()
|
initRlglPurego()
|
||||||
|
|
||||||
|
@ -3894,15 +3900,15 @@ func AttachAudioStreamProcessor(stream AudioStream, processor AudioCallback) {
|
||||||
processor(unsafe.Slice((*float32)(bufferData), frames), int(frames))
|
processor(unsafe.Slice((*float32)(bufferData), frames), int(frames))
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
|
ptr := uintptr(reflect.ValueOf(processor).UnsafePointer())
|
||||||
|
audioCallbacks[ptr] = fn
|
||||||
attachAudioStreamProcessor(uintptr(unsafe.Pointer(&stream)), fn)
|
attachAudioStreamProcessor(uintptr(unsafe.Pointer(&stream)), fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetachAudioStreamProcessor - Detach audio stream processor from stream
|
// DetachAudioStreamProcessor - Detach audio stream processor from stream
|
||||||
func DetachAudioStreamProcessor(stream AudioStream, processor AudioCallback) {
|
func DetachAudioStreamProcessor(stream AudioStream, processor AudioCallback) {
|
||||||
fn := purego.NewCallback(func(bufferData unsafe.Pointer, frames int32) uintptr {
|
ptr := uintptr(reflect.ValueOf(processor).UnsafePointer())
|
||||||
processor(unsafe.Slice((*float32)(bufferData), frames), int(frames))
|
fn := audioCallbacks[ptr]
|
||||||
return 0
|
|
||||||
})
|
|
||||||
detachAudioStreamProcessor(uintptr(unsafe.Pointer(&stream)), fn)
|
detachAudioStreamProcessor(uintptr(unsafe.Pointer(&stream)), fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3912,15 +3918,15 @@ func AttachAudioMixedProcessor(processor AudioCallback) {
|
||||||
processor(unsafe.Slice((*float32)(bufferData), frames), int(frames))
|
processor(unsafe.Slice((*float32)(bufferData), frames), int(frames))
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
|
ptr := uintptr(reflect.ValueOf(processor).UnsafePointer())
|
||||||
|
audioCallbacks[ptr] = fn
|
||||||
attachAudioMixedProcessor(fn)
|
attachAudioMixedProcessor(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetachAudioMixedProcessor - Detach audio stream processor from the entire audio pipeline
|
// DetachAudioMixedProcessor - Detach audio stream processor from the entire audio pipeline
|
||||||
func DetachAudioMixedProcessor(processor AudioCallback) {
|
func DetachAudioMixedProcessor(processor AudioCallback) {
|
||||||
fn := purego.NewCallback(func(bufferData unsafe.Pointer, frames int32) uintptr {
|
ptr := uintptr(reflect.ValueOf(processor).UnsafePointer())
|
||||||
processor(unsafe.Slice((*float32)(bufferData), frames), int(frames))
|
fn := audioCallbacks[ptr]
|
||||||
return 0
|
|
||||||
})
|
|
||||||
detachAudioMixedProcessor(fn)
|
detachAudioMixedProcessor(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue