aboutsummaryrefslogtreecommitdiffstats
path: root/core/ambdec.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/ambdec.cpp')
-rw-r--r--core/ambdec.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/core/ambdec.cpp b/core/ambdec.cpp
index f98e1098..f3fe7566 100644
--- a/core/ambdec.cpp
+++ b/core/ambdec.cpp
@@ -42,8 +42,8 @@ enum class ReaderScope {
HFMatrix,
};
-#ifdef __USE_MINGW_ANSI_STDIO
-[[gnu::format(gnu_printf,2,3)]]
+#ifdef __MINGW32__
+[[gnu::format(__MINGW_PRINTF_FORMAT,2,3)]]
#else
[[gnu::format(printf,2,3)]]
#endif
@@ -53,7 +53,7 @@ std::optional<std::string> make_error(size_t linenum, const char *fmt, ...)
auto &str = ret.emplace();
str.resize(256);
- int printed{std::snprintf(const_cast<char*>(str.data()), str.length(), "Line %zu: ", linenum)};
+ int printed{std::snprintf(str.data(), str.length(), "Line %zu: ", linenum)};
if(printed < 0) printed = 0;
auto plen = std::min(static_cast<size_t>(printed), str.length());
@@ -111,7 +111,7 @@ std::optional<std::string> AmbDecConf::load(const char *fname) noexcept
{
if(command == "add_spkr")
{
- if(speaker_pos == NumSpeakers)
+ if(speaker_pos == Speakers.size())
return make_error(linenum, "Too many speakers specified");
AmbDecConf::SpeakerConf &spkr = Speakers[speaker_pos++];
@@ -145,7 +145,7 @@ std::optional<std::string> AmbDecConf::load(const char *fname) noexcept
}
else if(command == "add_row")
{
- if(pos == NumSpeakers)
+ if(pos == Speakers.size())
return make_error(linenum, "Too many matrix rows specified");
unsigned int mask{ChanMask};
@@ -205,12 +205,13 @@ std::optional<std::string> AmbDecConf::load(const char *fname) noexcept
}
else if(command == "/dec/speakers")
{
- if(NumSpeakers)
+ if(!Speakers.empty())
return make_error(linenum, "Duplicate speakers");
- istr >> NumSpeakers;
- if(!NumSpeakers)
- return make_error(linenum, "Invalid speakers: %zu", NumSpeakers);
- Speakers = std::make_unique<SpeakerConf[]>(NumSpeakers);
+ size_t numspeakers{};
+ istr >> numspeakers;
+ if(!numspeakers)
+ return make_error(linenum, "Invalid speakers: %zu", numspeakers);
+ Speakers.resize(numspeakers);
}
else if(command == "/dec/coeff_scale")
{
@@ -243,22 +244,22 @@ std::optional<std::string> AmbDecConf::load(const char *fname) noexcept
}
else if(command == "/speakers/{")
{
- if(!NumSpeakers)
+ if(Speakers.empty())
return make_error(linenum, "Speakers defined without a count");
scope = ReaderScope::Speakers;
}
else if(command == "/lfmatrix/{" || command == "/hfmatrix/{" || command == "/matrix/{")
{
- if(!NumSpeakers)
+ if(Speakers.empty())
return make_error(linenum, "Matrix defined without a speaker count");
if(!ChanMask)
return make_error(linenum, "Matrix defined without a channel mask");
- if(!Matrix)
+ if(Matrix.empty())
{
- Matrix = std::make_unique<CoeffArray[]>(NumSpeakers * FreqBands);
- LFMatrix = Matrix.get();
- HFMatrix = LFMatrix + NumSpeakers*(FreqBands-1);
+ Matrix.resize(Speakers.size() * FreqBands);
+ LFMatrix = Matrix.data();
+ HFMatrix = LFMatrix + Speakers.size()*(FreqBands-1);
}
if(FreqBands == 1)
@@ -285,8 +286,8 @@ std::optional<std::string> AmbDecConf::load(const char *fname) noexcept
if(!is_at_end(buffer, endpos))
return make_error(linenum, "Extra junk on end: %s", buffer.substr(endpos).c_str());
- if(speaker_pos < NumSpeakers || hfmatrix_pos < NumSpeakers
- || (FreqBands == 2 && lfmatrix_pos < NumSpeakers))
+ if(speaker_pos < Speakers.size() || hfmatrix_pos < Speakers.size()
+ || (FreqBands == 2 && lfmatrix_pos < Speakers.size()))
return make_error(linenum, "Incomplete decoder definition");
if(CoeffScale == AmbDecScale::Unset)
return make_error(linenum, "No coefficient scaling defined");