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 i = fscanf(log_file, "%f\t%f", &threshold, &min);
00711
00712 if ((i < 2) || (threshold != splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD))
00713 || (splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH) != min))
00714 {
00715 we_read_silence_from_logs = SPLT_FALSE;
00716 }
00717 else
00718 {
00719 splt_o_set_float_option(state, SPLT_OPT_PARAM_THRESHOLD, threshold);
00720 splt_o_set_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH, min);
00721 }
00722 }
00723
00724 free(log_silence_fname);
00725 log_silence_fname = NULL;
00726 }
00727
00728 if (!we_read_silence_from_logs && log_file)
00729 {
00730 fclose(log_file);
00731 log_file = NULL;
00732 }
00733 }
00734 }
00735
00736 char remove_str[128] = { '\0' };
00737 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00738 {
00739 snprintf(remove_str,128,_("YES"));
00740 }
00741 else
00742 {
00743 snprintf(remove_str,128,_("NO"));
00744 }
00745
00746 char auto_user_str[128] = { '\0' };
00747 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_NUMBER_TRACKS) > 0)
00748 {
00749 snprintf(auto_user_str,128,_("User"));
00750 }
00751 else
00752 {
00753 snprintf(auto_user_str,128,_("Auto"));
00754 }
00755
00756 if (! splt_o_get_int_option(state,SPLT_OPT_QUIET_MODE))
00757 {
00758 splt_c_put_info_message_to_client(state,
00759 _(" Silence split type: %s mode (Th: %.1f dB,"
00760 " Off: %.2f, Min: %.2f, Remove: %s, Min track: %.2f)\n"),
00761 auto_user_str,
00762 splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD),
00763 splt_o_get_float_option(state, SPLT_OPT_PARAM_OFFSET),
00764 splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH),
00765 remove_str,
00766 splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_TRACK_LENGTH));
00767 }
00768
00769 short read_silence_from_logs = SPLT_FALSE;
00770 if (we_read_silence_from_logs)
00771 {
00772 if (state->split.get_silence_level)
00773 {
00774 state->split.get_silence_level(0, INT_MAX, state->split.silence_level_client_data);
00775 }
00776
00777 splt_c_put_info_message_to_client(state,
00778 _(" Found silence log file '%s' ! Reading"
00779 " silence points from file to save time ;)\n"), log_fname);
00780
00781 found = splt_siu_parse_ssplit_file(state, log_file, error);
00782 if (log_file)
00783 {
00784 fclose(log_file);
00785 log_file = NULL;
00786 }
00787
00788 read_silence_from_logs = SPLT_TRUE;
00789 }
00790 else
00791 {
00792 if (state->split.get_silence_level)
00793 {
00794 state->split.get_silence_level(0, INT_MAX, state->split.silence_level_client_data);
00795 }
00796 found = splt_p_scan_silence(state, error);
00797 }
00798
00799
00800 if (*error >= 0)
00801 {
00802 if (!read_silence_from_logs)
00803 {
00804 splt_c_put_info_message_to_client(state, "\n");
00805 }
00806
00807 splt_c_put_info_message_to_client(state, _(" Total silence points found: %d."), found);
00808
00809 if (found > 0)
00810 {
00811 int selected_tracks = found + 1;
00812 int param_number_of_tracks = splt_o_get_int_option(state, SPLT_OPT_PARAM_NUMBER_TRACKS);
00813 if (param_number_of_tracks > 0)
00814 {
00815 selected_tracks = param_number_of_tracks;
00816 }
00817
00818 splt_c_put_info_message_to_client(state,
00819 _(" (Selected %d tracks)\n"), selected_tracks);
00820 }
00821 else
00822 {
00823 splt_c_put_info_message_to_client(state, "\n");
00824 }
00825
00826
00827 if (!splt_t_split_is_canceled(state))
00828 {
00829 found++;
00830 if ((number_tracks > 0) &&
00831 (number_tracks < SPLT_MAXSILENCE))
00832 {
00833 if (number_tracks < found)
00834 {
00835 found = number_tracks;
00836 }
00837 }
00838
00839 temp = state->silence_list;
00840
00841 int i;
00842
00843
00844
00845 for (i = 1; i < found; i++)
00846 {
00847 if (temp == NULL)
00848 {
00849 found = i;
00850 break;
00851 }
00852
00853 long end_track_point = 0;
00854 long end_track_point_after_silence = 0;
00855 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00856 {
00857 end_track_point = splt_co_time_to_long(temp->begin_position);
00858 end_track_point_after_silence = splt_co_time_to_long(temp->end_position);
00859 }
00860 else
00861 {
00862 end_track_point = splt_co_time_to_long(splt_siu_silence_position(temp, offset));
00863 }
00864
00865 if (i == 1)
00866 {
00867 append_error = splt_sp_append_splitpoint(state, 0, NULL, SPLT_SPLITPOINT);
00868 if (append_error < 0) { *error = append_error; found = i; break;}
00869 }
00870
00871 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00872 {
00873 append_error = splt_sp_append_splitpoint(state, end_track_point, NULL, SPLT_SKIPPOINT);
00874 if (append_error < 0) { *error = append_error; found = i; break;}
00875 append_error =
00876 splt_sp_append_splitpoint(state, end_track_point_after_silence, NULL, SPLT_SPLITPOINT);
00877 if (append_error < 0) { *error = append_error; found = i; break;}
00878 }
00879 else
00880 {
00881 append_error = splt_sp_append_splitpoint(state, end_track_point, NULL, SPLT_SPLITPOINT);
00882 if (append_error != SPLT_OK) { *error = append_error; found = i; break; }
00883 }
00884
00885 temp = temp->next;
00886 }
00887
00888
00889 if (splt_o_get_int_option(state, SPLT_OPT_PARAM_REMOVE_SILENCE))
00890 {
00891 splitpoints_appended = (found-1)*2+1;
00892 }
00893 else
00894 {
00895 splitpoints_appended = found;
00896 }
00897
00898 splt_d_print_debug(state,"Order splitpoints...\n");
00899 splt_sp_order_splitpoints(state, splitpoints_appended);
00900
00901 if (*error >= 0)
00902 {
00903 long total_time = splt_t_get_total_time(state);
00904 if (total_time <= 0)
00905 {
00906 total_time = LONG_MAX;
00907 }
00908
00909
00910 append_error =
00911 splt_sp_append_splitpoint(state, total_time, NULL, SPLT_SPLITPOINT);
00912 if (append_error != SPLT_OK) { *error = append_error; }
00913 }
00914
00915 splt_sp_skip_minimum_track_length_splitpoints(state, error);
00916 }
00917 else
00918 {
00919 *error = SPLT_SPLIT_CANCELLED;
00920 }
00921
00922
00923 if ((*error >= 0) && (found > 0) && !we_read_silence_from_logs)
00924 {
00925
00926 if (splt_o_get_int_option(state, SPLT_OPT_ENABLE_SILENCE_LOG))
00927 {
00928 splt_c_put_info_message_to_client(state,
00929 _(" Writing silence log file '%s' ...\n"),
00930 splt_t_get_silence_log_fname(state));
00931
00932 char *fname = splt_t_get_silence_log_fname(state);
00933 if (! splt_o_get_int_option(state, SPLT_OPT_PRETEND_TO_SPLIT))
00934 {
00935 FILE *log_file = NULL;
00936 if (!(log_file = splt_io_fopen(fname, "w")))
00937 {
00938 splt_e_set_strerror_msg_with_data(state, fname);
00939 *error = SPLT_ERROR_CANNOT_OPEN_FILE;
00940 }
00941 else
00942 {
00943
00944 struct splt_ssplit *temp = state->silence_list;
00945 fprintf(log_file, "%s\n", splt_t_get_filename_to_split(state));
00946 fprintf(log_file, "%.2f\t%.2f\n",
00947 splt_o_get_float_option(state, SPLT_OPT_PARAM_THRESHOLD),
00948 splt_o_get_float_option(state, SPLT_OPT_PARAM_MIN_LENGTH));
00949 while (temp != NULL)
00950 {
00951 fprintf(log_file, "%f\t%f\t%ld\n",
00952 temp->begin_position, temp->end_position, temp->len);
00953 temp = temp->next;
00954 }
00955 fflush(log_file);
00956 if (log_file)
00957 {
00958 fclose(log_file);
00959 log_file = NULL;
00960 }
00961 temp = NULL;
00962 }
00963 }
00964 }
00965 }
00966 }
00967
00968 splt_siu_ssplit_free(&state->silence_list);
00969
00970 splt_t_set_splitnumber(state, splitpoints_appended + 1);
00971
00972 return found;
00973 }
00974
00979 void splt_s_silence_split(splt_state *state, int *error)
00980 {
00981 splt_d_print_debug(state,"Starting silence split ...\n");
00982
00983
00984 splt_c_put_info_message_to_client(state, _(" info: starting silence mode split\n"));
00985
00986 int found = splt_s_set_silence_splitpoints(state, error);
00987
00988
00989 if (*error >= 0)
00990 {
00991
00992 if (found > 1)
00993 {
00994 splt_d_print_debug(state,"Writing silence tracks...\n");
00995
00996
00997 int output_filenames = splt_o_get_int_option(state,SPLT_OPT_OUTPUT_FILENAMES);
00998 if (output_filenames == SPLT_OUTPUT_DEFAULT)
00999 {
01000 splt_of_set_oformat(state, SPLT_DEFAULT_SILENCE_OUTPUT, error, SPLT_TRUE);
01001 if (*error < 0) { return; }
01002 }
01003
01004 splt_s_multiple_split(state, error);
01005
01006
01007 switch (*error)
01008 {
01009 case SPLT_OK_SPLIT:
01010 *error = SPLT_SILENCE_OK;
01011 break;
01012 case SPLT_OK_SPLIT_EOF:
01013 *error = SPLT_SILENCE_OK;
01014 break;
01015 default:
01016 break;
01017 }
01018 }
01019 else
01020 {
01021 *error = SPLT_NO_SILENCE_SPLITPOINTS_FOUND;
01022 }
01023 }
01024 }
01025
01030 void splt_s_trim_silence_split(splt_state *state, int *error)
01031 {
01032 splt_c_put_info_message_to_client(state, _(" info: starting trim using silence mode split\n"));
01033
01034 int found = splt_s_set_trim_silence_splitpoints(state, error);
01035 if (*error < 0) { return; }
01036
01037 if (found < 1)
01038 {
01039 *error = SPLT_NO_SILENCE_SPLITPOINTS_FOUND;
01040 return;
01041 }
01042
01043 splt_d_print_debug(state,"Writing tracks...\n");
01044
01045 int output_filenames = splt_o_get_int_option(state,SPLT_OPT_OUTPUT_FILENAMES);
01046 if (output_filenames == SPLT_OUTPUT_DEFAULT)
01047 {
01048 splt_of_set_oformat(state, SPLT_DEFAULT_TRIM_SILENCE_OUTPUT, error, SPLT_TRUE);
01049 if (*error < 0) { return; }
01050 }
01051
01052 splt_s_multiple_split(state, error);
01053
01054 switch (*error)
01055 {
01056 case SPLT_OK_SPLIT:
01057 *error = SPLT_TRIM_SILENCE_OK;
01058 break;
01059 case SPLT_OK_SPLIT_EOF:
01060 *error = SPLT_TRIM_SILENCE_OK;
01061 break;
01062 default:
01063 break;
01064 }
01065 }
01066
01067
01072 void splt_s_wrap_split(splt_state *state, int *error)
01073 {
01074 char *new_filename_path = splt_t_get_new_filename_path(state);
01075 char *filename = splt_t_get_filename_to_split(state);
01076
01077 splt_d_print_debug(state,"Begin wrap split for the file _%s_\n", filename);
01078
01079 splt_c_put_info_message_to_client(state, _(" info: starting wrap mode split\n"));
01080
01081 splt_p_dewrap(state, SPLT_FALSE, new_filename_path, error);
01082 }
01083