| 22 | } |
| 23 | |
| 24 | Sound AudioManager::load(const System::Path& path, LoadPolicy loadPolicy) |
| 25 | { |
| 26 | const std::string filePath = path.find(System::PathType::File); |
| 27 | Debug::Log->debug("<AudioManager> Loading Audio at '{}'", filePath); |
| 28 | if (filePath.empty()) |
| 29 | { |
| 30 | throw Exceptions::AudioFileNotFound( |
| 31 | path.toString(), System::MountablePath::StringPaths(), EXC_INFO); |
| 32 | } |
| 33 | |
| 34 | if (loadPolicy == LoadPolicy::Cache && m_cache.find(filePath) == m_cache.end()) |
| 35 | { |
| 36 | std::shared_ptr<SoLoud::Wav> sample = std::make_shared<SoLoud::Wav>(); |
| 37 | sample->load(filePath.c_str()); |
| 38 | m_cache[filePath] = sample; |
| 39 | } |
| 40 | std::shared_ptr<SoLoud::AudioSource> sample; |
| 41 | if (m_cache.find(filePath) != m_cache.end()) |
| 42 | { |
| 43 | sample = m_cache[filePath]; |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | if (loadPolicy == LoadPolicy::Stream) |
| 48 | { |
| 49 | sample = std::make_shared<SoLoud::WavStream>(); |
| 50 | dynamic_cast<SoLoud::WavStream*>(sample.get())->load(filePath.c_str()); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | sample = std::make_shared<SoLoud::Wav>(); |
| 55 | dynamic_cast<SoLoud::Wav*>(sample.get())->load(filePath.c_str()); |
| 56 | } |
| 57 | } |
| 58 | return Sound(m_engine, std::move(sample)); |
| 59 | } |
| 60 | } |