spatial_stream_player.h 4.2 KB

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