std::shared_ptr<Sound> System::GetSound(const std::string& id) { if(sounds.find(id) != sounds.end()) { std::shared_ptr<Sound> sound(new Sound); alGenSources(1, &sound->src); if(alGetError() != AL_NO_ERROR) { std::cout << "Failed to create OpenAL source for sound: " << id << std::endl; return nullptr; } // create openal buffer from source sound->buff = alureCreateBufferFromFile(sounds[id]->src.c_str()); if(sound->buff == 0) { std::cout << "Could not load: " << sound->buff << " : " << alureGetErrorString() << std::endl; return nullptr; } alSourcei(sound->src, AL_BUFFER, sound->buff); alSourcei(sound->src, AL_LOOPING, sounds[id]->loop); alSourcef(sound->src, AL_GAIN, sounds[id]->volume); alSourcei(sound->src, AL_SOURCE_RELATIVE, !sounds[id]->spatial); return sound; } return nullptr; }
internal bool32 al_load_sound_file(uint32 *sourceID, uint32 *bufferID, char *filename) { if ((*bufferID = alureCreateBufferFromFile(filename)) == AL_NONE) { al_log(true, "Alure failed to load %s. Alure error: %s\n", filename, alureGetErrorString()); return false; } if (al_print_if_error("AL load sound: Failed to generate audio buffer\n")) return false; alSourcei(*sourceID, AL_BUFFER, *bufferID); if (al_print_if_error("AL load sound: Failed to bind source to buffer\n")) return false; al_set_default_source_values(*sourceID); return true; }