Skip to content

Instantly share code, notes, and snippets.

@grejppi
Created October 21, 2014 19:24
Show Gist options
  • Save grejppi/316903e0feb2ba0ef3cb to your computer and use it in GitHub Desktop.
Save grejppi/316903e0feb2ba0ef3cb to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <stdio.h>
typedef union {
float f;
uint32_t i;
char b[4];
} rawfloat;
inline static float tune (uint32_t t) {
return ((((t >> ((t >> 16) + 1) * ((t << 2) >> (t >> ((t >> 13 & 1) ? 4 : 13)))) >> ((t << 21) & 1 ? ((t >> 2) & 0xf) : 0)) & 0xff) >> 1) / 255.0;
}
inline static float beat (uint32_t t) {
return (((t >> 2 & 0xffff) & (((t >> 2 & 0xffff) >> 4) & ((t >> ((t >> 18) & 0xf) & 0xffff) >> 3))) ? 127 : 0) / 255.0;
}
int main (int argc, char** argv) {
rawfloat rf;
float s;
float dc_in = 0;
float dc_out = 0;
for (uint32_t t = 0; t < (1 << 23); ++t) {
rf.f = 0;
s = 0;
s += tune (t);
s += beat (t);
dc_out = 0.999f * dc_out + s - dc_in;
dc_in = s;
rf.f += dc_out;
for (int i = 0; i < 4; ++i) {
putchar (rf.b[i]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment