mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
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:
57
rpc/rpc.go
Normal file
57
rpc/rpc.go
Normal file
@ -0,0 +1,57 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/rpc"
|
||||
)
|
||||
|
||||
type SyncServer struct {
|
||||
channel chan []float32
|
||||
}
|
||||
|
||||
func (s *SyncServer) Sync(syncData []float32, reply *int) error {
|
||||
select {
|
||||
case s.channel <- syncData:
|
||||
default:
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Receiver() (<-chan []float32, error) {
|
||||
c := make(chan []float32, 1)
|
||||
server := &SyncServer{channel: c}
|
||||
rpc.Register(server)
|
||||
rpc.HandleHTTP()
|
||||
l, e := net.Listen("tcp", ":31337")
|
||||
if e != nil {
|
||||
log.Fatal("listen error:", e)
|
||||
return nil, fmt.Errorf("net.listen failed: %v", e)
|
||||
}
|
||||
go func() {
|
||||
defer close(c)
|
||||
http.Serve(l, nil)
|
||||
}()
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func Sender(serverAddress string) (chan<- []float32, error) {
|
||||
c := make(chan []float32, 256)
|
||||
client, err := rpc.DialHTTP("tcp", serverAddress+":31337")
|
||||
if err != nil {
|
||||
log.Fatal("dialing:", err)
|
||||
return nil, fmt.Errorf("rpc.DialHTTP failed: %v", err)
|
||||
}
|
||||
go func() {
|
||||
for msg := range c {
|
||||
var reply int
|
||||
err = client.Call("SyncServer.Sync", msg, &reply)
|
||||
if err != nil {
|
||||
log.Fatal("SyncServer.Sync error:", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return c, nil
|
||||
}
|
Reference in New Issue
Block a user