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

📄 u_vc2demo_main.pas

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

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

	  u_vc2semo_main.pas
	  Voice Communicator components version 2.5
	  VC Sampler demo application - main form

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

	  Visit http://lakeofsoft.com/ for more information.

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

	  created by:
		Lake, May 2002

	  modified by:
		Lake, May-Dec 2002
		Lake, Feb 2003
		Lake, Oct 2005

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

{$I unaDef.inc }

unit u_vc2demo_main;

interface

uses
  Windows, unaTypes, Forms, Controls, StdCtrls, ComCtrls, Classes, ActnList, ExtCtrls, Dialogs, Buttons,
  unaClasses, unaMsAcmClasses, unaWave;

type
  Tc_form_vc2DemoMain = class(TForm)
    c_groupBox_top: TGroupBox;
    c_groupBox_bottom: TGroupBox;
    c_statusBar_main: TStatusBar;
    c_comboBox_playbackDevice: TComboBox;
    c_comboBox_recordingDevice: TComboBox;
    c_actionList_main: TActionList;
    ac_openOut: TAction;
    ac_closeOut: TAction;
    ac_closeIn: TAction;
    ac_chooseOut: TAction;
    ac_chooseIn: TAction;
    c_staticText_outFormat: TStaticText;
    c_staticText_inFormat: TStaticText;
    c_timer_update: TTimer;
    ac_addChannel: TAction;
    c_progressBar_outLeft: TProgressBar;
    c_progressBar_outRight: TProgressBar;
    c_progressBar_inRight: TProgressBar;
    c_progressBar_inLeft: TProgressBar;
    c_checkBox_saveOut2File: TCheckBox;
    c_edit_waveOutFile: TEdit;
    c_checkBox_saveIn2File: TCheckBox;
    c_edit_waveInFile: TEdit;
    c_sb_waveOutStart: TSpeedButton;
    c_sb_waveOutStop: TSpeedButton;
    c_sb_waveInStart: TSpeedButton;
    c_sb_waveInStop: TSpeedButton;
    ac_openIn: TAction;
    c_sb_waveOutChoose: TSpeedButton;
    c_sb_waveInChoose: TSpeedButton;
    c_sb_waveOutAddWave: TSpeedButton;
    c_speedButton_outFileOpen: TSpeedButton;
    c_speedButton_inFileOpen: TSpeedButton;
    c_saveDialog_main: TSaveDialog;
    c_checkBox_loop2Playback: TCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ac_openOutExecute(Sender: TObject);
    procedure ac_chooseOutExecute(Sender: TObject);
    procedure ac_closeOutExecute(Sender: TObject);
    procedure ac_openInExecute(Sender: TObject);
    procedure ac_closeInExecute(Sender: TObject);
    procedure ac_chooseInExecute(Sender: TObject);
    procedure c_timer_updateTimer(Sender: TObject);
    procedure ac_addChannelExecute(Sender: TObject);
    procedure c_comboBox_playbackDeviceChange(Sender: TObject);
    procedure c_comboBox_recordingDeviceChange(Sender: TObject);
    procedure c_speedButton_outFileOpenClick(Sender: TObject);
    procedure c_edit_waveOutFileChange(Sender: TObject);
    procedure c_speedButton_inFileOpenClick(Sender: TObject);
    procedure c_edit_waveInFileChange(Sender: TObject);
    procedure c_checkBox_saveOut2FileClick(Sender: TObject);
    procedure c_checkBox_saveIn2FileClick(Sender: TObject);
    procedure c_panel_infoClick(Sender: TObject);
  private
    { Private declarations }
    f_acm: unaMsAcm;
    f_ini: unaIniFile;
    f_waveOutDeviceId: unsigned;
    f_waveOutFormat: unaPCMFormat;
    f_waveInFormat: unaPCMFormat;
    f_waveInDeviceId: unsigned;
    //
    f_waveInFile: string;
    f_waveOutFile: string;
    f_hintColorCount: unsigned;
    f_hintTextCount: unsigned;
    //
    f_playback: unaWaveOutDevice;
    f_recorder: unaWaveInDevice;
    f_mixer: unaWaveMixerDevice;
    f_channels: unaObjectList;
    f_riffOut: unaRiffStream;
    f_riffIn: unaRiffStream;
    f_inOutResampler: unaWaveResampler;
    f_inOutStream: unaAbstractStream;
    //
    procedure createDevices();
    procedure destroyDevices();
    procedure updateVolume(device: unaWaveDevice);
    procedure reEnable(device: unaWaveDevice);
    //
    procedure myOnDA(sender: tObject; data: pointer; size: unsigned);
  public
    { Public declarations }
    property mixer: unaWaveMixerDevice read f_mixer;
    property playback: unaWaveOutDevice read f_playback;
    property acm: unaMsAcm read f_acm;
    property channels: unaObjectList read f_channels;
    property ini: unaIniFile read f_ini write f_ini;
  end;

var
  c_form_vc2DemoMain: Tc_form_vc2DemoMain;


implementation


{$R *.dfm}

uses
  Math, SysUtils, MMSystem, Graphics, ShellAPI,
  unaUtils, unaMsAcmAPI,
  u_vc2Demo_playChannel;

// --  --
procedure Tc_form_vc2DemoMain.createDevices();
var
  i: int;
  capsOut: WAVEOUTCAPSW;
  capsIn: WAVEINCAPSW;
begin
  f_acm := unaMsAcm.create();
  f_acm.enumDrivers();
  //
  f_playback := unaWaveOutDevice.create(WAVE_MAPPER, false, false, 10);
  with (f_playback) do begin
    setSampling(f_waveOutFormat);
    calcVolume := true;
    c_staticText_outFormat.caption := srcFormatInfo;
  end;
  //
  f_recorder := unaWaveInDevice.create();
  with (f_recorder) do begin
    //
    setSampling(f_waveInFormat);
    assignStream(false, nil);	// remove recorder output stream
    calcVolume := true;
    c_staticText_inFormat.caption := dstFormatInfo;
  end;
  //
  f_mixer := unaWaveMixerDevice.create(true);
  f_mixer.addConsumer(f_playback);
  f_mixer.setSampling(f_waveOutFormat);
  //
  f_channels := unaObjectList.create();
  f_channels.autoFree := false;
  //
  // OUT
  for i := -1 to unaWaveOutDevice.getDeviceCount() - 1 do begin
    unaWaveOutDevice.getCaps(unsigned(i), capsOut);
    c_comboBox_playbackDevice.items.addObject(capsOut.szPname, pointer(i + 10));
  end;
  if (WAVE_MAPPER = f_waveOutDeviceId) then
    c_comboBox_playbackDevice.itemIndex := 0
  else
    c_comboBox_playbackDevice.itemIndex := min(unsigned(c_comboBox_playbackDevice.items.count) - 1, f_waveOutDeviceId + 1);
  //
  // IN
  for i := -1 to unaWaveInDevice.getDeviceCount() - 1 do begin
    unaWaveInDevice.getCaps(unsigned(i), capsIn);
    c_comboBox_recordingDevice.items.addObject(capsIn.szPname, pointer(i + 10));
  end;
  if (WAVE_MAPPER = f_waveInDeviceId) then
    c_comboBox_recordingDevice.itemIndex := 0
  else
    c_comboBox_recordingDevice.itemIndex := min(unsigned(c_comboBox_recordingDevice.items.count) - 1, f_waveInDeviceId + 1);
  //
  //
  reEnable(f_playback);
  reEnable(f_recorder);
end;

// --  --
procedure Tc_form_vc2DemoMain.destroyDevices();
begin
  ac_closeOut.Execute();
  ac_closeIn.Execute();
  //
  freeAndNil(f_channels);
  freeAndNil(f_recorder);
  freeAndNil(f_playback);
  freeAndNil(f_mixer);
  freeAndNil(f_acm);
end;

// --  --
procedure Tc_form_vc2DemoMain.FormCreate(Sender: TObject);
begin
  f_ini := unaIniFile.create();

  // OUT
  f_ini.section := 'waveOut';
  f_waveOutDeviceId := f_ini.get('deviceId', WAVE_MAPPER);
  f_waveOutFormat.pcmSamplesPerSecond := f_ini.get('pcmSamplesPerSecond', unsigned(44100));
  f_waveOutFormat.pcmBitsPerSample := f_ini.get('pcmBitsPerSample', unsigned(16));
  f_waveOutFormat.pcmNumChannels := f_ini.get('pcmNumChannels', unsigned(2));
  //
  f_waveOutFile := trim(f_ini.get('fileName', ''));
  c_edit_waveOutFile.Text := f_waveOutFile;
  c_checkBox_saveOut2File.Checked := f_ini.get('saveToFile', false);

  // IN
  f_ini.section := 'waveIn';
  f_waveInDeviceId := f_ini.get('deviceId', WAVE_MAPPER);
  f_waveInFormat.pcmSamplesPerSecond := f_ini.get('pcmSamplesPerSecond', unsigned(44100));
  f_waveInFormat.pcmBitsPerSample := f_ini.get('pcmBitsPerSample', unsigned(16));
  f_waveInFormat.pcmNumChannels := f_ini.get('pcmNumChannels', unsigned(2));
  //
  f_waveInFile := trim(f_ini.get('fileName', ''));
  c_edit_waveInFile.Text := f_waveInFile;
  c_checkBox_saveIn2File.Checked := f_ini.get('saveToFile', false);

  //
  createDevices();

  //
  ini.section := 'main';
  c_saveDialog_main.InitialDir := ini.get('initialSaveDir', '.\');
end;

// --  --
procedure Tc_form_vc2DemoMain.FormDestroy(Sender: TObject);
begin
  // OUT
  f_ini.section := 'waveOut';
  f_ini.setValue('deviceId', f_waveOutDeviceId);
  f_ini.setValue('pcmSamplesPerSecond', f_waveOutFormat.pcmSamplesPerSecond);
  f_ini.setValue('pcmBitsPerSample', f_waveOutFormat.pcmBitsPerSample);
  f_ini.setValue('pcmNumChannels', f_waveOutFormat.pcmNumChannels);
  f_ini.setValue('fileName', f_waveOutFile);
  f_ini.setValue('saveToFile', c_checkBox_saveOut2File.Checked);

  // IN
  f_ini.section := 'waveIn';
  f_ini.setValue('deviceId', f_waveInDeviceId);
  f_ini.setValue('pcmSamplesPerSecond', f_waveInFormat.pcmSamplesPerSecond);
  f_ini.setValue('pcmBitsPerSample', f_waveInFormat.pcmBitsPerSample);
  f_ini.setValue('pcmNumChannels', f_waveInFormat.pcmNumChannels);
  f_ini.setValue('fileName', f_waveInFile);
  f_ini.setValue('saveToFile', c_checkBox_saveIn2File.Checked);

  freeAndNil(f_ini);
  //
  destroyDevices();
end;

// --  --
procedure Tc_form_vc2DemoMain.ac_openOutExecute(Sender: TObject);
var
  format: WAVEFORMATEX;
begin
  if (not f_playback.isOpen()) then begin
    //
    f_playback.deviceId := unsigned(int(c_comboBox_playbackDevice.Items.Objects[c_comboBox_playbackDevice.ItemIndex]) - 10);
    //f_playback.mapped := c_checkBox_outMapped.checked;
    //f_playback.direct := c_checkBox_outDirect.checked;
    if (c_checkBox_saveOut2File.Checked) then begin
      //
      fillPCMFormat(format, f_waveOutFormat.pcmSamplesPerSecond, f_waveOutFormat.pcmBitsPerSample, f_waveOutFormat.pcmNumChannels);
      f_riffOut := unaRiffStream.createNew(f_waveOutFile, format);
      f_riffOut.open();

⌨️ 快捷键说明

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