Browse Source

making code easier for me to understand, no big features added

Dave Schuyler 24 years ago
parent
commit
c64d301f3c

+ 94 - 71
panda/src/audio/audio_manager.cxx

@@ -25,7 +25,7 @@ AudioManager::UpdateFunc* AudioManager::_update_func =
 AudioManager::ShutdownFunc* AudioManager::_shutdown_func =
 AudioManager::ShutdownFunc* AudioManager::_shutdown_func =
     (AudioManager::ShutdownFunc*)0L;
     (AudioManager::ShutdownFunc*)0L;
 mutex AudioManager::_manager_mutex;
 mutex AudioManager::_manager_mutex;
-bool* AudioManager::_quit = (bool*)0L;
+bool AudioManager::_quit;
 thread* AudioManager::_spawned = (thread*)0L;
 thread* AudioManager::_spawned = (thread*)0L;
 AudioManager::LoopSet* AudioManager::_loopset = (AudioManager::LoopSet*)0L;
 AudioManager::LoopSet* AudioManager::_loopset = (AudioManager::LoopSet*)0L;
 AudioManager::LoopSet* AudioManager::_loopcopy = (AudioManager::LoopSet*)0L;
 AudioManager::LoopSet* AudioManager::_loopcopy = (AudioManager::LoopSet*)0L;
@@ -42,7 +42,8 @@ float AudioManager::_master_music_volume = 0.;
 //       Access: Public
 //       Access: Public
 //  Description: delete the AudioManager singleton
 //  Description: delete the AudioManager singleton
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-AudioManager::~AudioManager() {
+AudioManager::
+~AudioManager() {
   shutdown();
   shutdown();
   _global_ptr = (AudioManager*)0L;
   _global_ptr = (AudioManager*)0L;
 }
 }
@@ -53,7 +54,8 @@ AudioManager::~AudioManager() {
 //  Description: register a function that will maintain the buffers
 //  Description: register a function that will maintain the buffers
 //               for audio output
 //               for audio output
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::set_update_func(AudioManager::UpdateFunc* func) {
+void AudioManager::
+set_update_func(AudioManager::UpdateFunc* func) {
   if (_update_func != (AudioManager::UpdateFunc*)0L)
   if (_update_func != (AudioManager::UpdateFunc*)0L)
     audio_cat->error() << "There maybe be more then one audio driver installed"
     audio_cat->error() << "There maybe be more then one audio driver installed"
                << endl;
                << endl;
@@ -66,11 +68,14 @@ void AudioManager::set_update_func(AudioManager::UpdateFunc* func) {
 //  Description: make a copy of the loopset to use for the rest of
 //  Description: make a copy of the loopset to use for the rest of
 //               update
 //               update
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::copy_loopset() {
-  if (_loopcopy == (LoopSet*)0L)
+void AudioManager::
+copy_loopset() {
+  if (!_loopcopy) {
     _loopcopy = new LoopSet;
     _loopcopy = new LoopSet;
-  if (_loopset != (LoopSet*)0L)
+  }
+  if (_loopset) {
     *_loopcopy = *_loopset;
     *_loopcopy = *_loopset;
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -78,26 +83,26 @@ void AudioManager::copy_loopset() {
 //       Access: Public, Static
 //       Access: Public, Static
 //  Description: do generic update stuff
 //  Description: do generic update stuff
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::ns_update() {
+void AudioManager::
+ns_update() {
   // handle looping
   // handle looping
-  if (_loopcopy != (LoopSet*)0L)
+  if (!_loopcopy) {
     for (LoopSet::iterator i=_loopcopy->begin(); i!=_loopcopy->end(); ++i) {
     for (LoopSet::iterator i=_loopcopy->begin(); i!=_loopcopy->end(); ++i) {
       AudioSound* sound = *i;
       AudioSound* sound = *i;
       if (sound->status() == AudioSound::READY) {
       if (sound->status() == AudioSound::READY) {
-    if (audio_cat.is_debug())
-      audio_cat->debug() << "AudioManager::ns_update looping '"
-                 << sound->get_name() << "'" << endl;
-    AudioManager::play(sound);
-    AudioManager::set_loop(sound, true);
-      } else if (AudioManager::_master_volume_change)
-    if (sound->get_player()->adjust_volume(sound->get_state())) {
-      if (audio_cat.is_debug())
-        audio_cat->debug() << "AudioManager::ns_update sound is turned "
-                   << "off, stopping '" << sound->get_name()
-                   << "'" << endl;
-      AudioManager::stop(sound);
-    }
+        audio_debug("AudioManager::ns_update looping '" 
+            << sound->get_name() << "'");
+        AudioManager::play(sound);
+        AudioManager::set_loop(sound, true);
+      } else if (AudioManager::_master_volume_change) {
+        if (sound->get_player()->adjust_volume(sound->get_state())) {
+          audio_debug("AudioManager::ns_update sound is turned "
+              << "off, stopping '" << sound->get_name() << "'");
+          AudioManager::stop(sound);
+        }
+      }
     }
     }
+  }
   AudioManager::_master_volume_change = false;
   AudioManager::_master_volume_change = false;
 }
 }
 
 
@@ -107,13 +112,12 @@ void AudioManager::ns_update() {
 //  Description: register a function that will shutdown the internal
 //  Description: register a function that will shutdown the internal
 //               audio state
 //               audio state
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::set_shutdown_func(AudioManager::ShutdownFunc* func) {
-  if (_shutdown_func != (AudioManager::ShutdownFunc*)0L)
-    audio_cat->error() << "There maybe be more then one audio driver installed"
-               << endl;
+void AudioManager::
+set_shutdown_func(AudioManager::ShutdownFunc* func) {
+  if (_shutdown_func) {
+    audio_error("There maybe be more then one audio driver installed");
+  }
   _shutdown_func = func;
   _shutdown_func = func;
-  if (_quit == (bool*)0L)
-    _quit = new bool(false);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -122,9 +126,11 @@ void AudioManager::set_shutdown_func(AudioManager::ShutdownFunc* func) {
 //  Description: Initializes and/or returns the global pointer to the
 //  Description: Initializes and/or returns the global pointer to the
 //               one AudioManager object in the system.
 //               one AudioManager object in the system.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-AudioManager* AudioManager::get_ptr() {
-  if (_global_ptr == (AudioManager*)0L)
+AudioManager* AudioManager::
+get_ptr() {
+  if (!_global_ptr) {
     _global_ptr = new AudioManager;
     _global_ptr = new AudioManager;
+  }
   return _global_ptr;
   return _global_ptr;
 }
 }
 
 
@@ -133,14 +139,15 @@ AudioManager* AudioManager::get_ptr() {
 //       Access: Private
 //       Access: Private
 //  Description: get the player off the sound, and start it playing
 //  Description: get the player off the sound, and start it playing
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::ns_play(AudioSound* sound, float start_time) {
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "AudioManager: playing sound 0x" << (void*)sound
-               << " (" << sound->get_name() << ")" << endl;
-  if (sound->status() == AudioSound::PLAYING)
+void AudioManager::
+ns_play(AudioSound* sound, float start_time) {
+  audio_debug("AudioManager: playing sound 0x" 
+      << (void*)sound << " (" << sound->get_name() << ")");
+  if (sound->status() == AudioSound::PLAYING) {
     this->ns_stop(sound);
     this->ns_stop(sound);
-  sound->get_player()->play_sound(sound->get_sound(), sound->get_state(),
-                  start_time);
+  }
+  sound->get_player()->play_sound(sound->get_sound(), 
+      sound->get_state(), start_time);
   sound->get_player()->adjust_volume(sound->get_state());
   sound->get_player()->adjust_volume(sound->get_state());
 }
 }
 
 
@@ -149,13 +156,14 @@ void AudioManager::ns_play(AudioSound* sound, float start_time) {
 //       Access: Private
 //       Access: Private
 //  Description: get the player off the sound, and stop it playing
 //  Description: get the player off the sound, and stop it playing
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::ns_stop(AudioSound* sound) {
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "AudioManager: stopping sound 0x" << (void*)sound
-               << " (" << sound->get_name() << ")" << endl;
+void AudioManager::
+ns_stop(AudioSound* sound) {
+  audio_debug("AudioManager: stopping sound 0x" 
+      << (void*)sound << " (" << sound->get_name() << ")");
   this->ns_set_loop(sound, false);
   this->ns_set_loop(sound, false);
-  if (sound->status() == AudioSound::PLAYING)
+  if (sound->status() == AudioSound::PLAYING) {
     sound->get_player()->stop_sound(sound->get_sound(), sound->get_state());
     sound->get_player()->stop_sound(sound->get_sound(), sound->get_state());
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -163,7 +171,8 @@ void AudioManager::ns_stop(AudioSound* sound) {
 //       Access: Private
 //       Access: Private
 //  Description: set the looping state of the given sound
 //  Description: set the looping state of the given sound
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::ns_set_loop(AudioSound* sound, bool state) {
+void AudioManager::
+ns_set_loop(AudioSound* sound, bool state) {
   mutex_lock l(_manager_mutex);
   mutex_lock l(_manager_mutex);
   if (_loopset == (LoopSet*)0L)
   if (_loopset == (LoopSet*)0L)
     _loopset = new LoopSet;
     _loopset = new LoopSet;
@@ -178,12 +187,14 @@ void AudioManager::ns_set_loop(AudioSound* sound, bool state) {
 //       Access: Private
 //       Access: Private
 //  Description: get the looping state of the given sound
 //  Description: get the looping state of the given sound
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-bool AudioManager::ns_get_loop(AudioSound* sound) {
+bool AudioManager::
+ns_get_loop(AudioSound* sound) {
   mutex_lock l(_manager_mutex);
   mutex_lock l(_manager_mutex);
-  if (_loopset == (LoopSet*)0L)
+  if (!_loopset) {
     return false;
     return false;
+  }
   LoopSet::iterator i = _loopset->find(sound);
   LoopSet::iterator i = _loopset->find(sound);
-  return (i != _loopset->end());
+  return i != _loopset->end();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -191,16 +202,25 @@ bool AudioManager::ns_get_loop(AudioSound* sound) {
 //       Access: static
 //       Access: static
 //  Description: the thread function to call update forever.
 //  Description: the thread function to call update forever.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void* AudioManager::spawned_update(void* data) {
+void* AudioManager::
+spawned_update(void* data) {
   bool* flag = (bool*)data;
   bool* flag = (bool*)data;
-  while (! (*flag)) {
-    AudioManager::update();
-    ipc_traits::sleep(0, audio_auto_update_delay);
+  try {
+    // *flag connects to AudioManager::_quit
+    while (! (*flag)) {
+      AudioManager::update();
+      ipc_traits::sleep(0, audio_auto_update_delay);
+    }
+  } catch (...) {
+    audio_error("Uncought Exception in audio update thread.");
+    throw;
   }
   }
+  // Switch the flag back to false,
+  // so AudioManager::ns_shutdown()
+  // knows we're done:
   *flag = false;
   *flag = false;
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "exiting update thread" << endl;
-  return (void*)0L;
+  audio_debug("exiting update thread");
+  return 0;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -208,7 +228,8 @@ void* AudioManager::spawned_update(void* data) {
 //       Access: Private
 //       Access: Private
 //  Description: get the player off the sound, and set volume on it
 //  Description: get the player off the sound, and set volume on it
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::ns_set_volume(AudioSound* sound, float v) {
+void AudioManager::
+ns_set_volume(AudioSound* sound, float v) {
   sound->get_player()->set_volume(sound->get_state(), v);
   sound->get_player()->set_volume(sound->get_state(), v);
 }
 }
 
 
@@ -217,11 +238,10 @@ void AudioManager::ns_set_volume(AudioSound* sound, float v) {
 //       Access: Private
 //       Access: Private
 //  Description: spawn a thread that calls update every so often
 //  Description: spawn a thread that calls update every so often
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::ns_spawn_update() {
-  if (_spawned == (thread*)0L) {
-    if (_quit == (bool*)0L)
-      _quit = new bool(false);
-    *_quit = false;
+void AudioManager::
+ns_spawn_update() {
+  if (!_spawned) {
+    _quit = false;
     thread::priority_t pri;
     thread::priority_t pri;
     switch (audio_thread_priority) {
     switch (audio_thread_priority) {
     case 0:
     case 0:
@@ -234,14 +254,14 @@ void AudioManager::ns_spawn_update() {
       pri = thread::PRIORITY_HIGH;
       pri = thread::PRIORITY_HIGH;
       break;
       break;
     default:
     default:
-      audio_cat->error() << "audio-thread-priority set to something other "
-             << "then low, normal, or high" << endl;
+      audio_error("audio-thread-priority set to something other "
+          << "then low, normal, or high");
       audio_thread_priority = 1;
       audio_thread_priority = 1;
       pri = thread::PRIORITY_NORMAL;
       pri = thread::PRIORITY_NORMAL;
     }
     }
-    _spawned = thread::create(spawned_update, _quit, pri);
+    _spawned = thread::create(spawned_update, &_quit, pri);
   } else {
   } else {
-    audio_cat->error() << "tried to spawn 2 update threads" << endl;
+    audio_error("tried to spawn 2 update threads");
   }
   }
 }
 }
 
 
@@ -250,14 +270,17 @@ void AudioManager::ns_spawn_update() {
 //       Access: Private
 //       Access: Private
 //  Description: non-static implementation of shutdown stuff
 //  Description: non-static implementation of shutdown stuff
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioManager::ns_shutdown() {
-  if (_quit != (bool*)0L)
-    *_quit = true;
-  if (_shutdown_func != (ShutdownFunc*)0L)
+void AudioManager::
+ns_shutdown() {
+  audio_debug("AudioManager::ns_shutdown()");
+  _quit = true;
+  if (_shutdown_func) {
     (*_shutdown_func)();
     (*_shutdown_func)();
-  if (_spawned != (thread*)0L)
-    while (*_quit);
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "update thread has shutdown" << endl;
-  delete _quit;
+  }
+  if (_spawned) {
+    while (_quit) {
+      // waiting on update thread to stop spinning.
+    }
+  }
+  audio_debug("update thread has shutdown");
 }
 }

+ 43 - 32
panda/src/audio/audio_manager.h

@@ -28,6 +28,48 @@
 #include "pset.h"
 #include "pset.h"
 
 
 class EXPCL_PANDA AudioManager {
 class EXPCL_PANDA AudioManager {
+  typedef void UpdateFunc();
+  typedef void ShutdownFunc();
+  typedef pset<AudioSound*> LoopSet;
+
+PUBLISHED:
+  INLINE static void play(AudioSound*, float = 0.0);
+  INLINE static void stop(AudioSound*);
+  
+  INLINE static void set_loop(AudioSound*, bool);
+  INLINE static bool get_loop(AudioSound*);
+  
+  INLINE static void set_volume(AudioSound*, float);
+  
+  INLINE static void update();
+  INLINE static void spawn_update();
+  
+  INLINE static void shutdown();
+  
+  INLINE static void set_master_sfx_volume(float);
+  INLINE static float get_master_sfx_volume();
+  
+  INLINE static void set_master_music_volume(float);
+  INLINE static float get_master_music_volume();
+  
+  INLINE static void set_all_sound_active(bool);
+  INLINE static bool get_all_sound_active();
+  
+  INLINE static void set_sfx_active(bool);
+  INLINE static bool get_sfx_active();
+  
+  INLINE static void set_music_active(bool);
+  INLINE static bool get_music_active();
+
+public:
+  INLINE static void set_hard_sfx_active(bool);
+  INLINE static void set_hard_music_active(bool);
+
+  virtual ~AudioManager();
+
+  static void set_update_func(UpdateFunc*);
+  static void set_shutdown_func(ShutdownFunc*);
+
 private:
 private:
   INLINE AudioManager();
   INLINE AudioManager();
 
 
@@ -44,14 +86,11 @@ private:
   static AudioManager* get_ptr();
   static AudioManager* get_ptr();
   static void* spawned_update(void*);
   static void* spawned_update(void*);
 
 
-  typedef void UpdateFunc();
-  typedef void ShutdownFunc();
-  typedef pset<AudioSound*> LoopSet;
   static AudioManager* _global_ptr;
   static AudioManager* _global_ptr;
   static UpdateFunc* _update_func;
   static UpdateFunc* _update_func;
   static ShutdownFunc* _shutdown_func;
   static ShutdownFunc* _shutdown_func;
   static mutex _manager_mutex;
   static mutex _manager_mutex;
-  static bool* _quit;
+  static bool _quit;
   static thread* _spawned;
   static thread* _spawned;
   static LoopSet* _loopset;
   static LoopSet* _loopset;
   static LoopSet* _loopcopy;
   static LoopSet* _loopcopy;
@@ -62,34 +101,6 @@ private:
   static float _master_sfx_volume;
   static float _master_sfx_volume;
   static float _master_music_volume;
   static float _master_music_volume;
   static bool _master_volume_change;
   static bool _master_volume_change;
-public:
-  virtual ~AudioManager();
-
-  static void set_update_func(UpdateFunc*);
-  static void set_shutdown_func(ShutdownFunc*);
-
-PUBLISHED:
-  INLINE static void play(AudioSound*, float = 0.);
-  INLINE static void stop(AudioSound*);
-  INLINE static void set_loop(AudioSound*, bool);
-  INLINE static bool get_loop(AudioSound*);
-  INLINE static void set_volume(AudioSound*, float);
-  INLINE static void update();
-  INLINE static void spawn_update();
-  INLINE static void shutdown();
-  INLINE static void set_master_sfx_volume(float);
-  INLINE static void set_master_music_volume(float);
-  INLINE static float get_master_sfx_volume();
-  INLINE static float get_master_music_volume();
-  INLINE static void set_all_sound_active(bool);
-  INLINE static bool get_all_sound_active();
-  INLINE static void set_sfx_active(bool);
-  INLINE static void set_music_active(bool);
-  INLINE static bool get_sfx_active();
-  INLINE static bool get_music_active();
-public:
-  INLINE static void set_hard_sfx_active(bool);
-  INLINE static void set_hard_music_active(bool);
 };
 };
 
 
 #include "audio_manager.I"
 #include "audio_manager.I"

+ 81 - 73
panda/src/audio/audio_midi.cxx

@@ -78,31 +78,30 @@ AudioMidi::AudioMidi(Filename filename, int header_idx) {
   unsigned LONG curr = read32(in, dummy);
   unsigned LONG curr = read32(in, dummy);
   int count = 0;
   int count = 0;
   bool done = false;
   bool done = false;
-  do {
+  while (1) {
     if (curr == MThd) {
     if (curr == MThd) {
       ++count;
       ++count;
-      if (count == header_idx)
-    done = true;
-      else {
-    scroll8(prev, curr, in, dummy);
-    scroll8(prev, curr, in, dummy);
-    scroll8(prev, curr, in, dummy);
-    scroll8(prev, curr, in, dummy);
+      if (count == header_idx) {
+        break;
+      } else {
+        scroll8(prev, curr, in, dummy);
+        scroll8(prev, curr, in, dummy);
+        scroll8(prev, curr, in, dummy);
+        scroll8(prev, curr, in, dummy);
       }
       }
     } else {
     } else {
       scroll8(prev, curr, in, dummy);
       scroll8(prev, curr, in, dummy);
     }
     }
-    if (in.eof())
-      done = true;
-  } while (!done);
-  if (in.eof()) {
-    cerr << "fewer then " << header_idx << " headers in file (" << count
-     << ")" << endl;
-    return;
+    if (in.eof()) {
+      cerr << "fewer than " << header_idx << " headers in file (" << count
+       << ")" << endl;
+      return;
+    }
   }
   }
   if (prev == RIFF) {
   if (prev == RIFF) {
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "it's a RIFF file" << endl;
       audio_cat->debug() << "it's a RIFF file" << endl;
+    }
     curr = read32(in, dummy);
     curr = read32(in, dummy);
     curr = read32(in, dummy);
     curr = read32(in, dummy);
     curr = read32(in, dummy);
     curr = read32(in, dummy);
@@ -129,11 +128,11 @@ AudioMidi::AudioMidi(Filename filename, int header_idx) {
     done = false;
     done = false;
     do {
     do {
       if (curr == MThd)
       if (curr == MThd)
-    done = true;
+        done = true;
       else
       else
-    scroll8(prev, curr, in, dummy);
+        scroll8(prev, curr, in, dummy);
       if (in.eof())
       if (in.eof())
-    done = true;
+        done = true;
     } while (!done);
     } while (!done);
     if (in.eof()) {
     if (in.eof()) {
       cerr << "truncated file!" << endl;
       cerr << "truncated file!" << endl;
@@ -144,58 +143,64 @@ AudioMidi::AudioMidi(Filename filename, int header_idx) {
     numtracks = read16(in, dummy);
     numtracks = read16(in, dummy);
     division = read16(in, dummy);
     division = read16(in, dummy);
   }
   }
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "Read header.  tracklen = " << tracklen
     audio_cat->debug() << "Read header.  tracklen = " << tracklen
-               << "  format = " << format << "  numtracks = "
-               << numtracks << "  division = " << division << endl;
+        << "  format = " << format << "  numtracks = "
+        << numtracks << "  division = " << division << endl;
+  }
   for (int currtrack = 0; currtrack < numtracks; ++currtrack) {
   for (int currtrack = 0; currtrack < numtracks; ++currtrack) {
     string fudge;
     string fudge;
     curr = read32(in, dummy);
     curr = read32(in, dummy);
     if (curr != MTrk) {
     if (curr != MTrk) {
-      if (audio_cat.is_debug())
-    audio_cat->debug() << "having to seach for track #" << currtrack
-               << endl;
+      if (audio_cat.is_debug()) {
+        audio_cat->debug() << "having to seach for track #" 
+            << currtrack << endl;
+      }
       if (curr == MThd) {
       if (curr == MThd) {
-    if (audio_cat.is_debug())
-      audio_cat->debug() << "hit a header instead, skipping track" << endl;
-    continue;
+        if (audio_cat.is_debug()) {
+          audio_cat->debug() << "hit a header instead, skipping track" << endl;
+        }
+        continue;
       } else {
       } else {
-    done = false;
-    if (currtrack > 0) {
-      string stmp = (*(_seq.rbegin()));
-      int i = stmp.rfind("MTrk");
-      if (i != string::npos) {
-        fudge = stmp.substr(i+4, string::npos);
-        unsigned char b;
-        b = ((curr >> 24) & 0xff);
-        fudge += b;
-        b = ((curr >> 16) & 0xff);
-        fudge += b;
-        b = ((curr >> 8) & 0xff);
-        fudge += b;
-        b = (curr & 0xff);
-        fudge += b;
-        done = true;
-      }
-    }
-    if (!done) {
-      do {
-        if (curr == MTrk)
-          done = true;
-        else
-          scroll8(prev, curr, in, dummy);
-        if (in.eof())
-          done = true;
-      } while (!done);
-      if (in.eof()) {
-        cerr << "truncated file" << endl;
-        return;
+        done = false;
+        if (currtrack > 0) {
+          string stmp = (*(_seq.rbegin()));
+          int i = stmp.rfind("MTrk");
+          if (i != string::npos) {
+            fudge = stmp.substr(i+4, string::npos);
+            unsigned char b;
+            b = ((curr >> 24) & 0xff);
+            fudge += b;
+            b = ((curr >> 16) & 0xff);
+            fudge += b;
+            b = ((curr >> 8) & 0xff);
+            fudge += b;
+            b = (curr & 0xff);
+            fudge += b;
+            done = true;
+          }
+        }
+        if (!done) {
+          do {
+            if (curr == MTrk) {
+              done = true;
+            } else {
+              scroll8(prev, curr, in, dummy);
+            }
+            if (in.eof()) {
+              done = true;
+            }
+          } while (!done);
+          if (in.eof()) {
+            cerr << "truncated file" << endl;
+            return;
+          }
+        }
       }
       }
     }
     }
-      }
-    }
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "fudge = '" << fudge << "'" << endl;
       audio_cat->debug() << "fudge = '" << fudge << "'" << endl;
+    }
     istringstream fudges(fudge);
     istringstream fudges(fudge);
     if (fudge.empty()) {
     if (fudge.empty()) {
       // force EOF
       // force EOF
@@ -205,34 +210,37 @@ AudioMidi::AudioMidi(Filename filename, int header_idx) {
     unsigned LONG thislen = read32(in, fudges);
     unsigned LONG thislen = read32(in, fudges);
     if (audio_cat.is_debug())
     if (audio_cat.is_debug())
       audio_cat->debug() << "found track #" << currtrack << " with length = "
       audio_cat->debug() << "found track #" << currtrack << " with length = "
-             << thislen << endl;
+          << thislen << endl;
     {
     {
       ostringstream os;
       ostringstream os;
       int i;
       int i;
       for (i=0; i<thislen; ++i) {
       for (i=0; i<thislen; ++i) {
-    unsigned char b;
-    b = read8(in, fudges);
-    os << b;
-    if (in.eof() && ((i+1) < thislen))
-      break;
+        unsigned char b;
+        b = read8(in, fudges);
+        os << b;
+        if (in.eof() && ((i+1) < thislen))
+          break;
       }
       }
       if (in.eof() && (i != thislen)) {
       if (in.eof() && (i != thislen)) {
-    cerr << "truncated file" << endl;
+        cerr << "truncated file" << endl;
       }
       }
       string s = os.str();
       string s = os.str();
       _seq.push_back(s);
       _seq.push_back(s);
-      if (audio_cat.is_debug())
-    audio_cat->debug() << "track data (" << s.length() << "): '" << s
-               << "'" << endl;
+      if (audio_cat.is_debug()) {
+        audio_cat->debug() << "track data (" << s.length() << "): '" << s
+            << "'" << endl;
+      }
     }
     }
   }
   }
-  if ((_seq.size() != numtracks) && audio_cat.is_debug())
+  if ((_seq.size() != numtracks) && audio_cat.is_debug()) {
     audio_cat->debug()
     audio_cat->debug()
       << "actual number of tracks read does not match header. ("
       << "actual number of tracks read does not match header. ("
       << _seq.size() << " != " << numtracks << ")" << endl;
       << _seq.size() << " != " << numtracks << ")" << endl;
+  }
 }
 }
 
 
-AudioMidi::AudioMidi(const AudioMidi& c) : _seq(c._seq) {}
+AudioMidi::AudioMidi(const AudioMidi& c) : _seq(c._seq) {
+}
 
 
 AudioMidi::~AudioMidi() {
 AudioMidi::~AudioMidi() {
 }
 }

+ 1 - 1
panda/src/audio/audio_midi.h

@@ -28,7 +28,7 @@ private:
   typedef plist<string> StrList;
   typedef plist<string> StrList;
   StrList _seq;
   StrList _seq;
 public:
 public:
-  AudioMidi(Filename, int = 1);
+  AudioMidi(Filename filename, int header_idx = 1);
   AudioMidi(const AudioMidi&);
   AudioMidi(const AudioMidi&);
   ~AudioMidi();
   ~AudioMidi();
 
 

+ 99 - 72
panda/src/audio/audio_pool.cxx

@@ -20,18 +20,20 @@
 #include "config_audio.h"
 #include "config_audio.h"
 #include <config_util.h>
 #include <config_util.h>
 
 
-AudioPool* AudioPool::_global_ptr = (AudioPool*)0L;
+AudioPool* AudioPool::_global_ptr; // static is 0 by default.
 typedef pmap<string, AudioPool::SoundLoadFunc*> SoundLoaders;
 typedef pmap<string, AudioPool::SoundLoadFunc*> SoundLoaders;
-SoundLoaders* _sound_loaders = (SoundLoaders*)0L;
+static SoundLoaders* _sound_loaders; // static is 0 by default.
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: check_sound_loaders
 //     Function: check_sound_loaders
 //       Access: Static
 //       Access: Static
 //  Description: ensure that the sound loaders map has been initialized
 //  Description: ensure that the sound loaders map has been initialized
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-static void check_sound_loaders() {
-  if (_sound_loaders == (SoundLoaders*)0L)
+static void 
+check_sound_loaders() {
+  if (!_sound_loaders) {
     _sound_loaders = new SoundLoaders;
     _sound_loaders = new SoundLoaders;
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -40,9 +42,11 @@ static void check_sound_loaders() {
 //  Description: Initializes and/or returns the global pointer to the
 //  Description: Initializes and/or returns the global pointer to the
 //               one AudioPool object in the system.
 //               one AudioPool object in the system.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-AudioPool* AudioPool::get_ptr() {
-  if (_global_ptr == (AudioPool*)0L)
+AudioPool* AudioPool::
+get_ptr() {
+  if (!_global_ptr) {
     _global_ptr = new AudioPool;
     _global_ptr = new AudioPool;
+  }
   audio_load_loaders();
   audio_load_loaders();
   return _global_ptr;
   return _global_ptr;
 }
 }
@@ -52,71 +56,86 @@ AudioPool* AudioPool::get_ptr() {
 //       Access: Private
 //       Access: Private
 //  Description: The nonstatic implementation of has_sound().
 //  Description: The nonstatic implementation of has_sound().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-bool AudioPool::ns_has_sound(Filename filename) {
+bool AudioPool::
+ns_has_sound(Filename filename) {
   filename.resolve_filename(get_sound_path());
   filename.resolve_filename(get_sound_path());
 
 
   SoundMap::const_iterator si;
   SoundMap::const_iterator si;
   si = _sounds.find(filename);
   si = _sounds.find(filename);
-  if (si != _sounds.end()) {
-    // this sound was previously loaded
-    return true;
+  return si != _sounds.end();
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: AudioPool::call_sound_loader
+//       Access: Private
+//  Description: Call the sound loader to load the sound, without
+//               looking in the sound pool.
+////////////////////////////////////////////////////////////////////
+PT(AudioTraits::SoundClass) AudioPool::
+call_sound_loader(Filename fileName) {
+  if (!fileName.exists()) {
+    audio_info("'" << fileName << "' does not exist");
+    return 0;
+  }
+  audio_info("Loading sound " << fileName);
+  // Determine which sound loader to use:
+  string ext = fileName.get_extension();
+  SoundLoaders::const_iterator sli;
+  check_sound_loaders();
+  sli = _sound_loaders->find(ext);
+  if (sli == _sound_loaders->end()) {
+    audio_error("no loader available for audio type '" << ext << "'");
+    return 0;
+  }
+  // Call the sound loader:
+  PT(AudioTraits::SoundClass) sound=(*((*sli).second))(fileName);
+  if (!sound) {
+    audio_error("could not load '" << fileName << "'");
   }
   }
-  return false;
+  return sound;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: AudioPool::ns_load_sound
 //     Function: AudioPool::ns_load_sound
 //       Access: Private
 //       Access: Private
 //  Description: The nonstatic implementation of load_sound().
 //  Description: The nonstatic implementation of load_sound().
-////////////////////////////////////////////////////////////////////
-AudioSound* AudioPool::ns_load_sound(Filename filename) {
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "in AudioPool::ns_load_sound" << endl;
-  filename.resolve_filename(get_sound_path());
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "resolved filename is '" << filename << "'" << endl;
+//
+//               First we will search the pool for the sound.
+//               If that fails, we will call the loader for the
+//               sound, and then add this sound to the pool.
+////////////////////////////////////////////////////////////////////
+AudioSound* AudioPool::
+ns_load_sound(Filename fileName) {
+  audio_debug("in AudioPool::ns_load_sound");
+  fileName.resolve_filename(get_sound_path());
+  audio_debug("resolved fileName is '" << fileName << "'");
 
 
+  PT(AudioTraits::SoundClass) sound=0;
+  // Get the sound, either from the pool or from a loader:
   SoundMap::const_iterator si;
   SoundMap::const_iterator si;
-  si = _sounds.find(filename);
+  si = _sounds.find(fileName);
   if (si != _sounds.end()) {
   if (si != _sounds.end()) {
-    // this sound was previously loaded
-    PT(AudioTraits::SoundClass) sc = (*si).second;
-    if (audio_cat.is_debug())
-      audio_cat->debug() << "sound is already loaded (0x" << (void*)sc
-             << ")" << endl;
-    AudioSound* ret = new AudioSound(sc, sc->get_state(), sc->get_player(),
-                     sc->get_delstate(), filename);
-    if (audio_cat.is_debug())
-      audio_cat->debug() << "AudioPool: returning 0x" << (void*)ret << endl;
-    return ret;
-  }
-  if (!filename.exists()) {
-    audio_cat.info() << "'" << filename << "' does not exist" << endl;
-    return (AudioSound*)0L;
-  }
-  audio_cat.info() << "Loading sound " << filename << endl;
-  string ext = filename.get_extension();
-  SoundLoaders::const_iterator sli;
-  check_sound_loaders();
-  sli = _sound_loaders->find(ext);
-  if (sli == _sound_loaders->end()) {
-    audio_cat->error() << "no loader available for audio type '" << ext
-               << "'" << endl;
-    return (AudioSound*)0L;
+    // ...found the sound in the pool.
+    sound = (*si).second;
+    audio_debug("sound found in pool (0x" << (void*)sound << ")");
+  } else {
+    // ...the sound was not found in the cache/pool.
+    sound=call_sound_loader(fileName);
+    if (sound) {
+      // Put it in the pool:
+      _sounds[fileName] = sound;
+    }
   }
   }
-  PT(AudioTraits::SoundClass) sound = (*((*sli).second))(filename);
-  if (sound == (AudioTraits::SoundClass*)0L) {
-    audio_cat->error() << "could not load '" << filename << "'" << endl;
-    return (AudioSound*)0L;
+  // Create an AudioSound from the sound:
+  AudioSound* audioSound = 0;
+  if (sound) {
+    audioSound = new AudioSound(sound, 
+      sound->get_state(), sound->get_player(),
+      sound->get_delstate(), fileName);
   }
   }
-  AudioSound* the_sound = new AudioSound(sound, sound->get_state(),
-                     sound->get_player(),
-                     sound->get_delstate(), filename);
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "AudioPool: returning 0x" << (void*)the_sound
-               << endl;
-  _sounds[filename] = sound;
-  return the_sound;
+  audio_debug("AudioPool: returning 0x" << (void*)audioSound);
+  return audioSound;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -125,9 +144,7 @@ AudioSound* AudioPool::ns_load_sound(Filename filename) {
 //  Description: The nonstatic implementation of release_sound().
 //  Description: The nonstatic implementation of release_sound().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void AudioPool::ns_release_sound(AudioSound* sound) {
 void AudioPool::ns_release_sound(AudioSound* sound) {
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "AudioPool: releasing sound 0x" << (void*)sound
-               << endl;
+  audio_debug("AudioPool: releasing sound 0x" << (void*)sound);
   string filename = sound->get_name();
   string filename = sound->get_name();
   SoundMap::iterator si;
   SoundMap::iterator si;
   si = _sounds.find(filename);
   si = _sounds.find(filename);
@@ -140,9 +157,9 @@ void AudioPool::ns_release_sound(AudioSound* sound) {
 //       Access: Private
 //       Access: Private
 //  Description: The nonstatic implementation of release_all_sounds().
 //  Description: The nonstatic implementation of release_all_sounds().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioPool::ns_release_all_sounds() {
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "AudioPool: releasing all sounds" << endl;
+void AudioPool::
+ns_release_all_sounds() {
+  audio_debug("AudioPool: releasing all sounds");
   _sounds.clear();
   _sounds.clear();
 }
 }
 
 
@@ -151,17 +168,24 @@ void AudioPool::ns_release_all_sounds() {
 //       Access: Public, static
 //       Access: Public, static
 //  Description: A static function to register a function for loading
 //  Description: A static function to register a function for loading
 //               audio sounds.
 //               audio sounds.
+//               ext: a file name extension (e.g. .mp3 or .wav).
+//               func: a function that will be called to load a file
+//                     with the extension 'ext'.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-void AudioPool::register_sound_loader(const string& ext,
-                       AudioPool::SoundLoadFunc* func) {
-  SoundLoaders::const_iterator sli;
+void AudioPool::
+register_sound_loader(const string& ext,
+    AudioPool::SoundLoadFunc* func) {
   check_sound_loaders();
   check_sound_loaders();
-  sli = _sound_loaders->find(ext);
-  if (sli != _sound_loaders->end()) {
-    audio_cat->warning() << "attempted to register a loader for audio type '"
-             << ext << "' more then once." << endl;
-    return;
-  }
+  #ifndef NDEBUG //[
+    // Debug check: See if the loader is already registered:
+    SoundLoaders::const_iterator sli = _sound_loaders->find(ext);
+    if (sli != _sound_loaders->end()) {
+      audio_cat->warning() 
+        << "attempted to register a loader for audio type '"
+        << ext << "' more then once." << endl;
+      return;
+    }
+  #endif //]
   (*_sound_loaders)[ext] = func;
   (*_sound_loaders)[ext] = func;
 }
 }
 
 
@@ -170,9 +194,12 @@ void AudioPool::register_sound_loader(const string& ext,
 //       Access: Public
 //       Access: Public
 //  Description: return the name of the nth loaded  sound
 //  Description: return the name of the nth loaded  sound
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-string AudioPool::ns_get_nth_sound_name(int n) const {
+string AudioPool::
+ns_get_nth_sound_name(int n) const {
   SoundMap::const_iterator i;
   SoundMap::const_iterator i;
   int j;
   int j;
-  for (i=_sounds.begin(), j=0; j<n; ++i, ++j);
+  for (i=_sounds.begin(), j=0; j<n; ++i, ++j) {
+    // the work is being done in the for statement.
+  }
   return (*i).first;
   return (*i).first;
 }
 }

+ 20 - 12
panda/src/audio/audio_pool.h

@@ -27,11 +27,31 @@
 #include <filename.h>
 #include <filename.h>
 #include <pointerTo.h>
 #include <pointerTo.h>
 
 
+// The AudioPool is a cache of SoundClass objects.  When retrieving
+// a sound, you will actually get an AudioSound object (which you own).
 class EXPCL_PANDA AudioPool {
 class EXPCL_PANDA AudioPool {
+public:
+  typedef AudioTraits::SoundClass* SoundLoadFunc(Filename);
+
+PUBLISHED:
+  INLINE static bool has_sound(const string& filename);
+  INLINE static bool verify_sound(const string& filename);
+  
+  INLINE static AudioSound* load_sound(const string& filename);
+  
+  INLINE static void release_sound(AudioSound* sound);
+  INLINE static void release_all_sounds();
+  
+  INLINE static int get_num_loaded_sounds();
+  INLINE static string get_nth_sound_name(int);
+  
+  static void register_sound_loader(const string&, SoundLoadFunc*);
+
 private:
 private:
   INLINE AudioPool();
   INLINE AudioPool();
 
 
   bool ns_has_sound(Filename filename);
   bool ns_has_sound(Filename filename);
+  PT(AudioTraits::SoundClass) call_sound_loader(Filename fileName);
   AudioSound* ns_load_sound(Filename filename);
   AudioSound* ns_load_sound(Filename filename);
   void ns_release_sound(AudioSound* sound);
   void ns_release_sound(AudioSound* sound);
   void ns_release_all_sounds();
   void ns_release_all_sounds();
@@ -42,18 +62,6 @@ private:
   static AudioPool *_global_ptr;
   static AudioPool *_global_ptr;
   typedef pmap<string, PT(AudioTraits::SoundClass) > SoundMap;
   typedef pmap<string, PT(AudioTraits::SoundClass) > SoundMap;
   SoundMap _sounds;
   SoundMap _sounds;
-public:
-  typedef AudioTraits::SoundClass* SoundLoadFunc(Filename);
-
-PUBLISHED:
-  INLINE static bool has_sound(const string& filename);
-  INLINE static bool verify_sound(const string& filename);
-  INLINE static AudioSound* load_sound(const string& filename);
-  INLINE static void release_sound(AudioSound* sound);
-  INLINE static void release_all_sounds();
-  INLINE static int get_num_loaded_sounds();
-  INLINE static string get_nth_sound_name(int);
-  static void register_sound_loader(const string&, SoundLoadFunc*);
 };
 };
 
 
 #include "audio_pool.I"
 #include "audio_pool.I"

+ 8 - 7
panda/src/audio/audio_sound.cxx

@@ -28,10 +28,9 @@ TypeHandle AudioSound::_type_handle;
 //  Description: deletes the sound data and then lets the system
 //  Description: deletes the sound data and then lets the system
 //               destroy this structure
 //               destroy this structure
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-AudioSound::~AudioSound() {
-  if (audio_cat.is_debug())
-    audio_cat->debug() << "AudioSound destructor (" << get_name() << ")"
-               << endl;
+AudioSound::
+~AudioSound() {
+  audio_debug("AudioSound destructor (" << get_name() << ")");
   AudioManager::stop(this);
   AudioManager::stop(this);
   (*_delstate)(_state);
   (*_delstate)(_state);
 }
 }
@@ -41,7 +40,8 @@ AudioSound::~AudioSound() {
 //       Access: Public
 //       Access: Public
 //  Description: return the length (in seconds) of the sound
 //  Description: return the length (in seconds) of the sound
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-float AudioSound::length() const {
+float AudioSound::
+length() const {
   return _sound->length();
   return _sound->length();
 }
 }
 
 
@@ -50,7 +50,8 @@ float AudioSound::length() const {
 //       Access: Public
 //       Access: Public
 //  Description: return the current play status of this sound
 //  Description: return the current play status of this sound
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-AudioSound::SoundStatus AudioSound::status() const {
+AudioSound::SoundStatus AudioSound::
+status() const {
   AudioTraits::PlayingClass::PlayingStatus stat = _state->status();
   AudioTraits::PlayingClass::PlayingStatus stat = _state->status();
   switch (stat) {
   switch (stat) {
   case AudioTraits::PlayingClass::BAD:
   case AudioTraits::PlayingClass::BAD:
@@ -60,6 +61,6 @@ AudioSound::SoundStatus AudioSound::status() const {
   case AudioTraits::PlayingClass::PLAYING:
   case AudioTraits::PlayingClass::PLAYING:
     return PLAYING;
     return PLAYING;
   }
   }
-  audio_cat->error() << "unknown status for sound" << endl;
+  audio_error("unknown status for sound");
   return BAD;
   return BAD;
 }
 }

+ 1 - 1
panda/src/audio/audio_trait.cxx

@@ -24,7 +24,7 @@ AudioTraits::SoundClass::~SoundClass() {
 
 
 float AudioTraits::SoundClass::length() const {
 float AudioTraits::SoundClass::length() const {
   audio_cat->error() << "In abstract SoundClass::length!" << endl;
   audio_cat->error() << "In abstract SoundClass::length!" << endl;
-  return -1.;
+  return -1.0;
 }
 }
 
 
 AudioTraits::PlayingClass* AudioTraits::SoundClass::get_state() const {
 AudioTraits::PlayingClass* AudioTraits::SoundClass::get_state() const {

+ 1 - 1
panda/src/audio/audio_trait.h

@@ -46,7 +46,7 @@ public:
     SoundClass* _sound;
     SoundClass* _sound;
     float _volume;
     float _volume;
   public:
   public:
-    PlayingClass(SoundClass* s) : _sound(s), _volume(1.) {}
+    PlayingClass(SoundClass* s) : _sound(s), _volume(1.0) {}
     virtual ~PlayingClass();
     virtual ~PlayingClass();
 
 
     enum PlayingStatus { BAD, READY, PLAYING } ;
     enum PlayingStatus { BAD, READY, PLAYING } ;

+ 168 - 96
panda/src/audio/audio_win_traits.cxx

@@ -65,17 +65,20 @@ static IDirectSound* musicDirectSound = NULL;
 #define MULTI_TO_WIDE(x,y) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, y, -1, x, _MAX_PATH);
 #define MULTI_TO_WIDE(x,y) MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, y, -1, x, _MAX_PATH);
 
 
 
 
-static void update_win(void) {
+static void update_win() {
 }
 }
 
 
-static void initialize(void) {
-  if (have_initialized)
+static void initialize() {
+  if (have_initialized) {
     return;
     return;
-  if (!audio_is_active)
+  }
+  if (!audio_is_active) {
     return;
     return;
+  }
 
 
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winAudio initialize" << endl;
     audio_cat->debug() << "in winAudio initialize" << endl;
+  }
 
 
   // rumor has it this will work, if it doesn't we need to create an invisible
   // rumor has it this will work, if it doesn't we need to create an invisible
   // application window for this kind of thing
   // application window for this kind of thing
@@ -167,13 +170,15 @@ static void initialize(void) {
   AudioManager::set_update_func(update_win);
   AudioManager::set_update_func(update_win);
   have_initialized = true;
   have_initialized = true;
 
 
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "out of winAudio initialize" << endl;
     audio_cat->debug() << "out of winAudio initialize" << endl;
+  }
 }
 }
 
 
-static void shutdown(void) {
-  if (audio_cat.is_debug())
+static void shutdown() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winaudio shutdown" << endl;
     audio_cat->debug() << "in winaudio shutdown" << endl;
+  }
 
 
   // release the primary sound buffer
   // release the primary sound buffer
   if (soundPrimaryBuffer) {
   if (soundPrimaryBuffer) {
@@ -201,23 +206,26 @@ static void shutdown(void) {
   // shutdown COM
   // shutdown COM
   CoUninitialize();
   CoUninitialize();
 
 
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "out of winaudio shutdown" << endl;
     audio_cat->debug() << "out of winaudio shutdown" << endl;
+  }
 }
 }
 
 
-WinSample::~WinSample(void) {
+WinSample::~WinSample() {
   // we may or may not be leaking the _data
   // we may or may not be leaking the _data
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "winsample destructor called" << endl;
     audio_cat->debug() << "winsample destructor called" << endl;
+  }
 }
 }
 
 
-float WinSample::length(void) const {
-  if (audio_cat.is_debug())
+float WinSample::length() const {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "winsample length called" << endl;
     audio_cat->debug() << "winsample length called" << endl;
+  }
   return _len / (audio_mix_freq * 2. * 2.);
   return _len / (audio_mix_freq * 2. * 2.);
 }
 }
 
 
-AudioTraits::PlayingClass* WinSample::get_state(void) const {
+AudioTraits::PlayingClass* WinSample::get_state() const {
   WinSamplePlaying* ret = new WinSamplePlaying((WinSample*)this);
   WinSamplePlaying* ret = new WinSamplePlaying((WinSample*)this);
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())
     audio_cat->debug() << "winsample get_state returning 0x" << (void*)ret
     audio_cat->debug() << "winsample get_state returning 0x" << (void*)ret
@@ -225,7 +233,7 @@ AudioTraits::PlayingClass* WinSample::get_state(void) const {
   return ret;
   return ret;
 }
 }
 
 
-AudioTraits::PlayerClass* WinSample::get_player(void) const {
+AudioTraits::PlayerClass* WinSample::get_player() const {
   AudioTraits::PlayerClass* ret = WinSamplePlayer::get_instance();
   AudioTraits::PlayerClass* ret = WinSamplePlayer::get_instance();
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())
     audio_cat->debug() << "winsample get_player returning 0x" << (void*)ret
     audio_cat->debug() << "winsample get_player returning 0x" << (void*)ret
@@ -233,7 +241,7 @@ AudioTraits::PlayerClass* WinSample::get_player(void) const {
   return ret;
   return ret;
 }
 }
 
 
-AudioTraits::DeletePlayingFunc* WinSample::get_delstate(void) const {
+AudioTraits::DeletePlayingFunc* WinSample::get_delstate() const {
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())
     audio_cat->debug() << "winsample get_delstate returning 0x"
     audio_cat->debug() << "winsample get_delstate returning 0x"
                << (void*)(WinSamplePlaying::destroy) << endl;
                << (void*)(WinSamplePlaying::destroy) << endl;
@@ -274,8 +282,9 @@ HRESULT readMMIO(HMMIO hmmio, MMCKINFO* pckInRIFF, WAVEFORMATEX** ppwfxInfo) {
     if (mmioRead(hmmio, (CHAR*)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD))
     if (mmioRead(hmmio, (CHAR*)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD))
       return E_FAIL;
       return E_FAIL;
     *ppwfxInfo = (WAVEFORMATEX*)new CHAR[sizeof(WAVEFORMATEX)+cbExtraBytes];
     *ppwfxInfo = (WAVEFORMATEX*)new CHAR[sizeof(WAVEFORMATEX)+cbExtraBytes];
-    if (*ppwfxInfo == NULL)
+    if (*ppwfxInfo == NULL) {
       return E_FAIL;
       return E_FAIL;
+    }
     memcpy(*ppwfxInfo, &pcmWaveFormat, sizeof(pcmWaveFormat));
     memcpy(*ppwfxInfo, &pcmWaveFormat, sizeof(pcmWaveFormat));
     (*ppwfxInfo)->cbSize = cbExtraBytes;
     (*ppwfxInfo)->cbSize = cbExtraBytes;
     if (mmioRead(hmmio, (CHAR*)(((BYTE*)&((*ppwfxInfo)->cbSize))+sizeof(WORD)),
     if (mmioRead(hmmio, (CHAR*)(((BYTE*)&((*ppwfxInfo)->cbSize))+sizeof(WORD)),
@@ -328,8 +337,9 @@ HRESULT wave_read_file(HMMIO hmmio, UINT cbRead, BYTE* pbDest, MMCKINFO* pckIn,
   if (mmioGetInfo(hmmio, &mmioinfoIn, 0) != 0)
   if (mmioGetInfo(hmmio, &mmioinfoIn, 0) != 0)
     return E_FAIL;
     return E_FAIL;
   UINT cbDataIn = cbRead;
   UINT cbDataIn = cbRead;
-  if (cbDataIn > pckIn->cksize)
+  if (cbDataIn > pckIn->cksize) {
     cbDataIn = pckIn->cksize;
     cbDataIn = pckIn->cksize;
+  }
   for (DWORD cT=0; cT<cbDataIn; ++cT) {
   for (DWORD cT=0; cT<cbDataIn; ++cT) {
     // copy bytes from the io to the buffer
     // copy bytes from the io to the buffer
     if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) {
     if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) {
@@ -356,8 +366,9 @@ HRESULT wave_load_internal(const CHAR* filename, WAVEFORMATEX& wavInfo,
   wavData = NULL;
   wavData = NULL;
   wavSize = 0;
   wavSize = 0;
   HRESULT result = wave_open_file(filename, &hmmioIn, &pwfx, &ckInRiff);
   HRESULT result = wave_open_file(filename, &hmmioIn, &pwfx, &ckInRiff);
-  if (FAILED(result))
+  if (FAILED(result)) {
     return result;
     return result;
+  }
   result = wave_start_data_read(&hmmioIn, &ckIn, &ckInRiff);
   result = wave_start_data_read(&hmmioIn, &ckIn, &ckInRiff);
   if (SUCCEEDED(result)) {
   if (SUCCEEDED(result)) {
     memcpy(&wavInfo, pwfx, sizeof(WAVEFORMATEX));
     memcpy(&wavInfo, pwfx, sizeof(WAVEFORMATEX));
@@ -381,14 +392,16 @@ HRESULT wave_load(const CHAR* filename, WAVEFORMATEX& wavInfo, BYTE*& wavData,
 }
 }
 
 
 WinSample* WinSample::load_wav(Filename filename) {
 WinSample* WinSample::load_wav(Filename filename) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winsample load_wav" << endl;
     audio_cat->debug() << "in winsample load_wav" << endl;
+  }
   WinSample* ret = (WinSample*)0L;
   WinSample* ret = (WinSample*)0L;
 
 
   initialize();
   initialize();
 
 
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return ret;
     return ret;
+  }
 
 
   WAVEFORMATEX wavInfo;
   WAVEFORMATEX wavInfo;
   UINT wavSize = 0;
   UINT wavSize = 0;
@@ -397,10 +410,12 @@ WinSample* WinSample::load_wav(Filename filename) {
   string stmp = filename.to_os_specific();
   string stmp = filename.to_os_specific();
   HRESULT result = wave_load(stmp.c_str(), wavInfo, wavData, wavSize);
   HRESULT result = wave_load(stmp.c_str(), wavInfo, wavData, wavSize);
   if (FAILED(result)) {
   if (FAILED(result)) {
-    if (wavData)
+    if (wavData) {
       delete [] wavData;
       delete [] wavData;
-    if (audio_cat.is_debug())
+    }
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "wave_load failed, returning NULL" << endl;
       audio_cat->debug() << "wave_load failed, returning NULL" << endl;
+    }
     return ret;
     return ret;
   }
   }
 
 
@@ -409,20 +424,23 @@ WinSample* WinSample::load_wav(Filename filename) {
   ret->_data = wavData;
   ret->_data = wavData;
   ret->_len = wavSize;
   ret->_len = wavSize;
 
 
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "returning 0x" << (void*)ret << endl;
     audio_cat->debug() << "returning 0x" << (void*)ret << endl;
+  }
   return ret;
   return ret;
 }
 }
 
 
 WinSample* WinSample::load_raw(unsigned char* data, unsigned long size) {
 WinSample* WinSample::load_raw(unsigned char* data, unsigned long size) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winsample load_raw" << endl;
     audio_cat->debug() << "in winsample load_raw" << endl;
+  }
   WinSample* ret = (WinSample*)0L;
   WinSample* ret = (WinSample*)0L;
 
 
   initialize();
   initialize();
 
 
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return ret;
     return ret;
+  }
 
 
   // synth a wav header for this data
   // synth a wav header for this data
   WAVEFORMATEX wavInfo;
   WAVEFORMATEX wavInfo;
@@ -435,8 +453,9 @@ WinSample* WinSample::load_raw(unsigned char* data, unsigned long size) {
   wavInfo.nAvgBytesPerSec = wavInfo.nSamplesPerSec * wavInfo.nBlockAlign;
   wavInfo.nAvgBytesPerSec = wavInfo.nSamplesPerSec * wavInfo.nBlockAlign;
 
 
   if (data == (unsigned char*)0L) {
   if (data == (unsigned char*)0L) {
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "data is null, returning same" << endl;
       audio_cat->debug() << "data is null, returning same" << endl;
+    }
     return ret;
     return ret;
   }
   }
 
 
@@ -451,10 +470,11 @@ WinSample* WinSample::load_raw(unsigned char* data, unsigned long size) {
   return ret;
   return ret;
 }
 }
 
 
-WinMusic::~WinMusic(void) {
+WinMusic::~WinMusic() {
   // AudioManager::stop(this);
   // AudioManager::stop(this);
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in WinMusic::~WinMusic()" << endl;
     audio_cat->debug() << "in WinMusic::~WinMusic()" << endl;
+  }
 
 
   if (_music) {
   if (_music) {
     _music->Release();
     _music->Release();
@@ -477,13 +497,15 @@ WinMusic::~WinMusic(void) {
     _buffer = NULL;
     _buffer = NULL;
   }
   }
 
 
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "out of WinMusic::~WinMusic()" << endl;
     audio_cat->debug() << "out of WinMusic::~WinMusic()" << endl;
+  }
 }
 }
 
 
-void WinMusic::init(void) {
-  if (audio_cat.is_debug())
+void WinMusic::init() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in WinMusic::init()" << endl;
     audio_cat->debug() << "in WinMusic::init()" << endl;
+  }
 
 
   initialize();
   initialize();
   // create the direct sound performance object
   // create the direct sound performance object
@@ -543,8 +565,9 @@ void WinMusic::init(void) {
   // add the synth to the performance
   // add the synth to the performance
   // result = _performance->AddPort(_synth);
   // result = _performance->AddPort(_synth);
   result = _performance->AddPort(NULL);
   result = _performance->AddPort(NULL);
-  if (result == DMUS_E_NOT_INIT)
+  if (result == DMUS_E_NOT_INIT) {
     audio_cat->error() << "got DMUS_N_NOT_INIT" << endl;
     audio_cat->error() << "got DMUS_N_NOT_INIT" << endl;
+  }
   else if (result == DMUS_E_CANNOT_OPEN_PORT)
   else if (result == DMUS_E_CANNOT_OPEN_PORT)
     audio_cat->error() << "got DMUS_E_CANNOT_OPEN_PORT" << endl;
     audio_cat->error() << "got DMUS_E_CANNOT_OPEN_PORT" << endl;
   else if (result == E_OUTOFMEMORY)
   else if (result == E_OUTOFMEMORY)
@@ -566,14 +589,15 @@ void WinMusic::init(void) {
                        << endl;
                        << endl;
 }
 }
 
 
-float WinMusic::length(void) const {
+float WinMusic::length() const {
   // DO THIS
   // DO THIS
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "winmusic length" << endl;
     audio_cat->debug() << "winmusic length" << endl;
+  }
   return -1.;
   return -1.;
 }
 }
 
 
-AudioTraits::PlayingClass* WinMusic::get_state(void) const {
+AudioTraits::PlayingClass* WinMusic::get_state() const {
   WinMusicPlaying* ret = new WinMusicPlaying((WinMusic*)this);
   WinMusicPlaying* ret = new WinMusicPlaying((WinMusic*)this);
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())
     audio_cat->debug() << "winmusic get_state returning 0x"
     audio_cat->debug() << "winmusic get_state returning 0x"
@@ -581,7 +605,7 @@ AudioTraits::PlayingClass* WinMusic::get_state(void) const {
   return ret;
   return ret;
 }
 }
 
 
-AudioTraits::PlayerClass* WinMusic::get_player(void) const {
+AudioTraits::PlayerClass* WinMusic::get_player() const {
   AudioTraits::PlayerClass* ret = WinMusicPlayer::get_instance();
   AudioTraits::PlayerClass* ret = WinMusicPlayer::get_instance();
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())
     audio_cat->debug() << "winmusic get_player returning 0x" << (void*)ret
     audio_cat->debug() << "winmusic get_player returning 0x" << (void*)ret
@@ -589,7 +613,7 @@ AudioTraits::PlayerClass* WinMusic::get_player(void) const {
   return ret;
   return ret;
 }
 }
 
 
-AudioTraits::DeletePlayingFunc* WinMusic::get_delstate(void) const {
+AudioTraits::DeletePlayingFunc* WinMusic::get_delstate() const {
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())
     audio_cat->debug() << "winmusic get_delstate returning 0x"
     audio_cat->debug() << "winmusic get_delstate returning 0x"
                << (void*)(WinMusicPlaying::destroy) << endl;
                << (void*)(WinMusicPlaying::destroy) << endl;
@@ -597,18 +621,21 @@ AudioTraits::DeletePlayingFunc* WinMusic::get_delstate(void) const {
 }
 }
 
 
 WinMusic* WinMusic::load_midi(Filename filename) {
 WinMusic* WinMusic::load_midi(Filename filename) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in WinMusic::load_midi()" << endl;
     audio_cat->debug() << "in WinMusic::load_midi()" << endl;
+  }
   initialize();
   initialize();
 
 
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return (WinMusic*)0L;
     return (WinMusic*)0L;
+  }
 
 
   // WinMusic* ret = (WinMusic*)0L;
   // WinMusic* ret = (WinMusic*)0L;
   WinMusic* ret = new WinMusic();
   WinMusic* ret = new WinMusic();
   if (ret->_performance && ret->_music) {
   if (ret->_performance && ret->_music) {
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "for some reason, have to stop" << endl;
       audio_cat->debug() << "for some reason, have to stop" << endl;
+    }
     ret->_performance->Stop(NULL, NULL, 0, 0);
     ret->_performance->Stop(NULL, NULL, 0, 0);
   }
   }
   ret->_music = NULL;
   ret->_music = NULL;
@@ -658,12 +685,14 @@ WinMusic* WinMusic::load_midi(Filename filename) {
 */
 */
   string stmp = filename.to_os_specific();
   string stmp = filename.to_os_specific();
   MULTI_TO_WIDE(fdesc.wszFileName, stmp.c_str());
   MULTI_TO_WIDE(fdesc.wszFileName, stmp.c_str());
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "os_specific name '" << stmp << "'" << endl;
     audio_cat->debug() << "os_specific name '" << stmp << "'" << endl;
+  }
   if (filename.is_local()) {
   if (filename.is_local()) {
     fdesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
     fdesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "is local" << endl;
       audio_cat->debug() << "is local" << endl;
+    }
     char szDir[2] = ".";
     char szDir[2] = ".";
     WCHAR wszDir[2];
     WCHAR wszDir[2];
     MULTI_TO_WIDE(wszDir, szDir);
     MULTI_TO_WIDE(wszDir, szDir);
@@ -678,8 +707,9 @@ WinMusic* WinMusic::load_midi(Filename filename) {
     }
     }
   } else {
   } else {
     fdesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH;
     fdesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH;
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "is not local" << endl;
       audio_cat->debug() << "is not local" << endl;
+    }
   }
   }
   result = loader->GetObject(&fdesc, IID_IDirectMusicSegment2,
   result = loader->GetObject(&fdesc, IID_IDirectMusicSegment2,
                  (void**)&(ret->_music));
                  (void**)&(ret->_music));
@@ -701,13 +731,15 @@ WinMusic* WinMusic::load_midi(Filename filename) {
 
 
 WinSamplePlaying::WinSamplePlaying(AudioTraits::SoundClass* s)
 WinSamplePlaying::WinSamplePlaying(AudioTraits::SoundClass* s)
   : AudioTraits::PlayingClass(s) {
   : AudioTraits::PlayingClass(s) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in WinSamplePlaying constructor" << endl;
     audio_cat->debug() << "in WinSamplePlaying constructor" << endl;
+  }
 
 
   initialize();
   initialize();
 
 
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return;
     return;
+  }
 
 
   WinSample* ws = (WinSample*)s;
   WinSample* ws = (WinSample*)s;
 
 
@@ -718,8 +750,9 @@ WinSamplePlaying::WinSamplePlaying(AudioTraits::SoundClass* s)
     return;
     return;
   }
   }
   if (ws->_data == (unsigned char*)0L) {
   if (ws->_data == (unsigned char*)0L) {
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "the sample has null data, returning" << endl;
       audio_cat->debug() << "the sample has null data, returning" << endl;
+    }
     return;
     return;
   }
   }
 
 
@@ -735,8 +768,9 @@ WinSamplePlaying::WinSamplePlaying(AudioTraits::SoundClass* s)
 
 
   if (FAILED(result)) {
   if (FAILED(result)) {
     _channel = NULL;
     _channel = NULL;
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "failed to create a channel" << endl;
       audio_cat->debug() << "failed to create a channel" << endl;
+    }
     return;
     return;
   }
   }
   BYTE* dst = NULL;
   BYTE* dst = NULL;
@@ -764,9 +798,10 @@ WinSamplePlaying::WinSamplePlaying(AudioTraits::SoundClass* s)
   this->unlock();
   this->unlock();
 }
 }
 
 
-WinSamplePlaying::~WinSamplePlaying(void) {
-  if (audio_cat.is_debug())
+WinSamplePlaying::~WinSamplePlaying() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "winsampleplaying destructor" << endl;
     audio_cat->debug() << "winsampleplaying destructor" << endl;
+  }
 }
 }
 
 
 void WinSamplePlaying::destroy(AudioTraits::PlayingClass* play) {
 void WinSamplePlaying::destroy(AudioTraits::PlayingClass* play) {
@@ -776,7 +811,7 @@ void WinSamplePlaying::destroy(AudioTraits::PlayingClass* play) {
   delete play;
   delete play;
 }
 }
 
 
-AudioTraits::PlayingClass::PlayingStatus WinSamplePlaying::status(void) {
+AudioTraits::PlayingClass::PlayingStatus WinSamplePlaying::status() {
   if (_channel) {
   if (_channel) {
     DWORD dwStatus;
     DWORD dwStatus;
     _channel->GetStatus(&dwStatus);
     _channel->GetStatus(&dwStatus);
@@ -787,9 +822,10 @@ AudioTraits::PlayingClass::PlayingStatus WinSamplePlaying::status(void) {
   return AudioTraits::PlayingClass::READY;
   return AudioTraits::PlayingClass::READY;
 }
 }
 
 
-BYTE* WinSamplePlaying::lock(void) {
-  if (audio_cat.is_debug())
+BYTE* WinSamplePlaying::lock() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winsampleplaying lock" << endl;
     audio_cat->debug() << "in winsampleplaying lock" << endl;
+  }
   WinSample* s = (WinSample*)(_sound);
   WinSample* s = (WinSample*)(_sound);
   HRESULT result = _channel->Lock(0, 0, (void**)&_data, &(s->_len), NULL,
   HRESULT result = _channel->Lock(0, 0, (void**)&_data, &(s->_len), NULL,
                   0, DSBLOCK_ENTIREBUFFER);
                   0, DSBLOCK_ENTIREBUFFER);
@@ -797,33 +833,39 @@ BYTE* WinSamplePlaying::lock(void) {
     audio_cat->error() << "failed to lock buffer" << endl;
     audio_cat->error() << "failed to lock buffer" << endl;
     return NULL;
     return NULL;
   }
   }
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "returning 0x" << (void*)_data << endl;
     audio_cat->debug() << "returning 0x" << (void*)_data << endl;
+  }
   return _data;
   return _data;
 }
 }
 
 
-void WinSamplePlaying::unlock(void) {
-  if (audio_cat.is_debug())
+void WinSamplePlaying::unlock() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winsampleplaying unlock" << endl;
     audio_cat->debug() << "in winsampleplaying unlock" << endl;
+  }
   WinSample* s = (WinSample*)(_sound);
   WinSample* s = (WinSample*)(_sound);
   HRESULT result = _channel->Unlock(_data, s->_len, NULL, 0);
   HRESULT result = _channel->Unlock(_data, s->_len, NULL, 0);
   CHECK_RESULT(result, "failed to unlock buffer");
   CHECK_RESULT(result, "failed to unlock buffer");
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "out of winsampleplaying unlock" << endl;
     audio_cat->debug() << "out of winsampleplaying unlock" << endl;
+  }
 }
 }
 
 
 WinMusicPlaying::WinMusicPlaying(AudioTraits::SoundClass* s)
 WinMusicPlaying::WinMusicPlaying(AudioTraits::SoundClass* s)
   : AudioTraits::PlayingClass(s) {
   : AudioTraits::PlayingClass(s) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winmusicplaying constructor" << endl;
     audio_cat->debug() << "in winmusicplaying constructor" << endl;
+  }
   initialize();
   initialize();
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "out of winmusicplaying constructor" << endl;
     audio_cat->debug() << "out of winmusicplaying constructor" << endl;
+  }
 }
 }
 
 
-WinMusicPlaying::~WinMusicPlaying(void) {
-  if (audio_cat.is_debug())
+WinMusicPlaying::~WinMusicPlaying() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "winmusicplaying destructor" << endl;
     audio_cat->debug() << "winmusicplaying destructor" << endl;
+  }
 }
 }
 
 
 void WinMusicPlaying::destroy(AudioTraits::PlayingClass* play) {
 void WinMusicPlaying::destroy(AudioTraits::PlayingClass* play) {
@@ -833,7 +875,7 @@ void WinMusicPlaying::destroy(AudioTraits::PlayingClass* play) {
   delete play;
   delete play;
 }
 }
 
 
-AudioTraits::PlayingClass::PlayingStatus WinMusicPlaying::status(void) {
+AudioTraits::PlayingClass::PlayingStatus WinMusicPlaying::status() {
   WinMusic* wm = (WinMusic*)_sound;
   WinMusic* wm = (WinMusic*)_sound;
 
 
   if (wm->get_performance() && wm->get_music()) {
   if (wm->get_performance() && wm->get_music()) {
@@ -846,20 +888,24 @@ AudioTraits::PlayingClass::PlayingStatus WinMusicPlaying::status(void) {
 
 
 WinSamplePlayer* WinSamplePlayer::_global_instance = (WinSamplePlayer*)0L;
 WinSamplePlayer* WinSamplePlayer::_global_instance = (WinSamplePlayer*)0L;
 
 
-WinSamplePlayer::~WinSamplePlayer(void) {
-  if (audio_cat.is_debug())
+WinSamplePlayer::~WinSamplePlayer() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winsampleplayer destructor" << endl;
     audio_cat->debug() << "in winsampleplayer destructor" << endl;
+  }
 }
 }
 
 
 void WinSamplePlayer::play_sound(AudioTraits::SoundClass* sample,
 void WinSamplePlayer::play_sound(AudioTraits::SoundClass* sample,
                AudioTraits::PlayingClass* play, float start_time) {
                AudioTraits::PlayingClass* play, float start_time) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winsampleplayer play_sound" << endl;
     audio_cat->debug() << "in winsampleplayer play_sound" << endl;
+  }
   initialize();
   initialize();
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return;
     return;
-  if (!AudioManager::get_sfx_active())
+  }
+  if (!AudioManager::get_sfx_active()) {
     return;
     return;
+  }
   WinSample* wsample = (WinSample*)sample;
   WinSample* wsample = (WinSample*)sample;
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
@@ -869,40 +915,49 @@ void WinSamplePlayer::play_sound(AudioTraits::SoundClass* sample,
     WAVEFORMATEX f = wsample->get_format();
     WAVEFORMATEX f = wsample->get_format();
     float factor = ((float)l) / f.nAvgBytesPerSec;
     float factor = ((float)l) / f.nAvgBytesPerSec;
     factor = start_time / factor;
     factor = start_time / factor;
-    if (factor > 1.)
+    if (factor > 1.) {
       factor = 1.;
       factor = 1.;
+    }
     DWORD p = (DWORD)(l * factor);
     DWORD p = (DWORD)(l * factor);
     p = (p >> 2) << 2;  // zero the last 2 bits
     p = (p >> 2) << 2;  // zero the last 2 bits
     chan->SetCurrentPosition(p);
     chan->SetCurrentPosition(p);
     HRESULT result = chan->Play(0, 0, 0);
     HRESULT result = chan->Play(0, 0, 0);
-    if (FAILED(result))
+    if (FAILED(result)) {
       audio_cat->error() << "sample play failed" << endl;
       audio_cat->error() << "sample play failed" << endl;
+    }
   }
   }
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "out of winsampleplayer play_sound" << endl;
     audio_cat->debug() << "out of winsampleplayer play_sound" << endl;
+  }
 }
 }
 
 
 void WinSamplePlayer::stop_sound(AudioTraits::SoundClass*,
 void WinSamplePlayer::stop_sound(AudioTraits::SoundClass*,
                AudioTraits::PlayingClass* play) {
                AudioTraits::PlayingClass* play) {
   initialize();
   initialize();
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return;
     return;
-  if (!AudioManager::get_sfx_active())
+  }
+  if (!AudioManager::get_sfx_active()) {
     return;
     return;
+  }
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
-  if (chan)
+  if (chan) {
     chan->Stop();
     chan->Stop();
+  }
 }
 }
 
 
 void WinSamplePlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
 void WinSamplePlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "winsampleplayer set_volume" << endl;
     audio_cat->debug() << "winsampleplayer set_volume" << endl;
+  }
   initialize();
   initialize();
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return;
     return;
-  if (!AudioManager::get_sfx_active())
+  }
+  if (!AudioManager::get_sfx_active()) {
     return;
     return;
+  }
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
   float tmpv = v * AudioManager::get_master_sfx_volume();
   float tmpv = v * AudioManager::get_master_sfx_volume();
@@ -914,13 +969,16 @@ void WinSamplePlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
 }
 }
 
 
 bool WinSamplePlayer::adjust_volume(AudioTraits::PlayingClass* play) {
 bool WinSamplePlayer::adjust_volume(AudioTraits::PlayingClass* play) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "winsampleplayer adjust_volume" << endl;
     audio_cat->debug() << "winsampleplayer adjust_volume" << endl;
+  }
   initialize();
   initialize();
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return true;
     return true;
-  if (!AudioManager::get_sfx_active())
+  }
+  if (!AudioManager::get_sfx_active()) {
     return true;
     return true;
+  }
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   WinSamplePlaying* wplay = (WinSamplePlaying*)play;
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
   LPDIRECTSOUNDBUFFER chan = wplay->get_channel();
   float tmpv = play->get_volume() * AudioManager::get_master_sfx_volume();
   float tmpv = play->get_volume() * AudioManager::get_master_sfx_volume();
@@ -931,9 +989,10 @@ bool WinSamplePlayer::adjust_volume(AudioTraits::PlayingClass* play) {
   return false;
   return false;
 }
 }
 
 
-WinSamplePlayer* WinSamplePlayer::get_instance(void) {
-  if (audio_cat.is_debug())
+WinSamplePlayer* WinSamplePlayer::get_instance() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winsampleplayer get_instance" << endl;
     audio_cat->debug() << "in winsampleplayer get_instance" << endl;
+  }
   if (_global_instance == (WinSamplePlayer*)0L)
   if (_global_instance == (WinSamplePlayer*)0L)
     _global_instance = new WinSamplePlayer();
     _global_instance = new WinSamplePlayer();
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())
@@ -944,20 +1003,24 @@ WinSamplePlayer* WinSamplePlayer::get_instance(void) {
 
 
 WinMusicPlayer* WinMusicPlayer::_global_instance = (WinMusicPlayer*)0L;
 WinMusicPlayer* WinMusicPlayer::_global_instance = (WinMusicPlayer*)0L;
 
 
-WinMusicPlayer::~WinMusicPlayer(void) {
-  if (audio_cat.is_debug())
+WinMusicPlayer::~WinMusicPlayer() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in winmusicplayer destructor" << endl;
     audio_cat->debug() << "in winmusicplayer destructor" << endl;
+  }
 }
 }
 
 
 void WinMusicPlayer::play_sound(AudioTraits::SoundClass* music,
 void WinMusicPlayer::play_sound(AudioTraits::SoundClass* music,
                 AudioTraits::PlayingClass*, float) {
                 AudioTraits::PlayingClass*, float) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in WinMusicPlayer::play_sound()" << endl;
     audio_cat->debug() << "in WinMusicPlayer::play_sound()" << endl;
+  }
   initialize();
   initialize();
-  if (!audio_is_active)
+  if (!audio_is_active) {
     return;
     return;
-  if (!AudioManager::get_music_active())
+  }
+  if (!AudioManager::get_music_active()) {
     return;
     return;
+  }
   WinMusic* wmusic = (WinMusic*)music;
   WinMusic* wmusic = (WinMusic*)music;
   IDirectMusicPerformance* _perf = wmusic->get_performance();
   IDirectMusicPerformance* _perf = wmusic->get_performance();
   IDirectMusicSegment* _msc = wmusic->get_music();
   IDirectMusicSegment* _msc = wmusic->get_music();
@@ -965,8 +1028,9 @@ void WinMusicPlayer::play_sound(AudioTraits::SoundClass* music,
     audio_cat->debug() << "about to jump in: _perf = " << (void*)_perf
     audio_cat->debug() << "about to jump in: _perf = " << (void*)_perf
                        << "  _msc = " << (void*)_msc << endl;
                        << "  _msc = " << (void*)_msc << endl;
   if (_perf && _msc) {
   if (_perf && _msc) {
-    if (audio_cat.is_debug())
+    if (audio_cat.is_debug()) {
       audio_cat->debug() << "made it inside" << endl;
       audio_cat->debug() << "made it inside" << endl;
+    }
     // _msc->SetRepeats(0);
     // _msc->SetRepeats(0);
     IDirectMusicSegmentState* segState;
     IDirectMusicSegmentState* segState;
     // HRESULT result = _perf->PlaySegment(_msc, 0, 0, NULL);
     // HRESULT result = _perf->PlaySegment(_msc, 0, 0, NULL);
@@ -987,8 +1051,9 @@ void WinMusicPlayer::play_sound(AudioTraits::SoundClass* music,
       };
       };
     }
     }
   }
   }
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "out of WinMusicPlayer::play_sound()" << endl;
     audio_cat->debug() << "out of WinMusicPlayer::play_sound()" << endl;
+  }
 }
 }
 
 
 void WinMusicPlayer::stop_sound(AudioTraits::SoundClass* music,
 void WinMusicPlayer::stop_sound(AudioTraits::SoundClass* music,
@@ -997,25 +1062,29 @@ void WinMusicPlayer::stop_sound(AudioTraits::SoundClass* music,
   IDirectMusicPerformance* _perf = wmusic->get_performance();
   IDirectMusicPerformance* _perf = wmusic->get_performance();
   IDirectMusicSegment* _msc = wmusic->get_music();
   IDirectMusicSegment* _msc = wmusic->get_music();
 
 
-  if (!AudioManager::get_music_active())
+  if (!AudioManager::get_music_active()) {
     return;
     return;
+  }
   if (_perf && _msc) {
   if (_perf && _msc) {
     HRESULT result = _perf->Stop(_msc, 0, 0, 0);
     HRESULT result = _perf->Stop(_msc, 0, 0, 0);
-    if (result != S_OK)
+    if (result != S_OK) {
       audio_cat->error() << "music stop failed" << endl;
       audio_cat->error() << "music stop failed" << endl;
+    }
     else if (audio_cat.is_debug())
     else if (audio_cat.is_debug())
       audio_cat->debug() << "music stop succeeded" << endl;
       audio_cat->debug() << "music stop succeeded" << endl;
   }
   }
 }
 }
 
 
 void WinMusicPlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
 void WinMusicPlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "WinMusicPlayer::set_volume()" << endl;
     audio_cat->debug() << "WinMusicPlayer::set_volume()" << endl;
+  }
   WinMusicPlaying* wplay = (WinMusicPlaying*)play;
   WinMusicPlaying* wplay = (WinMusicPlaying*)play;
   IDirectMusicPerformance* perf = wplay->get_performance();
   IDirectMusicPerformance* perf = wplay->get_performance();
   float tmpv = v * AudioManager::get_master_music_volume();
   float tmpv = v * AudioManager::get_master_music_volume();
-  if (!AudioManager::get_music_active())
+  if (!AudioManager::get_music_active()) {
     return;
     return;
+  }
   if (perf) {
   if (perf) {
     LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
     LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
     perf->SetGlobalParam(GUID_PerfMasterVolume, &v2, sizeof(LONG));
     perf->SetGlobalParam(GUID_PerfMasterVolume, &v2, sizeof(LONG));
@@ -1024,13 +1093,15 @@ void WinMusicPlayer::set_volume(AudioTraits::PlayingClass* play, float v) {
 }
 }
 
 
 bool WinMusicPlayer::adjust_volume(AudioTraits::PlayingClass* play) {
 bool WinMusicPlayer::adjust_volume(AudioTraits::PlayingClass* play) {
-  if (audio_cat.is_debug())
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "WinMusicPlayer::adjust_volume()" << endl;
     audio_cat->debug() << "WinMusicPlayer::adjust_volume()" << endl;
+  }
   WinMusicPlaying* wplay = (WinMusicPlaying*)play;
   WinMusicPlaying* wplay = (WinMusicPlaying*)play;
   IDirectMusicPerformance* perf = wplay->get_performance();
   IDirectMusicPerformance* perf = wplay->get_performance();
   float tmpv = play->get_volume() * AudioManager::get_master_music_volume();
   float tmpv = play->get_volume() * AudioManager::get_master_music_volume();
-  if (!AudioManager::get_music_active())
+  if (!AudioManager::get_music_active()) {
     return true;
     return true;
+  }
   if (perf) {
   if (perf) {
     LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
     LONG v2 = (tmpv * (DSBVOLUME_MAX - DSBVOLUME_MIN)) + DSBVOLUME_MIN;
     perf->SetGlobalParam(GUID_PerfMasterVolume, &v2, sizeof(LONG));
     perf->SetGlobalParam(GUID_PerfMasterVolume, &v2, sizeof(LONG));
@@ -1038,9 +1109,10 @@ bool WinMusicPlayer::adjust_volume(AudioTraits::PlayingClass* play) {
   return false;
   return false;
 }
 }
 
 
-WinMusicPlayer* WinMusicPlayer::get_instance(void) {
-  if (audio_cat.is_debug())
+WinMusicPlayer* WinMusicPlayer::get_instance() {
+  if (audio_cat.is_debug()) {
     audio_cat->debug() << "in WinMusicPlayer::get_instance" << endl;
     audio_cat->debug() << "in WinMusicPlayer::get_instance" << endl;
+  }
   if (_global_instance == (WinMusicPlayer*)0L)
   if (_global_instance == (WinMusicPlayer*)0L)
     _global_instance = new WinMusicPlayer();
     _global_instance = new WinMusicPlayer();
   if (audio_cat.is_debug())
   if (audio_cat.is_debug())

+ 18 - 0
panda/src/audio/config_audio.h

@@ -41,4 +41,22 @@ extern EXPCL_PANDA int audio_thread_priority;
 
 
 extern EXPCL_PANDA void audio_load_loaders();
 extern EXPCL_PANDA void audio_load_loaders();
 
 
+#ifndef NDEBUG //[
+  // Non-release build:
+  #define audio_debug(msg) \
+  if (audio_cat.is_debug()) { \
+    audio_cat->debug() << msg << endl; \
+  }
+
+  #define audio_info(msg) \
+    audio_cat->info() << msg << endl
+#else //][
+  // Release build:
+  #define audio_debug(msg) ((void)0)
+  #define audio_info(msg) ((void)0)
+#endif //]
+
+#define audio_error(msg) \
+  audio_cat->error() << msg << endl
+
 #endif /* __CONFIG_AUDIO_H__ */
 #endif /* __CONFIG_AUDIO_H__ */