Skip to content

Commit

Permalink
Fix printing hex values
Browse files Browse the repository at this point in the history
fmt's :x type doesn't behave as expected with signed/negative integer values.
Unlike %x, which prints the value as-is with hex digits, as if always unsigned,
fmt's :x will display a - with a negated hex value, making it non-obvious what
the hex value actually is.
  • Loading branch information
kcat committed Dec 8, 2024
1 parent ca8afd7 commit 47712b3
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 244 deletions.
68 changes: 41 additions & 27 deletions al/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <numeric>
#include <optional>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -764,15 +763,15 @@ try {
if(freq < 1)
context->throw_error(AL_INVALID_VALUE, "Invalid sample rate {}", freq);
if((flags&INVALID_STORAGE_MASK) != 0)
context->throw_error(AL_INVALID_VALUE, "Invalid storage flags 0x{:x}",
context->throw_error(AL_INVALID_VALUE, "Invalid storage flags {:#x}",
flags&INVALID_STORAGE_MASK);
if((flags&AL_MAP_PERSISTENT_BIT_SOFT) && !(flags&MAP_READ_WRITE_FLAGS))
context->throw_error(AL_INVALID_VALUE,
"Declaring persistently mapped storage without read or write access");

auto usrfmt = DecomposeUserFormat(format);
if(!usrfmt)
context->throw_error(AL_INVALID_ENUM, "Invalid format 0x{:04x}", format);
context->throw_error(AL_INVALID_ENUM, "Invalid format {:#04x}", as_unsigned(format));

auto bdata = static_cast<const std::byte*>(data);
LoadData(context, albuf, freq, static_cast<ALuint>(size), usrfmt->channels, usrfmt->type,
Expand Down Expand Up @@ -801,7 +800,7 @@ try {

auto usrfmt = DecomposeUserFormat(format);
if(!usrfmt)
context->throw_error(AL_INVALID_ENUM, "Invalid format 0x{:04x}", format);
context->throw_error(AL_INVALID_ENUM, "Invalid format {:#04x}", as_unsigned(format));

PrepareUserPtr(context, albuf, freq, usrfmt->channels, usrfmt->type,
static_cast<std::byte*>(data), static_cast<ALuint>(size));
Expand All @@ -823,7 +822,7 @@ try {
if(!albuf)
context->throw_error(AL_INVALID_NAME, "Invalid buffer ID {}", buffer);
if((access&INVALID_MAP_FLAGS) != 0)
context->throw_error(AL_INVALID_VALUE, "Invalid map flags 0x{:x}",
context->throw_error(AL_INVALID_VALUE, "Invalid map flags {:#x}",
access&INVALID_MAP_FLAGS);
if(!(access&MAP_READ_WRITE_FLAGS))
context->throw_error(AL_INVALID_VALUE, "Mapping buffer {} without read or write access",
Expand Down Expand Up @@ -930,7 +929,7 @@ try {

auto usrfmt = DecomposeUserFormat(format);
if(!usrfmt)
context->throw_error(AL_INVALID_ENUM, "Invalid format 0x{:04x}", format);
context->throw_error(AL_INVALID_ENUM, "Invalid format {:#04x}", as_unsigned(format));

const ALuint unpack_align{albuf->UnpackAlign};
const ALuint align{SanitizeAlignment(usrfmt->type, unpack_align)};
Expand Down Expand Up @@ -985,7 +984,8 @@ try {
if(LookupBuffer(device, buffer) == nullptr)
context->throw_error(AL_INVALID_NAME, "Invalid buffer ID {}", buffer);

context->throw_error(AL_INVALID_ENUM, "Invalid buffer float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer float property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1004,7 +1004,8 @@ try {
if(LookupBuffer(device, buffer) == nullptr)
context->throw_error(AL_INVALID_NAME, "Invalid buffer ID {}", buffer);

context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-float property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1024,7 +1025,8 @@ try {
if(!values)
context->throw_error(AL_INVALID_VALUE, "NULL pointer");

context->throw_error(AL_INVALID_ENUM, "Invalid buffer float-vector property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer float-vector property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand Down Expand Up @@ -1067,7 +1069,8 @@ try {
albuf->mAmbiLayout = layout.value();
return;
}
context->throw_error(AL_INVALID_VALUE, "Invalid unpack ambisonic layout 0x{:04x}", value);
context->throw_error(AL_INVALID_VALUE, "Invalid unpack ambisonic layout {:#04x}",
as_unsigned(value));

case AL_AMBISONIC_SCALING_SOFT:
if(albuf->ref.load(std::memory_order_relaxed) != 0)
Expand All @@ -1078,7 +1081,8 @@ try {
albuf->mAmbiScaling = scaling.value();
return;
}
context->throw_error(AL_INVALID_VALUE, "Invalid unpack ambisonic scaling 0x{:04x}", value);
context->throw_error(AL_INVALID_VALUE, "Invalid unpack ambisonic scaling {:#04x}",
as_unsigned(value));

case AL_UNPACK_AMBISONIC_ORDER_SOFT:
if(value < 1 || value > 14)
Expand All @@ -1087,7 +1091,8 @@ try {
return;
}

context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1105,7 +1110,8 @@ try {
if(LookupBuffer(device, buffer) == nullptr)
context->throw_error(AL_INVALID_NAME, "Invalid buffer ID {}", buffer);

context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-integer property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand Down Expand Up @@ -1154,8 +1160,8 @@ try {
return;
}

context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x{:04x}",
param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer-vector property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand Down Expand Up @@ -1185,7 +1191,8 @@ try {
return;
}

context->throw_error(AL_INVALID_ENUM, "Invalid buffer float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer float property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1205,7 +1212,8 @@ try {
if(!value1 || !value2 || !value3)
context->throw_error(AL_INVALID_VALUE, "NULL pointer");

context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-float property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1232,7 +1240,8 @@ try {
if(!values)
context->throw_error(AL_INVALID_VALUE, "NULL pointer");

context->throw_error(AL_INVALID_ENUM, "Invalid buffer float-vector property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer float-vector property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand Down Expand Up @@ -1303,7 +1312,8 @@ try {
return;
}

context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1323,7 +1333,8 @@ try {
if(!value1 || !value2 || !value3)
context->throw_error(AL_INVALID_VALUE, "NULL pointer");

context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-integer property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand Down Expand Up @@ -1371,8 +1382,8 @@ try {
return;
}

context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x{:04x}",
param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer integer-vector property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1398,7 +1409,7 @@ try {

auto usrfmt = DecomposeUserFormat(format);
if(!usrfmt)
context->throw_error(AL_INVALID_ENUM, "Invalid format 0x{:04x}", format);
context->throw_error(AL_INVALID_ENUM, "Invalid format {:#04x}", as_unsigned(format));

PrepareCallback(context, albuf, freq, usrfmt->channels, usrfmt->type, callback, userptr);
}
Expand Down Expand Up @@ -1431,7 +1442,8 @@ try {
return;
}

context->throw_error(AL_INVALID_ENUM, "Invalid buffer pointer property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer pointer property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand All @@ -1451,7 +1463,8 @@ try {
if(!value1 || !value2 || !value3)
context->throw_error(AL_INVALID_VALUE, "NULL pointer");

context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-pointer property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer 3-pointer property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand Down Expand Up @@ -1479,7 +1492,8 @@ try {
if(!values)
context->throw_error(AL_INVALID_VALUE, "NULL pointer");

context->throw_error(AL_INVALID_ENUM, "Invalid buffer pointer-vector property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid buffer pointer-vector property {:#04x}",
as_unsigned(param));
}
catch(al::base_exception&) {
}
Expand Down Expand Up @@ -1567,7 +1581,7 @@ try {

const auto storage = EaxStorageFromEnum(value);
if(!storage)
context->throw_error(AL_INVALID_ENUM, "Unsupported X-RAM mode 0x{:x}", value);
context->throw_error(AL_INVALID_ENUM, "Unsupported X-RAM mode {:#x}", as_unsigned(value));

if(n == 0)
return AL_TRUE;
Expand Down
49 changes: 28 additions & 21 deletions al/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,33 +175,33 @@ auto LookupFilter(al::Device *device, ALuint id) noexcept -> ALfilter*
/* Null filter parameter handlers */
template<>
void FilterTable<NullFilterTable>::setParami(ALCcontext *context, ALfilter*, ALenum param, int)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<NullFilterTable>::setParamiv(ALCcontext *context, ALfilter*, ALenum param, const int*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<NullFilterTable>::setParamf(ALCcontext *context, ALfilter*, ALenum param, float)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<NullFilterTable>::setParamfv(ALCcontext *context, ALfilter*, ALenum param, const float*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<NullFilterTable>::getParami(ALCcontext *context, const ALfilter*, ALenum param, int*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<NullFilterTable>::getParamiv(ALCcontext *context, const ALfilter*, ALenum param, int*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<NullFilterTable>::getParamf(ALCcontext *context, const ALfilter*, ALenum param, float*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<NullFilterTable>::getParamfv(ALCcontext *context, const ALfilter*, ALenum param, float*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid null filter property {:#04x}", as_unsigned(param)); }

/* Lowpass parameter handlers */
template<>
void FilterTable<LowpassFilterTable>::setParami(ALCcontext *context, ALfilter*, ALenum param, int)
{ context->throw_error(AL_INVALID_ENUM, "Invalid low-pass integer property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid low-pass integer property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<LowpassFilterTable>::setParamiv(ALCcontext *context, ALfilter *filter, ALenum param, const int *values)
{ setParami(context, filter, param, *values); }
Expand All @@ -222,14 +222,15 @@ void FilterTable<LowpassFilterTable>::setParamf(ALCcontext *context, ALfilter *f
filter->GainHF = val;
return;
}
context->throw_error(AL_INVALID_ENUM, "Invalid low-pass float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid low-pass float property {:#04x}",
as_unsigned(param));
}
template<>
void FilterTable<LowpassFilterTable>::setParamfv(ALCcontext *context, ALfilter *filter, ALenum param, const float *vals)
{ setParamf(context, filter, param, *vals); }
template<>
void FilterTable<LowpassFilterTable>::getParami(ALCcontext *context, const ALfilter*, ALenum param, int*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid low-pass integer property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid low-pass integer property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<LowpassFilterTable>::getParamiv(ALCcontext *context, const ALfilter *filter, ALenum param, int *values)
{ getParami(context, filter, param, values); }
Expand All @@ -241,7 +242,8 @@ void FilterTable<LowpassFilterTable>::getParamf(ALCcontext *context, const ALfil
case AL_LOWPASS_GAIN: *val = filter->Gain; return;
case AL_LOWPASS_GAINHF: *val = filter->GainHF; return;
}
context->throw_error(AL_INVALID_ENUM, "Invalid low-pass float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid low-pass float property {:#04x}",
as_unsigned(param));
}
template<>
void FilterTable<LowpassFilterTable>::getParamfv(ALCcontext *context, const ALfilter *filter, ALenum param, float *vals)
Expand All @@ -250,7 +252,7 @@ void FilterTable<LowpassFilterTable>::getParamfv(ALCcontext *context, const ALfi
/* Highpass parameter handlers */
template<>
void FilterTable<HighpassFilterTable>::setParami(ALCcontext *context, ALfilter*, ALenum param, int)
{ context->throw_error(AL_INVALID_ENUM, "Invalid high-pass integer property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid high-pass integer property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<HighpassFilterTable>::setParamiv(ALCcontext *context, ALfilter *filter, ALenum param, const int *values)
{ setParami(context, filter, param, *values); }
Expand All @@ -271,14 +273,15 @@ void FilterTable<HighpassFilterTable>::setParamf(ALCcontext *context, ALfilter *
filter->GainLF = val;
return;
}
context->throw_error(AL_INVALID_ENUM, "Invalid high-pass float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid high-pass float property {:#04x}",
as_unsigned(param));
}
template<>
void FilterTable<HighpassFilterTable>::setParamfv(ALCcontext *context, ALfilter *filter, ALenum param, const float *vals)
{ setParamf(context, filter, param, *vals); }
template<>
void FilterTable<HighpassFilterTable>::getParami(ALCcontext *context, const ALfilter*, ALenum param, int*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid high-pass integer property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid high-pass integer property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<HighpassFilterTable>::getParamiv(ALCcontext *context, const ALfilter *filter, ALenum param, int *values)
{ getParami(context, filter, param, values); }
Expand All @@ -290,7 +293,8 @@ void FilterTable<HighpassFilterTable>::getParamf(ALCcontext *context, const ALfi
case AL_HIGHPASS_GAIN: *val = filter->Gain; return;
case AL_HIGHPASS_GAINLF: *val = filter->GainLF; return;
}
context->throw_error(AL_INVALID_ENUM, "Invalid high-pass float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid high-pass float property {:#04x}",
as_unsigned(param));
}
template<>
void FilterTable<HighpassFilterTable>::getParamfv(ALCcontext *context, const ALfilter *filter, ALenum param, float *vals)
Expand All @@ -299,7 +303,7 @@ void FilterTable<HighpassFilterTable>::getParamfv(ALCcontext *context, const ALf
/* Bandpass parameter handlers */
template<>
void FilterTable<BandpassFilterTable>::setParami(ALCcontext *context, ALfilter*, ALenum param, int)
{ context->throw_error(AL_INVALID_ENUM, "Invalid band-pass integer property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid band-pass integer property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<BandpassFilterTable>::setParamiv(ALCcontext *context, ALfilter *filter, ALenum param, const int *values)
{ setParami(context, filter, param, *values); }
Expand All @@ -326,14 +330,15 @@ void FilterTable<BandpassFilterTable>::setParamf(ALCcontext *context, ALfilter *
filter->GainLF = val;
return;
}
context->throw_error(AL_INVALID_ENUM, "Invalid band-pass float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid band-pass float property {:#04x}",
as_unsigned(param));
}
template<>
void FilterTable<BandpassFilterTable>::setParamfv(ALCcontext *context, ALfilter *filter, ALenum param, const float *vals)
{ setParamf(context, filter, param, *vals); }
template<>
void FilterTable<BandpassFilterTable>::getParami(ALCcontext *context, const ALfilter*, ALenum param, int*)
{ context->throw_error(AL_INVALID_ENUM, "Invalid band-pass integer property 0x{:04x}", param); }
{ context->throw_error(AL_INVALID_ENUM, "Invalid band-pass integer property {:#04x}", as_unsigned(param)); }
template<>
void FilterTable<BandpassFilterTable>::getParamiv(ALCcontext *context, const ALfilter *filter, ALenum param, int *values)
{ getParami(context, filter, param, values); }
Expand All @@ -346,7 +351,8 @@ void FilterTable<BandpassFilterTable>::getParamf(ALCcontext *context, const ALfi
case AL_BANDPASS_GAINHF: *val = filter->GainHF; return;
case AL_BANDPASS_GAINLF: *val = filter->GainLF; return;
}
context->throw_error(AL_INVALID_ENUM, "Invalid band-pass float property 0x{:04x}", param);
context->throw_error(AL_INVALID_ENUM, "Invalid band-pass float property {:#04x}",
as_unsigned(param));
}
template<>
void FilterTable<BandpassFilterTable>::getParamfv(ALCcontext *context, const ALfilter *filter, ALenum param, float *vals)
Expand Down Expand Up @@ -437,7 +443,8 @@ try {
case AL_FILTER_TYPE:
if(!(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS
|| value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS))
context->throw_error(AL_INVALID_VALUE, "Invalid filter type 0x{:04x}", value);
context->throw_error(AL_INVALID_VALUE, "Invalid filter type {:#04x}",
as_unsigned(value));
InitFilterParams(alfilt, value);
return;
}
Expand Down
Loading

0 comments on commit 47712b3

Please sign in to comment.