Skip to content

Commit

Permalink
Hoist buffer allocation again, out of RealtimeEffectManager
Browse files Browse the repository at this point in the history
(cherry picked from commit 4113446;
modified for Tenacity)
Signed-off-by: Avery King <[email protected]>
  • Loading branch information
Paul-Licameli authored and generic-pers0n committed Aug 27, 2024
1 parent 240c3f0 commit a39c797
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/AudioIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ bool AudioIoCallback::FillOutputBuffers(
// Do realtime effects
if( !dropQuickly && len > 0 ) {
if (pScope)
pScope->Process(mTrackChannelsBuffer[0], mAudioScratchBuffers.data(), len);
pScope->Process(mTrackChannelsBuffer[0], mAudioScratchBuffers.data(), mScratchPointers.data(), len);
// Mix the results with the existing output (software playthrough) and
// apply panning. If post panning effects are desired, the panning would
// need to be be split out from the mixing and applied in a separate step.
Expand Down
11 changes: 4 additions & 7 deletions src/effects/RealtimeEffectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ void RealtimeEffectManager::ProcessStart()
// This will be called in a different thread than the main GUI thread.
//
size_t RealtimeEffectManager::Process(Track *track,
float **buffers,
size_t numSamples)
float *const *buffers, float *const *scratch,
size_t numSamples)
{
using namespace std::chrono;

Expand All @@ -197,15 +197,13 @@ size_t RealtimeEffectManager::Process(Track *track,
static_cast<float **>(alloca(chans * sizeof(float *)));
const auto obuf =
static_cast<float **>(alloca(chans * sizeof(float *)));
const auto scratch =
static_cast<float*>(alloca(numSamples * sizeof(float)));

// And populate the input with the buffers we've been given while allocating
// NEW output buffers
for (unsigned int i = 0; i < chans; i++)
{
ibuf[i] = buffers[i];
obuf[i] = static_cast<float*>(alloca(numSamples * sizeof(float)));
obuf[i] = scratch[i];
}

// Now call each effect in the chain while swapping buffer pointers to feed the
Expand All @@ -218,8 +216,7 @@ size_t RealtimeEffectManager::Process(Track *track,
if (bypassed)
return;

state.Process(track, chans, ibuf, obuf, scratch, numSamples);

state.Process(track, chans, ibuf, obuf, scratch[chans], numSamples);
for (auto i = 0; i < chans; ++i)
std::swap(ibuf[i], obuf[i]);
called++;
Expand Down
14 changes: 11 additions & 3 deletions src/effects/RealtimeEffectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class TENACITY_DLL_API RealtimeEffectManager final

friend RealtimeEffects::ProcessingScope;
void ProcessStart();
size_t Process(Track *track, float **buffers, size_t numSamples);
/*! @copydoc ProcessScope::Process */
size_t Process(Track *track,
float *const *buffers, float *const *scratch, size_t numSamples);
void ProcessEnd() noexcept;

RealtimeEffectManager(const RealtimeEffectManager&) = delete;
Expand Down Expand Up @@ -196,11 +198,17 @@ class ProcessingScope {
RealtimeEffectManager::Get(*pProject).ProcessEnd();
}

size_t Process(Track *track, float **buffers, size_t numSamples)
size_t Process(Track *track,
float *const *buffers, /*!< Assume as many buffers, as channels were
specified in the AddTrack call */
float *const *scratch, /*!< As many temporary buffers as in buffers,
plus one more */
size_t numSamples //!< length of each buffer
)
{
if (auto pProject = mwProject.lock())
return RealtimeEffectManager::Get(*pProject)
.Process(track, buffers, numSamples);
.Process(track, buffers, scratch, numSamples);
else
return numSamples; // consider them trivially processed
}
Expand Down

0 comments on commit a39c797

Please sign in to comment.