Class TCastleSound
Unit
Declaration
type TCastleSound = class(TCastleComponent)
Description
Sound file that can be loaded from URL (possibly reusing a cache, possibly using streaming) and played.
Aside from sound file (also called "sound buffer" or "audio clip" in various APIs) this class allows to configue also playback values, like Volume and Pitch.
This class does not handle actual playing of the sound, as it doesn't manage the 3D position of sound in case of spatial sounds, looping etc. To play it, use TCastleSoundSource. Attach TCastleSoundSource to a TCastleTransform within some TCastleViewport.
This class can be nicely serialized (so you can use this as a SubComponent e.g. in TCastleBehavior descendants that want to expose some sound, like TCastleMoveAttack).
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleSound
Overview
Methods
![]() |
procedure Loaded; override; |
![]() |
procedure DoChange; virtual; |
![]() |
constructor Create(AOwner: TComponent); override; |
![]() |
destructor Destroy; override; |
Properties
![]() |
property Buffer: TSoundBuffer read FBuffer; |
![]() |
property URL: String read FURL write SetURL; |
![]() |
property Stream: Boolean read FStream write SetStream default false; |
![]() |
property Volume: Single read FVolume write SetVolume default 1.0; |
![]() |
property Pitch: Single read FPitch write SetPitch default 1.0; |
![]() |
property Spatial: Boolean read FSpatial write SetSpatial default true; |
![]() |
property MinGain: Single read FMinGain write SetMinGain default 0.0; |
![]() |
property MaxGain: Single read FMaxGain write SetMaxGain default 1.0; |
Description
Methods
![]() |
procedure Loaded; override; |
![]() |
procedure DoChange; virtual; |
![]() |
constructor Create(AOwner: TComponent); override; |
![]() |
destructor Destroy; override; |
Properties
![]() |
property Buffer: TSoundBuffer read FBuffer; |
|
Loaded sound buffer, for playing the buffer with the SoundEngine. | |
![]() |
property URL: String read FURL write SetURL; |
|
If you plan to change Stream, note that it is best to do it before setting URL. Changing Stream while URL is already set means that the sound is reloaded. | |
![]() |
property Stream: Boolean read FStream write SetStream default false; |
|
Play sound using streaming. This means that the sound is gradually decompressed in memory, which means that loading time is much smaller, although there may be a small overhead on CPU during playback. Streaming is usually a good idea for longer sounds, e.g. music tracks. See also TSoundLoading for details. If you plan to change Stream, note that it is best to do it before setting URL. Changing Stream while URL is already set means that the sound is reloaded. | |
![]() |
property Spatial: Boolean read FSpatial write SetSpatial default true; |
|
Is the sound playback spatialized. Spatial sounds are louder/more silent depending on their 3D distance to listener (this means a distance from TCastleTransform origin to the camera within the TCastleViewport). Note that some sound backends (like OpenAL) can only spatialize mono sounds, and play stereo sounds always as non-spatialized. | |
Generated by PasDoc 0.16.0.


