diff --git a/Makefile b/Makefile index aa2a0a3..f0a2d0d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS = -D_GNU_SOURCE=1 -W -Wall -O3 -std=c99 -ffast-math +CFLAGS = -DUP=1 -DDN=1 -D_GNU_SOURCE=1 -W -Wall -O3 -std=c99 -ffast-math LDFLAGS = -lm -lasound all: encode decode debug diff --git a/debug.c b/debug.c index a04a281..05be10e 100644 --- a/debug.c +++ b/debug.c @@ -81,12 +81,23 @@ int main(int argc, char **argv) int evn_count = 0; int first_hor_sync = 0; +#if DN && UP // 320 / 0.088 = 160 / 0.044 = 40000 / 11 = 3636.(36)~ pixels per second for Y, U and V int64_t factor_L = 40000; int64_t factor_M = 11 * rate; int64_t factor_D = gcd(factor_L, factor_M); factor_L /= factor_D; factor_M /= factor_D; +#endif +#if DN && !UP + int64_t factor_L = 1; + // factor_M * step should be smaller than pixel length + int64_t factor_M = rate * 0.088 / 320.0; +#endif +#if !DN + int64_t factor_L = 1; + int64_t factor_M = 1; +#endif // we want odd number of taps, 4 and 2 ms window length gives best results int cnt_taps = 1 | (int)(rate * factor_L * 0.004); @@ -192,10 +203,11 @@ int main(int argc, char **argv) begin_vis_hi = vis_hi ? 0 : begin_vis_hi; static int ticks = 0; - printf("%f %f %f %d %d %d %d %d %d %d %d\n", (float)ticks++ * dstep, dat_freq, cnt_freq, - 50*hor_sync+950, 50*cal_leader+850, 50*cal_break+750, - 50*vis_ss+650, 50*vis_lo+550, 50*vis_hi+450, - 50*sep_evn+350, 50*sep_odd+250); + if (ticks++ < 5.0 * drate) + printf("%f %f %f %d %d %d %d %d %d %d %d\n", (float)ticks * dstep, dat_freq, cnt_freq, + 50*hor_sync+950, 50*cal_leader+850, 50*cal_break+750, + 50*vis_ss+650, 50*vis_lo+550, 50*vis_hi+450, + 50*sep_evn+350, 50*sep_odd+250); if (cal_leader && !cal_break && got_cal_break && cal_ticks >= (int)(drate * (cal_leader_len + cal_break_len) * leader_tolerance) && diff --git a/decode.c b/decode.c index 5af04c8..c65ff56 100644 --- a/decode.c +++ b/decode.c @@ -25,9 +25,21 @@ void process_line(uint8_t *pixel, uint8_t *y_pixel, uint8_t *uv_pixel, int y_wid if (n % 2) for (int y = n-1, l = 0; l < 2 && y < height; l++, y++) { for (int x = 0; x < width; x++) { +#if DN && UP uint8_t Y = y_pixel[x + l*y_width]; uint8_t U = uv_pixel[x/2 + uv_width]; uint8_t V = uv_pixel[x/2]; +#else + float y_xf = (float)x * (float)y_width / (float)width; + float uv_xf = (float)x * (float)uv_width / (float)width; + int y_x0 = y_xf; + int uv_x0 = uv_xf; + int y_x1 = fclampf(0, y_width, y_xf + 1); + int uv_x1 = fclampf(0, uv_width, uv_xf + 1); + uint8_t Y = flerpf(y_pixel[y_x0 + l*y_width], y_pixel[y_x1 + l*y_width], y_xf - (float)y_x0); + uint8_t U = flerpf(uv_pixel[uv_x0 + uv_width], uv_pixel[uv_x1 + uv_width], uv_xf - (float)uv_x0); + uint8_t V = flerpf(uv_pixel[uv_x0], uv_pixel[uv_x1], uv_xf - (float)uv_x0); +#endif uint8_t *p = pixel + 3 * width * y + 3 * x; p[0] = R_YUV(Y, U, V); p[1] = G_YUV(Y, U, V); @@ -98,12 +110,23 @@ int main(int argc, char **argv) int evn_count = 0; int first_hor_sync = 0; +#if DN && UP // 320 / 0.088 = 160 / 0.044 = 40000 / 11 = 3636.(36)~ pixels per second for Y, U and V int64_t factor_L = 40000; int64_t factor_M = 11 * rate; int64_t factor_D = gcd(factor_L, factor_M); factor_L /= factor_D; factor_M /= factor_D; +#endif +#if DN && !UP + int64_t factor_L = 1; + // factor_M * step should be smaller than pixel length + int64_t factor_M = rate * 0.088 / 320.0; +#endif +#if !DN + int64_t factor_L = 1; + int64_t factor_M = 1; +#endif // we want odd number of taps, 4 and 2 ms window length gives best results int cnt_taps = 1 | (int)(rate * factor_L * 0.004);