Added magic_enum as a dependency. Tweaked ErrorHandling
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
|||||||
[submodule "lib/miniaudio"]
|
[submodule "lib/miniaudio"]
|
||||||
path = lib/miniaudio
|
path = lib/miniaudio
|
||||||
url = https://github.com/mackron/miniaudio
|
url = https://github.com/mackron/miniaudio
|
||||||
|
[submodule "lib/magic_enum"]
|
||||||
|
path = lib/magic_enum
|
||||||
|
url = https://github.com/Neargye/magic_enum
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-subobject-linkage")
|
|||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(lib/miniaudio)
|
add_subdirectory(lib/miniaudio)
|
||||||
|
add_subdirectory(lib/magic_enum)
|
||||||
|
|
||||||
find_package(Corrade REQUIRED Main)
|
find_package(Corrade REQUIRED Main)
|
||||||
find_package(Magnum REQUIRED)
|
find_package(Magnum REQUIRED)
|
||||||
|
|||||||
1
lib/magic_enum
Submodule
1
lib/magic_enum
Submodule
Submodule lib/magic_enum added at ec5734e491
@@ -1,4 +1,6 @@
|
|||||||
#include "ChargeAudio.hpp"
|
#include "ChargeAudio.hpp"
|
||||||
|
#include "magic_enum/include/magic_enum/magic_enum.hpp"
|
||||||
|
#include <Corrade/Utility/Debug.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
void ChargeAudio::ThrowOnRuntimeError(std::string message,
|
void ChargeAudio::ThrowOnRuntimeError(std::string message,
|
||||||
@@ -7,6 +9,7 @@ void ChargeAudio::ThrowOnRuntimeError(std::string message,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utility::Error{} << message << " (" << errorType << ")";
|
Utility::Error{} << message.c_str()
|
||||||
throw new std::runtime_error(message + ". Check STDERR for more info.\n");
|
<< magic_enum::enum_name(errorType).data();
|
||||||
|
throw new std::runtime_error(message + " Check STDERR for more info.\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ Sound::Sound(Engine *engine, std::function<void(Sound *)> setupFunction,
|
|||||||
maConfig = ma_sound_config_init_2(&baseEngine->maEngine);
|
maConfig = ma_sound_config_init_2(&baseEngine->maEngine);
|
||||||
maConfig.endCallback = Sound::onSoundFinish;
|
maConfig.endCallback = Sound::onSoundFinish;
|
||||||
maConfig.pEndCallbackUserData = this;
|
maConfig.pEndCallbackUserData = this;
|
||||||
|
|
||||||
setupFunction(this);
|
setupFunction(this);
|
||||||
|
|
||||||
ma_result maResponse =
|
ma_result maResponse =
|
||||||
ma_sound_init_ex(&baseEngine->maEngine, &maConfig, &maSound);
|
ma_sound_init_ex(&baseEngine->maEngine, &maConfig, &maSound);
|
||||||
ThrowOnRuntimeError("Failed to create a new sound. " + additionalErrorMessage,
|
ThrowOnRuntimeError("Failed to create a new sound. " + additionalErrorMessage,
|
||||||
@@ -63,18 +65,20 @@ bool Sound::SetPlaybackTime(float time) {
|
|||||||
|
|
||||||
// Controls
|
// Controls
|
||||||
void Sound::Play() {
|
void Sound::Play() {
|
||||||
ma_sound_start(&maSound);
|
ThrowOnRuntimeError("Failed to start the sound.", ma_sound_start(&maSound));
|
||||||
state = Sound::SoundState::Playing;
|
state = Sound::SoundState::Playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sound::Pause() {
|
void Sound::Pause() {
|
||||||
ma_sound_stop(&maSound);
|
ThrowOnRuntimeError("Failed to pause the sound.", ma_sound_stop(&maSound));
|
||||||
state = Sound::SoundState::Paused;
|
state = Sound::SoundState::Paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sound::Reset() {
|
void Sound::Reset() {
|
||||||
if (type == SoundType::StreamedRawPCM) {
|
if (type == SoundType::StreamedRawPCM) {
|
||||||
ThrowOnRuntimeError("You cannot reset on Streamed RawPCM sounds!");
|
ThrowOnRuntimeError(
|
||||||
|
"You cannot reset on Streamed RawPCM sounds! Since the buffer is a "
|
||||||
|
"ring buffer there isn't a \"start\" to return to.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_sound_seek_to_pcm_frame(&maSound, 0);
|
ma_sound_seek_to_pcm_frame(&maSound, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user