sointu/bridge/bridge.go.in
Veikko Sariola 7aac3917b7 Implement a bridge to call Sointu from Go language.
The main interface is render_samples function, which renders several samples in one call,
to limit the number of calls from Go to C. This is compiled into a library, which is then
linked and called from bridge.go.
2020-10-22 21:19:13 +03:00

56 lines
1.2 KiB
Go

package bridge
import "fmt"
import "unsafe"
// #cgo CFLAGS: -I${INCLUDE_PATH}
// #cgo LDFLAGS: ${LIBRARY_PATH}
// #include <sointu.h>
import "C"
type SynthState = C.SynthState
func (s *SynthState) Render(buffer []float32) int {
fmt.Printf("Calling Render...\n")
var ret = C.su_render_samples(s, C.int(len(buffer))/2, (*C.float)(&buffer[0]))
fmt.Printf("Returning from Render...\n")
return int(ret)
}
func (s *SynthState) SetCommands(c [2048]byte) {
pk := *((*[2048]C.uchar)(unsafe.Pointer(&c)))
s.Commands = pk
}
func (s *SynthState) SetValues(c [16384]byte) {
pk := *((*[16384]C.uchar)(unsafe.Pointer(&c)))
s.Values = pk
}
func (s *SynthState) Trigger(voice int,note int) {
fmt.Printf("Calling Trigger...\n")
s.Synth.Voices[voice] = C.Voice{}
s.Synth.Voices[voice].Note = C.int(note)
fmt.Printf("Returning from Trigger...\n")
}
func (s *SynthState) Release(voice int) {
fmt.Printf("Calling Release...\n")
s.Synth.Voices[voice].Release = 1
fmt.Printf("Returning from Release...\n")
}
func (s *SynthState) RowEnd() bool {
return s.RowTick == s.RowLen
}
func (s *SynthState) ResetRow() bool {
return s.RowTick == 0
}
func NewSynthState() *SynthState {
s := new(SynthState)
s.RandSeed = 1
return s
}