simplify copyBytes excess calc and do sseek()
This commit is contained in:
parent
c5a2e317c4
commit
87556c5b7e
|
@ -1,3 +1,3 @@
|
||||||
load :0;
|
load :0;
|
||||||
amp 3 1 10;
|
amp 3 1 20;
|
||||||
quicksave;
|
quicksave;
|
||||||
|
|
|
@ -190,19 +190,17 @@ pub const Image = struct {
|
||||||
|
|
||||||
while (i <= end) : (i += buf.len) {
|
while (i <= end) : (i += buf.len) {
|
||||||
std.debug.warn("i={}, buf.len={}, end={}\n", i, buf.len, end);
|
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 read_bytes: i64 = undefined;
|
||||||
var view: []f32 = buf[0..buf.len];
|
var view: []f32 = buf[0..buf.len];
|
||||||
|
|
||||||
if (excess > 0) {
|
if (bytes_until_end < buf.len) {
|
||||||
std.debug.warn(
|
read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, bytes_until_end));
|
||||||
"excess of {} bytes, reading {} instead\n",
|
view = buf[0..bytes_until_end];
|
||||||
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)];
|
|
||||||
} else {
|
} else {
|
||||||
read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, buf.len));
|
read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, buf.len));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue