audio_stream_ogg_vorbis.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "core/io/resource_loader.h"
  33. #include "servers/audio/audio_stream.h"
  34. #include "thirdparty/misc/stb_vorbis.h"
  35. class AudioStreamOGGVorbis;
  36. class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled {
  37. GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled)
  38. stb_vorbis *ogg_stream;
  39. stb_vorbis_alloc ogg_alloc;
  40. uint32_t frames_mixed;
  41. bool active;
  42. int loops;
  43. friend class AudioStreamOGGVorbis;
  44. Ref<AudioStreamOGGVorbis> vorbis_stream;
  45. protected:
  46. virtual void _mix_internal(AudioFrame *p_buffer, int p_frames);
  47. virtual float get_stream_sampling_rate();
  48. public:
  49. virtual void start(float p_from_pos = 0.0);
  50. virtual void stop();
  51. virtual bool is_playing() const;
  52. virtual int get_loop_count() const; //times it looped
  53. virtual float get_playback_position() const;
  54. virtual void seek(float p_time);
  55. AudioStreamPlaybackOGGVorbis() {}
  56. ~AudioStreamPlaybackOGGVorbis();
  57. };
  58. class AudioStreamOGGVorbis : public AudioStream {
  59. GDCLASS(AudioStreamOGGVorbis, AudioStream)
  60. OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged
  61. RES_BASE_EXTENSION("oggstr");
  62. friend class AudioStreamPlaybackOGGVorbis;
  63. void *data;
  64. uint32_t data_len;
  65. int decode_mem_size;
  66. float sample_rate;
  67. int channels;
  68. float length;
  69. bool loop;
  70. float loop_offset;
  71. void clear_data();
  72. protected:
  73. static void _bind_methods();
  74. public:
  75. void set_loop(bool p_enable);
  76. bool has_loop() const;
  77. void set_loop_offset(float p_seconds);
  78. float get_loop_offset() const;
  79. virtual Ref<AudioStreamPlayback> instance_playback();
  80. virtual String get_stream_name() const;
  81. void set_data(const PoolVector<uint8_t> &p_data);
  82. PoolVector<uint8_t> get_data() const;
  83. virtual float get_length() const; //if supported, otherwise return 0
  84. AudioStreamOGGVorbis();
  85. virtual ~AudioStreamOGGVorbis();
  86. };
  87. #endif