diff --git a/app/src/main/rs/decoder.rs b/app/src/main/rs/decoder.rs index 50c8621..7648a3a 100644 --- a/app/src/main/rs/decoder.rs +++ b/app/src/main/rs/decoder.rs @@ -247,9 +247,11 @@ void decode(int samples) { sync_pos = buffer_pos - sync_buildup_length; } + static int reset_on_first_sync; if (automatic_mode_detection) { int detected_mode = calibration_detector(dat_value, dat_amp, cnt_amp, cnt_quantized); if (detected_mode >= 0) { + reset_on_first_sync = 1; free_running = 0; reset_buffer(); switch_mode(detected_mode); @@ -261,13 +263,23 @@ void decode(int samples) { switch_mode(estimated_mode); } } + if (sync_pulse && reset_on_first_sync) { + reset_on_first_sync = 0; + hpos = buffer_pos - sync_pos; + seperator_counter = 0; + continue; + } int u_sep = u_sep_begin <= hpos && hpos < u_sep_end; int v_sep = v_sep_begin <= hpos && hpos < v_sep_end; seperator_counter += (u_sep || v_sep) ? dat_quantized : 0; if (++hpos >= maximum_length || sync_pulse) { + static int too_early_sync_counter; if (hpos < minimum_length) { + if (++too_early_sync_counter <= 5) + continue; + too_early_sync_counter = 0; hpos = buffer_pos - sync_pos; seperator_counter = 0; continue; @@ -280,6 +292,7 @@ void decode(int samples) { sync_pos += scanline_length; } else { sync_timeout = 0; + too_early_sync_counter = 0; hpos = buffer_pos - sync_pos; } switch (current_decoder) { diff --git a/app/src/main/rs/initialization.rsh b/app/src/main/rs/initialization.rsh index 8378152..77653db 100644 --- a/app/src/main/rs/initialization.rsh +++ b/app/src/main/rs/initialization.rsh @@ -45,7 +45,6 @@ void initialize(float rate, int length, int iw, int ih, int sw, int sh, int sgw, seperator_counter = 0; buffer_cleared = 0; free_running = 1; - minimum_length = 0.05f * sample_rate; minimum_sync_length = 0.002f * sample_rate; sync_buildup_length = round((sync_buildup_ms * sample_rate) / 1000.0f); diff --git a/app/src/main/rs/modes.rsh b/app/src/main/rs/modes.rsh index 44fe8f1..5dbae32 100644 --- a/app/src/main/rs/modes.rsh +++ b/app/src/main/rs/modes.rsh @@ -37,6 +37,7 @@ void raw_mode() bitmap_width = maximum_width; bitmap_height = maximum_height; sync_length = minimum_sync_length; + minimum_length = 0.05f * sample_rate; maximum_length = buffer_length; scanline_length = maximum_length; } @@ -72,7 +73,8 @@ void robot36_mode() u_end = v_end = round((uv_end_ms * sample_rate) / 1000.0f); scanline_length = robot36_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } void robot72_mode() { @@ -114,7 +116,8 @@ void robot72_mode() u_end = round((u_end_ms * sample_rate) / 1000.0f); scanline_length = robot72_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } void martin1_mode() { @@ -146,7 +149,8 @@ void martin1_mode() b_begin = round((b_begin_ms * sample_rate) / 1000.0f); scanline_length = martin1_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } void martin2_mode() { @@ -178,7 +182,8 @@ void martin2_mode() b_begin = round((b_begin_ms * sample_rate) / 1000.0f); scanline_length = martin2_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } void scottie1_mode() { @@ -210,7 +215,8 @@ void scottie1_mode() b_begin = round((b_begin_ms * sample_rate) / 1000.0f); scanline_length = scottie1_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } void scottie2_mode() { @@ -242,7 +248,8 @@ void scottie2_mode() b_begin = round((b_begin_ms * sample_rate) / 1000.0f); scanline_length = scottie2_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } void scottieDX_mode() { @@ -274,7 +281,8 @@ void scottieDX_mode() b_begin = round((b_begin_ms * sample_rate) / 1000.0f); scanline_length = scottieDX_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } void wrasseSC2_180_mode() { @@ -304,7 +312,8 @@ void wrasseSC2_180_mode() b_begin = round((b_begin_ms * sample_rate) / 1000.0f); scanline_length = wrasseSC2_180_scanline_length; - maximum_length = scanline_length + (sync_porch_ms * sample_rate) / 1000.0f; + minimum_length = scanline_length - 0.001f * sample_rate; + maximum_length = scanline_length + 0.001f * sample_rate; } static void switch_mode(int new_mode)