From 49c04ccfc7fc326c3128d116a43bcad5fff6077d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 27 Oct 2016 20:24:16 +0200 Subject: [PATCH] decoder/sidplay: fix playback speed with libsidplayfp https://bugs.musicpd.org/view.php?id=4577 --- NEWS | 1 + src/decoder/plugins/SidplayDecoderPlugin.cxx | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index c873cbc2f..0f11eea76 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ver 0.19.20 (not yet released) * decoder - ffmpeg: ignore empty packets + - sidplay: fix playback speed with libsidplayfp ver 0.19.19 (2016/08/23) * decoder diff --git a/src/decoder/plugins/SidplayDecoderPlugin.cxx b/src/decoder/plugins/SidplayDecoderPlugin.cxx index 794a5dab8..8793a41b2 100644 --- a/src/decoder/plugins/SidplayDecoderPlugin.cxx +++ b/src/decoder/plugins/SidplayDecoderPlugin.cxx @@ -354,12 +354,19 @@ sidplay_file_decode(Decoder &decoder, Path path_fs) DecoderCommand cmd; do { short buffer[4096]; - size_t nbytes; - nbytes = player.play(buffer, ARRAY_SIZE(buffer)); - if (nbytes == 0) + const auto result = player.play(buffer, ARRAY_SIZE(buffer)); + if (result <= 0) break; +#ifdef HAVE_SIDPLAYFP + /* libsidplayfp returns the number of samples */ + const size_t nbytes = result * sizeof(buffer[0]); +#else + /* libsidplay2 returns the number of bytes */ + const size_t nbytes = result; +#endif + decoder_timestamp(decoder, (double)player.time() / timebase); cmd = decoder_data(decoder, nullptr, buffer, nbytes, 0);