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

📄 u_common_audioconfig.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:

(*
	----------------------------------------------

	  u_common_audioConfig.pas
	  Voice Communicator components 2.5 Pro - audio configuration form

	----------------------------------------------
	  This source code cannot be used without
	  proper permission granted to you as a private
	  person or an entity by the Lake of Soft, Ltd

	  Visit http://lakeofsoft.com/ for details.

	  Copyright (c) 2002, 2007 Lake of Soft, Ltd
		     All rights reserved
	----------------------------------------------

	  created by:
		Lake, 19 Feb 2003

	  modified by:
		Lake, Feb-Oct 2003
		Lake, May-Oct 2005
		Lake, Apr 2007

	----------------------------------------------
*)

{$I unaDef.inc}

unit
  u_common_audioConfig;

interface

uses
  Windows, unaTypes, MMSystem, unaClasses, unaMsAcmClasses, unaMsMixer, unaVcIDE,
  Forms, StdCtrls, Controls, ExtCtrls, Classes, Dialogs;


const
  //----
  //
  c_strDefSection	= 'waveAudio';


type
  //
  // --  --
  //
  pdriverDesc = ^tdriverDesc;
  tdriverDesc = packed record
    //
    r_mode: unaAcmCodecDriverMode;
    r_library: wideString;
    r_formatIndex: int32;
  end;

  //
  // --  --
  //
  pinOutDriverDesc = ^tinOutDriverDesc;
  tinOutDriverDesc = packed record
    //
    r_in: tdriverDesc;
    r_out: tdriverDesc;
  end;

  //
  // --  --
  //
  Tc_form_common_audioConfig = class(TForm)
    c_label_inDevice: TLabel;
    c_label_inTitle: TLabel;
    c_bevel_top: TBevel;
    c_comboBox_waveIn: TComboBox;
    c_label_inFormat: TLabel;
    c_label_outTitle: TLabel;
    c_bevel_middle: TBevel;
    c_button_OK: TButton;
    c_bevel_bottom: TBevel;
    c_button_cancel: TButton;
    c_edit_inFormat: TEdit;
    c_button_inFormatBrowse: TButton;
    c_label_outDevice: TLabel;
    c_comboBox_waveOut: TComboBox;
    c_label_outFormat: TLabel;
    c_edit_outFormat: TEdit;
    c_button_outFormatBrowse: TButton;
    c_button_configAudio: TButton;
    c_button_inVolControl: TButton;
    c_button_outVolControl: TButton;
    c_comboBox_inCodecMode: TComboBox;
    c_label_inDriverMode: TLabel;
    c_comboBox_outCodecMode: TComboBox;
    c_label_outDriverMode: TLabel;
    c_comboBox_inCodecTag: TComboBox;
    c_comboBox_outCodecTag: TComboBox;
    c_openDialog_lib: TOpenDialog;
    c_label_inCodecFT: TLabel;
    c_label_outCodecFT: TLabel;
    c_cb_enableSD: TCheckBox;
    c_label_sdMode: TLabel;
    //
    procedure formCreate(sender: tObject);
    procedure formDestroy(sender: tObject);
    //
    procedure c_button_inFormatBrowseClick(sender: tObject);
    procedure c_button_outFormatBrowseClick(sender: tObject);
    procedure c_button_configAudioClick(sender: tObject);
    procedure c_button_inVolControlClick(sender: tObject);
    procedure c_button_outVolControlClick(sender: tObject);
    procedure c_comboBox_inCodecModeChange(Sender: TObject);
    procedure c_comboBox_outCodecModeChange(Sender: TObject);
    procedure c_comboBox_waveInChange(Sender: TObject);
    procedure c_comboBox_waveOutChange(Sender: TObject);
    procedure c_comboBox_inCodecTagChange(Sender: TObject);
    procedure c_comboBox_outCodecTagChange(Sender: TObject);
    procedure c_cb_enableSDClick(Sender: TObject);
  private
    { Private declarations }
    f_config: unaIniAbstractStorage;
    f_section: string;
    f_enumComplete: bool;
    //
    f_includeMapper: bool;
    f_syncInOutFormat: bool;
    f_allowModeChange: bool;
    //
    f_waveInSDMode: unaWaveInSDMehtods;
    f_waveInId: int;
    f_waveOutId: int;
    f_inOutDriver: tinOutDriverDesc;
    //
    f_formatIn: pWAVEFORMATEX;
    f_formatOut: pWAVEFORMATEX;
    f_formatIn_nonPCMOK: bool;
    f_formatOut_nonPCMOK: bool;
    //
    f_maxFormatSize: unsigned;
    //
    f_mixer: unaMsMixerSystem;
    f_enumFlags: int;
    f_enumFormat: PWAVEFORMATEX;
    //
    f_defFTIn: int;
    f_defFTOut: int;
    //
    function doLoadFormat(var format: pWAVEFORMATEX; const key: string; defFormatTag: int): int;
    function doFormatChoose(var format: pWAVEFORMATEX; var title: string): int;
    procedure loadConfig();
    procedure saveConfig();
    //
    function do_load_Config(doLoad: bool; waveIn: TunavclWaveInDevice; waveOut: TunavclWaveOutDevice; codecIn, codecOut: TunavclWaveCodecDevice; config: unaIniAbstractStorage; const section: string): HRESULT; overload;
    function do_config(doShow: bool; var waveInId, waveOutId: int; var formatIn, formatOut: pWAVEFORMATEX; var inOutDriver: tinOutDriverDesc; config: unaIniAbstractStorage; const section: string; var sdMode: unaWaveInSDMehtods): HRESULT; overload;
    function do_config(doShow: bool): HRESULT; overload;
    //
    function doConfig(config: unaIniAbstractStorage; const section: string): HRESULT; overload;
    function doLoadConfig(config: unaIniAbstractStorage; const section: string): HRESULT; overload;
    //
    procedure enumWaveDevices();
    procedure showCodecTags(inCodec: bool);
  public
    { Public declarations }
    //
    {DP:METHOD
      WARNING! If you allocate formatIn or formatOut manually, make sure they are large enough to store any ACM format.
	       You can assign nil otherwise.
    }
    function doConfig(var waveInId, waveOutId: int; var formatIn, formatOut: pWAVEFORMATEX; var inOutDriver: tinOutDriverDesc; var sdMode: unaWaveInSDMehtods; config: unaIniAbstractStorage; const section: string = c_strDefSection): HRESULT; overload;
    //
    function doConfig(waveIn: TunavclWaveInDevice; waveOut: TunavclWaveOutDevice; codecIn, codecOut: TunavclWaveCodecDevice; config: unaIniAbstractStorage; const section: string = c_strDefSection): HRESULT; overload;
    //
    function doLoadConfig(var waveInId, waveOutId: int; var formatIn, formatOut: pWAVEFORMATEX; var inOutDriver: tinOutDriverDesc; var sdMode: unaWaveInSDMehtods; config: unaIniAbstractStorage; const section: string = c_strDefSection): HRESULT; overload;
    //
    function doLoadConfig(waveIn: TunavclWaveInDevice; waveOut: TunavclWaveOutDevice; codecIn, codecOut: TunavclWaveCodecDevice; config: unaIniAbstractStorage; const section: string = c_strDefSection): HRESULT; overload;
    //
    procedure setupUI(syncInOutFormat: bool; includeMapper: bool = true; allowModeChange: bool = true);
    //
    {DP:METHOD
	Reallocate and initializate enumFormat properly if enumFlags <> 0 as needed.
    }
    property enumFlags: int read f_enumFlags write f_enumFlags;
    property enumFormat: PWAVEFORMATEX read f_enumFormat write f_enumFormat;
  end;


var
  c_form_common_audioConfig: Tc_form_common_audioConfig;


implementation


{$R *.dfm}

uses
  unaMsAcmAPI, unaOpenH323PluginAPI, unaUtils, unaVCIDEutils,
  Math;


// --  --
function driverMode2index(mode: unaAcmCodecDriverMode): int;
begin
  case (mode) of

     unacdm_acm:
       result := 0;

     unacdm_openH323plugin:
       result := 1;

     else
       result := -1;

  end;
end;

// --  --
function index2driverMode(index: int): unaAcmCodecDriverMode;
begin
  case (index) of

    0: result := unacdm_acm;

    1: result := unacdm_openH323plugin;

    else
      result := unacdm_internal;

  end;
end;


{ Tc_form_common_audioConfig }

// --  --
procedure Tc_form_common_audioConfig.formCreate(sender: tObject);
begin
  f_maxFormatSize := getMaxWaveFormatSize();
  //
  f_mixer := unaMsMixerSystem.create(false);
  //
  f_enumComplete := false;
  //
  enumFlags := 0;
  f_enumFormat := malloc(sizeOf(f_enumFormat^));
  fillChar(f_enumFormat^, sizeOf(f_enumFormat^), #0);
end;

// --  --
procedure Tc_form_common_audioConfig.formDestroy(sender: tObject);
begin
  mrealloc(f_enumFormat);
  freeAndNil(f_mixer);
end;

// --  --
function Tc_form_common_audioConfig.do_config(doShow: bool): HRESULT;
var
  ok: bool;
begin
  if (0 = f_defFTIn) then begin
    //
    if (nil <> f_formatIn) then
      f_defFTIn := f_formatIn.wFormatTag
    else
      f_defFTIn := WAVE_FORMAT_PCM;
  end;
  //
  if (0 = f_defFTOut) then begin
    //
    if (nil <> f_formatOut) then
      f_defFTOut := f_formatOut.wFormatTag
    else
      f_defFTOut := WAVE_FORMAT_PCM;
  end;
  //
  loadConfig();
  //
  if (doShow) then
    ok := (mrOK = showModal())
  else
    ok := true;
  //
  if (ok and doShow) then
    saveConfig();
  //
  if (ok) then
    result := S_OK
  else
    result := -1;
end;

// --  --
function Tc_form_common_audioConfig.do_config(doShow: bool; var waveInId, waveOutId: int; var formatIn, formatOut: pWAVEFORMATEX; var inOutDriver: tinOutDriverDesc; config: unaIniAbstractStorage; const section: string; var sdMode: unaWaveInSDMehtods): HRESULT;
begin
  f_config := config;
  f_section := section;
  //
  f_waveInId  := waveInId;
  f_waveInSDMode := sdMode;
  f_waveOutId := waveOutId;
  f_formatIn  := formatIn;
  //
  if (not f_syncInOutFormat) then
    f_formatOut := formatOut;
  //
  f_inOutDriver := inOutDriver;
  //
  result := do_config(doShow);
  //
  if (Succeeded(result)) then begin
    //
    waveInId  := f_waveInId;
    waveOutId := f_waveOutId;
    sdMode := f_waveInSDMode;
    //
    formatIn  := f_formatIn;
    if (not f_syncInOutFormat) then
      formatOut := f_formatOut;
    //
    inOutDriver := f_inOutDriver;
  end;
end;

// --  --
function Tc_form_common_audioConfig.do_load_Config(doLoad: bool; waveIn: TunavclWaveInDevice; waveOut: TunavclWaveOutDevice; codecIn, codecOut: TunavclWaveCodecDevice; config: unaIniAbstractStorage; const section: string): HRESULT;
begin
  if (nil <> waveIn) then begin
    //
    f_waveInId := waveIn.deviceId;
    f_waveInSDMode := waveIn.silenceDetectionMode;
  end
  else begin
    //
    f_waveInId := -1;
    f_waveInSDMode := unasdm_none;
  end;
  //
  if (nil <> waveOut) then
    f_waveOutId := waveOut.deviceId
  else
    f_waveOutId := -1;
  //
  if (0 = f_defFTIn) then begin
    //
    if (nil <> codecIn) then
      f_defFTIn := codecIn.formatTag
    else
      f_defFTIn := WAVE_FORMAT_PCM;
  end;
  //
  if (0 = f_defFTOut) then begin
    //
    if (nil <> codecOut) then
      f_defFTOut := codecOut.formatTag
    else
      f_defFTOut := WAVE_FORMAT_PCM;
  end;
  //
  f_formatIn := nil;
  f_formatOut := nil;
  //
  if (nil <> codecIn) then begin
    //
    f_inOutDriver.r_in.r_mode := codecIn.driverMode;
    f_inOutDriver.r_in.r_library := codecIn.driverLibrary;
    f_inOutDriver.r_in.r_formatIndex := int(codecIn.formatTag);
  end;
  //
  if (nil <> codecOut) then begin
    //
    f_inOutDriver.r_out.r_mode := codecOut.driverMode;
    f_inOutDriver.r_out.r_library := codecOut.driverLibrary;
    f_inOutDriver.r_out.r_formatIndex := int(codecOut.formatTag);
  end;
  //
  if (doLoad) then
    result := doLoadConfig(config, section)
  else
    result := doConfig(config, section);
  //
  if (Succeeded(result)) then begin
    //
    if (nil <> waveIn) then begin
      //
      waveIn.deviceId := f_waveInId;
      waveIn.silenceDetectionMode := f_waveInSDMode;
    end;
    //
    if (nil <> waveOut) then
      waveOut.deviceId := f_waveOutId;
    //
    if ((nil <> f_formatIn) and (nil <> codecIn)) then begin
      //
      case (f_inOutDriver.r_in.r_mode) of

	unacdm_acm: begin
	  //
	  codecIn.driverMode := f_inOutDriver.r_in.r_mode;
	  //
	  if (f_formatIn_nonPCMOK) then
	    codecIn.setNonPCMFormat(f_formatIn^)
	  else begin
	    //
	    // 11 APR 2007: bug, thanks to dayde for pointing it out
	    //
	    f_formatIn.wFormatTag := WAVE_FORMAT_PCM;
	    codecIn.formatTag := f_formatIn.wFormatTag;
	    codecIn.pcmFormat := f_formatIn;
	  end;
	end;

	unacdm_openH323plugin: begin
	  //
	  // in this order: 1) mode; 2) lib; 3) tag
	  codecIn.driverMode := f_inOutDriver.r_in.r_mode;
	  codecIn.driverLibrary := f_inOutDriver.r_in.r_library;
	  codecIn.formatTag := f_inOutDriver.r_in.r_formatIndex;
	end;

      end;	// case
      //
      if (nil <> waveIn) then
	waveIn.pcmFormat := codecIn.pcmFormat;
    end
    else
      if ((nil <> waveIn) and (nil <> f_formatIn)) then
	waveIn.pcmFormat := f_formatIn;
    //
    mrealloc(f_formatIn);
    //
    if ((nil <> f_formatOut) and (nil <> codecOut)) then begin
      //
      case (f_inOutDriver.r_out.r_mode) of

	unacdm_acm: begin
	  //
	  codecIn.driverMode := f_inOutDriver.r_out.r_mode;
	  //
	  if (f_formatOut_nonPCMOK) then
	    codecOut.setNonPCMFormat(f_formatOut^)
	  else begin
	    //
	    codecOut.formatTag := f_formatOut.wFormatTag;
	    f_formatOut.wFormatTag := WAVE_FORMAT_PCM;
	    codecOut.pcmFormat := f_formatOut;
	  end;
	end;

	unacdm_openH323plugin: begin
	  //
	  // in this order: 1) mode; 2) lib; 3) tag
	  codecOut.driverMode := f_inOutDriver.r_out.r_mode;
	  codecOut.driverLibrary := f_inOutDriver.r_out.r_library;
	  codecOut.formatTag := f_inOutDriver.r_out.r_formatIndex;
	end;

      end;	// case () ...
      //
      if (nil <> waveOut) then
	waveOut.pcmFormat := codecOut.pcmFormat;
    end
    else
      if ((nil <> waveOut) and (nil <> f_formatOut)) then
	waveOut.pcmFormat := f_formatOut;
    //
    mrealloc(f_formatOut);
  end;
end;

// --  --
function Tc_form_common_audioConfig.doConfig(config: unaIniAbstractStorage; const section: string): HRESULT;
begin
  // FT OK
  f_config := config;
  f_section := section;
  //
  result := do_config(true);
  //
  f_defFTIn := 0;
  f_defFTOut := 0;
end;

// --  --
function Tc_form_common_audioConfig.doConfig(var waveInId, waveOutId: int; var formatIn, formatOut: pWAVEFORMATEX; var inOutDriver: tinOutDriverDesc; var sdMode: unaWaveInSDMehtods; config: unaIniAbstractStorage; const section: string): HRESULT;
begin
  // FT OK
  result := do_config(true, waveInId, waveOutId, formatIn, formatOut, inOutDriver, config, section, sdMode);
  //
  f_defFTIn := 0;
  f_defFTOut := 0;
end;

// --  --
function Tc_form_common_audioConfig.doConfig(waveIn: TunavclWaveInDevice; waveOut: TunavclWaveOutDevice; codecIn, codecOut: TunavclWaveCodecDevice; config: unaIniAbstractStorage; const section: string): HRESULT;
begin
  // FT OK
  result := do_load_Config(false, waveIn, waveOut, codecIn, codecOut, config, section);
  //
  f_defFTIn := 0;
  f_defFTOut := 0;
end;

// --  --
function Tc_form_common_audioConfig.doLoadConfig(var waveInId, waveOutId: int; var formatIn, formatOut: pWAVEFORMATEX; var inOutDriver: tinOutDriverDesc; var sdMode: unaWaveInSDMehtods; config: unaIniAbstractStorage; const section: string): HRESULT;
begin
  // FT OK
  result := do_config(false, waveInId, waveOutId, formatIn, formatOut, inOutDriver, config, section, sdMode);
  //
  f_defFTIn := 0;
  f_defFTOut := 0;
end;

// --  --
function Tc_form_common_audioConfig.doLoadConfig(waveIn: TunavclWaveInDevice; waveOut: TunavclWaveOutDevice; codecIn, codecOut: TunavclWaveCodecDevice; config: unaIniAbstractStorage; const section: string): HRESULT;
begin
  // FT OK
  result := do_load_Config(true, waveIn, waveOut, codecIn, codecOut, config, section);
  //
  f_defFTIn := 0;
  f_defFTOut := 0;
end;

⌨️ 快捷键说明

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