home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Game_Audio / audio_sdk / src / AudioScript / SoundMgr.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-06-05  |  4.8 KB  |  164 lines

  1. /***********************************************************\
  2. Copyright (C) James Boer, 2002. 
  3. All rights reserved worldwide.
  4.  
  5. This software is provided "as is" without express or implied
  6. warranties. You may freely copy and compile this source into
  7. applications you distribute provided that the copyright text
  8. below is included in the resulting source code, for example:
  9. "Portions Copyright (C) James Boer, 2002"
  10. \***********************************************************/
  11. #ifndef __SOUNDMGR_H
  12. #define __SOUNDMGR_H
  13.  
  14. #include "Audio.h"
  15. #include "Script.h"
  16. #include "SoundScape.h"
  17. #include <map>
  18.  
  19. namespace Audio
  20. {
  21.  
  22. typedef std::vector<ISound*> ISoundVector;
  23. typedef std::queue<ISound*> ISoundQueue;
  24. typedef std::vector<ISound3D*> ISound3DVector;
  25. typedef std::queue<ISound3D*> ISound3DQueue;
  26.  
  27. struct SoundPool
  28. {
  29.     ISoundVector    m_Used;
  30.     ISoundQueue        m_Free;
  31.     SoundInit        m_Init;
  32. };
  33.  
  34. struct Sound3DPool
  35. {
  36.     ISound3DVector    m_Used;
  37.     ISound3DQueue    m_Free;
  38.     Sound3DInit        m_Init;
  39. };
  40.  
  41. typedef std::map<std::string, SoundPool> StrSndPoolMap;
  42. typedef std::map<std::string, Sound3DPool> StrSnd3DPoolMap;
  43.  
  44. typedef std::list<ISoundScape*> SoundScapeList;
  45. typedef std::map<std::string, SoundScapeInternalInit> SSInitMap;
  46. typedef std::vector<ISoundScape*> SoundScapeVector;
  47.  
  48.  
  49.  
  50. class SoundManager : public ISoundManager
  51. {
  52. // Interface functions
  53. public:
  54.     
  55.     bool Init();
  56.     void Term();
  57.  
  58.     bool IsInitialized()    {  return m_bInitialized;  }
  59.  
  60.  
  61.     // Load a sound script from a file
  62.     bool LoadScript(std::string sFileName);
  63.  
  64.     // Removes all loaded sounds, 3d sounds, and soundscape registrations
  65.     // from memory.
  66.     bool RemoveAll();
  67.  
  68.     bool GetSound(std::string sSoundName, ISound*& pSound);
  69.     bool ReleaseSound(std::string sSoundName, ISound* pSound);
  70.     bool GetSoundInit(std::string sSoundName, SoundInit& init);
  71.     bool IsSoundRegistered(std::string sSoundName);
  72.     void ResetSoundItr();
  73.     bool GetNextSound(std::string& sSoundName);
  74.     bool RemoveSound(std::string sSoundName);
  75.     bool RemoveAllSounds();
  76.  
  77.     bool GetSound3D(std::string sSound3DName, ISound3D*& pSound3D);
  78.     bool ReleaseSound3D(std::string sSound3DName, ISound3D* pSound3D);
  79.     bool GetSound3DInit(std::string sSound3DName, Sound3DInit& init);
  80.     bool IsSound3DRegistered(std::string sSound3DName);
  81.     void ResetSound3DItr();
  82.     bool GetNextSound3D(std::string& sSound3DName);
  83.     bool RemoveSound3D(std::string sSound3DName);
  84.     bool RemoveAllSounds3D();
  85.  
  86.     bool CreateSoundScape(ISoundScape*& pSoundScape);
  87.     bool InitSoundScape(std::string sSoundScapeName, ISoundScape*& pSoundScape);
  88.     bool IsSoundScapeRegistered(std::string sSoundScapeName);
  89.     void ResetSoundScapeItr();
  90.     bool GetNextSoundScape(std::string& sSoundScapeName);
  91.     bool RemoveSoundScape(std::string sSoundScapeName);
  92.     bool RemoveAllSoundScapes();
  93.  
  94.  
  95. // Concrete functions    
  96. public:
  97.     SoundManager();
  98.     virtual ~SoundManager();
  99.  
  100.     void Clear();
  101.  
  102.     void InsertSoundScape(ISoundScape* pSoundScape);
  103.     void RemoveSoundScape(ISoundScape* pSoundScape);
  104.  
  105.     float GetCurrentTime()    {  return m_fCurrentTime;  }
  106.     float GetFrameTime()    {  return m_fFrameTime;  }
  107.  
  108.     CRITICAL_SECTION& GetUpdateCS()    {  return m_csSoundMgrUpdate;  }
  109.  
  110. // Internal functions and types
  111. private:
  112.     // Separate thread for timed events
  113.     static void TimeEvent(LPVOID lpv);
  114.     // Service all currently playing streaming buffers
  115.     void ServiceSoundScapes();
  116.  
  117.     bool LoadSound(ScriptNode* pNode);
  118.     bool LoadSound3D(ScriptNode* pNode);
  119.     bool LoadSoundScape(ScriptNode* pNode);
  120.     bool LoadBackground(ScriptNode* pNode, BackgroundElement& bge);
  121.     bool LoadPeriodic(ScriptNode* pNode, PeriodicElement& pe);
  122.  
  123. private:
  124.  
  125.     // Bool indicating initialization status
  126.     bool                        m_bInitialized;
  127.     // Script loader object
  128.     ScriptLoader                m_Loader;
  129.  
  130.     // Map associating strings with sound pools
  131.     StrSndPoolMap                m_SndMap;
  132.     // Iterator for traversing through all sound init structure names
  133.     StrSndPoolMap::iterator        m_SndItr;
  134.  
  135.     // Map associating strings with sound3d initialization structures
  136.     StrSnd3DPoolMap                m_Snd3DMap;
  137.     // Iterator for traversing through all sound3d init structure names
  138.     StrSnd3DPoolMap::iterator    m_Snd3DItr;
  139.  
  140.     // SoundScape string-name to init structure map
  141.     SSInitMap                    m_SSMap;
  142.     // Iterator for traversing through all soundscape init structure names
  143.     SSInitMap::iterator            m_SSItr;
  144.  
  145.     // List of all updating soundscapes
  146.     SoundScapeList                m_SoundScapeUpdateList;
  147.  
  148.     // Shut-down synchronization handle
  149.     HANDLE                        m_hTerm;
  150.     // Critical section ensuring update thread is properly
  151.     // synchonized with other functions
  152.     CRITICAL_SECTION            m_csSoundMgrUpdate;
  153.  
  154.     // Track the current time for all time-based calculations
  155.     float                        m_fCurrentTime;
  156.     float                        m_fFrameTime;
  157. };
  158.  
  159. inline static SoundManager* CSoundMgr()
  160. {  return static_cast<SoundManager*>(SoundMgr());  }
  161.  
  162. }; // namespace Audio
  163.  
  164. #endif // __SOUNDMGR_H