Forums > MaxMSP

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

May 14, 2014 | 2:35 pm

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


May 14, 2014 | 5:08 pm

What about the noise~ object?


May 14, 2014 | 8:26 pm

"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

– Pasted Max Patch, click to expand. –

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


May 15, 2014 | 5:28 am

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.)


May 15, 2014 | 7:15 am

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.


May 15, 2014 | 3:54 pm

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.


May 15, 2014 | 4:13 pm

"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)


May 15, 2014 | 8:11 pm

@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!


May 16, 2014 | 6:47 am

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 4 months by  Peter Castine. Reason: Clarified certain details

May 17, 2014 | 3:18 pm

@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:

– Pasted Max Patch, click to expand. –

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.


May 17, 2014 | 4:12 pm

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.

– Pasted Max Patch, click to expand. –

May 17, 2014 | 4:14 pm

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


May 17, 2014 | 4:26 pm

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!

– Pasted Max Patch, click to expand. –

May 17, 2014 | 5:23 pm

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


May 17, 2014 | 5:28 pm

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


May 17, 2014 | 5:46 pm

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


May 17, 2014 | 5:48 pm

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


May 17, 2014 | 5:59 pm

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


May 17, 2014 | 6:02 pm

yes, that’d be really useful I guess..
What about recording the impulse respons of the filter? That migh get you there I guess(?)


Viewing 19 posts - 1 through 19 (of 19 total)