Cafu Engine
BufferManager.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_SOUNDSYS_BUFFER_MANAGER_HPP_INCLUDED
8 #define CAFU_SOUNDSYS_BUFFER_MANAGER_HPP_INCLUDED
9 
10 #include "../SoundShader.hpp" // For LoadTypeE.
11 #include "Templates/Array.hpp"
12 
13 #include <string>
14 
15 
16 class BufferT;
17 
18 
19 /// This class efficiently manages audio buffers by employing resource sharing whenever possible.
21 {
22  public:
23 
24  /// Returns the BufferManagerTs singleton instance.
25  static BufferManagerT* GetInstance();
26 
27  /// This method obtains a BufferT instance for the specified resource (a file or a capture device).
28  /// When the user code is done with the returned buffer, it must call ReleaseBuffer() in order to release the buffer.
29  /// (The implementation can return a newly created or a reference-counted BufferT instance for resource sharing.)
30  ///
31  /// @param ResName The name of the resource (file or capture device) that the requested buffer is for (i.e. created from).
32  /// @param ForceMono Whether the data from the resource should be reduced to a single channel before use (mono output).
33  /// @param LoadType The type of buffer that should handle the resource (see SoundShaderT for more details).
34  ///
35  /// @returns a BufferT instance for the specified resource. Throws an exception of type std::runtime_error on failure.
36  BufferT* GetBuffer(const std::string& ResName, bool ForceMono, SoundShaderT::LoadTypeE LoadType);
37 
38  /// Updates all buffers.
39  void UpdateAll();
40 
41  /// Releases a buffer.
42  /// Internally, the released buffer may or may not be completely deleted from memory, depending on its reference count.
43  /// @param Buffer The buffer to release.
44  void ReleaseBuffer(BufferT* Buffer);
45 
46  /// Releases all buffers.
47  void ReleaseAll();
48 
49 
50  private:
51 
52  /// Private constructor for singleton pattern.
54 
55  /// The destructor.
56  ~BufferManagerT();
57 
58  /// Deletes all buffers that have no references left and are thus unused.
59  void CleanUp();
60 
61  ArrayT<BufferT*> m_Buffers; ///< The set of buffers currently known to and managed by the buffer manager.
62 };
63 
64 #endif
This class efficiently manages audio buffers by employing resource sharing whenever possible...
Definition: BufferManager.hpp:20
void ReleaseAll()
Releases all buffers.
Definition: BufferManager.cpp:156
BufferT * GetBuffer(const std::string &ResName, bool ForceMono, SoundShaderT::LoadTypeE LoadType)
This method obtains a BufferT instance for the specified resource (a file or a capture device)...
Definition: BufferManager.cpp:42
A BufferT encapsulates an audio resource such as a file or a capture device.
Definition: Buffer.hpp:22
void UpdateAll()
Updates all buffers.
Definition: BufferManager.cpp:135
static BufferManagerT * GetInstance()
Returns the BufferManagerTs singleton instance.
Definition: BufferManager.cpp:22
void ReleaseBuffer(BufferT *Buffer)
Releases a buffer.
Definition: BufferManager.cpp:126
LoadTypeE
Determines how a sound file is loaded into memory.
Definition: SoundShader.hpp:34