0
0
Fork 0
mirror of https://github.com/ZDoom/qzdoom-gpl.git synced 2024-12-14 06:01:09 +00:00

Implement GetStats for OpenAL streams

This commit is contained in:
Chris Robinson 2013-06-30 20:31:41 -07:00
parent 68988ab93c
commit 665d685a44
3 changed files with 73 additions and 2 deletions

View file

@ -345,6 +345,41 @@ void *OpenALSoundStream::GetData(size_t bytes)
return data;
}
FString OpenALSoundStream::GetStats()
{
FString stats;
ALfloat volume;
ALint processed;
ALint queued;
ALint state;
ALenum err;
alGetSourcef(Source, AL_GAIN, &volume);
alGetSourcei(Source, AL_SOURCE_STATE, &state);
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
if((err=alGetError()) != AL_NO_ERROR)
{
stats = "Error getting stats: ";
stats += alGetString(err);
return stats;
}
stats = (state == AL_INITIAL) ? "Buffering" : (state == AL_STOPPED) ? "Underrun" :
(state == AL_PLAYING || state == AL_PAUSED) ? "Ready" : "Unknown state";
stats.AppendFormat(",%3d%% buffered", (queued ? 100-(processed*100/queued) : 0));
stats.AppendFormat(", %d%%", int(volume * 100));
if(state == AL_PAUSED)
stats += ", paused";
if(state == AL_PLAYING)
stats += ", playing";
stats.AppendFormat(", %uHz", SampleRate);
if(!Playing)
stats += " XX";
return stats;
}
bool OpenALSoundStream::InitSample()
{
UInt32 smpsize = 0;

View file

@ -47,6 +47,8 @@ public:
virtual bool IsEnded();
virtual FString GetStats();
bool Init(const char *filename, int offset, int length);
bool Init(const BYTE *data, unsigned int datalen);
};

View file

@ -400,6 +400,40 @@ public:
return !Playing;
}
FString GetStats()
{
FString stats;
ALfloat volume;
ALint processed;
ALint queued;
ALint state;
ALenum err;
alGetSourcef(Source, AL_GAIN, &volume);
alGetSourcei(Source, AL_SOURCE_STATE, &state);
alGetSourcei(Source, AL_BUFFERS_QUEUED, &queued);
alGetSourcei(Source, AL_BUFFERS_PROCESSED, &processed);
if((err=alGetError()) != AL_NO_ERROR)
{
stats = "Error getting stats: ";
stats += alGetString(err);
return stats;
}
stats = (state == AL_INITIAL) ? "Buffering" : (state == AL_STOPPED) ? "Underrun" :
(state == AL_PLAYING || state == AL_PAUSED) ? "Ready" : "Unknown state";
stats.AppendFormat(",%3d%% buffered", (queued ? 100-(processed*100/queued) : 0));
stats.AppendFormat(", %d%%", int(volume * 100));
if(state == AL_PAUSED)
stats += ", paused";
if(state == AL_PLAYING)
stats += ", playing";
stats.AppendFormat(", %uHz", SampleRate);
if(!Playing)
stats += " XX";
return stats;
}
bool Init(SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata)
{
if(!SetupSource())