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

📄 u_common_audioconfig.pas

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

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

// --  --
function Tc_form_common_audioConfig.doLoadFormat(var format: pWAVEFORMATEX; const key: string; defFormatTag: int): int;
var
  formatStr: string;
  size: unsigned;
begin
  result := 0;
  //
  // assuming f_formatIn was allocated to store max format size
  formatStr := trim(f_config.get(f_section, key, ''));
  //
  if ((nil <> f_formatIn) and ('' <> formatStr)) then begin
    //
    size := f_maxFormatSize;
    str2waveFormatEx(formatStr, format, size);
    //
    if (1 > size) then
      formatStr	:= '';	// something is wrong with format string
  end
  else
    size := 0;
  //
  if ((nil = format) or (1 > size)) then begin
    //
    if (nil = format) then
      // allocate space for max format size
      allocateWaveFormat(format);
    //
    if ('' <> formatStr) then begin
      //
      size := f_maxFormatSize;
      str2waveFormatEx(formatStr, format, size);
      //
      result := 1;
    end;
    //
    if (1 > size) then begin
      //
      fillPCMFormat(format^, choice(0 = enumFormat.nSamplesPerSec, unsigned(c_defSamplingSamplesPerSec), enumFormat.nSamplesPerSec), choice(0 = enumFormat.wBitsPerSample, unsigned(c_defSamplingBitsPerSample), enumFormat.wBitsPerSample), choice(0 = enumFormat.nChannels, unsigned(c_defSamplingNumChannels), enumFormat.nChannels));
      format.wFormatTag := defFormatTag;
    end;
  end;
end;

// --  --
procedure Tc_form_common_audioConfig.loadConfig();
var
  sec: string;
begin
  enumWaveDevices();
  //
  if (f_config.enter(f_section, sec, 100)) then begin
    //
    try
      // load configuration
      c_comboBox_waveIn.itemIndex  := f_config.get('wave.in.deviceIdIndex',  deviceId2index(f_waveInId));
      f_waveInId := index2deviceId(c_comboBox_waveIn);
      c_comboBox_waveOut.itemIndex := f_config.get('wave.out.deviceIdIndex', deviceId2index(f_waveOutId));
      f_waveOutId := index2deviceId(c_comboBox_waveOut);
      //
      c_comboBox_inCodecMode.itemIndex  := f_config.get('codec.in.driverModeIndex',  driverMode2index(f_inOutDriver.r_in.r_mode));
      f_inOutDriver.r_in.r_mode := index2driverMode(c_comboBox_inCodecMode.itemIndex);
      //
      f_inOutDriver.r_in.r_formatIndex := f_config.get('codec.in.formatIndex', f_inOutDriver.r_in.r_formatIndex);
      f_inOutDriver.r_in.r_library := f_config.get('codec.in.driverLib', f_inOutDriver.r_in.r_library);
      //
      f_waveInSDMode := unaWaveInSDMehtods(f_config.get('wave.in.sd.mode', ord(f_waveInSDMode)));
      case (f_waveInSDMode) of

	unasdm_none: c_cb_enableSD.State := cbUnchecked;
	unasdm_VC  : c_cb_enableSD.State := cbGrayed;
	unasdm_DSP : c_cb_enableSD.State := cbChecked;

      end;
      c_cb_enableSDClick(self);
      //
      showCodecTags(true);
      //
      if (not f_syncInOutFormat) then begin
	//
	c_comboBox_outCodecMode.itemIndex := f_config.get('codec.out.driverModeIndex', driverMode2index(f_inOutDriver.r_out.r_mode));
	f_inOutDriver.r_out.r_mode := index2driverMode(c_comboBox_outCodecMode.itemIndex);
	//
	f_inOutDriver.r_out.r_formatIndex := f_config.get('codec.out.formatIndex', f_inOutDriver.r_out.r_formatIndex);
	f_inOutDriver.r_out.r_library := f_config.get('codec.out.driverLib', f_inOutDriver.r_out.r_library);
	//
	showCodecTags(false);
      end;
      //
    finally
      f_config.leave(sec);
    end;
  end;
  //
  f_formatIn_nonPCMOK := (1 = doLoadFormat(f_formatIn, 'wave.in.format', f_defFTIn));
  if (unacdm_openH323plugin = f_inOutDriver.r_in.r_mode) then begin
    //
    c_edit_inFormat.text := f_inOutDriver.r_in.r_library;
  end
  else begin
    //
    if (nil <> f_formatIn) then
      c_edit_inFormat.text := format2str(f_formatIn^);
  end;
  //
  if (not f_syncInOutFormat) then begin
    //
    f_formatOut_nonPCMOK := (1 = doLoadFormat(f_formatOut, 'wave.out.format', f_defFTOut));
    if (unacdm_openH323plugin = f_inOutDriver.r_out.r_mode) then begin
      //
      c_edit_outFormat.text := f_inOutDriver.r_out.r_library;
    end
    else begin
      //
      if (nil <> f_formatOut) then
	c_edit_outFormat.text := format2str(f_formatOut^);
    end;
  end
  else
    c_edit_outFormat.text := c_edit_inFormat.text;
  //
end;

// --  --
procedure Tc_form_common_audioConfig.saveConfig();
var
  sec: string;
begin
  enumWaveDevices();
  //
  if (f_config.enter(f_section, sec, 100)) then begin
    //
    try
      // save configuration
      f_config.setValue('wave.in.deviceIdIndex',  c_comboBox_waveIn.itemIndex);
      f_config.setValue('wave.out.deviceIdIndex', c_comboBox_waveOut.itemIndex);
      //
      f_config.setValue('codec.in.driverModeIndex',  driverMode2index(f_inOutDriver.r_in.r_mode));
      f_config.setValue('codec.in.formatIndex',                       f_inOutDriver.r_in.r_formatIndex);
      f_config.setValue('codec.in.driverLib',                         f_inOutDriver.r_in.r_library);
      //
      f_config.setValue('codec.out.driverModeIndex', driverMode2index(f_inOutDriver.r_out.r_mode));
      f_config.setValue('codec.out.formatIndex',                      f_inOutDriver.r_out.r_formatIndex);
      f_config.setValue('codec.out.driverLib',                        f_inOutDriver.r_out.r_library);
      //
      f_config.setValue('wave.in.sd.mode', ord(f_waveInSDMode));
      //
      // assuming f_formatIn is allocated and valid
      if ((nil <> f_formatIn) and f_formatIn_nonPCMOK) then
	f_config.setValue('wave.in.format', waveFormatEx2Str(f_formatIn^));
      //
      // assuming f_formatOut is allocated and valid
      if (not f_syncInOutFormat and (nil <> f_formatOut) and f_formatOut_nonPCMOK) then
	f_config.setValue('wave.out.format', waveFormatEx2str(f_formatOut^));
      //
    finally
      f_config.leave(sec);
    end
  end;
end;

// --  --
function Tc_form_common_audioConfig.doFormatChoose(var format: pWAVEFORMATEX; var title: string): int;
begin
  if (mmNoError(formatChooseAlloc(format, format.wFormatTag, c_defSamplingSamplesPerSec, title, ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT, enumFlags, choice(0 = enumFlags, nil, f_enumFormat), f_maxFormatSize, handle))) then begin
    //
    title := format2str(format^);
    result := S_OK;
  end
  else
    result := -1;
  //
end;

// --  --
procedure Tc_form_common_audioConfig.c_button_inFormatBrowseClick(sender: tObject);
var
  title: string;
begin
  case (index2driverMode(c_comboBox_inCodecMode.itemIndex)) of

    unacdm_acm: begin
      //
      title := 'Select recording format';
      if (Succeeded(doFormatChoose(f_formatIn, title))) then begin
	//
	c_edit_inFormat.text := title;
	if (f_syncInOutFormat) then
	  c_edit_outFormat.text := c_edit_inFormat.text;
	//
	f_formatIn_nonPCMOK := true;
      end;
    end;

    unacdm_openH323plugin: begin
      //
      if (c_openDialog_lib.execute()) then begin
	//
	f_inOutDriver.r_in.r_library := extractFileNameW(c_openDialog_lib.fileName);
	c_edit_inFormat.text := f_inOutDriver.r_in.r_library;
	//
	showCodecTags(true);
      end;
    end;

  end;
end;

// --  --
procedure Tc_form_common_audioConfig.c_button_outFormatBrowseClick(sender: tObject);
var
  title: string;
begin
  case (index2driverMode(c_comboBox_outCodecMode.itemIndex)) of

    unacdm_acm: begin
      //
      if (not f_syncInOutFormat) then begin
	//
	title := 'Select playback format';
	if (Succeeded(doFormatChoose(f_formatOut, title))) then begin
	  //
	  c_edit_outFormat.text := title;
	  //
	  f_formatOut_nonPCMOK := true;
	end;
      end;
    end;

    unacdm_openH323plugin: begin
      //
      if (c_openDialog_lib.execute()) then begin
	//
	f_inOutDriver.r_out.r_library := extractFileNameW(c_openDialog_lib.fileName);
	c_edit_outFormat.text := f_inOutDriver.r_out.r_library;
	//
	showCodecTags(false);
      end;
    end;

  end;
end;

// --  --
procedure Tc_form_common_audioConfig.c_button_configAudioClick(sender: tObject);
begin
  execApp('RUNDLL32.EXE', 'MMSYS.CPL,ShowAudioPropertySheet', false);
end;

// --  --
procedure Tc_form_common_audioConfig.c_button_inVolControlClick(sender: tObject);
var
  mxId: int;
begin
  if (0 <= f_waveInId) then begin
    //
    f_mixer.enumDevices();
    mxId := f_mixer.getMixerId(f_waveInId, true{IN});
    //
    if (0 > mxId) then begin
      //
      guiMessageBox(handle, 'This device has no mixer.', 'Information', MB_OK or MB_ICONEXCLAMATION);
    end
    else begin
      //
      execApp('sndvol32.exe', '/r /d' + int2str(mxId), false);
    end;
  end;
end;

// --  --
procedure Tc_form_common_audioConfig.c_button_outVolControlClick(sender: tObject);
var
  mxId: int;
begin
  if (0 <= f_waveOutId) then begin
    //
    f_mixer.enumDevices();
    mxId := f_mixer.getMixerId(f_waveOutId, false{OUT});
    //
    if (0 > mxId) then begin
      //
      guiMessageBox(handle, 'This device has no mixer.', 'Information', MB_OK or MB_ICONEXCLAMATION);
    end
    else begin
      //
      execApp('sndvol32.exe', '/p /d' + int2str(mxId), false);
    end;
  end;
end;

// --  --
procedure Tc_form_common_audioConfig.setupUI(syncInOutFormat, includeMapper, allowModeChange: bool);
begin
  f_syncInOutFormat := syncInOutFormat;
  f_includeMapper := includeMapper;
  f_allowModeChange := allowModeChange;
  //
  c_button_outFormatBrowse.visible := not f_syncInOutFormat;
  c_edit_outFormat.visible := not f_syncInOutFormat;
  c_comboBox_outCodecTag.visible := not f_syncInOutFormat;
  c_label_outCodecFT.visible := not f_syncInOutFormat;
  c_label_outFormat.visible := not f_syncInOutFormat;
  //
  c_label_inDriverMode.visible := allowModeChange;
  c_comboBox_inCodecMode.visible := allowModeChange;
  c_label_outDriverMode.visible := allowModeChange and not f_syncInOutFormat;
  c_comboBox_outCodecMode.visible := allowModeChange and not f_syncInOutFormat;
  //
  if (f_syncInOutFormat) then
    c_edit_outFormat.text := c_edit_inFormat.text;
  //  
end;

// --  --
procedure Tc_form_common_audioConfig.enumWaveDevices();
begin
  if (not f_enumComplete) then begin
    //
    f_enumComplete := true;
    //
    unaVcIDEUtils.enumWaveDevices(c_comboBox_waveIn, true, f_includeMapper);
    unaVcIDEUtils.enumWaveDevices(c_comboBox_waveOut, false, f_includeMapper);
  end;
end;

// --  --
procedure Tc_form_common_audioConfig.c_comboBox_inCodecModeChange(sender: tObject);
begin
  f_inOutDriver.r_in.r_mode := index2driverMode(c_comboBox_inCodecMode.itemIndex);
  //
  showCodecTags(true);
end;

// --  --
procedure Tc_form_common_audioConfig.c_comboBox_outCodecModeChange(sender: tObject);
begin
  f_inOutDriver.r_out.r_mode := index2driverMode(c_comboBox_outCodecMode.itemIndex);
  //
  showCodecTags(false);
end;

// --  --
procedure Tc_form_common_audioConfig.showCodecTags(inCodec: bool);

type
  //
  popenH323pluginCodecs = ^openH323pluginCodecs;
  openH323pluginCodecs = array[word] of pluginCodec_definition;

var
  i: int;
  combo: tComboBox;
  edit: tEdit;
  lib: wideString;
  pproc: plugin_proc;
  codecDefRoot: popenH323pluginCodecs;
  cnt: uint32;
  label1, label2: tLabel;
  doShow: bool;
begin
  if (inCodec) then begin
    //
    combo := c_comboBox_inCodecTag;
    edit := c_edit_inFormat;
    label1 := c_label_inCodecFT;
    label2 := c_label_inFormat;
    //
    lib := f_inOutDriver.r_in.r_library;
    //
    doShow := (unacdm_openH323plugin = f_inOutDriver.r_in.r_mode);
  end
  else begin
    //
    combo := c_comboBox_outCodecTag;
    edit := c_edit_outFormat;
    label1 := c_label_outCodecFT;
    label2 := c_label_outFormat;
    //
    lib := f_inOutDriver.r_out.r_library;
    //
    doShow := (unacdm_openH323plugin = f_inOutDriver.r_out.r_mode);
  end;
  //
  if (doShow) then begin
    //
    combo.items.clear();
    //
    if ('' = lib) then begin
      //
      if (c_openDialog_lib.execute()) then begin
	//
	lib := extractFileNameW(c_openDialog_lib.fileName);
	//
	if (inCodec) then
	  f_inOutDriver.r_in.r_library := lib
	else
	  f_inOutDriver.r_out.r_library := lib;
      end;
    end;
    //
    edit.text := lib;
    //
    fillChar(pproc, sizeOf(pproc), #0);
    if (0 = plugin_loadDLL(pproc, lib)) then begin
      //
      try
	//
	pointer(codecDefRoot) := pproc.rproc_getCodecFunction(cnt, PLUGIN_CODEC_VERSION);
	//
	if ((nil <> codecDefRoot) and (0 < cnt)) then begin
	  //
	  for i := 0 to cnt - 1 do begin
	    //
	    if ('L16' = trim(string(codecDefRoot[i].sourceFormat))) then
	      combo.items.add(codecDefRoot[i].descr);
	    //
	  end;
	end;
	//
      finally
	plugin_unloadDLL(pproc);
      end;
    end;
    //
    if (0 < combo.items.count) then begin
      //
      if (inCodec) then
	combo.itemIndex := min(combo.items.count - 1, f_inOutDriver.r_in.r_formatIndex)
      else
	combo.itemIndex := min(combo.items.count - 1, f_inOutDriver.r_out.r_formatIndex);
      //
    end;
    //
    label1.visible := true;
    label2.caption := '&Library';
  end
  else begin
    //
    if (inCodec) then begin
      //
      if (nil <> f_formatIn) then
	edit.text := format2str(f_formatIn^);
    end
    else begin
      //
      if (nil <> f_formatOut) then
	edit.text := format2str(f_formatOut^);
    end;
    //
    label1.visible := false;
    label2.caption := label1.caption;
  end;
  //
  combo.visible := doShow;
end;

// --  --
procedure Tc_form_common_audioConfig.c_comboBox_waveInChange(sender: TObject);
begin
  f_waveInId := index2deviceId(c_comboBox_waveIn);
end;

// --  --
procedure Tc_form_common_audioConfig.c_comboBox_waveOutChange(sender: TObject);
begin
  f_waveOutId := index2deviceId(c_comboBox_waveOut);
end;

// --  --
procedure Tc_form_common_audioConfig.c_comboBox_inCodecTagChange(sender: TObject);
begin
  f_inOutDriver.r_in.r_formatIndex := c_comboBox_inCodecTag.itemIndex;
end;

// --  --
procedure Tc_form_common_audioConfig.c_comboBox_outCodecTagChange(sender: TObject);
begin
  f_inOutDriver.r_out.r_formatIndex := c_comboBox_outCodecTag.itemIndex;
end;

// --  --
procedure Tc_form_common_audioConfig.c_cb_enableSDClick(Sender: TObject);
begin
  case (c_cb_enableSD.State) of

    cbUnchecked: begin
      //
      c_label_sdMode.caption := 'SD: none';
      f_waveInSDMode := unasdm_none;
    end;

    cbGrayed: begin
      //
      c_label_sdMode.caption := 'SD: VC';
      f_waveInSDMode := unasdm_VC;
    end;

    cbChecked: begin
      //
      c_label_sdMode.caption := 'SD: DSP';
      f_waveInSDMode := unasdm_DSP;
    end;

  end;
end;


end.

⌨️ 快捷键说明

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