This commit is contained in:
Luna 2023-08-04 21:34:51 -03:00
parent ed67a52b15
commit 7cc93c2976
7 changed files with 25 additions and 25 deletions

View file

@ -24,7 +24,7 @@ pub const RandomNoise = struct {
if (params.fill_bytes > 0) {
var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null;
for (rand_buf) |_, idx| {
for (rand_buf, 0..) |_, idx| {
rand_buf[idx] = r.random().float(f32);
}
@ -72,8 +72,8 @@ pub const WildNoise = struct {
if (params.fill_bytes > 0) {
var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null;
for (rand_buf) |_, idx| {
rand_buf[idx] = @intToFloat(f32, r.random().int(u1));
for (rand_buf, 0..) |_, idx| {
rand_buf[idx] = @as(f32, @floatFromInt(r.random().int(u1)));
}
return WildNoise{
@ -99,7 +99,7 @@ pub const WildNoise = struct {
bufs.out[0] = rand_buf[self.cnt];
self.cnt += 1;
} else {
bufs.out[0] = @intToFloat(f32, self.r.random().int(u1));
bufs.out[0] = @as(f32, @floatFromInt(self.r.random().int(u1)));
}
}
};
@ -163,7 +163,7 @@ pub const Embed = struct {
image.sseek(self.sndfile, 0);
self.buf = try self.allocator.alloc(f32, @intCast(usize, in_fmt.channels));
self.buf = try self.allocator.alloc(f32, @as(usize, @intCast(in_fmt.channels)));
}
pub fn deinit(self: *@This()) void {

View file

@ -63,7 +63,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
}
pub fn sseek(file: *c.SNDFILE, offset: usize) void {
const offset_i64 = @intCast(i64, offset);
const offset_i64 = @as(i64, @intCast(offset));
const frames = c.sf_seek(file, offset_i64, c.SEEK_SET);
const frames_current = c.sf_seek(file, 0, c.SEEK_CUR);
std.debug.assert(frames == frames_current);
@ -80,7 +80,7 @@ pub fn temporaryName(allocator: std.mem.Allocator) ![]u8 {
var nam = try allocator.alloc(u8, template.len);
std.mem.copy(u8, nam, template);
const seed = @truncate(u64, @bitCast(u128, std.time.nanoTimestamp()));
const seed = @as(u64, @truncate(@as(u128, @bitCast(std.time.nanoTimestamp()))));
var r = std.rand.DefaultPrng.init(seed);
var fill = nam[template_start.len..nam.len];
@ -88,8 +88,8 @@ pub fn temporaryName(allocator: std.mem.Allocator) ![]u8 {
var i: usize = 0;
while (i < 100) : (i += 1) {
// generate a random uppercase letter, that is, 65 + random number.
for (fill) |_, f_idx| {
var idx = @intCast(u8, r.random().uintLessThan(u5, 24));
for (fill, 0..) |_, f_idx| {
var idx = @as(u8, @intCast(r.random().uintLessThan(u5, 24)));
var letter = @as(u8, 65) + idx;
fill[f_idx] = letter;
}
@ -151,7 +151,7 @@ pub const Image = struct {
.sndfile = sndfile,
.path = path,
.curpath = path,
.frames = @intCast(usize, in_fmt.frames),
.frames = @as(usize, @intCast(in_fmt.frames)),
};
return image;
@ -161,7 +161,7 @@ pub const Image = struct {
var in_fmt = mkSfInfo();
// clone sndfile
var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt);
std.debug.assert(self.frames == @intCast(usize, in_fmt.frames));
std.debug.assert(self.frames == @as(usize, @intCast(in_fmt.frames)));
var image = try self.allocator.create(Image);
@ -173,7 +173,7 @@ pub const Image = struct {
.sndfile = sndfile,
.path = self.path,
.curpath = self.curpath,
.frames = @intCast(usize, in_fmt.frames),
.frames = @as(usize, @intCast(in_fmt.frames)),
};
return image;
@ -198,12 +198,12 @@ pub const Image = struct {
pub fn read(self: *Image, file_chans: c_int, buf: []f32) bool {
const n_read: c.sf_count_t = c.sf_readf_float(self.sndfile, buf.ptr, 1);
const buf_chans = @intCast(c_int, buf.len);
const buf_chans = @as(c_int, @intCast(buf.len));
var i = file_chans - 1;
while (i < buf_chans) : (i += 1) {
//buf[@intCast(usize, i)] = buf[i % file_chans];
buf[@intCast(usize, i)] = buf[@intCast(usize, @mod(i, file_chans))];
buf[@as(usize, @intCast(i))] = buf[@as(usize, @intCast(@mod(i, file_chans)))];
}
return n_read == 1;
@ -237,13 +237,13 @@ pub const Image = struct {
var view: []f32 = buf[0..buf.len];
if (bytes_until_end < buf.len) {
read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, bytes_until_end));
read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @as(i64, @intCast(bytes_until_end)));
view = buf[0..bytes_until_end];
} 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, @as(i64, @intCast(buf.len)));
}
try swrite(out_file, view.ptr, @intCast(i64, view.len));
try swrite(out_file, view.ptr, @as(i64, @intCast(view.len)));
}
sseek(self.sndfile, end);
@ -264,7 +264,7 @@ pub const Image = struct {
// std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames));
self.curpath = path;
self.frames = @intCast(usize, in_fmt.frames);
self.frames = @as(usize, @intCast(in_fmt.frames));
log.debug("\timage: reopened on '{s}' (frames={d}, fmt.frames={d})", .{
self.curpath,

View file

@ -669,7 +669,7 @@ pub const Lang = struct {
comptime var lowered_command_name = [_]u8{0} ** struct_name.len;
comptime {
for (struct_name) |c, i| {
for (struct_name, 0..) |c, i| {
lowered_command_name[i] = std.ascii.toLower(c);
}
}

View file

@ -69,7 +69,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port {
var ports = try ctx.allocator.alloc(Port, n_ports);
for (ports) |_, idx| {
for (ports, 0..) |_, idx| {
var port: *Port = &ports[idx];
port.* = Port{
.lilv_port = null,

View file

@ -30,8 +30,8 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt
var heap_cmd = try allocator.create(CommandStruct);
@memcpy(
@ptrCast([*]u8, &heap_cmd),
@ptrCast([*]const u8, &casted),
@as([*]u8, @ptrCast(&heap_cmd)),
@as([*]const u8, @ptrCast(&casted)),
@sizeOf(CommandStruct),
);

View file

@ -101,8 +101,8 @@ pub const RunContext = struct {
var i: usize = 0;
var o: usize = 0;
for (ports) |_, p_idx| {
var p = @intCast(u32, p_idx);
for (ports, 0..) |_, p_idx| {
var p = @as(u32, @intCast(p_idx));
var port: *lv2.Port = &ports[p_idx];
switch (port.ptype) {

View file

@ -70,7 +70,7 @@ pub const Runner = struct {
// ':0' should ALWAYS point to the image.
if (self.repl) index += 3 else index += 3;
for (self.args) |arg, idx| {
for (self.args, 0..) |arg, idx| {
log.debug("arg{d} = {s}", .{ idx, arg });
}
log.debug("fetch arg idx={d}", .{index});