📄 unamsacmclasses.pas
字号:
(*
----------------------------------------------
unaMsAcmClasses.pas - MS ACM classes
Voice Communicator components version 2.5
----------------------------------------------
This source code cannot be used without
proper permission granted to you as a private
person or an entity by the Lake of Soft, Ltd
Visit http://lakeofsoft.com/ for details.
Copyright (c) 2001, 2007 Lake of Soft, Ltd
All rights reserved
----------------------------------------------
created by:
Lake, 01 Jan 2002
modified by:
Lake, Jan-Dec 2002
Lake, Jan-Dec 2003
Lake, Jan-Dec 2004
Lake, Jan-Oct 2005
Lake, Mar-Apr 2007
----------------------------------------------
*)
{$I unaDef.inc}
{xx $DEFINE UNA_VC_USE_GLOBAL_MEM } // define to enable Global memory allocation for ACM headers
{$DEFINE UNA_VC_ACMCLASSES_USE_DSP } // define to link with DSPDlib modules
unit
unaMsAcmClasses;
{DP:UNIT
Contains Microsoft ACM wrapper and wave device classes.
}
interface
{$IFDEF DEBUG }
// low level debug, do not use
{x $DEFINE DEBUG_LOG }
{x $DEFINE DEBUG_LOG_RT }
{x $DEFINE DEBUG_LOG_MIXER }
{$ENDIF }
uses
Windows, unaTypes, MMSystem, unaMsAcmAPI,
unaUtils, unaClasses, unaWave, unaRiff, unaOpenH323PluginAPI, unaBladeEncAPI, unaEncoderAPI,
{$IFDEF UNA_PROFILE }
unaProfile,
{$ENDIF}
{$IFDEF __SYSUTILS_H_ }
SysUtils, Math,
{$ENDIF}
{$IFDEF UNA_VC_ACMCLASSES_USE_DSP }
unaDspLibH, unaDSPDLib, unaDspLibAutomation,
{$ENDIF }
unaPlacebo;
var
// number of chunks to be processed per second (in real time mode)
//
// default value was changed from 20 to 25 (for 11025 rate to be handled better)
c_defChunksPerSecond: unsigned = 25;
// number of chunks which should be present in input buffer
// of waveOutDevice component, before actual driver will be feeded with data
// (helps avoid cuts, but increases the latency)
// default value is 2
c_defPlaybackChunksAheadNumber: unsigned = 2;
// limits the number of chunks which can be feed ahead to waveOut driver
// default value is c_defPlaybackChunksAheadNumber + 2
c_def_max_playbackChunksAheadNumber: unsigned = 2 + 2;
// number of chunks to put into waveIn recording queue
// (does not afftect the latency)
// default value is 5
c_defRecordingChunksAheadNum: unsigned = 5;
const
//
c_defSamplingSamplesPerSec = 44100;
c_defSamplingBitsPerSample = 16;
c_defSamplingNumChannels = 2;
//
{$IFDEF UNA_PROFILE}
var
profId_unaMsAcmStreamDevice_internalWrite: unsigned;
profId_unaMsAcmStreamDevice_internalRead: unsigned;
profId_unaMsAcmStreamDevice_getDataAvail: unsigned;
profId_unaMsAcmStreamDevice_locateHeader: unsigned;
profId_unaMsAcmCodec_insideCodec: unsigned;
profId_unaWaveExclusiveMixer_pump: unsigned;
{$ENDIF}
type
//
// -- --
//
tunaAcmDetailsType = (
uadtUnused,
uadtFilterDetails,
uadtFormatDetails
);
punaAcmDetails = ^unaAcmDetails;
unaAcmDetails = record
r_type: tunaAcmDetailsType;
case tunaAcmDetailsType of
uadtUnused: (r_unused: unsigned);
uadtFilterDetails: (
r_filterDetails: ACMFILTERDETAILS;
);
uadtFormatDetails: (
r_formatDetails: ACMFORMATDETAILS;
);
end;
//
// -- unaMsAcmObject --
//
unaMsAcmDriver = class;
unaMsAcmObjectTag = class;
{DP:CLASS
This base class is designed to store the MS ACM objects, such as formats and filters.
}
unaMsAcmObject = class(unaObject)
private
f_driver: unaMsAcmDriver;
f_details: unaAcmDetails;
f_tag: unaMsAcmObjectTag;
protected
procedure deleteDetails(); virtual;
public
constructor create(); overload; virtual;
constructor create(tag: unaMsAcmObjectTag); overload;
procedure BeforeDestruction(); override;
//
{DP:METHOD
Returns details stored in this object.
}
function getDetails(): punaAcmDetails;
//
property tag: unaMsAcmObjectTag read f_tag;
end;
//
// -- unaMsAcmFilter --
//
{DP:METHOD
This class stores information about the given MS ACM filter.
}
unaMsAcmFilter = class(unaMsAcmObject)
private
public
constructor create(); overload; override;
constructor create(tag: unaMsAcmObjectTag; const details: ACMFILTERDETAILS); overload;
end;
//
// -- unaMsAcmFormat --
//
{DP:METHOD
This class stores information about the given MS ACM format.
}
unaMsAcmFormat = class(unaMsAcmObject)
public
constructor create(); overload; override;
constructor create(tag: unaMsAcmObjectTag; const details: ACMFORMATDETAILS); overload;
//
function formatChoose(var buf: ACMFORMATCHOOSE; const title: string = ''): MMRESULT;
end;
//
// -- unaMsAcmObjectTag --
//
{DP:METHOD
This base class is designed to store the information about MS ACM object tag, such as format tag and filter tag.
}
unaMsAcmObjectTag = class(unaObject)
private
f_driver: unaMsAcmDriver;
public
constructor create(driver: unaMsAcmDriver); overload;
end;
//
// -- unaMsAcmFilterTag --
//
{DP:METHOD
This class stores information about the given MS ACM format tag.
}
unaMsAcmFilterTag = class(unaMsAcmObjectTag)
private
f_tag: ACMFILTERTAGDETAILS;
public
constructor create(driver: unaMsAcmDriver; const tag: ACMFILTERTAGDETAILS); overload;
//
property tag: ACMFILTERTAGDETAILS read f_tag;
end;
//
// -- unaMsAcmFormatTag --
//
{DP:METHOD
This class stores information about the given MS ACM format tag.
}
unaMsAcmFormatTag = class(unaMsAcmObjectTag)
private
f_tag: ACMFORMATTAGDETAILS;
public
constructor create(driver: unaMsAcmDriver; const tag: ACMFORMATTAGDETAILS); overload;
//
property tag: ACMFORMATTAGDETAILS read f_tag;
end;
//
// -- unaMsAcmDriver --
//
unaMsAcm = class;
unaWaveDevice = class;
{DP:CLASS
List of installed drivers is maintained by <a href="#class_unaMsAcm">unaMsAcm</a> class, so usually there is no need to create/destroy the driver class explicitly.
Use the unaMsAcm.getDriver() method instead.
<P />Driver has lists of associated wave formats and filters.
You should explicitly call enumFilters() or enumFormats() to enumerate the filters and formats supported by driver. Driver will be opened for enumeration purposes.
Explicitly opening the driver by calling the open() method ensures the driver handle will be valid until class is destroyed, or method close() is called.
<P />Use getDetails() method to retrieve pointer on ACMDRIVERDETAILSW structure. You should treat this structure as read-only.
}
unaMsAcmDriver = class(unaObject)
private
f_details: ACMDRIVERDETAILSW;
f_detailsValid: bool;
//
f_id: HACMDRIVERID;
//
f_isInstallable: bool;
f_libName: wideString;
f_refCount: int;
//
f_handle: HACMDRIVER;
f_support: unsigned;
f_maxWaveFormatSize: unsigned;
f_enumFormatsFlag: unsigned;
//
f_formatWasEnum: bool;
f_formatLastEnumFlags: unsigned;
f_formatLastEnumWave: WAVEFORMATEX;
f_formatLastEnumTagsOnly: bool;
//
f_filters: unaObjectList;
f_filterTags: unaObjectList;
f_formats: unaObjectList;
f_formatTags: unaObjectList;
f_acm: unaMsAcm;
//
procedure addFilter(tag: unaMsAcmObjectTag; const pafd: ACMFILTERDETAILS);
procedure addFormat(tag: unaMsAcmObjectTag; const pafd: ACMFORMATDETAILS);
procedure fillDetails();
protected
function isMyLib(const libName: wideString): bool;
function refInc(delta: int): int;
public
{DP:METHOD
Initializes the instance of MS ACM driver object. id parameters specifies the ID of driver to use.
}
constructor create(acm: unaMsAcm; id: HACMDRIVERID; support: unsigned; const libName: wideString = '');
destructor Destroy(); override;
//
procedure AfterConstruction(); override;
procedure BeforeDestruction(); override;
// -- enum --
{DP:METHOD
Enumerates waveform-audio filters available from the ACM driver.
Enumerated filters will be stored in the filters list. You can access them using getFilter() method.
}
function enumFilters(flags: unsigned = 0): MMRESULT;
{DP:METHOD
Enumerates waveform-audio formats available from the ACM driver.
You can specify any combination of the following values for flags parameter:
<UL>
<LI>ACM_FORMATENUMF_HARDWARE - The enumerator should only enumerate formats that are supported as native input or output formats on one or more of the installed waveform-audio devices.</LI>
<LI>ACM_FORMATENUMF_INPUT - Enumerator should enumerate only formats that are supported for input (recording).</LI>
<LI>ACM_FORMATENUMF_NCHANNELS - The nChannels member of the WAVEFORMATEX structure pointed to by the pwfx parameter is valid. The enumerator will enumerate only a format that conforms to this attribute.</LI>
<LI>ACM_FORMATENUMF_NSAMPLESPERSEC - The nSamplesPerSec member of the WAVEFORMATEX structure pointed to by the pwfx parameter is valid. The enumerator will enumerate only a format that conforms to this attribute.</LI>
<LI>ACM_FORMATENUMF_OUTPUT - Enumerator should enumerate only formats that are supported for output (playback).</LI>
<LI>ACM_FORMATENUMF_WBITSPERSAMPLE - The wBitsPerSample member of the WAVEFORMATEX structure pointed to by the pwfx parameter is valid. The enumerator will enumerate only a format that conforms to this attribute.</LI>
<LI>ACM_FORMATENUMF_WFORMATTAG - This is default flag, and you should use it in most cases.</LI>
</UL>
Enumerated formats will be stored in the formats list. You can access them using getFormat() method.
}
function enumFormats(flags: unsigned = 0; force: bool = false; pwfx: pWAVEFORMATEX = nil; tagsOnly: bool = false): MMRESULT;
// -- handle --
{DP:METHOD
Opens the ACM driver.
<P />Installabe drivers need not to be opened.
}
function open(): MMRESULT;
{DP:METHOD
Closes a previously opened ACM driver instance.
}
function close(): MMRESULT;
{DP:METHOD
Returns true if driver was successfully opened or false otherwise.
}
function isOpen(): bool;
{DP:METHOD
Returns driver handle returned by acmDriverOpen() function
}
function getHandle(): HACMDRIVER;
{DP:METHOD
Sends a message to installed or opened driver.
}
function sendDriverMessage(msg: UINT; lParam1: LongInt; lParam2: Longint = 0): Longint;
//
{DP:METHOD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -