AUDIOSYSTEM.H
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 3k
Category:

OpenCV

Development Platform:

Visual C++

  1. #ifndef __AUDIOSYSTEM_H
  2. #define __AUDIOSYSTEM_H
  3. #include <dmusicc.h>               // DirectMusic includes
  4. #include <dmusici.h>
  5. #include <d3d8types.h>             // for D3DVECTOR
  6. #include <cguid.h>                 // for GUID_NULL
  7. /*
  8. The CAudio class
  9. */
  10. class CAudio
  11. {
  12. private:
  13. IDirectMusicSegment8 *dmusicSegment;      // the segment
  14. // The 3D buffer might not be used (e.g. background music).
  15. // It should only be used for 3D positional sounds.
  16. IDirectSound3DBuffer *ds3DBuffer;
  17. bool is3DSound; // true if this is a 3D sound
  18. protected:
  19. public:
  20. CAudio() { dmusicSegment = NULL; ds3DBuffer = NULL; is3DSound = false; }
  21. ~CAudio() 
  22. {
  23. if (dmusicSegment != NULL)
  24. {
  25. dmusicSegment->Release(); 
  26. dmusicSegment = NULL;
  27. }
  28. if (ds3DBuffer != NULL)
  29. {
  30. ds3DBuffer->Release(); 
  31. ds3DBuffer = NULL;
  32. }
  33. }
  34. void SetSegment(IDirectMusicSegment8 *seg) { dmusicSegment = seg; }
  35. IDirectMusicSegment8 *GetSegment() { return dmusicSegment; }
  36. void Set3DBuffer(IDirectSound3DBuffer *dsBuff);
  37. IDirectSound3DBuffer *Get3DBuffer() { return ds3DBuffer; }
  38. bool Is3DSound() { return is3DSound; }
  39. void Set3DSound(bool b) { is3DSound = b; }
  40. void Set3DParams(float minDistance, float maxDistance);
  41. void Set3DPos(float x, float y, float z);
  42. };
  43. class CAudioSystem
  44. {
  45. private:
  46. IDirectMusicLoader8 *dmusicLoader;              // the loader
  47. IDirectMusicPerformance8 *dmusicPerformance;    // the performance
  48. IDirectMusicAudioPath8 *dmusic3DAudioPath;      // the audiopath
  49. IDirectSound3DListener8 *ds3DListener;          // 3d listener
  50. DS3DLISTENER dsListenerParams;                  // 3d listener properties
  51. public:
  52. CAudioSystem();
  53. ~CAudioSystem();
  54. bool InitDirectXAudio(HWND hwnd);
  55. IDirectSound3DBuffer8 *Create3DBuffer();
  56. CAudio *Create(char *filename, bool is3DSound);
  57. IDirectMusicSegment8 *CreateSegment(char *filename, bool is3DSound);
  58. void Play(CAudio *audio, DWORD numRepeats);
  59. void Stop(CAudio *audio);
  60. void PlaySegment(IDirectMusicSegment8 *dmSeg, bool is3DSound, DWORD numRepeats);
  61. void StopSegment(IDirectMusicSegment8 *dmSeg);
  62. void Shutdown();
  63. void SetListenerPos(float cameraX, float cameraY, float cameraZ);
  64. void SetListenerRolloff(float rolloff);
  65. void SetListenerOrientation(float forwardX, float forwardY, float forwardZ,
  66.    float topX, float topY, float topZ)
  67. {
  68. ds3DListener->SetOrientation(forwardX, forwardY, -forwardZ, topX, topY, topZ, DS3D_IMMEDIATE);
  69. }
  70. IDirectMusicPerformance8 *GetPerformance() { return dmusicPerformance; }
  71. };
  72. #endif