Panda3D
|
00001 // Filename: fmodAudioManager.h 00002 // Created by: cort (January 22, 2003) 00003 // Extended by: ben (October 22, 2003) 00004 // Prior system by: cary 00005 // Rewrite [for new Version of FMOD-EX] by: Stan Rosenbaum "Staque" - Spring 2006 00006 // 00007 // 00008 //////////////////////////////////////////////////////////////////// 00009 // 00010 // PANDA 3D SOFTWARE 00011 // Copyright (c) Carnegie Mellon University. All rights reserved. 00012 // 00013 // All use of this software is subject to the terms of the revised BSD 00014 // license. You should have received a copy of this license along 00015 // with this source code in a file named "LICENSE." 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // 00022 //Hello, all future Panda audio code people! This is my errata 00023 //documentation to help any future programmer maintain FMOD and PANDA. 00024 // 00025 //This documentation more then that is needed, but I wanted to go all 00026 //out, with the documentation. Because I was a totally newbie at 00027 //programming [especially with C/C++] this semester I want to make 00028 //sure future code maintainers have that insight I did not when 00029 //starting on the PANDA project here at the ETC/CMU. 00030 // 00031 //As of Spring 2006, Panda's FMOD audio support has been pretty much 00032 //completely rewritten. This has been done so PANDA can use FMOD-EX 00033 //[or AKA FMOD 4] and some of its new features. 00034 // 00035 //First, the FMOD-EX API itself has been completely rewritten compared 00036 //to previous versions. FMOD now handles any type of audio files, wave 00037 //audio [WAV, AIF, MP3, OGG, etc...] or musical file [MID, TRACKERS] 00038 //as the same type of an object. The API has also been structured more 00039 //like a sound studio, with 'sounds' and 'channels'. This will be 00040 //covered more in the FmodAudioSound.h/.cxx sources. 00041 // 00042 //Second, FMOD now offers virtually unlimited sounds to be played at 00043 //once via their virtual channels system. Actually the theoretical 00044 //limit is around 4000, but that is still a lot. What you need to know 00045 //about this, is that even thought you might only hear 32 sound being 00046 //played at once, FMOD will keep playing any additional sounds, and 00047 //swap those on virtual channels in and out with those on real 00048 //channels depending on priority, or distance [if you are dealing with 00049 //3D audio]. 00050 // 00051 //Third, FMOD's DSP support has been added. So you can now add GLOBAL 00052 //or SOUND specific DSP effects. Right not you can only use FMOD's 00053 //built in DSP effects. But adding support for FMOD's support of VST 00054 //effects shouldn't be that hard. 00055 // 00056 //As for the FmodManager itself, it is pretty straight forward, I 00057 //hope. As a manager class, it will create the FMOD system with the 00058 //"_system" variable which is an instance of FMOD::SYSTEM. (Actually, 00059 //we create only one global _system variable now, and share it with 00060 //all outstanding FmodManager objects--this appears to be the way FMOD 00061 //wants to work.) The FmodManager class is also the one responsible 00062 //for creation of Sounds, DSP, and maintaining the GLOBAL DSP chains 00063 //[The GLOBAL DSP chain is the DSP Chain which affects ALL the 00064 //sounds]. 00065 // 00066 //Any way that is it for an intro, lets move on to looking at the rest 00067 //of the code. 00068 // 00069 //////////////////////////////////////////////////////////////////// 00070 00071 00072 #ifndef __FMOD_AUDIO_MANAGER_H__ 00073 #define __FMOD_AUDIO_MANAGER_H__ 00074 00075 //First the includes. 00076 #include "pandabase.h" 00077 #include "pset.h" 00078 00079 #ifdef HAVE_FMODEX //[ 00080 00081 #include "audioManager.h" 00082 00083 //The Includes needed for FMOD 00084 #include <fmod.hpp> 00085 #include <fmod_errors.h> 00086 00087 class FmodAudioSound; 00088 00089 extern void fmod_audio_errcheck(const char *context, FMOD_RESULT n); 00090 00091 class EXPCL_FMOD_AUDIO FmodAudioManager : public AudioManager { 00092 friend class FmodAudioSound; 00093 00094 public: 00095 00096 //Constructor and Destructor 00097 FmodAudioManager(); 00098 virtual ~FmodAudioManager(); 00099 00100 virtual bool is_valid(); 00101 00102 virtual PT(AudioSound) get_sound(const string&, bool positional = false, int mode=SM_heuristic); 00103 virtual PT(AudioSound) get_sound(MovieAudio *, bool positional = false, int mode=SM_heuristic); 00104 00105 virtual int getSpeakerSetup(); 00106 virtual void setSpeakerSetup(SpeakerModeCategory cat); 00107 00108 virtual void set_volume(float); 00109 virtual float get_volume() const; 00110 00111 virtual void set_active(bool); 00112 virtual bool get_active() const; 00113 00114 virtual void stop_all_sounds(); 00115 00116 virtual void update(); 00117 00118 // This controls the "set of ears" that listens to 3D spacialized sound 00119 // px, py, pz are position coordinates. Can be 0.0f to ignore. 00120 // vx, vy, vz are a velocity vector in UNITS PER SECOND (default: meters). 00121 // fx, fy and fz are the respective components of a unit forward-vector 00122 // ux, uy and uz are the respective components of a unit up-vector 00123 // These changes will NOT be invoked until audio_3d_update() is called. 00124 virtual void audio_3d_set_listener_attributes(float px, float py, float pz, 00125 float vx, float xy, float xz, 00126 float fx, float fy, float fz, 00127 float ux, float uy, float uz); 00128 00129 // REMOVE THIS ONE 00130 virtual void audio_3d_get_listener_attributes(float *px, float *py, float *pz, 00131 float *vx, float *vy, float *vz, 00132 float *fx, float *fy, float *fz, 00133 float *ux, float *uy, float *uz); 00134 00135 // Control the "relative distance factor" for 3D spacialized audio. Default is 1.0 00136 // Fmod uses meters internally, so give a float in Units-per meter 00137 // Don't know what Miles uses. 00138 virtual void audio_3d_set_distance_factor(float factor); 00139 virtual float audio_3d_get_distance_factor() const; 00140 00141 // Control the presence of the Doppler effect. Default is 1.0 00142 // Exaggerated Doppler, use >1.0 00143 // Diminshed Doppler, use <1.0 00144 virtual void audio_3d_set_doppler_factor(float factor); 00145 virtual float audio_3d_get_doppler_factor() const; 00146 00147 // Exaggerate or diminish the effect of distance on sound. Default is 1.0 00148 // Faster drop off, use >1.0 00149 // Slower drop off, use <1.0 00150 virtual void audio_3d_set_drop_off_factor(float factor); 00151 virtual float audio_3d_get_drop_off_factor() const; 00152 00153 //THESE ARE NOT USED ANYMORE. 00154 //THEY ARE ONLY HERE BECAUSE THEY are still needed by Miles. 00155 //THESE are stubs in FMOD-EX version 00156 //////////////////////////////////////////////////////////////////// 00157 virtual void set_concurrent_sound_limit(unsigned int limit = 0); 00158 virtual unsigned int get_concurrent_sound_limit() const; 00159 virtual void reduce_sounds_playing_to(unsigned int count); 00160 virtual void uncache_sound(const string&); 00161 virtual void clear_cache(); 00162 virtual void set_cache_limit(unsigned int count); 00163 virtual unsigned int get_cache_limit() const; 00164 //////////////////////////////////////////////////////////////////// 00165 00166 private: 00167 static FMOD_RESULT F_CALLBACK 00168 open_callback(const char *name, int unicode, unsigned int *file_size, 00169 void **handle, void **user_data); 00170 00171 static FMOD_RESULT F_CALLBACK 00172 close_callback(void *handle, void *user_data); 00173 00174 static FMOD_RESULT F_CALLBACK 00175 read_callback(void *handle, void *buffer, unsigned int size_bytes, 00176 unsigned int *bytes_read, void *user_data); 00177 00178 static FMOD_RESULT F_CALLBACK 00179 seek_callback(void *handle, unsigned int pos, void *user_data); 00180 00181 FMOD::DSP *make_dsp(const FilterProperties::FilterConfig &conf); 00182 void update_dsp_chain(FMOD::DSP *head, FilterProperties *config); 00183 virtual bool configure_filters(FilterProperties *config); 00184 00185 private: 00186 00187 static FMOD::System *_system; 00188 static pset<FmodAudioManager *> _all_managers; 00189 00190 static bool _system_is_valid; 00191 00192 static float _distance_factor; 00193 static float _doppler_factor; 00194 static float _drop_off_factor; 00195 00196 FMOD::ChannelGroup *_channelgroup; 00197 00198 FMOD_VECTOR _position; 00199 FMOD_VECTOR _velocity; 00200 FMOD_VECTOR _forward; 00201 FMOD_VECTOR _up; 00202 00203 // DLS info for MIDI files 00204 string _dlsname; 00205 FMOD_CREATESOUNDEXINFO _midi_info; 00206 00207 bool _is_valid; 00208 bool _active; 00209 00210 // The set of all sounds. Needed only to implement stop_all_sounds. 00211 typedef pset<FmodAudioSound *> SoundSet; 00212 SoundSet _all_sounds; 00213 00214 //////////////////////////////////////////////////////////// 00215 //These are needed for Panda's Pointer System. DO NOT ERASE! 00216 //////////////////////////////////////////////////////////// 00217 00218 public: 00219 static TypeHandle get_class_type() { 00220 return _type_handle; 00221 } 00222 static void init_type() { 00223 AudioManager::init_type(); 00224 register_type(_type_handle, "FmodAudioManager", AudioManager::get_class_type()); 00225 } 00226 virtual TypeHandle get_type() const { 00227 return get_class_type(); 00228 } 00229 virtual TypeHandle force_init_type() { 00230 init_type(); 00231 return get_class_type(); 00232 } 00233 00234 private: 00235 static TypeHandle _type_handle; 00236 00237 //////////////////////////////////////////////////////////// 00238 //DONE 00239 //////////////////////////////////////////////////////////// 00240 00241 }; 00242 00243 EXPCL_FMOD_AUDIO AudioManager *Create_FmodAudioManager(); 00244 00245 00246 #endif //] 00247 00248 #endif /* __FMOD_AUDIO_MANAGER_H__ */