mmtool如何实现语音的网络传输?(100分)

  • 主题发起人 主题发起人 ynhhr
  • 开始时间 开始时间
Y

ynhhr

Unregistered / Unconfirmed
GUEST, unregistred user!
我用以下代码实现在局域网内传输从麦克接收的声音,但执行到MMWaveOut1.Start;时报错“unable start device”,这如何是好?

procedure TForm1.btnFormatClick(Sender: TObject);
begin

if MMACM1.ACMPresent then

begin

if MMACM1.ChooseFormat(MMWaveIn1.PWaveFormat,'Select Format') then

begin

MMWaveOut1.PWaveFormat := MMACM1.PWaveFormat;
MMWaveIn1.PWaveFormat := MMACM1.PWaveFormat;
BufferCounter := 0;
MMWaveIn1.Start;
end;

end;

end;


procedure TForm1.MMWaveIn1BufferReady(Sender: TObject;
lpWaveHdr: PWaveHdr);
begin

INC(BufferCounter);
NMUDP1.SendBuffer(lpWaveHdr^.lpdata^,lpWaveHdr^.dwBytesRecorded);
MMRingBuffer1.PutBuffer(lpWaveHdr^.lpData,lpWaveHdr^.dwBytesRecorded,BufferCounter,0);
end;


procedure TForm1.btnPlayClick(Sender: TObject);
begin

try
if (wosPause in MMWaveOut1.State)and (wosPlay in MMWaveOut1.State) then

MMWaveOut1.Restart
else
if not (wosPlay in MMWaveOut1.State) then

begin

IntReceive := 0;
MMWaveOut1.Start;
end;


except
raise
end;

end;


procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer;
FromIP: String;
Port: Integer);
var lpWaveHdr: PWaveHdr;
PCharBuf : Pchar;
begin

inc(BufferCounter);
//把接收到的数据写入MMRingBuffer2中以备MMWaveOut1播放用
lpWaveHdr := AllocMem(sizeof(PWaveHdr));
try
PCharBuf := allocMem(10000);
try
lpWaveHdr.lpData := PCharBuf;
NMUDP1.ReadBuffer(lpWaveHdr.lpData^,NumberBytes);

MMRingBuffer2.PutBuffer(lpWaveHdr.lpData,NumberBytes,BufferCounter,0);
finally
FreeMem(PCharBuf);
end;

finally
FreeMem(lpWaveHdr);
end;

end;


procedure TForm1.MMWaveOut1BufferLoad(Sender: TObject;
lpWaveHdr: PWaveHdr;
var MoreBuffers: Boolean);
var
{$IFDEF WIN32}
Dummy: DWORD;
{$else
}
Dummy: Longint;
{$ENDIF}
begin

lpWaveHdr^.dwBytesRecorded := lpWaveHdr^.dwBufferLength;
MMRingBuffer2.GetBuffer(lpWaveHdr^.lpData,lpWaveHdr^.dwBytesRecorded,lpWaveHdr^.dwUser,Dummy);
MoreBuffers := not MMRingBuffer2.Empty;
end;



 
用acm不是很好吗! 我没用过mmtools,不过好像他在处理声音方面比acm强!
:) 这年头,能做出老板的要求就够了。。。。。。
 
ACM我会,但播放WAVE文件还得调用api,很麻烦。
 
看来只有靠自己了! :(
这里的高手都成缩头乌龟了。
 
老大,调用wav就一句话你也怕麻烦啊!!¥!·#¥·#¥:)
 
后退
顶部