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

    May 14 2014 | 9: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 15 2014 | 12:08 am
      What about the noise~ object?
    • May 15 2014 | 3:26 am
      "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 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:
      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
      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 | 12:28 pm
      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
    • May 15 2014 | 2:15 pm
      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 | 10: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 | 11: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 16 2014 | 3:11 am
      @olsen this: 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 | 1:47 pm
      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).
    • May 17 2014 | 10: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:
      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 | 11: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.
    • May 17 2014 | 11:14 pm
      (made it in gen~ so I can more easily verify that it actually produces pink noise)
    • May 17 2014 | 11: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!
    • May 18 2014 | 12:23 am
      how comes that your example produces output greater than 1. and smaller then -1. ?
    • May 18 2014 | 12:28 am
      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 18 2014 | 12:46 am
      40? for me a division by 8 seem to be closest to what i get when i record pink~ into the buffer..
    • May 18 2014 | 12:48 am
      Ah, I don't know, I tried it with the gen version. Might be different..
    • May 18 2014 | 12:59 am
      thanks anyway. it seems to be close to the solution. i wonder what exact last scaling step is missing.
    • May 18 2014 | 1:02 am
      yes, that'd be really useful I guess.. What about recording the impulse respons of the filter? That migh get you there I guess(?)