From f5d9c7b487166562a833fc86363d78468d711070 Mon Sep 17 00:00:00 2001 From: Ellen Poe Date: Thu, 9 Sep 2021 18:54:18 -0700 Subject: Replace stb_vorbis with libogg+libvorbis --- modules/stb_vorbis/SCsub | 27 -- modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 278 --------------------- modules/stb_vorbis/audio_stream_ogg_vorbis.h | 114 --------- modules/stb_vorbis/config.py | 16 -- .../doc_classes/AudioStreamOGGVorbis.xml | 26 -- modules/stb_vorbis/register_types.cpp | 52 ---- modules/stb_vorbis/register_types.h | 37 --- .../stb_vorbis/resource_importer_ogg_vorbis.cpp | 104 -------- modules/stb_vorbis/resource_importer_ogg_vorbis.h | 58 ----- 9 files changed, 712 deletions(-) delete mode 100644 modules/stb_vorbis/SCsub delete mode 100644 modules/stb_vorbis/audio_stream_ogg_vorbis.cpp delete mode 100644 modules/stb_vorbis/audio_stream_ogg_vorbis.h delete mode 100644 modules/stb_vorbis/config.py delete mode 100644 modules/stb_vorbis/doc_classes/AudioStreamOGGVorbis.xml delete mode 100644 modules/stb_vorbis/register_types.cpp delete mode 100644 modules/stb_vorbis/register_types.h delete mode 100644 modules/stb_vorbis/resource_importer_ogg_vorbis.cpp delete mode 100644 modules/stb_vorbis/resource_importer_ogg_vorbis.h (limited to 'modules/stb_vorbis') diff --git a/modules/stb_vorbis/SCsub b/modules/stb_vorbis/SCsub deleted file mode 100644 index 8fddb23dc8..0000000000 --- a/modules/stb_vorbis/SCsub +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_modules") - -env_stb_vorbis = env_modules.Clone() - -# Thirdparty source files - -thirdparty_obj = [] - -thirdparty_sources = ["#thirdparty/misc/stb_vorbis.c"] - -env_thirdparty = env_stb_vorbis.Clone() -env_thirdparty.disable_warnings() -env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) -env.modules_sources += thirdparty_obj - -# Godot source files - -module_obj = [] - -env_stb_vorbis.add_source_files(module_obj, "*.cpp") -env.modules_sources += module_obj - -# Needed to force rebuilding the module files when the thirdparty library is updated. -env.Depends(module_obj, thirdparty_obj) diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp deleted file mode 100644 index 6554c6e274..0000000000 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/*************************************************************************/ -/* audio_stream_ogg_vorbis.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "audio_stream_ogg_vorbis.h" - -#include "core/io/file_access.h" - -int AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { - ERR_FAIL_COND_V(!active, 0); - - int todo = p_frames; - - int start_buffer = 0; - - int frames_mixed_this_step = p_frames; - - while (todo && active) { - float *buffer = (float *)p_buffer; - if (start_buffer > 0) { - buffer = (buffer + start_buffer * 2); - } - int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, buffer, todo * 2); - if (vorbis_stream->channels == 1 && mixed > 0) { - //mix mono to stereo - for (int i = start_buffer; i < start_buffer + mixed; i++) { - p_buffer[i].r = p_buffer[i].l; - } - } - todo -= mixed; - frames_mixed += mixed; - - if (todo) { - //end of file! - bool is_not_empty = mixed > 0 || stb_vorbis_stream_length_in_samples(ogg_stream) > 0; - if (vorbis_stream->loop && is_not_empty) { - //loop - seek(vorbis_stream->loop_offset); - loops++; - // we still have buffer to fill, start from this element in the next iteration. - start_buffer = p_frames - todo; - } else { - frames_mixed_this_step = p_frames - todo; - for (int i = p_frames - todo; i < p_frames; i++) { - p_buffer[i] = AudioFrame(0, 0); - } - active = false; - todo = 0; - } - } - } - return frames_mixed_this_step; -} - -float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { - return vorbis_stream->sample_rate; -} - -void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { - active = true; - seek(p_from_pos); - loops = 0; - _begin_resample(); -} - -void AudioStreamPlaybackOGGVorbis::stop() { - active = false; -} - -bool AudioStreamPlaybackOGGVorbis::is_playing() const { - return active; -} - -int AudioStreamPlaybackOGGVorbis::get_loop_count() const { - return loops; -} - -float AudioStreamPlaybackOGGVorbis::get_playback_position() const { - return float(frames_mixed) / vorbis_stream->sample_rate; -} - -void AudioStreamPlaybackOGGVorbis::seek(float p_time) { - if (!active) { - return; - } - - if (p_time >= vorbis_stream->get_length()) { - p_time = 0; - } - frames_mixed = uint32_t(vorbis_stream->sample_rate * p_time); - - stb_vorbis_seek(ogg_stream, frames_mixed); -} - -AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() { - if (ogg_alloc.alloc_buffer) { - stb_vorbis_close(ogg_stream); - memfree(ogg_alloc.alloc_buffer); - } -} - -Ref AudioStreamOGGVorbis::instance_playback() { - Ref ovs; - - ERR_FAIL_COND_V_MSG(data == nullptr, ovs, - "This AudioStreamOGGVorbis does not have an audio file assigned " - "to it. AudioStreamOGGVorbis should not be created from the " - "inspector or with `.new()`. Instead, load an audio file."); - - ovs.instantiate(); - ovs->vorbis_stream = Ref(this); - ovs->ogg_alloc.alloc_buffer = (char *)memalloc(decode_mem_size); - ovs->ogg_alloc.alloc_buffer_length_in_bytes = decode_mem_size; - ovs->frames_mixed = 0; - ovs->active = false; - ovs->loops = 0; - int error; - ovs->ogg_stream = stb_vorbis_open_memory((const unsigned char *)data, data_len, &error, &ovs->ogg_alloc); - if (!ovs->ogg_stream) { - memfree(ovs->ogg_alloc.alloc_buffer); - ovs->ogg_alloc.alloc_buffer = nullptr; - ERR_FAIL_COND_V(!ovs->ogg_stream, Ref()); - } - - return ovs; -} - -String AudioStreamOGGVorbis::get_stream_name() const { - return ""; //return stream_name; -} - -void AudioStreamOGGVorbis::clear_data() { - if (data) { - memfree(data); - data = nullptr; - data_len = 0; - } -} - -void AudioStreamOGGVorbis::set_data(const Vector &p_data) { - int src_data_len = p_data.size(); - uint32_t alloc_try = 1024; - Vector alloc_mem; - char *w; - stb_vorbis *ogg_stream = nullptr; - stb_vorbis_alloc ogg_alloc; - - // Vorbis comments may be up to UINT32_MAX, but that's arguably pretty rare. - // Let's go with 2^30 so we don't risk going out of bounds. - const uint32_t MAX_TEST_MEM = 1 << 30; - - while (alloc_try < MAX_TEST_MEM) { - alloc_mem.resize(alloc_try); - w = alloc_mem.ptrw(); - - ogg_alloc.alloc_buffer = w; - ogg_alloc.alloc_buffer_length_in_bytes = alloc_try; - - const uint8_t *src_datar = p_data.ptr(); - - int error; - ogg_stream = stb_vorbis_open_memory((const unsigned char *)src_datar, src_data_len, &error, &ogg_alloc); - - if (!ogg_stream && error == VORBIS_outofmem) { - alloc_try *= 2; - } else { - ERR_FAIL_COND(alloc_try == MAX_TEST_MEM); - ERR_FAIL_COND(ogg_stream == nullptr); - - stb_vorbis_info info = stb_vorbis_get_info(ogg_stream); - - channels = info.channels; - sample_rate = info.sample_rate; - decode_mem_size = alloc_try; - //does this work? (it's less mem..) - //decode_mem_size = ogg_alloc.alloc_buffer_length_in_bytes + info.setup_memory_required + info.temp_memory_required + info.max_frame_size; - - length = stb_vorbis_stream_length_in_seconds(ogg_stream); - stb_vorbis_close(ogg_stream); - - // free any existing data - clear_data(); - - data = memalloc(src_data_len); - memcpy(data, src_datar, src_data_len); - data_len = src_data_len; - - break; - } - } - - ERR_FAIL_COND_MSG(alloc_try == MAX_TEST_MEM, vformat("Couldn't set vorbis data even with an alloc buffer of %d bytes, report bug.", MAX_TEST_MEM)); -} - -Vector AudioStreamOGGVorbis::get_data() const { - Vector vdata; - - if (data_len && data) { - vdata.resize(data_len); - { - uint8_t *w = vdata.ptrw(); - memcpy(w, data, data_len); - } - } - - return vdata; -} - -void AudioStreamOGGVorbis::set_loop(bool p_enable) { - loop = p_enable; -} - -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; -} - -float AudioStreamOGGVorbis::get_length() const { - return length; -} - -bool AudioStreamOGGVorbis::is_monophonic() const { - return false; -} - -void AudioStreamOGGVorbis::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamOGGVorbis::set_data); - ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamOGGVorbis::get_data); - - 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::PACKED_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "has_loop"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "loop_offset"), "set_loop_offset", "get_loop_offset"); -} - -AudioStreamOGGVorbis::AudioStreamOGGVorbis() {} - -AudioStreamOGGVorbis::~AudioStreamOGGVorbis() { - clear_data(); -} diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h deleted file mode 100644 index 1311c4ce7a..0000000000 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************/ -/* audio_stream_ogg_vorbis.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef AUDIO_STREAM_STB_VORBIS_H -#define AUDIO_STREAM_STB_VORBIS_H - -#include "core/io/resource_loader.h" -#include "servers/audio/audio_stream.h" - -#include "thirdparty/misc/stb_vorbis.h" - -class AudioStreamOGGVorbis; - -class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { - GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled); - - stb_vorbis *ogg_stream = nullptr; - stb_vorbis_alloc ogg_alloc; - uint32_t frames_mixed = 0; - bool active = false; - int loops = 0; - - friend class AudioStreamOGGVorbis; - - Ref vorbis_stream; - -protected: - virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override; - virtual float get_stream_sampling_rate() override; - -public: - virtual void start(float p_from_pos = 0.0) override; - virtual void stop() override; - virtual bool is_playing() const override; - - virtual int get_loop_count() const override; //times it looped - - virtual float get_playback_position() const override; - virtual void seek(float p_time) override; - - AudioStreamPlaybackOGGVorbis() {} - ~AudioStreamPlaybackOGGVorbis(); -}; - -class AudioStreamOGGVorbis : public AudioStream { - GDCLASS(AudioStreamOGGVorbis, AudioStream); - OBJ_SAVE_TYPE(AudioStream); // Saves derived classes with common type so they can be interchanged. - RES_BASE_EXTENSION("oggstr"); - - friend class AudioStreamPlaybackOGGVorbis; - - void *data = nullptr; - uint32_t data_len = 0; - - int decode_mem_size = 0; - float sample_rate = 1.0; - int channels = 1; - float length = 0.0; - bool loop = false; - float loop_offset = 0.0; - void clear_data(); - -protected: - static void _bind_methods(); - -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() override; - virtual String get_stream_name() const override; - - void set_data(const Vector &p_data); - Vector get_data() const; - - virtual float get_length() const override; //if supported, otherwise return 0 - - virtual bool is_monophonic() const override; - - AudioStreamOGGVorbis(); - virtual ~AudioStreamOGGVorbis(); -}; - -#endif diff --git a/modules/stb_vorbis/config.py b/modules/stb_vorbis/config.py deleted file mode 100644 index 1eb0a8cf33..0000000000 --- a/modules/stb_vorbis/config.py +++ /dev/null @@ -1,16 +0,0 @@ -def can_build(env, platform): - return True - - -def configure(env): - pass - - -def get_doc_classes(): - return [ - "AudioStreamOGGVorbis", - ] - - -def get_doc_path(): - return "doc_classes" diff --git a/modules/stb_vorbis/doc_classes/AudioStreamOGGVorbis.xml b/modules/stb_vorbis/doc_classes/AudioStreamOGGVorbis.xml deleted file mode 100644 index 94fdff5d43..0000000000 --- a/modules/stb_vorbis/doc_classes/AudioStreamOGGVorbis.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - OGG Vorbis audio stream driver. - - - OGG Vorbis audio stream driver. - - - - - - - - Contains the audio data in bytes. - - - If [code]true[/code], the stream will automatically loop when it reaches the end. - - - Time in seconds at which the stream starts after being looped. - - - - - diff --git a/modules/stb_vorbis/register_types.cpp b/modules/stb_vorbis/register_types.cpp deleted file mode 100644 index bdb1cf69cf..0000000000 --- a/modules/stb_vorbis/register_types.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "register_types.h" - -#include "audio_stream_ogg_vorbis.h" - -#ifdef TOOLS_ENABLED -#include "core/config/engine.h" -#include "resource_importer_ogg_vorbis.h" -#endif - -void register_stb_vorbis_types() { -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { - Ref ogg_import; - ogg_import.instantiate(); - ResourceFormatImporter::get_singleton()->add_importer(ogg_import); - } -#endif - GDREGISTER_CLASS(AudioStreamOGGVorbis); -} - -void unregister_stb_vorbis_types() { -} diff --git a/modules/stb_vorbis/register_types.h b/modules/stb_vorbis/register_types.h deleted file mode 100644 index d36d87606c..0000000000 --- a/modules/stb_vorbis/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef STB_VORBIS_REGISTER_TYPES_H -#define STB_VORBIS_REGISTER_TYPES_H - -void register_stb_vorbis_types(); -void unregister_stb_vorbis_types(); - -#endif // STB_VORBIS_REGISTER_TYPES_H diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp deleted file mode 100644 index 85de698efd..0000000000 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/*************************************************************************/ -/* resource_importer_ogg_vorbis.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "resource_importer_ogg_vorbis.h" - -#include "core/io/file_access.h" -#include "core/io/resource_saver.h" -#include "scene/resources/texture.h" - -String ResourceImporterOGGVorbis::get_importer_name() const { - return "ogg_vorbis"; -} - -String ResourceImporterOGGVorbis::get_visible_name() const { - return "OGGVorbis"; -} - -void ResourceImporterOGGVorbis::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("ogg"); -} - -String ResourceImporterOGGVorbis::get_save_extension() const { - return "oggstr"; -} - -String ResourceImporterOGGVorbis::get_resource_type() const { - return "AudioStreamOGGVorbis"; -} - -bool ResourceImporterOGGVorbis::get_option_visibility(const String &p_option, const Map &p_options) const { - return true; -} - -int ResourceImporterOGGVorbis::get_preset_count() const { - return 0; -} - -String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { - return String(); -} - -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::FLOAT, "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, Variant *r_metadata) { - bool loop = p_options["loop"]; - float loop_offset = p_options["loop_offset"]; - - FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); - - ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file '" + p_source_file + "'."); - - uint64_t len = f->get_length(); - - Vector data; - data.resize(len); - uint8_t *w = data.ptrw(); - - f->get_buffer(w, len); - - memdelete(f); - - Ref ogg_stream; - ogg_stream.instantiate(); - - ogg_stream->set_data(data); - ERR_FAIL_COND_V(!ogg_stream->get_data().size(), ERR_FILE_CORRUPT); - ogg_stream->set_loop(loop); - ogg_stream->set_loop_offset(loop_offset); - - return ResourceSaver::save(p_save_path + ".oggstr", ogg_stream); -} - -ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() { -} diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h deleted file mode 100644 index 60fe3381fb..0000000000 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************/ -/* resource_importer_ogg_vorbis.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef RESOURCEIMPORTEROGGVORBIS_H -#define RESOURCEIMPORTEROGGVORBIS_H - -#include "audio_stream_ogg_vorbis.h" -#include "core/io/resource_importer.h" - -class ResourceImporterOGGVorbis : public ResourceImporter { - GDCLASS(ResourceImporterOGGVorbis, ResourceImporter); - -public: - virtual String get_importer_name() const override; - virtual String get_visible_name() const override; - virtual void get_recognized_extensions(List *p_extensions) const override; - virtual String get_save_extension() const override; - virtual String get_resource_type() const override; - - virtual int get_preset_count() const override; - virtual String get_preset_name(int p_idx) const override; - - virtual void get_import_options(List *r_options, int p_preset = 0) const override; - virtual bool get_option_visibility(const String &p_option, const Map &p_options) const override; - - virtual Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files = nullptr, Variant *r_metadata = nullptr) override; - - ResourceImporterOGGVorbis(); -}; - -#endif // RESOURCEIMPORTEROGGVORBIS_H -- cgit v1.2.3