Convert sampleCount <-> floating or -> long long explicitly ...

... A non-narrowing conversion out to long long is a necessity, but the
conversions to float and double are simply conveniences.

Conversion from floating is explicit, to avoid unintended consequences with
arithmetic operators, when later sampleCount ceases to be an alias for an
integral type.

Some conversions are not made explicit, where I expect to change the type of
the variable later to have mere size_t width.
This commit is contained in:
Paul Licameli 2016-08-25 08:53:59 -04:00
parent 99dca62cff
commit 78be459fa1
53 changed files with 329 additions and 207 deletions

View File

@ -69,6 +69,11 @@ public:
operator type () const { return value; }
float as_float() const { return value; }
double as_double() const { return value; }
long long as_long_long() const { return value; }
sampleCount &operator += (sampleCount b) { value += b.value; return *this; }
sampleCount &operator -= (sampleCount b) { value -= b.value; return *this; }
sampleCount &operator *= (sampleCount b) { value *= b.value; return *this; }

View File

@ -412,7 +412,7 @@ struct AudioIO::ScrubQueue
// Needed by the main thread sometimes
wxMutexLocker locker(mUpdating);
const Entry &previous = mEntries[(mLeadingIdx + Size - 1) % Size];
return previous.mS1 / mRate;
return previous.mS1.as_double() / mRate;
}
// This is for avoiding deadlocks while starting a scrub:
@ -446,9 +446,11 @@ struct AudioIO::ScrubQueue
return false;
auto actualDuration = origDuration;
const sampleCount s1 = options.enqueueBySpeed
? s0 + lrint(origDuration * end) // end is a speed
: sampleCount(lrint(end * mRate)); // end is a time
const sampleCount s1 ( options.enqueueBySpeed
? s0.as_double() +
lrint(origDuration.as_double() * end) // end is a speed
: lrint(end * mRate) // end is a time
);
auto success =
current->Init(previous, s0, s1, actualDuration, options);
if (success)
@ -537,8 +539,10 @@ struct AudioIO::ScrubQueue
// Adjust the start time
auto &start = entry.mS0;
const auto end = entry.mS1;
const auto ratio = static_cast<double>(toDiscard) / static_cast<double>(dur);
const sampleCount adjustment = std::abs(end - start) * ratio;
const auto ratio = toDiscard.as_double() / dur.as_double();
const sampleCount adjustment(
std::abs((end - start).as_long_long()) * ratio
);
if (start <= end)
start += adjustment;
else
@ -622,7 +626,8 @@ private:
const bool &adjustStart = options.adjustStart;
wxASSERT(duration > 0);
double speed = static_cast<double>(std::abs(s1 - s0)) / duration;
double speed =
(std::abs((s1 - s0).as_long_long())) / duration.as_double();
bool adjustedSpeed = false;
auto minSpeed = std::min(options.minSpeed, options.maxSpeed);
@ -655,7 +660,7 @@ private:
if (speed < minSpeed) {
// Trim the duration.
duration = std::max(0L, lrint(speed * duration / minSpeed));
duration = std::max(0L, lrint(speed * duration.as_double() / minSpeed));
speed = minSpeed;
adjustedSpeed = true;
}
@ -672,7 +677,7 @@ private:
if (adjustedSpeed && !adjustStart)
{
// adjust s1
const sampleCount diff = lrint(speed * duration);
const sampleCount diff = lrint(speed * duration.as_double());
if (s0 < s1)
s1 = s0 + diff;
else
@ -689,8 +694,11 @@ private:
auto newDuration = duration;
const auto newS1 = std::max(options.minSample, std::min(options.maxSample, s1));
if(s1 != newS1)
newDuration = std::max<sampleCount>(0,
(duration * double(newS1 - s0) / (s1 - s0))
newDuration = std::max( sampleCount{ 0 },
sampleCount(
duration.as_double() * (newS1 - s0).as_double() /
(s1 - s0).as_double()
)
);
// When playback follows a fast mouse movement by "stuttering"
// at maximum playback, don't make stutters too short to be useful.
@ -712,7 +720,7 @@ private:
{
// Limit diff because this is seeking.
const sampleCount diff =
lrint(std::min(options.maxSpeed, speed) * duration);
lrint(std::min(options.maxSpeed, speed) * duration.as_double());
if (s0 < s1)
s0 = s1 - diff;
else
@ -737,8 +745,8 @@ private:
double GetTime(double rate) const
{
return
(mS0 +
(mS1 - mS0) * static_cast<double>(mPlayed) / static_cast<double>(mDuration))
(mS0.as_double() +
(mS1 - mS0).as_double() * mPlayed.as_double() / mDuration.as_double())
/ rate;
}
@ -3587,9 +3595,10 @@ void AudioIO::FillBuffers()
if (!mSilentScrub)
{
double startTime, endTime, speed;
startTime = startSample / mRate;
endTime = endSample / mRate;
speed = double(std::abs(endSample - startSample)) / mScrubDuration;
startTime = startSample.as_double() / mRate;
endTime = endSample.as_double() / mRate;
auto diff = (endSample - startSample).as_long_long();
speed = double(std::abs(diff)) / mScrubDuration.as_double();
for (i = 0; i < mPlaybackTracks.size(); i++)
mPlaybackMixers[i]->SetTimesAndSpeed(startTime, endTime, speed);
}

View File

@ -405,7 +405,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) {
Printf(wxT("Expected len %d, track len %lld.\n"), nChunks * chunkSize,
(long long) t->GetClipByIndex(0)->GetSequence()->GetNumSamples());
t->GetClipByIndex(0)->GetSequence()->GetNumSamples().as_long_long());
goto fail;
}
@ -426,7 +426,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
Printf(wxT("Cut (%d, %d) failed.\n"), (x0 * chunkSize),
(x0 + xlen) * chunkSize);
Printf(wxT("Expected len %d, track len %lld.\n"), nChunks * chunkSize,
(long long) t->GetClipByIndex(0)->GetSequence()->GetNumSamples());
t->GetClipByIndex(0)->GetSequence()->GetNumSamples().as_long_long());
goto fail;
}
@ -443,7 +443,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
if (t->GetClipByIndex(0)->GetSequence()->GetNumSamples() != nChunks * chunkSize) {
Printf(wxT("Trial %d\n"), z);
Printf(wxT("Expected len %d, track len %lld.\n"), nChunks * chunkSize,
(long long) t->GetClipByIndex(0)->GetSequence()->GetNumSamples());
t->GetClipByIndex(0)->GetSequence()->GetNumSamples().as_long_long());
goto fail;
}
// Copy

View File

@ -60,7 +60,9 @@ bool CrossFader::GetSamples(samplePtr buffer, sampleFormat format,
bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount start, sampleCount len)
{
std::cout << "Crossfading from " << start << " to " << len+start << std::endl;
std::cout << "Crossfading from " << start.as_long_long()
<< " to " << ( len + start ).as_long_long()
<< std::endl;
// start refers to the position in the wave.
@ -103,13 +105,23 @@ bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount
//it will be no longer than the clip itself.
clipLength[i] = tmpclip->GetNumSamples()-clipStart[i];
std::cout << "X:" << " " << clipLength[i] << " " << tmpclip->GetStartSample() << " ";
std::cout << "X:" << " "
<< clipLength[i].as_long_long()
<< " "
<< tmpclip->GetStartSample().as_long_long()
<< " ";
//if the buffer ends before the clip does, adjust the length
if(clipStart[i] + len < clipLength[i])
{
clipLength[i] = len + clipStart[i];
}
std::cout << clipStart[i] << " " << clipLength[i] << " " << clipLength[i] - clipStart[i] << std::endl;
std::cout
<< clipStart[i].as_long_long()
<< " "
<< clipLength[i].as_long_long()
<< " "
<< ( clipLength[i] - clipStart[i] ).as_long_long()
<< std::endl;
}
std::cout << "-------------\n";
@ -143,7 +155,7 @@ bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount
{
// UNSAFE_SAMPLE_COUNT_TRUNCATION
// -- but class CrossFader is not used as of this writing
f += shortSeq[i][j+ clipStart[i]];
f += shortSeq[ i ][ j+ clipStart[i].as_long_long() ];
clips++;
}
@ -193,7 +205,7 @@ bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount
{
// UNSAFE_SAMPLE_COUNT_TRUNCATION
// -- but class CrossFader is not used as of this writing
f+= intSeq[i][j+clipStart[i]];
f+= intSeq[ i ][ j + clipStart[ i ].as_long_long() ];
clips++;
}
@ -242,10 +254,11 @@ bool CrossFader::CrossFadeMix(samplePtr buffer, sampleFormat format, sampleCount
// -- hey wait, you never even tried to initialize floatSeq,
// not even with bad casts!!!
// Subscripts out of bounds, bombs away!!!
f += floatSeq[i][j + clipStart[i]];
f += floatSeq[ i ][ ( j + clipStart[ i ] ).as_long_long() ];
clips++;
}
cout << f << " "<< i << " "<< floatSeq[i][j+clipStart[i]] << "|";
cout << f << " "<< i << " "
<< floatSeq[ i ][ j + clipStart[ i ].as_long_long() ] << "|";
}
if(clips == 0)
*dest = 0.0f;

View File

@ -438,7 +438,8 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
: std::min(endTime, mT1);
const auto endPos = track->TimeToLongSamples(tEnd);
// Find the time corresponding to the start of the queue, for use with time track
double t = (*pos + (backwards ? *queueLen : - *queueLen)) / trackRate;
double t = ((*pos).as_long_long() +
(backwards ? *queueLen : - *queueLen)) / trackRate;
while (out < mMaxOut) {
if (*queueLen < mProcessLen) {
@ -459,8 +460,7 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
track->GetEnvelopeValues(mEnvValues,
getLen,
(*pos - (getLen- 1)) / trackRate);
(*pos - (getLen- 1)).as_double() / trackRate);
*pos -= getLen;
}
else {
@ -469,7 +469,7 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
track->GetEnvelopeValues(mEnvValues,
getLen,
(*pos) / trackRate);
(*pos).as_double() / trackRate);
*pos += getLen;
}
@ -552,7 +552,7 @@ sampleCount Mixer::MixSameRate(int *channelFlags, WaveTrackCache &cache,
const WaveTrack *const track = cache.GetTrack();
auto slen = mMaxOut;
int c;
const double t = *pos / track->GetRate();
const double t = ( *pos ).as_double() / track->GetRate();
const double trackEndTime = track->GetEndTime();
const double trackStartTime = track->GetStartTime();
const bool backwards = (mT1 < mT0);
@ -652,7 +652,7 @@ sampleCount Mixer::Process(sampleCount maxToProcess)
maxOut = std::max(maxOut,
MixSameRate(channelFlags, mInputTrack[i], &mSamplePos[i]));
double t = (double)mSamplePos[i] / (double)track->GetRate();
double t = mSamplePos[i].as_double() / (double)track->GetRate();
if (mT0 > mT1)
// backwards (as possibly in scrubbing)
mTime = std::max(std::min(t, mTime), mT1);

View File

@ -371,7 +371,7 @@ bool Sequence::GetRMS(sampleCount start, sampleCount len,
// PRL: catch bugs like 1320:
wxASSERT(length == len);
*outRMS = sqrt(sumsq/length);
*outRMS = sqrt(sumsq / length.as_double() );
return true;
}
@ -450,20 +450,20 @@ bool Sequence::Paste(sampleCount s, const Sequence *src)
wxLogError(
wxT("Sequence::Paste: sampleCount s %s is < 0 or > mNumSamples %s)."),
// PRL: Why bother with Internat when the above is just wxT?
Internat::ToString(((wxLongLong)s).ToDouble(), 0).c_str(),
Internat::ToString(((wxLongLong)mNumSamples).ToDouble(), 0).c_str());
Internat::ToString(s.as_double(), 0).c_str(),
Internat::ToString(mNumSamples.as_double(), 0).c_str());
wxASSERT(false);
return false;
}
// Quick check to make sure that it doesn't overflow
if (Overflows(((double)mNumSamples) + ((double)src->mNumSamples)))
if (Overflows((mNumSamples.as_double()) + (src->mNumSamples.as_double())))
{
wxLogError(
wxT("Sequence::Paste: mNumSamples %s + src->mNumSamples %s would overflow."),
// PRL: Why bother with Internat when the above is just wxT?
Internat::ToString(((wxLongLong)mNumSamples).ToDouble(), 0).c_str(),
Internat::ToString(((wxLongLong)src->mNumSamples).ToDouble(), 0).c_str());
Internat::ToString(mNumSamples.as_double(), 0).c_str(),
Internat::ToString(src->mNumSamples.as_double(), 0).c_str());
wxASSERT(false);
return false;
}
@ -629,7 +629,7 @@ bool Sequence::SetSilence(sampleCount s0, sampleCount len)
bool Sequence::InsertSilence(sampleCount s0, sampleCount len)
{
// Quick check to make sure that it doesn't overflow
if (Overflows(((double)mNumSamples) + ((double)len)))
if (Overflows((mNumSamples.as_double()) + (len.as_double())))
return false;
if (len <= 0)
@ -676,7 +676,7 @@ bool Sequence::AppendAlias(const wxString &fullPath,
sampleCount len, int channel, bool useOD)
{
// Quick check to make sure that it doesn't overflow
if (Overflows(((double)mNumSamples) + ((double)len)))
if (Overflows((mNumSamples.as_double()) + ((double)len)))
return false;
SeqBlock newBlock(
@ -695,7 +695,7 @@ bool Sequence::AppendCoded(const wxString &fName, sampleCount start,
sampleCount len, int channel, int decodeType)
{
// Quick check to make sure that it doesn't overflow
if (Overflows(((double)mNumSamples) + ((double)len)))
if (Overflows((mNumSamples.as_double()) + ((double)len)))
return false;
SeqBlock newBlock(
@ -711,7 +711,7 @@ bool Sequence::AppendCoded(const wxString &fName, sampleCount start,
bool Sequence::AppendBlock(const SeqBlock &b)
{
// Quick check to make sure that it doesn't overflow
if (Overflows(((double)mNumSamples) + ((double)b.f->GetLength())))
if (Overflows((mNumSamples.as_double()) + ((double)b.f->GetLength())))
return false;
SeqBlock newBlock(
@ -939,8 +939,8 @@ void Sequence::HandleXMLEndTag(const wxChar *tag)
wxLogWarning(
wxT(" Sequence has missing block file with length %s > mMaxSamples %s.\n Setting length to mMaxSamples. This will likely cause some block files to be considered orphans."),
// PRL: Why bother with Internat when the above is just wxT?
Internat::ToString(((wxLongLong)len).ToDouble(), 0).c_str(),
Internat::ToString(((wxLongLong)mMaxSamples).ToDouble(), 0).c_str());
Internat::ToString(len.as_double(), 0).c_str(),
Internat::ToString((double)mMaxSamples, 0).c_str());
len = mMaxSamples;
}
block.f = make_blockfile<SilentBlockFile>(len);
@ -965,9 +965,9 @@ void Sequence::HandleXMLEndTag(const wxChar *tag)
wxT(" Start (%s) for block file %s is not one sample past end of previous block (%s).\n")
wxT(" Moving start so blocks are contiguous."),
// PRL: Why bother with Internat when the above is just wxT?
Internat::ToString(((wxLongLong)(block.start)).ToDouble(), 0).c_str(),
Internat::ToString(block.start.as_double(), 0).c_str(),
sFileAndExtension.c_str(),
Internat::ToString(((wxLongLong)numSamples).ToDouble(), 0).c_str());
Internat::ToString(numSamples.as_double(), 0).c_str());
block.start = numSamples;
mErrorOpening = true;
}
@ -977,8 +977,8 @@ void Sequence::HandleXMLEndTag(const wxChar *tag)
wxLogWarning(
wxT("Gap detected in project file. Correcting sequence sample count from %s to %s."),
// PRL: Why bother with Internat when the above is just wxT?
Internat::ToString(((wxLongLong)mNumSamples).ToDouble(), 0).c_str(),
Internat::ToString(((wxLongLong)numSamples).ToDouble(), 0).c_str());
Internat::ToString(mNumSamples.as_double(), 0).c_str(),
Internat::ToString(numSamples.as_double(), 0).c_str());
mNumSamples = numSamples;
mErrorOpening = true;
}
@ -1003,7 +1003,7 @@ void Sequence::WriteXML(XMLWriter &xmlFile)
xmlFile.WriteAttr(wxT("maxsamples"), mMaxSamples);
xmlFile.WriteAttr(wxT("sampleformat"), mSampleFormat);
xmlFile.WriteAttr(wxT("numsamples"), mNumSamples);
xmlFile.WriteAttr(wxT("numsamples"), mNumSamples.as_long_long() );
for (b = 0; b < mBlock.size(); b++) {
SeqBlock &bb = mBlock[b];
@ -1024,7 +1024,7 @@ void Sequence::WriteXML(XMLWriter &xmlFile)
}
xmlFile.StartTag(wxT("waveblock"));
xmlFile.WriteAttr(wxT("start"), bb.start);
xmlFile.WriteAttr(wxT("start"), bb.start.as_long_long() );
bb.f->SaveXML(xmlFile);
@ -1050,7 +1050,8 @@ int Sequence::FindBlock(sampleCount pos) const
//this is not a binary search, but a
//dictionary search where we guess something smarter than the binary division
//of the unsearched area, since samples are usually proportional to block file number.
const double frac = double(pos - loSamples) / (hiSamples - loSamples);
const double frac = (pos - loSamples).as_double() /
(hiSamples - loSamples).as_double();
guess = std::min(hi - 1, lo + size_t(frac * (hi - lo)));
const SeqBlock &block = mBlock[guess];
@ -1333,7 +1334,7 @@ bool Sequence::GetWaveDisplay(float *min, float *max, float *rms, int* bl,
// Decide the summary level
const double samplesPerPixel =
double(whereNext - whereNow) / (nextPixel - pixel);
(whereNext - whereNow).as_double() / (nextPixel - pixel);
const int divisor =
(samplesPerPixel >= 65536) ? 65536
: (samplesPerPixel >= 256) ? 256
@ -1478,7 +1479,7 @@ bool Sequence::Append(samplePtr buffer, sampleFormat format,
sampleCount len, XMLWriter* blockFileLog /*=NULL*/)
{
// Quick check to make sure that it doesn't overflow
if (Overflows(((double)mNumSamples) + ((double)len)))
if (Overflows(mNumSamples.as_double() + ((double)len)))
return false;
// If the last block is not full, we need to add samples to it
@ -1773,7 +1774,7 @@ void Sequence::DebugPrintf(wxString *dest) const
*dest += wxString::Format
(wxT(" Block %3u: start %8lld, len %8lld, refs %ld, "),
i,
(long long) seqBlock.start,
seqBlock.start.as_long_long(),
seqBlock.f ? (long long) seqBlock.f->GetLength() : 0,
seqBlock.f ? seqBlock.f.use_count() : 0);
@ -1792,7 +1793,7 @@ void Sequence::DebugPrintf(wxString *dest) const
}
if (pos != mNumSamples)
*dest += wxString::Format
(wxT("ERROR mNumSamples = %lld\n"), (long long) mNumSamples);
(wxT("ERROR mNumSamples = %lld\n"), mNumSamples.as_long_long());
}
// static

View File

@ -1337,7 +1337,7 @@ void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect &
dc.SetPen(muted ? muteSamplePen : samplePen);
for (decltype(slen) s = 0; s < slen; s++) {
const double time = toffset + (s + s0) / rate;
const double time = toffset + (s + s0).as_double() / rate;
const int xx = // An offset into the rectangle rect
std::max(-10000, std::min(10000,
int(zoomInfo.TimeToPosition(time, -leftOffset))));
@ -1575,7 +1575,7 @@ struct ClipParameters
//trim selection so that it only contains the actual samples
if (ssel0 != ssel1 && ssel1 > (sampleCount)(0.5 + trackLen * rate)) {
ssel1 = 0.5 + trackLen * rate;
ssel1 = sampleCount( 0.5 + trackLen * rate );
}
// The variable "hiddenMid" will be the rectangle containing the
@ -2122,8 +2122,8 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache,
const double &t0 = params.t0;
const double &tOffset = params.tOffset;
const double &ssel0 = params.ssel0;
const double &ssel1 = params.ssel1;
const auto ssel0 = params.ssel0;
const auto ssel1 = params.ssel1;
const double &averagePixelsPerSample = params.averagePixelsPerSample;
const double &rate = params.rate;
const double &hiddenLeftOffset = params.hiddenLeftOffset;

View File

@ -4585,7 +4585,8 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event )
//This interpolates each sample linearly:
values[i - start] =
mDrawingLastDragSampleValue + (newLevel - mDrawingLastDragSampleValue) *
(float)(i - mDrawingLastDragSample) / (s0 - mDrawingLastDragSample);
(i - mDrawingLastDragSample).as_float() /
(s0 - mDrawingLastDragSample).as_float();
}
mDrawingTrack->Set((samplePtr)&values[0], floatSample, start, size);
}

View File

@ -88,7 +88,7 @@ VoiceKey::~VoiceKey()
sampleCount VoiceKey::OnForward (WaveTrack & t, sampleCount start, sampleCount len)
{
if((mWindowSize) >= len+10){
if((mWindowSize) >= (len + 10).as_double() ){
/* i18n-hint: Voice key is an experimental/incomplete feature that
is used to navigate in vocal recordings, to move forwards and
@ -240,7 +240,7 @@ sampleCount VoiceKey::OnBackward (WaveTrack & t, sampleCount end, sampleCount le
{
if((mWindowSize) >= len+10){
if((mWindowSize) >= (len + 10).as_double() ){
wxMessageBox(_("Selection is too small to use voice key."));
return end;
@ -377,7 +377,7 @@ sampleCount VoiceKey::OnBackward (WaveTrack & t, sampleCount end, sampleCount le
sampleCount VoiceKey::OffForward (WaveTrack & t, sampleCount start, sampleCount len)
{
if((mWindowSize) >= len+10){
if((mWindowSize) >= (len + 10).as_double() ){
wxMessageBox(_("Selection is too small to use voice key."));
return start;
@ -390,7 +390,7 @@ sampleCount VoiceKey::OffForward (WaveTrack & t, sampleCount start, sampleCount
unsigned int WindowSizeInt = (unsigned int)(rate * mWindowSize); //Size of window to examine
unsigned int SilentWindowSizeInt = (unsigned int)(rate * mSilentWindowSize); //This much signal is necessary to trip key
auto samplesleft = len - WindowSizeInt; //Indexes the number of samples remaining in the selection
sampleCount samplesleft ( len.as_double() - WindowSizeInt ); //Indexes the number of samples remaining in the selection
auto lastsubthresholdsample = start; //start this off at the selection start
// keeps track of the sample number of the last sample to not exceed the threshold
@ -513,7 +513,7 @@ sampleCount VoiceKey::OffBackward (WaveTrack & t, sampleCount end, sampleCount l
{
if((mWindowSize) >= len+10){
if((mWindowSize) >= (len + 10).as_double() ){
wxMessageBox(_("Selection is too small to use voice key."));
return end;
@ -863,7 +863,7 @@ double VoiceKey::TestEnergy (WaveTrack & t, sampleCount start, sampleCount len)
}
delete [] buffer;
return sum / originalLen;
return sum / originalLen.as_double();
}
@ -916,7 +916,7 @@ double VoiceKey::TestSignChanges(WaveTrack & t, sampleCount start, sampleCount l
s += block;
}
delete [] buffer;
return (double)signchanges/originalLen;
return (double)signchanges / originalLen.as_double();
}
void VoiceKey::TestSignChangesUpdate(double & currentsignchanges, int len,
@ -973,7 +973,7 @@ double VoiceKey::TestDirectionChanges(WaveTrack & t, sampleCount start, sampleCo
s += block;
}
delete [] buffer;
return (double)directionchanges/originalLen;
return (double)directionchanges/originalLen.as_double();
}

View File

@ -124,9 +124,9 @@ public:
return;
double samplesPerPixel = rate/pps;
//rate is SR, start is first time of the waveform (in second) on cache
long invalStart = (sampleStart - start*rate)/samplesPerPixel ;
long invalStart = (sampleStart.as_double() - start*rate) / samplesPerPixel ;
long invalEnd = (sampleEnd - start*rate)/samplesPerPixel +1; //we should cover the end..
long invalEnd = (sampleEnd.as_double() - start*rate)/samplesPerPixel +1; //we should cover the end..
//if they are both off the cache boundary in the same direction, the cache is missed,
//so we are safe, and don't need to track this one.
@ -326,7 +326,7 @@ WaveClip::WaveClip(const WaveClip& orig, const std::shared_ptr<DirManager> &proj
mEnvelope = std::make_unique<Envelope>();
mEnvelope->Paste(0.0, orig.mEnvelope.get());
mEnvelope->SetOffset(orig.GetOffset());
mEnvelope->SetTrackLen(((double)orig.mSequence->GetNumSamples()) / orig.mRate);
mEnvelope->SetTrackLen((orig.mSequence->GetNumSamples().as_double()) / orig.mRate);
mWaveCache = std::make_unique<WaveCache>();
mSpecCache = std::make_unique<SpecCache>();
mSpecPxCache = std::make_unique<SpecPxCache>(1);
@ -378,7 +378,7 @@ double WaveClip::GetEndTime() const
{
auto numSamples = mSequence->GetNumSamples();
double maxLen = mOffset + double(numSamples+mAppendBufferLen)/mRate;
double maxLen = mOffset + (numSamples+mAppendBufferLen).as_double()/mRate;
// JS: calculated value is not the length;
// it is a maximum value and can be negative; no clipping to 0
@ -387,7 +387,7 @@ double WaveClip::GetEndTime() const
sampleCount WaveClip::GetStartSample() const
{
return floor(mOffset * mRate + 0.5);
return sampleCount( floor(mOffset * mRate + 0.5) );
}
sampleCount WaveClip::GetEndSample() const
@ -446,7 +446,7 @@ void findCorrection(const std::vector<sampleCount> &oldWhere, size_t oldLen,
// Look at the loop that populates "where" below to understand this.
// Find the sample position that is the origin in the old cache.
const double oldWhere0 = oldWhere[1] - samplesPerPixel;
const double oldWhere0 = oldWhere[1].as_double() - samplesPerPixel;
const double oldWhereLast = oldWhere0 + oldLen * samplesPerPixel;
// Find the length in samples of the old cache.
const double denom = oldWhereLast - oldWhere0;
@ -485,9 +485,9 @@ fillWhere(std::vector<sampleCount> &where, size_t len, double bias, double corre
{
// Be careful to make the first value non-negative
const double w0 = 0.5 + correction + bias + t0 * rate;
where[0] = std::max(0.0, floor(w0));
where[0] = sampleCount( std::max(0.0, floor(w0)) );
for (decltype(len) x = 1; x < len + 1; x++)
where[x] = floor(w0 + double(x) * samplesPerPixel);
where[x] = sampleCount( floor(w0 + double(x) * samplesPerPixel) );
}
}
@ -783,9 +783,13 @@ bool SpecCache::CalculateOneSpectrum
sampleCount start;
if (xx < 0)
start = where[0] + xx * (rate / pixelsPerSecond);
start = sampleCount(
where[0].as_double() + xx * (rate / pixelsPerSecond)
);
else if (xx > len)
start = where[len] + (xx - len) * (rate / pixelsPerSecond);
start = sampleCount(
where[len].as_double() + (xx - len) * (rate / pixelsPerSecond)
);
else
start = where[xx];
@ -820,7 +824,7 @@ bool SpecCache::CalculateOneSpectrum
// Start is at least -windowSize / 2
for (auto ii = start; ii < 0; ++ii)
*adj++ = 0;
myLen += start;
myLen += start.as_long_long(); // add a negative
start = 0;
copy = true;
}
@ -835,8 +839,12 @@ bool SpecCache::CalculateOneSpectrum
}
if (myLen > 0) {
useBuffer = (float*)(waveTrackCache.Get(floatSample,
floor(0.5 + start + offset * rate), myLen));
useBuffer = (float*)(waveTrackCache.Get(
floatSample, sampleCount(
floor(0.5 + start.as_double() + offset * rate)
),
myLen)
);
if (copy)
memcpy(adj, useBuffer, myLen * sizeof(float));
@ -1255,17 +1263,17 @@ void WaveClip::ConvertToSampleFormat(sampleFormat format)
void WaveClip::UpdateEnvelopeTrackLen()
{
mEnvelope->SetTrackLen(((double)mSequence->GetNumSamples()) / mRate);
mEnvelope->SetTrackLen((mSequence->GetNumSamples().as_double()) / mRate);
}
void WaveClip::TimeToSamplesClip(double t0, sampleCount *s0) const
{
if (t0 < mOffset)
*s0 = 0;
else if (t0 > mOffset + double(mSequence->GetNumSamples())/mRate)
else if (t0 > mOffset + mSequence->GetNumSamples().as_double()/mRate)
*s0 = mSequence->GetNumSamples();
else
*s0 = floor(((t0 - mOffset) * mRate) + 0.5);
*s0 = sampleCount( floor(((t0 - mOffset) * mRate) + 0.5) );
}
void WaveClip::ClearDisplayRect() const
@ -1462,8 +1470,8 @@ bool WaveClip::CreateFromCopy(double t0, double t1, const WaveClip* other)
mEnvelope = std::make_unique<Envelope>();
mEnvelope->CopyFrom(other->mEnvelope.get(),
mOffset + (double)s0/mRate,
mOffset + (double)s1/mRate);
mOffset + s0.as_double()/mRate,
mOffset + s1.as_double()/mRate);
MarkChanged();
@ -1503,7 +1511,7 @@ bool WaveClip::Paste(double t0, const WaveClip* other)
if (mSequence->Paste(s0, pastedClip->mSequence.get()))
{
MarkChanged();
mEnvelope->Paste((double)s0/mRate + mOffset, pastedClip->mEnvelope.get());
mEnvelope->Paste(s0.as_double()/mRate + mOffset, pastedClip->mEnvelope.get());
mEnvelope->RemoveUnneededPoints();
OffsetCutLines(t0, pastedClip->GetEndTime() - pastedClip->GetStartTime());
@ -1823,7 +1831,10 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
if (progress)
{
int updateResult = progress->Update(pos, numSamples);
int updateResult = progress->Update(
pos.as_long_long(),
numSamples.as_long_long()
);
error = (updateResult != eProgressSuccess);
if (error)
{

View File

@ -1484,8 +1484,10 @@ bool WaveTrack::Disjoin(double t0, double t1)
if( seqEnd - seqStart + 1 > minSamples )
{
regions.push_back(Region(
seqStart / GetRate() + clip->GetStartTime(),
seqEnd / GetRate() + clip->GetStartTime()));
seqStart.as_double() / GetRate()
+ clip->GetStartTime(),
seqEnd.as_double() / GetRate()
+ clip->GetStartTime()));
}
seqStart = -1;
}
@ -1851,12 +1853,12 @@ bool WaveTrack::Unlock() const
AUDACITY_DLL_API sampleCount WaveTrack::TimeToLongSamples(double t0) const
{
return floor(t0 * mRate + 0.5);
return sampleCount( floor(t0 * mRate + 0.5) );
}
double WaveTrack::LongSamplesToTime(sampleCount pos) const
{
return ((double)pos) / mRate;
return pos.as_double() / mRate;
}
double WaveTrack::GetStartTime() const
@ -1976,15 +1978,16 @@ bool WaveTrack::GetRMS(float *rms, double t0, double t1)
{
clip->TimeToSamplesClip(wxMax(t0, clip->GetStartTime()), &clipStart);
clip->TimeToSamplesClip(wxMin(t1, clip->GetEndTime()), &clipEnd);
sumsq += cliprms * cliprms * (clipEnd - clipStart);
sumsq += cliprms * cliprms * (clipEnd - clipStart).as_float();
length += (clipEnd - clipStart);
} else
}
else
{
result = false;
}
}
}
*rms = length > 0.0 ? sqrt(sumsq / length) : 0.0;
*rms = length > 0 ? sqrt(sumsq / length.as_double()) : 0.0;
return result;
}
@ -2366,7 +2369,7 @@ bool WaveTrack::SplitAt(double t)
//offset the NEW clip by the splitpoint (noting that it is already offset to c->GetStartTime())
sampleCount here = llrint(floor(((t - c->GetStartTime()) * mRate) + 0.5));
newClip->Offset((double)here/(double)mRate);
newClip->Offset(here.as_double()/(double)mRate);
// This could invalidate the iterators for the loop! But we return
// at once so it's okay
mClips.push_back(std::move(newClip)); // transfer ownership

View File

@ -69,7 +69,7 @@ void LegacyAliasBlockFile::SaveXML(XMLWriter &xmlFile)
xmlFile.WriteAttr(wxT("name"), mFileName.GetFullName());
xmlFile.WriteAttr(wxT("aliaspath"), mAliasedFileName.GetFullPath());
xmlFile.WriteAttr(wxT("aliasstart"),
static_cast<long long>( mAliasStart ));
mAliasStart.as_long_long() );
xmlFile.WriteAttr(wxT("aliaslen"), mLen);
xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
xmlFile.WriteAttr(wxT("summarylen"), mSummaryInfo.totalSummaryBytes);

View File

@ -209,7 +209,7 @@ void ODDecodeBlockFile::SaveXML(XMLWriter &xmlFile)
LockRead();
xmlFile.WriteAttr(wxT("audiofile"), mAudioFileName.GetFullPath());
xmlFile.WriteAttr(wxT("aliasstart"),
static_cast<long long>( mAliasStart ));
mAliasStart.as_long_long());
xmlFile.WriteAttr(wxT("aliaslen"), mLen);
xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
xmlFile.WriteAttr(wxT("decodetype"), (size_t)mType);

View File

@ -248,7 +248,7 @@ void ODPCMAliasBlockFile::SaveXML(XMLWriter &xmlFile)
xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath());
xmlFile.WriteAttr(wxT("aliasstart"),
static_cast<long long>( mAliasStart));
mAliasStart.as_long_long());
xmlFile.WriteAttr(wxT("aliaslen"), mLen);
xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
@ -531,7 +531,8 @@ int ODPCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
// Third party library has its own type alias, check it
static_assert(sizeof(sampleCount::type) <= sizeof(sf_count_t),
"Type sf_count_t is too narrow to hold a sampleCount");
SFCall<sf_count_t>(sf_seek, sf.get(), mAliasStart + start, SEEK_SET);
SFCall<sf_count_t>(sf_seek, sf.get(),
( mAliasStart + start ).as_long_long(), SEEK_SET);
wxASSERT(info.channels >= 0);
SampleBuffer buffer(len * info.channels, floatSample);

View File

@ -119,7 +119,8 @@ int PCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format,
// Third party library has its own type alias, check it
static_assert(sizeof(sampleCount::type) <= sizeof(sf_count_t),
"Type sf_count_t is too narrow to hold a sampleCount");
SFCall<sf_count_t>(sf_seek, sf.get(), mAliasStart + start, SEEK_SET);
SFCall<sf_count_t>(sf_seek, sf.get(),
( mAliasStart + start ).as_long_long(), SEEK_SET);
wxASSERT(info.channels >= 0);
SampleBuffer buffer(len * info.channels, floatSample);
@ -170,7 +171,7 @@ void PCMAliasBlockFile::SaveXML(XMLWriter &xmlFile)
xmlFile.WriteAttr(wxT("summaryfile"), mFileName.GetFullName());
xmlFile.WriteAttr(wxT("aliasfile"), mAliasedFileName.GetFullPath());
xmlFile.WriteAttr(wxT("aliasstart"),
static_cast<long long>( mAliasStart ));
mAliasStart.as_long_long());
xmlFile.WriteAttr(wxT("aliaslen"), mLen);
xmlFile.WriteAttr(wxT("aliaschannel"), mAliasChannel);
xmlFile.WriteAttr(wxT("min"), mMin);

View File

@ -126,7 +126,8 @@ bool CompareAudioCommand::Apply(CommandExecutionContext context)
position += block;
Progress(
double(position - s0) / double(length)
(position - s0).as_double() /
length.as_double()
);
}

View File

@ -357,8 +357,11 @@ bool EffectAutoDuck::Process()
pos += len;
if (TotalProgress( ((double)(pos-start)) / (end-start) /
(GetNumWaveTracks() + 1) ))
if (TotalProgress(
(pos - start).as_double() /
(end - start).as_double() /
(GetNumWaveTracks() + 1)
))
{
cancel = true;
break;
@ -526,8 +529,8 @@ bool EffectAutoDuck::ApplyDuckFade(int trackNumber, WaveTrack* t,
if (fadeUpSamples < 1)
fadeUpSamples = 1;
float fadeDownStep = mDuckAmountDb / fadeDownSamples;
float fadeUpStep = mDuckAmountDb / fadeUpSamples;
float fadeDownStep = mDuckAmountDb / fadeDownSamples.as_double();
float fadeUpStep = mDuckAmountDb / fadeUpSamples.as_double();
while (pos < end)
{
@ -537,8 +540,8 @@ bool EffectAutoDuck::ApplyDuckFade(int trackNumber, WaveTrack* t,
for (auto i = pos; i < pos + len; i++)
{
float gainDown = fadeDownStep * (i - start);
float gainUp = fadeUpStep * (end - i);;
float gainDown = fadeDownStep * (i - start).as_float();
float gainUp = fadeUpStep * (end - i).as_float();
float gain;
if (gainDown > gainUp)

View File

@ -479,7 +479,7 @@ bool EffectChangeSpeed::ProcessOne(WaveTrack * track,
//Get the length of the selection (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);
auto len = (end - start).as_double();
// Initiate processing buffers, most likely shorter than
// the length of the selection being processed.
@ -524,7 +524,7 @@ bool EffectChangeSpeed::ProcessOne(WaveTrack * track,
samplePos += results.first;
// Update the Progress meter
if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) {
if (TrackProgress(mCurTrackNum, (samplePos - start).as_double() / len)) {
bResult = false;
break;
}

View File

@ -242,7 +242,8 @@ bool EffectClickRemoval::ProcessOne(int count, WaveTrack * track, sampleCount st
s += block;
if (TrackProgress(count, s / (double) len)) {
if (TrackProgress(count, s.as_double() /
len.as_double())) {
bResult = false;
break;
}

View File

@ -122,8 +122,8 @@ bool EffectDtmf::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames
numSamplesSequence = nT1 - nT0; // needs to be exact number of samples selected
//make under-estimates if anything, and then redistribute the few remaining samples
numSamplesTone = floor(dtmfTone * mSampleRate);
numSamplesSilence = floor(dtmfSilence * mSampleRate);
numSamplesTone = sampleCount( floor(dtmfTone * mSampleRate) );
numSamplesSilence = sampleCount( floor(dtmfSilence * mSampleRate) );
// recalculate the sum, and spread the difference - due to approximations.
// Since diff should be in the order of "some" samples, a division (resulting in zero)
@ -528,7 +528,9 @@ bool EffectDtmf::MakeDtmfTone(float *buffer, sampleCount len, float fs, wxChar t
// now generate the wave: 'last' is used to avoid phase errors
// when inside the inner for loop of the Process() function.
for(decltype(len) i = 0; i < len; i++) {
buffer[i]=amplitude*0.5*(sin(A*(i+last))+sin(B*(i+last)));
buffer[i] = amplitude * 0.5 *
(sin( A * (i + last).as_double() ) +
sin( B * (i + last).as_double() ));
}
// generate a fade-in of duration 1/250th of second

View File

@ -1566,7 +1566,7 @@ bool Effect::ProcessTrack(int count,
genDur = mDuration;
}
genLength = left->GetRate() * genDur;
genLength = sampleCount( left->GetRate() * genDur );
delayRemaining = genLength;
cleared = true;
@ -1772,7 +1772,9 @@ bool Effect::ProcessTrack(int count,
if (mNumChannels > 1)
{
if (TrackGroupProgress(count, (inLeftPos - leftStart) / (double) (isGenerator ? genLength : len)))
if (TrackGroupProgress(count,
(inLeftPos - leftStart).as_double() /
(isGenerator ? genLength : len).as_double()))
{
rc = false;
break;
@ -1780,7 +1782,9 @@ bool Effect::ProcessTrack(int count,
}
else
{
if (TrackProgress(count, (inLeftPos - leftStart) / (double) (isGenerator ? genLength : len)))
if (TrackProgress(count,
(inLeftPos - leftStart).as_double() /
(isGenerator ? genLength : len).as_double()))
{
rc = false;
break;

View File

@ -1117,7 +1117,8 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
len -= block;
s += block;
if (TrackProgress(count, (s-start)/(double)originalLen))
if (TrackProgress(count, ( s - start ).as_double() /
originalLen.as_double()))
{
bLoopSuccess = false;
break;

View File

@ -84,14 +84,18 @@ sampleCount EffectFade::ProcessBlock(float **inBlock, float **outBlock, sampleCo
{
for (decltype(blockLen) i = 0; i < blockLen; i++)
{
obuf[i] = (ibuf[i] * ((float) mSample++)) / mSampleCnt;
obuf[i] =
(ibuf[i] * ( mSample++ ).as_float()) /
mSampleCnt.as_float();
}
}
else
{
for (decltype(blockLen) i = 0; i < blockLen; i++)
{
obuf[i] = (ibuf[i] * ((float) mSampleCnt - 1 - mSample++)) / mSampleCnt;
obuf[i] = (ibuf[i] *
( mSampleCnt - 1 - mSample++ ).as_float()) /
mSampleCnt.as_float();
}
}

View File

@ -179,7 +179,9 @@ bool EffectFindClipping::ProcessOne(LabelTrack * lt,
while (s < len) {
if (block == 0) {
if (TrackProgress(count, s / (double) len)) {
if (TrackProgress(count,
s.as_double() /
len.as_double() )) {
bGoodResult = false;
break;
}
@ -210,7 +212,7 @@ bool EffectFindClipping::ProcessOne(LabelTrack * lt,
if (stoprun >= mStop) {
lt->AddLabel(SelectedRegion(startTime,
wt->LongSamplesToTime(start + s - mStop)),
wxString::Format(wxT("%lld of %lld"), (long long) startrun, (long long) (samps - mStop)));
wxString::Format(wxT("%lld of %lld"), startrun.as_long_long(), (samps - mStop).as_long_long()));
startrun = 0;
stoprun = 0;
samps = 0;

View File

@ -133,7 +133,9 @@ bool BlockGenerator::GenerateTrack(WaveTrack *tmp,
i += block;
// Update the progress meter
if (TrackProgress(ntrack, (double)i / numSamples))
if (TrackProgress(ntrack,
i.as_double() /
numSamples.as_double()))
bGoodResult = false;
}
delete[] data;

View File

@ -1312,7 +1312,9 @@ bool EffectNoiseReduction::Worker::ProcessOne
// Update the Progress meter, let user cancel
bLoopSuccess =
!effect.TrackProgress(count, (samplePos - start) / (double)len);
!effect.TrackProgress(count,
( samplePos - start ).as_double() /
len.as_double() );
}
if (bLoopSuccess) {

View File

@ -377,7 +377,7 @@ bool EffectNormalize::AnalyseDC(WaveTrack * track, const wxString &msg)
//Get the length of the buffer (as double). len is
//used simply 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);
auto len = (end - start).as_double();
//Initiate a processing buffer. This buffer will (most likely)
//be shorter than the length of the track being processed.
@ -408,7 +408,7 @@ bool EffectNormalize::AnalyseDC(WaveTrack * track, const wxString &msg)
//Update the Progress meter
if (TrackProgress(mCurTrackNum,
((double)(s - start) / len)/2.0, msg)) {
((s - start).as_double() / len)/2.0, msg)) {
rc = false; //lda .. break, not return, so that buffer is deleted
break;
}
@ -417,7 +417,7 @@ bool EffectNormalize::AnalyseDC(WaveTrack * track, const wxString &msg)
//Clean up the buffer
delete[] buffer;
mOffset = (float)(-mSum / mCount); // calculate actual offset (amount that needs to be added on)
mOffset = -mSum / mCount.as_double(); // calculate actual offset (amount that needs to be added on)
//Return true because the effect processing succeeded ... unless cancelled
return rc;
@ -437,7 +437,7 @@ bool EffectNormalize::ProcessOne(WaveTrack * track, const wxString &msg)
//Get the length of the buffer (as double). len is
//used simply 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);
auto len = (end - start).as_double();
//Initiate a processing buffer. This buffer will (most likely)
//be shorter than the length of the track being processed.
@ -468,7 +468,7 @@ bool EffectNormalize::ProcessOne(WaveTrack * track, const wxString &msg)
//Update the Progress meter
if (TrackProgress(mCurTrackNum,
0.5+((double)(s - start) / len)/2.0, msg)) {
0.5+((s - start).as_double() / len)/2.0, msg)) {
rc = false; //lda .. break, not return, so that buffer is deleted
break;
}

View File

@ -273,7 +273,7 @@ bool EffectPaulstretch::ProcessOne(WaveTrack *track,double t0,double t1,int coun
if (len < minDuration) { //error because the selection is too short
float maxTimeRes = log(len) / log(2.0);
float maxTimeRes = log( len.as_double() ) / log(2.0);
maxTimeRes = pow(2.0, floor(maxTimeRes) + 0.5);
maxTimeRes = maxTimeRes / track->GetRate();
@ -313,8 +313,9 @@ bool EffectPaulstretch::ProcessOne(WaveTrack *track,double t0,double t1,int coun
}
double adjust_amount = (double)len /
((double)len - ((double)stretch_buf_size * 2.0));
auto dlen = len.as_double();
double adjust_amount = dlen /
(dlen - ((double)stretch_buf_size * 2.0));
amount = 1.0 + (amount - 1.0) * adjust_amount;
auto outputTrack = mFactory->NewWaveTrack(track->GetSampleFormat(),track->GetRate());
@ -371,11 +372,13 @@ bool EffectPaulstretch::ProcessOne(WaveTrack *track,double t0,double t1,int coun
stretch.out_bufsize);
nget = stretch.get_nsamples();
if (TrackProgress(count, (s / (double) len))) {
if (TrackProgress(count,
s.as_double() / len.as_double()
)) {
cancelled=true;
break;
};
};
}
}
delete [] fade_track_smps;
outputTrack->Flush();

View File

@ -396,7 +396,10 @@ sampleCount EffectPhaser::InstanceProcess(EffectPhaserState & data, float **inBl
if (((data.skipcount++) % lfoskipsamples) == 0)
{
//compute sine between 0 and 1
data.gain = (1.0 + cos(data.skipcount * data.lfoskip + data.phase)) / 2.0;
data.gain =
(1.0 +
cos(data.skipcount.as_double() * data.lfoskip
+ data.phase)) / 2.0;
// change lfo shape
data.gain = expm1(data.gain * phaserlfoshape) / expm1(phaserlfoshape);

View File

@ -245,7 +245,8 @@ bool EffectReverse::ProcessOneClip(int count, WaveTrack *track,
len -= 2 * block;
first += block;
if( TrackProgress(count, 2*(first-originalStart) / (double) originalLen) ) {
if( TrackProgress(count, 2 * ( first - originalStart ).as_double() /
originalLen.as_double() ) ) {
rc = false;
break;
}

View File

@ -116,8 +116,8 @@ long resampleCB(void *cb_data, SBSMSFrame *data)
data->buf = r->buf;
data->size = blockSize;
if(r->bPitch) {
float t0 = (float)(r->processed) / r->iface->getSamplesToInput();
float t1 = (float)(r->processed + blockSize) / r->iface->getSamplesToInput();
float t0 = r->processed.as_float() / r->iface->getSamplesToInput();
float t1 = (r->processed + blockSize).as_float() / r->iface->getSamplesToInput();
data->ratio0 = r->iface->getStretch(t0);
data->ratio1 = r->iface->getStretch(t1);
} else {
@ -295,7 +295,7 @@ bool EffectSBSMS::Process()
auto samplesIn = end - start;
// Samples for SBSMS to process after resampling
auto samplesToProcess = (sampleCount) ((float)samplesIn*(srProcess/srTrack));
auto samplesToProcess = (sampleCount) (samplesIn.as_float() * (srProcess/srTrack));
SlideType outSlideType;
SBSMSResampleCB outResampleCB;
@ -310,12 +310,12 @@ bool EffectSBSMS::Process()
static_assert(sizeof(sampleCount::type) <=
sizeof(_sbsms_::SampleCountType),
"Type _sbsms_::SampleCountType is too narrow to hold a sampleCount");
rb.iface = std::make_unique<SBSMSInterfaceSliding>(&rateSlide,&pitchSlide,
bPitchReferenceInput,
samplesToProcess,0,
nullptr);
rb.iface = std::make_unique<SBSMSInterfaceSliding>
(&rateSlide, &pitchSlide, bPitchReferenceInput,
static_cast<_sbsms_::SampleCountType>
( samplesToProcess.as_long_long() ),
0, nullptr);
} else {
rb.bPitch = false;
outSlideType = (srProcess==srTrack?SlideIdentity:SlideConstant);
@ -332,13 +332,14 @@ bool EffectSBSMS::Process()
processPresamples =
std::min(processPresamples,
decltype(processPresamples)
((float)(start-trackStart)*(srProcess/srTrack)));
(( start - trackStart ).as_float() *
(srProcess/srTrack)));
auto trackPresamples = start - trackStart;
trackPresamples =
std::min(trackPresamples,
decltype(trackPresamples)
((float)(processPresamples)*(srTrack/srProcess)));
(processPresamples.as_float() *
(srTrack/srProcess)));
rb.offset = start - trackPresamples;
rb.end = trackEnd;
rb.iface = std::make_unique<SBSMSEffectInterface>
@ -346,11 +347,9 @@ bool EffectSBSMS::Process()
bPitchReferenceInput,
// UNSAFE_SAMPLE_COUNT_TRUNCATION
// The argument type is only long!
static_cast<long> ( static_cast<size_t> (
samplesToProcess ) ),
static_cast<long> ( samplesToProcess.as_long_long() ),
// This argument type is also only long!
static_cast<long> ( static_cast<size_t> (
processPresamples ) ),
static_cast<long> ( processPresamples.as_long_long() ),
rb.quality.get());
}
@ -364,7 +363,7 @@ bool EffectSBSMS::Process()
sampleCount samplesToOutput = rb.iface->getSamplesToOutput();
// Samples in output after resampling back
auto samplesOut = (sampleCount) ((float)samplesToOutput * (srTrack/srProcess));
auto samplesOut = (sampleCount) (samplesToOutput.as_float() * (srTrack/srProcess));
// Duration in track time
double duration = (mCurT1-mCurT0) * mTotalStretch;
@ -399,7 +398,7 @@ bool EffectSBSMS::Process()
if(rightTrack)
rb.outputRightTrack->Append((samplePtr)outBufRight, floatSample, outputCount);
double frac = (double)pos/(double)samplesOut;
double frac = (double)pos / samplesOut.as_double();
int nWhichTrack = mCurTrackNum;
if(rightTrack) {
nWhichTrack = 2*(mCurTrackNum/2);

View File

@ -84,7 +84,7 @@ bool EffectSimpleMono::ProcessOne(WaveTrack * track,
//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);
auto len = (end - start).as_double();
//Initiate a processing buffer. This buffer will (most likely)
//be shorter than the length of the track being processed.
@ -118,7 +118,9 @@ bool EffectSimpleMono::ProcessOne(WaveTrack * track,
s += block;
//Update the Progress meter
if (TrackProgress(mCurTrackNum, (s - start) / len)) {
if (TrackProgress(mCurTrackNum,
(s - start).as_double() /
len)) {
delete[]buffer;
return false;
}

View File

@ -178,7 +178,7 @@ bool EffectSoundTouch::ProcessOne(WaveTrack *track,
//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);
auto len = (end - start).as_double();
//Initiate a processing buffer. This buffer will (most likely)
//be shorter than the length of the track being processed.
@ -211,7 +211,7 @@ bool EffectSoundTouch::ProcessOne(WaveTrack *track,
s += block;
//Update the Progress meter
if (TrackProgress(mCurTrackNum, (s - start) / len))
if (TrackProgress(mCurTrackNum, (s - start).as_double() / len))
return false;
}
@ -256,7 +256,7 @@ bool EffectSoundTouch::ProcessStereo(WaveTrack* leftTrack, WaveTrack* rightTrack
//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);
double len = (end - start).as_double();
//Initiate a processing buffer. This buffer will (most likely)
//be shorter than the length of the track being processed.
@ -304,7 +304,7 @@ bool EffectSoundTouch::ProcessStereo(WaveTrack* leftTrack, WaveTrack* rightTrack
//Update the Progress meter
// mCurTrackNum is left track. Include right track.
int nWhichTrack = mCurTrackNum;
double frac = (sourceSampleCount - start) / len;
double frac = (sourceSampleCount - start).as_double() / len;
if (frac < 0.5)
frac *= 2.0; // Show twice as far for each track, because we're doing 2 at once.
else

View File

@ -154,7 +154,7 @@ bool EffectStereoToMono::ProcessOne(int count)
leftBuffer[i] = curMonoFrame;
}
bResult &= mOutTrack->Append((samplePtr)leftBuffer, floatSample, limit);
if (TrackProgress(count, 2.*((double)index / (double)(mEnd - mStart))))
if (TrackProgress(count, 2.*(index.as_double() / (mEnd - mStart).as_double())))
return false;
}

View File

@ -169,8 +169,12 @@ sampleCount EffectToneGen::ProcessBlock(float **WXUNUSED(inBlock), float **outBl
double BlendedLogFrequency = 0.0;
// calculate delta, and reposition from where we left
double amplitudeQuantum = (mAmplitude[1] - mAmplitude[0]) / mSampleCnt;
BlendedAmplitude = mAmplitude[0] + amplitudeQuantum * mSample;
auto doubleSampleCount = mSampleCnt.as_double();
auto doubleSample = mSample.as_double();
double amplitudeQuantum =
(mAmplitude[1] - mAmplitude[0]) / doubleSampleCount;
BlendedAmplitude = mAmplitude[0] +
amplitudeQuantum * doubleSample;
// precalculations:
double pre2PI = 2.0 * M_PI;
@ -183,15 +187,15 @@ sampleCount EffectToneGen::ProcessBlock(float **WXUNUSED(inBlock), float **outBl
mLogFrequency[0] = log10(mFrequency[0]);
mLogFrequency[1] = log10(mFrequency[1]);
// calculate delta, and reposition from where we left
frequencyQuantum = (mLogFrequency[1] - mLogFrequency[0]) / mSampleCnt;
BlendedLogFrequency = mLogFrequency[0] + frequencyQuantum * mSample;
frequencyQuantum = (mLogFrequency[1] - mLogFrequency[0]) / doubleSampleCount;
BlendedLogFrequency = mLogFrequency[0] + frequencyQuantum * doubleSample;
BlendedFrequency = pow(10.0, BlendedLogFrequency);
}
else
{
// this for regular case, linear interpolation
frequencyQuantum = (mFrequency[1] - mFrequency[0]) / mSampleCnt;
BlendedFrequency = mFrequency[0] + frequencyQuantum * mSample;
frequencyQuantum = (mFrequency[1] - mFrequency[0]) / doubleSampleCount;
BlendedFrequency = mFrequency[0] + frequencyQuantum * doubleSample;
}
// synth loop

View File

@ -553,7 +553,7 @@ bool EffectTruncSilence::Analyze(RegionList& silenceList,
double previewLength;
gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLength, 6.0);
// Minimum required length in samples.
const sampleCount previewLen = previewLength * wt->GetRate();
const sampleCount previewLen( previewLength * wt->GetRate() );
// Keep position in overall silences list for optimization
RegionList::iterator rit(silenceList.begin());
@ -574,8 +574,10 @@ bool EffectTruncSilence::Analyze(RegionList& silenceList,
if (!inputLength) {
// Show progress dialog, test for cancellation
bool cancelled = TotalProgress(
detectFrac * (whichTrack + (*index - start) / (double)(end - start)) /
(double)GetNumWaveTracks());
detectFrac * (whichTrack +
(*index - start).as_double() /
(end - start).as_double()) /
(double)GetNumWaveTracks());
if (cancelled) {
delete [] buffer;
return false;
@ -649,8 +651,11 @@ bool EffectTruncSilence::Analyze(RegionList& silenceList,
break;
case kCompress:
allowed = wt->TimeToLongSamples(mInitialAllowedSilence);
outLength += allowed +
(*silentFrame - allowed) * mSilenceCompressPercent / 100.0;
outLength += sampleCount(
allowed.as_double() +
(*silentFrame - allowed).as_double()
* mSilenceCompressPercent / 100.0
);
break;
// default: // Not currently used.
}

View File

@ -105,7 +105,7 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
//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);
auto len = (end - start).as_double();
auto maxblock = track->GetMaxBlockSize();
//Initiate a processing buffer. This buffer will (most likely)
@ -165,9 +165,13 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
//Update the Progress meter
if (mSecondPassDisabled)
ret = TotalProgress((mCurTrackNum + (s-start)/len) / GetNumWaveTracks());
ret = TotalProgress(
(mCurTrackNum + (s-start).as_double()/len) /
GetNumWaveTracks());
else
ret = TotalProgress((mCurTrackNum + (s-start)/len + GetNumWaveTracks()*mPass)/ (GetNumWaveTracks()*2));
ret = TotalProgress(
(mCurTrackNum + (s-start).as_double()/len + GetNumWaveTracks()*mPass) /
(GetNumWaveTracks()*2));
if (ret) {
delete[]buffer1;
delete[]buffer2;

View File

@ -1213,7 +1213,7 @@ sampleCount AudioUnitEffect::GetLatency()
&latency,
&dataSize);
return latency * mSampleRate;
return sampleCount( latency * mSampleRate );
}
return 0;

View File

@ -903,7 +903,7 @@ sampleCount LadspaEffect::GetLatency()
if (mUseLatency && mLatencyPort >= 0 && !mLatencyDone)
{
mLatencyDone = true;
return mOutputControls[mLatencyPort];
return sampleCount ( mOutputControls[mLatencyPort] );
}
return 0;

View File

@ -774,7 +774,7 @@ sampleCount LV2Effect::GetLatency()
if (mUseLatency && mLatencyPort >= 0 && !mLatencyDone)
{
mLatencyDone = true;
return mLatency;
return sampleCount( mLatency );
}
return 0;

View File

@ -972,7 +972,7 @@ bool NyquistEffect::ProcessOne()
// increased with a nyquist comment directive.
// See the parsing of "maxlen"
auto curLen = (long)(static_cast<long long>(mCurLen));
auto curLen = long(mCurLen.as_long_long());
nyx_set_audio_params(mCurTrack[0]->GetRate(), curLen);
nyx_set_input_audio(StaticGetCallback, (void *)this,
@ -1758,7 +1758,8 @@ int NyquistEffect::GetCallback(float *buffer, int ch,
len);
if (ch == 0) {
double progress = mScale*(((float)start+len)/mCurLen);
double progress = mScale *
( (start+len)/ mCurLen.as_double() );
if (progress > mProgressIn) {
mProgressIn = progress;

View File

@ -524,7 +524,7 @@ bool VampEffect::Process()
// UNSAFE_SAMPLE_COUNT_TRUNCATION
// Truncation in case of very long tracks!
Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime(
(long) static_cast<long long>( ls ),
long( ls.as_long_long() ),
(int)(mRate + 0.5)
);
@ -545,14 +545,18 @@ bool VampEffect::Process()
if (channels > 1)
{
if (TrackGroupProgress(count, (ls - lstart) / double(originalLen)))
if (TrackGroupProgress(count,
(ls - lstart).as_double() /
originalLen.as_double() ))
{
return false;
}
}
else
{
if (TrackProgress(count, (ls - lstart) / double(originalLen)))
if (TrackProgress(count,
(ls - lstart).as_double() /
originalLen.as_double() ))
{
return false;
}

View File

@ -615,8 +615,14 @@ int FFmpegImportFileHandle::Import(TrackFactory *trackFactory,
// This only works well for single streams since we assume
// each stream is of the same duration and channels
res = mProgress->Update(i+sampleDuration*c+ sampleDuration*sc->m_stream->codec->channels*s,
sampleDuration*sc->m_stream->codec->channels*mNumStreams);
res = mProgress->Update(
(i+sampleDuration * c +
sampleDuration*sc->m_stream->codec->channels * s
).as_long_long(),
(sampleDuration *
sc->m_stream->codec->channels * mNumStreams
).as_long_long()
);
if (res != eProgressSuccess)
break;
}

View File

@ -499,7 +499,10 @@ int FLACImportFileHandle::Import(TrackFactory *trackFactory,
for (int c = 0; c < mNumChannels; ++c, ++iter)
iter->get()->AppendCoded(mFilename, i, blockLen, c, ODTask::eODFLAC);
mUpdateResult = mProgress->Update(i, fileTotalFrames);
mUpdateResult = mProgress->Update(
i.as_long_long(),
fileTotalFrames.as_long_long()
);
if (mUpdateResult != eProgressSuccess)
break;
}

View File

@ -400,13 +400,21 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
iter->get()->AppendAlias(mFilename, i, blockLen, c,useOD);
if (++updateCounter == 50) {
updateResult = mProgress->Update(i, fileTotalFrames);
updateResult = mProgress->Update(
i.as_long_long(),
fileTotalFrames.as_long_long()
);
updateCounter = 0;
if (updateResult != eProgressSuccess)
break;
}
}
updateResult = mProgress->Update(fileTotalFrames, fileTotalFrames);
// One last update for completion
updateResult = mProgress->Update(
fileTotalFrames.as_long_long(),
fileTotalFrames.as_long_long()
);
if(useOD)
{
@ -485,8 +493,10 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
framescompleted += block;
}
updateResult = mProgress->Update((long long unsigned)framescompleted,
(long long unsigned)fileTotalFrames);
updateResult = mProgress->Update(
framescompleted.as_long_long(),
fileTotalFrames.as_long_long()
);
if (updateResult != eProgressSuccess)
break;

View File

@ -360,8 +360,9 @@ int QTImportFileHandle::Import(TrackFactory *trackFactory,
numSamples += numFrames;
updateResult = mProgress->Update((wxULongLong_t)numSamples,
(wxULongLong_t)totSamples);
updateResult = mProgress->Update(
numSamples.as_long_long(),
totSamples.as_long_long() );
if (numFrames == 0 || flags & kQTMovieAudioExtractionComplete) {
break;

View File

@ -278,8 +278,10 @@ void ImportRaw(wxWindow *parent, const wxString &fileName,
framescompleted += block;
}
updateResult = progress.Update((wxULongLong_t)framescompleted,
(wxULongLong_t)totalFrames);
updateResult = progress.Update(
framescompleted.as_long_long(),
totalFrames.as_long_long()
);
if (updateResult != eProgressSuccess)
break;

View File

@ -204,7 +204,9 @@ void ODComputeSummaryTask::Update()
const auto odpcmaFile =
std::static_pointer_cast<ODPCMAliasBlockFile>(file);
odpcmaFile->SetStart(block.start);
odpcmaFile->SetClipOffset(clip->GetStartTime()*clip->GetRate());
odpcmaFile->SetClipOffset(sampleCount(
clip->GetStartTime()*clip->GetRate()
));
//these will always be linear within a sequence-lets take advantage of this by keeping a cursor.
while(insertCursor<(int)tempBlocks.size()&&

View File

@ -330,7 +330,10 @@ int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCo
mCurrentPos = start+len +1;
while(numAttempts++ < kMaxSeekRewindAttempts && mCurrentPos > start) {
//we want to move slightly before the start of the block file, but not too far ahead
targetts = (start-kDecodeSampleAllowance*numAttempts/kMaxSeekRewindAttempts) * ((double)st->time_base.den/(st->time_base.num * st->codec->sample_rate ));
targetts =
(start - kDecodeSampleAllowance * numAttempts / kMaxSeekRewindAttempts)
.as_long_long() *
((double)st->time_base.den/(st->time_base.num * st->codec->sample_rate ));
if(targetts<0)
targetts=0;
@ -384,7 +387,7 @@ int ODFFmpegDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCo
seeking = false;
}
if(actualDecodeStart != mCurrentPos)
printf("ts not matching - now:%llu , last:%llu, lastlen:%llu, start %llu, len %llu\n",actualDecodeStart, mCurrentPos, mCurrentLen, start, len);
printf("ts not matching - now:%llu , last:%llu, lastlen:%llu, start %llu, len %llu\n",actualDecodeStart.as_long_long(), mCurrentPos.as_long_long(), mCurrentLen, start.as_long_long(), len);
//if we've skipped over some samples, fill the gap with silence. This could happen often in the beginning of the file.
if(actualDecodeStart>start && firstpass) {
// find the number of samples for the leading silence

View File

@ -194,7 +194,7 @@ int ODFlacDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCoun
static_assert(sizeof(sampleCount::type) <=
sizeof(FLAC__int64),
"Type FLAC__int64 is too narrow to hold a sampleCount");
if(!mFile->seek_absolute(start))
if(!mFile->seek_absolute(static_cast<FLAC__int64>( start.as_long_long() )))
{
mFlacFileLock.Unlock();
return -1;

View File

@ -159,7 +159,9 @@ void ODDecodeTask::Update()
std::static_pointer_cast<ODDecodeBlockFile>(file))->GetDecodeType() == this->GetODType())
{
oddbFile->SetStart(block.start);
oddbFile->SetClipOffset(clip->GetStartTime()*clip->GetRate());
oddbFile->SetClipOffset(sampleCount(
clip->GetStartTime()*clip->GetRate()
));
//these will always be linear within a sequence-lets take advantage of this by keeping a cursor.
while(insertCursor<(int)tempBlocks.size()&&

View File

@ -437,9 +437,9 @@ void SelectionBar::ValuesToControls()
{ // mRightTime is the length.
// Be sure to take into account the sub-sample offset.
// See TimeToLongSamples and LongSamplesToTime but here at the project rate.
double t = (sampleCount)floor(mEnd * mRate + 0.5);
t -= (sampleCount)floor(mStart * mRate + 0.5);
t /= mRate;
auto samples = (sampleCount)floor(mEnd * mRate + 0.5);
samples -= (sampleCount)floor(mStart * mRate + 0.5);
auto t = samples.as_double() / mRate;
mRightTime->SetValue(t);
}

View File

@ -793,7 +793,7 @@ void NumericConverter::ValueToControls(double rawValue, bool nearest /* = true *
if (theValue < 0)
t_frac = -1;
else
t_frac = (theValue - t_int);
t_frac = (theValue - t_int.as_double() );
unsigned int i;
int tenMins;
int mins;
@ -849,7 +849,7 @@ void NumericConverter::ValueToControls(double rawValue, bool nearest /* = true *
if (t_int >= 0) {
// UNSAFE_SAMPLE_COUNT_TRUNCATION
// truncation danger!
value = (static_cast<long long>( t_int ) / mFields[i].base);
value = (t_int.as_long_long() / mFields[i].base);
if (mFields[i].range > 0)
value = value % mFields[i].range;
}