diff options
Diffstat (limited to 'src/sf.zig')
-rw-r--r-- | src/sf.zig | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/sf.zig b/src/sf.zig index bce6dcc..1d8f1dd 100644 --- a/src/sf.zig +++ b/src/sf.zig @@ -1,5 +1,5 @@ // libsndfile wrapper -// Copyright (C) 2021-2022 Nguyễn Gia Phong +// Copyright (C) 2021-2023 Nguyễn Gia Phong // // This file is part of zeal. // @@ -29,7 +29,7 @@ pub const Mode = enum { read_write, }; -pub const Error = Allocator.Error || error { +pub const Error = Allocator.Error || error{ UnrecognizedFormat, SystemError, MalformedFile, @@ -58,7 +58,7 @@ pub const SndFile = struct { 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 { + return SndFile{ .pimpl = pimpl orelse return switch (c.sf_error(null)) { c.SF_ERR_UNRECOGNISED_FORMAT => Error.UnrecognizedFormat, c.SF_ERR_SYSTEM => Error.SystemError, @@ -66,7 +66,7 @@ pub const SndFile = struct { c.SF_ERR_UNSUPPORTED_ENCODING => Error.UnsupportedEncoding, else => unreachable, }, - .frames = @intCast(usize, info.frames), + .frames = @intCast(info.frames), .sample_rate = info.samplerate, .channels = info.channels, .format = info.format, @@ -79,11 +79,11 @@ pub const SndFile = struct { /// The returned memory is managed by the caller. pub fn read(self: SndFile, allocator: Allocator, frames: usize) Error![]const i16 { - const items = frames * @intCast(usize, self.channels); + const items = frames * @as(usize, @intCast(self.channels)); const memory = try allocator.alloc(i16, items); errdefer allocator.free(memory); - const n = c.sf_read_short(self.pimpl, memory.ptr, @intCast(i64, items)); - return try allocator.realloc(memory, @intCast(usize, n)); + const n = c.sf_read_short(self.pimpl, memory.ptr, @intCast(items)); + return try allocator.realloc(memory, @intCast(n)); } /// Read the entire file. The returned memory is managed by the caller. |