Change the sointu.h api to return -1, 0 or n>0 depending if buffer is full and/or row ended.

test_render_samples_api.c was added to test the api. bridge.go was modified to reflect that there is no need to check for row manually; su_render_samples already returns the information if a row has ended.
This commit is contained in:
Veikko Sariola
2020-10-24 13:00:08 +03:00
parent c9e8000c5f
commit 6e85ff674a
7 changed files with 158 additions and 38 deletions

View File

@ -2,6 +2,7 @@ package bridge
import "fmt"
import "unsafe"
import "math"
// #cgo CFLAGS: -I"${SRCDIR}/../include"
// #cgo LDFLAGS: "${SRCDIR}/../build/src/libsointu.a"
@ -83,16 +84,12 @@ func (s *SynthState) Release(voice int) {
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
// The default behaviour will be to have rows/beats disabled i.e.
// fill the whole buffer every call. This is a lot better default
// behaviour than leaving this 0 (Render would never render anything)
s.SamplesPerRow = math.MaxInt32
return s
}

View File

@ -5,7 +5,6 @@ import (
"encoding/binary"
"github.com/vsariola/sointu/bridge"
"io/ioutil"
"math"
"path"
"runtime"
"testing"
@ -34,7 +33,6 @@ func TestBridge(t *testing.T) {
// synthState->RandSeed = 1;
// initialized in NewSynthState
// synthState->RowLen = INT32_MAX;
s.RowLen = math.MaxInt32 // (why?)
// synthState->NumVoices = 1;
s.NumVoices = 1
// synthState->Synth.Voices[0].Note = 64;
@ -42,15 +40,15 @@ func TestBridge(t *testing.T) {
// retval = su_render_samples(buffer, su_max_samples / 2, synthState);
buffer := make([]float32, su_max_samples)
remaining := s.Render(buffer)
if remaining != 0 {
t.Fatalf("could not render full buffer, %v bytes remaining, expected %v", remaining, len(buffer))
if remaining > 0 {
t.Fatalf("could not render full buffer, %v bytes remaining, expected <= 0", remaining)
}
// synthState->Synth.Voices[0].Release++;
s.Synth.Voices[0].Release++
sbuffer := make([]float32, su_max_samples)
remaining = s.Render(sbuffer)
if remaining != 0 {
t.Fatalf("could not render second full buffer, %v bytes remaining, expected %v", remaining, len(buffer))
if remaining > 0 {
t.Fatalf("could not render second full buffer, %v bytes remaining, expected <= 0", remaining)
}
buffer = append(buffer, sbuffer...)
_, filename, _, _ := runtime.Caller(0)