This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Tom Tsou gerrit-no-reply at lists.osmocom.org
Review at https://gerrit.osmocom.org/2920
sigProcLib: Remove heap based signal vector allocations
The osmo-trx internals rely heavily on dynamic alloction of
I/Q signal vectors. In a number of cases there is no reason
to to use dynamic rather than stack based allocation. Convert
these cases accordingly.t
Change-Id: If53da1bf77b5944b6117765fa98ce12e1ccdeede
---
M Transceiver52M/sigProcLib.cpp
1 file changed, 49 insertions(+), 68 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/20/2920/1
diff --git a/Transceiver52M/sigProcLib.cpp b/Transceiver52M/sigProcLib.cpp
index 3a9a529..04cb0d4 100644
--- a/Transceiver52M/sigProcLib.cpp
+++ b/Transceiver52M/sigProcLib.cpp
@@ -626,8 +626,7 @@
{
int burst_len, sps = 4;
float phase;
- signalVector *c0_pulse, *c1_pulse, *c0_burst;
- signalVector *c1_burst, *c0_shaped, *c1_shaped;
+ signalVector *c0_pulse, *c1_pulse, *c0_shaped, *c1_shaped;
signalVector::iterator c0_itr, c1_itr;
c0_pulse = GSMPulse4->c0;
@@ -638,13 +637,10 @@
burst_len = 625;
- c0_burst = new signalVector(burst_len, c0_pulse->size());
- c0_burst->isReal(true);
- c0_itr = c0_burst->begin();
-
- c1_burst = new signalVector(burst_len, c1_pulse->size());
- c1_burst->isReal(true);
- c1_itr = c1_burst->begin();
+ signalVector c0_burst(burst_len, c0_pulse->size());
+ signalVector c1_burst(burst_len, c1_pulse->size());
+ c0_itr = c0_burst.begin();
+ c1_itr = c1_burst.begin();
/* Padded differential tail bits */
*c0_itr = 2.0 * (0x00 & 0x01) - 1.0;
@@ -660,10 +656,9 @@
*c0_itr = 2.0 * (0x00 & 0x01) - 1.0;
/* Generate C0 phase coefficients */
- GMSKRotate(*c0_burst, sps);
- c0_burst->isReal(false);
+ GMSKRotate(c0_burst, sps);
- c0_itr = c0_burst->begin();
+ c0_itr = c0_burst.begin();
c0_itr += sps * 2;
c1_itr += sps * 2;
@@ -688,8 +683,8 @@
*c1_itr = *c0_itr * Complex<float>(0, phase);
/* Primary (C0) and secondary (C1) pulse shaping */
- c0_shaped = convolve(c0_burst, c0_pulse, NULL, START_ONLY);
- c1_shaped = convolve(c1_burst, c1_pulse, NULL, START_ONLY);
+ c0_shaped = convolve(&c0_burst, c0_pulse, NULL, START_ONLY);
+ c1_shaped = convolve(&c1_burst, c1_pulse, NULL, START_ONLY);
/* Sum shaped outputs into C0 */
c0_itr = c0_shaped->begin();
@@ -697,10 +692,7 @@
for (unsigned i = 0; i < c0_shaped->size(); i++ )
*c0_itr++ += *c1_itr++;
- delete c0_burst;
- delete c1_burst;
delete c1_shaped;
-
return c0_shaped;
}
@@ -774,7 +766,7 @@
static signalVector *shapeEdgeBurst(const signalVector &symbols)
{
size_t nsyms, nsamps = 625, sps = 4;
- signalVector *burst, *shape;
+ signalVector *shape;
signalVector::iterator burst_itr;
nsyms = symbols.size();
@@ -782,10 +774,10 @@
if (nsyms * sps > nsamps)
nsyms = 156;
- burst = new signalVector(nsamps, GSMPulse4->c0->size());
+ signalVector burst(nsamps, GSMPulse4->c0->size());
/* Delay burst by 1 symbol */
- burst_itr = burst->begin() + sps;
+ burst_itr = burst.begin() + sps;
for (size_t i = 0; i < nsyms; i++) {
float phase = i * 3.0f * M_PI / 8.0f;
Complex<float> rot = Complex<float>(cos(phase), sin(phase));
@@ -795,8 +787,7 @@
}
/* Single Gaussian pulse approximation shaping */
- shape = convolve(burst, GSMPulse4->c0, NULL, START_ONLY);
- delete burst;
+ shape = convolve(&burst, GSMPulse4->c0, NULL, START_ONLY);
return shape;
}
@@ -812,38 +803,37 @@
return NULL;
int i = 0;
- BitVector *bits = new BitVector(148);
+ BitVector bits(148);
signalVector *burst;
/* Tail bits */
for (; i < 3; i++)
- (*bits)[i] = 0;
+ bits[i] = 0;
/* Random bits */
for (; i < 60; i++)
- (*bits)[i] = rand() % 2;
+ bits[i] = rand() % 2;
/* Stealing bit */
- (*bits)[i++] = 0;
+ bits[i++] = 0;
/* Training sequence */
for (int n = 0; i < 87; i++, n++)
- (*bits)[i] = gTrainingSequence[tsc][n];
+ bits[i] = gTrainingSequence[tsc][n];
/* Stealing bit */
- (*bits)[i++] = 0;
+ bits[i++] = 0;
/* Random bits */
for (; i < 145; i++)
- (*bits)[i] = rand() % 2;
+ bits[i] = rand() % 2;
/* Tail bits */
for (; i < 148; i++)
- (*bits)[i] = 0;
+ bits[i] = 0;
int guard = 8 + !(tn % 4);
- burst = modulateBurst(*bits, guard, sps);
- delete bits;
+ burst = modulateBurst(bits, guard, sps);
return burst;
}
@@ -861,28 +851,27 @@
return NULL;
int i = 0;
- BitVector *bits = new BitVector(88+delay);
+ BitVector bits(88 + delay);
signalVector *burst;
/* delay */
for (; i < delay; i++)
- (*bits)[i] = 0;
+ bits[i] = 0;
/* head and synch bits */
for (int n = 0; i < 49+delay; i++, n++)
- (*bits)[i] = gRACHBurst[n];
+ bits[i] = gRACHBurst[n];
/* Random bits */
for (; i < 85+delay; i++)
- (*bits)[i] = rand() % 2;
+ bits[i] = rand() % 2;
/* Tail bits */
for (; i < 88+delay; i++)
- (*bits)[i] = 0;
+ bits[i] = 0;
int guard = 68-delay + !(tn % 4);
- burst = modulateBurst(*bits, guard, sps);
- delete bits;
+ burst = modulateBurst(bits, guard, sps);
return burst;
}
@@ -921,17 +910,18 @@
if ((tsc < 0) || (tsc > 7))
return NULL;
- signalVector *shape, *burst = new signalVector(148);
+ signalVector *shape;
+ signalVector burst(148);
const BitVector *midamble = &gEdgeTrainingSequence[tsc];
/* Tail */
int n, i = 0;
for (; i < tail; i++)
- (*burst)[i] = psk8_table[7];
+ burst[i] = psk8_table[7];
/* Body */
for (; i < tail + data; i++)
- (*burst)[i] = psk8_table[rand() % 8];
+ burst[i] = psk8_table[rand() % 8];
/* TSC */
for (n = 0; i < tail + data + train; i++, n++) {
@@ -939,19 +929,18 @@
(((unsigned) (*midamble)[3 * n + 1] & 0x01) << 1) |
(((unsigned) (*midamble)[3 * n + 2] & 0x01) << 2);
- (*burst)[i] = psk8_table[index];
+ burst[i] = psk8_table[index];
}
/* Body */
for (; i < tail + data + train + data; i++)
- (*burst)[i] = psk8_table[rand() % 8];
+ burst[i] = psk8_table[rand() % 8];
/* Tail */
for (; i < tail + data + train + data + tail; i++)
- (*burst)[i] = psk8_table[7];
+ burst[i] = psk8_table[7];
- shape = shapeEdgeBurst(*burst);
- delete burst;
+ shape = shapeEdgeBurst(burst);
return shape;
}
@@ -989,7 +978,7 @@
int guard_len, int sps)
{
int burst_len;
- signalVector *pulse, *burst, *shaped;
+ signalVector *pulse, *shaped;
signalVector::iterator burst_itr;
if (sps == 1)
@@ -999,9 +988,9 @@
burst_len = sps * (bits.size() + guard_len);
- burst = new signalVector(burst_len, pulse->size());
- burst->isReal(true);
- burst_itr = burst->begin();
+ signalVector burst(burst_len, pulse->size());
+ burst.isReal(true);
+ burst_itr = burst.begin();
/* Raw bits are not differentially encoded */
for (unsigned i = 0; i < bits.size(); i++) {
@@ -1009,13 +998,11 @@
burst_itr += sps;
}
- GMSKRotate(*burst, sps);
- burst->isReal(false);
+ GMSKRotate(burst, sps);
+ burst.isReal(false);
/* Single Gaussian pulse approximation shaping */
- shaped = convolve(burst, pulse, NULL, START_ONLY);
-
- delete burst;
+ shaped = convolve(&burst, pulse, NULL, START_ONLY);
return shaped;
}
@@ -1516,19 +1503,16 @@
static signalVector *downsampleBurst(const signalVector &burst)
{
- signalVector *in, *out;
+ signalVector in(DOWNSAMPLE_IN_LEN, dnsampler->len());
+ signalVector *out = new signalVector(DOWNSAMPLE_OUT_LEN);
+ memcpy(in.begin(), burst.begin(), DOWNSAMPLE_IN_LEN * 2 * sizeof(float));
- in = new signalVector(DOWNSAMPLE_IN_LEN, dnsampler->len());
- out = new signalVector(DOWNSAMPLE_OUT_LEN);
- memcpy(in->begin(), burst.begin(), DOWNSAMPLE_IN_LEN * 2 * sizeof(float));
-
- if (dnsampler->rotate((float *) in->begin(), DOWNSAMPLE_IN_LEN,
+ if (dnsampler->rotate((float *) in.begin(), DOWNSAMPLE_IN_LEN,
(float *) out->begin(), DOWNSAMPLE_OUT_LEN) < 0) {
delete out;
out = NULL;
}
- delete in;
return out;
};
@@ -1621,7 +1605,6 @@
{
int rc, start, len;
bool clipping = false;
- signalVector *corr;
if ((sps != 1) && (sps != 4))
return -SIGERR_UNSUPPORTED;
@@ -1637,12 +1620,10 @@
start = target - head - 1;
len = head + tail;
- corr = new signalVector(len);
+ signalVector corr(len);
- rc = detectBurst(rxBurst, *corr, sync,
+ rc = detectBurst(rxBurst, corr, sync,
thresh, sps, &, &toa, start, len);
- delete corr;
-
if (rc < 0) {
return -SIGERR_INTERNAL;
} else if (!rc) {
--
To view, visit https://gerrit.osmocom.org/2920
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If53da1bf77b5944b6117765fa98ce12e1ccdeede
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Tom Tsou <tom at tsou.cc>