@@ -81,7 +81,7 @@ int green2 = 0;
8181int blue2 = 0 ;
8282int audio = 0 ;
8383
84- char sync_a = 0 ;
84+ char sync_a = 'G' ;
8585
8686//enable 16 bit to 8 bit conversion
8787int r16 = 0 ;
@@ -108,9 +108,12 @@ int cmb_mode_r = 0;
108108int cmb_mode_g = 0 ;
109109int cmb_mode_b = 0 ;
110110
111- //
111+ //read mode
112112int read_mode = 0 ;//0 = multitthreading / 1 = hybrid (R --> GB) / 2 = hybrid (RG --> B) / 3 = sequential (R -> G -> B)
113113
114+ //pipe mode
115+ char pipe_mode = 'A' ;
116+
114117int sample_type = 1 ;// 1 == signed 0 == unsigned
115118
116119uint32_t sample_cnt_r = 0 ;//used for tbc processing
@@ -129,7 +132,7 @@ uint32_t field_cnt_r = 0;//used for tbc processing
129132uint32_t field_cnt_g = 0 ;//used for tbc processing
130133uint32_t field_cnt_b = 0 ;//used for tbc processing
131134
132- unsigned char * pipe_buf = NULL ;
135+ // unsigned char *pipe_buf = NULL;
133136
134137//thread for processing
135138pthread_t thread_r ;
@@ -170,6 +173,8 @@ void usage(void)
170173 "\t[-FstartR seek to frame for input R\n"
171174 "\t[-FstartG seek to frame for input G\n"
172175 "\t[-FstartB seek to frame for input B\n"
176+ "\t[-audioOffset offset audio from a duration of x frame\n"
177+ "\t[-pipeMode (default = A) option : A = Audio file / R = output of R / G = output of G / B = output of B\n"
173178 "\t[-readMode (default = 0) option : 0 = multit-threading (RGB) / 1 = hybrid (R --> GB) / 2 = hybrid (RG --> B) / 3 = sequential (R -> G -> B)\n"
174179 );
175180 exit (1 );
@@ -240,6 +245,7 @@ int read_sample_file(void *inpt_color)
240245 int is_stereo = 0 ;
241246 int combine_mode = 0 ;
242247 int is_sync_a = 0 ;
248+ int use_pipe = 0 ;
243249
244250 long i = 0 ;//counter for tmp_buf
245251 long y = 0 ;//counter for calc
@@ -282,11 +288,15 @@ int read_sample_file(void *inpt_color)
282288 is_stereo = red2 ;
283289 combine_mode = cmb_mode_r ;
284290 is16 = r16 ;
285- if (sync_a == 'R' )
291+ if (sync_a == 'R' && pipe_mode == 'A' )
286292 {
287293 is_sync_a = 1 ;
288294 streamA = file_audio ;
289295 }
296+ else if (pipe_mode == 'R' )
297+ {
298+ use_pipe = 1 ;
299+ }
290300 }
291301 else if (color == 'G' )
292302 {
@@ -303,11 +313,15 @@ int read_sample_file(void *inpt_color)
303313 is_stereo = green2 ;
304314 combine_mode = cmb_mode_g ;
305315 is16 = g16 ;
306- if (sync_a == 'G' )
316+ if (sync_a == 'G' && pipe_mode == 'A' )
307317 {
308318 is_sync_a = 1 ;
309319 streamA = file_audio ;
310320 }
321+ else if (pipe_mode == 'G' )
322+ {
323+ use_pipe = 1 ;
324+ }
311325 }
312326 else if (color == 'B' )
313327 {
@@ -324,11 +338,15 @@ int read_sample_file(void *inpt_color)
324338 is_stereo = blue2 ;
325339 combine_mode = cmb_mode_b ;
326340 is16 = b16 ;
327- if (sync_a == 'B' )
341+ if (sync_a == 'B' && pipe_mode == 'A' )
328342 {
329343 is_sync_a = 1 ;
330344 streamA = file_audio ;
331345 }
346+ else if (pipe_mode == 'B' )
347+ {
348+ use_pipe = 1 ;
349+ }
332350 }
333351
334352 //IRE
@@ -348,7 +366,7 @@ int read_sample_file(void *inpt_color)
348366 v_end = 1107 * (1 + is16 );
349367 cbust_start = 98 * (1 + is16 );//not set
350368 cbust_end = 138 * (1 + is16 );//not set
351- audio_frame = ((88200 /25 ) * ( 1 + b16 ) );
369+ audio_frame = ((88200 /25 ) * 2 );
352370 //sample_skip = 4 * (1 + is16);//remove 4 extra sample in pal
353371 }
354372 else if (sample_rate == 14318181 || sample_rate == 14318170 )//NTSC multiplied by 2 if input is 16bit
@@ -360,7 +378,7 @@ int read_sample_file(void *inpt_color)
360378 v_end = 894 * (1 + is16 );
361379 cbust_start = 78 * (1 + is16 );
362380 cbust_end = 110 * (1 + is16 );
363- audio_frame = ((88200 /30 ) * ( 1 + b16 ) );
381+ audio_frame = ((88200 /30 ) * 2 );
364382 }
365383
366384 unsigned long buf_size = (1310720 + (is16 * 1310720 ));
@@ -471,7 +489,7 @@ int read_sample_file(void *inpt_color)
471489 {
472490 if (combine_mode == 0 )//default
473491 {
474- tmp_buf [i ] = round ((value16 + value16_2 )/ 256.0 );//convert to 8 bit
492+ tmp_buf [i ] = round ((* value16_signed + * value16_2_signed )/ 256.0 ) + 128 ;//convert to 8 bit
475493 }
476494 else //mode 1
477495 {
@@ -557,6 +575,11 @@ int read_sample_file(void *inpt_color)
557575 }
558576
559577 memcpy (buffer , tmp_buf , 1310720 );
578+ if (isatty (STDOUT_FILENO ) == 0 && use_pipe )
579+ {
580+ fwrite (tmp_buf , 1310720 ,1 ,stdout );
581+ fflush (stdout );
582+ }
560583
561584 free (tmp_buf );
562585 free (audio_buf );
@@ -748,6 +771,8 @@ int main(int argc, char **argv)
748771 uint64_t start_g = 0 ;
749772 uint64_t start_b = 0 ;
750773 uint64_t start_audio = 0 ;
774+
775+ long audio_offset = 0 ;
751776
752777 //file adress
753778 char * filename_r = NULL ;
@@ -759,16 +784,16 @@ int main(int argc, char **argv)
759784 char * filename2_b = NULL ;
760785 char * filename_audio = NULL ;
761786
762- pipe_buf = malloc (1310720 );
787+ // pipe_buf = malloc(1310720);
763788
764- if (pipe_buf == NULL )
789+ /* if (pipe_buf == NULL)
765790 {
766791 free(pipe_buf); // Free both in case only one was allocated
767792 fprintf(stderr, "malloc error (pipe_buf)\n");
768793 return -1;
769- }
794+ }*/
770795
771- setvbuf (stdout ,pipe_buf ,_IOLBF ,1310720 );
796+ // setvbuf(stdout,pipe_buf,_IOLBF,1310720);
772797
773798 int option_index = 0 ;
774799 static struct option long_options [] = {
@@ -796,6 +821,8 @@ int main(int argc, char **argv)
796821 {"cmbModeR" , 1 , 0 , 21 },
797822 {"cmbModeG" , 1 , 0 , 22 },
798823 {"cmbModeB" , 1 , 0 , 23 },
824+ {"audioOffset" , 1 , 0 , 24 },
825+ {"pipeMode" , 1 , 0 , 25 },
799826 {0 , 0 , 0 , 0 }
800827 };
801828
@@ -901,10 +928,10 @@ int main(int argc, char **argv)
901928 filename2_b = optarg ;
902929 break ;
903930 case 20 :
904- if (optarg == 'r' ){sync_a = 'R' ;}
905- else if (optarg == 'g' ){sync_a = 'G' ;}
906- else if (optarg == 'b' ){sync_a = 'B' ;}
907- else {sync_a = optarg ;}
931+ if (* optarg == 'r' ){sync_a = 'R' ;}
932+ else if (* optarg == 'g' ){sync_a = 'G' ;}
933+ else if (* optarg == 'b' ){sync_a = 'B' ;}
934+ else {sync_a = * optarg ;}
908935 break ;
909936 case 21 :
910937 cmb_mode_r = atoi (optarg );
@@ -915,6 +942,16 @@ int main(int argc, char **argv)
915942 case 23 :
916943 cmb_mode_b = atoi (optarg );
917944 break ;
945+ case 24 :
946+ audio_offset = atol (optarg );
947+ break ;
948+ case 25 :
949+ if (* optarg == 'a' ){pipe_mode = 'A' ;}
950+ else if (* optarg == 'r' ){pipe_mode = 'R' ;}
951+ else if (* optarg == 'g' ){pipe_mode = 'G' ;}
952+ else if (* optarg == 'b' ){pipe_mode = 'B' ;}
953+ else {pipe_mode = * optarg ;}
954+ break ;
918955 default :
919956 usage ();
920957 break ;
@@ -945,16 +982,25 @@ int main(int argc, char **argv)
945982 usage ();
946983 }
947984
948- if ((sync_a != 'R' ) && (sync_a != 'G' ) && (sync_a != 'B' ) && ( sync_a != 0 ) )
985+ if ((sync_a != 'R' ) && (sync_a != 'G' ) && (sync_a != 'B' ))
949986 {
950987 fprintf (stderr , "\nUnknow parametter '%c' for option -syncA / value : (R,r,G,g,B,b)\n\n" ,sync_a );
951988 usage ();
952989 }
953990 else if (sync_a == 'R' ){start_audio = start_r ;}
954991 else if (sync_a == 'G' ){start_audio = start_g ;}
955992 else if (sync_a == 'B' ){start_audio = start_b ;}
993+ else if (red == 1 && green == 0 && blue == 0 ){start_audio = start_r ; sync_a = 'R' ;}//select the channel if only 1 is activated
994+ else if (red == 0 && green == 1 && blue == 0 ){start_audio = start_g ; sync_a = 'G' ;}
995+ else if (red == 0 && green == 0 && blue == 1 ){start_audio = start_b ; sync_a = 'B' ;}
956996 else {start_audio = start_g ; sync_a = 'G' ;}//default value
957997
998+ if ((pipe_mode != 'A' ) && (pipe_mode != 'R' ) && (pipe_mode != 'G' ) && (pipe_mode != 'B' ))
999+ {
1000+ fprintf (stderr , "\nUnknow parametter '%c' for option -pipeMode / value : (A,a,R,r,G,g,B,b)\n\n" ,pipe_mode );
1001+ usage ();
1002+ }
1003+
9581004 if ((cmb_mode_r < 0 || cmb_mode_r > 1 ) || (cmb_mode_g < 0 || cmb_mode_g > 1 ) || (cmb_mode_b < 0 || cmb_mode_b > 1 ))
9591005 {
9601006 fprintf (stderr , "\nCombine mode invalid / value : (0 ,1)\n\n" );
@@ -978,14 +1024,14 @@ int main(int argc, char **argv)
9781024 start_r = start_r * ((709375 + (1135 * tbcR )) * (1 + r16 ));
9791025 start_g = start_g * ((709375 + (1135 * tbcB )) * (1 + g16 ));
9801026 start_b = start_b * ((709375 + (1135 * tbcG )) * (1 + b16 ));
981- start_audio = start_audio * ((88200 /25 ) * ( 1 + b16 ) );
1027+ start_audio = ( start_audio + audio_offset ) * ((88200 /25 ) * 2 );
9821028 }
9831029 else if (samp_rate == 14318181 || samp_rate == 14318170 )//NTSC set first frame
9841030 {
9851031 start_r = start_r * ((477750 + (910 * tbcR )) * (1 + r16 ));
9861032 start_g = start_g * ((477750 + (910 * tbcG )) * (1 + g16 ));
9871033 start_b = start_b * ((477750 + (910 * tbcB )) * (1 + b16 ));
988- start_audio = start_audio * ((88200 /30 ) * ( 1 + b16 ) );
1034+ start_audio = ( start_audio + audio_offset ) * ((88200 /30 ) * 2 );
9891035 }
9901036
9911037//RED
@@ -1258,7 +1304,7 @@ if(audio == 1)
12581304 }
12591305 }
12601306
1261- free (pipe_buf );
1307+ // free(pipe_buf);
12621308
12631309 return 0 ;
12641310}
0 commit comments