diff options
Diffstat (limited to 'modules/stb_vorbis')
-rw-r--r-- | modules/stb_vorbis/SCsub | 4 | ||||
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 48 | ||||
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.h | 2 | ||||
-rw-r--r-- | modules/stb_vorbis/config.py | 3 | ||||
-rw-r--r-- | modules/stb_vorbis/register_types.cpp | 1 | ||||
-rw-r--r-- | modules/stb_vorbis/register_types.h | 5 | ||||
-rw-r--r-- | modules/stb_vorbis/resource_importer_ogg_vorbis.cpp | 10 | ||||
-rw-r--r-- | modules/stb_vorbis/resource_importer_ogg_vorbis.h | 2 |
8 files changed, 29 insertions, 46 deletions
diff --git a/modules/stb_vorbis/SCsub b/modules/stb_vorbis/SCsub index d14939a3b1..266c87c802 100644 --- a/modules/stb_vorbis/SCsub +++ b/modules/stb_vorbis/SCsub @@ -1,7 +1,7 @@ #!/usr/bin/env python -Import('env') -Import('env_modules') +Import("env") +Import("env_modules") env_stb_vorbis = env_modules.Clone() diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 42f341cef7..3aceaf11c5 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -33,7 +33,6 @@ #include "core/os/file_access.h" void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { - ERR_FAIL_COND(!active); int todo = p_frames; @@ -76,12 +75,10 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra } 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; @@ -89,27 +86,25 @@ void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { } void AudioStreamPlaybackOGGVorbis::stop() { - active = false; } -bool AudioStreamPlaybackOGGVorbis::is_playing() const { +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) +void AudioStreamPlaybackOGGVorbis::seek(float p_time) { + if (!active) { return; + } if (p_time >= vorbis_stream->get_length()) { p_time = 0; @@ -122,19 +117,18 @@ void AudioStreamPlaybackOGGVorbis::seek(float p_time) { AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() { if (ogg_alloc.alloc_buffer) { stb_vorbis_close(ogg_stream); - AudioServer::get_singleton()->audio_data_free(ogg_alloc.alloc_buffer); + memfree(ogg_alloc.alloc_buffer); } } Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { - Ref<AudioStreamPlaybackOGGVorbis> ovs; - ERR_FAIL_COND_V(data == NULL, ovs); + ERR_FAIL_COND_V(data == nullptr, ovs); ovs.instance(); ovs->vorbis_stream = Ref<AudioStreamOGGVorbis>(this); - ovs->ogg_alloc.alloc_buffer = (char *)AudioServer::get_singleton()->audio_data_alloc(decode_mem_size); + 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; @@ -142,9 +136,8 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { int error; ovs->ogg_stream = stb_vorbis_open_memory((const unsigned char *)data, data_len, &error, &ovs->ogg_alloc); if (!ovs->ogg_stream) { - - AudioServer::get_singleton()->audio_data_free(ovs->ogg_alloc.alloc_buffer); - ovs->ogg_alloc.alloc_buffer = NULL; + memfree(ovs->ogg_alloc.alloc_buffer); + ovs->ogg_alloc.alloc_buffer = nullptr; ERR_FAIL_COND_V(!ovs->ogg_stream, Ref<AudioStreamPlaybackOGGVorbis>()); } @@ -152,31 +145,28 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { } String AudioStreamOGGVorbis::get_stream_name() const { - return ""; //return stream_name; } void AudioStreamOGGVorbis::clear_data() { if (data) { - AudioServer::get_singleton()->audio_data_free(data); - data = NULL; + memfree(data); + data = nullptr; data_len = 0; } } void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { - int src_data_len = p_data.size(); #define MAX_TEST_MEM (1 << 20) uint32_t alloc_try = 1024; Vector<char> alloc_mem; char *w; - stb_vorbis *ogg_stream = NULL; + stb_vorbis *ogg_stream = nullptr; stb_vorbis_alloc ogg_alloc; while (alloc_try < MAX_TEST_MEM) { - alloc_mem.resize(alloc_try); w = alloc_mem.ptrw(); @@ -189,12 +179,10 @@ void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { 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 == NULL); + ERR_FAIL_COND(ogg_stream == nullptr); stb_vorbis_info info = stb_vorbis_get_info(ogg_stream); @@ -210,7 +198,8 @@ void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { // free any existing data clear_data(); - data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar); + data = memalloc(src_data_len); + copymem(data, src_datar, src_data_len); data_len = src_data_len; break; @@ -219,7 +208,6 @@ void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { } Vector<uint8_t> AudioStreamOGGVorbis::get_data() const { - Vector<uint8_t> vdata; if (data_len && data) { @@ -238,7 +226,6 @@ void AudioStreamOGGVorbis::set_loop(bool p_enable) { } bool AudioStreamOGGVorbis::has_loop() const { - return loop; } @@ -251,12 +238,10 @@ float AudioStreamOGGVorbis::get_loop_offset() const { } float AudioStreamOGGVorbis::get_length() const { - return length; } 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); @@ -272,8 +257,7 @@ void AudioStreamOGGVorbis::_bind_methods() { } AudioStreamOGGVorbis::AudioStreamOGGVorbis() { - - data = NULL; + data = nullptr; data_len = 0; length = 0; sample_rate = 1; diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index f296e8c19f..3002134651 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -39,7 +39,6 @@ class AudioStreamOGGVorbis; class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { - GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled); stb_vorbis *ogg_stream; @@ -71,7 +70,6 @@ public: }; 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"); diff --git a/modules/stb_vorbis/config.py b/modules/stb_vorbis/config.py index 200b8dfd50..1eb0a8cf33 100644 --- a/modules/stb_vorbis/config.py +++ b/modules/stb_vorbis/config.py @@ -1,13 +1,16 @@ 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/register_types.cpp b/modules/stb_vorbis/register_types.cpp index ac2612bd6a..6669d30278 100644 --- a/modules/stb_vorbis/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -38,7 +38,6 @@ #endif void register_stb_vorbis_types() { - #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { Ref<ResourceImporterOGGVorbis> ogg_import; diff --git a/modules/stb_vorbis/register_types.h b/modules/stb_vorbis/register_types.h index f6147abd01..f5a1dd31bc 100644 --- a/modules/stb_vorbis/register_types.h +++ b/modules/stb_vorbis/register_types.h @@ -28,5 +28,10 @@ /* 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 index 13d96541e3..d68d050d34 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -35,16 +35,14 @@ #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<String> *p_extensions) const { +void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const { p_extensions->push_back("ogg"); } @@ -53,31 +51,27 @@ String ResourceImporterOGGVorbis::get_save_extension() const { } String ResourceImporterOGGVorbis::get_resource_type() const { - return "AudioStreamOGGVorbis"; } bool ResourceImporterOGGVorbis::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { - return true; } int ResourceImporterOGGVorbis::get_preset_count() const { return 0; } -String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { +String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { return String(); } 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::FLOAT, "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, Variant *r_metadata) { - bool loop = p_options["loop"]; float loop_offset = p_options["loop_offset"]; diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h index 43541bcf3c..8d6f71a456 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.h +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.h @@ -50,7 +50,7 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - virtual Error 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 = NULL, Variant *r_metadata = NULL); + virtual Error 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 = nullptr, Variant *r_metadata = nullptr); ResourceImporterOGGVorbis(); }; |