Memory functions. More...
Functions | |
template<class T > | |
void | compact (T *dst, const T *src, uint32_t len, uint32_t chunkSize) |
Copies every 'chunkSize'th element to 'dst'; akin to downsampling. | |
template<class T > | |
uint32_t | copyToRing (T *ring, uint32_t ringSize, uint32_t ringTap, const T *src, uint32_t len) |
Copies elements into a ring buffer. | |
template<class T > | |
void | copyFromRing (const T *ring, uint32_t ringSize, uint32_t ringTap, T *dst, uint32_t len) |
Copies a number of element from a ring buffer. | |
template<class T > | |
void | copyAllFromRing (const T *ring, uint32_t ringSize, uint32_t ringTap, T *dst) |
Copies all elements from a ring buffer. | |
template<class T > | |
void | deepCopy (T *dst, const T *src, uint32_t len) |
Copy source 'src' array bytes to destination 'dst'. | |
template<class T > | |
bool | deepEqual (const T *src1, const T *src2, uint32_t len) |
Returns whether array bytes are equal (==). | |
template<class T > | |
void | deepMove (T *dst, const T *src, uint32_t len) |
Move source 'src' array bytes to destination 'dst'. Arrays can overlap. | |
template<class T > | |
void | deepZero (T *arr, uint32_t len) |
Set elements' bytes to zero. | |
template<class T > | |
void | deinterleave (T *dst, const T *src, uint32_t numFrames, uint32_t numChannels) |
Deinterleave an array of elements with any number of channels. | |
template<class T > | |
void | deinterleave2 (T *dst, const T *src, uint32_t numFrames) |
Deinterleave an array of elements with 2 channels. | |
template<class T > | |
void | expand (T *dst, const T *src, uint32_t lenSrc, uint32_t amount) |
Expands elements from 'src' to 'dst'. | |
template<class T > | |
void | free (T *&ptr) |
Like standard free, but checks if pointer is valid (!=0) and sets it to zero after freeing it. | |
template<class T > | |
bool | indexOf (const T &elem, uint32_t &ind, const T *src, uint32_t len, uint32_t str=1) |
Finds index 'ind' of first element in 'src' equal to 'elem'. | |
template<class T > | |
void | interleave (T *dst, const T *src, uint32_t numFrames, uint32_t numChannels) |
Interleave an array of elements with any number of channels. | |
template<class T > | |
void | interleave2 (T *dst, const T *src, uint32_t numFrames) |
Interleave an array of elements with 2 channels. | |
template<class T > | |
void | keep (T *arr, uint32_t len, uint32_t stride, uint32_t offset=0) |
Keeps every Nth element; the rest are zeroed. | |
template<class T > | |
void | permute (T *arr, uint32_t len, uint64_t k) |
Perform kth permutation on array. | |
template<class T > | |
void | pivot (uint32_t index, T *arr, uint32_t len) |
Pivot elements around 'index' element. | |
template<class T > | |
void | reflectLeft (T *arr, uint32_t len, uint32_t str=1) |
Reflect right half of array to left half. | |
template<class T > | |
void | reflectRight (T *arr, uint32_t len, uint32_t str=1) |
Reflect left half of array to right half. | |
template<class T > | |
void | repeat (uint32_t chunkSize, T *arr, uint32_t len) |
Repeats first 'chunkSize' elements until end of array. | |
template<class T > | |
void | replace (const T &val, const T &with, T *arr, uint32_t len, uint32_t str=1) |
Replace instances of one element with another. | |
template<class T > | |
void | replace (const T *val, const T *with, uint32_t num, T *arr, uint32_t len, uint32_t str=1) |
Replace multiple instances of one element with another. | |
template<class T > | |
bool | resize (T *&arr, uint32_t sizeNow, uint32_t sizeNew) |
Resizes array. Returns true if resized, false otherwise. | |
template<class T > | |
void | reverse (T *arr, uint32_t len, uint32_t str=1) |
Reverse elements' order in array. | |
template<class T > | |
void | reverse2 (T *arr, uint32_t len, uint32_t str=1) |
Reverse every two elements. | |
template<class T > | |
void | rotateHalf (T *arr, uint32_t len, uint32_t str=1) |
Rotate elements half the length of the array. | |
template<class T > | |
void | rotateLeft1 (T *arr, uint32_t len, uint32_t str=1) |
Rotate elements left by 1. | |
template<class T > | |
void | rotateLeft (uint32_t order, T *arr, uint32_t len) |
Rotate elements left by 'order' elements. | |
template<class T > | |
void | rotateRight1 (T *arr, uint32_t len, uint32_t str=1) |
Rotate elements right by 1. | |
template<class T > | |
void | scale (T *dst, const T *src, uint32_t lenSrc, float stride) |
Copies elements from 'src' to fractionally strided locations in 'dst'. | |
template<class T > | |
void | scaleCrop (T *dst, const T *src, uint32_t len, float stride) |
Copies elements from 'src' to fractionally strided locations in 'dst'. | |
template<class T > | |
const T & | select (int n, const T &v1, const T &v2, const T &v3) |
Returns (n+1)th argument. | |
template<class T > | |
const T & | select (int n, const T &v1, const T &v2, const T &v3, const T &v4) |
Returns (n+1)th argument. | |
template<class T > | |
void | stretch (T *arr, uint32_t len, uint32_t amount) |
Stretches array by duplicating every element 'amount' times. | |
template<class T > | |
void | stretch (T *dst, const T *src, uint32_t lenSrc, uint32_t amount) |
Stretches array by duplicating every element 'amount' times. | |
template<class T > | |
void | swap (T &elem1, T &elem2) |
Swaps two elements in memory. | |
template<class T > | |
void | transpose2 (T *arr, uint32_t len) |
Transpose a 2 x (len/2) matrix. | |
template<class T > | |
bool | unique (const T *src, uint32_t len, uint32_t str=1) |
Returns true if all elements are different. | |
template<class T > | |
void | zero (T *arr, uint32_t len, uint32_t str=1) |
Sets elements to zero. | |
template<class T > | |
T | at (const T *src, uint32_t fbits, uint32_t phase) |
Get value from a power-of-two array. | |
template<class T > | |
void | put (T *dst, uint32_t fbits, uint32_t phase, T value) |
Set value in a power-of-two array. | |
void | arrayStridedDup (float *dst, const float *src, uint32_t numFrames, uint32_t stride) |
Memory functions.
These operations only involve moving data positions in memory and thus are completely object type independent, i.e. generic. Some operations require the objects to understand the = and == operators. Operations post-fixed with 'L' or 'R' are referring to the direction of the action either 'to the left' or 'to the right', respectively.
void gam::mem::arrayStridedDup | ( | float * | dst, |
const float * | src, | ||
uint32_t | numFrames, | ||
uint32_t | stride | ||
) |
Duplicates strided elements in array a_a_a_a_ -> aaaaaaaa numFrames = 4, stride = 2 b___b___ -> bbbbbbbb numFrames = 2, stride = 4
T at | ( | const T * | src, |
uint32_t | fbits, | ||
uint32_t | phase | ||
) |
Get value from a power-of-two array.
'src': waveform
'fbits': number of bits in fractional part of phase
'phase': fixed-point phase of lookup (full period is [0, 2^32))
void copyAllFromRing | ( | const T * | ring, |
uint32_t | ringSize, | ||
uint32_t | ringTap, | ||
T * | dst | ||
) |
Copies all elements from a ring buffer.
[in] | ring | pointer to source ring buffer |
[in] | ringSize | number of elements in source ring |
[in] | ringTap | ring location to start copy from, usually location of oldest element |
[in] | dst | destination array (size must at least match ring size) |
uint32_t copyToRing | ( | T * | ring, |
uint32_t | ringSize, | ||
uint32_t | ringTap, | ||
const T * | src, | ||
uint32_t | len | ||
) |
Copies elements into a ring buffer.
Returns the next tap index. This will not guaranteed to be in the range [0, ringSize) and therefore should be wrapped into the proper range.
void deinterleave | ( | T * | dst, |
const T * | src, | ||
uint32_t | numFrames, | ||
uint32_t | numChannels | ||
) |
Deinterleave an array of elements with any number of channels.
numFrames = length / numChannels
void deinterleave2 | ( | T * | dst, |
const T * | src, | ||
uint32_t | numFrames | ||
) |
Deinterleave an array of elements with 2 channels.
numFrames = length / numChannels
Example: abababab -> aaaabbbb
void expand | ( | T * | dst, |
const T * | src, | ||
uint32_t | lenSrc, | ||
uint32_t | amount | ||
) |
Expands elements from 'src' to 'dst'.
Elements are copied contiguously from 'src' to strided locations in 'dst'. 'dst' must have room for 'lenSrc' times 'amount' elements.
Ex.: 1234 -> 1.2.3.4. (amount = 2) Ex.: 1234 -> 1..2..3..4.. (amount = 3)
void free | ( | T *& | ptr | ) |
Like standard free, but checks if pointer is valid (!=0) and sets it to zero after freeing it.
This uses C-style memory management. No destructors will be called on class-type objects.
bool indexOf | ( | const T & | elem, |
uint32_t & | ind, | ||
const T * | src, | ||
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Finds index 'ind' of first element in 'src' equal to 'elem'.
Returns whether a match was found.
void interleave | ( | T * | dst, |
const T * | src, | ||
uint32_t | numFrames, | ||
uint32_t | numChannels | ||
) |
Interleave an array of elements with any number of channels.
numFrames = length / numChannels
void interleave2 | ( | T * | dst, |
const T * | src, | ||
uint32_t | numFrames | ||
) |
Interleave an array of elements with 2 channels.
numFrames = length / numChannels
Example: aaaabbbb -> abababab
void keep | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | stride, | ||
uint32_t | offset = 0 |
||
) |
Keeps every Nth element; the rest are zeroed.
[in] | arr | Array to operate on. |
[in] | len | Number of elements in array. |
[in] | stride | Spacing between kept elements. |
[in] | offset | Offset of spacing from start of array. |
void permute | ( | T * | arr, |
uint32_t | len, | ||
uint64_t | k | ||
) |
Perform kth permutation on array.
The length of the array must be <= 20.
void put | ( | T * | dst, |
uint32_t | fbits, | ||
uint32_t | phase, | ||
T | value | ||
) |
Set value in a power-of-two array.
'dst': waveform
'fbits': number of bits in fractional part of phase
'phase': fixed-point phase of lookup (full period is [0, 2^32))
void reflectLeft | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Reflect right half of array to left half.
The first len/2 elements will be overwritten.
Example: ....1234 -> 43211234
void reflectRight | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Reflect left half of array to right half.
The last len/2 elements will be overwritten.
Example: 1234.... -> 12344321
void repeat | ( | uint32_t | chunkSize, |
T * | arr, | ||
uint32_t | len | ||
) |
Repeats first 'chunkSize' elements until end of array.
Example: 1234.... -> 12341234
bool resize | ( | T *& | arr, |
uint32_t | sizeNow, | ||
uint32_t | sizeNew | ||
) |
Resizes array. Returns true if resized, false otherwise.
This uses C-style memory management. No constructors or destructors will be called on class-type objects.
void reverse | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Reverse elements' order in array.
Example: 1234 -> 4321
void reverse2 | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Reverse every two elements.
Example: 1234 -> 2143
void rotateHalf | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Rotate elements half the length of the array.
Works only for even length arrays.
void rotateLeft1 | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Rotate elements left by 1.
Example: 1234 -> 2341
void rotateRight1 | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | str = 1 |
||
) |
Rotate elements right by 1.
Example: 1234 -> 4123
void scale | ( | T * | dst, |
const T * | src, | ||
uint32_t | lenSrc, | ||
float | stride | ||
) |
Copies elements from 'src' to fractionally strided locations in 'dst'.
The destination indices are rounded up. 'dst' must have room for 'lenSrc' times 'amount' elements.
Ex.: 12345678 -> 12.34.56.78 (amount = 1.5)
Ex.: 1234 -> 1..2..3..4.. (amount = 3)
void scaleCrop | ( | T * | dst, |
const T * | src, | ||
uint32_t | len, | ||
float | stride | ||
) |
Copies elements from 'src' to fractionally strided locations in 'dst'.
The destination indices are rounded up with overrun elements being cropped, i.e. not copied.
Ex.: 12345678 -> 12.34.56 (amount = 1.5)
Ex.: 1234 -> 1..2 (amount = 3)
void stretch | ( | T * | arr, |
uint32_t | len, | ||
uint32_t | amount | ||
) |
Stretches array by duplicating every element 'amount' times.
'len' must be an integer multiple of 'amount'.
Example: 1234.... -> 11223344
void stretch | ( | T * | dst, |
const T * | src, | ||
uint32_t | lenSrc, | ||
uint32_t | amount | ||
) |
Stretches array by duplicating every element 'amount' times.
'dst' must have room for 'lenSrc' times 'amount' elements.
Example: 1234 -> 11223344
void transpose2 | ( | T * | arr, |
uint32_t | len | ||
) |
Transpose a 2 x (len/2) matrix.
Example: 12121212 -> 11112222