| 1 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build darwin || (linux && !android) || windows |
| 6 |
|
| 7 |
package al |
| 8 |
|
| 9 |
/* |
| 10 |
#cgo darwin CFLAGS: -DGOOS_darwin |
| 11 |
#cgo linux CFLAGS: -DGOOS_linux |
| 12 |
#cgo windows CFLAGS: -DGOOS_windows |
| 13 |
#cgo darwin LDFLAGS: -framework OpenAL |
| 14 |
#cgo linux LDFLAGS: -lopenal |
| 15 |
#cgo windows LDFLAGS: -lOpenAL32 |
| 16 |
|
| 17 |
#ifdef GOOS_darwin |
| 18 |
#include <stdlib.h> |
| 19 |
#include <OpenAL/alc.h> |
| 20 |
#endif |
| 21 |
|
| 22 |
#ifdef GOOS_linux |
| 23 |
#include <stdlib.h> |
| 24 |
#include <AL/alc.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#ifdef GOOS_windows |
| 28 |
#include <windows.h> |
| 29 |
#include <stdlib.h> |
| 30 |
#include <AL/alc.h> |
| 31 |
#endif |
| 32 |
*/ |
| 33 |
import "C" |
| 34 |
import "unsafe" |
| 35 |
|
| 36 |
/* |
| 37 |
On Ubuntu 14.04 'Trusty', you may have to install these libraries: |
| 38 |
sudo apt-get install libopenal-dev |
| 39 |
*/ |
| 40 |
|
| 41 |
func alcGetError(d unsafe.Pointer) int32 { |
| 42 |
dev := (*C.ALCdevice)(d) |
| 43 |
return int32(C.alcGetError(dev)) |
| 44 |
} |
| 45 |
|
| 46 |
func alcOpenDevice(name string) unsafe.Pointer { |
| 47 |
n := C.CString(name) |
| 48 |
defer C.free(unsafe.Pointer(n)) |
| 49 |
|
| 50 |
return (unsafe.Pointer)(C.alcOpenDevice((*C.ALCchar)(unsafe.Pointer(n)))) |
| 51 |
} |
| 52 |
|
| 53 |
func alcCloseDevice(d unsafe.Pointer) bool { |
| 54 |
dev := (*C.ALCdevice)(d) |
| 55 |
return C.alcCloseDevice(dev) == C.ALC_TRUE |
| 56 |
} |
| 57 |
|
| 58 |
func alcCreateContext(d unsafe.Pointer, attrs []int32) unsafe.Pointer { |
| 59 |
dev := (*C.ALCdevice)(d) |
| 60 |
return (unsafe.Pointer)(C.alcCreateContext(dev, nil)) |
| 61 |
} |
| 62 |
|
| 63 |
func alcMakeContextCurrent(c unsafe.Pointer) bool { |
| 64 |
ctx := (*C.ALCcontext)(c) |
| 65 |
return C.alcMakeContextCurrent(ctx) == C.ALC_TRUE |
| 66 |
} |
| 67 |
|
| 68 |
func alcDestroyContext(c unsafe.Pointer) { |
| 69 |
C.alcDestroyContext((*C.ALCcontext)(c)) |
| 70 |
} |