bindings for attaching/detaching mixed audio processor
This commit is contained in:
parent
6bc3d79c96
commit
c2c8150de9
1 changed files with 56 additions and 1 deletions
|
@ -16,13 +16,33 @@ static void audioStreamWrapperCallback(void *data, unsigned int frames) {
|
|||
static void setAudioStreamCallbackWrapper(AudioStream stream) {
|
||||
SetAudioStreamCallback(stream, audioStreamWrapperCallback);
|
||||
}
|
||||
|
||||
extern void internalAudioMixedProcessorGo(void *, int);
|
||||
|
||||
static void audioMixedProcessorCallback(void *data, unsigned int frames) {
|
||||
internalAudioMixedProcessorGo(data, frames);
|
||||
}
|
||||
|
||||
static void setAudioMixedProcessorCallbackWrapper() {
|
||||
AttachAudioMixedProcessor(audioMixedProcessorCallback);
|
||||
}
|
||||
|
||||
static void unsetAudioMixedProcessorCallbackWrapper() {
|
||||
DetachAudioMixedProcessor(audioMixedProcessorCallback);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"reflect"
|
||||
"sync"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var internalAudioStreamCallback AudioCallback
|
||||
var (
|
||||
internalAudioStreamCallback AudioCallback
|
||||
audioMixedProcessorsMutex = sync.RWMutex{}
|
||||
audioMixedProcessors = []AudioCallback{}
|
||||
)
|
||||
|
||||
// SetAudioStreamCallback - Audio thread callback to request new data
|
||||
func SetAudioStreamCallback(stream AudioStream, callback AudioCallback) {
|
||||
|
@ -37,6 +57,41 @@ func internalAudioStreamCallbackGo(data unsafe.Pointer, frames C.int) {
|
|||
}
|
||||
}
|
||||
|
||||
func AttachAudioMixedProcessor(callback AudioCallback) {
|
||||
audioMixedProcessorsMutex.Lock()
|
||||
defer audioMixedProcessorsMutex.Unlock()
|
||||
|
||||
if len(audioMixedProcessors) == 0 {
|
||||
C.setAudioMixedProcessorCallbackWrapper()
|
||||
}
|
||||
|
||||
audioMixedProcessors = append(audioMixedProcessors, callback)
|
||||
}
|
||||
|
||||
func DetachAudioMixedProcessor(callback AudioCallback) {
|
||||
audioMixedProcessorsMutex.Lock()
|
||||
defer audioMixedProcessorsMutex.Unlock()
|
||||
|
||||
callbackPtr := reflect.ValueOf(callback).Pointer()
|
||||
for i := len(audioMixedProcessors) - 1; i >= 0; i-- {
|
||||
if reflect.ValueOf(audioMixedProcessors[i]).Pointer() == callbackPtr {
|
||||
audioMixedProcessors = append(audioMixedProcessors[:i], audioMixedProcessors[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(audioMixedProcessors) == 0 {
|
||||
C.unsetAudioMixedProcessorCallbackWrapper()
|
||||
}
|
||||
}
|
||||
|
||||
//export internalAudioMixedProcessorGo
|
||||
func internalAudioMixedProcessorGo(data unsafe.Pointer, frames C.int) {
|
||||
for _, callback := range audioMixedProcessors {
|
||||
callback(unsafe.Slice((*float32)(data), frames), int(frames))
|
||||
}
|
||||
}
|
||||
|
||||
// newWaveFromPointer - Returns new Wave from pointer
|
||||
func newWaveFromPointer(ptr unsafe.Pointer) Wave {
|
||||
return *(*Wave)(ptr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue