<br> WTWaveOut=class(TObject)<br> private<br> { Private declarations }<br> hWaveOut:HWAVEOUT;<br> wfex:tWAVEFORMATEX;<br> isInited:Boolean;<br> public<br> { Public declarations }<br> procedure Play(buf:LPCTSTR;size:DWORD);<br> published<br> { published declarations }<br> property wFormatTag:Word read wfex.wFormatTag default 1;<br> property nChannels:Word read wfex.nChannels default 1;<br> property nSamplesPerSec:Cardinal read wfex.nSamplesPerSec default 8000;<br> property wBitsPerSample:Word read wfex.wBitsPerSample default 8;<br> property nAvgBytesPerSec:Cardinal read wfex.nAvgBytesPerSec default 0;<br> property nBlockAlign:Word read wfex.nBlockAlign default 0; <br> Constructor Create(channels,freq,bits:Int64;wFormat:Word;hWnd:HWND);<br> destructor Destroy;<br> end;<br><br>{WTWaveOut}<br><br>Constructor WTWaveOut.Create(channels,freq,bits:Int64;wFormat:Word;hWnd:HWND);<br>var<br> res:MMRESULT;<br>begin<br> isInited:=True;<br>// wfex.cbSize:=sizeof(tWAVEFORMATEX);<br> wfex.cbSize:=32;<br> wfex.wFormatTag := wFormat ;<br> wfex.nChannels := channels;<br> wfex.nSamplesPerSec := freq;<br> wfex.wBitsPerSample := bits;<br> wfex.nBlockAlign := wfex.nChannels * (wfex.wBitsPerSample div 8);<br> wfex.nAvgBytesPerSec := wfex.nSamplesPerSec * wfex.nBlockAlign;<br><br> res := waveOutOpen(@hWaveOut,<br> WAVE_MAPPER, @wfex, DWORD(hWnd), 0, CALLBACK_WINDOW);<br> if (res<>MMSYSERR_NOERROR) then<br> begin<br> isInited:=False;<br>// self.Free;<br>// self:=nil;<br> end;<br>end;<br><br>destructor WTWaveOut.Destroy;<br>begin<br> isInited:=False;<br> waveOutReset(hWaveOut);<br> waveOutClose(hWaveOut);<br> hWaveOut := 0;<br>end;<br><br>procedure WTWaveOut.Play(buf:LPCTSTR;size:DWORD);<br>var<br> pwh:PWaveHdr;<br>begin<br> if isInited then<br> begin<br> pwh:=GetMemory(sizeof(WAVEHDR));<br> pwh.dwFlags:=0;<br> pwh.dwBufferLength:=size;<br> pwh.lpData:=GetMemory(size);<br>// FillMemory(pwh.lpData,size,0);<br> CopyMemory(pwh.lpData,buf,size);<br> waveOutPrepareHeader(hWaveOut, pwh, sizeof(WAVEHDR));<br> waveOutWrite(hWaveOut, pwh, sizeof(WAVEHDR));<br> end;<br>end;<br>