f18d408c08
* This new audio stream allows to play multiple sounds and control them over time from code. * It greatly simplifies tasks such as generative music (music generated from code) or audio. This new type of stream was added with the goal of fixing audio blending in AnimationPlayer and AnimationTree, but can be used by others for their regular audio needs. Does not fix anything currently, but should help implement #69758 properly. Some demo code of how to use this: ```GDScript var player = $SomeNode as AudioStreamPlayer player.stream = AudioStreamPolyphonic.new() var playback = player.get_stream_playback() as AudioStreamPlaybackPolyphonic var id = playback.play_stream(preload("res://Clip1.ogg")) await get_tree().create_timer(1).timeout playback.set_stream_volume(id,-12) # Set volume to half after one second await get_tree().create_timer(2).timeout var id2 = playback.play_stream(preload("res://Clip2.ogg")) # 2 seconds later, start another clip await get_tree().create_timer(1).timeout playback.stop_stream(id) # 1 second later, kill the first clip playback.set_stream_pitch_scale(id2,1.5) # Make the second clip go 50% faster ```
61 lines
3.1 KiB
XML
61 lines
3.1 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<class name="AudioStreamPlaybackPolyphonic" inherits="AudioStreamPlayback" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
|
|
<brief_description>
|
|
Playback instance for [AudioStreamPolyphonic].
|
|
</brief_description>
|
|
<description>
|
|
Playback instance for [AudioStreamPolyphonic]. After setting the [code]stream[/code] property of [AudioStreamPlayer], [AudioStreamPlayer2D], or [AudioStreamPlayer3D], the playback instance can be obtained by calling [method AudioStreamPlayer.get_stream_playback], [method AudioStreamPlayer2D.get_stream_playback] or [method AudioStreamPlayer3D.get_stream_playback] methods.
|
|
</description>
|
|
<tutorials>
|
|
</tutorials>
|
|
<methods>
|
|
<method name="is_stream_playing" qualifiers="const">
|
|
<return type="bool" />
|
|
<param index="0" name="stream" type="int" />
|
|
<description>
|
|
Return true whether the stream associated with an integer ID is still playing. Check [method play_stream] for information on when this ID becomes invalid.
|
|
</description>
|
|
</method>
|
|
<method name="play_stream">
|
|
<return type="int" />
|
|
<param index="0" name="stream" type="AudioStream" />
|
|
<param index="1" name="from_offset" type="float" default="0" />
|
|
<param index="2" name="volume_db" type="float" default="0" />
|
|
<param index="3" name="pitch_scale" type="float" default="1.0" />
|
|
<description>
|
|
Play an [AudioStream] at a given offset, volume and pitch scale. Playback starts immediately.
|
|
The return value is an unique integer ID that is associated to this playback stream and which can be used to controll it.
|
|
This ID becomes invalid when the stream ends (if it does not loop), when the [AudioStreamPlaybackPolyphonic] is stopped, or when [method stop_stream] is called.
|
|
This function returns [constant INVALID_ID] if the amount of streams currently playing equals [member AudioStreamPolyphonic.polyphony]. If you need a higher amount of maximum polyphony, raise this value.
|
|
</description>
|
|
</method>
|
|
<method name="set_stream_pitch_scale">
|
|
<return type="void" />
|
|
<param index="0" name="stream" type="int" />
|
|
<param index="1" name="pitch_scale" type="float" />
|
|
<description>
|
|
Change the stream pitch scale. The [param stream] argument is an integer ID returned by [method play_stream].
|
|
</description>
|
|
</method>
|
|
<method name="set_stream_volume">
|
|
<return type="void" />
|
|
<param index="0" name="stream" type="int" />
|
|
<param index="1" name="volume_db" type="float" />
|
|
<description>
|
|
Change the stream volume (in db). The [param stream] argument is an integer ID returned by [method play_stream].
|
|
</description>
|
|
</method>
|
|
<method name="stop_stream">
|
|
<return type="void" />
|
|
<param index="0" name="stream" type="int" />
|
|
<description>
|
|
Stop a stream. The [param stream] argument is an integer ID returned by [method play_stream], which becomes invalid after calling this function.
|
|
</description>
|
|
</method>
|
|
</methods>
|
|
<constants>
|
|
<constant name="INVALID_ID" value="-1">
|
|
Returned by [method play_stream] in case it could not allocate a stream for playback.
|
|
</constant>
|
|
</constants>
|
|
</class>
|