mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
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:
parent
ff4155a08e
commit
5bbec75120
14
audio.go
14
audio.go
@ -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.
|
||||
//
|
||||
|
Reference in New Issue
Block a user