Hey everyone, this is my first time posting on the audacity forums. I’ve been looking at the nyquist language, but I have yet to build a plugin.
Anyway, I have this algorithm which seems to produce different types of noise. Basically, when generating a next random sample, its range of values is limited to a window of values surrounding the previous sample. Here is the code, which i run by pasting into the nyquist prompt for an existing silence track:
;; create array
(setq maxlen 10000000)
(setq samplerate (snd-srate s))
(setf common (make-array (snd-length s maxlen)))
;; set window parameters, windowpos will change
(setq windowsize 0.2) ;; 0.02 -> brown, 2.0 -> white
(setq windowpos 0)
(do
(
(n 0 (1+ n))
(v (snd-fetch s) (setq v (snd-fetch s)))
)
;; code taken from
;; https://forum.audacityteam.org/t/help-with-iteration-functions-in-nyquist/7268/4
((not v) common)
;; sample = windowpos + random * windowsize - windowsize/2
(setf sample
(+
windowpos
(* (rrandom) windowsize)
(/ windowsize -2.0)
)
)
;; clamp sample to [-1, +1] range
(setf sample (min 1 (max -1 sample)))
;; determine probability next sample will go downward
;; window for next values is offset accordingly
(setf downprobability
(+ 0.5 (* 0.5 sample))
)
;; windowpos = sample + windowsize/2 - downprob * windowsize
(setf windowpos
(+
sample
(/ windowsize 2.0)
(* downprobability windowsize -1)
)
)
(setf (aref common n) sample)
) ;; end of do loop
;; turn array into sound
(snd-from-array 0 samplerate common)
It appears to successfully recreate brown noise at a window size of 0.02 (1/100 of possible values) and it degrades into white noise at a window size of 2 (all possible values). It “almost” sounds like blue noise at higher window sizes due to the clamping from -1 to +1, but it’s definitely got problems recreating blue noise and even pink noise: The frequency spectrum it produces is not linear on a logarithmic plot like those seen at http://en.wikipedia.org/wiki/Colors_of_noise.
My question is would some changes to this algorithm allow it to recreate pink noise or would that be a lost cause? My original thought was to use a different “down” probability for the next sample, but have yet to find one that works.