|
ape
0.5.0
Audio Programming Environment
|
Go to the documentation of this file.
40 uarray(
const std::vector<
typename std::remove_const_t<T>>& source) :
uarray(source.
data(), source.
size()) {}
44 uarray(T* buffer, std::size_t length)
45 : buffer(buffer), length(length)
47 #ifndef CPPAPE_RELEASE
57 #ifndef CPPAPE_RELEASE
68 #ifndef CPPAPE_RELEASE
69 assert(index < length);
79 #ifndef CPPAPE_RELEASE
80 assert(index < length);
88 T*
begin() noexcept {
return buffer; }
92 const T*
begin() const noexcept {
return buffer; }
96 T*
end() noexcept {
return buffer + length; }
100 const T*
end() const noexcept {
return buffer + length; }
104 T*
data() noexcept {
return buffer; }
108 const T*
data() const noexcept {
return buffer; }
113 std::size_t
size() const noexcept {
return length; }
128 assert(offset <= length);
130 newLength = length - offset;
132 assert((offset + newLength) <= length);
133 return { buffer + offset, newLength };
136 template<
typename Other>
137 typename std::enable_if<std::is_standard_layout<Other>::value && !std::is_const<T>::value,
uarray<Other>>::type
140 static_assert((
sizeof(T) /
sizeof(Other)) *
sizeof(Other) ==
sizeof(T),
"Other is not divisble by T");
141 static_assert(
alignof(T) <=
alignof(Other),
"Other is less aligned than T");
143 constexpr
auto ratio =
sizeof(T) /
sizeof(Other);
145 return { reinterpret_cast<Other*>(buffer), length * ratio };
148 template<
typename Other>
149 typename std::enable_if<std::is_standard_layout<Other>::value && std::is_const<T>::value,
uarray<const Other>>::type
152 static_assert((
sizeof(T) /
sizeof(Other)) *
sizeof(Other) ==
sizeof(T),
"Other is not divisble by T");
153 static_assert(
alignof(T) <=
alignof(Other),
"Other is less aligned than T");
155 constexpr
auto ratio =
sizeof(T) /
sizeof(Other);
157 return { reinterpret_cast<const Other*>(buffer), length * ratio };
173 assert(offset <= length);
176 newLength = length - offset;
178 assert((offset + newLength) <= length);
179 return { buffer + offset, newLength };
194 const std::size_t length;
234 : source(matrix), row(row)
272 return row == right.row && source.data == right.source.data;
277 return !(*
this == right);
288 umatrix(T *
const *
data, std::size_t channelsOrRows, std::size_t samplesOrColumns)
304 #ifndef CPPAPE_RELEASE
314 iterator
begin() const noexcept {
return { *
this }; }
367 void resize(std::size_t channelCount, std::size_t samples)
370 buffer.resize(channelCount * samples);
372 for (std::size_t c = 0; c < channelCount; ++c)
418 auto mod = x % source.
size();
419 x = mod < 0 ? mod + source.
size() : mod;
425 auto mod = x % source.
size();
426 x = mod < 0 ? mod + source.
size() : mod;
432 return source[x % source.
size()];
437 return source[x % source.
size()];
467 if (x >= 0 && x < source.
size())
470 return static_cast<T>(0);
475 if (x >= 0 && x < source.
size())
478 return static_cast<T>(0);
483 if (x < source.
size())
486 return static_cast<T>(0);
491 if (x < source.
size())
494 return static_cast<T>(0);
529 template<
typename Container>
530 friend auto cyclic_begin(Container& c, std::size_t offset);
532 template<
typename Container>
533 friend auto cyclic_end(Container& c, std::size_t offset, std::size_t length);
548 if (++origin >= bounds)
584 left.base == right.base &&
585 left.distance == right.distance &&
586 left.origin == right.origin &&
587 left.bounds == right.bounds;
592 return !(left == right);
597 std::ptrdiff_t distance;
613 template<
typename Container>
619 ret.origin = offset % c.size();
620 ret.bounds = c.size();
636 template<
typename Container>
637 inline auto cyclic_end(Container& c, std::size_t offset, std::size_t length)
641 ret.distance = length;
642 ret.origin = (offset + length) % c.size();
643 ret.bounds = c.size();
652 inline void clear(std::vector<T>& arr) noexcept
654 std::fill(arr.begin(), arr.end(), T());
661 inline typename std::enable_if<!std::is_const_v<T>>::type
664 std::fill(arr.begin(), arr.end(), T());
671 inline typename std::enable_if<!std::is_const_v<T>>::type
674 for (std::size_t c = offset; c < mat.
channels(); ++c)
695 return { data, size };
701 return { data, size };
auto cyclic_begin(Container &c, std::size_t offset)
Constructs a suitable beginning iterator of a cyclic iteration on c . Iteration effectively wraps aro...
Definition: misc.h:614
uarray< T > operator[](std::size_t row) const CPPAPE_NOEXCEPT_IF_RELEASE
Access the row in the matrix.
Definition: misc.h:302
auto cyclic_end(Container &c, std::size_t offset, std::size_t length)
Specifies an "end" to cyclic_begin
Definition: misc.h:637
std::forward_iterator_tag iterator_category
Definition: misc.h:526
umatrix(T *const *data, std::size_t channelsOrRows, std::size_t samplesOrColumns)
Construct from a pointer array.
Definition: misc.h:288
umatrix< T > asMatrix() noexcept
Explicitly alias as a mutable umatrix.
Definition: misc.h:396
An infinitely indexable read-only signal that windows the original signal (ie. it is zero outside of ...
Definition: misc.h:459
T * begin() noexcept
Returns an iterator to the beginning of the array pointed to
Definition: misc.h:88
iterator begin() const noexcept
Retrieve an iterator that can enumerate channels contained in this matrix.
Definition: misc.h:314
T value_type
Definition: misc.h:522
uarray< T > operator*()
Definition: misc.h:265
value_type & reference
Definition: misc.h:524
std::bidirectional_iterator_tag iterator_category
Definition: misc.h:231
uarray< T > as_uarray(std::vector< T > &vec)
Definition: misc.h:681
const T * data() const noexcept
Retrieve a const raw pointer to the array pointed to
Definition: misc.h:108
A container representing a 2d rectangular array (and can be used syntactically like one)....
Definition: misc.h:212
T operator()(std::uint32_t x) const noexcept
Definition: misc.h:489
bool operator==(const iterator &right) const noexcept
Definition: misc.h:270
auto pointers()
Returns a possibly cv-qualified T * const*
Definition: misc.h:341
friend bool operator==(circular_iterator< T > left, circular_iterator< T > right)
Definition: misc.h:581
std::size_t columns() const noexcept
samples()
Definition: misc.h:336
iterator & operator++()
Definition: misc.h:239
T operator()(std::int64_t x) const noexcept
Definition: misc.h:465
std::ptrdiff_t difference_type
Definition: misc.h:523
this_type & operator--() noexcept
Definition: misc.h:568
std::size_t numColumns
Definition: misc.h:354
T value_type
Definition: misc.h:216
friend auto cyclic_begin(Container &c, std::size_t offset)
Constructs a suitable beginning iterator of a cyclic iteration on c . Iteration effectively wraps aro...
Definition: misc.h:614
std::vector< T > buffer
Definition: misc.h:402
std::size_t channels() const noexcept
Definition: misc.h:328
iterator & operator--()
Definition: misc.h:245
this_type & operator++() noexcept
Definition: misc.h:546
T * end() noexcept
Returns an iterator pointing to 1 element past the end of the array pointed to
Definition: misc.h:96
T operator()(std::int32_t x) const noexcept
Definition: misc.h:423
void resize(std::size_t channelCount, std::size_t samples)
Retranslate the buffers and contents to adhere to the dimensionality given by the arguments....
Definition: misc.h:367
iterator end() const noexcept
Retrieve an iterator pointing to one past the last channel in this matrix. begin()
Definition: misc.h:319
iterator(umatrix< T > matrix, std::size_t row=0)
Definition: misc.h:233
An unowned array wrapper - a mutable "view" of something else, that cannot be resized....
Definition: misc.h:24
uarray(T *buffer, std::size_t length)
Construct from a possibly cv-qualified source
Definition: misc.h:44
std::ptrdiff_t difference_type
Definition: misc.h:227
value_type & reference
Definition: misc.h:230
windowed_signal(uarray< const T > source)
Definition: misc.h:463
const T hermite4(const T offset, const T ym1, const T y0, const T y1, const T y2)
Do hermite 4 interpolation given the four y-coordinates
Definition: interpolation.h:76
Definition: audiofile.h:7
const auto pointers() const noexcept
Definition: misc.h:342
const T * end() const noexcept
Returns a const iterator pointing to 1 element past the end of the array pointed to
Definition: misc.h:100
T value_type
Definition: misc.h:228
T *const * data
Definition: misc.h:353
uarray< T > slice(std::size_t offset, std::size_t newLength=-1) noexcept
Returns a new, constant uarray formed from a slice of the original.
Definition: misc.h:126
std::size_t size() const noexcept
Returns the size of the array pointed to by this uarray
Definition: misc.h:113
std::size_t samples() const noexcept
Definition: misc.h:324
uarray(std::vector< T > &source)
Construct from a mutable vector.
Definition: misc.h:36
uarray< const T > slice(std::size_t offset, std::size_t newLength=-1) const noexcept
Returns a new, constant uarray formed from a slice of the original.
Definition: misc.h:171
circular_signal(uarray< const T > source)
Definition: misc.h:414
reference operator*() noexcept
Definition: misc.h:536
T * data() noexcept
Retrieve a raw pointer to the array pointed to
Definition: misc.h:104
bool operator!=(const iterator &right) const noexcept
Definition: misc.h:275
uarray(T *begin, T *end)
Construct from a possibly cv-qualified iterator pair
Definition: misc.h:54
value_type * pointer
Definition: misc.h:229
LegacyForwardIterator with capability of iterating N steps around a flat source with an offset....
Definition: misc.h:518
T operator()(std::uint64_t x) const noexcept
Definition: misc.h:430
T * pointer
Definition: misc.h:525
uarray(const std::vector< typename std::remove_const_t< T >> &source)
Construct a read-only uarray from a const-qualified vector.
Definition: misc.h:40
friend bool operator!=(circular_iterator< T > left, circular_iterator< T > right)
Definition: misc.h:590
An infinitely indexable read-only signal that repeats the original signal. Supports signed and unsign...
Definition: misc.h:410
std::vector< T * > channels
Definition: misc.h:401
std::enable_if< std::is_standard_layout< Other >::value &&std::is_const< T >::value, uarray< const Other > >::type reinterpret() const noexcept
Definition: misc.h:150
T & operator[](std::size_t index)
Access a potential read-only element at index
Definition: misc.h:66
An owned 2d rectangular matrix that supports a T** representation and being aliased as a umatrix.
Definition: misc.h:361
T operator()(std::uint64_t x) const noexcept
Definition: misc.h:481
friend auto cyclic_end(Container &c, std::size_t offset, std::size_t length)
Specifies an "end" to cyclic_begin
Definition: misc.h:637
Iterator for enumerating the rows of a umatrix umatrix<T>::begin()
Definition: misc.h:225
std::size_t rows() const noexcept
channels()
Definition: misc.h:332
void clear(std::vector< T > &arr) noexcept
Clear a uarray of non-const qualified T elements to a default-initialized value.
Definition: misc.h:652
const T * begin() const noexcept
Returns a const iterator to the beginning of the array pointed to
Definition: misc.h:92
pointer operator->() noexcept
Definition: misc.h:556
T operator()(std::int32_t x) const noexcept
Definition: misc.h:473
T value_type
Alias for T
Definition: misc.h:31
T operator()(std::uint32_t x) const noexcept
Definition: misc.h:435
T operator()(std::int64_t x) const noexcept
Definition: misc.h:416
std::size_t numRows
Definition: misc.h:354
std::enable_if< std::is_standard_layout< Other >::value &&!std::is_const< T >::value, uarray< Other > >::type reinterpret() noexcept
Definition: misc.h:138