Repository navigation
PlanarView: Add channel stride and subView - #4
Merged
Merged
Conversation
A PlanarView can now carry a channel stride larger than its channel length, so it can describe a range of samples inside a larger planar block. Added a stride constructor, getChannelStride, isContiguous and subView(offset, count). The default stride equals the sample count, so existing views behave exactly as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
PlanarViewgains a channel stride: channelcnow startsc * channelStrideelements after channel 0. The stride defaults to the channel length, so a view built with the existing constructors is still one contiguous block. A larger stride leaves gaps between channels, which is what a range of samples inside a larger planar block looks like.Why
To represent sub-block ranges of a multi-channel planar buffer. A polyphonic synth base in ESeq needs to hand each voice a zero-based view of just the samples it renders (e.g. from a note-on partway through the block), without copying. Existing callers keep identical behaviour, because the default stride equals the sample count.
API added
PlanarView(T* data, SizeType numChannels, SizeType numSamples, SizeType channelStride), plus a matching deduction guide. AssertschannelStride >= numSampleswhen there is more than one channel.int getChannelStride() constbool isContiguous() const: true when empty, single-channel, orchannelStride == numSamples.PlanarView subView(SizeType offset, SizeType count = toEnd) const: samples[offset, offset + count)of every channel, keeping the stride. Offset and count are clamped to the channel length.static constexpr int toEnd(forwarded fromSpan<T>::toEnd).Behaviour changes inside the class
getChannel,operator[]andPlanarIteratoroffset by the stride, not the sample count.fillnow fills channel by channel, so it leaves the gaps between channels alone.flat()assertsisContiguous().getNumElements()still returns the logical count (channels × samples) and excludes the gaps.sizeof(PlanarView)grows by oneint.Tests
PlanarView.is_a_pointer_and_two_intstoPlanarView.is_a_pointer_and_three_ints. Itsstatic_assertnow compares against a struct of a pointer and three ints, so it accounts for padding to the pointer's alignment.subViewoffsets, iterating a strided view,fillon a sub-view leaving the gaps alone, const conversion keeping the stride,isContiguouscases,subViewclamping and empty results,flat()on an empty strided sub-view, andsubViewat compile time.Test results
488/488 passing in this repo's own build.