From e0d03ec5c1023c4f191b4011b76a16ef581d3ccf Mon Sep 17 00:00:00 2001 From: naftalimurgor Date: Sun, 12 Jun 2022 21:45:18 +0300 Subject: [PATCH] ( #816 ) Move `data/audio_buffer.hpp` to `base/` * adapt `CMakeList.txt` * adapt all client code in `assets/` to namespace `base` * adapt all client code in `audio` to namespace `base` * adapt `audio_buffer.hpp` from namespace `data` to namespace `base` --- src/CMakeLists.txt | 2 +- src/assets/resource_loader.cpp | 4 ++-- src/assets/resource_loader.hpp | 6 +++--- src/assets/voc_decoder.cpp | 4 ++-- src/assets/voc_decoder.hpp | 4 ++-- src/audio/sound_system.cpp | 28 ++++++++++++++-------------- src/audio/sound_system.hpp | 2 +- src/{data => base}/audio_buffer.hpp | 4 ++-- 8 files changed, 27 insertions(+), 27 deletions(-) rename src/{data => base}/audio_buffer.hpp (95%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99ca61572..7becc5044 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ set(core_sources audio/sound_system.hpp base/array_view.cpp base/array_view.hpp + base/audio_buffer.hpp base/clock.hpp base/container_utils.hpp base/defer.hpp @@ -52,7 +53,6 @@ set(core_sources base/string_utils.hpp base/warnings.hpp data/actor_ids.hpp - data/audio_buffer.hpp data/bonus.hpp data/duke_script.hpp data/game_options.cpp diff --git a/src/assets/resource_loader.cpp b/src/assets/resource_loader.cpp index 69dc30499..4ec72507b 100644 --- a/src/assets/resource_loader.cpp +++ b/src/assets/resource_loader.cpp @@ -440,7 +440,7 @@ bool ResourceLoader::hasSoundBlasterSound(const data::SoundId id) const } -data::AudioBuffer +base::AudioBuffer ResourceLoader::loadSoundBlasterSound(const data::SoundId id) const { const auto digitizedSoundFileName = digitizedSoundFilenameForId(id); @@ -493,7 +493,7 @@ std::vector } -data::AudioBuffer ResourceLoader::loadSound(std::string_view name) const +base::AudioBuffer ResourceLoader::loadSound(std::string_view name) const { return assets::decodeVoc(file(name)); } diff --git a/src/assets/resource_loader.hpp b/src/assets/resource_loader.hpp index 401856f92..4b2e5ace3 100644 --- a/src/assets/resource_loader.hpp +++ b/src/assets/resource_loader.hpp @@ -21,8 +21,8 @@ #include "assets/duke_script_loader.hpp" #include "assets/palette.hpp" #include "base/array_view.hpp" +#include "base/audio_buffer.hpp" #include "base/image.hpp" -#include "data/audio_buffer.hpp" #include "data/movie.hpp" #include "data/song.hpp" #include "data/sound_ids.hpp" @@ -102,7 +102,7 @@ class ResourceLoader data::Song loadMusic(std::string_view name) const; bool hasSoundBlasterSound(data::SoundId id) const; - data::AudioBuffer loadSoundBlasterSound(data::SoundId id) const; + base::AudioBuffer loadSoundBlasterSound(data::SoundId id) const; std::vector replacementSoundPaths(data::SoundId id) const; @@ -133,7 +133,7 @@ class ResourceLoader data::Image loadTiledFullscreenImage( std::string_view name, const data::Palette16& overridePalette) const; - data::AudioBuffer loadSound(std::string_view name) const; + base::AudioBuffer loadSound(std::string_view name) const; std::filesystem::path mGamePath; std::vector mModPaths; diff --git a/src/assets/voc_decoder.cpp b/src/assets/voc_decoder.cpp index 4c2ebad1f..5a739eecc 100644 --- a/src/assets/voc_decoder.cpp +++ b/src/assets/voc_decoder.cpp @@ -375,7 +375,7 @@ void decodeAudio( } // namespace -data::AudioBuffer decodeVoc(const ByteBuffer& data) +base::AudioBuffer decodeVoc(const ByteBuffer& data) { LeStreamReader reader(data); if (!readAndValidateVocHeader(reader)) @@ -383,7 +383,7 @@ data::AudioBuffer decodeVoc(const ByteBuffer& data) throw std::invalid_argument("Invalid VOC file header"); } - std::vector decodedSamples; + std::vector decodedSamples; std::optional sampleRate; while (reader.hasData()) diff --git a/src/assets/voc_decoder.hpp b/src/assets/voc_decoder.hpp index 918f80904..e820dfd44 100644 --- a/src/assets/voc_decoder.hpp +++ b/src/assets/voc_decoder.hpp @@ -17,12 +17,12 @@ #pragma once #include "assets/byte_buffer.hpp" -#include "data/audio_buffer.hpp" +#include "base/audio_buffer.hpp" namespace rigel::assets { -data::AudioBuffer decodeVoc(const ByteBuffer& data); +base::AudioBuffer decodeVoc(const ByteBuffer& data); } diff --git a/src/audio/sound_system.cpp b/src/audio/sound_system.cpp index 0d523a576..b8b860a07 100644 --- a/src/audio/sound_system.cpp +++ b/src/audio/sound_system.cpp @@ -67,8 +67,8 @@ const auto COMBINED_SOUNDS_ADLIB_PERCENTAGE = 0.30f; const auto DESIRED_SAMPLE_RATE = 44100; const auto BUFFER_SIZE = 2048; -data::AudioBuffer - resampleAudio(const data::AudioBuffer& buffer, const int newSampleRate) +base::AudioBuffer + resampleAudio(const base::AudioBuffer& buffer, const int newSampleRate) { using ResamplerPtr = std::unique_ptr; @@ -82,7 +82,7 @@ data::AudioBuffer base::integerDivCeil(inputLength, buffer.mSampleRate) * newSampleRate); - std::vector resampled(outputLength); + std::vector resampled(outputLength); speex_resampler_process_int( pResampler.get(), 0, @@ -95,7 +95,7 @@ data::AudioBuffer } -void appendRampToZero(data::AudioBuffer& buffer, const int sampleRate) +void appendRampToZero(base::AudioBuffer& buffer, const int sampleRate) { // Roughly 10 ms of linear ramp const auto rampLength = (sampleRate / 100); @@ -107,7 +107,7 @@ void appendRampToZero(data::AudioBuffer& buffer, const int sampleRate) { const auto interpolation = i / static_cast(rampLength); const auto rampedValue = lastSample * (1.0 - interpolation); - buffer.mSamples.push_back(base::roundTo(rampedValue)); + buffer.mSamples.push_back(base::roundTo(rampedValue)); } } @@ -115,8 +115,8 @@ void appendRampToZero(data::AudioBuffer& buffer, const int sampleRate) // Prepares the given audio buffer to be loaded into a Mix_Chunk. This includes // resampling to the given sample rate and making sure the buffer ends in a // zero value to avoid clicks/pops. -data::AudioBuffer - prepareBuffer(const data::AudioBuffer& original, const int sampleRate) +base::AudioBuffer + prepareBuffer(const base::AudioBuffer& original, const int sampleRate) { auto buffer = resampleAudio(original, sampleRate); if (buffer.mSamples.back() != 0) @@ -133,7 +133,7 @@ data::AudioBuffer // Converts the given audio buffer into the given audio format and returns it // as a raw buffer RawBuffer convertBuffer( - const data::AudioBuffer& buffer, + const base::AudioBuffer& buffer, const std::uint16_t audioFormat, const int numChannels) { @@ -163,8 +163,8 @@ RawBuffer convertBuffer( void overlaySound( - data::AudioBuffer& base, - const data::AudioBuffer& overlay, + base::AudioBuffer& base, + const base::AudioBuffer& overlay, const float overlayVolume) { assert(base.mSampleRate == overlay.mSampleRate); @@ -181,7 +181,7 @@ void overlaySound( reinterpret_cast(base.mSamples.data()), reinterpret_cast(overlay.mSamples.data()), AUDIO_S16LSB, - static_cast(overlay.mSamples.size() * sizeof(data::Sample)), + static_cast(overlay.mSamples.size() * sizeof(base::Sample)), overlayVolumeSdl); } @@ -191,7 +191,7 @@ auto idToIndex(const data::SoundId id) return static_cast(id); } -data::AudioBuffer renderAdlibSound( +base::AudioBuffer renderAdlibSound( const assets::AdlibSound& sound, const AdlibEmulator::Type emulatorType) { @@ -215,7 +215,7 @@ data::AudioBuffer renderAdlibSound( const auto octaveBits = static_cast((sound.mOctave & 7) << 2); const auto samplesPerTick = OPL2_SAMPLE_RATE / ADLIB_SOUND_RATE; - std::vector renderedSamples; + std::vector renderedSamples; renderedSamples.reserve(sound.mSoundData.size() * samplesPerTick); for (const auto byte : sound.mSoundData) @@ -237,7 +237,7 @@ data::AudioBuffer renderAdlibSound( } -data::AudioBuffer loadSoundForStyle( +base::AudioBuffer loadSoundForStyle( const data::SoundId id, const data::SoundStyle soundStyle, const int sampleRate, diff --git a/src/audio/sound_system.hpp b/src/audio/sound_system.hpp index 8c30c6208..3004f1f22 100644 --- a/src/audio/sound_system.hpp +++ b/src/audio/sound_system.hpp @@ -16,8 +16,8 @@ #pragma once +#include "base/audio_buffer.hpp" #include "base/defer.hpp" -#include "data/audio_buffer.hpp" #include "data/game_options.hpp" #include "data/song.hpp" #include "data/sound_ids.hpp" diff --git a/src/data/audio_buffer.hpp b/src/base/audio_buffer.hpp similarity index 95% rename from src/data/audio_buffer.hpp rename to src/base/audio_buffer.hpp index 3ca917e0d..901cb4f6b 100644 --- a/src/data/audio_buffer.hpp +++ b/src/base/audio_buffer.hpp @@ -20,7 +20,7 @@ #include -namespace rigel::data +namespace rigel::base { using Sample = std::int16_t; @@ -33,4 +33,4 @@ struct AudioBuffer }; -} // namespace rigel::data +} // namespace rigel::base