Skip to content

ern0/bytebeat-player

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bytebeat-player

What is it?

It's a very simple bytebeat player, using SDL2 (tested on MacOS and Linux/Ubuntu).

Bytebeat is a method for producing music. The music is produced by a function, which calculates the actual sample value from the time tick value:

byte sample = funct(int tick)

You can read more about it in post: Algorithmic symphonies from one line of code -- how and why? - Don't miss the videos!

Create your own music!

Step 1: Create your music as a separate .cpp file in song/ directory. This is my "simple house" formula, you can find it in song/simple_house.cpp:

const int FREQ = 4000;
const int VOLUME_MUL = 50;

#include "bytebeat-player.cpp"

u32 byteBeat(u32 t) {

  u32 drum = divnz(3300,modnz(t,2000)) * 17;
  u32 bassline = ( modnz(t,2000*4) < (2000*1.2) ? t*4 : 0 );
  u32 tunfm = (t*4) | ( 4*t * (( divnz(t,2000*8) & 3) + 5) );
  u32 tune = ( modnz(t,2000) > (2000*0.55) ? tunfm : 0 );

  return drum | bassline | tune;
} 

Frequency value should be 44100 for best result. As you see, I've defined a short u32 alias for uint32_t.

Step 2: modify launcher script file called s, change the name of the executable to your source file name, but without .cpp extension:

#/bin/bash
bin/simple_house

Step 3: Compile by executing script called p. It will parse script s to find out which song to include, and will create the result in the bin/ directory.

Note the size of the result!

ern0@optiplex:~/work/bytebeat-player$ ll bin/simple_house
-rwxrwxr-x 1 ern0 ern0 14K May  1 19:02 bin/simple_house*

Step 4: Launch your music by executing script s - enjoy!

ern0@optiplex:~/work/bytebeat-player$ s
playing...

See also

There is a HTML5 web player: Simple House, web version