///////////////////////////////////////////////////////
| 76 | |
| 77 | //////////////////////////////////////////////////////////// |
| 78 | std::unique_ptr<SoundFileReader> SoundFileFactory::createReaderFromMemory(const void* data, std::size_t sizeInBytes) |
| 79 | { |
| 80 | // Wrap the memory file into a file stream |
| 81 | MemoryInputStream stream(data, sizeInBytes); |
| 82 | |
| 83 | // Test the stream for all the registered factories |
| 84 | for (const auto& [fpCreate, fpCheck] : getReaderFactoryMap()) |
| 85 | { |
| 86 | if (!stream.seek(0).has_value()) |
| 87 | { |
| 88 | err() << "Failed to seek sound stream" << std::endl; |
| 89 | return nullptr; |
| 90 | } |
| 91 | |
| 92 | if (fpCheck(stream)) |
| 93 | return fpCreate(); |
| 94 | } |
| 95 | |
| 96 | // No suitable reader found |
| 97 | err() << "Failed to open sound file from memory (format not supported)" << std::endl; |
| 98 | return nullptr; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | //////////////////////////////////////////////////////////// |