Commit autosave blobs during recording only as needed...

... when there really is at least one new sample block committed to the table,
which is typically only once in about every six seconds, with the default rate
and sample format.

Also renamed a callback function more aptly, since blocks are not files any
more.
This commit is contained in:
Paul Licameli 2020-07-10 19:05:48 -04:00
parent 047fa18afd
commit 6eb6aab8f5
8 changed files with 21 additions and 11 deletions

View File

@ -2893,6 +2893,8 @@ void AudioIO::FillBuffers()
if (mAudioThreadShouldCallFillBuffersOnce ||
deltat >= mMinCaptureSecsToCopy)
{
bool newBlocks = false;
// Append captured samples to the end of the WaveTracks.
// The WaveTracks have their own buffering for efficiency.
auto numChannels = mCaptureTracks.size();
@ -3014,7 +3016,8 @@ void AudioIO::FillBuffers()
// Now append
// see comment in second handler about guarantee
mCaptureTracks[i]->Append(temp.ptr(), format, size, 1);
newBlocks = mCaptureTracks[i]->Append(temp.ptr(), format, size, 1)
|| newBlocks;
} // end loop over capture channels
// Now update the recording shedule position
@ -3022,8 +3025,8 @@ void AudioIO::FillBuffers()
mRecordingSchedule.mLatencyCorrected = latencyCorrected;
auto pListener = GetListener();
if (pListener)
pListener->OnAudioIONewBlockFiles(&mCaptureTracks);
if (pListener && newBlocks)
pListener->OnAudioIONewBlocks(&mCaptureTracks);
}
// end of record buffering
},

View File

@ -25,7 +25,7 @@ public:
virtual void OnAudioIOStartRecording() = 0;
virtual void OnAudioIOStopRecording() = 0;
virtual void OnAudioIONewBlockFiles(const WaveTrackArray *tracks) = 0;
virtual void OnAudioIONewBlocks(const WaveTrackArray *tracks) = 0;
// Commit the addition of temporary recording tracks into the project
virtual void OnCommitRecording() = 0;

View File

@ -925,7 +925,7 @@ You are saving directly to a slow external storage device\n\
}
}
void ProjectAudioManager::OnAudioIONewBlockFiles(const WaveTrackArray *tracks)
void ProjectAudioManager::OnAudioIONewBlocks(const WaveTrackArray *tracks)
{
auto &project = mProject;
auto &projectFileIO = ProjectFileIO::Get( project );

View File

@ -137,7 +137,7 @@ private:
void OnAudioIORate(int rate) override;
void OnAudioIOStartRecording() override;
void OnAudioIOStopRecording() override;
void OnAudioIONewBlockFiles(const WaveTrackArray *tracks) override;
void OnAudioIONewBlocks(const WaveTrackArray *tracks) override;
void OnCommitRecording() override;
void OnSoundActivationThreshold() override;

View File

@ -1202,13 +1202,14 @@ void WaveClip::GetDisplayRect(wxRect* r)
*r = mDisplayRect;
}
void WaveClip::Append(samplePtr buffer, sampleFormat format,
bool WaveClip::Append(samplePtr buffer, sampleFormat format,
size_t len, unsigned int stride /* = 1 */)
// PARTIAL-GUARANTEE in case of exceptions:
// Some prefix (maybe none) of the buffer is appended, and no content already
// flushed to disk is lost.
{
//wxLogDebug(wxT("Append: len=%lli"), (long long) len);
bool result = false;
auto maxBlockSize = mSequence->GetMaxBlockSize();
auto blockSize = mSequence->GetIdealAppendLen();
@ -1228,6 +1229,7 @@ void WaveClip::Append(samplePtr buffer, sampleFormat format,
// flush some previously appended contents
// use STRONG-GUARANTEE
mSequence->Append(mAppendBuffer.ptr(), seqFormat, blockSize);
result = true;
// use NOFAIL-GUARANTEE for rest of this "if"
memmove(mAppendBuffer.ptr(),
@ -1255,6 +1257,8 @@ void WaveClip::Append(samplePtr buffer, sampleFormat format,
buffer += toCopy * SAMPLE_SIZE(format) * stride;
len -= toCopy;
}
return result;
}
void WaveClip::Flush()

View File

@ -281,7 +281,8 @@ public:
void UpdateEnvelopeTrackLen();
/// You must call Flush after the last Append
void Append(samplePtr buffer, sampleFormat format,
/// @return true if at least one complete block was created
bool Append(samplePtr buffer, sampleFormat format,
size_t len, unsigned int stride=1);
/// Flush must be called after last Append
void Flush();

View File

@ -1485,13 +1485,13 @@ void WaveTrack::Join(double t0, double t1)
}
}
void WaveTrack::Append(samplePtr buffer, sampleFormat format,
bool WaveTrack::Append(samplePtr buffer, sampleFormat format,
size_t len, unsigned int stride /* = 1 */)
// PARTIAL-GUARANTEE in case of exceptions:
// Some prefix (maybe none) of the buffer is appended, and no content already
// flushed to disk is lost.
{
RightmostOrNewClip()->Append(buffer, format, len, stride);
return RightmostOrNewClip()->Append(buffer, format, len, stride);
}
sampleCount WaveTrack::GetBlockStart(sampleCount s) const

View File

@ -220,8 +220,10 @@ private:
* If there is an existing WaveClip in the WaveTrack then the data is
* appended to that clip. If there are no WaveClips in the track, then a NEW
* one is created.
*
* @return true if at least one complete block was created
*/
void Append(samplePtr buffer, sampleFormat format,
bool Append(samplePtr buffer, sampleFormat format,
size_t len, unsigned int stride=1);
/// Flush must be called after last Append
void Flush();