AnnAudioEngine.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include "systemMacro.h"
12 
13 //C++ stdlib
14 #include <iostream>
15 #include <string>
16 #include <unordered_map>
17 #include <memory>
18 
19 //OpenAl
20 #include <al.h>
21 #include <alc.h>
22 
23 //libsndfile
24 #include <sndfile.h>
25 
26 //Other Annwvyn
27 #include "AnnTypes.h"
28 #include "AnnSubsystem.hpp"
29 #include "AnnAudioFile.hpp"
30 
31 namespace Annwvyn
32 {
33  class AnnEngine;
34  class AnnAudioEngine;
35 
38  {
39  public:
42 
44  ~AnnAudioSource();
45 
47  void setPositon(AnnVect3 position);
50  void setVolume(float gain) const;
52  void rewind() const;
54  void play() const;
56  void pause() const;
58  void stop() const;
60  void changeSound(std::string name);
61 
63  void setLooping(bool looping = true) const;
65  void setPositionRelToPlayer(bool relToPlayer = true);
66 
67  private:
68  friend class AnnAudioEngine;
72  ALuint source;
77  };
78 
80 
83  {
84  public:
87 
89  ~AnnAudioEngine();
90 
92  bool initOpenAL();
93 
95  void shutdownOpenAL();
96 
102  ALuint loadBuffer(const std::string& filename);
103 
110  void preLoadBuffer(const std::string& filename);
111 
113  ALuint isBufferLoader(const std::string& filename);
114 
117  void unloadBuffer(const std::string& filename);
118 
122  void playBGM(const std::string& filename, float volume = 0.5f);
123 
125  void stopBGM() const;
126 
128  std::string getLastError() const;
129 
131  AnnAudioSourcePtr createSource();
132 
134  AnnAudioSourcePtr createSource(std::string name);
135 
137  void removeSource(AnnAudioSourcePtr source);
138 
140  void logError() const;
141 
142  private:
145  void updateListenerPos(AnnVect3 pos);
146 
149  static void updateListenerOrient(AnnQuaternion orient);
150 
152  friend class AnnEngine;
153 
155  void update() override;
156 
158  void detectPlaybackDevices(const char* list);
159 
163  ALCdevice* alDevice;
165  ALCcontext* alContext;
166 
168  ALuint bgmBuffer;
170  ALuint bgmSource;
171 
174 
176  bool locked;
179 
184  };
185 
187 }
ALCdevice * alDevice
AL alDevice.
std::unordered_map< std::string, ALuint > buffers
Map between audio filenames and OpenAL buffer.
file for defining macros used for symbol export regarding the way the OS does things.
ALuint source
OpenAL source object.
Main engine class. Creating an instance of this class make the engine start.
Definition: AnnEngine.hpp:70
A 3D Vector.
Definition: AnnVect3.hpp:16
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
std::string lastError
The last error this class has generated.
ALuint bgmSource
Audio source for background music.
Class that handle the OpenAL audio.
bool locked
Prevent some operation if set to true.
AnnAudioFileManager * audioFileManager
Custom Ogre resource manager that loads binary files used to load audio files.
std::list< AnnAudioSourcePtr > audioSources
List of the audio sources object present in the audio engine.
Audio file ResourceManager.
Represent a Quaternion.
ALuint bgmBuffer
Audio buffer for background music.
Parent class of all Annwvyn SubSystem.
std::string bufferName
Name of the buffer (filename)
Represent an audio source in the engine.
Data types definition for Annwvyn.
#define AnnDllExport
Definition: systemMacro.h:24
AnnVect3 pos
Position of this source.
std::vector< std::string > detectedDevices
List of audio device names.
ALCcontext * alContext
AL Context.
bool posRelToPlayer
Relative to player, or not.