Sound
From Leadwerks Developer Wiki
Contents |
Introduction
Sounds in games have obvious effects to the atmosphere of the game, and can make or break the gaming experience. Therefore, the commands in Leadwerks Engine 2 allow complete access to sounds, including modifying the sounds with EAX effects.
The sound system was rewritten for version 2.1.1, to give more complete control over sound playback and settings.
Tutorials
Commands
Sound Commands
LoadSound
- C: TSound LoadSound( str filename )
- C++:
- Sound( const std::string& filename )
- virtual void Sound::Load( const std::string& filename )
- BlitzMax: LoadSound:TSound( filename:String )
- Lua: LoadSound ( filename )
- Pascal: function LoadSound ( filename:PAnsiChar ): THandle;
- This command loads a sound from an audio file. The formats that the engine can load are OGG and WAV. The LoadSound function will return a handle to any previously loaded sound from the same file to avoid loading assets twice.
- [Examples]
PlaySound
- C: void PlaySound(TSound sound)
- C++: void Sound::Play( void )
- BlitzMax: PlaySound:TSource( sound:TSound)
- Lua: PlaySound ( sound )
- Pascal: procedure PlaySound ( sound:THandle);
- This command plays a sound that is loaded into the engine, using the LoadSound command. For convenience PlaySound does not return a source in the DLL, because this source would have to be freed everytime a sound was played.
- [Examples]
EmitSound
- C: TSource EmitSound( TEntity entity, TEntity sound, flt range=10.0, flt volume=1.0, int flags=SOURCE_EAX )
- C++: void Entity::EmitSound( const Sound& sound, flt range, flt volume, int flags )
- BlitzMax: EmitSound:TSource( entity:TEntity, sound:TSound, range:Float=10.0, volume:Float=1.0, flags:Int=SOURCE_EAX )
- Pascal: procedure EmitSound ( entity:THandle; sound:THandle; range:Single=10; volume:Single=1; flags:Integer=0 );
- This command plays a sound which originates from the position of an entity. The sound must be loaded into the engine using the LoadSound command. The range parameter specifies the range in which the sound can be heard and the volume parameter specifies the volume at which the sound should play. Only mono sounds can be spatialized. Flags are:
- SOURCE_EAX (makes the sound play one single time)
- SOURCE_LOOP (makes the sound loop)
- [Examples]
FreeSound
- C: void FreeSound( TSound sound )
- C++: void Sound::Free( void ) Note: Also called from destructor
- Pascal: procedure FreeSound ( sound:THandle );
- Frees a sound from memory.
- [Examples]
Source Commands
CreateSource
- C: TSource CreateSource( TSound sound, int flags=SOURCE_EAX )
- C++: void Create( const Sound& sound, int mode )
- BlitzMax: CreateSource:TSource( TSound sound, inf flags = SOURCE_EAX )
- Pascal: function CreateSource ( sound:THandle; flags:Integer=0 ): THandle;
- Creates a source with the specified sound and returns it without playing the sound. This allows you to set advanced properties before playing the sound. Possible flags/modes are:
- SOURCE_EAX (makes the sound play one single time)
- SOURCE_LOOP (makes the sound loop)
- [Examples]
PlaySource
- C: void PlaySource(TSource source)
- C++: void Source::Play( void )
- Pascal: procedure PlaySource ( source:THandle );
- Plays the sound of the specified source.
- [Examples]
PauseSource
- C: void PauseSource(TSource source)
- C++: void Source::Pause( void )
- Pascal: procedure PauseSource ( source:THandle );
- Pauses the specified source.
- [Examples]
ResumeSource
- C: void ResumeSource(TSource source)
- C++: void Source::Resume( void)
- Pascal: procedure ResumeSource ( source:THandle );
- Resumes (= starts from current position) the specified source.
- [Examples]
StopSource
- C: void StopSource(TSource source)
- C++: void Source::Stop( void )
- Pascal: procedure StopSource ( source:THandle );
- Stops the specified source.
- [Examples]
GetSourceState
- C: int GetSourceState(TSource source)
- C++: SourceState Source::GetState( void ) const
- Pascal: function GetSourceState ( source:THandle ): Integer;
- Returns the current state the specified source. Return values are:
- SOURCE_STOPPED
- SOURCE_PLAYING
- SOURCE_PAUSED
SetSourceVolume
- C: void SetSourceVolume(TSource source, flt volume )
- C++: void Source::SetVolume( flt volume )
- Pascal: procedure SetSourceVolume ( source:THandle; volume:Single );
- Sets the volume of the specified source. A volume of 0.0 is silent and a volume of 1.0 is normal.
- [Examples]
SetSourcePitch
- C: void SetSourcePitch(TSource source, flt pitch=1)
- C++: void Source::SetPitch( flt pitch )
- Pascal: procedure SetSourcePitch ( source:THandle; pitch:Single=1 );
- Sets the pitch of the specified source.
- [Examples]
SetSourceRange
- C: void SetSourceRange(TSource source, flt range=50)
- C++: void Source::SetRange( flt range )
- Pascal: procedure SetSourceRange ( source:THandle; range:Single=50 );
- Sets the range of the specified source.
- [Examples]
SetSourcePosition
- C: void SetSourcePosition(TSource source, TVec3 &position=Vec3(0))
- C++: void Source::SetPosition( const TVec3& pos )
- Pascal: procedure SetSourcePosition ( source:THandle; const position:TVec3 );
- Sets the position of the specified source.
- [Examples]
FreeSource
- C: void FreeSource(TSource source)
- C++: void Source::Free( void ) Note: Also called from destructor
- Pascal: procedure FreeSource ( source:THandle );
- Frees the specified source from memory.
- [Examples]
EAX Commands
EAXSupported
- C: int EAXSupported( void )
- BlitzMax: EAXSupported:Int()
- Pascal: function EAXSupported: Integer;
- This command checks to see if EAX is supported on the user's machine, and returns the result.
- [Examples]
EAXEffect
- C: void EAXEffect( int effect, flt gain=1.0 )
- BlitzMax: EAXEffect( effect:Int, gain:Float=1.0 )
- Pascal: procedure EAXEffect ( effect:Integer=1; gain:Single=1 );
- Enables an EAX effect, as listed below:
- EAX_NORMAL = 0
- EAX_GENERIC = 1
- EAX_PADDEDCELL = 2
- EAX_ROOM = 3
- EAX_BATHROOM = 4
- EAX_LIVINGROOM = 5
- EAX_STONEROOM = 6
- EAX_AUDITORIUM = 7
- EAX_CONCERTHALL = 8
- EAX_CAVE = 9
- EAX_ARENA = 10
- EAX_HANGAR = 11
- EAX_CARPETTEDHALLWAY = 12
- EAX_HALLWAY = 13
- EAX_STONECORRIDOR = 14
- EAX_ALLEY = 15
- EAX_FOREST = 16
- EAX_CITY = 17
- EAX_MOUNTAINS = 18
- EAX_QUARRY = 19
- EAX_PLAIN = 20
- EAX_PARKINGLOT = 21
- EAX_SEWERPIPE = 22
- EAX_UNDERWATER = 23
- EAX_DRUGGED = 24
- EAX_DIZZY = 25
- EAX_PSYCHOTIC = 26
- [Examples]
