mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
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.
56 lines
1.2 KiB
Go
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
|
|
}
|