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;
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;