From 83d2624cdfc1dd45ab1da02881448c5584ff6050 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 29 Oct 2016 00:05:12 +0200 Subject: Modernize ReedSolomon, use vector instead of raw buffer --- src/ReedSolomon.cpp | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src/ReedSolomon.cpp') diff --git a/src/ReedSolomon.cpp b/src/ReedSolomon.cpp index 7508747..38d8ea8 100644 --- a/src/ReedSolomon.cpp +++ b/src/ReedSolomon.cpp @@ -1,6 +1,11 @@ /* Copyright (C) 2005, 2006, 2007, 2008, 2009 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) + + Copyright (C) 2016 + Matthias P. Braendli, matthias.braendli@mpb.li + + http://www.opendigitalradio.org */ /* This file is part of ODR-DabMux. @@ -20,6 +25,8 @@ */ #include "ReedSolomon.h" +#include +#include #include #include #include // For galois.h ... @@ -29,7 +36,6 @@ extern "C" { #include "fec/fec.h" } #include -#include #define SYMSIZE 8 @@ -38,8 +44,8 @@ ReedSolomon::ReedSolomon(int N, int K, bool reverse, int gfpoly, int firstRoot, { setReverse(reverse); - myN = N; - myK = K; + m_N = N; + m_K = K; const int symsize = SYMSIZE; const int nroots = N - K; // For EDI PFT, this must be 48 @@ -68,25 +74,25 @@ void ReedSolomon::setReverse(bool state) } -int ReedSolomon::encode(void* data, void* fec, unsigned long size) +int ReedSolomon::encode(void* data, void* fec, size_t size) { - unsigned char* input = reinterpret_cast(data); - unsigned char* output = reinterpret_cast(fec); + uint8_t* input = reinterpret_cast(data); + uint8_t* output = reinterpret_cast(fec); int ret = 0; if (reverse) { - unsigned char* buffer = new unsigned char[myN]; - memcpy(buffer, input, myK); - memcpy(&buffer[myK], output, myN - myK); + std::vector buffer(m_N); + + memcpy(&buffer[0], input, m_K); + memcpy(&buffer[m_K], output, m_N - m_K); - ret = decode_rs_char(rsData, buffer, nullptr, 0); + ret = decode_rs_char(rsData, &buffer[0], nullptr, 0); if ((ret != 0) && (ret != -1)) { - memcpy(input, buffer, myK); - memcpy(output, &buffer[myK], myN - myK); + memcpy(input, &buffer[0], m_K); + memcpy(output, &buffer[m_K], m_N - m_K); } - - delete[] buffer; - } else { + } + else { encode_rs_char(rsData, input, output); } @@ -94,15 +100,16 @@ int ReedSolomon::encode(void* data, void* fec, unsigned long size) } -int ReedSolomon::encode(void* data, unsigned long size) +int ReedSolomon::encode(void* data, size_t size) { - unsigned char* input = reinterpret_cast(data); + uint8_t* input = reinterpret_cast(data); int ret = 0; if (reverse) { ret = decode_rs_char(rsData, input, nullptr, 0); - } else { - encode_rs_char(rsData, input, &input[myK]); + } + else { + encode_rs_char(rsData, input, &input[m_K]); } return ret; -- cgit v1.2.3