4 category = "Instrument",
6 author = "Ardour Team",
7 description = [[Noise Generator (v-1.02)]]
10 function dsp_params ()
13 { ["type"] = "input", name = "White/Pink", min = 0, max = 1, default = 0, toggled = true },
14 { ["type"] = "input", name = "Gain", min = -60, max = 0, default = -18, unit="dB" },
18 function dsp_ioconfig ()
19 return { [1] = { audio_in = -1, audio_out = -1}, }
24 function dsp_init (rate)
31 function dsp_run (ins, outs, n_samples)
33 local a = {} -- init array
34 local ctrl = CtrlPorts:array ()
35 local noise = ctrl[1] or 0
36 local amplitude = ARDOUR.DSP.dB_to_coefficient (ctrl[2]) or ARDOUR.DSP.dB_to_coefficient (-18)
46 --Pink noise generation courtesy of Paul Kellet's refined method
47 --http://www.musicdsp.org/files/pink.txt
48 --If 'white' consists of uniform random numbers,
49 --the pink noise will have an almost gaussian distribution.
50 for s = 1, n_samples do
52 a[s] = amplitude * 2 * (math.random() - 0.5)
55 white = (amplitude * 0.25) * 2 * (math.random() - 0.5)
56 b0 = 0.99886 * b0 + white * 0.0555179;
57 b1 = 0.99332 * b1 + white * 0.0750759;
58 b2 = 0.96900 * b2 + white * 0.1538520;
59 b3 = 0.86650 * b3 + white * 0.3104856;
60 b4 = 0.55000 * b4 + white * 0.5329522;
61 b5 = -0.7616 * b5 - white * 0.0168980;
62 b6 = white * 0.115926;
63 a[s] = b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362;
67 if (draw > (sr/15)) then
72 -- passes array a {} into buffer
74 outs[c]:set_table(a, n_samples)
76 draw = draw + n_samples
79 function render_inline (ctx, w, max_h) --inline display
80 local ctrl = CtrlPorts:array()
86 local amplitude = ARDOUR.DSP.dB_to_coefficient(ctrl[2])
87 if ctrl[1] == 1 then pink = true end
88 if pink then inc = 0.7/w end
91 ctx:rectangle(0, 0, w, h)
92 ctx:set_source_rgba(0, 0, 0, 1.0)
94 ctx:set_line_width(1.5)
95 ctx:set_source_rgba(0.8, 0.8, 0.8, 1.0)
100 if pink then ycy = 0.3 else ycy = 0.5 end --slant slightly like an actual pink noise spectrum
101 y = math.log(20^amplitude) * (math.random() - 0.5) - p
102 yc = ycy * h + ((-0.5 * h) * y)
103 ctx:move_to (x, yc + 3)
104 ctx:line_to (l_x, l_y + 3)