feat: add the ability to use Sointu as a sync-tracker

There is a new "sync" opcode that saves the top-most signal every 256 samples to the new "syncBuffer" output. Additionally, you can enable saving the current fractional row as sync[0], avoiding calculating the beat in the shader, but also calculating the beat correctly when the beat is modulated.
This commit is contained in:
vsariola
2021-03-09 23:47:27 +02:00
parent a3bdf565fd
commit 99dbdfe223
30 changed files with 375 additions and 88 deletions

View File

@ -33,6 +33,7 @@ func main() {
list := flag.Bool("l", false, "Do not write files; just list files that would change instead.")
stdout := flag.Bool("s", false, "Do not write files; write to standard output instead.")
help := flag.Bool("h", false, "Show help.")
rowsync := flag.Bool("r", false, "Write the current fractional row as sync #0")
library := flag.Bool("a", false, "Compile Sointu into a library. Input files are not needed.")
jsonOut := flag.Bool("j", false, "Output the song as .json file instead of compiling.")
yamlOut := flag.Bool("y", false, "Output the song as .yml file instead of compiling.")
@ -53,9 +54,9 @@ func main() {
if compile || *library {
var err error
if *tmplDir != "" {
comp, err = compiler.NewFromTemplates(*targetOs, *targetArch, *output16bit, *tmplDir)
comp, err = compiler.NewFromTemplates(*targetOs, *targetArch, *output16bit, *rowsync, *tmplDir)
} else {
comp, err = compiler.New(*targetOs, *targetArch, *output16bit)
comp, err = compiler.New(*targetOs, *targetArch, *output16bit, *rowsync)
}
if err != nil {
fmt.Fprintf(os.Stderr, `error creating compiler: %v`, err)

View File

@ -17,5 +17,7 @@ func main() {
}
defer audioContext.Close()
synthService := bridge.BridgeService{}
gioui.Main(audioContext, synthService)
// TODO: native track does not support syncing at the moment (which is why
// we pass nil), as the native bridge does not support sync data
gioui.Main(audioContext, synthService, nil)
}

View File

@ -92,7 +92,7 @@ func main() {
synth.Release(i)
}
}
buffer, err := sointu.Play(synth, song) // render the song to calculate its length
buffer, _, err := sointu.Play(synth, song) // render the song to calculate its length
if err != nil {
return fmt.Errorf("sointu.Play failed: %v", err)
}

View File

@ -1,21 +1,33 @@
package main
import (
"flag"
"fmt"
"os"
"github.com/vsariola/sointu/oto"
"github.com/vsariola/sointu/rpc"
"github.com/vsariola/sointu/tracker/gioui"
"github.com/vsariola/sointu/vm"
)
func main() {
syncAddress := flag.String("address", "", "remote RPC server where to send sync data")
flag.Parse()
audioContext, err := oto.NewContext()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer audioContext.Close()
var syncChannel chan<- []float32
if *syncAddress != "" {
syncChannel, err = rpc.Sender(*syncAddress)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
synthService := vm.SynthService{}
gioui.Main(audioContext, synthService)
gioui.Main(audioContext, synthService, syncChannel)
}