00001 // Filename: audioManager.cxx 00002 // Created by: skyler (June 6, 2001) 00003 // Prior system by: cary 00004 // 00005 //////////////////////////////////////////////////////////////////// 00006 // 00007 // PANDA 3D SOFTWARE 00008 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00009 // 00010 // All use of this software is subject to the terms of the Panda 3d 00011 // Software license. You should have received a copy of this license 00012 // along with this source code; you will also find a current copy of 00013 // the license at http://www.panda3d.org/license.txt . 00014 // 00015 // To contact the maintainers of this program write to 00016 // panda3d@yahoogroups.com . 00017 // 00018 //////////////////////////////////////////////////////////////////// 00019 00020 #include "config_audio.h" 00021 #include "audioManager.h" 00022 00023 #include "nullAudioManager.h" 00024 00025 #include "load_dso.h" 00026 00027 namespace { 00028 PT(AudioManager) create_NullAudioManger() { 00029 audio_debug("create_NullAudioManger()"); 00030 return new NullAudioManager(); 00031 } 00032 } 00033 00034 Create_AudioManager_proc* AudioManager::_create_AudioManager 00035 =create_NullAudioManger; 00036 00037 void AudioManager:: 00038 register_AudioManager_creator(Create_AudioManager_proc* proc) { 00039 nassertv(_create_AudioManager==create_NullAudioManger); 00040 _create_AudioManager=proc; 00041 } 00042 00043 00044 00045 // Factory method for getting a platform specific AudioManager: 00046 PT(AudioManager) AudioManager:: 00047 create_AudioManager() { 00048 audio_debug("create_AudioManager()\n audio_library_name=\"" 00049 <<*audio_library_name<<"\""); 00050 static int lib_load; 00051 if (!lib_load) { 00052 lib_load=1; 00053 if (!audio_library_name->empty() && !((*audio_library_name) == "null")) { 00054 Filename dl_name = Filename::dso_filename( 00055 "lib"+*audio_library_name+".so"); 00056 dl_name.to_os_specific(); 00057 audio_debug(" dl_name=\""<<dl_name<<"\""); 00058 void* lib = load_dso(dl_name); 00059 if (!lib) { 00060 audio_error(" LoadLibrary() failed, will use NullAudioManager"); 00061 audio_error(" "<<load_dso_error()); 00062 nassertr(_create_AudioManager==create_NullAudioManger, 0); 00063 } else { 00064 // ...the library will register itself with the AudioManager. 00065 #if defined(DWORD) && defined(WIN32) && !defined(NDEBUG) //[ 00066 const int bufLen=256; 00067 char path[bufLen]; 00068 DWORD count = GetModuleFileName((HMODULE)lib, path, bufLen); 00069 if (count) { 00070 audio_debug(" GetModuleFileName() \""<<path<<"\""); 00071 } else { 00072 audio_debug(" GetModuleFileName() failed."); 00073 } 00074 #endif //] 00075 } 00076 } 00077 } 00078 PT(AudioManager) am = (*_create_AudioManager)(); 00079 if (!am->is_valid()) { 00080 am = create_NullAudioManger(); 00081 } 00082 am->_bExclusive = false; 00083 return am; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: AudioManager::get_null_sound 00088 // Access: Public 00089 // Description: Returns a special NullAudioSound object that has all 00090 // the interface of a normal sound object, but plays no 00091 // sound. This same object may also be returned by 00092 // get_sound() if it fails. 00093 //////////////////////////////////////////////////////////////////// 00094 PT(AudioSound) AudioManager:: 00095 get_null_sound() { 00096 if (_null_sound == (AudioSound *)NULL) { 00097 _null_sound = new NullAudioSound; 00098 } 00099 return _null_sound; 00100 } 00101 00102 void AudioManager:: 00103 set_mutually_exclusive(bool bExclusive) { 00104 _bExclusive = bExclusive; 00105 }