summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp11
-rw-r--r--scene/resources/audio_stream_sample.cpp6
-rw-r--r--servers/audio_server.cpp43
-rw-r--r--servers/audio_server.h14
4 files changed, 9 insertions, 65 deletions
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
index 42f341cef7..e5d0e0b12d 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
@@ -122,7 +122,7 @@ 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);
}
}
@@ -134,7 +134,7 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() {
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;
@@ -143,7 +143,7 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() {
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);
+ memfree(ovs->ogg_alloc.alloc_buffer);
ovs->ogg_alloc.alloc_buffer = NULL;
ERR_FAIL_COND_V(!ovs->ogg_stream, Ref<AudioStreamPlaybackOGGVorbis>());
}
@@ -158,7 +158,7 @@ String AudioStreamOGGVorbis::get_stream_name() const {
void AudioStreamOGGVorbis::clear_data() {
if (data) {
- AudioServer::get_singleton()->audio_data_free(data);
+ memfree(data);
data = NULL;
data_len = 0;
}
@@ -210,7 +210,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;
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index a68b750b31..06b65e4b4a 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -481,7 +481,7 @@ void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) {
AudioServer::get_singleton()->lock();
if (data) {
- AudioServer::get_singleton()->audio_data_free(data);
+ memfree(data);
data = NULL;
data_bytes = 0;
}
@@ -491,7 +491,7 @@ void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) {
const uint8_t *r = p_data.ptr();
int alloc_len = datalen + DATA_PAD * 2;
- data = AudioServer::get_singleton()->audio_data_alloc(alloc_len); //alloc with some padding for interpolation
+ data = memalloc(alloc_len); //alloc with some padding for interpolation
zeromem(data, alloc_len);
uint8_t *dataptr = (uint8_t *)data;
copymem(dataptr + DATA_PAD, r, datalen);
@@ -660,7 +660,7 @@ AudioStreamSample::AudioStreamSample() {
AudioStreamSample::~AudioStreamSample() {
if (data) {
- AudioServer::get_singleton()->audio_data_free(data);
+ memfree(data);
data = NULL;
data_bytes = 0;
}
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 0e68c8a543..02e6d0f2d4 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -1131,47 +1131,6 @@ double AudioServer::get_time_since_last_mix() const {
AudioServer *AudioServer::singleton = NULL;
-void *AudioServer::audio_data_alloc(uint32_t p_data_len, const uint8_t *p_from_data) {
-
- void *ad = memalloc(p_data_len);
- ERR_FAIL_COND_V(!ad, NULL);
- if (p_from_data) {
- copymem(ad, p_from_data, p_data_len);
- }
-
- {
- MutexLock lock(audio_data_lock);
-
- audio_data[ad] = p_data_len;
- audio_data_total_mem += p_data_len;
- audio_data_max_mem = MAX(audio_data_total_mem, audio_data_max_mem);
- }
-
- return ad;
-}
-
-void AudioServer::audio_data_free(void *p_data) {
-
- MutexLock lock(audio_data_lock);
-
- if (!audio_data.has(p_data)) {
- ERR_FAIL();
- }
-
- audio_data_total_mem -= audio_data[p_data];
- audio_data.erase(p_data);
- memfree(p_data);
-}
-
-size_t AudioServer::audio_data_get_total_memory_usage() const {
-
- return audio_data_total_mem;
-}
-size_t AudioServer::audio_data_get_max_memory_usage() const {
-
- return audio_data_max_mem;
-}
-
void AudioServer::add_callback(AudioCallback p_callback, void *p_userdata) {
lock();
CallbackItem ci;
@@ -1400,8 +1359,6 @@ void AudioServer::_bind_methods() {
AudioServer::AudioServer() {
singleton = this;
- audio_data_total_mem = 0;
- audio_data_max_mem = 0;
mix_frames = 0;
channel_count = 0;
to_mix = 0;
diff --git a/servers/audio_server.h b/servers/audio_server.h
index 8df0172750..a1a3dde719 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -232,14 +232,6 @@ private:
static AudioServer *singleton;
- // TODO create an audiodata pool to optimize memory
-
- Map<void *, uint32_t> audio_data;
- size_t audio_data_total_mem;
- size_t audio_data_max_mem;
-
- Mutex audio_data_lock;
-
void init_channels_and_buffers();
void _mix_step();
@@ -350,12 +342,6 @@ public:
virtual double get_time_to_next_mix() const;
virtual double get_time_since_last_mix() const;
- void *audio_data_alloc(uint32_t p_data_len, const uint8_t *p_from_data = NULL);
- void audio_data_free(void *p_data);
-
- size_t audio_data_get_total_memory_usage() const;
- size_t audio_data_get_max_memory_usage() const;
-
void add_callback(AudioCallback p_callback, void *p_userdata);
void remove_callback(AudioCallback p_callback, void *p_userdata);