So you basically have s=f(t) where s is the output sample, t the sample id and f a simple expression as the one I put on the title.
The thing is you can actually build quite complex song with it !
This technique has been called bytebeat and the main article describing it was made by someone named "viznut".
See the original article here http://countercomplex.blogspot.fr/2011/10/algorithmic-symphonies-from-one-line-of.html or here http://canonical.org/~kragen/bytebeat/
and and example with trippy visualizations :
I surely will include one or two of them in a test audio program on the sdk .. In the meantime here is the code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include "bitbox.h" | |
int song; | |
unsigned int t; | |
// bitbox port Makapuf 2015 - code GPL - songs by their respective author, idea and first implmentation by Viznut | |
// See : http://countercomplex.blogspot.fr/2011/10/algorithmic-symphonies-from-one-line-of.html <-- not one line of html :) | |
// also : http://pelulamu.net/countercomplex/music_formula_collection.txt | |
/* yes, the whole melody is done with single line equations ... */ | |
void game_snd_buffer(uint16_t* buffer, int len) { | |
uint8_t u=0,v; | |
for (int i = 0; i < len; i++) { | |
if (i%4 ==0) { | |
t++; // sample rate = 8kHz | |
switch(song) { | |
case 0 : u=(t*(t>>8|t>>9)&46&t>>8)^((t&t>>13)|t>>6); break; // "lost in space" by xpansive | |
case 1 : u=(t|(t>>9|t>>7))*t&(t>>11|t>>9); break; // by red- | |
case 2 : u=(t*5&(t>>7))|(t*3&(t*4>>10)); break; | |
case 3 : | |
v=t>>(7-(t>>15))&-t>>(7-(t>>15)); // By droid | |
u=v?t>>4|(t&(t>>5) / v) : 0; // guarding against divbyzero | |
break; | |
case 4 : u=t*(42&t>>10);break; // by .. many | |
case 5 : u=(t>>(t>>5*(t>>13)%8))|(t>>4) ;break; // by The_Cjay | |
case 6 : u=((1-(((t+10)>>((t>>9)&((t>>14))))&(t>>4&-2)))*2)*(((t>>10)^((t+((t>>6)&127))>>10))&1)*32+128;break; // by Ola | |
case 7 : u=t*((t>>13)&31&t>>9)-((t>>7)&23&t>>3); break; // ack | |
default : u=0; | |
} | |
} | |
buffer[i] = u<<8 | u; | |
} | |
} | |
// complex "game" indeed | |
void game_init() {} | |
void game_frame() { | |
static int pb; | |
int b=button_state(); | |
if (b&!pb) { | |
song = (song +1 )%8; | |
t=0; | |
message("song %d\n",song); | |
} | |
pb=b; | |
} | |
void graph_line() {} | |
void graph_frame() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAME=bytebeat | |
GAME_C_FILES=main.c | |
NO_USB=1 | |
NO_VGA=1 | |
include $(BITBOX)/lib/bitbox.mk |
it'd be cool to have a interpreter to put things in like this...
ReplyDeletealso, release the source code! (or link it here...)
ReplyDeletedone !
ReplyDeleteThis comment has been removed by the author.
ReplyDeletethat was a double post. looks great, thanks makapuf!
ReplyDeleteare there any stereo algorithmic songs yet? :)
ReplyDeleteI wonder if IBNIZ (https://github.com/viznut/IBNIZ) would run fast enough on the Bitbox to be useful...
ReplyDeleteThanks for example with trippy visualizations :) It seems to me that Mario and Sonic games had the similar music and graphics.
ReplyDelete