decoder/wavpack: move code to GetDuration()

This commit is contained in:
Max Kellermann 2016-12-09 21:45:22 +01:00
parent e8c374113e
commit caee420087

View File

@ -49,6 +49,15 @@ static constexpr int OPEN_DSD_FLAG = OPEN_DSD_AS_PCM;
static constexpr int OPEN_DSD_FLAG = 0; static constexpr int OPEN_DSD_FLAG = 0;
#endif #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. */ /** A pointer type for format converter function. */
typedef void (*format_samples_t)( typedef void (*format_samples_t)(
int bytes_per_sample, int bytes_per_sample,
@ -157,9 +166,7 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek)
? format_samples_float ? format_samples_float
: format_samples_int; : format_samples_int;
const auto total_time = client.Ready(audio_format, can_seek, GetDuration(wpc));
SongTime::FromScale<uint64_t>(WavpackGetNumSamples(wpc),
audio_format.sample_rate);
const int bytes_per_sample = WavpackGetBytesPerSample(wpc); const int bytes_per_sample = WavpackGetBytesPerSample(wpc);
const int output_sample_size = audio_format.GetFrameSize(); 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) / const uint32_t samples_requested = ARRAY_SIZE(chunk) /
audio_format.channels; audio_format.channels;
client.Ready(audio_format, can_seek, total_time);
DecoderCommand cmd = client.GetCommand(); DecoderCommand cmd = client.GetCommand();
while (cmd != DecoderCommand::STOP) { while (cmd != DecoderCommand::STOP) {
if (cmd == DecoderCommand::SEEK) { if (cmd == DecoderCommand::SEEK) {
@ -224,10 +229,8 @@ wavpack_scan_file(Path path_fs,
WavpackCloseFile(wpc); WavpackCloseFile(wpc);
}; };
const auto duration = const auto duration = GetDuration(wpc);
SongTime::FromScale<uint64_t>(WavpackGetNumSamples(wpc), tag_handler_invoke_duration(handler, handler_ctx, SongTime(duration));
WavpackGetSampleRate(wpc));
tag_handler_invoke_duration(handler, handler_ctx, duration);
return true; return true;
} }