类似于网络电话
使用了wavemix控件,自己找一下
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, NMUDP, ACMWaveOut, ACMWaveIn, ACMDialog,
ComCtrls, Mmsystem;
type
TForm1 = class(TForm)
ACMDialog1: TACMDialog;
ACMWaveIn1: TACMWaveIn;
ACMWaveOut1: TACMWaveOut;
NMUDP1: TNMUDP;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ACMWaveIn1Data(data: Pointer; size: Integer);
procedure NMUDP1DataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: string; Port: Integer);
procedure FormCreate(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
PlayPackets: integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
format: pointer;
begin
NMUDP1.Remotehost := edit1.text;
format := ACMDialog1.OpenDialog;
if format = nil then exit;
ACMWaveOut1.Open(format);
ACMWaveIn1.Open(format);
Button1.Enabled := false;
Button2.Enabled := true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ACMWaveIn1.Close;
ACMWaveOut1.Close;
Button1.Enabled := true;
Button2.Enabled := false;
end;
procedure TForm1.ACMWaveIn1Data(data: Pointer; size: Integer);
var
mdata: array[1..15000] of char;
k: integer;
//str: string;
begin
{str := 'send:';
for k := 1 to 10 do str := str + ' ' + inttostr(integer(pchar(dword(data) + k - 1)^));
str := 'send:' + inttostr(size);
memo1.lines.add(str);}
for k := 1 to size do mdata[k] := pchar(dword(data) + k - 1)^;
NMUDP1.SendBuffer(mdata, size);
end;
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: string; Port: Integer);
var
mdata: array[1..15000] of char;
data: Pchar;
// str: string;
// k: integer;
begin
NMUDP1.ReadBuffer(mdata, NumberBytes);
data := pchar(dword(@mdata));
// str:='recv:';
// for k:=1 to 10 do str:=str+' '+inttostr(integer(pchar(dword(data)+k-1)^));
// str:='recv:'+inttostr(NumberBytes);
// memo1.lines.add(str);
label1.caption := inttostr(PlayPackets);
inc(PlayPackets);
ACMWaveOut1.PlayBack(data, NumberBytes);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ACMWaveOut1.visible := false;
ACMWaveIn1.visible := false;
NMUDP1.ReportLevel := Status_Basic;
NMUDP1.LocalPort := 6668;
NMUDP1.RemotePort := 6668;
PlayPackets := 0;
label1.caption := inttostr(PlayPackets);
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
var
t, v: Longint;
begin
// if a=0 then Exit;
t := TrackBar1.Position;
v := (t shl 8) or (t shl 24);
waveOutSetVolume(0, v);
end;
end.