为什么我的语音程序在Win2000下无法使用?(100分)

  • 主题发起人 主题发起人 jingtao
  • 开始时间 开始时间
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(format:PWaveFormatEx);
var
waveformat:PWaveFormatEx;
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(format:PWaveFormatEx);
var
WaveFormat:PWaveFormatEx;
Header:PWaveHdr;
memBlock:PChar;
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下运行正常.
 
有没有留意 WaveOutOpen 和 WaveInOpen 的帮助信息,是否有注明某些东西在 98 和 2K 下有所不同?
这种情况(在 98 和 2K 下有所不同)是比较常见的。
 
直接用底层API和MSACM接口来写的啊
没有帮助,因为当时WIN2000还没有出现啊:)
 
这种问题一般解决方法是:
避免建立临近的 FREE BLOCK .
 
我估计出错是因为系统不支持该语音格式
但是PCM是很常用的格式啊
YB_unique:
具体怎么解决?
 
问题已经解决
给分.
 
请问jingtao大虾,你是如何解决的?
 

Similar threads

后退
顶部