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"); }
static Xen g_mus_sound_comment(Xen gfilename) { #define H_mus_sound_comment "(" S_mus_sound_comment " filename): comment (a string) found in sound file's header" char *res = NULL, *str = NULL; Xen newstr; Xen_check_type(Xen_is_string(gfilename), gfilename, 1, S_mus_sound_comment, "a string"); res = mus_sound_comment(str = mus_expand_filename(Xen_string_to_C_string(gfilename))); if (str) free(str); newstr = C_string_to_Xen_string(res); if (res) free(res); return(newstr); }
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); }