Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/audiotraits/fmodAudioManager.h

Go to the documentation of this file.
00001 // Filename: fmodAudioManager.h
00002 // Created by:  cort (January 22, 2003)
00003 // Prior system by: cary
00004 //
00005 ////////////////////////////////////////////////////////////////////
00006 //
00007 // PANDA 3D SOFTWARE
00008 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00009 //
00010 // All use of this software is subject to the terms of the Panda 3d
00011 // Software license.  You should have received a copy of this license
00012 // along with this source code; you will also find a current copy of
00013 // the license at http://www.panda3d.org/license.txt .
00014 //
00015 // To contact the maintainers of this program write to
00016 // panda3d@yahoogroups.com .
00017 //
00018 ////////////////////////////////////////////////////////////////////
00019 
00020 #ifndef __FMOD_AUDIO_MANAGER_H__
00021 #define __FMOD_AUDIO_MANAGER_H__
00022 
00023 #include <pandabase.h>
00024 #ifdef HAVE_FMOD //[
00025 
00026 #include "audioManager.h"
00027 class FmodAudioSound;
00028 #include "filename.h"
00029 #include "pdeque.h"
00030 #include "pmap.h"
00031 #include "pset.h"
00032 
00033 #include <fmod.h>
00034 
00035 class EXPCL_FMOD_AUDIO FmodAudioManager : public AudioManager {
00036   // All of these methods are stubbed out to some degree.
00037   // If you're looking for a starting place for a new AudioManager,
00038   // please consider looking at the milesAudioManager.
00039   
00040 public:
00041   FmodAudioManager();
00042   virtual ~FmodAudioManager();
00043   
00044   virtual bool is_valid();
00045   
00046   virtual PT(AudioSound) get_sound(const string&);
00047   virtual void uncache_sound(const string&);
00048   virtual void clear_cache();
00049   virtual void set_cache_limit(int);
00050   virtual int get_cache_limit();
00051 
00052   // Indicates that the given sound was the most recently used.
00053   void most_recently_used(const string& path);
00054 
00055   // Uncaches the least recently used sound.
00056   void uncache_a_sound();
00057 
00058   virtual void set_volume(float);
00059   virtual float get_volume();
00060   
00061   virtual void set_active(bool);
00062   virtual bool get_active();
00063   void stop_all_sounds();
00064 
00065 protected:
00066   // increment or decrement the refcount of the given file's cache entry.
00067   // sounds can only be uncached when their refcounts are zero.
00068   void inc_refcount(const string& file_name);
00069   void dec_refcount(const string& file_name);
00070 private:
00071   typedef struct {
00072     size_t size; // size of the data field, in bytes
00073     unsigned int refcount; // how many AudioSound objects are referencing me?
00074     bool stale; // can this entry be  purged from the cache?
00075     char *data; // the memory-mapped audio file.
00076   } SoundCacheEntry;
00077   typedef pmap<string, SoundCacheEntry > SoundMap;
00078   SoundMap _sounds;
00079 
00080   typedef pset<FmodAudioSound* > AudioSet;
00081   // The offspring of this manager:
00082   AudioSet _soundsOnLoan;
00083 
00084   // The Least Recently Used mechanism:
00085   typedef pdeque<string> LRU;
00086   LRU _lru;
00087 
00088   void release_sound(FmodAudioSound *audioSound);
00089 
00090   int _cache_limit;
00091   static int _active_managers;
00092   bool _is_valid;
00093   bool _active;
00094   
00095   char* load(const Filename& filename, size_t &size) const;
00096 
00097   friend class FmodAudioSound;
00098 };
00099 
00100 EXPCL_FMOD_AUDIO PT(AudioManager) Create_AudioManager();
00101 
00102 #endif //]
00103 
00104 #endif /* __FMOD_AUDIO_MANAGER_H__ */

Generated on Fri May 2 00:34:30 2003 for Panda by doxygen1.3