wavein.cpp
上传用户:oldpeter23
上传日期:2013-01-09
资源大小:1111k
文件大小:3k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. //NetTalk
  2. /*------------------------------------------------------------------------------*
  3.  =============================
  4.    模块名称: wavein.cpp
  5.  =============================
  6.  
  7.  [版权]
  8.  
  9.    2000-2002  115软件工厂  版权所有
  10.                                               
  11. *------------------------------------------------------------------------------*/
  12. #include <Windows.h>
  13. #include "wavein.h"
  14. #pragma comment(lib,"Winmm")
  15. /*------------------------------------------------------------------------------*/
  16. void waveInErrorMsg(MMRESULT mmr,char* szTitle)
  17. {
  18. char txt[MAXERRORLENGTH];
  19. waveInGetErrorText(mmr,txt,MAXERRORLENGTH);
  20. MessageBox(0,txt,szTitle,MB_OK|MB_ICONWARNING);
  21. }
  22. /*------------------------------------------------------------------------------*/
  23. CWaveIn::CWaveIn()
  24. {
  25. m_mmr=0;
  26. m_hIn=0;
  27. }
  28. /*------------------------------------------------------------------------------*/
  29. //打开录音设备
  30. BOOL CWaveIn::OpenDev(WAVEFORMATEX* pfmt,DWORD dwCallback,DWORD dwCallbackInstance,DWORD fdwOpen)
  31. {
  32. BOOL bRet=FALSE;
  33. WAVEFORMATEX wf;
  34. if(!pfmt)//默认格式
  35. {
  36. wf.wFormatTag = WAVE_FORMAT_PCM;
  37. wf.cbSize = 0;
  38. wf.wBitsPerSample=16;
  39. wf.nSamplesPerSec=8000;
  40. wf.nChannels=1;
  41. wf.nAvgBytesPerSec = wf.nSamplesPerSec*(wf.wBitsPerSample/8);
  42. wf.nBlockAlign = wf.nChannels     *(wf.wBitsPerSample/8);
  43. pfmt=&wf;
  44. }
  45. MMRESULT mmr;
  46. mmr=waveInOpen(0,WAVE_MAPPER,pfmt,0,0,WAVE_FORMAT_QUERY);
  47. if(mmr)
  48. {
  49. SetLastMMError(mmr);
  50. goto RET;
  51. }
  52. mmr=waveInOpen(&m_hIn,WAVE_MAPPER,pfmt,dwCallback,dwCallbackInstance,fdwOpen);
  53. if(mmr)
  54. {
  55. SetLastMMError(mmr);
  56. goto RET;
  57. }
  58. bRet=TRUE;
  59. RET:
  60. return bRet;
  61. }
  62. /*------------------------------------------------------------------------------*/
  63. CWaveIn::operator HWAVEIN() const
  64. {
  65. return m_hIn;
  66. }
  67. /*------------------------------------------------------------------------------*/
  68. CWaveIn::~CWaveIn()
  69. {
  70. }
  71. /*------------------------------------------------------------------------------*/
  72. MMRESULT CWaveIn::GetLastMMError()
  73. {
  74. return m_mmr;
  75. }
  76. /*------------------------------------------------------------------------------*/
  77. void CWaveIn::SetLastMMError(MMRESULT mmr)
  78. {
  79. m_mmr=mmr;
  80. }
  81. /*------------------------------------------------------------------------------*/
  82. //该死的死锁!就出现在这里
  83. BOOL CWaveIn::CloseDev()
  84. {
  85. BOOL bRet=FALSE;
  86. if(!m_hIn)
  87. goto RET;
  88. m_mmr=waveInReset(m_hIn);
  89. if(m_mmr)
  90. goto RET;
  91. m_mmr=waveInClose(m_hIn);
  92. if(m_mmr)
  93. goto RET;
  94. m_hIn=0;
  95. bRet=TRUE;
  96. RET:
  97. return bRet;
  98. }
  99. /*------------------------------------------------------------------------------*/
  100. HWAVEIN CWaveIn::GetHandle()
  101. {
  102. return m_hIn;
  103. }