FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * *
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 *
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  ***************************************************************************/
22 // Standard C++ library includes
24 // Platform specific includes
26 // 3rd party library includes
28 // FIFE includes
29 // These includes are split up in two parts, separated by one empty line
30 // First block: files included from the FIFE root src directory
31 // Second block: files included from the same folder
33 #include "util/log/logger.h"
34 #include "util/base/exception.h"
36 #include "actionaudio.h"
37 #include "soundmanager.h"
38 #include "soundemitter.h"
39 #include "soundsource.h"
41 namespace FIFE {
42  static Logger _log(LM_AUDIO);
45  public:
47  m_source = source;
48  }
49  virtual ~SoundChangeListener() {}
51  virtual void onInstanceChanged(Instance* instance, InstanceChangeInfo info) {
52  if ((info & ICHANGE_LOC) == ICHANGE_LOC) {
54  } else if ((info & ICHANGE_ROTATION) == ICHANGE_ROTATION) {
56  }
57  }
59  private:
61  };
64  m_instance(instance),
65  m_audio(NULL) {
68  m_listener = new SoundChangeListener(this);
71  // inital data
72  setPosition();
74  }
78  delete m_listener;
80  }
83  if (audio != m_audio) {
84  if (m_audio) {
85  m_emitter->stop();
86  }
88  m_audio = audio;
89  if (m_audio) {
91  m_emitter->play();
92  } else {
93  m_emitter->reset();
94  }
95  } else if (audio && !m_emitter->isLooping()) {
96  m_emitter->rewind();
97  m_emitter->play();
98  }
99  }
102  return m_audio;
103  }
106  if (m_audio) {
108  }
109  }
112  if (m_audio && m_audio->isDirection()) {
114  }
115  }
134  }
136 }
bool isLooping() const
Return playing mode.
void setPosition(const AudioSpaceCoordinate &position)
Sets the position of the SoundEmitter in the virtual audio space.
void setGain(float gain)
Sets the gain of the emitter.
void setConeOuterAngle(float outer)
Sets outer angle of the sound cone, in degrees.
float getGain() const
Returns the gain of the emitter.
Definition: actionaudio.cpp:84
void setPitch(float pitch)
Sets pitch multiplier.
void setConeOuterGain(float gain)
Sets the gain when outside the oriented cone.
void setActionAudio(ActionAudio *audio)
Sets the ActionAudio.
Definition: soundsource.cpp:82
Interface class between Instance / ActionAudio and SoundEmitter.
Definition: soundsource.h:45
void reset(bool defaultall=false)
Reset the emitter, free all internal buffers.
const std::string & getGroupName() const
Return the name of the group to which the emitter is added.
Definition: actionaudio.cpp:76
void setRelativePositioning(bool relative)
Sets Positioning-Type Default is false.
SoundEmitter * createEmitter()
Returns a pointer to an allocated emitter-instance.
float getRolloff() const
static Logger _log(LM_AUDIO)
SoundSource(Instance *instance)
Definition: soundsource.cpp:63
static SoundManager * instance()
Definition: singleton.h:84
Location & getLocationRef()
Gets reference of current location of instance.
Definition: instance.cpp:318
bool isLooping() const
Return playing mode.
bool isRelativePositioning() const
Return Positioning-Type.
float getConeOuterAngle() const
Return outer angle of the sound cone, in degrees.
void setMaxDistance(float distance)
Sets the max distance used with the Inverse Clamped Distance Model to set the distance where there wi...
void addChangeListener(InstanceChangeListener *listener)
Adds new instance change listener.
Definition: instance.cpp:384
SoundChangeListener(SoundSource *source)
Definition: soundsource.cpp:46
void play()
Plays the associated audio file.
uint32_t InstanceChangeInfo
Definition: instance.h:77
void setGroup(const std::string &group)
Sets the group name.
The class for holding audio data per Action.
Definition: actionaudio.h:41
float getReferenceDistance() const
Return the reference distance.
uint32_t getId() const
Returns the emitter-id.
float getMinGain() const
Returns the min.
float getMaxGain() const
Returns the max.
Definition: actionaudio.cpp:92
Location getFacingLocation()
Returns the direction where instance is heading.
Definition: instance.cpp:913
void setPosition()
Sets the positon of the SoundEmitter, called from Instance.
void removeChangeListener(InstanceChangeListener *listener)
Removes associated instance change listener.
Definition: instance.cpp:403
void setMaxGain(float gain)
Sets the max.
void setLooping(bool loop)
Sets the playing mode.
float getMaxDistance() const
Return the max distance.
virtual void onInstanceChanged(Instance *instance, InstanceChangeInfo info)
Definition: soundsource.cpp:51
const std::string & getSoundFileName() const
Return the name of the sound file.
Definition: actionaudio.cpp:68
float getConeInnerAngle() const
Return inner angle of the sound cone, in degrees.
void setReferenceDistance(float distance)
Sets the distance under which the volume for the SoundEmitter would normally drop by half (before bei...
void updateSoundEmitter()
Moves data from ActionAudio to SoundEmitter.
float getConeOuterGain() const
Return the gain when outside the oriented cone.
const AudioSpaceCoordinate & getVelocity() const
Return the velocity of the SoundEmitter in the virtual audio space.
float getPitch() const
Return pitch multiplier.
void setDirection(const AudioSpaceCoordinate &direction)
Sets the direction of the SoundEmitter in the virtual audio space.
void rewind()
Rewinds the associated audio file.
void setMinGain(float gain)
Sets the min.
void setDirection()
Sets the direction of the SoundEmitter, called from Instance.
ActionAudio * getActionAudio() const
Return ActionAudio.
void releaseEmitter(uint32_t emitterId)
Release an emitter-instance given by emitter-id.
Instance * m_instance
Associated Instance.
Definition: soundsource.h:73
ActionAudio * m_audio
Actual ActionAudio.
Definition: soundsource.h:75
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.
SoundChangeListener * m_listener
InstanceChangeListener for position and direction.
Definition: soundsource.h:79
void setRolloff(float rolloff)
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.
bool isDirection() const
Return true if the Instance direction is used, false for undirected.
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Definition: location.cpp:117
SoundEmitter * m_emitter
Related SoundEmitter.
Definition: soundsource.h:77