alc_android.go 1.8 KB

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