{
"code" : "/* The sounds of Fibonacci\r\nIn the Fibonacci-sequence every term is found by adding the two previous terms:\r\n\r\n0, 1, 1, 2, 3, 5, 8, 13.....\r\n\r\nIf you divide the terms of the Fibonacci-sequence by any given number and note the remainder, you will find a repeating sequence called the Pisano Period (Leonardo Pisano was the real name of Fibonacci):\r\n\r\n2: 0, 1, 1, 0, 1, 1, 0, 1, 1, 0...\r\n3: 0, 1, 1, 2, 0, 2, 2, 1, 0, 1, 1, 2, 0, 2, 2, 1...\r\n\r\nThis is great, because you can simply turn a Pisano Period into sound! For the number 2 the period has a length of 3 and using a sampling rate of 44100 this will result in a tone of 14700 Hz, which is within audible range (if you are young enough). The Pisano Period for the number 1000 is roundabout 1500, which will give you a tone of about 30 Hz, well within audible range.\r\n\r\nAny term of the Pisano Period for a given number can be found by adding the two previous terms of that Pisano Period, divide it by the given number en note the remainder. That's nice, because you don't have to work with the enormous numbers of the original Fibonacci-sequence.\r\n\r\nAny Pisano period will contain 1 or 2 or 4 zeros.\r\n\r\nThis idea was inspired by this video:\r\nhttp://www.youtube.com/watch?v=Nu-lW-Ifyec\r\n\r\nThe Fibonacci-sequence can be found in the Online Encyclopedia of Integer Sequences:\r\nhttp://oeis.org/A000045\r\n\r\nas well as the sequence of lengths of the Pisano Period for different numbers:\r\nhttp://oeis.org/A001175\r\n\r\n */\r\n \r\n s.boot;\r\n a=Array.new(14700000);//array for storing 1000 sounds each with a duration of 1/3 of a second\r\n c=Array.newClear(14700) //array for storing 1 sound with a duration of 1/3 of a second\r\n c.put(0,0);\r\n c.put(1,1);\r\n (\r\n for (2, 1000, {arg j; // voor j=2 t/m 1000, divisors\r\n\tfor (2, 14699, {arg i; c=c.put(i, (c[i-1]+c[i-2])%j)});\r\n\t c=2*(c+0.5)/j-1; //normalise, this will but the values conveniently between -1 and 1\r\n \tfor (0, 14699, {arg i; a=a.add(c[i])});\r\n \t// a.add(c); will not work: a will contain an array in each cell in stead of a number\r\n \tc.put(0,0); //this is necessary after normalising\r\n \t c.put(1,1);\r\n });\r\n ) //this will take a few seconds\r\n a=a.add(0); //to avoid glitches when switching the sound of. It also prevents nasty effects when playing the sounds repeatedly\t\r\n b=Buffer.loadCollection(s, a);\r\n x = { PlayBuf.ar(1, b, BufRateScale.kr(b), loop: 0) };\r\n x.play;\r\n x.free;\r\n b.free; \r\n a.free;",
"name" : "The Sounds of Fibonacci",
"labels" : [
"mathematics",
"research"
],
"id" : "1-4VW",
"ancestor_list" : [],
"description" : "Pisano Periods for the numbers 2 to 1000 converted to sounds",
"author" : "henk.lasschuit",
"is_private" : null
}