Compare commits
2 commits
d12268f028
...
87556c5b7e
Author | SHA1 | Date | |
---|---|---|---|
87556c5b7e | |||
c5a2e317c4 |
2 changed files with 18 additions and 22 deletions
|
@ -1,3 +1,3 @@
|
||||||
load :0;
|
load :0;
|
||||||
amp 3 1 10;
|
amp 3 1 20;
|
||||||
quicksave;
|
quicksave;
|
||||||
|
|
|
@ -54,12 +54,10 @@ fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sseek(file: *c.SNDFILE, offset: usize) !void {
|
fn sseek(file: *c.SNDFILE, offset: usize) void {
|
||||||
const frames = c.sf_seek(file, @intCast(i64, offset), c.SEEK_SET);
|
const frames = c.sf_seek(file, @intCast(i64, offset), c.SEEK_SET);
|
||||||
|
|
||||||
if (frames != @intCast(i64, offset)) {
|
if (frames != @intCast(i64, offset)) {
|
||||||
std.debug.warn("failed to seek to {}\n", offset);
|
std.debug.warn("failed to seek to {}\n", offset);
|
||||||
return error.SeekFail;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,24 +185,22 @@ pub const Image = struct {
|
||||||
|
|
||||||
// we do sf_seek() calls to make sure we are actually on the start
|
// we do sf_seek() calls to make sure we are actually on the start
|
||||||
// and actually end at the end position for the file.
|
// and actually end at the end position for the file.
|
||||||
try sseek(self.sndfile, start);
|
sseek(self.sndfile, start);
|
||||||
try sseek(out_file, start);
|
sseek(out_file, start);
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
@ -212,8 +208,8 @@ pub const Image = struct {
|
||||||
try swrite(out_file, view.ptr, @intCast(i64, view.len));
|
try swrite(out_file, view.ptr, @intCast(i64, view.len));
|
||||||
}
|
}
|
||||||
|
|
||||||
try sseek(self.sndfile, end);
|
sseek(self.sndfile, end);
|
||||||
try sseek(out_file, end);
|
sseek(out_file, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos {
|
fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos {
|
||||||
|
@ -304,7 +300,7 @@ pub const Image = struct {
|
||||||
seek_pos.start,
|
seek_pos.start,
|
||||||
);
|
);
|
||||||
|
|
||||||
try sseek(self.sndfile, seek_pos.start);
|
sseek(self.sndfile, seek_pos.start);
|
||||||
|
|
||||||
var i: usize = seek_pos.start;
|
var i: usize = seek_pos.start;
|
||||||
std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end);
|
std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end);
|
||||||
|
@ -323,7 +319,7 @@ pub const Image = struct {
|
||||||
try swrite(out_file, outbuf.ptr, 1);
|
try swrite(out_file, outbuf.ptr, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try sseek(self.sndfile, seek_pos.end);
|
sseek(self.sndfile, seek_pos.end);
|
||||||
|
|
||||||
// post-plugin copy
|
// post-plugin copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
|
@ -368,7 +364,7 @@ pub const Image = struct {
|
||||||
const seek_pos = self.getSeekPos(position);
|
const seek_pos = self.getSeekPos(position);
|
||||||
|
|
||||||
// make sure we start from 0
|
// make sure we start from 0
|
||||||
try sseek(self.sndfile, 0);
|
sseek(self.sndfile, 0);
|
||||||
|
|
||||||
// there are four main stages:
|
// there are four main stages:
|
||||||
// - the bmp header copy
|
// - the bmp header copy
|
||||||
|
@ -383,7 +379,7 @@ pub const Image = struct {
|
||||||
seek_pos.start,
|
seek_pos.start,
|
||||||
);
|
);
|
||||||
|
|
||||||
try sseek(self.sndfile, seek_pos.start);
|
sseek(self.sndfile, seek_pos.start);
|
||||||
|
|
||||||
var i: usize = seek_pos.start;
|
var i: usize = seek_pos.start;
|
||||||
std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end);
|
std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end);
|
||||||
|
@ -402,7 +398,7 @@ pub const Image = struct {
|
||||||
try swrite(out_file, bufs.out.ptr, 1);
|
try swrite(out_file, bufs.out.ptr, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try sseek(self.sndfile, seek_pos.end);
|
sseek(self.sndfile, seek_pos.end);
|
||||||
|
|
||||||
// post-plugin copy
|
// post-plugin copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue