Bytebeat: Sound from Javascript functions

(Description copied from StephanShi's website)

Bytebeat

Bytebeat music (or one-liner music) was invented in September 2011. They're generally a piece of rhythmic and somewhat melodic music with no score, no instruments, and no real oscillators. It's simply a single-line formula that defines a waveform as a function of time, processed (usually) 8000 times per second, resulting in an audible waveform with a 256-step resolution from silence (0) to full amplitude (256). If you put that formula into a program with a loop that increments time variable (t), you can generate the headerless unsigned 8 bit mono 8kHz audio stream on output, like in this application. Since these directly output a waveform, they have great performance in compiled languages and can often be ran on even the weakest embedded devices.


Famous bytebeats

  • 42 Melody: t*(42&t>>10) (8000Hz, 8s)
  • Neurofunk: t*((t&4096?t%65536<59392?7:t&7:16)+(1&t>>14))>>(3&-t>>(t&2048?2:10))|t>>(t&16384?t&4096?10:3:2) (8000Hz, 32s)
  • Moon Scanner Generalization: 2*(t>>5&t)-(t>>5)+t*(t>>14&14) (8000Hz, 32s)
  • Sierpinski Harmony: 5*t&t>>7|3*t&4*t>>10 (8000Hz, 8s)
  • Street Surfer: t&4096?t/2*(t^t%255)|t>>5:t/8|(t&8192?4*t:t) (8000HZ, 4s)
  • Fanfare: (t&8192?t&4096?t&1024?2*t:4*t:t&512?4*t:4.2*t:(t&4096?t&1024?2*t:10*t:t&512?2*t:8*t)>>2)*(t&16384?3:2)|t*(t&16384?1/8:1/(.01*t)) (8000HZ, 4s)
    There are many more out there.
    The sample bytebeat for my project: t*=4/3,e=(a,b)=>a>=0?a%b:(a-Math.floor(a/256)*256),f=(x,v)=>(e(x,256))/v,g=(...a)=>a.map(it=>f(it,a.length)).reduce((a,c)=>a+c),h=a=>t<65536?0:(t*a)^(42-(t*a)),kick=10000/(t%4096),g(h([1.5,1.5,1,1.5,1.6,1.6,1,1.6,1.667,1.667,1,1.667,1.6,1.6,1,1.6][(t>>11)%16]*2),h(4/[4,5,6,5][(t>>13)%4]),t/131072%5<1?0:t/131072%5<3?h([4,4.5,0,4.5,0,4,0,4,4,4.75,0,4.75,0,4.5,0,4.5,4,4.5,0,4.5,0,4,0,4,4,4.75,0,4.75,0,4.5,0,4.5,4,4.5,0,4.5,0,4,0,4,4,4.75,0,4.75,0,4.5,4.2,4,7.5,7,7,7,0,0,6,5.25,6,6,6,6,0,0,0,0][(t>>11)%64]):t/131072%5<4?h([4,4,0,4,4.5,4,4.5,0,4.75,4.75,0,4.75,4.5,4.75,4.5,0][(t>>11)%16]):h([4,0][(t>>16)%2]),t*[128,0,0,0,128,0,0,0,128,0,0,0,128,0,0,0,128,128,128,128,0,0,0,0,128,0,0,0,128,0,0,0][(t>>8)%32],kick,kick,kick,kick,[0,0,1,0,1,0,1,1][(t>>10)%8]*Math.random()*256) (8000HZ, 61.46s)

As it turns out, there were 3 bytebeat projects before mine.

..how??

How I made the sample song? Or how this works in general?

Honestly, both. What is the value of t?

  1. t represents the index of the current sample. The full file is modulo 256 and then divided by 256 to produce a valid sound for Snap !. E.g. if your bytebeat was "t" and you were on sample 255, the corresponding sample in the audio file would have the value 0.9960375. However, if you were on sample 257, the corresponding sample would have the value 0.00390625. This causes it to produce a click sound on sample 256, as it immediately goes from 0.9960375 to 0. Additionally, if your bytebeat was "t*2", it would multiply every number by 2, causing it to be skip-counting to 512 by 2. Then the full file is modulo 256, causing it to be skip-counting to 256 twice, and then divided by 256. This causes there to be a click on both sample 128 and 256, doubling the click sounds and therefore doubling the frequency. Now apply this to every javascript function there is that returns a real number value.
  2. 1 year of using bytebeat
    Also I'm the same person who made the "Working Tetration Function" from last year.

Hm, interesting

I do remember you, welcome back! I think you are also interested in searching the properties of the infinitesimal numbers in the special syntax of algebra, it is not? By the way, your project seems like useful for describing numbers using functions to get those colors. :~)
Also I had to modify a copy of that to get this result, it looks like a bunch of marine waves...

the project is a lot slower than it could be because the same javascript function is created for every sample. reusing it is much faster. it's also standard practice to define some extra variables for compatibility with older bytebeats. i just copied over the relevant code from my bytebeat website.

i also added click to replay because minibake (210 seconds with an incredibly large and inefficient eval) still takes an hour to load