void forget_temps(void) { int i; for (i = 0; i < tempfiles_size; i++) if ((tempfiles[i]) && (mus_file_probe(tempfiles[i]->name))) snd_remove(tempfiles[i]->name, REMOVE_FROM_CACHE); }
static void display_sound_file_entry(FILE *fp, const char *name, sound_file *sf) { #define TIME_BUFFER_SIZE 64 int i, lim; time_t date; char timestr[TIME_BUFFER_SIZE]; char *comment; date = sf->write_date; if (date != 0) strftime(timestr, TIME_BUFFER_SIZE, "%a %d-%b-%Y %H:%M:%S", localtime(&date)); else snprintf(timestr, TIME_BUFFER_SIZE, "(date cleared)"); fprintf(fp, " %s: %s, chans: %d, srate: %d, type: %s, format: %s, samps: %lld", name, timestr, sf->chans, sf->srate, mus_header_type_name(sf->header_type), mus_data_format_name(sf->data_format), sf->samples); if (sf->loop_modes) { if (sf->loop_modes[0] != 0) fprintf(fp, ", loop mode %d: %d to %d", sf->loop_modes[0], sf->loop_starts[0], sf->loop_ends[0]); if (sf->loop_modes[1] != 0) fprintf(fp, ", loop mode %d: %d to %d, ", sf->loop_modes[1], sf->loop_starts[1], sf->loop_ends[1]); fprintf(fp, ", base: %d, detune: %d", sf->base_note, sf->base_detune); } if (sf->maxamps) { lim = sf->maxamps_size; if (lim > 0) { if (lim > 64) lim = 64; for (i = 0; i < lim; i++) { if (i > 1) fprintf(fp, ", "); fprintf(fp, " %.3f at %.3f ", sf->maxamps[i], (sf->srate > 0) ? (float)((double)(sf->maxtimes[i]) / (double)(sf->srate)) : (float)(sf->maxtimes[i])); } } } if (mus_file_probe(name)) { comment = mus_sound_comment(name); if (comment) { fprintf(fp, "\n comment: %s", comment); free(comment); } } else fprintf(fp, " [defunct]"); fprintf(fp, "\n"); }
int mus_sound_open_input(const char *arg) { int fd = -1; if (!(mus_file_probe(arg))) mus_error(MUS_CANT_OPEN_FILE, "mus_sound_open_input: can't open %s: %s", arg, STRERROR(errno)); else { sound_file *sf = NULL; mus_sound_initialize(); sf = get_sf(arg); if (sf) { fd = mus_file_open_read(arg); if (fd == -1) mus_error(MUS_CANT_OPEN_FILE, "mus_sound_open_input: can't open %s: %s", arg, STRERROR(errno)); else { mus_file_open_descriptors(fd, arg, sf->sample_type, sf->datum_size, sf->data_location, sf->chans, sf->header_type); lseek(fd, sf->data_location, SEEK_SET); if (sf->saved_data) mus_file_save_data(fd, sf->samples / sf->chans, sf->saved_data); } } } return(fd); }
static Xen g_file_to_array(Xen filename, Xen chan, Xen start, Xen samples, Xen data) { #define H_file_to_array "(" S_file_to_array " filename chan start samples data): read the sound file \ 'filename' placing samples from channel 'chan' into the " S_vct " 'data' starting in the file \ at frample 'start' and reading 'samples' samples altogether." int chn, chans; mus_long_t samps; vct *v; const char *name = NULL; Xen_check_type(Xen_is_string(filename), filename, 1, S_file_to_array, "a string"); Xen_check_type(Xen_is_integer(chan), chan, 2, S_file_to_array, "an integer"); Xen_check_type(Xen_is_llong(start), start, 3, S_file_to_array, "an integer"); Xen_check_type(Xen_is_llong(samples), samples, 4, S_file_to_array, "an integer"); Xen_check_type((mus_is_vct(data)), data, 5, S_file_to_array, "a " S_vct); name = Xen_string_to_C_string(filename); if (!(mus_file_probe(name))) Xen_error(NO_SUCH_FILE, Xen_list_3(C_string_to_Xen_string(S_file_to_array ": ~S ~A"), filename, C_string_to_Xen_string(STRERROR(errno)))); v = Xen_to_vct(data); samps = Xen_llong_to_C_llong(samples); if (samps <= 0) Xen_out_of_range_error(S_file_to_array, 4, samples, "samples <= 0?"); if (samps > mus_vct_length(v)) samps = mus_vct_length(v); chn = Xen_integer_to_C_int(chan); chans = mus_sound_chans(name); if ((chn < 0) || (chn > chans)) Xen_error(NO_SUCH_CHANNEL, Xen_list_4(C_string_to_Xen_string(S_file_to_array ": invalid chan: ~A, ~S has ~A chans"), chan, filename, C_int_to_Xen_integer(chans))); if (chans <= 0) Xen_error(BAD_HEADER, Xen_list_2(C_string_to_Xen_string(S_file_to_array ": ~S chans <= 0"), filename)); mus_file_to_float_array(name, chn, Xen_llong_to_C_llong(start), samps, mus_vct_data(v)); return(data); }
int mus_sound_prune(void) { int i, pruned = 0; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (!(mus_file_probe(sound_table[i]->file_name)))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; pruned++; } return(pruned); }
int mus_sound_prune(void) { int j, pruned = 0; for (j = 0; j < NUM_SOUND_TABLES; j++) { int i, sound_table_size; sound_file **sound_table; sound_table = sound_tables[j]; sound_table_size = sound_table_sizes[j]; for (i = 0; i < sound_table_size; i++) if ((sound_table[i]) && (!(mus_file_probe(sound_table[i]->file_name)))) { free_sound_file(sound_table[i]); sound_table[i] = NULL; pruned++; } } return(pruned); }
int main(int argc, char *argv[]) { int chans, srate, ctr; mus_sample_t samp_type; mus_header_t type; mus_long_t samples; float length = 0.0; time_t date; int *loops = NULL; char *comment, *header_name; char *samp_type_info = NULL, *samp_type_name, *ampstr = NULL; char timestr[64]; if (argc == 1) {printf("usage: sndinfo file\n"); exit(0);} mus_sound_initialize(); for (ctr = 1; ctr < argc; ctr++) { if (mus_file_probe(argv[ctr])) /* see if it exists */ { date = mus_sound_write_date(argv[ctr]); srate = mus_sound_srate(argv[ctr]); if (srate == MUS_ERROR) { fprintf(stdout, "%s: not a sound file?\n", argv[ctr]); continue; } chans = mus_sound_chans(argv[ctr]); samples = mus_sound_samples(argv[ctr]); comment = mus_sound_comment(argv[ctr]); if ((chans > 0) && (srate > 0)) length = (float)((double)samples / (double)(chans * srate)); loops = mus_sound_loop_info(argv[ctr]); type = mus_sound_header_type(argv[ctr]); header_name = (char *)mus_header_type_name(type); samp_type = mus_sound_sample_type(argv[ctr]); if (samp_type != MUS_UNKNOWN_SAMPLE) samp_type_info = (char *)mus_sample_type_name(samp_type); else { int orig_type; if (samp_type_info == NULL) samp_type_info = (char *)calloc(64, sizeof(char)); orig_type = mus_sound_original_sample_type(argv[ctr]); samp_type_name = (char *)mus_header_original_sample_type_name(orig_type, type); if (samp_type_name) snprintf(samp_type_info, 64, "%d (%s)", orig_type, samp_type_name); else snprintf(samp_type_info, 64, "%d", orig_type); } fprintf(stdout, "%s:\n srate: %d\n chans: %d\n length: %f", argv[ctr], srate, chans, length); if (length < 10.0) { int samps; samps = mus_sound_framples(argv[ctr]); fprintf(stdout, " (%d sample%s)", samps, (samps != 1) ? "s" : ""); } fprintf(stdout, "\n"); fprintf(stdout, " header type: %s\n sample type: %s\n ", header_name, samp_type_info); strftime(timestr, 64, "%a %d-%b-%Y %H:%M %Z", localtime(&date)); fprintf(stdout, "written: %s", timestr); if ((chans > 0) && (mus_sound_maxamp_exists(argv[ctr]))) { ampstr = display_maxamps(argv[ctr], chans); if (ampstr) fprintf(stdout, "%s", ampstr); } fprintf(stdout, "\n"); if (comment) fprintf(stdout, " comment: %s\n", comment); if (loops) { fprintf(stdout, " loop: %d to %d\n", loops[0], loops[1]); if (loops[2] != 0) fprintf(stdout, " loop: %d to %d\n", loops[2], loops[3]); if (loops[0] != 0) fprintf(stdout, " base: %d, detune: %d\n", loops[4], loops[5]); } } else fprintf(stderr, "%s: %s\n", argv[ctr], strerror(errno)); if (ctr < argc - 1) fprintf(stdout, "\n"); } return(0); }