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

📄 unavcide.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    property position: int64 read getPosition;
    {DP:MEHTOD
      Returns first provider of a component (if any).
    }
    property providerOneAndOnly: unavclInOutPipe read getProviderOneAndOnly;
    {DP:METHOD
      Array of component consumers.
    }
    property consumers[index: unsigned]: unavclInOutPipe read getConsumer;
    {DP:METHOD
      Array of providers for component.
    }
    property providers[index: unsigned]: unavclInOutPipe read getProvider;
    //
  published
    //
    // -- PROPERTIES --
    //
    {DP:METHOD
      Returns or sets the current state of the pipe.
      Set to true to activate (open) the component. All other properties should be set to proper values before activation.
      Set to false to deactivate (close) the component.
    }
    property active: bool read getActive write setActive default false;
    {DP:METHOD
      Specifies the consumer of component.
      When set, specified consumer will receive all the stream data from the component.
      This allows chaining the components into data flow row.
    }
    property consumer: unavclInOutPipe read getConsumerOneAndOnly write setConsumerOneAndOnly;
    {DP:METHOD
      Specifies the file name to store the stream into.
      dumpInput is be used to store the input stream, which is coming as input for component.
      Stream will be saved in "as is" format.
      For example, <A href="#class_TunavclWaveOutDevice">TunavclWaveOutDevice</A> will store input stream as sequence of PCM samples.
    }
    property dumpInput: string read f_dumpInput write f_dumpInput;
    {DP:METHOD
      Specifies the file name to store the stream into.
      dumpOutput is be used to store the output stream, which is coming as output from the component.
      Stream will be saved in "as is" format.
      For example, <A href="#class_TunavclWaveInDevice">TunavclWaveInDevice</A> will store output stream as sequence of PCM samples.
    }
    property dumpOutput: string read f_dumpOutput write f_dumpOutput;
    {DP:METHOD
      When true the component will assign stream format to the consumer (if any).
      This simplifies the process of distributing stream format among linked components.
      For example <A href="#class_TunavclWaveRiff">TunavclWaveRiff</A> component can assign PCM format for linked <A href="#class_TunavclWaveOutDevice">TunavclWaveOutDevice</A> component, so WAVe file will be played back correctly.
    }
    property isFormatProvider: bool read f_isFormatProvider write f_isFormatProvider default false;
    {DP:METHOD
       When true tells the component it must activate consumer (if any) before activating itself.
       Same applies for deactivation. When false the component does not change the consumer state.
    }
    property autoActivate: bool read f_autoActivate write f_autoActivate default true;
    {DP:METHOD
       When true tells the component it must activate consumer (if any) before activating itself.
       Same applies for deactivation. When false the component does not change the consumer state.
    }
    property enableDataProxy: bool read f_enableDataProxy write f_enableDataProxy default false;
    //
    // -- EVENTS --
    //
    {DP:METHOD
      This event is fired every time component has produced or received new chunk of data.
      Use this event to access the raw stream data. Any modifications you made with data will not affect data consumers.
      To modify data before it will passed to consumers, use onDataDSP() event.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onDataAvailable: unavclPipeDataEvent read f_dataAvail write f_dataAvail;
    {DP:METHOD
      This event is fired every time component has produced or received new chunk of data.
      Use this event to access the raw stream data. Any modifications you made with data will be used by comsumers.
      To modify data without affecting consumers, use onDataAvail() event.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onDataDSP: unavclPipeDataEvent read f_dataDSP write f_dataDSP;
    {DP:METHOD
      This event is fired after new format was applied to a pipe.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onFormatChangeAfter: unavclPipeAfterFormatChangeEvent read f_afterFormatChange write f_afterFormatChange;
    {DP:METHOD
      This event is fired before new format is about to be applied to a pipe.
      Using allowFormatChange parameter it is possible to disable format's applying.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onFormatChangeBefore: unavclPipeBeforeFormatChangeEvent read f_beforeFormatChange write f_beforeFormatChange;
  end;


// -----------------------
//  -- wave components --
// -----------------------


const
  defOverNumValue = 5;

type
  //
  // -- unavclWavePipeFormatExchange --
  //
  punavclWavePipeFormatExchange = ^unavclWavePipeFormatExchange;
  unavclWavePipeFormatExchange = packed record
    //
    r_format: unaWaveFormat;
    //
    r_driverMode: int32;			// custom driver mode
    r_driverLib: array[0..64] of wideChar;	// library module name
  end;


  //
  // -- unaInOutWavePipe --
  //

  {DP:CLASS
    Base abstract class for wave devices.
  }
  unavclInOutWavePipe = class(unavclInOutPipe)
  private
    f_deviceId: int;
    f_mapped: bool;
    f_deviceWasCreated: bool;
    f_iNeedDriver: bool;
    f_needToUnloadDriver: bool;
    f_driverMode: unaAcmCodecDriverMode;
    f_driverLibrary: wideString;
    //
    f_direct: bool;
    f_realTime: bool;
    f_applyFormatTagImmunable: bool;
    f_needApplyFormatOnCreate: bool;	// some devices already has format assigned after creation,
					// and this flag should be set to true in that case
    f_overNum: unsigned;
    f_formatTag: unsigned;
    f_loop: bool;
    f_inputIsPcm: bool;
    f_addSilence: bool;
    f_calcVolume: bool;
    f_sdmCache: unaWaveInSDMehtods;
    //
    f_waveError: int;
    //
    f_pcmFormat: WAVEFORMATEX;
    //
    f_acm: unaMsAcm;
    f_driver: unaMsAcmDriver;
    f_device: unaMsAcmStreamDevice;
    //
    function getFormat(): pWAVEFORMATEX;
    function getSamplingParam(index: int): unsigned;
    function getWaveErrorAsString(): string;
    //
    procedure myOnDA(sender: tObject; data: pointer; len: unsigned);
    //
    procedure setMapped(value: bool);
    procedure setDirect(value: bool);
    procedure setOverNum(value: unsigned);
    procedure setRealTime(value: bool);
    procedure setInputIsPcm(value: bool);
    procedure setCalcVolume(value: bool);
    //
    procedure setDeviceId(value: int);
    procedure setFormatTag(value: unsigned);
    procedure setFormat(value: pWAVEFORMATEX);
    procedure setDriver(value: unaMsAcmDriver);
    procedure setSamplingParam(index: int; value: unsigned);
    //
    procedure setAddSilence(value: bool);
    procedure setLoop(value: bool);
    procedure setDriverMode(value: unaAcmCodecDriverMode);
    procedure setDriverLibrary(const value: wideString);
    //
    procedure setSdm(value: unaWaveInSDMehtods);
  protected
    procedure doSetDeviceId(value: int); virtual;
    procedure doSetFormatTag(value: unsigned); virtual;
    procedure doSetFormat(value: pWAVEFORMATEX); virtual;
    procedure doSetDriver(value: unaMsAcmDriver); virtual;
    procedure doSetSamplingParam(index: int; value: unsigned); virtual;
    //
    procedure doSetAddSilence(value: bool); virtual;
    procedure doSetLoop(value: bool); virtual;
    procedure doSetDriverMode(value: unaAcmCodecDriverMode); virtual;
    procedure doSetDriverLibrary(const value: wideString); virtual;
    //
    function doGetPosition(): int64; override;
    //
    {DP:METHOD
      Does all the job of device creation. Should be overriten with actual implementation.
      Should not be called directly.
    }
    procedure createNewDevice(); virtual;
    {DP:MEHTOD
      Called when new device is about to be created.
    }
    procedure destroyOldDevice(); virtual;
    {DP:METHOD
      Applies new stream format for the wave device.
    }
    function applyDeviceFormat(const format: WAVEFORMATEX; isSrc: bool = true): bool; virtual; abstract;
    {DP:METHOD
      Writes data into the wave device.
    }
    function doWrite(data: pointer; len: unsigned; provider: unavclInOutPipe = nil): int; override;
    {DP:METHOD
      Reads data from the wave device.
    }
    function doRead(data: pointer; len: unsigned): unsigned; override;
    {DP:METHOD
      Returns data size available to read from the wave device.
    }
    function getAvailableDataLen(index: int): unsigned; override;
    {DP:METHOD
      Opens the wave device.
    }
    function doOpen(): bool; override;
    {DP:METHOD
      Closes the wave device.
    }
    procedure doClose(); override;
    {DP:METHOD
      Enters one-thread execution mode for the wave device.
    }
    function doEnter(timeOut: unsigned = 1000): bool; override;
    {DP:METHOD
      Leaves one-thread execution mode for the wave device.
    }
    procedure doLeave(); override;
    {DP:METHOD
      Returns active state of the wave device.
    }
    function  isActive(): bool; override;
    {DP:METHOD
      Applies stream format on the pipe.
    }
    function applyFormat(data: pointer; len: unsigned; provider: unavclInOutPipe = nil; restoreActiveState: bool = false): bool; override;
    {DP:METHOD
      Returns format exchange data of the pipe stream.
    }
    function getFormatExchangeData(out data: pointer): unsigned; override;
    {
    }
    function getChunkSize(): unsigned; virtual;
    {
    }
    function getDstChunkSize(): unsigned; virtual;
    {DP:METHOD
      Triggers when device driver has been changed.
    }
    procedure onDriverChanged(); virtual;
    {DP:METHOD
      Initializes the wave device.
    }
    procedure Loaded(); override;
    //
    //
    {DP:METHOD
      Adds provider to the wave device.
    }
    function doAddProvider(provider: unavclInOutPipe): bool; override;
    {DP:METHOD
      Removes provider from the wave device.
    }
    procedure doRemoveProvider(provider: unavclInOutPipe); override;
    //
    {DP:METHOD
      Internal.
    }
    property deviceWasCreated: bool read f_deviceWasCreated;
    {DP:METHOD
      Specifies whether device should add silence when it runs out of audio data.
    }
    property addSilence: bool read f_addSilence write setAddSilence default false;
    {DP:METHOD
      Specifies device ID for the wave device.
    }
    property deviceId: int read f_deviceId write setDeviceId default int(WAVE_MAPPER);
    {DP:METHOD
      Specifies audio format tag for the wave device.
    }
    property formatTag: unsigned read f_formatTag write setFormatTag default WAVE_FORMAT_PCM;
    {DP:METHOD
      Specifies the device is immunable for format tag changes (usually useful for codecs).
    }
    property formatTagImmunable: bool read f_applyFormatTagImmunable write f_applyFormatTagImmunable default false;
    {DP:METHOD
      Specifies whether wave device is mapped.
    }
    property mapped: bool read f_mapped write setMapped default false;
    {DP:METHOD
      Specifies whether wave device is direct.
    }
    property direct: bool read f_direct write setDirect default false;
    {DP:METHOD
      Specifies whether device is working as real-time device.
    }
    property realTime: bool read f_realTime write setRealTime default false;
    {DP:METHOD
      Specifies whether wave stream should be looped from end to beginning.
    }
    property loop: bool read f_loop write setLoop default false;
    {DP:METHOD
      Specifies whether format of input stream of the device is PCM.
    }
    property inputIsPcm: bool read f_inputIsPcm write setInputIsPcm default true;
    { }
    property driverMode: unaAcmCodecDriverMode read f_driverMode write setDriverMode default unacdm_acm;
    { }
    property driverLibrary: wideString read f_driverLibrary write setDriverLibrary;
    {DP:METHOD
      Specifies which method will be used to detect silence.
      <UL>
	<LI>unasdm_none - no silence detection</LI>
	<LI>unasdm_VC - "old" method, which uses minVolumeLevel and minActiveTime</LI>
	<LI>unasdm_DSP</LI>
      <UL>
    }
    property silenceDetectionMode: unaWaveInSDMehtods read f_sdmCache write setSdm default unasdm_none;
  public
    {DP:METHOD
      Assigns default values for properties.
    }
    constructor Create(owner: tComponent); override;
    {DP:METHOD
    }
    constructor createWaveDevice(deviceId: int = int(WAVE_MAPPER); formatTag: unsigned = WAVE_FORMAT_PCM; realTime: bool = false);
    {DP:METHOD
      Creates the wave device.
    }
    procedure AfterConstruction(); override;
    {DP:METHOD
      Destroys the wave device.
    }
    procedure BeforeDestruction(); override;
    {DP:METHOD
      Destroys previuosly created wave device, then creates new one.
      Assigns required callbacks for device.
    }
    procedure createDevice();
    {DP:METHOD
      Creates ACM driver for device (if needed).
    }
    procedure createDriver();
    //
    {DP:METHOD
      Refreshes the device format.

⌨️ 快捷键说明

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