summaryrefslogtreecommitdiffstats
path: root/src/ReedSolomon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ReedSolomon.cpp')
-rw-r--r--src/ReedSolomon.cpp49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/ReedSolomon.cpp b/src/ReedSolomon.cpp
index 69e1191..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
@@ -47,7 +53,7 @@ ReedSolomon::ReedSolomon(int N, int K, bool reverse, int gfpoly, int firstRoot,
rsData = init_rs_char(symsize, gfpoly, firstRoot, primElem, nroots, pad);
- if (rsData == NULL) {
+ if (rsData == nullptr) {
std::stringstream ss;
ss << "Invalid Reed-Solomon parameters! " <<
"N=" << N << " ; K=" << K << " ; pad=" << pad;
@@ -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, NULL, 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, NULL, 0);
- } else {
- encode_rs_char(rsData, input, &input[myK]);
+ ret = decode_rs_char(rsData, input, nullptr, 0);
+ }
+ else {
+ encode_rs_char(rsData, input, &input[m_K]);
}
return ret;