class_audiostreamwav.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/AudioStreamWAV.xml.
  6. .. _class_AudioStreamWAV:
  7. AudioStreamWAV
  8. ==============
  9. **Inherits:** :ref:`AudioStream<class_AudioStream>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Stores audio data loaded from WAV files.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. AudioStreamWAV stores sound samples loaded from WAV files. To play the stored sound, use an :ref:`AudioStreamPlayer<class_AudioStreamPlayer>` (for non-positional audio) or :ref:`AudioStreamPlayer2D<class_AudioStreamPlayer2D>`/:ref:`AudioStreamPlayer3D<class_AudioStreamPlayer3D>` (for positional audio). The sound can be looped.
  15. This class can also be used to store dynamically-generated PCM audio data. See also :ref:`AudioStreamGenerator<class_AudioStreamGenerator>` for procedural audio generation.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Runtime file loading and saving <../tutorials/io/runtime_file_loading_and_saving>`
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  26. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`data<class_AudioStreamWAV_property_data>` | ``PackedByteArray()`` |
  27. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  28. | :ref:`Format<enum_AudioStreamWAV_Format>` | :ref:`format<class_AudioStreamWAV_property_format>` | ``0`` |
  29. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  30. | :ref:`int<class_int>` | :ref:`loop_begin<class_AudioStreamWAV_property_loop_begin>` | ``0`` |
  31. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  32. | :ref:`int<class_int>` | :ref:`loop_end<class_AudioStreamWAV_property_loop_end>` | ``0`` |
  33. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  34. | :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>` | :ref:`loop_mode<class_AudioStreamWAV_property_loop_mode>` | ``0`` |
  35. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  36. | :ref:`int<class_int>` | :ref:`mix_rate<class_AudioStreamWAV_property_mix_rate>` | ``44100`` |
  37. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  38. | :ref:`bool<class_bool>` | :ref:`stereo<class_AudioStreamWAV_property_stereo>` | ``false`` |
  39. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  40. | :ref:`Dictionary<class_Dictionary>` | :ref:`tags<class_AudioStreamWAV_property_tags>` | ``{}`` |
  41. +-----------------------------------------------+-------------------------------------------------------------+-----------------------+
  42. .. rst-class:: classref-reftable-group
  43. Methods
  44. -------
  45. .. table::
  46. :widths: auto
  47. +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`AudioStreamWAV<class_AudioStreamWAV>` | :ref:`load_from_buffer<class_AudioStreamWAV_method_load_from_buffer>`\ (\ stream_data\: :ref:`PackedByteArray<class_PackedByteArray>`, options\: :ref:`Dictionary<class_Dictionary>` = {}\ ) |static| |
  49. +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`AudioStreamWAV<class_AudioStreamWAV>` | :ref:`load_from_file<class_AudioStreamWAV_method_load_from_file>`\ (\ path\: :ref:`String<class_String>`, options\: :ref:`Dictionary<class_Dictionary>` = {}\ ) |static| |
  51. +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_to_wav<class_AudioStreamWAV_method_save_to_wav>`\ (\ path\: :ref:`String<class_String>`\ ) |
  53. +---------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. .. rst-class:: classref-section-separator
  55. ----
  56. .. rst-class:: classref-descriptions-group
  57. Enumerations
  58. ------------
  59. .. _enum_AudioStreamWAV_Format:
  60. .. rst-class:: classref-enumeration
  61. enum **Format**: :ref:`🔗<enum_AudioStreamWAV_Format>`
  62. .. _class_AudioStreamWAV_constant_FORMAT_8_BITS:
  63. .. rst-class:: classref-enumeration-constant
  64. :ref:`Format<enum_AudioStreamWAV_Format>` **FORMAT_8_BITS** = ``0``
  65. 8-bit PCM audio codec.
  66. .. _class_AudioStreamWAV_constant_FORMAT_16_BITS:
  67. .. rst-class:: classref-enumeration-constant
  68. :ref:`Format<enum_AudioStreamWAV_Format>` **FORMAT_16_BITS** = ``1``
  69. 16-bit PCM audio codec.
  70. .. _class_AudioStreamWAV_constant_FORMAT_IMA_ADPCM:
  71. .. rst-class:: classref-enumeration-constant
  72. :ref:`Format<enum_AudioStreamWAV_Format>` **FORMAT_IMA_ADPCM** = ``2``
  73. Audio is lossily compressed as IMA ADPCM.
  74. .. _class_AudioStreamWAV_constant_FORMAT_QOA:
  75. .. rst-class:: classref-enumeration-constant
  76. :ref:`Format<enum_AudioStreamWAV_Format>` **FORMAT_QOA** = ``3``
  77. Audio is lossily compressed as `Quite OK Audio <https://qoaformat.org/>`__.
  78. .. rst-class:: classref-item-separator
  79. ----
  80. .. _enum_AudioStreamWAV_LoopMode:
  81. .. rst-class:: classref-enumeration
  82. enum **LoopMode**: :ref:`🔗<enum_AudioStreamWAV_LoopMode>`
  83. .. _class_AudioStreamWAV_constant_LOOP_DISABLED:
  84. .. rst-class:: classref-enumeration-constant
  85. :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>` **LOOP_DISABLED** = ``0``
  86. Audio does not loop.
  87. .. _class_AudioStreamWAV_constant_LOOP_FORWARD:
  88. .. rst-class:: classref-enumeration-constant
  89. :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>` **LOOP_FORWARD** = ``1``
  90. Audio loops the data between :ref:`loop_begin<class_AudioStreamWAV_property_loop_begin>` and :ref:`loop_end<class_AudioStreamWAV_property_loop_end>`, playing forward only.
  91. .. _class_AudioStreamWAV_constant_LOOP_PINGPONG:
  92. .. rst-class:: classref-enumeration-constant
  93. :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>` **LOOP_PINGPONG** = ``2``
  94. Audio loops the data between :ref:`loop_begin<class_AudioStreamWAV_property_loop_begin>` and :ref:`loop_end<class_AudioStreamWAV_property_loop_end>`, playing back and forth.
  95. .. _class_AudioStreamWAV_constant_LOOP_BACKWARD:
  96. .. rst-class:: classref-enumeration-constant
  97. :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>` **LOOP_BACKWARD** = ``3``
  98. Audio loops the data between :ref:`loop_begin<class_AudioStreamWAV_property_loop_begin>` and :ref:`loop_end<class_AudioStreamWAV_property_loop_end>`, playing backward only.
  99. .. rst-class:: classref-section-separator
  100. ----
  101. .. rst-class:: classref-descriptions-group
  102. Property Descriptions
  103. ---------------------
  104. .. _class_AudioStreamWAV_property_data:
  105. .. rst-class:: classref-property
  106. :ref:`PackedByteArray<class_PackedByteArray>` **data** = ``PackedByteArray()`` :ref:`🔗<class_AudioStreamWAV_property_data>`
  107. .. rst-class:: classref-property-setget
  108. - |void| **set_data**\ (\ value\: :ref:`PackedByteArray<class_PackedByteArray>`\ )
  109. - :ref:`PackedByteArray<class_PackedByteArray>` **get_data**\ (\ )
  110. Contains the audio data in bytes.
  111. \ **Note:** If :ref:`format<class_AudioStreamWAV_property_format>` is set to :ref:`FORMAT_8_BITS<class_AudioStreamWAV_constant_FORMAT_8_BITS>`, this property expects signed 8-bit PCM data. To convert from unsigned 8-bit PCM, subtract 128 from each byte.
  112. \ **Note:** If :ref:`format<class_AudioStreamWAV_property_format>` is set to :ref:`FORMAT_QOA<class_AudioStreamWAV_constant_FORMAT_QOA>`, this property expects data from a full QOA file.
  113. **Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedByteArray<class_PackedByteArray>` for more details.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_AudioStreamWAV_property_format:
  117. .. rst-class:: classref-property
  118. :ref:`Format<enum_AudioStreamWAV_Format>` **format** = ``0`` :ref:`🔗<class_AudioStreamWAV_property_format>`
  119. .. rst-class:: classref-property-setget
  120. - |void| **set_format**\ (\ value\: :ref:`Format<enum_AudioStreamWAV_Format>`\ )
  121. - :ref:`Format<enum_AudioStreamWAV_Format>` **get_format**\ (\ )
  122. Audio format.
  123. .. rst-class:: classref-item-separator
  124. ----
  125. .. _class_AudioStreamWAV_property_loop_begin:
  126. .. rst-class:: classref-property
  127. :ref:`int<class_int>` **loop_begin** = ``0`` :ref:`🔗<class_AudioStreamWAV_property_loop_begin>`
  128. .. rst-class:: classref-property-setget
  129. - |void| **set_loop_begin**\ (\ value\: :ref:`int<class_int>`\ )
  130. - :ref:`int<class_int>` **get_loop_begin**\ (\ )
  131. The loop start point (in number of samples, relative to the beginning of the stream).
  132. .. rst-class:: classref-item-separator
  133. ----
  134. .. _class_AudioStreamWAV_property_loop_end:
  135. .. rst-class:: classref-property
  136. :ref:`int<class_int>` **loop_end** = ``0`` :ref:`🔗<class_AudioStreamWAV_property_loop_end>`
  137. .. rst-class:: classref-property-setget
  138. - |void| **set_loop_end**\ (\ value\: :ref:`int<class_int>`\ )
  139. - :ref:`int<class_int>` **get_loop_end**\ (\ )
  140. The loop end point (in number of samples, relative to the beginning of the stream).
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_AudioStreamWAV_property_loop_mode:
  144. .. rst-class:: classref-property
  145. :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>` **loop_mode** = ``0`` :ref:`🔗<class_AudioStreamWAV_property_loop_mode>`
  146. .. rst-class:: classref-property-setget
  147. - |void| **set_loop_mode**\ (\ value\: :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>`\ )
  148. - :ref:`LoopMode<enum_AudioStreamWAV_LoopMode>` **get_loop_mode**\ (\ )
  149. The loop mode.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_AudioStreamWAV_property_mix_rate:
  153. .. rst-class:: classref-property
  154. :ref:`int<class_int>` **mix_rate** = ``44100`` :ref:`🔗<class_AudioStreamWAV_property_mix_rate>`
  155. .. rst-class:: classref-property-setget
  156. - |void| **set_mix_rate**\ (\ value\: :ref:`int<class_int>`\ )
  157. - :ref:`int<class_int>` **get_mix_rate**\ (\ )
  158. The sample rate for mixing this audio. Higher values require more storage space, but result in better quality.
  159. In games, common sample rates in use are ``11025``, ``16000``, ``22050``, ``32000``, ``44100``, and ``48000``.
  160. According to the `Nyquist-Shannon sampling theorem <https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_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.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_AudioStreamWAV_property_stereo:
  164. .. rst-class:: classref-property
  165. :ref:`bool<class_bool>` **stereo** = ``false`` :ref:`🔗<class_AudioStreamWAV_property_stereo>`
  166. .. rst-class:: classref-property-setget
  167. - |void| **set_stereo**\ (\ value\: :ref:`bool<class_bool>`\ )
  168. - :ref:`bool<class_bool>` **is_stereo**\ (\ )
  169. If ``true``, audio is stereo.
  170. .. rst-class:: classref-item-separator
  171. ----
  172. .. _class_AudioStreamWAV_property_tags:
  173. .. rst-class:: classref-property
  174. :ref:`Dictionary<class_Dictionary>` **tags** = ``{}`` :ref:`🔗<class_AudioStreamWAV_property_tags>`
  175. .. rst-class:: classref-property-setget
  176. - |void| **set_tags**\ (\ value\: :ref:`Dictionary<class_Dictionary>`\ )
  177. - :ref:`Dictionary<class_Dictionary>` **get_tags**\ (\ )
  178. Contains user-defined tags if found in the WAV data.
  179. Commonly used tags include ``title``, ``artist``, ``album``, ``tracknumber``, and ``date`` (``date`` does not have a standard date format).
  180. \ **Note:** No tag is *guaranteed* to be present in every file, so make sure to account for the keys not always existing.
  181. \ **Note:** Only WAV files using a ``LIST`` chunk with an identifier of ``INFO`` to encode the tags are currently supported.
  182. .. rst-class:: classref-section-separator
  183. ----
  184. .. rst-class:: classref-descriptions-group
  185. Method Descriptions
  186. -------------------
  187. .. _class_AudioStreamWAV_method_load_from_buffer:
  188. .. rst-class:: classref-method
  189. :ref:`AudioStreamWAV<class_AudioStreamWAV>` **load_from_buffer**\ (\ stream_data\: :ref:`PackedByteArray<class_PackedByteArray>`, options\: :ref:`Dictionary<class_Dictionary>` = {}\ ) |static| :ref:`🔗<class_AudioStreamWAV_method_load_from_buffer>`
  190. Creates a new **AudioStreamWAV** instance from the given buffer. The buffer must contain WAV data.
  191. The keys and values of ``options`` match the properties of :ref:`ResourceImporterWAV<class_ResourceImporterWAV>`. The usage of ``options`` is identical to :ref:`load_from_file()<class_AudioStreamWAV_method_load_from_file>`.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_AudioStreamWAV_method_load_from_file:
  195. .. rst-class:: classref-method
  196. :ref:`AudioStreamWAV<class_AudioStreamWAV>` **load_from_file**\ (\ path\: :ref:`String<class_String>`, options\: :ref:`Dictionary<class_Dictionary>` = {}\ ) |static| :ref:`🔗<class_AudioStreamWAV_method_load_from_file>`
  197. Creates a new **AudioStreamWAV** instance from the given file path. The file must be in WAV format.
  198. The keys and values of ``options`` match the properties of :ref:`ResourceImporterWAV<class_ResourceImporterWAV>`.
  199. \ **Example:** Load the first file dropped as a WAV and play it:
  200. ::
  201. @onready var audio_player = $AudioStreamPlayer
  202. func _ready():
  203. get_window().files_dropped.connect(_on_files_dropped)
  204. func _on_files_dropped(files):
  205. if files[0].get_extension() == "wav":
  206. audio_player.stream = AudioStreamWAV.load_from_file(files[0], {
  207. "force/max_rate": true,
  208. "force/max_rate_hz": 11025
  209. })
  210. audio_player.play()
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_AudioStreamWAV_method_save_to_wav:
  214. .. rst-class:: classref-method
  215. :ref:`Error<enum_@GlobalScope_Error>` **save_to_wav**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_AudioStreamWAV_method_save_to_wav>`
  216. Saves the AudioStreamWAV as a WAV file to ``path``. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.
  217. \ **Note:** A ``.wav`` extension is automatically appended to ``path`` if it is missing.
  218. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  219. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  220. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  221. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  222. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  223. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  224. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  225. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  226. .. |void| replace:: :abbr:`void (No return value.)`