Quote:
Originally Posted by geekmaster
In this case, the "funny number stuff" is just there to synthesize some interesting noise.
If this had been a "musical synthesis" demo, I would have tried to show what was going on in the "magic formulas". This is so simple I did not think that necessary, but because you are "into" music, I will do that now:
Geekmaster "noisy rhythms" Demo,
Sound Synthesis Algorithm,
Theory of Operation:
Spoiler:
The C "random()" function returns a random positive integer value (including 0). Normally you limit it to a range by truncating it. In this case, the "&3" keeps only the bottom two bits (giving random values in the range 0-3).
The outer "i" loop is repeated 256 times, and each iteration plays a 1024-byte sound buffer after it is filled with "amplitude modulated" random number by an inner "j" loop.
In the inner "j" loop, the buffer gets filled with 1024 2-bit random numbers that have been multiplied by (i*350). This multiplication changes (modulates) the maximum value of the result (i.e. the peak amplitude of the waveform in the buffer). In this case, i*350 causes the max value to be greater than 255 in many cases, so when the value is truncated to 8-bits and stored into a 1-byte sound buffer position, it gets "distorted" in a way that causes some very large numbers to become small (quiet).
Because the amplitude modulator control variable "i" sweeps from 0-255 while this demo plays, each 1024-buffer (short time period of random "hissing" noise) gets its volume set to a different "constrained random" value. I chose different multiplier (distortion/gain) values until I found a value (350) that sounded pleasing with a nice syncopated periodicity, giving it a not-so-annoying semi-percussive rift.
Enough? Or should I continue? I can go into deeper layers of detail on number theory, human perception, software algorithms and optimization, and personal opinion all day long. I think I will quit now. Any questions? 
|
Excellent! I think that covers it nicely sir.
In other news I think I finally managed to x-compile alsa...