| 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 |
package al |
| 6 |
|
| 7 |
/* |
| 8 |
#include <stdlib.h> |
| 9 |
#include <dlfcn.h> |
| 10 |
#include <AL/al.h> |
| 11 |
#include <AL/alc.h> |
| 12 |
|
| 13 |
ALCint call_alcGetError(LPALCGETERROR fn, ALCdevice* d) { |
| 14 |
return fn(d); |
| 15 |
} |
| 16 |
|
| 17 |
ALCdevice* call_alcOpenDevice(LPALCOPENDEVICE fn, const ALCchar* name) { |
| 18 |
return fn(name); |
| 19 |
} |
| 20 |
|
| 21 |
ALCboolean call_alcCloseDevice(LPALCCLOSEDEVICE fn, ALCdevice* d) { |
| 22 |
return fn(d); |
| 23 |
} |
| 24 |
|
| 25 |
ALCcontext* call_alcCreateContext(LPALCCREATECONTEXT fn, ALCdevice* d, const ALCint* attrs) { |
| 26 |
return fn(d, attrs); |
| 27 |
} |
| 28 |
|
| 29 |
ALCboolean call_alcMakeContextCurrent(LPALCMAKECONTEXTCURRENT fn, ALCcontext* c) { |
| 30 |
return fn(c); |
| 31 |
} |
| 32 |
|
| 33 |
void call_alcDestroyContext(LPALCDESTROYCONTEXT fn, ALCcontext* c) { |
| 34 |
return fn(c); |
| 35 |
} |
| 36 |
*/ |
| 37 |
import "C" |
| 38 |
import ( |
| 39 |
"sync" |
| 40 |
"unsafe" |
| 41 |
) |
| 42 |
|
| 43 |
var once sync.Once |
| 44 |
|
| 45 |
func alcGetError(d unsafe.Pointer) int32 { |
| 46 |
dev := (*C.ALCdevice)(d) |
| 47 |
return int32(C.call_alcGetError(alcGetErrorFunc, dev)) |
| 48 |
} |
| 49 |
|
| 50 |
func alcOpenDevice(name string) unsafe.Pointer { |
| 51 |
once.Do(initAL) |
| 52 |
n := C.CString(name) |
| 53 |
defer C.free(unsafe.Pointer(n)) |
| 54 |
|
| 55 |
return (unsafe.Pointer)(C.call_alcOpenDevice(alcOpenDeviceFunc, (*C.ALCchar)(unsafe.Pointer(n)))) |
| 56 |
} |
| 57 |
|
| 58 |
func alcCloseDevice(d unsafe.Pointer) bool { |
| 59 |
dev := (*C.ALCdevice)(d) |
| 60 |
return C.call_alcCloseDevice(alcCloseDeviceFunc, dev) == C.AL_TRUE |
| 61 |
} |
| 62 |
|
| 63 |
func alcCreateContext(d unsafe.Pointer, attrs []int32) unsafe.Pointer { |
| 64 |
dev := (*C.ALCdevice)(d) |
| 65 |
// TODO(jbd): Handle attrs. |
| 66 |
return (unsafe.Pointer)(C.call_alcCreateContext(alcCreateContextFunc, dev, nil)) |
| 67 |
} |
| 68 |
|
| 69 |
func alcMakeContextCurrent(c unsafe.Pointer) bool { |
| 70 |
ctx := (*C.ALCcontext)(c) |
| 71 |
return C.call_alcMakeContextCurrent(alcMakeContextCurrentFunc, ctx) == C.AL_TRUE |
| 72 |
} |
| 73 |
|
| 74 |
func alcDestroyContext(c unsafe.Pointer) { |
| 75 |
C.call_alcDestroyContext(alcDestroyContextFunc, (*C.ALCcontext)(c)) |
| 76 |
} |