home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Game_Audio / audio_sdk / src / AudioScript / SoundScape.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-07-01  |  3.4 KB  |  157 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 __SOUNDSCAPE_H
  12. #define __SOUNDSCAPE_H
  13.  
  14. #include "Audio.h"
  15.  
  16. namespace Audio
  17. {
  18.  
  19. // Internally used to contain all data needed for playback
  20. // of a background element
  21. struct BackgroundElement
  22. {
  23.     BackgroundElement()    {  Clear();  }
  24.     void Clear()
  25.     {
  26.         m_Init.Clear();
  27.         m_sSoundID.erase();
  28.         m_fCurrentVolume = 1.0f;
  29.         m_fTargetVolumeTime = 0.0f;
  30.         m_fCurrentVolumeChangeRate = 0.0f;
  31.         m_fCurrentPitch = 1.0f;
  32.         m_fTargetPitchTime = 0.0f;
  33.         m_fCurrentPitchChangeRate = 0.0f;
  34.     }
  35.  
  36.     BackgroundInit    m_Init;
  37.     std::string        m_sSoundID;
  38.     float            m_fCurrentVolume;
  39.     float            m_fTargetVolumeTime;
  40.     float            m_fCurrentVolumeChangeRate;
  41.     float            m_fCurrentPitch;
  42.     float            m_fTargetPitchTime;
  43.     float            m_fCurrentPitchChangeRate;
  44. };
  45.  
  46.  
  47. // Internally used to contain all data needed for playback
  48. // of a periodic element
  49. struct PeriodicElement
  50. {
  51.     PeriodicElement()    {  Clear();  }
  52.     void Clear()
  53.     {
  54.         m_Init.Clear();
  55.         m_sSound3DID.erase();
  56.         m_fNextPlay = 0.0f;
  57.         m_vPosition.x = 0.0f;
  58.         m_vPosition.y = 0.0f;
  59.         m_vPosition.z = 0.0f;
  60.     }
  61.  
  62.     PeriodicInit    m_Init;
  63.     std::string        m_sSound3DID;
  64.     float            m_fNextPlay;
  65.     AUDIOVECTOR        m_vPosition;
  66. };
  67.  
  68.  
  69. typedef std::vector<BackgroundElement> SSBEVector;
  70. typedef std::vector<PeriodicElement> SSPEVector;
  71.  
  72. // Used to internally initialize a soundscape using scripts
  73. struct SoundScapeInternalInit
  74. {
  75.     SSBEVector    m_aBackground;
  76.     SSPEVector    m_aPeriodic;
  77. };
  78.  
  79.  
  80. class SoundScape : public ISoundScape
  81. {
  82.  
  83. DEFINE_POOL(SoundScape);
  84.  
  85. // Interface functions
  86. public:
  87.     bool Init();
  88.     void Destroy();
  89.  
  90.     bool IsInitialized() const    {  return m_bInitialized;  }
  91.  
  92.     bool AddElement(const BackgroundInit& init);
  93.     bool AddElement(const PeriodicInit& init);
  94.  
  95.     bool Load();
  96.     bool Unload();
  97.     bool IsLoaded() const;
  98.  
  99.     bool Play();
  100.     bool Stop();
  101.     bool Pause();
  102.  
  103.     bool IsPlaying() const;
  104.     bool IsPaused() const;
  105.  
  106.     bool IsLooping() const;
  107.  
  108.     bool SetVolume(float fVolume);
  109.     bool GetVolume(float &fVolume) const;
  110.  
  111.     // Generic property support (for driver-specific extensions)
  112.     bool QuerySupport(const GUID& guid, uint32 nID, uint32* pTypeSupport);
  113.     bool Get(const GUID& guidProperty, uint32 nID, void* pInstanceData,
  114.         uint32 nInstanceLength, void* pPropData, 
  115.         uint32 nPropLength, uint32* pBytesReturned);
  116.     bool Set(const GUID& guidProperty, uint32 nID, void* pInstanceData,
  117.         uint32 nInstanceLength, void* pPropData, 
  118.         uint32 nPropLength, bool bStoreProperty);
  119.  
  120. // Concrete-only functions
  121. public:
  122.  
  123.     void Term();
  124.     bool InternalInit(SoundScapeInternalInit& init);
  125.     void Update();
  126.  
  127. private:
  128.     SoundScape();
  129.     virtual ~SoundScape();
  130.  
  131.     void Clear();
  132.  
  133.     void UpdateBackground();
  134.     void UpdatePeriodic();
  135.  
  136. // Private data
  137. private:
  138.  
  139.     bool        m_bInitialized;
  140.     bool        m_bFirstUpdate;
  141.     bool        m_bLoaded;
  142.     bool        m_bPlaying;
  143.     bool        m_bPaused;
  144.  
  145.     SSBEVector    m_aBackground;
  146.     SSPEVector    m_aPeriodic;
  147.  
  148.     float        m_fCurrentTime;
  149.  
  150.     float        m_fVolume;
  151.     bool        m_bVolumeChanged;
  152. };
  153.  
  154. }; // namespace Audio
  155.  
  156.  
  157. #endif // __SOUNDSCAPE_H