| OLD | NEW |
| (Empty) |
| 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 // +build darwin | |
| 6 | |
| 7 // Package alc provides OpenAL's ALC (Audio Library Context) bindings for Go. | |
| 8 package alc | |
| 9 | |
| 10 /* | |
| 11 #cgo darwin CFLAGS: -DGOOS_darwin | |
| 12 #cgo darwin LDFLAGS: -framework OpenAL | |
| 13 | |
| 14 #ifdef GOOS_darwin | |
| 15 #include <stdlib.h> | |
| 16 #include <OpenAL/alc.h> | |
| 17 #endif | |
| 18 */ | |
| 19 import "C" | |
| 20 import "unsafe" | |
| 21 | |
| 22 // Error returns one of these values. | |
| 23 const ( | |
| 24 InvalidDevice = 0xA001 | |
| 25 InvalidContext = 0xA002 | |
| 26 InvalidEnum = 0xA003 | |
| 27 InvalidValue = 0xA004 | |
| 28 OutOfMemory = 0xA005 | |
| 29 ) | |
| 30 | |
| 31 // Device represents an audio device. | |
| 32 type Device struct { | |
| 33 d *C.ALCdevice | |
| 34 } | |
| 35 | |
| 36 // Error returns the last known error from the current device. | |
| 37 func (d *Device) Error() int32 { | |
| 38 return int32(C.alcGetError(d.d)) | |
| 39 } | |
| 40 | |
| 41 // Context represents a context created in the OpenAL layer. A valid current | |
| 42 // context is required to run OpenAL functions. | |
| 43 // The returned context will be available process-wide if it's made the | |
| 44 // current by calling MakeContextCurrent. | |
| 45 type Context struct { | |
| 46 c *C.ALCcontext | |
| 47 } | |
| 48 | |
| 49 // Open opens a new device in the OpenAL layer. | |
| 50 func Open(name string) *Device { | |
| 51 n := C.CString(name) | |
| 52 defer C.free(unsafe.Pointer(n)) | |
| 53 return &Device{d: C.alcOpenDevice((*C.ALCchar)(unsafe.Pointer(n)))} | |
| 54 } | |
| 55 | |
| 56 // Close closes the device. | |
| 57 func (d *Device) Close() bool { | |
| 58 return C.alcCloseDevice(d.d) == 1 | |
| 59 } | |
| 60 | |
| 61 // CreateContext creates a new context. | |
| 62 func (d *Device) CreateContext(attrs []int32) *Context { | |
| 63 // TODO(jbd): Handle attributes. | |
| 64 c := C.alcCreateContext(d.d, nil) | |
| 65 return &Context{c: c} | |
| 66 } | |
| 67 | |
| 68 // MakeContextCurrent makes a context current process-wide. | |
| 69 func MakeContextCurrent(c *Context) bool { | |
| 70 return C.alcMakeContextCurrent(c.c) == 1 | |
| 71 } | |
| OLD | NEW |