lib/fmt/RuntimeError: new library
Replacing FormatRuntimeError().
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "AudioParser.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -46,7 +46,7 @@ ParseSampleRate(const char *src, bool mask, const char **endptr_r)
|
||||
if (endptr == src) {
|
||||
throw std::invalid_argument("Failed to parse the sample rate");
|
||||
} else if (!audio_valid_sample_rate(value))
|
||||
throw FormatInvalidArgument("Invalid sample rate: %lu", value);
|
||||
throw FmtInvalidArgument("Invalid sample rate: {}", value);
|
||||
|
||||
*endptr_r = endptr;
|
||||
return value;
|
||||
@@ -100,8 +100,7 @@ ParseSampleFormat(const char *src, bool mask, const char **endptr_r)
|
||||
break;
|
||||
|
||||
default:
|
||||
throw FormatInvalidArgument("Invalid sample format: %lu",
|
||||
value);
|
||||
throw FmtInvalidArgument("Invalid sample format: {}", value);
|
||||
}
|
||||
|
||||
assert(audio_valid_sample_format(sample_format));
|
||||
@@ -125,8 +124,7 @@ ParseChannelCount(const char *src, bool mask, const char **endptr_r)
|
||||
if (endptr == src)
|
||||
throw std::invalid_argument("Failed to parse the channel count");
|
||||
else if (!audio_valid_channel_count(value))
|
||||
throw FormatInvalidArgument("Invalid channel count: %u",
|
||||
value);
|
||||
throw FmtInvalidArgument("Invalid channel count: {}", value);
|
||||
|
||||
*endptr_r = endptr;
|
||||
return value;
|
||||
@@ -152,8 +150,8 @@ ParseAudioFormat(const char *src, bool mask)
|
||||
src = endptr + 1;
|
||||
dest.channels = ParseChannelCount(src, mask, &src);
|
||||
if (*src != 0)
|
||||
throw FormatInvalidArgument("Extra data after channel count: %s",
|
||||
src);
|
||||
throw FmtInvalidArgument("Extra data after channel count: {}",
|
||||
src);
|
||||
|
||||
return dest;
|
||||
}
|
||||
@@ -178,8 +176,8 @@ ParseAudioFormat(const char *src, bool mask)
|
||||
dest.channels = ParseChannelCount(src, mask, &src);
|
||||
|
||||
if (*src != 0)
|
||||
throw FormatInvalidArgument("Extra data after channel count: %s",
|
||||
src);
|
||||
throw FmtInvalidArgument("Extra data after channel count: {}",
|
||||
src);
|
||||
|
||||
assert(mask
|
||||
? dest.IsMaskValid()
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
#include "ChannelsConverter.hxx"
|
||||
#include "PcmChannels.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/AudioFormatFormatter.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
#include "util/SpanCast.hxx"
|
||||
|
||||
#include <cassert>
|
||||
@@ -38,8 +39,8 @@ PcmChannelsConverter::Open(SampleFormat _format,
|
||||
break;
|
||||
|
||||
default:
|
||||
throw FormatRuntimeError("PCM channel conversion for %s is not implemented",
|
||||
sample_format_to_string(_format));
|
||||
throw FmtRuntimeError("PCM channel conversion for {} is not implemented",
|
||||
_format);
|
||||
}
|
||||
|
||||
format = _format;
|
||||
|
||||
@@ -19,30 +19,30 @@
|
||||
|
||||
#include "CheckAudioFormat.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
|
||||
void
|
||||
CheckSampleRate(unsigned long sample_rate)
|
||||
{
|
||||
if (!audio_valid_sample_rate(sample_rate))
|
||||
throw FormatRuntimeError("Invalid sample rate: %lu",
|
||||
sample_rate);
|
||||
throw FmtRuntimeError("Invalid sample rate: {}",
|
||||
sample_rate);
|
||||
}
|
||||
|
||||
void
|
||||
CheckSampleFormat(SampleFormat sample_format)
|
||||
{
|
||||
if (!audio_valid_sample_format(sample_format))
|
||||
throw FormatRuntimeError("Invalid sample format: %u",
|
||||
unsigned(sample_format));
|
||||
throw FmtRuntimeError("Invalid sample format: {}",
|
||||
unsigned(sample_format));
|
||||
}
|
||||
|
||||
void
|
||||
CheckChannelCount(unsigned channels)
|
||||
{
|
||||
if (!audio_valid_channel_count(channels))
|
||||
throw FormatRuntimeError("Invalid channel count: %u",
|
||||
channels);
|
||||
throw FmtRuntimeError("Invalid channel count: {}",
|
||||
channels);
|
||||
}
|
||||
|
||||
AudioFormat
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "config/Option.hxx"
|
||||
#include "config/Block.hxx"
|
||||
#include "config/Param.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
#include "config.h"
|
||||
|
||||
#ifdef ENABLE_LIBSAMPLERATE
|
||||
@@ -122,8 +122,8 @@ GetResamplerConfig(const ConfigData &config, ConfigBlock &buffer)
|
||||
return MigrateResamplerConfig(old_param, buffer);
|
||||
|
||||
if (old_param != nullptr)
|
||||
throw FormatRuntimeError("Cannot use both 'resampler' (line %d) and 'samplerate_converter' (line %d)",
|
||||
block->line, old_param->line);
|
||||
throw FmtRuntimeError("Cannot use both 'resampler' (line {}) and 'samplerate_converter' (line {})",
|
||||
block->line, old_param->line);
|
||||
|
||||
block->SetUsed();
|
||||
return block;
|
||||
@@ -137,8 +137,8 @@ pcm_resampler_global_init(const ConfigData &config)
|
||||
|
||||
const char *plugin_name = block->GetBlockValue("plugin");
|
||||
if (plugin_name == nullptr)
|
||||
throw FormatRuntimeError("'plugin' missing in line %d",
|
||||
block->line);
|
||||
throw FmtRuntimeError("'plugin' missing in line {}",
|
||||
block->line);
|
||||
|
||||
if (strcmp(plugin_name, "internal") == 0) {
|
||||
selected_resampler = SelectedResampler::FALLBACK;
|
||||
@@ -153,8 +153,8 @@ pcm_resampler_global_init(const ConfigData &config)
|
||||
pcm_resample_lsr_global_init(*block);
|
||||
#endif
|
||||
} else {
|
||||
throw FormatRuntimeError("No such resampler plugin: %s",
|
||||
plugin_name);
|
||||
throw FmtRuntimeError("No such resampler plugin: {}",
|
||||
plugin_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
#include "FormatConverter.hxx"
|
||||
#include "PcmFormat.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/AudioFormatFormatter.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -36,9 +37,8 @@ PcmFormatConverter::Open(SampleFormat _src_format, SampleFormat _dest_format)
|
||||
|
||||
case SampleFormat::S8:
|
||||
case SampleFormat::DSD:
|
||||
throw FormatRuntimeError("PCM conversion from %s to %s is not implemented",
|
||||
sample_format_to_string(_src_format),
|
||||
sample_format_to_string(_dest_format));
|
||||
throw FmtRuntimeError("PCM conversion from {} to {} is not implemented",
|
||||
_src_format, _dest_format);
|
||||
|
||||
case SampleFormat::S16:
|
||||
case SampleFormat::S24_P32:
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
#include "LibsamplerateResampler.hxx"
|
||||
#include "config/Block.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
#include "util/ASCII.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "util/SpanCast.hxx"
|
||||
#include "Log.hxx"
|
||||
@@ -69,8 +69,8 @@ pcm_resample_lsr_global_init(const ConfigBlock &block)
|
||||
{
|
||||
const char *converter = block.GetBlockValue("type", "2");
|
||||
if (!lsr_parse_converter(converter))
|
||||
throw FormatRuntimeError("unknown samplerate converter '%s'",
|
||||
converter);
|
||||
throw FmtRuntimeError("unknown samplerate converter '{}'",
|
||||
converter);
|
||||
|
||||
FmtDebug(libsamplerate_domain,
|
||||
"libsamplerate converter '{}'",
|
||||
@@ -93,8 +93,8 @@ LibsampleratePcmResampler::Open(AudioFormat &af, unsigned new_sample_rate)
|
||||
int src_error;
|
||||
state = src_new(lsr_converter, channels, &src_error);
|
||||
if (!state)
|
||||
throw FormatRuntimeError("libsamplerate initialization has failed: %s",
|
||||
src_strerror(src_error));
|
||||
throw FmtRuntimeError("libsamplerate initialization has failed: {}",
|
||||
src_strerror(src_error));
|
||||
|
||||
memset(&data, 0, sizeof(data));
|
||||
|
||||
@@ -138,8 +138,8 @@ LibsampleratePcmResampler::Resample2(std::span<const float> src)
|
||||
|
||||
int result = src_process(state, &data);
|
||||
if (result != 0)
|
||||
throw FormatRuntimeError("libsamplerate has failed: %s",
|
||||
src_strerror(result));
|
||||
throw FmtRuntimeError("libsamplerate has failed: {}",
|
||||
src_strerror(result));
|
||||
|
||||
return {data.data_out, size_t(data.output_frames_gen * channels)};
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "SoxrResampler.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "config/Block.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
@@ -100,18 +100,17 @@ SoxrParsePrecision(unsigned value) {
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter invalid precision : %d [16|20|24|28|32]", value);
|
||||
throw FmtInvalidArgument("soxr converter invalid precision: {} [16|20|24|28|32]",
|
||||
value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static double
|
||||
SoxrParsePhaseResponse(unsigned value) {
|
||||
if (value > 100) {
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter invalid phase_respons : %d (0-100)", value);
|
||||
}
|
||||
if (value > 100)
|
||||
throw FmtInvalidArgument("soxr converter invalid phase_respons : {} (0-100)",
|
||||
value);
|
||||
|
||||
return double(value);
|
||||
}
|
||||
@@ -120,15 +119,13 @@ static double
|
||||
SoxrParsePassbandEnd(const char *svalue) {
|
||||
char *endptr;
|
||||
double value = strtod(svalue, &endptr);
|
||||
if (svalue == endptr || *endptr != 0) {
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter passband_end value not a number: %s", svalue);
|
||||
}
|
||||
if (svalue == endptr || *endptr != 0)
|
||||
throw FmtInvalidArgument("soxr converter passband_end value not a number: {}",
|
||||
svalue);
|
||||
|
||||
if (value < 1 || value > 100) {
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter invalid passband_end : %s (1-100%%)", svalue);
|
||||
}
|
||||
if (value < 1 || value > 100)
|
||||
throw FmtInvalidArgument("soxr converter invalid passband_end: {} (1-100%)",
|
||||
svalue);
|
||||
|
||||
return value / 100.0;
|
||||
}
|
||||
@@ -137,15 +134,13 @@ static double
|
||||
SoxrParseStopbandBegin(const char *svalue) {
|
||||
char *endptr;
|
||||
double value = strtod(svalue, &endptr);
|
||||
if (svalue == endptr || *endptr != 0) {
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter stopband_begin value not a number: %s", svalue);
|
||||
}
|
||||
if (svalue == endptr || *endptr != 0)
|
||||
throw FmtInvalidArgument("soxr converter stopband_begin value not a number: {}",
|
||||
svalue);
|
||||
|
||||
if (value < 100 || value > 199) {
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter invalid stopband_begin : %s (100-150%%)", svalue);
|
||||
}
|
||||
if (value < 100 || value > 199)
|
||||
throw FmtInvalidArgument("soxr converter invalid stopband_begin: {} (100-150%)",
|
||||
svalue);
|
||||
|
||||
return value / 100.0;
|
||||
}
|
||||
@@ -155,14 +150,13 @@ SoxrParseAttenuation(const char *svalue) {
|
||||
char *endptr;
|
||||
double value = strtod(svalue, &endptr);
|
||||
if (svalue == endptr || *endptr != 0) {
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter attenuation value not a number: %s", svalue);
|
||||
throw FmtInvalidArgument("soxr converter attenuation value not a number: {}",
|
||||
svalue);
|
||||
}
|
||||
|
||||
if (value < 0 || value > 30) {
|
||||
throw FormatInvalidArgument(
|
||||
"soxr converter invalid attenuation : %s (0-30dB))", svalue);
|
||||
}
|
||||
if (value < 0 || value > 30)
|
||||
throw FmtInvalidArgument("soxr converter invalid attenuation: {} (0-30dB))",
|
||||
svalue);
|
||||
|
||||
return 1 / std::pow(10, value / 10.0);
|
||||
}
|
||||
@@ -176,8 +170,8 @@ pcm_resample_soxr_global_init(const ConfigBlock &block)
|
||||
|
||||
if (recipe == SOXR_INVALID_RECIPE) {
|
||||
assert(quality_string != nullptr);
|
||||
throw FormatRuntimeError("unknown quality setting '%s' in line %d",
|
||||
quality_string, block.line);
|
||||
throw FmtRuntimeError("unknown quality setting '{}' in line {}",
|
||||
quality_string, block.line);
|
||||
} else if (recipe == SOXR_CUSTOM_RECIPE) {
|
||||
// used to preset possible internal flags, like SOXR_RESET_ON_CLEAR
|
||||
soxr_quality = soxr_quality_spec(SOXR_DEFAULT_RECIPE, 0);
|
||||
@@ -222,8 +216,8 @@ SoxrPcmResampler::Open(AudioFormat &af, unsigned new_sample_rate)
|
||||
af.channels, &e,
|
||||
p_soxr_io, &soxr_quality, &soxr_runtime);
|
||||
if (soxr == nullptr)
|
||||
throw FormatRuntimeError("soxr initialization has failed: %s",
|
||||
e);
|
||||
throw FmtRuntimeError("soxr initialization has failed: {}",
|
||||
e);
|
||||
|
||||
FmtDebug(soxr_domain, "soxr engine '{}'", soxr_engine(soxr));
|
||||
if (soxr_use_custom_recipe)
|
||||
@@ -284,7 +278,7 @@ SoxrPcmResampler::Resample(std::span<const std::byte> src)
|
||||
soxr_error_t e = soxr_process(soxr, src.data(), n_frames, &i_done,
|
||||
output_buffer, o_frames, &o_done);
|
||||
if (e != nullptr)
|
||||
throw FormatRuntimeError("soxr error: %s", e);
|
||||
throw FmtRuntimeError("soxr error: {}", e);
|
||||
|
||||
return { (const std::byte *)output_buffer, o_done * frame_size };
|
||||
}
|
||||
@@ -301,7 +295,7 @@ SoxrPcmResampler::Flush()
|
||||
soxr_error_t e = soxr_process(soxr, nullptr, 0, nullptr,
|
||||
output_buffer, o_frames, &o_done);
|
||||
if (e != nullptr)
|
||||
throw FormatRuntimeError("soxr error: %s", e);
|
||||
throw FmtRuntimeError("soxr error: {}", e);
|
||||
|
||||
if (o_done == 0)
|
||||
/* flush complete */
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#include "Volume.hxx"
|
||||
#include "Silence.hxx"
|
||||
#include "Traits.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "lib/fmt/AudioFormatFormatter.hxx"
|
||||
#include "lib/fmt/RuntimeError.hxx"
|
||||
#include "util/TransformN.hxx"
|
||||
|
||||
#include "Dither.cxx" // including the .cxx file to get inlined templates
|
||||
@@ -154,8 +155,8 @@ PcmVolume::Open(SampleFormat _format, bool allow_convert)
|
||||
|
||||
switch (_format) {
|
||||
case SampleFormat::UNDEFINED:
|
||||
throw FormatRuntimeError("Software volume for %s is not implemented",
|
||||
sample_format_to_string(_format));
|
||||
throw FmtRuntimeError("Software volume for {} is not implemented",
|
||||
_format);
|
||||
|
||||
case SampleFormat::S8:
|
||||
break;
|
||||
|
||||
@@ -30,6 +30,7 @@ pcm_basic = static_library(
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
util_dep,
|
||||
fmt_dep,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user