/
out.go
50 lines (41 loc) · 922 Bytes
/
out.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
// Package portaudio is for modular binding of mix to audio interface via PortAudio
package portaudio
import (
"github.com/gordonklaus/portaudio"
"gopkg.in/mix.v0/bind/sample"
"gopkg.in/mix.v0/bind/spec"
)
var outPortaudioStream *portaudio.Stream
func ConfigureOutput(s spec.AudioSpec) {
var err error
outSpec = &s
portaudio.Initialize()
outPortaudioStream, err = portaudio.OpenDefaultStream(0, s.Channels, s.Freq, 0, outPortaudioStreamCallback)
noErr(err)
noErr(outPortaudioStream.Start())
}
func TeardownOutput() {
// noErr(out.Stop())
// noErr(out.Close())
portaudio.Terminate()
}
/*
*
private */
var (
outSpec *spec.AudioSpec
)
func outPortaudioStreamCallback(out [][]float32) {
var smp []sample.Value
for s := range out[0] {
smp = sample.OutNext()
for c := 0; c < outSpec.Channels; c++ {
out[c][s] = float32(smp[c])
}
}
}
func noErr(err error) {
if err != nil {
panic(err)
}
}