Skip to content

Instantly share code, notes, and snippets.

@Skoddiethecat
Created April 22, 2018 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skoddiethecat/e8e8e9c658354b9986bd2f4809d38ca9 to your computer and use it in GitHub Desktop.
Save Skoddiethecat/e8e8e9c658354b9986bd2f4809d38ca9 to your computer and use it in GitHub Desktop.
SineBeats! w/modulations
/*
This code is used to send an unsigned 8-bit char to stdout.
Once compiled, stdout can be piped to a raw file, and then
rendered into a wav using the following BASH commands.
Note: Requires sox, length can be controlled with head (8M).
gcc -o sinebeat sinebeat.c -lm
./sine | head -c 16M > sinebeat.raw
sox -r 32000 -c 1 -t u8 sinebeat.raw sinebeat.wav
Setting test to 1 enables 'debug mode' for quick bytebeat editing.
Setting test to 0 enables time based modulations that were used
in the track.
*/
#include <stdio.h>
#include <math.h>
#include <stdint.h>
int bytebeat(int t){ return (((1+t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7)-((t>>8|t>>16&64)/16);}
void main(){
unsigned long t;
int i;
int m;
int b;
int f;
const int fq = 200;
const int sr = 32000;
int test = 0; //DEBUG MODE
f = fq;
for(t=0;;t++){
if (test == 1){i = bytebeat(t);}
else{
if (t < (4 * sr)){i = t;}
else if (t < 8 * sr){
b += 1;
if (b % 2 == 0){m += 1;i = m>>2;}
else {i = t;}
}
else if (t < (12 * sr)){
b += 1;
m += 1;
if (b % 4 == 0){i = m>>2;}
else {i = m<<8;}
}
else if (t < (16 * sr)){
b += 1;
m += 1;
f = f + ((b % 4) - 2);
if (b % 8 == 0){i = m>>2;}
else {i = m<<4;}
}
else if (t < (60 * sr)){f = fq; i = bytebeat(t);}
else if (t < (120 * sr)){
if (t % 64000 == 0){f = f + 13;}
i = bytebeat(t);
}
else if (t < (180 * sr)){
if (t % 64000 == 0){f = f - 13;}
i = bytebeat(t);
}
else {f = fq; i = bytebeat(t);}
}
uint8_t out = (sin(f * (2 * M_PI) * i / sr) * 127) + 128;
putchar(out);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment