Offline
Sweeeeeeden
boomlinde wrote:

Finally a home for bad PRNGs!

Actually, I misread the code. Rather than being LFSRs, these things produce their out value only from the index from the counter. There is no feedback, so by default, the code works in divisions of two of the sample frequency (/2, /4, /8 and so on.) It might still qualify as a PRNG (pseudo-random number generator) given a random-like enough function. In particular, you'd need to mix in some multiplication, division or modulo by some "good" number, preferably add or even prime.

And anyway, I'm writing a huge-ass post about the theory behind all this. Hopefully it'll be done before the weekend ends.

Last edited by nitro2k01 (Sep 30, 2011 9:28 pm)

Offline
ad-hell-aide

This is all very inspiring, I have to say. I could spend hours / days on this stuff.

Offline
hardcore, Australia

Here's a few examples for Arduino developed by the Dr (little-scale) and myself.
To run it you need an arduino, with an R2R DAC on PORTB pins 0 - 3 (i.e. digital pins 8, 9, 10, 11).


Here's an image to help you with the R2R DAC
I didn't follow that image in regards to R1 and R2, I just used a single value for everything.

Personally I used a piezo buzzer on the output, but you could put it through an amplifier or whatever you wanted.


void setup() {DDRB=B00001111;}
void loop() {for(long i=0;i<1000000;i++) {
PORTB = i / 3 >> (i % 40 + 5) | i / (24 + i & 3) >> (i % (15 - ((i >> 15) % 8) * 6) + 5);
}}

An example from the doctor-scale, with audio.
http://milkcrate.com.au/_other/useless/ … r_%234.mp3
And it's tweetable.
http://twitter.com/#!/littlescale/statu … 7984927744

void setup() {DDRB=B00001111;}
void loop() {for(long i=0;i<100000;i++) {
PORTB = i / 3 >> 1 | i / 2 >> 2 & (i / 5) >> 7 | i & 31 * i * (i >> 8);
}}

void setup() {DDRB=B00001111;}
void loop() {for(long i=0;i<100000;i++) {
PORTB=i/152>>(i%(i/9939))|((i%5)>>(17*15));
  }}
void setup() {DDRB=B00001111;}
void loop() {for(long i=0;i<100000;i++) {
  PORTB = i / 7000 >> (i % (i/5)) | i / (24 + i & 6300) >> (i % (137 - ((i << 15) % 8) >> 6) + 5);
}}
void setup() {DDRB=B00001111;}
void loop() {for(int i=0;i<100000;i++){
  PORTB=i/70>>(i/7<<(i/8))<<i*9%(24+i*30)>>18766*(i*5%4);
}}
void setup() {DDRB=B00001111;}
void loop() {for(int i=0;i<100000;i++) {
PORTB=i/992>>(i%(i/939))<< (i*i*i)>>((i<<5)>>(17/i)); 
}}
void setup() {DDRB=B00001111;}
void loop() {for(long i=0;i<100000;i++) {
PORTB=i/12>>(i%(i/939))%((i%93)>>(17*3)); 
}}

Basically just play around with numbers, "int" and "long" can be changed for varying sounds.

Last edited by godinpants (Oct 1, 2011 10:48 am)

Offline
A gray world of dread
viznut wrote:

The exploration continues!

Inspiring indeed. Incredible how the math translates into those patterns.

Lazerbeat wrote:

Forgive me but would someone be sweet enough to really dumb this down for me and explain it like im 5? It sounds awesome but I feel I am missing a bit of the awesome due to lack of background knowledge.

I'll try the basic stuff. Nitro's post will undoubtedly be more in-depth.

The output for these is 8bit / 8kHz. That means the amplitude range is from -127 to 127 (or 0 to 255) in decimal values. At 8kHz, I can put 8000 characters per second to the output. PCM encoding for 8bits means that the output value to the sound generator will be directly translated into an amplitude value.

The program is a simple loop which increases the t variable until it hits 65535 (assuming it's 16bits), then snaps back to 0. It only consists of a function which will put out a char value (8bits). Should the input equation be larger than 8bits, it will be shortened (truncated) to 8bits.

The clever thing here is to choose constants and operations in such a way that they'll modify t to generate a "pleasing" output, ie something that sounds pattern-y enough to pass as structured music.
Which is awesome, because it gives a peek into how the math of something looks which our brain recognizes as "music".

Offline
Russia, Moscow

I'm pretty sure t is 32-bit.

Offline
Philly, PA, USA

unnecessary post, sorry

this is still super cool

Last edited by pixls (Oct 1, 2011 5:25 pm)

Offline
ad-hell-aide

Having a 32 bit number means that the loop can go for much longer, allowing for a longer piece of music before it repeats and also allowing for a wider range of output based on the index.

Offline
Sweeeeeeden

odinpants: Correct me if I'm wrong, but if you set DDRB to B00001111, doesn't that mean you're only outputting the 4 lower bits?

Offline
ad-hell-aide

The R2R DAC that we were using was only 4 bits in depth.

Offline
Sweeeeeeden

Oh wait, I'm an idiot. I skipped the boring part and only looked at the code.

Offline
ad-hell-aide

Seven Arduino examples with audio: http://little-scale.blogspot.com/2011/1 … imple.html

Offline
geldrop

cool project!

Offline
A gray world of dread
gijs wrote:

cool project!

Thanks for that!
Did something with it.

Offline
Milwaukee, WI

I'm not sure why it took me this long to find this thread but here's my (admittedly uneducated) contribution - Vic 20 "math music" from '04:

http://dispyz.radiograffiti.org/track/i … 1-vic-2004

I'm not sure if the method of creation of this exact piece was a line of C, but I do know he's been known to do that very thing over the years. Perhaps he's got some code to share.

Offline
A gray world of dread

Part 3


The Chaos Theory cover is a jaw dropper. Was this reverse engineered somehow?

Offline
Sweeeeeeden

µB: That one and any one that contains a string is "cheating". Instead of generating the sound algorithmically, the content is sequenced and stored as a string. While certainly still cool, I think it's no longer made in the same original spirit. You're no longer just letting the numbers speak.