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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ comparer-config.toml

#ignore cmake cache
/build-*/
/build_*/
.vscode/tasks.json

# Extra files in the source distribution (see make_src_dist.py)
Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/SDL3_mixer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set(SDLMIXER_VORBIS_TREMOR OFF)
set(SDLMIXER_WAVPACK OFF)

FetchContent_Declare_ExcludeFromAll(SDL_mixer
URL https://github.com/libsdl-org/SDL_mixer/archive/7d37755016f0952c32c9483c556d8608da7ee82f.tar.gz
URL_HASH SHA256=2fa63f1eb623e3acd0012a461771eb93332e2026205f9487da3a3a75bc790111
URL https://github.com/libsdl-org/SDL_mixer/archive/refs/tags/release-3.2.0.tar.gz
URL_HASH SHA256=1077fef4a6e9513027da0a08e6f1b8645f8c88c8bef001c17befeb52b129b5dd
)
FetchContent_MakeAvailable_ExcludeFromAll(SDL_mixer)
28 changes: 16 additions & 12 deletions Source/engine/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
#include <utility>

#ifdef USE_SDL3
#include <SDL3/SDL_audio.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_timer.h>
#include <SDL3_mixer/SDL_mixer.h>
#else
#include <Aulib/Stream.h>
#include <SDL.h>

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

View workflow job for this annotation

GitHub Actions / tidy-check

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

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

Expand All @@ -30,19 +30,19 @@
#include "game_mode.hpp"
#include "options.h"
#include "utils/log.hpp"
#include "utils/math.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 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 38 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

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

included header stubs.h is not used directly

namespace devilution {

bool gbSndInited;

#ifdef USE_SDL3
SDL_AudioDeviceID CurrentAudioDeviceId;
MIX_Mixer *CurrentMixer;
#endif

/** The active background music track id. */
Expand All @@ -54,7 +54,7 @@

namespace {

SoundSample music;

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

View workflow job for this annotation

GitHub Actions / tidy-check

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

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

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

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

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:71: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 78 in Source/engine/sound.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

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

no header providing "SDL_GetError" is directly included
}

#ifdef STREAM_ALL_AUDIO_MIN_FILE_SIZE
Expand Down Expand Up @@ -119,26 +119,24 @@

SoundSample *DuplicateSound(const SoundSample &sound)
{
#ifdef USE_SDL3
return nullptr;
#else
auto duplicate = std::make_unique<SoundSample>();
if (duplicate->DuplicateFrom(sound) != 0)
return nullptr;
auto *result = duplicate.get();
decltype(duplicateSounds.begin()) it;
{
const std::lock_guard<SdlMutex> lock(*duplicateSoundsMutex);

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

View workflow job for this annotation

GitHub Actions / tidy-check

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

unchecked access to optional value
duplicateSounds.push_back(std::move(duplicate));
it = duplicateSounds.end();
--it;
}
#ifndef USE_SDL3
result->SetFinishCallback([it]([[maybe_unused]] Aulib::Stream &stream) {
const std::lock_guard<SdlMutex> lock(*duplicateSoundsMutex);
duplicateSounds.erase(it);
});
return result;
#endif
return result;
}

/** Maps from track ID to track name in spawn. */
Expand Down Expand Up @@ -166,12 +164,12 @@

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

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

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:167:40 [misc-include-cleaner]

no header providing "VOLUME_MAX" is directly included

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

View workflow job for this annotation

GitHub Actions / tidy-check

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

no header providing "VOLUME_MIN" is directly included
}

void OptionAudioChanged()
{
effects_cleanup_sfx(false);

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

View workflow job for this annotation

GitHub Actions / tidy-check

Source/engine/sound.cpp:172:2 [misc-include-cleaner]

no header providing "devilution::effects_cleanup_sfx" is directly included
music_stop();
snd_deinit();
snd_init();
Expand Down Expand Up @@ -263,18 +261,22 @@
// 22kHz, the audio format to 16-bit signed, use 2 output channels
// (stereo), and a 2KiB output buffer.
#ifdef USE_SDL3
if (!MIX_Init()) {
LogError(LogCategory::Audio, "Failed to initialize SDL_mixer: {}", SDL_GetError());
return;
}
const AudioOptions &audioOptions = GetOptions().Audio;
SDL_AudioSpec specHint = {};
specHint.format = SDL_AUDIO_S16LE;
specHint.channels = *audioOptions.channels;
specHint.freq = static_cast<int>(*audioOptions.sampleRate);
const SDL_AudioDeviceID resolvedId = SDL_OpenAudioDevice(audioOptions.device.id(), &specHint);
if (resolvedId == 0) {
LogError(LogCategory::Audio, "Failed to open audio device: {}", SDL_GetError());
CurrentMixer = MIX_CreateMixerDevice(audioOptions.device.id(), &specHint);
if (CurrentMixer == nullptr) {
LogError(LogCategory::Audio, "Failed to create mixer device: {}", SDL_GetError());
SDL_ClearError();
MIX_Quit();
return;
}
CurrentAudioDeviceId = resolvedId;
#else
if (!Aulib::init(*GetOptions().Audio.sampleRate, AUDIO_S16, *GetOptions().Audio.channels, *GetOptions().Audio.bufferSize, *GetOptions().Audio.device)) {
LogError(LogCategory::Audio, "Failed to initialize audio (Aulib::init): {}", SDL_GetError());
Expand All @@ -291,9 +293,11 @@
void snd_deinit()
{
if (gbSndInited) {
ClearDuplicateSounds();
#ifdef USE_SDL3
const AudioOptions &audioOptions = GetOptions().Audio;
SDL_CloseAudioDevice(audioOptions.device.id());
MIX_DestroyMixer(CurrentMixer);
CurrentMixer = nullptr;
MIX_Quit();
#else
Aulib::quit();
#endif
Expand Down
4 changes: 2 additions & 2 deletions Source/engine/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#ifndef NOSOUND
#ifdef USE_SDL3
#include <SDL3/SDL_audio.h>
struct MIX_Mixer;
#endif

#include "utils/soundsample.h"
Expand Down Expand Up @@ -59,7 +59,7 @@ struct TSnd {

extern bool gbSndInited;
#ifdef USE_SDL3
extern SDL_AudioDeviceID CurrentAudioDeviceId;
extern MIX_Mixer *CurrentMixer;
#endif

extern _music_id sgnMusicTrack;
Expand Down
6 changes: 5 additions & 1 deletion Source/storm/storm_svid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#ifndef NOSOUND
#include <SDL3/SDL_audio.h>
#include <SDL3_mixer/SDL_mixer.h>
#endif
#else
#include <SDL.h>
Expand All @@ -30,6 +31,7 @@
#include "engine/assets.hpp"
#include "engine/dx.h"
#include "engine/palette.h"
#include "engine/sound.h"
#include "options.h"
#include "utils/display.h"
#include "utils/log.hpp"
Expand Down Expand Up @@ -313,7 +315,9 @@ void SVidInitAudioStream(const SmackerAudioInfo &audioInfo)
SVidAudioStream = nullptr;
return;
}
if (!SDL_BindAudioStream(CurrentAudioDeviceId, SVidAudioStream)) {
const SDL_AudioDeviceID deviceId = static_cast<SDL_AudioDeviceID>(
SDL_GetNumberProperty(MIX_GetMixerProperties(CurrentMixer), MIX_PROP_MIXER_DEVICE_NUMBER, 0));
if (!SDL_BindAudioStream(deviceId, SVidAudioStream)) {
LogError(LogCategory::Audio, "SDL_BindAudioStream (from SVidPlayBegin): {}", SDL_GetError());
SDL_ClearError();
SDL_DestroyAudioStream(SVidAudioStream);
Expand Down
Loading
Loading