[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Wed Sep 14 21:57:31 CEST 2005


SVN commit 460695 by staikos:

- cleanup of formatting to make it much more legible
- convert a for-loop into a memset which will be much more efficient on
  optimized builds



 M  +28 -32    kstpsd.cpp  


--- trunk/extragear/graphics/kst/kst/kstpsd.cpp #460694:460695
@@ -24,6 +24,7 @@
 
 #include <qstylesheet.h>
 
+#include <kdebug.h>
 #include <kglobal.h>
 #include <klocale.h>
 
@@ -316,14 +317,9 @@
   }
 
   int i_subset, i_samp;
-  int n_subsets;
-  int v_len;
   int copyLen;
-  double *psd, *f;
   double mean;
-  double nf;
   KstVectorPtr iv = _inputVectors[INVECTOR];
-  bool done;
 
   if (update_counter <= 0) {
     assert(update_counter == 0);
@@ -334,30 +330,33 @@
 
   _adjustLengths();
 
-  v_len = iv->length();
-  n_subsets = v_len/_PSDLen+1;
-  if (v_len%_PSDLen==0) n_subsets--;
+  int v_len = iv->length();
+  int n_subsets = v_len / _PSDLen + 1;
+  if (v_len % _PSDLen == 0) {
+    --n_subsets;
+  }
 
   _last_n_new += iv->numNew();
+  assert(_last_n_new >= 0);
 
   if ((!xUpdated || (_last_n_new < _PSDLen/16 &&
           n_subsets - _last_n_subsets < 1 &&
-          iv->length() != iv->numNew())) && !force ) {
+          iv->length() != iv->numNew())) && !force) {
     return setLastUpdateResult(NO_CHANGE);
   }
 
-  psd = (*_sVector)->value();
-  f = (*_fVector)->value();
+  double *psd = (*_sVector)->value();
+  double *f = (*_fVector)->value();
 
-  for (i_samp = 0; i_samp < _PSDLen; i_samp++) {
+  for (i_samp = 0; i_samp < _PSDLen; ++i_samp) {
     psd[i_samp] = 0;
-    f[i_samp] = i_samp*0.5*_Freq/( _PSDLen-1 );
+    f[i_samp] = i_samp * 0.5 * _Freq / (_PSDLen - 1);
   }
 
-  nf = 0;
-  done = false;
+  double nf = 0;
+  bool done = false;
 
-  for (i_subset = 0; !done; i_subset++) {
+  for (i_subset = 0; !done; ++i_subset) {
     // copy each chunk into a[] and find mean
     if (i_subset*_PSDLen + _ALen < v_len) {
       copyLen = _ALen;
@@ -367,14 +366,12 @@
     }
 
     mean = 0;
-    for (i_samp = 0; i_samp < copyLen; i_samp++) {
-      mean += (
-        _a[i_samp] =
-        iv->interpolate(i_samp + i_subset*_PSDLen, v_len)
-        );
+    for (i_samp = 0; i_samp < copyLen; ++i_samp) {
+      _a[i_samp] = iv->interpolate(i_samp + i_subset*_PSDLen, v_len);
+      mean += _a[i_samp];
     }
     if (copyLen > 1) {
-      mean /= (double)copyLen;
+      mean /= double(copyLen);
     }
 
     if (apodize()) {
@@ -383,32 +380,31 @@
      
     // remove mean and apodize
     if (removeMean() && apodize()) {
-      for (i_samp=0; i_samp<copyLen; i_samp++) {
-        _a[i_samp]= (_a[i_samp]-mean)*_w[i_samp];
+      for (i_samp = 0; i_samp < copyLen; ++i_samp) {
+        _a[i_samp]= (_a[i_samp] - mean)*_w[i_samp];
       }
     } else if (removeMean()) {
-      for (i_samp=0; i_samp<copyLen; i_samp++) {
+      for (i_samp = 0; i_samp < copyLen; ++i_samp) {
         _a[i_samp] -= mean;
       }
     } else if (apodize()) {
-      for (i_samp=0; i_samp<copyLen; i_samp++) {
+      for (i_samp = 0; i_samp < copyLen; ++i_samp) {
         _a[i_samp] *= _w[i_samp];
       }
     }
 
     nf += copyLen;
 
-
-    for (;i_samp < _ALen; i_samp++) {
-      _a[i_samp] = 0.0;
+    if (i_samp < _ALen) {
+      memset(&_a[i_samp], 0, sizeof(double)*(_ALen - i_samp));
     }
 
     // fft a
     rdft(_ALen, 1, _a);
     psd[0] += _a[0]*_a[0];
     psd[_PSDLen-1] += _a[1]*_a[1];
-    for (i_samp=1; i_samp<_PSDLen-1; i_samp++) {
-      psd[i_samp]+= cabs2(_a[i_samp*2], _a[i_samp*2+1]);
+    for (i_samp = 1; i_samp < _PSDLen - 1; ++i_samp) {
+      psd[i_samp] += cabs2(_a[i_samp*2], _a[i_samp*2 + 1]);
     }
   }
 
@@ -417,7 +413,7 @@
   _last_n_new = 0;
 
   nf = 1.0/(double(_Freq)*double(nf/2.0));
-  for ( i_samp = 0; i_samp<_PSDLen; i_samp++ ) {
+  for (i_samp = 0; i_samp < _PSDLen; ++i_samp) {
     psd[i_samp] = sqrt(psd[i_samp]*nf);
   }
 


More information about the Kst mailing list