Home Units Hierarchy Routines All identifiers

Class unaMsAcmStreamDevice

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type unaMsAcmStreamDevice = class(unaThread)

Description

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.

Hierarchy

Overview

Methods

Public constructor create(createInStream: bool = true; createOutStream: bool = true; inOverNum: unsigned = 0; outOverNum: unsigned = 0; calcVolume: bool = false);
Public destructor Destroy(); override;
Public function addConsumer(device: unaMsAcmStreamDevice; removeOutStream: bool = true): unsigned;
Public function assignStream(streamClass: unaAbstractStreamClass; isInStream: bool; careDestroy: bool = true): unaAbstractStream; overload;
Public function assignStream(isInStream: bool; stream: unaAbstractStream; careDestroy: bool = false): unaAbstractStream; overload;
Public function close(timeout: tTimeout = 10012): MMRESULT;
Public function flush(waitForComplete: bool = true): bool;
Public function formatChooseDef(var format: pWAVEFORMATEX): MMRESULT;
Public function getDataAvailable(isIn: bool): unsigned;
Public function getErrorText(errorCode: MMRESULT): string;
Public function getMasterIsSrc(): bool;
Public function getPosition(): int64;
Public function getPrevVolume(channel: unsigned = $FFFFFFFF): unsigned;
Public function getUnVolume(channel: unsigned = $FFFFFFFF): unsigned;
Public function getVolume(channel: unsigned = $FFFFFFFF): unsigned;
Public function isOpen(): bool;
Public function okToRead(): bool;
Public function open(query: bool = false; timeout: tTimeout = 10002; flags: uint = 0; startDevice: bool = true): MMRESULT;
Public function read(buf: pointer; size: unsigned = 0): unsigned;
Public function removeConsumer(device: unaMsAcmStreamDevice): bool;
Public function waitForData(waitForInData: bool; timeout: tTimeout; expectedDataSize: unsigned = 0): bool;
Public function write(buf: pointer; size: unsigned): unsigned;
Protected function afterOpen(): MMRESULT; virtual;
Protected function beforeNewChunk(data: pointer; size: unsigned; formatExt: PWAVEFORMATEXTENSIBLE): bool; virtual;
Protected function close2(timeout: tTimeout = 10011): MMRESULT; virtual;
Protected function doClose(timeout: tTimeout = 1): MMRESULT; virtual;
Protected function doGetErrorText(errorCode: MMRESULT): string; virtual;
Protected function doGetPosition(): int64; virtual;
Protected function doOpen(flags: uint): MMRESULT; virtual;
Protected function doWrite(buf: pointer; size: unsigned): unsigned; virtual;
Protected function flush2(waitForComplete: bool = true): bool; virtual;
Protected function formatChooseDef2(var format: pWAVEFORMATEX): MMRESULT; dynamic;
Protected function getDspProperty(isLD: bool; propID: unsigned; def: int = 0): int; overload;
Protected function getDspProperty(isLD: bool; propID: unsigned; const def: float = 0.0): float; overload;
Protected function getMasterIsSrc2(): bool; virtual; abstract;
Protected function getProviderFormat(): PWAVEFORMATEXTENSIBLE; virtual;
Protected function open2(query: bool = false; timeout: tTimeout = 10001; flags: uint = 0; startDevice: bool = true): MMRESULT; virtual;
Protected function prepareHeader(header: pointer): MMRESULT; virtual; abstract;
Protected function setFormat(isSrc: bool; const format: aString): bool; overload;
Protected function setFormat(isSrc: bool; format: pWAVEFORMATEX): bool; overload; virtual;
Protected function setFormatExt(isSrc: bool; const formatExt: string): bool; overload;
Protected function setFormatExt(isSrc: bool; formatExt: PWAVEFORMATEXTENSIBLE): bool; overload; virtual;
Protected function unprepareHeader(header: pointer): MMRESULT; virtual; abstract;
Public procedure AfterConstruction(); override;
Public procedure BeforeDestruction(); override;
Public procedure setVolume100(channel: int = -1; volume: unsigned = 100);
Protected procedure afterClose(closeResult: MMRESULT); virtual;
Protected procedure removeHeader(var header: pointer); virtual; abstract;
Protected procedure setDspProperty(isLD: bool; propID: unsigned; const value: float); overload;
Protected procedure setDspProperty(isLD: bool; propID: unsigned; value: int); overload;
Protected procedure setRealTime(value: bool); virtual;
Protected procedure startIn(); override;
Protected procedure startOut(); override;

Properties

Public property calcVolume: bool read f_calcVolume write setCalcVolume;
Public property channelConsumeMask: int read f_channelConsumeMask write f_channelConsumeMask;
Public property channelMixMask: int read f_channelMixMask write f_channelMixMask;
Public property chunkPerSecond: unsigned read f_chunkPerSecond;
Public property chunkSize: unsigned read f_chunkSize;
Protected property dstChunkSize: unsigned read f_dstChunkSize;
Public property dstFormatExt: PWAVEFORMATEXTENSIBLE read f_dstFormatExt;
Public property dstFormatInfo: string read f_dstFormatInfo;
Public property flushBeforeClose: bool read f_flushBeforeClose write f_flushBeforeClose;
Protected property handle: unsigned read f_handle;
Public property inBytes: int64 read f_inBytes;
Public property inOverloadTotal: int64 read f_inOverloadTotal;
Public property inProgress: unsigned read f_inProgress;
Public property inStream: unaAbstractStream read f_inStream;
Public property isSilence: bool read f_isSilence;
Public property minActiveTime: unsigned read f_minAT write f_minAT;
Public property minVolumeLevel: unsigned read f_minVL write setMinVL;
Public property onDataAvailable: unaWaveDataEvent read f_onDA write f_onDA;
Public property onGetProviderFormat: unaWaveGetProviderFormatEvent read f_onGetProviderFormat write f_onGetProviderFormat;
Public property onThreshold: unaWaveOnThresholdEvent read f_onThreshold write f_onThreshold;
Public property outBytes: int64 read f_outBytes;
Public property outOverloadTotal: int64 read f_outOverloadTotal;
Public property outStream: unaAbstractStream read f_outStream;
Public property overNumIn: unsigned read f_inOverCN write setInOverCN;
Public property overNumOut: unsigned read f_outOverCN write setOutOverCN;
Public property realTime: bool read f_realTime write setRealTime;
Public property silenceDetectionMode: unaWaveInSDMethods read f_sdm write f_sdm;
Public property srcFormatExt: PWAVEFORMATEXTENSIBLE read f_srcFormatExt;
Public property srcFormatInfo: string read f_srcFormatInfo;

Description

Methods

Public constructor create(createInStream: bool = true; createOutStream: bool = true; inOverNum: unsigned = 0; outOverNum: unsigned = 0; calcVolume: bool = false);

Initializates class instance.

Public destructor Destroy(); override;
 
Public 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).

Public 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.

Public 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.

Public function close(timeout: tTimeout = 10012): MMRESULT;

Closes the device.

Public function flush(waitForComplete: bool = true): bool;
 
Public function formatChooseDef(var format: pWAVEFORMATEX): MMRESULT;

Default implementation of format choosing routine.

Public function getDataAvailable(isIn: bool): unsigned;

Returns number of bytes available to read from the device.

Public function getErrorText(errorCode: MMRESULT): string;

Returns error message text corresponding to given errorCode parameter.

Public function getMasterIsSrc(): bool;

Returns true if device is output device (playback or codec). Returns false if device is input device (recording).

Public function getPosition(): int64;

Returns current position in samples.

Public 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
channel
Channel number to read volume of.
Public 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
channel
Channel number to read volume of.
Public 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
channel
Channel number to read volume of.
Public function isOpen(): bool;

Returns true if device was opened successfully.

Public function okToRead(): bool;

Use this method to check if you can read new data from device.

Public function open(query: bool = false; timeout: tTimeout = 10002; flags: uint = 0; startDevice: bool = true): MMRESULT;

Opens the device.

Public 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.

Public function removeConsumer(device: unaMsAcmStreamDevice): bool;

Removes consumer from consumers list.

Public 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

Public function write(buf: pointer; size: unsigned): unsigned;

Sends data to device.

Protected function afterOpen(): MMRESULT; virtual;

Called after the device was opened. Descendant classes may override this method to perform additional actions required by hardware/software.

Protected 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.

Protected function close2(timeout: tTimeout = 10011): MMRESULT; virtual;
 
Protected function doClose(timeout: tTimeout = 1): MMRESULT; virtual;

Closes device. This method is usually overrided by descendant classes to perform the actual job.

Protected function doGetErrorText(errorCode: MMRESULT): string; virtual;

Uses mmGetErrorCodeText2() to produce the error message. Other devices could have own doGetErrorText() implementation.

Protected function doGetPosition(): int64; virtual;
 
Protected function doOpen(flags: uint): MMRESULT; virtual;

Opens device. This method is usually overrided by descendant classes to perform the actual job.

Protected function doWrite(buf: pointer; size: unsigned): unsigned; virtual;
 
Protected function flush2(waitForComplete: bool = true): bool; virtual;
 
Protected function formatChooseDef2(var format: pWAVEFORMATEX): MMRESULT; dynamic;
 
Protected function getDspProperty(isLD: bool; propID: unsigned; def: int = 0): int; overload;
 
Protected function getDspProperty(isLD: bool; propID: unsigned; const def: float = 0.0): float; overload;
 
Protected function getMasterIsSrc2(): bool; virtual; abstract;
 
Protected function getProviderFormat(): PWAVEFORMATEXTENSIBLE; virtual;
 
Protected function open2(query: bool = false; timeout: tTimeout = 10001; flags: uint = 0; startDevice: bool = true): MMRESULT; virtual;
 
Protected function prepareHeader(header: pointer): MMRESULT; virtual; abstract;

Prepares the buffer header before first use. Descendant classes must override this method.

Protected 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.

Protected function setFormat(isSrc: bool; format: pWAVEFORMATEX): bool; overload; virtual;

Sets the source or destination PCM format for device. Format is given as WAVEFORMATEX structure.

Protected 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.

Protected function setFormatExt(isSrc: bool; formatExt: PWAVEFORMATEXTENSIBLE): bool; overload; virtual;
 
Protected function unprepareHeader(header: pointer): MMRESULT; virtual; abstract;

Unprepares the buffer header after last use. Descendant classes must override this method.

Public procedure AfterConstruction(); override;
 
Public procedure BeforeDestruction(); override;
 
Public procedure setVolume100(channel: int = -1; volume: unsigned = 100);

Changes the volume of specified channel.

Parameters
volume
100 means no volume change (100%); 50 = 50%; 200 = 200% and so on.
channel
Default value of -1 means this volume will be applied on all channels.
Protected procedure afterClose(closeResult: MMRESULT); virtual;
 
Protected procedure removeHeader(var header: pointer); virtual; abstract;
 
Protected procedure setDspProperty(isLD: bool; propID: unsigned; const value: float); overload;
 
Protected procedure setDspProperty(isLD: bool; propID: unsigned; value: int); overload;
 
Protected procedure setRealTime(value: bool); virtual;
 
Protected procedure startIn(); override;
 
Protected procedure startOut(); override;
 

Properties

Public 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.

Public 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.

Public 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.

Public 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.

Public property chunkSize: unsigned read f_chunkSize;

Size in bytes of internal buffer used to handle the audio stream data.

Protected property dstChunkSize: unsigned read f_dstChunkSize;

Size in bytes of internal buffer used to handle the audio stream data.

Public property dstFormatExt: PWAVEFORMATEXTENSIBLE read f_dstFormatExt;

Returns destination format for device.

Public property dstFormatInfo: string read f_dstFormatInfo;

Returns string representation of destination wave format.

Public property flushBeforeClose: bool read f_flushBeforeClose write f_flushBeforeClose;

Specifies whether component will flush unfinished data before closing.

Protected property handle: unsigned read f_handle;

WinAPI device handle (if applicable)

Public property inBytes: int64 read f_inBytes;

Number of bytes passed to device (as input). Playback and codec devices increase this value.

Public property inOverloadTotal: int64 read f_inOverloadTotal;

Total amount of in-data skipped due to overload

Public property inProgress: unsigned read f_inProgress;

Number of chunks passed to Windows ACM or wave device and not yet processed.

Public property inStream: unaAbstractStream read f_inStream;

Data passed to device first is strored in inStream

Public property isSilence: bool read f_isSilence;

True if components is currently not producing any audio chunks due to low signal level.

Public 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.

Public 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.

Public property onDataAvailable: unaWaveDataEvent read f_onDA write f_onDA;

This event is called when new data is available.

Public property onGetProviderFormat: unaWaveGetProviderFormatEvent read f_onGetProviderFormat write f_onGetProviderFormat;

Returns format assigned to external provider.

Public property onThreshold: unaWaveOnThresholdEvent read f_onThreshold write f_onThreshold;

This event is fired when current level of signal is crossing the "silence" mark.

Public property outBytes: int64 read f_outBytes;

Number of bytes produced by device (as output). Recording and codec devices increase this value.

Public property outOverloadTotal: int64 read f_outOverloadTotal;

Total amount of out-data skipped due to overload

Public property outStream: unaAbstractStream read f_outStream;

Data produced by device first is stored in outStream

Public property overNumIn: unsigned read f_inOverCN write setInOverCN;

Number of input chunks which could be queued

Public property overNumOut: unsigned read f_outOverCN write setOutOverCN;

Number of output chunks which could be queued

Public property realTime: bool read f_realTime write setRealTime;
 
Public property silenceDetectionMode: unaWaveInSDMethods read f_sdm write f_sdm;

Specifies which method will be used to detect silence.

Public property srcFormatExt: PWAVEFORMATEXTENSIBLE read f_srcFormatExt;

Returns source format for device.

Public property srcFormatInfo: string read f_srcFormatInfo;

Returns string representation of source format.

(c) 2012 Lake of Soft


Generated by PasDoc 0.12.1 on 2012-10-09