Browse Source

first attempt to protect fmod against multithreaded access

David Rose 14 years ago
parent
commit
25cb3ae4a5

+ 20 - 1
panda/src/audiotraits/fmodAudioManager.cxx

@@ -26,9 +26,9 @@
 #include "config_util.h"
 #include "config_util.h"
 #include "fmodAudioManager.h"
 #include "fmodAudioManager.h"
 #include "fmodAudioSound.h"
 #include "fmodAudioSound.h"
-//Needed so People use Panda's Generic UNIX Style Paths for Filename.
 #include "filename.h"
 #include "filename.h"
 #include "virtualFileSystem.h"
 #include "virtualFileSystem.h"
+#include "reMutexHolder.h"
 
 
 //FMOD Headers.
 //FMOD Headers.
 #include <fmod.hpp>
 #include <fmod.hpp>
@@ -38,6 +38,7 @@
 
 
 TypeHandle FmodAudioManager::_type_handle;
 TypeHandle FmodAudioManager::_type_handle;
 
 
+ReMutex FmodAudioManager::_lock;
 FMOD::System *FmodAudioManager::_system; 
 FMOD::System *FmodAudioManager::_system; 
 
 
 pset<FmodAudioManager *> FmodAudioManager::_all_managers;
 pset<FmodAudioManager *> FmodAudioManager::_all_managers;
@@ -85,6 +86,7 @@ AudioManager *Create_FmodAudioManager() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 FmodAudioManager::
 FmodAudioManager::
 FmodAudioManager() {
 FmodAudioManager() {
+  ReMutexHolder holder(_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
   //We need a varible temporary to check the FMOD Version.
   //We need a varible temporary to check the FMOD Version.
@@ -187,6 +189,7 @@ FmodAudioManager() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 FmodAudioManager::
 FmodAudioManager::
 ~FmodAudioManager() {
 ~FmodAudioManager() {
+  ReMutexHolder holder(_lock);
   // Be sure to delete associated sounds before deleting the manager!
   // Be sure to delete associated sounds before deleting the manager!
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
@@ -222,6 +225,7 @@ is_valid() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 FMOD::DSP *FmodAudioManager::
 FMOD::DSP *FmodAudioManager::
 make_dsp(const FilterProperties::FilterConfig &conf) {
 make_dsp(const FilterProperties::FilterConfig &conf) {
+  ReMutexHolder holder(_lock);
   FMOD_DSP_TYPE dsptype;
   FMOD_DSP_TYPE dsptype;
   FMOD_RESULT result;
   FMOD_RESULT result;
   FMOD::DSP *dsp;
   FMOD::DSP *dsp;
@@ -348,6 +352,7 @@ make_dsp(const FilterProperties::FilterConfig &conf) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 update_dsp_chain(FMOD::DSP *head, FilterProperties *config) {
 update_dsp_chain(FMOD::DSP *head, FilterProperties *config) {
+  ReMutexHolder holder(_lock);
   const FilterProperties::ConfigVector &conf = config->get_config();
   const FilterProperties::ConfigVector &conf = config->get_config();
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
@@ -391,6 +396,7 @@ update_dsp_chain(FMOD::DSP *head, FilterProperties *config) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool FmodAudioManager::
 bool FmodAudioManager::
 configure_filters(FilterProperties *config) {
 configure_filters(FilterProperties *config) {
+  ReMutexHolder holder(_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   FMOD::DSP *head;
   FMOD::DSP *head;
   result = _channelgroup->getDSPHead(&head);
   result = _channelgroup->getDSPHead(&head);
@@ -409,6 +415,7 @@ configure_filters(FilterProperties *config) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PT(AudioSound) FmodAudioManager::
 PT(AudioSound) FmodAudioManager::
 get_sound(const string &file_name, bool positional, int) {
 get_sound(const string &file_name, bool positional, int) {
+  ReMutexHolder holder(_lock);
   //Needed so People use Panda's Generic UNIX Style Paths for Filename.
   //Needed so People use Panda's Generic UNIX Style Paths for Filename.
   //path.to_os_specific() converts it back to the proper OS version later on.
   //path.to_os_specific() converts it back to the proper OS version later on.
   
   
@@ -446,6 +453,7 @@ get_sound(MovieAudio *source, bool positional, int) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 int FmodAudioManager::
 int FmodAudioManager::
 getSpeakerSetup() {
 getSpeakerSetup() {
+  ReMutexHolder holder(_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   FMOD_SPEAKERMODE speakerMode;
   FMOD_SPEAKERMODE speakerMode;
   int returnMode;
   int returnMode;
@@ -510,6 +518,7 @@ getSpeakerSetup() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 setSpeakerSetup(AudioManager::SpeakerModeCategory cat) {
 setSpeakerSetup(AudioManager::SpeakerModeCategory cat) {
+  ReMutexHolder holder(_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   FMOD_SPEAKERMODE speakerModeType = (FMOD_SPEAKERMODE)cat;
   FMOD_SPEAKERMODE speakerModeType = (FMOD_SPEAKERMODE)cat;
   result = _system->setSpeakerMode( speakerModeType);
   result = _system->setSpeakerMode( speakerModeType);
@@ -524,6 +533,7 @@ setSpeakerSetup(AudioManager::SpeakerModeCategory cat) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 set_volume(PN_stdfloat volume) {
 set_volume(PN_stdfloat volume) {
+  ReMutexHolder holder(_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   result = _channelgroup->setVolume(volume);
   result = _channelgroup->setVolume(volume);
   fmod_audio_errcheck("_channelgroup->setVolume()", result);
   fmod_audio_errcheck("_channelgroup->setVolume()", result);
@@ -536,6 +546,7 @@ set_volume(PN_stdfloat volume) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PN_stdfloat FmodAudioManager::
 PN_stdfloat FmodAudioManager::
 get_volume() const {
 get_volume() const {
+  ReMutexHolder holder(_lock);
   float volume;
   float volume;
   FMOD_RESULT result;
   FMOD_RESULT result;
   result = _channelgroup->getVolume(&volume);
   result = _channelgroup->getVolume(&volume);
@@ -551,6 +562,7 @@ get_volume() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 set_active(bool active) {
 set_active(bool active) {
+  ReMutexHolder holder(_lock);
   if (_active != active) {
   if (_active != active) {
     _active = active;
     _active = active;
 
 
@@ -580,6 +592,7 @@ get_active() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 stop_all_sounds() {
 stop_all_sounds() {
+  ReMutexHolder holder(_lock);
   // We have to walk through this list with some care, since stopping
   // We have to walk through this list with some care, since stopping
   // a sound may also remove it from the set (if there are no other
   // a sound may also remove it from the set (if there are no other
   // references to the sound).
   // references to the sound).
@@ -601,6 +614,7 @@ stop_all_sounds() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 update() {
 update() {
+  ReMutexHolder holder(_lock);
   _system->update();
   _system->update();
 }
 }
 
 
@@ -621,6 +635,7 @@ update() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 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) {
 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) {
+  ReMutexHolder holder(_lock);
   audio_debug("FmodAudioManager::audio_3d_set_listener_attributes()");
   audio_debug("FmodAudioManager::audio_3d_set_listener_attributes()");
 
 
   FMOD_RESULT result;
   FMOD_RESULT result;
@@ -666,6 +681,7 @@ audio_3d_get_listener_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 audio_3d_set_distance_factor(PN_stdfloat factor) {
 audio_3d_set_distance_factor(PN_stdfloat factor) {
+  ReMutexHolder holder(_lock);
   audio_debug( "FmodAudioManager::audio_3d_set_distance_factor( factor= " << factor << ")" );
   audio_debug( "FmodAudioManager::audio_3d_set_distance_factor( factor= " << factor << ")" );
   
   
   FMOD_RESULT result;
   FMOD_RESULT result;
@@ -699,6 +715,7 @@ audio_3d_get_distance_factor() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 audio_3d_set_doppler_factor(PN_stdfloat factor) {
 audio_3d_set_doppler_factor(PN_stdfloat factor) {
+  ReMutexHolder holder(_lock);
   audio_debug("FmodAudioManager::audio_3d_set_doppler_factor(factor="<<factor<<")");
   audio_debug("FmodAudioManager::audio_3d_set_doppler_factor(factor="<<factor<<")");
 
 
   FMOD_RESULT result;
   FMOD_RESULT result;
@@ -730,6 +747,7 @@ audio_3d_get_doppler_factor() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioManager::
 void FmodAudioManager::
 audio_3d_set_drop_off_factor(PN_stdfloat factor) {
 audio_3d_set_drop_off_factor(PN_stdfloat factor) {
+  ReMutexHolder holder(_lock);
   audio_debug("FmodAudioManager::audio_3d_set_drop_off_factor("<<factor<<")");
   audio_debug("FmodAudioManager::audio_3d_set_drop_off_factor("<<factor<<")");
 
 
   FMOD_RESULT result;
   FMOD_RESULT result;
@@ -748,6 +766,7 @@ audio_3d_set_drop_off_factor(PN_stdfloat factor) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PN_stdfloat FmodAudioManager::
 PN_stdfloat FmodAudioManager::
 audio_3d_get_drop_off_factor() const {
 audio_3d_get_drop_off_factor() const {
+  ReMutexHolder holder(_lock);
   audio_debug("FmodAudioManager::audio_3d_get_drop_off_factor()");
   audio_debug("FmodAudioManager::audio_3d_get_drop_off_factor()");
 
 
   return _drop_off_factor;
   return _drop_off_factor;

+ 3 - 1
panda/src/audiotraits/fmodAudioManager.h

@@ -169,7 +169,9 @@ private:
   virtual bool configure_filters(FilterProperties *config);
   virtual bool configure_filters(FilterProperties *config);
   
   
  private:
  private:
-  
+  // This global lock protects all access to FMod library interfaces.
+  static ReMutex _lock;
+
   static FMOD::System *_system;
   static FMOD::System *_system;
   static pset<FmodAudioManager *> _all_managers;
   static pset<FmodAudioManager *> _all_managers;
 
 

+ 25 - 2
panda/src/audiotraits/fmodAudioSound.cxx

@@ -26,6 +26,7 @@
 #include "fmodAudioSound.h"
 #include "fmodAudioSound.h"
 #include "string_utils.h"
 #include "string_utils.h"
 #include "subfileInfo.h"
 #include "subfileInfo.h"
+#include "reMutexHolder.h"
 
 
 TypeHandle FmodAudioSound::_type_handle;
 TypeHandle FmodAudioSound::_type_handle;
 
 
@@ -39,6 +40,7 @@ TypeHandle FmodAudioSound::_type_handle;
 
 
 FmodAudioSound::
 FmodAudioSound::
 FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) { 
 FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) { 
+  ReMutexHolder holder(FmodAudioManager::_lock);
   audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: " << file_name  );
   audio_debug("FmodAudioSound::FmodAudioSound() Creating new sound, filename: " << file_name  );
 
 
   _active = manager->get_active();
   _active = manager->get_active();
@@ -212,6 +214,7 @@ FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 FmodAudioSound::
 FmodAudioSound::
 ~FmodAudioSound() {
 ~FmodAudioSound() {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
   //Remove me from table of all sounds.
   //Remove me from table of all sounds.
@@ -240,6 +243,7 @@ play() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 stop() {
 stop() {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
   if (_channel != 0) {
   if (_channel != 0) {
@@ -295,7 +299,7 @@ get_loop() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_loop_count(unsigned long loop_count) {
 set_loop_count(unsigned long loop_count) {
-
+  ReMutexHolder holder(FmodAudioManager::_lock);
   audio_debug("FmodAudioSound::set_loop_count()   Setting the sound's loop count to: " << loop_count);
   audio_debug("FmodAudioSound::set_loop_count()   Setting the sound's loop count to: " << loop_count);
 
 
   //LOCALS
   //LOCALS
@@ -328,6 +332,7 @@ set_loop_count(unsigned long loop_count) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 unsigned long FmodAudioSound::
 unsigned long FmodAudioSound::
 get_loop_count() const {
 get_loop_count() const {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   int loop_count;
   int loop_count;
 
 
@@ -350,6 +355,7 @@ get_loop_count() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_time(PN_stdfloat start_time) {
 set_time(PN_stdfloat start_time) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   _start_time = start_time;
   _start_time = start_time;
 
 
   if (status() == PLAYING) {
   if (status() == PLAYING) {
@@ -365,6 +371,7 @@ set_time(PN_stdfloat start_time) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PN_stdfloat FmodAudioSound::
 PN_stdfloat FmodAudioSound::
 get_time() const {
 get_time() const {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   unsigned int current_time;
   unsigned int current_time;
 
 
@@ -389,6 +396,7 @@ get_time() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_volume(PN_stdfloat vol) {
 set_volume(PN_stdfloat vol) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   _volume = vol;
   _volume = vol;
   set_volume_on_channel();
   set_volume_on_channel();
 }
 }
@@ -410,6 +418,7 @@ get_volume() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 start_playing() {
 start_playing() {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
   if (!_active) {
   if (!_active) {
@@ -469,6 +478,7 @@ start_playing() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_volume_on_channel() {
 set_volume_on_channel() {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
   if (_channel != 0) {
   if (_channel != 0) {
@@ -488,6 +498,7 @@ set_volume_on_channel() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_balance(PN_stdfloat bal) {
 set_balance(PN_stdfloat bal) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   _balance = bal;
   _balance = bal;
   set_speaker_mix_or_balance_on_channel();
   set_speaker_mix_or_balance_on_channel();
 }
 }
@@ -516,6 +527,7 @@ get_balance() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_play_rate(PN_stdfloat rate) {
 set_play_rate(PN_stdfloat rate) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   _playrate = rate;
   _playrate = rate;
   set_play_rate_on_channel();
   set_play_rate_on_channel();
 }
 }
@@ -537,6 +549,7 @@ get_play_rate() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_play_rate_on_channel() {
 set_play_rate_on_channel() {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   PN_stdfloat frequency = _sampleFrequency * _playrate;
   PN_stdfloat frequency = _sampleFrequency * _playrate;
   
   
@@ -568,6 +581,7 @@ get_name() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PN_stdfloat FmodAudioSound::
 PN_stdfloat FmodAudioSound::
 length() const {
 length() const {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   unsigned int length;
   unsigned int length;
 
 
@@ -594,6 +608,7 @@ length() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz) {
 set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   _location.x = px;
   _location.x = px;
   _location.y = pz;
   _location.y = pz;
   _location.z = py;
   _location.z = py;
@@ -612,6 +627,7 @@ set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat vx
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_3d_attributes_on_channel() {
 set_3d_attributes_on_channel() {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   FMOD_MODE soundMode;
   FMOD_MODE soundMode;
 
 
@@ -647,6 +663,7 @@ get_3d_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz, PN_stdfloat
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_3d_min_distance(PN_stdfloat dist) {
 set_3d_min_distance(PN_stdfloat dist) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
   _min_dist = dist;
   _min_dist = dist;
@@ -672,6 +689,7 @@ get_3d_min_distance() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_3d_max_distance(PN_stdfloat dist) {
 set_3d_max_distance(PN_stdfloat dist) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
 
 
   _max_dist = dist;
   _max_dist = dist;
@@ -703,6 +721,7 @@ get_3d_max_distance() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PN_stdfloat FmodAudioSound::
 PN_stdfloat FmodAudioSound::
 get_speaker_mix(AudioManager::SpeakerId speaker) {
 get_speaker_mix(AudioManager::SpeakerId speaker) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   if (_channel == 0) {
   if (_channel == 0) {
     return 0.0;
     return 0.0;
   }
   }
@@ -751,6 +770,7 @@ get_speaker_mix(AudioManager::SpeakerId speaker) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 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) {
 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) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   _mix[AudioManager::SPK_frontleft]  = frontleft;
   _mix[AudioManager::SPK_frontleft]  = frontleft;
   _mix[AudioManager::SPK_frontright] = frontright;
   _mix[AudioManager::SPK_frontright] = frontright;
   _mix[AudioManager::SPK_center]     = center;
   _mix[AudioManager::SPK_center]     = center;
@@ -776,6 +796,7 @@ set_speaker_mix(PN_stdfloat frontleft, PN_stdfloat frontright, PN_stdfloat cente
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_speaker_mix_or_balance_on_channel() {
 set_speaker_mix_or_balance_on_channel() {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   FMOD_MODE soundMode;
   FMOD_MODE soundMode;
 
 
@@ -825,7 +846,7 @@ get_priority() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_priority(int priority) {
 set_priority(int priority) {
-  // intentionally blank
+  ReMutexHolder holder(FmodAudioManager::_lock);
 
 
   audio_debug("FmodAudioSound::set_priority()");
   audio_debug("FmodAudioSound::set_priority()");
 
 
@@ -844,6 +865,7 @@ set_priority(int priority) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 AudioSound::SoundStatus FmodAudioSound::
 AudioSound::SoundStatus FmodAudioSound::
 status() const {
 status() const {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   FMOD_RESULT result;
   FMOD_RESULT result;
   bool playingState;
   bool playingState;
 
 
@@ -869,6 +891,7 @@ status() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void FmodAudioSound::
 void FmodAudioSound::
 set_active(bool active) {
 set_active(bool active) {
+  ReMutexHolder holder(FmodAudioManager::_lock);
   if (_active != active) {
   if (_active != active) {
     _active = active;
     _active = active;
     if (_active) {
     if (_active) {

+ 1 - 0
panda/src/audiotraits/fmodAudioSound.h

@@ -76,6 +76,7 @@
 #ifdef HAVE_FMODEX //[
 #ifdef HAVE_FMODEX //[
 
 
 #include "audioSound.h"
 #include "audioSound.h"
+#include "reMutex.h"
 
 
 #include <fmod.hpp>
 #include <fmod.hpp>
 #include <fmod_errors.h>
 #include <fmod_errors.h>