waveOutWrite

msdn原文说明

  The  waveOutWrite function sends a data block to the given waveform-audio output device.
  MMRESULT waveOutWrite(
  HWAVEOUT hwo,
  LPWAVEHDR pwh,
  UINT cbwh
  );
   Parameters
   hwo
  Handle to the waveform-audio output device.
   pwh
  Pointer to a  WAVEHDR structure containing information about the data block.
   cbwh
  Size, in bytes, of the  WAVEHDR structure.
   Return Values
  Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following.
  
ValueDescription
MMSYSERR_INVALHANDLESpecified device handle is invalid.
MMSYSERR_NODRIVERNo device driver is present.
MMSYSERR_NOMEMUnable to allocate or lock memory.
WAVERR_UNPREPAREDThe data block pointed to by the pwh parameter hasn't been prepared.
  Remarks
  When the buffer is finished, the WHDR_DONE bit is set in the  dwFlags member of the  WAVEHDR structure.
  The buffer must be prepared with the  waveOutPrepareHeader function before it is passed to  waveOutWrite. Unless the device is paused by calling the  waveOutPause function, playback begins when the first data block is sent to the device.
   Requirements
    Windows NT/2000/XP: Included in Windows NT 3.1 and later.
    Windows 95/98/Me: Included in Windows 95 and later.
    Header: Declared in Mmsystem.h; include Windows.h.
    Library: Use Winmm.lib.
   See Also
  Waveform Audio, Waveform Functions,  WAVEHDRwaveOutPrepareHeaderwaveOutPause

中文说明:

  警告:在使用此函数之前,请先调用waveOutPrepareHeader函数
  这个函数将在音频媒体中播放pwh指定的数据
  hwo 音频设备句柄,通过waveOutOpen获得
  pwh 播放数据的信息.
  注意:要播放的数据一般在声音文件里面获得,并填入这个结构.由于是直接播放数据,所以要播放多少数据可以通过修改这个结构来达到目的.
  cbwh pwh结构的大小,单位字节/BYTE
  返回值
  MMSYSERR_NOERROR 成功
  MMSYSERR_INVALHANDLE hwo是无效的
  MMSYSERR_NODRIVER 没有音频设备
  MMSYSERR_NOMEM 内存不足
  WAVERR_UNPREPARED 没有调用waveOutPrepareHeader函数,或者调用waveOutPrepareHeader失败
  注意
  播放完数据后 WHDR_DONE 会设置到pwh指向的结构体中的 dwFlags 成员
  在调用本函数之前必须调用waveOutPrepareHeader函数.
  除非是恢复被 waveOutPause函数暂停的设备,回调函数会在第一个数据块一送达设备的时候就开始运作.回调函数在waveOutOpen里面设置
  警告:请不要在回调函数里面调用任何的waveOut系列的函数,否则一定会造成死锁(也就是程序失去响应).哪怕是 waveOutUnprepareHeader, waveOutClose
  也是不行的.我看到网上有些例子在回调函数里面使用了这个,这是错误的做法.
  要求:
  系统要求:NT3.1以及之后的版本,windows95以及之后的版本.(其实就是没有什么系统要求,只要是windows就好)
  头文件:本系列函数声明在Mmsystem.h中.包含Windows.h就可以了.
  库文件:Winmm.lib

个人使用心得

  首先是头文件,库要包含到项目里面去,这我就不废话了
  调用顺序是waveOutOpen -> waveOutPrepareHeader ->waveOutWrite
  然后是waveOutUnprepareHeader,这个调用的时机必须是在播放完成以后.也就是那个WHDR_DONE设置到dwFlags之后.没有播放完成调用这个会导致一个异常中断.访问的地方是不可读的.
  最后关闭时调用waveOutClose.调用完这个后,hwo就是一个不可靠的变量了.不能再使用这个来传给其他waveOut函数了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值