From 430677fc07655e190bcea7951bd11075b2911445 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 19:16:09 -0300 Subject: [PATCH] enhance embed custom plugin - seek to 0 on setup - ignore and copy original bytes if we reached end of audio file --- src/custom.zig | 4 +++- src/image.zig | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 4c8c611..0727113 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -164,6 +164,8 @@ pub const Embed = struct { &in_fmt, ); + image.sseek(self.sndfile, 0); + self.buf = try self.allocator.alloc(f32, @intCast(usize, in_fmt.channels)); } @@ -173,7 +175,7 @@ pub const Embed = struct { const read_bytes = c.sf_readf_float(self.sndfile, self.buf.ptr, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF for embed\n"); + bufs.out[0] = bufs.in[0]; return; } diff --git a/src/image.zig b/src/image.zig index 3badd58..9748bc9 100644 --- a/src/image.zig +++ b/src/image.zig @@ -65,7 +65,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { } } -fn sseek(file: *c.SNDFILE, offset: usize) void { +pub fn sseek(file: *c.SNDFILE, offset: usize) void { const offset_i64 = @intCast(i64, offset); const frames = c.sf_seek(file, offset_i64, c.SEEK_SET); const frames_current = c.sf_seek(file, 0, c.SEEK_CUR);