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 void setCursor(SoundPositionType type, float value);
00171
00174 float getCursor(SoundPositionType type);
00175
00178 void setPosition(float x, float y, float z) {
00179 alSource3f(m_source, AL_POSITION, x, y, z);
00180 }
00181
00184 void setVelocity(float x, float y, float z) {
00185 alSource3f(m_source, AL_VELOCITY, x, y, z);
00186 }
00187
00188 private:
00191 virtual void updateEvent(unsigned long time);
00192
00195 void attachSoundClip();
00196
00197 SoundManager* m_manager;
00198 SoundClipPool* m_pool;
00199 ALuint m_source;
00200 SoundClip* m_soundclip;
00201 unsigned int m_soundclipid;
00202 unsigned int m_streamid;
00203 unsigned int m_emitterid;
00204 bool m_loop;
00205 type_callback m_callback;
00206 };
00207 }
00208
00209 #endif