J
jingtao
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var
Format: PWAVEFORMATEX;
FMaxFmtSize: DWORD;
begin
if acmMetrics(nil, ACM_METRIC_MAX_SIZE_FORMAT, FMaxFmtSize) <> 0 then
begin
showmessage('Error getting the max compression format size.');
Exit;
end;
GetMem(Format, FMaxFmtSize);
if Format = nil then
begin
showmessage('Error allocating local memory for WaveFormatEx structure.');
Exit;
end;
// initialize the format to standard PCM...
FillChar(Format^, FMaxFmtSize, 0);
Format.wFormatTag :=WAVE_FORMAT_PCM;
Format.nChannels := 1;
Format.nSamplesPerSec := 11025;
Format.nAvgBytesPerSec := 11025;
Format.nBlockAlign := 1;
Format.wBitsPerSample := 8;
Format.cbSize := 0;
SoundOut1.Open(format);
SoundIN1.Open(format);
end;
其中OPEN代码如下:
procedure TACMWaveOut.Open(formatWaveFormatEx);
var
waveformatWaveFormatEx;
maxsizeformat,i:integer;
begin
if (format<>nil) and (HWaveOut1=nil) then
begin
acmMetrics(0, ACM_METRIC_MAX_SIZE_FORMAT,MaxSizeFormat);
getmem(WaveFormat, MaxSizeFormat);
move(format^,waveformat^,maxsizeformat);
HWaveOut1:=new(PHWaveOut);
//create playing handle with waveformatex structure
i:=WaveOutOpen(HWaveOut1,0,waveformat,handle,0,CALLBACK_WINDOW or WAVE_MAPPED);
if i<>0 then
begin
showmessage('Problem creating playing handle' + inttostr(i));
exit;
end;
closed:=false;
end;
end;
----------------
procedure TACMWaveIn.Open(formatWaveFormatEx);
var
WaveFormatWaveFormatEx;
HeaderWaveHdr;
memBlockChar;
i,j,maxsizeformat:integer;
begin
if (hwavein1=nil) and (format<>nil) then
begin
acmMetrics(0, ACM_METRIC_MAX_SIZE_FORMAT,MaxSizeFormat);
getmem(WaveFormat, MaxSizeFormat);
move(format^,waveformat^,maxsizeformat);
sizebuf:=format.nAvgBytesPerSec;
HWaveIn1:=new(PHWaveIn);
// create record handle with waveformatex structure
i:=WaveInOpen(HWaveIn1,0,waveformat,handle,0,CALLBACK_WINDOW or WAVE_MAPPED);
if i<>0 then
begin
showmessage('Problem creating record handle' + inttostr(i));
exit;
end;
closed:=false;
{need to add some buffers to the recording queue}
{in case the messages that blocks have been recorded}
{are delayed}
for j:= 1 to 3do
begin
{make a new block}
Header:=new(PWaveHdr);
memBlock:=new(PChar);
getmem(memblock,sizebuf);
//allocate memory
Header:=new(PwaveHdr);
header.lpdata:=memBlock;
header.dwbufferlength:=sizebuf;
header.dwbytesrecorded:=0;
header.dwUser:=0;
header.dwflags:=0;
header.dwloops:=0;
{prepare the new block}
i:=waveInPrepareHeader(HWaveIn1^,Header,sizeof(TWavehdr));
if i<>0 then
showmessage('In Prepare error');
{add it to the buffer}
i:=waveInAddBuffer(HWaveIn1^,Header,sizeof(TWaveHdr));
if i<>0 then
showmessage('Add buffer error');
end;
{of loop}
{finally start recording}
i:=waveInStart(HwaveIn1^);
if i<>0 then
showmessage('Start error');
end;
end;
-----------------------------------------------------------
出错信息:
Problem creating record handle32
Problem creating playing handle32
注意:该程序在Win98下运行正常.
var
Format: PWAVEFORMATEX;
FMaxFmtSize: DWORD;
begin
if acmMetrics(nil, ACM_METRIC_MAX_SIZE_FORMAT, FMaxFmtSize) <> 0 then
begin
showmessage('Error getting the max compression format size.');
Exit;
end;
GetMem(Format, FMaxFmtSize);
if Format = nil then
begin
showmessage('Error allocating local memory for WaveFormatEx structure.');
Exit;
end;
// initialize the format to standard PCM...
FillChar(Format^, FMaxFmtSize, 0);
Format.wFormatTag :=WAVE_FORMAT_PCM;
Format.nChannels := 1;
Format.nSamplesPerSec := 11025;
Format.nAvgBytesPerSec := 11025;
Format.nBlockAlign := 1;
Format.wBitsPerSample := 8;
Format.cbSize := 0;
SoundOut1.Open(format);
SoundIN1.Open(format);
end;
其中OPEN代码如下:
procedure TACMWaveOut.Open(formatWaveFormatEx);
var
waveformatWaveFormatEx;
maxsizeformat,i:integer;
begin
if (format<>nil) and (HWaveOut1=nil) then
begin
acmMetrics(0, ACM_METRIC_MAX_SIZE_FORMAT,MaxSizeFormat);
getmem(WaveFormat, MaxSizeFormat);
move(format^,waveformat^,maxsizeformat);
HWaveOut1:=new(PHWaveOut);
//create playing handle with waveformatex structure
i:=WaveOutOpen(HWaveOut1,0,waveformat,handle,0,CALLBACK_WINDOW or WAVE_MAPPED);
if i<>0 then
begin
showmessage('Problem creating playing handle' + inttostr(i));
exit;
end;
closed:=false;
end;
end;
----------------
procedure TACMWaveIn.Open(formatWaveFormatEx);
var
WaveFormatWaveFormatEx;
HeaderWaveHdr;
memBlockChar;
i,j,maxsizeformat:integer;
begin
if (hwavein1=nil) and (format<>nil) then
begin
acmMetrics(0, ACM_METRIC_MAX_SIZE_FORMAT,MaxSizeFormat);
getmem(WaveFormat, MaxSizeFormat);
move(format^,waveformat^,maxsizeformat);
sizebuf:=format.nAvgBytesPerSec;
HWaveIn1:=new(PHWaveIn);
// create record handle with waveformatex structure
i:=WaveInOpen(HWaveIn1,0,waveformat,handle,0,CALLBACK_WINDOW or WAVE_MAPPED);
if i<>0 then
begin
showmessage('Problem creating record handle' + inttostr(i));
exit;
end;
closed:=false;
{need to add some buffers to the recording queue}
{in case the messages that blocks have been recorded}
{are delayed}
for j:= 1 to 3do
begin
{make a new block}
Header:=new(PWaveHdr);
memBlock:=new(PChar);
getmem(memblock,sizebuf);
//allocate memory
Header:=new(PwaveHdr);
header.lpdata:=memBlock;
header.dwbufferlength:=sizebuf;
header.dwbytesrecorded:=0;
header.dwUser:=0;
header.dwflags:=0;
header.dwloops:=0;
{prepare the new block}
i:=waveInPrepareHeader(HWaveIn1^,Header,sizeof(TWavehdr));
if i<>0 then
showmessage('In Prepare error');
{add it to the buffer}
i:=waveInAddBuffer(HWaveIn1^,Header,sizeof(TWaveHdr));
if i<>0 then
showmessage('Add buffer error');
end;
{of loop}
{finally start recording}
i:=waveInStart(HwaveIn1^);
if i<>0 then
showmessage('Start error');
end;
end;
-----------------------------------------------------------
出错信息:
Problem creating record handle32
Problem creating playing handle32
注意:该程序在Win98下运行正常.