FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
soundmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_SOUNDMANAGER_H
23 #define FIFE_SOUNDMANAGER_H
24 
25 // Standard C++ library includes
26 
27 // Platform specific includes
28 
29 // 3rd party library includes
30 
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "fife_openal.h"
36 
37 namespace FIFE {
38  class SoundEmitter;
39 
40  class SoundManager {
41  public:
42 
43  SoundManager();
44 
45  ~SoundManager();
46 
49  void init();
50 
56  SoundEmitter* getEmitter(uint32_t emitterid) const;
57 
61 
64  void releaseEmitter(uint32_t emitterid);
65 
68  ALCcontext* getContext() const {
69  return m_context;
70  }
71 
76  void setVolume(float vol) {
77  if (m_device == NULL) {
78  m_volume = vol;
79  }
80  alListenerf(AL_GAIN, vol);
81  }
82 
85  float getVolume() const{
86  return m_volume;
87  }
88 
91  void mute() {
92  alGetListenerf(AL_GAIN, &m_mutevol);
93  alListenerf(AL_GAIN, 0);
94  }
95 
98  void unmute() {
99  alListenerf(AL_GAIN, m_mutevol);
100  }
101 
104  void setListenerPosition(float x, float y, float z) {
105  alListener3f(AL_POSITION, x, y, z);
106  }
107 
110  void setListenerOrientation(float x, float y, float z) {
111  ALfloat vec[6] = { x, y, z, 0.0, 0.0, 1.0};
112  alListenerfv(AL_ORIENTATION, vec);
113  }
114 
117  void setListenerVelocity(float x, float y, float z);
118 
121  bool isActive() const{
122  return m_device != NULL;
123  }
124 
125  private:
126 
127  std::vector<SoundEmitter*> m_emittervec; // emitter-vector
128  ALCcontext* m_context; // OpenAL context
129  ALCdevice* m_device; // OpenAL device
130  float m_mutevol; // volume before mute() was called
131  float m_volume; // volume to support setVolume-calls before initialization
132  };
133 }
134 #endif
void unmute()
Unmutes to volume before mute() was called.
Definition: soundmanager.h:98
SoundEmitter * createEmitter()
Returns a pointer to an allocated emitter-instance.
bool isActive() const
Returns true if audio module is active.
Definition: soundmanager.h:121
ALCcontext * m_context
Definition: soundmanager.h:128
float getVolume() const
Return the Master Volume.
Definition: soundmanager.h:85
void init()
Initializes the audio system.
void setVolume(float vol)
Sets the Master Volume.
Definition: soundmanager.h:76
ALCdevice * m_device
Definition: soundmanager.h:129
void setListenerPosition(float x, float y, float z)
Sets the position of the listener (alter ego).
Definition: soundmanager.h:104
The class for playing audio files.
Definition: soundemitter.h:46
void setListenerOrientation(float x, float y, float z)
Sets the orientation of the listener (alter ego).
Definition: soundmanager.h:110
std::vector< SoundEmitter * > m_emittervec
Definition: soundmanager.h:127
void setListenerVelocity(float x, float y, float z)
Sets the velocity of the listener (alter ego).
unsigned int uint32_t
Definition: core.h:40
ALCcontext * getContext() const
Returns an openAL context.
Definition: soundmanager.h:68
void releaseEmitter(uint32_t emitterid)
Release an emitter-instance given by emitter-id.
SoundEmitter * getEmitter(uint32_t emitterid) const
Returns a pointer to an emitter-instance given by emitterid.
void mute()
Mute.
Definition: soundmanager.h:91