add assertions about seek state and seek position
This commit is contained in:
parent
0e323f6631
commit
f8814ca94d
3 changed files with 30 additions and 12 deletions
|
@ -45,6 +45,15 @@ fn sopen(
|
||||||
return ImageError.OpenFail;
|
return ImageError.OpenFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const frames_on_end = c.sf_seek(file, 0, c.SEEK_END);
|
||||||
|
_ = c.sf_seek(file, 0, c.SEEK_SET);
|
||||||
|
std.testing.expectEqual(fmt.frames, frames_on_end);
|
||||||
|
|
||||||
|
const frames_on_end_by_end = c.sf_seek(file, frames_on_end, c.SEEK_SET);
|
||||||
|
std.testing.expectEqual(frames_on_end, frames_on_end_by_end);
|
||||||
|
|
||||||
|
std.debug.warn("frames on end: {}, frame on end (2): {}\n", frames_on_end, frames_on_end_by_end);
|
||||||
|
|
||||||
return file.?;
|
return file.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,22 +61,20 @@ fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
|
||||||
const count = c.sf_writef_float(file, buf, frames);
|
const count = c.sf_writef_float(file, buf, frames);
|
||||||
|
|
||||||
if (count != frames) {
|
if (count != frames) {
|
||||||
std.debug.warn("Wanted to read {}, got {}\n", frames, count);
|
std.debug.warn("Wanted to write {}, got {}\n", frames, count);
|
||||||
return ImageError.WriteFail;
|
return ImageError.WriteFail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 offset_i64 = @intCast(i64, offset);
|
||||||
if (frames != @intCast(i64, offset)) {
|
const frames = c.sf_seek(file, offset_i64, c.SEEK_SET);
|
||||||
std.debug.warn("failed to seek to {}\n", offset);
|
const frames_current = c.sf_seek(file, 0, c.SEEK_CUR);
|
||||||
}
|
std.testing.expectEqual(frames, frames_current);
|
||||||
}
|
|
||||||
|
|
||||||
fn sf_tell(file: *c.SNDFILE) i64 {
|
if (frames != offset_i64) {
|
||||||
var frames = c.sf_seek(file, 0, c.SEEK_CUR);
|
std.debug.warn("failed to seek to {} (seeked {} frames, offset_i64={})\n", offset, frames, offset_i64);
|
||||||
std.debug.warn("\t\t{} frames\n", frames);
|
}
|
||||||
return -frames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Caller owns the returned memory.
|
/// Caller owns the returned memory.
|
||||||
|
@ -132,6 +139,7 @@ pub const Image = struct {
|
||||||
pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image {
|
pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image {
|
||||||
var in_fmt = mkSfInfo();
|
var in_fmt = mkSfInfo();
|
||||||
var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt);
|
var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt);
|
||||||
|
|
||||||
var image = try allocator.create(Image);
|
var image = try allocator.create(Image);
|
||||||
|
|
||||||
std.debug.assert(in_fmt.frames > i64(0));
|
std.debug.assert(in_fmt.frames > i64(0));
|
||||||
|
@ -152,6 +160,8 @@ pub const Image = struct {
|
||||||
var in_fmt = mkSfInfo();
|
var in_fmt = mkSfInfo();
|
||||||
// clone sndfile
|
// clone sndfile
|
||||||
var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt);
|
var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt);
|
||||||
|
std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames));
|
||||||
|
|
||||||
var image = try self.allocator.create(Image);
|
var image = try self.allocator.create(Image);
|
||||||
|
|
||||||
std.debug.assert(in_fmt.frames > i64(0));
|
std.debug.assert(in_fmt.frames > i64(0));
|
||||||
|
@ -249,10 +259,17 @@ pub const Image = struct {
|
||||||
var in_fmt = mkSfInfo();
|
var in_fmt = mkSfInfo();
|
||||||
|
|
||||||
self.sndfile = try sopen(self.allocator, path, c.SFM_READ, &in_fmt);
|
self.sndfile = try sopen(self.allocator, path, c.SFM_READ, &in_fmt);
|
||||||
|
std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames));
|
||||||
|
|
||||||
self.curpath = path;
|
self.curpath = path;
|
||||||
self.frames = @intCast(usize, in_fmt.frames);
|
self.frames = @intCast(usize, in_fmt.frames);
|
||||||
|
|
||||||
std.debug.warn("\timage: reopened on '{}'\n", self.curpath);
|
std.debug.warn(
|
||||||
|
"\timage: reopened on '{}' (frames={}, fmt.frames={})\n",
|
||||||
|
self.curpath,
|
||||||
|
self.frames,
|
||||||
|
in_fmt.frames,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn checkValid(self: *Image) !void {
|
pub fn checkValid(self: *Image) !void {
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
|
||||||
defer runqs_args.deinit();
|
defer runqs_args.deinit();
|
||||||
|
|
||||||
// TODO change the runqs command to something given in an env var
|
// TODO change the runqs command to something given in an env var
|
||||||
try runqs_args.append("feh");
|
try runqs_args.append("ristretto");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
lang.reset();
|
lang.reset();
|
||||||
|
|
|
@ -34,6 +34,7 @@ pub const Position = struct {
|
||||||
index: usize,
|
index: usize,
|
||||||
|
|
||||||
pub fn seekPos(self: Position, total_size: usize) SeekPos {
|
pub fn seekPos(self: Position, total_size: usize) SeekPos {
|
||||||
|
std.debug.assert(self.index <= self.split);
|
||||||
var tot = total_size / self.split;
|
var tot = total_size / self.split;
|
||||||
|
|
||||||
return SeekPos{
|
return SeekPos{
|
||||||
|
|
Loading…
Reference in a new issue