diff options
author | Max Kellermann <max@duempel.org> | 2014-09-24 20:54:20 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-09-24 22:21:13 +0200 |
commit | 441f9cc2ee1e62be0d5869c247aecff78c2ca3c6 (patch) | |
tree | f3da3a635c38e2feaddde27d41fb80c4bab46ddd /src/decoder/plugins/FlacMetadata.cxx | |
parent | 9f4fc8ad33470d2f82faafb96d5db41967faa151 (diff) | |
download | mpd-441f9cc2ee1e62be0d5869c247aecff78c2ca3c6.tar.gz mpd-441f9cc2ee1e62be0d5869c247aecff78c2ca3c6.tar.xz mpd-441f9cc2ee1e62be0d5869c247aecff78c2ca3c6.zip |
tag/ReplayGain: add VorbisComment parser
Move code from the Vorbis and FLAC decoder plugins.
Diffstat (limited to '')
-rw-r--r-- | src/decoder/plugins/FlacMetadata.cxx | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/src/decoder/plugins/FlacMetadata.cxx b/src/decoder/plugins/FlacMetadata.cxx index a36d1b2e9..2c3c496a6 100644 --- a/src/decoder/plugins/FlacMetadata.cxx +++ b/src/decoder/plugins/FlacMetadata.cxx @@ -26,6 +26,7 @@ #include "tag/TagBuilder.hxx" #include "tag/Tag.hxx" #include "tag/VorbisComment.hxx" +#include "tag/ReplayGain.hxx" #include "ReplayGainInfo.hxx" #include "util/ASCII.hxx" #include "util/SplitString.hxx" @@ -52,37 +53,22 @@ vorbis_comment_value(const FLAC__StreamMetadata *block, return comment + name_length + 1; } -static bool -flac_find_float_comment(const FLAC__StreamMetadata *block, - const char *cmnt, float *fl) -{ - const char *value = vorbis_comment_value(block, cmnt); - if (value == nullptr) - return false; - - *fl = (float)atof(value); - return true; -} - bool flac_parse_replay_gain(ReplayGainInfo &rgi, const FLAC__StreamMetadata *block) { + const FLAC__StreamMetadata_VorbisComment &vc = + block->data.vorbis_comment; + rgi.Clear(); bool found = false; - if (flac_find_float_comment(block, "replaygain_album_gain", - &rgi.tuples[REPLAY_GAIN_ALBUM].gain)) - found = true; - if (flac_find_float_comment(block, "replaygain_album_peak", - &rgi.tuples[REPLAY_GAIN_ALBUM].peak)) - found = true; - if (flac_find_float_comment(block, "replaygain_track_gain", - &rgi.tuples[REPLAY_GAIN_TRACK].gain)) - found = true; - if (flac_find_float_comment(block, "replaygain_track_peak", - &rgi.tuples[REPLAY_GAIN_TRACK].peak)) - found = true; + + const auto *comments = vc.comments; + for (FLAC__uint32 i = 0, n = vc.num_comments; i < n; ++i) + if (ParseReplayGainVorbis(rgi, + (const char *)comments[i].entry)) + found = true; return found; } |