00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_SOUNDEMITTER_H_
00023 #define FIFE_SOUNDEMITTER_H_
00024
00025
00026
00027
00028
00029
00030 #include <boost/function.hpp>
00031
00032
00033
00034
00035
00036 #include "util/time/timeevent.h"
00037
00038 #include "soundclip.h"
00039
00040 namespace FIFE {
00041
00042 class SoundManager;
00043
00046 class SoundEmitter : private TimeEvent {
00047 public:
00048 typedef boost::function0<void> type_callback;
00049
00050 SoundEmitter(SoundManager* manager, uint32_t uid);
00051 ~SoundEmitter();
00052
00055 uint32_t getId() const{
00056 return m_emitterid;
00057 }
00058
00065 void setPositioning(bool relative) {
00066 alSourcei(m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
00067 }
00068
00073 void setRolloff(float rolloff) {
00074 alSourcef (m_source, AL_ROLLOFF_FACTOR, rolloff);
00075 }
00076
00080 void setSoundClip(SoundClipPtr soundclip);
00081
00085 SoundClipPtr getSoundClip() { return m_soundclip; };
00086
00092 void setCallback(const type_callback& cb);
00093
00098 void reset(bool defaultall = false);
00099
00102 void release();
00103
00106 void setLooping(bool loop);
00107
00110 void play();
00111
00114 void stop();
00115
00118 void pause() {
00119 if (m_soundclip) {
00120 alSourcePause(m_source);
00121 }
00122 }
00123
00128 void setGain(float gain) {
00129 alSourcef(m_source, AL_GAIN, gain);
00130 }
00131
00136 float getGain() {
00137 float tmp;
00138 alGetSourcef(m_source, AL_GAIN, &tmp);
00139 return tmp;
00140 }
00141
00146 bool isStereo() {
00147 if (m_soundclip) {
00148 return m_soundclip->getDecoder()->isStereo();
00149 }
00150 return false;
00151 }
00152
00155 int16_t getBitResolution() {
00156 if (m_soundclip) {
00157 return m_soundclip->getDecoder()->getBitResolution();
00158 }
00159 return 0;
00160 }
00161
00164 uint64_t getSampleRate() {
00165 if (m_soundclip) {
00166 return m_soundclip->getDecoder()->getSampleRate();
00167 }
00168 return 0;
00169 }
00170
00173 uint64_t getDecodedLength() {
00174 if (m_soundclip) {
00175 return m_soundclip->getDecoder()->getDecodedLength();
00176
00177 }
00178 return 0;
00179 }
00180
00183 uint64_t getDuration() {
00184 if (m_soundclip) {
00185 double samplerate = static_cast<double>(getSampleRate()) / 1000.0;
00186 double bitres = static_cast<double>(getBitResolution());
00187 double size = static_cast<double>(getDecodedLength()) * 8.0;
00188 double stereo = (isStereo() ? 2.0 : 1.0);
00189 double time = ( size / (samplerate * bitres) ) / stereo;
00190
00191 return static_cast<uint64_t>(time);
00192 }
00193 return 0;
00194 }
00195
00198 void setCursor(SoundPositionType type, float value);
00199
00202 float getCursor(SoundPositionType type);
00203
00206 void setPosition(float x, float y, float z) {
00207 alSource3f(m_source, AL_POSITION, x, y, z);
00208 }
00209
00212 void setVelocity(float x, float y, float z) {
00213 alSource3f(m_source, AL_VELOCITY, x, y, z);
00214 }
00215
00216 private:
00219 virtual void updateEvent(uint32_t time);
00220
00223 void attachSoundClip();
00224
00225 SoundManager* m_manager;
00226 ALuint m_source;
00227 SoundClipPtr m_soundclip;
00228 uint32_t m_soundclipid;
00229 uint32_t m_streamid;
00230 uint32_t m_emitterid;
00231 bool m_loop;
00232 type_callback m_callback;
00233 };
00234 }
00235
00236 #endif