~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to src/Mix.cpp

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "Prefs.h"
40
40
#include "Project.h"
41
41
#include "Resample.h"
 
42
#include "float_cast.h"
42
43
 
43
44
bool MixAndRender(TrackList *tracks, TrackFactory *trackFactory,
44
45
                  double rate, sampleFormat format,
318
319
                                    int *queueStart, int *queueLen,
319
320
                                    Resample *SRC)
320
321
{
321
 
   double initialWarp = mRate / track->GetRate();
322
 
   double t = *pos / track->GetRate();
 
322
   double trackRate = track->GetRate();
 
323
   double initialWarp = mRate / trackRate;
 
324
   double t = *pos / trackRate;
323
325
   int sampleSize = SAMPLE_SIZE(floatSample);
324
326
   int i, c;
325
327
 
326
328
   sampleCount out = 0;
327
329
 
 
330
   // Find the last sample
 
331
   longSampleCount last = -1;
 
332
   WaveClipList::Node* it = track->GetClipIterator();
 
333
   while (it) {
 
334
      longSampleCount end = it->GetData()->GetEndSample();
 
335
      if (end > last) {
 
336
         last = end;
 
337
      }
 
338
      it = it->GetNext();
 
339
   }
 
340
 
 
341
   longSampleCount max = trackRate * mT1;
 
342
   if (last > max)
 
343
      last = max;
 
344
 
328
345
   while(out < mMaxOut) {
329
346
      if (*queueLen < mProcessLen) {
330
 
         memmove(queue, &queue[*queueStart],
331
 
                 (*queueLen)*sampleSize);
 
347
         memmove(queue, &queue[*queueStart], (*queueLen)*sampleSize);
332
348
         *queueStart = 0;
333
349
 
334
350
         int getLen = mQueueMaxLen - *queueLen;
335
351
 
336
 
         #if 0
337
 
 
338
 
         // TODO: fix this code so that extra silence isn't added
339
 
         // to the end of a track
340
 
 
341
 
         double trackTime = (*pos + getLen) / track->GetRate();
342
 
         if (trackTime > track->GetEndTime()) {
343
 
            getLen = (int)(0.5 + track->GetRate() *
344
 
                           (track->GetEndTime() -
345
 
                            ((*pos) / track->GetRate())));
346
 
         }
347
 
         #endif
 
352
         // Constrain
 
353
         if (*pos + getLen > last) {
 
354
            getLen = last - *pos;
 
355
         }
 
356
 
 
357
         // Nothing to do if past end of track
 
358
         if (getLen <= 0) {
 
359
            break;
 
360
         }
348
361
 
349
362
         track->Get((samplePtr)&queue[*queueLen], floatSample,
350
363
                    *pos, getLen);
351
364
 
352
 
         track->GetEnvelopeValues(mEnvValues, getLen, (*pos) / track->GetRate(),
353
 
                                  1.0 / track->GetRate());
 
365
         track->GetEnvelopeValues(mEnvValues, getLen, (*pos) / trackRate,
 
366
                                  1.0 / trackRate);
354
367
 
355
368
         for(i=0; i<getLen; i++)
356
369
            queue[(*queueLen)+i] *= mEnvValues[i];
387
400
      *queueStart += input_used;
388
401
      *queueLen -= input_used;
389
402
      out += outgen;
390
 
      t += (input_used / track->GetRate());
 
403
      t += (input_used / trackRate);
391
404
 
392
405
      if (last)
393
406
         break;
400
413
         mGains[c] = 1.0;
401
414
 
402
415
   MixBuffers(mNumChannels, channelFlags, mGains,
403
 
              (samplePtr)mFloatBuffer, mTemp, mMaxOut, mInterleaved);
 
416
              (samplePtr)mFloatBuffer, mTemp, out, mInterleaved);
404
417
 
405
 
   return mMaxOut;
 
418
   return out;
406
419
}
407
420
 
408
421
sampleCount Mixer::MixSameRate(int *channelFlags, WaveTrack *track,
444
457
{
445
458
   if (mT >= mT1)
446
459
      return 0;
447
 
   
 
460
 
448
461
   int i, j;
449
462
   sampleCount out;
450
463
   sampleCount maxOut = 0;
543
556
      mT = mT0;
544
557
   if( mT > mT1 )
545
558
      mT = mT1;
546
 
   
 
559
 
547
560
   for(i=0; i<mNumInputTracks; i++) {
548
561
      mSamplePos[i] = mInputTrack[i]->TimeToLongSamples(mT);
549
562
      mQueueStart[i] = 0;