aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-29 00:05:12 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-29 00:05:12 +0200
commit83d2624cdfc1dd45ab1da02881448c5584ff6050 (patch)
treeeec44e4977e506331ee808cfdc735c6c17160d04 /src
parent32bdfb274ec20318dd7d45fb62cd6e51323453f7 (diff)
downloaddabmux-83d2624cdfc1dd45ab1da02881448c5584ff6050.tar.gz
dabmux-83d2624cdfc1dd45ab1da02881448c5584ff6050.tar.bz2
dabmux-83d2624cdfc1dd45ab1da02881448c5584ff6050.zip
Modernize ReedSolomon, use vector instead of raw buffer
Diffstat (limited to 'src')
-rw-r--r--src/ReedSolomon.cpp45
-rw-r--r--src/ReedSolomon.h30
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