func GenBuffers(numBuffers int) ([]Buffer, error) { if numBuffers == 0 { return nil, nil // AL guarantees that 0 will have no effect, so we'll save ourselves the C call } buf := make([]Buffer, numBuffers) C.alGenBuffers(C.ALsizei(C.int(numBuffers)), (*C.ALuint)(unsafe.Pointer(&buf[0]))) // Since a Buffer is a struct{C.ALuint} an array of Buffers is an array of ALuints if err := GetError(); err != nil { return nil, err } return buf, nil }
func (s *Sound) LoadPCMData() { format := 0 if s.Channels > 1 { switch s.BitsPerSample { case 8: format = C.AL_FORMAT_STEREO8 case 16: format = C.AL_FORMAT_STEREO16 } } else { switch s.BitsPerSample { case 8: format = C.AL_FORMAT_MONO8 case 16: format = C.AL_FORMAT_MONO16 } } C.alGenBuffers(1, &s.buffer) C.alBufferData(s.buffer, C.ALenum(format), unsafe.Pointer(&s.Data[0]), C.ALsizei(s.Size), C.ALsizei(s.Frequency)) }
// Not really any different from GenBuffers(1), except it returns a single buffer instead of a slice func GenBuffer() (buf Buffer, err error) { C.alGenBuffers(C.ALsizei(C.int(1)), &buf.buffer) err = GetError() return }
func alGenBuffers(n int) []Buffer { s := make([]Buffer, n) C.alGenBuffers(C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0]))) return s }
func GenBuffers(buffers []Buffer) { if len(buffers) > 0 { C.alGenBuffers(C.ALsizei(len(buffers)), (*C.ALuint)(&buffers[0])) } }
func GenBuffer() Buffer { var b C.ALuint C.alGenBuffers(1, &b) return Buffer(b) }