diff --git a/src/sound/oalsdlsound.cpp b/src/sound/oalsdlsound.cpp index d0fb88a2f7..6ef7d9118a 100644 --- a/src/sound/oalsdlsound.cpp +++ b/src/sound/oalsdlsound.cpp @@ -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; diff --git a/src/sound/oalsdlsound.h b/src/sound/oalsdlsound.h index 597a825585..7b7a0ce737 100644 --- a/src/sound/oalsdlsound.h +++ b/src/sound/oalsdlsound.h @@ -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); }; diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index 1bccec31de..afcaed59f9 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -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()) @@ -428,8 +462,8 @@ public: if(Format == AL_NONE) { - Printf("Unsupported format: 0x%x\n", flags); - return false; + Printf("Unsupported format: 0x%x\n", flags); + return false; } int smpsize = 1;