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

📄 unamsacmclasses.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      Returns driver details.
    }
    function getDetails(): pACMDRIVERDETAILSW;
    {DP:METHOD
      Returns true if driver is enabled.
    }
    function isEnabled(): bool;
    {DP:METHOD
      Returns ACM priority of the driver.
    }
    function getPriority(): unsigned;
    {DP:METHOD
      Sets ACM priority of the driver.
    }
    procedure setPriority(value: unsigned);
    {DP:METHOD
      Enables of disables the driver.
    }
    procedure setEnabled(value: bool);
    // -- filters and formats --
    {DP:METHOD
      Returns number of formats stored in format list.
    }
    function getFormatCount(): unsigned;
    function getFormatTagCount(): unsigned;
    {DP:METHOD
      Returns number of filters stored in filter list.
    }
    function getFilterCount(): unsigned;
    {DP:METHOD
      Returns wave format object by its index in format list.
    }
    function getFormat(index: unsigned): unaMsAcmFormat;
    function getFormatTag(index: unsigned): unaMsAcmFormatTag;
    {DP:METHOD
      Returns wave filter object by its index in filter list.
    }
    function getFilter(index: unsigned): unaMsAcmFilter;
    // -- helping functions --
    {DP:METHOD
      Displays a custom About dialog box from an ACM driver.
      If the driver does not support a custom About dialog box, MMSYSERR_NOTSUPPORTED will be returned.
    }
    function about(wnd: HWND): MMRESULT;
    {DP:METHOD
      Queries the ACM driver to suggest a destination format for the supplied source format.
      srcFormat is a WAVEFORMATEX structure that identifies the source format for which a destination format will be suggested by the driver.
      dstFormat is a WAVEFORMATEX structure that will receive the suggested destination format for the srcFormat format. Depending on the flags parameter, some members of the structure pointed to by dstFormat may require initialization.
      The following values are defined for flags parameter:
      <UL>
	<LI>ACM_FORMATSUGGESTF_NCHANNELS - The nChannels member of the structure pointed to by dstFormat is valid. The ACM will query the driver if it can suggest a destination format matching nChannels or fail.</LI>
	<LI>ACM_FORMATSUGGESTF_NSAMPLESPERSEC - The nSamplesPerSec member of the structure pointed to by dstFormat is valid. The ACM will query acceptable the driver if it can suggest a destination format matching nSamplesPerSec or fail.</LI>
	<LI>ACM_FORMATSUGGESTF_WBITSPERSAMPLE - The wBitsPerSample member of the structure pointed to by dstFormat is valid. The ACM will query acceptable the driver if it can suggest a destination format matching wBitsPerSample or fail.</LI>
	<LI>ACM_FORMATSUGGESTF_WFORMATTAG - The wFormatTag member of the structure pointed to by dstFormat is valid. The ACM will query the driver if it can suggest a destination format matching wFormatTag or fail.</LI>
      </UL>
      Returns MMSYSERR_NOERROR if successful or an error code otherwise.
    }
    function suggestCodecFormat(const srcFormat: WAVEFORMATEX; var dstFormat: WAVEFORMATEX; flags: unsigned): MMRESULT;
    // -- other --
    {DP:METHOD
      Calls the master acm class to fill the given ACMFORMATDETAILS structure.
    }
    function preparePafd(var pafd: ACMFORMATDETAILS; tag: unsigned = 0; index: unsigned = 0): bool;
    {DP:METHOD
      Retrieves format details and fills the PCM sampling parameters of given wave device.
    }
    function assignFormat(tag: unsigned; index: unsigned; device: unaWaveDevice): bool;
    // -- properties --
    {DP:METHOD
      id of the driver.
    }
    property id: HACMDRIVERID read f_id;
    {DP:METHOD
      unaMsAcm class instance.
    }
    property acm: unaMsAcm read f_acm;
    {DP:METHOD
      Read-only property which indicates whether the driver was created as installable.
    }
    property isInstallable: bool read f_isInstallable;
  end;


  //
  // -- unaMsAcm --
  //

  {DP:CLASS
    This class holds a list of drivers installed on the system.
    Driver usually corresponds to one specific audio format and may contain converters, codecs and filters.
    You should explicitly call enumDrivers() method to enumerate installed drivers.

    <P />Every installed driver has unique manufacturer and product identifiers (MID and PID).
    You can use these identifiers to locate specific driver.
    Use getDriver() method to retrieve driver by index or MID/PID pair.
  }
  unaMsAcm = class(unaObject)
  private
    f_version: unsigned;
    f_drivers: unaObjectList;
    //
    function getAcmCount(index: int): unsigned;
  protected
    {DP:METHOD
      Adds driver to the list of drivers.
    }
    procedure addEnumedDriver(id: HACMDRIVERID; support: unsigned); virtual;
  public
    {DP:METHOD
      Allocates internal structures needed for class instance.
    }
    constructor create();
    destructor Destroy(); override;
    //
    {DP:METHOD
      Enumerates installed ACM drivers.
      The following values are defined for flags parameter:
      <UL>
	<LI>ACM_DRIVERENUMF_DISABLED - Disabled ACM drivers should be included in the enumeration.</LI>
	<LI>ACM_DRIVERENUMF_NOLOCAL - Only global drivers should be included in the enumeration.</LI>
      </UL>
      Enumerated drivers are stored in driver list. You can access them using the getDriver() method.
    }
    procedure enumDrivers(flags: unsigned = 0);
    {DP:METHOD
      Searches the list of drivers for driver with specified mid and pid values.
    }
    function getDriver(mid, pid: unsigned): unaMsAcmDriver; overload;
    {DP:METHOD
      Returns driver from the list of drivers. Driver is specified by the index in the list (starting from 0).
    }
    function getDriver(index: unsigned): unaMsAcmDriver; overload;
    {DP:METHOD
      Returns driver from the list of drivers. Driver is specified by the format tag supported by driver.
    }
    function getDriverByFormatTag(formatTag: unsigned): unaMsAcmDriver;
    {DP:METHOD
      Returns number of drivers enumerated by enumDrivers() method.
    }
    function getDriverCount(): unsigned;
    {DP:METHOD
      Opens installable ACM driver.
    }
    function openDriver(const driverLibrary: wideString): unaMsAcmDriver;
    {DP:METHOD
      Closes installable ACM driver opened previously with openDriver();
    }
    procedure closeDriver(driver: unaMsAcmDriver);
    //
    {DP:METHOD
      Allocates given ACMFORMATDETAILS structure.
    }
    function preparePafd(var pafd: ACMFORMATDETAILS; tag: unsigned = 0; index: unsigned = 0; driver: unsigned = 0): bool;
    //
    {DP:METHOD
      Version of ACM.
    }
    property version: unsigned read f_version;
    //
    {DP:METHOD
      Total number of enabled global ACM drivers (of all support types) in the system.
    }
    property countDrivers   : unsigned index ACM_METRIC_COUNT_DRIVERS    read getACMCount;
    {DP:METHOD
      Number of global ACM compressor or decompressor drivers in the system.
    }
    property countCodecs    : unsigned index ACM_METRIC_COUNT_CODECS     read getACMCount;
    {DP:METHOD
      Number of global ACM converter drivers in the system.
    }
    property countConverters: unsigned index ACM_METRIC_COUNT_CONVERTERS read getACMCount;
    {DP:METHOD
      Number of global ACM filter drivers in the system.
    }
    property countFilters   : unsigned index ACM_METRIC_COUNT_FILTERS    read getACMCount;
    {DP:METHOD
      Number of global disabled ACM drivers (of all support types) in the system.
    }
    property countDisabled  : unsigned index ACM_METRIC_COUNT_DISABLED   read getACMCount;
    {DP:METHOD
      Number of global ACM hardware drivers in the system.
    }
    property countHardware  : unsigned index ACM_METRIC_COUNT_HARDWARE   read getACMCount;
    {DP:METHOD
      Total number of enabled local ACM drivers (of all support types) for the calling task.
    }
    property countLocalDrivers   : unsigned index ACM_METRIC_COUNT_LOCAL_DRIVERS    read getACMCount;
    {DP:METHOD
      Number of local ACM compressor drivers, ACM decompressor drivers, or both for the calling task.
    }
    property countLocalCodecs    : unsigned index ACM_METRIC_COUNT_LOCAL_CODECS     read getACMCount;
    {DP:METHOD
      Number of local ACM converter drivers for the calling task.
    }
    property countLocalConverters: unsigned index ACM_METRIC_COUNT_LOCAL_CONVERTERS read getACMCount;
    {DP:METHOD
      Number of local ACM filter drivers for the calling task.
    }
    property countLocalFilters   : unsigned index ACM_METRIC_COUNT_LOCAL_FILTERS    read getACMCount;
    {DP:METHOD
      Total number of local disabled ACM drivers, of all support types, for the calling task.
    }
    property countLocalDisabled  : unsigned index ACM_METRIC_COUNT_LOCAL_DISABLED   read getACMCount;
  end;



  unaMsAcmStreamDevice = class;

  //
  // -- unaMsAcmStreamHeader --
  //
  {DP:CLASS
    Base class for storing the wave and stream headers of wave and ACM devices.
  }
  unaMsAcmDeviceHeader = class(unaObject)
  private
    f_device: unaMsAcmStreamDevice;
    f_num: unsigned;
    f_needRePrepare: bool;
    f_isFree: bool;
    f_gate: unaInProcessGate;
    //
  protected
    {DP:METHOD
      Returns status of header. Descendant classes must override this method.
    }
    function getStatus(index: int): bool; virtual; abstract;
    {DP:METHOD
      Sets status of header. Descendant classes must override this method.
    }
    procedure setStatus(index: int; value: bool); virtual; abstract;
    //
    {DP:METHOD
      Prepares the header before first usage. This class calls prepareHeader() method of device to do this.
    }
    function prepare(): MMRESULT; virtual;
    {DP:METHOD
      Unprepares the header before first usage. This class calls unprepareHeader() method of device to do this.
    }
    function unprepare(): MMRESULT; virtual;
    {DP:METHOD
      Prepares the header after it was used once or more.
    }
    procedure rePrepare(); virtual;
    //
    {DP:METHOD
      Returns true if header contains data what was produced or used by device and can be changed or re-used. Descendant classes must override this method.
    }
    function isDoneHeader(): bool; virtual; abstract;
    function isInQueue(): bool; virtual; abstract;
    //
    function enter(timeout: unsigned): bool;
    procedure leave();
  public
    {DP:METHOD
      Creates device buffer header. This buffer is used to pass data to and from device.
    }
    constructor create(device: unaMsAcmStreamDevice);
    procedure AfterConstruction(); override;
    procedure BeforeDestruction(); override;
    //
    property isFree: bool read f_isFree write f_isFree;
  end;


  {DP:METHOD
    This event is used to inform the class owner about new data when it becomes available.
    It should be used only with classes which produces the data (like unaWaveInDevice or unaMsAcmCodec).
  }
  unaWaveDataEvent = procedure (sender: tObject; data: pointer; size: unsigned) of object;

  // --  --
  unaWaveInOnThresholdEvent = procedure (sender: tObject; var passThrough: bool) of object;

  //
  unaWaveInSDMehtods = (unasdm_none, unasdm_VC, unasdm_DSP);

  {$IFDEF UNA_VC_ACMCLASSES_USE_DSP }
  //
  unaDspSignalData 	= array[byte] of pdspl_float;
  unaDspSignalDataSize	= array[byte] of uint;
  {$ENDIF }

  //
  // -- unaMsAcmStreamDevice --
  //
  {DP:CLASS
    This is abstract class used as a base for classes dealing with audio streams (codecs, waveIn and waveOut, mixers).

    <P />Before opening stream device you should specify source and destination formats of audio streams device will work with.
    Method setFormat() will be called to set up source and destination format structures. You can access these structures later using the srcFormat and dstFormat properties.
    They are pointers on WAVEFORMATEX and should be treated as read-only data. Destructor takes care about releasing these structures.

    <P />All stream processing is done chunk by chunk. Chunk is the minimal amount of data which can be processed once in a time.
    Chunk size is calculated automatically, and it will be enough to hold about 1/10 of second of audio. Use chunkSize property to examine current size of chunk.

    <P />Since processing the audio stream could take some time, unaMsAcmStreamDevice has build-in mechanism which prevents stream overloading.
    Use the checkOverload property to enable or disable this mechanism. numOverload property specifies maximum number of unprocessed chunks in output or input stream.
    When actual number reaches this value, all new chunks will be discarded, until there will be enough space in the stream to put new chunk of data.

    <P />inBytes and outBytes properties holds the amount of audio data written to and read from device.
  }
  unaMsAcmStreamDevice = class(unaThread)
  private
    f_handle: unsigned;
    f_inBytes: int64;
    f_outBytes: int64;
    f_skipTotal: int64;
    f_closing: bool;
    f_flushing: bool;
    f_realtime: bool;
    f_chunkSize: unsigned;
    f_dstChunkSize: unsigned;
    f_chunkPerSecond: unsigned;
    f_flushBeforeClose: bool;
    //
    f_inProgress: unsigned;	// number of headers in queue (our version)
    f_srcFormatInfo: string;
    f_dstFormatInfo: string;
    f_options: unsigned;
    f_inOverCN: unsigned;	// in chunks (0 - do not check)
    f_outOverCN: unsigned;	// in chunks (0 - do not check)
    f_inOverSize: unsigned;	// in bytes
    f_outOverSize: unsigned;	// in bytes
    f_inOverloadTotal: int64;		// total amount of in-data skipped due to overload
    f_outOverloadTotal: int64;		// total amount of out-data skipped due to overload
    f_careInStreamDestroy: bool;
    f_careOutStreamDestroy: bool;
    f_inStreamIsunaMemoryStream: bool;
    f_outStreamIsunaMemoryStream: bool;
    //
    f_waitInterval: unsigned;
    //
    f_savedCV: bool;	// this is used by some devices when they change CV value
    f_calcVolume: bool;
{$IFDEF VCX_DEMO }
    f_headersServed: int64;
{$ENDIF}
    f_volume: array[byte] of uint;
    f_prevVolume: array[byte] of uint;
    //
    f_onDA: unaWaveDataEvent;
    //
    f_lastHeaderNum: unsigned;
    f_lastDoneHeaderNum: unsigned;
    //

⌨️ 快捷键说明

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