Components Demo

This unit is a demo showing how to build new input and output components for NewAC.

Summary
Components DemoThis unit is a demo showing how to build new input and output components for NewAC.
Constants
InitialBufferSizeAn Integer equal to $1000 (that’s 4096 bytes, if you don’t speak hex).
TDemoWaveInA demo input component capable of reading data from raw PCM wav files.
Functions
OpenFileCalled by the base methods of TAuFileIn class to open the file.
CloseFileCalled by the base methods of TAuFileIn class to close the file.
CreateReimplementing constructor and destructor is optional.
GetDataInternalUsed by NewAC to retrieve decoded data.
Variables
Integer - the number of bytes to read, returns bytes read.
Functions
SeekInternalPerforms the file seeking.
TDemoWaveOutA demo output component capable of storing data on disk or in a stream in the raw PCM wav format.
Functions
PreparePerforms all the steps required to initialize output.
DoOutputCalled in a loop to perform actual output.
DoneCalled to do whatever is needed to close the output as well as freeing any associated resources.
Compare4Used internally by ReadRIFFHeader.
ReadRIFFHeaderA helper function that parses wav file header and gets audio data parameters.

Constants

InitialBufferSize

An Integer equal to $1000 (that’s 4096 bytes, if you don’t speak hex).  The InitialBufferSize constant holds the initial size of the input buffer.  This way we can change the default buffer size easily, without delving into the code.

TDemoWaveIn

A demo input component capable of reading data from raw PCM wav files.  Like most input components, it descends from the TAuFileIn class.

Summary
Functions
OpenFileCalled by the base methods of TAuFileIn class to open the file.
CloseFileCalled by the base methods of TAuFileIn class to close the file.
CreateReimplementing constructor and destructor is optional.
GetDataInternalUsed by NewAC to retrieve decoded data.
Variables
Integer - the number of bytes to read, returns bytes read.
Functions
SeekInternalPerforms the file seeking.

Functions

OpenFile

procedure OpenFile; override

Called by the base methods of TAuFileIn class to open the file.  It should prepare the component for reading data.  This method also sets values for several internal and inherited fields.

CloseFile

procedure CloseFile; override

Called by the base methods of TAuFileIn class to close the file.  It should clear all resources assosiated with input.

Create

constructor Create(AOwner: TComponent); override

Reimplementing constructor and destructor is optional.  It depends on the requirements of your component.

GetDataInternal

Used by NewAC to retrieve decoded data.  You should pass the number of bytes you want to read in the Bytes parameter.  This method returns the pointer to the data buffre in the Buffer variable parameter and the number of bytes actually read in the buffer in the Bytes paramter.  The buffer pointer must be provided by THIS method and not by the caller.  The pointer returned by GetData should be valid until the next call to the method.  When the method cannot return any more data it should return nil in the Buffer and 0 in the Bytes parameter.  The GetDataInternal method can return less bytes than it is asked to and it should not be considered as an end of file indication.

Parameters

Buffer: Pointeran unassigned pointer to use for the results, GetData initializes the pointer itself.

Variables

Integer - the number of bytes to read, returns bytes read.

Functions

SeekInternal

function SeekInternal(var SampleNum : Int64) : Boolean; override

Performs the file seeking.  The new position is set in samples, not in bytes, relatively to the beginning of the file.  Seek should return True if the input is seekable and False otherwise.  This method implementation is optional.  If your input component doesn’t support seeking.

function TSomeInputComponent.Seek(SampleNum : Integer) : Boolean;
begin
Result := False;
end;

In the SampleNum parameter we pass the new position in the input stream in frames (which are called samples ;-) relative to the beginning of the stream.

TDemoWaveOut

A demo output component capable of storing data on disk or in a stream in the raw PCM wav format.  Like most output components, it descends from the TAuFileOut class.

Summary
Functions
PreparePerforms all the steps required to initialize output.
DoOutputCalled in a loop to perform actual output.
DoneCalled to do whatever is needed to close the output as well as freeing any associated resources.
Compare4Used internally by ReadRIFFHeader.
ReadRIFFHeaderA helper function that parses wav file header and gets audio data parameters.

Functions

Prepare

procedure Prepare; override

Performs all the steps required to initialize output.

DoOutput

function DoOutput(Abort : Boolean):Boolean; override

Called in a loop to perform actual output.  If the Abort parameter is set to True the function must do whatever is needed to stop the output.  The function may be called several times with the Abort value set to True.  The return value indicartes wheter an output operation should continue.  If the function has done its job (because of an end of input file condition, or because the Abort parameter is set to True, or because of some failure, it should return False as a result.  Otherwise it returns True.

Parameters

Abort: Booleanset to True in order to stop the output operation

Returns

SuccessBoolean

Done

procedure Done; override

Called to do whatever is needed to close the output as well as freeing any associated resources.

Compare4

function Compare4(S1, 
S2 : PChar) : Boolean

Used internally by ReadRIFFHeader.

ReadRIFFHeader

function ReadRIFFHeader(Stream : TStream;
var AudioInfo : TAudioInfo) : Boolean

A helper function that parses wav file header and gets audio data parameters.  This is relevant only to wave file readers, so no further comments are necessary.

procedure OpenFile; override
Called by the base methods of TAuFileIn class to open the file.
procedure CloseFile; override
Called by the base methods of TAuFileIn class to close the file.
constructor Create(AOwner: TComponent); override
Reimplementing constructor and destructor is optional.
function SeekInternal(var SampleNum : Int64) : Boolean; override
Performs the file seeking.
procedure Prepare; override
Performs all the steps required to initialize output.
function DoOutput(Abort : Boolean):Boolean; override
Called in a loop to perform actual output.
procedure Done; override
Called to do whatever is needed to close the output as well as freeing any associated resources.
function Compare4(S1, 
S2 : PChar) : Boolean
Used internally by ReadRIFFHeader.
function ReadRIFFHeader(Stream : TStream;
var AudioInfo : TAudioInfo) : Boolean
A helper function that parses wav file header and gets audio data parameters.
A descendant of TAuStreamedOutput to deal with files and streams.
Close