summary refs log tree commit diff
path: root/src/alc.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/alc.zig')
-rw-r--r--src/alc.zig67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/alc.zig b/src/alc.zig
index ca83bf6..b493a78 100644
--- a/src/alc.zig
+++ b/src/alc.zig
@@ -16,15 +16,12 @@
 // 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");
-    @cInclude("AL/alext.h");
-});
+const c = @import("cimport.zig");
 
 /// Opaque device handle.
-pub const Device = ALCdevice;
+pub const Device = c.ALCdevice;
 /// Opaque context handle.
-pub const Context = ALCcontext;
+pub const Context = c.ALCcontext;
 
 pub const Error = error {
     /// Invalid device handle.
@@ -39,21 +36,21 @@ pub const Error = error {
     OutOfMemory,
 };
 
-pub const FALSE = ALC_FALSE;
-pub const TRUE = ALC_TRUE;
-pub const DONT_CARE  = ALC_DONT_CATE_SOFT;
+pub const FALSE = c.ALC_FALSE;
+pub const TRUE = c.ALC_TRUE;
+pub const DONT_CARE  = c.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;
+pub const HRTF = c.ALC_HRTF_SOFT;
 
 /// Create and attach a context to the given device.
 pub fn createContext(device: *Device, attrlist: [:0]const i32) Error!*Context {
-    if (alcCreateContext(device, attrlist.ptr)) |context|
+    if (c.alcCreateContext(device, attrlist.ptr)) |context|
         return context;
-    return switch (alcGetError(device)) {
-        ALC_INVALID_DEVICE => Error.InvalidDevice,
-        ALC_INVALID_VALUE => Error.InvalidValue,
+    return switch (c.alcGetError(device)) {
+        c.ALC_INVALID_DEVICE => Error.InvalidDevice,
+        c.ALC_INVALID_VALUE => Error.InvalidValue,
         else => unreachable,
     };
 }
@@ -61,30 +58,30 @@ pub fn createContext(device: *Device, attrlist: [:0]const i32) Error!*Context {
 /// Make the given context the active process-wide context.
 /// Passing NULL clears the active context.
 pub fn makeContextCurrent(context: ?*Context) Error!void {
-    if (alcMakeContextCurrent(context) == TRUE)
+    if (c.alcMakeContextCurrent(context) == TRUE)
         return;
-    if (alcGetError(null) == ALC_INVALID_CONTEXT)
+    if (c.alcGetError(null) == c.ALC_INVALID_CONTEXT)
         return Error.InvalidContext;
     unreachable;
 }
 
 /// Remove a context from its device and destroys it.
 pub fn destroyContext(context: *Context) Error!void {
-    alcDestroyContext(context);
-    if (alcGetError(null) == ALC_INVALID_CONTEXT)
+    c.alcDestroyContext(context);
+    if (c.alcGetError(null) == c.ALC_INVALID_CONTEXT)
         return Error.InvalidContext;
 }
 
 /// Return the currently active context.
 pub fn getCurrentContext() ?*Context {
-    return alcGetCurrentContext();
+    return c.alcGetCurrentContext();
 }
 
 /// Return the device that a particular context is attached to.
 pub fn getContextsDevice(context: *Context) Error!*Device {
-    if (alcGetContextsDevice(context)) |device|
+    if (c.alcGetContextsDevice(context)) |device|
         return device;
-    if (alcGetError(null) == ALC_INVALID_CONTEXT)
+    if (c.alcGetError(null) == c.ALC_INVALID_CONTEXT)
         return Error.InvalidContext;
     unreachable;
 }
@@ -92,33 +89,33 @@ pub fn getContextsDevice(context: *Context) Error!*Device {
 /// Open the named playback device.
 pub fn openDevice(name: ?[:0]const u8) Error!*Device {
     const name_ptr = if (name == null) null else name.?.ptr;
-    if (alcOpenDevice(name_ptr)) |device|
+    if (c.alcOpenDevice(name_ptr)) |device|
         return device;
-    return switch (alcGetError(null)) {
-        ALC_INVALID_VALUE => Error.InvalidValue,
-        ALC_OUT_OF_MEMORY => Error.OutOfMemory,
+    return switch (c.alcGetError(null)) {
+        c.ALC_INVALID_VALUE => Error.InvalidValue,
+        c.ALC_OUT_OF_MEMORY => Error.OutOfMemory,
         else => unreachable,
     };
 }
 
 /// Close the given playback device.
 pub fn closeDevice(device: *Device) Error!void {
-    if (alcCloseDevice(device) == TRUE)
+    if (c.alcCloseDevice(device) == TRUE)
         return;
-    if (alcGetError(device) == ALC_INVALID_DEVICE)
+    if (c.alcGetError(device) == c.ALC_INVALID_DEVICE)
         return Error.InvalidDevice;
     unreachable;
 }
 
-pub fn getInt(device: *Device, param: ALCenum) Error!i32 {
+pub fn getInt(device: *Device, param: c.ALCenum) Error!i32 {
     var data: i32 = undefined;
-    alcGetIntegerv(device, param, 1, &data);
-    return switch (alcGetError(device)) {
-        ALC_NO_ERROR => data,
-        ALC_INVALID_VALUE => Error.InvalidValue,
-        ALC_INVALID_ENUM => Error.InvalidEnum,
-        ALC_INVALID_DEVICE => Error.InvalidDevice,
-        ALC_INVALID_CONTEXT => Error.InvalidContext,
+    c.alcGetIntegerv(device, param, 1, &data);
+    return switch (c.alcGetError(device)) {
+        c.ALC_NO_ERROR => data,
+        c.ALC_INVALID_VALUE => Error.InvalidValue,
+        c.ALC_INVALID_ENUM => Error.InvalidEnum,
+        c.ALC_INVALID_DEVICE => Error.InvalidDevice,
+        c.ALC_INVALID_CONTEXT => Error.InvalidContext,
         else => unreachable,
     };
 }