TDME2 1.9.121
AudioBufferManager.cpp
Go to the documentation of this file.
2
3#include <string>
4#include <unordered_map>
5
6#include <tdme/tdme.h>
7#include <tdme/audio/Audio.h>
10
11using std::string;
12using std::unordered_map;
13
18
19AudioBufferManager::AudioBufferManager()
20{
21}
22
24{
25 // check if we already manage this audio buffer
26 auto audioBufferManagedIt = audioBuffers.find(id);
27 AudioBufferManager_AudioBufferManaged* audioBufferManaged = audioBufferManagedIt != audioBuffers.end()?audioBufferManagedIt->second:nullptr;
28 if (audioBufferManaged != nullptr) {
29 audioBufferManaged->incrementReferenceCounter();
30 // yep, return buffer
31 return audioBufferManaged;
32 }
33 // not yet, create managed audio buffer with no AL id attached yet
34 audioBufferManaged = new AudioBufferManager_AudioBufferManaged(this, id, Audio::ALBUFFERID_NONE);
35 audioBufferManaged->incrementReferenceCounter();
36 // add it to our audioBuffers
37 audioBuffers[audioBufferManaged->getId()] = audioBufferManaged;
38 // return audio buffer
39 return audioBufferManaged;
40}
41
43{
44 auto audioBufferManagedIt = audioBuffers.find(id);
45 AudioBufferManager_AudioBufferManaged* audioBufferManaged = audioBufferManagedIt != audioBuffers.end()?audioBufferManagedIt->second:nullptr;
46 if (audioBufferManaged != nullptr) {
47 if (audioBufferManaged->decrementReferenceCounter()) {
48 // remove from our list
49 audioBuffers.erase(audioBufferManagedIt);
50 delete audioBufferManaged;
51 // report to called that this audio buffer can be removed
52 return true;
53 } else {
54 return false;
55 }
56 }
57 // should never happen
58 Console::println(string("Warning: audio buffer not loaded by audio buffer manager"));
59 return false;
60}
bool removeAudioBuffer(const string &id)
Removes a texture from manager / open gl stack.
unordered_map< string, AudioBufferManager_AudioBufferManaged * > audioBuffers
friend class AudioBufferManager_AudioBufferManaged
AudioBufferManager_AudioBufferManaged * addAudioBuffer(const string &id)
Adds a audio buffer to manager / open al stack.
Interface to audio module.
Definition: Audio.h:30
static constexpr int32_t ALBUFFERID_NONE
Definition: Audio.h:36
Console class.
Definition: Console.h:26