00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00038 #include <sys/stat.h>
00039 #include <string.h>
00040 #include <math.h>
00041
00042 #include "splt.h"
00043
00044
00046 static long splt_s_real_split(double splt_beg, double splt_end,
00047 int save_end_point, int *error, splt_state *state)
00048 {
00049 char *final_fname = splt_su_get_fname_with_path_and_extension(state,error);
00050 long new_end_point = splt_co_time_to_long_ceil(splt_end);
00051
00052 if (*error >= 0)
00053 {
00054 double new_sec_end_point =
00055 splt_p_split(state, final_fname, splt_beg, splt_end, error, save_end_point);
00056
00057 if (new_sec_end_point == -1.0)
00058 {
00059 new_end_point = LONG_MAX;
00060 }
00061 else
00062 {
00063 new_end_point = splt_co_time_to_long_ceil(new_sec_end_point);
00064 }
00065
00066 if (*error >= 0)
00067 {
00068 splt_c_update_progress(state,1.0,1.0,1,1,1);
00069
00070 int err = SPLT_OK;
00071 err = splt_c_put_split_file(state, final_fname);
00072 if (err < 0) { *error = err; }
00073 }
00074 }
00075
00076 if (final_fname)
00077 {
00078 free(final_fname);
00079 final_fname = NULL;
00080 }
00081
00082 return new_end_point;
00083 }
00084
00086 static long splt_s_split(splt_state *state, int first_splitpoint,
00087 int second_splitpoint, int *error)
00088 {
00089 int get_error = SPLT_OK;
00090 long split_begin = splt_sp_get_splitpoint_value(state, first_splitpoint, &get_error);
00091 long split_end = splt_sp_get_splitpoint_value(state, second_splitpoint, &get_error);
00092
00093 long new_end_point = split_end;
00094
00095 int save_end_point = SPLT_TRUE;
00096 if (splt_sp_get_splitpoint_type(state, second_splitpoint, &get_error) == SPLT_SKIPPOINT ||
00097 splt_o_get_long_option(state, SPLT_OPT_OVERLAP_TIME) > 0)
00098 {
00099 save_end_point = SPLT_FALSE;
00100 }
00101
00102 if (get_error == SPLT_OK)
00103 {
00104
00105 if (*error >= 0)
00106 {
00107
00108 if (split_begin != split_end)
00109 {
00110
00111
00112 double splt_beg = split_begin / 100;
00113 splt_beg += ((split_begin % 100) / 100.);
00114 double splt_end = 0;
00115
00116
00117 if (split_end == LONG_MAX)
00118 {
00119 splt_end = -1;
00120 }
00121 else
00122 {
00123 splt_end = split_end / 100;
00124 splt_end += ((split_end % 100) / 100.);
00125 }
00126
00127 new_end_point = splt_s_real_split(splt_beg, splt_end, save_end_point, error, state);
00128 }
00129 else
00130 {
00131 splt_e_set_error_data_from_splitpoint(state, split_begin);
00132 *error = SPLT_ERROR_EQUAL_SPLITPOINTS;
00133 }
00134 }
00135 }
00136 else
00137 {
00138 *error = get_error;
00139 }
00140
00141 return new_end_point;
00142 }
00143
00145 void splt_s_multiple_split(splt_state *state, int *error)
00146 {
00147 int split_type = splt_o_get_int_option(state, SPLT_OPT_SPLIT_MODE);
00148 int err = SPLT_OK;
00149
00150 splt_of_set_oformat_digits(state);
00151
00152 if (split_type == SPLT_OPTION_NORMAL_MODE)
00153 {
00154 splt_c_put_info_message_to_client(state, _(" info: starting normal split\n"));
00155 }
00156
00157 splt_u_print_overlap_time(state);
00158
00159 int get_error = SPLT_OK;
00160
00161 splt_array *new_end_points = splt_array_new();
00162
00163 int i = 0;
00164 int number_of_splitpoints = splt_t_get_splitnumber(state);
00165
00166 while (i < number_of_splitpoints - 1)
00167 {
00168 splt_t_set_current_split(state, i);
00169
00170 if (!splt_t_split_is_canceled(state))
00171 {
00172 get_error = SPLT_OK;
00173
00174 int first_splitpoint_type = splt_sp_get_splitpoint_type(state, i, &get_error);
00175 if (first_splitpoint_type == SPLT_SKIPPOINT)
00176 {
00177 splt_d_print_debug(state, "SKIP splitpoint at _%d_\n", i);
00178 i++;
00179 continue;
00180 }
00181
00182 splt_tu_auto_increment_tracknumber(state);
00183
00184 long saved_end_point = splt_sp_get_splitpoint_value(state, i+1, &get_error);
00185 splt_sp_overlap_time(state, i + 1);
00186
00187 err = splt_u_finish_tags_and_put_output_format_filename(state, i);
00188 if (err < 0) { *error = err; goto end; }
00189
00190 int end_point_index = i+1;
00191 long new_end_point = splt_s_split(state, i, end_point_index, error);
00192 splt_pair *index_end_point =
00193 splt_pair_new((void *) &end_point_index, (void *) &new_end_point);
00194 splt_array_append(new_end_points, (void *)index_end_point);
00195
00196 splt_sp_set_splitpoint_value(state, i + 1, saved_end_point);
00197
00198 if ((*error < 0) || (*error == SPLT_OK_SPLIT_EOF))
00199 {
00200 break;
00201 }
00202 }
00203 else
00204 {
00205 *error = SPLT_SPLIT_CANCELLED;
00206 goto end;
00207 }
00208
00209 i++;
00210 }
00211
00212 end:
00213 for (i = 0;i < splt_array_length(new_end_points);i++)
00214 {
00215 splt_pair *index_end_point = (splt_pair *) splt_array_get(new_end_points, i);
00216
00217 splt_sp_set_splitpoint_value(state,
00218 *((int*) splt_pair_first(index_end_point)),
00219 *((long*) splt_pair_second(index_end_point)));
00220
00221 splt_pair_free(&index_end_point);
00222 }
00223
00224 splt_array_free(&new_end_points);
00225 }
00226
00227 void splt_s_normal_split(splt_state *state, int *error)
00228 {
00229 int output_filenames = splt_o_get_int_option(state,SPLT_OPT_OUTPUT_FILENAMES);
00230 if (output_filenames == SPLT_OUTPUT_DEFAULT)
00231 {
00232 splt_of_set_oformat(state, SPLT_DEFAULT_OUTPUT, error, SPLT_TRUE);
00233 if (*error < 0) { return; }
00234 }
00235
00236 splt_s_multiple_split(state, error);
00237 }
00238
00240 void splt_s_error_split(splt_state *state, int *error)
00241 {
00242 splt_c_put_info_message_to_client(state, _(" info: starting error mode split\n"));
00243 char *final_fname = NULL;
00244
00245
00246 splt_p_search_syncerrors(state, error);
00247
00248
00249
00250 splt_c_update_progress(state,1.0,1.0,1,1,1);
00251
00252 int err = SPLT_OK;
00253
00254
00255 if (*error >= 0)
00256 {
00257
00258 splt_t_set_splitnumber(state, state->serrors->serrors_points_num - 1);
00259
00260 splt_of_set_oformat_digits(state);
00261
00262 if (splt_o_get_int_option(state,SPLT_OPT_OUTPUT_FILENAMES) == SPLT_OUTPUT_DEFAULT)
00263 {
00264 splt_of_set_oformat(state, SPLT_DEFAULT_SYNCERROR_OUTPUT, &err, SPLT_TRUE);
00265 if (err < 0) { *error = err; goto bloc_end; }
00266 }
00267
00268
00269 int i = 0;
00270 for (i = 0; i < state->serrors->serrors_points_num - 1; i++)
00271 {
00272
00273 if (!splt_t_split_is_canceled(state))
00274 {
00275
00276 splt_t_set_current_split(state, i);
00277
00278 splt_tu_auto_increment_tracknumber(state);
00279
00280
00281 int err = splt_sp_append_splitpoint(state, 0, "", SPLT_SPLITPOINT);
00282 if (err < 0) { *error = err; goto bloc_end; }
00283
00284 err = splt_u_finish_tags_and_put_output_format_filename(state, -1);
00285 if (err < 0) { *error = err; goto bloc_end; }
00286
00287 final_fname = splt_su_get_fname_with_path_and_extension(state, error);
00288
00289 if (*error >= 0)
00290 {
00291 splt_io_create_output_dirs_if_necessary(state, final_fname, error);
00292 if (error < 0)
00293 {
00294 goto bloc_end;
00295 }
00296
00297
00298 int split_result = splt_p_simple_split(state, final_fname,
00299 (off_t) state->serrors->serrors_points[i],
00300 (off_t) state->serrors->serrors_points[i+1]);
00301
00302
00303 splt_c_update_progress(state,1.0,1.0,1,1,1);
00304
00305 if (split_result >= 0)
00306 {
00307 *error = SPLT_SYNC_OK;
00308 }
00309 else
00310 {
00311 *error = split_result;
00312 }
00313
00314
00315 if (*error == SPLT_SYNC_OK)
00316 {
00317 err = splt_c_put_split_file(state, final_fname);
00318 if (err < 0) { *error = err; goto bloc_end; }
00319 }
00320 }
00321 else
00322 {
00323
00324 goto bloc_end;
00325 }
00326
00327
00328 if (final_fname)
00329 {
00330 free(final_fname);
00331 final_fname = NULL;
00332 }
00333 }
00334
00335 else
00336 {
00337 *error = SPLT_SPLIT_CANCELLED;
00338 goto bloc_end;
00339 }
00340 }
00341 }
00342 else
00343 {
00344 if (*error >= 0 && err < 0)
00345 {
00346 *error = err;
00347 }
00348 }
00349
00350 bloc_end:
00351
00352 if (final_fname)
00353 {
00354 free(final_fname);
00355 final_fname = NULL;
00356 }
00357 }
00358
00359
00362 static void splt_s_split_by_time(splt_state *state, int *error,
00363 double split_time_length, int number_of_files)
00364 {
00365 char *final_fname = NULL;
00366 int j=0, tracks=1;
00367 double begin = 0.f;
00368 double end = split_time_length;
00369 long total_time = splt_t_get_total_time(state);
00370
00371 if (split_time_length >= 0)
00372 {
00373 splt_u_print_overlap_time(state);
00374
00375 int err = SPLT_OK;
00376
00377 int temp_int = number_of_files + 1;
00378 if (total_time > 0 && number_of_files == -1)
00379 {
00380 temp_int = (int)floor(((total_time / 100.0) / (split_time_length))+1) + 1;
00381 }
00382 splt_t_set_splitnumber(state, temp_int);
00383
00384 splt_of_set_oformat_digits(state);
00385
00386
00387 int output_filenames = splt_o_get_int_option(state, SPLT_OPT_OUTPUT_FILENAMES);
00388 if (output_filenames == SPLT_OUTPUT_DEFAULT)
00389 {
00390 splt_of_set_oformat(state, SPLT_DEFAULT_OUTPUT, &err, SPLT_TRUE);
00391 if (err < 0) { *error = err; return; }
00392 }
00393
00394
00395 err = splt_sp_append_splitpoint(state, 0, "", SPLT_SPLITPOINT);
00396 if (err >= 0)
00397 {
00398 int save_end_point = SPLT_TRUE;
00399 if (splt_o_get_long_option(state, SPLT_OPT_OVERLAP_TIME) > 0)
00400 {
00401 save_end_point = SPLT_FALSE;
00402 }
00403
00404 splt_array *new_end_points = splt_array_new();
00405
00406 do {
00407 if (!splt_t_split_is_canceled(state))
00408 {
00409 err = splt_sp_append_splitpoint(state, 0, "", SPLT_SPLITPOINT);
00410 if (err < 0) { *error = err; break; }
00411
00412 splt_t_set_current_split(state, tracks-1);
00413
00414 splt_tu_auto_increment_tracknumber(state);
00415
00416 int current_split = splt_t_get_current_split(state);
00417
00418 splt_sp_set_splitpoint_value(state, current_split,
00419 splt_co_time_to_long_ceil(begin));
00420 long end_splitpoint = splt_co_time_to_long_ceil(end);
00421 splt_sp_set_splitpoint_value(state, current_split+1, end_splitpoint);
00422
00423 long overlapped_time = splt_sp_overlap_time(state, current_split+1);
00424 double overlapped_end = -1;
00425 if (overlapped_time != LONG_MAX)
00426 {
00427 overlapped_end = (double) ((double) overlapped_time / 100.0);
00428 }
00429
00430 err = splt_u_finish_tags_and_put_output_format_filename(state, -1);
00431 if (err < 0) { *error = err; break; }
00432
00433 final_fname = splt_su_get_fname_with_path_and_extension(state,&err);
00434 if (err < 0) { *error = err; break; }
00435
00436 double new_sec_end_point = splt_p_split(state, final_fname,
00437 begin, overlapped_end, error, save_end_point);
00438 long new_end_point = 0;
00439 if (new_sec_end_point == -1.0)
00440 {
00441 new_end_point = LONG_MAX;
00442 }
00443 else
00444 {
00445 new_end_point = splt_co_time_to_long_ceil(new_sec_end_point);
00446 }
00447
00448 int end_point_index = current_split + 1;
00449 splt_pair *index_end_point =
00450 splt_pair_new((void *) &end_point_index, (void *) &new_end_point);
00451 splt_array_append(new_end_points, (void *) index_end_point);
00452
00453
00454 if (*error >= 0)
00455 {
00456 err = splt_c_put_split_file(state, final_fname);
00457 if (err < 0) { *error = err; break; }
00458 }
00459
00460
00461 begin = end;
00462 end += split_time_length;
00463 tracks++;
00464
00465
00466 if ((*error == SPLT_MIGHT_BE_VBR) ||
00467 (*error == SPLT_OK_SPLIT_EOF) ||
00468 (*error < 0))
00469 {
00470 tracks = 0;
00471 }
00472
00473 if (*error==SPLT_ERROR_BEGIN_OUT_OF_FILE)
00474 {
00475 j--;
00476 }
00477
00478 if (final_fname)
00479 {
00480
00481 free(final_fname);
00482 final_fname = NULL;
00483 }
00484 }
00485 else
00486 {
00487 *error = SPLT_SPLIT_CANCELLED;
00488 break;
00489 }
00490
00491 } while (j++<tracks);
00492
00493 if (final_fname)
00494 {
00495 free(final_fname);
00496 final_fname = NULL;
00497 }
00498
00499 int i = 0;
00500 for (i = 0;i < splt_array_length(new_end_points);i++)
00501 {
00502 splt_pair *index_end_point = (splt_pair *) splt_array_get(new_end_points, i);
00503
00504 splt_sp_set_splitpoint_value(state,
00505 *((int*) splt_pair_first(index_end_point)),
00506 *((long*) splt_pair_second(index_end_point)));
00507
00508 splt_pair_free(&index_end_point);
00509 }
00510
00511 splt_array_free(&new_end_points);
00512 }
00513 else
00514 {
00515 *error = err;
00516 }
00517
00518
00519 switch (*error)
00520 {
00521
00522
00523
00524
00525 case SPLT_OK_SPLIT:
00526 *error = SPLT_TIME_SPLIT_OK;
00527 break;
00528 case SPLT_OK_SPLIT_EOF:
00529 *error = SPLT_TIME_SPLIT_OK;
00530 break;
00531 case SPLT_ERROR_BEGIN_OUT_OF_FILE:
00532 *error = SPLT_TIME_SPLIT_OK;
00533 break;
00534 default:
00535 break;
00536 }
00537 }
00538 else
00539 {
00540 *error = SPLT_ERROR_NEGATIVE_TIME_SPLIT;
00541 }
00542 }
00543
00549 void splt_s_time_split(splt_state *state, int *error)
00550 {
00551 splt_c_put_info_message_to_client(state, _(" info: starting time mode split\n"));
00552
00553 double split_time_length = (double) splt_o_get_float_option(state, SPLT_OPT_SPLIT_TIME);
00554 if (((long)split_time_length) == 0)
00555 {
00556 *error = SPLT_ERROR_TIME_SPLIT_VALUE_INVALID;
00557 return;
00558 }
00559
00560 splt_s_split_by_time(state, error, split_time_length, -1);
00561 }
00562
00568 void splt_s_equal_length_split(splt_state *state, int *error)
00569 {
00570 splt_c_put_info_message_to_client(state, _(" info: starting 'split in equal tracks' mode\n"));
00571
00572 double total_time = splt_t_get_total_time_as_double_secs(state);
00573 if (total_time > 0)
00574 {
00575 int number_of_files =
00576 splt_o_get_int_option(state, SPLT_OPT_LENGTH_SPLIT_FILE_NUMBER);
00577
00578 if (number_of_files > 0)
00579 {
00580 double split_time_length = total_time / number_of_files;
00581 splt_s_split_by_time(state, error, split_time_length, number_of_files);
00582 }
00583 else
00584 {
00585 *error = SPLT_ERROR_LENGTH_SPLIT_VALUE_INVALID;
00586 return;
00587 }
00588 }
00589 else
00590 {
00591 *error = SPLT_ERROR_CANNOT_GET_TOTAL_TIME;
00592 return;
00593 }
00594
00595 if (*error == SPLT_TIME_SPLIT_OK)
00596 {
00597 *error = SPLT_LENGTH_SPLIT_OK;
00598 }
00599 }
00600
00601 int splt_s_set_trim_silence_splitpoints(splt_state *state, int *error)
00602 {
00603 splt_d_print_debug(state, "Search and set trim silence splitpoints...\n");
00604
00605 int found = 0;
00606 struct splt_ssplit *temp = NULL;
00607 int append_error = SPLT_OK;
00608
00609 if (! splt_o_get_int_option(state,SPLT_OPT_QUIET_MODE))
00610 {
00611 splt_c_put_info_message_to_client(state,
00612 _(" Trim silence split - Th: %.1f dB\n"),
00613 splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD));
00614 }
00615
00616 if (state->split.get_silence_level)
00617 {
00618 state->split.get_silence_level(0, INT_MAX, state->split.silence_level_client_data);
00619 }
00620 found = splt_p_scan_trim_silence(state, error);
00621 if (*error < 0) { goto end; }
00622
00623 if (splt_t_split_is_canceled(state))
00624 {
00625 *error = SPLT_SPLIT_CANCELLED;
00626 goto end;
00627 }
00628
00629 temp = state->silence_list;
00630 int i;
00631 long previous = 0;
00632 for (i = 1; i < found + 1; i++)
00633 {
00634 if (temp == NULL)
00635 {
00636 found = i;
00637 break;
00638 }
00639
00640 long temp_silence_pos = splt_siu_silence_position(temp, 0) * 100;
00641
00642 if (i > 1 && temp_silence_pos < previous)
00643 {
00644 temp_silence_pos = LONG_MAX;
00645 }
00646
00647 append_error = splt_sp_append_splitpoint(state, temp_silence_pos, NULL, SPLT_SPLITPOINT);
00648 if (append_error != SPLT_OK) { *error = append_error; found = i; break; }
00649
00650 temp = temp->next;
00651
00652 previous = temp_silence_pos;
00653 }
00654
00655 end:
00656 splt_siu_ssplit_free(&state->silence_list);
00657 splt_t_set_splitnumber(state, found);
00658
00659 return found;
00660 }
00661
00662
00670 int splt_s_set_silence_splitpoints(splt_state *state, int *error)
00671 {
00672 splt_d_print_debug(state,"Search and set silence splitpoints...\n");
00673
00674 int found = 0;
00675 int splitpoints_appended = 0;
00676 struct splt_ssplit *temp = NULL;
00677 int append_error = SPLT_OK;
00678
00679 float offset = splt_o_get_float_option(state,SPLT_OPT_PARAM_OFFSET);
00680 int number_tracks = splt_o_get_int_option(state, SPLT_OPT_PARAM_NUMBER_TRACKS);
00681
00682 int we_read_silence_from_logs = SPLT_FALSE;
00683
00684 FILE *log_file = NULL;
00685 char *log_fname = splt_t_get_silence_log_fname(state);
00686 if (splt_o_get_int_option(state, SPLT_OPT_ENABLE_SILENCE_LOG))
00687 {
00688 if ((log_file = splt_io_fopen(log_fname, "r")))
00689 {
00690 char *log_silence_fname = splt_io_readline(log_file, error);
00691 if (*error < 0)
00692 {
00693 if (log_silence_fname)
00694 {
00695 free(log_silence_fname);
00696 log_silence_fname = NULL;
00697 }
00698 fclose(log_file);
00699 return found;
00700 }
00701
00702 if (log_silence_fname && log_silence_fname[0] != '\0')
00703 {
00704 log_silence_fname[strlen(log_silence_fname)-1] = '\0';
00705 if (strcmp(log_silence_fname, splt_t_get_filename_to_split(state)) == 0)
00706 {
00707 we_read_silence_from_logs = SPLT_TRUE;
00708 float threshold = SPLT_DEFAULT_PARAM_THRESHOLD;
00709 float min = SPLT_DEFAULT_PARAM_MINIMUM_LENGTH;
00710 int shots = SPLT_DEFAULT_PARAM_SHOTS;
00711 int i = fscanf(log_file, "%f\t%f\t%d", &threshold, &min, &shots);
00712
00713
00714 if (i == 2) { shots = SPLT_DEFAULT_PARAM_SHOTS; }
00715
00716 if ((i < 2) ||
00717 (threshold != splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD)) ||
00718 (splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH) != min) ||
00719 (splt_o_get_int_option(state, SPLT_OPT_PARAM_SHOTS) != shots))
00720 {
00721 we_read_silence_from_logs = SPLT_FALSE;
00722 }
00723 else
00724 {
00725 splt_o_set_float_option(state, SPLT_OPT_PARAM_THRESHOLD, threshold);
00726 splt_o_set_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH, min);
00727 splt_o_set_int_option(state, SPLT_OPT_PARAM_SHOTS, shots);
00728 }
00729 }
00730
00731 free(log_silence_fname);
00732 log_silence_fname = NULL;
00733 }
00734
00735 if (!we_read_silence_from_logs && log_file)
00736 {
00737 fclose(log_file);
00738 log_file = NULL;
00739 }
00740 }
00741 }
00742
00743 char remove_str[128] = { '\0' };
00744 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00745 {
00746 snprintf(remove_str,128,_("YES"));
00747 }
00748 else
00749 {
00750 snprintf(remove_str,128,_("NO"));
00751 }
00752
00753 char auto_user_str[128] = { '\0' };
00754 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_NUMBER_TRACKS) > 0)
00755 {
00756 snprintf(auto_user_str,128,_("User"));
00757 }
00758 else
00759 {
00760 snprintf(auto_user_str,128,_("Auto"));
00761 }
00762
00763 if (! splt_o_get_int_option(state,SPLT_OPT_QUIET_MODE))
00764 {
00765 splt_c_put_info_message_to_client(state,
00766 _(" Silence split type: %s mode (Th: %.1f dB,"
00767 " Off: %.2f, Min: %.2f, Remove: %s, Min track: %.2f, Shots: %d)\n"),
00768 auto_user_str,
00769 splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD),
00770 splt_o_get_float_option(state, SPLT_OPT_PARAM_OFFSET),
00771 splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH),
00772 remove_str,
00773 splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_TRACK_LENGTH),
00774 splt_o_get_int_option(state, SPLT_OPT_PARAM_SHOTS));
00775 }
00776
00777 short read_silence_from_logs = SPLT_FALSE;
00778 if (we_read_silence_from_logs)
00779 {
00780 if (state->split.get_silence_level)
00781 {
00782 state->split.get_silence_level(0, INT_MAX, state->split.silence_level_client_data);
00783 }
00784
00785 splt_c_put_info_message_to_client(state,
00786 _(" Found silence log file '%s' ! Reading"
00787 " silence points from file to save time ;)\n"), log_fname);
00788
00789 found = splt_siu_parse_ssplit_file(state, log_file, error);
00790 if (log_file)
00791 {
00792 fclose(log_file);
00793 log_file = NULL;
00794 }
00795
00796 read_silence_from_logs = SPLT_TRUE;
00797 }
00798 else
00799 {
00800 if (state->split.get_silence_level)
00801 {
00802 state->split.get_silence_level(0, INT_MAX, state->split.silence_level_client_data);
00803 }
00804 found = splt_p_scan_silence(state, error);
00805 }
00806
00807
00808 if (*error >= 0)
00809 {
00810 if (!read_silence_from_logs)
00811 {
00812 splt_c_put_info_message_to_client(state, "\n");
00813 }
00814
00815 splt_c_put_info_message_to_client(state, _(" Total silence points found: %d."), found);
00816
00817 if (found > 0)
00818 {
00819 int selected_tracks = found + 1;
00820 int param_number_of_tracks = splt_o_get_int_option(state, SPLT_OPT_PARAM_NUMBER_TRACKS);
00821 if (param_number_of_tracks > 0)
00822 {
00823 selected_tracks = param_number_of_tracks;
00824 }
00825
00826 splt_c_put_info_message_to_client(state,
00827 _(" (Selected %d tracks)\n"), selected_tracks);
00828 }
00829 else
00830 {
00831 splt_c_put_info_message_to_client(state, "\n");
00832 }
00833
00834
00835 if (!splt_t_split_is_canceled(state))
00836 {
00837 found++;
00838 if ((number_tracks > 0) &&
00839 (number_tracks < SPLT_MAXSILENCE))
00840 {
00841 if (number_tracks < found)
00842 {
00843 found = number_tracks;
00844 }
00845 }
00846
00847 temp = state->silence_list;
00848
00849 int i;
00850
00851
00852
00853 for (i = 1; i < found; i++)
00854 {
00855 if (temp == NULL)
00856 {
00857 found = i;
00858 break;
00859 }
00860
00861 long end_track_point = 0;
00862 long end_track_point_after_silence = 0;
00863 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00864 {
00865 end_track_point = splt_co_time_to_long(temp->begin_position);
00866 end_track_point_after_silence = splt_co_time_to_long(temp->end_position);
00867 }
00868 else
00869 {
00870 end_track_point = splt_co_time_to_long(splt_siu_silence_position(temp, offset));
00871 }
00872
00873 if (i == 1)
00874 {
00875 append_error = splt_sp_append_splitpoint(state, 0, NULL, SPLT_SPLITPOINT);
00876 if (append_error < 0) { *error = append_error; found = i; break;}
00877 }
00878
00879 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00880 {
00881 append_error = splt_sp_append_splitpoint(state, end_track_point, NULL, SPLT_SKIPPOINT);
00882 if (append_error < 0) { *error = append_error; found = i; break;}
00883 append_error =
00884 splt_sp_append_splitpoint(state, end_track_point_after_silence, NULL, SPLT_SPLITPOINT);
00885 if (append_error < 0) { *error = append_error; found = i; break;}
00886 }
00887 else
00888 {
00889 append_error = splt_sp_append_splitpoint(state, end_track_point, NULL, SPLT_SPLITPOINT);
00890 if (append_error != SPLT_OK) { *error = append_error; found = i; break; }
00891 }
00892
00893 temp = temp->next;
00894 }
00895
00896
00897 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00898 {
00899 splitpoints_appended = (found-1)*2+1;
00900 }
00901 else
00902 {
00903 splitpoints_appended = found;
00904 }
00905
00906 splt_d_print_debug(state,"Order splitpoints...\n");
00907 splt_sp_order_splitpoints(state, splitpoints_appended);
00908
00909 if (*error >= 0)
00910 {
00911 long total_time = splt_t_get_total_time(state);
00912 if (total_time <= 0)
00913 {
00914 total_time = LONG_MAX;
00915 }
00916
00917
00918 append_error =
00919 splt_sp_append_splitpoint(state, total_time, NULL, SPLT_SPLITPOINT);
00920 if (append_error != SPLT_OK) { *error = append_error; }
00921 }
00922
00923 splt_sp_skip_minimum_track_length_splitpoints(state, error);
00924 }
00925 else
00926 {
00927 *error = SPLT_SPLIT_CANCELLED;
00928 }
00929
00930
00931 if ((*error >= 0) && (found > 0) && !we_read_silence_from_logs)
00932 {
00933
00934 if (splt_o_get_int_option(state, SPLT_OPT_ENABLE_SILENCE_LOG))
00935 {
00936 splt_c_put_info_message_to_client(state,
00937 _(" Writing silence log file '%s' ...\n"),
00938 splt_t_get_silence_log_fname(state));
00939
00940 char *fname = splt_t_get_silence_log_fname(state);
00941 if (! splt_o_get_int_option(state, SPLT_OPT_PRETEND_TO_SPLIT))
00942 {
00943 FILE *log_file = NULL;
00944 if (!(log_file = splt_io_fopen(fname, "w")))
00945 {
00946 splt_e_set_strerror_msg_with_data(state, fname);
00947 *error = SPLT_ERROR_CANNOT_OPEN_FILE;
00948 }
00949 else
00950 {
00951
00952 struct splt_ssplit *temp = state->silence_list;
00953 fprintf(log_file, "%s\n", splt_t_get_filename_to_split(state));
00954 fprintf(log_file, "%.2f\t%.2f\t%d\n",
00955 splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD),
00956 splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH),
00957 splt_o_get_int_option(state, SPLT_OPT_PARAM_SHOTS));
00958 while (temp != NULL)
00959 {
00960 fprintf(log_file, "%f\t%f\t%ld\n",
00961 temp->begin_position, temp->end_position, temp->len);
00962 temp = temp->next;
00963 }
00964 fflush(log_file);
00965 if (log_file)
00966 {
00967 fclose(log_file);
00968 log_file = NULL;
00969 }
00970 temp = NULL;
00971 }
00972 }
00973 }
00974 }
00975 }
00976
00977 splt_siu_ssplit_free(&state->silence_list);
00978
00979 splt_t_set_splitnumber(state, splitpoints_appended + 1);
00980
00981 return found;
00982 }
00983
00988 void splt_s_silence_split(splt_state *state, int *error)
00989 {
00990 splt_d_print_debug(state,"Starting silence split ...\n");
00991
00992
00993 splt_c_put_info_message_to_client(state, _(" info: starting silence mode split\n"));
00994
00995 int found = splt_s_set_silence_splitpoints(state, error);
00996
00997
00998 if (*error >= 0)
00999 {
01000
01001 if (found > 1)
01002 {
01003 splt_d_print_debug(state,"Writing silence tracks...\n");
01004
01005
01006 int output_filenames = splt_o_get_int_option(state,SPLT_OPT_OUTPUT_FILENAMES);
01007 if (output_filenames == SPLT_OUTPUT_DEFAULT)
01008 {
01009 splt_of_set_oformat(state, SPLT_DEFAULT_SILENCE_OUTPUT, error, SPLT_TRUE);
01010 if (*error < 0) { return; }
01011 }
01012
01013 splt_s_multiple_split(state, error);
01014
01015
01016 switch (*error)
01017 {
01018 case SPLT_OK_SPLIT:
01019 *error = SPLT_SILENCE_OK;
01020 break;
01021 case SPLT_OK_SPLIT_EOF:
01022 *error = SPLT_SILENCE_OK;
01023 break;
01024 default:
01025 break;
01026 }
01027 }
01028 else
01029 {
01030 *error = SPLT_NO_SILENCE_SPLITPOINTS_FOUND;
01031 }
01032 }
01033 }
01034
01039 void splt_s_trim_silence_split(splt_state *state, int *error)
01040 {
01041 splt_c_put_info_message_to_client(state, _(" info: starting trim using silence mode split\n"));
01042
01043 int found = splt_s_set_trim_silence_splitpoints(state, error);
01044 if (*error < 0) { return; }
01045
01046 if (found < 1)
01047 {
01048 *error = SPLT_NO_SILENCE_SPLITPOINTS_FOUND;
01049 return;
01050 }
01051
01052 splt_d_print_debug(state,"Writing tracks...\n");
01053
01054 int output_filenames = splt_o_get_int_option(state,SPLT_OPT_OUTPUT_FILENAMES);
01055 if (output_filenames == SPLT_OUTPUT_DEFAULT)
01056 {
01057 splt_of_set_oformat(state, SPLT_DEFAULT_TRIM_SILENCE_OUTPUT, error, SPLT_TRUE);
01058 if (*error < 0) { return; }
01059 }
01060
01061 splt_s_multiple_split(state, error);
01062
01063 switch (*error)
01064 {
01065 case SPLT_OK_SPLIT:
01066 *error = SPLT_TRIM_SILENCE_OK;
01067 break;
01068 case SPLT_OK_SPLIT_EOF:
01069 *error = SPLT_TRIM_SILENCE_OK;
01070 break;
01071 default:
01072 break;
01073 }
01074 }
01075
01076
01081 void splt_s_wrap_split(splt_state *state, int *error)
01082 {
01083 char *new_filename_path = splt_t_get_new_filename_path(state);
01084 char *filename = splt_t_get_filename_to_split(state);
01085
01086 splt_d_print_debug(state,"Begin wrap split for the file _%s_\n", filename);
01087
01088 splt_c_put_info_message_to_client(state, _(" info: starting wrap mode split\n"));
01089
01090 splt_p_dewrap(state, SPLT_FALSE, new_filename_path, error);
01091 }
01092