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

Modified Files:
        AudioIO.h AudioIO.cpp 
Log Message:
Fix jumping to end of track when seeking
Fix "Play at Speed" (transcription toolbar) timing to stop at the correct time 
and to provide proper indicator positioning.

Index: AudioIO.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudioIO.cpp,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -d -r1.155 -r1.156
--- AudioIO.cpp 29 Mar 2007 04:30:46 -0000      1.155
+++ AudioIO.cpp 25 Apr 2007 03:46:00 -0000      1.156
@@ -884,13 +884,20 @@
    mTime    = t0;
    mSeek    = 0;
    mLastRecordingOffset = 0;
-   mPlaySpeed = 100.0 / (timeTrack ? timeTrack->GetRangeUpper() : 100);
    mPlaybackTracks = playbackTracks;
    mCaptureTracks  = captureTracks;
    mPlayLooped = playLooped;
    mCutPreviewGapStart = cutPreviewGapStart;
    mCutPreviewGapLen = cutPreviewGapLen;
 
+   mPlaySpeed = 1.0;
+   if (timeTrack) {
+      mPlaySpeed = timeTrack->GetEnvelope()->GetValue(t0);
+      mPlaySpeed = 1 / ((timeTrack->GetRangeLower() * (1 - mPlaySpeed) +
+                        mPlaySpeed * timeTrack->GetRangeUpper())/100.0);
+   }
+   mWarpedT1 = mT0 + ((mT1 - mT0) * mPlaySpeed);
+
    //
    // The RingBuffer sizes, and the max amount of the buffer to
    // fill at a time, both grow linearly with the number of
@@ -964,7 +971,7 @@
          mPlaybackBuffers[i] = new RingBuffer(floatSample, playbackBufferSize);
 
          mPlaybackMixers[i]  = new Mixer(1, &mPlaybackTracks[i],
-                                         timeTrack, mT0, mT1, 1,
+                                         timeTrack, mT0, mWarpedT1, 1,
                                          playbackMixBufferSize, false,
                                          mRate, floatSample, false);
          mPlaybackMixers[i]->ApplyTrackGains(false);
@@ -1312,7 +1319,7 @@
          absoluteTime += mCutPreviewGapLen;
    }
 
-   return absoluteTime / mPlaySpeed;
+   return absoluteTime;
 }
 
 double AudioIO::GetStreamTime()
@@ -1672,7 +1679,7 @@
       // region - then we should just fill the buffer.
       //
       if (secsAvail >= mMaxPlaybackSecsToCopy ||
-          (!mPlayLooped && (secsAvail > 0 && mT+secsAvail >= mT1)))
+          (!mPlayLooped && (secsAvail > 0 && mT+secsAvail >= mWarpedT1)))
       {
          // Limit maximum buffer size (increases performance)
          if (secsAvail > mMaxPlaybackSecsToCopy)
@@ -1686,9 +1693,9 @@
          // This is the purpose of this loop.
          do {
             deltat = secsAvail;
-            if( mT + deltat > mT1 )
+            if( mT + deltat > mWarpedT1 )
             {
-               deltat = mT1 - mT;
+               deltat = mWarpedT1 - mT;
                if( deltat < 0.0 )
                   deltat = 0.0;
             }
@@ -1702,14 +1709,14 @@
                // resampling, format conversion, and possibly time track
                // warping
                int processed =
-                  mPlaybackMixers[i]->Process((int)(deltat * mRate + 0.5));
+                  mPlaybackMixers[i]->Process(lrint(deltat * mRate));
                samplePtr warpedSamples = mPlaybackMixers[i]->GetBuffer();
                mPlaybackBuffers[i]->Put(warpedSamples, floatSample, processed);
             }
 
             // msmeyer: If playing looped, check if we are at the end of the 
buffer
             // and if yes, restart from the beginning.
-            if (mPlayLooped && mT >= mT1)
+            if (mPlayLooped && mT >= mWarpedT1)
             {
                for (i = 0; i < mPlaybackTracks.GetCount(); i++)
                   mPlaybackMixers[i]->Restart();
@@ -1914,6 +1921,7 @@
                gAudioIO->mPlaybackMixers[i]->Reposition( gAudioIO->mTime );
                gAudioIO->mPlaybackBuffers[i]->Discard( 
gAudioIO->mPlaybackBuffers[i]->AvailForGet() );
             }
+            gAudioIO->mT = gAudioIO->mTime;
 
             // Reload the ring buffers
             gAudioIO->mAudioThreadShouldCallFillBuffersOnce = true;
@@ -1968,7 +1976,7 @@
             // the end, then we've actually finished playing the entire
             // selection.
             // msmeyer: We never finish if we are playing looped
-            if (len == 0 && gAudioIO->mT >= gAudioIO->mT1 &&
+            if (len == 0 && gAudioIO->mTime >= gAudioIO->mT1 &&
                 !gAudioIO->mPlayLooped)
             {
              #if USE_PORTAUDIO_V19
@@ -1979,6 +1987,12 @@
              #endif
             }
 
+            // Wrap to start if looping
+            if (gAudioIO->mPlayLooped && gAudioIO->mTime >= gAudioIO->mT1)
+            {
+               gAudioIO->mTime = gAudioIO->mT0 + (gAudioIO->mTime - 
gAudioIO->mT1);
+            }
+
             if (vt->GetChannel() == Track::LeftChannel ||
                 vt->GetChannel() == Track::MonoChannel)
             {
@@ -2087,7 +2101,7 @@
       }
       
       // Update the current time position
-      gAudioIO->mTime += (framesPerBuffer / gAudioIO->mRate);
+      gAudioIO->mTime += ((framesPerBuffer / gAudioIO->mRate) / 
gAudioIO->mPlaySpeed);
       
       // Record the reported latency from PortAudio.
       // TODO: Don't recalculate this with every callback?

Index: AudioIO.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/AudioIO.h,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- AudioIO.h   19 Nov 2006 19:03:40 -0000      1.47
+++ AudioIO.h   25 Apr 2007 03:46:00 -0000      1.48
@@ -215,6 +215,7 @@
    double              mT0;
    double              mT1;
    double              mTime;
+   double              mWarpedT1;
    double              mSeek;
    double              mPlaySpeed;
    double              mPlaybackRingBufferSecs;


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to