refactor: rename sointu.Render as AudioBuffer.Fill

The Render name misleading as it did not do the same thing as normal
Synth.Render, because it disregarded time limits. Conceptually, as
the function modifies the state of the synth, it would be better to
be synth.Fill(audioBuffer), but we cannot define methods on
interfaces; therefore, it is audioBuffer.Fill(synth) now.
This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-10-19 11:11:42 +03:00
parent ff4155a08e
commit 5bbec75120
4 changed files with 22 additions and 23 deletions

View File

@ -3,6 +3,7 @@ package sointu
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"math"
)
@ -31,6 +32,19 @@ type (
}
)
// Fill fills the AudioBuffer using a Synth, disregarding all syncs and time
// limits. Note that this will change the state of the Synth.
func (buffer AudioBuffer) Fill(synth Synth) error {
s, _, err := synth.Render(buffer, math.MaxInt32)
if err != nil {
return fmt.Errorf("synth.Render failed: %v", err)
}
if s != len(buffer) {
return errors.New("in AudioBuffer.Fill, synth.Render should have filled the whole buffer but did not")
}
return nil
}
// Wav converts an AudioBuffer into a valid WAV-file, returned as a []byte
// array.
//