Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Source/engine/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
#include <string>

#include <Aulib/Stream.h>
#ifdef USE_SDL3
#include <SDL3/SDL_timer.h>
#else
#include <SDL.h>

Check warning on line 20 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:20:1 [misc-include-cleaner]

included header SDL.h is not used directly
#endif
#include <expected.hpp>

#include "engine/assets.hpp"
#include "game_mode.hpp"
#include "options.h"
#include "utils/log.hpp"
#include "utils/math.h"

Check warning on line 28 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:28:1 [misc-include-cleaner]

included header math.h is not used directly
#include "utils/sdl_mutex.h"
#include "utils/status_macros.hpp"
#include "utils/stdcompat/shared_ptr_array.hpp"
#include "utils/str_cat.hpp"
#include "utils/stubs.h"

Check warning on line 33 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:33:1 [misc-include-cleaner]

included header stubs.h is not used directly

namespace devilution {

Expand All @@ -40,7 +44,7 @@

namespace {

SoundSample music;

Check warning on line 47 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:47:1 [misc-include-cleaner]

no header providing "devilution::SoundSample" is directly included

std::string GetMp3Path(const char *path)
{
Expand All @@ -54,14 +58,14 @@
{
bool isMp3 = true;
std::string foundPath = GetMp3Path(path);
AssetRef ref = FindAsset(foundPath.c_str());

Check warning on line 61 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:61:27 [readability-redundant-string-cstr]

redundant call to 'c_str'
if (!ref.ok()) {
ref = FindAsset(path);
foundPath = path;
isMp3 = false;
}
if (!ref.ok()) {
return tl::make_unexpected(StrCat("Audio file not found\n", path, "\n", SDL_GetError(), "\n" __FILE__ ":", __LINE__));

Check warning on line 68 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:68:75 [misc-include-cleaner]

no header providing "SDL_GetError" is directly included
}

#ifdef STREAM_ALL_AUDIO_MIN_FILE_SIZE
Expand All @@ -82,9 +86,9 @@
}
} else {
#if !defined(STREAM_ALL_AUDIO_MIN_FILE_SIZE) || STREAM_ALL_AUDIO_MIN_FILE_SIZE == 0
const size_t size = ref.size();

Check warning on line 89 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:89:9 [misc-include-cleaner]

no header providing "size_t" is directly included
#endif
AssetHandle handle = OpenAsset(std::move(ref));

Check warning on line 91 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:91:39 [misc-include-cleaner]

no header providing "std::move" is directly included
if (!handle.ok()) {
return tl::make_unexpected(StrCat("Failed to load audio file\n", foundPath, "\n", SDL_GetError(), "\n" __FILE__ ":", __LINE__));
}
Expand All @@ -111,7 +115,7 @@
auto *result = duplicate.get();
decltype(duplicateSounds.begin()) it;
{
const std::lock_guard<SdlMutex> lock(*duplicateSoundsMutex);

Check warning on line 118 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:118:41 [bugprone-unchecked-optional-access]

unchecked access to optional value
duplicateSounds.push_back(std::move(duplicate));
it = duplicateSounds.end();
--it;
Expand Down Expand Up @@ -148,7 +152,7 @@

int CapVolume(int volume)
{
return std::clamp(volume, VOLUME_MIN, VOLUME_MAX);

Check warning on line 155 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:155:28 [misc-include-cleaner]

no header providing "VOLUME_MIN" is directly included
}

void OptionAudioChanged()
Expand Down
2 changes: 1 addition & 1 deletion Source/utils/push_aulib_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void PushAulibDecoder::DiscardPendingSamples() noexcept
queue_ = std::queue<AudioQueueItem>();
}

bool PushAulibDecoder::open([[maybe_unused]] SDL_RWops *rwops)
bool PushAulibDecoder::open([[maybe_unused]] SDL_IOStream *rwops)
{
assert(rwops == nullptr);
return true;
Expand Down
8 changes: 7 additions & 1 deletion Source/utils/push_aulib_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
#include <variant>

#include <Aulib/Decoder.h>

#ifdef USE_SDL3
#include <SDL3/SDL_mutex.h>
#else
#include <SDL_mutex.h>
#endif

#include "utils/sdl_compat.h"
#include "utils/sdl_mutex.h"

namespace devilution {
Expand All @@ -36,7 +42,7 @@ class PushAulibDecoder final : public ::Aulib::Decoder {

void DiscardPendingSamples() noexcept;

bool open(SDL_RWops *rwops) override;
bool open(SDL_IOStream *rwops) override;

[[nodiscard]] int getChannels() const override
{
Expand Down
11 changes: 8 additions & 3 deletions Source/utils/soundsample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
#include <Aulib/DecoderDrwav.h>
#include <Aulib/Stream.h>

#ifdef USE_SDL3
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_iostream.h>
#else
#include <SDL.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#else
#include "utils/sdl2_backports.h"
#endif
#endif

#include "engine/assets.hpp"
#include "options.h"
Expand Down Expand Up @@ -67,7 +72,7 @@ std::unique_ptr<Aulib::Decoder> CreateDecoder(bool isMp3)
return std::make_unique<Aulib::DecoderDrwav>();
}

std::unique_ptr<Aulib::Stream> CreateStream(SDL_RWops *handle, bool isMp3)
std::unique_ptr<Aulib::Stream> CreateStream(SDL_IOStream *handle, bool isMp3)
{
auto decoder = CreateDecoder(isMp3);
if (!decoder->open(handle)) // open for `getRate`
Expand Down Expand Up @@ -139,7 +144,7 @@ bool SoundSample::Play(int numIterations)

int SoundSample::SetChunkStream(std::string filePath, bool isMp3, bool logErrors)
{
SDL_RWops *handle = OpenAssetAsSdlRwOps(filePath.c_str(), /*threadsafe=*/true);
SDL_IOStream *handle = OpenAssetAsSdlRwOps(filePath.c_str(), /*threadsafe=*/true);
if (handle == nullptr) {
if (logErrors)
LogError(LogCategory::Audio, "OpenAsset failed (from SoundSample::SetChunkStream) for {}: {}", filePath, SDL_GetError());
Expand All @@ -162,7 +167,7 @@ int SoundSample::SetChunk(ArraySharedPtr<std::uint8_t> fileData, std::size_t dwB
isMp3_ = isMp3;
file_data_ = std::move(fileData);
file_data_size_ = dwBytes;
SDL_RWops *buf = SDL_RWFromConstMem(file_data_.get(), static_cast<int>(dwBytes));
SDL_IOStream *buf = SDL_IOFromConstMem(file_data_.get(), static_cast<int>(dwBytes));
if (buf == nullptr) {
return -1;
}
Expand Down
Loading