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

📄 unamsacmclasses.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    //
    function afterOpen(): MMRESULT; override;
    //
    function prepareHeader(header: unaMsAcmDeviceHeader): MMRESULT; override;
    function unprepareHeader(header: unaMsAcmDeviceHeader): MMRESULT; override;
    function addHeader(header: unaWaveHeader): MMRESULT; override;
    //
    function onHeaderDone(header: unaWaveHeader; wakeUpByHeaderDone: bool): bool; override;
    {DP:METHOD
      Displays a format choose dialog.
      Reallocates (if necessary) the given format.
    }
    function formatChooseDef2(var format: pWAVEFORMATEX): MMRESULT; override;
    {DP:METHOD
      Returns true.
    }
    function getMasterIsSrc2(): bool; override;
    {DP:METHOD
      Flushes all data pending to be played back.
    }
    function flush2(waitForComplete: bool = true): bool; override;
  public
    constructor create(deviceID: unsigned = WAVE_MAPPER; mapped: bool = false; direct: bool = false; overNum: unsigned = 0);
    procedure AfterConstruction(); override;
    //
    function getCaps(): pWAVEOUTCAPSW; overload;
    // -- class functions --
    class function getCaps(deviceID: unsigned; var caps: WAVEOUTCAPSW): bool; overload;
    class function getDeviceCount(): unsigned;
    class function getErrorText(errorCode: MMRESULT): string;
    //
    function formatChoose(var format: pWAVEFORMATEX; const title: string = ''; style: unsigned = ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT; enumFlag: unsigned = ACM_FORMATENUMF_HARDWARE + ACM_FORMATENUMF_OUTPUT; enumFormat: pWAVEFORMATEX = nil): MMRESULT;
    {DP:METHOD
      Not supported yet. Use getVolume() instead.
    }
    property volume: unsigned read getDeviceVolume write setDeviceVolume;
    {DP:METHOD
      Not supported yet.
    }
    property pitch: unsigned read getPitch write setPitch;
    {DP:METHOD
      Not supported yet.
    }
    property playbackRate: unsigned read getPlaybackRate write setPlaybackRate;
    {DP:METHOD
      Amount of audio data which appear too late to be played back in real time.
    }
    property outOfData: int64 read f_outOfData;
    {DP:METHOD
      Fires every time new chunk was feed to wave-out device.
    }
    property onAfterChunkFeed: unaWaveDataEvent read f_onACF write f_onACF;
    {DP:METHOD
      Fires every time chunk was just played out by wave-out device.
    }
    property onAfterChunkDone: unaWaveDataEvent read f_onACD write f_onACD;
  end;


  unaMMTimer = class;

  //
  // -- unaWaveSoftwareDevice --
  //
  {DP:CLASS
    This is base class for software devices, such as wave mixer.
  }
  unaWaveSoftwareDevice = class(unaWaveDevice)
  private
    f_realTimerCount: unsigned;
    //
    f_realTimer: unaAbstractTimer;
    f_nonrealTimeDelay: unsigned;
    //
    procedure onTick(sender: tObject);
    procedure checkRealTimer();
    procedure adjustRTInterval(isSrc: bool);
  protected
    {DP:METHOD
      WARNING! this call will change the realtime clock interval.
      <BR />so, be careful when setting the format of realtime devices with non-default timer interval.
    }
    function setFormatEx(isSrc: bool; const format: WAVEFORMATEX): bool; override;
    procedure setRealTime(value: bool); override;
    //
    function prepareHeader(header: unaMsAcmDeviceHeader): MMRESULT; override;
    function unprepareHeader(header: unaMsAcmDeviceHeader): MMRESULT; override;
    //
    function afterOpen(): MMRESULT; override;
    procedure afterClose(closeResult: MMRESULT); override;
    function open2(query: bool = false; timeout: unsigned = 10000; flags: unsigned = 0): MMRESULT; override;
    //
    function addHeader(header: unaWaveHeader): MMRESULT; override;
    function onHeaderDone(header: unaWaveHeader; wakeUpByHeaderDone: bool): bool; override;
    {DP:METHOD
      Returns true.
    }
    function getMasterIsSrc2(): bool; override;
  public
    constructor create(realTime: bool = false; isIn: bool = true; overNum: unsigned = 0);
    destructor Destroy(); override;
    procedure AfterConstruction(); override;
    //
    property realTimer: unaAbstractTimer read f_realTimer;
  end;


  unaOnRiffStreamIsDone = procedure(sender: tObject) of object;

  //
  // -- unaRiffStream --
  //
  {DP:CLASS
    RIFF WAVE stream.
    <BR>Use this class to read or create RIFF WAVE files.
    <BR>Non-PCM files will be automatically converted to PCM format when reading.
    <BR>Creation of non-PCM files is also possible.
  }
  unaRiffStream = class(unaWaveSoftwareDevice)
  private
    f_realTimeFeedSize: unsigned;
    f_status: int;
    //
    f_streamSize: unsigned;
    f_streamPos: unsigned;
    f_streamPosHistory: unsigned;
    f_readingIsDone: bool;
    f_streamIsDone: bool;
{$IFDEF VCX_DEMO }
    f_headersServedRiff: int;
{$ENDIF}
    f_fileName: wideString;
    //
    f_originalSize: unsigned;
    f_dataSizeOfs: unsigned;
    f_riffSrcFormat: pWAVEFORMATEX;
    f_riffDstFormatTag: unsigned;
    //
    f_srcChunk: pointer;
    f_dstChunk: pointer;
    //
    f_loop: bool;
    f_dataChunk: unaRiffChunk;
    f_dataChunkOfs: unsigned;
    // input
    f_acm: unaMsAcm;
    f_riff: unaRIFile;
    f_codec: unaMsAcmCodec;
    f_playbackHistory: unaList;
    // output
    f_riffStream: unaFileStream;
    //
    f_onStreamIsDone: unaOnRiffStreamIsDone;
    //
    function browseRiff(chunk: unaRiffChunk; options: unsigned): bool;
    procedure clearPlaybackHistory();
    procedure setStreamPos(value: unsigned);
    function readNextChunk(): bool;
  protected
    function afterOpen(): MMRESULT; override;
    procedure afterClose(closeResult: MMRESULT); override;
    function onHeaderDone(header: unaWaveHeader; wakeUpByHeaderDone: bool): bool; override;
    {DP:METHOD
      Forces all awaiting data to be resampled.
    }
    function flush2(waitForComplete: bool = true): bool; override;
    {DP:METHOD
      Returns current position in wav stream.
    }
    function doGetPosition(): int64; override;
  public
    {DP:METHOD
      Opens existing RIFF WAVE file for reading.
    }
    constructor create(const fileName: wideString; realTime: bool = false; loop: bool = false; acm: unaMsAcm = nil);
    {DP:METHOD
      Creates new RIFF WAVE file for writing.
    }
    constructor createNew(const fileName: wideString; const srcFormat: WAVEFORMATEX; dstFormatTag: unsigned = WAVE_FORMAT_PCM; acm: unaMsAcm = nil);
    //
    destructor Destroy(); override;
    procedure AfterConstruction(); override;
    //
    {DP:METHOD
      Assigns new existing RIFF WAVE file for reading.
    }
    function assignRIFile(const fileName: wideString): int;
    {DP:METHOD
      Assigns ouput file for writing.
    }
    function assignRIFileWrite(const fileName: wideString; const srcFormat: WAVEFORMATEX; dstFormatTag: unsigned = WAVE_FORMAT_PCM): int; overload;
    {DP:METHOD
      Assigns ouput file for writing.
    }
    function assignRIFileWrite(const fileName: wideString; dstFormat: pWAVEFORMATEX): int; overload;
    //
    procedure passiveOpen();
    function readData(buf: pointer; maxSize: unsigned): unsigned;
    //
    {DP:METHOD
    <PRE>
4	- output riff: cannot locate required codec format
3	- output riff: cannot locate required codec
2	- output riff: cannot create output stream
1	- output riff: OK
-------
0	- input riff: OK
-1	- input riff: file is not valid RIFF
-2	- input riff: file is valid RIFF file, but is not a valid WAVE file
-3	- input riff: not acm was specified (but it is required for conversion)
-4	- input riff: unknown driver (cannot locate MS ACM codec)
-5	- input riff: unknown format (for selected MS ACM codec)
$0FFFFFFF - no init
    </PRE>
    }
    property status: int read f_status;
    {DP:METHOD
      Codec used for compression or decompression.
    }
    property codec: unaMsAcmCodec read f_codec;
    {DP:METHOD
      WAV file name.
    }
    property fileName: wideString read f_fileName;
    {DP:METHOD
      WAVe stream size in bytes.
    }
    property streamSize: unsigned read f_streamSize;
    {DP:METHOD
      Current position in WAVe stream in bytes.
    }
    property streamPosition: unsigned read f_streamPos write setStreamPos;
    {DP:METHOD
      True when no more data can be read from stream (and loop = false).
    }
    property streamIsDone: bool read f_streamIsDone;
    {DP:METHOD
      Number of bytes in the input WAVE file.
    }
    property originalSize: unsigned read f_originalSize;
    {DP:METHOD
      Set this property to true if you wish to loop the file reading operation from end to beginning.
    }
    property loop: bool read f_loop write f_loop;
    //
    property onStreamIsDone: unaOnRiffStreamIsDone read f_onStreamIsDone write f_onStreamIsDone;
  end;


  //
  // -- unaWaveMultiStreamDevice --
  //
  {DP:CLASS
    This is base class for devices working with more than two streams.
  }
  unaWaveMultiStreamDevice = class(unaWaveSoftwareDevice)
  private
    f_streams: unaObjectList;
    f_autoAddSilence: bool;
  protected
    procedure action(stream: unaAbstractStream); virtual;
    function pump2(size: unsigned = 0): unsigned; virtual;
  public
    constructor create(realTime: bool = false; autoAddSilence: bool = true; overNum: unsigned = 0);
    destructor Destroy(); override;
    //
    function addStream(stream: unaAbstractStream = nil): unaAbstractStream;
    function removeStream(stream: unaAbstractStream = nil): bool;
    function getStream(index: int): unaAbstractStream;
    function getStreamCount(): unsigned;
    //
    function pump(size: unsigned = 0): unsigned;
    //
    property addSilence: bool read f_autoAddSilence write f_autoAddSilence;
  end;


  //
  // -- unaWaveMixDevice --
  //
  {DP:CLASS
    This class performs software mixing of input streams.
  }
  unaWaveMixerDevice = class(unaWaveMultiStreamDevice)
  private
    f_bufSrc: pArray;
    f_bufDst: pArray;
    f_lastBufSrcSize: unsigned;
    f_lastBufDstSize: unsigned;
  protected
    function onHeaderDone(header: unaWaveHeader; wakeUpByHeaderDone: bool): bool; override;
  public
    destructor Destroy(); override;
    //
    procedure mix();
  end;


  //
  // -- unaWaveExclusiveMixerDevice --
  //
  {DP:CLASS
    This class performs exclusive mixing of input streams.
  }
  unaWaveExclusiveMixerDevice = class(unaWaveMultiStreamDevice)
  private
    f_buf: pArray;
    f_bufSMX: pArray;
    f_lastBufSize: unsigned;
    f_lastBuffSMXSize: unsigned;
    //
    function getSize(): unsigned;
  protected
    function pump2(size: unsigned = 0): unsigned; override;
  public
    destructor Destroy(); override;
  end;


  //
  // -- unaWaveResampler --
  //

  {DP:CLASS
    This class can resample audio stream from one PCM format to another.
    <BR />It does not use ACM codecs.
    <BR />8, 16 and 32 bits samples with virtually unlimited number of channels and samples per second are supported.
  }
  unaWaveResampler = class(unaWaveSoftwareDevice)
  private
    f_srcChunk: unaPCMChunk;
    f_dstChunk: unaPCMChunk;
    f_volume:  array[byte] of uint;
    f_needVolumeAdjust: bool;
  protected
    function onHeaderDone(header: unaWaveHeader; wakeUpByHeaderDone: bool): bool; override;
    {DP:METHOD
      Returns false.
    }
    function getMasterIsSrc2(): bool; override;
    {DP:METHOD
      Forces all awaiting data to be resampled.
    }
    f

⌨️ 快捷键说明

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