aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2016-04-22 02:39:35 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2016-04-22 02:41:57 +0300
commit63f950fc474a0b371feee74485192c11bed03187 (patch)
treebc06bbb5ced51fa25ddc279147e2ac022621867b
parent03026f0bc68748b95bfe774ff48f88985cd9690a (diff)
downloadatracdenc-63f950fc474a0b371feee74485192c11bed03187.tar.gz
Fix memory corruption: wrong size of HPFBuffer.
-rw-r--r--src/transient_detector.cpp12
-rw-r--r--src/transient_detector.h5
2 files changed, 8 insertions, 9 deletions
diff --git a/src/transient_detector.cpp b/src/transient_detector.cpp
index fb46aad..43897d6 100644
--- a/src/transient_detector.cpp
+++ b/src/transient_detector.cpp
@@ -13,25 +13,23 @@ static double calculateRMS(const double* in, uint32_t n) {
}
void TTransientDetector::HPFilter(const double* in, double* out) {
- const uint32_t firLen = 21;
static const double fircoef[] = {
-8.65163e-18 * 2.0, -0.00851586 * 2.0, -6.74764e-18 * 2.0, 0.0209036 * 2.0,
-3.36639e-17 * 2.0, -0.0438162 * 2.0, -1.54175e-17 * 2.0, 0.0931738 * 2.0,
-5.52212e-17 * 2.0, -0.313819 * 2.0
};
- const uint32_t x = prevBufSz;
- memcpy(HPFBuffer.data() + x, in, BlockSz * sizeof(double));
+ memcpy(HPFBuffer.data() + PrevBufSz, in, BlockSz * sizeof(double));
const double* inBuf = HPFBuffer.data();
for (int i = 0; i < BlockSz; ++i) {
double s = inBuf[i + 10];
double s2 = 0;
- for (int j = 0; j < ((firLen - 1) / 2) - 1 ; j += 2) {
- s += fircoef[j] * (inBuf[i + j] + inBuf[i + firLen - j]);
- s2 += fircoef[j + 1] * (inBuf[i + j + 1] + inBuf[i + firLen - j - 1]);
+ for (int j = 0; j < ((FIRLen - 1) / 2) - 1 ; j += 2) {
+ s += fircoef[j] * (inBuf[i + j] + inBuf[i + FIRLen - j]);
+ s2 += fircoef[j + 1] * (inBuf[i + j + 1] + inBuf[i + FIRLen - j - 1]);
}
out[i] = (s + s2)/2;
}
- memcpy(HPFBuffer.data(), in + (BlockSz - x), x * sizeof(double));
+ memcpy(HPFBuffer.data(), in + (BlockSz - PrevBufSz), PrevBufSz * sizeof(double));
}
diff --git a/src/transient_detector.h b/src/transient_detector.h
index 9e066d4..b3db6ba 100644
--- a/src/transient_detector.h
+++ b/src/transient_detector.h
@@ -8,7 +8,8 @@ class TTransientDetector {
const uint32_t ShortSz;
const uint32_t BlockSz;
const uint32_t NShortBlocks;
- static const uint32_t prevBufSz = 20;
+ static const uint32_t PrevBufSz = 20;
+ static const uint32_t FIRLen = 21;
void HPFilter(const double* in, double* out);
std::vector<double> HPFBuffer;
double LastEnergy = 0.0;
@@ -18,7 +19,7 @@ public:
, BlockSz(blockSz)
, NShortBlocks(blockSz/shortSz)
{
- HPFBuffer.resize(BlockSz + prevBufSz);
+ HPFBuffer.resize(BlockSz + FIRLen);
}
bool Detect(const double* buf);
};