soundtemplates.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // soundtemplates.h
  3. //
  4. // Several useful sound template implementations.
  5. //
  6. namespace SoundEngine {
  7. // creates a sound template for the given wave file
  8. HRESULT CreateWaveFileSoundTemplate(TRef<ISoundTemplate>& pstDest, const ZString& strFilename);
  9. // creates a dummy sound template
  10. // (NOTE: Not optimized - fix or use only for error handling!)
  11. HRESULT CreateDummySoundTemplate(TRef<ISoundTemplate>& pstDest);
  12. // creates a sound template which uses the given sound template to create
  13. // sounds and turns then into a 3D sounds with the given minimum distance.
  14. HRESULT Create3DSoundTemplate(TRef<ISoundTemplate>& pstDest,
  15. ISoundTemplate* pstSource, float fMinimumDistance);
  16. // creates a sound template which adds a sound cone to the given sound
  17. HRESULT CreateSoundConeTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource,
  18. float fInnerAngle, float fOuterAngle, float fOutsideGain);
  19. // creates a sound template which shifts the pitch of the created sound
  20. HRESULT CreatePitchSoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource,
  21. float fPitch);
  22. // creates a sound template which adjusts the gain of the created sound
  23. HRESULT CreateGainSoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource,
  24. float fGain);
  25. // creates a sound template which adjusts the Priority of the created sound
  26. HRESULT CreatePrioritySoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource,
  27. float fPriority);
  28. // creates a looping sound from the given template
  29. HRESULT CreateLoopingSoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource);
  30. // creates an ASR sound from the given template with the given loop start and loop length (in seconds)
  31. HRESULT CreateASRSoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource,
  32. float fLoopStart, float fLoopLength);
  33. // creates a sound template which plays two sounds at once
  34. HRESULT CreatePairedSoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource1,
  35. ISoundTemplate* pstSource2);
  36. // Creates an ASR sound from the given template for a weapon that fires every n
  37. // seconds. This assumes the sound for a single shot falls off dramaticly after
  38. // 2n seconds, and plays some tricks based on this like only playing the two
  39. // most recent sounds.
  40. HRESULT CreateRepeatingFireSoundTemplate(TRef<ISoundTemplate>& pstDest,
  41. ISoundTemplate* pstSource,
  42. float fFireDelay);
  43. // provides an interface for adding new sound templates to a random sound
  44. // template.
  45. class IRandomSoundTemplate : public ISoundTemplate
  46. {
  47. public:
  48. // adds the given template as a possible sound to play, with the given
  49. // weight. The weight can be any arbitrary number, but a sound with weight
  50. // f will play half as often as a sound with weight 2*f.
  51. virtual HRESULT AddSoundTemplate(ISoundTemplate* pstSource, float fWeight) = 0;
  52. };
  53. // creates a sound template which randomly chooses from the sound templates
  54. // it contains each time a sound is played.
  55. HRESULT CreateRandomSoundTemplate(TRef<IRandomSoundTemplate>& pstDest);
  56. // creates a sound template for a sound which plays intermittently, and has a 50%
  57. // chance of playing over a period of fPeriod seconds. If bMultipleSounds is
  58. // true, this allows multiple sounds to play at the same time.
  59. HRESULT CreateIntermittentSoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource,
  60. float fPeriod, bool bMultipleSounds);
  61. // provides an interface for manipulating a sound mutex
  62. class ISoundMutex : public ISoundObject
  63. {
  64. public:
  65. // erases any pending sounds without playing them
  66. virtual HRESULT Reset() = 0;
  67. };
  68. // Creates a mutex used for the serialized sound template below. Each
  69. // mutex represents a single syncronization point - sounds with the same mutex
  70. // won't overlap, but sounds with different mutexes won't be prevented from
  71. // overlapping.
  72. HRESULT CreateSoundMutex(TRef<ISoundMutex>& pmutex);
  73. // Creates a sound template for a sound which will not be played at the same
  74. // time as any other sound created by a serial sound template with the same
  75. // mutex. fTimeout specifies the amount of time a sound can be delayed before
  76. // it is discarded. fPriority specifies the relative priority of the sound,
  77. // which is added to the age of a sound when trying to find the oldest sound
  78. // to play next. bSingleInstance specifies whether multiple copies of the
  79. // given sound can queue up - if false, just the most recent one will play.
  80. HRESULT CreateSerializedSoundTemplate(TRef<ISoundTemplate>& pstDest, ISoundTemplate* pstSource,
  81. ISoundMutex* pmutex, float fTimeout, float fPriority,
  82. bool bSingleInstance);
  83. };