From 5a077a0b37b801402aeafd4744e42049ecad3502 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 12 Dec 2016 11:56:22 -0800 Subject: [PATCH] Add a method to check if a channel config and sample type are supported --- include/AL/alure2.h | 73 +++++++++++++++++++++++++++++------------------------ src/buffer.cpp | 4 +-- src/context.cpp | 18 +++++++++++++ src/context.h | 2 ++ src/source.cpp | 9 ++++++- 5 files changed, 69 insertions(+), 37 deletions(-) diff --git a/include/AL/alure2.h b/include/AL/alure2.h index f5af93b..5692cb9 100644 --- a/include/AL/alure2.h +++ b/include/AL/alure2.h @@ -206,6 +206,40 @@ public: static_assert(sizeof(Vector3) == sizeof(ALfloat[3]), "Bad Vector3 size"); +enum class SampleType { + UInt8, + Int16, + Float32, + Mulaw +}; +ALURE_API const char *GetSampleTypeName(SampleType type); + +enum class ChannelConfig { + /** 1-channel mono sound. */ + Mono, + /** 2-channel stereo sound. */ + Stereo, + /** 2-channel rear sound (back-left and back-right). */ + Rear, + /** 4-channel surround sound. */ + Quad, + /** 5.1 surround sound. */ + X51, + /** 6.1 surround sound. */ + X61, + /** 7.1 surround sound. */ + X71, + /** 3-channel B-Format, using FuMa channel ordering and scaling. */ + BFormat2D, + /** 4-channel B-Format, using FuMa channel ordering and scaling. */ + BFormat3D +}; +ALURE_API const char *GetChannelConfigName(ChannelConfig cfg); + +ALURE_API ALuint FramesToBytes(ALuint frames, ChannelConfig chans, SampleType type); +ALURE_API ALuint BytesToFrames(ALuint bytes, ChannelConfig chans, SampleType type); + + /** * Creates a version number value using the specified \param major and * \param minor values. @@ -430,6 +464,12 @@ public: // Functions below require the context to be current /** + * Queries if the channel configuration and sample type are supported by + * the context. + */ + virtual bool isSupported(ChannelConfig channels, SampleType type) const = 0; + + /** * Creates and caches a \ref Buffer for the given audio file or resource * \param name. Multiple calls with the same name will return the same * \ref Buffer object. @@ -503,39 +543,6 @@ public: }; -enum class SampleType { - UInt8, - Int16, - Float32, - Mulaw -}; -ALURE_API const char *GetSampleTypeName(SampleType type); - -enum class ChannelConfig { - /** 1-channel mono sound. */ - Mono, - /** 2-channel stereo sound. */ - Stereo, - /** 2-channel rear sound (back-left and back-right). */ - Rear, - /** 4-channel surround sound. */ - Quad, - /** 5.1 surround sound. */ - X51, - /** 6.1 surround sound. */ - X61, - /** 7.1 surround sound. */ - X71, - /** 3-channel B-Format, using FuMa channel ordering and scaling. */ - BFormat2D, - /** 4-channel B-Format, using FuMa channel ordering and scaling. */ - BFormat3D -}; -ALURE_API const char *GetChannelConfigName(ChannelConfig cfg); - -ALURE_API ALuint FramesToBytes(ALuint frames, ChannelConfig chans, SampleType type); -ALURE_API ALuint BytesToFrames(ALuint bytes, ChannelConfig chans, SampleType type); - enum class BufferLoadStatus { Pending, Ready diff --git a/src/buffer.cpp b/src/buffer.cpp index 9d7f454..4774b8d 100644 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -299,9 +299,7 @@ ALenum GetFormat(ChannelConfig chans, SampleType type) } #undef RETURN_FMT - std::stringstream sstr; - sstr<< "Format not supported ("< ALContext::createDecoder(const String &name) } +bool ALContext::isSupported(ChannelConfig channels, SampleType type) const +{ + return GetFormat(channels, type) != AL_NONE; +} + + Buffer *ALContext::getBuffer(const String &name) { CheckContext(this); @@ -529,6 +535,12 @@ Buffer *ALContext::getBuffer(const String &name) // Get the format before calling the bufferLoading message handler, to // ensure it's something OpenAL can handle. ALenum format = GetFormat(chans, type); + if(format == AL_NONE) + { + std::stringstream sstr; + sstr<< "Format not supported ("<bufferLoading(name, chans, type, srate, data); @@ -578,6 +590,12 @@ Buffer *ALContext::getBufferAsync(const String &name) if(!frames) throw std::runtime_error("No samples for buffer"); ALenum format = GetFormat(chans, type); + if(format == AL_NONE) + { + std::stringstream sstr; + sstr<< "Format not supported ("< createDecoder(const String &name) override final; + bool isSupported(ChannelConfig channels, SampleType type) const override final; + Buffer *getBuffer(const String &name) override final; Buffer *getBufferAsync(const String &name) override final; void removeBuffer(const String &name) override final; diff --git a/src/source.cpp b/src/source.cpp index ced4ce1..688cb36 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -83,9 +84,15 @@ public: mLoopPts.second = std::numeric_limits::max(); } - mFormat = GetFormat(chans, type); mFrequency = srate; mFrameSize = FramesToBytes(1, chans, type); + mFormat = GetFormat(chans, type); + if(mFormat == AL_NONE) + { + std::stringstream sstr; + sstr<< "Format not supported ("<