Debian Codegraph @

scene/resources/audio_stream_polyphonic.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_stream_polyphonic.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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
31 #pragma once
32
33 #include "core/templates/local_vector.h"
34 #include "scene/scene_string_names.h"
35 #include "servers/audio/audio_server.h"
36 #include "servers/audio/audio_stream.h"
37
38 class AudioStreamPolyphonic : public AudioStream {
39 GDCLASS(AudioStreamPolyphonic, AudioStream)
40 int polyphony = 32;
41
42 AudioServer::PlaybackType playback_type;
43
44 static void _bind_methods();
45
46 public:
47 virtual Ref<AudioStreamPlayback> instantiate_playback() override;
48 virtual String get_stream_name() const override;
49 virtual bool is_monophonic() const override;
50
51 void set_polyphony(int p_voices);
52 int get_polyphony() const;
53
54 virtual bool is_meta_stream() const override { return true; }
55
56 AudioStreamPolyphonic();
57 };
58
59 class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback {
60 GDCLASS(AudioStreamPlaybackPolyphonic, AudioStreamPlayback)
61
62 constexpr static uint32_t INTERNAL_BUFFER_LEN = 128;
63
64 struct Stream {
65 SafeFlag active;
66 SafeFlag pending_play;
67 SafeFlag finish_request;
68 float play_offset = 0;
69 float pitch_scale = 1.0;
70 Ref<AudioStream> stream;
71 Ref<AudioStreamPlayback> stream_playback;
72 float prev_volume_db = 0;
73 float volume_db = 0;
74 uint32_t id = 0;
75
76 Stream() :
77 active(false), pending_play(false), finish_request(false) {}
78 };
79
80 LocalVector<Stream> streams;
81 AudioFrame internal_buffer[INTERNAL_BUFFER_LEN];
82
83 bool active = false;
84 uint32_t id_counter = 1;
85
86 bool _is_sample = false;
87 Ref<AudioSamplePlayback> sample_playback;
88
89 _FORCE_INLINE_ Stream *_find_stream(int64_t p_id);
90 _FORCE_INLINE_ const Stream *_find_stream(int64_t p_id) const;
91
92 friend class AudioStreamPolyphonic;
93
94 protected:
95 static void _bind_methods();
96
97 public:
98 typedef int64_t ID;
99 enum {
100 INVALID_ID = -1
101 };
102
103 virtual void start(double p_from_pos = 0.0) override;
104 virtual void stop() override;
105 virtual bool is_playing() const override;
106
107 virtual int get_loop_count() const override; //times it looped
108
109 virtual double get_playback_position() const override;
110 virtual void seek(double p_time) override;
111
112 virtual void tag_used_streams() override;
113
114 virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;
115
116 ID play_stream(const Ref<AudioStream> &p_stream, float p_from_offset = 0, float p_volume_db = 0, float p_pitch_scale = 1.0, AudioServer::PlaybackType p_playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT, const StringName &p_bus = SceneStringName(Master));
117 void set_stream_volume(ID p_stream_id, float p_volume_db);
118 void set_stream_pitch_scale(ID p_stream_id, float p_pitch_scale);
119 bool is_stream_playing(ID p_stream_id) const;
120 void stop_stream(ID p_stream_id);
121
122 virtual void set_is_sample(bool p_is_sample) override;
123 virtual bool get_is_sample() const override;
124 virtual Ref<AudioSamplePlayback> get_sample_playback() const override;
125 virtual void set_sample_playback(const Ref<AudioSamplePlayback> &p_playback) override;
126
127 private:
128 #ifndef DISABLE_DEPRECATED
129 ID _play_stream_bind_compat_91382(const Ref<AudioStream> &p_stream, float p_from_offset = 0, float p_volume_db = 0, float p_pitch_scale = 1.0);
130 static void _bind_compatibility_methods();
131 #endif // DISABLE_DEPRECATED
132
133 public:
134 AudioStreamPlaybackPolyphonic();
135 };