mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-22 06:54:34 -04:00
Separate Synth and SynthState: SynthState is the part that Render changes.
This should make testing easier, as Synth can be assumed to stay the same during each call. Synth is also the part that we can parse from .asm/.json file and a Patch can be compiled into a synth. Synth can be eventually made quite opaque to the user. The user should not need to worry about opcodes etc.
This commit is contained in:
10
song/song.go
10
song/song.go
@ -86,13 +86,11 @@ func (s *Song) FirstTrackVoice(track int) int {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (s *Song) Render() ([]float32, error) {
|
||||
func (s *Song) Render(synth *bridge.Synth, state *bridge.SynthState) ([]float32, error) {
|
||||
err := s.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
synth := bridge.NewSynthState()
|
||||
synth.SetPatch(s.Patch)
|
||||
curVoices := make([]int, len(s.Tracks))
|
||||
for i := range curVoices {
|
||||
curVoices[i] = s.FirstTrackVoice(i)
|
||||
@ -113,17 +111,17 @@ func (s *Song) Render() ([]float32, error) {
|
||||
if note == 1 { // anything but hold causes an action.
|
||||
continue // TODO: can hold be actually something else than 1?
|
||||
}
|
||||
synth.Release(curVoices[t])
|
||||
state.Release(curVoices[t])
|
||||
if note > 1 {
|
||||
curVoices[t]++
|
||||
first := s.FirstTrackVoice(t)
|
||||
if curVoices[t] >= first+s.Tracks[t].NumVoices {
|
||||
curVoices[t] = first
|
||||
}
|
||||
synth.Trigger(curVoices[t], note)
|
||||
state.Trigger(curVoices[t], note)
|
||||
}
|
||||
}
|
||||
samples, _, _ := synth.RenderTime(buffer[2*totaln:], rowtime)
|
||||
samples, _, _ := synth.RenderTime(state, buffer[2*totaln:], rowtime)
|
||||
totaln += samples
|
||||
}
|
||||
return buffer, nil
|
||||
|
@ -38,7 +38,12 @@ func TestSongRender(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("NewSong failed: %v", err)
|
||||
}
|
||||
buffer, err := song.Render()
|
||||
synth, err := bridge.Compile(patch)
|
||||
if err != nil {
|
||||
t.Fatalf("Compiling patch failed: %v", err)
|
||||
}
|
||||
state := bridge.NewSynthState()
|
||||
buffer, err := song.Render(synth, state)
|
||||
if err != nil {
|
||||
t.Fatalf("Render failed: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user