Home Units Hierarchy Routines All identifiers

Unit unaWave

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Set of routines to work with PCM wave data.

Version 2.5.2008.07 Still here

Version 2.5.2011.12 x64 compatibility

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
record unaPCMChunk  
packed record unaPCMFormat  
packed record unavclWavePipeFormatExchange Data structure used for format exchange.
packed record unaWaveFormat  

Functions and Procedures

function waveMix(buf1, buf2, buf3: pointer; samples: unsigned; bits1, bits2, bits3: unsigned; doAdd: bool = true; numChannels: unsigned = 1): unsigned; overload;
function waveMix(const chunk1, chunk2, chunk3: unaPCMChunk; doAdd: bool = true): unsigned; overload;
function waveGetVolume(buf: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned = 1; channel: unsigned = 0; deltaMethod: bool = false): unsigned;
function waveGetLogVolume(volume: int): unsigned;
function waveGetLogVolume100(volume: int): unsigned;
function waveExtractChannel(buf, dest: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned = 1; channel: unsigned = 0): unsigned;
function waveReplaceChannel(buf, source: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned = 1; channel: unsigned = 0): unsigned;
function waveReverse(buf: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned): unsigned;
function waveResample(bufSrc, bufDst: pointer; samples, numChannelsSrc, numChannelsDst, bitsSrc, bitsDst, rateSrc, rateDst: unsigned): unsigned; overload;
function waveResample(const bufSrc: unaPCMChunk; var bufDst: unaPCMChunk): unsigned; overload;
function waveGetChunkMaxSamplesCount(const chunk: unaPCMChunk): unsigned;
function waveGetChunkCurSamplesCount(const chunk: unaPCMChunk): unsigned;
function waveReallocateChunk(var chunk: unaPCMChunk; numSamples: unsigned = 0): unsigned;
function waveReadFromChunk(var chunk: unaPCMChunk; buf: pointer; size: unsigned; bufOffs: unsigned = 0): unsigned;
function waveWriteToChunk(var chunk: unaPCMChunk; buf: pointer; size: unsigned; bufOffs: unsigned = 0): unsigned;
function waveFindNextGcd(rate1, rate2: unsigned; startFrom: unsigned): unsigned;
function waveModifyVolume100(volume: unsigned; buf: pointer; samples: unsigned; bits: unsigned = 16; numChannels: unsigned = 1; channel: int = -1): unsigned; overload;
function waveModifyVolume100(volume: unsigned; const chunk: unaPCMChunk; channel: int): unsigned; overload;

Types

punaPCMFormat = ˆunaPCMFormat;
punaWaveFormat = ˆunaWaveFormat;
punaPCMChunk = ˆunaPCMChunk;
punavclWavePipeFormatExchange = ˆunavclWavePipeFormatExchange;

Description

Functions and Procedures

function waveMix(buf1, buf2, buf3: pointer; samples: unsigned; bits1, bits2, bits3: unsigned; doAdd: bool = true; numChannels: unsigned = 1): unsigned; overload;

Mixes buf1 and buf2 and stores the result in buf3 (buf3 could be one of buf1 or buf2).

bitsN (N = 1, 2 or 3) specifies the number or bits in sample: 8 = 1 byte per sample (from $00 = -128 to $FF = +127; $7F = -1, $80 = 0) 16 = 2 bytes per sample (from $8000 = -32768 to $7FFF = 32767; $0 = 0, $FFFF = -1) 32 = 4 bytes per sample (from $80000000 = -2147483648 to $7FFFFFFF = +2147483647; $0 = 0, $FFFFFFFF = -1)

Size of buffer #N in bytes = (bitsN * samples * numChannels) shr 3 Mixing is done by adding (doAdd is true) or subtracting (doAdd is false) samples with clipping.

Returns

number of samples mixed.

function waveMix(const chunk1, chunk2, chunk3: unaPCMChunk; doAdd: bool = true): unsigned; overload;

Mixes two chunks.

Returns

number of samples mixed.

function waveGetVolume(buf: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned = 1; channel: unsigned = 0; deltaMethod: bool = false): unsigned;

Calculates volume. Calculation is done by adding squares of samples and then dividing result on number of samples and applying square root. Assuming data has "natural" source. That means you can get useless results for signals, that are not sound by nature (constant non-zero signal for example).

Parameters
buf
pointer to PCM samples
samples
number of samples.
bits
should have the value as described in waveMix() routine
channel
For multi-channel streams specifies the channel number you wish to get the power of
numChannels
total number of channels in the stream
Returns

value is from 0 (silence) to 32768 (loudest possible sound)

function waveGetLogVolume(volume: int): unsigned;

Returns Logarithmic volume.

Parameters
volume
range is from 0 to 32768
Returns

value range from 0 to 300

function waveGetLogVolume100(volume: int): unsigned;

Returns Logarithmic volume.

Input range is from 0 to 32768.

Result range is from 0 to 100.

function waveExtractChannel(buf, dest: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned = 1; channel: unsigned = 0): unsigned;

Extracts specified channel from PCM chunk.

Parameters
dest
must be large enough to store required data (one mono channel)
channel
specifies which channel to extract (0, 1, 2... )
Returns

number of samples stored in dest buffer

function waveReplaceChannel(buf, source: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned = 1; channel: unsigned = 0): unsigned;

Replaces PCM data for specified channel with new one. Old data for this channel will be lost.

Parameters
channel
specifies which channel to replace (0, 1, 2... )
Returns

number of samples stored in dest buffer

function waveReverse(buf: pointer; samples: unsigned; bits: unsigned; numChannels: unsigned): unsigned;

Reverses PCM samples in wave chunk. bits specifies number of bits in sample. numChannels specifies number of channels in stream.

Returns

number of samples processed.

function waveResample(bufSrc, bufDst: pointer; samples, numChannelsSrc, numChannelsDst, bitsSrc, bitsDst, rateSrc, rateDst: unsigned): unsigned; overload;

Changes PCM stream characteristics.

numChannels conversions supported:

mono => any Number Of Channels stereo => mono; stereo; 4 channels; 6 channels; 8 channels ... 3 channels => mono; 3 channels; 6 channels; 9 channels ... 4 channels => mono; stereo; 4 channels; 8 channels; 12 channels ... 5 channels => mono; 5 channels; 10 channels; 15 channels ... 6 channels => mono; 3 channels; 6 channels; 12 channels ... ... i.e. (number of dst channels) mod (number of src channels) must be 0

Parameters
bufSrc
source samples
bufDst
destination samples (buffer must be already allocated)
samples
number of samples to read from bufSrc
numChannelsSrc
number of channels in source stream
numChannelsDst
number of channels in destination stream
bitsSrc
number of bits per sample in source stream
bitsDst
number of bits per sample in destination stream
rateSrc
sampling rate of source stream
rateDst
sampling rate of destination stream
Returns

number of bytes produced by the function.

function waveResample(const bufSrc: unaPCMChunk; var bufDst: unaPCMChunk): unsigned; overload;

Changes PCM stream characteristics.

Returns

number of bytes produced by the function.

function waveGetChunkMaxSamplesCount(const chunk: unaPCMChunk): unsigned;
 
Returns

number of full samples which can be stored in given PCM chunk.

function waveGetChunkCurSamplesCount(const chunk: unaPCMChunk): unsigned;
 
Returns

current number of full samples which is stored in given PCM chunk.

function waveReallocateChunk(var chunk: unaPCMChunk; numSamples: unsigned = 0): unsigned;

Reallocates PCM chunk to hold required number of samples. NOTE: chunk.chunkData must be a valid pointer (or nil) before calling this function.

Returns

number of bytes allocated.

function waveReadFromChunk(var chunk: unaPCMChunk; buf: pointer; size: unsigned; bufOffs: unsigned = 0): unsigned;

Reads bytes from PCM chunk.

Returns

number of bytes read

function waveWriteToChunk(var chunk: unaPCMChunk; buf: pointer; size: unsigned; bufOffs: unsigned = 0): unsigned;

Writes bytes to PCM chunk.

function waveFindNextGcd(rate1, rate2: unsigned; startFrom: unsigned): unsigned;

Returns next gcd value.

function waveModifyVolume100(volume: unsigned; buf: pointer; samples: unsigned; bits: unsigned = 16; numChannels: unsigned = 1; channel: int = -1): unsigned; overload;

Modifies linear volume for all samples.

Parameters
volume
Percentage of original volume (100 means no change).
Returns

Number of samples processed.

function waveModifyVolume100(volume: unsigned; const chunk: unaPCMChunk; channel: int): unsigned; overload;

Modifies linear volume for all samples.

Parameters
volume
Percentage of original volume (100 means no change).
Returns

Number of samples processed.

Types

punaPCMFormat = ˆunaPCMFormat;

– –

punaWaveFormat = ˆunaWaveFormat;

number of channels – –

punaPCMChunk = ˆunaPCMChunk;

channel mask – –

punavclWavePipeFormatExchange = ˆunavclWavePipeFormatExchange;
 

Author

(c) 2012 Lake of Soft


Generated by PasDoc 0.12.1 on 2012-10-09