Description | Hierarchy | Fields | Methods | Properties |
type unaMsAcmStreamDevice = class(unaThread)
This is abstract class used as a base for classes dealing with audio streams (codecs, waveIn and waveOut, mixers).
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.
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.
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.
inBytes and outBytes properties holds the amount of audio data written to and read from device.
constructor create(createInStream: bool = true; createOutStream: bool = true; inOverNum: unsigned = 0; outOverNum: unsigned = 0; calcVolume: bool = false); |
|
destructor Destroy(); override; |
|
function addConsumer(device: unaMsAcmStreamDevice; removeOutStream: bool = true): unsigned; |
|
function assignStream(streamClass: unaAbstractStreamClass; isInStream: bool; careDestroy: bool = true): unaAbstractStream; overload; |
|
function assignStream(isInStream: bool; stream: unaAbstractStream; careDestroy: bool = false): unaAbstractStream; overload; |
|
function close(timeout: tTimeout = 10012): MMRESULT; |
|
function flush(waitForComplete: bool = true): bool; |
|
function formatChooseDef(var format: pWAVEFORMATEX): MMRESULT; |
|
function getDataAvailable(isIn: bool): unsigned; |
|
function getErrorText(errorCode: MMRESULT): string; |
|
function getMasterIsSrc(): bool; |
|
function getPosition(): int64; |
|
function getPrevVolume(channel: unsigned = $FFFFFFFF): unsigned; |
|
function getUnVolume(channel: unsigned = $FFFFFFFF): unsigned; |
|
function getVolume(channel: unsigned = $FFFFFFFF): unsigned; |
|
function isOpen(): bool; |
|
function okToRead(): bool; |
|
function open(query: bool = false; timeout: tTimeout = 10002; flags: uint = 0; startDevice: bool = true): MMRESULT; |
|
function read(buf: pointer; size: unsigned = 0): unsigned; |
|
function removeConsumer(device: unaMsAcmStreamDevice): bool; |
|
function waitForData(waitForInData: bool; timeout: tTimeout; expectedDataSize: unsigned = 0): bool; |
|
function write(buf: pointer; size: unsigned): unsigned; |
|
function afterOpen(): MMRESULT; virtual; |
|
function beforeNewChunk(data: pointer; size: unsigned; formatExt: PWAVEFORMATEXTENSIBLE): bool; virtual; |
|
function close2(timeout: tTimeout = 10011): MMRESULT; virtual; |
|
function doClose(timeout: tTimeout = 1): MMRESULT; virtual; |
|
function doGetErrorText(errorCode: MMRESULT): string; virtual; |
|
function doGetPosition(): int64; virtual; |
|
function doOpen(flags: uint): MMRESULT; virtual; |
|
function doWrite(buf: pointer; size: unsigned): unsigned; virtual; |
|
function flush2(waitForComplete: bool = true): bool; virtual; |
|
function formatChooseDef2(var format: pWAVEFORMATEX): MMRESULT; dynamic; |
|
function getDspProperty(isLD: bool; propID: unsigned; def: int = 0): int; overload; |
|
function getDspProperty(isLD: bool; propID: unsigned; const def: float = 0.0): float; overload; |
|
function getMasterIsSrc2(): bool; virtual; abstract; |
|
function getProviderFormat(): PWAVEFORMATEXTENSIBLE; virtual; |
|
function open2(query: bool = false; timeout: tTimeout = 10001; flags: uint = 0; startDevice: bool = true): MMRESULT; virtual; |
|
function prepareHeader(header: pointer): MMRESULT; virtual; abstract; |
|
function setFormat(isSrc: bool; const format: aString): bool; overload; |
|
function setFormat(isSrc: bool; format: pWAVEFORMATEX): bool; overload; virtual; |
|
function setFormatExt(isSrc: bool; const formatExt: string): bool; overload; |
|
function setFormatExt(isSrc: bool; formatExt: PWAVEFORMATEXTENSIBLE): bool; overload; virtual; |
|
function unprepareHeader(header: pointer): MMRESULT; virtual; abstract; |
|
procedure AfterConstruction(); override; |
|
procedure BeforeDestruction(); override; |
|
procedure setVolume100(channel: int = -1; volume: unsigned = 100); |
|
procedure afterClose(closeResult: MMRESULT); virtual; |
|
procedure removeHeader(var header: pointer); virtual; abstract; |
|
procedure setDspProperty(isLD: bool; propID: unsigned; const value: float); overload; |
|
procedure setDspProperty(isLD: bool; propID: unsigned; value: int); overload; |
|
procedure setRealTime(value: bool); virtual; |
|
procedure startIn(); override; |
|
procedure startOut(); override; |
property calcVolume: bool read f_calcVolume write setCalcVolume; |
|
property channelConsumeMask: int read f_channelConsumeMask write f_channelConsumeMask; |
|
property channelMixMask: int read f_channelMixMask write f_channelMixMask; |
|
property chunkPerSecond: unsigned read f_chunkPerSecond; |
|
property chunkSize: unsigned read f_chunkSize; |
|
property dstChunkSize: unsigned read f_dstChunkSize; |
|
property dstFormatExt: PWAVEFORMATEXTENSIBLE read f_dstFormatExt; |
|
property dstFormatInfo: string read f_dstFormatInfo; |
|
property flushBeforeClose: bool read f_flushBeforeClose write f_flushBeforeClose; |
|
property handle: unsigned read f_handle; |
|
property inBytes: int64 read f_inBytes; |
|
property inOverloadTotal: int64 read f_inOverloadTotal; |
|
property inProgress: unsigned read f_inProgress; |
|
property inStream: unaAbstractStream read f_inStream; |
|
property isSilence: bool read f_isSilence; |
|
property minActiveTime: unsigned read f_minAT write f_minAT; |
|
property minVolumeLevel: unsigned read f_minVL write setMinVL; |
|
property onDataAvailable: unaWaveDataEvent read f_onDA write f_onDA; |
|
property onGetProviderFormat: unaWaveGetProviderFormatEvent read f_onGetProviderFormat write f_onGetProviderFormat; |
|
property onThreshold: unaWaveOnThresholdEvent read f_onThreshold write f_onThreshold; |
|
property outBytes: int64 read f_outBytes; |
|
property outOverloadTotal: int64 read f_outOverloadTotal; |
|
property outStream: unaAbstractStream read f_outStream; |
|
property overNumIn: unsigned read f_inOverCN write setInOverCN; |
|
property overNumOut: unsigned read f_outOverCN write setOutOverCN; |
|
property realTime: bool read f_realTime write setRealTime; |
|
property silenceDetectionMode: unaWaveInSDMethods read f_sdm write f_sdm; |
|
property srcFormatExt: PWAVEFORMATEXTENSIBLE read f_srcFormatExt; |
|
property srcFormatInfo: string read f_srcFormatInfo; |
constructor create(createInStream: bool = true; createOutStream: bool = true; inOverNum: unsigned = 0; outOverNum: unsigned = 0; calcVolume: bool = false); |
|
Initializates class instance. |
destructor Destroy(); override; |
|
function addConsumer(device: unaMsAcmStreamDevice; removeOutStream: bool = true): unsigned; |
|
Adds a new consumer for device output. All data produced by device will be passed to all consumers added by this method. If you wish to destroy the output stream leave the default true value for removeOutStream parameter. (Stream will be destroyed only if it was not a stream assigned by assignStream() with careDestroy = false). |
function assignStream(streamClass: unaAbstractStreamClass; isInStream: bool; careDestroy: bool = true): unaAbstractStream; overload; |
|
Assigns input or output stream for device. Stream will be created using the provided stream class. If you wish the device to destroy the stream in own destructor - specify true in careDestroy parameter. |
function assignStream(isInStream: bool; stream: unaAbstractStream; careDestroy: bool = false): unaAbstractStream; overload; |
|
Assigns input or output stream for device. You can specify nil as stream to disable the input/output. If you wish the device to destroy the stream in own destructor - specify true in careDestroy parameter. |
function close(timeout: tTimeout = 10012): MMRESULT; |
|
Closes the device. |
function flush(waitForComplete: bool = true): bool; |
|
function formatChooseDef(var format: pWAVEFORMATEX): MMRESULT; |
|
Default implementation of format choosing routine. |
function getDataAvailable(isIn: bool): unsigned; |
|
Returns number of bytes available to read from the device. |
function getErrorText(errorCode: MMRESULT): string; |
|
Returns error message text corresponding to given errorCode parameter. |
function getMasterIsSrc(): bool; |
|
Returns true if device is output device (playback or codec). Returns false if device is input device (recording). |
function getPosition(): int64; |
|
Returns current position in samples. |
function getPrevVolume(channel: unsigned = $FFFFFFFF): unsigned; |
|
Returns previous volume level for open device. If default value is specifed ($FFFFFFFF), returns median volume of all channels Parameters
|
function getUnVolume(channel: unsigned = $FFFFFFFF): unsigned; |
|
Returns unchanged volume level for open device. Volume range is from 0 to 32768. If default value is specifed ($FFFFFFFF), returns median volume of all channels Parameters
|
function getVolume(channel: unsigned = $FFFFFFFF): unsigned; |
|
Returns current volume level for open device. Volume range is from 0 to 32768. If default value is specifed ($FFFFFFFF), returns median volume of all channels Parameters
|
function isOpen(): bool; |
|
Returns true if device was opened successfully. |
function okToRead(): bool; |
|
Use this method to check if you can read new data from device. |
function open(query: bool = false; timeout: tTimeout = 10002; flags: uint = 0; startDevice: bool = true): MMRESULT; |
|
Opens the device. |
function read(buf: pointer; size: unsigned = 0): unsigned; |
|
Reads data from device. Returns size of actual returned data. Specify 0 as size parameter value when reading from ACM codec device. |
function removeConsumer(device: unaMsAcmStreamDevice): bool; |
|
Removes consumer from consumers list. |
function waitForData(waitForInData: bool; timeout: tTimeout; expectedDataSize: unsigned = 0): bool; |
|
Waits for data either in inStream or in outStream. Returns true if data is available, false if timeout has expired |
function write(buf: pointer; size: unsigned): unsigned; |
|
Sends data to device. |
function afterOpen(): MMRESULT; virtual; |
|
Called after the device was opened. Descendant classes may override this method to perform additional actions required by hardware/software. |
function beforeNewChunk(data: pointer; size: unsigned; formatExt: PWAVEFORMATEXTENSIBLE): bool; virtual; |
|
Adjusts volume as needed (if calcVolume is True). Calculates f_volume[] values (if calcVolume is True) for PCM data. Returns the result of checkSilence() routine. |
function close2(timeout: tTimeout = 10011): MMRESULT; virtual; |
|
function doClose(timeout: tTimeout = 1): MMRESULT; virtual; |
|
Closes device. This method is usually overrided by descendant classes to perform the actual job. |
function doGetErrorText(errorCode: MMRESULT): string; virtual; |
|
Uses mmGetErrorCodeText2() to produce the error message. Other devices could have own doGetErrorText() implementation. |
function doGetPosition(): int64; virtual; |
|
function doOpen(flags: uint): MMRESULT; virtual; |
|
Opens device. This method is usually overrided by descendant classes to perform the actual job. |
function doWrite(buf: pointer; size: unsigned): unsigned; virtual; |
|
function flush2(waitForComplete: bool = true): bool; virtual; |
|
function formatChooseDef2(var format: pWAVEFORMATEX): MMRESULT; dynamic; |
|
function getDspProperty(isLD: bool; propID: unsigned; def: int = 0): int; overload; |
|
function getDspProperty(isLD: bool; propID: unsigned; const def: float = 0.0): float; overload; |
|
function getMasterIsSrc2(): bool; virtual; abstract; |
|
function getProviderFormat(): PWAVEFORMATEXTENSIBLE; virtual; |
|
function open2(query: bool = false; timeout: tTimeout = 10001; flags: uint = 0; startDevice: bool = true): MMRESULT; virtual; |
|
function prepareHeader(header: pointer): MMRESULT; virtual; abstract; |
|
Prepares the buffer header before first use. Descendant classes must override this method. |
function setFormat(isSrc: bool; const format: aString): bool; overload; |
|
Sets the source or destination PCM format for device. Format is given in string representation using base64 encoding. |
function setFormat(isSrc: bool; format: pWAVEFORMATEX): bool; overload; virtual; |
|
Sets the source or destination PCM format for device. Format is given as WAVEFORMATEX structure. |
function setFormatExt(isSrc: bool; const formatExt: string): bool; overload; |
|
Sets the source or destination PCM format for device. Format is given in string representation using base64 encoding. |
function setFormatExt(isSrc: bool; formatExt: PWAVEFORMATEXTENSIBLE): bool; overload; virtual; |
|
function unprepareHeader(header: pointer): MMRESULT; virtual; abstract; |
|
Unprepares the buffer header after last use. Descendant classes must override this method. |
procedure AfterConstruction(); override; |
|
procedure BeforeDestruction(); override; |
|
procedure setVolume100(channel: int = -1; volume: unsigned = 100); |
|
Changes the volume of specified channel.
Parameters
|
procedure afterClose(closeResult: MMRESULT); virtual; |
|
procedure removeHeader(var header: pointer); virtual; abstract; |
|
procedure setDspProperty(isLD: bool; propID: unsigned; const value: float); overload; |
|
procedure setDspProperty(isLD: bool; propID: unsigned; value: int); overload; |
|
procedure setRealTime(value: bool); virtual; |
|
procedure startIn(); override; |
|
procedure startOut(); override; |
|
property calcVolume: bool read f_calcVolume write setCalcVolume; |
|
Specifies whether volume level calculation should be performed. Set to true if planning to use silence detection when silenceDetectionMode is set to unasdm_VC. |
property channelConsumeMask: int read f_channelConsumeMask write f_channelConsumeMask; |
|
Mix incoming channels into one. Default is -1 ($FFFFFFFF), means no mixing. Each bit set to 1 means the channel will mixed. Least significant bit corresponds to channel #0. All channels are mixed into one (mono) channel, unless -1 is specified as mask. NOTE: for stereo, mask 3 and -1 are different. 3 means two channels will be mixed into one -1 means two channels will be consumed as is If this filed is set to 0, no data will be consumed. |
property channelMixMask: int read f_channelMixMask write f_channelMixMask; |
|
The channel(s) to pass to consumers. Default is -1 ($FFFFFFFF), means all channels. Each bit set to 1 means the channel will be passed to consumers. Least significant bit corresponds to channel #0. All channels are mixed into one (mono) channel, unless -1 is specified as mask. NOTE: for stereo, mask 3 and -1 are different. 3 means two channels will be mixed into one -1 means two channels will be passed as is If this filed is set to 0, no data will be passed to consumers. Consumers must be smart enough to receive only 1 channel even if data format has more channels. |
property chunkPerSecond: unsigned read f_chunkPerSecond; |
|
Specifies number of chunks produced by component per second. Note, that not all components are working in real time, in which case this property has no meaning. Readonly property, change the global c_defChunksPerSecond variable if you wish to change this number. |
property chunkSize: unsigned read f_chunkSize; |
|
Size in bytes of internal buffer used to handle the audio stream data. |
property dstChunkSize: unsigned read f_dstChunkSize; |
|
Size in bytes of internal buffer used to handle the audio stream data. |
property dstFormatExt: PWAVEFORMATEXTENSIBLE read f_dstFormatExt; |
|
Returns destination format for device. |
property dstFormatInfo: string read f_dstFormatInfo; |
|
Returns string representation of destination wave format. |
property flushBeforeClose: bool read f_flushBeforeClose write f_flushBeforeClose; |
|
Specifies whether component will flush unfinished data before closing. |
property handle: unsigned read f_handle; |
|
WinAPI device handle (if applicable) |
property inBytes: int64 read f_inBytes; |
|
Number of bytes passed to device (as input). Playback and codec devices increase this value. |
property inOverloadTotal: int64 read f_inOverloadTotal; |
|
Total amount of in-data skipped due to overload |
property inProgress: unsigned read f_inProgress; |
|
Number of chunks passed to Windows ACM or wave device and not yet processed. |
property inStream: unaAbstractStream read f_inStream; |
|
Data passed to device first is strored in inStream |
property isSilence: bool read f_isSilence; |
|
True if components is currently not producing any audio chunks due to low signal level. |
property minActiveTime: unsigned read f_minAT write f_minAT; |
|
Specifies the minimum amount of time (in milliseconds) for silence detection to be active once activated. Has meaning only when silenceDetectionMode is set to unasdm_VC. |
property minVolumeLevel: unsigned read f_minVL write setMinVL; |
|
Specifies the minimum value of volume level for silence detection. Has meaning only when silenceDetectionMode is set to unasdm_VC. Set this property to 0 to disable the volume detection feature. |
property onDataAvailable: unaWaveDataEvent read f_onDA write f_onDA; |
|
This event is called when new data is available. |
property onGetProviderFormat: unaWaveGetProviderFormatEvent read f_onGetProviderFormat write f_onGetProviderFormat; |
|
Returns format assigned to external provider. |
property onThreshold: unaWaveOnThresholdEvent read f_onThreshold write f_onThreshold; |
|
This event is fired when current level of signal is crossing the "silence" mark. |
property outBytes: int64 read f_outBytes; |
|
Number of bytes produced by device (as output). Recording and codec devices increase this value. |
property outOverloadTotal: int64 read f_outOverloadTotal; |
|
Total amount of out-data skipped due to overload |
property outStream: unaAbstractStream read f_outStream; |
|
Data produced by device first is stored in outStream |
property overNumIn: unsigned read f_inOverCN write setInOverCN; |
|
Number of input chunks which could be queued |
property overNumOut: unsigned read f_outOverCN write setOutOverCN; |
|
Number of output chunks which could be queued |
property realTime: bool read f_realTime write setRealTime; |
|
property silenceDetectionMode: unaWaveInSDMethods read f_sdm write f_sdm; |
|
Specifies which method will be used to detect silence. |
property srcFormatExt: PWAVEFORMATEXTENSIBLE read f_srcFormatExt; |
|
Returns source format for device. |
property srcFormatInfo: string read f_srcFormatInfo; |
|
Returns string representation of source format. |
(c) 2012 Lake of Soft