sample.h 3.3 KB

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