summaryrefslogtreecommitdiff
path: root/src/scope/layouts.zig
blob: d8fc48483ce22a3fe02b65369438b14ece701c95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! What the shaders read, as Zig structs: the only definition. The shaders
//! include GLSL generated from these (see sketchbook's `glsl.zig`). No
//! imports, so the shader build can compile this alone.

/// FFT length: the analysis window, zero-padded to twice its size so the
/// spectrum is sampled twice as finely as the window resolves.
pub const fft_size = 8192;
pub const window = 4096;
/// The most columns a view can have; the column buffers hold this many.
pub const max_columns = 2048;
/// The tallest spectrogram; its buffer holds this many rows of
/// `max_columns`.
pub const max_rows = 1024;
// All three analyses read samples `offset + i` of their sample buffer for
// `0 <= i < samples`, so one buffer can hold several sounds.
/// The spectrogram's window, zero-padded to `spectrogram_fft` points.
pub const spectrogram_window = 2048;
pub const spectrogram_fft = 4096;

/// spectrum.comp: the window ending at `end`, and the columns to fill.
pub const SpectrumParams = extern struct {
    offset: u32,
    /// Sample index one past the window's last sample.
    end: u32,
    /// Samples on the tape.
    samples: u32,
    columns: u32,
    /// Nonzero: forget the smoothed levels and peaks.
    reset: u32,
    rate: f32,
    min_freq: f32,
    max_freq: f32,
    /// Seconds since the previous analysis, for smoothing.
    dt: f32,
    pad0: u32 = 0,
    pad1: u32 = 0,
    pad2: u32 = 0,

    pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
};

/// waveform.comp: column `c` covers samples `first + c * spp` up to the next
/// column's start, and is written to slot `(slot + c) % ring`: the live
/// view writes its newest columns into a ring, the others from slot 0.
pub const WaveParams = extern struct {
    offset: u32,
    first: u32,
    samples: u32,
    columns: u32,
    spp: f32,
    slot: u32,
    ring: u32,
    pad: u32 = 0,

    pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
};

pub const Tint = enum(u32) { take, recording, live };

/// waveform.frag. Pixel column `x` shows slot `(x + scroll) % width`; only
/// the last `filled` columns have anything in them.
pub const WaveView = extern struct {
    size: [2]f32,
    /// Pixels; negative hides it.
    playhead: f32,
    gain: f32,
    /// A `Tint`.
    tint: u32,
    scroll: u32,
    filled: u32,
    pad: u32 = 0,

    pub const glsl = .{ .uniform = .{ .set = 3, .instance = "u" } };
};

/// spectrum.frag.
pub const SpectrumView = extern struct {
    size: [2]f32,
    floor_db: f32,
    ceil_db: f32,
    min_freq: f32,
    max_freq: f32,
    pad: [2]f32 = .{ 0, 0 },

    pub const glsl = .{ .uniform = .{ .set = 3, .instance = "u" } };
};

/// spectrogram.comp: the same columns as `WaveParams`, each analysed into
/// `rows` log-spaced frequency rows, row 0 the lowest.
/// Columns land in slots as `WaveParams` says.
pub const SpectrogramParams = extern struct {
    offset: u32,
    first: u32,
    samples: u32,
    columns: u32,
    rows: u32,
    spp: f32,
    rate: f32,
    min_freq: f32,
    max_freq: f32,
    slot: u32,
    ring: u32,
    pad: u32 = 0,

    pub const glsl = .{ .uniform = .{ .set = 2, .instance = "u" } };
};

/// spectrogram.frag; `scroll` and `filled` as in `WaveView`.
pub const SpectrogramView = extern struct {
    size: [2]f32,
    floor_db: f32,
    ceil_db: f32,
    /// Pixels; negative hides it.
    playhead: f32,
    scroll: u32,
    filled: u32,
    pad: f32 = 0,

    pub const glsl = .{ .uniform = .{ .set = 3, .instance = "u" } };
};