aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-11 16:21:09 +0100
committerMax Kellermann <max@duempel.org>2008-11-11 16:21:09 +0100
commit5e686add91a7c2a89b886d04136983480793a26f (patch)
tree3c6c755c86141a1b9305f04648fd4294b6c64b00 /src
parentc883d761abbf0bfa491f28a340c2c535ec6e0268 (diff)
downloadmpd-5e686add91a7c2a89b886d04136983480793a26f.tar.gz
mpd-5e686add91a7c2a89b886d04136983480793a26f.tar.xz
mpd-5e686add91a7c2a89b886d04136983480793a26f.zip
wavpack: added wavpack_tag_float()
The function simplifies wavpack_replaygain(), because it already contains the float parser, and it works with a fixed buffer instead of doing expensive heap allocations.
Diffstat (limited to '')
-rw-r--r--src/decoder/wavpack_plugin.c66
1 files changed, 25 insertions, 41 deletions
diff --git a/src/decoder/wavpack_plugin.c b/src/decoder/wavpack_plugin.c
index 07d363495..10dd7fd02 100644
--- a/src/decoder/wavpack_plugin.c
+++ b/src/decoder/wavpack_plugin.c
@@ -213,20 +213,22 @@ wavpack_decode(struct decoder * decoder, WavpackContext *wpc, bool canseek,
} while (samplesgot == samplesreq);
}
-static char *
-wavpack_tag(WavpackContext *wpc, const char *key)
+/**
+ * Locate and parse a floating point tag. Returns true if it was
+ * found.
+ */
+static bool
+wavpack_tag_float(WavpackContext *wpc, const char *key, float *value_r)
{
- char *value = NULL;
- int size;
-
- size = WavpackGetTagItem(wpc, key, NULL, 0);
- if (size > 0) {
- size++;
- value = g_malloc(size);
- WavpackGetTagItem(wpc, key, value, size);
- }
+ char buffer[64];
+ int ret;
- return value;
+ ret = WavpackGetTagItem(wpc, key, buffer, sizeof(buffer));
+ if (ret <= 0)
+ return false;
+
+ *value_r = atof(buffer);
+ return true;
}
static struct replay_gain_info *
@@ -234,38 +236,20 @@ wavpack_replaygain(WavpackContext *wpc)
{
struct replay_gain_info *replay_gain_info;
bool found = false;
- char *value;
replay_gain_info = replay_gain_info_new();
- value = wavpack_tag(wpc, "replaygain_track_gain");
- if (value) {
- replay_gain_info->track_gain = atof(value);
- free(value);
- found = true;
- }
-
- value = wavpack_tag(wpc, "replaygain_album_gain");
- if (value) {
- replay_gain_info->album_gain = atof(value);
- free(value);
- found = true;
- }
-
- value = wavpack_tag(wpc, "replaygain_track_peak");
- if (value) {
- replay_gain_info->track_peak = atof(value);
- free(value);
- found = true;
- }
-
- value = wavpack_tag(wpc, "replaygain_album_peak");
- if (value) {
- replay_gain_info->album_peak = atof(value);
- free(value);
- found = true;
- }
-
+ found = wavpack_tag_float(wpc, "replaygain_track_gain",
+ &replay_gain_info->track_gain)
+ ||
+ wavpack_tag_float(wpc, "replaygain_track_peak",
+ &replay_gain_info->track_peak)
+ ||
+ wavpack_tag_float(wpc, "replaygain_album_gain",
+ &replay_gain_info->album_gain)
+ ||
+ wavpack_tag_float(wpc, "replaygain_album_peak",
+ &replay_gain_info->album_peak);
if (found) {
return replay_gain_info;