DSBuffer.h
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:4k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // Copyright (C) 1998-1999 DXGuide.  All Rights Reserved.
  2. // File: DSBuffer.h
  3. #ifndef _DSBUFFER__H
  4. #define _DSBUFFER__H
  5. #if _MSC_VER >= 1000
  6. #pragma once
  7. #endif // _MSC_VER >= 1000
  8. class CWaveFile;
  9. class CDS3DListener;
  10. class CPackFileManager;
  11. class CDirectSound;
  12. enum CDirectSound::WAVEFORMATCODE;
  13. class CDSBuffer
  14. {
  15. friend class CDirectSound;
  16. friend class CDS3DListener;
  17. friend class CDirectMusic;
  18. public:
  19. enum DSB_FLAG2
  20. {
  21. DSB2_LOOP = 1L,
  22. DSB2_NO_FILE = 2L,
  23. };
  24. public:
  25. CDSBuffer(void);
  26. virtual ~CDSBuffer();
  27. protected:
  28. bool Create(CDirectSound*  pDS); // primary
  29. public:
  30. virtual bool Create(CDirectSound*  pDS, LPCTSTR  lpszFileName,
  31. CPackFileManager*  pPackFileManager = NULL,
  32. int  nBuffer = 1,
  33. DWORD  dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STATIC);
  34. bool Create(CDirectSound*  pDS, WORD  wID,
  35. int  nBuffer = 1,
  36. DWORD  dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STATIC);
  37. protected:
  38. bool Create(CDirectSound*  pDS, CWaveFile*  pWaveFile,
  39. int  nBuffer, DWORD  dwFlags);
  40. bool CreatePrimarySoundBuffer(void);
  41. virtual bool CreateSecondarySoundBuffer(void);
  42. protected:
  43. bool CreateSoundBuffer(
  44. DWORD  dwBufSize,
  45. DWORD  dwFreq,
  46. DWORD  dwBitsPerSample,
  47. WORD  wBlkAlign,
  48. bool  bStereo);
  49. bool CreateSoundBuffer(DWORD  dwBufSize,
  50. WAVEFORMATEX*  pWaveFormatEX);
  51. public:
  52. void GetFormat(void);
  53. bool SetFormat(CDirectSound::WAVEFORMATCODE  waveFormatCode);
  54. virtual HRESULT FillSoundDataBuffer(DWORD  dwWriteBytes = 0);
  55. HRESULT GetCaps(LPDSBCAPS  lpDSBufferCaps) const;
  56. protected:
  57. static CString FormatCodeToText(CDirectSound::WAVEFORMATCODE  waveFormatCode);
  58. static bool FormatCodeToWFX(CDirectSound::WAVEFORMATCODE  waveFormatCode, PWAVEFORMATEX  pwfx);
  59. bool FindHighestFormat(void);
  60. public:
  61. CDirectSound::WAVEFORMATCODE CalcWaveFormatCode(PWAVEFORMATEX  pwfx);
  62. public:
  63. virtual bool Play(void);
  64. virtual bool Stop(int  nIndex = 0);
  65. virtual void SetLoop(bool  bLoop);
  66. LONG GetVolume(int  nIndex = 0) const;
  67. HRESULT SetVolume(LONG  lVolume, int  nIndex = 0);
  68. LONG GetPan(int  nIndex = 0) const;
  69. HRESULT SetPan(LONG  lPan, int  nIndex = 0);
  70. DWORD GetFrequency(int  nIndex = 0) const;
  71. HRESULT SetFrequency(DWORD  dwFrequency, int  nIndex = 0);
  72. public:
  73. // Batch parameter manipulation
  74. HRESULT GetAllParameters(DS3DBUFFER*  pDS3DBuffer, int  nIndex = 0) const;
  75. HRESULT SetAllParameters(const DS3DBUFFER*  pDS3DBuffer, DWORD  dwApply, int  nIndex = 0);
  76. // Distance
  77. HRESULT GetMaxDistance(D3DVALUE*  pflMaxDistance, int  nIndex = 0) const;
  78. HRESULT SetMaxDistance(D3DVALUE  pflMaxDistance, DWORD  dwApply, int  nIndex = 0);
  79. HRESULT GetMinDistance(D3DVALUE*  pflMaxDistance, int  nIndex = 0) const;
  80. HRESULT SetMinDistance(D3DVALUE  pflMaxDistance, DWORD  dwApply, int  nIndex = 0);
  81. // Operation mode
  82. HRESULT GetMode(DWORD*  dwMode, int  nIndex = 0) const;
  83. HRESULT SetMode(DWORD  dwMode, DWORD  dwApply, int  nIndex = 0);
  84. // Position
  85. HRESULT GetPosition(D3DVECTOR*  vPosition, int  nIndex = 0) const;
  86. HRESULT SetPosition(D3DVALUE  x, D3DVALUE  y, D3DVALUE  z, DWORD  dwApply, int  nIndex = 0);
  87. // Sound Projection Cones
  88. HRESULT GetConeAngles(DWORD*  dwInsideConeAngle, DWORD*  dwOutsideConeAngle, int  nIndex = 0) const;
  89. HRESULT SetConeAngles(DWORD  dwInsideConeAngle, DWORD  dwOutsideConeAngle, DWORD  dwApply, int  nIndex = 0);
  90. HRESULT GetConeOrientation(D3DVECTOR*  vOrientation, int  nIndex = 0) const;
  91. HRESULT SetConeOrientation(D3DVALUE  x, D3DVALUE  y, D3DVALUE  z, DWORD  dwApply, int  nIndex = 0);
  92. HRESULT GetConeOutsideVolume(LONG*  lConeOutsideVolume, int  nIndex = 0) const;
  93. HRESULT SetConeOutsideVolume(LONG  lConeOutsideVolume, DWORD  dwApply, int  nIndex = 0);
  94. // Velocity
  95. HRESULT GetVelocity(D3DVECTOR*  vVelocity, int  nIndex = 0) const;
  96. HRESULT SetVelocity(D3DVALUE  x, D3DVALUE  y, D3DVALUE  z, DWORD  dwApply, int  nIndex = 0);
  97. protected:
  98. LPDIRECTSOUNDBUFFER GetFreeBuffer(void);
  99. HRESULT ReLoadSoundBuffer(void);
  100. public:
  101. #ifdef _DEBUG
  102. static ULONG m_ulDSBufferCounter;
  103. #endif // _DEBUG
  104. protected:
  105. CDirectSound* m_pDS;
  106. LPDIRECTSOUNDBUFFER* m_ppDSB;
  107. union
  108. {
  109. LPDIRECTSOUND3DBUFFER* m_ppDS3DB;
  110. CDS3DListener* m_pDS3DListener;
  111. };
  112. protected:
  113. int m_nBuffers;
  114. int m_nCurrent;
  115. union
  116. {
  117. CWaveFile* m_pWaveFile;
  118. WAVEFORMATEX* m_pWfxFormat;
  119. };
  120. CDirectSound::WAVEFORMATCODE m_waveFormatCode;
  121. DWORD m_dwDSBFlags2;
  122. DWORD m_dwDSBFlags;
  123. };
  124. #endif // _DSBUFFER__H