diff --git a/include/libnyquist/AudioDecoder.h b/include/libnyquist/AudioDecoder.h index a9cdd7f..0e9fdcd 100644 --- a/include/libnyquist/AudioDecoder.h +++ b/include/libnyquist/AudioDecoder.h @@ -64,6 +64,7 @@ public: ~NyquistIO(); int Load(AudioData * data, const std::string & path); + int Load(AudioData *data, std::string extension, std::vector & buffer); bool IsFileSupported(const std::string path) const; diff --git a/src/AudioDecoder.cpp b/src/AudioDecoder.cpp index 450590f..3ace882 100644 --- a/src/AudioDecoder.cpp +++ b/src/AudioDecoder.cpp @@ -74,6 +74,35 @@ int NyquistIO::Load(AudioData * data, const std::string & path) return IOError::UnknownError; } +int NyquistIO::Load(AudioData *data, std::string extension, std::vector & buffer) +{ + if (decoderTable.find(extension) == decoderTable.end()) + { + return IOError::ExtensionNotSupported; + } + + if (decoderTable.size() > 0) + { + auto decoder = GetDecoderForExtension(extension); + + try + { + return decoder->LoadFromBuffer(data, buffer); + } + catch (std::exception e) + { + std::cerr << "Caught fatal exception: " << e.what() << std::endl; + } + } + else + { + return IOError::NoDecodersLoaded; + } + + // Should never be reached + return IOError::UnknownError; +} + bool NyquistIO::IsFileSupported(const std::string path) const { auto fileExtension = ParsePathForExtension(path);