diff --git a/test/FakeDecoderAPI.cxx b/test/FakeDecoderAPI.cxx index 9204835fe..f443c5d42 100644 --- a/test/FakeDecoderAPI.cxx +++ b/test/FakeDecoderAPI.cxx @@ -121,18 +121,26 @@ FakeDecoder::SubmitTag(gcc_unused InputStream *is, return DecoderCommand::NONE; } +static void +DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple) +{ + if (tuple.IsDefined()) + fprintf(stderr, "replay_gain[%s]: gain=%f peak=%f\n", + name, tuple.gain, tuple.peak); +} + +static void +DumpReplayGainInfo(const ReplayGainInfo &info) +{ + DumpReplayGainTuple("album", info.tuples[REPLAY_GAIN_ALBUM]); + DumpReplayGainTuple("track", info.tuples[REPLAY_GAIN_TRACK]); +} + void FakeDecoder::SubmitReplayGain(const ReplayGainInfo *rgi) { - const ReplayGainTuple *tuple = &rgi->tuples[REPLAY_GAIN_ALBUM]; - if (tuple->IsDefined()) - fprintf(stderr, "replay_gain[album]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); - - tuple = &rgi->tuples[REPLAY_GAIN_TRACK]; - if (tuple->IsDefined()) - fprintf(stderr, "replay_gain[track]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); + if (rgi != nullptr) + DumpReplayGainInfo(*rgi); } void diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx index c4408b1b5..603d96e7b 100644 --- a/test/dump_rva2.cxx +++ b/test/dump_rva2.cxx @@ -45,6 +45,21 @@ config_get_string(gcc_unused enum ConfigOption option, return default_value; } +static void +DumpReplayGainTuple(const char *name, const ReplayGainTuple &tuple) +{ + if (tuple.IsDefined()) + fprintf(stderr, "replay_gain[%s]: gain=%f peak=%f\n", + name, tuple.gain, tuple.peak); +} + +static void +DumpReplayGainInfo(const ReplayGainInfo &info) +{ + DumpReplayGainTuple("album", info.tuples[REPLAY_GAIN_ALBUM]); + DumpReplayGainTuple("track", info.tuples[REPLAY_GAIN_TRACK]); +} + int main(int argc, char **argv) try { #ifdef HAVE_LOCALE_H @@ -79,15 +94,7 @@ try { return EXIT_FAILURE; } - const ReplayGainTuple *tuple = &replay_gain.tuples[REPLAY_GAIN_ALBUM]; - if (tuple->IsDefined()) - fprintf(stderr, "replay_gain[album]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); - - tuple = &replay_gain.tuples[REPLAY_GAIN_TRACK]; - if (tuple->IsDefined()) - fprintf(stderr, "replay_gain[track]: gain=%f peak=%f\n", - tuple->gain, tuple->peak); + DumpReplayGainInfo(replay_gain); return EXIT_SUCCESS; } catch (const std::exception &e) {