comparison engine/core/audio/soundemitter.h @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 90005975cdbb
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
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 modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_SOUNDEMITTER_H_
23 #define FIFE_SOUNDEMITTER_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 "vfs/raw/rawdata.h"
36 #include "util/time/timeevent.h"
37
38 #include "soundclip.h"
39
40 namespace FIFE {
41
42 class SoundManager;
43 class SoundClipPool;
44
45 /** The class for playing audio files
46 */
47 class SoundEmitter : private TimeEvent {
48 public:
49 SoundEmitter(SoundManager* manager, SoundClipPool* pool, unsigned int uid);
50
51 ~SoundEmitter();
52
53 /** Returns the emitter-id
54 */
55 unsigned int getID() {
56 return m_emitterid;
57 }
58
59 /** Sets Positioning-Type
60 * Default is false
61 *
62 * @param relative If set to true, the emitters position will be interpreted relative to the listener object
63 *
64 */
65 void setPositioning(bool relative) {
66 alSourcei(m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
67 }
68
69 /** Sets the sound clip to be used by this emitter.
70 * @param sound_id SoundClipPool id of the sound to be used.
71 */
72 void setSoundClip(unsigned int sound_id);
73
74 /** Reset the emitter, free all internal buffers
75 *
76 * @param defaultall If set to true, emitter position, velocity, gain and type will be set to the default values
77 */
78 void reset(bool defaultall = false);
79
80 /** Releases the emitter
81 */
82 void release();
83
84 /** Sets the playing mode
85 */
86 void setLooping(bool loop);
87
88 /** Plays the associated audio file.
89 */
90 void play();
91
92 /** Stops playing the audio file and rewinds to the beginning
93 */
94 void stop();
95
96 /** Pauses playing the audio file
97 */
98 void pause() {
99 if (m_soundclip) {
100 alSourcePause(m_source);
101 }
102 }
103
104 /** Sets the gain of the emitter
105 *
106 * @param gain The gain value. 0=silence ... 1.0=normal loudness.
107 */
108 void setGain(float gain) {
109 alSourcef(m_source, AL_GAIN, gain);
110 }
111
112 /** Returns the gain of the emitter
113 *
114 * @return The gain value. 0=silence ... 1.0=normal loudness.
115 */
116 float getGain() {
117 float tmp;
118 alGetSourcef(m_source, AL_GAIN, &tmp);
119 return tmp;
120 }
121
122 /** Tests if the audio data is stereo data or mono.
123 *
124 * @return Returns true if the audio data is stereo, false if mono.
125 */
126 bool isStereo() {
127 if (m_soundclip) {
128 return m_soundclip->getDecoder()->isStereo();
129 }
130 return false;
131 }
132
133 /** Returns the bit resolution
134 */
135 short getBitResolution() {
136 if (m_soundclip) {
137 return m_soundclip->getDecoder()->getBitResolution();
138 }
139 return 0;
140 }
141
142 /** Returns the sample rate
143 */
144 unsigned long getSampleRate() {
145 if (m_soundclip) {
146 return m_soundclip->getDecoder()->getSampleRate();
147 }
148 return 0;
149 }
150
151 /** Sets the cursor position in the audio file
152 */
153 void setCursor(SoundPositionType type, float value);
154
155 /** Returns the cursor position in the audio file
156 */
157 float getCursor(SoundPositionType type);
158
159 /** Sets the position of the SoundEmitter in the virtual audio space.
160 */
161 void setPosition(float x, float y, float z) {
162 alSource3f(m_source, AL_POSITION, x, y, z);
163 }
164
165 /** Sets the velocity of the SoundEmitter in the virtual audio space.
166 */
167 void setVelocity(float x, float y, float z) {
168 alSource3f(m_source, AL_VELOCITY, x, y, z);
169 }
170
171 private:
172 /** Implementation of the pure virtual function from TimeEvent to update streaming
173 */
174 virtual void updateEvent(unsigned long time);
175
176 /** Internal function to attach a soundclip to the source
177 */
178 void attachSoundClip();
179
180 SoundManager* m_manager;
181 SoundClipPool* m_pool;
182 ALuint m_source; // The openAL-source
183 SoundClip* m_soundclip; // the attached soundclip
184 unsigned int m_soundclipid;// id of the attached soundclip
185 unsigned int m_streamid; // the id of the stream
186 unsigned int m_emitterid; // the emitter-id
187 bool m_loop; // loop?
188 };
189 }
190
191 #endif