sample.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*************************************************************************/
  2. /* sample.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef SAMPLE_H
  31. #define SAMPLE_H
  32. #include "resource.h"
  33. #include "servers/audio_server.h"
  34. class Sample : public Resource {
  35. OBJ_TYPE(Sample, Resource);
  36. RES_BASE_EXTENSION("smp");
  37. public:
  38. enum Format {
  39. FORMAT_PCM8,
  40. FORMAT_PCM16,
  41. FORMAT_IMA_ADPCM
  42. };
  43. enum LoopFormat {
  44. LOOP_NONE,
  45. LOOP_FORWARD,
  46. LOOP_PING_PONG // not supported in every platform
  47. };
  48. private:
  49. Format format;
  50. int length;
  51. bool stereo;
  52. LoopFormat loop_format;
  53. int loop_begin;
  54. int loop_end;
  55. int mix_rate;
  56. RID sample;
  57. void _set_data(const Dictionary &p_data);
  58. Dictionary _get_data() const;
  59. protected:
  60. static void _bind_methods();
  61. public:
  62. void create(Format p_format, bool p_stereo, int p_length);
  63. Format get_format() const;
  64. bool is_stereo() const;
  65. int get_length() const;
  66. void set_data(const DVector<uint8_t> &p_buffer);
  67. DVector<uint8_t> get_data() const;
  68. void set_mix_rate(int p_rate);
  69. int get_mix_rate() const;
  70. void set_loop_format(LoopFormat p_format);
  71. LoopFormat get_loop_format() const;
  72. void set_loop_begin(int p_pos);
  73. int get_loop_begin() const;
  74. void set_loop_end(int p_pos);
  75. int get_loop_end() const;
  76. virtual RID get_rid() const;
  77. Sample();
  78. ~Sample();
  79. };
  80. VARIANT_ENUM_CAST(Sample::Format);
  81. VARIANT_ENUM_CAST(Sample::LoopFormat);
  82. #endif // SAMPLE_H