diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /modules/stb_vorbis | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'modules/stb_vorbis')
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 134 | ||||
-rw-r--r-- | modules/stb_vorbis/audio_stream_ogg_vorbis.h | 31 | ||||
-rw-r--r-- | modules/stb_vorbis/register_types.cpp | 1 | ||||
-rw-r--r-- | modules/stb_vorbis/resource_importer_ogg_vorbis.cpp | 31 | ||||
-rw-r--r-- | modules/stb_vorbis/resource_importer_ogg_vorbis.h | 11 |
5 files changed, 89 insertions, 119 deletions
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index d3d7ab2307..884eb905fa 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -28,20 +28,19 @@ /*************************************************************************/ #include "audio_stream_ogg_vorbis.h" -#include "thirdparty/stb_vorbis/stb_vorbis.c" #include "os/file_access.h" +#include "thirdparty/stb_vorbis/stb_vorbis.c" - -void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame* p_buffer,int p_frames) { +void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { ERR_FAIL_COND(!active); - int todo=p_frames; + int todo = p_frames; - while(todo) { + while (todo) { - int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream,2,(float*)p_buffer,todo*2); - todo-=mixed; + int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2); + todo -= mixed; if (todo) { //end of file! @@ -50,15 +49,13 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame* p_buffer,int p_fram seek_pos(0); loops++; } else { - for(int i=mixed;i<p_frames;i++) { - p_buffer[i]=AudioFrame(0,0); + for (int i = mixed; i < p_frames; i++) { + p_buffer[i] = AudioFrame(0, 0); } - active=false; + active = false; } } } - - } float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { @@ -66,20 +63,17 @@ float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { return vorbis_stream->sample_rate; } - void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { seek_pos(p_from_pos); - active=true; - loops=0; + active = true; + loops = 0; _begin_resample(); - - } void AudioStreamPlaybackOGGVorbis::stop() { - active=false; + active = false; } bool AudioStreamPlaybackOGGVorbis::is_playing() const { @@ -93,14 +87,14 @@ int AudioStreamPlaybackOGGVorbis::get_loop_count() const { float AudioStreamPlaybackOGGVorbis::get_pos() const { - return float(frames_mixed)/vorbis_stream->sample_rate; + return float(frames_mixed) / vorbis_stream->sample_rate; } void AudioStreamPlaybackOGGVorbis::seek_pos(float p_time) { if (!active) return; - stb_vorbis_seek(ogg_stream, uint32_t(p_time*vorbis_stream->sample_rate)); + stb_vorbis_seek(ogg_stream, uint32_t(p_time * vorbis_stream->sample_rate)); } float AudioStreamPlaybackOGGVorbis::get_length() const { @@ -117,27 +111,25 @@ AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() { Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { - - Ref<AudioStreamPlaybackOGGVorbis> ovs; - printf("instance at %p, data %p\n",this,data); + printf("instance at %p, data %p\n", this, data); - ERR_FAIL_COND_V(data==NULL,ovs); + ERR_FAIL_COND_V(data == NULL, 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_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 ); + 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_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) { AudioServer::get_singleton()->audio_data_free(ovs->ogg_alloc.alloc_buffer); - ovs->ogg_alloc.alloc_buffer=NULL; - ERR_FAIL_COND_V(!ovs->ogg_stream,Ref<AudioStreamPlaybackOGGVorbis>()); + ovs->ogg_alloc.alloc_buffer = NULL; + ERR_FAIL_COND_V(!ovs->ogg_stream, Ref<AudioStreamPlaybackOGGVorbis>()); } return ovs; @@ -145,40 +137,40 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { String AudioStreamOGGVorbis::get_stream_name() const { - return "";//return stream_name; + return ""; //return stream_name; } -void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t>& p_data) { +void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) { - int src_data_len=p_data.size(); -#define MAX_TEST_MEM (1<<20) + int src_data_len = p_data.size(); +#define MAX_TEST_MEM (1 << 20) - uint32_t alloc_try=1024; + uint32_t alloc_try = 1024; PoolVector<char> alloc_mem; PoolVector<char>::Write w; - stb_vorbis * ogg_stream=NULL; + stb_vorbis *ogg_stream = NULL; stb_vorbis_alloc ogg_alloc; - while(alloc_try<MAX_TEST_MEM) { + while (alloc_try < MAX_TEST_MEM) { alloc_mem.resize(alloc_try); w = alloc_mem.write(); - ogg_alloc.alloc_buffer=w.ptr(); - ogg_alloc.alloc_buffer_length_in_bytes=alloc_try; + ogg_alloc.alloc_buffer = w.ptr(); + ogg_alloc.alloc_buffer_length_in_bytes = alloc_try; PoolVector<uint8_t>::Read src_datar = p_data.read(); int error; - ogg_stream = stb_vorbis_open_memory( (const unsigned char*)src_datar.ptr(), src_data_len, &error, &ogg_alloc ); + ogg_stream = stb_vorbis_open_memory((const unsigned char *)src_datar.ptr(), src_data_len, &error, &ogg_alloc); - if (!ogg_stream && error==VORBIS_outofmem) { + if (!ogg_stream && error == VORBIS_outofmem) { w = PoolVector<char>::Write(); - alloc_try*=2; + alloc_try *= 2; } else { - ERR_FAIL_COND(alloc_try==MAX_TEST_MEM); - ERR_FAIL_COND(ogg_stream==NULL); + ERR_FAIL_COND(alloc_try == MAX_TEST_MEM); + ERR_FAIL_COND(ogg_stream == NULL); stb_vorbis_info info = stb_vorbis_get_info(ogg_stream); @@ -190,19 +182,17 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t>& p_data) { //print_line("succeded "+itos(ogg_alloc.alloc_buffer_length_in_bytes)+" setup "+itos(info.setup_memory_required)+" setup temp "+itos(info.setup_temp_memory_required)+" temp "+itos(info.temp_memory_required)+" maxframe"+itos(info.max_frame_size)); - length=stb_vorbis_stream_length_in_seconds(ogg_stream); + length = stb_vorbis_stream_length_in_seconds(ogg_stream); stb_vorbis_close(ogg_stream); - data = AudioServer::get_singleton()->audio_data_alloc(src_data_len,src_datar.ptr()); - data_len=src_data_len; + data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr()); + data_len = src_data_len; break; } } - - printf("create at %p, data %p\n",this,data); - + printf("create at %p, data %p\n", this, data); } PoolVector<uint8_t> AudioStreamOGGVorbis::get_data() const { @@ -213,16 +203,15 @@ PoolVector<uint8_t> AudioStreamOGGVorbis::get_data() const { vdata.resize(data_len); { PoolVector<uint8_t>::Write w = vdata.write(); - copymem(w.ptr(),data,data_len); + copymem(w.ptr(), data, data_len); } - } return vdata; } void AudioStreamOGGVorbis::set_loop(bool p_enable) { - loop=p_enable; + loop = p_enable; } bool AudioStreamOGGVorbis::has_loop() const { @@ -230,31 +219,24 @@ bool AudioStreamOGGVorbis::has_loop() const { return loop; } - 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_data", "data"), &AudioStreamOGGVorbis::set_data); + ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamOGGVorbis::get_data); - 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"); + ClassDB::bind_method(D_METHOD("set_loop", "enable"), &AudioStreamOGGVorbis::set_loop); + ClassDB::bind_method(D_METHOD("has_loop"), &AudioStreamOGGVorbis::has_loop); + 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"); } AudioStreamOGGVorbis::AudioStreamOGGVorbis() { - - data=NULL; - length=0; - sample_rate=1; - channels=1; - decode_mem_size=0; - loop=false; + data = NULL; + length = 0; + sample_rate = 1; + channels = 1; + 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 2313fc4ae3..c32b3e578d 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -29,36 +29,35 @@ #ifndef AUDIO_STREAM_STB_VORBIS_H #define AUDIO_STREAM_STB_VORBIS_H -#include "servers/audio/audio_stream.h" #include "io/resource_loader.h" +#include "servers/audio/audio_stream.h" #define STB_VORBIS_HEADER_ONLY #include "thirdparty/stb_vorbis/stb_vorbis.c" #undef STB_VORBIS_HEADER_ONLY - class AudioStreamOGGVorbis; class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { - GDCLASS( AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled ) + GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled) - stb_vorbis * ogg_stream; + stb_vorbis *ogg_stream; stb_vorbis_alloc ogg_alloc; uint32_t frames_mixed; bool active; int loops; -friend class AudioStreamOGGVorbis; + friend class AudioStreamOGGVorbis; Ref<AudioStreamOGGVorbis> vorbis_stream; -protected: - virtual void _mix_internal(AudioFrame* p_buffer, int p_frames); +protected: + virtual void _mix_internal(AudioFrame *p_buffer, int p_frames); virtual float get_stream_sampling_rate(); public: - virtual void start(float p_from_pos=0.0); + virtual void start(float p_from_pos = 0.0); virtual void stop(); virtual bool is_playing() const; @@ -69,17 +68,17 @@ public: virtual float get_length() const; //if supported, otherwise return 0 - AudioStreamPlaybackOGGVorbis() { } + AudioStreamPlaybackOGGVorbis() {} ~AudioStreamPlaybackOGGVorbis(); }; class AudioStreamOGGVorbis : public AudioStream { - GDCLASS( AudioStreamOGGVorbis, AudioStream ) - OBJ_SAVE_TYPE( AudioStream ) //children are all saved as AudioStream, so they can be exchanged + GDCLASS(AudioStreamOGGVorbis, AudioStream) + OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged RES_BASE_EXTENSION("asogg"); -friend class AudioStreamPlaybackOGGVorbis; + friend class AudioStreamPlaybackOGGVorbis; void *data; uint32_t data_len; @@ -89,23 +88,21 @@ friend class AudioStreamPlaybackOGGVorbis; int channels; float length; bool loop; -protected: +protected: static void _bind_methods(); -public: +public: void set_loop(bool p_enable); bool has_loop() const; virtual Ref<AudioStreamPlayback> instance_playback(); virtual String get_stream_name() const; - void set_data(const PoolVector<uint8_t>& p_data); + void set_data(const PoolVector<uint8_t> &p_data); PoolVector<uint8_t> get_data() const; AudioStreamOGGVorbis(); }; - - #endif diff --git a/modules/stb_vorbis/register_types.cpp b/modules/stb_vorbis/register_types.cpp index 41fbc6fbd7..36b7ebc11a 100644 --- a/modules/stb_vorbis/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -41,5 +41,4 @@ void register_stb_vorbis_types() { } void unregister_stb_vorbis_types() { - } diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index 03495652d4..11d8551db5 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -37,11 +37,11 @@ String ResourceImporterOGGVorbis::get_importer_name() const { return "ogg_vorbis"; } -String ResourceImporterOGGVorbis::get_visible_name() const{ +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"); } @@ -50,12 +50,12 @@ String ResourceImporterOGGVorbis::get_save_extension() const { return "asogg"; } -String ResourceImporterOGGVorbis::get_resource_type() 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 { +bool ResourceImporterOGGVorbis::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { return true; } @@ -68,23 +68,18 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { return String(); } +void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options, int p_preset) 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::BOOL, "loop"), true)); } - - -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) { +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"]; - FileAccess *f = FileAccess::open(p_source_file,FileAccess::READ); + FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); if (!f) { - ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); + ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); } size_t len = f->get_len(); @@ -93,7 +88,7 @@ Error ResourceImporterOGGVorbis::import(const String& p_source_file, const Strin data.resize(len); PoolVector<uint8_t>::Write w = data.write(); - f->get_buffer(w.ptr(),len); + f->get_buffer(w.ptr(), len); memdelete(f); @@ -103,10 +98,8 @@ Error ResourceImporterOGGVorbis::import(const String& p_source_file, const Strin ogg_stream->set_data(data); ogg_stream->set_loop(loop); - return ResourceSaver::save(p_save_path+".asogg",ogg_stream); + return ResourceSaver::save(p_save_path + ".asogg", ogg_stream); } -ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() -{ - +ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() { } diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h index 15fc2cd2f3..2f0fcbe9a1 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.h +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.h @@ -29,12 +29,11 @@ #ifndef RESOURCEIMPORTEROGGVORBIS_H #define RESOURCEIMPORTEROGGVORBIS_H - -#include "io/resource_import.h" #include "audio_stream_ogg_vorbis.h" +#include "io/resource_import.h" class ResourceImporterOGGVorbis : public ResourceImporter { - GDCLASS(ResourceImporterOGGVorbis,ResourceImporter) + GDCLASS(ResourceImporterOGGVorbis, ResourceImporter) public: virtual String get_importer_name() const; virtual String get_visible_name() const; @@ -45,10 +44,10 @@ public: virtual int get_preset_count() const; virtual String get_preset_name(int p_idx) const; - 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 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); + 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); ResourceImporterOGGVorbis(); }; |