| 42 | } |
| 43 | |
| 44 | AudioFile* AudioCache::load(String filename) { |
| 45 | std::string fullPath = SharedContent.getFullPath(filename); |
| 46 | auto it = _audioFiles.find(fullPath); |
| 47 | if (it != _audioFiles.end()) { |
| 48 | return it->second; |
| 49 | } |
| 50 | auto data = SharedContent.load(fullPath); |
| 51 | if (!data.first) { |
| 52 | Error("failed to load sound file \"{}\".", filename.toString()); |
| 53 | return nullptr; |
| 54 | } |
| 55 | AudioFile* audioFile = nullptr; |
| 56 | if (shouldStream(filename, data.second)) { |
| 57 | audioFile = WavStream::create(std::move(data.first), data.second); |
| 58 | } else { |
| 59 | audioFile = WavFile::create(std::move(data.first), data.second); |
| 60 | } |
| 61 | if (audioFile) { |
| 62 | _audioFiles[fullPath] = audioFile; |
| 63 | return audioFile; |
| 64 | } else { |
| 65 | Error("failed to load audio file \"{}\".", filename.toString()); |
| 66 | return nullptr; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void AudioCache::loadAsync(String filename, const std::function<void(AudioFile*)>& handler) { |
| 71 | std::string fullPath = SharedContent.getFullPath(filename); |
nothing calls this directly
no test coverage detected