Debian Codegraph @

servers/audio/effects/audio_stream_generator.h

raw symbols SCIP
1 /**************************************************************************/
2 /* audio_stream_generator.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/ring_buffer.h"
34 #include "servers/audio/audio_stream.h"
35
36 class AudioStreamGenerator : public AudioStream {
37 GDCLASS(AudioStreamGenerator, AudioStream);
38
39 public:
40 enum AudioStreamGeneratorMixRate {
41 MIX_RATE_OUTPUT,
42 MIX_RATE_INPUT,
43 MIX_RATE_CUSTOM,
44 MIX_RATE_MAX,
45 };
46
47 private:
48 AudioStreamGeneratorMixRate mix_rate_mode = MIX_RATE_CUSTOM;
49 float mix_rate = 44100;
50 float buffer_len = 0.5;
51
52 protected:
53 static void _bind_methods();
54
55 public:
56 float _get_target_rate() const;
57
58 void set_mix_rate(float p_mix_rate);
59 float get_mix_rate() const;
60
61 void set_mix_rate_mode(AudioStreamGeneratorMixRate p_mix_rate_mode);
62 AudioStreamGeneratorMixRate get_mix_rate_mode() const;
63
64 void set_buffer_length(float p_seconds);
65 float get_buffer_length() const;
66
67 virtual Ref<AudioStreamPlayback> instantiate_playback() override;
68 virtual String get_stream_name() const override;
69
70 virtual double get_length() const override;
71 virtual bool is_monophonic() const override;
72 AudioStreamGenerator() {}
73 };
74
75 class AudioStreamGeneratorPlayback : public AudioStreamPlaybackResampled {
76 GDCLASS(AudioStreamGeneratorPlayback, AudioStreamPlaybackResampled);
77 friend class AudioStreamGenerator;
78 RingBuffer<AudioFrame> buffer;
79 int skips;
80 bool active;
81 float mixed;
82 AudioStreamGenerator *generator = nullptr;
83
84 protected:
85 virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override;
86 virtual float get_stream_sampling_rate() override;
87
88 static void _bind_methods();
89
90 public:
91 virtual void start(double p_from_pos = 0.0) override;
92 virtual void stop() override;
93 virtual bool is_playing() const override;
94
95 virtual int get_loop_count() const override; //times it looped
96
97 virtual double get_playback_position() const override;
98 virtual void seek(double p_time) override;
99
100 bool push_frame(const Vector2 &p_frame);
101 bool can_push_buffer(int p_frames) const;
102 bool push_buffer(const PackedVector2Array &p_frames);
103 int get_frames_available() const;
104 int get_skips() const;
105
106 virtual void tag_used_streams() override;
107
108 void clear_buffer();
109
110 AudioStreamGeneratorPlayback();
111 };
112
113 VARIANT_ENUM_CAST(AudioStreamGenerator::AudioStreamGeneratorMixRate);