X-Git-Url: https://git.sesse.net/?p=c64tapwav;a=blobdiff_plain;f=sync.cpp;h=3acd2016bf9e9ff86cc2a0cfd69a64374d167ebf;hp=d29180858eee42111fb288f2c2c8520b4533913a;hb=866751f2909657ee7d62f936e3d2cb2ecb7806fb;hpb=08089f496815d725c3bee171bae0e884642ffc05;ds=sidebyside diff --git a/sync.cpp b/sync.cpp index d291808..3acd201 100644 --- a/sync.cpp +++ b/sync.cpp @@ -18,8 +18,8 @@ struct stereo_sample { short left, right; }; -struct double_stereo_sample { - double left, right; +struct float_stereo_sample { + float left, right; }; inline short clip(int x) @@ -75,7 +75,7 @@ int main(int argc, char **argv) double inv_sd_left = 1.0 / sqrt(var_left); double inv_sd_right = 1.0 / sqrt(var_right); - std::vector norm; + std::vector norm; norm.resize(pcm.size()); for (unsigned i = 0; i < pcm.size(); ++i) { @@ -102,7 +102,9 @@ int main(int argc, char **argv) #endif double delays[NUM_THEORIES]; + std::vector alloc_hypot; hypothesis *bases = new hypothesis[NUM_THEORIES]; + alloc_hypot.push_back(bases); for (int h = 0; h < NUM_THEORIES; ++h) { delays[h] = THEORY_FROM + h * (THEORY_TO - THEORY_FROM) / (NUM_THEORIES - 1); @@ -120,6 +122,7 @@ int main(int argc, char **argv) size_t end = std::min(i + BUFSIZE, total_end); hypothesis *hyp = new hypothesis[NUM_THEORIES]; + alloc_hypot.push_back(hyp); // evaluate all hypotheses for (int h = 0; h < NUM_THEORIES; ++h) { @@ -177,22 +180,28 @@ int main(int argc, char **argv) fprintf(fp, "%f %f\n", i * BUFSIZE / 44100.0, best_path[i]); } fclose(fp); + + // save some RAM + norm = std::vector(); + for (unsigned i = 0; i < alloc_hypot.size(); ++i) { + delete[] alloc_hypot[i]; + } fprintf(stderr, "Stretching right channel to match left... %7.2f%%", 0.0); double inv_sd = sqrt(2.0) / sqrt(var_left + var_right); std::vector aligned_pcm; std::vector mono_pcm; + aligned_pcm.resize(total_end); + mono_pcm.resize(total_end); for (unsigned i = 0; i < total_end; ++i) { double d = lanczos_interpolate(best_path, i / double(BUFSIZE)); int left = pcm[i].left; int right = lanczos_interpolate_right(pcm, i + d); - stereo_sample ss; - ss.left = left; - ss.right = clip(right); - aligned_pcm.push_back(ss); + aligned_pcm[i].left = left; + aligned_pcm[i].right = clip(right); - mono_pcm.push_back(clip(lrintf(inv_sd * 4096.0 * (left + right)))); + mono_pcm[i] = clip(lrintf(inv_sd * 4096.0 * (left + right))); if (i % 4096 == 0) { fprintf(stderr, "\b\b\b\b\b\b\b\b%7.2f%%", 100.0 * i / total_end);