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_run (ins, outs, n_samples)
26 local a = {} -- init array
27 local ctrl = CtrlPorts:array ()
28 local noise = ctrl[1] or 0
29 local amplitude = ARDOUR.DSP.dB_to_coefficient (ctrl[2]) or ARDOUR.DSP.dB_to_coefficient (-18)
39 --Pink noise generation courtesy of Paul Kellet's refined method
40 --http://www.musicdsp.org/files/pink.txt
41 --If 'white' consists of uniform random numbers,
42 --the pink noise will have an almost gaussian distribution.
43 for s = 1, n_samples do
45 a[s] = amplitude * 2 * (math.random() - 0.5)
48 white = (amplitude * 0.25) * 2 * (math.random() - 0.5)
49 b0 = 0.99886 * b0 + white * 0.0555179;
50 b1 = 0.99332 * b1 + white * 0.0750759;
51 b2 = 0.96900 * b2 + white * 0.1538520;
52 b3 = 0.86650 * b3 + white * 0.3104856;
53 b4 = 0.55000 * b4 + white * 0.5329522;
54 b5 = -0.7616 * b5 - white * 0.0168980;
55 b6 = white * 0.115926;
56 a[s] = b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362;
60 -- passes array a {} into buffer
62 outs[c]:set_table(a, n_samples)
71 function render_inline (ctx, w, max_h) --inline display
72 local ctrl = CtrlPorts:array()
78 local amplitude = ARDOUR.DSP.dB_to_coefficient(ctrl[2])
79 if ctrl[1] == 1 then pink = true end
80 if pink then inc = 0.7/w end
83 ctx:rectangle(0, 0, w, h)
84 ctx:set_source_rgba(0, 0, 0, 1.0)
86 ctx:set_line_width(1.5)
87 ctx:set_source_rgba(0.8, 0.8, 0.8, 1.0)
92 if pink then ycy = 0.3 else ycy = 0.5 end --slant slightly like an actual pink noise spectrum
93 y = math.log(20^amplitude) * (math.random() - 0.5) - p
94 yc = ycy * h + ((-0.5 * h) * y)
95 ctx:move_to (x, yc + 3)
96 ctx:line_to (l_x, l_y + 3)