AudioStreamRandomizer
Inherits: AudioStream < Resource < Shared < Object
Wraps a pool of audio streams with pitch and volume shifting.
Description
Section titled “Description”Picks a random AudioStream from the pool, depending on the playback mode, and applies random pitch shifting and volume shifting during playback.
Properties
Section titled “Properties”Methods
Section titled “Methods”| Returns | Method |
|---|---|
| void | add_stream(index, stream, weight) |
| AudioStream | get_stream(index) |
| float | get_stream_probability_weight(index) |
| void | move_stream(index_from, index_to) |
| void | remove_stream(index) |
| void | set_stream(index, stream) |
| void | set_stream_probability_weight(index, weight) |
Enumerations and constants
Section titled “Enumerations and constants”enum PlaybackMode
Section titled “enum PlaybackMode”- PLAYBACK_RANDOM_NO_REPEATS =
0— Pick a stream at random according to the probability weights chosen for each stream, but avoid playing the same stream twice in a row whenever possible. If only 1 sound is present in the pool, the same sound will always play, effectively allowing repeats to occur.
- PLAYBACK_RANDOM =
1— Pick a stream at random according to the probability weights chosen for each stream. If only 1 sound is present in the pool, the same sound will always play.
- PLAYBACK_SEQUENTIAL =
2— Play streams in the order they appear in the stream pool. If only 1 sound is present in the pool, the same sound will always play.
Property descriptions
Section titled “Property descriptions”playback_mode
Section titled “playback_mode”AudioStreamRandomizer.PlaybackMode playback_mode = 0
Setter/getter: set_playback_mode(), get_playback_mode()
Controls how this AudioStreamRandomizer picks which AudioStream to play next.
random_pitch
Section titled “random_pitch”float random_pitch = 1.0
Setter/getter: set_random_pitch(), get_random_pitch()
The largest possible frequency multiplier of the random pitch variation. Pitch will be randomly chosen within a range of [code skip-lint]1.0 / random_pitch[/code] and [code skip-lint]random_pitch[/code]. A value of 1.0 means no variation. A value of 2.0 means pitch will be randomized between double and half.
Note: Setting this property also sets random_pitch_semitones.
random_pitch_semitones
Section titled “random_pitch_semitones”float random_pitch_semitones = 0.0
Setter/getter: set_random_pitch_semitones(), get_random_pitch_semitones()
The largest possible distance, in semitones, of the random pitch variation. A value of 0.0 means no variation.
Note: Setting this property also sets random_pitch.
random_volume_offset_db
Section titled “random_volume_offset_db”float random_volume_offset_db = 0.0
Setter/getter: set_random_volume_offset_db(), get_random_volume_offset_db()
The intensity of random volume variation. Volume will be increased or decreased by a random value up to [code skip-lint]random_volume_offset_db[/code]. A value of 0.0 means no variation. A value of 3.0 means volume will be randomized between -3.0 dB and +3.0 dB.
stream_{index}/stream
Section titled “stream_{index}/stream”AudioStream stream_{index}/stream
The AudioStream at index.
Note: index is a value in the 0 .. streams_count - 1 range.
stream_{index}/weight
Section titled “stream_{index}/weight”float stream_{index}/weight = 1.0
The probability weight of the AudioStream at index.
Note: index is a value in the 0 .. streams_count - 1 range.
streams_count
Section titled “streams_count”int streams_count = 0
Setter/getter: set_streams_count(), get_streams_count()
The number of streams in the stream pool.
Method descriptions
Section titled “Method descriptions”add_stream
Section titled “add_stream”void add_stream(index: int, stream: AudioStream, weight: float = 1.0)
Insert a stream at the specified index. If the index is less than zero, the insertion occurs at the end of the underlying pool.
get_stream
Section titled “get_stream”AudioStream get_stream(index: int) const
Returns the stream at the specified index.
get_stream_probability_weight
Section titled “get_stream_probability_weight”float get_stream_probability_weight(index: int) const
Returns the probability weight associated with the stream at the given index.
move_stream
Section titled “move_stream”void move_stream(index_from: int, index_to: int)
Move a stream from one index to another.
remove_stream
Section titled “remove_stream”void remove_stream(index: int)
Remove the stream at the specified index.
set_stream
Section titled “set_stream”void set_stream(index: int, stream: AudioStream)
Set the AudioStream at the specified index.
set_stream_probability_weight
Section titled “set_stream_probability_weight”void set_stream_probability_weight(index: int, weight: float)
Set the probability weight of the stream at the specified index. The higher this value, the more likely that the randomizer will choose this stream during random playback modes.