soundemitter.h
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 "vfs/raw/rawdata.h"
00037 #include "util/time/timeevent.h"
00038
00039 #include "soundclip.h"
00040
00041 namespace FIFE {
00042
00043 class SoundManager;
00044 class SoundClipPool;
00045
00048 class SoundEmitter : private TimeEvent {
00049 public:
00050 typedef boost::function0<void> type_callback;
00051
00052 SoundEmitter(SoundManager* manager, SoundClipPool* pool, unsigned int uid);
00053 ~SoundEmitter();
00054
00057 unsigned int getId() const{
00058 return m_emitterid;
00059 }
00060
00067 void setPositioning(bool relative) {
00068 alSourcei(m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
00069 }
00070
00075 void setRolloff(float rolloff) {
00076 alSourcef (m_source, AL_ROLLOFF_FACTOR, rolloff);
00077 }
00078
00082 void setSoundClip(unsigned int sound_id);
00083
00089 void setCallback(const type_callback& cb);
00090
00095 void reset(bool defaultall = false);
00096
00099 void release();
00100
00103 void setLooping(bool loop);
00104
00107 void play();
00108
00111 void stop();
00112
00115 void pause() {
00116 if (m_soundclip) {
00117 alSourcePause(m_source);
00118 }
00119 }
00120
00125 void setGain(float gain) {
00126 alSourcef(m_source, AL_GAIN, gain);
00127 }
00128
00133 float getGain() {
00134 float tmp;
00135 alGetSourcef(m_source, AL_GAIN, &tmp);
00136 return tmp;
00137 }
00138
00143 bool isStereo() const{
00144 if (m_soundclip) {
00145 return m_soundclip->getDecoder()->isStereo();
00146 }
00147 return false;
00148 }
00149
00152 short getBitResolution() const {
00153 if (m_soundclip) {
00154 return m_soundclip->getDecoder()->getBitResolution();
00155 }
00156 return 0;
00157 }
00158
00161 unsigned long getSampleRate() const{
00162 if (m_soundclip) {
00163 return m_soundclip->getDecoder()->getSampleRate();
00164 }
00165 return 0;
00166 }
00167
00170 unsigned long getDecodedLength() const{
00171 if (m_soundclip) {
00172 return m_soundclip->getDecoder()->getDecodedLength();
00173
00174 }
00175 return 0;
00176 }
00177
00180 unsigned long getDuration() const{
00181 if (m_soundclip) {
00182 double samplerate = static_cast<double>(getSampleRate()) / 1000.0;
00183 double bitres = static_cast<double>(getBitResolution());
00184 double size = static_cast<double>(getDecodedLength()) * 8.0;
00185 double stereo = (isStereo() ? 2.0 : 1.0);
00186 double time = ( size / (samplerate * bitres) ) / stereo;
00187
00188 return static_cast<unsigned long>(time);
00189 }
00190 return 0;
00191 }
00192
00195 void setCursor(SoundPositionType type, float value);
00196
00199 float getCursor(SoundPositionType type);
00200
00203 void setPosition(float x, float y, float z) {
00204 alSource3f(m_source, AL_POSITION, x, y, z);
00205 }
00206
00209 void setVelocity(float x, float y, float z) {
00210 alSource3f(m_source, AL_VELOCITY, x, y, z);
00211 }
00212
00213 private:
00216 virtual void updateEvent(unsigned long time);
00217
00220 void attachSoundClip();
00221
00222 SoundManager* m_manager;
00223 SoundClipPool* m_pool;
00224 ALuint m_source;
00225 SoundClip* m_soundclip;
00226 unsigned int m_soundclipid;
00227 unsigned int m_streamid;
00228 unsigned int m_emitterid;
00229 bool m_loop;
00230 type_callback m_callback;
00231 };
00232 }
00233
00234 #endif