mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-25 18:00:37 -04:00
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.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
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
|
|
}
|