Update of /cvsroot/audacity/audacity-src/src
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv15640/src

Modified Files:
        TrackArtist.cpp TrackPanel.cpp WaveClip.cpp WaveClip.h 
Log Message:
Introduced new SpecPxCach to speed up the drawing of selections on spectrograms 
- my measurements say it halves the time taken to draw the highlighting of the 
selection on a Spectrogram, and it makes the user experince better.
Fixed a bug when maxFreq is beyond current track's nyquist frequency.
Update all the tracks that have a Spectrogram displayed, not just the first one 
like it did before.

Index: WaveClip.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/WaveClip.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- WaveClip.h  24 Jan 2007 01:13:33 -0000      1.17
+++ WaveClip.h  29 Jan 2007 00:48:25 -0000      1.18
@@ -30,6 +30,25 @@
 class WaveClip;
 class WaveClipList;
 
+class SpecPxCache {
+public:
+   SpecPxCache(int cacheLen)
+   {
+      len = cacheLen;
+      values = new float[len];
+      valid = false;
+   }
+
+   ~SpecPxCache()
+   {
+      delete[] values;
+   }
+
+   sampleCount  len;
+   float       *values;
+   bool         valid;
+};
+
 WX_DECLARE_LIST(WaveClip, WaveClipList);
 
 class WaveClip: public XMLTagHandler
@@ -178,6 +197,9 @@
    virtual XMLTagHandler *HandleXMLChild(const wxChar *tag);
    virtual void WriteXML(XMLWriter &xmlFile);
 
+   // Cache of values to colour pixels of Spectrogram - used by TrackArtist
+   SpecPxCache    *mSpecPxCache;
+
 protected:
    wxRect mDisplayRect;
 

Index: WaveClip.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/WaveClip.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- WaveClip.cpp        25 Jan 2007 03:01:11 -0000      1.27
+++ WaveClip.cpp        29 Jan 2007 00:48:25 -0000      1.28
@@ -21,7 +21,7 @@
 
 \class SpecCache
 \brief Cache used with WaveClip to cache spectrum information (for
-drawing).
+drawing).  Cache's the Spectrogram frequency samples.
 
 *//*******************************************************************/
 
@@ -102,7 +102,6 @@
    float       *freq;
 };
 
-
 WaveClip::WaveClip(DirManager *projDirManager, sampleFormat format, int rate)
 {
    mOffset = 0;
@@ -111,6 +110,7 @@
    mEnvelope = new Envelope();
    mWaveCache = new WaveCache(1);
    mSpecCache = new SpecCache(1, 1, false);
+   mSpecPxCache = new SpecPxCache(1);
    mAppendBuffer = NULL;
    mAppendBufferLen = 0;
    mDirty = 0;
@@ -131,6 +131,7 @@
    mEnvelope->SetTrackLen(orig.mSequence->GetNumSamples() / orig.mRate);
    mWaveCache = new WaveCache(1);
    mSpecCache = new SpecCache(1, 1, false);
+   mSpecPxCache = new SpecPxCache(1);
 
    for (WaveClipList::Node* it=orig.mCutLines.GetFirst(); it; it=it->GetNext())
       mCutLines.Append(new WaveClip(*it->GetData(), projDirManager));
@@ -146,6 +147,7 @@
    delete mEnvelope;
    delete mWaveCache;
    delete mSpecCache;
+   delete mSpecPxCache;
 
    if (mAppendBuffer)
       DeleteSamples(mAppendBuffer);
@@ -392,7 +394,7 @@
        mSpecCache->pps == pixelsPerSecond) {
       memcpy(freq, mSpecCache->freq, numPixels*half*sizeof(float));
       memcpy(where, mSpecCache->where, (numPixels+1)*sizeof(sampleCount));
-      return true;
+      return false;  //hit cache completely
    }
 
    SpecCache *oldCache = mSpecCache;

Index: TrackArtist.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/TrackArtist.cpp,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- TrackArtist.cpp     28 Jan 2007 16:03:23 -0000      1.90
+++ TrackArtist.cpp     29 Jan 2007 00:48:25 -0000      1.91
@@ -315,7 +315,13 @@
       double rate = ((WaveTrack *) t)->GetRate();
       int windowSize = gPrefs->Read(wxT("/Spectrum/FFTSize"), 256);
       int maxFreq = gPrefs->Read(wxT("/Spectrum/MaxFreq"), rate/2.);
+      if(maxFreq > rate/2.)
+         maxFreq = rate/2.;
       int minFreq = gPrefs->Read(wxT("/Spectrum/MinFreq"), 0.);
+      if(minFreq < 0) {
+         minFreq = 0.;
+         gPrefs->Write(wxT("/Spectrum/MinFreq"), 0L);
+      }
 
       /*
          draw the ruler
@@ -1413,19 +1419,31 @@
    float *freq = new float[mid.width * half];
    sampleCount *where = new sampleCount[mid.width+1];
 
-   if (!clip->GetSpectrogram(freq, where, mid.width,
-                              t0, pps, autocorrelation)) {
-      delete image;
-      delete[] where;
-      delete[] freq;
-      return;
-   }
-
+   bool updated = clip->GetSpectrogram(freq, where, mid.width,
+                              t0, pps, autocorrelation);
    bool isGrayscale = false;
    gPrefs->Read(wxT("/Spectrum/Grayscale"), &isGrayscale, false);
    int maxFreq = gPrefs->Read(wxT("/Spectrum/MaxFreq"), rate/2.);
+   if(maxFreq > rate/2.)
+      maxFreq = rate/2.;
    int minFreq = gPrefs->Read(wxT("/Spectrum/MinFreq"), 0L);
-   int minSamples = int (minFreq * windowSize / rate + 0.5);   // units here 
are fft bins
+   if(minFreq < 0) {
+      minFreq = 0.;
+      gPrefs->Write(wxT("/Spectrum/MinFreq"), 0L);
+   }
+   bool usePxCache = false;
+
+   if( !updated && clip->mSpecPxCache->valid && (clip->mSpecPxCache->len == 
mid.height * mid.width) ) {
+      usePxCache = true;
+   }
+   else {
+      delete clip->mSpecPxCache;
+      clip->mSpecPxCache = new SpecPxCache(mid.width * mid.height);
+      usePxCache = false;
+      clip->mSpecPxCache->valid = true;
+   }
+
+   int minSamples = int (minFreq * windowSize / rate + 0.5);   // units are 
fft bins
    int maxSamples = int (maxFreq * windowSize / rate + 0.5);
    float binPerPx = float(maxSamples - minSamples) / float(mid.height);
 
@@ -1438,37 +1456,42 @@
       for (int yy = 0; yy < mid.height; yy++) {
          bool selflag = (ssel0 <= w0 && w1 < ssel1);
          unsigned char rv, gv, bv;
+         float value;
 
-         float bin0 = float (yy) * binPerPx + minSamples;
-         float bin1 = float (yy + 1) * binPerPx + minSamples;
+         if(!usePxCache) {
+            float bin0 = float (yy) * binPerPx + minSamples;
+            float bin1 = float (yy + 1) * binPerPx + minSamples;
 
-         float value;
 
-         if (int (bin1) == int (bin0))
-            value = freq[half * x + int (bin0)];
-         else {
-            float binwidth= bin1 - bin0;
-            value = freq[half * x + int (bin0)] * (1.f - bin0 + (int)bin0);
+            if (int (bin1) == int (bin0))
+               value = freq[half * x + int (bin0)];
+            else {
+               float binwidth= bin1 - bin0;
+               value = freq[half * x + int (bin0)] * (1.f - bin0 + (int)bin0);
 
-            bin0 = 1 + int (bin0);
-            while (bin0 < int (bin1)) {
-               value += freq[half * x + int (bin0)];
-               bin0 += 1.0;
+               bin0 = 1 + int (bin0);
+               while (bin0 < int (bin1)) {
+                  value += freq[half * x + int (bin0)];
+                  bin0 += 1.0;
+               }
+               value += freq[half * x + int (bin1)] * (bin1 - int (bin1));
+
+               value /= binwidth;
             }
-            value += freq[half * x + int (bin1)] * (bin1 - int (bin1));
 
-            value /= binwidth;
-         }
+            if (!autocorrelation) {
+               // Last step converts dB to a 0.0-1.0 range
+               value = (value + 80.0) / 80.0;
+            }
 
-         if (!autocorrelation) {
-            // Last step converts dB to a 0.0-1.0 range
-            value = (value + 80.0) / 80.0;
+            if (value > 1.0)
+               value = float(1.0);
+            if (value < 0.0)
+               value = float(0.0);
+            clip->mSpecPxCache->values[x * mid.height + yy] = value;
          }
-
-         if (value > 1.0)
-            value = float(1.0);
-         if (value < 0.0)
-            value = float(0.0);
+         else
+            value = clip->mSpecPxCache->values[x * mid.height + yy];
 
          GetColorGradient(value, selflag, isGrayscale, &rv, &gv, &bv);
 

Index: TrackPanel.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/TrackPanel.cpp,v
retrieving revision 1.337
retrieving revision 1.338
diff -u -d -r1.337 -r1.338
--- TrackPanel.cpp      28 Jan 2007 15:45:51 -0000      1.337
+++ TrackPanel.cpp      29 Jan 2007 00:48:25 -0000      1.338
@@ -2519,6 +2519,19 @@
    if(spectrum) {
       gPrefs->Write(wxT("/Spectrum/MaxFreq"), (long)max);
       gPrefs->Write(wxT("/Spectrum/MinFreq"), (long)min);
+      TrackListIterator iter(mTracks);
+      Track *t = iter.First();
+      while (t) {
+         if (t->GetKind() == Track::Wave) {
+            WaveTrack *wt = (WaveTrack *)t;
+            WaveClipList::Node* it;
+            for(it=wt->GetClipIterator(); it; it=it->GetNext()) {
+               WaveClip *clip = it->GetData();
+               clip->mSpecPxCache->valid = false;
+            }
+         }
+         t = iter.Next();
+      }
    }
    else {
       track->SetDisplayBounds(min, max);


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to