diff options
-rw-r--r-- | src/ReedSolomon.cpp | 45 | ||||
-rw-r--r-- | src/ReedSolomon.h | 30 |
2 files changed, 43 insertions, 32 deletions
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 <vector> +#include <algorithm> #include <stdexcept> #include <sstream> #include <stdio.h> // For galois.h ... @@ -29,7 +36,6 @@ extern "C" { #include "fec/fec.h" } #include <assert.h> -#include <stdlib.h> #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<unsigned char*>(data); - unsigned char* output = reinterpret_cast<unsigned char*>(fec); + uint8_t* input = reinterpret_cast<uint8_t*>(data); + uint8_t* output = reinterpret_cast<uint8_t*>(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<uint8_t> 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<unsigned char*>(data); + uint8_t* input = reinterpret_cast<uint8_t*>(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; diff --git a/src/ReedSolomon.h b/src/ReedSolomon.h index d96a522..abcef62 100644 --- a/src/ReedSolomon.h +++ b/src/ReedSolomon.h @@ -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. @@ -19,34 +24,33 @@ along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _REEDSOLOMON -#define _REEDSOLOMON +#pragma once #ifdef HAVE_CONFIG_H # include <config.h> #endif +#include <stdlib.h> class ReedSolomon { public: - ReedSolomon(int N, int K, bool reverse = false, + ReedSolomon(int N, int K, + bool reverse = false, int gfpoly = 0x11d, int firstRoot = 0, int primElem = 1); - ReedSolomon(const ReedSolomon& clone); - virtual ~ReedSolomon(); + ReedSolomon(const ReedSolomon& other) = delete; + ReedSolomon operator=(const ReedSolomon& other) = delete; + ~ReedSolomon(); void setReverse(bool state); - int encode(void* data, void* fec, unsigned long size); - int encode(void* data, unsigned long size); - -protected: - int myN; - int myK; + int encode(void* data, void* fec, size_t size); + int encode(void* data, size_t size); private: + int m_N; + int m_K; + void* rsData; bool reverse; }; - -#endif // _REEDSOLOMON |