aboutsummaryrefslogtreecommitdiffstats
path: root/lib/decoding/openbts
diff options
context:
space:
mode:
authorPiotr Krysik <ptrkrysik@gmail.com>2018-02-27 08:34:03 +0100
committerPiotr Krysik <ptrkrysik@gmail.com>2018-02-27 14:45:14 +0100
commit792330777d7c21df02ce1ecb6f876b076a14b519 (patch)
tree66541ce1c9619f2e4e3f523ad5a9f4e7ce875682 /lib/decoding/openbts
parent8bed612c39731e94b7061dc74227e1debee2a429 (diff)
Portability fix: replacing tables of variable size with memory allocations
Diffstat (limited to 'lib/decoding/openbts')
-rw-r--r--lib/decoding/openbts/AmrCoder.cpp75
-rw-r--r--lib/decoding/openbts/ViterbiR204.cpp13
2 files changed, 58 insertions, 30 deletions
diff --git a/lib/decoding/openbts/AmrCoder.cpp b/lib/decoding/openbts/AmrCoder.cpp
index 718baf0..db5b2d8 100644
--- a/lib/decoding/openbts/AmrCoder.cpp
+++ b/lib/decoding/openbts/AmrCoder.cpp
@@ -24,11 +24,10 @@
#include <iostream>
#include <stdio.h>
#include <sstream>
+#include <cstdlib>
using namespace std;
-
-
ViterbiTCH_AFS12_2::ViterbiTCH_AFS12_2()
{
assert(mDeferral < 32);
@@ -378,7 +377,7 @@ void ViterbiTCH_AFS12_2::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -394,8 +393,8 @@ void ViterbiTCH_AFS12_2::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -445,6 +444,9 @@ void ViterbiTCH_AFS12_2::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
@@ -582,7 +584,7 @@ void ViterbiTCH_AFS10_2::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -598,8 +600,8 @@ void ViterbiTCH_AFS10_2::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -649,6 +651,9 @@ void ViterbiTCH_AFS10_2::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
@@ -786,7 +791,7 @@ void ViterbiTCH_AFS7_95::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -802,8 +807,8 @@ void ViterbiTCH_AFS7_95::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -853,6 +858,9 @@ void ViterbiTCH_AFS7_95::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
@@ -990,7 +998,7 @@ void ViterbiTCH_AFS7_4::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -1006,8 +1014,8 @@ void ViterbiTCH_AFS7_4::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -1057,6 +1065,9 @@ void ViterbiTCH_AFS7_4::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
@@ -1196,7 +1207,7 @@ void ViterbiTCH_AFS6_7::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -1212,8 +1223,8 @@ void ViterbiTCH_AFS6_7::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -1263,6 +1274,9 @@ void ViterbiTCH_AFS6_7::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
@@ -1402,7 +1416,7 @@ void ViterbiTCH_AFS5_9::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -1418,8 +1432,8 @@ void ViterbiTCH_AFS5_9::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -1469,6 +1483,9 @@ void ViterbiTCH_AFS5_9::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
@@ -1610,7 +1627,7 @@ void ViterbiTCH_AFS5_15::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -1626,8 +1643,8 @@ void ViterbiTCH_AFS5_15::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -1677,6 +1694,9 @@ void ViterbiTCH_AFS5_15::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
@@ -1818,7 +1838,7 @@ void ViterbiTCH_AFS4_75::decode(const SoftVector &in, BitVector& target)
assert(sz == decoder.iRate()*target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -1834,8 +1854,8 @@ void ViterbiTCH_AFS4_75::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -1885,6 +1905,9 @@ void ViterbiTCH_AFS4_75::decode(const SoftVector &in, BitVector& target)
oCount++;
}
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
diff --git a/lib/decoding/openbts/ViterbiR204.cpp b/lib/decoding/openbts/ViterbiR204.cpp
index 296e292..fe31aad 100644
--- a/lib/decoding/openbts/ViterbiR204.cpp
+++ b/lib/decoding/openbts/ViterbiR204.cpp
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <sstream>
#include <string.h>
+#include <cstdlib>
using namespace std;
@@ -70,7 +71,7 @@ void ViterbiR2O4::encode(const BitVector& in, BitVector& target) const
assert(sz*coder.iRate() == target.size());
// Build a "history" array where each element contains the full history.
- uint32_t history[sz];
+ uint32_t * history = (uint32_t *) malloc(sizeof(uint32_t)*sz);
uint32_t accum = 0;
for (size_t i=0; i<sz; i++) {
accum = (accum<<1) | in.bit(i);
@@ -85,6 +86,7 @@ void ViterbiR2O4::encode(const BitVector& in, BitVector& target) const
*op++ = coder.stateTable(g,index);
}
}
+ free(history);
}
@@ -224,7 +226,7 @@ void ViterbiR2O4::decode(const SoftVector &in, BitVector& target)
// Build a "history" array where each element contains the full history.
// (pat) We only use every other history element, so why are we setting them?
- uint32_t history[ctsz];
+ uint32_t * history = (uint32_t *)malloc(sizeof(uint32_t)*ctsz);
{
BitVector bits = in.sliced();
uint32_t accum = 0;
@@ -241,8 +243,8 @@ void ViterbiR2O4::decode(const SoftVector &in, BitVector& target)
}
// Precompute metric tables.
- float matchCostTable[ctsz];
- float mismatchCostTable[ctsz];
+ float * matchCostTable = (float *)malloc(sizeof(float)*ctsz);
+ float * mismatchCostTable = (float *)malloc(sizeof(float)*ctsz);
{
const float *dp = in.begin();
for (size_t i=0; i<sz; i++) {
@@ -296,6 +298,9 @@ void ViterbiR2O4::decode(const SoftVector &in, BitVector& target)
// Dont think minCost == NULL can happen.
mBitErrorCnt = minCost ? minCost->bitErrorCnt : 0;
}
+ free(history);
+ free(matchCostTable);
+ free(mismatchCostTable);
}
// vim: ts=4 sw=4