]> git.sesse.net Git - c64tapwav/blobdiff - decode.cpp
Make leveler minimum level configurable, since it is connected to hysteresis limit.
[c64tapwav] / decode.cpp
index ab242d0be5845f7145e0b40ca75c5a646207ca25..b3b8aa3376f355b9fcad9e8cd3aa4fc9b1bf2b4b 100644 (file)
@@ -42,6 +42,12 @@ static bool output_leveled = false;
 static std::vector<float> train_snap_points;
 static bool do_train = false;
 
+// The minimum estimated sound level (for do_auto_level) at any given point.
+// If you decrease this, you'll be able to amplify really silent signals
+// by more, but you'll also increase the level of silent (ie. noise-only) segments,
+// possibly caused misdetected pulses in these segments.
+static float min_level = 0.05f;
+
 // between [x,x+1]
 double find_zerocrossing(const std::vector<float> &pcm, int x)
 {
@@ -164,6 +170,7 @@ void output_tap(const std::vector<pulse>& pulses, double calibration_factor)
 
 static struct option long_options[] = {
        {"auto-level",       0,                 0, 'a' },
+       {"output-leveled",   0,                 0, 'A' },
        {"no-calibrate",     0,                 0, 's' },
        {"plot-cycles",      0,                 0, 'p' },
        {"hysteresis-limit", required_argument, 0, 'l' },
@@ -181,6 +188,7 @@ void help()
        fprintf(stderr, "\n");
        fprintf(stderr, "  -a, --auto-level             automatically adjust amplitude levels throughout the file\n");
        fprintf(stderr, "  -A, --output-leveled         output leveled waveform to leveled.raw\n");
+       fprintf(stderr, "  -m, --min-level              minimum estimated sound level (0..32768) for --auto-level\n");
        fprintf(stderr, "  -s, --no-calibrate           do not try to calibrate on sync pulse length\n");
        fprintf(stderr, "  -p, --plot-cycles            output debugging info to cycles.plot\n");
        fprintf(stderr, "  -l, --hysteresis-limit VAL   change amplitude threshold for ignoring pulses (0..32768)\n");
@@ -198,7 +206,7 @@ void parse_options(int argc, char **argv)
 {
        for ( ;; ) {
                int option_index = 0;
-               int c = getopt_long(argc, argv, "aAspl:f:Fc:t:qh", long_options, &option_index);
+               int c = getopt_long(argc, argv, "aAm:spl:f:Fc:t:qh", long_options, &option_index);
                if (c == -1)
                        break;
 
@@ -211,6 +219,10 @@ void parse_options(int argc, char **argv)
                        output_leveled = true;
                        break;
 
+               case 'm':
+                       min_level = atof(optarg) / 32768.0;
+                       break;
+
                case 's':
                        do_calibrate = false;
                        break;
@@ -458,7 +470,7 @@ int main(int argc, char **argv)
        }
 
        if (do_auto_level) {
-               pcm = level_samples(pcm, sample_rate);
+               pcm = level_samples(pcm, min_level, sample_rate);
                if (output_leveled) {
                        FILE *fp = fopen("leveled.raw", "wb");
                        fwrite(pcm.data(), pcm.size() * sizeof(pcm[0]), 1, fp);