Browse Source

ARAPluginDemo: Fix incorrect sample reading in editor renderer

v7.0.9
attila Attila Szarvas 2 years ago
parent
commit
4804e9afd2
1 changed files with 14 additions and 30 deletions
  1. +14
    -30
      examples/Plugins/ARAPluginDemo.h

+ 14
- 30
examples/Plugins/ARAPluginDemo.h View File

@@ -110,7 +110,10 @@ public:
void writeInto (AudioBuffer<float>& buffer) void writeInto (AudioBuffer<float>& buffer)
{ {
if (loopRange.getLength() == 0) if (loopRange.getLength() == 0)
{
buffer.clear(); buffer.clear();
return;
}
const auto numChannelsToCopy = std::min (inputBuffer->getNumChannels(), buffer.getNumChannels()); const auto numChannelsToCopy = std::min (inputBuffer->getNumChannels(), buffer.getNumChannels());
@@ -140,36 +143,15 @@ private:
int64 pos; int64 pos;
}; };
class OptionalRange
{
public:
using Type = Range<int64>;
OptionalRange() : valid (false) {}
explicit OptionalRange (Type valueIn) : valid (true), value (std::move (valueIn)) {}
explicit operator bool() const noexcept { return valid; }
const auto& operator*() const
{
jassert (valid);
return value;
}
private:
bool valid;
Type value;
};
//============================================================================== //==============================================================================
// Returns the modified sample range in the output buffer. // Returns the modified sample range in the output buffer.
inline OptionalRange readPlaybackRangeIntoBuffer (Range<double> playbackRange,
const ARAPlaybackRegion* playbackRegion,
AudioBuffer<float>& buffer,
const std::function<AudioFormatReader* (ARA::PlugIn::AudioSource*)>& getReader)
inline std::optional<Range<int64>> readPlaybackRangeIntoBuffer (Range<double> playbackRange,
const ARAPlaybackRegion* playbackRegion,
AudioBuffer<float>& buffer,
const std::function<AudioFormatReader* (ARA::PlugIn::AudioSource*)>& getReader)
{ {
const auto rangeInAudioModificationTime = playbackRange.movedToStartAt (playbackRange.getStart()
- playbackRegion->getStartInAudioModificationTime());
const auto rangeInAudioModificationTime = playbackRange - playbackRegion->getStartInPlaybackTime()
+ playbackRegion->getStartInAudioModificationTime();
const auto audioSource = playbackRegion->getAudioModification()->getAudioSource(); const auto audioSource = playbackRegion->getAudioModification()->getAudioSource();
const auto audioModificationSampleRate = audioSource->getSampleRate(); const auto audioModificationSampleRate = audioSource->getSampleRate();
@@ -181,7 +163,9 @@ inline OptionalRange readPlaybackRangeIntoBuffer (Range<double> playbackRange,
const auto inputOffset = jlimit ((int64_t) 0, audioSource->getSampleCount(), sampleRangeInAudioModification.getStart()); const auto inputOffset = jlimit ((int64_t) 0, audioSource->getSampleCount(), sampleRangeInAudioModification.getStart());
const auto outputOffset = -std::min (sampleRangeInAudioModification.getStart(), (int64_t) 0);
// With the output offset it can always be said of the output buffer, that the zeroth element
// corresponds to beginning of the playbackRange.
const auto outputOffset = std::max (-sampleRangeInAudioModification.getStart(), (int64_t) 0);
/* TODO: Handle different AudioSource and playback sample rates. /* TODO: Handle different AudioSource and playback sample rates.
@@ -203,12 +187,12 @@ inline OptionalRange readPlaybackRangeIntoBuffer (Range<double> playbackRange,
}(); }();
if (readLength == 0) if (readLength == 0)
return OptionalRange { {} };
return Range<int64>();
auto* reader = getReader (audioSource); auto* reader = getReader (audioSource);
if (reader != nullptr && reader->read (&buffer, (int) outputOffset, (int) readLength, inputOffset, true, true)) if (reader != nullptr && reader->read (&buffer, (int) outputOffset, (int) readLength, inputOffset, true, true))
return OptionalRange { { outputOffset, readLength } };
return Range<int64>::withStartAndLength (outputOffset, readLength);
return {}; return {};
} }


Loading…
Cancel
Save