2
0
Эх сурвалжийг харах

Apply patch from forum user teedee

rdb 15 жил өмнө
parent
commit
6c41c5db1d

+ 30 - 46
panda/src/audiotraits/fmodAudioManager.cxx

@@ -171,6 +171,9 @@ FmodAudioManager() {
     _dlsname = dls_pathname.to_os_specific();
     _dlsname = dls_pathname.to_os_specific();
     _midi_info.dlsname = _dlsname.c_str();
     _midi_info.dlsname = _dlsname.c_str();
   }
   }
+
+  result = _system->createChannelGroup("UserGroup", &_channelgroup);
+  fmod_audio_errcheck("_system->createChannelGroup()", result);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -342,41 +345,34 @@ 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) {
   const FilterProperties::ConfigVector &conf = config->get_config();
   const FilterProperties::ConfigVector &conf = config->get_config();
-  FMOD_RESULT res1,res2,res3,res4,res5;
+  FMOD_RESULT result;
+
   while (1) {
   while (1) {
     int numinputs;
     int numinputs;
-    res1 = head->getNumInputs(&numinputs);
+    result = head->getNumInputs(&numinputs);
+    fmod_audio_errcheck("head->getNumInputs()", result);
     if (numinputs != 1) {
     if (numinputs != 1) {
       break;
       break;
     }
     }
     FMOD::DSP *prev;
     FMOD::DSP *prev;
-    res2 = head->getInput(0, &prev, NULL);
+    result = head->getInput(0, &prev, NULL);
+    fmod_audio_errcheck("head->getInput()", result);
     void *userdata;
     void *userdata;
-    res3 = prev->getUserData(&userdata);
+    result = prev->getUserData(&userdata);
+    fmod_audio_errcheck("prev->getUserData()", result);
     if (userdata != USER_DSP_MAGIC) {
     if (userdata != USER_DSP_MAGIC) {
       break;
       break;
     }
     }
-    res4 = prev->remove();
-    res5 = prev->release();
-    if ((res1!=FMOD_OK)||(res2!=FMOD_OK)||(res3!=FMOD_OK)||(res4!=FMOD_OK)||(res5!=FMOD_OK)) {
-      audio_error("Could not clean up DSP chain.");
-      return;
-    }
+    result = prev->remove();
+    fmod_audio_errcheck("prev->remove()", result);
+    result = prev->release();
+    fmod_audio_errcheck("prev->release()", result);
   }
   }
-  
+
   for (int i=0; i<(int)(conf.size()); i++) {
   for (int i=0; i<(int)(conf.size()); i++) {
     FMOD::DSP *dsp = make_dsp(conf[i]);
     FMOD::DSP *dsp = make_dsp(conf[i]);
-    if (dsp == 0) break;
-    FMOD::DSP *prev;
-    res1 = head->getInput(0, &prev, NULL);
-    res2 = head->disconnectFrom(prev);
-    res3 = head->addInput(dsp, NULL);
-    res4 = dsp->addInput(prev, NULL);
-    res5 = dsp->setActive(true);
-    if ((res1!=FMOD_OK)||(res2!=FMOD_OK)||(res3!=FMOD_OK)||(res4!=FMOD_OK)||(res5!=FMOD_OK)) {
-      audio_error("Could not update DSP chain.");
-      return;
-    }
+    result = _channelgroup->addDSP(dsp, NULL);
+    fmod_audio_errcheck("_channelgroup->addDSP()", result);
   }
   }
 }
 }
 
 
@@ -393,7 +389,7 @@ bool FmodAudioManager::
 configure_filters(FilterProperties *config) {
 configure_filters(FilterProperties *config) {
   FMOD_RESULT result;
   FMOD_RESULT result;
   FMOD::DSP *head;
   FMOD::DSP *head;
-  result = _system->getDSPHead(&head);
+  result = _channelgroup->getDSPHead(&head);
   if (result != 0) {
   if (result != 0) {
     audio_error("Getting DSP head: " << FMOD_ErrorString(result) );
     audio_error("Getting DSP head: " << FMOD_ErrorString(result) );
     return false;
     return false;
@@ -519,39 +515,27 @@ setSpeakerSetup(AudioManager::SpeakerModeCategory cat) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FmodAudioManager::set_volume(float volume)
 //     Function: FmodAudioManager::set_volume(float volume)
 //       Access: Public
 //       Access: Public
-//  Description: Sets the master volume.
+//  Description: Sets the volume of the AudioManager.
+//               It is not an override, but a multiplier.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void FmodAudioManager::set_volume(float volume) {
-  FMOD::ChannelGroup *channelGroup;
-  FMOD_RESULT	result;
-  
-  result = _system->getMasterChannelGroup(&channelGroup);
-  if (result == FMOD_OK) {
-    channelGroup->setVolume(volume);
-  } else {
-    fmod_audio_errcheck("_system->getMasterChannelGroup()", result);
-  }
+void FmodAudioManager::
+set_volume(float volume) {
+  FMOD_RESULT result;
+  result = _channelgroup->setVolume(volume);
+  fmod_audio_errcheck("_channelgroup->setVolume()", result);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: FmodAudioManager::get_volume()
 //     Function: FmodAudioManager::get_volume()
 //       Access: Public
 //       Access: Public
-//  Description: Returns the master volume.
+//  Description: Returns the AudioManager's volume.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 float FmodAudioManager::
 float FmodAudioManager::
 get_volume() const {
 get_volume() const {
-  FMOD::ChannelGroup *channelGroup;
-  FMOD_RESULT result;
   float volume;
   float volume;
-
-  result = _system->getMasterChannelGroup(&channelGroup);
-  if (result == FMOD_OK) {
-    channelGroup->getVolume(&volume);
-  } else {
-    fmod_audio_errcheck("_system->getMasterChannelGroup()", result);
-    volume = 1.0;
-  }
-
+  FMOD_RESULT result;
+  result = _channelgroup->getVolume(&volume);
+  fmod_audio_errcheck("_channelgroup->getVolume()", result);
   return volume;
   return volume;
 }
 }
 
 

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

@@ -184,7 +184,7 @@ private:
   
   
  private:
  private:
   
   
-  static FMOD::System *_system; 
+  static FMOD::System *_system;
   static pset<FmodAudioManager *> _all_managers;
   static pset<FmodAudioManager *> _all_managers;
 
 
   static bool _system_is_valid;
   static bool _system_is_valid;
@@ -193,6 +193,8 @@ private:
   static float _doppler_factor;
   static float _doppler_factor;
   static float _drop_off_factor;
   static float _drop_off_factor;
 
 
+  FMOD::ChannelGroup *_channelgroup;
+
   FMOD_VECTOR _position;
   FMOD_VECTOR _position;
   FMOD_VECTOR _velocity;
   FMOD_VECTOR _velocity;
   FMOD_VECTOR _forward;
   FMOD_VECTOR _forward;

+ 5 - 3
panda/src/audiotraits/fmodAudioSound.cxx

@@ -164,9 +164,9 @@ play() {
 //               reference count of the associated FmodAudioSound.
 //               reference count of the associated FmodAudioSound.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 FMOD_RESULT F_CALLBACK sound_end_callback(FMOD_CHANNEL *  channel, 
 FMOD_RESULT F_CALLBACK sound_end_callback(FMOD_CHANNEL *  channel, 
-					  FMOD_CHANNEL_CALLBACKTYPE  type, 
-					  void *commanddata1, 
-					  void *commanddata2) {
+                      FMOD_CHANNEL_CALLBACKTYPE  type, 
+                      void *commanddata1, 
+                      void *commanddata2) {
   if (type == FMOD_CHANNEL_CALLBACKTYPE_END) {
   if (type == FMOD_CHANNEL_CALLBACKTYPE_END) {
     FMOD::Channel *fc = (FMOD::Channel *)channel;
     FMOD::Channel *fc = (FMOD::Channel *)channel;
     void *userdata = NULL;
     void *userdata = NULL;
@@ -383,6 +383,8 @@ start_playing() {
   if (_channel == 0) {
   if (_channel == 0) {
     result = _manager->_system->playSound(FMOD_CHANNEL_FREE, _sound, true, &_channel);
     result = _manager->_system->playSound(FMOD_CHANNEL_FREE, _sound, true, &_channel);
     fmod_audio_errcheck("_system->playSound()", result);
     fmod_audio_errcheck("_system->playSound()", result);
+    result = _channel->setChannelGroup(_manager->_channelgroup);
+    fmod_audio_errcheck("_channel->setChannelGroup()", result);
     result = _channel->setUserData(this);
     result = _channel->setUserData(this);
     fmod_audio_errcheck("_channel->setUserData()", result);
     fmod_audio_errcheck("_channel->setUserData()", result);
     result = _channel->setCallback(sound_end_callback);
     result = _channel->setCallback(sound_end_callback);