Gray Noise

FP's icon

Is there any Gray Noise code somewhere (Max or Gen) ?

I had sc.graynoise but it is broken in Apple ARM.

Thx.

Graham Wakefield's icon

If you have a filter that imparts an "equal loudness" contour, would passing white noise through it do the job?

Having said that, the description in supercollider (if that is what sc.graynoise refers to) looks different: "Generates noise which results from flipping random bits in a word." So the "Gray" in the name actually refers to graycode (binary decomposition -- see https://en.wikipedia.org/wiki/Gray_code). [https://doc.sccode.org/Classes/GrayNoise.html]. Source is at https://github.com/supercollider/supercollider/blob/90dbcbddaddc072f615fabd22214388311748f64/server/plugins/NoiseUGens.cpp#L216:

counter ^= 1L << (trand(s1, s2, s3) & 31); ZXP(out) = counter * 4.65661287308e-10f;

This code is incredibly dense, but can be made sense of. Counter is an int32, and is state that is in a feedback operation (we update counter each sample with ^=). ^= means applying an XOR to this integer. The trand(s1, s2, s3) is defined elsewhere, but just generates a random 32-bit integer. & 31 means that it will wrap in 32 bits, never be larger than that (I'm not sure why that's needed here.) 1L << that means left bitshift as a 64-bit integer by one step. 1<<0 = 1, 1<<1 = 2, 1<<3 = 4, etc. So the minimum random value is 1. So, on every sample, we XOR our stored "counter" with a random integer that is between 1 and 2^33, I think. This is then wrapped back to 32 bits because counter is an int32. Then the * 4.65661287308e-10f part is to convert this into a 0..1 range by dividing by 2^31.

We don't have bit operators in gen, but you can emulate it (thought it certainly won't be as efficient). You'd have to decompose the signal into 32 bits first, and do the same to an abs(noise()), do xor operations on each pair of corresponding bits, then recompose this into a number again. That number would be fed back to the input.

FP's icon

Ho, thank you very much for this explanation. Very clear.

Anyway Volker sent the sc-max Silicon version on another thread. Yeepi!

So I'll give a try to this later...