class_sample.rst 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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:`int<class_int>` | :ref:`get_format<class_Sample_get_format>` **(** **)** const |
  17. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`bool<class_bool>` | :ref:`is_stereo<class_Sample_is_stereo>` **(** **)** const |
  19. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`int<class_int>` | :ref:`get_length<class_Sample_get_length>` **(** **)** const |
  21. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  22. | void | :ref:`set_data<class_Sample_set_data>` **(** :ref:`RawArray<class_rawarray>` data **)** |
  23. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`RawArray<class_rawarray>` | :ref:`get_data<class_Sample_get_data>` **(** **)** const |
  25. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`set_mix_rate<class_Sample_set_mix_rate>` **(** :ref:`int<class_int>` hz **)** |
  27. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`int<class_int>` | :ref:`get_mix_rate<class_Sample_get_mix_rate>` **(** **)** const |
  29. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`set_loop_format<class_Sample_set_loop_format>` **(** :ref:`int<class_int>` format **)** |
  31. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`get_loop_format<class_Sample_get_loop_format>` **(** **)** const |
  33. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`set_loop_begin<class_Sample_set_loop_begin>` **(** :ref:`int<class_int>` pos **)** |
  35. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`get_loop_begin<class_Sample_get_loop_begin>` **(** **)** const |
  37. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`set_loop_end<class_Sample_set_loop_end>` **(** :ref:`int<class_int>` pos **)** |
  39. +----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_loop_end<class_Sample_get_loop_end>` **(** **)** const |
  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_format:
  60. - :ref:`int<class_int>` **get_format** **(** **)** const
  61. Return the sample format.
  62. .. _class_Sample_is_stereo:
  63. - :ref:`bool<class_bool>` **is_stereo** **(** **)** const
  64. Return whether the current sample was created as stereo.
  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_set_data:
  69. - void **set_data** **(** :ref:`RawArray<class_rawarray>` data **)**
  70. 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:
  71. Get the sample length (:ref:`get_length<class_Sample_get_length>`).
  72. If the sample format is FORMAT_PCM16, multiply it by 2.
  73. If the sample format is FORMAT_IMA_ADPCM, divide it by 2 (rounding any fraction up), then add 4.
  74. If the sample is stereo (:ref:`is_stereo<class_Sample_is_stereo>`), multiply it by 2.
  75. .. _class_Sample_get_data:
  76. - :ref:`RawArray<class_rawarray>` **get_data** **(** **)** const
  77. Return sample data as little endian.
  78. .. _class_Sample_set_mix_rate:
  79. - void **set_mix_rate** **(** :ref:`int<class_int>` hz **)**
  80. Set the mix rate for the sample (expected playback frequency).
  81. .. _class_Sample_get_mix_rate:
  82. - :ref:`int<class_int>` **get_mix_rate** **(** **)** const
  83. Return the mix rate for the sample.
  84. .. _class_Sample_set_loop_format:
  85. - void **set_loop_format** **(** :ref:`int<class_int>` format **)**
  86. Set the loop format (use LOOP\_\* constants as argument).
  87. .. _class_Sample_get_loop_format:
  88. - :ref:`int<class_int>` **get_loop_format** **(** **)** const
  89. Return the loop format.
  90. .. _class_Sample_set_loop_begin:
  91. - void **set_loop_begin** **(** :ref:`int<class_int>` pos **)**
  92. Set the loop begin position. It must be a valid frame and less than the loop end position.
  93. .. _class_Sample_get_loop_begin:
  94. - :ref:`int<class_int>` **get_loop_begin** **(** **)** const
  95. Return the loop begin position.
  96. .. _class_Sample_set_loop_end:
  97. - void **set_loop_end** **(** :ref:`int<class_int>` pos **)**
  98. Set the loop end position. It must be a valid frame and greater than the loop begin position.
  99. .. _class_Sample_get_loop_end:
  100. - :ref:`int<class_int>` **get_loop_end** **(** **)** const
  101. Return the loop end position.