make copyBytes allocate its own buffer
This commit is contained in:
parent
b59f937d00
commit
8c2bbee372
1 changed files with 4 additions and 17 deletions
|
@ -54,12 +54,6 @@ fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getEndPos(path: []const u8) !usize {
|
|
||||||
var file = try std.fs.File.openRead(path);
|
|
||||||
defer file.close();
|
|
||||||
return file.getEndPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
||||||
const template_start = "/temp/temp_";
|
const template_start = "/temp/temp_";
|
||||||
const template = "/tmp/temp_XXXXXXXX";
|
const template = "/tmp/temp_XXXXXXXX";
|
||||||
|
@ -125,6 +119,7 @@ pub const Image = struct {
|
||||||
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));
|
||||||
|
std.debug.assert(in_fmt.seekable == i32(1));
|
||||||
|
|
||||||
image.* = Image{
|
image.* = Image{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
|
@ -167,10 +162,12 @@ pub const Image = struct {
|
||||||
fn copyBytes(
|
fn copyBytes(
|
||||||
self: *Image,
|
self: *Image,
|
||||||
out_file: *c.SNDFILE,
|
out_file: *c.SNDFILE,
|
||||||
buf: []f32,
|
|
||||||
start: usize,
|
start: usize,
|
||||||
end: usize,
|
end: usize,
|
||||||
) !void {
|
) !void {
|
||||||
|
var buf = try self.allocator.alloc(f32, BufferSize);
|
||||||
|
defer self.allocator.free(buf);
|
||||||
|
|
||||||
const total_bytes = end - start;
|
const total_bytes = end - start;
|
||||||
var i: usize = start;
|
var i: usize = start;
|
||||||
|
|
||||||
|
@ -287,13 +284,9 @@ pub const Image = struct {
|
||||||
// - plugin
|
// - plugin
|
||||||
// - post-plugin
|
// - post-plugin
|
||||||
|
|
||||||
var file_copy_buf = try self.allocator.alloc(f32, BufferSize);
|
|
||||||
defer self.allocator.free(file_copy_buf);
|
|
||||||
|
|
||||||
// pre-plugin copy, merged with bmp header copy
|
// pre-plugin copy, merged with bmp header copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
file_copy_buf,
|
|
||||||
usize(0),
|
usize(0),
|
||||||
seek_pos.start,
|
seek_pos.start,
|
||||||
);
|
);
|
||||||
|
@ -322,7 +315,6 @@ pub const Image = struct {
|
||||||
// post-plugin copy
|
// post-plugin copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
file_copy_buf,
|
|
||||||
seek_pos.end + 1,
|
seek_pos.end + 1,
|
||||||
self.frames,
|
self.frames,
|
||||||
);
|
);
|
||||||
|
@ -371,13 +363,9 @@ pub const Image = struct {
|
||||||
// - CUSTOM plugin
|
// - CUSTOM plugin
|
||||||
// - post-plugin
|
// - post-plugin
|
||||||
|
|
||||||
var file_copy_buf = try self.allocator.alloc(f32, BufferSize);
|
|
||||||
defer self.allocator.free(file_copy_buf);
|
|
||||||
|
|
||||||
// pre-plugin copy, merged with bmp header copy
|
// pre-plugin copy, merged with bmp header copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
file_copy_buf,
|
|
||||||
usize(0),
|
usize(0),
|
||||||
seek_pos.start,
|
seek_pos.start,
|
||||||
);
|
);
|
||||||
|
@ -406,7 +394,6 @@ pub const Image = struct {
|
||||||
// post-plugin copy
|
// post-plugin copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
file_copy_buf,
|
|
||||||
seek_pos.end + 1,
|
seek_pos.end + 1,
|
||||||
self.frames,
|
self.frames,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue