@@ -45,23 +45,18 @@ static fl2k_dev_t *dev = NULL;
4545static volatile int do_exit = 0 ;
4646static volatile int repeat = 1 ;
4747
48+ uint32_t samp_rate = 100000000 ;
49+
4850//input file
4951FILE * file_r ;
5052FILE * file_g ;
5153FILE * file_b ;
5254
53- FILE * tmp_file ;
54-
5555//buffer for tx
5656char * txbuf_r = NULL ;
5757char * txbuf_g = NULL ;
5858char * txbuf_b = NULL ;
5959
60- //buffer for reading 16 bit input
61- unsigned short * read_buff_r = NULL ;//reading buffer
62- unsigned short * read_buff_g = NULL ;//reading buffer
63- unsigned short * read_buff_b = NULL ;//reading buffer
64-
6560//chanel activation
6661int red = 0 ;
6762int green = 0 ;
@@ -72,22 +67,34 @@ int r16 = 0;
7267int g16 = 0 ;
7368int b16 = 0 ;
7469
70+ //if it's a tbc
71+ int tbcR = 0 ;
72+ int tbcG = 0 ;
73+ int tbcB = 0 ;
74+
7575int sample_type = 1 ;// 1 == signed 0 == unsigned
7676
77+ uint32_t sample_cnt_r = 0 ;//used for tbc processing
78+ uint32_t sample_cnt_g = 0 ;//used for tbc processing
79+ uint32_t sample_cnt_b = 0 ;//used for tbc processing
80+
7781void usage (void )
7882{
7983 fprintf (stderr ,
8084 "fl2k_file2, a sample player for FL2K VGA dongles\n\n"
8185 "Usage:\n"
8286 "\t[-d device_index (default: 0)]\n"
83- "\t[-s samplerate (default: 100 MS/s)]\n"
87+ "\t[-s samplerate (default: 100 MS/s) you can write(ntsc) ]\n"
8488 "\t[-u Set sample type to unsigned]\n"
8589 "\t[-R filename (use '-' to read from stdin)\n"
8690 "\t[-G filename (use '-' to read from stdin)\n"
8791 "\t[-G filename (use '-' to read from stdin)\n"
8892 "\t[-R16 (convert bits 16 to 8)\n"
8993 "\t[-G16 (convert bits 16 to 8)\n"
9094 "\t[-B16 (convert bits 16 to 8)\n"
95+ "\t[-tbcR interpret R as tbc file\n"
96+ "\t[-tbcG interpret G as tbc file\n"
97+ "\t[-tbcB interpret B as tbc file\n"
9198 );
9299 exit (1 );
93100}
@@ -113,24 +120,65 @@ static void sighandler(int signum)
113120}
114121#endif
115122
116- int read16_to8 (void * buffer , FILE * stream )
123+ int read16_to8 (void * buffer , FILE * stream , int istbc , char color , uint32_t sample_rate )
117124{
118125 unsigned char tmp_buf [1310720 ] ;
119126 unsigned short * calc = malloc (2 );
120127
121- //unsigned char value = 0;
122-
123128 unsigned long i = 0 ;
124129
130+ //(NTSC line = 910 frame = 477750) (PAL line = 1135 frame = 709375)
131+ unsigned long frame_lengt = 0 ;
132+ unsigned long line_lengt = 0 ;
133+
134+ int * sample_cnt = NULL ;
135+
125136 int ret = 2 ;
126137
138+ if (color == 'R' )
139+ {
140+ sample_cnt = & sample_cnt_r ;
141+ }
142+ else if (color == 'G' )
143+ {
144+ sample_cnt = & sample_cnt_g ;
145+ }
146+ else if (color == 'B' )
147+ {
148+ sample_cnt = & sample_cnt_b ;
149+ }
150+
151+ if (sample_rate == 17734475 || sample_rate == 17735845 )//PAL
152+ {
153+ frame_lengt = 709375 ;
154+ line_lengt = 1135 ;
155+ }
156+ else if (sample_rate == 14318181 || sample_rate == 14318170 )//NTSC
157+ {
158+ frame_lengt = 477750 ;
159+ line_lengt = 910 ;
160+ }
161+
162+ //buffer used for skip 1 line
163+ void * skip = malloc (line_lengt );
164+
127165 while (i < 1310720 )
128166 {
167+ //if we are at then end of the frame skip one line
168+ if ((* sample_cnt == frame_lengt ) && (istbc == 1 ))
169+ {
170+ //skip 1 line
171+ fread (skip ,1 ,line_lengt ,stream );
172+ fread (skip ,1 ,line_lengt ,stream );
173+ * sample_cnt = 0 ;
174+ }
175+
129176 fread (calc ,2 ,1 ,stream );
130177
131178 tmp_buf [i ] = (* calc / 256 );//convert to 8 bit
132179
133180 i += 1 ;//on avance le buffer de 1
181+ * sample_cnt += 1 ;
134182 }
135183
136184 memcpy (buffer , & tmp_buf [0 ], 1310720 );
@@ -141,26 +189,18 @@ int read16_to8(void *buffer, FILE *stream)
141189 free (calc );
142190 }
143191
192+ if (skip )
193+ {
194+ free (skip );
195+ }
196+
144197 return ret ;
145198}
146199
147200void fl2k_callback (fl2k_data_info_t * data_info )
148201{
149202 static uint32_t repeat_cnt = 0 ;
150203
151- //unsigned to signed
152- unsigned char * usign_r = (void * )txbuf_r ;
153- unsigned char * usign_g = (void * )txbuf_g ;
154- unsigned char * usign_b = (void * )txbuf_b ;
155-
156- //counter 0 - 1310720
157- long buf_size = 0 ;
158-
159- // store the 8 bit value
160- unsigned char var_r_1 = 0 ;
161- unsigned char var_g_1 = 0 ;
162- unsigned char var_b_1 = 0 ;
163-
164204 //store the number of block readed
165205 int r ;
166206 int g ;
@@ -196,7 +236,7 @@ void fl2k_callback(fl2k_data_info_t *data_info)
196236 {
197237 if (r16 == 1 )
198238 {
199- r = read16_to8 (txbuf_r ,file_r );
239+ r = read16_to8 (txbuf_r ,file_r , tbcR , 'R' , samp_rate );
200240 }
201241 else
202242 {
@@ -213,25 +253,11 @@ void fl2k_callback(fl2k_data_info_t *data_info)
213253 {
214254 if (g16 == 1 )
215255 {
216- // tmp file
217- /*tmp_file = fopen("R:\osmo-fl2k-64bit-20220717\santana_converted.s8", "ab");
218- if (!tmp_file)
219- {
220- fprintf(stderr, "(TMP) : Failed to open %s\n", tmp_file);
221- return -ENOENT;
222- }*/
223-
224- g = read16_to8 (txbuf_g ,file_g );
225-
226- /*if (tmp_file && (tmp_file != stdin))
227- {
228- fclose(tmp_file);
229- }*/
256+ g = read16_to8 (txbuf_g ,file_g ,tbcG ,'G' ,samp_rate );
230257 }
231258 else
232259 {
233260 g = fread (txbuf_g , 1 , 1310720 , file_g );
234- printf ("txbuf : %x %x %x %x %x\n" ,* txbuf_g ,(* txbuf_g << 8 ) + 255 ,* txbuf_g << 16 ,* txbuf_g << 24 ,* txbuf_g << 32 );
235261 }
236262
237263 if (ferror (file_g ))
@@ -244,7 +270,7 @@ void fl2k_callback(fl2k_data_info_t *data_info)
244270 {
245271 if (b16 == 1 )
246272 {
247- b = read16_to8 (txbuf_b ,file_b );
273+ b = read16_to8 (txbuf_b ,file_b , tbcB , 'B' , samp_rate );
248274 }
249275 else
250276 {
@@ -270,7 +296,6 @@ int main(int argc, char **argv)
270296 struct sigaction sigact , sigign ;
271297#endif
272298 int r , opt , i ;
273- uint32_t samp_rate = 100000000 ;
274299 uint32_t buf_num = 0 ;
275300 int dev_index = 0 ;
276301 void * status ;
@@ -285,6 +310,9 @@ int main(int argc, char **argv)
285310 {"R16" , no_argument , 0 , 'x' },
286311 {"G16" , no_argument , 0 , 'y' },
287312 {"B16" , no_argument , 0 , 'z' },
313+ {"tbcR" , no_argument , 0 , 'j' },
314+ {"tbcG" , no_argument , 0 , 'k' },
315+ {"tbcB" , no_argument , 0 , 'l' },
288316 {0 , 0 , 0 , 0 }
289317 };
290318
@@ -297,7 +325,18 @@ int main(int argc, char **argv)
297325 repeat = (int )atoi (optarg );
298326 break ;
299327 case 's' :
300- samp_rate = (uint32_t )atof (optarg );
328+ if ((strcmp (optarg , "ntsc" ) == 0 ) || (strcmp (optarg , "NTSC" ) == 0 ) || (strcmp (optarg , "Ntsc" ) == 0 ))
329+ {
330+ samp_rate = (uint32_t ) 14318181 ;
331+ }
332+ else if ((strcmp (optarg , "pal" ) == 0 ) || (strcmp (optarg , "PAL" ) == 0 ) || (strcmp (optarg , "Pal" ) == 0 ))
333+ {
334+ samp_rate = (uint32_t ) 17734475 ;
335+ }
336+ else
337+ {
338+ samp_rate = (uint32_t )atof (optarg );
339+ }
301340 break ;
302341 case 'u' :
303342 sample_type = 0 ;
@@ -323,6 +362,15 @@ int main(int argc, char **argv)
323362 case 'z' :
324363 b16 = 1 ;
325364 break ;
365+ case 'j' :
366+ tbcR = 1 ;
367+ break ;
368+ case 'k' :
369+ tbcG = 1 ;
370+ break ;
371+ case 'l' :
372+ tbcB = 1 ;
373+ break ;
326374 default :
327375 usage ();
328376 break ;
@@ -361,12 +409,6 @@ if(red == 1)
361409 fprintf (stderr , "(RED) : malloc error!\n" );
362410 goto out ;
363411 }
364-
365- read_buff_r = malloc (2 );
366- if (!read_buff_r ) {
367- fprintf (stderr , "(RED 16) : malloc error!\n" );
368- goto out ;
369- }
370412}
371413
372414//GREEN
@@ -390,12 +432,6 @@ if(green == 1)
390432 fprintf (stderr , "(GREEN) : malloc error!\n" );
391433 goto out ;
392434 }
393-
394- read_buff_g = malloc (2 );
395- if (!read_buff_g ) {
396- fprintf (stderr , "(GREEN 16) : malloc error!\n" );
397- goto out ;
398- }
399435}
400436//BLUE
401437if (blue == 1 )
@@ -418,12 +454,6 @@ if(blue == 1)
418454 fprintf (stderr , "(BLUE) : malloc error!\n" );
419455 goto out ;
420456 }
421-
422- read_buff_b = malloc (2 );
423- if (!read_buff_b ) {
424- fprintf (stderr , "(BLUE 16) : malloc error!\n" );
425- goto out ;
426- }
427457}
428458
429459//next
@@ -468,11 +498,6 @@ if(red == 1)
468498 {
469499 free (txbuf_r );
470500 }
471-
472- if (read_buff_r )
473- {
474- free (read_buff_r );
475- }
476501
477502 if (file_r && (file_r != stdin ))
478503 {
@@ -486,11 +511,6 @@ if(green == 1)
486511 {
487512 free (txbuf_g );
488513 }
489-
490- if (read_buff_g )
491- {
492- free (read_buff_g );
493- }
494514
495515 if (file_g && (file_g != stdin ))
496516 {
@@ -504,11 +524,6 @@ if(blue == 1)
504524 {
505525 free (txbuf_b );
506526 }
507-
508- if (read_buff_b )
509- {
510- free (read_buff_b );
511- }
512527
513528 if (file_b && (file_b != stdin ))
514529 {
0 commit comments