aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/OpusTags.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-24 23:56:06 +0200
committerMax Kellermann <max@duempel.org>2013-10-24 23:56:06 +0200
commitac8e5be9f4342ec6b746dfb12d21700d7409a07d (patch)
tree0ae5918a96ea467003249be0226fac0f0cb94a9c /src/decoder/OpusTags.cxx
parentc76952534e0ab82b179d360f07beceb634a0a154 (diff)
downloadmpd-ac8e5be9f4342ec6b746dfb12d21700d7409a07d.tar.gz
mpd-ac8e5be9f4342ec6b746dfb12d21700d7409a07d.tar.xz
mpd-ac8e5be9f4342ec6b746dfb12d21700d7409a07d.zip
decoder/opus: support replay gain
Parse the R128_TRACK_GAIN comment string.
Diffstat (limited to 'src/decoder/OpusTags.cxx')
-rw-r--r--src/decoder/OpusTags.cxx15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/decoder/OpusTags.cxx b/src/decoder/OpusTags.cxx
index ed2b054b4..e0319ad48 100644
--- a/src/decoder/OpusTags.cxx
+++ b/src/decoder/OpusTags.cxx
@@ -23,6 +23,7 @@
#include "XiphTags.hxx"
#include "tag/TagHandler.hxx"
#include "tag/Tag.hxx"
+#include "ReplayGainInfo.hxx"
#include <stdint.h>
#include <string.h>
@@ -41,8 +42,19 @@ ParseOpusTagName(const char *name)
static void
ScanOneOpusTag(const char *name, const char *value,
+ replay_gain_info *rgi,
const struct tag_handler *handler, void *ctx)
{
+ if (rgi != nullptr && strcmp(name, "R128_TRACK_GAIN") == 0) {
+ /* R128_TRACK_GAIN is a Q7.8 fixed point number in
+ dB */
+
+ char *endptr;
+ long l = strtol(value, &endptr, 10);
+ if (endptr > value && *endptr == 0)
+ rgi->tuples[REPLAY_GAIN_TRACK].gain = double(l) / 256.;
+ }
+
tag_handler_invoke_pair(handler, ctx, name, value);
if (handler->tag != nullptr) {
@@ -54,6 +66,7 @@ ScanOneOpusTag(const char *name, const char *value,
bool
ScanOpusTags(const void *data, size_t size,
+ replay_gain_info *rgi,
const struct tag_handler *handler, void *ctx)
{
OpusReader r(data, size);
@@ -79,7 +92,7 @@ ScanOpusTags(const void *data, size_t size,
if (eq != nullptr && eq > p) {
*eq = 0;
- ScanOneOpusTag(p, eq + 1, handler, ctx);
+ ScanOneOpusTag(p, eq + 1, rgi, handler, ctx);
}
delete[] p;