From 3edca782acbaa5eba631fd9469a95877e0e16ba3 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 13 Jul 2019 17:49:09 -0300 Subject: [PATCH] add basic rng init on RandomNoise plugin --- examples/noise.scri | 3 +++ src/custom.zig | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 examples/noise.scri diff --git a/examples/noise.scri b/examples/noise.scri new file mode 100644 index 0000000..171c934 --- /dev/null +++ b/examples/noise.scri @@ -0,0 +1,3 @@ +load :0; +noise 3 1; +quicksave; diff --git a/src/custom.zig b/src/custom.zig index e0fadc3..0e2b3e3 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -5,20 +5,24 @@ const plugins = @import("plugin.zig"); const c = lv2.c; -const RunContext = plugins.RunContext; +const RunBuffers = plugins.RunBuffers; pub const RandomNoise = struct { allocator: *std.mem.Allocator, + r: std.rand.DefaultPrng, pub fn init( allocator: *std.mem.Allocator, ) RandomNoise { + var r = std.rand.DefaultPrng.init(std.time.timestamp()); + return RandomNoise{ .allocator = allocator, + .r = r, }; } - pub fn run(self: *RandomNoise, rctx: *RunContext) void { - rctx.in_buf[0] = f32(2); + pub fn run(self: *RandomNoise, bufs: *RunBuffers) void { + bufs.out[0] = self.r.random.float(f32); } };