readded ability to set loop offset in seconds, closes #9630

This commit is contained in:
Juan Linietsky 2017-08-22 11:47:24 -03:00
parent e54c4028ef
commit 8ad7139631
3 changed files with 21 additions and 1 deletions

View file

@ -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;
}

View file

@ -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<AudioStreamPlayback> instance_playback();
virtual String get_stream_name() const;

View file

@ -72,11 +72,13 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const {
void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *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<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *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);
}