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.
This commit is contained in:
parent
cf1fd2b0da
commit
47ed89bd4c
1
NEWS
1
NEWS
|
@ -4,6 +4,7 @@ ver 0.15.2 (2009/??/??)
|
||||||
- ape: added protection against large memory allocations
|
- ape: added protection against large memory allocations
|
||||||
* decoders:
|
* decoders:
|
||||||
- mad: skip ID3 frames when libid3tag is disabled
|
- mad: skip ID3 frames when libid3tag is disabled
|
||||||
|
- flac: parse all replaygain tags
|
||||||
|
|
||||||
|
|
||||||
ver 0.15.1 (2009/07/15)
|
ver 0.15.1 (2009/07/15)
|
||||||
|
|
|
@ -40,9 +40,9 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
|
||||||
data->tag = NULL;
|
data->tag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
flac_find_float_comment(const FLAC__StreamMetadata *block,
|
flac_find_float_comment(const FLAC__StreamMetadata *block,
|
||||||
const char *cmnt, float *fl)
|
const char *cmnt, float *fl, bool *found_r)
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
size_t pos;
|
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,
|
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
|
||||||
cmnt);
|
cmnt);
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
pos = strlen(cmnt) + 1; /* 1 is for '=' */
|
pos = strlen(cmnt) + 1; /* 1 is for '=' */
|
||||||
len = block->data.vorbis_comment.comments[offset].length - pos;
|
len = block->data.vorbis_comment.comments[offset].length - pos;
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
p = &block->data.vorbis_comment.comments[offset].entry[pos];
|
p = &block->data.vorbis_comment.comments[offset].entry[pos];
|
||||||
tmp = p[len];
|
tmp = p[len];
|
||||||
|
@ -65,28 +65,32 @@ flac_find_float_comment(const FLAC__StreamMetadata *block,
|
||||||
*fl = (float)atof((char *)p);
|
*fl = (float)atof((char *)p);
|
||||||
p[len] = tmp;
|
p[len] = tmp;
|
||||||
|
|
||||||
return true;
|
*found_r = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
flac_parse_replay_gain(const FLAC__StreamMetadata *block,
|
flac_parse_replay_gain(const FLAC__StreamMetadata *block,
|
||||||
struct flac_data *data)
|
struct flac_data *data)
|
||||||
{
|
{
|
||||||
bool found;
|
bool found = false;
|
||||||
|
|
||||||
if (data->replay_gain_info)
|
if (data->replay_gain_info)
|
||||||
replay_gain_info_free(data->replay_gain_info);
|
replay_gain_info_free(data->replay_gain_info);
|
||||||
|
|
||||||
data->replay_gain_info = replay_gain_info_new();
|
data->replay_gain_info = replay_gain_info_new();
|
||||||
|
|
||||||
found = flac_find_float_comment(block, "replaygain_album_gain",
|
flac_find_float_comment(block, "replaygain_album_gain",
|
||||||
&data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain) ||
|
&data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain,
|
||||||
flac_find_float_comment(block, "replaygain_album_peak",
|
&found);
|
||||||
&data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak) ||
|
flac_find_float_comment(block, "replaygain_album_peak",
|
||||||
flac_find_float_comment(block, "replaygain_track_gain",
|
&data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak,
|
||||||
&data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].gain) ||
|
&found);
|
||||||
flac_find_float_comment(block, "replaygain_track_peak",
|
flac_find_float_comment(block, "replaygain_track_gain",
|
||||||
&data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak);
|
&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) {
|
if (!found) {
|
||||||
replay_gain_info_free(data->replay_gain_info);
|
replay_gain_info_free(data->replay_gain_info);
|
||||||
|
|
Loading…
Reference in New Issue