static bool process_file(char *filename) { int i; wave_info *info; bool success; if (NULL == (info = new_wave_info(filename))) st_error("cannot continue due to error(s) shown above"); input_is_cd_quality = (PROB_NOT_CD(info) ? FALSE : TRUE); get_extractable_tracks(); if (repeated_split_point) read_split_points_repeated(info); else read_split_points_file(info); if (files[numfiles-2]->beginning_byte > info->data_size) st_error("split points go beyond input file's data size"); if (files[numfiles-2]->beginning_byte == info->data_size) { st_free(files[numfiles-1]); numfiles--; } else { files[numfiles-1]->beginning_byte = info->data_size; files[numfiles-1]->data_size = info->data_size - files[numfiles-2]->beginning_byte; adjust_splitfile(numfiles-1); } success = split_file(info); for (i=0;i<numfiles;i++) st_free(files[i]); st_free(info); return success; }
static void check_headers() { int i; bool ba_warned = 0; for (i=0;i<numfiles;i++) { if (PROB_NOT_CD(files[i])) all_files_cd_quality = FALSE; if (PROB_HDR_INCONSISTENT(files[i])) st_error("file has an inconsistent header: [%s]",files[i]->filename); if (PROB_TRUNCATED(files[i])) st_error("file seems to be truncated: [%s]",files[i]->filename); } for (i=1;i<numfiles;i++) { if (files[i]->wave_format != files[0]->wave_format) st_error("WAVE format differs among these files"); if (files[i]->channels != files[0]->channels) st_error("number of channels differs among these files"); if (files[i]->samples_per_sec != files[0]->samples_per_sec) st_error("samples per second differs among these files"); if (files[i]->avg_bytes_per_sec != files[0]->avg_bytes_per_sec) st_error("average bytes per second differs among these files"); if (files[i]->bits_per_sample != files[0]->bits_per_sample) st_error("bits per sample differs among these files"); if (files[i]->block_align != files[0]->block_align) { if (!ba_warned) { st_warning("block align differs among these files"); ba_warned = TRUE; } } } }
void shn_length_to_str(shn_file *info) /* converts length of file to a string in m:ss or m:ss.ff format */ { ulong newlength,rem1,rem2,frames,ms; double tmp; if (PROB_NOT_CD(info->wave_header)) { newlength = (ulong)info->wave_header.exact_length; tmp = info->wave_header.exact_length - (double)((ulong)info->wave_header.exact_length); ms = (ulong)((tmp * 1000.0) + 0.5); if (1000 == ms) { ms = 0; newlength++; } shn_snprintf(info->wave_header.m_ss,16,"%lu:%02lu.%03lu",newlength/60,newlength%60,ms); } else { newlength = info->wave_header.length; rem1 = info->wave_header.data_size % CD_RATE; rem2 = rem1 % CD_BLOCK_SIZE; frames = rem1 / CD_BLOCK_SIZE; if (rem2 >= (CD_BLOCK_SIZE / 2)) frames++; if (frames == CD_BLOCKS_PER_SEC) { frames = 0; newlength++; } shn_snprintf(info->wave_header.m_ss,16,"%lu:%02lu.%02lu",newlength/60,newlength%60,frames); } }
static bool process(int argc,char **argv,int start) { int i,j,remainder; bool needs_fixing = FALSE,found_errors = FALSE,success; char *filename; input_init(start,argc,argv); input_read_all_files(); numfiles = input_get_file_count(); if (numfiles < 1) st_help("need one or more files to process"); if (NULL == (files = malloc((numfiles + 1) * sizeof(wave_info *)))) st_error("could not allocate memory for file info array"); for (i=0;i<numfiles;i++) { filename = input_get_filename(); if (NULL == (files[i] = new_wave_info(filename))) { st_error("could not open file: [%s]",filename); } } files[numfiles] = NULL; /* validate files */ for (i=0;i<numfiles;i++) { if (PROB_NOT_CD(files[i])) { st_warning("file is not CD-quality: [%s]",files[i]->filename); found_errors = TRUE; } if (PROB_HDR_INCONSISTENT(files[i])) { st_warning("file has an inconsistent header: [%s]",files[i]->filename); found_errors = TRUE; } if (PROB_TRUNCATED(files[i])) { st_warning("file seems to be truncated: [%s]",files[i]->filename); found_errors = TRUE; } if (PROB_BAD_BOUND(files[i])) needs_fixing = TRUE; } if (found_errors) st_error("could not fix files due to errors, see above"); if (check_only) exit(needs_fixing ? ST_EXIT_SUCCESS : ST_EXIT_ERROR); if (!needs_fixing) st_error("everything seems fine, no need for fixing"); reorder_files(files,numfiles); i = 0; while (!PROB_BAD_BOUND(files[i])) i++; if (skip) { if (i != 0) { st_warning("skipping first %d file%s because %s would not be changed",i,(1==i)?"":"s",(1==i)?"it":"they"); for (j=0;j<i;j++) st_free(files[j]); for (j=i;j<numfiles;j++) { files[j-i] = files[j]; files[j] = NULL; } numfiles -= i; } } if (numfiles < 1) st_error("need one or more files to process"); switch (desired_shift) { case SHIFT_BACKWARD: calculate_breaks_backward(); break; case SHIFT_FORWARD: calculate_breaks_forward(); break; case SHIFT_ROUND: calculate_breaks_round(); break; } calculation_sanity_check(); remainder = files[numfiles-1]->new_data_size % CD_BLOCK_SIZE; if (remainder) pad_bytes = CD_BLOCK_SIZE - remainder; success = write_fixed_files(); for (i=0;i<numfiles;i++) st_free(files[i]); st_free(files); return success; }