FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
soundemitter.cpp
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 // Standard C++ library includes
23 #include <algorithm>
24 
25 // Platform specific includes
26 
27 // 3rd party library includes
28 
29 // FIFE includes
30 // These includes are split up in two parts, separated by one empty line
31 // First block: files included from the FIFE root src directory
32 // Second block: files included from the same folder
33 #include "util/log/logger.h"
34 #include "util/base/exception.h"
35 #include "util/time/timemanager.h"
36 
37 #include "soundemitter.h"
38 #include "soundmanager.h"
39 #include "soundclipmanager.h"
40 
41 namespace FIFE {
42  static Logger _log(LM_AUDIO);
43 
45  m_manager(manager),
46  m_source(0),
47  m_directFilter(NULL),
48  m_soundClip(),
49  m_soundClipId(0),
50  m_streamId(0),
51  m_emitterId(uid),
52  m_group(""),
53  m_samplesOffset(0),
54  m_active(false),
55  m_fadeIn(false),
56  m_fadeOut(false),
57  m_origGain(0.0f),
58  m_fadeInStartTimestamp(0),
59  m_fadeInEndTimestamp(0),
60  m_fadeOutStartTimestamp(0),
61  m_fadeOutEndTimestamp(0),
62  m_playCheckDifference(0) {
63 
64  if (!m_manager->isActive()) {
65  return;
66  }
67 
69  }
70 
72  if (!m_manager->isActive()) {
73  return;
74  }
75 
76  reset();
77  }
78 
79  void SoundEmitter::setSource(ALuint source) {
80  if (!source && m_source) {
81  alSourceStop(m_source);
82 
83  // Release all buffers
84  alSourcei(m_source, AL_BUFFER, AL_NONE);
85  alGetError();
86 
88  }
89  m_source = source;
90  if (m_source > 0) {
91  m_active = true;
93  syncData();
94  } else {
95  m_active = false;
96  }
97  }
98 
99  ALuint SoundEmitter::getSource() const {
100  return m_source;
101  }
102 
103  bool SoundEmitter::isActive() const {
104  return m_active;
105  }
106 
109  return;
110  }
111  if (m_fadeIn || m_fadeOut) {
112  checkFade();
113  }
114  // non streaming
115  if (!m_soundClip->isStream()) {
116  if (getState() == SD_STOPPED_STATE) {
117  stop();
118  }
119  return;
120  }
121 
122  ALint procs;
123  ALint bufs;
124  ALuint buffer;
125  alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &procs);
126 
127  while (procs--) {
128  // needed for correct cursor position
129  float samplesOffset, newOffset;
130  alGetSourcef(m_source, AL_SAMPLE_OFFSET, &samplesOffset);
131 
132  alSourceUnqueueBuffers(m_source, 1, &buffer);
133 
134  alGetSourcef(m_source, AL_SAMPLE_OFFSET, &newOffset);
135  m_samplesOffset += (samplesOffset - newOffset);
136 
137  if (m_soundClip->getStream(m_streamId, buffer)) {
138  // EOF!
139  if (m_internData.loop) {
140  // play again from the beginning
142  m_soundClip->getStream(m_streamId, buffer);
143  } else {
144  // check if the playback has been finished
145  alGetSourcei(m_source, AL_BUFFERS_QUEUED, &bufs);
146  if (bufs == 0) {
147  stop();
148  }
149  continue;
150  }
151  }
152  alSourceQueueBuffers(m_source, 1, &buffer);
153  }
154 
155  CHECK_OPENAL_LOG(_log, LogManager::LEVEL_ERROR, "error while streaming")
156  }
157 
159  return m_emitterId;
160  }
161 
163  if (isActive()) {
164  alSourcei(m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
165  }
166  m_internData.relative = relative;
167  }
168 
170  return m_internData.relative;
171  }
172 
174  if (isActive()) {
175  ALfloat vec[3] = { static_cast<ALfloat>(direction.x), static_cast<ALfloat>(direction.y), static_cast<ALfloat>(direction.z) };
176  alSourcefv(m_source, AL_DIRECTION, vec);
177  }
178  m_internData.direction = direction;
179  }
180 
182  return m_internData.direction;
183  }
184 
185  void SoundEmitter::setPitch(float pitch) {
186  if (pitch > 0.0) {
187  if (isActive()) {
188  alSourcef(m_source, AL_PITCH, pitch);
189  }
190  m_internData.pitch = pitch;
191  }
192  }
193 
194  float SoundEmitter::getPitch() const {
195  return m_internData.pitch;
196  }
197 
198  void SoundEmitter::setRolloff(float rolloff) {
199  if (isActive()) {
200  alSourcef(m_source, AL_ROLLOFF_FACTOR, rolloff);
201  }
202  m_internData.rolloff = rolloff;
203  }
204 
205  float SoundEmitter::getRolloff() const {
206  return m_internData.rolloff;
207  }
208 
209  void SoundEmitter::reset(bool defaultall) {
210  // remove effects and filter
211  if (m_directFilter) {
213  }
214  std::vector<SoundEffect*>effects = m_effects;
215  for (std::vector<SoundEffect*>::iterator it = effects.begin(); it != effects.end(); ++it) {
216  if (*it) {
218  }
219  }
220  // release buffer and source handle
221  if (isActive()) {
222  alSourceStop(m_source);
223  alSourcei(m_source, AL_BUFFER, AL_NONE);
224  alGetError();
225  m_manager->releaseSource(this);
226  }
227  // reset clip
228  if (m_soundClip) {
229  if (m_soundClip->isStream()) {
231  m_streamId = 0;
232  }
233  m_soundClipId = 0;
234  // release the soundClip
235  //SoundClipManager::instance()->free(m_soundClipId);
236  m_soundClip.reset();
237  }
238 
239  // default source properties
240  if (defaultall) {
241  resetInternData();
242  if (isActive()) {
243  syncData();
244  }
245  }
246 
247  if (m_group != "") {
248  m_manager->removeFromGroup(this);
249  m_group = "";
250  }
251  m_samplesOffset = 0;
252  m_fadeIn = false;
253  m_fadeOut = false;
254  m_origGain = 0;
255  }
256 
259  }
260 
262  // equal clip
263  if (m_soundClipId == soundClip->getHandle()) {
264  return;
265  }
266 
267  detachSoundClip();
268  m_soundClipId = soundClip->getHandle();
269  m_soundClip = soundClip;
270 
271  attachSoundClip();
272  }
273 
275  return m_soundClip;
276  }
277 
278  void SoundEmitter::setSoundClip(const std::string& name) {
280  setSoundClip(clip);
281  }
282 
284  if (!m_soundClip->isStream()) {
285  if (!isActive()) {
286  return;
287  }
288  // non-streaming
289  alSourceQueueBuffers(m_source, m_soundClip->countBuffers(), m_soundClip->getBuffers());
290  alSourcei(m_source, AL_LOOPING, m_internData.loop ? AL_TRUE : AL_FALSE);
291 
292  } else {
293  // streaming
296  if (!isActive()) {
297  return;
298  }
299  // queue initial buffers
300  alSourceQueueBuffers(m_source, BUFFER_NUM, m_soundClip->getBuffers(m_streamId));
301  alSourcei(m_source, AL_LOOPING, AL_FALSE);
302  }
303 
304  CHECK_OPENAL_LOG(_log, LogManager::LEVEL_ERROR, "error attaching sound clip")
305  }
306 
308  if (!m_soundClip) {
309  return;
310  }
311  SoundStateType state = getState();
312  if (state == SD_PLAYING_STATE || state == SD_PAUSED_STATE) {
313  stop();
314  }
315  if (isActive()) {
316  // detach all buffers
317  alSourcei(m_source, AL_BUFFER, AL_NONE);
318  CHECK_OPENAL_LOG(_log, LogManager::LEVEL_ERROR, "error detaching sound clip");
319  }
320  if (m_soundClip->isStream()) {
322  m_streamId = 0;
323  }
324  m_soundClipId = 0;
325  m_soundClip.reset();
326  }
327 
328  void SoundEmitter::setLooping(bool loop) {
329  if (m_soundClip && isActive()) {
330  if (!m_soundClip->isStream()) {
331  alSourcei(m_source, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
332  } else {
333  alSourcei(m_source, AL_LOOPING, AL_FALSE);
334  }
335  }
336  m_internData.loop = loop;
337  }
338 
339  bool SoundEmitter::isLooping() const {
340  return m_internData.loop;
341  }
342 
344  if (m_soundClip && isActive()) {
345  alSourcePlay(m_source);
346  }
349  // resume
351  m_internData.playTimestamp -= static_cast<uint32_t>(getCursor(SD_TIME_POS) * 1000);
352  }
354  }
355 
356  void SoundEmitter::play(float inTime, float outTime) {
357  float zero = 0;
359  if (!Mathf::Equal(zero, inTime)) {
360  m_fadeIn = true;
361  setGain(0.0f);
362  play();
364  m_fadeInEndTimestamp = m_fadeInStartTimestamp + static_cast<uint32_t>(inTime * 1000.0f);
365  }
366  if (getState() != SD_PLAYING_STATE) {
367  play();
368  }
369  if (!Mathf::Equal(zero, outTime)) {
370  m_fadeOut = true;
371  setGain(0.0f);
373  m_fadeOutStartTimestamp = m_fadeOutEndTimestamp - static_cast<uint32_t>(outTime * 1000.0f);
374  }
375  }
376 
378  if (m_soundClip && isActive()) {
379  alSourceStop(m_source);
380  rewind();
381  }
385  }
386 
387  void SoundEmitter::stop(float time) {
388  m_fadeOut = true;
391  m_fadeOutEndTimestamp = m_fadeOutStartTimestamp + static_cast<uint32_t>(time * 1000.0f);
392  }
393 
395  if (m_soundClip && isActive()) {
396  alSourcePause(m_source);
397  }
399  }
400 
403  m_samplesOffset = 0;
404  if (!isActive() || !m_soundClip) {
405  return;
406  }
407  if (m_soundClip->isStream()) {
409  } else {
410  alSourceRewind(m_source);
411  }
412  }
413 
414  void SoundEmitter::setGain(float gain) {
415  if (isActive()) {
416  alSourcef(m_source, AL_GAIN, gain);
417  }
418  m_internData.volume = gain;
419  }
420 
421  float SoundEmitter::getGain() const {
422  return m_internData.volume;
423  }
424 
425  void SoundEmitter::setMaxGain(float gain) {
426  if (isActive()) {
427  alSourcef(m_source, AL_MAX_GAIN, gain);
428  }
429  m_internData.maxVolume = gain;
430  }
431 
432  float SoundEmitter::getMaxGain() const {
433  return m_internData.maxVolume;
434  }
435 
436  void SoundEmitter::setMinGain(float gain) {
437  if (isActive()) {
438  alSourcef(m_source, AL_MIN_GAIN, gain);
439  }
440  m_internData.minVolume = gain;
441  }
442 
443  float SoundEmitter::getMinGain() const {
444  return m_internData.minVolume;
445  }
446 
448  if (m_soundClip) {
449  return m_soundClip->getDecoder()->isStereo();
450  }
451  return false;
452  }
453 
455  if (m_soundClip) {
457  }
458  return 0;
459  }
460 
462  if (m_soundClip) {
463  return m_soundClip->getDecoder()->getSampleRate();
464  }
465  return 0;
466  }
467 
469  if (m_soundClip) {
471  }
472  return 0;
473  }
474 
476  if (m_soundClip) {
477  //convert to milliseconds
478  double samplerate = static_cast<double>(getSampleRate()) / 1000.0;
479  double bitres = static_cast<double>(getBitResolution());
480  // convert to bits
481  double size = static_cast<double>(getDecodedLength()) * 8.0;
482  double stereo = (isStereo() ? 2.0 : 1.0);
483  double time = ( size / (samplerate * bitres) ) / stereo;
484 
485  return static_cast<uint64_t>(time);
486  }
487  return 0;
488  }
489 
492  }
493 
495  if (isLooping()) {
496  return false;
497  }
498  if (isActive()) {
499  return getState() == SD_STOPPED_STATE;
500  }
501  if (getState() == SD_STOPPED_STATE) {
502  return true;
503  }
504  // roughly check, in the case the clip do not plays (is not active)
505  return (m_internData.playTimestamp + m_playCheckDifference + static_cast<uint32_t>(getDuration())) <= TimeManager::instance()->getTime();
506  }
507 
508  void SoundEmitter::setCursor(SoundPositionType type, float value) {
509  if (!m_soundClip || !isActive()) {
510  return;
511  }
512 
513  ALint state = 0;
514 
515  if (!m_soundClip->isStream()) {
516  switch(type) {
517  case SD_BYTE_POS:
518  alSourcef(m_source, AL_BYTE_OFFSET, value);
519  break;
520  case SD_SAMPLE_POS:
521  alSourcef(m_source, AL_SAMPLE_OFFSET, value);
522  break;
523  case SD_TIME_POS:
524  alSourcef(m_source, AL_SEC_OFFSET, value);
525  break;
526  }
527 
528  CHECK_OPENAL_LOG(_log, LogManager::LEVEL_ERROR, "error setting cursor position")
529  } else {
530  switch (type) {
531  case SD_BYTE_POS:
532  m_samplesOffset = value / (getBitResolution() / 8 * (isStereo() ? 2 : 1));
533  break;
534  case SD_SAMPLE_POS:
535  m_samplesOffset = value;
536  break;
537  case SD_TIME_POS:
538  m_samplesOffset = value * getSampleRate();
539  break;
540  }
541  alGetSourcei(m_source, AL_SOURCE_STATE, &state);
542  if (state == AL_PLAYING || state == AL_PAUSED) {
543  alSourceStop(m_source);
544  }
545 
546  m_soundClip->setStreamPos(m_streamId, type, value);
547 
548  // detach all buffers
549  alSourcei(m_source, AL_BUFFER, 0);
550 
551  // queue the buffers with new data
553  alSourceQueueBuffers(m_source, BUFFER_NUM, m_soundClip->getBuffers(m_streamId));
554 
555  if (state == AL_PLAYING) {
556  alSourcePlay(m_source);
557  }
558 
559  CHECK_OPENAL_LOG(_log, LogManager::LEVEL_ERROR, "error setting stream cursor position")
560  }
561  }
562 
564  if (!m_soundClip || !isActive()) {
565  return 0.0f;
566  }
567 
568  ALfloat pos = 0.0f;
569 
570  switch(type) {
571  case SD_BYTE_POS:
572  alGetSourcef(m_source, AL_BYTE_OFFSET, &pos);
573  break;
574  case SD_SAMPLE_POS:
575  alGetSourcef(m_source, AL_SAMPLE_OFFSET, &pos);
576  break;
577  case SD_TIME_POS:
578  alGetSourcef(m_source, AL_SEC_OFFSET, &pos);
579  break;
580  }
581 
582  if (m_soundClip->isStream()) {
583  switch (type) {
584  case SD_BYTE_POS:
585  pos += m_samplesOffset * (getBitResolution() / 8 * (isStereo() ? 2 : 1));
586  break;
587  case SD_SAMPLE_POS:
588  pos += m_samplesOffset;
589  break;
590  case SD_TIME_POS:
591  pos += m_samplesOffset / getSampleRate();
592  break;
593  }
594  }
595 
596  CHECK_OPENAL_LOG(_log, LogManager::LEVEL_ERROR, "error getting cursor")
597 
598  return pos;
599  }
600 
602  if (isActive()) {
603  alSource3f(m_source, AL_POSITION, static_cast<ALfloat>(position.x), static_cast<ALfloat>(position.y), static_cast<ALfloat>(position.z));
604  }
605  m_internData.position = position;
606  }
607 
609  return m_internData.position;
610  }
611 
613  double zero = 0;
615  }
616 
618  if (isActive()) {
619  alSourcef(m_source, AL_REFERENCE_DISTANCE, distance);
620  }
622  }
623 
625  return m_internData.refDistance;
626  }
627 
629  if (isActive()) {
630  alSourcef(m_source, AL_MAX_DISTANCE, distance);
631  }
633  }
634 
636  return m_internData.maxDistance;
637  }
638 
640  if (isActive()) {
641  alSource3f(m_source, AL_VELOCITY, static_cast<ALfloat>(velocity.x), static_cast<ALfloat>(velocity.y), static_cast<ALfloat>(velocity.z));
642  }
643  m_internData.velocity = velocity;
644  }
645 
647  return m_internData.velocity;
648  }
649 
651  if (isActive()) {
652  alSourcef(m_source, AL_CONE_INNER_ANGLE, inner);
653  }
655  }
656 
659  }
660 
662  if (isActive()) {
663  alSourcef(m_source, AL_CONE_OUTER_ANGLE, outer);
664  }
666  }
667 
670  }
671 
673  if (isActive()) {
674  alSourcef(m_source, AL_CONE_OUTER_GAIN, gain);
675  }
677  }
678 
681  }
682 
684  if (!isActive()) {
685  return m_internData.soundState;
686  }
687  ALint state;
688  alGetSourcei(m_source, AL_SOURCE_STATE, &state);
689  switch(state) {
690  case AL_INITIAL:
691  return SD_INITIAL_STATE;
692  break;
693  case AL_PLAYING:
694  return SD_PLAYING_STATE;
695  break;
696  case AL_PAUSED:
697  return SD_PAUSED_STATE;
698  break;
699  case AL_STOPPED:
700  return SD_STOPPED_STATE;
701  break;
702  default:
703  return SD_UNKNOWN_STATE;
704  break;
705  }
706  }
707 
708  void SoundEmitter::setGroup(const std::string& group) {
709  if (group != m_group) {
710  if (m_group != "") {
711  m_manager->removeFromGroup(this);
712  }
713  m_group = group;
714  if (m_group != "") {
715  m_manager->addToGroup(this);
716  }
717  }
718  }
719 
720  const std::string& SoundEmitter::getGroup() {
721  return m_group;
722  }
723 
742  if (m_internData.loop) {
743  timediff = timediff % getDuration();
744  }
745  float time = static_cast<float>(timediff) / 1000.0f;
746  attachSoundClip();
747  setCursor(SD_TIME_POS, time);
748  if (m_soundClip && isActive()) {
750  alSourcePlay(m_source);
751  }
752  }
753  }
754 
756  m_internData.volume = 1.0;
757  m_internData.maxVolume = 1.0;
758  m_internData.minVolume = 0.0;
760  m_internData.maxDistance = 1000000.0;
761  m_internData.rolloff = 1.0;
762  m_internData.pitch = 1.0;
766  m_internData.position = AudioSpaceCoordinate(0.0, 0.0, 0.0);
768  m_internData.velocity = AudioSpaceCoordinate(0.0, 0.0, 0.0);
771  m_internData.loop = false;
772  m_internData.relative = false;
773  }
774 
776  uint32_t timestamp = TimeManager::instance()->getTime();
777  if (m_fadeIn) {
778  float delta = m_origGain / static_cast<float>(m_fadeInEndTimestamp - m_fadeInStartTimestamp);
779  if (timestamp >= m_fadeInEndTimestamp) {
780  m_fadeIn = false;
782  } else {
783  float gain = delta * static_cast<float>(timestamp - m_fadeInStartTimestamp);
784  gain = std::min(gain, m_origGain);
785  setGain(gain);
786  }
787  } else if (m_fadeOut) {
788  float delta = m_origGain / static_cast<float>(m_fadeOutEndTimestamp - m_fadeOutStartTimestamp);
789  if (timestamp >= m_fadeOutEndTimestamp) {
790  m_fadeOut = false;
791  stop();
793  } else {
794  float gain = delta * static_cast<float>(m_fadeOutEndTimestamp - timestamp);
795  gain = std::max(gain, 0.0f);
796  setGain(gain);
797  }
798  }
799  }
800 
802  bool added = false;
803  for (std::vector<SoundEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); ++it) {
804  if (!(*it)) {
805  (*it) = effect;
806  added = true;
807  break;
808  }
809  }
810  if (!added) {
811  m_effects.push_back(effect);
812  }
813  }
814 
816  for (std::vector<SoundEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); ++it) {
817  if (effect == *it) {
818  (*it) = NULL;
819  break;
820  }
821  }
822  }
823 
825  uint8_t counter = 0;
826  for (std::vector<SoundEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); ++it) {
827  if (*it) {
828  ++counter;
829  }
830  }
831  return counter;
832  }
833 
835  uint8_t number = 0;
836  for (std::vector<SoundEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); ++it) {
837  if (effect == *it) {
838  break;
839  }
840  ++number;
841  }
842  return number;
843  }
844 
846  m_directFilter = filter;
847  }
848 
850  return m_directFilter;
851  }
852 
854  for (std::vector<SoundEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); ++it) {
855  if (*it) {
856  m_manager->activateEffect(*it, this);
857  }
858  }
859  if (m_directFilter) {
861  }
862  }
863 
865  for (std::vector<SoundEffect*>::iterator it = m_effects.begin(); it != m_effects.end(); ++it) {
866  if (*it) {
867  m_manager->deactivateEffect(*it, this);
868  }
869  }
870  if (m_directFilter) {
872  }
873  }
874 
878  }
879  }
880 
882  m_listeners.push_back(listener);
883  }
884 
886  std::vector<SoundEmitterListener*>::iterator i = m_listeners.begin();
887  while (i != m_listeners.end()) {
888  if ((*i) == listener) {
889  *i = NULL;
890  return;
891  }
892  ++i;
893  }
894 
895  FL_WARN(_log, "Cannot remove unknown listener");
896  }
897 
899  std::vector<SoundEmitterListener*>::iterator i = m_listeners.begin();
900  for (; i != m_listeners.end(); ++i) {
901  if (*i) {
902  (*i)->onSoundFinished(m_emitterId, m_soundClipId);
903  }
904  }
905  m_listeners.erase(std::remove(m_listeners.begin(), m_listeners.end(), (SoundEmitterListener*)NULL), m_listeners.end());
906  }
907 }
uint32_t getPlayTimestamp()
Returns timestamp of the last play start in milliseconds.
#define FL_WARN(logger, msg)
Definition: logger.h:72
uint32_t m_emitterId
The emitter-id.
Definition: soundemitter.h:423
void setSource(ALuint source)
Sets openAl-source.
uint32_t getId() const
Returns the emitter-id.
uint32_t m_fadeOutStartTimestamp
fade out start time
Definition: soundemitter.h:463
void setPosition(const AudioSpaceCoordinate &position)
Sets the position of the SoundEmitter in the virtual audio space.
bool getStream(uint32_t streamid, ALuint buffer)
Refill a processed buffer with new data.
Definition: soundclip.cpp:228
float m_origGain
original gain
Definition: soundemitter.h:457
void activateEffects()
Activates effects if the Emitter got the openAL-source.
float getGain() const
Returns the gain of the emitter.
void setGain(float gain)
Sets the gain of the emitter.
void checkFade()
Updates fade in and out.
void removeFromGroup(SoundEmitter *emitter)
Removes the emitter from group.
void setConeOuterAngle(float outer)
Sets outer angle of the sound cone, in degrees.
std::vector< SoundEffect * > m_effects
holds pointer to applied SoundEffects
Definition: soundemitter.h:469
void setPitch(float pitch)
Sets pitch multiplier.
uint32_t getTime() const
Get the time.
void setConeOuterGain(float gain)
Sets the gain when outside the oriented cone.
float getMaxGain() const
Returns the max.
AudioSpaceCoordinate getDirection() const
Return the direction of the SoundEmitter in the virtual audio space.
SoundStateType
State of the audio file.
Definition: soundemitter.h:43
void removeEffect(SoundEffect *effect)
Removes effect.
SoundStateType getState()
Returns the state of the audio file.
void reset(bool defaultall=false)
Reset the emitter, free all internal buffers.
uint64_t getSampleRate() const
Returns the sample rate.
Definition: sounddecoder.h:114
SoundClipPtr m_soundClip
The attached sound clip.
Definition: soundemitter.h:417
void setRelativePositioning(bool relative)
Sets Positioning-Type Default is false.
bool isPosition() const
Return if it is a positional SoundEmitter.
void reset(T *ptr=0)
reset this pointer to a null shared pointer this can be used to lower the reference count of the shar...
Definition: sharedptr.h:164
void update()
Called once a frame from the SoundManager.
const std::string & getGroup()
Return the group name.
std::vector< SoundEmitterListener * > m_listeners
listeners for sound related events
Definition: soundemitter.h:471
void setCheckDifference()
Sets the time difference between play and the first check if it&#39;s playable.
float getMaxDistance() const
Return the max distance.
bool m_fadeOut
fade out clip
Definition: soundemitter.h:455
uint32_t m_fadeInStartTimestamp
fade in start time
Definition: soundemitter.h:459
void pause()
Pauses playing the audio file.
uint32_t m_fadeInEndTimestamp
fade in end time
Definition: soundemitter.h:461
Base class for Efx sound effects.
Definition: soundeffect.h:46
float getPitch() const
Return pitch multiplier.
The class defines filters.
Definition: soundfilter.h:43
Listener interface for SoundEmitter.
Definition: soundemitter.h:53
float getMinGain() const
Returns the min.
DoublePoint3D AudioSpaceCoordinate
Definition: modelcoords.h:36
bool isStereo()
Tests if the audio data is stereo data or mono.
uint32_t m_streamId
The id of the stream.
Definition: soundemitter.h:421
static Logger _log(LM_AUDIO)
#define CHECK_OPENAL_LOG(logger, level, msg)
Definition: fife_openal.h:49
SoundDecoder * getDecoder() const
Returns the attached decoder.
Definition: soundclip.cpp:283
bool isActive() const
Return if the Emitter is active / have an openAl-source.
AudioSpaceCoordinate direction
Definition: soundemitter.h:438
AudioSpaceCoordinate getVelocity() const
Return the velocity of the SoundEmitter in the virtual audio space.
void detachSoundClip()
Internal function to detach a SoundClip from the source.
static SoundClipManager * instance()
Definition: singleton.h:84
void activateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundEffect for the SoundEmitter.
void release()
Releases the emitter.
float getConeOuterGain() const
Return the gain when outside the oriented cone.
struct FIFE::SoundEmitter::internData m_internData
void setCursor(SoundPositionType type, float value)
Sets the cursor position in the audio file.
uint8_t getEffectCount()
Return the number of effects.
std::string m_group
the group name
Definition: soundemitter.h:447
void acquireStream(uint32_t streamid)
Fills the streaming-buffers with initial data.
Definition: soundclip.cpp:219
void setMaxDistance(float distance)
Sets the max distance used with the Inverse Clamped Distance Model to set the distance where there wi...
uint64_t getSampleRate()
Returns the sample rate.
void deactivateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundEffect for the SoundEmitter.
bool m_active
is active
Definition: soundemitter.h:451
unsigned char uint8_t
Definition: core.h:38
float getRolloff() const
Return the AL_ROLEOFF_FACTOR.
ALuint m_source
The openAL-source.
Definition: soundemitter.h:413
SoundPositionType
Different types of audio-file positions.
Definition: soundclip.h:44
void attachSoundClip()
Internal function to attach a SoundClip to the source.
void syncData()
Updates OpenAL with collected data.
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:287
void setDirectFilter(SoundFilter *filter)
Sets the direct filter.
void deactivateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundFilter for the SoundEmitter.
void removeEmitterFromSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Removes given SoundEmitter from the specific SoundEffect.
void play()
Plays the associated audio file.
uint32_t countBuffers() const
Returns the number of buffers used by the SoundClip (only for non-streaming sound clips) ...
Definition: soundclip.cpp:146
bool isStereo() const
Tests if the audio data is stereo data or mono.
Definition: sounddecoder.h:92
virtual uint64_t getDecodedLength() const =0
Returns the decoded length of the file in bytes.
bool isStream() const
Does this SoundClip require a streaming mechanism?
Definition: soundclip.cpp:142
void setGroup(const std::string &group)
Sets the group name.
SoundFilter * m_directFilter
Applied direct sound filter.
Definition: soundemitter.h:415
bool isLooping() const
Return playing mode.
ALuint getSource() const
Return openAl-source.
uint32_t m_fadeOutEndTimestamp
fade out end time
Definition: soundemitter.h:465
float getCursor(SoundPositionType type)
Returns the cursor position in the audio file.
void setMaxGain(float gain)
Sets the max.
void setLooping(bool loop)
Sets the playing mode.
int16_t getBitResolution()
Returns the bit resolution.
void addToGroup(SoundEmitter *emitter)
Adds the emitter to group.
float getConeInnerAngle() const
Return inner angle of the sound cone, in degrees.
void addListener(SoundEmitterListener *listener)
Adds new SoundEmitter listener.
void releaseSource(SoundEmitter *emitter)
Release the source handle.
float m_samplesOffset
saves sample offset for played stream parts
Definition: soundemitter.h:449
bool isRelativePositioning() const
Return Positioning-Type.
void removeListener(SoundEmitterListener *listener)
Removes associated SoundEmitter listener.
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
Definition: checked.h:198
virtual SoundClipPtr get(const std::string &name)
Gets a shared pointer to the SoundClip.
bool m_fadeIn
fade in clip
Definition: soundemitter.h:453
void callOnSoundFinished()
Calls the Listeners if a sound finished.
uint64_t getDuration()
Returns the duration of the sound clip in milliseconds.
void quitStreaming(uint32_t streamid)
Quits Streaming.
Definition: soundclip.cpp:260
void addEffect(SoundEffect *effect)
Adds effect.
ALuint * getBuffers(uint32_t streamid=0) const
Returns the array of buffers for queuing.
Definition: soundclip.cpp:150
void setReferenceDistance(float distance)
Sets the distance under which the volume for the SoundEmitter would normally drop by half (before bei...
void activateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundFilter for the SoundEmitter.
int16_t getBitResolution() const
Returns the bit resolution.
Definition: sounddecoder.h:108
float getConeOuterAngle() const
Return outer angle of the sound cone, in degrees.
void setDirection(const AudioSpaceCoordinate &direction)
Sets the direction of the SoundEmitter in the virtual audio space.
uint64_t getDecodedLength()
Returns the length of the decoded length in bytes.
SoundClipPtr getSoundClip()
Get the current sound clip used by this emitter.
void rewind()
Rewinds the associated audio file.
void setMinGain(float gain)
Sets the min.
AudioSpaceCoordinate position
Definition: soundemitter.h:437
uint8_t getEffectNumber(SoundEffect *effect)
Return the number of the given effect.
void releaseEmitter(uint32_t emitterId)
Release an emitter-instance given by emitter-id.
uint32_t m_playCheckDifference
time difference between play and first check
Definition: soundemitter.h:467
void resetInternData()
Resets collected data to defaults.
SoundEmitter(SoundManager *manager, uint32_t uid)
uint32_t m_soundClipId
Id of the attached sound clip.
Definition: soundemitter.h:419
const int16_t BUFFER_NUM
Definition: soundconfig.h:190
SoundManager * m_manager
Access to the SoundManager.
Definition: soundemitter.h:411
void setConeInnerAngle(float inner)
Sets inner angle of the sound cone, in degrees.
void stop()
Stops playing the audio file and rewinds to the beginning.
unsigned int uint32_t
Definition: core.h:40
ResourceHandle getHandle()
Definition: resource.h:68
AudioSpaceCoordinate getPosition() const
Return the position of the SoundEmitter in the virtual audio space.
void setRolloff(float rolloff)
Sets the AL_ROLEOFF_FACTOR.
void setVelocity(const AudioSpaceCoordinate &velocity)
Sets the velocity of the SoundEmitter in the virtual audio space.
void setSoundClip(SoundClipPtr soundClip)
Sets the sound clip to be used by this emitter.
float getReferenceDistance() const
Return the reference distance.
bool setStreamPos(uint32_t streamid, SoundPositionType type, float value)
Sets the stream position.
Definition: soundclip.cpp:181
uint32_t beginStreaming()
Starts streaming the soundclip.
Definition: soundclip.cpp:154
AudioSpaceCoordinate velocity
Definition: soundemitter.h:439
bool isActive() const
Returns true if audio module is active.
void deactivateEffects()
Deactivates effects if the Emitter loses the openAL-source.
SoundFilter * getDirectFilter()
Return the direct filter.
bool isFinished()
Returns true if clip is finished.