Skip to content

Commit

Permalink
fix(logging): Handling wchar_t on Windows.
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Nana <[email protected]>
  • Loading branch information
na2axl committed Jun 22, 2024
1 parent 8ee12f6 commit 8785005
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 33 deletions.
6 changes: 4 additions & 2 deletions include/SparkyStudios/Audio/Amplitude/Core/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#ifndef SPARK_AUDIO_LOG_H
#define SPARK_AUDIO_LOG_H

#include <fmt/format.h>
#include <fmt/chrono.h>
#include <fmt/std.h>
#include <fmt/xchar.h>

#include <SparkyStudios/Audio/Amplitude/Core/Common.h>

Expand All @@ -34,7 +36,7 @@
#define amLog(_level_, _message_, ...) \
if (amLogger != nullptr) \
{ \
amLogger->_level_(fmt::format(_message_, ##__VA_ARGS__), __FILE__, __LINE__); \
amLogger->_level_(fmt::format((_message_), ##__VA_ARGS__), __FILE__, __LINE__); \
} \
(void)0

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Codecs/AMS/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ namespace SparkyStudios::Audio::Amplitude

if (!ReadHeader(_file, m_format, _blockSize))
{
amLogError("The AMS codec cannot handle the file: '{}'", file->GetPath());
amLogError("The AMS codec cannot handle the file: '{}'", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand Down Expand Up @@ -598,7 +598,7 @@ namespace SparkyStudios::Audio::Amplitude

if (!WriteHeader(_file, m_format, _samplesPerBlock))
{
amLogError("The AMS codec was unable to write the file: '{}'", file->GetPath());
amLogError("The AMS codec was unable to write the file: '{}'", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Codecs/MP3/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace SparkyStudios::Audio::Amplitude
{
if (!m_codec->CanHandleFile(file))
{
amLogError("The MP3 codec cannot handle the file: '{}'", file->GetPath());
amLogError("The MP3 codec cannot handle the file: '{}'", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand All @@ -73,14 +73,14 @@ namespace SparkyStudios::Audio::Amplitude

if (drmp3_init(&_mp3, onRead, onSeek, _file.get(), &codec->m_allocationCallbacks) == DRMP3_FALSE)
{
amLogError("Cannot load the MP3 file: '{}'", file->GetPath());
amLogError("Cannot load the MP3 file: '{}'", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

const drmp3_uint64 framesCount = drmp3_get_pcm_frame_count(&_mp3);
if (framesCount == DRMP3_FALSE)
{
amLogError("Cannot load the MP3 file: '{}'.", file->GetPath());
amLogError("Cannot load the MP3 file: '{}'.", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand Down
9 changes: 5 additions & 4 deletions src/Core/Codecs/WAV/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace SparkyStudios::Audio::Amplitude
{
if (!m_codec->CanHandleFile(file))
{
amLogError("The WAV codec cannot handle the file: '{}'.", file->GetPath());
amLogError("The WAV codec cannot handle the file: '{}'.", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand All @@ -79,7 +79,7 @@ namespace SparkyStudios::Audio::Amplitude

if (drwav_init(&_wav, onRead, onSeek, _file.get(), &codec->m_allocationCallbacks) == DRWAV_FALSE)
{
amLogError("Cannot load the WAV file: '{}'.", file->GetPath());
amLogError("Cannot load the WAV file: '{}'.", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand Down Expand Up @@ -141,7 +141,8 @@ namespace SparkyStudios::Audio::Amplitude
if (!_isFormatSet)
{
amLogError(
"The WAV codec cannot open the file '{}' without a format set. Have you missed to call SetFormat()?", file->GetPath());
"The WAV codec cannot open the file '{}' without a format set. Have you missed to call SetFormat()?",
AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand All @@ -158,7 +159,7 @@ namespace SparkyStudios::Audio::Amplitude
if (drwav_init_write_sequential_pcm_frames(
&_wav, &format, m_format.GetFramesCount(), onWrite, _file.get(), &codec->m_allocationCallbacks) == DRWAV_FALSE)
{
amLogError("Cannot load the WAV file: '{}'.", file->GetPath());
amLogError("Cannot load the WAV file: '{}'.", AM_OS_STRING_TO_STRING(file->GetPath()));
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Core/Drivers/MiniAudio/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ namespace SparkyStudios::Audio::Amplitude
switch (level)
{
case MA_LOG_LEVEL_DEBUG:
amLogger->Debug(pMessage, __FILE__, __LINE__);
amLogDebug("{}", pMessage);
break;
case MA_LOG_LEVEL_INFO:
amLogger->Info(pMessage, __FILE__, __LINE__);
amLogInfo("{}", pMessage);
break;
case MA_LOG_LEVEL_WARNING:
amLogger->Warning(pMessage, __FILE__, __LINE__);
amLogWarning("{}", pMessage);
break;
case MA_LOG_LEVEL_ERROR:
amLogger->Error(pMessage, __FILE__, __LINE__);
amLogError("{}", pMessage);
break;
default:
amLogger->Critical(pMessage, __FILE__, __LINE__);
amLogCritical("{}", pMessage);
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,26 +222,26 @@ namespace SparkyStudios::Audio::Amplitude

if (!plugin->has_symbol("RegisterPlugin"))
{
amLogError("LoadPlugin fail on '{}'. The library doesn't export a RegisterPlugin symbol.", pluginLibraryName);
amLogError("LoadPlugin fail on '{}'. The library doesn't export a RegisterPlugin symbol.", AM_OS_STRING_TO_STRING(pluginLibraryName));
return nullptr;
}

if (!plugin->has_symbol("PluginName"))
{
amLogError("LoadPlugin fail on '{}'. The library doesn't export a PluginName symbol.", pluginLibraryName);
amLogError("LoadPlugin fail on '{}'. The library doesn't export a PluginName symbol.", AM_OS_STRING_TO_STRING(pluginLibraryName));
return nullptr;
}

if (!plugin->has_symbol("PluginVersion"))
{
amLogError("LoadPlugin fail on '{}'. The library doesn't export a PluginVersion symbol.", pluginLibraryName);
amLogError("LoadPlugin fail on '{}'. The library doesn't export a PluginVersion symbol.", AM_OS_STRING_TO_STRING(pluginLibraryName));
return nullptr;
}

if (const auto registerFunc = plugin->get_function<bool(Engine*, MemoryManager*)>("RegisterPlugin");
!registerFunc(amEngine, amMemory))
{
amLogError("LoadPlugin fail on '{}'. The plugin registration has failed.", pluginLibraryName);
amLogError("LoadPlugin fail on '{}'. The plugin registration has failed.", AM_OS_STRING_TO_STRING(pluginLibraryName));
return nullptr;
}

Expand Down Expand Up @@ -550,7 +550,7 @@ namespace SparkyStudios::Audio::Amplitude
{
if (const AmOsString& configFilePath = _fs->ResolvePath(configFile); !LoadFile(_fs->OpenFile(configFilePath), &_configSrc))
{
amLogError("Could not load audio config file at path '{}'.", configFile);
amLogError("Could not load audio config file at path '{}'.", AM_OS_STRING_TO_STRING(configFile));
return false;
}

Expand Down Expand Up @@ -850,7 +850,7 @@ namespace SparkyStudios::Audio::Amplitude
{
if (const auto findIt = _state->sound_bank_id_map.find(filename); findIt == _state->sound_bank_id_map.end())
{
amLogWarning("Cannot deinitialize Soundbank '{}'. Soundbank not loaded.", filename);
amLogWarning("Cannot deinitialize Soundbank '{}'. Soundbank not loaded.", AM_OS_STRING_TO_STRING(filename));
AMPLITUDE_ASSERT(0);
}
else
Expand Down
12 changes: 6 additions & 6 deletions src/Mixer/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace SparkyStudios::Audio::Amplitude
static void OnSoundStarted(Mixer* mixer, MixerLayer* layer)
{
const auto* sound = layer->snd->sound.get();
amLogDebug("Started sound: {}.", sound->GetSound()->GetPath());
amLogDebug("Started sound: {}.", AM_OS_STRING_TO_STRING(sound->GetSound()->GetPath()));

const auto* channel = sound->GetChannel();
auto* channelState = channel->GetParentChannelState();
Expand All @@ -257,7 +257,7 @@ namespace SparkyStudios::Audio::Amplitude
static void OnSoundPaused(Mixer* mixer, MixerLayer* layer)
{
const auto* sound = layer->snd->sound.get();
amLogDebug("Paused sound: {}.", sound->GetSound()->GetPath());
amLogDebug("Paused sound: {}.", AM_OS_STRING_TO_STRING(sound->GetSound()->GetPath()));

const auto* channel = sound->GetChannel();
auto* channelState = channel->GetParentChannelState();
Expand All @@ -268,7 +268,7 @@ namespace SparkyStudios::Audio::Amplitude
static void OnSoundResumed(Mixer* mixer, MixerLayer* layer)
{
const auto* sound = layer->snd->sound.get();
amLogDebug("Resumed sound: {}.", sound->GetSound()->GetPath());
amLogDebug("Resumed sound: {}.", AM_OS_STRING_TO_STRING(sound->GetSound()->GetPath()));

const auto* channel = sound->GetChannel();
auto* channelState = channel->GetParentChannelState();
Expand All @@ -279,7 +279,7 @@ namespace SparkyStudios::Audio::Amplitude
static void OnSoundStopped(Mixer* mixer, MixerLayer* layer)
{
const auto* sound = layer->snd->sound.get();
amLogDebug("Stopped sound: {}.", sound->GetSound()->GetPath());
amLogDebug("Stopped sound: {}.", AM_OS_STRING_TO_STRING(sound->GetSound()->GetPath()));

const auto* channel = sound->GetChannel();
auto* channelState = channel->GetParentChannelState();
Expand All @@ -293,7 +293,7 @@ namespace SparkyStudios::Audio::Amplitude
static bool OnSoundLooped(Mixer* mixer, MixerLayer* layer)
{
auto* sound = layer->snd->sound.get();
amLogDebug("Looped sound: {}.", sound->GetSound()->GetPath());
amLogDebug("Looped sound: {}.", AM_OS_STRING_TO_STRING(sound->GetSound()->GetPath()));

Mixer::IncrementSoundLoopCount(sound);

Expand Down Expand Up @@ -322,7 +322,7 @@ namespace SparkyStudios::Audio::Amplitude
static void OnSoundEnded(Mixer* mixer, MixerLayer* layer)
{
auto* sound = layer->snd->sound.get();
amLogDebug("Ended sound: {}.", sound->GetSound()->GetPath());
amLogDebug("Ended sound: {}.", AM_OS_STRING_TO_STRING(sound->GetSound()->GetPath()));

RealChannel* channel = sound->GetChannel();
auto* channelState = channel->GetParentChannelState();
Expand Down
2 changes: 1 addition & 1 deletion src/Mixer/RealChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace SparkyStudios::Audio::Amplitude
if (!success)
{
_channelLayersId[layer] = kAmInvalidObjectId;
amLogError("Could not play sound '{}'.", _activeSounds[layer]->GetSound()->GetPath());
amLogError("Could not play sound '{}'.", AM_OS_STRING_TO_STRING(_activeSounds[layer]->GetSound()->GetPath()));
}

return success;
Expand Down
8 changes: 4 additions & 4 deletions src/Sound/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace SparkyStudios::Audio::Amplitude

if (!loader->Exists(filename))
{
amLogError("Cannot load the sound: the file \"{}\" does not exist.", filename);
amLogError("Cannot load the sound: the file \"{}\" does not exist.", AM_OS_STRING_TO_STRING(filename));
return;
}

Expand All @@ -145,14 +145,14 @@ namespace SparkyStudios::Audio::Amplitude
_codec = Codec::FindCodecForFile(file);
if (_codec == nullptr)
{
amLogError("Cannot load the sound: unable to find codec for '{}'.", filename);
amLogError("Cannot load the sound: unable to find codec for '{}'.", AM_OS_STRING_TO_STRING(filename));
return;
}

_decoder = _codec->CreateDecoder();
if (!_decoder->Open(file))
{
amLogError("Cannot load the sound: unable to initialize a decoder for '{}'.", filename);
amLogError("Cannot load the sound: unable to initialize a decoder for '{}'.", AM_OS_STRING_TO_STRING(filename));
return;
}

Expand Down Expand Up @@ -287,7 +287,7 @@ namespace SparkyStudios::Audio::Amplitude
_decoder = _parent->_codec->CreateDecoder();
if (!_decoder->Open(file))
{
amLogError("Cannot load the sound: unable to initialize a decoder for '{}'.", filename);
amLogError("Cannot load the sound: unable to initialize a decoder for '{}'.", AM_OS_STRING_TO_STRING(filename));
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions tools/amac/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstdarg>
#include <iostream>

#include <SparkyStudios/Audio/Amplitude/Amplitude.h>
Expand Down
1 change: 1 addition & 0 deletions tools/ampk/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstdarg>
#include <iostream>

#include <SparkyStudios/Audio/Amplitude/Amplitude.h>
Expand Down

0 comments on commit 8785005

Please sign in to comment.