mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
refactor!: rename SynthService to Synther and related types
The -er suffix is more idiomatic for single method interfaces, and the interface is not doing much more than converting the patch to a synth. Names were updated throughout the project to reflect this change. In particular, the "Service" in SynthService was not telling anything helpful.
This commit is contained in:
parent
e4a2ed9f32
commit
0a67129a0c
@ -13,17 +13,17 @@ import (
|
||||
"github.com/vsariola/sointu/vm"
|
||||
)
|
||||
|
||||
type BridgeService struct {
|
||||
type NativeSynther struct {
|
||||
}
|
||||
|
||||
type BridgeSynth C.Synth
|
||||
type NativeSynth C.Synth
|
||||
|
||||
func (s BridgeService) Compile(patch sointu.Patch, bpm int) (sointu.Synth, error) {
|
||||
func (s NativeSynther) Synth(patch sointu.Patch, bpm int) (sointu.Synth, error) {
|
||||
synth, err := Synth(patch, bpm)
|
||||
return synth, err
|
||||
}
|
||||
|
||||
func Synth(patch sointu.Patch, bpm int) (*BridgeSynth, error) {
|
||||
func Synth(patch sointu.Patch, bpm int) (*NativeSynth, error) {
|
||||
s := new(C.Synth)
|
||||
if n := patch.NumDelayLines(); n > 64 {
|
||||
return nil, fmt.Errorf("native bridge has currently a hard limit of 64 delaylines; patch uses %v", n)
|
||||
@ -55,7 +55,7 @@ func Synth(patch sointu.Patch, bpm int) (*BridgeSynth, error) {
|
||||
s.NumVoices = C.uint(comPatch.NumVoices)
|
||||
s.Polyphony = C.uint(comPatch.PolyphonyBitmask)
|
||||
s.RandSeed = 1
|
||||
return (*BridgeSynth)(s), nil
|
||||
return (*NativeSynth)(s), nil
|
||||
}
|
||||
|
||||
// Render renders until the buffer is full or the modulated time is reached, whichever
|
||||
@ -79,7 +79,7 @@ func Synth(patch sointu.Patch, bpm int) (*BridgeSynth, error) {
|
||||
// time > maxtime, as it is modulated and the time could advance by 2 or more, so the loop
|
||||
// exit condition would fire when the time is already past maxtime.
|
||||
// Under no conditions, nsamples >= len(buffer)/2 i.e. guaranteed to never overwrite the buffer.
|
||||
func (bridgesynth *BridgeSynth) Render(buffer sointu.AudioBuffer, maxtime int) (int, int, error) {
|
||||
func (bridgesynth *NativeSynth) Render(buffer sointu.AudioBuffer, maxtime int) (int, int, error) {
|
||||
synth := (*C.Synth)(bridgesynth)
|
||||
// TODO: syncBuffer is not getting passed to cgo; do we want to even try to support the syncing with the native bridge
|
||||
if len(buffer)%1 == 1 {
|
||||
@ -95,7 +95,7 @@ func (bridgesynth *BridgeSynth) Render(buffer sointu.AudioBuffer, maxtime int) (
|
||||
}
|
||||
|
||||
// Trigger is part of C.Synths' implementation of sointu.Synth interface
|
||||
func (bridgesynth *BridgeSynth) Trigger(voice int, note byte) {
|
||||
func (bridgesynth *NativeSynth) Trigger(voice int, note byte) {
|
||||
s := (*C.Synth)(bridgesynth)
|
||||
if voice < 0 || voice >= len(s.SynthWrk.Voices) {
|
||||
return
|
||||
@ -106,7 +106,7 @@ func (bridgesynth *BridgeSynth) Trigger(voice int, note byte) {
|
||||
}
|
||||
|
||||
// Release is part of C.Synths' implementation of sointu.Synth interface
|
||||
func (bridgesynth *BridgeSynth) Release(voice int) {
|
||||
func (bridgesynth *NativeSynth) Release(voice int) {
|
||||
s := (*C.Synth)(bridgesynth)
|
||||
if voice < 0 || voice >= len(s.SynthWrk.Voices) {
|
||||
return
|
||||
@ -115,7 +115,7 @@ func (bridgesynth *BridgeSynth) Release(voice int) {
|
||||
}
|
||||
|
||||
// Update
|
||||
func (bridgesynth *BridgeSynth) Update(patch sointu.Patch, bpm int) error {
|
||||
func (bridgesynth *NativeSynth) Update(patch sointu.Patch, bpm int) error {
|
||||
s := (*C.Synth)(bridgesynth)
|
||||
if n := patch.NumDelayLines(); n > 64 {
|
||||
return fmt.Errorf("native bridge has currently a hard limit of 64 delaylines; patch uses %v", n)
|
@ -40,7 +40,7 @@ func TestOscillatSine(t *testing.T) {
|
||||
}}}
|
||||
tracks := []sointu.Track{{NumVoices: 1, Order: []int{0}, Patterns: []sointu.Pattern{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}}}}
|
||||
song := sointu.Song{BPM: 100, RowsPerBeat: 4, Score: sointu.Score{RowsPerPattern: 16, Length: 1, Tracks: tracks}, Patch: patch}
|
||||
buffer, err := sointu.Play(bridge.BridgeService{}, song, false)
|
||||
buffer, err := sointu.Play(bridge.NativeSynther{}, song, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Render failed: %v", err)
|
||||
}
|
||||
@ -95,7 +95,7 @@ func TestAllRegressionTests(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not parse the .yml file: %v", err)
|
||||
}
|
||||
buffer, err := sointu.Play(bridge.BridgeService{}, song, false)
|
||||
buffer, err := sointu.Play(bridge.NativeSynther{}, song, false)
|
||||
buffer = buffer[:song.Score.LengthInRows()*song.SamplesPerRow()] // extend to the nominal length always.
|
||||
if err != nil {
|
||||
t.Fatalf("Play failed: %v", err)
|
@ -13,22 +13,22 @@ import (
|
||||
|
||||
//go:generate go run generate/generate.go
|
||||
|
||||
// Interpreter is a pure-Go bytecode interpreter for the Sointu VM bytecode. It
|
||||
// GoSynth is a pure-Go bytecode interpreter for the Sointu VM bytecode. It
|
||||
// can only simulate bytecode compiled for AllFeatures, as the opcodes hard
|
||||
// coded in it for speed. If you are interested exactly how opcodes / units
|
||||
// work, studying Interpreter.Render is a good place to start.
|
||||
// work, studying GoSynth.Render is a good place to start.
|
||||
//
|
||||
// Internally, it uses software stack with practically no limitations in the
|
||||
// number of signals, so be warned that if you compose patches for it, they
|
||||
// might not work with the x87 implementation, as it has only 8-level stack.
|
||||
type Interpreter struct {
|
||||
type GoSynth struct {
|
||||
bytePatch BytePatch
|
||||
stack []float32
|
||||
synth synth
|
||||
delaylines []delayline
|
||||
}
|
||||
|
||||
type SynthService struct {
|
||||
type GoSynther struct {
|
||||
}
|
||||
|
||||
const MAX_VOICES = 32
|
||||
@ -92,27 +92,27 @@ func Synth(patch sointu.Patch, bpm int) (sointu.Synth, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error compiling %v", err)
|
||||
}
|
||||
ret := &Interpreter{bytePatch: *bytePatch, stack: make([]float32, 0, 4), delaylines: make([]delayline, patch.NumDelayLines())}
|
||||
ret := &GoSynth{bytePatch: *bytePatch, stack: make([]float32, 0, 4), delaylines: make([]delayline, patch.NumDelayLines())}
|
||||
ret.synth.randSeed = 1
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (s SynthService) Compile(patch sointu.Patch, bpm int) (sointu.Synth, error) {
|
||||
func (s GoSynther) Synth(patch sointu.Patch, bpm int) (sointu.Synth, error) {
|
||||
synth, err := Synth(patch, bpm)
|
||||
return synth, err
|
||||
}
|
||||
|
||||
func (s *Interpreter) Trigger(voiceIndex int, note byte) {
|
||||
func (s *GoSynth) Trigger(voiceIndex int, note byte) {
|
||||
s.synth.voices[voiceIndex] = voice{}
|
||||
s.synth.voices[voiceIndex].note = note
|
||||
s.synth.voices[voiceIndex].sustain = true
|
||||
}
|
||||
|
||||
func (s *Interpreter) Release(voiceIndex int) {
|
||||
func (s *GoSynth) Release(voiceIndex int) {
|
||||
s.synth.voices[voiceIndex].sustain = false
|
||||
}
|
||||
|
||||
func (s *Interpreter) Update(patch sointu.Patch, bpm int) error {
|
||||
func (s *GoSynth) Update(patch sointu.Patch, bpm int) error {
|
||||
bytePatch, err := Encode(patch, AllFeatures{}, bpm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error compiling %v", err)
|
||||
@ -140,7 +140,7 @@ func (s *Interpreter) Update(patch sointu.Patch, bpm int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Interpreter) Render(buffer sointu.AudioBuffer, maxtime int) (samples int, time int, renderError error) {
|
||||
func (s *GoSynth) Render(buffer sointu.AudioBuffer, maxtime int) (samples int, time int, renderError error) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
renderError = fmt.Errorf("render panicced: %v", err)
|
@ -43,7 +43,7 @@ func TestAllRegressionTests(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not parse the .yml file: %v", err)
|
||||
}
|
||||
buffer, err := sointu.Play(vm.SynthService{}, song, false)
|
||||
buffer, err := sointu.Play(vm.GoSynther{}, song, false)
|
||||
buffer = buffer[:song.Score.LengthInRows()*song.SamplesPerRow()] // extend to the nominal length always.
|
||||
if err != nil {
|
||||
t.Fatalf("Play failed: %v", err)
|
Reference in New Issue
Block a user