# Create a whitenoise generator with only Max objects (no Gen or externals)

Anyone knows how to wrap around it, i’m having some trouble?

It’s probably unnecessarily cumbersome and there are thousand better ways to do it but it’s more for purposes of study than anything else.

Thanks a bunch

What about the noise~ object?

"What about the noise~ object?"

^haha, i don’t think that’s what he meant, but it’s funny because it’s true!

can’t give any awesomely advanced answers here as i’ve never felt like studying noise-generation(only noise-shaping :D)…

but one place i’d start is looking at code from musicdsp.org(or anywhere else you can search for ‘noise’ code), and figure out the max patch from the code.

for example, i went there(click on the ‘Archive’ tab to get to the search), searched ‘noise’, this page came up as one of the results:

http://musicdsp.org/showone.php?id=217

and here’s a quick max patch version of it, albeit perhaps not as exact/efficient as i could have been in gen~ or using code, particularly to create the initial 19.19191919191919… :p

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
1015.3ocyY11aaaCDG+01eJXE1q17Chj5wfNLrOGqCCzRz1LwhTfhpMsE0e1
GIkjiiaRijrkTP.T.uPYd2Od2w+l46ym4rQ7HsvAbG3e.yl884ylYMYLLqd7
LmLxiIGHE1o4jHxxnbkyhp+lh9nxZ+iKSEkaNPWlbfk7.PsmBNHHoYzhBfPB
xHOPAEkRJfo.JIa2Npr.rgtUnMUnHREiuCPJSYBvc4Me5GXbZhnjaWB+Zi7x
LQo5.UYcH2Zq4DUxd8mw+IoIpp.BCCV4u..QqbW.h8LOC0OA+a8qrUvUEruQ
My1NoZyxcarexmrvRsgnXy8KQNm8xbRl8kc9aIibv4I+iwabOnw1OlO27XwU
hX8j.1vD7YM7XBNXyWARx8Dvm3aHEzTf1ThHkB1JEYf8TI8tOw2qT42sdcVY
AKIsHekPtacwdwWDb5p784+EK8OQvvWj33tRbnExnfPC2QnXyHuvqD433Ij4
ebIWvJn.c7mWpb5JPPQPCCfw1bvnHKdbuVfDMB.gS+hds9Id7g0GAvUMlqff
5q4zpv0ofsiqchSg2yAE7Wj4fCsropXE2ZPcNV75HVP2NrjKdfdDXSUjcNIo
I18bsIIt8I1wcL1wu+SIBvFPD32+DBzzkPni5i5p2ghJPaaEuf9PE3z08fwS
oOdYcxslMUUSQn9vF2oKi4Cq+UUQa0hoT8ouZrUCDtpJBYOWtaLAEOBLwHSj
ri9SPwE7avWkI8GG91BGrUsBLpa3HZBOkgRe3MqdtxLkvfdeHDxa5NDZS41s
TYCbL5l7eCBsP+RD9tWiTn2TkKxupSLrOnBOBMgKRD4zicWyJN9LoXPr6oec
J.OORPCcVuRVxSNN.RNg13DhrwomWe1FcGgsQ52RIIG68W8v0FXd9MOeoMQH
dn2D+CsFw3gSNTzYAYG2Cmv94KMRD8u8PotBtgJ8QIT3TRkAKMwKp2xfBlNf
76CFPhC5MOvSGONcuh5NJvXyOCfDw5S+P8o34Z9FV1kwdMbWbsrVW0X+4.qP
TJSZB25DUvSNaJsPw3DESvOaNgOaN6YooT94GmjwRyELtp1EBsIHvPeadhtH
pYzSKCqfr4.0h.2Wbm9V59Qug6e67FbK7FiHfdPScxqMMK5znAflW3aub.XP
Nr89eiKWoXJJnpy54Wr9Mz+iayFv3kObwR8J9i23keBag+fcGO+oM4al6kaj
7m1fmKxwFT7fZCdd+4Nv2MMaCdmUZg6Vuypd+3J0n9AqBesQg1KwzLX.5p1l
lX3QrIlWaI833OgsooQe6gUouijmW++v05KFOQK88dgzLLXgcHiWMzpU0QR+
LqY9gVKDoV5pRqasTVIv7w.Om4l04Gy+eKgjUkA
-----------end_max5_patcher-----------
```

one of the quickest ways i’ve found to learn both dsp and max/msp at the same time(not that i’ve learnt all that much of either ;p).

hope it helps.

EDIT: OH WAIT! you said ‘only max objects’ meaning no signal objects either, i’m an idiot :p

but then hopefully everyone here already knows that! >:D

still… you get the idea… go there, do that, this time only using max(you could still use peek~ for any possible recursion at non-signal rate), easypeasy, teeee heeee! >;D

Raja’s example is noisy, but it’s not white noise. At all.

Your standard white noise is simply a bog-standard random number generator (RNG) producing values at the sampling rate.

If the goal is to get something to a DAC, there are going to have to be some MSP objects involved somewhere down the road (so I don’t read the challenge as "no MSP objects allowed", rather as MSP objects being part of Max). So noise~ is the obvious candidate.

Otherwise, you can implement a simple RNG as `x[n+1] = a * x[n] + b mod c`

with arbitrary values for a, b, and c (although the values should be fairly large and, ideally, mutually prime). That is typically used for integer values in a range like 0 <= x < 2^32; a little scaling will give you floating-point samples in the range 1 <= x < 1. (Getting an inclusive range at both ends is just a tad tricky and, frankly, not worth the effort–you won’t hear the difference.)

While Peter’s answer is true (is always :) ), if you want white noise in the Max domain, you just need to bang a random object at scheduler rate.

Well, what you get is not white noise at audio sample rate, but at max’s sample rate(scheduler rate). It’s the best max can do.

Otherwise, to make noise you can actually hear: peters answer.

Hey. I am looking for the same in pink. That seems a bit more complicated. I know the deviation of the random values must look like a bell curve or one half of it. Can this be done with some math behind a random object.

I think not. I found algorithm examples to generate "pink numbers" in C.

But they use multiple rng to do it. I not fully understand the code example yet. O.

"Raja’s example is noisy, but it’s not white noise. At all."

haha, sorry, maybe i should’ve clarified, but i thought this was obvious before i posted… and was merely trying to be helpful in showing where to go in order to try your own research :)

#OhTheSweetStingOfMaleEgoDominatedElectronicMusicCommunities

also, since they wrote, "but it’s more for purposes of study than anything else"

it actually sounds like the goal would not necessarily be to get audio to the dac.

so this:

x[n+1] = a * x[n] + b mod c

is the answer we ALL needed! :D Thanks!

(when i look through the source for noise~… ooops… i mean… dream of it in my head… ya that’s it… i don’t still have the source code to max5, don’t even think it!… but ya, it looks similar :D

#CarefullyDancingJustWithinTheLimitsOfNDAs)

@olsen

this: http://www.firstpr.com.au/dsp/pink-noise/

seems o imply we can filter white noise tyo get something fairly pink. I’d take the first example right away, seems most straight forward. (although I guess the others might be more accurate)

cheers!

Sorry for any misunderstanding, Raja. But if I misunderstood, others may have, as well.

Regarding the formula I gave: it’s a standard formula in the literature (see, for instance, Knuth *Art of Computer Programming* vol. III). I don’t have access to source code for Max, either, but DDZ wrote the the list many years ago that he simply took the RNG from *Numerical Recipes in C*, which is yet another implementation of the algorithm given by Knuth.

As to pink noise: yes, the samples in pink noise have a Gaussian distribution, but that’s not what makes it pink. What makes pink noise "pink" is the correlation between samples.

This is easy to confirm if you have Litter Pro: lp.gsss~ is a plain, uncorrelated Gaussian generator, mainly used for dithering. It actually sounds the same as white noise at audio levels (to the extent that I doubt anyone could reliably tell the difference in A/B tests). The objects lp.sss~ and lp.zzz~ produce pink noise (using two different algorithms, of which lp.zzz~ is generally considered "superior"… James McCartney developed the algorithm used here, so of course it’s good!).

You can produce pink noise by filtering white noise, but that’s a relatively expensive operation, and it’s only an approximation of "real" pink noise. Tim Place wrote an external using this approach, and it uses a third- or fifth-order filter (sorry, forget which). At the time I wrote lp.zzz~ I compared it to Tim’s implementation, and the Litter implementation used only about 1/8 of the CPU as the filter approach.

OTOH, the filter approach is pretty easy to write in Max/MSP. Direct generation of correlated samples not so easy (although it might be possible to do something clever by adding a series of square waves at octave intervals, going right up to Nyquist, with the amplitudes set by a RNG).

- This reply was modified 3 months by Peter Castine. Reason: Clarified certain details

@peter thanks for clarifying. So it’s not only the distribution.

@woyteg i know nearly nothing about dsp calculations. if i now try to translate this filter example to max

b0 = 0.99765 * b0 + white * 0.0990460;

b1 = 0.96300 * b1 + white * 0.2965164;

b2 = 0.57000 * b2 + white * 1.0526913;

tmp = b0 + b1 + b2 + white * 0.1848;

it seem not to work the way i understand it in max:

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
1768.3oc6as0aaaCE9YWf9efPnOr1lXPRQcaE6gs+FcEAxVzNpSVxPhNIaE6
+93Ec2RxL0WDCvRATpnNT5ie7vuygWxOd+6VXsJ6EZgE3WAeErXwO3krPVln
jEUErvZW3KqSBKjFZsiVTDtkZcW4CYzWXxG.WVWV5gcwoITlrF3pR2jkxJh+
GpnPDbIrk0YGXUliZadZ3No4V+ddbXB3OxRhp+Hp5v968TUCvxB7spmEGIqU
1pueOFGTWk8gr0OFmt8gb5ZlpVtAdKwN2APDOONj.13kh6bWBAeSVq+88uS7
a9utSaNZSRFuQMLcfZ.SNu0w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3bN+u9f9N
v99mLIBDokG7rIPnlDmHFq3m2d7rqt7rxI1+Z5DKYqwoPcoogSnZh37dZlHk
ZxeXmpqcekqy1silVN6gKN2nZTZlsZWxANZC+jCx7HxAWPYP3yog2ZhkIwoi
N4IIDDFLBkTjcHecU2ZsCLnGf3SviEmVOi6u1RSouoOFGE0a1spIBVHlYoZB
852W95guHPslvWjxjwA+.cguLaZCC9xoPAP5w9dlG6OjC8TrOxvXen999NFn
yCTWmG4RhXj99ZJb5Zfv2SeeejAJb5nO78MP1GOWvuJsyl0p2pH7IZzC7OFO
skGBYr73UGXpTL5reCm+xoqwJ1+pVZ4gQxTHXzu71jrUgIka0RcsGZUrq4ue
5szhSuLdCb5srZjsl5DIm2M+TWs14Ih7z8fUImCOqMqazC088vk9Pu1mgZi5
XH.m7HERbcZum5kmBgy6ncWkz+QLE..VAA+VqSyA+1OCdVrqasNNGvu7moBS
QJScsgPgonNlpNfbjRSwRSc7fJSwsLEUdDasUlx1smaq76JeicrUc.l9BnF5
Bku0YGTyfgbI1HVnt8uax2tp61S0c14Suk+PR4wYhn1OEhri0AOPGqxso6bu
J6n6q9W0cerpu3jazJimwT7EGBKfciYGq1OfR+f9fuBn0MEkIgF91BMLTeng
twPyVenAuwcn9ZAMr2sGZ3.8fF1XgFJvbg1LzghfZoqIN292bnomjqbfLxLg
FbFfFrqL+XPCMCCCrMWwChdPydFfFVOnc5Qn6hi1mEmxJyBhOGixbnPpc1H.
M78D0801KuuEft3sXjdsX3LzY.M1fLHMCMids9I1AJ2gR2BaexP2V5jTY701
Goerxw5Hvu1Vqi5uKJDQsceNp+jf6eqc4skFKu8Z1ZcM2DHzSdpeKvfhRKg1
bDk19R39dcXMM5PmA0Wnl4Q6LCPSuQnv.ik0Dqi1YLLnbUV5c90knp+4Vu+Y
Vefyq9nmUc4Gje4+.Fuw7pB
-----------end_max5_patcher-----------
```

what’s wrong? how is this filter calculated correctly and what is the init value for b0-2?

another problem is the floats in the example are too long for max.

hi, it’s written in a (at least to me) reall strange way..

But here you go with a gen version, ready to be translated to max.

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
1342.3oc6assbihCD8Y7WgKdb1rtnEHtruseGolZJhQiilAKn.bRlcpY+1Wc
AHBaSBf7l.iyKlR269zpOcaP5mqrruK6IRo85+Z8sqsr94JKKYUhJrpKaYuO
9osowkxtYWlS1VUjUtMKm7u12n5Qdb016orceof2nZ1PNnMN2ve.hGtNNhGf
3w5OWOJ1g8TVJoRNwn5JoIxkI6tu8mtMSe1gJd2p9QNQM2115ygpU4j.hJ+0
pUhetYfJDi7HewZVpJxSREvdGg0pdeMiUUR+G4pCB050zZv0Wp0gJHXD5Lzq
NWR2whSeVyEBEKdurY6+tfxa67XhtzRJpQhZnfOMzTxCjhRZFSq2V1w44ZUa
oMDA98sL4D4eSaUTlpJnspBxCzlw+bGiK3XVEGvNTnD8mB8sUMxsYqZFZCfB
NtxcNtJD0WsOxCqgobC7tsYopk+10NahtQ6GnaGSy19chDtcZpjuQlQY4EjR
BqJtpVhaaNg703CoUe47aB519Wi2R5cvm0XYYuqfljwDBQmQJptY43v.VtsB
qqLxdvhyOyfK45wgx6hKDVf6RIZa13awyxR61TqQm6oDyn6iqHUTkvhbZmT5
97BJqpyBQXw7439xsEYooclJUKOblVR36K1RdjlTcubtzgRd2o4Ml.6VLJgt
iTV0stp3ckcqoCWl9FVcJfN0+RTAcoC9DWNgPuP8F6YGQeTCXI0fKxS7.iOl
Z3T5APqAMJBDVWH5ma7kYI5i8zpgAs1i7xCkEqeTv.LTjTyu7LnoJ7hS8OcT
8WvFnFkm+qaCb5wF3ursA+ggnePzl.LG6hviA9gPW4vbwtJWgM3WC+Q8f+dW
23OBpweXR3OxX728pF+gv.IzE4NE3udXl.+nkM7+IQZYXjeDL83od3HYNQ9R
JH+nIGOEB9HdZKZ5MJBk1QgLLdJDdUym34gEbAPj2nP+lQgMjNAhV1n+8zxp
rhebQrAHDdB1.Dxend.8kUuyRmR2YCNX5z4tQAZz4dnoCjvxGHQQ9Xv2.vr9
0PYdrQzGwFaQSuQwN2NJiiMdcmqMJLTEkKXT+S+lQYbrQuOhM1flHT3DrAlG
aDvKeJ8HeWCd2gdN5AGMfO2+2.jLxwyfXi.nmng+zSz.fqpXi8ijlGgy4JIB
2YvPG2KSbpqq+BWu.o4AaB+cfgLvGOcnT8soLmfbg+d0XYzRSXG8k6AAYvZ2
nISNtviXySmLw3.MJnzSsgLbxaHOwmXnXkyaCVQYqM3EhiU4H5o9BmSOX7xd
+FGCQl7hSvWDPbg+ZS3qnI6Dq+u5dNJtufI6v5cIcXe9jyjRY8cPQjZin8yC
fkYGJ11XFa9Pzq6pXIjxJJq8fDcaqpbT+tmljz8b6nNpKkhCNSxvocFsH6OP
QVbPSlKxLdnxr.mg4gL6NFYddfyhuDzvjY2Ahy6oI4YTVUYyWLTcvmfZRAe0
WDWTr6p9+u4AMFUclXdFJaiT4lf4AEoxtBh5ZdhdyMOQiQScFulBfqRSCUYo
6tAgqK9VuQzYnpJLMUswmS8vMLTYT6VDTE83l7lRu03.LPb3LjTuaNjAiQlm
GwkDm0hgIyAKv3RNyGYdn4r.9Syutgrt181Ez8qaJV6Wi7hdu7qggluILixC
BMFYdl3WOz7MAzxKgFX97eQFJ8YfYIlTGO1W2ottTsOsu26kK8Pi5MeBTOz3
GgyGWCXDf7LgAZnYxBvrAlGZvoKE+y5Ou54Zpuphxos6akRcyEOVYpu+hmB7
5BWOJPmnCmJ7mJ3cDtitNfBA4nqA3QWAvSu9e8c0+3qyuV8e.D8WgvA
-----------end_max5_patcher-----------
```

(made it in gen~ so I can more easily verify that it actually produces pink noise)

ah what the heck, below is the max version attached. I wrote the values in a buffer too to look at the buffers spectrum (using the spectrumdraw external from the HIRT) for confirming that it works. cheers!

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
1156.3oc2ZssbihCD8Y6uBJdb1LtTKgDv717cr0VagskSXFt3BjS7lol7suf
D3KY.aIEO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z87NBk07ZQZgb76S
5T6RwbRmdJc8Zdwoq045z5jkY70iuHCZaOHMrGh6rm1W+y04mX2YOTcrGlyr
GPG2E0czCYZImemxXX6Abm2RGyAG5N2Enq8.tycgulbF4N4CSC9IzslCbM0L
1s1y0bW.ys1C4J1SfyLmHcx83tbg.nq83lfcfpq8fcSoO5ZND2POZIebWkO5
4tbWzEnk+hdE4bd55skMSCnq781OYk1ooqlUJAjegVu6Hj5sNGhNbzQi31gN
ltnaJk7vciLC5LOEoQaf2GBhOw6iA3Due+QJuOz+oG7ax6i0Ectgs0YRXQSp
wUcWdwXM4FCzgmICgyjgvYxPSTgpkpHY61m4U0clmDT94Ieqr5vWGWiwTnNT
9t+8q3Om12eUGRpV8TpfuRrqRsXI6iX9yaeN+b9+BxqRTnB
-----------end_max5_patcher-----------
```

how comes that your example produces output greater than 1. and smaller then -1. ?

Good question, I have not the faintest idea. Didn’t think about the filter itself, just implemented it…

seems a division by 40 is close to normalization

40? for me a division by 8 seem to be closest to what i get when i record pink~ into the buffer..

Ah, I don’t know, I tried it with the gen version. Might be different..

thanks anyway. it seems to be close to the solution. i wonder what exact last scaling step is missing.

yes, that’d be really useful I guess..

What about recording the impulse respons of the filter? That migh get you there I guess(?)