add basic rng init on RandomNoise plugin
This commit is contained in:
parent
16116371f5
commit
3edca782ac
2 changed files with 10 additions and 3 deletions
3
examples/noise.scri
Normal file
3
examples/noise.scri
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
load :0;
|
||||||
|
noise 3 1;
|
||||||
|
quicksave;
|
|
@ -5,20 +5,24 @@ const plugins = @import("plugin.zig");
|
||||||
|
|
||||||
const c = lv2.c;
|
const c = lv2.c;
|
||||||
|
|
||||||
const RunContext = plugins.RunContext;
|
const RunBuffers = plugins.RunBuffers;
|
||||||
|
|
||||||
pub const RandomNoise = struct {
|
pub const RandomNoise = struct {
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
|
r: std.rand.DefaultPrng,
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
) RandomNoise {
|
) RandomNoise {
|
||||||
|
var r = std.rand.DefaultPrng.init(std.time.timestamp());
|
||||||
|
|
||||||
return RandomNoise{
|
return RandomNoise{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
|
.r = r,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(self: *RandomNoise, rctx: *RunContext) void {
|
pub fn run(self: *RandomNoise, bufs: *RunBuffers) void {
|
||||||
rctx.in_buf[0] = f32(2);
|
bufs.out[0] = self.r.random.float(f32);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue