Skip to content

Latest commit

 

History

History
84 lines (57 loc) · 4.33 KB

class_audiostreamgenerator.rst

File metadata and controls

84 lines (57 loc) · 4.33 KB
github_url:hide

AudioStreamGenerator

Inherits: :ref:`AudioStream<class_AudioStream>` < :ref:`Resource<class_Resource>` < :ref:`RefCounted<class_RefCounted>` < :ref:`Object<class_Object>`

Audio stream that generates sounds procedurally.

Description

This audio stream does not play back sounds, but expects a script to generate audio data for it instead. See also :ref:`AudioStreamGeneratorPlayback<class_AudioStreamGeneratorPlayback>`.

See also :ref:`AudioEffectSpectrumAnalyzer<class_AudioEffectSpectrumAnalyzer>` for performing real-time audio spectrum analysis.

Note: Due to performance constraints, this class is best used from C# or from a compiled language via GDExtension. If you still want to use this class from GDScript, consider using a lower :ref:`mix_rate<class_AudioStreamGenerator_property_mix_rate>` such as 11,025 Hz or 22,050 Hz.

Tutorials

Properties

:ref:`float<class_float>` :ref:`buffer_length<class_AudioStreamGenerator_property_buffer_length>` 0.5
:ref:`float<class_float>` :ref:`mix_rate<class_AudioStreamGenerator_property_mix_rate>` 44100.0

Property Descriptions

Default 0.5
Setter set_buffer_length(value)
Getter get_buffer_length()

The length of the buffer to generate (in seconds). Lower values result in less latency, but require the script to generate audio data faster, resulting in increased CPU usage and more risk for audio cracking if the CPU can't keep up.


Default 44100.0
Setter set_mix_rate(value)
Getter get_mix_rate()

The sample rate to use (in Hz). Higher values are more demanding for the CPU to generate, but result in better quality.

In games, common sample rates in use are 11025, 16000, 22050, 32000, 44100, and 48000.

According to the Nyquist-Shannon sampling theorem, there is no quality difference to human hearing when going past 40,000 Hz (since most humans can only hear up to ~20,000 Hz, often less). If you are generating lower-pitched sounds such as voices, lower sample rates such as 32000 or 22050 may be usable with no loss in quality.