diff --git a/panda/src/audio/audioManager.cxx b/panda/src/audio/audioManager.cxx index f47bb4e0c3..22b8caf018 100644 --- a/panda/src/audio/audioManager.cxx +++ b/panda/src/audio/audioManager.cxx @@ -24,6 +24,10 @@ #include "load_dso.h" + +TypeHandle AudioManager::_type_handle; + + namespace { PT(AudioManager) create_NullAudioManger() { audio_debug("create_NullAudioManger()"); diff --git a/panda/src/audio/audioManager.h b/panda/src/audio/audioManager.h index 011da0f972..c48323b308 100644 --- a/panda/src/audio/audioManager.h +++ b/panda/src/audio/audioManager.h @@ -26,7 +26,7 @@ typedef PT(AudioManager) Create_AudioManager_proc(); -class EXPCL_PANDA AudioManager : public ReferenceCount { +class EXPCL_PANDA AudioManager : public TypedReferenceCount { PUBLISHED: // Create an AudioManager for each category of sounds you have. // E.g. @@ -121,6 +121,24 @@ protected: AudioManager() { // intentionally blank. } + + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + TypedReferenceCount::init_type(); + register_type(_type_handle, "AudioManager", + TypedReferenceCount::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; }; #endif /* __AUDIO_MANAGER_H__ */ diff --git a/panda/src/audio/audioSound.h b/panda/src/audio/audioSound.h index 13d5dd646f..55d5efb2f5 100644 --- a/panda/src/audio/audioSound.h +++ b/panda/src/audio/audioSound.h @@ -21,13 +21,13 @@ #define __AUDIOSOUND_H__ #include "config_audio.h" -#include "referenceCount.h" +#include "typedReferenceCount.h" #include "pointerTo.h" class AudioManager; -class EXPCL_PANDA AudioSound : public ReferenceCount { +class EXPCL_PANDA AudioSound : public TypedReferenceCount { PUBLISHED: virtual ~AudioSound() {} @@ -111,10 +111,14 @@ public: return _type_handle; } static void init_type() { - ReferenceCount::init_type(); + TypedReferenceCount::init_type(); register_type(_type_handle, "AudioSound", - ReferenceCount::get_class_type()); + TypedReferenceCount::get_class_type()); } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} private: static TypeHandle _type_handle; diff --git a/panda/src/audio/config_audio.cxx b/panda/src/audio/config_audio.cxx index ea136ee70d..8a3f6098af 100644 --- a/panda/src/audio/config_audio.cxx +++ b/panda/src/audio/config_audio.cxx @@ -18,6 +18,7 @@ #include "config_audio.h" #include "dconfig.h" +#include "audioManager.h" #include "audioSound.h" Configure(config_audio); @@ -67,6 +68,7 @@ ConfigureFn(config_audio) { audio_library_name = new string( config_audio.GetString("audio-library-name", "miles_audio")); + AudioManager::init_type(); AudioSound::init_type(); } diff --git a/panda/src/audiotraits/config_milesAudio.cxx b/panda/src/audiotraits/config_milesAudio.cxx index 941797a8c9..79f3b57589 100644 --- a/panda/src/audiotraits/config_milesAudio.cxx +++ b/panda/src/audiotraits/config_milesAudio.cxx @@ -50,6 +50,9 @@ init_libMilesAudio() { initialized = true; AudioManager::register_AudioManager_creator(Create_AudioManager); + + MilesAudioManager::init_type(); + MilesAudioSound::init_type(); } #endif //] diff --git a/panda/src/audiotraits/milesAudioManager.cxx b/panda/src/audiotraits/milesAudioManager.cxx index 6de35c028b..ebcf6964fa 100644 --- a/panda/src/audiotraits/milesAudioManager.cxx +++ b/panda/src/audiotraits/milesAudioManager.cxx @@ -30,6 +30,9 @@ #include + +TypeHandle MilesAudioManager::_type_handle; + int MilesAudioManager::_active_managers = 0; HDLSFILEID MilesAudioManager::_dls_field = NULL; @@ -84,7 +87,10 @@ void CustomMilesShutdown() { //////////////////////////////////////////////////////////////////// // Function: MilesAudioManager::MilesAudioManager // Access: Public -// Description: +// Description: Create an audio manager. This may open the Miles +// sound system if there were no other MilesAudioManager +// instances. Subsequent managers may use the same +// Miles resources. //////////////////////////////////////////////////////////////////// MilesAudioManager:: MilesAudioManager() { @@ -165,6 +171,7 @@ MilesAudioManager() { // either way. ++_active_managers; audio_debug(" _active_managers="<<_active_managers); + nassertv(_active_managers>0); if (_is_valid) { assert(is_valid()); @@ -180,7 +187,10 @@ MilesAudioManager() { //////////////////////////////////////////////////////////////////// // Function: MilesAudioManager::~MilesAudioManager // Access: Public -// Description: +// Description: Clean up this audio manager and possibly release +// the Miles resources that are reserved by the +// application (the later happens if this is the last +// active manager). //////////////////////////////////////////////////////////////////// MilesAudioManager:: ~MilesAudioManager() { @@ -188,6 +198,7 @@ MilesAudioManager:: // Be sure to delete associated sounds before deleting the manager: nassertv(_sounds_on_loan.empty()); clear_cache(); + nassertv(_active_managers>0); --_active_managers; audio_debug(" _active_managers="<<_active_managers); if (_active_managers==0) { @@ -209,20 +220,22 @@ MilesAudioManager:: //////////////////////////////////////////////////////////////////// // Function: MilesAudioManager::is_valid // Access: -// Description: +// Description: This is mostly for debugging, but it it could be +// used to detect errors in a release build if you +// don't mind the cpu cost. //////////////////////////////////////////////////////////////////// bool MilesAudioManager:: is_valid() { bool check=true; if (_sounds.size() != _lru.size()) { - audio_debug("--sizes--"); + audio_debug("-- Error _sounds.size() != _lru.size() --"); check=false; } else { LRU::const_iterator i=_lru.begin(); for (; i != _lru.end(); ++i) { SoundMap::const_iterator smi=_sounds.find(**i); if (smi == _sounds.end()) { - audio_debug("--"<<**i<<"--"); + audio_debug("-- "<<**i<<" in _lru and not in _sounds --"); check=false; break; } @@ -559,14 +572,14 @@ starting_sound(MilesAudioSound* audio) { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioManager::stoping_sound +// Function: MilesAudioManager::stopping_sound // Access: // Description: Inform the manager that a sound is finished or // someone called stop on the sound (this should not // be called if a sound is only paused). //////////////////////////////////////////////////////////////////// void MilesAudioManager:: -stoping_sound(MilesAudioSound* audio) { +stopping_sound(MilesAudioSound* audio) { _sounds_playing.erase(audio); if (_hasMidiSounds && _sounds_playing.size() == 0) { force_midi_reset(); diff --git a/panda/src/audiotraits/milesAudioManager.h b/panda/src/audiotraits/milesAudioManager.h index 0e3705afab..5b30711e1e 100644 --- a/panda/src/audiotraits/milesAudioManager.h +++ b/panda/src/audiotraits/milesAudioManager.h @@ -98,7 +98,7 @@ private: void uncache_a_sound(); void starting_sound(MilesAudioSound* audio); - void stoping_sound(MilesAudioSound* audio); + void stopping_sound(MilesAudioSound* audio); // utility function that should be moved to another class: bool get_registry_entry(HKEY base, @@ -118,6 +118,24 @@ private: static void AILCALLBACK vfs_close_callback(U32 file_handle); friend class MilesAudioSound; + + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + AudioManager::init_type(); + register_type(_type_handle, "MilesAudioManager", + AudioManager::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; }; EXPCL_MILES_AUDIO PT(AudioManager) Create_AudioManager(); diff --git a/panda/src/audiotraits/milesAudioSound.cxx b/panda/src/audiotraits/milesAudioSound.cxx index 3286179e1b..e038d93940 100644 --- a/panda/src/audiotraits/milesAudioSound.cxx +++ b/panda/src/audiotraits/milesAudioSound.cxx @@ -23,6 +23,10 @@ #include "milesAudioSound.h" #include "milesAudioManager.h" + +TypeHandle MilesAudioSound::_type_handle; + + #define NEED_MILES_LENGTH_WORKAROUND #if (((MSS_MAJOR_VERSION == 6) && (MSS_MINOR_VERSION >= 5)) || (MSS_MAJOR_VERSION >= 7)) @@ -73,6 +77,7 @@ namespace { void AILCALLBACK pandaAudioAilCallback_Sequence(HSEQUENCE S) { assert(S); + AutoAilLock milesLock; audio_debug("pandaAudioAilCallback_Sequence(HSEQUENCE="<<((void*)S)<<")"); MilesAudioSound* sound = (MilesAudioSound*)AIL_sequence_user_data( S, user_data_index); @@ -92,6 +97,7 @@ namespace { void AILCALLBACK pandaAudioAilCallback_Sample(HSAMPLE S) { assert(S); + AutoAilLock milesLock; audio_debug("pandaAudioAilCallback_Sample(HSAMPLE="<<((void*)S)<<")"); MilesAudioSound* sound = (MilesAudioSound*)AIL_sample_user_data( S, user_data_index); @@ -118,7 +124,7 @@ namespace { if (!audio || !sound) { return; } - AIL_lock(); + AutoAilLock milesLock; if (audio->handle != NULL) { switch (audio->type) { case AIL_QUICK_XMIDI_TYPE: @@ -143,13 +149,12 @@ namespace { break; } } - AIL_unlock(); } } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::MilesAudioSound // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -169,7 +174,7 @@ MilesAudioSound(MilesAudioManager* manager, } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::~MilesAudioSound // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -182,7 +187,7 @@ MilesAudioSound:: } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::play // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -202,7 +207,7 @@ play() { _manager->starting_sound(this); // Start playing: if (AIL_quick_play(_audio, _loop_count)) { - panda_AIL_quick_set_finished_callback(_audio, this); + //#*#panda_AIL_quick_set_finished_callback(_audio, this); // assert(status()==PLAYING); audio_debug(" started sound " << _file_name ); } else { @@ -216,14 +221,14 @@ play() { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::stop // Access: // Description: //////////////////////////////////////////////////////////////////// void MilesAudioSound:: stop() { miles_audio_debug("stop()"); - _manager->stoping_sound(this); + _manager->stopping_sound(this); // The _paused flag should not be cleared here. _paused is not like // the Pause button on a cd/dvd player. It is used as a flag to say // that it was looping when it was set inactive. There is no need to @@ -235,21 +240,21 @@ stop() { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::finished // Access: // Description: //////////////////////////////////////////////////////////////////// void MilesAudioSound:: finished() { miles_audio_debug("finished()"); - _manager->stoping_sound(this); + _manager->stopping_sound(this); if (!_finished_event.empty()) { throw_event(_finished_event); } } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::set_loop // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -261,7 +266,7 @@ set_loop(bool loop) { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::get_loop // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -394,7 +399,7 @@ set_volume(float volume) { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::get_volume // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -405,7 +410,7 @@ get_volume() const { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::set_balance // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -418,7 +423,7 @@ set_balance(float balance_right) { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::get_balance // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -429,7 +434,7 @@ get_balance() const { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::length // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -476,7 +481,7 @@ length() const { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::set_active // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -508,7 +513,7 @@ set_active(bool active) { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::get_active // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -519,7 +524,7 @@ get_active() const { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::set_finished_event // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -530,7 +535,7 @@ set_finished_event(const string& event) { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::get_finished_event // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -541,7 +546,7 @@ get_finished_event() const { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::get_name // Access: // Description: //////////////////////////////////////////////////////////////////// @@ -552,7 +557,7 @@ get_name() const { } //////////////////////////////////////////////////////////////////// -// Function: MilesAudioSound:: +// Function: MilesAudioSound::status // Access: // Description: //////////////////////////////////////////////////////////////////// diff --git a/panda/src/audiotraits/milesAudioSound.h b/panda/src/audiotraits/milesAudioSound.h index ff89b0da0f..b84b375ee3 100644 --- a/panda/src/audiotraits/milesAudioSound.h +++ b/panda/src/audiotraits/milesAudioSound.h @@ -26,6 +26,19 @@ #include "audioSound.h" #include "milesAudioManager.h" #include "mss.h" + +class AutoAilLock { + // This will lock and unlock the Miles AIL timer based + // on the current code block. (Auto in the class name + // is referring to "auto variable"). +public: + AutoAilLock() { + AIL_lock(); + } + ~AutoAilLock() { + AIL_unlock(); + } +}; class EXPCL_MILES_AUDIO MilesAudioSound : public AudioSound { public: @@ -129,6 +142,24 @@ private: HAUDIO audio, string file_name, float length=0.0f); friend class MilesAudioManager; + + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + AudioSound::init_type(); + register_type(_type_handle, "MilesAudioSound", + AudioSound::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; }; #include "milesAudioSound.I"