~alva/scratchy

66a15348c44c96888eb1ff94f1f906a149254434 — ugla 7 months ago b028556 trunk
Make boop
1 files changed, 10 insertions(+), 5 deletions(-)

M src/linux.zig
M src/linux.zig => src/linux.zig +10 -5
@@ 21,13 21,15 @@ const DiskStatsArray = std.BoundedArray(DiskStats, N_DISKS_SHOULD_BE_ENOUGH_FOR_

const UPDATE_FREQ_NS = std.time.ns_per_s / 10;

const BoopBuffer = [1024 * 64]f32;

const Total = struct {
    reads: u64 = std.math.maxInt(u64),
    writes: u64 = std.math.maxInt(u64),
};

pub fn crackle() !void {
    var buf: [4096]u8 = undefined;
    var buf: [256 * N_DISKS_SHOULD_BE_ENOUGH_FOR_ANYONE]u8 = undefined;
    var total = Total{};
    var file = try std.fs.cwd().openFile(disk_stats_path, .{});
    defer file.close();


@@ 84,7 86,7 @@ fn processStats(stats: *DiskStatsArray, total: *Total, prng: anytype) !void {
    const rd = reads_total -| total.reads;

    if (0 < wd + rd) {
        var crap: [2048]f32 = undefined;
        var crap: BoopBuffer = std.mem.zeroes(BoopBuffer);
        var ss = c.pa_sample_spec{
            .format = c.PA_SAMPLE_FLOAT32NE,
            .rate = 44100,


@@ 119,9 121,12 @@ fn processStats(stats: *DiskStatsArray, total: *Total, prng: anytype) !void {
    total.writes = writes_total;
}

fn generateNoise(amount: u64, buf: *[2048]f32, prng: anytype) void {
fn generateNoise(amount: u64, buf: *BoopBuffer, prng: anytype) void {
    var i: usize = 0;
    while (i < buf.len and i < amount) : (i += 1) {
        buf[i] = prng.float(f32);
    var phase: f32 = 0.0;

    while (i < buf.len and i < amount * 16) : (i += 1) {
        phase += @intToFloat(f32, amount) * 0.000001;
        buf[i] = std.math.sin(phase) + prng.float(f32) * 0.02;
    }
}
\ No newline at end of file