about summary refs log tree commit diff
path: root/src/sf.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/sf.zig')
-rw-r--r--src/sf.zig35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/sf.zig b/src/sf.zig
index 80cfd9e..96568b6 100644
--- a/src/sf.zig
+++ b/src/sf.zig
@@ -20,7 +20,7 @@ const Allocator = std.mem.Allocator;
 const assert = std.debug.assert;
 const std = @import("std");
 
-usingnamespace @cImport(@cInclude("sndfile.h"));
+const c = @import("cimport.zig");
 
 pub const Mode = enum {
     read,
@@ -36,7 +36,7 @@ pub const Error = Allocator.Error || error {
 };
 
 pub const SndFile = struct {
-    pimpl: *SNDFILE,
+    pimpl: *c.SNDFILE,
     frames: usize,
     sample_rate: c_int,
     channels: c_int,
@@ -47,20 +47,21 @@ pub const SndFile = struct {
     /// Open the sound file at the specified path.
     pub fn open(path: [:0]const u8, mode: Mode) Error!SndFile {
         const c_mode = switch (mode) {
-            .read => SFM_READ,
-            .write => SFM_WRITE,
-            .read_write => SFM_RDWR,
+            .read => c.SFM_READ,
+            .write => c.SFM_WRITE,
+            .read_write => c.SFM_RDWR,
         };
 
-        var info: SF_INFO = undefined;
-        const pimpl = sf_open(path.ptr, c_mode, &info);
-        _ = sf_command(pimpl, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
+        var info: c.SF_INFO = undefined;
+        const pimpl = c.sf_open(path.ptr, c_mode, &info);
+        _ = c.sf_command(pimpl, c.SFC_SET_SCALE_FLOAT_INT_READ,
+                         null, c.SF_TRUE);
         return SndFile {
-            .pimpl = pimpl orelse return switch (sf_error(null)) {
-                SF_ERR_UNRECOGNISED_FORMAT => Error.UnrecognizedFormat,
-                SF_ERR_SYSTEM => Error.SystemError,
-                SF_ERR_MALFORMED_FILE => Error.MalformedFile,
-                SF_ERR_UNSUPPORTED_ENCODING => Error.UnsupportedEncoding,
+            .pimpl = pimpl orelse return switch (c.sf_error(null)) {
+                c.SF_ERR_UNRECOGNISED_FORMAT => Error.UnrecognizedFormat,
+                c.SF_ERR_SYSTEM => Error.SystemError,
+                c.SF_ERR_MALFORMED_FILE => Error.MalformedFile,
+                c.SF_ERR_UNSUPPORTED_ENCODING => Error.UnsupportedEncoding,
                 else => unreachable,
             },
             .frames = @intCast(usize, info.frames),
@@ -74,17 +75,17 @@ pub const SndFile = struct {
 
     /// Read the requested number of frames.
     /// The returned memory is managed by the caller.
-    pub fn read(self: SndFile, allocator: *Allocator,
+    pub fn read(self: SndFile, allocator: Allocator,
                 frames: usize) Error![]const i16 {
         const items = frames * @intCast(usize, self.channels);
         const memory = try allocator.alloc(i16, items);
         errdefer allocator.free(memory);
-        const n = sf_read_short(self.pimpl, memory.ptr, @intCast(i64, items));
+        const n = c.sf_read_short(self.pimpl, memory.ptr, @intCast(i64, items));
         return try allocator.realloc(memory, @intCast(usize, n));
     }
 
     /// Read the entire file.  The returned memory is managed by the caller.
-    pub fn readAll(self: SndFile, allocator: *Allocator) Error![]const i16 {
+    pub fn readAll(self: SndFile, allocator: Allocator) Error![]const i16 {
         return self.read(allocator, self.frames);
     }
 
@@ -92,6 +93,6 @@ pub const SndFile = struct {
     /// Like std.os.close, this function does not return
     /// any indication of failure.
     pub fn close(self: SndFile) void {
-        assert(sf_close(self.pimpl) == 0);
+        assert(c.sf_close(self.pimpl) == 0);
     }
 };