00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "config_audio.h"
00017 #include "audioManager.h"
00018 #include "atomicAdjust.h"
00019 #include "nullAudioManager.h"
00020 #include "windowsRegistry.h"
00021 #include "virtualFileSystem.h"
00022 #include "config_util.h"
00023 #include "load_dso.h"
00024
00025 #ifdef WIN32
00026 #include <windows.h>
00027 #endif
00028
00029
00030 TypeHandle AudioManager::_type_handle;
00031
00032
00033 namespace {
00034 AudioManager *create_NullAudioManager() {
00035 audio_debug("create_NullAudioManager()");
00036 return new NullAudioManager();
00037 }
00038 }
00039
00040 Create_AudioManager_proc* AudioManager::_create_AudioManager
00041 =create_NullAudioManager;
00042
00043 void AudioManager::register_AudioManager_creator(Create_AudioManager_proc* proc) {
00044 nassertv(_create_AudioManager==create_NullAudioManager);
00045 _create_AudioManager=proc;
00046 }
00047
00048
00049
00050
00051 PT(AudioManager) AudioManager::create_AudioManager() {
00052 audio_debug("create_AudioManager()\n audio_library_name=\""<<audio_library_name<<"\"");
00053 static bool lib_load = false;
00054 if (!lib_load) {
00055 lib_load = true;
00056 if (!audio_library_name.empty() && !(audio_library_name == "null")) {
00057 Filename dl_name = Filename::dso_filename(
00058 "lib"+string(audio_library_name)+".so");
00059 dl_name.to_os_specific();
00060 audio_debug(" dl_name=\""<<dl_name<<"\"");
00061 void *handle = load_dso(get_plugin_path().get_value(), dl_name);
00062 if (handle == (void *)NULL) {
00063 audio_error(" load_dso(" << dl_name << ") failed, will use NullAudioManager");
00064 audio_error(" "<<load_dso_error());
00065 nassertr(_create_AudioManager == create_NullAudioManager, NULL);
00066 } else {
00067
00068
00069 string lib_name = audio_library_name;
00070 if (lib_name.substr(0, 2) == "p3") {
00071 lib_name = lib_name.substr(2);
00072 }
00073 string symbol_name = "get_audio_manager_func_" + lib_name;
00074 void *dso_symbol = get_dso_symbol(handle, symbol_name);
00075 if (audio_cat.is_debug()) {
00076 audio_cat.debug()
00077 << "symbol of " << symbol_name << " = " << dso_symbol << "\n";
00078 }
00079
00080 if (dso_symbol == (void *)NULL) {
00081
00082 unload_dso(handle);
00083 handle = NULL;
00084 audio_error(" Audio library did not provide get_audio_manager_func, will use NullAudioManager");
00085 } else {
00086 typedef Create_AudioManager_proc *FuncType();
00087 Create_AudioManager_proc *factory_func = (*(FuncType *)dso_symbol)();
00088 AudioManager::register_AudioManager_creator(factory_func);
00089 }
00090 }
00091 }
00092 }
00093 PT(AudioManager) am = (*_create_AudioManager)();
00094 if (!am->is_exact_type(NullAudioManager::get_class_type()) && !am->is_valid()) {
00095 audio_error(" " << am->get_type() << " is not valid, will use NullAudioManager");
00096 am = create_NullAudioManager();
00097 }
00098 return am;
00099 }
00100
00101
00102
00103
00104
00105
00106 AudioManager::
00107 ~AudioManager() {
00108 if (_null_sound != (AudioSound *)NULL) {
00109 unref_delete((AudioSound *)_null_sound);
00110 }
00111 }
00112
00113
00114
00115
00116
00117
00118 AudioManager::
00119 AudioManager() {
00120 _null_sound = NULL;
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 void AudioManager::
00133 shutdown() {
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 PT(AudioSound) AudioManager::
00145 get_null_sound() {
00146 if (_null_sound == (AudioSound *)NULL) {
00147 AudioSound *new_sound = new NullAudioSound;
00148 new_sound->ref();
00149 void *result = AtomicAdjust::compare_and_exchange_ptr(_null_sound, (void *)NULL, (void *)new_sound);
00150 if (result != NULL) {
00151
00152 nassertr(_null_sound != new_sound, NULL);
00153 unref_delete(new_sound);
00154 }
00155 nassertr(_null_sound != NULL, NULL);
00156 }
00157
00158 return (AudioSound *)_null_sound;
00159 }
00160
00161
00162
00163
00164
00165
00166 int AudioManager::
00167 getSpeakerSetup() {
00168
00169 return 0;
00170 }
00171
00172
00173
00174
00175
00176
00177 void AudioManager::
00178 setSpeakerSetup(SpeakerModeCategory cat) {
00179
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 bool AudioManager::
00194 configure_filters(FilterProperties *config) {
00195 const FilterProperties::ConfigVector &conf = config->get_config();
00196 if (conf.empty()) {
00197 return true;
00198 } else {
00199 return false;
00200 }
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210 void AudioManager::
00211 update() {
00212
00213 }
00214
00215
00216
00217
00218
00219
00220 void AudioManager::audio_3d_set_listener_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz, PN_stdfloat fx, PN_stdfloat fy, PN_stdfloat fz, PN_stdfloat ux, PN_stdfloat uy, PN_stdfloat uz) {
00221
00222 }
00223
00224
00225
00226
00227
00228
00229 void AudioManager::audio_3d_get_listener_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz, PN_stdfloat *vx, PN_stdfloat *vy, PN_stdfloat *vz, PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz, PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz) {
00230
00231 }
00232
00233
00234
00235
00236
00237
00238 void AudioManager::audio_3d_set_distance_factor(PN_stdfloat factor) {
00239
00240 }
00241
00242
00243
00244
00245
00246
00247 PN_stdfloat AudioManager::audio_3d_get_distance_factor() const {
00248
00249 return 0.0f;
00250 }
00251
00252
00253
00254
00255
00256
00257 void AudioManager::audio_3d_set_doppler_factor(PN_stdfloat factor) {
00258
00259 }
00260
00261
00262
00263
00264
00265
00266 PN_stdfloat AudioManager::audio_3d_get_doppler_factor() const {
00267
00268 return 0.0f;
00269 }
00270
00271
00272
00273
00274
00275
00276 void AudioManager::audio_3d_set_drop_off_factor(PN_stdfloat factor) {
00277
00278 }
00279
00280
00281
00282
00283
00284
00285 PN_stdfloat AudioManager::audio_3d_get_drop_off_factor() const {
00286
00287 return 0.0f;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 Filename AudioManager::
00299 get_dls_pathname() {
00300 Filename dls_filename = audio_dls_file;
00301 if (!dls_filename.empty()) {
00302 VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
00303 vfs->resolve_filename(dls_filename, get_model_path());
00304
00305 return dls_filename;
00306 }
00307
00308 #ifdef WIN32
00309 Filename pathname;
00310
00311
00312 string os_filename = WindowsRegistry::get_string_value("SOFTWARE\\Microsoft\\DirectMusic", "GMFilePath", "");
00313
00314 if (!os_filename.empty()) {
00315 pathname = Filename::from_os_specific(os_filename);
00316 } else {
00317 char sysdir[MAX_PATH+1];
00318 GetSystemDirectory(sysdir,MAX_PATH+1);
00319 pathname = Filename(Filename::from_os_specific(sysdir), Filename("drivers/gm.dls"));
00320 }
00321 pathname.make_true_case();
00322 return pathname;
00323
00324 #elif defined(IS_OSX)
00325
00326 return Filename("/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls");
00327
00328 #else
00329 return Filename();
00330 #endif
00331 }
00332
00333
00334
00335
00336
00337
00338 void AudioManager::
00339 output(ostream &out) const {
00340 out << get_type();
00341 }
00342
00343
00344
00345
00346
00347
00348 void AudioManager::
00349 write(ostream &out) const {
00350 out << (*this) << "\n";
00351 }
00352
00353
00354
00355
00356
00357
00358 void AudioManager::
00359 set_speaker_configuration(LVecBase3 *speaker1, LVecBase3 *speaker2, LVecBase3 *speaker3, LVecBase3 *speaker4, LVecBase3 *speaker5, LVecBase3 *speaker6, LVecBase3 *speaker7, LVecBase3 *speaker8, LVecBase3 *speaker9) {
00360
00361 }