X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=synth_main.cpp;fp=synth_main.cpp;h=9f2ca968bf409f72e2d9dd60b6f30c2f07307dfd;hb=02cfbb7d322c6a683924ceb3b6277fca33c6b97e;hp=0000000000000000000000000000000000000000;hpb=35d290f19c02f0e884f4baec704851cfd1b86988;p=c64tapwav diff --git a/synth_main.cpp b/synth_main.cpp new file mode 100644 index 0000000..9f2ca96 --- /dev/null +++ b/synth_main.cpp @@ -0,0 +1,42 @@ +#include +#include + +#include "common.h" +#include "synth.h" + +using namespace std; + +int main(int argc, char **argv) +{ + FILE *fp = fopen(argv[1], "rb"); + fseek(fp, 14, SEEK_SET); + + int x = 0; + + vector pulses; + while (!feof(fp)) { + int len = getc(fp); + int cycles; + if (len == 0) { + int a = getc(fp); + int b = getc(fp); + int c = getc(fp); + cycles = a | (b << 8) | (c << 16); + } else { + cycles = len * 8; + } + pulse p; + p.start = float(x) * WAVE_FREQ / C64_FREQ; + p.end = (float(x) + cycles * 0.5) * WAVE_FREQ / C64_FREQ; + pulses.push_back(p); + x += cycles; + } + + vector samples = synth(pulses); + + for (int i = 0; i < samples.size(); ++i) { + //printf("%f %f\n", samples[i], refiltered_samples[i]); + short s = lrintf(samples[i] * 16384.0f); + fwrite(&s, 2, 1, stdout); + } +}