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

Various incidentals to the ongoing sampleCount sweep

Some simplification in the Repair effect
  Rewrite RingBuffer methods with size_t arguments and returns
  Rewrite Resample::Process to take and return size_t values
  SAMPLE_SIZE macro returns size_t
  BlockFile::GetSpaceUsage() returns an unsigned value
  Return wide type from ImportFileHandle::GetFileUncompressedBytes()...
  Undo a global effect with RAII
  these functions do not need to be virtual
  Comments where casting to sampleCount from other library typedefs
  Fix incorrect comment, use auto
This commit is contained in:
Paul Licameli 2016-09-06 12:40:30 -04:00
commit 3da69173d3
45 changed files with 215 additions and 241 deletions

View File

@ -58,7 +58,6 @@
#include "NoteTrack.h"
#include "Prefs.h"
#include "Project.h"
#include "Resample.h"
#include "SampleFormat.h"
#include "Sequence.h"
#include "TimeTrack.h"

View File

@ -3052,34 +3052,21 @@ MidiThread::ExitCode MidiThread::Entry()
}
#endif
int AudioIO::GetCommonlyAvailPlayback()
size_t AudioIO::GetCommonlyAvailPlayback()
{
int commonlyAvail = mPlaybackBuffers[0]->AvailForPut();
unsigned int i;
for (i = 1; i < mPlaybackTracks.size(); i++)
{
int thisBlockAvail = mPlaybackBuffers[i]->AvailForPut();
if( thisBlockAvail < commonlyAvail )
commonlyAvail = thisBlockAvail;
}
auto commonlyAvail = mPlaybackBuffers[0]->AvailForPut();
for (unsigned i = 1; i < mPlaybackTracks.size(); ++i)
commonlyAvail = std::min(commonlyAvail,
mPlaybackBuffers[i]->AvailForPut());
return commonlyAvail;
}
int AudioIO::GetCommonlyAvailCapture()
size_t AudioIO::GetCommonlyAvailCapture()
{
int commonlyAvail = mCaptureBuffers[0]->AvailForGet();
unsigned int i;
for (i = 1; i < mCaptureTracks.size(); i++)
{
int avail = mCaptureBuffers[i]->AvailForGet();
if( avail < commonlyAvail )
commonlyAvail = avail;
}
auto commonlyAvail = mCaptureBuffers[0]->AvailForGet();
for (unsigned i = 1; i < mCaptureTracks.size(); ++i)
commonlyAvail = std::min(commonlyAvail,
mCaptureBuffers[i]->AvailForGet());
return commonlyAvail;
}
@ -3546,7 +3533,11 @@ void AudioIO::FillBuffers()
processed = mPlaybackMixers[i]->Process(frames);
wxASSERT(processed <= frames);
warpedSamples = mPlaybackMixers[i]->GetBuffer();
mPlaybackBuffers[i]->Put(warpedSamples, floatSample, processed);
const auto put = mPlaybackBuffers[i]->Put
(warpedSamples, floatSample, processed);
// wxASSERT(put == processed);
// but we can't assert in this thread
wxUnusedVar(put);
}
//if looping and processed is less than the full chunk/block/buffer that gets pulled from
@ -3560,7 +3551,11 @@ void AudioIO::FillBuffers()
{
mSilentBuf.Resize(frames, floatSample);
ClearSamples(mSilentBuf.ptr(), floatSample, 0, frames);
mPlaybackBuffers[i]->Put(mSilentBuf.ptr(), floatSample, frames - processed);
const auto put = mPlaybackBuffers[i]->Put
(mSilentBuf.ptr(), floatSample, frames - processed);
// wxASSERT(put == frames - processed);
// but we can't assert in this thread
wxUnusedVar(put);
}
}
@ -3626,7 +3621,7 @@ void AudioIO::FillBuffers()
if (mCaptureTracks.size() > 0) // start record buffering
{
int commonlyAvail = GetCommonlyAvailCapture();
auto commonlyAvail = GetCommonlyAvailCapture();
//
// Determine how much this will add to captured tracks
@ -3643,7 +3638,7 @@ void AudioIO::FillBuffers()
for( i = 0; (int)i < numChannels; i++ )
{
int avail = commonlyAvail;
auto avail = commonlyAvail;
sampleFormat trackFormat = mCaptureTracks[i]->GetSampleFormat();
AutoSaveFile appendLog;
@ -3651,22 +3646,32 @@ void AudioIO::FillBuffers()
if( mFactor == 1.0 )
{
SampleBuffer temp(avail, trackFormat);
const auto got =
mCaptureBuffers[i]->Get(temp.ptr(), trackFormat, avail);
// wxASSERT(got == avail);
// but we can't assert in this thread
wxUnusedVar(got);
mCaptureTracks[i]-> Append(temp.ptr(), trackFormat, avail, 1,
&appendLog);
}
else
{
int size = lrint(avail * mFactor);
size_t size = lrint(avail * mFactor);
SampleBuffer temp1(avail, floatSample);
SampleBuffer temp2(size, floatSample);
const auto got =
mCaptureBuffers[i]->Get(temp1.ptr(), floatSample, avail);
// wxASSERT(got == avail);
// but we can't assert in this thread
wxUnusedVar(got);
/* we are re-sampling on the fly. The last resampling call
* must flush any samples left in the rate conversion buffer
* so that they get recorded
*/
size = mResample[i]->Process(mFactor, (float *)temp1.ptr(), avail, !IsStreamActive(),
&size, (float *)temp2.ptr(), size);
const auto results =
mResample[i]->Process(mFactor, (float *)temp1.ptr(), avail,
!IsStreamActive(), (float *)temp2.ptr(), size);
size = results.second;
mCaptureTracks[i]-> Append(temp2.ptr(), floatSample, size, 1,
&appendLog);
}
@ -4320,7 +4325,13 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
for (i = 0; i < (unsigned int)numPlaybackTracks; i++)
{
gAudioIO->mPlaybackMixers[i]->Reposition(gAudioIO->mTime);
gAudioIO->mPlaybackBuffers[i]->Discard(gAudioIO->mPlaybackBuffers[i]->AvailForGet());
const auto toDiscard =
gAudioIO->mPlaybackBuffers[i]->AvailForGet();
const auto discarded =
gAudioIO->mPlaybackBuffers[i]->Discard( toDiscard );
// wxASSERT( discarded == toDiscard );
// but we can't assert in this thread
wxUnusedVar(discarded);
}
// Reload the ring buffers
@ -4404,7 +4415,7 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
{
len = gAudioIO->mPlaybackBuffers[t]->Get((samplePtr)tempBufs[chanCnt],
floatSample,
(int)framesPerBuffer);
framesPerBuffer);
if (len < framesPerBuffer)
// Pad with zeroes to the end, in case of a short channel
memset((void*)&tempBufs[chanCnt][len], 0,
@ -4433,17 +4444,17 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
// silence? If it terminates immediately, does that terminate any MIDI
// playback that might also be going on? ...Maybe muted audio tracks + MIDI,
// the playback would NEVER terminate. ...I think the #else part is probably preferable...
unsigned int len;
size_t len;
if (cut)
{
len = (unsigned int)
len =
gAudioIO->mPlaybackBuffers[t]->Discard(framesPerBuffer);
} else
{
len = (unsigned int)
len =
gAudioIO->mPlaybackBuffers[t]->Get((samplePtr)tempFloats,
floatSample,
(int)framesPerBuffer);
framesPerBuffer);
}
#endif
@ -4561,12 +4572,10 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
if( inputBuffer && (numCaptureChannels > 0) )
{
unsigned int len = framesPerBuffer;
size_t len = framesPerBuffer;
for( t = 0; t < numCaptureChannels; t++) {
unsigned int avail =
(unsigned int)gAudioIO->mCaptureBuffers[t]->AvailForPut();
if (avail < len)
len = avail;
len = std::min( len,
gAudioIO->mCaptureBuffers[t]->AvailForPut());
}
if (len < framesPerBuffer)
@ -4612,9 +4621,12 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
} break;
} // switch
gAudioIO->mCaptureBuffers[t]->Put((samplePtr)tempBuffer,
gAudioIO->mCaptureFormat,
len);
const auto put =
gAudioIO->mCaptureBuffers[t]->Put(
(samplePtr)tempBuffer, gAudioIO->mCaptureFormat, len);
// wxASSERT(put == len);
// but we can't assert in this thread
wxUnusedVar(put);
}
}
}

View File

@ -439,7 +439,7 @@ private:
*
* Returns the smallest of the buffer free space values in the event that
* they are different. */
int GetCommonlyAvailPlayback();
size_t GetCommonlyAvailPlayback();
/** \brief Get the number of audio samples ready in all of the recording
* buffers.
@ -447,7 +447,7 @@ private:
* Returns the smallest of the number of samples available for storage in
* the recording buffers (i.e. the number of samples that can be read from
* all record buffers without underflow). */
int GetCommonlyAvailCapture();
size_t GetCommonlyAvailCapture();
/** \brief get the index of the supplied (named) recording device, or the
* device selected in the preferences if none given.

View File

@ -336,6 +336,9 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
// Rememebr the old blocksize, so that we can restore it later.
auto oldBlockSize = Sequence::GetMaxDiskBlockSize();
const auto cleanup = finally([=]
{ Sequence::SetMaxDiskBlockSize(oldBlockSize); }
);
Sequence::SetMaxDiskBlockSize(blockSize * 1024);
wxBusyCursor busy;
@ -535,7 +538,6 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
dd.reset();
Sequence::SetMaxDiskBlockSize(oldBlockSize);
Printf(wxT("Benchmark completed successfully.\n"));
HoldPrint(false);

View File

@ -634,7 +634,7 @@ void AliasBlockFile::ChangeAliasedFileName(wxFileNameWrapper &&newAliasedFile)
mAliasedFileName = std::move(newAliasedFile);
}
wxLongLong AliasBlockFile::GetSpaceUsage() const
auto AliasBlockFile::GetSpaceUsage() const -> DiskByteCount
{
wxFFile summaryFile(mFileName.GetFullPath());
return summaryFile.Length();

View File

@ -105,8 +105,8 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ {
virtual GetFileNameResult GetFileName() const;
virtual void SetFileName(wxFileNameWrapper &&name);
virtual sampleCount GetLength() const { return mLen; }
virtual void SetLength(const sampleCount newLen) { mLen = newLen; }
sampleCount GetLength() const { return mLen; }
void SetLength(const sampleCount newLen) { mLen = newLen; }
/// Locks this BlockFile, to prevent it from being moved
virtual void Lock();
@ -140,7 +140,9 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ {
/// Create a NEW BlockFile identical to this, using the given filename
virtual BlockFilePtr Copy(wxFileNameWrapper &&newFileName) = 0;
virtual wxLongLong GetSpaceUsage() const = 0;
// Report disk space usage.
using DiskByteCount = unsigned long long;
virtual DiskByteCount GetSpaceUsage() const = 0;
/// if the on-disk state disappeared, either recover it (if it was
//summary only), write out a placeholder of silence data (missing
@ -223,7 +225,7 @@ class AliasBlockFile /* not final */ : public BlockFile
// Reading
wxLongLong GetSpaceUsage() const override;
DiskByteCount GetSpaceUsage() const override;
/// as SilentLog (which would affect Summary data access), but
// applying to Alias file access

View File

@ -15,7 +15,6 @@ been abandoned.
#include "CrossFade.h"
#include "SampleFormat.h"
#include "Resample.h"
#include "WaveClip.h"
#include <iostream>

View File

@ -16,7 +16,6 @@
/// to produce the desired crossfading
#include "SampleFormat.h"
#include "Resample.h"
#include "WaveClip.h"

View File

@ -126,7 +126,7 @@ void FindDependencies(AudacityProject *project,
continue;
const wxString &fileNameStr = fileName.GetFullPath();
int blockBytes = (SAMPLE_SIZE(format) *
auto blockBytes = (SAMPLE_SIZE(format) *
aliasBlockFile->GetLength());
if (aliasedFileHash.count(fileNameStr) > 0)
// Already put this AliasBlockFile in aliasedFileHash.

View File

@ -91,7 +91,6 @@ simplifies construction of menu items.
#include "Screenshot.h"
#include "ondemand/ODManager.h"
#include "Resample.h"
#include "BatchProcessDialog.h"
#include "BatchCommands.h"
#include "prefs/BatchPrefs.h"

View File

@ -414,7 +414,7 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
const double trackRate = track->GetRate();
const double initialWarp = mRate / mSpeed / trackRate;
const double tstep = 1.0 / trackRate;
int sampleSize = SAMPLE_SIZE(floatSample);
auto sampleSize = SAMPLE_SIZE(floatSample);
decltype(mMaxOut) out = 0;
@ -508,23 +508,18 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
(t, t + (double)thisProcessLen / trackRate);
}
int input_used;
int outgen = pResample->Process(factor,
auto results = pResample->Process(factor,
&queue[*queueStart],
thisProcessLen,
last,
&input_used,
&mFloatBuffer[out],
mMaxOut - out);
if (outgen < 0) {
return 0;
}
const auto input_used = results.first;
*queueStart += input_used;
*queueLen -= input_used;
out += outgen;
t += ((backwards ? -input_used : input_used) / trackRate);
out += results.second;
t += (input_used / trackRate) * (backwards ? -1 : 1);
if (last) {
break;

View File

@ -74,20 +74,20 @@ const wxString Resample::GetBestMethodKey()
int Resample::GetFastMethodDefault() {return 1;}
int Resample::GetBestMethodDefault() {return 3;}
int Resample::Process(double factor,
std::pair<size_t, size_t>
Resample::Process(double factor,
float *inBuffer,
int inBufferLen,
size_t inBufferLen,
bool lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen)
size_t outBufferLen)
{
size_t idone, odone;
if (mbWantConstRateResampling)
{
soxr_process((soxr_t)mHandle,
inBuffer , (size_t)(lastFlag? ~inBufferLen : inBufferLen), &idone,
outBuffer, (size_t) outBufferLen, &odone);
inBuffer , (lastFlag? ~inBufferLen : inBufferLen), &idone,
outBuffer, outBufferLen, &odone);
}
else
{
@ -95,11 +95,10 @@ int Resample::Process(double factor,
inBufferLen = lastFlag? ~inBufferLen : inBufferLen;
soxr_process((soxr_t)mHandle,
inBuffer , (size_t)inBufferLen , &idone,
outBuffer, (size_t)outBufferLen, &odone);
inBuffer , inBufferLen , &idone,
outBuffer, outBufferLen, &odone);
}
*inBufferUsed = (int)idone;
return (int)odone;
return { idone, odone };
}
void Resample::SetMethod(const bool useBestMethod)

View File

@ -58,20 +58,20 @@ class Resample final
@param inBufferLen Length of the input buffer, in samples.
@param lastFlag Flag to indicate this is the last lot of input samples and
the buffer needs to be emptied out into the rate converter.
@param inBufferUsed Number of samples from inBuffer that have been used
(unless lastFlag is true, we don't garuntee to process all the samples in
the input this time, we may leave some for next time)
@param outBuffer Buffer to write output (converted) samples to.
@param outBufferLen How big outBuffer is.
@return Number of output samples created by this call
@return Number of input samples consumed, and number of output samples
created by this call
*/
int Process(double factor,
std::pair<size_t, size_t>
Process(double factor,
float *inBuffer,
int inBufferLen,
size_t inBufferLen,
bool lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen);
size_t outBufferLen);
protected:
void SetMethod(const bool useBestMethod);

View File

@ -24,20 +24,18 @@
#include "RingBuffer.h"
RingBuffer::RingBuffer(sampleFormat format, int size)
: mFormat(format)
, mBufferSize(size > 64 ? size : 64)
RingBuffer::RingBuffer(sampleFormat format, size_t size)
: mFormat{ format }
, mBufferSize{ std::max<size_t>(size, 64) }
, mBuffer( mBufferSize, mFormat )
{
mStart = 0;
mEnd = 0;
}
RingBuffer::~RingBuffer()
{
}
int RingBuffer::Len()
size_t RingBuffer::Len()
{
return (mEnd + mBufferSize - mStart) % mBufferSize;
}
@ -46,31 +44,21 @@ int RingBuffer::Len()
// For the writer only:
//
int RingBuffer::AvailForPut()
size_t RingBuffer::AvailForPut()
{
return (mBufferSize-4) - Len();
return std::max<size_t>(mBufferSize - Len(), 4) - 4;
}
int RingBuffer::Put(samplePtr buffer, sampleFormat format,
int samplesToCopy)
size_t RingBuffer::Put(samplePtr buffer, sampleFormat format,
size_t samplesToCopy)
{
samplePtr src;
int block;
int copied;
int pos;
int len = Len();
if (samplesToCopy > (mBufferSize-4) - len)
samplesToCopy = (mBufferSize-4) - len;
src = buffer;
copied = 0;
pos = mEnd;
samplesToCopy = std::min( samplesToCopy, AvailForPut() );
auto src = buffer;
size_t copied = 0;
auto pos = mEnd;
while(samplesToCopy) {
block = samplesToCopy;
if (block > mBufferSize - pos)
block = mBufferSize - pos;
auto block = std::min( samplesToCopy, mBufferSize - pos );
CopySamples(src, format,
mBuffer.ptr() + pos * SAMPLE_SIZE(mFormat), mFormat,
@ -91,29 +79,20 @@ int RingBuffer::Put(samplePtr buffer, sampleFormat format,
// For the reader only:
//
int RingBuffer::AvailForGet()
size_t RingBuffer::AvailForGet()
{
return Len();
}
int RingBuffer::Get(samplePtr buffer, sampleFormat format,
int samplesToCopy)
size_t RingBuffer::Get(samplePtr buffer, sampleFormat format,
size_t samplesToCopy)
{
samplePtr dest;
int block;
int copied;
int len = Len();
if (samplesToCopy > len)
samplesToCopy = len;
dest = buffer;
copied = 0;
samplesToCopy = std::min( samplesToCopy, Len() );
auto dest = buffer;
size_t copied = 0;
while(samplesToCopy) {
block = samplesToCopy;
if (block > mBufferSize - mStart)
block = mBufferSize - mStart;
auto block = std::min( samplesToCopy, mBufferSize - mStart );
CopySamples(mBuffer.ptr() + mStart * SAMPLE_SIZE(mFormat), mFormat,
dest, format,
@ -128,12 +107,9 @@ int RingBuffer::Get(samplePtr buffer, sampleFormat format,
return copied;
}
int RingBuffer::Discard(int samplesToDiscard)
size_t RingBuffer::Discard(size_t samplesToDiscard)
{
int len = Len();
if (samplesToDiscard > len)
samplesToDiscard = len;
samplesToDiscard = std::min( samplesToDiscard, Len() );
mStart = (mStart + samplesToDiscard) % mBufferSize;

View File

@ -15,31 +15,31 @@
class RingBuffer {
public:
RingBuffer(sampleFormat format, int size);
RingBuffer(sampleFormat format, size_t size);
~RingBuffer();
//
// For the writer only:
//
int AvailForPut();
int Put(samplePtr buffer, sampleFormat format, int samples);
size_t AvailForPut();
size_t Put(samplePtr buffer, sampleFormat format, size_t samples);
//
// For the reader only:
//
int AvailForGet();
int Get(samplePtr buffer, sampleFormat format, int samples);
int Discard(int samples);
size_t AvailForGet();
size_t Get(samplePtr buffer, sampleFormat format, size_t samples);
size_t Discard(size_t samples);
private:
int Len();
size_t Len();
sampleFormat mFormat;
int mStart;
int mEnd;
int mBufferSize;
size_t mStart { 0 };
size_t mEnd { 0 };
size_t mBufferSize;
SampleBuffer mBuffer;
};

View File

@ -88,17 +88,17 @@ AUDACITY_DLL_API void DeleteSamples(samplePtr p)
void ClearSamples(samplePtr src, sampleFormat format,
int start, int len)
{
int size = SAMPLE_SIZE(format);
auto size = SAMPLE_SIZE(format);
memset(src + start*size, 0, len*size);
}
void ReverseSamples(samplePtr src, sampleFormat format,
int start, int len)
{
int size = SAMPLE_SIZE(format);
auto size = SAMPLE_SIZE(format);
samplePtr first = src + start * size;
samplePtr last = src + (start + len - 1) * size;
enum { fixedSize = SAMPLE_SIZE(floatSample) };
enum : size_t { fixedSize = SAMPLE_SIZE(floatSample) };
wxASSERT(size <= fixedSize);
char temp[fixedSize];
while (first < last) {

View File

@ -29,7 +29,7 @@ typedef enum {
} sampleFormat;
/** \brief Return the size (in memory) of one sample (bytes) */
#define SAMPLE_SIZE(SampleFormat) (SampleFormat >> 16)
#define SAMPLE_SIZE(SampleFormat) ( size_t{ (SampleFormat) >> 16 } )
#endif
// Used to determine how to fill in empty areas of audio.
@ -39,8 +39,8 @@ typedef enum {
}fillFormat;
/** \brief Return the size on disk of one uncompressed sample (bytes) */
#define SAMPLE_SIZE_DISK(SampleFormat) ((SampleFormat == int24Sample) ? \
3 : SAMPLE_SIZE(SampleFormat) )
#define SAMPLE_SIZE_DISK(SampleFormat) (((SampleFormat) == int24Sample) ? \
size_t{ 3 } : SAMPLE_SIZE(SampleFormat) )
const wxChar *GetSampleFormatStr(sampleFormat format);

View File

@ -480,7 +480,7 @@ bool Sequence::Paste(sampleCount s, const Sequence *src)
const BlockArray &srcBlock = src->mBlock;
auto addedLen = src->mNumSamples;
const unsigned int srcNumBlocks = srcBlock.size();
int sampleSize = SAMPLE_SIZE(mSampleFormat);
auto sampleSize = SAMPLE_SIZE(mSampleFormat);
if (addedLen == 0 || srcNumBlocks == 0)
return true;
@ -578,7 +578,7 @@ bool Sequence::Paste(sampleCount s, const Sequence *src)
const auto srcLastTwoLen =
penultimate.f->GetLength() +
srcBlock[srcNumBlocks - 1].f->GetLength();
const sampleCount rightSplit = splitBlock.f->GetLength() - splitPoint;
const auto rightSplit = splitBlock.f->GetLength() - splitPoint;
const auto rightLen = rightSplit + srcLastTwoLen;
SampleBuffer sampleBuffer(std::max(leftLen, rightLen), mSampleFormat);
@ -1116,7 +1116,7 @@ bool Sequence::CopyWrite(SampleBuffer &scratch,
wxASSERT(start + len <= length);
wxASSERT(start >= 0);
int sampleSize = SAMPLE_SIZE(mSampleFormat);
auto sampleSize = SAMPLE_SIZE(mSampleFormat);
Read(scratch.ptr(), mSampleFormat, b, 0, length);
memcpy(scratch.ptr() + start*sampleSize, buffer, len*sampleSize);
@ -1590,7 +1590,7 @@ bool Sequence::Delete(sampleCount start, sampleCount len)
const unsigned int b0 = FindBlock(start);
unsigned int b1 = FindBlock(start + len - 1);
int sampleSize = SAMPLE_SIZE(mSampleFormat);
auto sampleSize = SAMPLE_SIZE(mSampleFormat);
// Special case: if the samples to DELETE are all within a single
// block and the resulting length is not too small, perform the

View File

@ -22,7 +22,6 @@
#include "Envelope.h"
#include "Prefs.h"
#include "Internat.h"
#include "Resample.h"
#include "ViewInfo.h"
//TODO-MB: are these sensible values?

View File

@ -106,7 +106,7 @@ void UndoManager::CalculateSpaceUsage()
// in the previous level
if (prev->count( &*file ) == 0 && cur->count( &*file ) == 0)
{
space[i] += file->GetSpaceUsage().GetValue();
space[i] += { file->GetSpaceUsage() };
}
// Add file to current set

View File

@ -73,7 +73,7 @@ struct UndoState {
using UndoStack = std::vector <movable_ptr<UndoStackElem>>;
using SpaceArray = std::vector <wxLongLong_t> ;
using SpaceArray = std::vector <unsigned long long> ;
// These flags control what extra to do on a PushState
// Default is AUTOSAVE

View File

@ -1793,11 +1793,11 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
break;
}
int inBufferUsed = 0;
outGenerated = resample.Process(factor, inBuffer, inLen, isLast,
&inBufferUsed, outBuffer, bufsize);
const auto results = resample.Process(factor, inBuffer, inLen, isLast,
outBuffer, bufsize);
outGenerated = results.second;
pos += inBufferUsed;
pos += results.first;
if (outGenerated < 0)
{

View File

@ -344,7 +344,7 @@ BlockFilePtr LegacyBlockFile::Copy(wxFileNameWrapper &&newFileName)
mLen, mSummaryInfo.fields < 3);
}
wxLongLong LegacyBlockFile::GetSpaceUsage() const
auto LegacyBlockFile::GetSpaceUsage() const -> DiskByteCount
{
wxFFile dataFile(mFileName.GetFullPath());
return dataFile.Length();

View File

@ -57,7 +57,7 @@ class LegacyBlockFile final : public BlockFile {
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override;
/// Write an XML representation of this file
void SaveXML(XMLWriter &xmlFile) override;
wxLongLong GetSpaceUsage() const override;
DiskByteCount GetSpaceUsage() const override;
void Recover() override;
static BlockFilePtr BuildFromXML(const wxString &dir, const wxChar **attrs,

View File

@ -77,7 +77,7 @@ ODDecodeBlockFile::~ODDecodeBlockFile()
//Check to see if we have the file for these calls.
wxLongLong ODDecodeBlockFile::GetSpaceUsage() const
auto ODDecodeBlockFile::GetSpaceUsage() const -> DiskByteCount
{
if(IsSummaryAvailable())
{

View File

@ -60,7 +60,7 @@ class ODDecodeBlockFile final : public SimpleBlockFile
bool IsSummaryBeingComputed() override { return false; }
//Calls that rely on summary files need to be overidden
wxLongLong GetSpaceUsage() const override;
DiskByteCount GetSpaceUsage() const override;
/// Gets extreme values for the specified region
void GetMinMax(sampleCount start, sampleCount len,
float *outMin, float *outMax, float *outRMS) const override;

View File

@ -77,11 +77,11 @@ ODPCMAliasBlockFile::~ODPCMAliasBlockFile()
//Check to see if we have the file for these calls.
wxLongLong ODPCMAliasBlockFile::GetSpaceUsage() const
auto ODPCMAliasBlockFile::GetSpaceUsage() const -> DiskByteCount
{
if(IsSummaryAvailable())
{
wxLongLong ret;
DiskByteCount ret;
mFileNameMutex.Lock();
wxFFile summaryFile(mFileName.GetFullPath());
ret= summaryFile.Length();

View File

@ -63,7 +63,7 @@ class ODPCMAliasBlockFile final : public PCMAliasBlockFile
bool IsSummaryBeingComputed() override { return mSummaryBeingComputed; }
//Calls that rely on summary files need to be overidden
wxLongLong GetSpaceUsage() const override;
DiskByteCount GetSpaceUsage() const override;
/// Gets extreme values for the specified region
void GetMinMax(sampleCount start, sampleCount len,
float *outMin, float *outMax, float *outRMS) const override;

View File

@ -82,7 +82,7 @@ BlockFilePtr SilentBlockFile::Copy(wxFileNameWrapper &&)
return newBlockFile;
}
wxLongLong SilentBlockFile::GetSpaceUsage() const
auto SilentBlockFile::GetSpaceUsage() const -> DiskByteCount
{
return 0;
}

View File

@ -42,7 +42,7 @@ class SilentBlockFile final : public BlockFile {
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override;
/// Write an XML representation of this file
void SaveXML(XMLWriter &xmlFile) override;
wxLongLong GetSpaceUsage() const override;
DiskByteCount GetSpaceUsage() const override;
void Recover() override { };
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs);

View File

@ -123,9 +123,9 @@ SimpleBlockFile::SimpleBlockFile(wxFileNameWrapper &&baseFileName,
mCache.active = true;
mCache.needWrite = true;
mCache.format = format;
mCache.sampleData = new char[sampleLen * SAMPLE_SIZE(format)];
memcpy(mCache.sampleData,
sampleData, sampleLen * SAMPLE_SIZE(format));
const auto sampleDataSize = sampleLen * SAMPLE_SIZE(format);
mCache.sampleData = new char[sampleDataSize];
memcpy(mCache.sampleData, sampleData, sampleDataSize);
ArrayOf<char> cleanup;
void* summaryData = BlockFile::CalcSummary(sampleData, sampleLen,
format, cleanup);
@ -547,7 +547,7 @@ BlockFilePtr SimpleBlockFile::Copy(wxFileNameWrapper &&newFileName)
return newBlockFile;
}
wxLongLong SimpleBlockFile::GetSpaceUsage() const
auto SimpleBlockFile::GetSpaceUsage() const -> DiskByteCount
{
if (mCache.active && mCache.needWrite)
{
@ -598,9 +598,11 @@ wxLongLong SimpleBlockFile::GetSpaceUsage() const
file.Close();
}
return sizeof(auHeader) +
return
sizeof(auHeader) +
mSummaryInfo.totalSummaryBytes +
(GetLength() * SAMPLE_SIZE_DISK(mFormat));
(GetLength() * SAMPLE_SIZE_DISK(mFormat))
;
}
void SimpleBlockFile::Recover(){

View File

@ -72,7 +72,7 @@ class PROFILE_DLL_API SimpleBlockFile /* not final */ : public BlockFile {
/// Write an XML representation of this file
void SaveXML(XMLWriter &xmlFile) override;
wxLongLong GetSpaceUsage() const override;
DiskByteCount GetSpaceUsage() const override;
void Recover() override;
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs);

View File

@ -510,25 +510,20 @@ bool EffectChangeSpeed::ProcessOne(WaveTrack * track,
//Get the samples from the track and put them in the buffer
track->Get((samplePtr) inBuffer, floatSample, samplePos, blockSize);
int inUsed;
int outgen = resample.Process(mFactor,
const auto results = resample.Process(mFactor,
inBuffer,
blockSize,
((samplePos + blockSize) >= end),
&inUsed,
outBuffer,
outBufferSize);
if (outgen < 0) {
bResult = false;
break;
}
const auto outgen = results.second;
if (outgen > 0)
outputTrack->Append((samplePtr)outBuffer, floatSample,
outgen);
// Increment samplePos
samplePos += inUsed;
samplePos += results.first;
// Update the Progress meter
if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) {

View File

@ -78,45 +78,34 @@ bool EffectRepair::Process()
WaveTrack *track = (WaveTrack *) iter.First();
int count = 0;
while (track) {
const
double trackStart = track->GetStartTime();
const double repair_t0 = std::max(mT0, trackStart);
const
double trackEnd = track->GetEndTime();
double repair_t0 = mT0;
double repair_t1 = mT1;
repair_t0 = (repair_t0 < trackStart? trackStart: repair_t0);
repair_t1 = (repair_t1 > trackEnd? trackEnd: repair_t1);
if (repair_t0 < repair_t1) { // selection is within track audio
double rate = track->GetRate();
const double repair_t1 = std::min(mT1, trackEnd);
const
double repair_deltat = repair_t1 - repair_t0;
double spacing = repair_deltat * 2;
if (spacing < 128. / rate)
spacing = 128. / rate;
double t0 = repair_t0 - spacing;
double t1 = repair_t1 + spacing;
t0 = t0 < trackStart? trackStart: t0;
t1 = t1 > trackEnd? trackEnd: t1;
repair_t0 = (repair_t0 < t0? t0: repair_t0);
repair_t1 = (repair_t1 > t1? t1: repair_t1);
auto s0 = track->TimeToLongSamples(t0);
auto repair0 = track->TimeToLongSamples(repair_t0);
auto repair1 = track->TimeToLongSamples(repair_t1);
auto s1 = track->TimeToLongSamples(t1);
auto repairStart = repair0 - s0;
auto repairLen = repair1 - repair0;
auto len = s1 - s0;
if (repair_deltat > 0) { // selection is within track audio
const auto repair0 = track->TimeToLongSamples(repair_t0);
const auto repair1 = track->TimeToLongSamples(repair_t1);
const auto repairLen = repair1 - repair0;
if (repairLen > 128) {
::wxMessageBox(_("The Repair effect is intended to be used on very short sections of damaged audio (up to 128 samples).\n\nZoom in and select a tiny fraction of a second to repair."));
bGoodResult = false;
break;
}
const double rate = track->GetRate();
const double spacing = std::max(repair_deltat * 2, 128. / rate);
const double t0 = std::max(repair_t0 - spacing, trackStart);
const double t1 = std::min(repair_t1 + spacing, trackEnd);
const auto s0 = track->TimeToLongSamples(t0);
const auto s1 = track->TimeToLongSamples(t1);
const auto repairStart = (repair0 - s0);
const auto len = s1 - s0;
if (s0 == repair0 && s1 == repair1) {
::wxMessageBox(_("Repair works by using audio data outside the selection region.\n\nPlease select a region that has audio touching at least one side of it.\n\nThe more surrounding audio, the better it performs."));
/// The Repair effect needs some data to go on.\n\nPlease select an area to repair with some audio on at least one side (the more the better)."));

View File

@ -95,7 +95,7 @@ bool EffectTwoPassSimpleMono::ProcessPass()
//ProcessOne() takes a track, transforms it to bunch of buffer-blocks,
//and executes ProcessSimpleMono on these blocks
//and executes TwoBufferProcessPass1 or TwoBufferProcessPass2 on these blocks
bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
sampleCount start, sampleCount end)
{

View File

@ -204,7 +204,7 @@ public:
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
///! Imports audio
///\return import status (see Import.cpp)
@ -460,7 +460,7 @@ wxString FFmpegImportFileHandle::GetFileDescription()
}
int FFmpegImportFileHandle::GetFileUncompressedBytes()
auto FFmpegImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
// TODO: Get Uncompressed byte count.
return 0;

View File

@ -153,7 +153,7 @@ public:
bool Init();
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
int Import(TrackFactory *trackFactory, TrackHolders &outTracks,
Tags *tags) override;
@ -427,7 +427,7 @@ wxString FLACImportFileHandle::GetFileDescription()
}
int FLACImportFileHandle::GetFileUncompressedBytes()
auto FLACImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
// TODO: Get Uncompressed byte count.
return 0;
@ -487,7 +487,8 @@ int FLACImportFileHandle::Import(TrackFactory *trackFactory,
//add the task to the ODManager
if(useOD)
{
auto fileTotalFrames = (sampleCount)mNumSamples;
auto fileTotalFrames =
(sampleCount)mNumSamples; // convert from FLAC__uint64
auto maxBlockSize = mChannels.begin()->get()->GetMaxBlockSize();
for (decltype(fileTotalFrames) i = 0; i < fileTotalFrames; i += maxBlockSize) {
const auto blockLen =

View File

@ -170,7 +170,7 @@ public:
bool Init();
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
///! Called by Import.cpp
///\return number of readable audio streams in the file
@ -1005,8 +1005,8 @@ GStreamerImportFileHandle::GetFileDescription()
// ----------------------------------------------------------------------------
// Return number of uncompressed bytes in file...doubtful this is possible
int
GStreamerImportFileHandle::GetFileUncompressedBytes()
auto
GStreamerImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
return 0;
}

View File

@ -124,7 +124,7 @@ public:
~LOFImportFileHandle();
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
int Import(TrackFactory *trackFactory, TrackHolders &outTracks,
Tags *tags) override;
@ -226,7 +226,7 @@ wxString LOFImportFileHandle::GetFileDescription()
return DESC;
}
int LOFImportFileHandle::GetFileUncompressedBytes()
auto LOFImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
return 0;
}

View File

@ -130,7 +130,7 @@ public:
~MP3ImportFileHandle();
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
int Import(TrackFactory *trackFactory, TrackHolders &outTracks,
Tags *tags) override;
@ -199,7 +199,7 @@ wxString MP3ImportFileHandle::GetFileDescription()
return DESC;
}
int MP3ImportFileHandle::GetFileUncompressedBytes()
auto MP3ImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
// TODO
return 0;

View File

@ -123,7 +123,7 @@ public:
~OggImportFileHandle();
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
int Import(TrackFactory *trackFactory, TrackHolders &outTracks,
Tags *tags) override;
@ -223,7 +223,7 @@ wxString OggImportFileHandle::GetFileDescription()
return DESC;
}
int OggImportFileHandle::GetFileUncompressedBytes()
auto OggImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
// TODO:
return 0;

View File

@ -93,7 +93,7 @@ public:
~PCMImportFileHandle();
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
int Import(TrackFactory *trackFactory, TrackHolders &outTracks,
Tags *tags) override;
@ -215,7 +215,7 @@ wxString PCMImportFileHandle::GetFileDescription()
return SFCall<wxString>(sf_header_name, mInfo.format);
}
int PCMImportFileHandle::GetFileUncompressedBytes()
auto PCMImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
return mInfo.frames * mInfo.channels * SAMPLE_SIZE(mFormat);
}
@ -367,7 +367,8 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
channels.begin()->get()->SetLinked(true);
}
auto fileTotalFrames = (sampleCount)mInfo.frames;
auto fileTotalFrames =
(sampleCount)mInfo.frames; // convert from sf_count_t
auto maxBlockSize = channels.begin()->get()->GetMaxBlockSize();
int updateResult = false;

View File

@ -147,8 +147,10 @@ public:
virtual wxString GetFileDescription() = 0;
// Return an estimate of how many bytes the file will occupy once
// imported
virtual int GetFileUncompressedBytes() = 0;
// imported. In principle this may exceed main memory, so don't use
// size_t.
using ByteCount = unsigned long long;
virtual ByteCount GetFileUncompressedBytes() = 0;
// do the actual import, creating whatever tracks are necessary with
// the TrackFactory and calling the progress callback every iteration

View File

@ -135,7 +135,7 @@ class QTImportFileHandle final : public ImportFileHandle
}
wxString GetFileDescription();
int GetFileUncompressedBytes();
ByteCount GetFileUncompressedBytes() override;
wxInt32 GetStreamCount()
{
@ -219,7 +219,7 @@ wxString QTImportFileHandle::GetFileDescription()
return DESC;
}
int QTImportFileHandle::GetFileUncompressedBytes()
auto QTImportFileHandle::GetFileUncompressedBytes() -> ByteCount
{
return 0;
}
@ -233,7 +233,8 @@ int QTImportFileHandle::Import(TrackFactory *trackFactory,
OSErr err = noErr;
MovieAudioExtractionRef maer = NULL;
int updateResult = eProgressSuccess;
auto totSamples = (sampleCount) GetMovieDuration(mMovie);
auto totSamples =
(sampleCount) GetMovieDuration(mMovie); // convert from TimeValue
decltype(totSamples) numSamples = 0;
Boolean discrete = true;
UInt32 quality = kQTAudioRenderQuality_Max;
@ -459,8 +460,8 @@ void QTImportFileHandle::AddMetadata(Tags *tags)
QTPropertyValuePtr outValPtr = nil;
QTPropertyValueType outPropType;
ByteCount outPropValueSize;
ByteCount outPropValueSizeUsed = 0;
::ByteCount outPropValueSize;
::ByteCount outPropValueSizeUsed = 0;
UInt32 outPropFlags;
UInt32 dataType;

View File

@ -175,7 +175,9 @@ void ImportRaw(wxWindow *parent, const wxString &fileName,
SFCall<sf_count_t>(sf_seek, sndFile.get(), 0, SEEK_SET);
auto totalFrames = (sampleCount)(sndInfo.frames * percent / 100.0);
auto totalFrames =
// fraction of a sf_count_t value
(sampleCount)(sndInfo.frames * percent / 100.0);
//
// Sample format: