Change the Render function in bridge.go to return a tuple of: number of samples rendered; bool indicating if rowend was reached; and a possible error.

The callbacks are gone; the row looping is the job of the user which is probably better for everyone.
This commit is contained in:
Veikko Sariola
2020-10-26 08:30:43 +02:00
parent acab824523
commit 470ba28592
3 changed files with 37 additions and 40 deletions

View File

@ -98,10 +98,13 @@ func (s *Song) Render() ([]float32, error) {
for i := range curVoices {
curVoices[i] = s.FirstTrackVoice(i)
}
processRow := func(row int) {
if row >= s.TotalRows() {
return
}
samples := s.Samples
if samples < 0 {
samples = s.TotalRows() * s.SamplesPerRow()
}
buffer := make([]float32, samples*2)
totaln := 0
for row := 0; row < s.TotalRows(); row++ {
patternRow := row % s.PatternRows()
pattern := row / s.PatternRows()
for t := range s.Tracks {
@ -119,17 +122,8 @@ func (s *Song) Render() ([]float32, error) {
synth.Trigger(curVoices[t], note)
}
}
n, _, _ := synth.Render(buffer[2*totaln:])
totaln += n
}
samples := s.Samples
if samples < 0 {
samples = s.TotalRows() * s.SamplesPerRow()
}
buffer := make([]float32, samples*2)
row := 0
processRow(0)
synth.Render(buffer, s.TotalRows(), func() {
row++
processRow(row)
})
return buffer, nil
}