fix(sointu): fix sync data getting output from play & test it

This commit is contained in:
vsariola 2021-03-10 09:06:42 +02:00
parent df9713865f
commit 43ef6fa72c
2 changed files with 6 additions and 3 deletions

View File

@ -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)
}

View File

@ -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")
}
})
}
}