audio_stream.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*************************************************************************/
  2. /* audio_stream.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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_H
  30. #define AUDIO_STREAM_H
  31. #include "resource.h"
  32. #include "servers/audio_server.h"
  33. #include "scene/resources/audio_stream.h"
  34. class AudioStream : public Resource {
  35. OBJ_TYPE( AudioStream, Resource );
  36. OBJ_SAVE_TYPE( AudioStream ); //children are all saved as AudioStream, so they can be exchanged
  37. friend class InternalAudioStream;
  38. struct InternalAudioStream : public AudioServer::AudioStream {
  39. ::AudioStream *owner;
  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 bool can_update_mt() const;
  44. virtual void update();
  45. };
  46. int _mix_rate;
  47. InternalAudioStream *internal_audio_stream;
  48. protected:
  49. _FORCE_INLINE_ int get_mix_rate() const { return _mix_rate; }
  50. virtual int get_channel_count() const=0;
  51. virtual bool mix(int32_t *p_buffer, int p_frames)=0;
  52. static void _bind_methods();
  53. public:
  54. enum UpdateMode {
  55. UPDATE_NONE,
  56. UPDATE_IDLE,
  57. UPDATE_THREAD
  58. };
  59. AudioServer::AudioStream *get_audio_stream();
  60. virtual void play()=0;
  61. virtual void stop()=0;
  62. virtual bool is_playing() const=0;
  63. virtual void set_paused(bool p_paused)=0;
  64. virtual bool is_paused(bool p_paused) const=0;
  65. virtual void set_loop(bool p_enable)=0;
  66. virtual bool has_loop() const=0;
  67. virtual float get_length() const=0;
  68. virtual String get_stream_name() const=0;
  69. virtual int get_loop_count() const=0;
  70. virtual float get_pos() const=0;
  71. virtual void seek_pos(float p_time)=0;
  72. virtual UpdateMode get_update_mode() const=0;
  73. virtual void update()=0;
  74. AudioStream();
  75. ~AudioStream();
  76. };
  77. VARIANT_ENUM_CAST( AudioStream::UpdateMode );
  78. #endif // AUDIO_STREAM_H