1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-07 07:12:34 +02:00

Merge commit '1281f1b14b03355f694cd104d6b4d9919de107a6'

* commit '1281f1b14b03355f694cd104d6b4d9919de107a6':
  Common function limits buffer size to sampleCount known to be small
This commit is contained in:
Paul Licameli 2016-08-23 12:46:37 -04:00
commit 0d3c00662e
31 changed files with 161 additions and 226 deletions

View File

@ -60,6 +60,18 @@ typedef __int64 sampleCount;
typedef long long sampleCount; typedef long long sampleCount;
#endif #endif
// ----------------------------------------------------------------------------
// Function returning the minimum of a sampleCount and a size_t,
// hiding the casts
// ----------------------------------------------------------------------------
inline size_t limitSampleBufferSize( size_t bufferSize, sampleCount limit )
{
return static_cast<size_t> (
std::min( sampleCount( bufferSize ), std::max( sampleCount(0), limit ) )
);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Supported sample formats // Supported sample formats
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -96,10 +96,10 @@
// Use on-demand importing for FLAC. Has issues with opening projects that // Use on-demand importing for FLAC. Has issues with opening projects that
// have not been fully imported in builds without FLAC support, so disabled for // have not been fully imported in builds without FLAC support, so disabled for
// 2.0 release // 2.0 release
//#define EXPERIMENTAL_OD_FLAC #define EXPERIMENTAL_OD_FLAC
// similarly for FFmpeg: // similarly for FFmpeg:
// Won't build on Fedora 17 or Windows VC++, per http://bugzilla.audacityteam.org/show_bug.cgi?id=539. // Won't build on Fedora 17 or Windows VC++, per http://bugzilla.audacityteam.org/show_bug.cgi?id=539.
//#define EXPERIMENTAL_OD_FFMPEG 1 #define EXPERIMENTAL_OD_FFMPEG 1
// Paul Licameli (PRL) 5 Oct 2014 // Paul Licameli (PRL) 5 Oct 2014
#define EXPERIMENTAL_SPECTRAL_EDITING #define EXPERIMENTAL_SPECTRAL_EDITING

View File

@ -448,9 +448,10 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
memmove(queue, &queue[*queueStart], (*queueLen) * sampleSize); memmove(queue, &queue[*queueStart], (*queueLen) * sampleSize);
*queueStart = 0; *queueStart = 0;
int getLen = const auto getLen = limitSampleBufferSize(
std::min((backwards ? *pos - endPos : endPos - *pos), mQueueMaxLen - *queueLen,
sampleCount(mQueueMaxLen - *queueLen)); backwards ? *pos - endPos : endPos - *pos
);
// Nothing to do if past end of play interval // Nothing to do if past end of play interval
if (getLen > 0) { if (getLen > 0) {
@ -475,7 +476,7 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
*pos += getLen; *pos += getLen;
} }
for (int i = 0; i < getLen; i++) { for (decltype(+getLen) i = 0; i < getLen; i++) {
queue[(*queueLen) + i] *= mEnvValues[i]; queue[(*queueLen) + i] *= mEnvValues[i];
} }

View File

@ -239,7 +239,7 @@ bool Sequence::GetMinMax(sampleCount start, sampleCount len,
unsigned int block0 = FindBlock(start); unsigned int block0 = FindBlock(start);
unsigned int block1 = FindBlock(start + len - 1); unsigned int block1 = FindBlock(start + len - 1);
sampleCount s0, l0, maxl0; sampleCount s0;
// First calculate the min/max of the blocks in the middle of this region; // First calculate the min/max of the blocks in the middle of this region;
// this is very fast because we have the min/max of every entire block // this is very fast because we have the min/max of every entire block
@ -267,11 +267,9 @@ bool Sequence::GetMinMax(sampleCount start, sampleCount len,
if (block0Min < min || block0Max > max) { if (block0Min < min || block0Max > max) {
s0 = start - theBlock.start; s0 = start - theBlock.start;
l0 = len; const auto maxl0 = theBlock.start + theFile->GetLength() - start;
maxl0 = theBlock.start + theFile->GetLength() - start;
wxASSERT(maxl0 <= mMaxSamples); // Vaughan, 2011-10-19 wxASSERT(maxl0 <= mMaxSamples); // Vaughan, 2011-10-19
if (l0 > maxl0) const auto l0 = limitSampleBufferSize ( maxl0, len );
l0 = maxl0;
float partialMin, partialMax, partialRMS; float partialMin, partialMax, partialRMS;
theFile->GetMinMax(s0, l0, theFile->GetMinMax(s0, l0,
@ -293,7 +291,7 @@ bool Sequence::GetMinMax(sampleCount start, sampleCount len,
if (block1Min < min || block1Max > max) { if (block1Min < min || block1Max > max) {
s0 = 0; s0 = 0;
l0 = (start + len) - theBlock.start; const auto l0 = (start + len) - theBlock.start;
wxASSERT(l0 <= mMaxSamples); // Vaughan, 2011-10-19 wxASSERT(l0 <= mMaxSamples); // Vaughan, 2011-10-19
float partialMin, partialMax, partialRMS; float partialMin, partialMax, partialRMS;
@ -328,7 +326,7 @@ bool Sequence::GetRMS(sampleCount start, sampleCount len,
unsigned int block0 = FindBlock(start); unsigned int block0 = FindBlock(start);
unsigned int block1 = FindBlock(start + len - 1); unsigned int block1 = FindBlock(start + len - 1);
sampleCount s0, l0, maxl0; sampleCount s0;
// First calculate the rms of the blocks in the middle of this region; // First calculate the rms of the blocks in the middle of this region;
// this is very fast because we have the rms of every entire block // this is very fast because we have the rms of every entire block
@ -351,11 +349,9 @@ bool Sequence::GetRMS(sampleCount start, sampleCount len,
const SeqBlock &theBlock = mBlock[block0]; const SeqBlock &theBlock = mBlock[block0];
const auto &theFile = theBlock.f; const auto &theFile = theBlock.f;
s0 = start - theBlock.start; s0 = start - theBlock.start;
l0 = len; const auto maxl0 = theBlock.start + theFile->GetLength() - start;
maxl0 = theBlock.start + theFile->GetLength() - start;
wxASSERT(maxl0 <= mMaxSamples); // Vaughan, 2011-10-19 wxASSERT(maxl0 <= mMaxSamples); // Vaughan, 2011-10-19
if (l0 > maxl0) const auto l0 = limitSampleBufferSize( maxl0, len );
l0 = maxl0;
float partialMin, partialMax, partialRMS; float partialMin, partialMax, partialRMS;
theFile->GetMinMax(s0, l0, &partialMin, &partialMax, &partialRMS); theFile->GetMinMax(s0, l0, &partialMin, &partialMax, &partialRMS);
@ -369,7 +365,7 @@ bool Sequence::GetRMS(sampleCount start, sampleCount len,
const auto &theFile = theBlock.f; const auto &theFile = theBlock.f;
s0 = 0; s0 = 0;
l0 = (start + len) - theBlock.start; const auto l0 = (start + len) - theBlock.start;
wxASSERT(l0 <= mMaxSamples); // PRL: I think Vaughan missed this wxASSERT(l0 <= mMaxSamples); // PRL: I think Vaughan missed this
float partialMin, partialMax, partialRMS; float partialMin, partialMax, partialRMS;
@ -1181,7 +1177,8 @@ bool Sequence::Set(samplePtr buffer, sampleFormat format,
SampleBuffer temp; SampleBuffer temp;
if (buffer && format != mSampleFormat) { if (buffer && format != mSampleFormat) {
temp.Allocate(std::min(len, mMaxSamples), mSampleFormat); const auto size = limitSampleBufferSize( mMaxSamples, len );
temp.Allocate(size, mSampleFormat);
} }
int b = FindBlock(start); int b = FindBlock(start);
@ -1190,8 +1187,7 @@ bool Sequence::Set(samplePtr buffer, sampleFormat format,
SeqBlock &block = mBlock[b]; SeqBlock &block = mBlock[b];
const sampleCount bstart = start - block.start; const sampleCount bstart = start - block.start;
const sampleCount fileLength = block.f->GetLength(); const sampleCount fileLength = block.f->GetLength();
const int blen = const auto blen = limitSampleBufferSize( fileLength - bstart, len );
std::min(len, fileLength - bstart);
if (buffer) { if (buffer) {
if (format == mSampleFormat) if (format == mSampleFormat)

View File

@ -2336,7 +2336,7 @@ void TrackPanel::SnapCenterOnce(const WaveTrack *pTrack, bool up)
void TrackPanel::StartSnappingFreqSelection (const WaveTrack *pTrack) void TrackPanel::StartSnappingFreqSelection (const WaveTrack *pTrack)
{ {
static const sampleCount minLength = 8; static const size_t minLength = 8;
const double rate = pTrack->GetRate(); const double rate = pTrack->GetRate();
@ -2346,11 +2346,11 @@ void TrackPanel::StartSnappingFreqSelection (const WaveTrack *pTrack)
pTrack->TimeToLongSamples(mViewInfo->selectedRegion.t0()); pTrack->TimeToLongSamples(mViewInfo->selectedRegion.t0());
const sampleCount end = const sampleCount end =
pTrack->TimeToLongSamples(mViewInfo->selectedRegion.t1()); pTrack->TimeToLongSamples(mViewInfo->selectedRegion.t1());
const sampleCount length = const auto length =
std::min(sampleCount(frequencySnappingData.max_size()), std::min(frequencySnappingData.max_size(),
std::min(sampleCount(10485760), // as in FreqWindow.cpp limitSampleBufferSize( 10485760, // as in FreqWindow.cpp
end - start)); end - start ));
const sampleCount effectiveLength = std::max(minLength, length); const auto effectiveLength = std::max(minLength, length);
frequencySnappingData.resize(effectiveLength, 0.0f); frequencySnappingData.resize(effectiveLength, 0.0f);
pTrack->Get( pTrack->Get(
reinterpret_cast<samplePtr>(&frequencySnappingData[0]), reinterpret_cast<samplePtr>(&frequencySnappingData[0]),

View File

@ -110,7 +110,6 @@ sampleCount VoiceKey::OnForward (WaveTrack & t, sampleCount start, sampleCount l
auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection
lastsubthresholdsample = start; //start this off at the selection start lastsubthresholdsample = start; //start this off at the selection start
int blockruns=0; //keeps track of the number of consecutive above-threshold blocks int blockruns=0; //keeps track of the number of consecutive above-threshold blocks
int blocksize; //The final block may be smaller than WindowSizeInt, so use this
//This loop goes through the selection a block at a time. If a long enough run //This loop goes through the selection a block at a time. If a long enough run
@ -122,12 +121,7 @@ sampleCount VoiceKey::OnForward (WaveTrack & t, sampleCount start, sampleCount l
i += (WindowSizeInt - 1) , samplesleft -= (WindowSizeInt - 1)) { i += (WindowSizeInt - 1) , samplesleft -= (WindowSizeInt - 1)) {
//Set blocksize so that it is the right size //Set blocksize so that it is the right size
if((unsigned int)samplesleft < WindowSizeInt){ const auto blocksize = limitSampleBufferSize( WindowSizeInt, samplesleft);
blocksize = samplesleft;
}
else {
blocksize = WindowSizeInt;
}
//Test whether we are above threshold (the number of stats) //Test whether we are above threshold (the number of stats)
if(AboveThreshold(t,i,blocksize)) if(AboveThreshold(t,i,blocksize))
@ -263,7 +257,6 @@ sampleCount VoiceKey::OnBackward (WaveTrack & t, sampleCount end, sampleCount le
auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection
lastsubthresholdsample = end; //start this off at the end lastsubthresholdsample = end; //start this off at the end
int blockruns=0; //keeps track of the number of consecutive above-threshold blocks int blockruns=0; //keeps track of the number of consecutive above-threshold blocks
int blocksize; //The final block may be smaller than WindowSizeInt, so use this
//This loop goes through the selection a block at a time in reverse order. If a long enough run //This loop goes through the selection a block at a time in reverse order. If a long enough run
@ -274,12 +267,8 @@ sampleCount VoiceKey::OnBackward (WaveTrack & t, sampleCount end, sampleCount le
i -= (WindowSizeInt - 1) , samplesleft -= (WindowSizeInt - 1)) { i -= (WindowSizeInt - 1) , samplesleft -= (WindowSizeInt - 1)) {
//Set blocksize so that it is the right size //Set blocksize so that it is the right size
if(samplesleft < (int)WindowSizeInt){
blocksize = samplesleft; const auto blocksize = limitSampleBufferSize( WindowSizeInt, samplesleft);
}
else {
blocksize = WindowSizeInt;
}
//Test whether we are above threshold //Test whether we are above threshold
@ -406,7 +395,6 @@ sampleCount VoiceKey::OffForward (WaveTrack & t, sampleCount start, sampleCount
auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection
lastsubthresholdsample = start; //start this off at the selection start lastsubthresholdsample = start; //start this off at the selection start
int blockruns=0; //keeps track of the number of consecutive above-threshold blocks int blockruns=0; //keeps track of the number of consecutive above-threshold blocks
int blocksize; //The final block may be smaller than WindowSizeInt, so use this
//This loop goes through the selection a block at a time. If a long enough run //This loop goes through the selection a block at a time. If a long enough run
//of above-threshold blocks occur, we return to the last sub-threshold block and //of above-threshold blocks occur, we return to the last sub-threshold block and
@ -416,12 +404,7 @@ sampleCount VoiceKey::OffForward (WaveTrack & t, sampleCount start, sampleCount
i += (WindowSizeInt - 1) , samplesleft -= (WindowSizeInt - 1)) { i += (WindowSizeInt - 1) , samplesleft -= (WindowSizeInt - 1)) {
//Set blocksize so that it is the right size //Set blocksize so that it is the right size
if(samplesleft < (int)WindowSizeInt){ const auto blocksize = limitSampleBufferSize( WindowSizeInt, samplesleft);
blocksize = samplesleft;
}
else {
blocksize = WindowSizeInt;
}
if(!AboveThreshold(t,i,blocksize)) if(!AboveThreshold(t,i,blocksize))
{ {
@ -547,7 +530,6 @@ sampleCount VoiceKey::OffBackward (WaveTrack & t, sampleCount end, sampleCount l
auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection
lastsubthresholdsample = end; //start this off at the end lastsubthresholdsample = end; //start this off at the end
int blockruns=0; //keeps track of the number of consecutive above-threshold blocks int blockruns=0; //keeps track of the number of consecutive above-threshold blocks
int blocksize; //The final block may be smaller than WindowSizeInt, so use this
//This loop goes through the selection a block at a time in reverse order. If a long enough run //This loop goes through the selection a block at a time in reverse order. If a long enough run
//of above-threshold blocks occur, we return to the last sub-threshold block and //of above-threshold blocks occur, we return to the last sub-threshold block and
@ -557,12 +539,7 @@ sampleCount VoiceKey::OffBackward (WaveTrack & t, sampleCount end, sampleCount l
i -= (WindowSizeInt - 1), samplesleft -= (WindowSizeInt -1 )) { i -= (WindowSizeInt - 1), samplesleft -= (WindowSizeInt -1 )) {
//Set blocksize so that it is the right size //Set blocksize so that it is the right size
if(samplesleft < (int)WindowSizeInt){ const auto blocksize = limitSampleBufferSize( WindowSizeInt, samplesleft);
blocksize = samplesleft;
}
else {
blocksize = WindowSizeInt;
}
if(!AboveThreshold(t,i,blocksize)) if(!AboveThreshold(t,i,blocksize))
{ {
@ -797,7 +774,6 @@ void VoiceKey::CalibrateNoise(WaveTrack & t, sampleCount start, sampleCount len)
// int n = len - WindowSizeInt; //This is how many samples we have // int n = len - WindowSizeInt; //This is how many samples we have
auto samplesleft = len - WindowSizeInt; auto samplesleft = len - WindowSizeInt;
int blocksize;
int samples=0; int samples=0;
for(auto i = start; samplesleft >= 10; for(auto i = start; samplesleft >= 10;
@ -807,14 +783,7 @@ void VoiceKey::CalibrateNoise(WaveTrack & t, sampleCount start, sampleCount len)
//samples left) take a chunk that eats the rest of the samples. //samples left) take a chunk that eats the rest of the samples.
samples++; //Increment the number of samples we have samples++; //Increment the number of samples we have
if(samplesleft < (int)WindowSizeInt) const auto blocksize = limitSampleBufferSize( WindowSizeInt, samplesleft);
{
blocksize = samplesleft;
}
else
{
blocksize = WindowSizeInt;
}
erg = TestEnergy(t, i, blocksize); erg = TestEnergy(t, i, blocksize);
sumerg +=(double)erg; sumerg +=(double)erg;
@ -872,22 +841,19 @@ double VoiceKey::TestEnergy (WaveTrack & t, sampleCount start, sampleCount len)
double sum = 1; double sum = 1;
sampleCount s = start; //Keep track of start sampleCount s = start; //Keep track of start
sampleCount originalLen = len; //Keep track of the length of block to process (its not the length of t) sampleCount originalLen = len; //Keep track of the length of block to process (its not the length of t)
sampleCount blockSize = t.GetMaxBlockSize(); //Determine size of sampling buffer const auto blockSize = limitSampleBufferSize(
t.GetMaxBlockSize(), len); //Determine size of sampling buffer
if( blockSize > len)
blockSize = len;
float *buffer = new float[blockSize]; //Get a sampling buffer float *buffer = new float[blockSize]; //Get a sampling buffer
while(len > 0) while(len > 0)
{ {
sampleCount block = t.GetBestBlockSize(s); //Figure out how much to grab //Figure out how much to grab
if(block > len) block = len; //Don't grab too much! const auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
t.Get((samplePtr)buffer,floatSample, s,block); //grab the block; t.Get((samplePtr)buffer,floatSample, s,block); //grab the block;
//Now, go through the block and calculate energy //Now, go through the block and calculate energy
for(int i = 0; i< block; i++) for(decltype(+block) i = 0; i< block; i++)
{ {
sum += buffer[i]*buffer[i]; sum += buffer[i]*buffer[i];
} }
@ -916,19 +882,16 @@ double VoiceKey::TestSignChanges(WaveTrack & t, sampleCount start, sampleCount l
sampleCount s = start; //Keep track of start sampleCount s = start; //Keep track of start
sampleCount originalLen = len; //Keep track of the length of block to process (its not the length of t) sampleCount originalLen = len; //Keep track of the length of block to process (its not the length of t)
sampleCount blockSize = t.GetMaxBlockSize(); //Determine size of sampling buffer const auto blockSize = limitSampleBufferSize(
t.GetMaxBlockSize(), len); //Determine size of sampling buffer
unsigned long signchanges = 1; unsigned long signchanges = 1;
int currentsign=0; int currentsign=0;
if( blockSize > len)
blockSize = len;
float *buffer = new float[blockSize]; //Get a sampling buffer float *buffer = new float[blockSize]; //Get a sampling buffer
while(len > 0) { while(len > 0) {
//Figure out how much to grab
sampleCount block = t.GetBestBlockSize(s); //Figure out how much to grab const auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
if(block > len) block = len; //Don't grab too much!
t.Get((samplePtr)buffer,floatSample, s,block); //grab the block; t.Get((samplePtr)buffer,floatSample, s,block); //grab the block;
@ -940,7 +903,7 @@ double VoiceKey::TestSignChanges(WaveTrack & t, sampleCount start, sampleCount l
//Now, go through the block and calculate zero crossings //Now, go through the block and calculate zero crossings
for(int i = 0; i< block; i++) for(decltype(+block) i = 0; i< block; i++)
{ {
if( sgn(buffer[i]) != currentsign) if( sgn(buffer[i]) != currentsign)
{ {
@ -975,19 +938,17 @@ double VoiceKey::TestDirectionChanges(WaveTrack & t, sampleCount start, sampleCo
sampleCount s = start; //Keep track of start sampleCount s = start; //Keep track of start
sampleCount originalLen = len; //Keep track of the length of block to process (its not the length of t) sampleCount originalLen = len; //Keep track of the length of block to process (its not the length of t)
sampleCount blockSize = t.GetMaxBlockSize(); //Determine size of sampling buffer const auto blockSize = limitSampleBufferSize(
t.GetMaxBlockSize(), len); //Determine size of sampling buffer
unsigned long directionchanges = 1; unsigned long directionchanges = 1;
float lastval=float(0); float lastval=float(0);
int lastdirection=1; int lastdirection=1;
if( blockSize > len)
blockSize = len;
float *buffer = new float[blockSize]; //Get a sampling buffer float *buffer = new float[blockSize]; //Get a sampling buffer
while(len > 0) { while(len > 0) {
//Figure out how much to grab
sampleCount block = t.GetBestBlockSize(s); //Figure out how much to grab const auto block = limitSampleBufferSize ( t.GetBestBlockSize(s), len );
if(block > len) block = len; //Don't grab too much!
t.Get((samplePtr)buffer,floatSample, s,block); //grab the block; t.Get((samplePtr)buffer,floatSample, s,block); //grab the block;
@ -999,7 +960,7 @@ double VoiceKey::TestDirectionChanges(WaveTrack & t, sampleCount start, sampleCo
//Now, go through the block and calculate zero crossings //Now, go through the block and calculate zero crossings
for(int i = 0; i< block; i++){ for(decltype(+block) i = 0; i< block; i++){
if( sgn(buffer[i]-lastval) != lastdirection) { if( sgn(buffer[i]-lastval) != lastdirection) {
directionchanges++; directionchanges++;

View File

@ -1717,9 +1717,7 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
*/ */
while (pos < numSamples || outGenerated > 0) while (pos < numSamples || outGenerated > 0)
{ {
int inLen = numSamples - pos; const auto inLen = limitSampleBufferSize( bufsize, numSamples - pos );
if (inLen > bufsize)
inLen = bufsize;
bool isLast = ((pos + inLen) == numSamples); bool isLast = ((pos + inLen) == numSamples);

View File

@ -1459,13 +1459,11 @@ bool WaveTrack::Disjoin(double t0, double t1)
sampleCount len = ( end - start ); sampleCount len = ( end - start );
for( sampleCount done = 0; done < len; done += maxAtOnce ) for( sampleCount done = 0; done < len; done += maxAtOnce )
{ {
sampleCount numSamples = maxAtOnce; const auto numSamples = limitSampleBufferSize( maxAtOnce, len - done );
if( done + maxAtOnce > len )
numSamples = len - done;
clip->GetSamples( ( samplePtr )buffer, floatSample, start + done, clip->GetSamples( ( samplePtr )buffer, floatSample, start + done,
numSamples ); numSamples );
for( sampleCount i = 0; i < numSamples; i++ ) for( decltype(+numSamples) i = 0; i < numSamples; i++ )
{ {
sampleCount curSamplePos = start + done + i; sampleCount curSamplePos = start + done + i;
@ -2148,7 +2146,7 @@ void WaveTrack::GetEnvelopeValues(double *buffer, size_t bufferLen,
// This conditional prevents the previous write past the buffer end, in clip->GetEnvelope() call. // This conditional prevents the previous write past the buffer end, in clip->GetEnvelope() call.
// Never increase rlen here. // Never increase rlen here.
// PRL bug 827: rewrote it again // PRL bug 827: rewrote it again
rlen = static_cast<size_t>( std::min(sampleCount( rlen ), nClipLen) ); rlen = limitSampleBufferSize( rlen, nClipLen );
rlen = std::min(rlen, size_t(floor(0.5 + (dClipEndTime - rt0) / tstep))); rlen = std::min(rlen, size_t(floor(0.5 + (dClipEndTime - rt0) / tstep)));
} }
clip->GetEnvelope()->GetValues(rbuf, rlen, rt0, tstep); clip->GetEnvelope()->GetValues(rbuf, rlen, rt0, tstep);

View File

@ -110,16 +110,13 @@ bool CompareAudioCommand::Apply(CommandExecutionContext context)
while (position < s1) while (position < s1)
{ {
// Get a block of data into the buffers // Get a block of data into the buffers
sampleCount block = mTrack0->GetBestBlockSize(position); const auto block = limitSampleBufferSize(
if (position + block > s1) mTrack0->GetBestBlockSize(position), s1 - position
{ );
block = s1 - position;
}
mTrack0->Get((samplePtr)buff0, floatSample, position, block); mTrack0->Get((samplePtr)buff0, floatSample, position, block);
mTrack1->Get((samplePtr)buff1, floatSample, position, block); mTrack1->Get((samplePtr)buff1, floatSample, position, block);
int buffPos = 0; for (decltype(+block) buffPos = 0; buffPos < block; ++buffPos)
for (buffPos = 0; buffPos < block; ++buffPos)
{ {
if (CompareSample(buff0[buffPos], buff1[buffPos]) > errorThreshold) if (CompareSample(buff0[buffPos], buff1[buffPos]) > errorThreshold)
{ {

View File

@ -306,9 +306,7 @@ bool EffectAutoDuck::Process()
while (pos < end) while (pos < end)
{ {
sampleCount len = end - pos; const auto len = limitSampleBufferSize( kBufSize, end - pos );
if (len > kBufSize)
len = kBufSize;
mControlTrack->Get((samplePtr)buf, floatSample, pos, (sampleCount)len); mControlTrack->Get((samplePtr)buf, floatSample, pos, (sampleCount)len);
@ -536,9 +534,7 @@ bool EffectAutoDuck::ApplyDuckFade(int trackNumber, WaveTrack* t,
while (pos < end) while (pos < end)
{ {
sampleCount len = end - pos; const auto len = limitSampleBufferSize( kBufSize, end - pos );
if (len > kBufSize)
len = kBufSize;
t->Get((samplePtr)buf, floatSample, pos, len); t->Get((samplePtr)buf, floatSample, pos, len);

View File

@ -194,7 +194,7 @@ sampleCount EffectDtmf::ProcessBlock(float **WXUNUSED(inbuf), float **outbuf, sa
numRemaining += (diff-- > 0 ? 1 : 0); numRemaining += (diff-- > 0 ? 1 : 0);
} }
sampleCount len = wxMin(numRemaining, size); const auto len = limitSampleBufferSize( size, numRemaining );
if (isTone) if (isTone)
{ {

View File

@ -1546,7 +1546,7 @@ bool Effect::ProcessTrack(int count,
sampleCount curBlockSize = 0; sampleCount curBlockSize = 0;
sampleCount curDelay = 0; sampleCount curDelay = 0;
sampleCount inputBufferCnt = 0; size_t inputBufferCnt = 0;
sampleCount outputBufferCnt = 0; sampleCount outputBufferCnt = 0;
bool cleared = false; bool cleared = false;
@ -1589,11 +1589,8 @@ bool Effect::ProcessTrack(int count,
if (inputBufferCnt == 0) if (inputBufferCnt == 0)
{ {
// Calculate the number of samples to get // Calculate the number of samples to get
inputBufferCnt = mBufferSize; inputBufferCnt =
if (inputBufferCnt > inputRemaining) limitSampleBufferSize( mBufferSize, inputRemaining );
{
inputBufferCnt = inputRemaining;
}
// Fill the input buffers // Fill the input buffers
left->Get((samplePtr) mInBuffer[0], floatSample, inLeftPos, inputBufferCnt); left->Get((samplePtr) mInBuffer[0], floatSample, inLeftPos, inputBufferCnt);

View File

@ -167,7 +167,7 @@ bool EffectFindClipping::ProcessOne(LabelTrack * lt,
sampleCount startrun = 0; sampleCount startrun = 0;
sampleCount stoprun = 0; sampleCount stoprun = 0;
sampleCount samps = 0; sampleCount samps = 0;
sampleCount block = 0; size_t block = 0;
double startTime = -1.0; double startTime = -1.0;
while (s < len) { while (s < len) {
@ -177,7 +177,7 @@ bool EffectFindClipping::ProcessOne(LabelTrack * lt,
break; break;
} }
block = s + blockSize > len ? len - s : blockSize; block = limitSampleBufferSize( blockSize, len - s );
wt->Get((samplePtr)buffer, floatSample, start + s, block); wt->Get((samplePtr)buffer, floatSample, start + s, block);
ptr = buffer; ptr = buffer;

View File

@ -121,12 +121,10 @@ bool BlockGenerator::GenerateTrack(WaveTrack *tmp,
numSamples = track.TimeToLongSamples(GetDuration()); numSamples = track.TimeToLongSamples(GetDuration());
sampleCount i = 0; sampleCount i = 0;
float *data = new float[tmp->GetMaxBlockSize()]; float *data = new float[tmp->GetMaxBlockSize()];
sampleCount block = 0;
while ((i < numSamples) && bGoodResult) { while ((i < numSamples) && bGoodResult) {
block = tmp->GetBestBlockSize(i); const auto block =
if (block > (numSamples - i)) limitSampleBufferSize( tmp->GetBestBlockSize(i), numSamples - i );
block = numSamples - i;
GenerateBlock(data, track, block); GenerateBlock(data, track, block);

View File

@ -1295,11 +1295,13 @@ bool EffectNoiseReduction::Worker::ProcessOne
FloatVector buffer(bufferSize); FloatVector buffer(bufferSize);
bool bLoopSuccess = true; bool bLoopSuccess = true;
sampleCount blockSize;
sampleCount samplePos = start; sampleCount samplePos = start;
while (bLoopSuccess && samplePos < start + len) { while (bLoopSuccess && samplePos < start + len) {
//Get a blockSize of samples (smaller than the size of the buffer) //Get a blockSize of samples (smaller than the size of the buffer)
blockSize = std::min(start + len - samplePos, track->GetBestBlockSize(samplePos)); const auto blockSize = limitSampleBufferSize(
track->GetBestBlockSize(samplePos),
start + len - samplePos
);
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr)&buffer[0], floatSample, samplePos, blockSize); track->Get((samplePtr)&buffer[0], floatSample, samplePos, blockSize);

View File

@ -576,15 +576,14 @@ bool EffectNoiseRemoval::ProcessOne(int count, WaveTrack * track,
float *buffer = new float[bufferSize]; float *buffer = new float[bufferSize];
bool bLoopSuccess = true; bool bLoopSuccess = true;
sampleCount blockSize;
sampleCount samplePos = start; sampleCount samplePos = start;
while (samplePos < start + len) { while (samplePos < start + len) {
//Get a blockSize of samples (smaller than the size of the buffer) //Get a blockSize of samples (smaller than the size of the buffer)
blockSize = track->GetBestBlockSize(samplePos);
//Adjust the block size if it is the final block in the track //Adjust the block size if it is the final block in the track
if (samplePos + blockSize > start + len) const auto blockSize = limitSampleBufferSize(
blockSize = start + len - samplePos; track->GetBestBlockSize(samplePos),
start + len - samplePos
);
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr)buffer, floatSample, samplePos, blockSize); track->Get((samplePtr)buffer, floatSample, samplePos, blockSize);

View File

@ -392,11 +392,11 @@ bool EffectNormalize::AnalyseDC(WaveTrack * track, const wxString &msg)
s = start; s = start;
while (s < end) { while (s < end) {
//Get a block of samples (smaller than the size of the buffer) //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 //Adjust the block size if it is the final block in the track
if (s + block > end) const auto block = limitSampleBufferSize(
block = end - s; track->GetBestBlockSize(s),
end - s
);
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer, floatSample, s, block); track->Get((samplePtr) buffer, floatSample, s, block);
@ -450,11 +450,11 @@ bool EffectNormalize::ProcessOne(WaveTrack * track, const wxString &msg)
s = start; s = start;
while (s < end) { while (s < end) {
//Get a block of samples (smaller than the size of the buffer) //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 //Adjust the block size if it is the final block in the track
if (s + block > end) const auto block = limitSampleBufferSize(
block = end - s; track->GetBestBlockSize(s),
end - s
);
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer, floatSample, s, block); track->Get((samplePtr) buffer, floatSample, s, block);

View File

@ -229,14 +229,13 @@ bool EffectReverse::ProcessOneClip(int count, WaveTrack *track,
sampleCount originalLen = (sampleCount)originalEnd-originalStart; sampleCount originalLen = (sampleCount)originalEnd-originalStart;
while (len > 1) { while (len > 1) {
sampleCount block = track->GetBestBlockSize(first); const auto block =
if (block > len / 2) limitSampleBufferSize( track->GetBestBlockSize(first), len / 2 );
block = len / 2;
second = first + (len - block); second = first + (len - block);
track->Get((samplePtr)buffer1, floatSample, first, block); track->Get((samplePtr)buffer1, floatSample, first, block);
track->Get((samplePtr)buffer2, floatSample, second, block); track->Get((samplePtr)buffer2, floatSample, second, block);
for (int i = 0; i < block; i++) { for (decltype(+block) i = 0; i < block; i++) {
tmp = buffer1[i]; tmp = buffer1[i];
buffer1[i] = buffer2[block-i-1]; buffer1[i] = buffer2[block-i-1];
buffer2[block-i-1] = tmp; buffer2[block-i-1] = tmp;

View File

@ -98,18 +98,17 @@ long resampleCB(void *cb_data, SBSMSFrame *data)
{ {
ResampleBuf *r = (ResampleBuf*) cb_data; ResampleBuf *r = (ResampleBuf*) cb_data;
long blockSize = r->leftTrack->GetBestBlockSize(r->offset); const auto blockSize = limitSampleBufferSize(
r->leftTrack->GetBestBlockSize(r->offset),
//Adjust the block size if it is the final block in the track r->end - r->offset
if (r->offset + blockSize > r->end) );
blockSize = r->end - r->offset;
// Get the samples from the tracks and put them in the buffers. // Get the samples from the tracks and put them in the buffers.
r->leftTrack->Get((samplePtr)(r->leftBuffer), floatSample, r->offset, blockSize); r->leftTrack->Get((samplePtr)(r->leftBuffer), floatSample, r->offset, blockSize);
r->rightTrack->Get((samplePtr)(r->rightBuffer), floatSample, r->offset, blockSize); r->rightTrack->Get((samplePtr)(r->rightBuffer), floatSample, r->offset, blockSize);
// convert to sbsms audio format // convert to sbsms audio format
for(int i=0; i<blockSize; i++) { for(decltype(+blockSize) i=0; i<blockSize; i++) {
r->buf[i][0] = r->leftBuffer[i]; r->buf[i][0] = r->leftBuffer[i];
r->buf[i][1] = r->rightBuffer[i]; r->buf[i][1] = r->rightBuffer[i];
} }
@ -376,12 +375,9 @@ bool EffectSBSMS::Process()
// process // process
while(pos<samplesOut && outputCount) { while(pos<samplesOut && outputCount) {
long frames; const auto frames =
if(pos+SBSMSOutBlockSize>samplesOut) { limitSampleBufferSize( SBSMSOutBlockSize, samplesOut - pos );
frames = samplesOut - pos;
} else {
frames = SBSMSOutBlockSize;
}
outputCount = resampler.read(outBuf,frames); outputCount = resampler.read(outBuf,frames);
for(int i = 0; i < outputCount; i++) { for(int i = 0; i < outputCount; i++) {
outBufLeft[i] = outBuf[i][0]; outBufLeft[i] = outBuf[i][0];

View File

@ -96,11 +96,9 @@ bool EffectSimpleMono::ProcessOne(WaveTrack * track,
s = start; s = start;
while (s < end) { while (s < end) {
//Get a block of samples (smaller than the size of the buffer) //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 //Adjust the block size if it is the final block in the track
if (s + block > end) const auto block =
block = end - s; limitSampleBufferSize( track->GetBestBlockSize(s), end - s );
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer, floatSample, s, block); track->Get((samplePtr) buffer, floatSample, s, block);

View File

@ -195,11 +195,8 @@ bool EffectSoundTouch::ProcessOne(WaveTrack *track,
s = start; s = start;
while (s < end) { while (s < end) {
//Get a block of samples (smaller than the size of the buffer) //Get a block of samples (smaller than the size of the buffer)
sampleCount block = track->GetBestBlockSize(s); const auto block =
limitSampleBufferSize( track->GetBestBlockSize(s), end - 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 //Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer, floatSample, s, block); track->Get((samplePtr) buffer, floatSample, s, block);
@ -283,18 +280,18 @@ bool EffectSoundTouch::ProcessStereo(WaveTrack* leftTrack, WaveTrack* rightTrack
sampleCount sourceSampleCount = start; sampleCount sourceSampleCount = start;
while (sourceSampleCount < end) { while (sourceSampleCount < end) {
//Get a block of samples (smaller than the size of the buffer) //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 //Adjust the block size if it is the final block in the track
if (sourceSampleCount + blockSize > end) const auto blockSize = limitSampleBufferSize(
blockSize = end - sourceSampleCount; leftTrack->GetBestBlockSize(sourceSampleCount),
end - sourceSampleCount
);
// Get the samples from the tracks and put them in the buffers. // Get the samples from the tracks and put them in the buffers.
leftTrack->Get((samplePtr)(leftBuffer), floatSample, sourceSampleCount, blockSize); leftTrack->Get((samplePtr)(leftBuffer), floatSample, sourceSampleCount, blockSize);
rightTrack->Get((samplePtr)(rightBuffer), floatSample, sourceSampleCount, blockSize); rightTrack->Get((samplePtr)(rightBuffer), floatSample, sourceSampleCount, blockSize);
// Interleave into soundTouchBuffer. // Interleave into soundTouchBuffer.
for (int index = 0; index < blockSize; index++) { for (decltype(+blockSize) index = 0; index < blockSize; index++) {
soundTouchBuffer[index*2] = leftBuffer[index]; soundTouchBuffer[index*2] = leftBuffer[index];
soundTouchBuffer[(index*2)+1] = rightBuffer[index]; soundTouchBuffer[(index*2)+1] = rightBuffer[index];
} }

View File

@ -144,11 +144,8 @@ bool EffectStereoToMono::ProcessOne(int count)
while (index < mEnd) { while (index < mEnd) {
bResult &= mLeftTrack->Get((samplePtr)leftBuffer, floatSample, index, idealBlockLen); bResult &= mLeftTrack->Get((samplePtr)leftBuffer, floatSample, index, idealBlockLen);
bResult &= mRightTrack->Get((samplePtr)rightBuffer, floatSample, index, idealBlockLen); bResult &= mRightTrack->Get((samplePtr)rightBuffer, floatSample, index, idealBlockLen);
sampleCount limit = idealBlockLen; const auto limit = limitSampleBufferSize( idealBlockLen, mEnd - index );
if ((index + idealBlockLen) > mEnd) { for (decltype(+limit) i = 0; i < limit; ++i) {
limit = mEnd - index;
}
for (sampleCount i = 0; i < limit; ++i) {
index++; index++;
curLeftFrame = leftBuffer[i]; curLeftFrame = leftBuffer[i];
curRightFrame = rightBuffer[i]; curRightFrame = rightBuffer[i];

View File

@ -624,16 +624,13 @@ bool EffectTruncSilence::Analyze(RegionList& silenceList,
// End of optimization // End of optimization
// Limit size of current block if we've reached the end // Limit size of current block if we've reached the end
sampleCount count = blockLen; const auto count = limitSampleBufferSize( blockLen, end - *index );
if ((*index + count) > end) {
count = end - *index;
}
// Fill buffer // Fill buffer
wt->Get((samplePtr)(buffer), floatSample, *index, count); wt->Get((samplePtr)(buffer), floatSample, *index, count);
// Look for silenceList in current block // Look for silenceList in current block
for (sampleCount i = 0; i < count; ++i) { for (decltype(+count) i = 0; i < count; ++i) {
if (inputLength && ((outLength >= previewLen) || (outLength > wt->TimeToLongSamples(*minInputLength)))) { if (inputLength && ((outLength >= previewLen) || (outLength > wt->TimeToLongSamples(*minInputLength)))) {
*inputLength = wt->LongSamplesToTime(*index + i) - wt->LongSamplesToTime(start); *inputLength = wt->LongSamplesToTime(*index + i) - wt->LongSamplesToTime(start);
break; break;

View File

@ -100,7 +100,7 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
sampleCount start, sampleCount end) sampleCount start, sampleCount end)
{ {
bool ret; bool ret;
sampleCount s, samples1, samples2, tmpcount; sampleCount s;
float *tmpfloat; float *tmpfloat;
//Get the length of the buffer (as double). len is //Get the length of the buffer (as double). len is
@ -113,12 +113,8 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
//be shorter than the length of the track being processed. //be shorter than the length of the track being processed.
float *buffer1 = new float[maxblock]; float *buffer1 = new float[maxblock];
float *buffer2 = new float[maxblock]; float *buffer2 = new float[maxblock];
samples1 = track->GetBestBlockSize(start); auto samples1 = limitSampleBufferSize(
if(start + samples1 > end) std::min( maxblock, track->GetBestBlockSize(start) ), end - start );
samples1 = end - start;
if(samples1 > maxblock)
samples1 = maxblock;
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer1, floatSample, start, samples1); track->Get((samplePtr) buffer1, floatSample, start, samples1);
@ -141,14 +137,10 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
s = start + samples1; s = start + samples1;
while (s < end) { while (s < end) {
//Get a block of samples (smaller than the size of the buffer) //Get a block of samples (smaller than the size of the buffer)
samples2 = track->GetBestBlockSize(s);
if(samples2 > maxblock)
samples2 = maxblock;
//Adjust the block size if it is the final block in the track //Adjust the block size if it is the final block in the track
if (s + samples2 > end) auto samples2 = limitSampleBufferSize(
samples2 = end - s; std::min( track->GetBestBlockSize(s), maxblock ), end - s
);
//Get the samples from the track and put them in the buffer //Get the samples from the track and put them in the buffer
track->Get((samplePtr) buffer2, floatSample, s, samples2); track->Get((samplePtr) buffer2, floatSample, s, samples2);
@ -189,9 +181,7 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
buffer1 = buffer2; buffer1 = buffer2;
buffer2 = tmpfloat; buffer2 = tmpfloat;
tmpcount = samples1; std::swap(samples1, samples2);
samples1 = samples2;
samples2 = tmpcount;
} }
// Send the last buffer with a NULL pointer for the current buffer // Send the last buffer with a NULL pointer for the current buffer

View File

@ -1740,9 +1740,9 @@ int NyquistEffect::GetCallback(float *buffer, int ch,
mCurBufferLen[ch] = mCurTrack[ch]->GetIdealBlockSize(); mCurBufferLen[ch] = mCurTrack[ch]->GetIdealBlockSize();
} }
if (mCurBufferStart[ch] + mCurBufferLen[ch] > mCurStart[ch] + mCurLen) { mCurBufferLen[ch] =
mCurBufferLen[ch] = mCurStart[ch] + mCurLen - mCurBufferStart[ch]; limitSampleBufferSize( mCurBufferLen[ch],
} mCurStart[ch] + mCurLen - mCurBufferStart[ch] );
mCurBuffer[ch].Allocate(mCurBufferLen[ch], floatSample); mCurBuffer[ch].Allocate(mCurBufferLen[ch], floatSample);
if (!mCurTrack[ch]->Get(mCurBuffer[ch].ptr(), floatSample, if (!mCurTrack[ch]->Get(mCurBuffer[ch].ptr(), floatSample,

View File

@ -222,7 +222,7 @@ private:
SampleBuffer mCurBuffer[2]; SampleBuffer mCurBuffer[2];
sampleCount mCurBufferStart[2]; sampleCount mCurBufferStart[2];
sampleCount mCurBufferLen[2]; size_t mCurBufferLen[2];
std::unique_ptr<WaveTrack> mOutputTrack[2]; std::unique_ptr<WaveTrack> mOutputTrack[2];

View File

@ -498,8 +498,7 @@ bool VampEffect::Process()
while (len != 0) while (len != 0)
{ {
int request = block; const auto request = limitSampleBufferSize( block, len );
if (request > len) request = len;
if (left) if (left)
{ {
@ -511,11 +510,11 @@ bool VampEffect::Process()
right->Get((samplePtr)data[1], floatSample, rs, request); right->Get((samplePtr)data[1], floatSample, rs, request);
} }
if (request < (int)block) if (request < block)
{ {
for (int c = 0; c < channels; ++c) for (int c = 0; c < channels; ++c)
{ {
for (int i = request; i < (int)block; ++i) for (decltype(block) i = request; i < block; ++i)
{ {
data[c][i] = 0.f; data[c][i] = 0.f;
} }

View File

@ -606,9 +606,8 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory,
sampleCount maxBlockSize = t->GetMaxBlockSize(); sampleCount maxBlockSize = t->GetMaxBlockSize();
//use the maximum blockfile size to divide the sections (about 11secs per blockfile at 44.1khz) //use the maximum blockfile size to divide the sections (about 11secs per blockfile at 44.1khz)
for (sampleCount i = 0; i < sampleDuration; i += maxBlockSize) { for (sampleCount i = 0; i < sampleDuration; i += maxBlockSize) {
sampleCount blockLen = maxBlockSize; const auto blockLen =
if (i + blockLen > sampleDuration) limitSampleBufferSize( maxBlockSize, sampleDuration - i );
blockLen = sampleDuration - i;
t->AppendCoded(mFilename, i, blockLen, c, ODTask::eODFFMPEG); t->AppendCoded(mFilename, i, blockLen, c, ODTask::eODFFMPEG);

View File

@ -487,12 +487,11 @@ int FLACImportFileHandle::Import(TrackFactory *trackFactory,
//add the task to the ODManager //add the task to the ODManager
if(useOD) if(useOD)
{ {
sampleCount fileTotalFrames = mNumSamples; sampleCount fileTotalFrames = (sampleCount)mNumSamples;
sampleCount maxBlockSize = mChannels.begin()->get()->GetMaxBlockSize(); sampleCount maxBlockSize = mChannels.begin()->get()->GetMaxBlockSize();
for (sampleCount i = 0; i < fileTotalFrames; i += maxBlockSize) { for (sampleCount i = 0; i < fileTotalFrames; i += maxBlockSize) {
sampleCount blockLen = maxBlockSize; const auto blockLen =
if (i + blockLen > fileTotalFrames) limitSampleBufferSize( maxBlockSize, fileTotalFrames - i );
blockLen = fileTotalFrames - i;
auto iter = mChannels.begin(); auto iter = mChannels.begin();
for (int c = 0; c < mNumChannels; ++c, ++iter) for (int c = 0; c < mNumChannels; ++c, ++iter)

View File

@ -388,10 +388,8 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
int updateCounter = 0; int updateCounter = 0;
for (sampleCount i = 0; i < fileTotalFrames; i += maxBlockSize) { for (sampleCount i = 0; i < fileTotalFrames; i += maxBlockSize) {
const auto blockLen =
sampleCount blockLen = maxBlockSize; limitSampleBufferSize( maxBlockSize, fileTotalFrames - i );
if (i + blockLen > fileTotalFrames)
blockLen = fileTotalFrames - i;
auto iter = channels.begin(); auto iter = channels.begin();
for (int c = 0; c < mInfo.channels; ++iter, ++c) for (int c = 0; c < mInfo.channels; ++iter, ++c)

View File

@ -105,7 +105,7 @@ void ImportRaw(wxWindow *parent, const wxString &fileName,
double percent = 100.0; double percent = 100.0;
TrackHolders channels; TrackHolders channels;
int updateResult = eProgressSuccess; int updateResult = eProgressSuccess;
long block;
{ {
SF_INFO sndInfo; SF_INFO sndInfo;
int result; int result;
@ -224,6 +224,10 @@ void ImportRaw(wxWindow *parent, const wxString &fileName,
SampleBuffer buffer(maxBlockSize, format); SampleBuffer buffer(maxBlockSize, format);
sampleCount framescompleted = 0; sampleCount framescompleted = 0;
if (totalFrames < 0) {
wxASSERT(false);
totalFrames = 0;
}
wxString msg; wxString msg;
@ -232,27 +236,38 @@ void ImportRaw(wxWindow *parent, const wxString &fileName,
/* i18n-hint: 'Raw' means 'unprocessed' here and should usually be tanslated.*/ /* i18n-hint: 'Raw' means 'unprocessed' here and should usually be tanslated.*/
ProgressDialog progress(_("Import Raw"), msg); ProgressDialog progress(_("Import Raw"), msg);
size_t block;
do { do {
block = maxBlockSize; block =
limitSampleBufferSize( maxBlockSize, totalFrames - framescompleted );
if (block + framescompleted > totalFrames)
block = totalFrames - framescompleted;
sf_count_t result;
if (format == int16Sample) if (format == int16Sample)
block = SFCall<sf_count_t>(sf_readf_short, sndFile.get(), (short *)srcbuffer.ptr(), block); result = SFCall<sf_count_t>(sf_readf_short, sndFile.get(), (short *)srcbuffer.ptr(), block);
else else
block = SFCall<sf_count_t>(sf_readf_float, sndFile.get(), (float *)srcbuffer.ptr(), block); result = SFCall<sf_count_t>(sf_readf_float, sndFile.get(), (float *)srcbuffer.ptr(), block);
if (result >= 0) {
block = result;
}
else {
// This is not supposed to happen, sndfile.h says result is always
// a count, not an invalid value for error
wxASSERT(false);
updateResult = eProgressFailed;
break;
}
if (block) { if (block) {
auto iter = channels.begin(); auto iter = channels.begin();
for(int c=0; c<numChannels; ++iter, ++c) { for(int c=0; c<numChannels; ++iter, ++c) {
if (format==int16Sample) { if (format==int16Sample) {
for(int j=0; j<block; j++) for(decltype(block) j=0; j<block; j++)
((short *)buffer.ptr())[j] = ((short *)buffer.ptr())[j] =
((short *)srcbuffer.ptr())[numChannels*j+c]; ((short *)srcbuffer.ptr())[numChannels*j+c];
} }
else { else {
for(int j=0; j<block; j++) for(decltype(block) j=0; j<block; j++)
((float *)buffer.ptr())[j] = ((float *)buffer.ptr())[j] =
((float *)srcbuffer.ptr())[numChannels*j+c]; ((float *)srcbuffer.ptr())[numChannels*j+c];
} }
@ -270,11 +285,7 @@ void ImportRaw(wxWindow *parent, const wxString &fileName,
} while (block > 0 && framescompleted < totalFrames); } while (block > 0 && framescompleted < totalFrames);
} }
int res = updateResult; if (updateResult == eProgressFailed || updateResult == eProgressCancelled) {
if (block < 0)
res = eProgressFailed;
if (res == eProgressFailed || res == eProgressCancelled) {
// It's a shame we can't return proper error code // It's a shame we can't return proper error code
return; return;
} }