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?
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
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.
@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).
@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:
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.
(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!
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(?)