-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (42 loc) · 1.08 KB
/
main.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
package main
import (
"flag"
"github.com/xlab/portaudio-go/portaudio"
"log"
"os"
"time"
)
const (
framesPerPacket = 4096
bitDepth = 16
audioChannels = 2
sampleFormat = portaudio.PaInt16
)
func main() {
var filename string
// flags declaration using flag package
flag.StringVar(&filename, "f", "", "Specify filename. No default")
flag.Parse() // after declaring flags we need to call it
if err := portaudio.Initialize(); err != 0 {
log.Fatalln("PortAudio init error:", err)
}
f, err := os.Open(filename)
if err != nil {
log.Fatalln(err)
}
defer f.Close()
alacReader := NewAlacReader(f, bitDepth)
defer alacReader.Close()
if err := alacReader.Decode(); err != nil {
log.Fatalln(err)
}
var stream *portaudio.Stream
if err := portaudio.OpenDefaultStream(&stream, 0, audioChannels, sampleFormat, alacReader.SampleRate(),
framesPerPacket, alacReader.StreamCallback, nil); err != 0 {
log.Fatalln("PortAudio error:", err)
}
if err := portaudio.StartStream(stream); err != 0 {
log.Fatalln("PortAudio error:", err)
}
time.Sleep(166 * time.Second)
}