kcat / openal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.
Other
2.22k stars 536 forks source link

MSVC 2019 build template error. #1024

Open red-001 opened 3 months ago

red-001 commented 3 months ago

MSVC doesn't like the usage of std::for_each in mastering.cpp, specially the usage in linkChannels and Compressor::process.

Replacing the std::for_each with a c++11 style range based loop fixes the issue. If c++11 support can be assumed, then replacing the legacy std::for_each usage with the new syntax is a potential fix.

kcat commented 3 months ago

What's the error? AFAIK, std::for_each and other algorithms are preferred over (ranged based) for loops. I don't have a problem using it if necessary, but if it's an otherwise easy fix to make std::for_each work, that may be better.

red-001 commented 3 months ago

sure

Build started...
1>------ Build started: Project: build_version, Configuration: RelWithDebInfo x64 ------
2>------ Build started: Project: OpenAL, Configuration: RelWithDebInfo x64 ------
2>mastering.cpp
2>openal-soft\common\alspan.h(140,68): error C2672: 'data': no matching overloaded function found
2>openal-soft\common\alspan.h(140): message : see reference to variable template 'const bool is_valid_container<<lambda_be7e22dd6062f4a97dff432001761bc7> &,float>' being compiled
2>openal-soft\common\alspan.h(140,1): error C2893: Failed to specialize function template 'unknown-type std::data(_Container &)'
2>%msvc_install_path%\VC\Tools\MSVC\14.29.30133\include\xutility(1975): message : see declaration of 'std::data'
2>openal-soft\common\alspan.h(140,1): message : With the following template arguments:
2>openal-soft\common\alspan.h(140,1): message : '_Container=Compressor::process::<lambda_be7e22dd6062f4a97dff432001761bc7>'
2>openal-soft\common\alspan.h(140): error C2062: type 'unknown-type' unexpected
2>openal-soft\core\mastering.cpp(430,59): error C3376: 'al::detail_::is_valid_container': only static data member templates are allowed
2>Done building project "OpenAL.vcxproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
kcat commented 3 months ago

And changing just the

std::for_each(OutBuffer.begin(), OutBuffer.end(), fill_max);

in Compressor::linkChannels and the

std::for_each(output.begin(), output.end(), apply_comp);

in Compressor::process fixes the compile error and the rest all builds properly? And this is using the latest Git master, not the 1.23.1 release, correct?

red-001 commented 3 months ago

yes I'm using latest git master, and that's all I changed.

diff --git a/core/mastering.cpp b/core/mastering.cpp
index b9e8aa50..74fbda67 100644
--- a/core/mastering.cpp
+++ b/core/mastering.cpp
@@ -119,7 +119,8 @@ void Compressor::linkChannels(const uint SamplesToDo,
         std::transform(sideChain.begin(), sideChain.end(), buffer.begin(), sideChain.begin(),
             max_abs);
     };
-    std::for_each(OutBuffer.begin(), OutBuffer.end(), fill_max);
+    for (const FloatBufferLine& e : OutBuffer)
+        fill_max(e);
 }

 /* This calculates the squared crest factor of the control signal for the
@@ -424,7 +425,9 @@ void Compressor::process(const uint SamplesToDo, FloatBufferLine *OutBuffer)
         std::transform(gains.cbegin(), gains.cend(), buffer.cbegin(), buffer.begin(),
             std::multiplies{});
     };
-    std::for_each(output.begin(), output.end(), apply_comp);
+
+    for (const FloatBufferSpan input : output)
+        apply_comp(input);

     const auto delayedGains = al::span{mSideChain}.subspan(SamplesToDo, mLookAhead);
     std::copy(delayedGains.begin(), delayedGains.end(), mSideChain.begin());