FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
soundmanager.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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  class SoundClipPool;
40 
41  class SoundManager {
42  public:
43 
44  SoundManager(SoundClipPool* pool);
45 
46  ~SoundManager();
47 
50  void init();
51 
57  SoundEmitter* getEmitter(unsigned int emitterid) const;
58 
61  SoundEmitter* createEmitter();
62 
65  void releaseEmitter(unsigned int emitterid);
66 
69  ALCcontext* getContext() const {
70  return m_context;
71  }
72 
77  void setVolume(float vol) {
78  if (m_device == NULL) {
79  m_volume = vol;
80  }
81  alListenerf(AL_GAIN, vol);
82  }
83 
86  float getVolume() const{
87  return m_volume;
88  }
89 
92  void mute() {
93  alGetListenerf(AL_GAIN, &m_mutevol);
94  alListenerf(AL_GAIN, 0);
95  }
96 
99  void unmute() {
100  alListenerf(AL_GAIN, m_mutevol);
101  }
102 
105  void setListenerPosition(float x, float y, float z) {
106  alListener3f(AL_POSITION, x, y, z);
107  }
108 
111  void setListenerOrientation(float x, float y, float z) {
112  ALfloat vec[6] = { x, y, z, 0.0, 0.0, 1.0};
113  alListenerfv(AL_ORIENTATION, vec);
114  }
115 
118  void setListenerVelocity(float x, float y, float z);
119 
122  bool isActive() const{
123  return m_device != NULL;
124  }
125 
126  private:
127 
128  std::vector<SoundEmitter*> m_emittervec; // emitter-vector
129  ALCcontext* m_context; // OpenAL context
130  ALCdevice* m_device; // OpenAL device
131  SoundClipPool* m_pool;
132  float m_mutevol; // volume before mute() was called
133  float m_volume; // volume to support setVolume-calls before initialization
134  };
135 }
136 #endif