From 47ed89bd4c6499d475d5f16cb89d7be95763670c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 22 Jul 2009 13:31:48 +0200 Subject: decoder/flac: parse all replaygain tags The FLAC replaygain parser used the "||" operator. This made the code stop after the first value which was found. --- NEWS | 1 + src/decoder/_flac_common.c | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 674cf61d9..374c58d80 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ ver 0.15.2 (2009/??/??) - ape: added protection against large memory allocations * decoders: - mad: skip ID3 frames when libid3tag is disabled + - flac: parse all replaygain tags ver 0.15.1 (2009/07/15) diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c index a450b6886..9e2d9f437 100644 --- a/src/decoder/_flac_common.c +++ b/src/decoder/_flac_common.c @@ -40,9 +40,9 @@ flac_data_init(struct flac_data *data, struct decoder * decoder, data->tag = NULL; } -static bool +static void flac_find_float_comment(const FLAC__StreamMetadata *block, - const char *cmnt, float *fl) + const char *cmnt, float *fl, bool *found_r) { int offset; size_t pos; @@ -52,12 +52,12 @@ flac_find_float_comment(const FLAC__StreamMetadata *block, offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, cmnt); if (offset < 0) - return false; + return; pos = strlen(cmnt) + 1; /* 1 is for '=' */ len = block->data.vorbis_comment.comments[offset].length - pos; if (len <= 0) - return false; + return; p = &block->data.vorbis_comment.comments[offset].entry[pos]; tmp = p[len]; @@ -65,28 +65,32 @@ flac_find_float_comment(const FLAC__StreamMetadata *block, *fl = (float)atof((char *)p); p[len] = tmp; - return true; + *found_r = true; } static void flac_parse_replay_gain(const FLAC__StreamMetadata *block, struct flac_data *data) { - bool found; + bool found = false; if (data->replay_gain_info) replay_gain_info_free(data->replay_gain_info); data->replay_gain_info = replay_gain_info_new(); - found = flac_find_float_comment(block, "replaygain_album_gain", - &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain) || - flac_find_float_comment(block, "replaygain_album_peak", - &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak) || - flac_find_float_comment(block, "replaygain_track_gain", - &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].gain) || - flac_find_float_comment(block, "replaygain_track_peak", - &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak); + flac_find_float_comment(block, "replaygain_album_gain", + &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain, + &found); + flac_find_float_comment(block, "replaygain_album_peak", + &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak, + &found); + flac_find_float_comment(block, "replaygain_track_gain", + &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].gain, + &found); + flac_find_float_comment(block, "replaygain_track_peak", + &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak, + &found); if (!found) { replay_gain_info_free(data->replay_gain_info); -- cgit v1.2.3