comparison engine/core/audio/soundemitter.h @ 173:454ed60ad7b2

* Added a setRoleoff() function to the SoundEmitter class This function sets AL_ROLEOFF_FACTOR. Rolloff factor judges the strength of attenuation over distance. It effect's the volume of the emitter over distance to the listener. You'll have to do plenty of testing to find a good value.
author nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 24 Jan 2009 22:26:46 +0000
parents 90005975cdbb
children 362fe23920b9
comparison
equal deleted inserted replaced
172:3fe0e68f4269 173:454ed60ad7b2
16 * You should have received a copy of the GNU Lesser General Public * 16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the * 17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., * 18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22 #ifndef FIFE_SOUNDEMITTER_H_ 22 #ifndef FIFE_SOUNDEMITTER_H_
23 #define FIFE_SOUNDEMITTER_H_ 23 #define FIFE_SOUNDEMITTER_H_
24 24
25 // Standard C++ library includes 25 // Standard C++ library includes
26 26
39 39
40 namespace FIFE { 40 namespace FIFE {
41 41
42 class SoundManager; 42 class SoundManager;
43 class SoundClipPool; 43 class SoundClipPool;
44 44
45 /** The class for playing audio files 45 /** The class for playing audio files
46 */ 46 */
47 class SoundEmitter : private TimeEvent { 47 class SoundEmitter : private TimeEvent {
48 public: 48 public:
49 SoundEmitter(SoundManager* manager, SoundClipPool* pool, unsigned int uid); 49 SoundEmitter(SoundManager* manager, SoundClipPool* pool, unsigned int uid);
50 50
51 ~SoundEmitter(); 51 ~SoundEmitter();
52 52
53 /** Returns the emitter-id 53 /** Returns the emitter-id
54 */ 54 */
55 unsigned int getID() { 55 unsigned int getID() {
56 return m_emitterid; 56 return m_emitterid;
57 } 57 }
58 58
59 /** Sets Positioning-Type 59 /** Sets Positioning-Type
60 * Default is false 60 * Default is false
61 * 61 *
62 * @param relative If set to true, the emitters position will be interpreted relative to the listener object 62 * @param relative If set to true, the emitters position will be interpreted relative to the listener object
63 * 63 *
64 */ 64 */
65 void setPositioning(bool relative) { 65 void setPositioning(bool relative) {
66 alSourcei(m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE); 66 alSourcei(m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
67 }
68
69 /** Sets the AL_ROLEOFF_FACTOR. Rolloff factor judges the strength of attenuation over distance.
70 *
71 * @param roleoff Roleoff factor. You'll need to do a lot of testing to find a value which suits your needs.
72 */
73 void setRoleoff(float roleoff) {
74 alSourcef (m_source, AL_ROLLOFF_FACTOR, roleoff);
67 } 75 }
68 76
69 /** Sets the sound clip to be used by this emitter. 77 /** Sets the sound clip to be used by this emitter.
70 * @param sound_id SoundClipPool id of the sound to be used. 78 * @param sound_id SoundClipPool id of the sound to be used.
71 */ 79 */
72 void setSoundClip(unsigned int sound_id); 80 void setSoundClip(unsigned int sound_id);
73 81
74 /** Reset the emitter, free all internal buffers 82 /** Reset the emitter, free all internal buffers
75 * 83 *
76 * @param defaultall If set to true, emitter position, velocity, gain and type will be set to the default values 84 * @param defaultall If set to true, emitter position, velocity, gain and type will be set to the default values
77 */ 85 */
78 void reset(bool defaultall = false); 86 void reset(bool defaultall = false);
79 87
80 /** Releases the emitter 88 /** Releases the emitter
81 */ 89 */
82 void release(); 90 void release();
83 91
84 /** Sets the playing mode 92 /** Sets the playing mode
85 */ 93 */
86 void setLooping(bool loop); 94 void setLooping(bool loop);
87 95
88 /** Plays the associated audio file. 96 /** Plays the associated audio file.
89 */ 97 */
90 void play(); 98 void play();
91 99
92 /** Stops playing the audio file and rewinds to the beginning 100 /** Stops playing the audio file and rewinds to the beginning
93 */ 101 */
94 void stop(); 102 void stop();
95 103
96 /** Pauses playing the audio file 104 /** Pauses playing the audio file
97 */ 105 */
98 void pause() { 106 void pause() {
99 if (m_soundclip) { 107 if (m_soundclip) {
100 alSourcePause(m_source); 108 alSourcePause(m_source);
101 } 109 }
102 } 110 }
103 111
104 /** Sets the gain of the emitter 112 /** Sets the gain of the emitter
105 * 113 *
106 * @param gain The gain value. 0=silence ... 1.0=normal loudness. 114 * @param gain The gain value. 0=silence ... 1.0=normal loudness.
107 */ 115 */
108 void setGain(float gain) { 116 void setGain(float gain) {
109 alSourcef(m_source, AL_GAIN, gain); 117 alSourcef(m_source, AL_GAIN, gain);
110 } 118 }
111 119
112 /** Returns the gain of the emitter 120 /** Returns the gain of the emitter
113 * 121 *
114 * @return The gain value. 0=silence ... 1.0=normal loudness. 122 * @return The gain value. 0=silence ... 1.0=normal loudness.
115 */ 123 */
116 float getGain() { 124 float getGain() {
117 float tmp; 125 float tmp;
118 alGetSourcef(m_source, AL_GAIN, &tmp); 126 alGetSourcef(m_source, AL_GAIN, &tmp);
119 return tmp; 127 return tmp;
120 } 128 }
121 129
122 /** Tests if the audio data is stereo data or mono. 130 /** Tests if the audio data is stereo data or mono.
123 * 131 *
124 * @return Returns true if the audio data is stereo, false if mono. 132 * @return Returns true if the audio data is stereo, false if mono.
125 */ 133 */
126 bool isStereo() { 134 bool isStereo() {
127 if (m_soundclip) { 135 if (m_soundclip) {
128 return m_soundclip->getDecoder()->isStereo(); 136 return m_soundclip->getDecoder()->isStereo();
129 } 137 }
130 return false; 138 return false;
131 } 139 }
132 140
133 /** Returns the bit resolution 141 /** Returns the bit resolution
134 */ 142 */
135 short getBitResolution() { 143 short getBitResolution() {
136 if (m_soundclip) { 144 if (m_soundclip) {
137 return m_soundclip->getDecoder()->getBitResolution(); 145 return m_soundclip->getDecoder()->getBitResolution();
138 } 146 }
139 return 0; 147 return 0;
140 } 148 }
141 149
142 /** Returns the sample rate 150 /** Returns the sample rate
143 */ 151 */
144 unsigned long getSampleRate() { 152 unsigned long getSampleRate() {
145 if (m_soundclip) { 153 if (m_soundclip) {
146 return m_soundclip->getDecoder()->getSampleRate(); 154 return m_soundclip->getDecoder()->getSampleRate();
147 } 155 }
148 return 0; 156 return 0;
149 } 157 }
150 158
151 /** Sets the cursor position in the audio file 159 /** Sets the cursor position in the audio file
152 */ 160 */
153 void setCursor(SoundPositionType type, float value); 161 void setCursor(SoundPositionType type, float value);
154 162
155 /** Returns the cursor position in the audio file 163 /** Returns the cursor position in the audio file
156 */ 164 */
157 float getCursor(SoundPositionType type); 165 float getCursor(SoundPositionType type);
158 166
159 /** Sets the position of the SoundEmitter in the virtual audio space. 167 /** Sets the position of the SoundEmitter in the virtual audio space.
160 */ 168 */
161 void setPosition(float x, float y, float z) { 169 void setPosition(float x, float y, float z) {
162 alSource3f(m_source, AL_POSITION, x, y, z); 170 alSource3f(m_source, AL_POSITION, x, y, z);
163 } 171 }
164 172
165 /** Sets the velocity of the SoundEmitter in the virtual audio space. 173 /** Sets the velocity of the SoundEmitter in the virtual audio space.
166 */ 174 */
167 void setVelocity(float x, float y, float z) { 175 void setVelocity(float x, float y, float z) {
168 alSource3f(m_source, AL_VELOCITY, x, y, z); 176 alSource3f(m_source, AL_VELOCITY, x, y, z);
169 } 177 }
170 178
171 private: 179 private:
172 /** Implementation of the pure virtual function from TimeEvent to update streaming 180 /** Implementation of the pure virtual function from TimeEvent to update streaming
173 */ 181 */
174 virtual void updateEvent(unsigned long time); 182 virtual void updateEvent(unsigned long time);
175 183