class_audiostreamsample.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/AudioStreamSample.xml.
  6. .. _class_AudioStreamSample:
  7. AudioStreamSample
  8. =================
  9. **Inherits:** :ref:`AudioStream<class_AudioStream>` **<** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Stores audio data loaded from WAV files.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. AudioStreamSample 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-reftable-group
  17. Properties
  18. ----------
  19. .. table::
  20. :widths: auto
  21. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  22. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`data<class_AudioStreamSample_property_data>` | ``PoolByteArray( )`` |
  23. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  24. | :ref:`Format<enum_AudioStreamSample_Format>` | :ref:`format<class_AudioStreamSample_property_format>` | ``0`` |
  25. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  26. | :ref:`int<class_int>` | :ref:`loop_begin<class_AudioStreamSample_property_loop_begin>` | ``0`` |
  27. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  28. | :ref:`int<class_int>` | :ref:`loop_end<class_AudioStreamSample_property_loop_end>` | ``0`` |
  29. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  30. | :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` | :ref:`loop_mode<class_AudioStreamSample_property_loop_mode>` | ``0`` |
  31. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  32. | :ref:`int<class_int>` | :ref:`mix_rate<class_AudioStreamSample_property_mix_rate>` | ``44100`` |
  33. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  34. | :ref:`bool<class_bool>` | :ref:`stereo<class_AudioStreamSample_property_stereo>` | ``false`` |
  35. +--------------------------------------------------+----------------------------------------------------------------+-----------------------+
  36. .. rst-class:: classref-reftable-group
  37. Methods
  38. -------
  39. .. table::
  40. :widths: auto
  41. +---------------------------------------+-------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_to_wav<class_AudioStreamSample_method_save_to_wav>` **(** :ref:`String<class_String>` path **)** |
  43. +---------------------------------------+-------------------------------------------------------------------------------------------------------------+
  44. .. rst-class:: classref-section-separator
  45. ----
  46. .. rst-class:: classref-descriptions-group
  47. Enumerations
  48. ------------
  49. .. _enum_AudioStreamSample_Format:
  50. .. rst-class:: classref-enumeration
  51. enum **Format**:
  52. .. _class_AudioStreamSample_constant_FORMAT_8_BITS:
  53. .. rst-class:: classref-enumeration-constant
  54. :ref:`Format<enum_AudioStreamSample_Format>` **FORMAT_8_BITS** = ``0``
  55. 8-bit audio codec.
  56. .. _class_AudioStreamSample_constant_FORMAT_16_BITS:
  57. .. rst-class:: classref-enumeration-constant
  58. :ref:`Format<enum_AudioStreamSample_Format>` **FORMAT_16_BITS** = ``1``
  59. 16-bit audio codec.
  60. .. _class_AudioStreamSample_constant_FORMAT_IMA_ADPCM:
  61. .. rst-class:: classref-enumeration-constant
  62. :ref:`Format<enum_AudioStreamSample_Format>` **FORMAT_IMA_ADPCM** = ``2``
  63. Audio is compressed using IMA ADPCM.
  64. .. rst-class:: classref-item-separator
  65. ----
  66. .. _enum_AudioStreamSample_LoopMode:
  67. .. rst-class:: classref-enumeration
  68. enum **LoopMode**:
  69. .. _class_AudioStreamSample_constant_LOOP_DISABLED:
  70. .. rst-class:: classref-enumeration-constant
  71. :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` **LOOP_DISABLED** = ``0``
  72. Audio does not loop.
  73. .. _class_AudioStreamSample_constant_LOOP_FORWARD:
  74. .. rst-class:: classref-enumeration-constant
  75. :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` **LOOP_FORWARD** = ``1``
  76. Audio loops the data between :ref:`loop_begin<class_AudioStreamSample_property_loop_begin>` and :ref:`loop_end<class_AudioStreamSample_property_loop_end>`, playing forward only.
  77. .. _class_AudioStreamSample_constant_LOOP_PING_PONG:
  78. .. rst-class:: classref-enumeration-constant
  79. :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` **LOOP_PING_PONG** = ``2``
  80. Audio loops the data between :ref:`loop_begin<class_AudioStreamSample_property_loop_begin>` and :ref:`loop_end<class_AudioStreamSample_property_loop_end>`, playing back and forth.
  81. .. _class_AudioStreamSample_constant_LOOP_BACKWARD:
  82. .. rst-class:: classref-enumeration-constant
  83. :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` **LOOP_BACKWARD** = ``3``
  84. Audio loops the data between :ref:`loop_begin<class_AudioStreamSample_property_loop_begin>` and :ref:`loop_end<class_AudioStreamSample_property_loop_end>`, playing backward only.
  85. .. rst-class:: classref-section-separator
  86. ----
  87. .. rst-class:: classref-descriptions-group
  88. Property Descriptions
  89. ---------------------
  90. .. _class_AudioStreamSample_property_data:
  91. .. rst-class:: classref-property
  92. :ref:`PoolByteArray<class_PoolByteArray>` **data** = ``PoolByteArray( )``
  93. .. rst-class:: classref-property-setget
  94. - void **set_data** **(** :ref:`PoolByteArray<class_PoolByteArray>` value **)**
  95. - :ref:`PoolByteArray<class_PoolByteArray>` **get_data** **(** **)**
  96. Contains the audio data in bytes.
  97. \ **Note:** This property expects signed PCM8 data. To convert unsigned PCM8 to signed PCM8, subtract 128 from each byte.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_AudioStreamSample_property_format:
  101. .. rst-class:: classref-property
  102. :ref:`Format<enum_AudioStreamSample_Format>` **format** = ``0``
  103. .. rst-class:: classref-property-setget
  104. - void **set_format** **(** :ref:`Format<enum_AudioStreamSample_Format>` value **)**
  105. - :ref:`Format<enum_AudioStreamSample_Format>` **get_format** **(** **)**
  106. Audio format. See :ref:`Format<enum_AudioStreamSample_Format>` constants for values.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_AudioStreamSample_property_loop_begin:
  110. .. rst-class:: classref-property
  111. :ref:`int<class_int>` **loop_begin** = ``0``
  112. .. rst-class:: classref-property-setget
  113. - void **set_loop_begin** **(** :ref:`int<class_int>` value **)**
  114. - :ref:`int<class_int>` **get_loop_begin** **(** **)**
  115. The loop start point (in number of samples, relative to the beginning of the sample). This information will be imported automatically from the WAV file if present.
  116. .. rst-class:: classref-item-separator
  117. ----
  118. .. _class_AudioStreamSample_property_loop_end:
  119. .. rst-class:: classref-property
  120. :ref:`int<class_int>` **loop_end** = ``0``
  121. .. rst-class:: classref-property-setget
  122. - void **set_loop_end** **(** :ref:`int<class_int>` value **)**
  123. - :ref:`int<class_int>` **get_loop_end** **(** **)**
  124. The loop end point (in number of samples, relative to the beginning of the sample). This information will be imported automatically from the WAV file if present.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_AudioStreamSample_property_loop_mode:
  128. .. rst-class:: classref-property
  129. :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` **loop_mode** = ``0``
  130. .. rst-class:: classref-property-setget
  131. - void **set_loop_mode** **(** :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` value **)**
  132. - :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` **get_loop_mode** **(** **)**
  133. The loop mode. This information will be imported automatically from the WAV file if present. See :ref:`LoopMode<enum_AudioStreamSample_LoopMode>` constants for values.
  134. .. rst-class:: classref-item-separator
  135. ----
  136. .. _class_AudioStreamSample_property_mix_rate:
  137. .. rst-class:: classref-property
  138. :ref:`int<class_int>` **mix_rate** = ``44100``
  139. .. rst-class:: classref-property-setget
  140. - void **set_mix_rate** **(** :ref:`int<class_int>` value **)**
  141. - :ref:`int<class_int>` **get_mix_rate** **(** **)**
  142. The sample rate for mixing this audio. Higher values require more storage space, but result in better quality.
  143. In games, common sample rates in use are ``11025``, ``16000``, ``22050``, ``32000``, ``44100``, and ``48000``.
  144. 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.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_AudioStreamSample_property_stereo:
  148. .. rst-class:: classref-property
  149. :ref:`bool<class_bool>` **stereo** = ``false``
  150. .. rst-class:: classref-property-setget
  151. - void **set_stereo** **(** :ref:`bool<class_bool>` value **)**
  152. - :ref:`bool<class_bool>` **is_stereo** **(** **)**
  153. If ``true``, audio is stereo.
  154. .. rst-class:: classref-section-separator
  155. ----
  156. .. rst-class:: classref-descriptions-group
  157. Method Descriptions
  158. -------------------
  159. .. _class_AudioStreamSample_method_save_to_wav:
  160. .. rst-class:: classref-method
  161. :ref:`Error<enum_@GlobalScope_Error>` **save_to_wav** **(** :ref:`String<class_String>` path **)**
  162. Saves the AudioStreamSample as a WAV file to ``path``. Samples with IMA ADPCM format can't be saved.
  163. \ **Note:** A ``.wav`` extension is automatically appended to ``path`` if it is missing.
  164. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  165. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  166. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  167. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`