Module: sfx

Sound effects API. Uses Web Audio API for sound effects and HTML5 audio for background music.

Summary

Methods

Detailed Description

Methods

apply_playlist(objs, delay, random)

Apply the new playlist from the given set of speakers. The new playlist starts playing immediately.
Parameters:
Name Type Description
objs Array.<Object3D> Array of objects.
delay number Number of seconds between tracks
random boolean Randomize playback sequence
Source:

check_active_speakers() → {boolean}

Check if there are some active speakers in use or not.
Returns:
Check result
Type
boolean
Source:

clear_playlist()

Stop playback and clear the playlist.
Source:

cyclic(obj, cyclic)

Set cyclic flag.
Parameters:
Name Type Description
obj Object3D Speaker object.
cyclic boolean New cyclic flag value.
Source:

detect_audio_container(hintopt) → {string}

Detect supported audio container. Containers have same meaning as file extension here, for each one possible fallback exists:
  • ogg -> mp4
  • mp3 -> ogg
  • mp4 -> ogg
Parameters:
Name Type Attributes Default Description
hint string <optional>
"ogg" Required container
Returns:
Supported container or ""
Type
string
Source:

detect_video_container(hintopt) → {string}

Detect supported video container. Containers have same meaning as file extension here, for each one possible fallback exists:
  • ogv -> m4v
  • m4v -> webm
  • webm -> m4v
Parameters:
Name Type Attributes Default Description
hint string <optional>
"webm" Required container
Returns:
Supported container or ""
Type
string
Source:

duck(objnullable, value, time)

Duck (reduce the volume). works independently from the volume API and the volume randomization
Parameters:
Name Type Attributes Description
obj Object3D <nullable>
Object 3D or null for MASTER
value number Duck amount.
time number Time to change volume.
Source:

get_compressor_params() → {CompressorParams}

Get compressor params.
Returns:
Params object
Type
CompressorParams
Source:

get_duration(objnullable) → {number}

Get duration of the speaker's playback cycle. Zero duration means looped or non-ready speaker
Parameters:
Name Type Attributes Description
obj Object3D <nullable>
Speaker object.
Returns:
Duration
Type
number
Source:

get_filter_freq_response(obj, freq_arr, mag_arr, phase_arr)

Get filter frequency response.
Parameters:
Name Type Description
obj Object3D Object 3D
freq_arr Float32Array Input array with frequencies.
mag_arr Float32Array Output array with filter response magnitudes.
phase_arr Float32Array Output array with filter response phases.
Source:

get_filter_params(obj) → {FilterParams}

Get filter params.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Params object
Type
FilterParams
Source:

get_positional_params(obj) → {PositionalParams}

Get positional params.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Params object
Type
PositionalParams
Source:

get_speaker_objects() → {Array}

Get the speaker objects which are used by the module.
Returns:
Speaker object array
Type
Array
Source:

get_volume(objnullable) → {number}

Get volume level.
Parameters:
Name Type Attributes Description
obj Object3D <nullable>
Object 3D or null for MASTER volume
Returns:
Volume (0..1)
Type
number
Source:

is_cyclic(obj) → {boolean}

Check if the cyclic flag is set.
Parameters:
Name Type Description
obj Object3D Speaker object.
Returns:
Cyclic flag value.
Type
boolean
Source:

is_muted(objnullable) → {boolean}

Check if the speaker is muted.
Parameters:
Name Type Attributes Description
obj Object3D <nullable>
Speaker object or null for the whole scene.
Returns:
Muted state.
Type
boolean
Source:

is_playing(obj) → {boolean}

Check if sound is played through the speaker now.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Playing state
Type
boolean
Source:

listener_reset_speed(speed, diropt, nullable)

Reset the listener speed. Use before rapid listener movements to neutralize undesirable doppler effect.
Parameters:
Name Type Attributes Default Description
speed number The listener new speed
dir Float32Array <optional>
<nullable>
null The listener new direction
Deprecated
Source:

listener_stride()

Make a listener stride. Use before quick listener movements to neutralize undesirable doppler effect.
Source:

loop_stop(obj, whenopt, waitopt)

Stop the speaker's looping playback.
Parameters:
Name Type Attributes Default Description
obj Object3D Speaker object
when number <optional>
0 Delay after exec in seconds
wait boolean <optional>
false Wait loop until currently played cycle is finished
Source:

mute(objnullable, muted)

Mute/unmute.
Parameters:
Name Type Attributes Description
obj Object3D <nullable>
Speaker object or null to mute the whole scene.
muted boolean New state
Source:

pause(obj)

Pause the speaker.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

play(obj, whenopt, durationopt)

Play sound through the speaker.
Parameters:
Name Type Attributes Default Description
obj Object3D Object 3D
when number <optional>
0 Delay after exec in seconds
duration number <optional>
0 Duration of the speaker's playback cycle (in seconds). duration=0 - assign default value according to sound playback length.
Source:

play_def(obj)

Play sound through the speaker using the default delay and duration params.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

playrate(obj) → {number}

Get the speaker playback rate value.
Parameters:
Name Type Description
obj Object3D Object 3D
Returns:
Playback rate
Type
number
Source:

playrate(obj, playrate)

Change the speaker playback rate value.
Parameters:
Name Type Description
obj Object3D Object 3D
playrate number Playback rate (1.0 - normal speed).
Source:

resume(obj)

Resume the paused speaker.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

set_compressor_params(params)

Set compressor params.
Parameters:
Name Type Description
params CompressorParams Params object
Source:

set_filter_params(obj, params)

Set filter params.
Parameters:
Name Type Description
obj Object3D Object 3D
params FilterParams Params object
Source:

set_positional_params(obj, params)

Set positional params.
Parameters:
Name Type Description
obj Object3D Object 3D
params PositionalParams Params object
Source:

set_volume(objnullable, volume)

Set volume level.
Parameters:
Name Type Attributes Description
obj Object3D <nullable>
Object 3D or null for MASTER volume
volume number Volume (0..1)
Source:

speaker_reset_speed(obj, speed, diropt, nullable)

Reset the speaker speed. It's necessary to nullify speed before the speaker has moved quickly in order to neutralize the undesirable doppler effect.
Parameters:
Name Type Attributes Default Description
obj Object3D Speaker object.
speed number The speaker's new speed
dir Float32Array <optional>
<nullable>
null The speaker's new direction
Deprecated
  • Use sfx.speaker_stride instead
Source:

speaker_reset_speed(obj)

Make a speaker stride. Use before rapid speaker movements to neutralize undesirable doppler effect.
Parameters:
Name Type Description
obj Object3D Speaker object.
Source:

stop(obj)

Stop the speaker.
Parameters:
Name Type Description
obj Object3D Object 3D
Source:

unduck(objnullable)

Unduck (restore the volume).
Parameters:
Name Type Attributes Description
obj Object3D <nullable>
Object 3D or null for MASTER
Source: