From 457eb02894a4586c02e757ce41bd9cf816390a8b Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 08:57:01 -0500 Subject: [PATCH 1/9] Patches for Windows compilation using Visual Studio 2019 These are patches used to allow successful compilation under conda-forge by Ryan Volz (https://github.com/ryanvolz) The feedstock for conda-forge can be found here: https://github.com/conda-forge/m17-cxx-demod-feedstock Patches 0004 through 0010 were applied as refenced in the conda_build_config.yaml and found here: https://github.com/conda-forge/m17-cxx-demod-feedstock/tree/master/recipe All credit for this effort goes to Ryan. Thanks Ryan! --- CMakeLists.txt | 5 ++--- apps/CMakeLists.txt | 4 ++-- apps/m17-demod.cpp | 12 ++++++------ include/m17cxx/ClockRecovery.h | 6 +++--- include/m17cxx/Convolution.h | 3 ++- include/m17cxx/Golay24.h | 9 ++++++--- include/m17cxx/M17Demodulator.h | 2 +- include/m17cxx/M17Framer.h | 4 ++-- include/m17cxx/M17Synchronizer.h | 3 ++- src/CMakeLists.txt | 8 +++++++- tests/CMakeLists.txt | 33 ++++++++++++++++---------------- tests/UtilTest.cpp | 3 ++- 12 files changed, 51 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7319927..37a7b52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(m17cxx DESCRIPTION "M17 Digital Voice modulation and demodulation" LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) # Require out-of-source builds file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH) @@ -24,10 +24,9 @@ message(STATUS "# Checking dependencies") set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -include(FindPkgConfig) include(GNUInstallDirs) -pkg_check_modules(CODEC2 REQUIRED codec2) +find_package(codec2 REQUIRED) set(Boost_USE_STATIC_LIBS FALSE) find_package(Boost COMPONENTS program_options REQUIRED) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index a419e7c..ea00798 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,7 +1,7 @@ add_executable(m17-demod m17-demod.cpp) -target_link_libraries(m17-demod PRIVATE m17cxx ${CODEC2_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(m17-demod PRIVATE m17cxx codec2 Boost::program_options) add_executable(m17-mod m17-mod.cpp) -target_link_libraries(m17-mod PRIVATE m17cxx ${CODEC2_LIBRARIES} ${Boost_LIBRARIES} Threads::Threads) +target_link_libraries(m17-mod PRIVATE m17cxx codec2 Boost::program_options Threads::Threads) install(TARGETS m17-demod m17-mod RUNTIME DESTINATION bin) diff --git a/apps/m17-demod.cpp b/apps/m17-demod.cpp index b26fad8..0dd7649 100644 --- a/apps/m17-demod.cpp +++ b/apps/m17-demod.cpp @@ -190,15 +190,15 @@ bool demodulate_audio(mobilinkd::M17FrameDecoder::audio_buffer_t const& audio, i if (noise_blanker && viterbi_cost > 80) { buf.fill(0); - std::cout.write((const char*)buf.begin(), 320); - std::cout.write((const char*)buf.begin(), 320); + std::cout.write((const char*)buf.data(), 320); + std::cout.write((const char*)buf.data(), 320); } else { - codec2_decode(codec2, buf.begin(), audio.begin() + 2); - std::cout.write((const char*)buf.begin(), 320); - codec2_decode(codec2, buf.begin(), audio.begin() + 10); - std::cout.write((const char*)buf.begin(), 320); + codec2_decode(codec2, buf.data(), audio.data() + 2); + std::cout.write((const char*)buf.data(), 320); + codec2_decode(codec2, buf.data(), audio.data() + 10); + std::cout.write((const char*)buf.data(), 320); } return result; diff --git a/include/m17cxx/ClockRecovery.h b/include/m17cxx/ClockRecovery.h index 611d2b4..37529e6 100644 --- a/include/m17cxx/ClockRecovery.h +++ b/include/m17cxx/ClockRecovery.h @@ -104,11 +104,11 @@ class ClockRecovery int8_t offset = sample_index_ - prev_sample_index_; // When in spec, the clock should drift by less than 1 sample per frame. - if (__builtin_expect(offset >= MAX_OFFSET, 0)) + if (offset >= MAX_OFFSET) [[unlikely]] { offset -= SAMPLES_PER_SYMBOL; } - else if (__builtin_expect(offset <= -MAX_OFFSET, 0)) + else if (offset <= -MAX_OFFSET) [[unlikely]] { offset += SAMPLES_PER_SYMBOL; } @@ -120,7 +120,7 @@ class ClockRecovery { // update_sample_index_() must be called first. - if (__builtin_expect((frame_count_ == 0), 0)) + if (frame_count_ == 0) [[unlikely]] { prev_sample_index_ = sample_index_; offset_ = 0.0; diff --git a/include/m17cxx/Convolution.h b/include/m17cxx/Convolution.h index 4f28b18..122effa 100644 --- a/include/m17cxx/Convolution.h +++ b/include/m17cxx/Convolution.h @@ -2,6 +2,7 @@ #pragma once +#include #include #include @@ -10,7 +11,7 @@ namespace mobilinkd inline constexpr uint32_t convolve_bit(uint32_t poly, uint32_t memory) { - return __builtin_popcount(poly & memory) & 1; + return std::popcount(poly & memory) & 1; } template diff --git a/include/m17cxx/Golay24.h b/include/m17cxx/Golay24.h index 58c2f0f..20ee171 100644 --- a/include/m17cxx/Golay24.h +++ b/include/m17cxx/Golay24.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include #include @@ -85,11 +86,13 @@ constexpr array sort(array array) // static constexpr uint16_t POLY = 0xAE3; constexpr uint16_t POLY = 0xC75; -struct __attribute__((packed)) SyndromeMapEntry +#pragma pack(push, 1) +struct SyndromeMapEntry { uint32_t a{0}; uint16_t b{0}; }; +#pragma pack(pop) /** * Calculate the syndrome of a [23,12] Golay codeword. @@ -110,7 +113,7 @@ constexpr uint32_t syndrome(uint32_t codeword) constexpr bool parity(uint32_t codeword) { - return __builtin_popcount(codeword) & 1; + return std::popcount(codeword) & 1; } constexpr SyndromeMapEntry makeSyndromeMapEntry(uint64_t val) @@ -212,7 +215,7 @@ bool decode(uint32_t input, uint32_t& output) // Apply the correction to the input. output = input ^ correction; // Only test parity for 3-bit errors. - return __builtin_popcount(syndrm) < 3 || !parity(output); + return std::popcount(syndrm) < 3 || !parity(output); } return false; diff --git a/include/m17cxx/M17Demodulator.h b/include/m17cxx/M17Demodulator.h index 3a21f11..4510651 100644 --- a/include/m17cxx/M17Demodulator.h +++ b/include/m17cxx/M17Demodulator.h @@ -556,7 +556,7 @@ void M17Demodulator::operator()(const FloatType input) // We need to pump a few ms of data through on startup to initialize // the demodulator. - if (__builtin_expect((initializing), 0)) + if (initializing) [[unlikely]] { --initializing; initialize(input); diff --git a/include/m17cxx/M17Framer.h b/include/m17cxx/M17Framer.h index c87fa04..c80365e 100644 --- a/include/m17cxx/M17Framer.h +++ b/include/m17cxx/M17Framer.h @@ -32,7 +32,7 @@ struct M17Framer if (index_ == N) { index_ = 0; - *result = buffer_.begin(); + *result = buffer_.data(); return N; } return 0; @@ -46,7 +46,7 @@ struct M17Framer if (index_ == N) { index_ = 0; - *result = buffer_.begin(); + *result = buffer_.data(); return N; } return 0; diff --git a/include/m17cxx/M17Synchronizer.h b/include/m17cxx/M17Synchronizer.h index 1861ed3..422fd3a 100644 --- a/include/m17cxx/M17Synchronizer.h +++ b/include/m17cxx/M17Synchronizer.h @@ -2,6 +2,7 @@ #pragma once +#include #include namespace mobilinkd @@ -24,7 +25,7 @@ struct M17Synchronizer buffer_ = ((buffer_ << 2) | bits) & 0xFFFF; auto tmp = buffer_ ^ expected_; - return __builtin_popcount(tmp) <= allowable_errors_; + return std::popcount(tmp) <= allowable_errors_; } void reset() { buffer_ = 0; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c402b40..12a375d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,13 @@ target_include_directories(m17cxx INTERFACE $ ) -target_compile_features(m17cxx INTERFACE cxx_std_17) +target_compile_features(m17cxx INTERFACE cxx_std_20) + +if(MSVC) + # specify standards-conformance mode + target_compile_options(m17cxx INTERFACE /permissive-) + target_compile_definitions(m17cxx INTERFACE _USE_MATH_DEFINES) +endif() source_group( TREE "${PROJECT_SOURCE_DIR}/include" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d188b05..a2dc698 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,4 @@ include(GoogleTest) -pkg_check_modules(CODEC2 REQUIRED codec2) include_directories ( ${TEST_SOURCE_DIR} @@ -7,65 +6,65 @@ include_directories ( ) add_executable (ConvolutionTest ConvolutionTest.cpp) -target_link_libraries(ConvolutionTest m17cxx gtest pthread) +target_link_libraries(ConvolutionTest m17cxx GTest::GTest) gtest_add_tests(ConvolutionTest "" AUTO) add_executable (M17FramerTest M17FramerTest.cpp) -target_link_libraries(M17FramerTest m17cxx gtest pthread) +target_link_libraries(M17FramerTest m17cxx GTest::Gtest) gtest_add_tests(M17FramerTest "" AUTO) add_executable (TrellisTest TrellisTest.cpp) -target_link_libraries(TrellisTest m17cxx gtest pthread) +target_link_libraries(TrellisTest m17cxx GTest::Gtest) gtest_add_tests(TrellisTest "" AUTO) add_executable (ViterbiTest ViterbiTest.cpp) -target_link_libraries(ViterbiTest m17cxx gtest pthread) +target_link_libraries(ViterbiTest m17cxx GTest::Gtest) gtest_add_tests(ViterbiTest "" AUTO) add_executable (Golay24Test Golay24Test.cpp) -target_link_libraries(Golay24Test m17cxx gtest pthread) +target_link_libraries(Golay24Test m17cxx GTest::Gtest) gtest_add_tests(Golay24Test "" AUTO) add_executable (CRC16Test CRC16Test.cpp) -target_link_libraries(CRC16Test m17cxx gtest pthread) +target_link_libraries(CRC16Test m17cxx GTest::Gtest) gtest_add_tests(CRC16Test "" AUTO) add_executable (M17RandomizerTest M17RandomizerTest.cpp) -target_link_libraries(M17RandomizerTest m17cxx gtest pthread) +target_link_libraries(M17RandomizerTest m17cxx GTest::Gtest) gtest_add_tests(M17RandomizerTest "" AUTO) add_executable (PolynomialInterleaverTest PolynomialInterleaverTest.cpp) -target_link_libraries(PolynomialInterleaverTest m17cxx gtest pthread) +target_link_libraries(PolynomialInterleaverTest m17cxx GTest::Gtest) gtest_add_tests(PolynomialInterleaverTest "" AUTO) add_executable (M17ModulatorTest M17ModulatorTest.cpp) -target_link_libraries(M17ModulatorTest m17cxx gtest pthread codec2) +target_link_libraries(M17ModulatorTest m17cxx GTest::Gtest codec2) gtest_add_tests(M17ModulatorTest "" AUTO) add_executable (UtilTest UtilTest.cpp) -target_link_libraries(UtilTest m17cxx gtest pthread) +target_link_libraries(UtilTest m17cxx GTest::Gtest) gtest_add_tests(UtilTest "" AUTO) add_executable (LinkSetupFrameTest LinkSetupFrameTest.cpp) -target_link_libraries(LinkSetupFrameTest m17cxx gtest pthread) +target_link_libraries(LinkSetupFrameTest m17cxx GTest::Gtest) gtest_add_tests(LinkSetupFrameTest "" AUTO) add_executable (SlidingDFTTest SlidingDFTTest.cpp) -target_link_libraries(SlidingDFTTest m17cxx gtest pthread) +target_link_libraries(SlidingDFTTest m17cxx GTest::Gtest) gtest_add_tests(SlidingDFTTest "" AUTO) add_executable (DataCarrierDetectTest DataCarrierDetectTest.cpp) -target_link_libraries(DataCarrierDetectTest m17cxx gtest pthread) +target_link_libraries(DataCarrierDetectTest m17cxx GTest::Gtest) gtest_add_tests(DataCarrierDetectTest "" AUTO) add_executable (ClockRecoveryTest ClockRecoveryTest.cpp) -target_link_libraries(ClockRecoveryTest m17cxx gtest pthread) +target_link_libraries(ClockRecoveryTest m17cxx GTest::Gtest) gtest_add_tests(ClockRecoveryTest "" AUTO) add_executable (FreqDevEstimatorTest FreqDevEstimatorTest.cpp) -target_link_libraries(FreqDevEstimatorTest m17cxx gtest pthread) +target_link_libraries(FreqDevEstimatorTest m17cxx GTest::Gtest) gtest_add_tests(FreqDevEstimatorTest "" AUTO) add_executable (CorrelatorTest CorrelatorTest.cpp) -target_link_libraries(CorrelatorTest m17cxx gtest pthread) +target_link_libraries(CorrelatorTest m17cxx GTest::Gtest) gtest_add_tests(CorrelatorTest "" AUTO) diff --git a/tests/UtilTest.cpp b/tests/UtilTest.cpp index 4adebe2..cfddcdf 100644 --- a/tests/UtilTest.cpp +++ b/tests/UtilTest.cpp @@ -2,6 +2,7 @@ #include +#include #include int main(int argc, char **argv) { @@ -210,7 +211,7 @@ TEST_F(UtilTest, PRBS9) uint16_t lfsr = 0x100; for (size_t i = 0; i != 511; ++i) { - lfsr = ((__builtin_popcount(lfsr & 0x11) & 1) << 8) | (lfsr >> 1); + lfsr = ((std::popcount(lfsr & 0x11u) & 1) << 8) | (lfsr >> 1); bool p = (lfsr & 0x100) == 0x100; bool n = prbs.generate(); EXPECT_EQ(p,n) << "i = " << i; From 9e8d24d9b48b7dda5171270908d98acea8af5325 Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 09:49:08 -0500 Subject: [PATCH 2/9] fixed typo for GTest::GTest --- tests/CMakeLists.txt | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2dc698..ff79e6d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,61 +10,61 @@ target_link_libraries(ConvolutionTest m17cxx GTest::GTest) gtest_add_tests(ConvolutionTest "" AUTO) add_executable (M17FramerTest M17FramerTest.cpp) -target_link_libraries(M17FramerTest m17cxx GTest::Gtest) +target_link_libraries(M17FramerTest m17cxx GTest::GTest) gtest_add_tests(M17FramerTest "" AUTO) add_executable (TrellisTest TrellisTest.cpp) -target_link_libraries(TrellisTest m17cxx GTest::Gtest) +target_link_libraries(TrellisTest m17cxx GTest::GTest) gtest_add_tests(TrellisTest "" AUTO) add_executable (ViterbiTest ViterbiTest.cpp) -target_link_libraries(ViterbiTest m17cxx GTest::Gtest) +target_link_libraries(ViterbiTest m17cxx GTest::GTest) gtest_add_tests(ViterbiTest "" AUTO) add_executable (Golay24Test Golay24Test.cpp) -target_link_libraries(Golay24Test m17cxx GTest::Gtest) +target_link_libraries(Golay24Test m17cxx GTest::GTest) gtest_add_tests(Golay24Test "" AUTO) add_executable (CRC16Test CRC16Test.cpp) -target_link_libraries(CRC16Test m17cxx GTest::Gtest) +target_link_libraries(CRC16Test m17cxx GTest::GTest) gtest_add_tests(CRC16Test "" AUTO) add_executable (M17RandomizerTest M17RandomizerTest.cpp) -target_link_libraries(M17RandomizerTest m17cxx GTest::Gtest) +target_link_libraries(M17RandomizerTest m17cxx GTest::GTest) gtest_add_tests(M17RandomizerTest "" AUTO) add_executable (PolynomialInterleaverTest PolynomialInterleaverTest.cpp) -target_link_libraries(PolynomialInterleaverTest m17cxx GTest::Gtest) +target_link_libraries(PolynomialInterleaverTest m17cxx GTest::GTest) gtest_add_tests(PolynomialInterleaverTest "" AUTO) add_executable (M17ModulatorTest M17ModulatorTest.cpp) -target_link_libraries(M17ModulatorTest m17cxx GTest::Gtest codec2) +target_link_libraries(M17ModulatorTest m17cxx GTest::GTest codec2) gtest_add_tests(M17ModulatorTest "" AUTO) add_executable (UtilTest UtilTest.cpp) -target_link_libraries(UtilTest m17cxx GTest::Gtest) +target_link_libraries(UtilTest m17cxx GTest::GTest) gtest_add_tests(UtilTest "" AUTO) add_executable (LinkSetupFrameTest LinkSetupFrameTest.cpp) -target_link_libraries(LinkSetupFrameTest m17cxx GTest::Gtest) +target_link_libraries(LinkSetupFrameTest m17cxx GTest::GTest) gtest_add_tests(LinkSetupFrameTest "" AUTO) add_executable (SlidingDFTTest SlidingDFTTest.cpp) -target_link_libraries(SlidingDFTTest m17cxx GTest::Gtest) +target_link_libraries(SlidingDFTTest m17cxx GTest::GTest) gtest_add_tests(SlidingDFTTest "" AUTO) add_executable (DataCarrierDetectTest DataCarrierDetectTest.cpp) -target_link_libraries(DataCarrierDetectTest m17cxx GTest::Gtest) +target_link_libraries(DataCarrierDetectTest m17cxx GTest::GTest) gtest_add_tests(DataCarrierDetectTest "" AUTO) add_executable (ClockRecoveryTest ClockRecoveryTest.cpp) -target_link_libraries(ClockRecoveryTest m17cxx GTest::Gtest) +target_link_libraries(ClockRecoveryTest m17cxx GTest::GTest) gtest_add_tests(ClockRecoveryTest "" AUTO) add_executable (FreqDevEstimatorTest FreqDevEstimatorTest.cpp) -target_link_libraries(FreqDevEstimatorTest m17cxx GTest::Gtest) +target_link_libraries(FreqDevEstimatorTest m17cxx GTest::GTest) gtest_add_tests(FreqDevEstimatorTest "" AUTO) add_executable (CorrelatorTest CorrelatorTest.cpp) -target_link_libraries(CorrelatorTest m17cxx GTest::Gtest) +target_link_libraries(CorrelatorTest m17cxx GTest::GTest) gtest_add_tests(CorrelatorTest "" AUTO) From 5dfde4709d7992feda4c29e15d7861aa6dec6e85 Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 10:08:22 -0500 Subject: [PATCH 3/9] Applies more patches for Windows compiling Missed the 0001 and 0002 patches provided by N1AI (https://github.com/n1ai) Patch 0003 adds some items that are later removed, so that patch is deliberately ignored. Part of the confusion is the conda-forge recipe was forked from N1AI and not the upstream repo. --- apps/m17-mod.cpp | 9 ++++----- include/m17cxx/Fsk4Demod.h | 7 +++---- include/m17cxx/M17Demodulator.h | 8 ++++---- include/m17cxx/M17Modulator.h | 5 ++--- include/m17cxx/M17Randomizer.h | 5 ++--- include/m17cxx/Trellis.h | 9 ++++----- include/m17cxx/Util.h | 6 +++--- 7 files changed, 22 insertions(+), 27 deletions(-) diff --git a/apps/m17-mod.cpp b/apps/m17-mod.cpp index eb16910..2c1bd43 100644 --- a/apps/m17-mod.cpp +++ b/apps/m17-mod.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -34,12 +33,12 @@ #include // Generated using scikit-commpy -const auto rrc_taps = std::experimental::make_array( +const auto rrc_taps = std::array{ 0.0029364388513841593, 0.0031468394550958484, 0.002699564567597445, 0.001661182944400927, 0.00023319405581230247, -0.0012851320781224025, -0.0025577136087664687, -0.0032843366522956313, -0.0032697038088887226, -0.0024733964729590865, -0.0010285696910973807, 0.0007766690889758685, 0.002553421969211845, 0.0038920145144327816, 0.004451886520053017, 0.00404219185231544, 0.002674727068399207, 0.0005756567993179152, -0.0018493784971116507, -0.004092346891623224, -0.005648131453822014, -0.006126925416243605, -0.005349511529163396, -0.003403189203405097, -0.0006430502751187517, 0.002365929161655135, 0.004957956568090113, 0.006506845894531803, 0.006569574194782443, 0.0050017573119839134, 0.002017321931508163, -0.0018256054303579805, -0.00571615173291049, -0.008746639552588416, -0.010105075751866371, -0.009265784007800534, -0.006136551625729697, -0.001125978562075172, 0.004891777252042491, 0.01071805138282269, 0.01505751553351295, 0.01679337935001369, 0.015256245142156299, 0.01042830577908502, 0.003031522725559901, -0.0055333532968188165, -0.013403099825723372, -0.018598682349642525, -0.01944761739590459, -0.015005271935951746, -0.0053887880354343935, 0.008056525910253532, 0.022816244158307273, 0.035513467692208076, 0.04244131815783876, 0.04025481153629372, 0.02671818654865632, 0.0013810216516704976, -0.03394615682795165, -0.07502635967975885, -0.11540977897637611, -0.14703962203941534, -0.16119995609538576, -0.14969512896336504, -0.10610329539459686, -0.026921412469634916, 0.08757875030779196, 0.23293327870303457, 0.4006012210123992, 0.5786324696325503, 0.7528286479934068, 0.908262741447522, 1.0309661131633199, 1.1095611856548013, 1.1366197723675815, 1.1095611856548013, 1.0309661131633199, 0.908262741447522, 0.7528286479934068, 0.5786324696325503, 0.4006012210123992, 0.23293327870303457, 0.08757875030779196, -0.026921412469634916, -0.10610329539459686, -0.14969512896336504, -0.16119995609538576, -0.14703962203941534, -0.11540977897637611, -0.07502635967975885, -0.03394615682795165, 0.0013810216516704976, 0.02671818654865632, 0.04025481153629372, 0.04244131815783876, 0.035513467692208076, 0.022816244158307273, 0.008056525910253532, -0.0053887880354343935, -0.015005271935951746, -0.01944761739590459, -0.018598682349642525, -0.013403099825723372, -0.0055333532968188165, 0.003031522725559901, 0.01042830577908502, 0.015256245142156299, 0.01679337935001369, 0.01505751553351295, 0.01071805138282269, 0.004891777252042491, -0.001125978562075172, -0.006136551625729697, -0.009265784007800534, -0.010105075751866371, -0.008746639552588416, -0.00571615173291049, -0.0018256054303579805, 0.002017321931508163, 0.0050017573119839134, 0.006569574194782443, 0.006506845894531803, 0.004957956568090113, 0.002365929161655135, -0.0006430502751187517, -0.003403189203405097, -0.005349511529163396, -0.006126925416243605, -0.005648131453822014, -0.004092346891623224, -0.0018493784971116507, 0.0005756567993179152, 0.002674727068399207, 0.00404219185231544, 0.004451886520053017, 0.0038920145144327816, 0.002553421969211845, 0.0007766690889758685, -0.0010285696910973807, -0.0024733964729590865, -0.0032697038088887226, -0.0032843366522956313, -0.0025577136087664687, -0.0012851320781224025, 0.00023319405581230247, 0.001661182944400927, 0.002699564567597445, 0.0031468394550958484, 0.0029364388513841593, 0.0 -); +}; -const auto evm_b = std::experimental::make_array(0.02008337, 0.04016673, 0.02008337); -const auto evm_a = std::experimental::make_array(1.0, -1.56101808, 0.64135154); +const auto evm_b = std::array{0.02008337, 0.04016673, 0.02008337}; +const auto evm_a = std::array{1.0, -1.56101808, 0.64135154}; const char VERSION[] = "2.2"; diff --git a/include/m17cxx/Fsk4Demod.h b/include/m17cxx/Fsk4Demod.h index 88892d2..b58d6dc 100644 --- a/include/m17cxx/Fsk4Demod.h +++ b/include/m17cxx/Fsk4Demod.h @@ -9,7 +9,6 @@ #include "SymbolEvm.h" #include -#include #include #include @@ -18,7 +17,7 @@ namespace mobilinkd namespace detail { -inline const auto rrc_taps = std::experimental::make_array( +inline const auto rrc_taps = std::array( -0.009265784007800534, -0.006136551625729697, -0.001125978562075172, 0.004891777252042491, 0.01071805138282269, 0.01505751553351295, 0.01679337935001369, 0.015256245142156299, 0.01042830577908502, 0.003031522725559901, -0.0055333532968188165, -0.013403099825723372, @@ -41,8 +40,8 @@ inline const auto rrc_taps = std::experimental::make_array( -0.001125978562075172, -0.006136551625729697, -0.009265784007800534 ); -inline const auto evm_b = std::experimental::make_array(0.02008337, 0.04016673, 0.02008337); -inline const auto evm_a = std::experimental::make_array(1.0, -1.56101808, 0.64135154); +inline const auto evm_b = std::array(0.02008337, 0.04016673, 0.02008337); +inline const auto evm_a = std::array(1.0, -1.56101808, 0.64135154); } // detail struct Fsk4Demod diff --git a/include/m17cxx/M17Demodulator.h b/include/m17cxx/M17Demodulator.h index 4510651..16b12a1 100644 --- a/include/m17cxx/M17Demodulator.h +++ b/include/m17cxx/M17Demodulator.h @@ -30,7 +30,7 @@ struct Taps template <> struct Taps { - static constexpr auto rrc_taps = std::experimental::make_array( + static constexpr auto rrc_taps = std::array{ 0.0029364388513841593, 0.0031468394550958484, 0.002699564567597445, 0.001661182944400927, 0.00023319405581230247, -0.0012851320781224025, -0.0025577136087664687, -0.0032843366522956313, -0.0032697038088887226, -0.0024733964729590865, -0.0010285696910973807, 0.0007766690889758685, @@ -69,13 +69,13 @@ struct Taps -0.0032697038088887226, -0.0032843366522956313, -0.0025577136087664687, -0.0012851320781224025, 0.00023319405581230247, 0.001661182944400927, 0.002699564567597445, 0.0031468394550958484, 0.0029364388513841593, 0.0 - ); + }; }; template <> struct Taps { - static constexpr auto rrc_taps = std::experimental::make_array( + static constexpr auto rrc_taps = std::array{ 0.0029364388513841593, 0.0031468394550958484, 0.002699564567597445, 0.001661182944400927, 0.00023319405581230247, -0.0012851320781224025, -0.0025577136087664687, -0.0032843366522956313, -0.0032697038088887226, -0.0024733964729590865, -0.0010285696910973807, 0.0007766690889758685, @@ -114,7 +114,7 @@ struct Taps -0.0032697038088887226, -0.0032843366522956313, -0.0025577136087664687, -0.0012851320781224025, 0.00023319405581230247, 0.001661182944400927, 0.002699564567597445, 0.0031468394550958484, 0.0029364388513841593, 0.0 - ); + }; }; } // detail diff --git a/include/m17cxx/M17Modulator.h b/include/m17cxx/M17Modulator.h index 617a4fe..a925722 100644 --- a/include/m17cxx/M17Modulator.h +++ b/include/m17cxx/M17Modulator.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -594,7 +593,7 @@ public: static baseband_t symbols_to_baseband(const symbols_t& symbols) { // Generated using scikit-commpy - static const auto rrc_taps = std::experimental::make_array( + static const auto rrc_taps = std::array{ -0.009265784007800534, -0.006136551625729697, -0.001125978562075172, 0.004891777252042491, 0.01071805138282269, 0.01505751553351295, 0.01679337935001369, 0.015256245142156299, 0.01042830577908502, 0.003031522725559901, -0.0055333532968188165, -0.013403099825723372, @@ -615,7 +614,7 @@ public: -0.0055333532968188165, 0.003031522725559901, 0.01042830577908502, 0.015256245142156299, 0.01679337935001369, 0.01505751553351295, 0.01071805138282269, 0.004891777252042491, -0.001125978562075172, -0.006136551625729697, -0.009265784007800534 - ); + }; static BaseFirFilter::value> rrc = makeFirFilter(rrc_taps); std::array baseband; diff --git a/include/m17cxx/M17Randomizer.h b/include/m17cxx/M17Randomizer.h index b9a87fa..e7c41e9 100644 --- a/include/m17cxx/M17Randomizer.h +++ b/include/m17cxx/M17Randomizer.h @@ -3,7 +3,6 @@ #pragma once #include -#include #include #include @@ -14,13 +13,13 @@ namespace detail { // M17 randomization matrix. -inline auto DC = std::experimental::make_array( +inline auto DC = std::array{ 0xd6, 0xb5, 0xe2, 0x30, 0x82, 0xFF, 0x84, 0x62, 0xba, 0x4e, 0x96, 0x90, 0xd8, 0x98, 0xdd, 0x5d, 0x0c, 0xc8, 0x52, 0x43, 0x91, 0x1d, 0xf8, 0x6e, 0x68, 0x2F, 0x35, 0xda, 0x14, 0xea, 0xcd, 0x76, 0x19, 0x8d, 0xd5, 0x80, 0xd1, 0x33, 0x87, 0x13, - 0x57, 0x18, 0x2d, 0x29, 0x78, 0xc3); + 0x57, 0x18, 0x2d, 0x29, 0x78, 0xc3}; } template diff --git a/include/m17cxx/Trellis.h b/include/m17cxx/Trellis.h index c530b79..172bb92 100644 --- a/include/m17cxx/Trellis.h +++ b/include/m17cxx/Trellis.h @@ -8,7 +8,6 @@ #include "Convolution.h" #include -#include #include #include @@ -31,14 +30,14 @@ inline constexpr std::array make_p1() { inline constexpr auto P1 = make_p1(); /// Puncture matrix for audio frames. Rate 6/11. -inline constexpr auto P2 = std::experimental::make_array( +inline constexpr auto P2 = std::array{ 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 0); + 1, 1, 1, 1, 1, 0}; /// Puncture matrix for packet frames (7/8). -inline constexpr auto P3 = std::experimental::make_array( - 1, 1, 1, 1, 1, 1, 1, 0); +inline constexpr auto P3 = std::array{ + 1, 1, 1, 1, 1, 1, 1, 0}; /** * Convert an integer value to an array of bits, with the diff --git a/include/m17cxx/Util.h b/include/m17cxx/Util.h index ef9a05d..7aca344 100644 --- a/include/m17cxx/Util.h +++ b/include/m17cxx/Util.h @@ -271,10 +271,10 @@ size_t puncture_bytes(const std::array& in, template constexpr T to_int(uint8_t v) { - constexpr auto MAX_INPUT = (1 << (n - 1)); - constexpr auto NEGATIVE_OFFSET = std::numeric_limits::type>::max() - (MAX_INPUT - 1); + constexpr auto MAX_LOCAL_INPUT = (1 << (n - 1)); + constexpr auto NEGATIVE_OFFSET = std::numeric_limits::type>::max() - (MAX_LOCAL_INPUT - 1); T r = v & (1 << (n - 1)) ? NEGATIVE_OFFSET : 0; - return r + (v & (MAX_INPUT - 1)); + return r + (v & (MAX_LOCAL_INPUT - 1)); } template From e908f1dc5c5e51d6d168698165583a7af77b361c Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 10:30:16 -0500 Subject: [PATCH 4/9] build instructions for Anaconda/Windows --- windows_conda_build.bat | 29 +++++++++++++++++++++++++++++ windows_conda_build.md | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 windows_conda_build.bat create mode 100644 windows_conda_build.md diff --git a/windows_conda_build.bat b/windows_conda_build.bat new file mode 100644 index 0000000..8da0df7 --- /dev/null +++ b/windows_conda_build.bat @@ -0,0 +1,29 @@ +setlocal EnableDelayedExpansion +@echo on + +:: Set number of CPUs to use for build +set CPU_COUNT=3 + +:: Make a build folder and change to it +mkdir build +cd build + +:: configure +cmake -G "Ninja" ^ + -DCMAKE_BUILD_TYPE:STRING=Release ^ + -DCMAKE_INSTALL_PREFIX:PATH="%LIBRARY_PREFIX%" ^ + -DCMAKE_PREFIX_PATH:PATH="%LIBRARY_PREFIX%" ^ + .. +if errorlevel 1 exit /B 1 + +:: build +cmake --build . --config Release -- -j%CPU_COUNT% +if errorlevel 1 exit /B 1 + +:: install +cmake --build . --config Release --target install +if errorlevel 1 exit /B 1 + +:: test +ctest --build-config Release --output-on-failure --timeout 120 -j%CPU_COUNT% +if errorlevel 1 exit /B 1 diff --git a/windows_conda_build.md b/windows_conda_build.md new file mode 100644 index 0000000..fc187db --- /dev/null +++ b/windows_conda_build.md @@ -0,0 +1,17 @@ +These are the steps used to locally build under Anaconda for Windows + +- Installed VS 2019 Community Edition +- Installed Miniconda x64 for Windows +- Forked and locally cloned the original m17-cxx-demod repo +- Manually applied patches 0001, 0002, 0004 through 0010 +- In a fresh Miniconda... + conda config --add channels conda-forge + conda create -n M17 vs2019_win-64 cmake ninja pkg-config boost-cpp gtest gmock gtest libcodec2 + conda activate M17 +- Copied https://github.com/conda-forge/m17-cxx-demod-feedstock/blob/master/recipe/bld.bat into my repo branch +- Modified the bld.bat + changed the exit 1 commands to exit /B 1 (so the command shell stayed open) + added set CPU_COUNT=3 +- renamed bld.bat to windows_conda_build.bat +- Executed batch file - and it works! tests passed, and can run the apps + From c6ba48ec12217ff0b1f2b4e59594dafbfa3f5afe Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 17:22:17 -0500 Subject: [PATCH 5/9] cleans up notes for Windows build under Conda --- README.md | 15 +++++++++++++++ windows_conda_build.bat => win_build.bat | 7 +++++++ windows_conda_build.md | 17 ----------------- 3 files changed, 22 insertions(+), 17 deletions(-) rename windows_conda_build.bat => win_build.bat (85%) delete mode 100644 windows_conda_build.md diff --git a/README.md b/README.md index 426053b..157c57a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,21 @@ It also requires a modern C++17 compiler (GCC 8 minimum). make test sudo make install +## Build Steps for local building under Anaconda for Windows + +### Prequisites +- Microsoft Visual Studio 2019 +- Miniconda (or Anaconda) x64 for Windows + +### From a clean Conda environment + ``` + conda config --add channels conda-forge + conda create -n M17 vs2019_win-64 cmake ninja pkg-config boost-cpp gtest gmock gtest libcodec2 + conda activate M17 + ``` + +### From the top level of the m17-cxx-demod repo, execute win_build.bat + ## Running This program was designed to be used with RTL-SDR, specifically rtl-fm. diff --git a/windows_conda_build.bat b/win_build.bat similarity index 85% rename from windows_conda_build.bat rename to win_build.bat index 8da0df7..3346e2b 100644 --- a/windows_conda_build.bat +++ b/win_build.bat @@ -1,3 +1,10 @@ +:: +:: win_build.bat +:: +:: Batch file to locally build under Windows using Conda +:: +:: See README.md for details +:: setlocal EnableDelayedExpansion @echo on diff --git a/windows_conda_build.md b/windows_conda_build.md deleted file mode 100644 index fc187db..0000000 --- a/windows_conda_build.md +++ /dev/null @@ -1,17 +0,0 @@ -These are the steps used to locally build under Anaconda for Windows - -- Installed VS 2019 Community Edition -- Installed Miniconda x64 for Windows -- Forked and locally cloned the original m17-cxx-demod repo -- Manually applied patches 0001, 0002, 0004 through 0010 -- In a fresh Miniconda... - conda config --add channels conda-forge - conda create -n M17 vs2019_win-64 cmake ninja pkg-config boost-cpp gtest gmock gtest libcodec2 - conda activate M17 -- Copied https://github.com/conda-forge/m17-cxx-demod-feedstock/blob/master/recipe/bld.bat into my repo branch -- Modified the bld.bat - changed the exit 1 commands to exit /B 1 (so the command shell stayed open) - added set CPU_COUNT=3 -- renamed bld.bat to windows_conda_build.bat -- Executed batch file - and it works! tests passed, and can run the apps - From 99ff332956b52d3f6b0def6b2bfb5d07ba851608 Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 17:25:57 -0500 Subject: [PATCH 6/9] clean up format --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 157c57a..683b4d1 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,12 @@ It also requires a modern C++17 compiler (GCC 8 minimum). - Miniconda (or Anaconda) x64 for Windows ### From a clean Conda environment - ``` + conda config --add channels conda-forge conda create -n M17 vs2019_win-64 cmake ninja pkg-config boost-cpp gtest gmock gtest libcodec2 conda activate M17 - ``` - -### From the top level of the m17-cxx-demod repo, execute win_build.bat + +### And then from the top level of the m17-cxx-demod repo, execute win_build.bat ## Running From a003486c859f092112f4bc49d2d38e438c309dd9 Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 17:27:29 -0500 Subject: [PATCH 7/9] fixed blocking --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 683b4d1..7abb54b 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,11 @@ It also requires a modern C++17 compiler (GCC 8 minimum). - Miniconda (or Anaconda) x64 for Windows ### From a clean Conda environment - + conda config --add channels conda-forge conda create -n M17 vs2019_win-64 cmake ninja pkg-config boost-cpp gtest gmock gtest libcodec2 conda activate M17 - + ### And then from the top level of the m17-cxx-demod repo, execute win_build.bat ## Running From f747403dc4d6c0e88b2cb1d1b6b51dd0a98f8924 Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Sat, 12 Mar 2022 22:14:20 -0500 Subject: [PATCH 8/9] conditionally links pthread (excludes for WIN32) --- tests/CMakeLists.txt | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ff79e6d..ce1ec95 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,66 +5,72 @@ include_directories ( .. ) +if(WIN32) + set(PTHREAD "") +else() + set(PTHREAD "pthread") +endif(WIN32) + add_executable (ConvolutionTest ConvolutionTest.cpp) -target_link_libraries(ConvolutionTest m17cxx GTest::GTest) +target_link_libraries(ConvolutionTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(ConvolutionTest "" AUTO) add_executable (M17FramerTest M17FramerTest.cpp) -target_link_libraries(M17FramerTest m17cxx GTest::GTest) +target_link_libraries(M17FramerTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(M17FramerTest "" AUTO) add_executable (TrellisTest TrellisTest.cpp) -target_link_libraries(TrellisTest m17cxx GTest::GTest) +target_link_libraries(TrellisTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(TrellisTest "" AUTO) add_executable (ViterbiTest ViterbiTest.cpp) -target_link_libraries(ViterbiTest m17cxx GTest::GTest) +target_link_libraries(ViterbiTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(ViterbiTest "" AUTO) add_executable (Golay24Test Golay24Test.cpp) -target_link_libraries(Golay24Test m17cxx GTest::GTest) +target_link_libraries(Golay24Test m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(Golay24Test "" AUTO) add_executable (CRC16Test CRC16Test.cpp) -target_link_libraries(CRC16Test m17cxx GTest::GTest) +target_link_libraries(CRC16Test m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(CRC16Test "" AUTO) add_executable (M17RandomizerTest M17RandomizerTest.cpp) -target_link_libraries(M17RandomizerTest m17cxx GTest::GTest) +target_link_libraries(M17RandomizerTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(M17RandomizerTest "" AUTO) add_executable (PolynomialInterleaverTest PolynomialInterleaverTest.cpp) -target_link_libraries(PolynomialInterleaverTest m17cxx GTest::GTest) +target_link_libraries(PolynomialInterleaverTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(PolynomialInterleaverTest "" AUTO) add_executable (M17ModulatorTest M17ModulatorTest.cpp) -target_link_libraries(M17ModulatorTest m17cxx GTest::GTest codec2) +target_link_libraries(M17ModulatorTest m17cxx GTest::GTest ${PTHREAD} codec2) gtest_add_tests(M17ModulatorTest "" AUTO) add_executable (UtilTest UtilTest.cpp) -target_link_libraries(UtilTest m17cxx GTest::GTest) +target_link_libraries(UtilTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(UtilTest "" AUTO) add_executable (LinkSetupFrameTest LinkSetupFrameTest.cpp) -target_link_libraries(LinkSetupFrameTest m17cxx GTest::GTest) +target_link_libraries(LinkSetupFrameTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(LinkSetupFrameTest "" AUTO) add_executable (SlidingDFTTest SlidingDFTTest.cpp) -target_link_libraries(SlidingDFTTest m17cxx GTest::GTest) +target_link_libraries(SlidingDFTTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(SlidingDFTTest "" AUTO) add_executable (DataCarrierDetectTest DataCarrierDetectTest.cpp) -target_link_libraries(DataCarrierDetectTest m17cxx GTest::GTest) +target_link_libraries(DataCarrierDetectTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(DataCarrierDetectTest "" AUTO) add_executable (ClockRecoveryTest ClockRecoveryTest.cpp) -target_link_libraries(ClockRecoveryTest m17cxx GTest::GTest) +target_link_libraries(ClockRecoveryTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(ClockRecoveryTest "" AUTO) add_executable (FreqDevEstimatorTest FreqDevEstimatorTest.cpp) -target_link_libraries(FreqDevEstimatorTest m17cxx GTest::GTest) +target_link_libraries(FreqDevEstimatorTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(FreqDevEstimatorTest "" AUTO) add_executable (CorrelatorTest CorrelatorTest.cpp) -target_link_libraries(CorrelatorTest m17cxx GTest::GTest) +target_link_libraries(CorrelatorTest m17cxx GTest::GTest ${PTHREAD}) gtest_add_tests(CorrelatorTest "" AUTO) From 4fd9a1d33f0fc2deed6fdaf56c3a76160c1829c2 Mon Sep 17 00:00:00 2001 From: Jay Francis Date: Mon, 14 Mar 2022 20:55:37 -0400 Subject: [PATCH 9/9] removed MSVC variants --- include/m17cxx/Convolution.h | 5 ----- include/m17cxx/Golay24.h | 5 ----- include/m17cxx/M17Synchronizer.h | 5 ----- 3 files changed, 15 deletions(-) diff --git a/include/m17cxx/Convolution.h b/include/m17cxx/Convolution.h index 2980894..122effa 100644 --- a/include/m17cxx/Convolution.h +++ b/include/m17cxx/Convolution.h @@ -6,11 +6,6 @@ #include #include -#ifdef _MSC_VER -# include -# define __builtin_popcount __popcnt -#endif - namespace mobilinkd { diff --git a/include/m17cxx/Golay24.h b/include/m17cxx/Golay24.h index b99cceb..20ee171 100644 --- a/include/m17cxx/Golay24.h +++ b/include/m17cxx/Golay24.h @@ -9,11 +9,6 @@ #include #include -#ifdef _MSC_VER -# include -# define __builtin_popcount __popcnt -#endif - namespace mobilinkd { // Parts are adapted from: diff --git a/include/m17cxx/M17Synchronizer.h b/include/m17cxx/M17Synchronizer.h index 086e0c6..422fd3a 100644 --- a/include/m17cxx/M17Synchronizer.h +++ b/include/m17cxx/M17Synchronizer.h @@ -5,11 +5,6 @@ #include #include -#ifdef _MSC_VER -# include -# define __builtin_popcount __popcnt -#endif - namespace mobilinkd {