Class AudioStreamWav
- Namespace
- Godot
- Assembly
- GodotSharp.dll
AudioStreamWAV stores sound samples loaded from WAV files. To play the stored sound, use an AudioStreamPlayer (for non-positional audio) or AudioStreamPlayer2D/AudioStreamPlayer3D (for positional audio). The sound can be looped.
This class can also be used to store dynamically-generated PCM audio data. See also AudioStreamGenerator for procedural audio generation.
[GodotClassName("AudioStreamWAV")]
public class AudioStreamWav : AudioStream, IDisposable
- Inheritance
-
AudioStreamWav
- Implements
- Inherited Members
Constructors
AudioStreamWav()
public AudioStreamWav()
Properties
Data
Contains the audio data in bytes.
Note: If Format is set to Format8Bits, this property expects signed 8-bit PCM data. To convert from unsigned 8-bit PCM, subtract 128 from each byte.
Note: If Format is set to Qoa, this property expects data from a full QOA file.
public byte[] Data { get; set; }
Property Value
- byte[]
Format
Audio format. See AudioStreamWav.FormatEnum constants for values.
public AudioStreamWav.FormatEnum Format { get; set; }
Property Value
LoopBegin
The loop start point (in number of samples, relative to the beginning of the stream).
public int LoopBegin { get; set; }
Property Value
LoopEnd
The loop end point (in number of samples, relative to the beginning of the stream).
public int LoopEnd { get; set; }
Property Value
LoopMode
The loop mode. See AudioStreamWav.LoopModeEnum constants for values.
public AudioStreamWav.LoopModeEnum LoopMode { get; set; }
Property Value
MixRate
The sample rate for mixing this audio. Higher values require more storage space, 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 using lower-pitched sounds such as voices, lower sample rates such as 32000
or 22050
may be usable with no loss in quality.
public int MixRate { get; set; }
Property Value
Stereo
If true, audio is stereo.
public bool Stereo { get; set; }
Property Value
Methods
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
LoadFromBuffer(byte[], Dictionary)
Creates a new AudioStreamWav instance from the given buffer. The buffer must contain WAV data.
The keys and values of options
match the properties of ResourceImporterWav
. The usage of options
is identical to LoadFromFile(string, Dictionary).
public static AudioStreamWav LoadFromBuffer(byte[] streamData, Dictionary options = null)
Parameters
streamData
byte[]options
Dictionary
Returns
LoadFromBuffer(ReadOnlySpan<byte>, Dictionary)
Creates a new AudioStreamWav instance from the given buffer. The buffer must contain WAV data.
The keys and values of options
match the properties of ResourceImporterWav
. The usage of options
is identical to LoadFromFile(string, Dictionary).
public static AudioStreamWav LoadFromBuffer(ReadOnlySpan<byte> streamData, Dictionary options)
Parameters
streamData
ReadOnlySpan<byte>options
Dictionary
Returns
LoadFromFile(string, Dictionary)
Creates a new AudioStreamWav instance from the given file path. The file must be in WAV format.
The keys and values of options
match the properties of ResourceImporterWav
.
Example: Load the first file dropped as a WAV and play it:
@onready var audio_player = $AudioStreamPlayer
func _ready():
get_window().files_dropped.connect(_on_files_dropped)
func _on_files_dropped(files):
if files[0].get_extension() == "wav":
audio_player.stream = AudioStreamWAV.load_from_file(files[0], {
"force/max_rate": true,
"force/max_rate_hz": 11025
})
audio_player.play()
public static AudioStreamWav LoadFromFile(string path, Dictionary options = null)
Parameters
path
stringoptions
Dictionary
Returns
SaveToWav(string)
Saves the AudioStreamWAV as a WAV file to path
. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.
Note: A .wav
extension is automatically appended to path
if it is missing.
public Error SaveToWav(string path)
Parameters
path
string