stream_player.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*************************************************************************/
  2. /* stream_player.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 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 STREAM_PLAYER_H
  30. #define STREAM_PLAYER_H
  31. #include "scene/resources/audio_stream.h"
  32. #include "scene/main/node.h"
  33. #include "servers/audio/audio_rb_resampler.h"
  34. class StreamPlayer : public Node {
  35. OBJ_TYPE(StreamPlayer,Node);
  36. //_THREAD_SAFE_CLASS_
  37. struct InternalStream : public AudioServer::AudioStream {
  38. StreamPlayer *player;
  39. virtual int get_channel_count() const;
  40. virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate
  41. virtual bool mix(int32_t *p_buffer,int p_frames);
  42. virtual void update();
  43. };
  44. InternalStream internal_stream;
  45. Ref<AudioStreamPlayback> playback;
  46. Ref<AudioStream> stream;
  47. int sp_get_channel_count() const;
  48. void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate
  49. bool sp_mix(int32_t *p_buffer,int p_frames);
  50. void sp_update();
  51. int server_mix_rate;
  52. RID stream_rid;
  53. bool paused;
  54. bool autoplay;
  55. bool loops;
  56. float volume;
  57. float loop_point;
  58. int buffering_ms;
  59. volatile bool stop_request;
  60. float resume_pos;
  61. AudioRBResampler resampler;
  62. bool _play;
  63. void _set_play(bool p_play);
  64. bool _get_play() const;
  65. protected:
  66. void _notification(int p_what);
  67. static void _bind_methods();
  68. public:
  69. void set_stream(const Ref<AudioStream> &p_stream);
  70. Ref<AudioStream> get_stream() const;
  71. void play(float p_from_offset=0);
  72. void stop();
  73. bool is_playing() const;
  74. void set_paused(bool p_paused);
  75. bool is_paused() const;
  76. void set_loop(bool p_enable);
  77. bool has_loop() const;
  78. void set_volume(float p_vol);
  79. float get_volume() const;
  80. void set_loop_restart_time(float p_secs);
  81. float get_loop_restart_time() const;
  82. void set_volume_db(float p_db);
  83. float get_volume_db() const;
  84. String get_stream_name() const;
  85. int get_loop_count() const;
  86. float get_pos() const;
  87. void seek_pos(float p_time);
  88. float get_length() const;
  89. void set_autoplay(bool p_vol);
  90. bool has_autoplay() const;
  91. void set_buffering_msec(int p_msec);
  92. int get_buffering_msec() const;
  93. StreamPlayer();
  94. ~StreamPlayer();
  95. };
  96. #endif // AUDIO_STREAM_PLAYER_H