Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

AudioStreamRandomizer

繼承: AudioStream < Resource < RefCounted < Object

以音高與音量偏移封裝一個音訊流池。

說明

依播放模式,從池中隨機選擇 AudioStream,並在播放時施加隨機音高與音量偏移。

教學

屬性

PlaybackMode

playback_mode

0

float

random_pitch

1.0

float

random_pitch_semitones

0.0

float

random_volume_offset_db

0.0

AudioStream

stream_{index}/stream

float

stream_{index}/weight

1.0

int

streams_count

0

方法

void

add_stream(index: int, stream: AudioStream, weight: float = 1.0)

AudioStream

get_stream(index: int) const

float

get_stream_probability_weight(index: int) const

void

move_stream(index_from: int, index_to: int)

void

remove_stream(index: int)

void

set_stream(index: int, stream: AudioStream)

void

set_stream_probability_weight(index: int, weight: float)


列舉

enum PlaybackMode: 🔗

PlaybackMode PLAYBACK_RANDOM_NO_REPEATS = 0

依各流的權重隨機選擇,但盡量避免連續兩次播放同一條流。若池中僅有一條聲音,則必然重複播放。

PlaybackMode PLAYBACK_RANDOM = 1

依各流的權重隨機選擇流。若池中僅有一條聲音,則必然重複播放同一聲音。

PlaybackMode PLAYBACK_SEQUENTIAL = 2

依流池中的順序播放。若池中只剩一條聲音,則始終播放同一聲音。


屬性說明

PlaybackMode playback_mode = 0 🔗

控制 AudioStreamRandomizer 決定下一條要播放的 AudioStream 的方式。


float random_pitch = 1.0 🔗

  • void set_random_pitch(value: float)

  • float get_random_pitch()

The largest possible frequency multiplier of the random pitch variation. Pitch will be randomly chosen within a range of 1.0 / random_pitch and random_pitch. 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.


float random_pitch_semitones = 0.0 🔗

  • void set_random_pitch_semitones(value: float)

  • float 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.


float random_volume_offset_db = 0.0 🔗

  • void set_random_volume_offset_db(value: float)

  • float get_random_volume_offset_db()

The intensity of random volume variation. Volume will be increased or decreased by a random value up to random_volume_offset_db. 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.


AudioStream stream_{index}/stream 🔗

The AudioStream at index.

Note: index is a value in the 0 .. streams_count - 1 range.


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.


int streams_count = 0 🔗

  • void set_streams_count(value: int)

  • int get_streams_count()

流池中的音訊流數量。


方法說明

void add_stream(index: int, stream: AudioStream, weight: float = 1.0) 🔗

在指定索引插入一條音訊流;若索引小於零,則插入至池末端。


AudioStream get_stream(index: int) const 🔗

返回指定索引處的音訊流。


float get_stream_probability_weight(index: int) const 🔗

返回指定索引處音訊流的機率權重。


void move_stream(index_from: int, index_to: int) 🔗

將音訊流從一個索引移動到另一個索引。


void remove_stream(index: int) 🔗

移除指定索引處的音訊流。


void set_stream(index: int, stream: AudioStream) 🔗

設定指定索引處的 AudioStream。


void set_stream_probability_weight(index: int, weight: float) 🔗

設定指定索引處音訊流的機率權重。值越高,隨機播放模式就越容易選到此流。