audio_stream_ogg_vorbis.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*************************************************************************/
  2. /* audio_stream_ogg_vorbis.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 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 AUDIO_STREAM_OGG_VORBIS_H
  30. #define AUDIO_STREAM_OGG_VORBIS_H
  31. #include "scene/resources/audio_stream_resampled.h"
  32. #include "vorbis/vorbisfile.h"
  33. #include "os/file_access.h"
  34. #include "io/resource_loader.h"
  35. #include "os/thread_safe.h"
  36. class AudioStreamOGGVorbis : public AudioStreamResampled {
  37. OBJ_TYPE(AudioStreamOGGVorbis,AudioStreamResampled);
  38. _THREAD_SAFE_CLASS_
  39. enum {
  40. MIN_MIX=1024
  41. };
  42. FileAccess *f;
  43. ov_callbacks _ov_callbacks;
  44. float length;
  45. static size_t _ov_read_func(void *p_dst,size_t p_data, size_t p_count, void *_f);
  46. static int _ov_seek_func(void *_f,ogg_int64_t offs, int whence);
  47. static int _ov_close_func(void *_f);
  48. static long _ov_tell_func(void *_f);
  49. virtual bool _can_mix() const;
  50. String file;
  51. int64_t frames_mixed;
  52. bool stream_loaded;
  53. volatile bool playing;
  54. OggVorbis_File vf;
  55. int stream_channels;
  56. int stream_srate;
  57. int current_section;
  58. volatile bool setting_up;
  59. bool paused;
  60. bool loops;
  61. int repeats;
  62. Error _load_stream();
  63. void _clear_stream();
  64. void _close_file();
  65. public:
  66. void set_file(const String& p_file);
  67. virtual void play();
  68. virtual void stop();
  69. virtual bool is_playing() const;
  70. virtual void set_paused(bool p_paused);
  71. virtual bool is_paused(bool p_paused) const;
  72. virtual void set_loop(bool p_enable);
  73. virtual bool has_loop() const;
  74. virtual float get_length() const;
  75. virtual String get_stream_name() const;
  76. virtual int get_loop_count() const;
  77. virtual float get_pos() const;
  78. virtual void seek_pos(float p_time);
  79. virtual UpdateMode get_update_mode() const;
  80. virtual void update();
  81. AudioStreamOGGVorbis();
  82. ~AudioStreamOGGVorbis();
  83. };
  84. class ResourceFormatLoaderAudioStreamOGGVorbis : public ResourceFormatLoader {
  85. public:
  86. virtual RES load(const String &p_path,const String& p_original_path="");
  87. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  88. virtual bool handles_type(const String& p_type) const;
  89. virtual String get_resource_type(const String &p_path) const;
  90. };
  91. #endif // AUDIO_STREAM_OGG_H