class_sample.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Sample:
  4. Sample
  5. ======
  6. **Inherits:** :ref:`Resource<class_resource>` **<** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Audio sample (sound) class.
  11. Member Functions
  12. ----------------
  13. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  14. | void | :ref:`create<class_Sample_create>` **(** :ref:`int<class_int>` format, :ref:`bool<class_bool>` stereo, :ref:`int<class_int>` length **)** |
  15. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`RawArray<class_rawarray>` | :ref:`get_data<class_Sample_get_data>` **(** **)** const |
  17. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`int<class_int>` | :ref:`get_format<class_Sample_get_format>` **(** **)** const |
  19. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`int<class_int>` | :ref:`get_length<class_Sample_get_length>` **(** **)** const |
  21. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`int<class_int>` | :ref:`get_loop_begin<class_Sample_get_loop_begin>` **(** **)** const |
  23. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`int<class_int>` | :ref:`get_loop_end<class_Sample_get_loop_end>` **(** **)** const |
  25. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`int<class_int>` | :ref:`get_loop_format<class_Sample_get_loop_format>` **(** **)** const |
  27. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`int<class_int>` | :ref:`get_mix_rate<class_Sample_get_mix_rate>` **(** **)** const |
  29. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`is_stereo<class_Sample_is_stereo>` **(** **)** const |
  31. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  32. | void | :ref:`set_data<class_Sample_set_data>` **(** :ref:`RawArray<class_rawarray>` data **)** |
  33. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`set_loop_begin<class_Sample_set_loop_begin>` **(** :ref:`int<class_int>` pos **)** |
  35. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`set_loop_end<class_Sample_set_loop_end>` **(** :ref:`int<class_int>` pos **)** |
  37. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`set_loop_format<class_Sample_set_loop_format>` **(** :ref:`int<class_int>` format **)** |
  39. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`set_mix_rate<class_Sample_set_mix_rate>` **(** :ref:`int<class_int>` hz **)** |
  41. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  42. Numeric Constants
  43. -----------------
  44. - **FORMAT_PCM8** = **0** --- 8-bits signed PCM audio.
  45. - **FORMAT_PCM16** = **1** --- 16-bits signed little endian PCM audio.
  46. - **FORMAT_IMA_ADPCM** = **2** --- IMA-ADPCM Audio.
  47. - **LOOP_NONE** = **0** --- No loop enabled.
  48. - **LOOP_FORWARD** = **1** --- Forward looping (when playback reaches loop end, goes back to loop begin).
  49. - **LOOP_PING_PONG** = **2** --- Ping-pong looping (when playback reaches loop end, plays backward until loop begin). Not available in all platforms.
  50. Description
  51. -----------
  52. Sample provides an audio sample class, containing audio data, together with some information for playback, such as format, mix rate and loop. It is used by sound playback routines.
  53. Member Function Description
  54. ---------------------------
  55. .. _class_Sample_create:
  56. - void **create** **(** :ref:`int<class_int>` format, :ref:`bool<class_bool>` stereo, :ref:`int<class_int>` length **)**
  57. Create new data for the sample, with format (see FORMAT\_\* constants), stereo hint, and length in samples (not bytes).
  58. Calling this method overrides previously existing data. Stereo samples are interleaved pairs of left and right points (in that order), but count as one sample for length purposes.
  59. .. _class_Sample_get_data:
  60. - :ref:`RawArray<class_rawarray>` **get_data** **(** **)** const
  61. Return sample data as little endian.
  62. .. _class_Sample_get_format:
  63. - :ref:`int<class_int>` **get_format** **(** **)** const
  64. Return the sample format.
  65. .. _class_Sample_get_length:
  66. - :ref:`int<class_int>` **get_length** **(** **)** const
  67. Return the sample length in samples. Stereo samples count as one, even if they are made of a left and a right sample.
  68. .. _class_Sample_get_loop_begin:
  69. - :ref:`int<class_int>` **get_loop_begin** **(** **)** const
  70. Return the loop begin position.
  71. .. _class_Sample_get_loop_end:
  72. - :ref:`int<class_int>` **get_loop_end** **(** **)** const
  73. Return the loop end position.
  74. .. _class_Sample_get_loop_format:
  75. - :ref:`int<class_int>` **get_loop_format** **(** **)** const
  76. Return the loop format.
  77. .. _class_Sample_get_mix_rate:
  78. - :ref:`int<class_int>` **get_mix_rate** **(** **)** const
  79. Return the mix rate for the sample.
  80. .. _class_Sample_is_stereo:
  81. - :ref:`bool<class_bool>` **is_stereo** **(** **)** const
  82. Return whether the current sample was created as stereo.
  83. .. _class_Sample_set_data:
  84. - void **set_data** **(** :ref:`RawArray<class_rawarray>` data **)**
  85. Set sample data. Data must be little endian, no matter the host platform, and exactly as long as to fit all samples. The length of this array can be calculated as follows:
  86. Get the sample length (:ref:`get_length<class_Sample_get_length>`). If the sample format is FORMAT_PCM16, multiply it by 2. If the sample format is FORMAT_IMA_ADPCM, divide it by 2 (rounding any fraction up), then add 4. If the sample is stereo (:ref:`is_stereo<class_Sample_is_stereo>`), multiply it by 2.
  87. .. _class_Sample_set_loop_begin:
  88. - void **set_loop_begin** **(** :ref:`int<class_int>` pos **)**
  89. Set the loop begin position. It must be a valid frame and less than the loop end position.
  90. .. _class_Sample_set_loop_end:
  91. - void **set_loop_end** **(** :ref:`int<class_int>` pos **)**
  92. Set the loop end position. It must be a valid frame and greater than the loop begin position.
  93. .. _class_Sample_set_loop_format:
  94. - void **set_loop_format** **(** :ref:`int<class_int>` format **)**
  95. Set the loop format (use LOOP\_\* constants as argument).
  96. .. _class_Sample_set_mix_rate:
  97. - void **set_mix_rate** **(** :ref:`int<class_int>` hz **)**
  98. Set the mix rate for the sample (expected playback frequency).