mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-17 17:50:57 +00:00
Get the length from sounds when possible
This commit is contained in:
parent
fd25ec2a62
commit
c6bb52c866
6 changed files with 22 additions and 2 deletions
|
@ -126,6 +126,7 @@ struct SoundDecoder
|
|||
virtual std::vector<char> readAll();
|
||||
virtual bool seek(size_t ms_offset) = 0;
|
||||
virtual size_t getSampleOffset() = 0;
|
||||
virtual size_t getSampleLength() { return 0; }
|
||||
|
||||
SoundDecoder() { }
|
||||
virtual ~SoundDecoder() { }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -15,6 +15,7 @@ struct SndFileDecoder : public SoundDecoder
|
|||
virtual std::vector<char> readAll();
|
||||
virtual bool seek(size_t ms_offset);
|
||||
virtual size_t getSampleOffset();
|
||||
virtual size_t getSampleLength();
|
||||
|
||||
SndFileDecoder() : SndFile(0) { }
|
||||
virtual ~SndFileDecoder();
|
||||
|
|
Loading…
Reference in a new issue