simplify copyBytes excess calc and do sseek()

This commit is contained in:
Luna 2019-07-15 11:26:41 -03:00
parent c5a2e317c4
commit 87556c5b7e
2 changed files with 8 additions and 10 deletions

View file

@ -1,3 +1,3 @@
load :0;
amp 3 1 10;
amp 3 1 20;
quicksave;

View file

@ -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));
}