Skip to content

Commit

Permalink
fix(platform): Fix platform string and format inconsistencies.
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Nana <[email protected]>
  • Loading branch information
na2axl committed Aug 25, 2024
1 parent 935aa40 commit 32e628a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@

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

#ifndef AM_ID_CHAR_FMT
// Defines the format used to print AmObjectId value
#define AM_ID_CHAR_FMT "%llu"
#endif

#endif // _AM_CORE_COMMON_PLATFORMS_APPLE_CONFIG_H
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@

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

#ifndef AM_ID_CHAR_FMT
// Defines the format used to print AmObjectId value
#define AM_ID_CHAR_FMT "%lu"
#endif

#endif // _AM_CORE_COMMON_PLATFORMS_LINUX_CONFIG_H
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
// Defines the format used to print AmOsString text
#define AM_OS_CHAR_FMT "%ls"

// Defines the format used to print AmObjectId value
#define AM_ID_CHAR_FMT "%llu"

// Macro used to convert a string literal to an AmOsString string at compile-time
#define AM_OS_STRING(s) L##s

Expand Down
18 changes: 9 additions & 9 deletions src/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ namespace SparkyStudios::Audio::Amplitude
}
else
{
amLogError("Unknown bus with ID '%llu' listed in child buses.", busId);
amLogError("Unknown bus with ID '" AM_ID_CHAR_FMT "' listed in child buses.", busId);
return false;
}
}
Expand All @@ -489,7 +489,7 @@ namespace SparkyStudios::Audio::Amplitude
else
{
ampooldelete(MemoryPoolKind::Engine, DuckBusInternalState, bus);
amLogError("Unknown bus with ID '%llu' listed in duck buses.", duck->id());
amLogError("Unknown bus with ID '" AM_ID_CHAR_FMT "' listed in duck buses.", duck->id());
return false;
}
}
Expand Down Expand Up @@ -887,7 +887,7 @@ namespace SparkyStudios::Audio::Amplitude
{
if (const auto findIt = _state->sound_bank_map.find(id); findIt == _state->sound_bank_map.end())
{
amLogWarning("Cannot deinitialize Soundbank with ID '%llu'. Soundbank not loaded.", id);
amLogWarning("Cannot deinitialize Soundbank with ID '" AM_ID_CHAR_FMT "'. Soundbank not loaded.", id);
AMPLITUDE_ASSERT(0);
}
else if (findIt->second->GetRefCounter()->Decrement() == 0)
Expand Down Expand Up @@ -1333,7 +1333,7 @@ namespace SparkyStudios::Audio::Amplitude
if (SwitchContainerHandle handle = GetSwitchContainerHandle(id))
return Play(handle, location, userGain);

amLogError("Cannot play sound: invalid ID (%llu).", id);
amLogError("Cannot play sound: invalid ID (" AM_ID_CHAR_FMT ").", id);
return Channel(nullptr);
}

Expand All @@ -1353,7 +1353,7 @@ namespace SparkyStudios::Audio::Amplitude
if (SwitchContainerHandle handle = GetSwitchContainerHandle(id))
return Play(handle, entity, userGain);

amLogError("Cannot play sound: invalid ID (%llu).", id);
amLogError("Cannot play sound: invalid ID (" AM_ID_CHAR_FMT ").", id);
return Channel(nullptr);
}

Expand Down Expand Up @@ -1425,23 +1425,23 @@ namespace SparkyStudios::Audio::Amplitude
if (SwitchHandle handle = GetSwitchHandle(id))
return SetSwitchState(handle, stateId);

amLogError("Cannot update switch: Invalid ID (%llu).", id);
amLogError("Cannot update switch: Invalid ID (" AM_ID_CHAR_FMT ").", id);
}

void EngineImpl::SetSwitchState(AmSwitchID id, const AmString& stateName) const
{
if (SwitchHandle handle = GetSwitchHandle(id))
return SetSwitchState(handle, stateName);

amLogError("Cannot update switch: Invalid ID (%llu).", id);
amLogError("Cannot update switch: Invalid ID (" AM_ID_CHAR_FMT ").", id);
}

void EngineImpl::SetSwitchState(AmSwitchID id, const SwitchState& state) const
{
if (SwitchHandle handle = GetSwitchHandle(id))
return SetSwitchState(handle, state);

amLogError("Cannot update switch: Invalid ID (%llu).", id);
amLogError("Cannot update switch: Invalid ID (" AM_ID_CHAR_FMT ").", id);
}

void EngineImpl::SetSwitchState(const AmString& name, AmObjectID stateId) const
Expand Down Expand Up @@ -1484,7 +1484,7 @@ namespace SparkyStudios::Audio::Amplitude
if (RtpcHandle handle = GetRtpcHandle(id))
return SetRtpcValue(handle, value);

amLogError("Cannot update RTPC value: Invalid RTPC ID (%llu).", id);
amLogError("Cannot update RTPC value: Invalid RTPC ID (" AM_ID_CHAR_FMT ").", id);
}

void EngineImpl::SetRtpcValue(const AmString& name, double value) const
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Playback/BusInternalState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace SparkyStudios::Audio::Amplitude
_bus = amEngine->FindBus(definition->id());
if (!_bus.Valid())
{
amLogError("Cannot initialize duck-bus internal state: unable to find a duck-bus with ID %llu.", definition->id());
amLogError("Cannot initialize duck-bus internal state: unable to find a duck-bus with ID " AM_ID_CHAR_FMT ".", definition->id());
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Playback/ChannelInternalState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ namespace SparkyStudios::Audio::Amplitude

if (!sound)
{
amLogError("Unable to find a sound object with id: %llu", item.m_id);
amLogError("Unable to find a sound object with id: " AM_ID_CHAR_FMT, item.m_id);
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Sound/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace SparkyStudios::Audio::Amplitude
m_bus = FindBusInternalState(state, definition->bus());
if (!m_bus)
{
amLogError("Collection %s specifies an unknown bus ID: %llu.", definition->name()->c_str(), definition->bus());
amLogError("Collection %s specifies an unknown bus ID: " AM_ID_CHAR_FMT ".", definition->name()->c_str(), definition->bus());
return false;
}

Expand All @@ -137,7 +137,7 @@ namespace SparkyStudios::Audio::Amplitude
}
else
{
amLogError("Sound definition is invalid: invalid effect ID '%llu'.", definition->effect());
amLogError("Sound definition is invalid: invalid effect ID '" AM_ID_CHAR_FMT "'.", definition->effect());
return false;
}
}
Expand All @@ -152,7 +152,7 @@ namespace SparkyStudios::Audio::Amplitude
if (!m_attenuation)
{
amLogError(
"Collection %s specifies an unknown attenuation ID: %llu.", definition->name()->c_str(), definition->attenuation());
"Collection %s specifies an unknown attenuation ID: " AM_ID_CHAR_FMT ".", definition->name()->c_str(), definition->attenuation());
return false;
}
}
Expand All @@ -176,13 +176,13 @@ namespace SparkyStudios::Audio::Amplitude

if (id == kAmInvalidObjectId)
{
amLogError("Collection %s specifies an invalid sound ID: %llu.", definition->name()->c_str(), id);
amLogError("Collection %s specifies an invalid sound ID: " AM_ID_CHAR_FMT ".", definition->name()->c_str(), id);
return false;
}

if (auto findIt = state->sound_map.find(id); findIt == state->sound_map.end())
{
amLogError("Collection %s specifies an unknown sound ID: %llu", definition->name()->c_str(), id);
amLogError("Collection %s specifies an unknown sound ID: " AM_ID_CHAR_FMT "", definition->name()->c_str(), id);
return false;
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/Sound/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ namespace SparkyStudios::Audio::Amplitude
m_bus = FindBusInternalState(state, definition->bus());
if (!m_bus)
{
amLogError("Sound %s specifies an unknown bus ID: %llu.", definition->name()->c_str(), definition->bus());
amLogError("Sound %s specifies an unknown bus ID: " AM_ID_CHAR_FMT ".", definition->name()->c_str(), definition->bus());
return false;
}

Expand All @@ -228,7 +228,7 @@ namespace SparkyStudios::Audio::Amplitude
}
else
{
amLogError("Sound definition is invalid: invalid effect ID '%llu'", definition->effect());
amLogError("Sound definition is invalid: invalid effect ID '" AM_ID_CHAR_FMT "'", definition->effect());
return false;
}
}
Expand All @@ -241,7 +241,7 @@ namespace SparkyStudios::Audio::Amplitude
}
else
{
amLogError("Sound definition is invalid: invalid attenuation ID '%llu'", definition->attenuation());
amLogError("Sound definition is invalid: invalid attenuation ID '" AM_ID_CHAR_FMT "'", definition->attenuation());
return false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Sound/SwitchContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace SparkyStudios::Audio::Amplitude
m_bus = FindBusInternalState(state, definition->bus());
if (!m_bus)
{
amLogError("SwitchContainer %s specifies an unknown bus ID: %llu.", definition->name()->c_str(), definition->bus());
amLogError("SwitchContainer %s specifies an unknown bus ID: " AM_ID_CHAR_FMT ".", definition->name()->c_str(), definition->bus());
return false;
}

Expand All @@ -106,7 +106,7 @@ namespace SparkyStudios::Audio::Amplitude
}
else
{
amLogError("Sound definition is invalid: invalid effect ID '%llu'", definition->effect());
amLogError("Sound definition is invalid: invalid effect ID '" AM_ID_CHAR_FMT "'", definition->effect());
return false;
}
}
Expand All @@ -121,7 +121,7 @@ namespace SparkyStudios::Audio::Amplitude
if (!m_attenuation)
{
amLogError(
"SwitchContainer %s specifies an unknown attenuation ID: %llu.", definition->name()->c_str(),
"SwitchContainer %s specifies an unknown attenuation ID: " AM_ID_CHAR_FMT ".", definition->name()->c_str(),
definition->attenuation());
return false;
}
Expand Down Expand Up @@ -150,14 +150,14 @@ namespace SparkyStudios::Audio::Amplitude

if (id == kAmInvalidObjectId)
{
amLogError("SwitchContainer %s specifies an invalid sound object ID: %llu.", definition->name()->c_str(), id);
amLogError("SwitchContainer %s specifies an invalid sound object ID: " AM_ID_CHAR_FMT ".", definition->name()->c_str(), id);
return false;
}

if (!state->sound_map.contains(id) && !state->collection_map.contains(id))
{
amLogError(
"SwitchContainer %s specifies an unknown sound object ID: %llu. It's neither a Sound nor a Collection.",
"SwitchContainer %s specifies an unknown sound object ID: " AM_ID_CHAR_FMT ". It's neither a Sound nor a Collection.",
definition->name()->c_str(), id);
return false;
}
Expand Down
27 changes: 8 additions & 19 deletions tools/amir/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,22 @@ int parseFileName_IRCAM(const AmOsString& fileName, SphericalPosition& position)
{
const auto azimuth_location = fileName.find(AM_OS_STRING("_T"));
if (azimuth_location == AmOsString::npos)
{
return EXIT_FAILURE;
}

const auto elevation_location = fileName.find(AM_OS_STRING("_P"));
if (elevation_location == AmOsString::npos)
{
return EXIT_FAILURE;
}

// azimuth in degrees 3 digits, we need to negate so that the angle is relative to positive z-axis
// - from 000 to 180 for source on your left
// - from 180 to 359 for source on your right
const auto azimuth = -std::strtof(fileName.substr(azimuth_location + 2, 3).c_str(), nullptr);
const auto azimuth = -std::strtof(AM_OS_STRING_TO_STRING(fileName.substr(azimuth_location + 2, 3)), nullptr);

// elevation in degrees, modulo 360, 3 digits
// - from 315 to 345 for source below your head
// - 0 for source in front of your head
// - from 015 to 090 for source above your head
const auto elevation = std::strtof(fileName.substr(elevation_location + 2, 3).c_str(), nullptr);
const auto elevation = std::strtof(AM_OS_STRING_TO_STRING(fileName.substr(elevation_location + 2, 3)), nullptr);

position = SphericalPosition::FromDegrees(azimuth, elevation);
return EXIT_SUCCESS;
Expand All @@ -125,15 +121,11 @@ int parseFileName_MIT(const AmOsString& fileName, SphericalPosition& position)
{
const auto azimuth_location = fileName.find('e');
if (azimuth_location == AmOsString::npos)
{
return EXIT_FAILURE;
}

const auto elevation_location = fileName.find('H');
if (elevation_location == AmOsString::npos)
{
return EXIT_FAILURE;
}

AmOsString azimuthString;
for (AmSize az = azimuth_location + 1; fileName[az] != 'a'; ++az)
Expand All @@ -146,13 +138,13 @@ int parseFileName_MIT(const AmOsString& fileName, SphericalPosition& position)
// azimuth in degrees 3 digits, we need to negate so that the angle is relative to positive z-axis
// - from 000 to 180 for source on your left
// - from 180 to 359 for source on your right
const auto azimuth = -std::strtof(azimuthString.c_str(), nullptr);
const auto azimuth = -std::strtof(AM_OS_STRING_TO_STRING(azimuthString), nullptr);

// elevation in degrees 2 digits
// - from -15 to -40 for source below your head
// - 0 for source in front of your head
// - from 15 to 90 for source above your head
const auto elevation = std::strtof(elevationString.c_str(), nullptr);
const auto elevation = std::strtof(AM_OS_STRING_TO_STRING(elevationString), nullptr);

position = SphericalPosition(azimuth * AM_DegToRad, elevation * AM_DegToRad, 1.0);
return EXIT_SUCCESS;
Expand All @@ -162,26 +154,23 @@ int parseFileName_SADIE(const AmOsString& fileName, SphericalPosition& position)
{
const auto azimuth_location = fileName.find(AM_OS_STRING("azi_"));
if (azimuth_location == AmOsString::npos)
{
return EXIT_FAILURE;
}

const auto elevation_location = fileName.find(AM_OS_STRING("_ele_"));
if (elevation_location == AmOsString::npos)
{
return EXIT_FAILURE;
}

// azimuth in degrees, we need to negate so that the angle is relative to positive z-axis
// azimuth in degrees
// - from 000 to 180 for source on your left
// - from 180 to 359 for source on your right
const auto azimuth = std::strtof(fileName.substr(azimuth_location + 4, elevation_location - (azimuth_location + 4)).c_str(), nullptr);
const auto azimuth =
std::strtof(AM_OS_STRING_TO_STRING(fileName.substr(azimuth_location + 4, elevation_location - (azimuth_location + 4))), nullptr);

// elevation in degrees
// - from -15 to -81 for source below your head
// - 0 for source in front of your head
// - from 15 to 90 for source above your head
const auto elevation = std::strtof(fileName.substr(elevation_location + 5).c_str(), nullptr);
const auto elevation = std::strtof(AM_OS_STRING_TO_STRING(fileName.substr(elevation_location + 5)), nullptr);

position = SphericalPosition::FromDegrees(azimuth, elevation);
return EXIT_SUCCESS;
Expand Down

0 comments on commit 32e628a

Please sign in to comment.