From 4ece0d79210c0f0351c16a0611f40308ceb8efb0 Mon Sep 17 00:00:00 2001 From: bmdhacks Date: Thu, 13 Feb 2025 16:01:47 -0800 Subject: Streaming Audio Problem: The current implementation reads the entire sound file in to memory in order to play it. For OGG background music, this uses 91 Megs of RAM by injesting all ogg songs as well as all wav assets. Solution: Change StarAudio to play the asset from a file handle and stream it off the disk. This results in a massive savings of RAM and doesn't really affect audio quality unless you're doing massive disk operations such as compiling Starbound. --- source/core/StarBuffer.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/core/StarBuffer.cpp') diff --git a/source/core/StarBuffer.cpp b/source/core/StarBuffer.cpp index 5b5b2e4..e8184e3 100644 --- a/source/core/StarBuffer.cpp +++ b/source/core/StarBuffer.cpp @@ -2,6 +2,7 @@ #include "StarMathCommon.hpp" #include "StarIODevice.hpp" #include "StarFormat.hpp" +#include "StarLogging.hpp" namespace Star { @@ -273,6 +274,18 @@ void ExternalBuffer::reset(char const* externalData, size_t len) { m_size = len; } +IODevicePtr Buffer::clone() { + auto cloned = make_shared(*this); + // Reset position to 0 while preserving mode and data + cloned->seek(0); + return cloned; +} + +IODevicePtr ExternalBuffer::clone() { + Logger::info("Cloning ExternalBuffer from position {}"); + return make_shared(*this); +} + size_t ExternalBuffer::doRead(size_t pos, char* data, size_t len) { if (len == 0) return 0; -- cgit v1.2.3