Pipi您说的方法已经编译通过,但程序还不正常,请您帮我看一下好么?
这个程序是语音采集、压缩,通过NMUDP发至本机,再解开放音,用了ACMIN、ACMOUT、
ACMConvertor三个控件。现在的情况是运行后听到的是一片噪音,我试过不通过NMUDP发送
直接播放正常。程序如下:
unit Demo2Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ACMIn, ACMOut, ACMConvertor, StdCtrls, NMUDP;
type
TfmMain = class(TForm)
ACMC: TACMConvertor;
ACMI: TACMIn;
Label1: TLabel;
NMUDP1: TNMUDP;
ACMC1: TACMConvertor;
ACMO1: TACMOut;
procedure FormCreate(Sender: TObject);
procedure ACMIBufferFull(Sender: TObject
Data: Pointer;
Size: Integer);
procedure NMUDP1DataReceived(Sender: TComponent
NumberBytes: Integer;
FromIP: String
Port: Integer);
private
{ Private declarations }
procedure TransmitData(Buffer : Pointer
Size : Integer);
public
{ Public declarations }
end;
var
fmMain: TfmMain;
implementation
{$R *.DFM}
procedure TfmMain.FormCreate(Sender: TObject);
begin
ACMC.InputBufferSize :=1024;
ACMI.BufferSize := ACMC.InputBufferSize;
ACMC.Active := True;
ACMI.Open(ACMC.FormatIn);
ACMO1.NumBuffers := 0;
ACMC1.Active :=true;
ACMO1.Open(ACMC1.Formatin);
NMUDP1.RemoteHost :='127.0.0.1';
NMUDP1.RemotePort :=7388;
NMUDP1.LocalPort :=7388;
end;
procedure TfmMain.ACMIBufferFull(Sender: TObject
Data: Pointer;
Size: Integer);
var
NewSize : Integer;
begin
Move(Data^,ACMC.BufferIn^,Size);
NewSize := ACMC.Convert;
TransmitData(ACMC.BufferOut,NewSize);
end;
procedure TfmMain.TransmitData(Buffer : Pointer
Size: Integer);
var
SA
char;
begin
getmem(sa,size);
NMUDP1.SendBuffer(PChar(sa)^,size);
freemem(sa,size);
end;
procedure TfmMain.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer
FromIP: String
Port: Integer);
var
SB:array[0..65535] of char;
begin
NMUDP1.ReadBuffer(sb,numberbytes);
ACMO1.Play(sb,numberbytes);
end;
end.