mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-26 08:54:56 -04:00
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.
This commit is contained in:
committed by
Veikko Sariola
parent
af14cd310b
commit
7aac3917b7
55
bridge/bridge.go.in
Normal file
55
bridge/bridge.go.in
Normal file
@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user