Skip to content

Instantly share code, notes, and snippets.

@JerrySievert
Created January 26, 2018 05:57
Show Gist options
  • Save JerrySievert/cfac490ac59044bd6f01b95ac50992b7 to your computer and use it in GitHub Desktop.
Save JerrySievert/cfac490ac59044bd6f01b95ac50992b7 to your computer and use it in GitHub Desktop.
converts samples to vcvrack for me
#include <stdio.h>
#include <stdlib.h>
union bytes {
float val;
unsigned char str[sizeof(float)];
};
int main (int argc, char **argv) {
FILE *f1;
union bytes b;
long len;
long l = 0;
if (argc < 2) {
printf("USAGE: %s file ...\n", argv[0]);
return 1;
}
for (int i = 1; i < argc; i++) {
l = 0;
f1 = fopen(argv[i], "r");
fseek(f1, 0, SEEK_END);
len = ftell(f1);
fseek(f1, 0, SEEK_SET);
printf("const float kick%d[] = {\n", i);
while (l < (len / sizeof(float))) {
fread(b.str, sizeof(char), 4, f1);
printf("%f", b.val * 5);
if (l < (len / sizeof(float)) - 1) {
printf(", ");
}
l++;
}
printf("\n};\n\nunsigned int kick%d_len = %ld;\n\n", i, (long) len / 4);
fclose(f1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment