Update of /cvsroot/audacity/audacity-src/src/effects
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv6083
Modified Files:
SoundTouchEffect.cpp ChangeSpeed.cpp ChangeSpeed.h
Log Message:
Do not shift start time of tracks unnecessarily.
Index: SoundTouchEffect.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/SoundTouchEffect.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- SoundTouchEffect.cpp 8 Aug 2006 02:40:45 -0000 1.9
+++ SoundTouchEffect.cpp 3 Jun 2007 18:04:34 -0000 1.10
@@ -1,14 +1,14 @@
/**********************************************************************
- Audacity: A Digital Audio Editor
+Audacity: A Digital Audio Editor
- SoundTouchEffect.cpp
+SoundTouchEffect.cpp
- Dominic Mazzoni, Vaughan Johnson
+Dominic Mazzoni, Vaughan Johnson
- This abstract class contains all of the common code for an
- effect that uses SoundTouch to do its processing (ChangeTempo
- and ChangePitch).
+This abstract class contains all of the common code for an
+effect that uses SoundTouch to do its processing (ChangeTempo
+ and ChangePitch).
**********************************************************************/
@@ -26,39 +26,58 @@
{
// Assumes that mSoundTouch has already been initialized
// by the subclass for subclass-specific parameters.
-
+
//Iterate over each track
TrackListIterator iter(mWaveTracks);
WaveTrack* leftTrack = (WaveTrack*)(iter.First());
- WaveTrack* rightTrack = NULL;
mCurTrackNum = 0;
m_maxNewLength = 0.0;
while (leftTrack) {
//Get start and end times from track
- double trackStart = leftTrack->GetStartTime();
- double trackEnd = leftTrack->GetEndTime();
-
+ mCurT0 = leftTrack->GetStartTime();
+ mCurT1 = leftTrack->GetEndTime();
+
//Set the current bounds to whichever left marker is
- //greater and whichever right marker is less:
- mCurT0 = mT0 < trackStart? trackStart: mT0;
- mCurT1 = mT1 > trackEnd? trackEnd: mT1;
-
+ //greater and whichever right marker is less
+ mCurT0 = wxMax(mT0, mCurT0);
+ mCurT1 = wxMin(mT1, mCurT1);
+
// Process only if the right marker is to the right of the left marker
if (mCurT1 > mCurT0) {
-
- //Transform the marker timepoints to samples
- longSampleCount start = leftTrack->TimeToLongSamples(mCurT0);
- longSampleCount end = leftTrack->TimeToLongSamples(mCurT1);
+ longSampleCount start, end;
- rightTrack = NULL;
if (leftTrack->GetLinked()) {
- rightTrack = (WaveTrack*)(iter.Next());
+ double t;
+ WaveTrack* rightTrack = (WaveTrack*)(iter.Next());
+
+ //Adjust bounds by the right tracks markers
+ t = rightTrack->GetStartTime();
+ t = wxMax(mT0, t);
+ mCurT0 = wxMin(mCurT0, t);
+ t = rightTrack->GetEndTime();
+ t = wxMin(mT1, t);
+ mCurT1 = wxMax(mCurT1, t);
+
+ //Transform the marker timepoints to samples
+ start = leftTrack->TimeToLongSamples(mCurT0);
+ end = leftTrack->TimeToLongSamples(mCurT1);
+
+ //Inform soundtouch there's 2 channels
mSoundTouch->setChannels(2);
+
+ //ProcessStereo() (implemented below) processes a stereo track
if (!ProcessStereo(leftTrack, rightTrack, start, end))
return false;
+
mCurTrackNum++; // Increment for rightTrack, too.
} else {
+ //Transform the marker timepoints to samples
+ start = leftTrack->TimeToLongSamples(mCurT0);
+ end = leftTrack->TimeToLongSamples(mCurT1);
+
+ //Inform soundtouch there's a single channel
mSoundTouch->setChannels(1);
+
//ProcessOne() (implemented below) processes a single track
if (!ProcessOne(leftTrack, start, end))
return false;
@@ -69,11 +88,12 @@
leftTrack = (WaveTrack*)(iter.Next());
mCurTrackNum++;
}
-
+
delete mSoundTouch;
mSoundTouch = NULL;
-
- mT1 = mT0 + m_maxNewLength; // Update selection.
+
+// mT0 = mCurT0;
+// mT1 = mCurT0 + m_maxNewLength; // Update selection.
return true;
}
@@ -84,37 +104,37 @@
{
WaveTrack *outputTrack;
longSampleCount s;
-
+
mSoundTouch->setSampleRate((unsigned int)(track->GetRate()+0.5));
outputTrack = mFactory->NewWaveTrack(track->GetSampleFormat(),
track->GetRate());
-
+
//Get the length of the buffer (as double). len is
//used simple to calculate a progress meter, so it is easier
//to make it a double now than it is to do it later
double len = (double)(end - start);
-
+
//Initiate a processing buffer. This buffer will (most likely)
//be shorter than the length of the track being processed.
float *buffer = new float[track->GetMaxBlockSize()];
-
+
//Go through the track one buffer at a time. s counts which
//sample the current buffer starts at.
s = start;
while (s < end) {
//Get a block of samples (smaller than the size of the buffer)
sampleCount block = track->GetBestBlockSize(s);
-
+
//Adjust the block size if it is the final block in the track
if (s + block > end)
block = end - s;
-
+
//Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer, floatSample, s, block);
-
+
//Add samples to SoundTouch
mSoundTouch->putSamples(buffer, block);
-
+
//Get back samples from SoundTouch
unsigned int outputCount = mSoundTouch->numSamples();
if (outputCount > 0) {
@@ -123,18 +143,18 @@
outputTrack->Append((samplePtr)buffer2, floatSample, outputCount);
delete[] buffer2;
}
-
+
//Increment s one blockfull of samples
s += block;
-
+
//Update the Progress meter
if (TrackProgress(mCurTrackNum, (s - start) / len))
return false;
}
-
+
// Tell SoundTouch to finish processing any remaining samples
mSoundTouch->flush();
-
+
unsigned int outputCount = mSoundTouch->numSamples();
if (outputCount > 0) {
float *buffer2 = new float[outputCount];
@@ -142,45 +162,44 @@
outputTrack->Append((samplePtr)buffer2, floatSample, outputCount);
delete[] buffer2;
}
-
+
// Flush the output WaveTrack (since it's buffered, too)
outputTrack->Flush();
-
+
// Clean up the buffer
delete[]buffer;
-
+
// Take the output track and insert it in place of the original
// sample data
-
- track->Clear(mT0, mT1);
- track->Paste(mT0, outputTrack);
-
- double newLength = outputTrack->GetEndTime();
- if (newLength > m_maxNewLength)
- m_maxNewLength = newLength;
-
+
+ track->Clear(mCurT0, mCurT1);
+ track->Paste(mCurT0, outputTrack);
+
+ double newLength = outputTrack->GetEndTime();
+ m_maxNewLength = wxMax(m_maxNewLength, newLength);
+
// Delete the outputTrack now that its data is inserted in place
delete outputTrack;
-
+
//Return true because the effect processing succeeded.
return true;
}
bool EffectSoundTouch::ProcessStereo(WaveTrack* leftTrack, WaveTrack*
rightTrack,
- longSampleCount start, longSampleCount
end)
+ longSampleCount start, longSampleCount
end)
{
mSoundTouch->setSampleRate((unsigned int)(leftTrack->GetRate()+0.5));
WaveTrack* outputLeftTrack =
mFactory->NewWaveTrack(leftTrack->GetSampleFormat(),
leftTrack->GetRate());
WaveTrack* outputRightTrack =
mFactory->NewWaveTrack(rightTrack->GetSampleFormat(),
- rightTrack->GetRate());
-
+ rightTrack->GetRate());
+
//Get the length of the buffer (as double). len is
//used simple to calculate a progress meter, so it is easier
//to make it a double now than it is to do it later
double len = (double)(end - start);
-
+
//Initiate a processing buffer. This buffer will (most likely)
//be shorter than the length of the track being processed.
// Make soundTouchBuffer twice as big as MaxBlockSize for each channel,
@@ -190,7 +209,7 @@
float* leftBuffer = new float[maxBlockSize];
float* rightBuffer = new float[maxBlockSize];
float* soundTouchBuffer = new float[maxBlockSize * 2];
-
+
// Go through the track one stereo buffer at a time.
// sourceSampleCount counts the sample at which the current buffer starts,
// per channel.
@@ -198,68 +217,70 @@
while (sourceSampleCount < end) {
//Get a block of samples (smaller than the size of the buffer)
sampleCount blockSize = leftTrack->GetBestBlockSize(sourceSampleCount);
-
+
//Adjust the block size if it is the final block in the track
if (sourceSampleCount + blockSize > end)
blockSize = end - sourceSampleCount;
-
+
// Get the samples from the tracks and put them in the buffers.
leftTrack->Get((samplePtr)(leftBuffer), floatSample, sourceSampleCount,
blockSize);
rightTrack->Get((samplePtr)(rightBuffer), floatSample,
sourceSampleCount, blockSize);
-
+
// Interleave into soundTouchBuffer.
for (int index = 0; index < blockSize; index++) {
soundTouchBuffer[index*2] = leftBuffer[index];
soundTouchBuffer[(index*2)+1] = rightBuffer[index];
}
-
+
//Add samples to SoundTouch
mSoundTouch->putSamples(soundTouchBuffer, blockSize);
-
+
//Get back samples from SoundTouch
unsigned int outputCount = mSoundTouch->numSamples();
if (outputCount > 0)
this->ProcessStereoResults(outputCount, outputLeftTrack,
outputRightTrack);
-
+
//Increment sourceSampleCount one blockfull of samples
sourceSampleCount += blockSize;
-
+
//Update the Progress meter
if (TrackProgress(mCurTrackNum, (sourceSampleCount - start) / len))
return false;
}
-
+
// Tell SoundTouch to finish processing any remaining samples
mSoundTouch->flush();
-
+
unsigned int outputCount = mSoundTouch->numSamples();
if (outputCount > 0)
this->ProcessStereoResults(outputCount, outputLeftTrack,
outputRightTrack);
-
+
// Flush the output WaveTracks (since they're buffered, too)
outputLeftTrack->Flush();
outputRightTrack->Flush();
-
+
// Clean up the buffers.
delete [] leftBuffer;
delete [] rightBuffer;
delete [] soundTouchBuffer;
-
+
// Take the output tracks and insert in place of the original
// sample data.
- leftTrack->Clear(mT0, mT1);
- leftTrack->Paste(mT0, outputLeftTrack);
- rightTrack->Clear(mT0, mT1);
- rightTrack->Paste(mT0, outputRightTrack);
-
- double newLength = outputLeftTrack->GetEndTime();
- if (newLength > m_maxNewLength)
- m_maxNewLength = newLength;
+ leftTrack->Clear(mCurT0, mCurT1);
+ leftTrack->Paste(mCurT0, outputLeftTrack);
+ rightTrack->Clear(mCurT0, mCurT1);
+ rightTrack->Paste(mCurT0, outputRightTrack);
+ // Track the longest result length
+ double newLength = outputLeftTrack->GetEndTime();
+ m_maxNewLength = wxMax(m_maxNewLength, newLength);
+ newLength = outputRightTrack->GetEndTime();
+ m_maxNewLength = wxMax(m_maxNewLength, newLength);
+
// Delete the outputTracks now that their data are inserted in place.
delete outputLeftTrack;
delete outputRightTrack;
-
+
//Return true because the effect processing succeeded.
return true;
}
@@ -270,7 +291,7 @@
{
float* outputSoundTouchBuffer = new float[outputCount*2];
mSoundTouch->receiveSamples(outputSoundTouchBuffer, outputCount);
-
+
// Dis-interleave outputSoundTouchBuffer into separate track buffers.
float* outputLeftBuffer = new float[outputCount];
float* outputRightBuffer = new float[outputCount];
@@ -279,14 +300,14 @@
outputLeftBuffer[index] = outputSoundTouchBuffer[index*2];
outputRightBuffer[index] = outputSoundTouchBuffer[(index*2)+1];
}
-
+
outputLeftTrack->Append((samplePtr)outputLeftBuffer, floatSample,
outputCount);
outputRightTrack->Append((samplePtr)outputRightBuffer, floatSample,
outputCount);
-
+
delete[] outputSoundTouchBuffer;
delete[] outputLeftBuffer;
delete[] outputRightBuffer;
-
+
return true;
}
Index: ChangeSpeed.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/ChangeSpeed.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ChangeSpeed.h 15 Apr 2007 02:23:26 -0000 1.11
+++ ChangeSpeed.h 3 Jun 2007 18:04:35 -0000 1.12
@@ -56,6 +56,8 @@
// track related
int mCurTrackNum;
double m_maxNewLength;
+ double mCurT0;
+ double mCurT1;
// control values
double m_PercentChange; // percent change to apply to tempo
Index: ChangeSpeed.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/ChangeSpeed.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- ChangeSpeed.cpp 3 Jun 2007 09:46:16 -0000 1.33
+++ ChangeSpeed.cpp 3 Jun 2007 18:04:35 -0000 1.34
@@ -91,24 +91,23 @@
WaveTrack *track = (WaveTrack *) iter.First();
mCurTrackNum = 0;
m_maxNewLength = 0.0;
- double curT0;
- double curT1;
+
while (track) {
//Get start and end times from track
- double trackStart = track->GetStartTime();
- double trackEnd = track->GetEndTime();
+ mCurT0 = track->GetStartTime();
+ mCurT1 = track->GetEndTime();
//Set the current bounds to whichever left marker is
//greater and whichever right marker is less:
- curT0 = mT0 < trackStart? trackStart: mT0;
- curT1 = mT1 > trackEnd? trackEnd: mT1;
+ mCurT0 = wxMax(mT0, mCurT0);
+ mCurT1 = wxMin(mT1, mCurT1);
// Process only if the right marker is to the right of the left marker
- if (curT1 > curT0) {
+ if (mCurT1 > mCurT0) {
//Transform the marker timepoints to samples
- longSampleCount start = track->TimeToLongSamples(curT0);
- longSampleCount end = track->TimeToLongSamples(curT1);
+ longSampleCount start = track->TimeToLongSamples(mCurT0);
+ longSampleCount end = track->TimeToLongSamples(mCurT1);
//ProcessOne() (implemented below) processes a single track
if (!ProcessOne(track, start, end))
@@ -120,7 +119,7 @@
mCurTrackNum++;
}
- mT1 = mT0 + m_maxNewLength; // Update selection.
+// mT1 = mT0 + m_maxNewLength; // Update selection.
return true;
}
@@ -210,8 +209,8 @@
// Take the output track and insert it in place of the original
// sample data
if (bLoopSuccess) {
- track->Clear(mT0, mT1);
- track->Paste(mT0, outputTrack);
+ track->Clear(mCurT0, mCurT1);
+ track->Paste(mCurT0, outputTrack);
}
double newLength = outputTrack->GetEndTime();
-------------------------------------------------------------------------
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