那位大侠帮我看看下面的程序 (100分)

  • 主题发起人 主题发起人 陈礼泉
  • 开始时间 开始时间

陈礼泉

Unregistered / Unconfirmed
GUEST, unregistred user!
程序到WaveOutWrite出错了 ???

procedure TForm1.Button2Click(Sender: TObject);
var
f : file
hBuffer : array[0..3] of THandle
Buffer : array[0..3] of lpstr
FileBUffer : array [0..8191] of char
i,ires : integer
hWaveOut : THandle
rWaveFormatEx : PWaveFormatEx
hWaveHdr : array [0..3] of THandle
rWaveHdr : array[0..3] of PWaveHdr
begin


for i := 0 to 3do

begin

hBuffer := GlobalAlloc(GMEM_MOVEABLE,8192);
Buffer := GlobalLock(hBuffer);
end;


if not Opendialog1.Execute then

Exit
AssignFile(f,Opendialog1.FileName);
reset(f,1);
Seek(f,500);
for i := 0 to 3do

begin

BlockRead(f,FileBuffer,8192,ires);
if ires <> 8192 then

begin

ShowMessage('read file error');
end;

strCopy(Buffer,@FileBuffer);
end;


rWaveFormatEx := AllocMem(sizeof(TWaveFormatEx));
rWaveFormatEx^.wFormatTag := WAVE_FORMAT_PCM
rWaveFormatEx^.nChannels := 1
rWaveFormatEx^.wBitsPerSample := 8
rWaveFormatEx^.cbSize := sizeof(TWaveFormatEx);
rWaveFormatEx^.nBlockAlign := 1
rWaveFormatEx^.nAvgBytesPerSec := 44100
rWaveFormatEx^.nSamplesPerSec := 44100
if WaveOutOpen(@hWaveOut,0,rWaveFormatEx,0,application.handle,0) = MMSYSERR_NOERROR then

begin

ShowMessage('Wave Out Open right');
end
else

begin

ShowMessage('Wave Out Open error');
end;


for i := 0 to 3do

begin

hWaveHdr := GlobalAlloc(GMEM_MOVEABLE or GMEM_ZEROINIT,sizeof(TWaveHdr));
rWaveHdr := GlobalLock(hWaveHdr);
end;


for i := 0 to 3do

begin

//rWaveHdr := AllocMem(sizeof(TWaveHdr));
rWaveHdr^.lpData := Buffer
rWaveHdr^.dwBufferLength := 8192
rWaveHdr^.dwBytesRecorded := 0
rWaveHdr^.dwUser := 0;
rWaveHdr^.dwFlags := WHDR_PREPARED
rWaveHdr^.dwLoops := 0
rWaveHdr^.lpNext := nil
rWaveHdr^.reserved := 0
if WaveOutPrepareHeader(hWaveOut,rWaveHdr,sizeof(TWaveHdr)) <> MMSYSERR_NOERROR then

ShowMessage('Wave Out PrepareHeader error');
end;


for i := 0 to 3do

begin

if WaveOutWrite(hWaveOut,rWaveHdr,sizeof(TWaveHDR)) <> MMSYSERR_NOERROR then

begin

ShowMessage('Wave Out Write Error ');

// ShowMessage(IntToStr(GetLastError()));
end;

end;


ShowMessage('Play End ');

for i := 0 to 3do

begin

GlobalUnLock(hBuffer);
GlobalFree(hBuffer);
GlobalUnLock(hWaveHdr);
GlobalFree(hWaveHdr);
end;

end;

 
这么长,功能这么高,100分太少,加200分,给我写EMAIL!
cxx91-94@263.net
 
再踢一脚
 
干吗的东东
 
编译出错,还是运行出错?? tell me
 
编译当然没有问题了,就是跟踪到WaveOutWrite是,这个函数总是调用不成功
 
比不能循环调用这个函数,这样第一次送进去的数据还没来得及播放你有送了第二批数据,当然会出错。
 
感觉你程序里的for循环语句写的太繁琐了。。。
 
我也试过,去掉3个缓冲区,只有一个时,也是同样的不成功,
To:卷兄:
因为是一个简单的例子,没有采用多线程,所以就多用了几个For
 
for i := 0 to 3do

begin

//rWaveHdr := AllocMem(sizeof(TWaveHdr));
rWaveHdr^.lpData := Buffer
rWaveHdr^.dwBufferLength := 8192
rWaveHdr^.dwBytesRecorded := 0
rWaveHdr^.dwUser := 0;
rWaveHdr^.dwFlags := WHDR_PREPARED
rWaveHdr^.dwLoops := 0
rWaveHdr^.lpNext := nil
rWaveHdr^.reserved := 0
if WaveOutPrepareHeader(hWaveOut,rWaveHdr,sizeof(TWaveHdr)) <> MMSYSERR_NOERROR then

ShowMessage('Wave Out PrepareHeader error');
end;


看看这个有没有错,我总觉得不对劲,你试试看。
 
TO XieHa:
WaveOutPrepareHeader调用已经没有问题,开始的时候,我是AllocMem给WaveHdr,
后来改成了GlobalAlloc,在堆栈中分配空间
 
这个,不懂!
 
[:)]
还没有解决么?
 
后退
顶部