audio_stream_ogg_vorbis.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*************************************************************************/
  2. /* audio_stream_ogg_vorbis.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 AUDIO_STREAM_STB_VORBIS_H
  31. #define AUDIO_STREAM_STB_VORBIS_H
  32. #include "io/resource_loader.h"
  33. #include "servers/audio/audio_stream.h"
  34. #define STB_VORBIS_HEADER_ONLY
  35. #pragma GCC diagnostic push
  36. #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
  37. #include "thirdparty/misc/stb_vorbis.c"
  38. #pragma GCC diagnostic pop
  39. #undef STB_VORBIS_HEADER_ONLY
  40. class AudioStreamOGGVorbis;
  41. class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled {
  42. GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled)
  43. stb_vorbis *ogg_stream;
  44. stb_vorbis_alloc ogg_alloc;
  45. uint32_t frames_mixed;
  46. bool active;
  47. int loops;
  48. friend class AudioStreamOGGVorbis;
  49. Ref<AudioStreamOGGVorbis> vorbis_stream;
  50. protected:
  51. virtual void _mix_internal(AudioFrame *p_buffer, int p_frames);
  52. virtual float get_stream_sampling_rate();
  53. public:
  54. virtual void start(float p_from_pos = 0.0);
  55. virtual void stop();
  56. virtual bool is_playing() const;
  57. virtual int get_loop_count() const; //times it looped
  58. virtual float get_playback_position() const;
  59. virtual void seek(float p_time);
  60. AudioStreamPlaybackOGGVorbis() {}
  61. ~AudioStreamPlaybackOGGVorbis();
  62. };
  63. class AudioStreamOGGVorbis : public AudioStream {
  64. GDCLASS(AudioStreamOGGVorbis, AudioStream)
  65. OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged
  66. RES_BASE_EXTENSION("oggstr");
  67. friend class AudioStreamPlaybackOGGVorbis;
  68. void *data;
  69. uint32_t data_len;
  70. int decode_mem_size;
  71. float sample_rate;
  72. int channels;
  73. float length;
  74. bool loop;
  75. float loop_offset;
  76. void clear_data();
  77. protected:
  78. static void _bind_methods();
  79. public:
  80. void set_loop(bool p_enable);
  81. bool has_loop() const;
  82. void set_loop_offset(float p_seconds);
  83. float get_loop_offset() const;
  84. virtual Ref<AudioStreamPlayback> instance_playback();
  85. virtual String get_stream_name() const;
  86. void set_data(const PoolVector<uint8_t> &p_data);
  87. PoolVector<uint8_t> get_data() const;
  88. virtual float get_length() const; //if supported, otherwise return 0
  89. AudioStreamOGGVorbis();
  90. virtual ~AudioStreamOGGVorbis();
  91. };
  92. #endif