Skip to content

Commit f34bfa4

Browse files
committed
SDL3: Port audio code
1 parent cab1d0a commit f34bfa4

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

Source/engine/sound.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
#include <optional>
1414
#include <string>
1515

16-
#include <Aulib/Stream.h>
16+
#ifdef USE_SDL3
17+
#include <SDL3/SDL_timer.h>
18+
#else
1719
#include <SDL.h>
20+
#endif
1821
#include <expected.hpp>
1922

2023
#include "engine/assets.hpp"

Source/utils/push_aulib_decoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void PushAulibDecoder::DiscardPendingSamples() noexcept
4444
queue_ = std::queue<AudioQueueItem>();
4545
}
4646

47-
bool PushAulibDecoder::open([[maybe_unused]] SDL_RWops *rwops)
47+
bool PushAulibDecoder::open([[maybe_unused]] SDL_IOStream *rwops)
4848
{
4949
assert(rwops == nullptr);
5050
return true;

Source/utils/push_aulib_decoder.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
#include <variant>
1010

1111
#include <Aulib/Decoder.h>
12+
13+
#ifdef USE_SDL3
14+
#include <SDL3/SDL_mutex.h>
15+
#else
1216
#include <SDL_mutex.h>
17+
#endif
1318

19+
#include "utils/sdl_compat.h"
1420
#include "utils/sdl_mutex.h"
1521

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

3743
void DiscardPendingSamples() noexcept;
3844

39-
bool open(SDL_RWops *rwops) override;
45+
bool open(SDL_IOStream *rwops) override;
4046

4147
[[nodiscard]] int getChannels() const override
4248
{

Source/utils/soundsample.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
#include <Aulib/DecoderDrwav.h>
1010
#include <Aulib/Stream.h>
1111

12+
#ifdef USE_SDL3
13+
#include <SDL3/SDL_error.h>
14+
#include <SDL3/SDL_iostream.h>
15+
#else
1216
#include <SDL.h>
1317
#ifdef USE_SDL1
1418
#include "utils/sdl2_to_1_2_backports.h"
1519
#else
1620
#include "utils/sdl2_backports.h"
1721
#endif
22+
#endif
1823

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

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

140145
int SoundSample::SetChunkStream(std::string filePath, bool isMp3, bool logErrors)
141146
{
142-
SDL_RWops *handle = OpenAssetAsSdlRwOps(filePath.c_str(), /*threadsafe=*/true);
147+
SDL_IOStream *handle = OpenAssetAsSdlRwOps(filePath.c_str(), /*threadsafe=*/true);
143148
if (handle == nullptr) {
144149
if (logErrors)
145150
LogError(LogCategory::Audio, "OpenAsset failed (from SoundSample::SetChunkStream) for {}: {}", filePath, SDL_GetError());
@@ -162,7 +167,7 @@ int SoundSample::SetChunk(ArraySharedPtr<std::uint8_t> fileData, std::size_t dwB
162167
isMp3_ = isMp3;
163168
file_data_ = std::move(fileData);
164169
file_data_size_ = dwBytes;
165-
SDL_RWops *buf = SDL_RWFromConstMem(file_data_.get(), static_cast<int>(dwBytes));
170+
SDL_IOStream *buf = SDL_IOFromConstMem(file_data_.get(), static_cast<int>(dwBytes));
166171
if (buf == nullptr) {
167172
return -1;
168173
}

0 commit comments

Comments
 (0)