diff options
Diffstat (limited to 'src/alc.zig')
-rw-r--r-- | src/alc.zig | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/src/alc.zig b/src/alc.zig index 68e12b3..405d8bc 100644 --- a/src/alc.zig +++ b/src/alc.zig @@ -16,21 +16,40 @@ // You should have received a copy of the GNU Lesser General Public License // along with zeal. If not, see <https://www.gnu.org/licenses/>. -usingnamespace @cImport({ @cInclude("AL/alc.h"); }); +usingnamespace @cImport({ + @cInclude("AL/alc.h"); + @cInclude("AL/alext.h"); +}); +/// Opaque device handle. pub const Device = ALCdevice; +/// Opaque context handle. pub const Context = ALCcontext; + pub const Error = error { + /// Invalid device handle. InvalidDevice, + /// Invalid context handle. InvalidContext, + /// Invalid enum parameter passed to an ALC call. InvalidEnum, + /// Invalid value parameter passed to an ALC call. InvalidValue, + /// Out of memory. OutOfMemory, }; +pub const FALSE = ALC_FALSE; +pub const TRUE = ALC_TRUE; +pub const DONT_CARE = ALC_DONT_CATE_SOFT; + +/// Context creation key to specify whether to enable HRTF +/// (either `FALSE`, `TRUE` or `DONT_CARE`). +pub const HRTF = ALC_HRTF_SOFT; + /// Create and attach a context to the given device. -pub fn createContext(device: *Device, attrlist: [*c]const ALCint) !*Context { - if (alcCreateContext(device, attrlist)) |context| +pub fn createContext(device: *Device, attributes: [:0]const i32) !*Context { + if (alcCreateContext(device, attributes.ptr)) |context| return context; return switch (alcGetError(device)) { ALC_INVALID_DEVICE => Error.InvalidDevice, @@ -42,7 +61,7 @@ pub fn createContext(device: *Device, attrlist: [*c]const ALCint) !*Context { /// Make the given context the active process-wide context. /// Passing NULL clears the active context. pub fn makeContextCurrent(context: ?*Context) !void { - if (alcMakeContextCurrent(context) == ALC_TRUE) + if (alcMakeContextCurrent(context) == TRUE) return; if (alcGetError(null) == ALC_INVALID_CONTEXT) return Error.InvalidContext; @@ -56,11 +75,9 @@ pub fn destroyContext(context: *Context) !void { return Error.InvalidContext; } -/// Returns the currently active context. -pub fn getCurrentContext() *Context { - if (alcGetCurrentContext()) |context| - return context; - unreachable; +/// Return the currently active context. +pub fn getCurrentContext() ?*Context { + return alcGetCurrentContext(); } /// Return the device that a particular context is attached to. @@ -73,8 +90,9 @@ pub fn getContextsDevice(context: *Context) !*Device { } /// Open the named playback device. -pub fn openDevice(device_name: [*c]const u8) !*Device { - if (alcOpenDevice(device_name)) |device| +pub fn openDevice(name: ?[]const u8) !*Device { + const name_ptr = if (name == null) null else name.?.ptr; + if (alcOpenDevice(name_ptr)) |device| return device; return switch (alcGetError(null)) { ALC_INVALID_VALUE => Error.InvalidValue, @@ -85,7 +103,7 @@ pub fn openDevice(device_name: [*c]const u8) !*Device { /// Close the given playback device. pub fn closeDevice(device: *Device) !void { - if (alcCloseDevice(device) == ALC_TRUE) + if (alcCloseDevice(device) == TRUE) return; if (alcGetError(device) == ALC_INVALID_DEVICE) return Error.InvalidDevice; |