diff --git a/synth.go b/synth.go index 3093805..40236cf 100644 --- a/synth.go +++ b/synth.go @@ -39,9 +39,9 @@ func Play(synth Synth, song Song) ([]float32, []float32, error) { } initialCapacity := song.Score.LengthInRows() * song.SamplesPerRow() * 2 buffer := make([]float32, 0, initialCapacity) - syncBuffer := make([]float32, 0, initialCapacity) rowbuffer := make([]float32, song.SamplesPerRow()*2) numSyncs := song.Patch.NumSyncs() + syncBuffer := make([]float32, 0, (song.Score.LengthInRows()*song.SamplesPerRow()+255)/256*(1+numSyncs)) syncRowBuffer := make([]float32, ((song.SamplesPerRow()+255)/256)*(1+numSyncs)) for row := 0; row < song.Score.LengthInRows(); row++ { patternRow := row % song.Score.RowsPerPattern @@ -87,7 +87,7 @@ func Play(synth Synth, song Song) ([]float32, []float32, error) { } rowtime += time buffer = append(buffer, rowbuffer[:samples*2]...) - syncBuffer = append(syncBuffer, syncRowBuffer[:syncs]...) + syncBuffer = append(syncBuffer, syncRowBuffer[:syncs*(1+numSyncs)]...) if tries > 100 { return nil, nil, fmt.Errorf("Song speed modulation likely so slow that row never advances; error at pattern %v, row %v", pattern, patternRow) } diff --git a/vm/interpreter_test.go b/vm/interpreter_test.go index 591a8a8..790cc38 100644 --- a/vm/interpreter_test.go +++ b/vm/interpreter_test.go @@ -45,7 +45,7 @@ func TestAllRegressionTests(t *testing.T) { if err != nil { t.Fatalf("Compiling patch failed: %v", err) } - buffer, _, err := sointu.Play(synth, song) + buffer, syncBuffer, err := sointu.Play(synth, song) buffer = buffer[:song.Score.LengthInRows()*song.SamplesPerRow()*2] // extend to the nominal length always. if err != nil { t.Fatalf("Play failed: %v", err) @@ -72,6 +72,9 @@ func TestAllRegressionTests(t *testing.T) { } } compareToRawFloat32(t, buffer, testname+".raw") + if strings.Contains(testname, "sync") { + compareToRawFloat32(t, syncBuffer, testname+"_syncbuf.raw") + } }) } }