forked from timshannon/go-openal
/
example.go
42 lines (32 loc) · 796 Bytes
/
example.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
package main
import (
"github.com/timshannon/go-openal/openal"
"io/ioutil"
)
func main() {
device := openal.OpenDevice("")
context := device.CreateContext()
context.Activate()
//listener := new(openal.Listener)
source := openal.NewSource()
//source.SetPitch(1)
//source.SetGain(1)
//position := &openal.Vector{0, 0, 0}
//velocity := &openal.Vector{0, 0, 0}
//source.SetPosition(position)
//source.SetVelocity(velocity)
source.SetLooping(false)
buffer := openal.NewBuffer()
data, err := ioutil.ReadFile("welcome.wav")
if err != nil {
panic(err)
}
buffer.SetData(openal.FormatMono16, data, 44100)
source.SetBuffer(buffer)
source.Play()
for source.State() == openal.Playing {
//loop long enough to let the wave file finish
}
source.Pause()
context.Destroy()
}