Class TCastleSound
Unit
Declaration
type TCastleSound = class(TCastleComponent)
Description
Sound 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. These playback values are intended to reflect preferences specific to this sound file. They are multiplied by playback values of the TCastleSoundSource (TCastleSoundSource.Volume, TCastleSoundSource.Pitch) and TCastlePlayingSound (to adjust it per-playback, using TCastlePlayingSound.Volume, TCastlePlayingSound.Pitch).
This class does not actually play the sound. It only defines something that can be played. To play the sound use SoundEngine.Play or TCastleSoundSource. For spatial sounds, attach TCastleSoundSource to a TCastleTransform within some TCastleViewport and set TCastleSoundSource.Sound or call TCastleSoundSource.Play.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastleComponent
- TCastleSound
Overview
Fields
nested const DefaultReferenceDistance = 1.0; |
|
nested const DefaultMaxDistance = 10000.0; |
Methods
procedure Loaded; override; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
function Duration: Single; |
|
function DataFormat: TSoundDataFormat; |
|
function Frequency: LongWord; |
Properties
property MinGain: Single read FMinGain write SetMinGain default 0.0; platform; |
|
property MaxGain: Single read FMaxGain write SetMaxGain default 1.0; platform; |
|
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 Priority: Single read FPriority write SetPriority default 0.5; |
|
property ReferenceDistance: Single read FReferenceDistance write SetReferenceDistance
default DefaultReferenceDistance; |
|
property MaxDistance: Single read FMaxDistance write SetMaxDistance
default DefaultMaxDistance; |
Description
Fields
nested const DefaultReferenceDistance = 1.0; |
|
nested const DefaultMaxDistance = 10000.0; |
|
Methods
procedure Loaded; override; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
function PropertySections(const PropertyName: String): TPropertySections; override; |
|
function Duration: Single; |
|
Duration of the sound, in seconds. -1 if not loaded yet. The sound is loaded once you set URL and don't get any loading exceptions. |
function DataFormat: TSoundDataFormat; |
|
Sound data format (disregarding compression on top of it), for informational purposes. Undefined if not loaded yet. The sound is loaded once you set URL and don't get any loading exceptions. |
function Frequency: LongWord; |
|
Frequency (sample rate) of the loaded sound file. 0 if not loaded yet. The sound is loaded once you set URL and don't get any loading exceptions. |
Properties
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 Volume: Single read FVolume write SetVolume default 1.0; |
|
Volume (how loud the sound is). Use this to indicate that e.g. a plane engine is louder than a mouse squeak (when heard from the same distance). Note: Do not make the actual sound data (in sound files) louder/more silent to express that something is louder/more silent in reality. This would usually lower the sound quality. Instead, keep your sound file data at max loudness ("normalized"), and use this property to adjust the volume associated with the sound. The effective sound volume is a multiplication of TCastleSound.Volume, TCastlePlayingSound.Volume and TCastleSoundSource.Volume (if the sound is played through TCastleSoundSource). It is also affected by spatial calculations (if the sound is played through TCastleSoundSource with TCastleSoundSource.Spatial = Any value > 0 is allowed. The default is 1. Note that, while values > 1 are allowed, but some sound backends (like OpenAL) may clip the resulting sound volume (after all volume influences, including spatial calculations are done) to 1.0. |
property Pitch: Single read FPitch write SetPitch default 1.0; |
|
Sound playing speed. The effective sound pitch is a multiplication of TCastleSound.Pitch, TCastlePlayingSound.Pitch and TCastleSoundSource.Pitch (if the sound is played through TCastleSoundSource). Changing this naturally also changes the audible sound. Each reduction by 50 percent equals a pitchshift of -12 semitones (one octave reduction). Each doubling equals a pitch shift of 12 semitones (one octave increase). Any value > 0 is allowed. |
property ReferenceDistance: Single read FReferenceDistance write SetReferenceDistance
default DefaultReferenceDistance; |
|
Spatial sound is fully audible (with Volume) at this distance. See TSoundDistanceModel for a description how distance affects the sound volume. |
property MaxDistance: Single read FMaxDistance write SetMaxDistance
default DefaultMaxDistance; |
|
Distance at which sound volume stops attenuating. For the linear distance model (SoundEngine.DistanceModel = dmLinear) this is also a distance at which sound volume drops to zero (completely silent). See TSoundDistanceModel for a description how distance affects the sound volume. |
Generated by PasDoc 0.16.0.