/
gaudio.go
99 lines (91 loc) · 2.83 KB
/
gaudio.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"github.com/ajhager/vox"
"path/filepath"
"strconv"
"time"
)
func errTest(err error) bool {
if err != nil {
panic(err)
return true
} else {
return false
}
}
func getSongLength(song vox.Song) int {
lines := song.Lines()
tick := song.TicksPerLine()
rate := int(vox.TicksPerSecond())
return lines * tick / rate
}
func studder(songPath string, studderTime int) {
songName := filepath.Base(songPath)
errTest(vox.Init("", 44100, 2, 0))
println("Vox!\nv" + vox.Version + "\n")
println("Playing song \"" + songName + "\"...")
defer vox.Quit()
song, err := vox.Open(songPath)
errTest(err)
song.SetLooping(false)
defer song.Close()
song.Play()
for !song.Finished() {
println("Line " + strconv.Itoa(song.Line()) + ", Volume " + strconv.Itoa(song.Volume()) + "%")
song.Pause()
time.Sleep(time.Duration(studderTime) * time.Millisecond)
song.Play()
time.Sleep(time.Duration(studderTime) * time.Millisecond)
}
}
func playInFull(songPath string) {
songName := filepath.Base(songPath)
errTest(vox.Init("", 44100, 2, 0))
println("Vox!\nv" + vox.Version + "\n")
println("Playing song \"" + songName + "\"...")
defer vox.Quit()
song, err := vox.Open(songPath)
errTest(err)
song.SetLooping(false)
defer song.Close()
song.Play()
for !song.Finished() { } //TODO: Doesn't ever stop...
}
func playSprite(songPath string, piece int) {
songName := filepath.Base(songPath)
errTest(vox.Init("", 44100, 2, 0))
println("Vox!\nv" + vox.Version + "\n")
println("Playing song \"" + songName + "\"...")
defer vox.Quit()
song, err := vox.Open(songPath)
errTest(err)
song.SetLooping(false)
pieceLength := song.Lines() / 8 // Eight pieces per sprite
defer song.Close()
song.Seek(piece * pieceLength, 0)
song.Play()
for song.Line() < ((piece + 1) * pieceLength - 1) {}
time.Sleep(time.Duration(getSongLength(*song)) * time.Second)
song.Pause()
}
func main() {
//playInFull("examples/simple_examples/fm.sunvox")
//studder("examples/kostya_m - Midnight.sunvox", 123)
//playInFull("examples/kostya_m - Midnight.sunvox")
//playInFull("sprite1.sunvox")
playSprite("sprite1.sunvox", 4)
playSprite("sprite1.sunvox", 4)
playSprite("sprite1.sunvox", 5)
playSprite("sprite1.sunvox", 7) // TODO: Below this line won't play!
playSprite("sprite1.sunvox", 7)
playSprite("sprite1.sunvox", 5)
playSprite("sprite1.sunvox", 4)
playSprite("sprite1.sunvox", 2)
playSprite("sprite1.sunvox", 0)
playSprite("sprite1.sunvox", 0)
playSprite("sprite1.sunvox", 2)
playSprite("sprite1.sunvox", 4)
playSprite("sprite1.sunvox", 4)
playSprite("sprite1.sunvox", 2)
playSprite("sprite1.sunvox", 2)
}