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

IP电话/视频会议

开发平台:

Visual C++

  1. //NetTalk
  2. /*------------------------------------------------------------------------------*
  3.  =============================
  4.    模块名称: AudioPlay.cpp
  5.  =============================
  6.  
  7.  [版权]
  8.  
  9.    2000-2002  115软件工厂  版权所有
  10.                                               
  11. *------------------------------------------------------------------------------*/
  12. #include "WndX.h"
  13. #include <MMREG.H>
  14. #include "WaveOut.h"
  15. #include "AudioPlay.h"
  16. /*------------------------------------------------------------------------------*/
  17. CAudioPlay::CAudioPlay()
  18. {
  19. }
  20. /*------------------------------------------------------------------------------*/
  21. //播放一块数据
  22. BOOL CAudioPlay::Play(char *buf, UINT uSize)
  23. {
  24. BOOL bRet=FALSE;
  25. char* p;
  26. LPWAVEHDR pwh=new WAVEHDR;
  27. if(!pwh)
  28. goto RET;
  29. p=new char[uSize];//重新分配一块内存(在播放结束后删除)
  30. if(!p)
  31. goto RET;
  32. CopyMemory(p,buf,uSize);
  33. ZeroMemory(pwh,sizeof(WAVEHDR));
  34. pwh->dwBufferLength=uSize;
  35. pwh->lpData=p;
  36. //
  37. m_mmr=waveOutPrepareHeader(m_hOut,pwh,sizeof(WAVEHDR));
  38.     if(m_mmr)
  39. goto RET;
  40. m_mmr=waveOutWrite(m_hOut,pwh,sizeof(WAVEHDR));
  41. if(m_mmr)
  42. goto RET;
  43. bRet=TRUE;
  44. RET:
  45. return bRet;
  46. }
  47. /*------------------------------------------------------------------------------*/
  48. //打开音频输出设备
  49. BOOL CAudioPlay::Create(WAVEFORMATEX *pwf,DWORD dwCallBack,DWORD dwInst,DWORD fdwOpen )
  50. {
  51. BOOL bRet=FALSE;
  52. if(m_hOut)
  53. {
  54. bRet=TRUE;
  55. goto RET;
  56. }
  57. //打开设备
  58. if(!OpenDev(pwf,dwCallBack,dwInst,fdwOpen))
  59. goto RET;
  60. bRet=TRUE;
  61. RET:
  62. return bRet;
  63. }
  64. /*------------------------------------------------------------------------------*/
  65. CAudioPlay::~CAudioPlay()
  66. {
  67. Destroy();
  68. }
  69. /*------------------------------------------------------------------------------*/
  70. BOOL CAudioPlay::Destroy()
  71. {
  72. BOOL bRet=FALSE;
  73. if(!CloseDev())
  74. goto RET;
  75. bRet=TRUE;
  76. RET:
  77. return bRet;
  78. }