aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-11 16:24:27 +0100
committerMax Kellermann <max@duempel.org>2008-11-11 16:24:27 +0100
commit5ddde0aac790c57b75f20ce71e100f4379f1c653 (patch)
treeb2e8ec4a99e032bf894002fd436c00e35e3cf5fd
parent5e686add91a7c2a89b886d04136983480793a26f (diff)
downloadmpd-5ddde0aac790c57b75f20ce71e100f4379f1c653.tar.gz
mpd-5ddde0aac790c57b75f20ce71e100f4379f1c653.tar.xz
mpd-5ddde0aac790c57b75f20ce71e100f4379f1c653.zip
replay_gain: converted struct replay_gain_info elements to an array
Having an array instead of individual variables allows the use of the replay_gain_mode enum as an array index.
-rw-r--r--src/decoder/_flac_common.c8
-rw-r--r--src/decoder/mp3_plugin.c12
-rw-r--r--src/decoder/mpc_plugin.c8
-rw-r--r--src/decoder/oggvorbis_plugin.c8
-rw-r--r--src/decoder/wavpack_plugin.c8
-rw-r--r--src/replay_gain.c38
-rw-r--r--src/replay_gain.h10
7 files changed, 47 insertions, 45 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c
index 3df7d24e5..200b6fee6 100644
--- a/src/decoder/_flac_common.c
+++ b/src/decoder/_flac_common.c
@@ -75,13 +75,13 @@ static void flacParseReplayGain(const FLAC__StreamMetadata * block,
data->replayGainInfo = replay_gain_info_new();
found |= flacFindVorbisCommentFloat(block, "replaygain_album_gain",
- &data->replayGainInfo->album_gain);
+ &data->replayGainInfo->tuples[REPLAY_GAIN_ALBUM].gain);
found |= flacFindVorbisCommentFloat(block, "replaygain_album_peak",
- &data->replayGainInfo->album_peak);
+ &data->replayGainInfo->tuples[REPLAY_GAIN_ALBUM].peak);
found |= flacFindVorbisCommentFloat(block, "replaygain_track_gain",
- &data->replayGainInfo->track_gain);
+ &data->replayGainInfo->tuples[REPLAY_GAIN_TRACK].gain);
found |= flacFindVorbisCommentFloat(block, "replaygain_track_peak",
- &data->replayGainInfo->track_peak);
+ &data->replayGainInfo->tuples[REPLAY_GAIN_TRACK].peak);
if (!found) {
replay_gain_info_free(data->replayGainInfo);
diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c
index 602c9e2f9..4ae6cd744 100644
--- a/src/decoder/mp3_plugin.c
+++ b/src/decoder/mp3_plugin.c
@@ -228,16 +228,16 @@ parse_id3_replay_gain_info(struct id3_tag *tag)
(&frame->fields[2]));
if (strcasecmp(key, "replaygain_track_gain") == 0) {
- replay_gain_info->track_gain = atof(value);
+ replay_gain_info->tuples[REPLAY_GAIN_TRACK].gain = atof(value);
found = true;
} else if (strcasecmp(key, "replaygain_album_gain") == 0) {
- replay_gain_info->album_gain = atof(value);
+ replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain = atof(value);
found = true;
} else if (strcasecmp(key, "replaygain_track_peak") == 0) {
- replay_gain_info->track_peak = atof(value);
+ replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak = atof(value);
found = true;
} else if (strcasecmp(key, "replaygain_album_peak") == 0) {
- replay_gain_info->album_peak = atof(value);
+ replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak = atof(value);
found = true;
}
@@ -761,8 +761,8 @@ mp3_decode_first_frame(struct mp3_data *data, struct tag **tag,
if (replay_gain_info_r && !*replay_gain_info_r &&
lame.track_gain) {
*replay_gain_info_r = replay_gain_info_new();
- (*replay_gain_info_r)->track_gain = lame.track_gain;
- (*replay_gain_info_r)->track_peak = lame.peak;
+ (*replay_gain_info_r)->tuples[REPLAY_GAIN_TRACK].gain = lame.track_gain;
+ (*replay_gain_info_r)->tuples[REPLAY_GAIN_TRACK].peak = lame.peak;
}
}
}
diff --git a/src/decoder/mpc_plugin.c b/src/decoder/mpc_plugin.c
index 6bb1d4f59..02b20a942 100644
--- a/src/decoder/mpc_plugin.c
+++ b/src/decoder/mpc_plugin.c
@@ -157,10 +157,10 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream)
audio_format.sample_rate = info.sample_freq;
replayGainInfo = replay_gain_info_new();
- replayGainInfo->album_gain = info.gain_album * 0.01;
- replayGainInfo->album_peak = info.peak_album / 32767.0;
- replayGainInfo->track_gain = info.gain_title * 0.01;
- replayGainInfo->track_peak = info.peak_title / 32767.0;
+ replayGainInfo->tuples[REPLAY_GAIN_ALBUM].gain = info.gain_album * 0.01;
+ replayGainInfo->tuples[REPLAY_GAIN_ALBUM].peak = info.peak_album / 32767.0;
+ replayGainInfo->tuples[REPLAY_GAIN_TRACK].gain = info.gain_title * 0.01;
+ replayGainInfo->tuples[REPLAY_GAIN_TRACK].peak = info.peak_title / 32767.0;
decoder_initialized(mpd_decoder, &audio_format,
inStream->seekable,
diff --git a/src/decoder/oggvorbis_plugin.c b/src/decoder/oggvorbis_plugin.c
index 446151a73..e707c4013 100644
--- a/src/decoder/oggvorbis_plugin.c
+++ b/src/decoder/oggvorbis_plugin.c
@@ -105,19 +105,19 @@ ogg_getReplayGainInfo(char **comments)
while (*comments) {
if ((temp =
ogg_parseComment(*comments, "replaygain_track_gain"))) {
- rgi->track_gain = atof(temp);
+ rgi->tuples[REPLAY_GAIN_TRACK].gain = atof(temp);
found = true;
} else if ((temp = ogg_parseComment(*comments,
"replaygain_album_gain"))) {
- rgi->album_gain = atof(temp);
+ rgi->tuples[REPLAY_GAIN_ALBUM].gain = atof(temp);
found = true;
} else if ((temp = ogg_parseComment(*comments,
"replaygain_track_peak"))) {
- rgi->track_peak = atof(temp);
+ rgi->tuples[REPLAY_GAIN_TRACK].peak = atof(temp);
found = true;
} else if ((temp = ogg_parseComment(*comments,
"replaygain_album_peak"))) {
- rgi->album_peak = atof(temp);
+ rgi->tuples[REPLAY_GAIN_ALBUM].peak = atof(temp);
found = true;
}
diff --git a/src/decoder/wavpack_plugin.c b/src/decoder/wavpack_plugin.c
index 10dd7fd02..67fa3fb44 100644
--- a/src/decoder/wavpack_plugin.c
+++ b/src/decoder/wavpack_plugin.c
@@ -240,16 +240,16 @@ wavpack_replaygain(WavpackContext *wpc)
replay_gain_info = replay_gain_info_new();
found = wavpack_tag_float(wpc, "replaygain_track_gain",
- &replay_gain_info->track_gain)
+ &replay_gain_info->tuples[REPLAY_GAIN_TRACK].gain)
||
wavpack_tag_float(wpc, "replaygain_track_peak",
- &replay_gain_info->track_peak)
+ &replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak)
||
wavpack_tag_float(wpc, "replaygain_album_gain",
- &replay_gain_info->album_gain)
+ &replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain)
||
wavpack_tag_float(wpc, "replaygain_album_peak",
- &replay_gain_info->album_peak);
+ &replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak);
if (found) {
return replay_gain_info;
diff --git a/src/replay_gain.c b/src/replay_gain.c
index 4f589c233..ebd8e40ca 100644
--- a/src/replay_gain.c
+++ b/src/replay_gain.c
@@ -25,6 +25,13 @@
#include "audio_format.h"
#include "os_compat.h"
+#include <glib.h>
+
+static const char *const replay_gain_mode_names[] = {
+ [REPLAY_GAIN_ALBUM] = "album",
+ [REPLAY_GAIN_TRACK] = "track",
+};
+
enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF;
static float replay_gain_preamp = 1.0;
@@ -86,11 +93,10 @@ struct replay_gain_info *replay_gain_info_new(void)
{
struct replay_gain_info *ret = xmalloc(sizeof(*ret));
- ret->album_gain = 0.0;
- ret->album_peak = 0.0;
-
- ret->track_gain = 0.0;
- ret->track_peak = 0.0;
+ for (unsigned i = 0; i < G_N_ELEMENTS(ret->tuples); ++i) {
+ ret->tuples[i].gain = 0.0;
+ ret->tuples[i].peak = 0.0;
+ }
/* set to -1 so that we know in replay_gain_apply to compute the scale */
ret->scale = -1.0;
@@ -116,20 +122,14 @@ replay_gain_apply(struct replay_gain_info *info, char *buffer, int size,
return;
if (info->scale < 0) {
- switch (replay_gain_mode) {
- case REPLAY_GAIN_TRACK:
- DEBUG("computing ReplayGain track scale with gain %f, "
- "peak %f\n", info->track_gain, info->track_peak);
- info->scale = calc_replay_gain_scale(info->track_gain,
- info->track_peak);
- break;
- default:
- DEBUG("computing ReplayGain album scale with gain %f, "
- "peak %f\n", info->album_gain, info->album_peak);
- info->scale = calc_replay_gain_scale(info->album_gain,
- info->album_peak);
- break;
- }
+ const struct replay_gain_tuple *tuple =
+ &info->tuples[replay_gain_mode];
+
+ DEBUG("computing ReplayGain %s scale with gain %f, peak %f\n",
+ replay_gain_mode_names[replay_gain_mode],
+ tuple->gain, tuple->peak);
+
+ info->scale = calc_replay_gain_scale(tuple->gain, tuple->peak);
}
if (info->scale <= 1.01 && info->scale >= 0.99)
diff --git a/src/replay_gain.h b/src/replay_gain.h
index d3fae3f46..73e9e1ef0 100644
--- a/src/replay_gain.h
+++ b/src/replay_gain.h
@@ -30,11 +30,13 @@ struct audio_format;
extern enum replay_gain_mode replay_gain_mode;
+struct replay_gain_tuple {
+ float gain;
+ float peak;
+};
+
struct replay_gain_info {
- float album_gain;
- float album_peak;
- float track_gain;
- float track_peak;
+ struct replay_gain_tuple tuples[2];
/* used internally by mpd, to mess with it */
float scale;