diff options
author | bmdhacks <bmd@bmdhacks.com> | 2025-02-13 16:01:47 -0800 |
---|---|---|
committer | bmdhacks <bmd@bmdhacks.com> | 2025-02-15 14:37:57 -0800 |
commit | 4ece0d79210c0f0351c16a0611f40308ceb8efb0 (patch) | |
tree | 7f27a77ccc27cdf0486d45feb6aa5ca484474e84 /source/core/StarIODeviceCallbacks.hpp | |
parent | eedd20da00e873ae188634f5e9af4a2e9efe8607 (diff) |
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.
Diffstat (limited to 'source/core/StarIODeviceCallbacks.hpp')
-rw-r--r-- | source/core/StarIODeviceCallbacks.hpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/core/StarIODeviceCallbacks.hpp b/source/core/StarIODeviceCallbacks.hpp new file mode 100644 index 0000000..8e2f9ed --- /dev/null +++ b/source/core/StarIODeviceCallbacks.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include "StarIODevice.hpp" +#include "vorbis/codec.h" +#include "vorbis/vorbisfile.h" + +namespace Star { + +// Provides callbacks for interfacing IODevice with ogg vorbis callbacks +class IODeviceCallbacks { +public: + explicit IODeviceCallbacks(IODevicePtr device); + + // No copying + IODeviceCallbacks(IODeviceCallbacks const&) = delete; + IODeviceCallbacks& operator=(IODeviceCallbacks const&) = delete; + + // Moving is ok + IODeviceCallbacks(IODeviceCallbacks&&) = default; + IODeviceCallbacks& operator=(IODeviceCallbacks&&) = default; + + // Get the underlying device + IODevicePtr const& device() const; + + // Callback functions for Ogg Vorbis + static size_t readFunc(void* ptr, size_t size, size_t nmemb, void* datasource); + static int seekFunc(void* datasource, ogg_int64_t offset, int whence); + static long int tellFunc(void* datasource); + + // Sets up callbacks for Ogg Vorbis + void setupOggCallbacks(ov_callbacks& callbacks); + +private: + IODevicePtr m_device; +}; + +} |