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. #pragma message("linking with Microsoft's DirectSound library ...")
  34. #pragma comment(lib, "dsound.lib")
  35. #include "GenRS_AutoLock.h"
  36. #include "GENRS_SyncObject.h"
  37. #define  BUFSIZE 400000
  38. enum AUDIO_FORMAT
  39. {
  40. AUDIO_FORMAT_PCM=1,
  41. AUDIO_FORMAT_ADPCM_MS=2,
  42. AUDIO_FORMAT_ADPCM_IMA,
  43. AUDIO_FORMAT_ALAW,
  44. AUDIO_FORMAT_ULAW,
  45. };
  46. typedef struct _AUDIO_CONFIG
  47.   WORD  wFormatTag; 
  48.   WORD  nChannels; 
  49.   DWORD nSamplesPerSec; 
  50.   DWORD nAvgBytesPerSec; 
  51.   WORD  nBlockAlign; 
  52.   WORD  wBitsPerSample; 
  53.   WORD  cbSize; 
  54. } AUDIO_CONFIG; 
  55. class __declspec(dllexport) CDirectSound  
  56. {
  57. public: // construction/destruction
  58. CDirectSound();
  59. ~CDirectSound();
  60. BOOL            WriteToBuf();
  61. int WriteDataToBuf(BYTE* pBuf,DWORD dwLen);
  62. //void            SetHWnd(HWND hWnd);
  63. BOOL            CreateDSound(/*void* pHeader*/AUDIO_CONFIG* WaveHead,DWORD dwHeadLen);
  64. BOOL            SetPlaySpeed(float fSpeed);
  65. public: // operations
  66. void            Play(INT nTime = 0, BOOL bLoop = TRUE);
  67. void Stop();
  68. void Pause();
  69. void Continue();
  70. protected: // implementation
  71. BOOL IsValid() const;
  72. BOOL            GetWaveData(void * pHeader, WAVEFORMATEX * & pWaveHeader,
  73.   DWORD & dwHeadSize);
  74. BOOL            GetWaveData(void * pRes, WAVEFORMATEX * & pWaveHeader, 
  75. void * & pbWaveData, DWORD & cbWaveSize);
  76. // BOOL            ParseBuffer();
  77. BOOL            SetSoundData(void * pSoundData,DWORD SoundSize);
  78. BOOL            SetSoundData(DWORD Offset,void * pSoundData, DWORD dwSoundSize);
  79. BOOL            CreateSoundBuffer(WAVEFORMATEX * pcmwf);
  80. private: // data member
  81. DSBPOSITIONNOTIFY    DSNotify[16];
  82. AUDIO_CONFIG         m_config;
  83. float                m_fRate;
  84. int                  m_rate;
  85. DWORD                m_nSamplesPerSec;
  86. DWORD                m_nAvgBytesPerSec;
  87. DWORD                m_dwTotalSize;
  88. DWORD                m_dwHeadLen;
  89. DWORD                m_dwBufNum;
  90. DWORD                m_dwBufLen;
  91. DWORD                m_dwBufSize;
  92. DWORD                m_dwOffset;
  93. DWORD                m_dwLen;
  94. DWORD                m_dwTheSound;
  95. HANDLE               notify_events[16];
  96. HANDLE               m_hPlayThread;
  97. HANDLE               m_sysncObj;
  98. HANDLE               m_hEvent;
  99. HWND                 m_hWnd;
  100. BYTE*                m_pTheSound;
  101. BOOL                 m_bStop;
  102. BOOL                 m_bFir;
  103. BOOL                 m_bEnabled;
  104. BOOL                 m_bPlay;
  105. static LPDIRECTSOUNDNOTIFY  m_pDsNotify; 
  106. static LPDIRECTSOUNDBUFFER  m_pDsb;
  107. static LPDIRECTSOUND m_lpDirectSound;
  108. static DWORD         m_dwInstances;
  109. };
  110. #endif // !defined(AFX_DIRECTSOUND_H__A20FE86F_118F_11D2_9AB3_0060B0CDC13E__INCLUDED_)