| 60 | // Load audio data from binary asset content |
| 61 | // |
| 62 | bool AudioAsset::LoadFromMemory(std::vector<uint8> const& data) |
| 63 | { |
| 64 | std::string extension = core::FileUtil::ExtractExtension(GetName()); |
| 65 | |
| 66 | bool dataLoaded = false; |
| 67 | AudioBufferData bufferData; |
| 68 | |
| 69 | if (extension == "wav") |
| 70 | { |
| 71 | dataLoaded = LoadWavFile(bufferData, data); |
| 72 | } |
| 73 | else if (extension == "ogg") |
| 74 | { |
| 75 | dataLoaded = LoadOggFile(bufferData, data); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | LOG("AudioAsset::LoadFromMemory > Cannot load audio data with this extension! Supported exensions: [.wav/.ogg]", core::LogLevel::Warning); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | if (!dataLoaded) |
| 84 | { |
| 85 | LOG("AudioAsset::LoadFromMemory > Failed to load audio buffer data!", core::LogLevel::Warning); |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | if (m_IsMonoForced) |
| 90 | { |
| 91 | ConvertToMono(bufferData); |
| 92 | } |
| 93 | |
| 94 | ALuint buffer; |
| 95 | alGenBuffers(1, &buffer); |
| 96 | alBufferData(buffer, bufferData.format, bufferData.data, bufferData.size, bufferData.frequency); |
| 97 | |
| 98 | if (AudioManager::GetInstance()->TestALError("Audio Loader alBufferData error")) |
| 99 | { |
| 100 | LOG("AudioAsset::LoadFromMemory > Failed - open AL error!", core::LogLevel::Warning); |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | delete[] bufferData.data; |
| 105 | |
| 106 | m_Data = new AudioData(buffer); |
| 107 | |
| 108 | // all done |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | //--------------------------------- |
| 113 | // AudioAsset::LoadWavFile |
nothing calls this directly
no test coverage detected