«Fractal Noise» by Michael Dzjaparidze

on 20 Sep'13 13:52 in noiserandomchaosfractal

This code generates fractal noise by cascading N first order filter sections. beta = 0 -> white noise, beta = 1 -> pink noise, beta = 2 -> brown noise. Not too sure about the normalization constant, since it is purely based on empirical reasoning, but it seems to work pretty well.

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
// Script for generating fractal noise by cascading N first order filters. From: "The Sounding Object", chapter 8
s.boot; s.scope

(
var fp1,n,fp,fo,a,b,beta,t,norm;

fp1 = 50;                                         // frequency of first pole
n = 6;                                            // nr. of poles
h = 2;                                            // density of poles per frequency decade
beta = 1;                                         // spectral parameter
t = s.sampleRate.reciprocal ? 44100.reciprocal;   // sampling period
norm = exp(beta).reciprocal**1.72;

fp = Array.newClear(n).put(0,fp1);   // pole frequencies
fo = Array.newClear(n);              // zero frequencies
a = Array.newClear(n);               // pole coefficients
b = Array.newClear(n);               // zero coefficients

n do: { |i|
   (i > 0).if { fp[i] = 10**h.reciprocal*fp[i-1] };
   fo[i] = 10**(0.5*beta*h.reciprocal)*fp[i];
   a[i] = exp(-2pi*fp[i]*t);
   b[i] = exp(-2pi*fo[i]*t)
};

SynthDef(\fractalNoise,{ arg out=0;
   var signal = WhiteNoise.ar(1!2);
   n do: { |i| signal = FOS.ar(signal,1,b[i].neg,a[i]) };
   Out.ar(out,norm*signal)
}).add;
)

// test it
s.sendMsg('/s_new',\fractalNoise,s.nextNodeID,0,1);
FreqScope.new


// probably more useful as a pseudo-ugen
FractalNoise {

   *ar { arg beta = 0, mul = 1, add = 0;
      var n = 6, h = 2, fp = 50, t = SampleDur.ir, norm = exp(beta).reciprocal**1.72, sig = WhiteNoise.ar(mul,add);

      n do: {
         var fo = 10**(0.5*beta*h.reciprocal)*fp;
         sig = FOS.ar(sig,1,exp(-2pi*fo*t).neg,exp(-2pi*fp*t));
         fp = 10**h.reciprocal*fp
      };

      ^(norm*sig)
   }

}
descendants
«Re: Fractal Noise» by anonymous (private)
full graph
raw 1691 chars (focus & ctrl+a+c to copy)
reception
comments