AudioStreamWAV.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. func _ready():
  34. get_window().files_dropped.connect(_on_files_dropped)
  35. func _on_files_dropped(files):
  36. if files[0].get_extension() == "wav":
  37. audio_player.stream = AudioStreamWAV.load_from_file(files[0], {
  38. "force/max_rate": true,
  39. "force/max_rate_hz": 11025
  40. })
  41. audio_player.play()
  42. [/codeblock]
  43. </description>
  44. </method>
  45. <method name="save_to_wav">
  46. <return type="int" enum="Error" />
  47. <param index="0" name="path" type="String" />
  48. <description>
  49. Saves the AudioStreamWAV as a WAV file to [param path]. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.
  50. [b]Note:[/b] A [code].wav[/code] extension is automatically appended to [param path] if it is missing.
  51. </description>
  52. </method>
  53. </methods>
  54. <members>
  55. <member name="data" type="PackedByteArray" setter="set_data" getter="get_data" default="PackedByteArray()">
  56. Contains the audio data in bytes.
  57. [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.
  58. [b]Note:[/b] If [member format] is set to [constant FORMAT_QOA], this property expects data from a full QOA file.
  59. </member>
  60. <member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamWAV.Format" default="0">
  61. Audio format. See [enum Format] constants for values.
  62. </member>
  63. <member name="loop_begin" type="int" setter="set_loop_begin" getter="get_loop_begin" default="0">
  64. The loop start point (in number of samples, relative to the beginning of the stream).
  65. </member>
  66. <member name="loop_end" type="int" setter="set_loop_end" getter="get_loop_end" default="0">
  67. The loop end point (in number of samples, relative to the beginning of the stream).
  68. </member>
  69. <member name="loop_mode" type="int" setter="set_loop_mode" getter="get_loop_mode" enum="AudioStreamWAV.LoopMode" default="0">
  70. The loop mode. See [enum LoopMode] constants for values.
  71. </member>
  72. <member name="mix_rate" type="int" setter="set_mix_rate" getter="get_mix_rate" default="44100">
  73. The sample rate for mixing this audio. Higher values require more storage space, but result in better quality.
  74. 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].
  75. 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.
  76. </member>
  77. <member name="stereo" type="bool" setter="set_stereo" getter="is_stereo" default="false">
  78. If [code]true[/code], audio is stereo.
  79. </member>
  80. <member name="tags" type="Dictionary" setter="set_tags" getter="get_tags" default="{}">
  81. Contains user-defined tags if found in the WAV data.
  82. 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).
  83. [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.
  84. [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.
  85. </member>
  86. </members>
  87. <constants>
  88. <constant name="FORMAT_8_BITS" value="0" enum="Format">
  89. 8-bit PCM audio codec.
  90. </constant>
  91. <constant name="FORMAT_16_BITS" value="1" enum="Format">
  92. 16-bit PCM audio codec.
  93. </constant>
  94. <constant name="FORMAT_IMA_ADPCM" value="2" enum="Format">
  95. Audio is lossily compressed as IMA ADPCM.
  96. </constant>
  97. <constant name="FORMAT_QOA" value="3" enum="Format">
  98. Audio is lossily compressed as [url=https://qoaformat.org/]Quite OK Audio[/url].
  99. </constant>
  100. <constant name="LOOP_DISABLED" value="0" enum="LoopMode">
  101. Audio does not loop.
  102. </constant>
  103. <constant name="LOOP_FORWARD" value="1" enum="LoopMode">
  104. Audio loops the data between [member loop_begin] and [member loop_end], playing forward only.
  105. </constant>
  106. <constant name="LOOP_PINGPONG" value="2" enum="LoopMode">
  107. Audio loops the data between [member loop_begin] and [member loop_end], playing back and forth.
  108. </constant>
  109. <constant name="LOOP_BACKWARD" value="3" enum="LoopMode">
  110. Audio loops the data between [member loop_begin] and [member loop_end], playing backward only.
  111. </constant>
  112. </constants>
  113. </class>