diff --git a/main.c b/main.c index c2a859e..0814af9 100644 --- a/main.c +++ b/main.c @@ -7,7 +7,10 @@ #include #include #include +#include + +#define am_delay(x) (square_am_signal(x, 0)) __m128i reg; __m128i reg_zero; __m128i reg_one; @@ -33,7 +36,12 @@ static inline void square_am_signal(float time, float frequency) { } } -int main() +int prefix(const char *pre, const char *str) +{ + return strncmp(pre, str, strlen(pre)) == 0; +} + +int main(int argc, char* argv[]) { mach_timebase_info_data_t theTimeBaseInfo; mach_timebase_info(&theTimeBaseInfo); @@ -46,33 +54,54 @@ int main() reg_zero = _mm_set_epi32(0, 0, 0, 0); reg_one = _mm_set_epi32(-1, -1, -1, -1); - + FILE* fp; + if (argc == 2) { + fp = fopen(argv[1], "r"); + } else { + puts("Supply file to read song from."); + exit(1); + } + char buffer[256]; while (1) { - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2093); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.790, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2349); - square_am_signal(0.790, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 3136); - square_am_signal(0.790, 3136); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2093); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2349); - square_am_signal(0.400, 2673); - square_am_signal(0.400, 2349); - square_am_signal(0.790, 2093); + fgets(buffer, 256 - 1, fp); + if (strlen(buffer) == 0) { + /* skip blank lines */ + continue; + } + + if (prefix(":beep", buffer)) { + int t; + int f; + if(sscanf(buffer, ":beep frequency=%d length=%dms", &f, &t) == 0) { + continue; + } + printf("F: %d, T: %d\n", f, t); + square_am_signal(t / 1000.0, f); + } else if (prefix(":delay", buffer)) { + int d; + if (sscanf(buffer, ":delay %dms", &d) == 0) { + continue; + } + printf("D: %d\n", d); + square_am_signal(d / 1000.0, 0); + } + /* Super Mario Bros. Theme + square_am_signal(0.100, 660); + am_delay(0.150); + square_am_signal(0.100, 660); + am_delay(0.300); + square_am_signal(0.100, 660); + am_delay(0.300); + square_am_signal(0.100, 510); + am_delay(0.100); + square_am_signal(0.100, 660); + am_delay(0.300); + square_am_signal(0.100, 770); + am_delay(0.550); + square_am_signal(0.100, 380); + am_delay(0.575);*/ + + + } } diff --git a/smb.song b/smb.song new file mode 100644 index 0000000..d8709df --- /dev/null +++ b/smb.song @@ -0,0 +1,351 @@ +:beep frequency=660 length=100ms; +:delay 150ms; +:beep frequency=660 length=100ms; +:delay 300ms; +:beep frequency=660 length=100ms; +:delay 300ms; +:beep frequency=510 length=100ms; +:delay 100ms; +:beep frequency=660 length=100ms; +:delay 300ms; +:beep frequency=770 length=100ms; +:delay 550ms; +:beep frequency=380 length=100ms; +:delay 575ms; + +:beep frequency=510 length=100ms; +:delay 450ms; +:beep frequency=380 length=100ms; +:delay 400ms; +:beep frequency=320 length=100ms; +:delay 500ms; +:beep frequency=440 length=100ms; +:delay 300ms; +:beep frequency=480 length=80ms; +:delay 330ms; +:beep frequency=450 length=100ms; +:delay 150ms; +:beep frequency=430 length=100ms; +:delay 300ms; +:beep frequency=380 length=100ms; +:delay 200ms; +:beep frequency=660 length=80ms; +:delay 200ms; +:beep frequency=760 length=50ms; +:delay 150ms; +:beep frequency=860 length=100ms; +:delay 300ms; +:beep frequency=700 length=80ms; +:delay 150ms; +:beep frequency=760 length=50ms; +:delay 350ms; +:beep frequency=660 length=80ms; +:delay 300ms; +:beep frequency=520 length=80ms; +:delay 150ms; +:beep frequency=580 length=80ms; +:delay 150ms; +:beep frequency=480 length=80ms; +:delay 500ms; + +:beep frequency=510 length=100ms; +:delay 450ms; +:beep frequency=380 length=100ms; +:delay 400ms; +:beep frequency=320 length=100ms; +:delay 500ms; +:beep frequency=440 length=100ms; +:delay 300ms; +:beep frequency=480 length=80ms; +:delay 330ms; +:beep frequency=450 length=100ms; +:delay 150ms; +:beep frequency=430 length=100ms; +:delay 300ms; +:beep frequency=380 length=100ms; +:delay 200ms; +:beep frequency=660 length=80ms; +:delay 200ms; +:beep frequency=760 length=50ms; +:delay 150ms; +:beep frequency=860 length=100ms; +:delay 300ms; +:beep frequency=700 length=80ms; +:delay 150ms; +:beep frequency=760 length=50ms; +:delay 350ms; +:beep frequency=660 length=80ms; +:delay 300ms; +:beep frequency=520 length=80ms; +:delay 150ms; +:beep frequency=580 length=80ms; +:delay 150ms; +:beep frequency=480 length=80ms; +:delay 500ms; + +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=760 length=100ms; +:delay 100ms; +:beep frequency=720 length=100ms; +:delay 150ms; +:beep frequency=680 length=100ms; +:delay 150ms; +:beep frequency=620 length=150ms; +:delay 300ms; + +:beep frequency=650 length=150ms; +:delay 300ms; +:beep frequency=380 length=100ms; +:delay 150ms; +:beep frequency=430 length=100ms; +:delay 150ms; + +:beep frequency=500 length=100ms; +:delay 300ms; +:beep frequency=430 length=100ms; +:delay 150ms; +:beep frequency=500 length=100ms; +:delay 100ms; +:beep frequency=570 length=100ms; +:delay 220ms; + +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=760 length=100ms; +:delay 100ms; +:beep frequency=720 length=100ms; +:delay 150ms; +:beep frequency=680 length=100ms; +:delay 150ms; +:beep frequency=620 length=150ms; +:delay 300ms; + +:beep frequency=650 length=200ms; +:delay 300ms; + +:beep frequency=1020 length=80ms; +:delay 300ms; +:beep frequency=1020 length=80ms; +:delay 150ms; +:beep frequency=1020 length=80ms; +:delay 300ms; + +:beep frequency=380 length=100ms; +:delay 300ms; +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=760 length=100ms; +:delay 100ms; +:beep frequency=720 length=100ms; +:delay 150ms; +:beep frequency=680 length=100ms; +:delay 150ms; +:beep frequency=620 length=150ms; +:delay 300ms; + +:beep frequency=650 length=150ms; +:delay 300ms; +:beep frequency=380 length=100ms; +:delay 150ms; +:beep frequency=430 length=100ms; +:delay 150ms; + +:beep frequency=500 length=100ms; +:delay 300ms; +:beep frequency=430 length=100ms; +:delay 150ms; +:beep frequency=500 length=100ms; +:delay 100ms; +:beep frequency=570 length=100ms; +:delay 420ms; + +:beep frequency=585 length=100ms; +:delay 450ms; + +:beep frequency=550 length=100ms; +:delay 420ms; + +:beep frequency=500 length=100ms; +:delay 360ms; + +:beep frequency=380 length=100ms; +:delay 300ms; +:beep frequency=500 length=100ms; +:delay 300ms; +:beep frequency=500 length=100ms; +:delay 150ms; +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=760 length=100ms; +:delay 100ms; +:beep frequency=720 length=100ms; +:delay 150ms; +:beep frequency=680 length=100ms; +:delay 150ms; +:beep frequency=620 length=150ms; +:delay 300ms; + +:beep frequency=650 length=150ms; +:delay 300ms; +:beep frequency=380 length=100ms; +:delay 150ms; +:beep frequency=430 length=100ms; +:delay 150ms; + +:beep frequency=500 length=100ms; +:delay 300ms; +:beep frequency=430 length=100ms; +:delay 150ms; +:beep frequency=500 length=100ms; +:delay 100ms; +:beep frequency=570 length=100ms; +:delay 220ms; + +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=760 length=100ms; +:delay 100ms; +:beep frequency=720 length=100ms; +:delay 150ms; +:beep frequency=680 length=100ms; +:delay 150ms; +:beep frequency=620 length=150ms; +:delay 300ms; + +:beep frequency=650 length=200ms; +:delay 300ms; + +:beep frequency=1020 length=80ms; +:delay 300ms; +:beep frequency=1020 length=80ms; +:delay 150ms; +:beep frequency=1020 length=80ms; +:delay 300ms; + +:beep frequency=380 length=100ms; +:delay 300ms; +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=760 length=100ms; +:delay 100ms; +:beep frequency=720 length=100ms; +:delay 150ms; +:beep frequency=680 length=100ms; +:delay 150ms; +:beep frequency=620 length=150ms; +:delay 300ms; + +:beep frequency=650 length=150ms; +:delay 300ms; +:beep frequency=380 length=100ms; +:delay 150ms; +:beep frequency=430 length=100ms; +:delay 150ms; + +:beep frequency=500 length=100ms; +:delay 300ms; +:beep frequency=430 length=100ms; +:delay 150ms; +:beep frequency=500 length=100ms; +:delay 100ms; +:beep frequency=570 length=100ms; +:delay 420ms; + +:beep frequency=585 length=100ms; +:delay 450ms; + +:beep frequency=550 length=100ms; +:delay 420ms; + +:beep frequency=500 length=100ms; +:delay 360ms; + +:beep frequency=380 length=100ms; +:delay 300ms; +:beep frequency=500 length=100ms; +:delay 300ms; +:beep frequency=500 length=100ms; +:delay 150ms; +:beep frequency=500 length=100ms; +:delay 300ms; + +:beep frequency=500 length=60ms; +:delay 150ms; +:beep frequency=500 length=80ms; +:delay 300ms; +:beep frequency=500 length=60ms; +:delay 350ms; +:beep frequency=500 length=80ms; +:delay 150ms; +:beep frequency=580 length=80ms; +:delay 350ms; +:beep frequency=660 length=80ms; +:delay 150ms; +:beep frequency=500 length=80ms; +:delay 300ms; +:beep frequency=430 length=80ms; +:delay 150ms; +:beep frequency=380 length=80ms; +:delay 600ms; + +:beep frequency=500 length=60ms; +:delay 150ms; +:beep frequency=500 length=80ms; +:delay 300ms; +:beep frequency=500 length=60ms; +:delay 350ms; +:beep frequency=500 length=80ms; +:delay 150ms; +:beep frequency=580 length=80ms; +:delay 150ms; +:beep frequency=660 length=80ms; +:delay 550ms; + +:beep frequency=870 length=80ms; +:delay 325ms; +:beep frequency=760 length=80ms; +:delay 600ms; + +:beep frequency=500 length=60ms; +:delay 150ms; +:beep frequency=500 length=80ms; +:delay 300ms; +:beep frequency=500 length=60ms; +:delay 350ms; +:beep frequency=500 length=80ms; +:delay 150ms; +:beep frequency=580 length=80ms; +:delay 350ms; +:beep frequency=660 length=80ms; +:delay 150ms; +:beep frequency=500 length=80ms; +:delay 300ms; +:beep frequency=430 length=80ms; +:delay 150ms; +:beep frequency=380 length=80ms; +:delay 600ms; + +:beep frequency=660 length=100ms; +:delay 150ms; +:beep frequency=660 length=100ms; +:delay 300ms; +:beep frequency=660 length=100ms; +:delay 300ms; +:beep frequency=510 length=100ms; +:delay 100ms; +:beep frequency=660 length=100ms; +:delay 300ms; +:beep frequency=770 length=100ms; +:delay 550ms; +:beep frequency=380 length=100ms; +:delay 575ms;