]> git.sesse.net Git - c64tapwav/commitdiff
Move detect_pulses into its own function.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 11 Mar 2015 22:26:08 +0000 (23:26 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 11 Mar 2015 22:26:08 +0000 (23:26 +0100)
decode.cpp

index 94bc1dd1668abe0482d6071e3de40082741806e1..1c9733184b013a7310e84c1ecea3b15e643d8a1f 100644 (file)
@@ -231,34 +231,9 @@ std::vector<float> do_filter(const std::vector<float>& pcm, const float* filter)
        return filtered_pcm;
 }
 
        return filtered_pcm;
 }
 
-int main(int argc, char **argv)
+std::vector<pulse> detect_pulses(const std::vector<float> &pcm, int sample_rate)
 {
 {
-       parse_options(argc, argv);
-
-       make_lanczos_weight_table();
-       std::vector<float> pcm;
-       int sample_rate;
-       if (!read_audio_file(argv[optind], &pcm, &sample_rate)) {
-               exit(1);
-       }
-
-       if (use_filter) {
-               pcm = do_filter(pcm, filter_coeff);
-       }
-
-#if 0
-       for (int i = 0; i < LEN; ++i) {
-               in[i] += rand() % 10000;
-       }
-#endif
-
-#if 0
-       for (int i = 0; i < LEN; ++i) {
-               printf("%d\n", in[i]);
-       }
-#endif
-
-       std::vector<pulse> pulses;  // in seconds
+       std::vector<pulse> pulses;
 
        // Find the flanks.
        int last_bit = -1;
 
        // Find the flanks.
        int last_bit = -1;
@@ -300,6 +275,37 @@ int main(int argc, char **argv)
                }
                last_bit = bit;
        }
                }
                last_bit = bit;
        }
+       return pulses;
+}
+
+int main(int argc, char **argv)
+{
+       parse_options(argc, argv);
+
+       make_lanczos_weight_table();
+       std::vector<float> pcm;
+       int sample_rate;
+       if (!read_audio_file(argv[optind], &pcm, &sample_rate)) {
+               exit(1);
+       }
+
+       if (use_filter) {
+               pcm = do_filter(pcm, filter_coeff);
+       }
+
+#if 0
+       for (int i = 0; i < LEN; ++i) {
+               in[i] += rand() % 10000;
+       }
+#endif
+
+#if 0
+       for (int i = 0; i < LEN; ++i) {
+               printf("%d\n", in[i]);
+       }
+#endif
+
+       std::vector<pulse> pulses = detect_pulses(pcm, sample_rate);
 
        double calibration_factor = 1.0;
        if (do_calibrate) {
 
        double calibration_factor = 1.0;
        if (do_calibrate) {