diff --git a/examples/middle_amp.scri b/examples/middle_amp.scri index f159c8e..a5928fd 100644 --- a/examples/middle_amp.scri +++ b/examples/middle_amp.scri @@ -1,3 +1,3 @@ load :0; -amp 3 1 10; +amp 3 1 20; quicksave; diff --git a/src/image.zig b/src/image.zig index 491e994..1523133 100644 --- a/src/image.zig +++ b/src/image.zig @@ -190,19 +190,17 @@ pub const Image = struct { while (i <= end) : (i += buf.len) { std.debug.warn("i={}, buf.len={}, end={}\n", i, buf.len, end); - const excess = @intCast(i64, i + buf.len) - @intCast(i64, end); + sseek(self.sndfile, i); + sseek(out_file, i); + + const bytes_until_end = end - i; var read_bytes: i64 = undefined; var view: []f32 = buf[0..buf.len]; - if (excess > 0) { - std.debug.warn( - "excess of {} bytes, reading {} instead\n", - excess, - @intCast(i64, buf.len) - excess, - ); - read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, buf.len) - excess); - view = buf[0..@intCast(usize, excess)]; + if (bytes_until_end < buf.len) { + read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, bytes_until_end)); + view = buf[0..bytes_until_end]; } else { read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, buf.len)); }