00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #ifndef __FMOD_AUDIO_SOUND_H__
00072 #define __FMOD_AUDIO_SOUND_H__
00073
00074 #include <pandabase.h>
00075
00076 #ifdef HAVE_FMODEX //[
00077
00078 #include "audioSound.h"
00079 #include "reMutex.h"
00080
00081 #include <fmod.hpp>
00082 #include <fmod_errors.h>
00083
00084 class EXPCL_FMOD_AUDIO FmodAudioSound : public AudioSound {
00085 public:
00086
00087 FmodAudioSound(AudioManager *manager, Filename fn, bool positional );
00088 ~FmodAudioSound();
00089
00090
00091
00092
00093
00094 void play();
00095 void stop();
00096
00097
00098
00099 void set_loop(bool loop=true);
00100 bool get_loop() const;
00101
00102
00103
00104 void set_loop_count(unsigned long loop_count=1);
00105 unsigned long get_loop_count() const;
00106
00107
00108
00109 void set_time(PN_stdfloat start_time=0.0);
00110 PN_stdfloat get_time() const;
00111
00112
00113
00114 void set_volume(PN_stdfloat volume=1.0);
00115 PN_stdfloat get_volume() const;
00116
00117
00118
00119
00120
00121 void set_balance(PN_stdfloat balance_right=0.0);
00122 PN_stdfloat get_balance() const;
00123
00124
00125
00126 void set_play_rate(PN_stdfloat play_rate=1.0f);
00127 PN_stdfloat get_play_rate() const;
00128
00129 const string &get_name() const;
00130
00131
00132 PN_stdfloat length() const;
00133
00134
00135
00136
00137 void set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz);
00138 void get_3d_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz, PN_stdfloat *vx, PN_stdfloat *vy, PN_stdfloat *vz);
00139
00140 void set_3d_min_distance(PN_stdfloat dist);
00141 PN_stdfloat get_3d_min_distance() const;
00142
00143 void set_3d_max_distance(PN_stdfloat dist);
00144 PN_stdfloat get_3d_max_distance() const;
00145
00146 AudioSound::SoundStatus status() const;
00147
00148 virtual PN_stdfloat get_speaker_mix(AudioManager::SpeakerId speaker);
00149 virtual void set_speaker_mix(PN_stdfloat frontleft, PN_stdfloat frontright, PN_stdfloat center, PN_stdfloat sub, PN_stdfloat backleft, PN_stdfloat backright, PN_stdfloat sideleft, PN_stdfloat sideright);
00150
00151 void set_active(bool active=true);
00152 bool get_active() const;
00153
00154 void finished();
00155 void set_finished_event(const string& event);
00156 const string& get_finished_event() const;
00157
00158 private:
00159 PT(FmodAudioManager) _manager;
00160 FMOD::Sound *_sound;
00161 FMOD::Channel *_channel;
00162
00163 Filename _file_name;
00164
00165 float _volume;
00166 float _balance;
00167 float _playrate;
00168 int _priority;
00169 float _mix[AudioManager::SPK_COUNT];
00170
00171 float _sampleFrequency;
00172 mutable float _length;
00173
00174 FMOD_SPEAKERMODE _speakermode;
00175
00176 FMOD_VECTOR _location;
00177 FMOD_VECTOR _velocity;
00178
00179 PN_stdfloat _min_dist;
00180 PN_stdfloat _max_dist;
00181
00182 void start_playing();
00183 void set_volume_on_channel();
00184 void set_balance_on_channel();
00185 void set_play_rate_on_channel();
00186 void set_speaker_mix_on_channel();
00187 void set_3d_attributes_on_channel();
00188
00189 void set_speaker_mix_or_balance_on_channel();
00190
00191 virtual int get_priority();
00192 virtual void set_priority(int priority);
00193
00194 bool _active;
00195 bool _paused;
00196 PN_stdfloat _start_time;
00197
00198 string _finished_event;
00199
00200
00201
00202
00203
00204
00205
00206 PT(FmodAudioSound) _self_ref;
00207
00208 static FMOD_RESULT F_CALLBACK
00209 sound_end_callback(FMOD_CHANNEL * channel,
00210 FMOD_CHANNEL_CALLBACKTYPE type,
00211 void *commanddata1,
00212 void *commanddata2);
00213
00214 static FMOD_RESULT F_CALLBACK
00215 open_callback(const char *name, int unicode, unsigned int *file_size,
00216 void **handle, void **user_data);
00217
00218 static FMOD_RESULT F_CALLBACK
00219 close_callback(void *handle, void *user_data);
00220
00221 static FMOD_RESULT F_CALLBACK
00222 read_callback(void *handle, void *buffer, unsigned int size_bytes,
00223 unsigned int *bytes_read, void *user_data);
00224
00225 static FMOD_RESULT F_CALLBACK
00226 seek_callback(void *handle, unsigned int pos, void *user_data);
00227
00228
00229
00230
00231
00232
00233 public:
00234 static TypeHandle get_class_type() {
00235 return _type_handle;
00236 }
00237 static void init_type() {
00238 AudioSound::init_type();
00239 register_type(_type_handle, "FmodAudioSound", AudioSound::get_class_type());
00240 }
00241 virtual TypeHandle get_type() const {
00242 return get_class_type();
00243 }
00244 virtual TypeHandle force_init_type() {
00245 init_type();
00246 return get_class_type();
00247 }
00248
00249 private:
00250 static TypeHandle _type_handle;
00251
00252
00253
00254
00255 };
00256
00257 #include "fmodAudioSound.I"
00258
00259 #endif //]
00260
00261 #endif
00262
00263
00264
00265
00266