WaveOut.h
上传用户:amei960
上传日期:2007-02-05
资源大小:143k
文件大小:2k
源码类别:

Audio

开发平台:

Visual C++

  1. #ifndef _WAVEOUT_H_
  2. #define _WAVEOUT_H_
  3. #define HERTZ_POOR 8000
  4. #define HERTZ_LOW 11025
  5. #define HERTZ_NORMAL 22050
  6. #define HERTZ_HIGH 44100
  7. #define PLAY_DELAY 5
  8. #include <mmsystem.h>
  9. #include <afxmt.h>
  10. //音频输出(播放数字音频)-将音频数据在硬件上进行播放
  11. class CWaveOut
  12. {
  13. private:
  14. static void CALLBACK waveOutProc(HWAVEOUT hwo,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2);
  15. private:
  16. WAVEOUTCAPS waveCaps;
  17. BOOL bDevOpen;
  18. HWAVEOUT m_hWave;
  19. private:
  20.     WORD nChannels; 
  21.     DWORD dwHertZ; 
  22.     WORD wBits;
  23. private:
  24. CCriticalSection m_Lock;
  25. int m_BufferQueue;
  26. inline int GetBufferNum();
  27. inline void AddBuffer();
  28. inline void SubBuffer();
  29. private:
  30. BOOL Open();
  31. void Close();
  32. public:
  33. CWaveOut();
  34. ~CWaveOut();
  35. //check
  36. public:
  37. BOOL IsExistDevice();
  38. WAVEOUTCAPS* GetDeviceCap();
  39. //setting
  40. public:
  41. enum CHANNEL { SINGLE ,  STEREO };
  42. inline void SetChannel(CHANNEL Channel);
  43. inline void SetHertZ(DWORD HertZ);
  44. inline void SetBit(WORD Bits);
  45. //operation
  46. public:
  47. BOOL Start();
  48. BOOL Play(char* buf,UINT nSize);
  49. void Stop();
  50. };
  51. inline void CWaveOut::SetChannel(CHANNEL Channel)
  52. {
  53. switch( Channel )
  54. {
  55. case SINGLE:
  56. nChannels = 1;
  57. break;
  58. case STEREO:
  59. nChannels = 2;
  60. break;
  61. }
  62. }
  63. inline void CWaveOut::SetHertZ(DWORD HertZ)
  64. {
  65. dwHertZ = HertZ;
  66. }
  67. inline void CWaveOut::SetBit(WORD Bits)
  68. {
  69. wBits = Bits;
  70. }
  71. inline int CWaveOut::GetBufferNum()
  72. {
  73. int nRet = 5;
  74. m_Lock.Lock();
  75. nRet = m_BufferQueue;
  76. m_Lock.Unlock();
  77. return nRet;
  78. }
  79. inline void CWaveOut::AddBuffer()
  80. {
  81. m_Lock.Lock();
  82. m_BufferQueue++;
  83. m_Lock.Unlock();
  84. }
  85. inline void CWaveOut::SubBuffer()
  86. {
  87. m_Lock.Lock();
  88. m_BufferQueue--;
  89. m_Lock.Unlock();
  90. }
  91. #endif