stream_player.h
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 
32 #include "scene/resources/audio_stream.h"
33 #include "scene/main/node.h"
34 #include "servers/audio/audio_rb_resampler.h"
35 
36 class StreamPlayer : public Node {
37 
38  OBJ_TYPE(StreamPlayer,Node);
39 
40  //_THREAD_SAFE_CLASS_
41 
42  struct InternalStream : public AudioServer::AudioStream {
43  StreamPlayer *player;
44  virtual int get_channel_count() const;
45  virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate
46  virtual bool mix(int32_t *p_buffer,int p_frames);
47  virtual void update();
48  };
49 
50 
51  InternalStream internal_stream;
52  Ref<AudioStreamPlayback> playback;
53  Ref<AudioStream> stream;
54 
55  int sp_get_channel_count() const;
56  void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate
57  bool sp_mix(int32_t *p_buffer,int p_frames);
58  void sp_update();
59 
60  int server_mix_rate;
61 
62  RID stream_rid;
63  bool paused;
64  bool autoplay;
65  bool loops;
66  float volume;
67  float loop_point;
68  int buffering_ms;
69  volatile bool stop_request;
70  float resume_pos;
71 
72  AudioRBResampler resampler;
73 
74  bool _play;
75  void _set_play(bool p_play);
76  bool _get_play() const;
77 protected:
78  void _notification(int p_what);
79 
80  static void _bind_methods();
81 public:
82 
83  void set_stream(const Ref<AudioStream> &p_stream);
84  Ref<AudioStream> get_stream() const;
85 
86  void play(float p_from_offset=0);
87  void stop();
88  bool is_playing() const;
89 
90  void set_paused(bool p_paused);
91  bool is_paused() const;
92 
93  void set_loop(bool p_enable);
94  bool has_loop() const;
95 
96  void set_volume(float p_vol);
97  float get_volume() const;
98 
99  void set_loop_restart_time(float p_secs);
100  float get_loop_restart_time() const;
101 
102  void set_volume_db(float p_db);
103  float get_volume_db() const;
104 
105  String get_stream_name() const;
106 
107  int get_loop_count() const;
108 
109  float get_pos() const;
110  void seek_pos(float p_time);
111  float get_length() const;
112  void set_autoplay(bool p_vol);
113  bool has_autoplay() const;
114 
115  void set_buffering_msec(int p_msec);
116  int get_buffering_msec() const;
117 
118  StreamPlayer();
119  ~StreamPlayer();
120 };
121 
122 #endif // AUDIO_STREAM_PLAYER_H
Definition: node.h:42
Definition: stream_player.h:36
Definition: rid.h:47
Definition: ustring.h:64