⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audiodx.pas

📁 絮语2007视频聊天软件源程序.仅供参考
💻 PAS
字号:
unit audiodx;

interface

uses
  Windows, Messages,SysUtils,Classes,extctrls,mmsystem,
  ACMOut, ACMConvertor, ACMIn,constunt;
  
type
  Taudio=class
      acm:TACMConvertor;
      constructor Create;
      destructor  Destroy;override;
    private
      hthread :thandle; Threadid:dword;
      wavebuffer:integer;
      acmin:TACMIn;
      acmlist:tstringlist;
      function openwavedevice:boolean;
      procedure closewavedevice;
      procedure ACMInBufferFull(Sender: TObject; Data: Pointer;Size: Integer);
    public
      avdata:string;
      procedure playwave;overload;
      procedure playwave(datastr:string);overload;
  end;
  
implementation
uses shareunit;

//------------------------------------------------------------------------------
// 播放提示声音
//------------------------------------------------------------------------------
procedure playerwave;stdcall;
begin
if not playsound_pc then
 sndPlaySound(pchar(playwave_code),SND_NODEFAULT)
 else playpc(playsound_code);
end;

//------------------------------------------------------------------------------
// 播放提示声音
//------------------------------------------------------------------------------
procedure Taudio.playwave;
begin
 hthread:=createthread(nil,0,@playerwave,nil,0,threadid);
end;

//------------------------------------------------------------------------------
// 播放音频
//------------------------------------------------------------------------------
procedure Taudio.playwave(datastr:string);
var i:integer;
begin
if acmlist.Count>0 then
for i:=1 to wavebuffer do
with tacmout(acmlist.Objects[i-1]) do
  if (not playing)and active then
    begin
    Play(datastr[1],length(datastr));
    break;
    end;
end;
//------------------------------------------------------------------------------
//  初始化 audio
//------------------------------------------------------------------------------
function Taudio.openwavedevice:boolean;
var i:integer; tmp:Tacmout;
begin
 try
 acm:=TACMConvertor.Create(nil);
 acm.openacmformat(extractfilepath(application_name)+'dat\');
 acmin:=Tacmin.Create(nil);
 acmin.BufferSize:=1024;
 acmin.OnBufferFull:=ACMInBufferFull;
 acmin.Open(acm.Formatin,mic_index);
  for i:=1 to wavebuffer do
    begin
    tmp:=Tacmout.Create(nil);
    tmp.Open(acm.Formatout,audio_index);
    acmlist.AddObject(inttostr(i),tmp);
    end;
 result:=acmin.Active;
 except
  result:=false;
  logmemo.add(timetostr(time)+': open wave I/O device error.');
 end;
end;

//------------------------------------------------------------------------------
//  关闭 audio
//------------------------------------------------------------------------------
procedure Taudio.closewavedevice;
var i:integer;
begin
acmin.Close;
if acmlist.Count>0 then
for i:=1 to wavebuffer do
  begin
  tacmout(acmlist.Objects[i-1]).close;
  tacmout(acmlist.Objects[i-1]).free;
  end;
end;

//------------------------------------------------------------------------------
// 发送声音
//------------------------------------------------------------------------------
procedure Taudio.ACMInBufferFull(Sender: TObject; Data: Pointer; Size: Integer);
var datasize:integer;
begin
datasize:=size;
setlength(avdata,datasize);
fillchar(avdata[1],datasize,#0);
with tmemorystream.Create do
  try
  writebuffer(data^,datasize);
  Seek(0,soFromBeginning);
  readbuffer(avdata[1],datasize);
  finally
  free;
  end;
sendmsgtohwnd(xy_media_audio);
end;

//------------------------------------------------------------------------------
// 构建 audio
//------------------------------------------------------------------------------
constructor Taudio.Create;
begin
  wavebuffer:=16;
  acmlist:=Tstringlist.Create;
  audioisok:=openwavedevice;
end;

//------------------------------------------------------------------------------
// 释放 audio
//------------------------------------------------------------------------------
destructor Taudio.Destroy;
begin
  if audioisok then closewavedevice;
  acm.saveacmformat(extractfilepath(application_name)+'dat\');
  if assigned(acmin) then freeandnil(acmin);
  if assigned(acm) then freeandnil(acm);
  freeandnil(acmlist);
  inherited Destroy;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -