| Description | uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables |
A set of general utilities for working with OpenAL.
This unit provides many comfortable utilities to work with OpenAL. Everything is based on my OpenAL binding in unit KambiOpenAL. Most important things are BeginAL and EndAL procedures for initializing / releasing OpenAL context. Also TALSoundFile class is useful to load files into OpenAL buffers.
This unit does not use alut* functions from KambiOpenAL, so your programs will not depend on existence of alut* functions in some library. You can define symbol USE_ALUT and recompile this unit to use alut* functions, but this is really useful only for debugging. One can say that this unit provides a superset of alut functionality.
When you're using this unit, you shouldn't use any alc* functions and alutInit/alutExit functions from KambiOpenAL. The rule is that this unit takes care about such things.
| Name | Description |
|---|---|
Class EALError |
This is for errors reported by alGetError (using constants AL_xxx) |
Class TALSoundFile |
function EnumerationExtPresent(out pDeviceList: PChar): boolean; overload; |
function EnumerationExtPresent: boolean; overload; |
procedure GetOpenALDevices(DevicesList: TStringList); |
function ALCDeviceToNiceStr(const ALCDevice: string): string; |
procedure OpenALOptionsParse; |
function OpenALOptionsHelp(PrintALCDeviceAsDefault: boolean): string; |
procedure BeginAL(CheckForAlut: boolean); |
function TryBeginAL(CheckForAlut: boolean): boolean; |
procedure EndAL; |
function GetALCString(enum: TALCenum): string; |
function GetALCStringTrapped(enum: TALCenum): string; |
procedure CheckAL(const situation: string); |
function alGetSource1i(SourceName: TALuint; Attribute: TALenum): TALint; |
function alGetSource1f(SourceName: TALuint; Attribute: TALenum): TALfloat; |
function alGetSource1bool(SourceName: TALuint; Attribute: TALenum): TALboolean; |
function alGetSource1ui(SourceName: TALuint; Attribute: TALenum): TALuint; |
function alGetSource3f(SourceName: TALuint; Attribute: TALenum): TALVector3f; |
function alGetBuffer1sizei(BufferName: TALuint; Attribute: TALenum): TALsizei; |
function alGetBuffer1i(BufferName: TALuint; Attribute: TALenum): TALint; |
function alGetBuffer1f(BufferName: TALuint; Attribute: TALenum): TALfloat; |
function alGetListener1f(Attribute: TALenum): TALfloat; |
function alGetListener3f(Attribute: TALenum): TALVector3f; |
function alGetListenerOrientation: TALTwoVectors3f; |
procedure alSourceVector3f(SourceName: TALuint; Param: TALenum; const Value: TALVector3f); |
procedure alListenerVector3f(Param: TALenum; const Value: TALVector3f); |
procedure alListenerOrientation(const Dir, Up: TALVector3f); overload; |
procedure alListenerOrientation(const Orient: TALTwoVectors3f); overload; |
procedure alCreateSources(n: TALsizei; sources: PALuint); |
procedure alCreateBuffers(n: TALsizei; buffers: PALuint); |
function alSourcePlayingOrPaused(ALSource: TALuint): boolean; |
BestALCDevice = ''; |
BoolToAL: array[boolean] of TALint = (AL_FALSE, AL_TRUE); |
ALCDevice: string = BestALCDevice; |
ALActive: boolean = false; |
ALActivationErrorMessage: string = ''; |
function EnumerationExtPresent(out pDeviceList: PChar): boolean; overload; |
|
Checks if ALC_ENUMERATION_EXT is present. If it is, pDeviceList is initialized. Below is some description of how it works: This used to be trivial:
But then buggy Apple openal implementation came. With this implementation
|
function EnumerationExtPresent: boolean; overload; |
procedure GetOpenALDevices(DevicesList: TStringList); |
|
This appends to DevicesList object list of available OpenAL devices. It uses ALC_ENUMERATION_EXT extension, so ALInited must be true and ALC_ENUMERATION_EXT. If ALC_ENUMERATION_EXT extension is not supported but ALInited is Otherwise it doesn't append anything to DevicesList. Remember that for every OpenAL implementation, there is also an implicit OpenAL device named '' (empty string) supported. |
function ALCDeviceToNiceStr(const ALCDevice: string): string; |
|
This returns nice, user-readable description of OpenAL device named ALCDevice. Currently this returns nice string for
|
procedure OpenALOptionsParse; |
|
This parses parameters in Parameters and interprets and removes recognized options. Internally it uses ParseParameters with ParseOnlyKnownLongOptions =
More user-oriented documentation for the above options is here: [http://vrmlengine.sourceforge.net/openal_notes.php#section_options] |
function OpenALOptionsHelp(PrintALCDeviceAsDefault: boolean): string; |
|
This is help string for options parsed by OpenALOptionsParse. Formatting is consistent with Kambi standards (see file If PrintALCDeviceAsDefault then it will also say (near the help for option --audio-device) that "defauls device is ..." and will give here current value of ALCDevice. This is usually useful, e.g. if you don't intend to modify directly ALCDevice (only indirectly via OpenALOptionsParse) then you should give here true. |
procedure BeginAL(CheckForAlut: boolean); |
|
You should deactivate and free the context by calling EndAL. You should usually use BeginAL; try ... finally EndAL; end;
Detailed description of what
Exceptions raised
|
function TryBeginAL(CheckForAlut: boolean): boolean; |
|
This is like BeginAL but it doesn't raise EOpenALError. So you should check ALActive (if |
procedure EndAL; |
|
This deactivates and frees the context initialized by last TryBeginAL or BeginAL call. ALActive is set to If not ALActive, then this does nothing. |
function GetALCString(enum: TALCenum): string; |
|
Simple wrapper — calls alcGetString with the device created by last TryBeginAL or BeginAL call (or nil if no TryBeginAL or BeginAL was called or the device was freed by EndAL). And returns normal Pascal AnsiString (so you don't have to worry anymore that alcGetString returns a pointer to some internal data in OpenAL library and you can't modify it). |
function GetALCStringTrapped(enum: TALCenum): string; |
|
Calls GetALCString and additionally checks alcGetError. If alcGetError returns error, it returns string looking like '(detailed error description)' (normal incorrect call to alcGetString would return just nil). Actually, this also checks normal al error (alGetError instead of alcGetError). That's because on Darwin (Mac OS X) Apple's OpenAL implementation fails to return some alcGetString (e.g. ALC_DEFAULT_DEVICE_SPECIFIER, ALC_DEVICE_SPECIFIER, ALC_EXTENSIONS) and reports this by setting AL error (instead of ALC one) to "invalid value". Yes, that's Apple's bug (TODO: report ? check newer al version ?). Just like all other functions that somehow check al[c]GetError, this function assumes that error state was "clear" before calling this function, i.e. al[c]GetError would return AL[C]_NO_ERROR. |
procedure CheckAL(const situation: string); |
Exceptions raised
|
function alGetSource1i(SourceName: TALuint; Attribute: TALenum): TALint; |
|
Simple wrappers for alGetSource*, alGetBuffer*, alGetListener* and alGetFloat/Integer/Boolean*. In many cases these should be more comfortable (because they are functions) and safer (no need to pass some pointer) than directly using related OpenAL functions. OpenAL errors are not checked by these functions (i.e. CheckAL or alGetError is not called). No checking does |
function alGetSource1f(SourceName: TALuint; Attribute: TALenum): TALfloat; |
function alGetSource1bool(SourceName: TALuint; Attribute: TALenum): TALboolean; |
function alGetSource1ui(SourceName: TALuint; Attribute: TALenum): TALuint; |
function alGetSource3f(SourceName: TALuint; Attribute: TALenum): TALVector3f; |
function alGetBuffer1sizei(BufferName: TALuint; Attribute: TALenum): TALsizei; |
function alGetBuffer1i(BufferName: TALuint; Attribute: TALenum): TALint; |
function alGetBuffer1f(BufferName: TALuint; Attribute: TALenum): TALfloat; |
function alGetListener1f(Attribute: TALenum): TALfloat; |
function alGetListener3f(Attribute: TALenum): TALVector3f; |
function alGetListenerOrientation: TALTwoVectors3f; |
procedure alSourceVector3f(SourceName: TALuint; Param: TALenum; const Value: TALVector3f); |
|
These functions are simple wrappers over OpenAL functions to allow you to pass TALVector* / TALTwoVectors* types. Just like with alGet* wrappers (above in this unit), no error checking is done (no CheckAL etc.) and no checking does |
procedure alListenerVector3f(Param: TALenum; const Value: TALVector3f); |
procedure alListenerOrientation(const Dir, Up: TALVector3f); overload; |
procedure alListenerOrientation(const Orient: TALTwoVectors3f); overload; |
procedure alCreateSources(n: TALsizei; sources: PALuint); |
|
Unfortunately current Creative OpenAL Windows implementation violates OpenAL specifitation : default source state (i.e. newly generated source state) is not as it is specified by OpenAL implementation : attributes MAX_DISTANCE, DIRECTION and CONE_OUTER_GAIN have different values. So ( So explaining it simply : always use |
procedure alCreateBuffers(n: TALsizei; buffers: PALuint); |
function alSourcePlayingOrPaused(ALSource: TALuint): boolean; |
BoolToAL: array[boolean] of TALint = (AL_FALSE, AL_TRUE); |
ALCDevice: string = BestALCDevice; |
|
This OpenAL device will be used when you will call TryBeginAL or BeginAL. I could make it instead a parameter for TryBeginAL / BeginAL procedures, but it's more comfortable to have a global variable for this — it's useful e.g. to easily implement handling of --audio-device option in OpenALOptionsParse. TryBeginAL / BeginAL procedures assume anyway that your program will require only one OpenAL context at any time. |
ALActive: boolean = false; |
|
|
ALActivationErrorMessage: string = ''; |
|
When BeginAL fails with EOpenALError or when TryBeginAL returns with false, they put error message in this variable. When you're using BeginAL this variable is actually useless for you, as this is equal to Message property of raised exception. But this is of course useful when you're using TryBeginAL, as this is the only way to get detailed info why TryBeginAL failed. |