-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpassthrough.go
59 lines (49 loc) · 1.31 KB
/
passthrough.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"github.com/xthexder/go-jack"
)
var channels int = 2
var PortsIn []*jack.Port
var PortsOut []*jack.Port
func process(nframes uint32) int {
for i, in := range PortsIn {
samplesIn := in.GetBuffer(nframes)
samplesOut := PortsOut[i].GetBuffer(nframes)
for i2, sample := range samplesIn {
samplesOut[i2] = sample
}
}
return 0
}
func main() {
client, status := jack.ClientOpen("Go Passthrough", jack.NoStartServer)
if status != 0 {
fmt.Println("Status:", jack.StrError(status))
return
}
defer client.Close()
for i := 0; i < channels; i++ {
portIn := client.PortRegister(fmt.Sprintf("in_%d", i), jack.DEFAULT_AUDIO_TYPE, jack.PortIsInput, 0)
PortsIn = append(PortsIn, portIn)
}
for i := 0; i < channels; i++ {
portOut := client.PortRegister(fmt.Sprintf("out_%d", i), jack.DEFAULT_AUDIO_TYPE, jack.PortIsOutput, 0)
PortsOut = append(PortsOut, portOut)
}
if code := client.SetProcessCallback(process); code != 0 {
fmt.Println("Failed to set process callback:", jack.StrError(code))
return
}
shutdown := make(chan struct{})
client.OnShutdown(func() {
fmt.Println("Shutting down")
close(shutdown)
})
if code := client.Activate(); code != 0 {
fmt.Println("Failed to activate client:", jack.StrError(code))
return
}
fmt.Println(client.GetName())
<-shutdown
}