diff options
Diffstat (limited to 'servers/audio/audio_stream.h')
-rw-r--r-- | servers/audio/audio_stream.h | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h index 0d426f99b2..922335508e 100644 --- a/servers/audio/audio_stream.h +++ b/servers/audio/audio_stream.h @@ -36,20 +36,33 @@ #include "servers/audio/audio_filter_sw.h" #include "servers/audio_server.h" +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" +#include "core/variant/native_ptr.h" + class AudioStreamPlayback : public RefCounted { GDCLASS(AudioStreamPlayback, RefCounted); +protected: + static void _bind_methods(); + GDVIRTUAL1(_start, float) + GDVIRTUAL0(_stop) + GDVIRTUAL0RC(bool, _is_playing) + GDVIRTUAL0RC(int, _get_loop_count) + GDVIRTUAL0RC(float, _get_playback_position) + GDVIRTUAL1(_seek, float) + GDVIRTUAL3R(int, _mix, GDNativePtr<AudioFrame>, float, int) public: - virtual void start(float p_from_pos = 0.0) = 0; - virtual void stop() = 0; - virtual bool is_playing() const = 0; + virtual void start(float p_from_pos = 0.0); + virtual void stop(); + virtual bool is_playing() const; - virtual int get_loop_count() const = 0; //times it looped + virtual int get_loop_count() const; //times it looped - virtual float get_playback_position() const = 0; - virtual void seek(float p_time) = 0; + virtual float get_playback_position() const; + virtual void seek(float p_time); - virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) = 0; + virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames); }; class AudioStreamPlaybackResampled : public AudioStreamPlayback { @@ -64,15 +77,17 @@ class AudioStreamPlaybackResampled : public AudioStreamPlayback { }; AudioFrame internal_buffer[INTERNAL_BUFFER_LEN + CUBIC_INTERP_HISTORY]; + unsigned int internal_buffer_end = -1; uint64_t mix_offset; protected: void _begin_resample(); - virtual void _mix_internal(AudioFrame *p_buffer, int p_frames) = 0; + // Returns the number of frames that were mixed. + virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) = 0; virtual float get_stream_sampling_rate() = 0; public: - virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; + virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; AudioStreamPlaybackResampled() { mix_offset = 0; } }; @@ -84,11 +99,15 @@ class AudioStream : public Resource { protected: static void _bind_methods(); + GDVIRTUAL0RC(Ref<AudioStreamPlayback>, _instance_playback) + GDVIRTUAL0RC(String, _get_stream_name) + GDVIRTUAL0RC(float, _get_length) + public: - virtual Ref<AudioStreamPlayback> instance_playback() = 0; - virtual String get_stream_name() const = 0; + virtual Ref<AudioStreamPlayback> instance_playback(); + virtual String get_stream_name() const; - virtual float get_length() const = 0; //if supported, otherwise return 0 + virtual float get_length() const; }; // Microphone @@ -123,11 +142,11 @@ class AudioStreamPlaybackMicrophone : public AudioStreamPlaybackResampled { Ref<AudioStreamMicrophone> microphone; protected: - virtual void _mix_internal(AudioFrame *p_buffer, int p_frames) override; + virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override; virtual float get_stream_sampling_rate() override; public: - virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; + virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; virtual void start(float p_from_pos = 0.0) override; virtual void stop() override; @@ -191,7 +210,7 @@ public: virtual float get_playback_position() const override; virtual void seek(float p_time) override; - virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; + virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override; ~AudioStreamPlaybackRandomPitch(); }; |