FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
soundemitter.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 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_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
36 
37 #include "soundclip.h"
38 
39 namespace FIFE {
40 
49  };
50 
54  public:
55  virtual ~SoundEmitterListener() {};
56 
61  virtual void onSoundFinished(uint32_t emitterId, uint32_t soundClipId) = 0;
62  };
63 
64  class SoundEffect;
65  class SoundFilter;
66  class SoundManager;
67 
70  class SoundEmitter {
71  public:
72 
73  SoundEmitter(SoundManager* manager, uint32_t uid);
74  ~SoundEmitter();
75 
78  void setSource(ALuint source);
79 
82  ALuint getSource() const;
83 
86  bool isActive() const;
87 
90  void update();
91 
94  uint32_t getId() const;
95 
102  void setRelativePositioning(bool relative);
103 
106  bool isRelativePositioning() const;
107 
111  void setReferenceDistance(float distance);
112 
115  float getReferenceDistance() const;
116 
120  void setMaxDistance(float distance);
121 
124  float getMaxDistance() const;
125 
130  void setRolloff(float rolloff);
131 
134  float getRolloff() const;
135 
139  void setSoundClip(SoundClipPtr soundClip);
140 
144  SoundClipPtr getSoundClip();
145 
149  void setSoundClip(const std::string& name);
150 
155  void reset(bool defaultall = false);
156 
159  void release();
160 
163  void setLooping(bool loop);
164 
167  bool isLooping() const;
168 
171  void play();
172 
175  void play(float inTime, float outTime);
176 
179  void stop();
180 
183  void stop(float time);
184 
187  void pause();
188 
191  void rewind();
192 
197  void setGain(float gain);
198 
203  float getGain() const;
204 
209  void setMaxGain(float gain);
210 
215  float getMaxGain() const;
216 
221  void setMinGain(float gain);
222 
227  float getMinGain() const;
228 
233  bool isStereo();
234 
237  int16_t getBitResolution();
238 
241  uint64_t getSampleRate();
242 
245  uint64_t getDecodedLength();
246 
249  uint64_t getDuration();
250 
253  uint32_t getPlayTimestamp();
254 
257  bool isFinished();
258 
261  void setCursor(SoundPositionType type, float value);
262 
265  float getCursor(SoundPositionType type);
266 
269  void setPosition(const AudioSpaceCoordinate& position);
270 
273  AudioSpaceCoordinate getPosition() const;
274 
277  bool isPosition() const;
278 
281  void setDirection(const AudioSpaceCoordinate& direction);
282 
285  AudioSpaceCoordinate getDirection() const;
286 
289  void setPitch(float pitch);
290 
293  float getPitch() const;
294 
297  void setVelocity(const AudioSpaceCoordinate& velocity);
298 
301  AudioSpaceCoordinate getVelocity() const;
302 
305  void setConeInnerAngle(float inner);
306 
309  float getConeInnerAngle() const;
310 
313  void setConeOuterAngle(float outer);
314 
317  float getConeOuterAngle() const;
318 
321  void setConeOuterGain(float gain);
322 
325  float getConeOuterGain() const;
326 
329  SoundStateType getState();
330 
333  void setGroup(const std::string& group);
334 
337  const std::string& getGroup();
338 
341  void addEffect(SoundEffect* effect);
342 
345  void removeEffect(SoundEffect* effect);
346 
349  uint8_t getEffectCount();
350 
353  uint8_t getEffectNumber(SoundEffect* effect);
354 
357  void setDirectFilter(SoundFilter* filter);
358 
361  SoundFilter* getDirectFilter();
362 
365  void activateEffects();
366 
369  void deactivateEffects();
370 
373  void setCheckDifference();
374 
378  void addListener(SoundEmitterListener* listener);
379 
383  void removeListener(SoundEmitterListener* listener);
384 
385  private:
388  void attachSoundClip();
389 
392  void detachSoundClip();
393 
396  void syncData();
397 
400  void checkFade();
401 
404  void resetInternData();
405 
408  void callOnSoundFinished();
409 
413  ALuint m_source;
424 
426  struct internData {
427  float volume;
428  float maxVolume;
429  float minVolume;
430  float refDistance;
431  float maxDistance;
432  float rolloff;
433  float pitch;
442  bool loop;
443  bool relative;
444  } m_internData;
445 
447  std::string m_group;
451  bool m_active;
453  bool m_fadeIn;
455  bool m_fadeOut;
457  float m_origGain;
469  std::vector<SoundEffect*> m_effects;
471  std::vector<SoundEmitterListener*> m_listeners;
472  };
473 }
474 
475 #endif
uint32_t m_emitterId
The emitter-id.
Definition: soundemitter.h:423
uint32_t m_fadeOutStartTimestamp
fade out start time
Definition: soundemitter.h:463
float m_origGain
original gain
Definition: soundemitter.h:457
std::vector< SoundEffect * > m_effects
holds pointer to applied SoundEffects
Definition: soundemitter.h:469
SoundStateType
State of the audio file.
Definition: soundemitter.h:43
SoundClipPtr m_soundClip
The attached sound clip.
Definition: soundemitter.h:417
std::vector< SoundEmitterListener * > m_listeners
listeners for sound related events
Definition: soundemitter.h:471
bool m_fadeOut
fade out clip
Definition: soundemitter.h:455
uint32_t m_fadeInStartTimestamp
fade in start time
Definition: soundemitter.h:459
uint32_t m_fadeInEndTimestamp
fade in end time
Definition: soundemitter.h:461
Base class for Efx sound effects.
Definition: soundeffect.h:46
The class defines filters.
Definition: soundfilter.h:43
Listener interface for SoundEmitter.
Definition: soundemitter.h:53
uint32_t m_streamId
The id of the stream.
Definition: soundemitter.h:421
AudioSpaceCoordinate direction
Definition: soundemitter.h:438
std::string m_group
the group name
Definition: soundemitter.h:447
bool m_active
is active
Definition: soundemitter.h:451
unsigned char uint8_t
Definition: core.h:38
ALuint m_source
The openAL-source.
Definition: soundemitter.h:413
SoundPositionType
Different types of audio-file positions.
Definition: soundclip.h:44
SoundFilter * m_directFilter
Applied direct sound filter.
Definition: soundemitter.h:415
void removeListener(std::deque< T > &vec, T &listener)
uint32_t m_fadeOutEndTimestamp
fade out end time
Definition: soundemitter.h:465
float m_samplesOffset
saves sample offset for played stream parts
Definition: soundemitter.h:449
void addListener(std::deque< T > &vec, T &listener)
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
Definition: checked.h:198
bool m_fadeIn
fade in clip
Definition: soundemitter.h:453
The class for playing audio files.
Definition: soundemitter.h:70
virtual void onSoundFinished(uint32_t emitterId, uint32_t soundClipId)=0
Called when a sound finished playing.
AudioSpaceCoordinate position
Definition: soundemitter.h:437
uint32_t m_playCheckDifference
time difference between play and first check
Definition: soundemitter.h:467
uint32_t m_soundClipId
Id of the attached sound clip.
Definition: soundemitter.h:419
SoundManager * m_manager
Access to the SoundManager.
Definition: soundemitter.h:411
unsigned int uint32_t
Definition: core.h:40
AudioSpaceCoordinate velocity
Definition: soundemitter.h:439
buffers OpenAL data
Definition: soundemitter.h:426