diff --git a/CMakeLists.txt b/CMakeLists.txt index c081766..d732945 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,4 +54,24 @@ set(BASIC_RADIO_USE_EASYLOGGING ON CACHE BOOL "Use easylogging for basic_radio" set(BASIC_SCRAPER_USE_EASYLOGGING ON CACHE BOOL "Use easylogging for basic_scraper" FORCE) add_subdirectory(${CMAKE_SOURCE_DIR}/src) -add_subdirectory(${CMAKE_SOURCE_DIR}/examples) \ No newline at end of file +add_subdirectory(${CMAKE_SOURCE_DIR}/examples) + +# private compiler flags from CMakePresets.json +function(add_project_target_flags target) + separate_arguments(PRIVATE_ARGS NATIVE_COMMAND "${PROJECT_TARGET_PRIVATE_COMPILER_FLAGS}") + target_compile_options(${target} PRIVATE ${PRIVATE_ARGS}) +endfunction() +# src/ +add_project_target_flags(ofdm_core) +add_project_target_flags(dab_core) +add_project_target_flags(basic_radio) +add_project_target_flags(basic_scraper) +# examples/ +add_project_target_flags(radio_app) +add_project_target_flags(basic_radio_app) +add_project_target_flags(basic_radio_app_cli) +add_project_target_flags(rtl_sdr) +add_project_target_flags(simulate_transmitter) +add_project_target_flags(convert_viterbi) +add_project_target_flags(apply_frequency_shift) +add_project_target_flags(read_wav) \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index eca5834..a875bb9 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -10,18 +10,44 @@ "name": "windows-msvc", "generator": "Ninja", "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl", "CMAKE_CXX_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING", "CMAKE_C_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING" } }, + { + "name": "windows-msvc-warnings", + "inherits": ["windows-msvc"], + "cacheVariables": { + "PROJECT_TARGET_PRIVATE_COMPILER_FLAGS": "/W3 /WX" + } + }, { "name": "windows-msvc-sanitize", - "generator": "Ninja", + "inherits": ["windows-msvc-warnings"], "cacheVariables": { "CMAKE_CXX_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /fsanitize=address /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION", "CMAKE_C_FLAGS_INIT": "/MP /fp:fast /arch:AVX2 /fsanitize=address /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING /D_DISABLE_VECTOR_ANNOTATION /D_DISABLE_STRING_ANNOTATION" } }, + { + "name": "windows-clang", + "generator": "Ninja", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CXX_FLAGS_INIT": "-ffast-math -march=native -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING", + "CMAKE_C_FLAGS_INIT": "-ffast-math -march=native -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING" + } + }, + { + "name": "windows-clang-warnings", + "inherits": ["windows-clang"], + "cacheVariables": { + "PROJECT_TARGET_PRIVATE_COMPILER_FLAGS": "-Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter" + } + }, { "name": "gcc", "generator": "Ninja", @@ -32,6 +58,13 @@ "CMAKE_C_FLAGS_INIT": "-ffast-math -march=native" } }, + { + "name": "gcc-warnings", + "inherits": ["gcc"], + "cacheVariables": { + "PROJECT_TARGET_PRIVATE_COMPILER_FLAGS": "-Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter" + } + }, { "name": "clang", "generator": "Ninja", @@ -42,6 +75,13 @@ "CMAKE_C_FLAGS_INIT": "-ffast-math -march=native" } }, + { + "name": "clang-warnings", + "inherits": ["clang"], + "cacheVariables": { + "PROJECT_TARGET_PRIVATE_COMPILER_FLAGS": "-Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter" + } + }, { "name": "clang-arm", "generator": "Ninja", diff --git a/examples/device/device.h b/examples/device/device.h index 1fee9b2..cc95f89 100644 --- a/examples/device/device.h +++ b/examples/device/device.h @@ -44,7 +44,7 @@ class Device void Close(); bool IsRunning() const { return is_running; } const auto& GetDescriptor() { return descriptor; } - const int GetBlockSize(void) { return block_size; } + int GetBlockSize(void) { return block_size; } const auto& GetGainList(void) { return gain_list; } bool GetIsGainManual(void) { return is_gain_manual; } float GetSelectedGain(void) { return selected_gain; } diff --git a/examples/read_wav.cpp b/examples/read_wav.cpp index 69bd674..a7c1228 100644 --- a/examples/read_wav.cpp +++ b/examples/read_wav.cpp @@ -141,7 +141,7 @@ int main(int argc, char** argv) { if (is_16_bit) { static auto convert_buf = std::vector(N); nb_read = fread(convert_buf.data(), sizeof(int16_t), N, fp_in); - for (int i = 0; i < nb_read; i++) { + for (size_t i = 0; i < nb_read; i++) { const int16_t v0 = convert_buf[i]; block[i] = (uint8_t)(v0/256 + 127); } @@ -213,6 +213,7 @@ bool validate_wav_header(WavHeader& header) { fprintf(stderr, "[WARN] Expected 8bits per sample for an 8bit IQ stream but got %d bits\n", header.BitsPerSample); is_warning = true; } - + + (void)is_warning; return !is_error; } \ No newline at end of file diff --git a/examples/rtl_sdr.cpp b/examples/rtl_sdr.cpp index df8ff05..3e2ad15 100644 --- a/examples/rtl_sdr.cpp +++ b/examples/rtl_sdr.cpp @@ -231,8 +231,6 @@ static void list_channels() { } int main(int argc, char **argv) { - const char* PROGRAM_NAME = "rtl_sdr"; - const char* PROGRAM_VERSION_NAME = "0.1.0"; auto parser = argparse::ArgumentParser("rtl_sdr", "0.1.0"); parser.add_description("An I/Q recorder for RTL2832 based DVB-T receivers"); init_parser(parser); diff --git a/examples/simulate_transmitter.cpp b/examples/simulate_transmitter.cpp index 071aae1..2d5638e 100644 --- a/examples/simulate_transmitter.cpp +++ b/examples/simulate_transmitter.cpp @@ -127,10 +127,9 @@ int main(int argc, char** argv) { // generate random digital data auto frame_bytes_buf = std::vector(nb_frame_bytes); - uint16_t scrambler_code_word = 0b0000000010101001; auto scrambler = Scrambler(); scrambler.Reset(); - for (int i = 0; i < nb_frame_bytes; i++) { + for (size_t i = 0; i < nb_frame_bytes; i++) { frame_bytes_buf[i] = scrambler.Process(); } @@ -148,7 +147,7 @@ int main(int argc, char** argv) { apply_pll_auto(frame_out_buf, frame_out_buf, frequency_norm); } - for (int i = 0; i < frame_size; i++) { + for (size_t i = 0; i < frame_size; i++) { const float I = frame_out_buf[i].real(); const float Q = frame_out_buf[i].imag(); const float A = 1.0f/(float)params.nb_data_carriers * 200.0f * 2.0f; diff --git a/src/basic_radio/basic_radio.cpp b/src/basic_radio/basic_radio.cpp index 4521d90..6a31b5b 100644 --- a/src/basic_radio/basic_radio.cpp +++ b/src/basic_radio/basic_radio.cpp @@ -9,7 +9,7 @@ #define LOG_ERROR(...) BASIC_RADIO_LOG_ERROR(fmt::format(__VA_ARGS__)) BasicRadio::BasicRadio(const DAB_Parameters& _params, const size_t nb_threads) -: params(_params), fic_runner(_params), thread_pool(nb_threads) +: params(_params), thread_pool(nb_threads), fic_runner(_params) { dab_misc_info = std::make_unique(); dab_database = std::make_unique(); diff --git a/src/basic_radio/basic_thread_pool.h b/src/basic_radio/basic_thread_pool.h index 614547f..ee5de13 100644 --- a/src/basic_radio/basic_thread_pool.h +++ b/src/basic_radio/basic_thread_pool.h @@ -6,6 +6,7 @@ #include #include #include +#include // simple thread pool to decode FIC and MSC channels across all cores class BasicThreadPool @@ -32,7 +33,7 @@ class BasicThreadPool nb_threads = _nb_threads ? _nb_threads : std::thread::hardware_concurrency(); task_threads.reserve(nb_threads); - for (int i = 0; i < nb_threads; i++) { + for (size_t i = 0; i < nb_threads; i++) { task_threads.emplace_back(&BasicThreadPool::RunnerThread, this); } } diff --git a/src/basic_scraper/basic_scraper.cpp b/src/basic_scraper/basic_scraper.cpp index 7e8c629..c6ec39d 100644 --- a/src/basic_scraper/basic_scraper.cpp +++ b/src/basic_scraper/basic_scraper.cpp @@ -154,10 +154,10 @@ FILE* BasicAudioScraper::CreateWavFile(BasicAudioParams params) { const int32_t BitsPerSample = params.bytes_per_sample * 8; const int32_t SampleRate = static_cast(params.frequency); - strncpy(header.ChunkID, "RIFF", 4); - strncpy(header.Format, "WAVE", 4); - strncpy(header.Subchunk1ID, "fmt ", 4); - strncpy(header.Subchunk2ID, "data", 4); + memcpy(header.ChunkID, "RIFF", 4); + memcpy(header.Format, "WAVE", 4); + memcpy(header.Subchunk1ID, "fmt ", 4); + memcpy(header.Subchunk2ID, "data", 4); header.Subchunk1Size = 16; // size of PCM format fields header.AudioFormat = 1; // Linear quantisation diff --git a/src/dab/algorithms/crc.h b/src/dab/algorithms/crc.h index 9239ecb..115a9ff 100644 --- a/src/dab/algorithms/crc.h +++ b/src/dab/algorithms/crc.h @@ -26,7 +26,7 @@ class CRC_Calculator { T crc = initial_value; const size_t shift = (sizeof(T)-1)*8; const size_t N = x.size(); - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { crc = crc ^ ((T)(x[i]) << shift); uint8_t lut_idx = (crc >> shift) & 0xFF; crc = (crc << 8) ^ lut[lut_idx]; @@ -48,9 +48,9 @@ class CRC_Calculator { const T bitcheck = 1u << (sizeof(T)*8 - 1); const int shift = (sizeof(T)-1)*8; - const int N = 256; + const size_t N = 256; auto* lut = new T[N]; - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { T crc = static_cast(i) << shift; for (int j = 0; j < 8; j++) { if ((crc & bitcheck) != 0) { diff --git a/src/dab/audio/aac_data_decoder.cpp b/src/dab/audio/aac_data_decoder.cpp index 42e81a1..531092e 100644 --- a/src/dab/audio/aac_data_decoder.cpp +++ b/src/dab/audio/aac_data_decoder.cpp @@ -35,8 +35,8 @@ bool AAC_Data_Decoder::ProcessDataElement(tcb::span data) { // Relevant functions are raw_data_block(...), and data_stream_element(...) const uint8_t header = data[0]; const uint8_t data_type = (header & 0b11100000) >> 5; - const uint8_t instance_tag = (header & 0b00011110) >> 1; - const uint8_t is_byte_align = (header & 0b00000001) >> 0; + // const uint8_t instance_tag = (header & 0b00011110) >> 1; + // const uint8_t is_byte_align = (header & 0b00000001) >> 0; if (data_type == 0) { // LOG_ERROR("Got null data type"); diff --git a/src/dab/audio/aac_frame_processor.cpp b/src/dab/audio/aac_frame_processor.cpp index 66112cb..4af24dc 100644 --- a/src/dab/audio/aac_frame_processor.cpp +++ b/src/dab/audio/aac_frame_processor.cpp @@ -186,9 +186,9 @@ bool AAC_Frame_Processor::CalculateFirecode(tcb::span buf) { } void AAC_Frame_Processor::AccumulateFrame(tcb::span buf) { - const auto N = buf.size(); + const size_t N = buf.size(); auto dst_buf = tcb::span(super_frame_buf).subspan(curr_dab_frame*N, N); - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { dst_buf[i] = buf[i]; } } @@ -217,9 +217,10 @@ void AAC_Frame_Processor::ProcessSuperFrame(const int nb_dab_frame_bytes) { // Table 2: Syntax of he_aac_super_frame_header() auto& buf = super_frame_buf; int curr_byte = 0; - const uint16_t firecode = (buf[0] << 8) | (buf[1]); + // TODO: We can fix firecode using ECC properties + // const uint16_t firecode = (buf[0] << 8) | (buf[1]); const uint8_t descriptor = buf[2]; - const uint8_t rfa = (descriptor & 0b10000000) >> 7; + // const uint8_t rfa = (descriptor & 0b10000000) >> 7; const uint8_t dac_rate = (descriptor & 0b01000000) >> 6; const uint8_t sbr_flag = (descriptor & 0b00100000) >> 5; const uint8_t aac_channel_mode = (descriptor & 0b00010000) >> 4; diff --git a/src/dab/database/dab_database_updater.h b/src/dab/database/dab_database_updater.h index 452bac8..63fc3a0 100644 --- a/src/dab/database/dab_database_updater.h +++ b/src/dab/database/dab_database_updater.h @@ -41,7 +41,7 @@ class DatabaseEntityUpdater DatabaseUpdaterGlobalStatistics& stats; public: DatabaseEntityUpdater(DatabaseUpdaterGlobalStatistics& _stats): stats(_stats) {} - ~DatabaseEntityUpdater() {} + virtual ~DatabaseEntityUpdater() {} virtual bool IsComplete() = 0; void OnCreate() { stats.nb_total++; diff --git a/src/dab/fic/fic_decoder.cpp b/src/dab/fic/fic_decoder.cpp index 61fd36b..2edf665 100644 --- a/src/dab/fic/fic_decoder.cpp +++ b/src/dab/fic/fic_decoder.cpp @@ -5,6 +5,7 @@ #include "../algorithms/crc.h" #include "../constants/puncture_codes.h" #include +#include #include "../dab_logging.h" #define TAG "fic-decoder" @@ -12,7 +13,7 @@ static auto _logger = DAB_LOG_REGISTER(TAG); #define LOG_MESSAGE(...) DAB_LOG_MESSAGE(TAG, fmt::format(__VA_ARGS__)) #define LOG_ERROR(...) DAB_LOG_ERROR(TAG, fmt::format(__VA_ARGS__)) -static const auto Generate_CRC_Calc() { +static auto Generate_CRC_Calc() { // DOC: ETSI EN 300 401 // Clause 5.2.1 - Fast Information Block (FIB) // CRC16 Polynomial is given by: @@ -28,13 +29,13 @@ static const auto Generate_CRC_Calc() { static auto CRC16_CALC = Generate_CRC_Calc(); -FIC_Decoder::FIC_Decoder(const int _nb_encoded_bits, const int _nb_fibs_per_group) +FIC_Decoder::FIC_Decoder(const size_t _nb_encoded_bits, const size_t _nb_fibs_per_group) // NOTE: 1/3 coding rate after puncturing and 1/4 code // For all transmission modes these parameters are constant -: nb_encoded_bits(_nb_encoded_bits), - nb_decoded_bits(_nb_encoded_bits/3), +: nb_fibs_per_group(_nb_fibs_per_group), + nb_encoded_bits(_nb_encoded_bits), nb_decoded_bytes(_nb_encoded_bits/(8*3)), - nb_fibs_per_group(_nb_fibs_per_group) + nb_decoded_bits(_nb_encoded_bits/3) { vitdec = std::make_unique(); vitdec->set_traceback_length(nb_decoded_bits); @@ -46,12 +47,8 @@ FIC_Decoder::FIC_Decoder(const int _nb_encoded_bits, const int _nb_fibs_per_grou FIC_Decoder::~FIC_Decoder() = default; // Each group contains 3 fibs (fast information blocks) in mode I -void FIC_Decoder::DecodeFIBGroup(tcb::span encoded_bits, const int cif_index) { - // viterbi decoding - int curr_encoded_bit = 0; - int curr_puncture_bit = 0; - int curr_decoded_bit = 0; - +void FIC_Decoder::DecodeFIBGroup(tcb::span encoded_bits, const size_t cif_index) { + assert(encoded_bits.size() >= nb_encoded_bits); // DOC: ETSI EN 300 401 // Clause 11.2 - Coding in the fast information channel // PI_16, PI_15 and PI_X are used @@ -63,8 +60,8 @@ void FIC_Decoder::DecodeFIBGroup(tcb::span encoded_bits, co // Perhaps these other modes also use the same puncture codes??? // Refer to DOC: docs/DAB_parameters.pdf, Clause A1.1: System parameters // for the number of bits per fib group for each transmission mode - const int nb_tail_bits = 6; - const int nb_decoded_bits_mode_I = (128*21 + 128*3 + 24)/int(DAB_Viterbi_Decoder::code_rate) - nb_tail_bits; + const size_t nb_tail_bits = 6; + const size_t nb_decoded_bits_mode_I = (128*21 + 128*3 + 24)/DAB_Viterbi_Decoder::code_rate - nb_tail_bits; if (nb_decoded_bits != nb_decoded_bits_mode_I) { LOG_ERROR("Expected {} encoded bits but got {}", nb_decoded_bits_mode_I, nb_decoded_bits); LOG_ERROR("ETSI EN 300 401 standard only gives the puncture codes used in transmission mode I"); @@ -89,17 +86,18 @@ void FIC_Decoder::DecodeFIBGroup(tcb::span encoded_bits, co // descrambler scrambler->Reset(); - for (int i = 0; i < nb_decoded_bytes; i++) { + for (size_t i = 0; i < nb_decoded_bytes; i++) { uint8_t b = scrambler->Process(); decoded_bytes[i] ^= b; } // crc16 check - const int nb_fib_bytes = nb_decoded_bytes/nb_fibs_per_group; - const int nb_crc16_bytes = 2; - const int nb_data_bytes = nb_fib_bytes-nb_crc16_bytes; + const size_t nb_fib_bytes = nb_decoded_bytes/nb_fibs_per_group; + const size_t nb_crc16_bytes = 2; + assert(nb_fib_bytes >= nb_crc16_bytes); + const size_t nb_data_bytes = nb_fib_bytes-nb_crc16_bytes; - for (int i = 0; i < nb_fibs_per_group; i++) { + for (size_t i = 0; i < nb_fibs_per_group; i++) { auto fib_buf = tcb::span(decoded_bytes).subspan(i*nb_fib_bytes, nb_fib_bytes); auto data_buf = fib_buf.first(nb_data_bytes); auto crc_buf = fib_buf.last(nb_crc16_bytes); @@ -109,7 +107,6 @@ void FIC_Decoder::DecodeFIBGroup(tcb::span encoded_bits, co const bool is_valid = crc16_rx == crc16_pred; LOG_MESSAGE("[crc16] fib={}/{} is_match={} pred={:04X} got={:04X}", i, nb_fibs_per_group, is_valid, crc16_pred, crc16_rx); - if (is_valid) { obs_on_fib.Notify(data_buf); } diff --git a/src/dab/fic/fic_decoder.h b/src/dab/fic/fic_decoder.h index dacd272..abfe54d 100644 --- a/src/dab/fic/fic_decoder.h +++ b/src/dab/fic/fic_decoder.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include "utility/observable.h" @@ -18,17 +19,17 @@ class FIC_Decoder std::unique_ptr scrambler; std::vector decoded_bytes; - const int nb_fibs_per_group; - const int nb_encoded_bits; - const int nb_decoded_bytes; - const int nb_decoded_bits; + const size_t nb_fibs_per_group; + const size_t nb_encoded_bits; + const size_t nb_decoded_bytes; + const size_t nb_decoded_bits; // fib buffer Observable> obs_on_fib; public: // number of bits in FIB (fast information block) group per CIF (common interleaved frame) - FIC_Decoder(const int _nb_encoded_bits, const int _nb_fibs_per_group); + FIC_Decoder(const size_t _nb_encoded_bits, const size_t _nb_fibs_per_group); ~FIC_Decoder(); - void DecodeFIBGroup(tcb::span encoded_bits, const int cif_index); + void DecodeFIBGroup(tcb::span encoded_bits, const size_t cif_index); auto& OnFIB(void) { return obs_on_fib; } }; \ No newline at end of file diff --git a/src/dab/fic/fig_processor.cpp b/src/dab/fic/fig_processor.cpp index 272f116..dd8c644 100644 --- a/src/dab/fic/fig_processor.cpp +++ b/src/dab/fic/fig_processor.cpp @@ -66,7 +66,6 @@ void FIG_Processor::ProcessFIB(tcb::span buf) { const int N = (int)buf.size(); int curr_byte = 0; - int curr_fig = 0; while (curr_byte < N) { const int nb_remain_bytes = N-curr_byte; @@ -197,10 +196,10 @@ void FIG_Processor::ProcessFIG_Type_2(tcb::span buf) { } const uint8_t descriptor = buf[0]; - FIG_Header_Type_2 header; - header.toggle_flag = (descriptor & 0b10000000) >> 7; - header.segment_index = (descriptor & 0b01110000) >> 4; - header.rfu = (descriptor & 0b00001000) >> 3; + // FIG_Header_Type_2 header; + // header.toggle_flag = (descriptor & 0b10000000) >> 7; + // header.segment_index = (descriptor & 0b01110000) >> 4; + // header.rfu = (descriptor & 0b00001000) >> 3; const uint8_t extension = (descriptor & 0b00000111) >> 0; auto field_buf = buf.subspan(1); @@ -213,13 +212,13 @@ void FIG_Processor::ProcessFIG_Type_6(tcb::span buf) { return; } - const uint8_t descriptor = buf[0]; - const uint8_t rfu = (descriptor & 0b10000000) >> 7; - const uint8_t cn = (descriptor & 0b01000000) >> 6; - const uint8_t oe = (descriptor & 0b00100000) >> 5; - const uint8_t pd = (descriptor & 0b00010000) >> 4; - const uint8_t lef = (descriptor & 0b00001000) >> 3; - const uint8_t short_CA_sys_id = (descriptor & 0b00000111) >> 0; + // const uint8_t descriptor = buf[0]; + // const uint8_t rfu = (descriptor & 0b10000000) >> 7; + // const uint8_t cn = (descriptor & 0b01000000) >> 6; + // const uint8_t oe = (descriptor & 0b00100000) >> 5; + // const uint8_t pd = (descriptor & 0b00010000) >> 4; + // const uint8_t lef = (descriptor & 0b00001000) >> 3; + // const uint8_t short_CA_sys_id = (descriptor & 0b00000111) >> 0; auto field_buf = buf.subspan(1); LOG_MESSAGE("fig 6 L={} Unsupported", field_buf.size()); @@ -255,7 +254,6 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_0( // Perhaps it is because no changes occur, but this isn't stated in standard // const uint8_t occurance_change = // (buf[4] & 0b11111111) >> 0; - const uint8_t occurance_change = 0x00; LOG_MESSAGE("fig 0/0 country_id={} ensemble_ref={} change={} alarm={} cif={}|{}", eid.country_id, eid.ensemble_reference, @@ -365,8 +363,8 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_2( } const uint8_t descriptor = service_buf[nb_service_id_bytes]; - const uint8_t rfa = (descriptor & 0b10000000) >> 7; - const uint8_t CAId = (descriptor & 0b01110000) >> 4; + // const uint8_t rfa = (descriptor & 0b10000000) >> 7; + // const uint8_t CAId = (descriptor & 0b01110000) >> 4; const uint8_t nb_service_components = (descriptor & 0b00001111) >> 0; // Determine if we have enough bytes for the service components data @@ -1032,6 +1030,8 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_8( curr_index += nb_length_bytes; curr_service++; } + + (void)curr_service; } // Country, LTO and International Table @@ -1415,7 +1415,6 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_21( } // increment this to update the block size - int nb_block_bytes = nb_block_header_bytes; auto* block_buf = &buf[curr_byte]; const uint16_t Rfa0 = @@ -1488,7 +1487,6 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_21( eid.country_id, eid.ensemble_reference, is_geographically_adjacent, is_transmission_mode_I, (float)(alt_freq)*1e-6f); - handler->OnFrequencyInformation_1_Ensemble( eid.country_id, eid.ensemble_reference, alt_freq, @@ -1514,7 +1512,6 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_21( Rfa0, RM, is_time_compensated, rds_pi_code, (float)(alt_freq)*1e-6f); - handler->OnFrequencyInformation_1_RDS_PI( rds_pi_code, alt_freq, is_time_compensated); } @@ -1541,9 +1538,7 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_21( const uint16_t freq = (static_cast(b[1] & 0b01111111) << 8) | ((b[2] & 0b11111111) << 0); - const uint32_t drm_id = (static_cast(drm_id_msb) << 16) | id; - // F' = k*F // k = 1kHz or 10kHz depending on the multiplier flag const uint32_t multiplier = is_multiplier ? 10000u : 1000u; @@ -1553,7 +1548,6 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_21( curr_block, curr_fi_list, i, nb_entries, Rfa0, RM, is_time_compensated, drm_id, (float)(alt_freq)*1e-6f); - handler->OnFrequencyInformation_1_DRM( drm_id, alt_freq, is_time_compensated); } @@ -1578,7 +1572,6 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_21( const uint16_t freq = (static_cast(b[1] & 0b11111111) << 8) | ((b[2] & 0b11111111) << 0); - const uint32_t amss_id = (static_cast(amss_id_msb) << 16) | id; // F' = F*1kHz @@ -1588,11 +1581,11 @@ void FIG_Processor::ProcessFIG_Type_0_Ext_21( curr_block, curr_fi_list, i, nb_entries, Rfa0, RM, is_time_compensated, amss_id, (float)(alt_freq)*1e-6f); - handler->OnFrequencyInformation_1_AMSS( amss_id, alt_freq, is_time_compensated); } } + break; default: LOG_ERROR("fig 0/21 Unknown RM value ({})", RM); return; @@ -1762,7 +1755,7 @@ void FIG_Processor::ProcessFIG_Type_1_Ext_4( const uint8_t descriptor = buf[0]; const uint8_t pd = (descriptor & 0b10000000) >> 7; - const uint8_t Rfa = (descriptor & 0b01110000) >> 4; + // const uint8_t Rfa = (descriptor & 0b01110000) >> 4; const uint8_t SCIdS = (descriptor & 0b00001111) >> 0; const int nb_sid_bytes = pd ? 4 : 2; diff --git a/src/dab/mot/MOT_assembler.cpp b/src/dab/mot/MOT_assembler.cpp index 3e25508..aaca2e6 100644 --- a/src/dab/mot/MOT_assembler.cpp +++ b/src/dab/mot/MOT_assembler.cpp @@ -21,12 +21,12 @@ void MOT_Assembler::Reset(void) { } } -void MOT_Assembler::SetTotalSegments(const int N) { +void MOT_Assembler::SetTotalSegments(const size_t N) { total_segments = N; segments.resize(total_segments); } -bool MOT_Assembler::AddSegment(const int index, const uint8_t* buf, const int N) { +bool MOT_Assembler::AddSegment(const size_t index, const uint8_t* buf, const size_t N) { if (index >= segments.size()) { segments.resize(index+1); } @@ -56,7 +56,7 @@ bool MOT_Assembler::AddSegment(const int index, const uint8_t* buf, const int N) auto* all_buf = unordered_buffer.data(); auto* dst_buf = &all_buf[curr_unordered_index]; - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { dst_buf[i] = buf[i]; } curr_unordered_index += N; @@ -74,7 +74,7 @@ bool MOT_Assembler::CheckComplete(void) { return false; } - for (int i = 0; i < total_segments; i++) { + for (size_t i = 0; i < total_segments; i++) { auto& segment = segments[i]; if (segment.length == 0) { return false; @@ -92,11 +92,11 @@ void MOT_Assembler::ReconstructOrderedBuffer(void) { ordered_buffer.resize(curr_unordered_index); auto* dst_buf = ordered_buffer.data(); - int curr_ordered_index = 0; - for (int i = 0; i < total_segments; i++) { + size_t curr_ordered_index = 0; + for (size_t i = 0; i < total_segments; i++) { auto& segment = segments[i]; const auto* src_buf = &all_src_buf[segment.unordered_index]; - for (int j = 0; j < segment.length; j++) { + for (size_t j = 0; j < segment.length; j++) { dst_buf[curr_ordered_index++] = src_buf[j]; } } diff --git a/src/dab/mot/MOT_assembler.h b/src/dab/mot/MOT_assembler.h index d00ec2f..7d7c55d 100644 --- a/src/dab/mot/MOT_assembler.h +++ b/src/dab/mot/MOT_assembler.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "utility/span.h" @@ -9,8 +10,8 @@ class MOT_Assembler { private: struct Segment { - int unordered_index; - int length; + size_t unordered_index; + size_t length; Segment() { unordered_index = 0; length = 0; @@ -20,14 +21,14 @@ class MOT_Assembler std::vector unordered_buffer; std::vector ordered_buffer; std::vector segments; - int total_segments; - int curr_unordered_index; + size_t total_segments = 0; + size_t curr_unordered_index = 0; public: MOT_Assembler(); ~MOT_Assembler() {} void Reset(void); - void SetTotalSegments(const int N); - bool AddSegment(const int index, const uint8_t* buf, const int N); + void SetTotalSegments(const size_t N); + bool AddSegment(const size_t index, const uint8_t* buf, const size_t N); tcb::span GetData() { return ordered_buffer; } bool CheckComplete(); private: diff --git a/src/dab/mot/MOT_processor.cpp b/src/dab/mot/MOT_processor.cpp index 7087900..046aca6 100644 --- a/src/dab/mot/MOT_processor.cpp +++ b/src/dab/mot/MOT_processor.cpp @@ -35,8 +35,8 @@ void MOT_Processor::Process_Segment(const MOT_MSC_Data_Group_Header header, tcb: // DOC: ETSI EN 301 234 // Clause 5.1.1: Segmentation header // Figure 7: Segmentation header - const int N = (int)buf.size(); - const int MIN_SEGMENT_HEADER_BYTES = 2; + const size_t N = buf.size(); + const size_t MIN_SEGMENT_HEADER_BYTES = 2; if (N < MIN_SEGMENT_HEADER_BYTES) { LOG_ERROR("Insufficient length for segment header {}<{}", N, MIN_SEGMENT_HEADER_BYTES); return; @@ -46,7 +46,7 @@ void MOT_Processor::Process_Segment(const MOT_MSC_Data_Group_Header header, tcb: const uint16_t segment_size = ((buf[0] & 0b00011111) << 8) | buf[1]; auto* data = &buf[MIN_SEGMENT_HEADER_BYTES]; - const int nb_data_bytes = N-MIN_SEGMENT_HEADER_BYTES; + const size_t nb_data_bytes = N-MIN_SEGMENT_HEADER_BYTES; if (nb_data_bytes != segment_size) { LOG_ERROR("Segment length mismatch seg_size={} data_size={}", segment_size, nb_data_bytes); @@ -116,13 +116,13 @@ bool MOT_Processor::CheckEntityComplete(const mot_transport_id_t transport_id) { return false; } - if (entity.header.header_size != (int)header_buf.size()) { + if (entity.header.header_size != uint32_t(header_buf.size())) { LOG_ERROR("Mismatching header length fields {}!={}", entity.header.header_size, header_buf.size()); return false; } - if (entity.header.body_size != (int)body_buf.size()) { + if (entity.header.body_size != uint32_t(body_buf.size())) { LOG_ERROR("Mismatching body length fields {}!={}", entity.header.body_size, body_buf.size()); return false; @@ -382,7 +382,7 @@ bool MOT_Processor::ProcessHeaderExtensionParameter_UTCTime(MOT_UTC_Time& entity const uint32_t MJD_date = ((buf[0] & 0b01111111) << 10) | ((buf[1] & 0b11111111) << 2) | ((buf[2] & 0b11000000) >> 6); - const uint8_t rfu0 = (buf[2] & 0b00110000) >> 4; + // const uint8_t rfu0 = (buf[2] & 0b00110000) >> 4; const uint8_t UTC_flag = (buf[2] & 0b00001000) >> 4; const uint8_t hours = ((buf[2] & 0b00000111) << 2) | ((buf[3] & 0b11000000) >> 6); diff --git a/src/dab/msc/msc_xpad_processor.cpp b/src/dab/msc/msc_xpad_processor.cpp index 3b5dd63..181372e 100644 --- a/src/dab/msc/msc_xpad_processor.cpp +++ b/src/dab/msc/msc_xpad_processor.cpp @@ -8,7 +8,7 @@ static auto _logger = DAB_LOG_REGISTER(TAG); #define LOG_MESSAGE(...) DAB_LOG_MESSAGE(TAG, fmt::format(__VA_ARGS__)) #define LOG_ERROR(...) DAB_LOG_ERROR(TAG, fmt::format(__VA_ARGS__)) -static const auto Generate_CRC_Calc() { +static auto Generate_CRC_Calc() { // DOC: ETSI EN 300 401 // Clause 5.3.3.4 - MSC data group CRC // CRC16 Polynomial is given by: @@ -113,7 +113,7 @@ MSC_XPAD_Processor::ProcessResult MSC_XPAD_Processor::Process(tcb::span> 5; + // const uint8_t rfa0 = (data[0] & 0b11100000) >> 5; const uint8_t transport_id_flag = (data[0] & 0b00010000) >> 4; const uint8_t length_indicator = (data[0] & 0b00001111) >> 0; diff --git a/src/dab/pad/pad_data_group.cpp b/src/dab/pad/pad_data_group.cpp index 4f434b8..a6a2095 100644 --- a/src/dab/pad/pad_data_group.cpp +++ b/src/dab/pad/pad_data_group.cpp @@ -1,7 +1,7 @@ #include "./pad_data_group.h" #include "../algorithms/crc.h" -static const auto Generate_CRC_Calc() { +static auto Generate_CRC_Calc() { // DOC: ETSI EN 300 401 // Clause 7.4.5 - Applications in XPAD // Clause 7.4.5.0 - Introduction @@ -22,7 +22,7 @@ size_t PAD_Data_Group::Consume(tcb::span data) { const size_t N = data.size(); const size_t nb_remain = nb_required_bytes - nb_curr_bytes; const size_t nb_read = (nb_remain > N) ? N : nb_remain; - for (int i = 0; i < nb_read; i++) { + for (size_t i = 0; i < nb_read; i++) { buffer[nb_curr_bytes++] = data[i]; } return nb_read; diff --git a/src/dab/pad/pad_data_length_indicator.cpp b/src/dab/pad/pad_data_length_indicator.cpp index bce191a..c90c5f4 100644 --- a/src/dab/pad/pad_data_length_indicator.cpp +++ b/src/dab/pad/pad_data_length_indicator.cpp @@ -60,7 +60,6 @@ void PAD_Data_Length_Indicator::Interpret(void) { // Clause 7.4.5.1.1: X-PAD data group for data group length indicator // Figure 34: Structure of the X-PAD data group for the data group length indicator auto buf = data_group.GetData(); - const size_t N = data_group.GetRequiredBytes(); const uint8_t rfa = (buf[0] & 0b11000000) >> 6; const uint16_t _length = ((buf[0] & 0b00111111) << 8) | diff --git a/src/dab/pad/pad_dynamic_label.cpp b/src/dab/pad/pad_dynamic_label.cpp index 8a10170..196291d 100644 --- a/src/dab/pad/pad_dynamic_label.cpp +++ b/src/dab/pad/pad_dynamic_label.cpp @@ -117,7 +117,7 @@ void PAD_Dynamic_Label::ReadGroupHeader(void) { const auto buf = data_group.GetData(); const uint8_t toggle_flag = (buf[0] & 0b10000000) >> 7; - const uint8_t first_last_flag = (buf[0] & 0b01100000) >> 5; + // const uint8_t first_last_flag = (buf[0] & 0b01100000) >> 5; const uint8_t control_flag = (buf[0] & 0b00010000) >> 4; // Control segment has no data field @@ -144,19 +144,19 @@ void PAD_Dynamic_Label::InterpretLabelSegment(void) { const auto buf = data_group.GetData(); const size_t N = data_group.GetRequiredBytes(); - const uint8_t toggle_flag = (buf[0] & 0b10000000) >> 7; + // const uint8_t toggle_flag = (buf[0] & 0b10000000) >> 7; const uint8_t first_last_flag = (buf[0] & 0b01100000) >> 5; - const uint8_t control_flag = (buf[0] & 0b00010000) >> 4; - const uint8_t length = (buf[0] & 0b00001111) >> 0; + // const uint8_t control_flag = (buf[0] & 0b00010000) >> 4; + // const uint8_t length = (buf[0] & 0b00001111) >> 0; const uint8_t field2 = (buf[1] & 0b11110000) >> 4; - const uint8_t rfa0 = (buf[1] & 0b00001111) >> 0; + // const uint8_t rfa0 = (buf[1] & 0b00001111) >> 0; const bool is_first = (first_last_flag & 0b10) != 0; const bool is_last = (first_last_flag & 0b01) != 0; uint8_t seg_num = 0; if (!is_first) { - const uint8_t rfa1 = (field2 & 0b1000) >> 3; + // const uint8_t rfa1 = (field2 & 0b1000) >> 3; seg_num = (field2 & 0b0111) >> 0; } if (is_last) { @@ -189,8 +189,8 @@ void PAD_Dynamic_Label::InterpretCommand(void) { const auto buf = data_group.GetData(); const uint8_t command = (buf[0] & 0b00001111) >> 0; - const uint8_t field2 = (buf[1] & 0b11110000) >> 4; - const uint8_t field3 = (buf[1] & 0b00001111) >> 0; + // const uint8_t field2 = (buf[1] & 0b11110000) >> 4; + // const uint8_t field3 = (buf[1] & 0b00001111) >> 0; // DOC: ETSI EN 300 401 // Clause 7.4.5.2 - Dynamic label diff --git a/src/dab/pad/pad_dynamic_label_assembler.cpp b/src/dab/pad/pad_dynamic_label_assembler.cpp index 67a4d8f..7562572 100644 --- a/src/dab/pad/pad_dynamic_label_assembler.cpp +++ b/src/dab/pad/pad_dynamic_label_assembler.cpp @@ -19,31 +19,31 @@ void PAD_Dynamic_Label_Assembler::Reset(void) { nb_required_segments = 0; nb_ordered_bytes = 0; is_changed = true; - for (int i = 0; i < MAX_SEGMENTS; i++) { + for (size_t i = 0; i < MAX_SEGMENTS; i++) { segments[i].length = 0; } } -bool PAD_Dynamic_Label_Assembler::UpdateSegment(tcb::span data, const int seg_num) { - if ((seg_num < 0) || (seg_num >= MAX_SEGMENTS)) { +bool PAD_Dynamic_Label_Assembler::UpdateSegment(tcb::span data, const size_t seg_num) { + if (seg_num >= MAX_SEGMENTS) { LOG_ERROR("Segment index {} falls out of bounds [{},{}]", seg_num, 0, MAX_SEGMENT_BYTES-1); return false; } const size_t length = data.size(); - if ((length <= 0) || (length > MAX_SEGMENT_BYTES)) { + if ((length < 1) || (length > MAX_SEGMENT_BYTES)) { LOG_ERROR("Segment length {} falls out of bounds [{},{}]", length, 1, MAX_SEGMENT_BYTES); return false; } auto& segment = segments[seg_num]; - const int index = seg_num * MAX_SEGMENT_BYTES; + const size_t index = seg_num * MAX_SEGMENT_BYTES; auto* ref_data = &unordered_buf[index]; const bool length_mismatch = (segment.length != length); bool content_mismatch = false; - for (int i = 0; i < length; i++) { + for (size_t i = 0; i < length; i++) { ref_data[i] = data[i]; content_mismatch = content_mismatch || (ref_data[i] != data[i]); } @@ -57,7 +57,7 @@ bool PAD_Dynamic_Label_Assembler::UpdateSegment(tcb::span data, c LOG_ERROR("Segment {} contents mismatch", seg_num); } - segment.length = (int)length; + segment.length = length; is_changed = is_changed || length_mismatch || content_mismatch; if (is_changed && CombineSegments()) { @@ -91,7 +91,7 @@ bool PAD_Dynamic_Label_Assembler::CombineSegments(void) { return false; } - for (int i = 0; i < nb_required_segments; i++) { + for (size_t i = 0; i < nb_required_segments; i++) { auto& segment = segments[i]; if (segment.length == 0) { return false; @@ -99,11 +99,11 @@ bool PAD_Dynamic_Label_Assembler::CombineSegments(void) { } // combine segments - int curr_byte = 0; - for (int i = 0; i < nb_required_segments; i++) { + size_t curr_byte = 0; + for (size_t i = 0; i < nb_required_segments; i++) { auto& segment = segments[i]; auto* buf = &unordered_buf[i * MAX_SEGMENT_BYTES]; - for (int j = 0; j < segment.length; j++) { + for (size_t j = 0; j < segment.length; j++) { ordered_buf[curr_byte++] = buf[j]; } } diff --git a/src/dab/pad/pad_dynamic_label_assembler.h b/src/dab/pad/pad_dynamic_label_assembler.h index 5dafc88..29654b6 100644 --- a/src/dab/pad/pad_dynamic_label_assembler.h +++ b/src/dab/pad/pad_dynamic_label_assembler.h @@ -8,12 +8,12 @@ class PAD_Dynamic_Label_Assembler { private: struct Segment { - int length; + size_t length; }; private: - const int MAX_MESSAGE_BYTES = 128; - const int MAX_SEGMENT_BYTES = 16; - const int MAX_SEGMENTS = MAX_MESSAGE_BYTES/MAX_SEGMENT_BYTES; + const size_t MAX_MESSAGE_BYTES = 128; + const size_t MAX_SEGMENT_BYTES = 16; + const size_t MAX_SEGMENTS = MAX_MESSAGE_BYTES/MAX_SEGMENT_BYTES; std::vector segments; size_t nb_required_segments; @@ -29,7 +29,7 @@ class PAD_Dynamic_Label_Assembler void Reset(void); // Any segment which updates the completed label returns true // Any segment which doesn't update the completed label returns false - bool UpdateSegment(tcb::span data, const int seg_num); + bool UpdateSegment(tcb::span data, const size_t seg_num); void SetTotalSegments(const size_t total_segments); void SetCharSet(const uint8_t _charset); uint8_t GetCharSet(void) const { return charset; } diff --git a/src/dab/pad/pad_processor.cpp b/src/dab/pad/pad_processor.cpp index d8ed126..aa7d0d9 100644 --- a/src/dab/pad/pad_processor.cpp +++ b/src/dab/pad/pad_processor.cpp @@ -76,9 +76,9 @@ void PAD_Processor::Process(tcb::span fpad, tcb::span> 6; const uint8_t fpad_byte_L0 = (fpad[0] & 0b00111111) >> 0; - const uint8_t fpad_byte_L1 = (fpad[1] & 0b11111100) >> 2; + // const uint8_t fpad_byte_L1 = (fpad[1] & 0b11111100) >> 2; const uint8_t fpad_CI_flag = (fpad[1] & 0b00000010) >> 1; - const uint8_t fpad_Z = (fpad[1] & 0b00000001) >> 0; + // const uint8_t fpad_Z = (fpad[1] & 0b00000001) >> 0; if (fpad_type != 0b00) { LOG_ERROR("FPAD type {} reserved for future use", fpad_type); @@ -87,7 +87,7 @@ void PAD_Processor::Process(tcb::span fpad, tcb::span> 4; const uint8_t xpad_L_type = (fpad_byte_L0 & 0b00001111) >> 0; - const uint8_t xpad_L_data = fpad_byte_L1; + // const uint8_t xpad_L_data = fpad_byte_L1; if ((xpad_indicator == 0b00) || (xpad_reversed.empty()) || (nb_xpad_bytes == 0)) { if ((xpad_indicator != 0b00) || !xpad_reversed.empty() || (nb_xpad_bytes != 0)) { @@ -114,7 +114,7 @@ void PAD_Processor::Process(tcb::span fpad, tcb::span xpad, const bool // Clause 7.4.4.1: Contents indicator in short X-PAD // Figure 32: Contents indicator for short X-PAD const uint8_t CI = xpad[curr_byte++]; - const uint8_t rfu = (CI & 0b11100000) >> 5; + // const uint8_t rfu = (CI & 0b11100000) >> 5; const uint8_t app_type = (CI & 0b00011111) >> 0; const auto indicator = PAD_Content_Indicator{ DATA_BYTES_WITH_CI, app_type }; @@ -228,7 +228,7 @@ void PAD_Processor::Process_Variable_XPAD(tcb::span xpad, const b void PAD_Processor::ProcessDataField(tcb::span data_field) { const int N = (int)data_field.size(); int curr_byte = 0; - for (int i = 0; i < ci_list.size(); i++) { + for (size_t i = 0; i < ci_list.size(); i++) { auto& content = ci_list[i]; const int nb_remain = N-curr_byte; diff --git a/src/dab/radio_fig_handler.cpp b/src/dab/radio_fig_handler.cpp index 5fe0e2f..4c54e2d 100644 --- a/src/dab/radio_fig_handler.cpp +++ b/src/dab/radio_fig_handler.cpp @@ -438,7 +438,7 @@ void Radio_FIG_Handler::OnServiceComponent_5_UserApplication( s_u.SetCountryID(country_id); s_u.SetExtendedCountryCode(extended_country_code); - auto& sc_u = updater->GetServiceComponentUpdater_Service(service_reference, service_component_id); + // auto& sc_u = updater->GetServiceComponentUpdater_Service(service_reference, service_component_id); LOG_MESSAGE("service_ref={} component_id={} app_type={} N={}", service_reference, service_component_id, app_type, N); diff --git a/src/ofdm/circular_buffer.h b/src/ofdm/circular_buffer.h index 4fa62c6..17ee707 100644 --- a/src/ofdm/circular_buffer.h +++ b/src/ofdm/circular_buffer.h @@ -25,7 +25,7 @@ class CircularBuffer nb_read = (N > N_remain) ? N_remain : N; } - for (int i = 0; i < nb_read; i++) { + for (size_t i = 0; i < nb_read; i++) { buf[index++] = src[i]; index = index % capacity; } diff --git a/src/ofdm/dab_mapper_ref.cpp b/src/ofdm/dab_mapper_ref.cpp index 411a260..f33ebb7 100644 --- a/src/ofdm/dab_mapper_ref.cpp +++ b/src/ofdm/dab_mapper_ref.cpp @@ -18,7 +18,7 @@ void get_DAB_mapper_ref(tcb::span carrier_map, const size_t nb_fft) { // DC is positioned at index=N/2 auto PI_TABLE = std::vector(N); PI_TABLE[0] = 0; - for (int i = 1; i < N; i++) { + for (size_t i = 1; i < N; i++) { PI_TABLE[i] = (size_t)((13*PI_TABLE[i-1]+K-1) % N); } @@ -31,7 +31,7 @@ void get_DAB_mapper_ref(tcb::span carrier_map, const size_t nb_fft) { // -F <= f <= F where f =/= 0 // We copy these inorder from the PI_TABLE mapping size_t carrier_map_index = 0; - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { const size_t v = PI_TABLE[i]; // outside of valid indices if ((v < start_index) || (v > end_index) || (v == DC_index)) { diff --git a/src/ofdm/dab_prs_ref.cpp b/src/ofdm/dab_prs_ref.cpp index bb48c8a..65ac1fa 100644 --- a/src/ofdm/dab_prs_ref.cpp +++ b/src/ofdm/dab_prs_ref.cpp @@ -137,7 +137,7 @@ static const PRS_Table_Entry* PRS_PARAMS_MODE_TABLE[4] = { }; void get_DAB_PRS_reference(const int transmission_mode, tcb::span> buf) { - const size_t nb_fft = buf.size(); + const int nb_fft = int(buf.size()); if (transmission_mode <= 0 || transmission_mode > 4) { throw std::runtime_error(fmt::format("Invalid transmission mode {}", transmission_mode)); return; diff --git a/src/ofdm/dsp/apply_pll.cpp b/src/ofdm/dsp/apply_pll.cpp index f670a3a..b203817 100644 --- a/src/ofdm/dsp/apply_pll.cpp +++ b/src/ofdm/dsp/apply_pll.cpp @@ -15,7 +15,7 @@ static void apply_pll_scalar( const size_t N = x.size(); const float dt_step = freq_norm; for (size_t i = 0; i < N; i++) { - float dt_sin = dt_norm + float(i)*freq_norm; + float dt_sin = dt_norm + float(i)*dt_step; float dt_cos = dt_sin+0.25f; // translate to [-0.5,+0.5] within chebyshev accurate range dt_sin = dt_sin - std::round(dt_sin); diff --git a/src/ofdm/ofdm_demodulator.cpp b/src/ofdm/ofdm_demodulator.cpp index 618339d..e2473d7 100644 --- a/src/ofdm/ofdm_demodulator.cpp +++ b/src/ofdm/ofdm_demodulator.cpp @@ -77,10 +77,10 @@ OFDM_Demod::OFDM_Demod( tcb::span _carrier_mapper, int nb_desired_threads) : params(_params), - null_power_dip_buffer(null_power_dip_buffer_data), - correlation_time_buffer(correlation_time_buffer_data), active_buffer(_params, active_buffer_data, ALIGN_AMOUNT), - inactive_buffer(_params, inactive_buffer_data, ALIGN_AMOUNT) + inactive_buffer(_params, inactive_buffer_data, ALIGN_AMOUNT), + null_power_dip_buffer(null_power_dip_buffer_data), + correlation_time_buffer(correlation_time_buffer_data) { // NOTE: Allocating joint block for better memory locality as well as alignment requirements // Alignment is required for FFTW3 to use SIMD instructions which increases performance @@ -121,7 +121,7 @@ OFDM_Demod::OFDM_Demod( // Clause 3.12.1 - Fine time synchronisation // Correlation in time domain is the conjugate product in frequency domain - for (int i = 0; i < params.nb_fft; i++) { + for (size_t i = 0; i < params.nb_fft; i++) { correlation_prs_fft_reference[i] = std::conj(_prs_fft_ref[i]); } @@ -129,7 +129,7 @@ OFDM_Demod::OFDM_Demod( // Correlation in frequency domain is the conjugate product in time domain CalculateRelativePhase(_prs_fft_ref, correlation_prs_time_reference); CalculateIFFT(correlation_prs_time_reference, correlation_prs_time_reference); - for (int i = 0; i < params.nb_fft; i++) { + for (size_t i = 0; i < params.nb_fft; i++) { correlation_prs_time_reference[i] = std::conj(correlation_prs_time_reference[i]); } @@ -169,9 +169,9 @@ void OFDM_Demod::CreateThreads(int nb_desired_threads) { const int nb_threads_remain = (nb_threads-i); const int nb_syms_in_thread = (int)std::ceil((float)nb_syms_remain / (float)nb_threads_remain); const int symbol_end = is_last_thread ? nb_syms : (symbol_start+nb_syms_in_thread); - pipelines.emplace_back(std::move(std::make_unique( + pipelines.emplace_back(std::make_unique( symbol_start, symbol_end - ))); + )); symbol_start = symbol_end; } } @@ -185,11 +185,11 @@ void OFDM_Demod::CreateThreads(int nb_desired_threads) { ); // Create pipeline threads - for (int i = 0; i < pipelines.size(); i++) { + for (size_t i = 0; i < pipelines.size(); i++) { auto& pipeline = *(pipelines[i].get()); // Some pipelines depend on data being processed in other pipelines - const int dependent_pipeline_index = i+1; + const size_t dependent_pipeline_index = i+1; OFDM_Demod_Pipeline* dependent_pipeline = NULL; if (dependent_pipeline_index < pipelines.size()) { dependent_pipeline = pipelines[dependent_pipeline_index].get(); @@ -204,8 +204,8 @@ void OFDM_Demod::CreateThreads(int nb_desired_threads) { struct { uint32_t start, end; } fields; uint64_t data; } X; - X.fields.start = (int)pipeline.GetSymbolStart(); - X.fields.end = (int)pipeline.GetSymbolEnd(); + X.fields.start = uint32_t(pipeline.GetSymbolStart()); + X.fields.end = uint32_t(pipeline.GetSymbolEnd()); PROFILE_TAG_DATA_THREAD(X.data); while (PipelineThread(pipeline, dependent_pipeline)); } @@ -334,7 +334,7 @@ size_t OFDM_Demod::FindNullPowerDip(tcb::span> buf) { // We do this so we can guarantee the full start of the PRS is attained after fine time sync const size_t L = null_power_dip_buffer.Length(); const size_t start_index = null_power_dip_buffer.GetIndex(); - for (int i = 0; i < L; i++) { + for (size_t i = 0; i < L; i++) { const size_t j = i+start_index; correlation_time_buffer[i] = null_power_dip_buffer[j]; } @@ -386,7 +386,7 @@ size_t OFDM_Demod::RunCoarseFreqSync(tcb::span> buf) { // Step 4: Conjugate product in time domain // NOTE: correlation_prs_time_reference is already the conjugate - for (int i = 0; i < params.nb_fft; i++) { + for (size_t i = 0; i < params.nb_fft; i++) { correlation_ifft_buffer[i] *= correlation_prs_time_reference[i]; } @@ -406,7 +406,7 @@ size_t OFDM_Demod::RunCoarseFreqSync(tcb::span> buf) { float max_value = correlation_frequency_response[max_index+M]; for (int i = -max_carrier_offset; i <= max_carrier_offset; i++) { const int fft_index = i+M; - if (fft_index == params.nb_fft) continue; + if (fft_index == int(params.nb_fft)) continue; const float value = correlation_frequency_response[fft_index]; if (value > max_value) { max_value = value; @@ -426,7 +426,7 @@ size_t OFDM_Demod::RunCoarseFreqSync(tcb::span> buf) { if (index < -max_carrier_offset) index = -max_carrier_offset; if (index > max_carrier_offset) index = max_carrier_offset; int fft_index = (index+M); - if (fft_index >= params.nb_fft) fft_index = int(params.nb_fft-1); + if (fft_index >= int(params.nb_fft)) fft_index = int(params.nb_fft-1); const float magnitude_dB = correlation_frequency_response[fft_index]; const float magnitude = std::pow(10.0f, magnitude_dB/20.0f); return Peak { fft_index-M, magnitude }; @@ -487,13 +487,13 @@ size_t OFDM_Demod::RunFineTimeSync(tcb::span> buf) { // Correlation in time domain is done by doing conjugate multiplication in frequency domain // NOTE: Our PRS FFT reference was conjugated in the constructor CalculateFFT(correlation_ifft_buffer, correlation_fft_buffer); - for (int i = 0; i < params.nb_fft; i++) { + for (size_t i = 0; i < params.nb_fft; i++) { correlation_fft_buffer[i] *= correlation_prs_fft_reference[i]; } // Get IFFT to get our correlation result CalculateIFFT(correlation_fft_buffer, correlation_ifft_buffer); - for (int i = 0; i < params.nb_fft; i++) { + for (size_t i = 0; i < params.nb_fft; i++) { const auto& v = correlation_ifft_buffer[i]; const float A = 20.0f*std::log10(std::abs(v)); correlation_impulse_response[i] = A; @@ -504,7 +504,7 @@ size_t OFDM_Demod::RunFineTimeSync(tcb::span> buf) { float impulse_avg = 0.0f; float impulse_max_value = correlation_impulse_response[0]; int impulse_max_index = 0; - for (int i = 0; i < params.nb_fft; i++) { + for (int i = 0; i < int(params.nb_fft); i++) { const float peak_value = correlation_impulse_response[i]; // We expect that the correlation peak will at least be somewhere near where we expect it @@ -559,7 +559,7 @@ size_t OFDM_Demod::ReadSymbols(tcb::span> buf) { // Copy the null symbol so we can use it in the PRS correlation step auto null_sym = inactive_buffer.GetNullSymbol(); correlation_time_buffer.SetLength(params.nb_null_period); - for (int i = 0; i < params.nb_null_period; i++) { + for (size_t i = 0; i < params.nb_null_period; i++) { correlation_time_buffer[i] = null_sym[i]; } @@ -654,7 +654,6 @@ bool OFDM_Demod::PipelineThread(OFDM_Demod_Pipeline& thread_data, OFDM_Demod_Pip const int symbol_start = (int)thread_data.GetSymbolStart(); const int symbol_end = (int)thread_data.GetSymbolEnd(); - const int total_symbols = symbol_end-symbol_start; const int symbol_end_no_null = std::min(symbol_end, (int)params.nb_frame_symbols); const int symbol_end_dqpsk = std::min(symbol_end, (int)params.nb_frame_symbols-1); @@ -872,7 +871,7 @@ void OFDM_Demod::CalculateViterbiBits(tcb::span> vec_b const size_t N = params.nb_data_carriers; // Clause 3.16 - Data demapper - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { // Clause 3.16.1 - Freuency deinterleaving const size_t j = carrier_mapper[i]; const auto& vec = vec_buf[j]; @@ -915,7 +914,7 @@ void OFDM_Demod::CalculateMagnitude(tcb::span> fft_buf PROFILE_BEGIN_FUNC(); const size_t N = params.nb_fft; const size_t M = N/2; - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { const size_t j = (i+M) % N; const float x = 20.0f*std::log10(std::abs(fft_buf[j])); mag_buf[i] = x; @@ -926,7 +925,7 @@ float OFDM_Demod::CalculateL1Average(tcb::span> block) PROFILE_BEGIN_FUNC(); const size_t N = block.size(); float l1_avg = 0.0f; - for (int i = 0; i < N; i++) { + for (size_t i = 0; i < N; i++) { auto& v = block[i]; l1_avg += std::abs(v.real()) + std::abs(v.imag()); } diff --git a/src/ofdm/ofdm_frame_buffer.h b/src/ofdm/ofdm_frame_buffer.h index 0d1b8ea..273b700 100644 --- a/src/ofdm/ofdm_frame_buffer.h +++ b/src/ofdm/ofdm_frame_buffer.h @@ -37,8 +37,8 @@ class OFDM_Frame_Buffer // NOTE: We take in a reference to a span since the buffer is allocated separately // The underlying buffer should be resized to GetTotalBufferBytes() OFDM_Frame_Buffer(const OFDM_Params& _params, tcb::span& _buf, const size_t _align_size) - : params(_params), - buf(_buf), + : buf(_buf), + params(_params), align_size(_align_size), prefix_size(sizeof(T) * _params.nb_cyclic_prefix), data_symbol_size(sizeof(T) * _params.nb_symbol_period), diff --git a/src/ofdm/ofdm_modulator.cpp b/src/ofdm/ofdm_modulator.cpp index 0ac8e8c..7266761 100644 --- a/src/ofdm/ofdm_modulator.cpp +++ b/src/ofdm/ofdm_modulator.cpp @@ -21,7 +21,7 @@ OFDM_Modulator::OFDM_Modulator( { auto buf = tcb::span(prs_time_ref).subspan(params.nb_cyclic_prefix, params.nb_fft); CalculateIFFT(prs_fft_ref, buf); - for (int i = 0; i < params.nb_cyclic_prefix; i++) { + for (size_t i = 0; i < params.nb_cyclic_prefix; i++) { prs_time_ref[i] = prs_time_ref[params.nb_fft+i]; } } @@ -29,7 +29,7 @@ OFDM_Modulator::OFDM_Modulator( last_sym_fft.resize(params.nb_fft); curr_sym_fft.resize(params.nb_fft); - for (int i = 0; i < params.nb_fft; i++) { + for (size_t i = 0; i < params.nb_fft; i++) { curr_sym_fft[i] = std::complex(0,0); last_sym_fft[i] = std::complex(0,0); } @@ -55,17 +55,17 @@ bool OFDM_Modulator::ProcessBlock( } // null period - for (int i = 0; i < params.nb_null_period; i++) { + for (size_t i = 0; i < params.nb_null_period; i++) { frame_out_buf[i] = std::complex(0,0); } // prs symbol - for (int i = 0; i < params.nb_symbol_period; i++) { + for (size_t i = 0; i < params.nb_symbol_period; i++) { frame_out_buf[i+params.nb_null_period] = prs_time_ref[i]; } // seed the dqpsk fft buffers - for (int i = 0; i < params.nb_fft; i++) { + for (size_t i = 0; i < params.nb_fft; i++) { last_sym_fft[i] = prs_fft_ref[i]; } @@ -75,14 +75,11 @@ bool OFDM_Modulator::ProcessBlock( const size_t nb_data_in = params.nb_data_carriers*2/8; const size_t nb_out = params.nb_symbol_period; // account for the PRS (phase reference symbol) - auto* data_symbols = &frame_out_buf[params.nb_null_period + params.nb_symbol_period]; - - for (int i = 0; i < nb_data_symbols; i++) { - const auto* sym_data_in = &data_in_buf[i*nb_data_in]; - auto* sym_out = &data_symbols[i*params.nb_symbol_period]; + auto data_symbols = frame_out_buf.subspan(params.nb_null_period + params.nb_symbol_period); + for (size_t i = 0; i < nb_data_symbols; i++) { CreateDataSymbol( - {sym_data_in, nb_data_in}, - {sym_out, params.nb_symbol_period}); + data_in_buf.subspan(i*nb_data_in, nb_data_in), + data_symbols.subspan(i*nb_out, nb_out)); } } @@ -94,7 +91,6 @@ void OFDM_Modulator::CreateDataSymbol( tcb::span> sym_out) { const size_t nb_data_in = sym_data_in.size(); - const size_t nb_out = sym_out.size(); static float A = 1.0f/std::sqrt(2.0f); static std::complex PHASE_MAP[4] = { @@ -104,7 +100,7 @@ void OFDM_Modulator::CreateDataSymbol( { // create fft for -F/2 <= f < 0 size_t curr_carrier = params.nb_fft - params.nb_data_carriers/2; - for (int i = 0; i < nb_data_in/2; i++) { + for (size_t i = 0; i < nb_data_in/2; i++) { const uint8_t b = sym_data_in[i]; curr_sym_fft[curr_carrier++] = PHASE_MAP[((b >> 0) & 0b11)]; curr_sym_fft[curr_carrier++] = PHASE_MAP[((b >> 2) & 0b11)]; @@ -114,7 +110,7 @@ void OFDM_Modulator::CreateDataSymbol( // create fft for 0 < f <= F/2 curr_carrier = 1; - for (int i = 0; i < nb_data_in/2; i++) { + for (size_t i = 0; i < nb_data_in/2; i++) { const size_t j = nb_data_in/2 + i; const uint8_t b = sym_data_in[j]; curr_sym_fft[curr_carrier++] = PHASE_MAP[((b >> 0) & 0b11)]; @@ -128,12 +124,12 @@ void OFDM_Modulator::CreateDataSymbol( // get the dqpsk // arg(z0*z1) = arg(z0) + arg(z1) { - for (int i = 0; i < params.nb_data_carriers/2; i++) { + for (size_t i = 0; i < params.nb_data_carriers/2; i++) { const size_t j = params.nb_fft - params.nb_data_carriers/2 + i; curr_sym_fft[j] = last_sym_fft[j] * curr_sym_fft[j]; } - for (int i = 0; i < params.nb_data_carriers/2; i++) { + for (size_t i = 0; i < params.nb_data_carriers/2; i++) { const size_t j = 1+i; curr_sym_fft[j] = last_sym_fft[j] * curr_sym_fft[j]; } @@ -146,7 +142,7 @@ void OFDM_Modulator::CreateDataSymbol( } // create cyclic prefix - for (int i = 0; i < params.nb_cyclic_prefix; i++) { + for (size_t i = 0; i < params.nb_cyclic_prefix; i++) { sym_out[i] = sym_out[i+params.nb_fft]; } diff --git a/src/ofdm/reconstruction_buffer.h b/src/ofdm/reconstruction_buffer.h index 6167baa..dc3011c 100644 --- a/src/ofdm/reconstruction_buffer.h +++ b/src/ofdm/reconstruction_buffer.h @@ -18,7 +18,7 @@ class ReconstructionBuffer const size_t N_required = Capacity()-length; const size_t nb_read = (N_required >= N) ? N : N_required; auto wr_buf = buf.subspan(length, nb_read); - for (int i = 0; i < nb_read; i++) { + for (size_t i = 0; i < nb_read; i++) { wr_buf[i] = src[i]; } length += nb_read;