AudioCtrl.h
上传用户:shenwh911
上传日期:2013-07-04
资源大小:54k
文件大小:5k
源码类别:

Audio

开发平台:

Visual C++

  1. #if !defined(AFX_AUDIOCTRL_H__17F72165_6C67_494E_B9D5_9935044316F0__INCLUDED_)
  2. #define AFX_AUDIOCTRL_H__17F72165_6C67_494E_B9D5_9935044316F0__INCLUDED_
  3. #include "VolumeCtrl.h"
  4. #if _MSC_VER > 1000
  5. #pragma once
  6. #endif // _MSC_VER > 1000
  7. typedef void (*MsgNotifyProc)(WPARAM wParam, LPARAM lParam);
  8. class CAudioCtrl : public CWnd
  9. {
  10. // Construction
  11. public:
  12. CAudioCtrl();
  13. // Attributes
  14. public:
  15. // Operations
  16. public:
  17. // Overrides
  18. // ClassWizard generated virtual function overrides
  19. //{{AFX_VIRTUAL(CAudioCtrl)
  20. public:
  21. virtual BOOL PreTranslateMessage(MSG* pMsg);
  22. //}}AFX_VIRTUAL
  23. // Implementation
  24. public:
  25. DWORD SetMixerDevs(UINT uiLine, DWORD* pdwMinVolume=NULL, DWORD* pdwMaxVolume=NULL);
  26. void Stop();
  27. BOOL SetRecordAudioFile(UINT uiChancel,char* pszFileName);
  28. BOOL Record(UINT uiRecChannel, DWORD dwSamplingRate, WORD  wSamplingBit);
  29. UINT GetWaveOutCount();
  30. UINT InitCtrl(UINT uiDevIndex, DWORD dwBufSize = 1024, HWND hwndParent = NULL, LPRECT lpRect = NULL, MsgNotifyProc msgNodityProc=NULL, WPARAM wParam=NULL);
  31. UINT GetWaveInAvailableDev();
  32. char* GetWaveInName(UINT uiDevID);
  33. UINT GetWaveInDevs();
  34. virtual ~CAudioCtrl();
  35. // Generated message map functions
  36. protected:
  37. LRESULT OnMM_WIM_DATA (WPARAM wParam, LPARAM lParam);
  38. LRESULT OnMM_WOM_DONE (WPARAM wParam, LPARAM lParam);
  39. //{{AFX_MSG(CAudioCtrl)
  40. afx_msg void OnTimer(UINT nIDEvent);
  41. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  42. //}}AFX_MSG
  43. DECLARE_MESSAGE_MAP()
  44. public:
  45. BOOL IsRecord();
  46. BOOL IsPlay();
  47. BOOL Play(char* pszPath);
  48. void SetCurVolume(DWORD dwValue);
  49. typedef enum _enum_status
  50. {
  51. ENUM_STATUS_INVALID, // 无效的状态
  52. ENUM_STATUS_READY, // 准备就绪
  53. ENUM_STATUS_PLAYING, // 正在播放
  54. ENUM_STATUS_RECORDING, // 正在录音
  55. ENUM_STATUS_STOPING, // 正在停止
  56. ENUM_STATUS_NUM,
  57. }ENUM_STATUS;
  58. // 录音的声道
  59. typedef enum _enum_rec_channel
  60. {
  61. ENUM_REC_CHANNEL_MONO,
  62. ENUM_REC_CHANNEL_STEREO,
  63. ENUM_REC_CHANNEL_ALONE,
  64. ENUM_REC_CHANNEL_NUM,
  65. } ENUM_REC_CHANNEL;
  66. // 保存文件的通道
  67. typedef enum _enum_file_channel
  68. {
  69. ENUM_FILE_CHANNEL_COMMON,
  70. ENUM_FILE_CHANNEL_LEFT=ENUM_FILE_CHANNEL_COMMON,
  71. ENUM_FILE_CHANNEL_RIGHT,
  72. ENUM_FILE_CHANNEL_NUM,
  73. } ENUM_FILE_CHANNEL;
  74. enum
  75. {
  76. TIMER_EVENT_STOPREC = 1,
  77. TIMER_EVENT_STOPPLAY,
  78. TIMER_EVENT_NUM,
  79. };
  80. private:
  81. void DrwaWaveShort(CClientDC &dc, DWORD dwDrawBytes, SHORT *pShortData, BOOL bLeftChannel);
  82. void DrwaWaveChar(CClientDC &dc, DWORD dwDrawBytes, BYTE *pCharData, BOOL bLeftChannel);
  83. void DrawWave(DWORD dwChannelBytes);
  84. void SetBkColor(COLORREF clr);
  85. CRect GetRectByChannel(BOOL bLeftChannel);
  86. void DrawBackground(CDC *pDC);
  87. void DrawBackground ( CDC *pDC, BOOL bLeftChannel );
  88. void StopAndFreeAll();
  89. void StopPlay();
  90. BOOL AddOutputBufferToQueue(int nIndex, int nSize);
  91. BOOL ReadSoundDataFromFile(LPVOID data, int &size);
  92. BOOL OpenWaveFile(char* lpszWaveFileName);
  93. void StopRecordAudioFile ( ENUM_FILE_CHANNEL eFileChannel, CString csStopFileType="wav" );
  94. BOOL AddInputBufferToQueue(int nIndex);
  95. BOOL AllocateBuffer(DWORD dwBufferSize);
  96. BOOL SetRelateParaAfterGetWaveFormat();
  97. void FreeBuffer();
  98. void SetWaveFormat(UINT uiRecChannel, DWORD dwSamplingRate, WORD  wSamplingBit);
  99. void StopRec();
  100. int PickupMonoData( WORD wBitsPerSample, char *szOrgData, int nOrgSize);
  101. BOOL Create(HWND hwndParent, LPRECT lpRect/*=NULL*/);
  102. void SetDeviceID(UINT uiIndex);
  103. UINT m_uiDeviceID;
  104. UINT                m_uiMixerID;
  105. DWORD m_dwQueuBufferSize;
  106. MsgNotifyProc m_pMsgNotifyProc;
  107. WPARAM m_wParam;
  108. ENUM_STATUS m_eStatus;
  109. ENUM_REC_CHANNEL m_eRecChannel;
  110. int m_nDataQueueNum;
  111. BOOL m_bRecording;
  112. HWAVEIN m_hRecord; // 录制句柄
  113. HWAVEOUT m_hPlay;   // 播放句柄
  114. WAVEFORMATEX m_Format;
  115. WORD m_wInQueu;        // 声音数据缓冲的数量
  116. char **m_szAryInData;  // 声音的数据缓冲
  117. char *m_szLeftInData;  // 左声道的数据缓冲
  118. char *m_szRightInData; // 右声道的数据缓冲
  119. WAVEHDR **m_pAryHdr;
  120. HMMIO m_hWaveFile[ENUM_FILE_CHANNEL_NUM];
  121. MMCKINFO m_MMCKInfoParent[ENUM_FILE_CHANNEL_NUM];
  122. MMCKINFO m_MMCKInfoChild[ENUM_FILE_CHANNEL_NUM];
  123. CBrush m_brsBkGnd; // 背景刷
  124. COLORREF m_clrBK;
  125. CRect m_rcClient;
  126. CPen m_PenB;
  127. CPen m_PenG;
  128. CPen m_PenPartLine;
  129. CFont m_fntChannelText;
  130. CFont m_fntDeviceNameText;
  131. BOOL m_bAlwaysDrawTowChannel; // 总是画两个声道的声波图
  132. enum
  133. {
  134. PARTLINE_HEIGHT = 2,
  135. COLOR_FRAME = RGB(128,64,0),
  136. };
  137. };
  138. #endif // !defined(AFX_AUDIOCTRL_H__17F72165_6C67_494E_B9D5_9935044316F0__INCLUDED_)