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 "NoteTrack.h"
#include "Prefs.h" #include "Prefs.h"
#include "Project.h" #include "Project.h"
#include "Resample.h"
#include "SampleFormat.h" #include "SampleFormat.h"
#include "Sequence.h" #include "Sequence.h"
#include "TimeTrack.h" #include "TimeTrack.h"

View File

@ -3052,34 +3052,21 @@ MidiThread::ExitCode MidiThread::Entry()
} }
#endif #endif
int AudioIO::GetCommonlyAvailPlayback() size_t AudioIO::GetCommonlyAvailPlayback()
{ {
int commonlyAvail = mPlaybackBuffers[0]->AvailForPut(); auto commonlyAvail = mPlaybackBuffers[0]->AvailForPut();
unsigned int i; for (unsigned i = 1; i < mPlaybackTracks.size(); ++i)
commonlyAvail = std::min(commonlyAvail,
for (i = 1; i < mPlaybackTracks.size(); i++) mPlaybackBuffers[i]->AvailForPut());
{
int thisBlockAvail = mPlaybackBuffers[i]->AvailForPut();
if( thisBlockAvail < commonlyAvail )
commonlyAvail = thisBlockAvail;
}
return commonlyAvail; return commonlyAvail;
} }
int AudioIO::GetCommonlyAvailCapture() size_t AudioIO::GetCommonlyAvailCapture()
{ {
int commonlyAvail = mCaptureBuffers[0]->AvailForGet(); auto commonlyAvail = mCaptureBuffers[0]->AvailForGet();
unsigned int i; for (unsigned i = 1; i < mCaptureTracks.size(); ++i)
commonlyAvail = std::min(commonlyAvail,
for (i = 1; i < mCaptureTracks.size(); i++) mCaptureBuffers[i]->AvailForGet());
{
int avail = mCaptureBuffers[i]->AvailForGet();
if( avail < commonlyAvail )
commonlyAvail = avail;
}
return commonlyAvail; return commonlyAvail;
} }
@ -3546,7 +3533,11 @@ void AudioIO::FillBuffers()
processed = mPlaybackMixers[i]->Process(frames); processed = mPlaybackMixers[i]->Process(frames);
wxASSERT(processed <= frames); wxASSERT(processed <= frames);
warpedSamples = mPlaybackMixers[i]->GetBuffer(); 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 //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); mSilentBuf.Resize(frames, floatSample);
ClearSamples(mSilentBuf.ptr(), floatSample, 0, frames); 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 if (mCaptureTracks.size() > 0) // start record buffering
{ {
int commonlyAvail = GetCommonlyAvailCapture(); auto commonlyAvail = GetCommonlyAvailCapture();
// //
// Determine how much this will add to captured tracks // Determine how much this will add to captured tracks
@ -3643,7 +3638,7 @@ void AudioIO::FillBuffers()
for( i = 0; (int)i < numChannels; i++ ) for( i = 0; (int)i < numChannels; i++ )
{ {
int avail = commonlyAvail; auto avail = commonlyAvail;
sampleFormat trackFormat = mCaptureTracks[i]->GetSampleFormat(); sampleFormat trackFormat = mCaptureTracks[i]->GetSampleFormat();
AutoSaveFile appendLog; AutoSaveFile appendLog;
@ -3651,22 +3646,32 @@ void AudioIO::FillBuffers()
if( mFactor == 1.0 ) if( mFactor == 1.0 )
{ {
SampleBuffer temp(avail, trackFormat); SampleBuffer temp(avail, trackFormat);
const auto got =
mCaptureBuffers[i]->Get(temp.ptr(), trackFormat, avail); 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, mCaptureTracks[i]-> Append(temp.ptr(), trackFormat, avail, 1,
&appendLog); &appendLog);
} }
else else
{ {
int size = lrint(avail * mFactor); size_t size = lrint(avail * mFactor);
SampleBuffer temp1(avail, floatSample); SampleBuffer temp1(avail, floatSample);
SampleBuffer temp2(size, floatSample); SampleBuffer temp2(size, floatSample);
const auto got =
mCaptureBuffers[i]->Get(temp1.ptr(), floatSample, avail); 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 /* we are re-sampling on the fly. The last resampling call
* must flush any samples left in the rate conversion buffer * must flush any samples left in the rate conversion buffer
* so that they get recorded * so that they get recorded
*/ */
size = mResample[i]->Process(mFactor, (float *)temp1.ptr(), avail, !IsStreamActive(), const auto results =
&size, (float *)temp2.ptr(), size); mResample[i]->Process(mFactor, (float *)temp1.ptr(), avail,
!IsStreamActive(), (float *)temp2.ptr(), size);
size = results.second;
mCaptureTracks[i]-> Append(temp2.ptr(), floatSample, size, 1, mCaptureTracks[i]-> Append(temp2.ptr(), floatSample, size, 1,
&appendLog); &appendLog);
} }
@ -4320,7 +4325,13 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
for (i = 0; i < (unsigned int)numPlaybackTracks; i++) for (i = 0; i < (unsigned int)numPlaybackTracks; i++)
{ {
gAudioIO->mPlaybackMixers[i]->Reposition(gAudioIO->mTime); 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 // Reload the ring buffers
@ -4404,7 +4415,7 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
{ {
len = gAudioIO->mPlaybackBuffers[t]->Get((samplePtr)tempBufs[chanCnt], len = gAudioIO->mPlaybackBuffers[t]->Get((samplePtr)tempBufs[chanCnt],
floatSample, floatSample,
(int)framesPerBuffer); framesPerBuffer);
if (len < framesPerBuffer) if (len < framesPerBuffer)
// Pad with zeroes to the end, in case of a short channel // Pad with zeroes to the end, in case of a short channel
memset((void*)&tempBufs[chanCnt][len], 0, 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 // silence? If it terminates immediately, does that terminate any MIDI
// playback that might also be going on? ...Maybe muted audio tracks + 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... // the playback would NEVER terminate. ...I think the #else part is probably preferable...
unsigned int len; size_t len;
if (cut) if (cut)
{ {
len = (unsigned int) len =
gAudioIO->mPlaybackBuffers[t]->Discard(framesPerBuffer); gAudioIO->mPlaybackBuffers[t]->Discard(framesPerBuffer);
} else } else
{ {
len = (unsigned int) len =
gAudioIO->mPlaybackBuffers[t]->Get((samplePtr)tempFloats, gAudioIO->mPlaybackBuffers[t]->Get((samplePtr)tempFloats,
floatSample, floatSample,
(int)framesPerBuffer); framesPerBuffer);
} }
#endif #endif
@ -4561,12 +4572,10 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
if( inputBuffer && (numCaptureChannels > 0) ) if( inputBuffer && (numCaptureChannels > 0) )
{ {
unsigned int len = framesPerBuffer; size_t len = framesPerBuffer;
for( t = 0; t < numCaptureChannels; t++) { for( t = 0; t < numCaptureChannels; t++) {
unsigned int avail = len = std::min( len,
(unsigned int)gAudioIO->mCaptureBuffers[t]->AvailForPut(); gAudioIO->mCaptureBuffers[t]->AvailForPut());
if (avail < len)
len = avail;
} }
if (len < framesPerBuffer) if (len < framesPerBuffer)
@ -4612,9 +4621,12 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
} break; } break;
} // switch } // switch
gAudioIO->mCaptureBuffers[t]->Put((samplePtr)tempBuffer, const auto put =
gAudioIO->mCaptureFormat, gAudioIO->mCaptureBuffers[t]->Put(
len); (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 * Returns the smallest of the buffer free space values in the event that
* they are different. */ * they are different. */
int GetCommonlyAvailPlayback(); size_t GetCommonlyAvailPlayback();
/** \brief Get the number of audio samples ready in all of the recording /** \brief Get the number of audio samples ready in all of the recording
* buffers. * buffers.
@ -447,7 +447,7 @@ private:
* Returns the smallest of the number of samples available for storage in * 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 * the recording buffers (i.e. the number of samples that can be read from
* all record buffers without underflow). */ * all record buffers without underflow). */
int GetCommonlyAvailCapture(); size_t GetCommonlyAvailCapture();
/** \brief get the index of the supplied (named) recording device, or the /** \brief get the index of the supplied (named) recording device, or the
* device selected in the preferences if none given. * 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. // Rememebr the old blocksize, so that we can restore it later.
auto oldBlockSize = Sequence::GetMaxDiskBlockSize(); auto oldBlockSize = Sequence::GetMaxDiskBlockSize();
const auto cleanup = finally([=]
{ Sequence::SetMaxDiskBlockSize(oldBlockSize); }
);
Sequence::SetMaxDiskBlockSize(blockSize * 1024); Sequence::SetMaxDiskBlockSize(blockSize * 1024);
wxBusyCursor busy; wxBusyCursor busy;
@ -535,7 +538,6 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
dd.reset(); dd.reset();
Sequence::SetMaxDiskBlockSize(oldBlockSize);
Printf(wxT("Benchmark completed successfully.\n")); Printf(wxT("Benchmark completed successfully.\n"));
HoldPrint(false); HoldPrint(false);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -91,7 +91,6 @@ simplifies construction of menu items.
#include "Screenshot.h" #include "Screenshot.h"
#include "ondemand/ODManager.h" #include "ondemand/ODManager.h"
#include "Resample.h"
#include "BatchProcessDialog.h" #include "BatchProcessDialog.h"
#include "BatchCommands.h" #include "BatchCommands.h"
#include "prefs/BatchPrefs.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 trackRate = track->GetRate();
const double initialWarp = mRate / mSpeed / trackRate; const double initialWarp = mRate / mSpeed / trackRate;
const double tstep = 1.0 / trackRate; const double tstep = 1.0 / trackRate;
int sampleSize = SAMPLE_SIZE(floatSample); auto sampleSize = SAMPLE_SIZE(floatSample);
decltype(mMaxOut) out = 0; decltype(mMaxOut) out = 0;
@ -508,23 +508,18 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
(t, t + (double)thisProcessLen / trackRate); (t, t + (double)thisProcessLen / trackRate);
} }
int input_used; auto results = pResample->Process(factor,
int outgen = pResample->Process(factor,
&queue[*queueStart], &queue[*queueStart],
thisProcessLen, thisProcessLen,
last, last,
&input_used,
&mFloatBuffer[out], &mFloatBuffer[out],
mMaxOut - out); mMaxOut - out);
if (outgen < 0) { const auto input_used = results.first;
return 0;
}
*queueStart += input_used; *queueStart += input_used;
*queueLen -= input_used; *queueLen -= input_used;
out += outgen; out += results.second;
t += ((backwards ? -input_used : input_used) / trackRate); t += (input_used / trackRate) * (backwards ? -1 : 1);
if (last) { if (last) {
break; break;

View File

@ -74,20 +74,20 @@ const wxString Resample::GetBestMethodKey()
int Resample::GetFastMethodDefault() {return 1;} int Resample::GetFastMethodDefault() {return 1;}
int Resample::GetBestMethodDefault() {return 3;} int Resample::GetBestMethodDefault() {return 3;}
int Resample::Process(double factor, std::pair<size_t, size_t>
Resample::Process(double factor,
float *inBuffer, float *inBuffer,
int inBufferLen, size_t inBufferLen,
bool lastFlag, bool lastFlag,
int *inBufferUsed,
float *outBuffer, float *outBuffer,
int outBufferLen) size_t outBufferLen)
{ {
size_t idone, odone; size_t idone, odone;
if (mbWantConstRateResampling) if (mbWantConstRateResampling)
{ {
soxr_process((soxr_t)mHandle, soxr_process((soxr_t)mHandle,
inBuffer , (size_t)(lastFlag? ~inBufferLen : inBufferLen), &idone, inBuffer , (lastFlag? ~inBufferLen : inBufferLen), &idone,
outBuffer, (size_t) outBufferLen, &odone); outBuffer, outBufferLen, &odone);
} }
else else
{ {
@ -95,11 +95,10 @@ int Resample::Process(double factor,
inBufferLen = lastFlag? ~inBufferLen : inBufferLen; inBufferLen = lastFlag? ~inBufferLen : inBufferLen;
soxr_process((soxr_t)mHandle, soxr_process((soxr_t)mHandle,
inBuffer , (size_t)inBufferLen , &idone, inBuffer , inBufferLen , &idone,
outBuffer, (size_t)outBufferLen, &odone); outBuffer, outBufferLen, &odone);
} }
*inBufferUsed = (int)idone; return { idone, odone };
return (int)odone;
} }
void Resample::SetMethod(const bool useBestMethod) 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 inBufferLen Length of the input buffer, in samples.
@param lastFlag Flag to indicate this is the last lot of input samples and @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. 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 (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) the input this time, we may leave some for next time)
@param outBuffer Buffer to write output (converted) samples to. @param outBuffer Buffer to write output (converted) samples to.
@param outBufferLen How big outBuffer is. @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, float *inBuffer,
int inBufferLen, size_t inBufferLen,
bool lastFlag, bool lastFlag,
int *inBufferUsed,
float *outBuffer, float *outBuffer,
int outBufferLen); size_t outBufferLen);
protected: protected:
void SetMethod(const bool useBestMethod); void SetMethod(const bool useBestMethod);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -57,7 +57,7 @@ class LegacyBlockFile final : public BlockFile {
BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override; BlockFilePtr Copy(wxFileNameWrapper &&newFileName) override;
/// Write an XML representation of this file /// Write an XML representation of this file
void SaveXML(XMLWriter &xmlFile) override; void SaveXML(XMLWriter &xmlFile) override;
wxLongLong GetSpaceUsage() const override; DiskByteCount GetSpaceUsage() const override;
void Recover() override; void Recover() override;
static BlockFilePtr BuildFromXML(const wxString &dir, const wxChar **attrs, 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. //Check to see if we have the file for these calls.
wxLongLong ODDecodeBlockFile::GetSpaceUsage() const auto ODDecodeBlockFile::GetSpaceUsage() const -> DiskByteCount
{ {
if(IsSummaryAvailable()) if(IsSummaryAvailable())
{ {

View File

@ -60,7 +60,7 @@ class ODDecodeBlockFile final : public SimpleBlockFile
bool IsSummaryBeingComputed() override { return false; } bool IsSummaryBeingComputed() override { return false; }
//Calls that rely on summary files need to be overidden //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 /// Gets extreme values for the specified region
void GetMinMax(sampleCount start, sampleCount len, void GetMinMax(sampleCount start, sampleCount len,
float *outMin, float *outMax, float *outRMS) const override; 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. //Check to see if we have the file for these calls.
wxLongLong ODPCMAliasBlockFile::GetSpaceUsage() const auto ODPCMAliasBlockFile::GetSpaceUsage() const -> DiskByteCount
{ {
if(IsSummaryAvailable()) if(IsSummaryAvailable())
{ {
wxLongLong ret; DiskByteCount ret;
mFileNameMutex.Lock(); mFileNameMutex.Lock();
wxFFile summaryFile(mFileName.GetFullPath()); wxFFile summaryFile(mFileName.GetFullPath());
ret= summaryFile.Length(); ret= summaryFile.Length();

View File

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

View File

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

View File

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

View File

@ -123,9 +123,9 @@ SimpleBlockFile::SimpleBlockFile(wxFileNameWrapper &&baseFileName,
mCache.active = true; mCache.active = true;
mCache.needWrite = true; mCache.needWrite = true;
mCache.format = format; mCache.format = format;
mCache.sampleData = new char[sampleLen * SAMPLE_SIZE(format)]; const auto sampleDataSize = sampleLen * SAMPLE_SIZE(format);
memcpy(mCache.sampleData, mCache.sampleData = new char[sampleDataSize];
sampleData, sampleLen * SAMPLE_SIZE(format)); memcpy(mCache.sampleData, sampleData, sampleDataSize);
ArrayOf<char> cleanup; ArrayOf<char> cleanup;
void* summaryData = BlockFile::CalcSummary(sampleData, sampleLen, void* summaryData = BlockFile::CalcSummary(sampleData, sampleLen,
format, cleanup); format, cleanup);
@ -547,7 +547,7 @@ BlockFilePtr SimpleBlockFile::Copy(wxFileNameWrapper &&newFileName)
return newBlockFile; return newBlockFile;
} }
wxLongLong SimpleBlockFile::GetSpaceUsage() const auto SimpleBlockFile::GetSpaceUsage() const -> DiskByteCount
{ {
if (mCache.active && mCache.needWrite) if (mCache.active && mCache.needWrite)
{ {
@ -598,9 +598,11 @@ wxLongLong SimpleBlockFile::GetSpaceUsage() const
file.Close(); file.Close();
} }
return sizeof(auHeader) + return
sizeof(auHeader) +
mSummaryInfo.totalSummaryBytes + mSummaryInfo.totalSummaryBytes +
(GetLength() * SAMPLE_SIZE_DISK(mFormat)); (GetLength() * SAMPLE_SIZE_DISK(mFormat))
;
} }
void SimpleBlockFile::Recover(){ 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 /// Write an XML representation of this file
void SaveXML(XMLWriter &xmlFile) override; void SaveXML(XMLWriter &xmlFile) override;
wxLongLong GetSpaceUsage() const override; DiskByteCount GetSpaceUsage() const override;
void Recover() override; void Recover() override;
static BlockFilePtr BuildFromXML(DirManager &dm, const wxChar **attrs); 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 //Get the samples from the track and put them in the buffer
track->Get((samplePtr) inBuffer, floatSample, samplePos, blockSize); track->Get((samplePtr) inBuffer, floatSample, samplePos, blockSize);
int inUsed; const auto results = resample.Process(mFactor,
int outgen = resample.Process(mFactor,
inBuffer, inBuffer,
blockSize, blockSize,
((samplePos + blockSize) >= end), ((samplePos + blockSize) >= end),
&inUsed,
outBuffer, outBuffer,
outBufferSize); outBufferSize);
if (outgen < 0) { const auto outgen = results.second;
bResult = false;
break;
}
if (outgen > 0) if (outgen > 0)
outputTrack->Append((samplePtr)outBuffer, floatSample, outputTrack->Append((samplePtr)outBuffer, floatSample,
outgen); outgen);
// Increment samplePos // Increment samplePos
samplePos += inUsed; samplePos += results.first;
// Update the Progress meter // Update the Progress meter
if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) { if (TrackProgress(mCurTrackNum, (samplePos - start) / len)) {

View File

@ -78,45 +78,34 @@ bool EffectRepair::Process()
WaveTrack *track = (WaveTrack *) iter.First(); WaveTrack *track = (WaveTrack *) iter.First();
int count = 0; int count = 0;
while (track) { while (track) {
const
double trackStart = track->GetStartTime(); double trackStart = track->GetStartTime();
const double repair_t0 = std::max(mT0, trackStart);
const
double trackEnd = track->GetEndTime(); double trackEnd = track->GetEndTime();
double repair_t0 = mT0; const double repair_t1 = std::min(mT1, trackEnd);
double repair_t1 = mT1; const
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();
double repair_deltat = repair_t1 - repair_t0; double repair_deltat = repair_t1 - repair_t0;
if (repair_deltat > 0) { // selection is within track audio
double spacing = repair_deltat * 2; const auto repair0 = track->TimeToLongSamples(repair_t0);
const auto repair1 = track->TimeToLongSamples(repair_t1);
if (spacing < 128. / rate) const auto repairLen = repair1 - repair0;
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 (repairLen > 128) { 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.")); ::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; bGoodResult = false;
break; 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) { 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.")); ::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).")); /// 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, //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, bool EffectTwoPassSimpleMono::ProcessOne(WaveTrack * track,
sampleCount start, sampleCount end) sampleCount start, sampleCount end)
{ {

View File

@ -204,7 +204,7 @@ public:
wxString GetFileDescription(); wxString GetFileDescription();
int GetFileUncompressedBytes(); ByteCount GetFileUncompressedBytes() override;
///! Imports audio ///! Imports audio
///\return import status (see Import.cpp) ///\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. // TODO: Get Uncompressed byte count.
return 0; return 0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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