R
redweek
Unregistered / Unconfirmed
GUEST, unregistred user!
当拨号完成后,用户拿起话筒时,通过moden播放‘*。wav’文件,使接听者可以听到声音。<br>1。怎样获得waveform out 设备的Iddevice?<br>2.怎样把‘*.wav’变成‘pcm’格式?<br>3。怎样播放?<br><br>我下面的程序有问题,谁能帮我解答?<br> e-mail:redweek@21cn.com<br> redweek@163.net<br><br><br>-------------------------------<br>unit waveout;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,mmsystem,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> lpdata:thandle;<br> mywaveout:hwaveout;<br><br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br> var<br> iomm:hMMIO;<br> mmckinfoparent:MMCKINFO;<br> mmckinfosubchunk:MMCKINFO;<br> dwfmtsize:integer;<br> pformat:twaveformatex;<br> caps:waveoutcaps;<br> deviceid:cardinal;<br> dwdatasize:integer;<br> hwavehdr:hglobal;<br> mylpwavehdrwavehdr;<br> wresult:double;<br> tt:longint;<br>begin<br><br> //open the given file for reading using buffered i/o /<br> iomm:=mmioopen('son1.wav',nil,MMIO_READ or MMIO_ALLOCBUF);<br><br> {locate a 'RIFF' chunk with a 'wave' form type,tomake sure it's a WAVE file}<br> // mmckinfoparent.fccType := mmioFOURCC('w','a','v','e');<br> mmiodescend(iomm,@mmckinfoparent,nil,MMIO_FINDRIFF);<br><br> {find the format chunk(form type 'fmt'),it's should be a subchunk of the 'RIFF' parent chunk}<br> // mmckinfosubchunk.ckid :=mmiofourcc('f','m','t','');<br> mmiodescend(iomm,@mmckinfosubchunk,@mmckinfoparent,MMIO_FINDCHUNK);<br><br> { get the size of the formt chunk,allocate and lock memory for }<br> dwfmtsize:=mmckinfosubchunk.cksize;<br><br> {read the format chunk}<br> tt:= mmioread(iomm,@pformat,dwfmtsize) ;<br> deviceid:=waveOutGetNumDevs;<br> if tt=-1 then<br> {make sure a waveform output device support this format}<br> waveoutgetdevcaps(deviceid,@caps,sizeof(caps)) ;<br> if waveoutopen(@mywaveout,deviceid,@pformat,0,0,WAVE_FORMAT_QUERY)=0 then<br> begin<br> showmessage('can not open');<br> end;<br><br> {ascend out of the format subchunk}<br> mmioascend(iomm,@mmckinfosubchunk,0);<br><br> {find the data subchunk}<br> // mmckinfosubchunk.ckid :=mmiofourcc('d','a','t','a');<br> mmiodescend(iomm,@mmckinfosubchunk,@mmckinfoparent,MMIO_FINDCHUNK);<br><br> {get the size of the data subchunk}<br> dwdatasize:=mmckinfosubchunk.cksize;<br> waveoutopen(@mywaveout,deviceid,@pformat,0,hinstance,CALLBACK_FUNCTION);<br><br> {allocate and lock memory for the header}<br> lpdata:=globalalloc(GMEM_MOVEABLE or GMEM_SHARE,sizeof(dwdatasize));<br><br> mmioread(iomm,@lpdata,dwdatasize);<br><br> hwavehdr:=Globalalloc(GMEM_MOVEable or GMEM_SHARE,sizeof(wavehdr) );<br> mylpwavehdr:=Globallock(hwavehdr) ;<br><br> mylpwavehdr^.lpData :=@lpdata;<br> mylpwavehdr^.dwBufferLength :=dwdatasize;<br> mylpwavehdr^.dwFlags :=0;<br> mylpwavehdr^.dwLoops :=0;<br> mylpwavehdr^.dwuser:=0;<br> waveoutprepareheader(mywaveout,mylpwavehdr,sizeof(wavehdr));<br><br> wresult:=waveoutwrite(mywaveout,mylpwavehdr,sizeof(wavehdr));<br> if wresult=0 then<br> showmessage('faild!');<br><br>end;<br><br>end.