summaryrefslogtreecommitdiffstats
path: root/modules/vorbis
diff options
context:
space:
mode:
authorAdam Scott <ascott.ca@gmail.com>2024-04-18 10:50:34 -0400
committerAdam Scott <ascott.ca@gmail.com>2024-06-18 11:06:31 -0400
commit52fa4f05f3945fdf511c249adede9b6d07c51beb (patch)
tree2ac2aca86c09dd757fd4a8b5defab932f2b8eb5d /modules/vorbis
parenteb20a68b323c1fcb75492f8132e1bd6d321713ec (diff)
downloadredot-engine-52fa4f05f3945fdf511c249adede9b6d07c51beb.tar.gz
Add samples playback support
Diffstat (limited to 'modules/vorbis')
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.cpp28
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.h13
2 files changed, 41 insertions, 0 deletions
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp
index b235b6f96c..ff032c88c6 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp
@@ -376,6 +376,22 @@ void AudioStreamPlaybackOggVorbis::seek(double p_time) {
}
}
+void AudioStreamPlaybackOggVorbis::set_is_sample(bool p_is_sample) {
+ _is_sample = p_is_sample;
+}
+
+bool AudioStreamPlaybackOggVorbis::get_is_sample() const {
+ return _is_sample;
+}
+
+Ref<AudioSamplePlayback> AudioStreamPlaybackOggVorbis::get_sample_playback() const {
+ return sample_playback;
+}
+
+void AudioStreamPlaybackOggVorbis::set_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {
+ sample_playback = p_playback;
+}
+
AudioStreamPlaybackOggVorbis::~AudioStreamPlaybackOggVorbis() {
if (block_is_allocated) {
vorbis_block_clear(&block);
@@ -517,6 +533,18 @@ void AudioStreamOggVorbis::get_parameter_list(List<Parameter> *r_parameters) {
r_parameters->push_back(Parameter(PropertyInfo(Variant::BOOL, "looping", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CHECKABLE), Variant()));
}
+Ref<AudioSample> AudioStreamOggVorbis::generate_sample() const {
+ Ref<AudioSample> sample;
+ sample.instantiate();
+ sample->stream = this;
+ sample->loop_mode = loop
+ ? AudioSample::LoopMode::LOOP_FORWARD
+ : AudioSample::LoopMode::LOOP_DISABLED;
+ sample->loop_begin = loop_offset;
+ sample->loop_end = 0;
+ return sample;
+}
+
void AudioStreamOggVorbis::_bind_methods() {
ClassDB::bind_static_method("AudioStreamOggVorbis", D_METHOD("load_from_buffer", "buffer"), &AudioStreamOggVorbis::load_from_buffer);
ClassDB::bind_static_method("AudioStreamOggVorbis", D_METHOD("load_from_file", "path"), &AudioStreamOggVorbis::load_from_file);
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h
index 64a7815b57..6293951f8d 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.h
+++ b/modules/vorbis/audio_stream_ogg_vorbis.h
@@ -75,6 +75,9 @@ class AudioStreamPlaybackOggVorbis : public AudioStreamPlaybackResampled {
Ref<OggPacketSequencePlayback> vorbis_data_playback;
Ref<AudioStreamOggVorbis> vorbis_stream;
+ bool _is_sample = false;
+ Ref<AudioSamplePlayback> sample_playback;
+
int _mix_frames(AudioFrame *p_buffer, int p_frames);
int _mix_frames_vorbis(AudioFrame *p_buffer, int p_frames);
@@ -100,6 +103,11 @@ public:
virtual void set_parameter(const StringName &p_name, const Variant &p_value) override;
virtual Variant get_parameter(const StringName &p_name) const override;
+ virtual void set_is_sample(bool p_is_sample) override;
+ virtual bool get_is_sample() const override;
+ virtual Ref<AudioSamplePlayback> get_sample_playback() const override;
+ virtual void set_sample_playback(const Ref<AudioSamplePlayback> &p_playback) override;
+
AudioStreamPlaybackOggVorbis() {}
~AudioStreamPlaybackOggVorbis();
};
@@ -159,6 +167,11 @@ public:
virtual void get_parameter_list(List<Parameter> *r_parameters) override;
+ virtual bool can_be_sampled() const override {
+ return true;
+ }
+ virtual Ref<AudioSample> generate_sample() const override;
+
AudioStreamOggVorbis();
virtual ~AudioStreamOggVorbis();
};