Class TSoundAllocator

Unit

Declaration

type TSoundAllocator = class(TObject)

Description

Manager of allocated sounds.

For efficiency, the pool of available sound sources (things that are actually audible at a given time) is limited. This limit comes from the backend limits (like OpenAL or APIs underneath OpenAL), it may also come from sound hardware limitations, and in general you should not have too many playing sources, as mixing many sources is time-consuming. So you cannot simply allocate new sound source for each of 100 creatures you display in the game.

This class hides this limitation, by managing a pool of sound sources, and returning on demand the next unused sound source (or Nil). It can prioritize sound sources, it can reuse sound sources that finished playing, it can interrupt a lower-priority sound when necessary to play a higher-priority sound.

This is automatically used by higher-level comfortable methods to play sounds like TSoundEngine.Play.

Hierarchy

  • TObject
  • TSoundAllocator

Overview

Fields

Public nested const DefaultMinAllocatedSources = 4;
Public nested const DefaultMaxAllocatedSources = 16;

Methods

Public constructor Create;
Public destructor Destroy; override;

Properties

Public property MinAllocatedSources: Cardinal read FMinAllocatedSources write SetMinAllocatedSources default DefaultMinAllocatedSources;
Public property MaxAllocatedSources: Cardinal read FMaxAllocatedSources write SetMaxAllocatedSources default DefaultMaxAllocatedSources;
Public property InternalAllocatedSources: TInternalSoundSourceList read FAllocatedSources;
Public property IsContextOpenSuccess: boolean read FIsContextOpenSuccess;

Description

Fields

Public nested const DefaultMinAllocatedSources = 4;

This item has no description.

Public nested const DefaultMaxAllocatedSources = 16;

This item has no description.

Methods

Public constructor Create;

This item has no description.

Public destructor Destroy; override;

This item has no description.

Properties

Public property MinAllocatedSources: Cardinal read FMinAllocatedSources write SetMinAllocatedSources default DefaultMinAllocatedSources;

Minimum / maximum number of allocated sources. Always keep MinAllocatedSources <= MaxAllocatedSources.

For the sake of speed, we always keep allocated at least MinAllocatedSources sources. This must be >= 1. Setting MinAllocatedSources too large value will raise ENoMoreSources.

At most MaxAllocatedSources sources may be simultaneously used (played). This prevents us from allocating too many sounds, which would be bad for speed (not to mention that it may be impossible under some backends, like OpenAL on Windows). When all MaxAllocatedSources sources are playing, the only way to play another sound is to use appropriately high Priority to AllocateSound.

Public property MaxAllocatedSources: Cardinal read FMaxAllocatedSources write SetMaxAllocatedSources default DefaultMaxAllocatedSources;

This item has no description.

Public property InternalAllocatedSources: TInternalSoundSourceList read FAllocatedSources;

All allocated (not necessarily used) sources. Accessing this is useful only for debugging tasks, in normal circumstances this is internal. This is Nil when ContextOpen was not yet called.

Public property IsContextOpenSuccess: boolean read FIsContextOpenSuccess;

Do we have active sound rendering context. This is True when you successfully called TSoundEngine.ContextOpen and you didn't call TSoundEngine.ContextClose yet.

You should not need this property much. The whole CastleSoundEngine API works regardless if the context was successfully open or not. However, reading this is useful to display to user warning e.g. "Sound could not be initialized for some reason" (use TSoundEngine.Information to get the details).

In case of OpenAL backend, this also implies that OpenAL library is loaded.


Generated by PasDoc 0.16.0-snapshot.