spatial_stream_player.h
1 /*************************************************************************/
2 /* spatial_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 SPATIAL_STREAM_PLAYER_H
30 #define SPATIAL_STREAM_PLAYER_H
31 
32 #include "scene/resources/audio_stream.h"
33 #include "scene/3d/spatial_player.h"
34 #include "servers/audio/audio_rb_resampler.h"
35 
37 
39 
40  _THREAD_SAFE_CLASS_
41 
42  struct InternalStream : public AudioServer::AudioStream {
43  SpatialStreamPlayer *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 
70  AudioRBResampler resampler;
71 
72  bool _play;
73  void _set_play(bool p_play);
74  bool _get_play() const;
75 protected:
76  void _notification(int p_what);
77 
78  static void _bind_methods();
79 public:
80 
81  void set_stream(const Ref<AudioStream> &p_stream);
82  Ref<AudioStream> get_stream() const;
83 
84  void play(float p_from_offset=0);
85  void stop();
86  bool is_playing() const;
87 
88  void set_paused(bool p_paused);
89  bool is_paused() const;
90 
91  void set_loop(bool p_enable);
92  bool has_loop() const;
93 
94  void set_volume(float p_vol);
95  float get_volume() const;
96 
97  void set_loop_restart_time(float p_secs);
98  float get_loop_restart_time() const;
99 
100  void set_volume_db(float p_db);
101  float get_volume_db() const;
102 
103  String get_stream_name() const;
104 
105  int get_loop_count() const;
106 
107  float get_pos() const;
108  void seek_pos(float p_time);
109  float get_length() const;
110  void set_autoplay(bool p_vol);
111  bool has_autoplay() const;
112 
113  void set_buffering_msec(int p_msec);
114  int get_buffering_msec() const;
115 
118 };
119 
120 #endif // SPATIAL_STREAM_PLAYER_H
Definition: rid.h:47
Definition: ustring.h:64
Definition: spatial_stream_player.h:36
Definition: spatial_player.h:39