xiph / LPCNet

Efficient neural speech synthesis
BSD 3-Clause "New" or "Revised" License
1.12k stars 295 forks source link

Windows build fixes #207

Closed xnorpx closed 1 year ago

xnorpx commented 1 year ago

This PR includes 3 changes to allow for Lpcnet Opus WIP work on Windows.

Using the same function name celt_exp2 with what is already in the Opus repo seems to throw the compiler/linker off and we get a cryptic parameter list error message that makes no sense but renaming the function solves this.

Use pragma message as preprocessor directive warning is not supported on MSVC

Include a missing header for MSVC due to use of floor in avx code.

Note that this needs to be refactored for runtime detection of AVX on MSVC.

When compiling a C file with AVX instructions and the /AVX2 compiler flag on MSVC, and including the math.h header, there is a possibility of AVX2-specific math objects being brought in. However, due to the linker's random selection of objects depending on their order, AVX2 instructions may be inadvertently used in code that is not intended to have them. This can lead to crashes on older machines that do not support AVX2 instructions.

xnorpx commented 1 year ago

Tested on Linux and Windows with Opus CMake build.

xnorpx commented 1 year ago

cmake .. -DOPUS_X86_PRESUME_AVX=OFF -DOPUS_FLOAT_APPROX=OFF -DOPUS_FAST_MATH=OFF -DOPUS_BUILD_TESTING=ON

opus\lpcnet\src\vec.h(62,21): error C2059: syntax error: '' [\opus\build\opus.vcxproj]

https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2059?f1url=%3FappId%3DDev16IDEF1%26l%3DEN-US%26k%3Dk(C2059)%26rd%3Dtrue&view=msvc-170

C2059 is raised when a preprocessor symbol name is re-used as an identifier. In the following example, the compiler sees DIGITS.ONE as the number 1, which is not valid as an enum element name:

cmake .. -DOPUS_X86_PRESUME_AVX=OFF -DOPUS_FLOAT_APPROX=ON -DOPUS_FAST_MATH=OFF -DOPUS_BUILD_TESTING=ON

\opus\celt\mathops.h(148,26): error C2084: function 'float celt_exp2(float)' already has a body \opus\build\opus.vcxproj] \opus\lpcnet\src\vec.h(62): message : see previous definition of 'celt_exp2' C:\git\xnorpx\opus\build\opus.vcxproj]

cmake .. -DOPUS_X86_PRESUME_AVX=OFF -DOPUS_FLOAT_APPROX=OFF -DOPUS_FAST_MATH=OFF -DOPUS_BUILD_TESTING=ON

Works

xnorpx commented 1 year ago

merged