陈
陈礼泉
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;
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;