-
Notifications
You must be signed in to change notification settings - Fork 5
/
hello.go
61 lines (55 loc) · 1.34 KB
/
hello.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
60
61
package main
import (
"github.com/moriyoshi/pulsego"
"fmt"
)
func send(ch chan int, val int) {
ch <- val
}
func myMain(sync_ch chan int, pa *pulsego.PulseMainLoop) {
defer send(sync_ch, 0)
ctx := pa.NewContext("default", 0)
if ctx == nil {
fmt.Println("Failed to create a new context")
return
}
defer ctx.Dispose();
st := ctx.NewStream("default", &pulsego.PulseSampleSpec {
Format:pulsego.SAMPLE_FLOAT32LE, Rate:22500, Channels: 1 })
if st == nil {
fmt.Println("Failed to create a new stream")
return
}
defer st.Dispose()
st.ConnectToSink()
var samples []float32 = make([]float32, 65536)
period := 40
count := 0
v := -1
for {
for i := range samples {
if count < period / 2 {
samples[i] = -0.8
} else {
samples[i] = 0.8
}
count += 1;
if (count >= period) {
count = 0
}
if i % 40 == 0 {
if period < 10 || period > 100 { v = -v }
period += v
}
}
st.Write(samples, pulsego.SEEK_RELATIVE);
}
}
func main() {
pa := pulsego.NewPulseMainLoop();
defer pa.Dispose()
pa.Start()
sync_ch := make(chan int)
go myMain(sync_ch, pa)
<-sync_ch
}