kopia lustrzana https://github.com/xdsopl/robot36
WIP: replaced linear with much more flexible circular buffer
rodzic
3743d023f9
commit
a69b4089f5
|
@ -18,6 +18,7 @@ limitations under the License.
|
|||
#define BLUR_RSH
|
||||
|
||||
#include "exports.rsh"
|
||||
#include "state.rsh"
|
||||
#include "blur_generated.rsh"
|
||||
|
||||
void incr_blur()
|
||||
|
|
Plik diff jest za duży
Load Diff
|
@ -33,6 +33,8 @@ static const int mode_scottie2 = 6;
|
|||
static const int mode_scottieDX = 7;
|
||||
static const int mode_wrasseSC2_180 = 8;
|
||||
|
||||
|
||||
static const float sync_buildup_seconds = 0.0011f;
|
||||
static const float robot36_scanline_seconds = 0.15f;
|
||||
static const float robot72_scanline_seconds = 0.3f;
|
||||
static const float martin1_scanline_seconds = 0.446446f;
|
||||
|
|
|
@ -41,7 +41,8 @@ static void reset_buffer()
|
|||
{
|
||||
vpos = 0;
|
||||
hpos = 0;
|
||||
prev_hpos = 0;
|
||||
prev_sync_pos = sync_pos = 0;
|
||||
buffer_pos = 0;
|
||||
seperator_counter = 0;
|
||||
sync_counter = sync_length;
|
||||
buffer_cleared = 1;
|
||||
|
@ -69,103 +70,66 @@ static void robot36_decoder()
|
|||
if ((free_running && mismatch_counter > 1) || mismatch_counter > 5)
|
||||
vpos ^= 1;
|
||||
prev_timeout = hpos >= maximum_length;
|
||||
static int even_sync_pos, odd_sync_pos;
|
||||
if (vpos & 1) {
|
||||
odd_sync_pos = prev_sync_pos;
|
||||
for (int i = 0; i < bitmap_width; ++i) {
|
||||
uchar even_y = value_blur(i, y_begin, y_end);
|
||||
uchar v = value_blur(i, v_begin, v_end);
|
||||
uchar odd_y = value_blur(i, prev_hpos + y_begin, prev_hpos + y_end);
|
||||
uchar u = value_blur(i, prev_hpos + u_begin, prev_hpos + u_end);
|
||||
uchar even_y = value_blur(i, even_sync_pos + y_begin, even_sync_pos + y_end);
|
||||
uchar v = value_blur(i, even_sync_pos + v_begin, even_sync_pos + v_end);
|
||||
uchar odd_y = value_blur(i, odd_sync_pos + y_begin, odd_sync_pos + y_end);
|
||||
uchar u = value_blur(i, odd_sync_pos + u_begin, odd_sync_pos + u_end);
|
||||
pixel_buffer[bitmap_width * (vpos-1) + i] = yuv(even_y, u, v);
|
||||
pixel_buffer[bitmap_width * vpos + i] = yuv(odd_y, u, v);
|
||||
}
|
||||
if (prev_timeout)
|
||||
hpos -= scanline_length;
|
||||
else
|
||||
hpos = 0;
|
||||
prev_hpos = 0;
|
||||
} else {
|
||||
if (prev_timeout) {
|
||||
prev_hpos = scanline_length;
|
||||
hpos -= scanline_length;
|
||||
} else {
|
||||
prev_hpos = hpos;
|
||||
hpos = 0;
|
||||
}
|
||||
even_sync_pos = prev_sync_pos;
|
||||
}
|
||||
++vpos;
|
||||
}
|
||||
|
||||
static void yuv_decoder()
|
||||
{
|
||||
for (int i = 0; i < bitmap_width; ++i) {
|
||||
uchar y = value_blur(i, y_begin, y_end);
|
||||
uchar u = value_blur(i, u_begin, u_end);
|
||||
uchar v = value_blur(i, v_begin, v_end);
|
||||
uchar y = value_blur(i, y_begin + prev_sync_pos, y_end + prev_sync_pos);
|
||||
uchar u = value_blur(i, u_begin + prev_sync_pos, u_end + prev_sync_pos);
|
||||
uchar v = value_blur(i, v_begin + prev_sync_pos, v_end + prev_sync_pos);
|
||||
pixel_buffer[bitmap_width * vpos + i] = yuv(y, u, v);
|
||||
}
|
||||
if (hpos >= maximum_length)
|
||||
hpos -= scanline_length;
|
||||
else
|
||||
hpos = 0;
|
||||
prev_hpos = 0;
|
||||
++vpos;
|
||||
}
|
||||
|
||||
static void rgb_decoder()
|
||||
{
|
||||
for (int i = 0; i < bitmap_width; ++i) {
|
||||
uchar r = value_blur(i, r_begin, r_end);
|
||||
uchar g = value_blur(i, g_begin, g_end);
|
||||
uchar b = value_blur(i, b_begin, b_end);
|
||||
uchar r = value_blur(i, r_begin + prev_sync_pos, r_end + prev_sync_pos);
|
||||
uchar g = value_blur(i, g_begin + prev_sync_pos, g_end + prev_sync_pos);
|
||||
uchar b = value_blur(i, b_begin + prev_sync_pos, b_end + prev_sync_pos);
|
||||
pixel_buffer[bitmap_width * vpos + i] = rgb(r, g, b);
|
||||
}
|
||||
if (hpos >= maximum_length)
|
||||
hpos -= scanline_length;
|
||||
else
|
||||
hpos = 0;
|
||||
prev_hpos = 0;
|
||||
++vpos;
|
||||
}
|
||||
|
||||
static void raw_decoder()
|
||||
{
|
||||
for (int i = 0; i < bitmap_width; ++i) {
|
||||
uchar value = value_blur(i, 0, hpos);
|
||||
uchar value = value_blur(i, prev_sync_pos, sync_pos);
|
||||
pixel_buffer[bitmap_width * vpos + i] = rgb(value, value, value);
|
||||
}
|
||||
prev_hpos = hpos = 0;
|
||||
++vpos;
|
||||
}
|
||||
|
||||
// don't you guys have anything better to do?
|
||||
static void scottie_decoder()
|
||||
{
|
||||
if (!prev_hpos) {
|
||||
for (int i = g_begin; i < g_end; ++i)
|
||||
value_buffer[i + b_begin - g_begin] = value_buffer[i];
|
||||
for (int i = r_begin; i < r_end; ++i)
|
||||
value_buffer[i + g_begin - r_begin] = value_buffer[i];
|
||||
prev_hpos = scanline_length;
|
||||
hpos = 0;
|
||||
static int first_sync = 1;
|
||||
if (!free_running && !vpos && first_sync) {
|
||||
first_sync = 0;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < bitmap_width; ++i) {
|
||||
uchar r = value_blur(i, prev_hpos + r_begin, prev_hpos + r_end);
|
||||
uchar g = value_blur(i, g_begin, g_end);
|
||||
uchar b = value_blur(i, b_begin, b_end);
|
||||
pixel_buffer[bitmap_width * vpos + i] = rgb(r, g, b);
|
||||
}
|
||||
for (int i = 0; i < scanline_length; ++i)
|
||||
value_buffer[i] = value_buffer[i + prev_hpos];
|
||||
prev_hpos = scanline_length;
|
||||
hpos = 0;
|
||||
++vpos;
|
||||
first_sync = 1;
|
||||
rgb_decoder();
|
||||
}
|
||||
|
||||
void decode(int samples) {
|
||||
*saved_width = 0;
|
||||
*saved_height = 0;
|
||||
for (int sample = 0; sample < samples; ++sample) {
|
||||
for (int sample = 0; sample < samples; ++sample, ++buffer_pos) {
|
||||
float amp = audio_buffer[sample] / 32768.0f;
|
||||
float power = amp * amp;
|
||||
if (filter(&avg_power, power) < 0.0000001f)
|
||||
|
@ -184,7 +148,7 @@ void decode(int samples) {
|
|||
int dat_active = cnt_amp < 2.0f * dat_amp;
|
||||
uchar cnt_level = save_cnt && cnt_active ? 127.5f - 127.5f * cnt_value : 0.0f;
|
||||
uchar dat_level = save_dat && dat_active ? 127.5f + 127.5f * dat_value : 0.0f;
|
||||
value_buffer[hpos + prev_hpos] = cnt_level | dat_level;
|
||||
value_buffer[buffer_pos & buffer_mask] = cnt_level | dat_level;
|
||||
|
||||
int cnt_quantized = round(cnt_value);
|
||||
int dat_quantized = round(dat_value);
|
||||
|
@ -192,6 +156,10 @@ void decode(int samples) {
|
|||
int sync_level = cnt_active && cnt_quantized == 0;
|
||||
int sync_pulse = !sync_level && sync_counter >= sync_length;
|
||||
sync_counter = sync_level ? sync_counter + 1 : 0;
|
||||
if (sync_pulse) {
|
||||
prev_sync_pos = sync_pos;
|
||||
sync_pos = buffer_pos - sync_buildup_length;
|
||||
}
|
||||
|
||||
if (*current_mode != mode_debug) {
|
||||
int detected_mode = calibration_detector(dat_value, dat_amp, cnt_amp, cnt_quantized);
|
||||
|
@ -214,8 +182,7 @@ void decode(int samples) {
|
|||
|
||||
if (++hpos >= maximum_length || sync_pulse) {
|
||||
if (hpos < minimum_length) {
|
||||
hpos = 0;
|
||||
prev_hpos = 0;
|
||||
hpos = buffer_pos - sync_pos;
|
||||
seperator_counter = 0;
|
||||
continue;
|
||||
}
|
||||
|
@ -235,6 +202,13 @@ void decode(int samples) {
|
|||
default:
|
||||
raw_decoder();
|
||||
}
|
||||
if (hpos >= maximum_length) {
|
||||
hpos -= scanline_length;
|
||||
sync_pos = prev_sync_pos + scanline_length;
|
||||
} else {
|
||||
hpos = buffer_pos - sync_pos;
|
||||
}
|
||||
++vpos;
|
||||
if (vpos == bitmap_height)
|
||||
save_buffer();
|
||||
if (vpos >= maximum_height)
|
||||
|
|
|
@ -25,6 +25,7 @@ void initialize(float rate, int length, int width, int height)
|
|||
{
|
||||
sample_rate = rate;
|
||||
buffer_length = length;
|
||||
buffer_mask = length - 1;
|
||||
maximum_width = width;
|
||||
maximum_height = height;
|
||||
|
||||
|
@ -32,13 +33,16 @@ void initialize(float rate, int length, int width, int height)
|
|||
pixel_buffer[i] = 0;
|
||||
|
||||
vpos = 0;
|
||||
prev_hpos = hpos = 0;
|
||||
hpos = 0;
|
||||
prev_sync_pos = sync_pos = 0;
|
||||
buffer_pos = 0;
|
||||
sync_counter = 0;
|
||||
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 = sync_buildup_seconds * sample_rate;
|
||||
|
||||
robot36_scanline_length = robot36_scanline_seconds * sample_rate;
|
||||
robot72_scanline_length = robot72_scanline_seconds * sample_rate;
|
||||
|
|
|
@ -70,7 +70,6 @@ void robot36_mode()
|
|||
bitmap_width = 320;
|
||||
bitmap_height = 240;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
const float sync_porch_seconds = 0.003f;
|
||||
const float sep_porch_seconds = 0.0015f;
|
||||
|
@ -79,7 +78,7 @@ void robot36_mode()
|
|||
const float seperator_seconds = 0.0045f;
|
||||
seperator_length = seperator_seconds * sample_rate;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
y_begin = (sync_porch_seconds - settling_time) * sample_rate;
|
||||
y_begin = sync_porch_seconds * sample_rate;
|
||||
y_end = y_begin + y_scan_seconds * sample_rate;
|
||||
u_sep_begin = v_sep_begin = y_end;
|
||||
u_sep_end = v_sep_end = u_sep_begin + seperator_seconds * sample_rate;
|
||||
|
@ -98,7 +97,6 @@ void robot72_mode()
|
|||
bitmap_width = 320;
|
||||
bitmap_height = 240;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
const float sync_porch_seconds = 0.003f;
|
||||
const float sep_porch_seconds = 0.0015f;
|
||||
|
@ -107,7 +105,7 @@ void robot72_mode()
|
|||
const float seperator_seconds = 0.0045f;
|
||||
seperator_length = seperator_seconds * sample_rate;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
y_begin = (sync_porch_seconds - settling_time) * sample_rate;
|
||||
y_begin = sync_porch_seconds * sample_rate;
|
||||
y_end = y_begin + y_scan_seconds * sample_rate;
|
||||
v_sep_begin = y_end;
|
||||
v_sep_end = v_sep_begin + seperator_seconds * sample_rate;
|
||||
|
@ -138,7 +136,7 @@ void martin1_mode()
|
|||
const float seperator_seconds = 0.000572f;
|
||||
seperator_length = seperator_seconds * sample_rate;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
g_begin = 0;
|
||||
g_begin = sync_porch_seconds * sample_rate;
|
||||
g_end = g_begin + g_scan_seconds * sample_rate;
|
||||
b_begin = g_end + seperator_seconds * sample_rate;
|
||||
b_end = b_begin + b_scan_seconds * sample_rate;
|
||||
|
@ -165,7 +163,7 @@ void martin2_mode()
|
|||
const float seperator_seconds = 0.000572f;
|
||||
seperator_length = seperator_seconds * sample_rate;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
g_begin = 0;
|
||||
g_begin = sync_porch_seconds * sample_rate;
|
||||
g_end = g_begin + g_scan_seconds * sample_rate;
|
||||
b_begin = g_end + seperator_seconds * sample_rate;
|
||||
b_end = b_begin + b_scan_seconds * sample_rate;
|
||||
|
@ -184,19 +182,18 @@ void scottie1_mode()
|
|||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
const float sync_porch_seconds = 0.0015f;
|
||||
const float rgb_scan_seconds = 0.138240f;
|
||||
const float seperator_seconds = 0.0015f;
|
||||
seperator_length = seperator_seconds * sample_rate;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
r_begin = (sync_porch_seconds - settling_time) * sample_rate;
|
||||
r_begin = sync_porch_seconds * sample_rate;
|
||||
r_end = r_begin + rgb_scan_seconds * sample_rate;
|
||||
g_begin = r_end + seperator_seconds * sample_rate;
|
||||
g_end = g_begin + rgb_scan_seconds * sample_rate;
|
||||
b_begin = g_end + seperator_seconds * sample_rate;
|
||||
b_end = b_begin + rgb_scan_seconds * sample_rate;
|
||||
b_end = - sync_seconds * sample_rate;
|
||||
b_begin = b_end - rgb_scan_seconds * sample_rate;
|
||||
g_end = b_begin - seperator_seconds * sample_rate;
|
||||
g_begin = g_end - rgb_scan_seconds * sample_rate;
|
||||
scanline_length = scottie1_scanline_length;
|
||||
maximum_length = scanline_length + sync_porch_seconds * sample_rate;
|
||||
}
|
||||
|
@ -210,19 +207,18 @@ void scottie2_mode()
|
|||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
const float sync_porch_seconds = 0.0015f;
|
||||
const float rgb_scan_seconds = 0.088064f;
|
||||
const float seperator_seconds = 0.0015f;
|
||||
seperator_length = seperator_seconds * sample_rate;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
r_begin = (sync_porch_seconds - settling_time) * sample_rate;
|
||||
r_begin = sync_porch_seconds * sample_rate;
|
||||
r_end = r_begin + rgb_scan_seconds * sample_rate;
|
||||
g_begin = r_end + seperator_seconds * sample_rate;
|
||||
g_end = g_begin + rgb_scan_seconds * sample_rate;
|
||||
b_begin = g_end + seperator_seconds * sample_rate;
|
||||
b_end = b_begin + rgb_scan_seconds * sample_rate;
|
||||
b_end = - sync_seconds * sample_rate;
|
||||
b_begin = b_end - rgb_scan_seconds * sample_rate;
|
||||
g_end = b_begin - seperator_seconds * sample_rate;
|
||||
g_begin = g_end - rgb_scan_seconds * sample_rate;
|
||||
scanline_length = scottie2_scanline_length;
|
||||
maximum_length = scanline_length + sync_porch_seconds * sample_rate;
|
||||
}
|
||||
|
@ -236,19 +232,18 @@ void scottieDX_mode()
|
|||
bitmap_width = 320;
|
||||
bitmap_height = 256;
|
||||
const float tolerance = 0.8f;
|
||||
const float settling_time = 0.0011f;
|
||||
const float sync_seconds = 0.009f;
|
||||
const float sync_porch_seconds = 0.0015f;
|
||||
const float rgb_scan_seconds = 0.3456f;
|
||||
const float seperator_seconds = 0.0015f;
|
||||
seperator_length = seperator_seconds * sample_rate;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
r_begin = (sync_porch_seconds - settling_time) * sample_rate;
|
||||
r_begin = sync_porch_seconds * sample_rate;
|
||||
r_end = r_begin + rgb_scan_seconds * sample_rate;
|
||||
g_begin = r_end + seperator_seconds * sample_rate;
|
||||
g_end = g_begin + rgb_scan_seconds * sample_rate;
|
||||
b_begin = g_end + seperator_seconds * sample_rate;
|
||||
b_end = b_begin + rgb_scan_seconds * sample_rate;
|
||||
b_end = - sync_seconds * sample_rate;
|
||||
b_begin = b_end - rgb_scan_seconds * sample_rate;
|
||||
g_end = b_begin - seperator_seconds * sample_rate;
|
||||
g_begin = g_end - rgb_scan_seconds * sample_rate;
|
||||
scanline_length = scottieDX_scanline_length;
|
||||
maximum_length = scanline_length + sync_porch_seconds * sample_rate;
|
||||
}
|
||||
|
@ -266,7 +261,7 @@ void wrasseSC2_180_mode()
|
|||
const float sync_porch_seconds = 0.0005f;
|
||||
const float rgb_scan_seconds = 0.235f;
|
||||
sync_length = tolerance * sync_seconds * sample_rate;
|
||||
r_begin = 0;
|
||||
r_begin = sync_porch_seconds * sample_rate;
|
||||
r_end = r_begin + rgb_scan_seconds * sample_rate;
|
||||
g_begin = r_end;
|
||||
g_end = g_begin + rgb_scan_seconds * sample_rate;
|
||||
|
|
|
@ -22,14 +22,15 @@ static ddc_t cnt_ddc, dat_ddc;
|
|||
static fmd_t cnt_fmd, dat_fmd;
|
||||
static int current_decoder;
|
||||
static int blur_power, free_running;
|
||||
static int sample_rate, prev_hpos;
|
||||
static int sample_rate, sync_pos, prev_sync_pos;
|
||||
static int maximum_variance, minimum_sync_length;
|
||||
static int scanline_length, minimum_length, maximum_length;
|
||||
static int vis_timeout, vis_length, bit_length;
|
||||
static int break_timeout, break_length;
|
||||
static int leader_timeout, leader_length;
|
||||
static int first_leader_length, second_leader_length;
|
||||
static int buffer_length, buffer_cleared;
|
||||
static int buffer_length, buffer_mask, buffer_pos;
|
||||
static int buffer_cleared;
|
||||
static int bitmap_width, bitmap_height;
|
||||
static int maximum_width, maximum_height;
|
||||
static int sync_length, sync_counter, vpos, hpos;
|
||||
|
@ -37,6 +38,7 @@ static int save_cnt, save_dat, seperator_counter, seperator_length;
|
|||
static int u_sep_begin, u_sep_end, v_sep_begin, v_sep_end;
|
||||
static int y_begin, y_end, u_begin, u_end, v_begin, v_end;
|
||||
static int r_begin, r_end, b_begin, b_end, g_begin, g_end;
|
||||
static int sync_buildup_length;
|
||||
static int robot36_scanline_length;
|
||||
static int robot72_scanline_length;
|
||||
static int martin1_scanline_length;
|
||||
|
|
15
utils/blur.c
15
utils/blur.c
|
@ -24,20 +24,20 @@ double gauss(double x, double radius)
|
|||
}
|
||||
void emit(int radius)
|
||||
{
|
||||
printf("\t\tif ((i-%d) < begin || end <= (i+%d)) {\n", radius, radius);
|
||||
printf("\t\tif ((p-%d) < begin || end <= (p+%d) || (i-%d) < 0 || buffer_length <= (i+%d)) {\n", radius, radius, radius, radius);
|
||||
for (int i = -radius; i < 0; ++i) {
|
||||
printf("\t\t\tif (begin <= (i%d)) {\n", i);
|
||||
printf("\t\t\tif (begin <= (p%d)) {\n", i);
|
||||
printf("\t\t\t\tweight_sum += %d;\n",
|
||||
(int)(16384 * gauss(i, radius)));
|
||||
printf("\t\t\t\tvalue_sum += %d * value_buffer[i%d];\n",
|
||||
printf("\t\t\t\tvalue_sum += %d * value_buffer[(i%d)&buffer_mask];\n",
|
||||
(int)(16384 * gauss(i, radius)), i);
|
||||
printf("\t\t\t}\n");
|
||||
}
|
||||
for (int i = 0; i <= radius; ++i) {
|
||||
printf("\t\t\tif ((i+%d) < end) {\n", i);
|
||||
printf("\t\t\tif ((p+%d) < end) {\n", i);
|
||||
printf("\t\t\t\tweight_sum += %d;\n",
|
||||
(int)(16384 * gauss(i, radius)));
|
||||
printf("\t\t\t\tvalue_sum += %d * value_buffer[i+%d];\n",
|
||||
printf("\t\t\t\tvalue_sum += %d * value_buffer[(i+%d)&buffer_mask];\n",
|
||||
(int)(16384 * gauss(i, radius)), i);
|
||||
printf("\t\t\t}\n");
|
||||
}
|
||||
|
@ -59,7 +59,8 @@ int main()
|
|||
{
|
||||
printf("/* code generated by 'utils/blur.c' */\n");
|
||||
printf("static uchar value_blur(int pixel, int begin, int end)\n{\n");
|
||||
printf("\tint i = (pixel * (end - begin) + (end - begin) / 2) / bitmap_width + begin;\n");
|
||||
printf("\tint p = (pixel * (end - begin) + (end - begin) / 2) / bitmap_width + begin;\n");
|
||||
printf("\tint i = p & buffer_mask;\n");
|
||||
printf("\tint weight_sum = 0;\n");
|
||||
printf("\tint value_sum = 0;\n");
|
||||
printf("\tswitch (blur_power) {\n");
|
||||
|
@ -67,6 +68,6 @@ int main()
|
|||
printf("\tcase %d:\n", i);
|
||||
emit((1 << i) | 1);
|
||||
}
|
||||
printf("\tdefault:\n\t\tif (i < begin || end <= i)\n\t\t\treturn 0;\n\t\treturn value_buffer[i];\n\t}\n\treturn 0;\n}\n");
|
||||
printf("\tdefault:\n\t\treturn value_buffer[i];\n\t}\n\treturn 0;\n}\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue