Skip to content
0.2.0-dev Download ZIP
116 lines ·6.6 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="AudioStreamWAV" inherits="AudioStream" api_type="core" 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="Audio streams">$DOCS_URL/tutorials/audio/audio_streams.html</link>
12 <link title="Runtime file loading and saving">$DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html</link>
13 </tutorials>
14 <methods>
15 <method name="load_from_buffer" qualifiers="static">
16 <return type="AudioStreamWAV" />
17 <param index="0" name="stream_data" type="PackedByteArray" />
18 <param index="1" name="options" type="Dictionary" default="{}" />
19 <description>
20 Creates a new [AudioStreamWAV] instance from the given buffer. The buffer must contain WAV data.
21 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].
22 </description>
23 </method>
24 <method name="load_from_file" qualifiers="static">
25 <return type="AudioStreamWAV" />
26 <param index="0" name="path" type="String" />
27 <param index="1" name="options" type="Dictionary" default="{}" />
28 <description>
29 Creates a new [AudioStreamWAV] instance from the given file path. The file must be in WAV format.
30 The keys and values of [param options] match the properties of [ResourceImporterWAV].
31 [b]Example:[/b] Load the first file dropped as a WAV and play it:
32 [codeblock]
33 @onready var audio_player = $AudioStreamPlayer
34
35 func _ready():
36 get_window().files_dropped.connect(_on_files_dropped)
37
38 func _on_files_dropped(files):
39 if files[0].get_extension() == "wav":
40 audio_player.stream = AudioStreamWAV.load_from_file(files[0], {
41 "force/max_rate": true,
42 "force/max_rate_hz": 11025
43 })
44 audio_player.play()
45 [/codeblock]
46 </description>
47 </method>
48 <method name="save_to_wav">
49 <return type="int" enum="Error" />
50 <param index="0" name="path" type="String" />
51 <description>
52 Saves the AudioStreamWAV as a WAV file to [param path]. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.
53 [b]Note:[/b] A [code].wav[/code] extension is automatically appended to [param path] if it is missing.
54 </description>
55 </method>
56 </methods>
57 <members>
58 <member name="data" type="PackedByteArray" setter="set_data" getter="get_data" default="PackedByteArray()">
59 Contains the audio data in bytes.
60 [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.
61 [b]Note:[/b] If [member format] is set to [constant FORMAT_QOA], this property expects data from a full QOA file.
62 </member>
63 <member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamWAV.Format" default="0">
64 Audio format.
65 </member>
66 <member name="loop_begin" type="int" setter="set_loop_begin" getter="get_loop_begin" default="0">
67 The loop start point (in number of samples, relative to the beginning of the stream).
68 </member>
69 <member name="loop_end" type="int" setter="set_loop_end" getter="get_loop_end" default="0">
70 The loop end point (in number of samples, relative to the beginning of the stream).
71 </member>
72 <member name="loop_mode" type="int" setter="set_loop_mode" getter="get_loop_mode" enum="AudioStreamWAV.LoopMode" default="0">
73 The loop mode.
74 </member>
75 <member name="mix_rate" type="int" setter="set_mix_rate" getter="get_mix_rate" default="44100">
76 The sample rate for mixing this audio. Higher values require more storage space, but result in better quality.
77 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].
78 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.
79 </member>
80 <member name="stereo" type="bool" setter="set_stereo" getter="is_stereo" default="false">
81 If [code]true[/code], audio is stereo.
82 </member>
83 <member name="tags" type="Dictionary" setter="set_tags" getter="get_tags" default="{}">
84 Contains user-defined tags if found in the WAV data.
85 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).
86 [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.
87 [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.
88 </member>
89 </members>
90 <constants>
91 <constant name="FORMAT_8_BITS" value="0" enum="Format">
92 8-bit PCM audio codec.
93 </constant>
94 <constant name="FORMAT_16_BITS" value="1" enum="Format">
95 16-bit PCM audio codec.
96 </constant>
97 <constant name="FORMAT_IMA_ADPCM" value="2" enum="Format">
98 Audio is lossily compressed as IMA ADPCM.
99 </constant>
100 <constant name="FORMAT_QOA" value="3" enum="Format">
101 Audio is lossily compressed as [url=https://qoaformat.org/]Quite OK Audio[/url].
102 </constant>
103 <constant name="LOOP_DISABLED" value="0" enum="LoopMode">
104 Audio does not loop.
105 </constant>
106 <constant name="LOOP_FORWARD" value="1" enum="LoopMode">
107 Audio loops the data between [member loop_begin] and [member loop_end], playing forward only.
108 </constant>
109 <constant name="LOOP_PINGPONG" value="2" enum="LoopMode">
110 Audio loops the data between [member loop_begin] and [member loop_end], playing back and forth.
111 </constant>
112 <constant name="LOOP_BACKWARD" value="3" enum="LoopMode">
113 Audio loops the data between [member loop_begin] and [member loop_end], playing backward only.
114 </constant>
115 </constants>
116</class>