summaryrefslogtreecommitdiff
path: root/src/decoder/plugins/WavpackDecoderPlugin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder/plugins/WavpackDecoderPlugin.cxx')
-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;
}