18 auto const startOffset = (
index + bufferLength -
count) % bufferLength;
19 auto const endOffset = (
index % bufferLength);
21 auto const firstLength = (startOffset < endOffset) ?
count : bufferLength - startOffset;
22 auto const secondLength =
count - firstLength;
24 slice.base.fragments[0].pointer = baseBufferPtr + (sampleWordSize * startOffset);
25 slice.base.fragments[0].size = sampleWordSize * firstLength;
27 slice.base.fragments[1].pointer = baseBufferPtr;
28 slice.base.fragments[1].size = sampleWordSize * secondLength;
30 slice.stride = sampleWordSize * bufferLength;
31 slice.count = channelCount;
41 return std::bit_cast<AudioEntryHeader const*>(
_data.data());
66 auto out = std::vector<Region>{};
70 out.emplace_back(
reinterpret_cast<std::uintptr_t
>(entry.data()), entry.size(),
nullptr,
nullptr,
Region::Location::host());
87 auto const& entry =
_entries.at(entryIndex);
88 auto const* header = entry.header();
92 if (header->count == 0)
98 if (header->count >
_layout.bufferLength)
101 "Invalid 'count' {} received in the header. More samples per channel than the ring holds ({}).", header->count,
_layout.bufferLength);
104 if (header->count > maxCountPerEntry)
107 "Invalid 'count' {} received in the header. That number of samples per channel would bust the bounce buffer entry.", header->count);
117 reinterpret_cast<std::uint8_t*
>(outRegion.
base),
120 auto srcAddr = entry.samples();
123 for (
auto chan = std::size_t{0}; chan < slices.
count; chan++)
128 if (fragment.size > 0)
130 auto const dstAddr =
reinterpret_cast<std::uint8_t*
>(fragment.pointer) + (slices.
stride * chan);
131 std::memcpy(dstAddr, srcAddr, fragment.size);
132 srcAddr += fragment.size;
An audio bounce buffer entry is backed by a collection of samples The layout is: AudioEntryHeader,...
std::vector< std::uint8_t > _data
std::uint8_t const * samples() const noexcept
Return a view to the samples data of the bounce buffer entry.
std::size_t size() const noexcept
The total size of the bounce buffer entry in bytes.
AudioEntryHeader const * header() const noexcept
Return a view on the header of the bounce buffer entry.
AudioBounceBufferEntry(std::uint32_t size)
Construct an AudioBounceBufferEntry with the given size in bytes. The size should be large enough to ...
std::uint8_t const * data() const noexcept
Return a view to the beginning of the bounce buffer entry data.
AudioEntryHeader const & unpack(std::size_t entryIndex, Region const &outRegion) const
Copy the samples from the bounce buffer entry to the provided output region, and return the header of...
DataLayout::Continuous _layout
std::vector< Region > getRegions() const noexcept
Return the regions corresponding to the bounce buffer entries. Each region corresponds to one bounce ...
static void getMutableMultiBufferSlices(std::uint64_t index, std::size_t count, std::size_t bufferLength, std::size_t sampleWordSize, std::size_t channelCount, std::uint8_t *baseBufferPtr, mxlMutableWrappedMultiBufferSlice &slice) noexcept
std::size_t entryCount() const noexcept
Return the number of entries in the bounce buffer.
AudioBounceBuffer(std::size_t entryCount, std::size_t entrySize, DataLayout::Continuous layout)
std::vector< AudioBounceBufferEntry > _entries
std::size_t entrySize() const noexcept
Return the size of a bounce buffer entry in bytes.
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
static Location host() noexcept
specify a host memory location.
Represent a memory region (unregistered).
struct mxlMutableWrappedMultiBufferSlice_t mxlMutableWrappedMultiBufferSlice
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
mxlMutableBufferSlice fragments[2]
mxlMutableWrappedBufferSlice base
Continuous layout variant of DataLayout.