DirectSound.h
上传用户:hygd004
上传日期:2022-02-04
资源大小:1841k
文件大小:4k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 1998 by J鰎g K鰊ig
  3. // All rights reserved
  4. //
  5. // This file is part of the completely free tetris clone "CGTetris".
  6. //
  7. // This is free software.
  8. // You may redistribute it by any means providing it is not sold for profit
  9. // without the authors written consent.
  10. //
  11. // No warrantee of any kind, expressed or implied, is included with this
  12. // software; use at your own risk, responsibility for damages (if any) to
  13. // anyone resulting from the use of this software rests entirely with the
  14. // user.
  15. //
  16. // Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  17. // I'll try to keep a version up to date.  I can be reached as follows:
  18. //    J.Koenig@adg.de                 (company site)
  19. //    Joerg.Koenig@rhein-neckar.de    (private site)
  20. /////////////////////////////////////////////////////////////////////////////
  21. // DirectSound.h: interface for the CDirectSound class.
  22. //
  23. //////////////////////////////////////////////////////////////////////
  24. #if !defined(AFX_DIRECTSOUND_H__A20FE86F_118F_11D2_9AB3_0060B0CDC13E__INCLUDED_)
  25. #define AFX_DIRECTSOUND_H__A20FE86F_118F_11D2_9AB3_0060B0CDC13E__INCLUDED_
  26. #if _MSC_VER >= 1000
  27. #pragma once
  28. #endif // _MSC_VER >= 1000
  29. #include <mmsystem.h>
  30. #define INITGUID
  31. #include <dsound.h>
  32. //#include "d:dxsdkincludedsound.h"
  33. #define  BUFSIZE 400000
  34. enum AUDIO_FORMAT
  35. {
  36. AUDIO_FORMAT_PCM=1,
  37. AUDIO_FORMAT_ADPCM_MS=2,
  38. AUDIO_FORMAT_ADPCM_IMA,
  39. AUDIO_FORMAT_ALAW,
  40. AUDIO_FORMAT_ULAW,
  41. };
  42. typedef struct _AUDIO_CONFIG
  43.   WORD  wFormatTag; 
  44.   WORD  nChannels; 
  45.   DWORD nSamplesPerSec; 
  46.   DWORD nAvgBytesPerSec; 
  47.   WORD  nBlockAlign; 
  48.   WORD  wBitsPerSample; 
  49.   WORD  cbSize; 
  50. } AUDIO_CONFIG; 
  51. class __declspec(dllexport) CDirectSound  
  52. {
  53. public: // construction/destruction
  54. CDirectSound();
  55. ~CDirectSound();
  56. BOOL            WriteToBuf();
  57. int WriteDataToBuf(BYTE* pBuf,DWORD dwLen);
  58. // void            SetHWnd(HWND hWnd);
  59. BOOL            CreateDSound(/*void* pHeader*/AUDIO_CONFIG* WaveHead,DWORD dwHeadLen);
  60. BOOL            SetPlaySpeed(float fSpeed);
  61. public: // operations
  62. void            Play(INT nTime = 0, BOOL bLoop = TRUE);
  63. void Stop();
  64. void Pause();
  65.     void            Open();
  66. void Continue();
  67. protected: // implementation
  68. BOOL IsValid() const;
  69. BOOL            GetWaveData(void * pHeader, WAVEFORMATEX * & pWaveHeader,
  70.   DWORD & dwHeadSize);
  71. BOOL            GetWaveData(void * pRes, WAVEFORMATEX * & pWaveHeader, 
  72. void * & pbWaveData, DWORD & cbWaveSize);
  73. // BOOL            ParseBuffer();
  74. BOOL            SetSoundData(void * pSoundData,DWORD SoundSize);
  75. BOOL            SetSoundData(DWORD Offset,void * pSoundData, DWORD dwSoundSize);
  76. BOOL            CreateSoundBuffer(WAVEFORMATEX * pcmwf);
  77. private: // data member
  78. DSBPOSITIONNOTIFY    DSNotify[16];
  79. AUDIO_CONFIG         m_config;
  80. float                m_fRate;
  81. int                  m_rate;
  82. DWORD                m_nSamplesPerSec;
  83. DWORD                m_nAvgBytesPerSec;
  84. DWORD                m_dwTotalSize;
  85. DWORD                m_dwHeadLen;
  86. DWORD                m_dwBufNum;
  87. DWORD                m_dwBufLen;
  88. DWORD                m_dwBufSize;
  89. DWORD                m_dwOffset;
  90. DWORD                m_dwLen;
  91. DWORD                m_dwTheSound;
  92. HANDLE               notify_events[16];
  93. HANDLE               m_hPlayThread;
  94. HANDLE               m_sysncObj;
  95. HANDLE               m_hEvent;
  96. HWND                 m_hWnd;
  97. BYTE*                m_pTheSound;
  98. BOOL                 m_bStop;
  99. BOOL                 m_bFir;
  100. BOOL                 m_bEnabled;
  101. BOOL                 m_bPlay;
  102.              
  103. static LPDIRECTSOUNDNOTIFY  m_pDsNotify; 
  104. static LPDIRECTSOUNDBUFFER  m_pDsb;
  105. static LPDIRECTSOUND m_lpDirectSound;
  106. static DWORD         m_dwInstances;
  107. };
  108. #endif // !defined(AFX_DIRECTSOUND_H__A20FE86F_118F_11D2_9AB3_0060B0CDC13E__INCLUDED_)