From 8ad7139631ca6860b2593b1b2ee94820118fc9b1 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 22 Aug 2017 11:47:24 -0300 Subject: [PATCH] readded ability to set loop offset in seconds, closes #9630 --- modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 15 ++++++++++++++- modules/stb_vorbis/audio_stream_ogg_vorbis.h | 4 ++++ .../stb_vorbis/resource_importer_ogg_vorbis.cpp | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 7b8b2abebb8..5ad16c73377 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -49,7 +49,7 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra //end of file! if (vorbis_stream->loop) { //loop - seek_pos(0); + seek_pos(vorbis_stream->loop_offset); loops++; } else { for (int i = mixed; i < p_frames; i++) { @@ -227,6 +227,14 @@ bool AudioStreamOGGVorbis::has_loop() const { return loop; } +void AudioStreamOGGVorbis::set_loop_offset(float p_seconds) { + loop_offset = p_seconds; +} + +float AudioStreamOGGVorbis::get_loop_offset() const { + return loop_offset; +} + void AudioStreamOGGVorbis::_bind_methods() { ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamOGGVorbis::set_data); @@ -235,8 +243,12 @@ void AudioStreamOGGVorbis::_bind_methods() { ClassDB::bind_method(D_METHOD("set_loop", "enable"), &AudioStreamOGGVorbis::set_loop); ClassDB::bind_method(D_METHOD("has_loop"), &AudioStreamOGGVorbis::has_loop); + ClassDB::bind_method(D_METHOD("set_loop_offset", "seconds"), &AudioStreamOGGVorbis::set_loop_offset); + ClassDB::bind_method(D_METHOD("get_loop_offset"), &AudioStreamOGGVorbis::get_loop_offset); + ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop", "has_loop"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_offset", "get_loop_offset"); } AudioStreamOGGVorbis::AudioStreamOGGVorbis() { @@ -245,6 +257,7 @@ AudioStreamOGGVorbis::AudioStreamOGGVorbis() { length = 0; sample_rate = 1; channels = 1; + loop_offset = 0; decode_mem_size = 0; loop = false; } diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index 46cdfd3f2d2..56bfe398c09 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -89,6 +89,7 @@ class AudioStreamOGGVorbis : public AudioStream { int channels; float length; bool loop; + float loop_offset; protected: static void _bind_methods(); @@ -97,6 +98,9 @@ public: void set_loop(bool p_enable); bool has_loop() const; + void set_loop_offset(float p_seconds); + float get_loop_offset() const; + virtual Ref instance_playback(); virtual String get_stream_name() const; diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index f0a7ee1ec6b..5a1157bf9c7 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -72,11 +72,13 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { void ResourceImporterOGGVorbis::get_import_options(List *r_options, int p_preset) const { r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_offset"), 0)); } Error ResourceImporterOGGVorbis::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files) { bool loop = p_options["loop"]; + float loop_offset = p_options["loop_offset"]; FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); if (!f) { @@ -98,6 +100,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin ogg_stream->set_data(data); ogg_stream->set_loop(loop); + ogg_stream->set_loop_offset(loop_offset); return ResourceSaver::save(p_save_path + ".oggstr", ogg_stream); }