From b470ca97b694a70b2e0a838059c755d5506ab8c2 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 28 Apr 2013 14:06:12 +0000 Subject: sid plugin: added end of song mark git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3425 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/sid/decoder_sid.cpp | 16 +++++++++++++--- src/plugins/Input/sid/decoder_sid.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src/plugins/Input') diff --git a/src/plugins/Input/sid/decoder_sid.cpp b/src/plugins/Input/sid/decoder_sid.cpp index c79b8bf70..30d694f8d 100644 --- a/src/plugins/Input/sid/decoder_sid.cpp +++ b/src/plugins/Input/sid/decoder_sid.cpp @@ -38,6 +38,8 @@ DecoderSID::DecoderSID(SidDatabase *db, const QString &url) : Decoder() m_url = url; m_player = new sidplayfp(); m_length = 0; + m_length_in_bytes = 0; + m_read_bytes = 0; } DecoderSID::~DecoderSID() @@ -47,6 +49,8 @@ DecoderSID::~DecoderSID() bool DecoderSID::initialize() { + m_length_in_bytes = 0; + m_read_bytes = 0; QString path = m_url; path.remove("sid://"); path.remove(QRegExp("#\\d+$")); @@ -137,6 +141,9 @@ bool DecoderSID::initialize() } configure(44100, 2); + m_length_in_bytes = audioParameters().sampleRate() * + audioParameters().channels() * + audioParameters().sampleSize() * m_length; qDebug("DecoderSID: initialize succes"); return true; } @@ -158,7 +165,10 @@ int DecoderSID::bitrate() qint64 DecoderSID::read(char *data, qint64 size) { - //if(m_player->time() > m_length) - // return 0; - return m_player->play((short *)data, size/2) * 2; + size = qMin(size, qMax(m_length_in_bytes - m_read_bytes, qint64(0))); + size -= size % 4; + if(size <= 0) + return 0; + m_read_bytes += size; + return m_player->play((short *)data, size/2) * 2; } diff --git a/src/plugins/Input/sid/decoder_sid.h b/src/plugins/Input/sid/decoder_sid.h index 05c70660a..69d8483cb 100644 --- a/src/plugins/Input/sid/decoder_sid.h +++ b/src/plugins/Input/sid/decoder_sid.h @@ -48,6 +48,8 @@ private: sidplayfp *m_player; SidDatabase *m_db; int m_length; + qint64 m_length_in_bytes; + qint64 m_read_bytes; }; #endif // DECODER_SID_H -- cgit v1.2.3-13-gbd6f