static void getfileinfo(char *filename, char *title, int *length_in_msec) { FLAC__StreamMetadata streaminfo; if (!filename || !*filename) { filename = lastfn_; if (length_in_msec) { *length_in_msec = stream_data_.length_in_msec; length_in_msec = 0; /* force skip in following code */ } } if (!FLAC__metadata_get_streaminfo(filename, &streaminfo)) { if (length_in_msec) *length_in_msec = -1; return; } if (title) { static WCHAR buffer[400]; format_title(filename, buffer, 400); WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, buffer, -1, title, 400, NULL, NULL); } if (length_in_msec) { /* with VC++ you have to spoon feed it the casting from uint64->int64->double */ FLAC__uint64 l = (FLAC__uint64)((double)(FLAC__int64)streaminfo.data.stream_info.total_samples / (double)streaminfo.data.stream_info.sample_rate * 1000.0 + 0.5); if (l > INT_MAX) l = INT_MAX; *length_in_msec = (int)l; } }
int FlacPcm::getInfos(MediaInfo *infos) { reader = infos->getReader(); if(!reader) return 0; //@@@ to be really "clean" we should go through the reader instead of directly to the file... if(!FLAC__metadata_get_streaminfo(infos->getFilename(), &streaminfo)) return 1; id3v1_struct tag; bool has_tag = get_id3v1_tag_(infos->getFilename(), &tag); infos->setLength(lengthInMsec()); //@@@ infos->setTitle(Std::filename(infos->getFilename())); infos->setTitle(tag.description); infos->setInfo(StringPrintf("FLAC:<%ihz:%ibps:%dch>", streaminfo.data.stream_info.sample_rate, streaminfo.data.stream_info.bits_per_sample, streaminfo.data.stream_info.channels)); //@@@ fix later if(has_tag) { infos->setData("Title", tag.title); infos->setData("Artist", tag.artist); infos->setData("Album", tag.album); } return 0; }
void getfileinfo(char *filename, char *title, int *length_in_msec) { FLAC__StreamMetadata streaminfo; if(0 == filename || filename[0] == '\0') { filename = lastfn_; if(length_in_msec) { *length_in_msec = getlength(); length_in_msec = 0; /* force skip in following code */ } } if(!FLAC__metadata_get_streaminfo(filename, &streaminfo)) { MessageBox(mod_.hMainWindow, filename, "ERROR: invalid/missing FLAC metadata", 0); if(title) { static const char *errtitle = "Invalid FLAC File: "; sprintf(title, "%s\"%s\"", errtitle, filename); } if(length_in_msec) *length_in_msec = -1; return; } if(title) { get_description_(filename, title, MAX_PATH); } if(length_in_msec) *length_in_msec = (int)(streaminfo.data.stream_info.total_samples * 10 / (streaminfo.data.stream_info.sample_rate / 100)); }
int flacdecode_reg(struct xlplayer *xlplayer) { struct flacdecode_vars *self; if (!(self = xlplayer->dec_data = malloc(sizeof (struct flacdecode_vars)))) { fprintf(stderr, "flacdecode_reg: malloc failure\n"); return REJECTED; } if (FLAC__metadata_get_streaminfo(xlplayer->pathname, &(self->metainfo))) { xlplayer->dec_init = flacdecode_init; xlplayer->dec_play = flacdecode_play; xlplayer->dec_eject = flacdecode_eject; return ACCEPTED; } return REJECTED; }
static void show_file_info(void) { FLAC__StreamMetadata streaminfo; struct stat _stat; gtk_label_set_text(GTK_LABEL(flac_samplerate), ""); gtk_label_set_text(GTK_LABEL(flac_channels), ""); gtk_label_set_text(GTK_LABEL(flac_bits_per_sample), ""); gtk_label_set_text(GTK_LABEL(flac_blocksize), ""); gtk_label_set_text(GTK_LABEL(flac_filesize), ""); gtk_label_set_text(GTK_LABEL(flac_samples), ""); gtk_label_set_text(GTK_LABEL(flac_bitrate), ""); if(!FLAC__metadata_get_streaminfo(current_filename, &streaminfo)) { return; } label_set_text(flac_samplerate, _("Samplerate: %d Hz"), streaminfo.data.stream_info.sample_rate); label_set_text(flac_channels, _("Channels: %d"), streaminfo.data.stream_info.channels); label_set_text(flac_bits_per_sample, _("Bits/Sample: %d"), streaminfo.data.stream_info.bits_per_sample); if(streaminfo.data.stream_info.min_blocksize == streaminfo.data.stream_info.max_blocksize) label_set_text(flac_blocksize, _("Blocksize: %d"), streaminfo.data.stream_info.min_blocksize); else label_set_text(flac_blocksize, _("Blocksize: variable\n min/max: %d/%d"), streaminfo.data.stream_info.min_blocksize, streaminfo.data.stream_info.max_blocksize); if (streaminfo.data.stream_info.total_samples) label_set_text(flac_samples, _("Samples: %llu\nLength: %d:%.2d"), streaminfo.data.stream_info.total_samples, (int)(streaminfo.data.stream_info.total_samples / streaminfo.data.stream_info.sample_rate / 60), (int)(streaminfo.data.stream_info.total_samples / streaminfo.data.stream_info.sample_rate % 60)); if(!stat(current_filename, &_stat) && S_ISREG(_stat.st_mode)) { #if _FILE_OFFSET_BITS == 64 label_set_text(flac_filesize, _("Filesize: %lld B"), _stat.st_size); #else label_set_text(flac_filesize, _("Filesize: %ld B"), _stat.st_size); #endif if (streaminfo.data.stream_info.total_samples) label_set_text(flac_bitrate, _("Avg. bitrate: %.1f kb/s\nCompression ratio: %.1f%%"), 8.0 * (float)(_stat.st_size) / (1000.0 * (float)streaminfo.data.stream_info.total_samples / (float)streaminfo.data.stream_info.sample_rate), 100.0 * (float)_stat.st_size / (float)(streaminfo.data.stream_info.bits_per_sample / 8 * streaminfo.data.stream_info.channels * streaminfo.data.stream_info.total_samples)); } }
void FLAC_XMMS__get_song_info(char *filename, char **title, int *length_in_msec) { FLAC__StreamMetadata streaminfo; if(0 == filename) filename = ""; if(!FLAC__metadata_get_streaminfo(filename, &streaminfo)) { /* @@@ how to report the error? */ if(title) { if (!is_http_source(filename)) { static const char *errtitle = "Invalid FLAC File: "; if(strlen(errtitle) + 1 + strlen(filename) + 1 + 1 < strlen(filename)) { /* overflow check */ *title = NULL; } else { *title = g_malloc(strlen(errtitle) + 1 + strlen(filename) + 1 + 1); sprintf(*title, "%s\"%s\"", errtitle, filename); } } else { *title = NULL; } } if(length_in_msec) *length_in_msec = -1; return; } if(title) { *title = flac_format_song_title(filename); } if(length_in_msec) { FLAC__uint64 l = (FLAC__uint64)((double)streaminfo.data.stream_info.total_samples / (double)streaminfo.data.stream_info.sample_rate * 1000.0 + 0.5); if (l > INT_MAX) l = INT_MAX; *length_in_msec = (int)l; } }
FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime) { FLAC__StreamMetadata streaminfo; float *title_gains = 0, *title_peaks = 0; float album_gain, album_peak; unsigned sample_rate = 0; unsigned bits_per_sample = 0; unsigned channels = 0; unsigned i; const char *error; FLAC__bool first = true; FLAC__ASSERT(num_files > 0); for(i = 0; i < num_files; i++) { FLAC__ASSERT(0 != filenames[i]); if(!FLAC__metadata_get_streaminfo(filenames[i], &streaminfo)) { fprintf(stderr, "%s: ERROR: can't open file or get STREAMINFO block\n", filenames[i]); return false; } if(first) { first = false; sample_rate = streaminfo.data.stream_info.sample_rate; bits_per_sample = streaminfo.data.stream_info.bits_per_sample; channels = streaminfo.data.stream_info.channels; } else { if(sample_rate != streaminfo.data.stream_info.sample_rate) { fprintf(stderr, "%s: ERROR: sample rate of %u Hz does not match previous files' %u Hz\n", filenames[i], streaminfo.data.stream_info.sample_rate, sample_rate); return false; } if(bits_per_sample != streaminfo.data.stream_info.bits_per_sample) { fprintf(stderr, "%s: ERROR: resolution of %u bps does not match previous files' %u bps\n", filenames[i], streaminfo.data.stream_info.bits_per_sample, bits_per_sample); return false; } if(channels != streaminfo.data.stream_info.channels) { fprintf(stderr, "%s: ERROR: # channels (%u) does not match previous files' (%u)\n", filenames[i], streaminfo.data.stream_info.channels, channels); return false; } } if(!grabbag__replaygain_is_valid_sample_frequency(sample_rate)) { fprintf(stderr, "%s: ERROR: sample rate of %u Hz is not supported\n", filenames[i], sample_rate); return false; } if(channels != 1 && channels != 2) { fprintf(stderr, "%s: ERROR: # of channels (%u) is not supported, must be 1 or 2\n", filenames[i], channels); return false; } } FLAC__ASSERT(bits_per_sample >= FLAC__MIN_BITS_PER_SAMPLE && bits_per_sample <= FLAC__MAX_BITS_PER_SAMPLE); if(!grabbag__replaygain_init(sample_rate)) { FLAC__ASSERT(0); /* double protection */ fprintf(stderr, "internal error\n"); return false; } if( 0 == (title_gains = (float*)malloc(sizeof(float) * num_files)) || 0 == (title_peaks = (float*)malloc(sizeof(float) * num_files)) ) die("out of memory allocating space for title gains/peaks"); for(i = 0; i < num_files; i++) { if(0 != (error = grabbag__replaygain_analyze_file(filenames[i], title_gains+i, title_peaks+i))) { fprintf(stderr, "%s: ERROR: during analysis (%s)\n", filenames[i], error); free(title_gains); free(title_peaks); return false; } } grabbag__replaygain_get_album(&album_gain, &album_peak); for(i = 0; i < num_files; i++) { if(0 != (error = grabbag__replaygain_store_to_file(filenames[i], album_gain, album_peak, title_gains[i], title_peaks[i], preserve_modtime))) { fprintf(stderr, "%s: ERROR: writing tags (%s)\n", filenames[i], error); free(title_gains); free(title_peaks); return false; } } free(title_gains); free(title_peaks); return true; }