Skip to content

Commit

Permalink
AudioClip::render signature to std::span
Browse files Browse the repository at this point in the history
  • Loading branch information
stellar-aria committed Jan 15, 2025
1 parent 8062c4a commit 6ecedd0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/deluge/dsp/compressor/rms_feedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "dsp/filter/ladder_components.h"
#include "dsp/stereo_sample.h"
#include <cmath>
#include <span>

class [[gnu::hot]] RMSFeedbackCompressor {
public:
Expand Down
15 changes: 8 additions & 7 deletions src/deluge/model/clip/audio_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "processing/audio_output.h"
#include "processing/engines/audio_engine.h"
#include "storage/storage_manager.h"
#include "util/fixedpoint.h"
#include <new>

namespace params = deluge::modulation::params;
Expand Down Expand Up @@ -543,8 +544,8 @@ int64_t AudioClip::getNumSamplesTilLoop(ModelStackWithTimelineCounter* modelStac
return loopTime - AudioEngine::audioSampleTimer;
}

void AudioClip::render(ModelStackWithTimelineCounter* modelStack, int32_t* outputBuffer, int32_t numSamples,
int32_t amplitude, int32_t amplitudeIncrement, int32_t pitchAdjust) {
void AudioClip::render(ModelStackWithTimelineCounter* modelStack, std::span<q31_t> outputBuffer, int32_t amplitude,
int32_t amplitudeIncrement, int32_t pitchAdjust) {

if (!voiceSample) {
return;
Expand All @@ -554,7 +555,7 @@ void AudioClip::render(ModelStackWithTimelineCounter* modelStack, int32_t* outpu

// First, if we're still attempting to do a "late start", see if we can do that (perhaps not if relevant audio data
// hasn't loaded yet)
if (doingLateStart && ((AudioOutput*)output)->envelope.state < EnvelopeStage::FAST_RELEASE) {
if (doingLateStart && static_cast<AudioOutput*>(this->output)->envelope.state < EnvelopeStage::FAST_RELEASE) {
uint64_t numSamplesIn = guide.getSyncedNumSamplesIn();

LateStartAttemptStatus result = voiceSample->attemptLateSampleStart(&guide, sample, numSamplesIn);
Expand Down Expand Up @@ -726,7 +727,7 @@ void AudioClip::render(ModelStackWithTimelineCounter* modelStack, int32_t* outpu
// forgot?) It's perhaps a little bit surprising, but this even works and sounds perfect (you never hear any of
// the margin) when time-stretching is happening! Down to about half speed. Below that, you hear some of the
// margin.
if (((AudioOutput*)output)->envelope.state < EnvelopeStage::FAST_RELEASE) {
if (static_cast<AudioOutput*>(this->output)->envelope.state < EnvelopeStage::FAST_RELEASE) {

ModelStackWithNoteRow* modelStackWithNoteRow = modelStack->addNoteRow(0, nullptr);

Expand All @@ -739,7 +740,7 @@ void AudioClip::render(ModelStackWithTimelineCounter* modelStack, int32_t* outpu
int32_t timeTilLoop = loopTime - AudioEngine::audioSampleTimer;

if (timeTilLoop < 1024) {
((AudioOutput*)output)
static_cast<AudioOutput*>(this->output)
->envelope.unconditionalRelease(EnvelopeStage::FAST_RELEASE, 8192); // Let's make it extra fast?
}
}
Expand All @@ -760,8 +761,8 @@ void AudioClip::render(ModelStackWithTimelineCounter* modelStack, int32_t* outpu
{
LoopType loopingType = getLoopingType(modelStack);

stillActive = voiceSample->render(&guide, outputBuffer, numSamples, sample, sample->numChannels, loopingType,
phaseIncrement, timeStretchRatio, amplitude, amplitudeIncrement,
stillActive = voiceSample->render(&guide, outputBuffer.data(), outputBuffer.size(), sample, sample->numChannels,
loopingType, phaseIncrement, timeStretchRatio, amplitude, amplitudeIncrement,
sampleControls.getInterpolationBufferSize(phaseIncrement),
sampleControls.interpolationMode, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/model/clip/audio_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AudioClip final : public Clip {
void processCurrentPos(ModelStackWithTimelineCounter* modelStack, uint32_t ticksSinceLast) override;
void expectNoFurtherTicks(Song* song, bool actuallySoundChange = true) override;
Error clone(ModelStackWithTimelineCounter* modelStack, bool shouldFlattenReversing = false) const override;
void render(ModelStackWithTimelineCounter* modelStack, int32_t* outputBuffer, int32_t numSamples, int32_t amplitude,
void render(ModelStackWithTimelineCounter* modelStack, std::span<q31_t> output, int32_t amplitude,
int32_t amplitudeIncrement, int32_t pitchAdjust);
void detachFromOutput(ModelStackWithTimelineCounter* modelStack, bool shouldRememberDrumName,
bool shouldDeleteEmptyNoteRowsAtEndOfList = false, bool shouldRetainLinksToSounds = false,
Expand Down
4 changes: 2 additions & 2 deletions src/deluge/processing/audio_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ bool AudioOutput::renderGlobalEffectableForClip(ModelStackWithTimelineCounter* m
/ static_cast<double>(render.size()));

std::span render_mono{reinterpret_cast<q31_t*>(render.data()), render.size()};
activeAudioClip.render(modelStack, render_mono.data(), render_mono.size(), amplitudeEffectiveStart,
amplitudeIncrementEffective, pitchAdjust);
activeAudioClip.render(modelStack, render_mono, amplitudeEffectiveStart, amplitudeIncrementEffective,
pitchAdjust);
rendered = true;
amplitudeLastTime = amplitudeLocal;

Expand Down

0 comments on commit 6ecedd0

Please sign in to comment.