diff --git a/src/sound/i_soundinternal.h b/src/sound/i_soundinternal.h index 0a7e8b0e0..499fe80a6 100644 --- a/src/sound/i_soundinternal.h +++ b/src/sound/i_soundinternal.h @@ -126,6 +126,7 @@ struct SoundDecoder virtual std::vector readAll(); virtual bool seek(size_t ms_offset) = 0; virtual size_t getSampleOffset() = 0; + virtual size_t getSampleLength() { return 0; } SoundDecoder() { } virtual ~SoundDecoder() { } diff --git a/src/sound/mpg123_decoder.cpp b/src/sound/mpg123_decoder.cpp index 63ccb6922..969706a98 100644 --- a/src/sound/mpg123_decoder.cpp +++ b/src/sound/mpg123_decoder.cpp @@ -182,4 +182,10 @@ size_t MPG123Decoder::getSampleOffset() return mpg123_tell(MPG123); } +size_t MPG123Decoder::getSampleLength() +{ + off_t len = mpg123_length(MPG123); + return (len > 0) ? len : 0; +} + #endif diff --git a/src/sound/mpg123_decoder.h b/src/sound/mpg123_decoder.h index 0d8d2e7ab..8b2b64fa7 100644 --- a/src/sound/mpg123_decoder.h +++ b/src/sound/mpg123_decoder.h @@ -14,6 +14,7 @@ struct MPG123Decoder : public SoundDecoder virtual size_t read(char *buffer, size_t bytes); virtual bool seek(size_t ms_offset); virtual size_t getSampleOffset(); + virtual size_t getSampleLength(); MPG123Decoder() : MPG123(0) { } virtual ~MPG123Decoder(); diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index f04990fa7..27f7d4755 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -388,12 +388,12 @@ public: FString GetStats() { FString stats; + size_t pos, len; ALfloat volume; ALint offset; ALint processed; ALint queued; ALint state; - size_t pos; ALenum err; alGetSourcef(Source, AL_GAIN, &volume); @@ -412,16 +412,22 @@ public: (state == AL_PLAYING || state == AL_PAUSED) ? "Ready" : "Unknown state"; pos = Decoder->getSampleOffset(); + len = Decoder->getSampleLength(); if(state == AL_STOPPED) offset = BufferCount * (Data.size()/FrameSize); else { size_t rem = queued*(Data.size()/FrameSize) - offset; if(pos > rem) pos -= rem; + else if(len > 0) pos += len - rem; else pos = 0; } + pos = (size_t)(pos * 1000.0 / SampleRate); + len = (size_t)(len * 1000.0 / SampleRate); stats.AppendFormat(",%3lu%% buffered", 100 - 100*offset/(BufferCount*(Data.size()/FrameSize))); - stats.AppendFormat(", %zu ms", pos); + stats.AppendFormat(", %zu.%03zu", pos/1000, pos%1000); + if(len > 0) + stats.AppendFormat(" / %zu.%03zu", len/1000, len%1000); if(state == AL_PAUSED) stats += ", paused"; if(state == AL_PLAYING) diff --git a/src/sound/sndfile_decoder.cpp b/src/sound/sndfile_decoder.cpp index 922fc8b1c..efcc6cf40 100644 --- a/src/sound/sndfile_decoder.cpp +++ b/src/sound/sndfile_decoder.cpp @@ -106,4 +106,9 @@ size_t SndFileDecoder::getSampleOffset() return sf_seek(SndFile, 0, SEEK_CUR); } +size_t SndFileDecoder::getSampleLength() +{ + return (SndInfo.frames > 0) ? SndInfo.frames : 0; +} + #endif diff --git a/src/sound/sndfile_decoder.h b/src/sound/sndfile_decoder.h index f329ab876..6c4dd3eda 100644 --- a/src/sound/sndfile_decoder.h +++ b/src/sound/sndfile_decoder.h @@ -15,6 +15,7 @@ struct SndFileDecoder : public SoundDecoder virtual std::vector readAll(); virtual bool seek(size_t ms_offset); virtual size_t getSampleOffset(); + virtual size_t getSampleLength(); SndFileDecoder() : SndFile(0) { } virtual ~SndFileDecoder();