static void metadata_callback(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) { file_info_struct *file_info = (file_info_struct*)client_data; (void)decoder; if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { FLAC__ASSERT(metadata->data.stream_info.total_samples < 0x100000000); /* this plugin can only handle < 4 gigasamples */ file_info->total_samples = (unsigned)(metadata->data.stream_info.total_samples&0xfffffffful); file_info->bits_per_sample = metadata->data.stream_info.bits_per_sample; file_info->channels = metadata->data.stream_info.channels; file_info->sample_rate = metadata->data.stream_info.sample_rate; if (file_info->bits_per_sample!=8 && file_info->bits_per_sample!=16 && file_info->bits_per_sample!=24) { FLAC_plugin__show_error("This plugin can only handle 8/16/24-bit samples."); file_info->abort_flag = true; return; } file_info->length_in_msec = (unsigned)((double)file_info->total_samples / (double)file_info->sample_rate * 1000.0 + 0.5); } else if (metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { double gain, peak; if (grabbag__replaygain_load_from_vorbiscomment(metadata, cfg.replaygain.album_mode, &gain, &peak)) { file_info->has_replaygain = true; file_info->replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)cfg.replaygain.preamp, !cfg.replaygain.hard_limit); } } }
FLAC__bool FLAC_plugin__replaygain_get_from_file(const char *filename, double *reference, FLAC__bool *reference_set, double *track_gain, FLAC__bool *track_gain_set, double *album_gain, FLAC__bool *album_gain_set, double *track_peak, FLAC__bool *track_peak_set, double *album_peak, FLAC__bool *album_peak_set) { FLAC__Metadata_SimpleIterator *iterator = FLAC__metadata_simple_iterator_new(); FLAC__bool ret = false; *track_gain_set = *album_gain_set = *track_peak_set = *album_peak_set = false; if(0 != iterator) { if(FLAC__metadata_simple_iterator_init(iterator, filename, /*read_only=*/true, /*preserve_file_stats=*/true)) { FLAC__bool got_vorbis_comments = false; ret = true; do { if(FLAC__metadata_simple_iterator_get_block_type(iterator) == FLAC__METADATA_TYPE_VORBIS_COMMENT) { FLAC__StreamMetadata *block = FLAC__metadata_simple_iterator_get_block(iterator); if(0 != block) { if(grabbag__replaygain_load_from_vorbiscomment(block, /*album_mode=*/false, /*strict=*/true, reference, track_gain, track_peak)) { *reference_set = *track_gain_set = *track_peak_set = true; } if(grabbag__replaygain_load_from_vorbiscomment(block, /*album_mode=*/true, /*strict=*/true, reference, album_gain, album_peak)) { *reference_set = *album_gain_set = *album_peak_set = true; } FLAC__metadata_object_delete(block); got_vorbis_comments = true; } } } while (!got_vorbis_comments && FLAC__metadata_simple_iterator_next(iterator)); } FLAC__metadata_simple_iterator_delete(iterator); } return ret; }
static void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) { stream_data_struct *stream_data = (stream_data_struct*)client_data; (void)decoder; if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { stream_data->total_samples = metadata->data.stream_info.total_samples; stream_data->bits_per_sample = metadata->data.stream_info.bits_per_sample; stream_data->channels = metadata->data.stream_info.channels; stream_data->sample_rate = metadata->data.stream_info.sample_rate; if (stream_data->bits_per_sample!=8 && stream_data->bits_per_sample!=16 && stream_data->bits_per_sample!=24) { FLAC_plugin__show_error("This plugin can only handle 8/16/24-bit samples."); stream_data->abort_flag = true; return; } { /* with VC++ you have to spoon feed it the casting from uint64->int64->double */ FLAC__uint64 l = (FLAC__uint64)((double)(FLAC__int64)stream_data->total_samples / (double)stream_data->sample_rate * 1000.0 + 0.5); if (l > INT_MAX) l = INT_MAX; stream_data->length_in_msec = (int)l; } } else if (metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { double reference, gain, peak; if (grabbag__replaygain_load_from_vorbiscomment(metadata, cfg.replaygain.album_mode, /*strict=*/false, &reference, &gain, &peak)) { stream_data->has_replaygain = true; stream_data->replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)cfg.replaygain.preamp, !cfg.replaygain.hard_limit); } } }
void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) { stream_data_struct *stream_data = (stream_data_struct *)client_data; (void)decoder; if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { stream_data->total_samples = metadata->data.stream_info.total_samples; stream_data->bits_per_sample = metadata->data.stream_info.bits_per_sample; stream_data->channels = metadata->data.stream_info.channels; stream_data->sample_rate = metadata->data.stream_info.sample_rate; { FLAC__uint64 l = (FLAC__uint64)((double)stream_data->total_samples / (double)stream_data->sample_rate * 1000.0 + 0.5); if (l > INT_MAX) l = INT_MAX; stream_data->length_in_msec = (int)l; } } else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { double reference, gain, peak; if(grabbag__replaygain_load_from_vorbiscomment(metadata, flac_cfg.output.replaygain.album_mode, /*strict=*/false, &reference, &gain, &peak)) { stream_data->has_replaygain = true; stream_data->replay_scale = grabbag__replaygain_compute_scale_factor(peak, gain, (double)flac_cfg.output.replaygain.preamp, /*prevent_clipping=*/!flac_cfg.output.replaygain.hard_limit); } } }