Debian Codegraph @

doc/classes/AudioStreamWAV.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="AudioStreamWAV" inherits="AudioStream" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 Stores audio data loaded from WAV files.
5 </brief_description>
6 <description>
7 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.
8 This class can also be used to store dynamically-generated PCM audio data. See also [AudioStreamGenerator] for procedural audio generation.
9 </description>
10 <tutorials>
11 <link title="Runtime file loading and saving">$DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html</link>
12 </tutorials>
13 <methods>
14 <method name="load_from_buffer" qualifiers="static">
15 <return type="AudioStreamWAV" />
16 <param index="0" name="stream_data" type="PackedByteArray" />
17 <param index="1" name="options" type="Dictionary" default="{}" />
18 <description>
19 Creates a new [AudioStreamWAV] instance from the given buffer. The buffer must contain WAV data.
20 The keys and values of [param options] match the properties of [ResourceImporterWAV]. The usage of [param options] is identical to [method AudioStreamWAV.load_from_file].
21 </description>
22 </method>
23 <method name="load_from_file" qualifiers="static">
24 <return type="AudioStreamWAV" />
25 <param index="0" name="path" type="String" />
26 <param index="1" name="options" type="Dictionary" default="{}" />
27 <description>
28 Creates a new [AudioStreamWAV] instance from the given file path. The file must be in WAV format.
29 The keys and values of [param options] match the properties of [ResourceImporterWAV].
30 [b]Example:[/b] Load the first file dropped as a WAV and play it:
31 [codeblock]
32 @onready var audio_player = $AudioStreamPlayer
33
34 func _ready():
35 get_window().files_dropped.connect(_on_files_dropped)
36
37 func _on_files_dropped(files):
38 if files[0].get_extension() == "wav":
39 audio_player.stream = AudioStreamWAV.load_from_file(files[0], {
40 "force/max_rate": true,
41 "force/max_rate_hz": 11025
42 })
43 audio_player.play()
44 [/codeblock]
45 </description>
46 </method>
47 <method name="save_to_wav">
48 <return type="int" enum="Error" />
49 <param index="0" name="path" type="String" />
50 <description>
51 Saves the AudioStreamWAV as a WAV file to [param path]. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.
52 [b]Note:[/b] A [code].wav[/code] extension is automatically appended to [param path] if it is missing.
53 </description>
54 </method>
55 </methods>
56 <members>
57 <member name="data" type="PackedByteArray" setter="set_data" getter="get_data" default="PackedByteArray()">
58 Contains the audio data in bytes.
59 [b]Note:[/b] If [member format] is set to [constant FORMAT_8_BITS], this property expects signed 8-bit PCM data. To convert from unsigned 8-bit PCM, subtract 128 from each byte.
60 [b]Note:[/b] If [member format] is set to [constant FORMAT_QOA], this property expects data from a full QOA file.
61 </member>
62 <member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamWAV.Format" default="0">
63 Audio format.
64 </member>
65 <member name="loop_begin" type="int" setter="set_loop_begin" getter="get_loop_begin" default="0">
66 The loop start point (in number of samples, relative to the beginning of the stream).
67 </member>
68 <member name="loop_end" type="int" setter="set_loop_end" getter="get_loop_end" default="0">
69 The loop end point (in number of samples, relative to the beginning of the stream).
70 </member>
71 <member name="loop_mode" type="int" setter="set_loop_mode" getter="get_loop_mode" enum="AudioStreamWAV.LoopMode" default="0">
72 The loop mode.
73 </member>
74 <member name="mix_rate" type="int" setter="set_mix_rate" getter="get_mix_rate" default="44100">
75 The sample rate for mixing this audio. Higher values require more storage space, but result in better quality.
76 In games, common sample rates in use are [code]11025[/code], [code]16000[/code], [code]22050[/code], [code]32000[/code], [code]44100[/code], and [code]48000[/code].
77 According to the [url=https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem]Nyquist-Shannon sampling theorem[/url], 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 [code]32000[/code] or [code]22050[/code] may be usable with no loss in quality.
78 </member>
79 <member name="stereo" type="bool" setter="set_stereo" getter="is_stereo" default="false">
80 If [code]true[/code], audio is stereo.
81 </member>
82 <member name="tags" type="Dictionary" setter="set_tags" getter="get_tags" default="{}">
83 Contains user-defined tags if found in the WAV data.
84 Commonly used tags include [code]title[/code], [code]artist[/code], [code]album[/code], [code]tracknumber[/code], and [code]date[/code] ([code]date[/code] does not have a standard date format).
85 [b]Note:[/b] No tag is [i]guaranteed[/i] to be present in every file, so make sure to account for the keys not always existing.
86 [b]Note:[/b] Only WAV files using a [code]LIST[/code] chunk with an identifier of [code]INFO[/code] to encode the tags are currently supported.
87 </member>
88 </members>
89 <constants>
90 <constant name="FORMAT_8_BITS" value="0" enum="Format">
91 8-bit PCM audio codec.
92 </constant>
93 <constant name="FORMAT_16_BITS" value="1" enum="Format">
94 16-bit PCM audio codec.
95 </constant>
96 <constant name="FORMAT_IMA_ADPCM" value="2" enum="Format">
97 Audio is lossily compressed as IMA ADPCM.
98 </constant>
99 <constant name="FORMAT_QOA" value="3" enum="Format">
100 Audio is lossily compressed as [url=https://qoaformat.org/]Quite OK Audio[/url].
101 </constant>
102 <constant name="LOOP_DISABLED" value="0" enum="LoopMode">
103 Audio does not loop.
104 </constant>
105 <constant name="LOOP_FORWARD" value="1" enum="LoopMode">
106 Audio loops the data between [member loop_begin] and [member loop_end], playing forward only.
107 </constant>
108 <constant name="LOOP_PINGPONG" value="2" enum="LoopMode">
109 Audio loops the data between [member loop_begin] and [member loop_end], playing back and forth.
110 </constant>
111 <constant name="LOOP_BACKWARD" value="3" enum="LoopMode">
112 Audio loops the data between [member loop_begin] and [member loop_end], playing backward only.
113 </constant>
114 </constants>
115 </class>