Create your blog and photo album with postbit
Create your blog and photo album

Create new post


Upload a picture:
Tags (keywords separated by comma)

Save Cancel
The JavaScript Blog js:   Followers: 3 ; Following: 3

Explore The JavaScript Blog's photo albums:
Photos from posts (7)
Javascript tools (2)

Digital Computer Music with Bitwise Operators

Bytebeat Music

Bytebeat music is a new kind of mathematical experimental extreme minimalist music using binary logical operators (binary arithmetic).
Very small equations can produce melodies and rhythms.
It is an interesting discovery in Computer Music made by (or shared by) Viznut (Ville-Matias Heikkilä). Here we create some of these sounds using JavaScript audio.

Those sounds use binary operators in equations to create music and sound effects.
Complex sound waves can be generated by combining time variable (t) and bitwise operation (logical AND, OR, SHIFT,...) to create patterns and structures that can be converted to sound to create beats, effects and a new kind of electronic music. Some of these sounds effects are similar to video game music, chiptune (chip music), Sawtooth wave, 8bit music synths and the demo scene assembly-generated music and tunes.

Here are some of my first "compositions" while playing with the equations:
Left audio channel: t*((t>>24|t>>44)&51&t>>1)
Right audio channel: t*((t>>24|t>>44)&15&t>>1)
Sample frequency: 22050 Khz
Left: t*((t>>12|t>>31)&51&t>>6)
Right: t*((t>>12|t>>31)&51&t>>5)
Sample frequency: 22050 Khz
Left speaker: (t/3)*((t>>12|t>>31)&31&t>>4)&68
Right speaker: (t/4)*((t>>12|t>>31)&31&t>>5)&68
Sample frequency: 44100 Khz
Left: (t/4)*(((t/2)>>12|t>>13)&15&t>>5)&180
Right: (t/3)*(((t/2)>>12|t>>13)&15&t>>4)&180
Left: (t/2)*((t>>12)&(t/2))&90
Right: (t/3)*((t>>12)&(t))&90
Sample frequency: 44100 Khz
Left: ((t/4)*((t>>12)&(t/2))&60)
Right: ((t/3)*((t>>12)^(t/2))&60)
44100 Khz
44100 Khz : sin(t*(sin(t*0.01)*0.0005))*63 : sin(t*(sin(t*0.003)*0.00015))*63 : sum of two sin waves
44100 Khz
This one does not have any bitwise operators, only sine curve to generate the sound.
Left: (3000/(t&(2100+t/4100))&1)*35 - (3000/(t&2100)&1)*35
Right: (3000/(t&(2200+t/2000))&1)*35 - (3000/(t&2200)&1)*35
44.1 Khz
Left: (3000/(t&(t>>10))&1)*35
Right: (3000/(t&(t>>11))&1)*35
44.1 Khz (with drums!)
Left: (3000/(t&(t>>10))&1)*35+(3000/(t&16383)&1)*35
Right: (3000/(t&(t>>11))&1)*35+(3000/(t&21383)&1)*35
44.1 Khz
Left: (3000/(t&(t<<10))&1)*35
Right: (3000/(t&(t>>10))&1)*35
44.1 Khz

Variation of this:

Improved complete version: (fade-laser effect) (fade-laser effect. This second version is better because of the "fade in effect" in the beginning to reduce starting noise)
Melody in two parts (3 seconds each), using the ternary operator:
t<(44100*3) ? (t/4)*((t<<1|t>>4)&13&t>>12)&58 // First part
: (t/6)*((t<<1|t>>4)&13&t>>12)&58 // Play after 3 sec.
Simple demo of two seconds audio.
Second 1 is a pure "t" note, second 2 is "t/2" (half frequency). Using ternary operator (condition true ? then : else).
t<44100 ? (t) : (t/2)
44100 Khz
Simple demo of a pure note of 440 Hz (pitch standard) using sine wave:
sin(frequency * 2 * PI * t/sample_rate) * Amplitude
sin(880*2*3.14*t/44100)*128 * Math.exp(-2*t/44100)
Same as above, but with "fade effect" created by decreasing amplitude using exponential function. Sound fades in about 2 seconds.
Same as above, but with inverse fade effect (volume increases) using "1-exp" function, so it will start as "0" and end as "1" as time increases: (...)*(1-Math.exp(-0.6*t/44100))
Water drop sound effect with echo. Change exp from -4 to -14 to increase fade effect and hear only one drop with no echo. Does not use bitwise operators, only plain cosine wave functions.
White noise (random number generator between 0 and 1, times 256 that is amplitude):
Based on the equation from Viznut's Countercomplex blog.
Left: (t*1&t>>7|t*3&t>>7|t*2&t/1024)
Right: (t*2&t>>7|t*4&t>>7|t*3&t/1024)
Improved version from above. Faster (>>6 instead of >>7) and more bass (t*0.5 instead of t*2).
Left: (t*3&t>>7|t*1&t>>6|(t*0.5)&t/1024)
Right: ((t*1)&t>>7|t*2&t>>6|t*3&t/1024)
Three tones, one after another.
( ((t*3)&t/256) | ((t*2)&t/512) | ((t*1)&t/1024) )
One tone:
Left: ((t/5.5125)*1000>>14) | (t/5.5125)*2000>>10
Right: ((t/5.5125)*500>>15) | (t/5.5125)*1000>>10
(Bass base, repetitive sound)
((t)*100>>14) | (t)*800>>12
((t)*100>>15) | (t)*800>>11
Left: ((t/2) & (t)>>6 | (t*3&t>>7) |(t*2)&t/1024 ) * "8421"[t>>16&3]/2
Right: (t*(t/2) & (t)>>6 | (t*3&t>>7) |(t*2)&t/1024 ) * "8421"[t>>16&3]/2
Left: (((2*t/ ("5434"[(t/2)>>16&3]) )) & (t/2)>>6 | ((t/2)*2&(t/2)>>7) |((t/2)*2)&(t/2)/1024 ) * "8421"[(t/2)>>16&3]/ 2
Right: (((2*t/ ("5434"[(t/2)>>16&3]) )) & (t/2)>>6 | ((t/2)*2&(t/2)>>7) |((t/2)*2)&(t/2)/1024 ) * "8421"[(t/2)>>16&3]
Sierpinski Triangle Music
t << (8%((t*1)&t/256))
Improved version of the Sierpinski Triangle music:
127%(t/16) >> (8 % ((t*1)&t/256))
Stereo version of Sierpinski music:
Left: 127%(t/16) >> (8 % ((t*2)&t/256))
Right: 127%(t/16) >> (8 % ((t*3)&t/256))
This one was created by "mu6k" (a demo scene hacker) and is one of the most interesting that I've seen. Great rhythm with drums beat, bass, harmonic tones. Let's try to decode part of it:

(3e3/(y=t&16383)&1)*35 + // first part
(x=t*"6689"[t>>16&3]/24&127)*y/4e4 + // second part
((t>>8^t>>10|t>>14|x)&63) // third part

The full equation creates some variables (x and y) that are used later. The three parts are added (with the "+" operator) so they are played together as a single composition.

The Drum
The first part is the beat (electronic drum):
(3000/(t&16383)&1)*35 (play)

Change the &16383 to other values to test other beat sounds, like this:
(3000/(t&21440)&1)*35 (play) or (3000/(t&2600)&1)*35 (play)

Tonal melody
The second part contains the melody (four notes are represented by the numbers 6,6,8,9) and can be isolated as a single equation that will play the four notes (44.1 Khz):
(t*"6689"[t>>13&3]/24&127) (play)
I changed from "t>>16" to "t>>13" because this seems to mean the note duration. It will play twice as fast when you subtract one number. So "t>>13" will play 2 times faster than "t>>14".
A more intuitive way to write would be:
(t*"6689"[(t>>13)%4]/24&127) // "%4" means 4 notes.

Changing it a bit (from "&127" to "&32"), it will sound more "pure", because it seems to be a filter:
(t*"6689"[t>>13&3]/24&32) (play)

Make a pulse effect to each note:
(t*"6689"[t>>15&3]/24&127) * (t&8191)/12000 (play)

And the third part of the equation uses this melody (encoded in the "x" variable) and adds some effects to it.

Mega Laser War:
Left: (600000/(t*t/280000&16383)&1)*8
Right: (600000/(t*t/380000&16383)&1)*8

Space Engine:
Left: (70000/(t*t*t/540000000&16383)&1)*10
Right: (70000/(t*t*t/340000000&16383)&1)*10

Riff duo:
Left: t*(t>>12)&(1)*t
Right: t*(t>>12)&(2)*t

Riff octaves:
Left: t*(t>>12)&(1)*t
Right: t*(t>>12)&(2 * parseInt(t/(44100*2)) )*t

Fading bass:
Left: (t&t%252)^t*0.5 - (t>>12)
Right: (t&t%254)^t*1 - (t>>11)

Blinking Bells:
Left: 63&t*(t>>12) * (1+( t>> 14) )
Right: 63&t*(t>>12) * (1+( t>> 13) )

I also wrote a PERL script to create sound waves that can be output to the audio speaker (/dev/audio):

(Equations by Rodrigo Siqueira)

Summary of bitwise operators in Javascript:
Bitwise AND: a & b
Bitwise OR: a | b
Bitwise XOR: a ^ b
Bitwise NOT: ~ a (invert the bits)
Left shift: a << b
Right shift: a >> b

More information:

Algorithmic symphonies from one line of code - how and why:

Audio visualization and sounds of many of those formulas:

Some deep analysis of one-line music programs:

Forum to post and share formulas:

Music formula collection:

Hacker News (Ycombinator) discussion:

The future:
Produce generative music using pentatonic scale, because pentatonic scale always sounds good and it is natural (see Bobby McFarrin hacks your brain with music TED video and listen to Minor Pentatonic Scale examples (from the "Color Your Major Chords Using Minor Pentatonic Scales").

Post by The JavaScript Blog (2011-11-10 17:15)

From: Kymatica
Also there's an app to do this in realtime on iphone/ipad: BitWiz Audio Synth, 2012-05-28 13:28

Post your comment:

Name: Email: Site:

| Explore users | New posts | Create your blog | Create your photo album |
| About Postbit | Our blog | Terms of use | Contact Postbit |

Copyright © 2017 -