]> git.sesse.net Git - c64tapwav/blob - synth_main.cpp
Make a debug.raw with detected pulses.
[c64tapwav] / synth_main.cpp
1 #include <stdio.h>
2 #include <math.h>
3
4 #include "common.h"
5 #include "synth.h"
6
7 using namespace std;
8
9 int main(int argc, char **argv)
10 {
11         FILE *fp = fopen(argv[1], "rb");
12         fseek(fp, 14, SEEK_SET);
13
14         int x = 0;
15         
16         vector<pulse> pulses;
17         while (!feof(fp)) {
18                 int len = getc(fp);
19                 int cycles;
20                 if (len == 0) {
21                         int a = getc(fp);
22                         int b = getc(fp);
23                         int c = getc(fp);
24                         cycles = a | (b << 8) | (c << 16);
25                 } else {
26                         cycles = len * 8;
27                 }
28                 pulse p;
29                 p.start = float(x) * WAVE_FREQ / C64_FREQ;
30                 p.end = (float(x) + cycles * 0.5) * WAVE_FREQ / C64_FREQ;
31                 pulses.push_back(p);
32                 x += cycles;
33         }
34
35         vector<float> samples = synth(pulses);
36
37         for (unsigned i = 0; i < samples.size(); ++i) {
38                 //printf("%f %f\n", samples[i], refiltered_samples[i]);
39                 short s = lrintf(samples[i] * 16384.0f);
40                 fwrite(&s, 2, 1, stdout);
41         }
42 }