summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-12-09 21:45:22 +0100
committerMax Kellermann <max@musicpd.org>2016-12-09 21:45:22 +0100
commitcaee420087473502e3d42bd53a5b67688786d635 (patch)
treee0a1c3cbe9ab442f56c7bb27c02082cc09e4afee /src
parente8c374113e92f6582512476700b86a68c3e1be2d (diff)
decoder/wavpack: move code to GetDuration()
Diffstat (limited to 'src')
-rw-r--r--src/decoder/plugins/WavpackDecoderPlugin.cxx21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/decoder/plugins/WavpackDecoderPlugin.cxx b/src/decoder/plugins/WavpackDecoderPlugin.cxx
index 18a2c02fb..b933ede40 100644
--- a/src/decoder/plugins/WavpackDecoderPlugin.cxx
+++ b/src/decoder/plugins/WavpackDecoderPlugin.cxx
@@ -49,6 +49,15 @@ static constexpr int OPEN_DSD_FLAG = OPEN_DSD_AS_PCM;
static constexpr int OPEN_DSD_FLAG = 0;
#endif
+gcc_pure
+static SignedSongTime
+GetDuration(WavpackContext *wpc)
+{
+ const uint32_t n_samples = WavpackGetNumSamples(wpc);
+ return SongTime::FromScale<uint64_t>(n_samples,
+ WavpackGetSampleRate(wpc));
+}
+
/** A pointer type for format converter function. */
typedef void (*format_samples_t)(
int bytes_per_sample,
@@ -157,9 +166,7 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek)
? format_samples_float
: format_samples_int;
- const auto total_time =
- SongTime::FromScale<uint64_t>(WavpackGetNumSamples(wpc),
- audio_format.sample_rate);
+ client.Ready(audio_format, can_seek, GetDuration(wpc));
const int bytes_per_sample = WavpackGetBytesPerSample(wpc);
const int output_sample_size = audio_format.GetFrameSize();
@@ -169,8 +176,6 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek)
const uint32_t samples_requested = ARRAY_SIZE(chunk) /
audio_format.channels;
- client.Ready(audio_format, can_seek, total_time);
-
DecoderCommand cmd = client.GetCommand();
while (cmd != DecoderCommand::STOP) {
if (cmd == DecoderCommand::SEEK) {
@@ -224,10 +229,8 @@ wavpack_scan_file(Path path_fs,
WavpackCloseFile(wpc);
};
- const auto duration =
- SongTime::FromScale<uint64_t>(WavpackGetNumSamples(wpc),
- WavpackGetSampleRate(wpc));
- tag_handler_invoke_duration(handler, handler_ctx, duration);
+ const auto duration = GetDuration(wpc);
+ tag_handler_invoke_duration(handler, handler_ctx, SongTime(duration));
return true;
}