some code formatting in bw_{buf,common,math,note_queue,rand,voice_alloc}
This commit is contained in:
parent
6c29b1f0cd
commit
2792602e2f
310
include/bw_buf.h
310
include/bw_buf.h
@ -85,55 +85,85 @@ extern "C" {
|
||||
/*! api {{{
|
||||
* #### bw_buf_fill()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_fill(float k, float *BW_RESTRICT dest, size_t n_elems);
|
||||
static inline void bw_buf_fill(
|
||||
float k,
|
||||
float * BW_RESTRICT dest,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Sets the first `n_elems` in `dest` to `k`.
|
||||
*
|
||||
* #### bw_buf_neg()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_neg(const float *src, float *dest, size_t n_elems);
|
||||
static inline void bw_buf_neg(
|
||||
const float * src,
|
||||
float * dest,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Inverts the sign of the first `n_elems` in `src` and stores the results in
|
||||
* the first `n_elems` of `dest`.
|
||||
*
|
||||
* #### bw_buf_add()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_add(const float *src, float k, float *dest, size_t n_elems);
|
||||
static inline void bw_buf_add(
|
||||
const float * src,
|
||||
float k,
|
||||
float * dest,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Adds `k` to the first `n_elems` in `src` and stores the results in the
|
||||
* first `n_elems` of `dest`.
|
||||
*
|
||||
* #### bw_buf_scale()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_scale(const float *src, float k, float *dest, size_t n_elems);
|
||||
static inline void bw_buf_scale(
|
||||
const float * src,
|
||||
float k,
|
||||
float * dest,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Multiplies the first `n_elems` in `src` by `k` and stores the results in
|
||||
* the first `n_elems` of `dest`.
|
||||
*
|
||||
* #### bw_buf_mix()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_mix(const float *src1, const float *src2, float *dest, size_t n_elems);
|
||||
static inline void bw_buf_mix(
|
||||
const float * src1,
|
||||
const float * src2,
|
||||
float * dest,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Adds the first `n_elems` of `src1` and `src2` and stores the results in
|
||||
* the first `n_elems` of `dest`.
|
||||
*
|
||||
* #### bw_buf_mul()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_mul(const float *src1, const float *src2, float *dest, size_t n_elems);
|
||||
static inline void bw_buf_mul(
|
||||
const float * src1,
|
||||
const float * src2,
|
||||
float * dest,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Multiplies the first `n_elems` of `src1` and `src2` and stores the results
|
||||
* in the first `n_elems` of `dest`.
|
||||
*
|
||||
* #### bw_buf_fill_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_fill_multi(float k, float *BW_RESTRICT const *BW_RESTRICT dest, size_t n_channels, size_t n_elems);
|
||||
static inline void bw_buf_fill_multi(
|
||||
float k,
|
||||
float * BW_RESTRICT const * BW_RESTRICT dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Sets the first `n_elems` in each of the `n_channels` buffers `dest` to
|
||||
* `k`.
|
||||
*
|
||||
* #### bw_buf_neg_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_neg_multi(const float * const *src, float * const *dest, size_t n_channels, size_t n_elems);
|
||||
static inline void bw_buf_neg_multi(
|
||||
const float * const * src,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Inverts the sign of the first `n_elems` in each of the `n_channels`
|
||||
* buffers `src` and stores the results in the first `n_elems` in each of the
|
||||
@ -141,7 +171,12 @@ static inline void bw_buf_neg_multi(const float * const *src, float * const *des
|
||||
*
|
||||
* #### bw_buf_add_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_add_multi(const float * const *src, float k, float * const *dest, size_t n_channels, size_t n_elems);
|
||||
static inline void bw_buf_add_multi(
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Adds `k` to the first `n_elems` in each of the `n_channels` buffers `src`
|
||||
* and stores the results in the first `n_elems` in each of the `n_channels`
|
||||
@ -149,7 +184,12 @@ static inline void bw_buf_add_multi(const float * const *src, float k, float * c
|
||||
*
|
||||
* #### bw_buf_scale_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_scale_multi(const float * const *src, float k, float * const *dest, size_t n_channels, size_t n_elems);
|
||||
static inline void bw_buf_scale_multi(
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Multiplies the first `n_elems` in each of the `n_channels` buffers `src`
|
||||
* by `k` and stores the results in the first `n_elems` in each of the
|
||||
@ -157,7 +197,12 @@ static inline void bw_buf_scale_multi(const float * const *src, float k, float *
|
||||
*
|
||||
* #### bw_buf_mix_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_mix_multi(const float * const *src1, const float * const *src2, float * const *dest, size_t n_channels, size_t n_elems);
|
||||
static inline void bw_buf_mix_multi(
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Adds the first `n_elems` in each of the `n_channels` buffers `src1` and
|
||||
* `src2` and stores the results in the first `n_elems` in each of the
|
||||
@ -165,7 +210,12 @@ static inline void bw_buf_mix_multi(const float * const *src1, const float * con
|
||||
*
|
||||
* #### bw_buf_mul_multi()
|
||||
* ```>>> */
|
||||
static inline void bw_buf_mul_multi(const float * const *src1, const float * const *src2, float * const *dest, size_t n_channels, size_t n_elems);
|
||||
static inline void bw_buf_mul_multi(
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Multiplies the first `n_elems` in each of the `n_channels` buffers `src1`
|
||||
* and `src2` and stores the results in the first `n_elems` in each of the
|
||||
@ -185,7 +235,10 @@ static inline void bw_buf_mul_multi(const float * const *src1, const float * con
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline void bw_buf_fill(float k, float *BW_RESTRICT dest, size_t n_elems) {
|
||||
static inline void bw_buf_fill(
|
||||
float k,
|
||||
float * BW_RESTRICT dest,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(!bw_is_nan(k));
|
||||
BW_ASSERT(dest != NULL);
|
||||
|
||||
@ -195,7 +248,10 @@ static inline void bw_buf_fill(float k, float *BW_RESTRICT dest, size_t n_elems)
|
||||
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
|
||||
}
|
||||
|
||||
static inline void bw_buf_neg(const float *src, float *dest, size_t n_elems) {
|
||||
static inline void bw_buf_neg(
|
||||
const float * src,
|
||||
float * dest,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src != NULL);
|
||||
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
|
||||
BW_ASSERT(dest != NULL);
|
||||
@ -206,7 +262,11 @@ static inline void bw_buf_neg(const float *src, float *dest, size_t n_elems) {
|
||||
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
|
||||
}
|
||||
|
||||
static inline void bw_buf_add(const float *src, float k, float *dest, size_t n_elems) {
|
||||
static inline void bw_buf_add(
|
||||
const float * src,
|
||||
float k,
|
||||
float * dest,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src != NULL);
|
||||
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
|
||||
BW_ASSERT(!bw_is_nan(k));
|
||||
@ -218,7 +278,11 @@ static inline void bw_buf_add(const float *src, float k, float *dest, size_t n_e
|
||||
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
|
||||
}
|
||||
|
||||
static inline void bw_buf_scale(const float *src, float k, float *dest, size_t n_elems) {
|
||||
static inline void bw_buf_scale(
|
||||
const float * src,
|
||||
float k,
|
||||
float * dest,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src != NULL);
|
||||
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
|
||||
BW_ASSERT(!bw_is_nan(k));
|
||||
@ -230,7 +294,11 @@ static inline void bw_buf_scale(const float *src, float k, float *dest, size_t n
|
||||
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
|
||||
}
|
||||
|
||||
static inline void bw_buf_mix(const float *src1, const float *src2, float *dest, size_t n_elems) {
|
||||
static inline void bw_buf_mix(
|
||||
const float * src1,
|
||||
const float * src2,
|
||||
float * dest,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src1 != NULL);
|
||||
BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems));
|
||||
BW_ASSERT(src2 != NULL);
|
||||
@ -243,7 +311,11 @@ static inline void bw_buf_mix(const float *src1, const float *src2, float *dest,
|
||||
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
|
||||
}
|
||||
|
||||
static inline void bw_buf_mul(const float *src1, const float *src2, float *dest, size_t n_elems) {
|
||||
static inline void bw_buf_mul(
|
||||
const float * src1,
|
||||
const float * src2,
|
||||
float * dest,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src1 != NULL);
|
||||
BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems));
|
||||
BW_ASSERT(src2 != NULL);
|
||||
@ -256,7 +328,11 @@ static inline void bw_buf_mul(const float *src1, const float *src2, float *dest,
|
||||
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
|
||||
}
|
||||
|
||||
static inline void bw_buf_fill_multi(float k, float *BW_RESTRICT const *BW_RESTRICT dest, size_t n_channels, size_t n_elems) {
|
||||
static inline void bw_buf_fill_multi(
|
||||
float k,
|
||||
float * BW_RESTRICT const * BW_RESTRICT dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(!bw_is_nan(k));
|
||||
BW_ASSERT(dest != NULL);
|
||||
|
||||
@ -264,7 +340,11 @@ static inline void bw_buf_fill_multi(float k, float *BW_RESTRICT const *BW_RESTR
|
||||
bw_buf_fill(k, dest[i], n_elems);
|
||||
}
|
||||
|
||||
static inline void bw_buf_neg_multi(const float * const *src, float * const *dest, size_t n_channels, size_t n_elems) {
|
||||
static inline void bw_buf_neg_multi(
|
||||
const float * const * src,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src != NULL);
|
||||
BW_ASSERT(dest != NULL);
|
||||
|
||||
@ -272,7 +352,12 @@ static inline void bw_buf_neg_multi(const float * const *src, float * const *des
|
||||
bw_buf_neg(src[i], dest[i], n_elems);
|
||||
}
|
||||
|
||||
static inline void bw_buf_add_multi(const float * const *src, float k, float * const *dest, size_t n_channels, size_t n_elems) {
|
||||
static inline void bw_buf_add_multi(
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src != NULL);
|
||||
BW_ASSERT(!bw_is_nan(k));
|
||||
BW_ASSERT(dest != NULL);
|
||||
@ -281,7 +366,12 @@ static inline void bw_buf_add_multi(const float * const *src, float k, float * c
|
||||
bw_buf_add(src[i], k, dest[i], n_elems);
|
||||
}
|
||||
|
||||
static inline void bw_buf_scale_multi(const float * const *src, float k, float * const *dest, size_t n_channels, size_t n_elems) {
|
||||
static inline void bw_buf_scale_multi(
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src != NULL);
|
||||
BW_ASSERT(!bw_is_nan(k));
|
||||
BW_ASSERT(dest != NULL);
|
||||
@ -290,7 +380,12 @@ static inline void bw_buf_scale_multi(const float * const *src, float k, float *
|
||||
bw_buf_scale(src[i], k, dest[i], n_elems);
|
||||
}
|
||||
|
||||
static inline void bw_buf_mix_multi(const float * const *src1, const float * const *src2, float * const *dest, size_t n_channels, size_t n_elems) {
|
||||
static inline void bw_buf_mix_multi(
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src1 != NULL);
|
||||
BW_ASSERT(src2 != NULL);
|
||||
BW_ASSERT(dest != NULL);
|
||||
@ -299,7 +394,12 @@ static inline void bw_buf_mix_multi(const float * const *src1, const float * con
|
||||
bw_buf_mix(src1[i], src2[i], dest[i], n_elems);
|
||||
}
|
||||
|
||||
static inline void bw_buf_mul_multi(const float * const *src1, const float * const *src2, float * const *dest, size_t n_channels, size_t n_elems) {
|
||||
static inline void bw_buf_mul_multi(
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t n_channels,
|
||||
size_t n_elems) {
|
||||
BW_ASSERT(src1 != NULL);
|
||||
BW_ASSERT(src2 != NULL);
|
||||
BW_ASSERT(dest != NULL);
|
||||
@ -322,98 +422,98 @@ namespace Brickworks {
|
||||
* ```>>> */
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufFill(
|
||||
float k,
|
||||
float *BW_RESTRICT const *BW_RESTRICT dest,
|
||||
size_t nSamples);
|
||||
float k,
|
||||
float * BW_RESTRICT const * BW_RESTRICT dest,
|
||||
size_t nSamples);
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufFill(
|
||||
float k,
|
||||
std::array<float *BW_RESTRICT, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
float k,
|
||||
std::array<float * BW_RESTRICT, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
/*! <<<```
|
||||
*
|
||||
* ##### Brickworks::bufNeg
|
||||
* ```>>> */
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufNeg(
|
||||
const float * const *src,
|
||||
float * const *dest,
|
||||
size_t nSamples);
|
||||
const float * const * src,
|
||||
float * const * dest,
|
||||
size_t nSamples);
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufNeg(
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
/*! <<<```
|
||||
*
|
||||
* ##### Brickworks::bufAdd
|
||||
* ```>>> */
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufAdd(
|
||||
const float * const *src,
|
||||
float k,
|
||||
float * const *dest,
|
||||
size_t nSamples);
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t nSamples);
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufAdd(
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
/*! <<<```
|
||||
*
|
||||
* ##### Brickworks::bufScale
|
||||
* ```>>> */
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufScale(
|
||||
const float * const *src,
|
||||
float k,
|
||||
float * const *dest,
|
||||
size_t nSamples);
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t nSamples);
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufScale(
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
/*! <<<```
|
||||
*
|
||||
* ##### Brickworks::bufMix
|
||||
* ```>>> */
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufMix(
|
||||
const float * const *src1,
|
||||
const float * const *src2,
|
||||
float * const *dest,
|
||||
size_t nSamples);
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t nSamples);
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufMix(
|
||||
const std::array<const float *, N_CHANNELS> src1,
|
||||
const std::array<const float *, N_CHANNELS> src2,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
const std::array<const float *, N_CHANNELS> src1,
|
||||
const std::array<const float *, N_CHANNELS> src2,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
/*! <<<```
|
||||
*
|
||||
* ##### Brickworks::bufMul
|
||||
* ```>>> */
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufMul(
|
||||
const float * const *src1,
|
||||
const float * const *src2,
|
||||
float * const *dest,
|
||||
size_t nSamples);
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t nSamples);
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufMul(
|
||||
const std::array<const float *, N_CHANNELS> src1,
|
||||
const std::array<const float *, N_CHANNELS> src2,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
const std::array<const float *, N_CHANNELS> src1,
|
||||
const std::array<const float *, N_CHANNELS> src2,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples);
|
||||
/*! <<<```
|
||||
* }}} */
|
||||
|
||||
@ -424,78 +524,78 @@ inline void bufMul(
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufFill(
|
||||
float k,
|
||||
float *BW_RESTRICT const *BW_RESTRICT dest,
|
||||
size_t nSamples) {
|
||||
float k,
|
||||
float * BW_RESTRICT const * BW_RESTRICT dest,
|
||||
size_t nSamples) {
|
||||
bw_buf_fill_multi(k, dest, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufFill(
|
||||
float k,
|
||||
const std::array<float *BW_RESTRICT, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
float k,
|
||||
const std::array<float * BW_RESTRICT, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
bufFill<N_CHANNELS>(k, dest.data(), nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufNeg(
|
||||
const float * const *src,
|
||||
float * const *dest,
|
||||
size_t nSamples) {
|
||||
const float * const * src,
|
||||
float * const * dest,
|
||||
size_t nSamples) {
|
||||
bw_buf_neg_multi(src, dest, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufNeg(
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
bufNeg<N_CHANNELS>(src.data(), dest.data(), nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufAdd(
|
||||
const float * const *src,
|
||||
float k,
|
||||
float * const *dest,
|
||||
size_t nSamples) {
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t nSamples) {
|
||||
bw_buf_add_multi(src, k, dest, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufAdd(
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
bufAdd<N_CHANNELS>(src.data(), k, dest.data(), nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufScale(
|
||||
const float * const *src,
|
||||
float k,
|
||||
float * const *dest,
|
||||
size_t nSamples) {
|
||||
const float * const * src,
|
||||
float k,
|
||||
float * const * dest,
|
||||
size_t nSamples) {
|
||||
bw_buf_scale_multi(src, k, dest, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufScale(
|
||||
const std::array<const float *, N_CHANNELS> src,
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
float k,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
bufScale<N_CHANNELS>(src.data(), k, dest.data(), nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufMix(
|
||||
const float * const *src1,
|
||||
const float * const *src2,
|
||||
float * const *dest,
|
||||
size_t nSamples) {
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t nSamples) {
|
||||
bw_buf_mix_multi(src1, src2, dest, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
@ -503,17 +603,17 @@ template<size_t N_CHANNELS>
|
||||
inline void bufMix(
|
||||
const std::array<const float *, N_CHANNELS> src1,
|
||||
const std::array<const float *, N_CHANNELS> src2,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
bufMix<N_CHANNELS>(src1.data(), src2.data(), dest.data(), nSamples);
|
||||
}
|
||||
|
||||
template<size_t N_CHANNELS>
|
||||
inline void bufMul(
|
||||
const float * const *src1,
|
||||
const float * const *src2,
|
||||
float * const *dest,
|
||||
size_t nSamples) {
|
||||
const float * const * src1,
|
||||
const float * const * src2,
|
||||
float * const * dest,
|
||||
size_t nSamples) {
|
||||
bw_buf_mul_multi(src1, src2, dest, N_CHANNELS, nSamples);
|
||||
}
|
||||
|
||||
@ -521,8 +621,8 @@ template<size_t N_CHANNELS>
|
||||
inline void bufMul(
|
||||
const std::array<const float *, N_CHANNELS> src1,
|
||||
const std::array<const float *, N_CHANNELS> src2,
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
const std::array<float *, N_CHANNELS> dest,
|
||||
size_t nSamples) {
|
||||
bufMul<N_CHANNELS>(src1.data(), src2.data(), dest.data(), nSamples);
|
||||
}
|
||||
|
||||
|
@ -170,8 +170,8 @@
|
||||
*
|
||||
* Otherwise, `BW_ASSERT` and `BW_ASSERT_DEEP` can either be provided by you,
|
||||
* otherwise `BW_ASSERT` is defined as `assert` (`assert.h` is `#include`d
|
||||
* and `BW_NO_STDLIB` must not be defined -- please mid that `assert.h` is
|
||||
* still influenced by `NDEBUG`), and `BW_ASSERT_DEEP` is defined as
|
||||
* and `BW_NO_STDLIB` must not be defined — please mid that `assert.h`
|
||||
* is still influenced by `NDEBUG`), and `BW_ASSERT_DEEP` is defined as
|
||||
* `BW_ASSERT`.
|
||||
*
|
||||
* >>> */
|
||||
@ -208,40 +208,49 @@ extern "C" {
|
||||
*
|
||||
* #### bw_is_inf()
|
||||
* ```>>> */
|
||||
static inline char bw_is_inf(float x);
|
||||
static inline char bw_is_inf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns non-`0` if `x` is positive or negative infinity, `0` otherwise.
|
||||
*
|
||||
* #### bw_is_nan()
|
||||
* ```>>> */
|
||||
static inline char bw_is_nan(float x);
|
||||
static inline char bw_is_nan(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns non-`0` if `x` is NaN, `0` otherwise.
|
||||
*
|
||||
* #### bw_is_finite()
|
||||
* ```>>> */
|
||||
static inline char bw_is_finite(float x);
|
||||
static inline char bw_is_finite(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns non-`0` if `x` is finite (neither NaN nor positive or negative
|
||||
* infinity), `0` otherwise.
|
||||
*
|
||||
* #### bw_has_inf()
|
||||
* ```>>> */
|
||||
static inline char bw_has_inf(const float *BW_RESTRICT x, size_t n_elems);
|
||||
static inline char bw_has_inf(
|
||||
const float * BW_RESTRICT x,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Scans the fist `n_elems` in buffer `x` and returns non-`0` if it contains
|
||||
* at least one positive or negative inifinity value, `0` otherwise.
|
||||
*
|
||||
* #### bw_has_nan()
|
||||
* ```>>> */
|
||||
static inline char bw_has_nan(const float *BW_RESTRICT x, size_t n_elems);
|
||||
static inline char bw_has_nan(
|
||||
const float * BW_RESTRICT x,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Scans the fist `n_elems` in buffer `x` and returns non-`0` if it contains
|
||||
* at least one NaN value, `0` otherwise.
|
||||
*
|
||||
* #### bw_has_only_finite()
|
||||
* ```>>> */
|
||||
static inline char bw_has_only_finite(const float *BW_RESTRICT x, size_t n_elems);
|
||||
static inline char bw_has_only_finite(
|
||||
const float * BW_RESTRICT x,
|
||||
size_t n_elems);
|
||||
/*! <<<```
|
||||
* Scans the fist `n_elems` in buffer `x` and returns non-`0` if it only
|
||||
* finds finite values (neither NaN nor positive or negative infinity), `0`
|
||||
@ -249,7 +258,8 @@ static inline char bw_has_only_finite(const float *BW_RESTRICT x, size_t n_elems
|
||||
*
|
||||
* #### bw_hash_sdbm()
|
||||
* ```>>> */
|
||||
static inline uint32_t bw_hash_sdbm(const char *BW_RESTRICT string);
|
||||
static inline uint32_t bw_hash_sdbm(
|
||||
const char * BW_RESTRICT string);
|
||||
/*! <<<```
|
||||
* Returns the sdbm hash of the given `string`.
|
||||
* }}} */
|
||||
@ -267,46 +277,56 @@ static inline uint32_t bw_hash_sdbm(const char *BW_RESTRICT string);
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline char bw_is_inf(float x) {
|
||||
static inline char bw_is_inf(
|
||||
float x) {
|
||||
union { uint32_t u; float f; } v;
|
||||
v.f = x;
|
||||
return (v.u & 0x7fffffff) == 0x7f800000;
|
||||
}
|
||||
|
||||
static inline char bw_is_nan(float x) {
|
||||
static inline char bw_is_nan(
|
||||
float x) {
|
||||
union { uint32_t u; float f; } v;
|
||||
v.f = x;
|
||||
return ((v.u & 0x7f800000) == 0x7f800000) && (v.u & 0x7fffff);
|
||||
}
|
||||
|
||||
static inline char bw_is_finite(float x) {
|
||||
static inline char bw_is_finite(
|
||||
float x) {
|
||||
union { uint32_t u; float f; } v;
|
||||
v.f = x;
|
||||
return (v.u & 0x7f800000) != 0x7f800000;
|
||||
}
|
||||
|
||||
static inline char bw_has_inf(const float *BW_RESTRICT x, size_t n_elems) {
|
||||
static inline char bw_has_inf(
|
||||
const float * BW_RESTRICT x,
|
||||
size_t n_elems) {
|
||||
char ret = 0;
|
||||
for (size_t i = 0; i < n_elems && !ret; i++)
|
||||
ret = bw_is_inf(x[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline char bw_has_nan(const float *BW_RESTRICT x, size_t n_elems) {
|
||||
static inline char bw_has_nan(
|
||||
const float * BW_RESTRICT x,
|
||||
size_t n_elems) {
|
||||
char ret = 0;
|
||||
for (size_t i = 0; i < n_elems && !ret; i++)
|
||||
ret = bw_is_nan(x[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline char bw_has_only_finite(const float *BW_RESTRICT x, size_t n_elems) {
|
||||
static inline char bw_has_only_finite(
|
||||
const float * BW_RESTRICT x,
|
||||
size_t n_elems) {
|
||||
char ret = 1;
|
||||
for (size_t i = 0; i < n_elems && ret; i++)
|
||||
ret = bw_is_finite(x[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint32_t bw_hash_sdbm(const char *BW_RESTRICT string) {
|
||||
static inline uint32_t bw_hash_sdbm(
|
||||
const char * BW_RESTRICT string) {
|
||||
uint32_t hash = 0;
|
||||
for (; *string != '\0'; string++)
|
||||
hash = *string + (hash << 6) + (hash << 16) - hash;
|
||||
|
@ -125,93 +125,121 @@ extern "C" {
|
||||
/*! api {{{
|
||||
* #### bw_signfilli32()
|
||||
* ```>>> */
|
||||
static inline int32_t bw_signfilli32(int32_t x);
|
||||
static inline int32_t bw_signfilli32(
|
||||
int32_t x);
|
||||
/*! <<<```
|
||||
* Returns `~0` if `x` is negative, `0` otherwise.
|
||||
*
|
||||
* #### bw_mini32()
|
||||
* ```>>> */
|
||||
static inline int32_t bw_mini32(int32_t a, int32_t b);
|
||||
static inline int32_t bw_mini32(
|
||||
int32_t a,
|
||||
int32_t b);
|
||||
/*! <<<```
|
||||
* Returns the minimum of `a` and `b`.
|
||||
*
|
||||
* #### bw_maxi32()
|
||||
* ```>>> */
|
||||
static inline int32_t bw_maxi32(int32_t a, int32_t b);
|
||||
static inline int32_t bw_maxi32(
|
||||
int32_t a,
|
||||
int32_t b);
|
||||
/*! <<<```
|
||||
* Returns the maximum of `a` and `b`.
|
||||
*
|
||||
* #### bw_clipi32()
|
||||
* ```>>> */
|
||||
static inline int32_t bw_clipi32(int32_t x, int32_t m, int32_t M);
|
||||
static inline int32_t bw_clipi32(
|
||||
int32_t x,
|
||||
int32_t m,
|
||||
int32_t M);
|
||||
/*! <<<```
|
||||
* Returns `x` unless it is smaller than `m`, in which case it returns `m`,
|
||||
* or bigger than `M`, in which case it returns `M`.
|
||||
*
|
||||
* #### bw_minu32()
|
||||
* ```>>> */
|
||||
static inline uint32_t bw_minu32(uint32_t a, uint32_t b);
|
||||
static inline uint32_t bw_minu32(
|
||||
uint32_t a,
|
||||
uint32_t b);
|
||||
/*! <<<```
|
||||
* Returns the minimum of `a` and `b`.
|
||||
*
|
||||
* #### bw_maxu32()
|
||||
* ```>>> */
|
||||
static inline uint32_t bw_maxu32(uint32_t a, uint32_t b);
|
||||
static inline uint32_t bw_maxu32(
|
||||
uint32_t a,
|
||||
uint32_t b);
|
||||
/*! <<<```
|
||||
* Returns the maximum of `a` and `b`.
|
||||
*
|
||||
* #### bw_clipu32()
|
||||
* ```>>> */
|
||||
static inline uint32_t bw_clipu32(uint32_t x, uint32_t m, uint32_t M);
|
||||
static inline uint32_t bw_clipu32(
|
||||
uint32_t x,
|
||||
uint32_t m,
|
||||
uint32_t M);
|
||||
/*! <<<```
|
||||
* Returns `x` unless it is smaller than `m`, in which case it returns `m`,
|
||||
* or bigger than `M`, in which case it returns `M`.
|
||||
*
|
||||
* #### bw_copysignf()
|
||||
* ```>>> */
|
||||
static inline float bw_copysignf(float x, float y);
|
||||
static inline float bw_copysignf(
|
||||
float x,
|
||||
float y);
|
||||
/*! <<<```
|
||||
* Returns a value that has the absolute value of `x` and the sign of `y`.
|
||||
*
|
||||
* #### bw_signf()
|
||||
* ```>>> */
|
||||
static inline float bw_signf(float x);
|
||||
static inline float bw_signf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns `1.f` if `x > 0.f`, `-1.f` if `x < 0.f` and `0.f` if `x == 0.f`.
|
||||
*
|
||||
* #### bw_absf()
|
||||
* ```>>> */
|
||||
static inline float bw_absf(float x);
|
||||
static inline float bw_absf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns the absolute value of `x`.
|
||||
*
|
||||
* #### bw_min0f()
|
||||
* ```>>> */
|
||||
static inline float bw_min0f(float x);
|
||||
static inline float bw_min0f(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns the minimum of `0.f` and `x`.
|
||||
*
|
||||
* #### bw_max0f()
|
||||
* ```>>> */
|
||||
static inline float bw_max0f(float x);
|
||||
static inline float bw_max0f(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns the maximum of `0.f` and `x`.
|
||||
*
|
||||
* #### bw_minf()
|
||||
* ```>>> */
|
||||
static inline float bw_minf(float a, float b);
|
||||
static inline float bw_minf(
|
||||
float a,
|
||||
float b);
|
||||
/*! <<<```
|
||||
* Returns the minimum of `a` and `b`.
|
||||
*
|
||||
* #### bw_maxf()
|
||||
* ```>>> */
|
||||
static inline float bw_maxf(float a, float b);
|
||||
static inline float bw_maxf(
|
||||
float a,
|
||||
float b);
|
||||
/*! <<<```
|
||||
* Returns the maximum of `a` and `b`.
|
||||
*
|
||||
* #### bw_clipf()
|
||||
* ```>>> */
|
||||
static inline float bw_clipf(float x, float m, float M);
|
||||
static inline float bw_clipf(
|
||||
float x,
|
||||
float m,
|
||||
float M);
|
||||
/*! <<<```
|
||||
* Returns `x` unless it is smaller than `m`, in which case it returns `m`,
|
||||
* or bigger than `M`, in which case it returns `M`.
|
||||
@ -220,7 +248,8 @@ static inline float bw_clipf(float x, float m, float M);
|
||||
*
|
||||
* #### bw_truncf()
|
||||
* ```>>> */
|
||||
static inline float bw_truncf(float x);
|
||||
static inline float bw_truncf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns `x` with its fractional part set to zero (i.e., rounded towards
|
||||
* zero).
|
||||
@ -229,7 +258,8 @@ static inline float bw_truncf(float x);
|
||||
*
|
||||
* #### bw_roundf()
|
||||
* ```>>> */
|
||||
static inline float bw_roundf(float x);
|
||||
static inline float bw_roundf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns `x` rounded to the nearest integer.
|
||||
*
|
||||
@ -240,7 +270,8 @@ static inline float bw_roundf(float x);
|
||||
*
|
||||
* #### bw_floorf()
|
||||
* ```>>> */
|
||||
static inline float bw_floorf(float x);
|
||||
static inline float bw_floorf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns the biggest integer less or equal than `x` (i.e., `x` is rounded
|
||||
* down).
|
||||
@ -249,7 +280,8 @@ static inline float bw_floorf(float x);
|
||||
*
|
||||
* #### bw_ceilf()
|
||||
* ```>>> */
|
||||
static inline float bw_ceilf(float x);
|
||||
static inline float bw_ceilf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns the smallest integer greater or equal than `x` (i.e., `x` is
|
||||
* rounded up).
|
||||
@ -258,7 +290,10 @@ static inline float bw_ceilf(float x);
|
||||
*
|
||||
* #### bw_intfracf()
|
||||
* ```>>> */
|
||||
static inline void bw_intfracf(float x, float *BW_RESTRICT i, float *BW_RESTRICT f);
|
||||
static inline void bw_intfracf(
|
||||
float x,
|
||||
float * BW_RESTRICT i,
|
||||
float * BW_RESTRICT f);
|
||||
/*! <<<```
|
||||
* Puts the integer part (floor) of `x` in `i` and the fractional part in
|
||||
* `f`.
|
||||
@ -267,7 +302,8 @@ static inline void bw_intfracf(float x, float *BW_RESTRICT i, float *BW_RESTRICT
|
||||
*
|
||||
* #### bw_rcpf()
|
||||
* ```>>> */
|
||||
static inline float bw_rcpf(float x);
|
||||
static inline float bw_rcpf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns the reciprocal of `x` (i.e., `1.f / x`).
|
||||
*
|
||||
@ -277,7 +313,8 @@ static inline float bw_rcpf(float x);
|
||||
*
|
||||
* #### bw_sin2pif()
|
||||
* ```>>> */
|
||||
static inline float bw_sin2pif(float x);
|
||||
static inline float bw_sin2pif(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the sine of 2 * pi * `x`, where `x` is given
|
||||
* in radians.
|
||||
@ -288,7 +325,8 @@ static inline float bw_sin2pif(float x);
|
||||
*
|
||||
* #### bw_sinf()
|
||||
* ```>>> */
|
||||
static inline float bw_sinf(float x);
|
||||
static inline float bw_sinf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the sine of `x`, where `x` is given in
|
||||
* radians.
|
||||
@ -299,7 +337,8 @@ static inline float bw_sinf(float x);
|
||||
*
|
||||
* #### bw_cos2pif()
|
||||
* ```>>> */
|
||||
static inline float bw_cos2pif(float x);
|
||||
static inline float bw_cos2pif(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the cosine of 2 * pi * `x`, where `x` is given
|
||||
* in radians.
|
||||
@ -310,7 +349,8 @@ static inline float bw_cos2pif(float x);
|
||||
*
|
||||
* #### bw_cosf()
|
||||
* ```>>> */
|
||||
static inline float bw_cosf(float x);
|
||||
static inline float bw_cosf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the cosine of `x`, where `x` is given in
|
||||
* radians.
|
||||
@ -321,7 +361,8 @@ static inline float bw_cosf(float x);
|
||||
*
|
||||
* #### bw_tan2pif()
|
||||
* ```>>> */
|
||||
static inline float bw_tan2pif(float x);
|
||||
static inline float bw_tan2pif(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the tangent of 2 * pi * `x`, where `x` is
|
||||
* given in radians.
|
||||
@ -333,7 +374,8 @@ static inline float bw_tan2pif(float x);
|
||||
*
|
||||
* #### bw_tanf()
|
||||
* ```>>> */
|
||||
static inline float bw_tanf(float x);
|
||||
static inline float bw_tanf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the tangent of `x`, where `x` is given in
|
||||
* radians.
|
||||
@ -345,7 +387,8 @@ static inline float bw_tanf(float x);
|
||||
*
|
||||
* #### bw_log2f()
|
||||
* ```>>> */
|
||||
static inline float bw_log2f(float x);
|
||||
static inline float bw_log2f(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the base-2 logarithm of `x`.
|
||||
*
|
||||
@ -355,7 +398,8 @@ static inline float bw_log2f(float x);
|
||||
*
|
||||
* #### bw_logf()
|
||||
* ```>>> */
|
||||
static inline float bw_logf(float x);
|
||||
static inline float bw_logf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the natural logarithm of `x`.
|
||||
*
|
||||
@ -365,7 +409,8 @@ static inline float bw_logf(float x);
|
||||
*
|
||||
* #### bw_log10f()
|
||||
* ```>>> */
|
||||
static inline float bw_log10f(float x);
|
||||
static inline float bw_log10f(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the base-10 logarithm of `x`.
|
||||
*
|
||||
@ -375,7 +420,8 @@ static inline float bw_log10f(float x);
|
||||
*
|
||||
* #### bw_pow2f()
|
||||
* ```>>> */
|
||||
static inline float bw_pow2f(float x);
|
||||
static inline float bw_pow2f(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of 2 raised to the power of `x`. For `x < -126.f`
|
||||
* it just returns `0.f`.
|
||||
@ -386,7 +432,8 @@ static inline float bw_pow2f(float x);
|
||||
*
|
||||
* #### bw_expf()
|
||||
* ```>>> */
|
||||
static inline float bw_expf(float x);
|
||||
static inline float bw_expf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of e (Euler's number) raised to the power of `x`.
|
||||
* For `x < -87.3365447505531f` it just returns `0`.
|
||||
@ -397,7 +444,8 @@ static inline float bw_expf(float x);
|
||||
*
|
||||
* #### bw_pow10f()
|
||||
* ```>>> */
|
||||
static inline float bw_pow10f(float x);
|
||||
static inline float bw_pow10f(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of 10 raised to the power of `x`. For
|
||||
* `x < -37.92977945366162f` it just returns `0`.
|
||||
@ -408,7 +456,8 @@ static inline float bw_pow10f(float x);
|
||||
*
|
||||
* #### bw_dB2linf()
|
||||
* ```>>> */
|
||||
static inline float bw_dB2linf(float x);
|
||||
static inline float bw_dB2linf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of 10 raised to the power of `x` / 20 (dB to
|
||||
* linear ratio conversion). For `x < -758.5955890732315f` it just returns
|
||||
@ -420,7 +469,8 @@ static inline float bw_dB2linf(float x);
|
||||
*
|
||||
* #### bw_lin2dBf()
|
||||
* ```>>> */
|
||||
static inline float bw_lin2dBf(float x);
|
||||
static inline float bw_lin2dBf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of 20 times the base-10 logarithm of `x` (linear
|
||||
* ratio to dB conversion).
|
||||
@ -431,7 +481,8 @@ static inline float bw_lin2dBf(float x);
|
||||
*
|
||||
* #### bw_sqrtf()
|
||||
* ```>>> */
|
||||
static inline float bw_sqrtf(float x);
|
||||
static inline float bw_sqrtf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the square root of `x`.
|
||||
*
|
||||
@ -441,7 +492,8 @@ static inline float bw_sqrtf(float x);
|
||||
*
|
||||
* #### bw_tanhf()
|
||||
* ```>>> */
|
||||
static inline float bw_tanhf(float x);
|
||||
static inline float bw_tanhf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the hyperbolic tangent of `x`.
|
||||
*
|
||||
@ -449,7 +501,8 @@ static inline float bw_tanhf(float x);
|
||||
*
|
||||
* #### bw_sinhf()
|
||||
* ```>>> */
|
||||
static inline float bw_sinhf(float x);
|
||||
static inline float bw_sinhf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the hyperbolic sine of `x`.
|
||||
*
|
||||
@ -459,7 +512,8 @@ static inline float bw_sinhf(float x);
|
||||
*
|
||||
* #### bw_coshf()
|
||||
* ```>>> */
|
||||
static inline float bw_coshf(float x);
|
||||
static inline float bw_coshf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the hyperbolic cosine of `x`.
|
||||
*
|
||||
@ -469,7 +523,8 @@ static inline float bw_coshf(float x);
|
||||
*
|
||||
* #### bw_asinhf()
|
||||
* ```>>> */
|
||||
static inline float bw_asinhf(float x);
|
||||
static inline float bw_asinhf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the hyperbolic arcsine of `x`.
|
||||
*
|
||||
@ -479,7 +534,8 @@ static inline float bw_asinhf(float x);
|
||||
*
|
||||
* #### bw_acoshf()
|
||||
* ```>>> */
|
||||
static inline float bw_acoshf(float x);
|
||||
static inline float bw_acoshf(
|
||||
float x);
|
||||
/*! <<<```
|
||||
* Returns an approximation of the hyperbolic arccosine of `x`.
|
||||
*
|
||||
@ -503,38 +559,55 @@ extern "C" {
|
||||
|
||||
// I hope the target architecture and compiler will use conditional ops here
|
||||
|
||||
static inline int32_t bw_signfilli32(int32_t x) {
|
||||
static inline int32_t bw_signfilli32(
|
||||
int32_t x) {
|
||||
return x < 0 ? ~0 : 0;
|
||||
}
|
||||
|
||||
static inline int32_t bw_mini32(int32_t a, int32_t b) {
|
||||
static inline int32_t bw_mini32(
|
||||
int32_t a,
|
||||
int32_t b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
static inline int32_t bw_maxi32(int32_t a, int32_t b) {
|
||||
static inline int32_t bw_maxi32(
|
||||
int32_t a,
|
||||
int32_t b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
static inline int32_t bw_clipi32(int32_t x, int32_t m, int32_t M) {
|
||||
static inline int32_t bw_clipi32(
|
||||
int32_t x,
|
||||
int32_t m,
|
||||
int32_t M) {
|
||||
return x < m ? m : (x > M ? M : x);
|
||||
}
|
||||
|
||||
static inline uint32_t bw_minu32(uint32_t a, uint32_t b) {
|
||||
static inline uint32_t bw_minu32(
|
||||
uint32_t a,
|
||||
uint32_t b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
static inline uint32_t bw_maxu32(uint32_t a, uint32_t b) {
|
||||
static inline uint32_t bw_maxu32(
|
||||
uint32_t a,
|
||||
uint32_t b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
static inline uint32_t bw_clipu32(uint32_t x, uint32_t m, uint32_t M) {
|
||||
static inline uint32_t bw_clipu32(
|
||||
uint32_t x,
|
||||
uint32_t m,
|
||||
uint32_t M) {
|
||||
return x < m ? m : (x > M ? M : x);
|
||||
}
|
||||
|
||||
// Here instead I don't trust C semantics to get close to conditional ops for
|
||||
// floating point numbers
|
||||
|
||||
static inline float bw_copysignf(float x, float y) {
|
||||
static inline float bw_copysignf(
|
||||
float x,
|
||||
float y) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
BW_ASSERT(!bw_is_nan(y));
|
||||
union { float f; uint32_t u; } v, s;
|
||||
@ -545,7 +618,8 @@ static inline float bw_copysignf(float x, float y) {
|
||||
return v.f;
|
||||
}
|
||||
|
||||
static inline float bw_signf(float x) {
|
||||
static inline float bw_signf(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
static const float y[4] = { 0.f, 1.f, 0.f, -1.f };
|
||||
union { float f; uint32_t u; } v;
|
||||
@ -555,7 +629,8 @@ static inline float bw_signf(float x) {
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline float bw_absf(float x) {
|
||||
static inline float bw_absf(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
union { float f; uint32_t u; } v;
|
||||
v.f = x;
|
||||
@ -564,7 +639,8 @@ static inline float bw_absf(float x) {
|
||||
return v.f;
|
||||
}
|
||||
|
||||
static inline float bw_min0f(float x) {
|
||||
static inline float bw_min0f(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
union { float f; int32_t i; } v;
|
||||
v.f = x;
|
||||
@ -573,7 +649,8 @@ static inline float bw_min0f(float x) {
|
||||
return v.f;
|
||||
}
|
||||
|
||||
static inline float bw_max0f(float x) {
|
||||
static inline float bw_max0f(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
union { float f; int32_t i; } v;
|
||||
v.f = x;
|
||||
@ -582,7 +659,9 @@ static inline float bw_max0f(float x) {
|
||||
return v.f;
|
||||
}
|
||||
|
||||
static inline float bw_minf(float a, float b) {
|
||||
static inline float bw_minf(
|
||||
float a,
|
||||
float b) {
|
||||
BW_ASSERT(!bw_is_nan(a));
|
||||
BW_ASSERT(!bw_is_nan(b));
|
||||
const float y = a < b ? a : b;
|
||||
@ -590,7 +669,9 @@ static inline float bw_minf(float a, float b) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_maxf(float a, float b) {
|
||||
static inline float bw_maxf(
|
||||
float a,
|
||||
float b) {
|
||||
BW_ASSERT(!bw_is_nan(a));
|
||||
BW_ASSERT(!bw_is_nan(b));
|
||||
const float y = a > b ? a : b;
|
||||
@ -598,7 +679,10 @@ static inline float bw_maxf(float a, float b) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_clipf(float x, float m, float M) {
|
||||
static inline float bw_clipf(
|
||||
float x,
|
||||
float m,
|
||||
float M) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
BW_ASSERT(!bw_is_nan(m));
|
||||
BW_ASSERT(!bw_is_nan(M));
|
||||
@ -608,7 +692,8 @@ static inline float bw_clipf(float x, float m, float M) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_truncf(float x) {
|
||||
static inline float bw_truncf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
union { float f; uint32_t u; } v;
|
||||
v.f = x;
|
||||
@ -620,7 +705,8 @@ static inline float bw_truncf(float x) {
|
||||
return v.f;
|
||||
}
|
||||
|
||||
static inline float bw_roundf(float x) {
|
||||
static inline float bw_roundf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
union { float f; uint32_t u; } v, s;
|
||||
v.f = x;
|
||||
@ -639,7 +725,8 @@ static inline float bw_roundf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_floorf(float x) {
|
||||
static inline float bw_floorf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
union { float f; int32_t i; } t, y, s;
|
||||
t.f = bw_truncf(x); // first bit set when t < 0
|
||||
@ -651,7 +738,8 @@ static inline float bw_floorf(float x) {
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline float bw_ceilf(float x) {
|
||||
static inline float bw_ceilf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
union { float f; int32_t i; } t, y, s;
|
||||
t.f = bw_truncf(x); // first bit set when t < 0
|
||||
@ -663,7 +751,10 @@ static inline float bw_ceilf(float x) {
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline void bw_intfracf(float x, float *BW_RESTRICT i, float *BW_RESTRICT f) {
|
||||
static inline void bw_intfracf(
|
||||
float x,
|
||||
float * BW_RESTRICT i,
|
||||
float * BW_RESTRICT f) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(i != NULL);
|
||||
BW_ASSERT(f != NULL);
|
||||
@ -674,7 +765,8 @@ static inline void bw_intfracf(float x, float *BW_RESTRICT i, float *BW_RESTRICT
|
||||
BW_ASSERT(bw_is_finite(*f));
|
||||
}
|
||||
|
||||
static inline float bw_rcpf(float x) {
|
||||
static inline float bw_rcpf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT((x >= 8.077935669e-28f && x <= 1.237940039e27f) || (x <= -8.077935669e-28f && x >= -1.237940039e27f));
|
||||
union { float f; int32_t i; } v;
|
||||
@ -686,7 +778,8 @@ static inline float bw_rcpf(float x) {
|
||||
return v.f;
|
||||
}
|
||||
|
||||
static inline float bw_sin2pif(float x) {
|
||||
static inline float bw_sin2pif(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
x = x - bw_floorf(x);
|
||||
float xp1 = x + x - 1.f;
|
||||
@ -697,28 +790,32 @@ static inline float bw_sin2pif(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_sinf(float x) {
|
||||
static inline float bw_sinf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
const float y = bw_sin2pif(0.1591549430918953f * x);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_cos2pif(float x) {
|
||||
static inline float bw_cos2pif(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
const float y = bw_sin2pif(x + 0.25f);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_cosf(float x) {
|
||||
static inline float bw_cosf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
const float y = bw_cos2pif(0.1591549430918953f * x);
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_tan2pif(float x) {
|
||||
static inline float bw_tan2pif(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT((x - 0.5f * bw_floorf(x + x) <= 0.249840845056908f)
|
||||
|| (x - 0.5f * bw_floorf(x + x) >= 0.250159154943092f));
|
||||
@ -727,7 +824,8 @@ static inline float bw_tan2pif(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_tanf(float x) {
|
||||
static inline float bw_tanf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT((x - 3.141592653589793f * bw_floorf(0.318309886183791f * x) <= 1.569796326794897f)
|
||||
|| (x - 3.141592653589793f * bw_floorf(0.318309886183791f * x) >= 1.571796326794896f));
|
||||
@ -737,7 +835,8 @@ static inline float bw_tanf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_log2f(float x) {
|
||||
static inline float bw_log2f(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= 1.175494350822287e-38f);
|
||||
union { float f; int32_t i; } v;
|
||||
@ -749,7 +848,8 @@ static inline float bw_log2f(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_logf(float x) {
|
||||
static inline float bw_logf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= 1.175494350822287e-38f);
|
||||
const float y = 0.693147180559945f * bw_log2f(x);
|
||||
@ -757,7 +857,8 @@ static inline float bw_logf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_log10f(float x) {
|
||||
static inline float bw_log10f(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= 1.175494350822287e-38f);
|
||||
const float y = 0.3010299956639811f * bw_log2f(x);
|
||||
@ -765,7 +866,8 @@ static inline float bw_log10f(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_pow2f(float x) {
|
||||
static inline float bw_pow2f(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
BW_ASSERT(x <= 127.999f);
|
||||
if (x < -126.f)
|
||||
@ -781,7 +883,8 @@ static inline float bw_pow2f(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_expf(float x) {
|
||||
static inline float bw_expf(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
BW_ASSERT(x <= 88.722f);
|
||||
const float y = bw_pow2f(1.442695040888963f * x);
|
||||
@ -789,7 +892,8 @@ static inline float bw_expf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_pow10f(float x) {
|
||||
static inline float bw_pow10f(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
BW_ASSERT(x <= 38.531f);
|
||||
const float y = bw_pow2f(3.321928094887363f * x);
|
||||
@ -797,7 +901,8 @@ static inline float bw_pow10f(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_dB2linf(float x) {
|
||||
static inline float bw_dB2linf(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
BW_ASSERT(x <= 770.630f);
|
||||
const float y = bw_pow2f(0.1660964047443682f * x);
|
||||
@ -805,7 +910,8 @@ static inline float bw_dB2linf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_lin2dBf(float x) {
|
||||
static inline float bw_lin2dBf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= 1.175494350822287e-38f);
|
||||
const float y = 20.f * bw_log10f(x);
|
||||
@ -813,7 +919,8 @@ static inline float bw_lin2dBf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_sqrtf(float x) {
|
||||
static inline float bw_sqrtf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= 0.f);
|
||||
if (x < 1.1754943508222875e-38f)
|
||||
@ -831,7 +938,8 @@ static inline float bw_sqrtf(float x) {
|
||||
return v.f;
|
||||
}
|
||||
|
||||
static inline float bw_tanhf(float x) {
|
||||
static inline float bw_tanhf(
|
||||
float x) {
|
||||
BW_ASSERT(!bw_is_nan(x));
|
||||
const float xm = bw_clipf(x, -2.115287308554551f, 2.115287308554551f);
|
||||
const float axm = bw_absf(xm);
|
||||
@ -840,7 +948,8 @@ static inline float bw_tanhf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_sinhf(float x) {
|
||||
static inline float bw_sinhf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= -88.722f && x <= 88.722f);
|
||||
const float y = 0.5f * (bw_expf(x) - bw_expf(-x));
|
||||
@ -848,7 +957,8 @@ static inline float bw_sinhf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_coshf(float x) {
|
||||
static inline float bw_coshf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= -88.722f && x <= 88.722f);
|
||||
const float y = 0.5f * (bw_expf(x) + bw_expf(-x));
|
||||
@ -856,7 +966,8 @@ static inline float bw_coshf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_asinhf(float x) {
|
||||
static inline float bw_asinhf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= -8.507059173023462e+37f && x <= 8.507059173023462e+37f);
|
||||
float a = bw_absf(x);
|
||||
@ -865,7 +976,8 @@ static inline float bw_asinhf(float x) {
|
||||
return y;
|
||||
}
|
||||
|
||||
static inline float bw_acoshf(float x) {
|
||||
static inline float bw_acoshf(
|
||||
float x) {
|
||||
BW_ASSERT(bw_is_finite(x));
|
||||
BW_ASSERT(x >= 1.f && x <= 8.507059173023462e+37f);
|
||||
const float y = bw_logf((x >= 8192.f ? x : bw_sqrtf(x * x - 1.f)) + x);
|
||||
|
@ -73,8 +73,8 @@ extern "C" {
|
||||
* #### bw_note_queue_status
|
||||
* ```>>> */
|
||||
typedef struct {
|
||||
char pressed;
|
||||
float velocity;
|
||||
char pressed;
|
||||
float velocity;
|
||||
} bw_note_queue_status;
|
||||
/*! <<<```
|
||||
* Note status:
|
||||
@ -85,8 +85,8 @@ typedef struct {
|
||||
* #### bw_note_queue_event
|
||||
* ```>>> */
|
||||
typedef struct {
|
||||
unsigned char note;
|
||||
char went_off;
|
||||
unsigned char note;
|
||||
char went_off;
|
||||
} bw_note_queue_event;
|
||||
/*! <<<```
|
||||
* Note on/off event:
|
||||
@ -97,10 +97,10 @@ typedef struct {
|
||||
* #### bw_note_queue
|
||||
* ```>>> */
|
||||
typedef struct {
|
||||
bw_note_queue_event events[128];
|
||||
bw_note_queue_status status[128];
|
||||
unsigned char n_events;
|
||||
unsigned char n_pressed;
|
||||
bw_note_queue_event events[128];
|
||||
bw_note_queue_status status[128];
|
||||
unsigned char n_events;
|
||||
unsigned char n_pressed;
|
||||
} bw_note_queue;
|
||||
/*! <<<```
|
||||
* Note on/off event queue and pressed key status:
|
||||
@ -115,21 +115,28 @@ typedef struct {
|
||||
*
|
||||
* #### bw_note_queue_reset()
|
||||
* ```>>> */
|
||||
static inline void bw_note_queue_reset(bw_note_queue *BW_RESTRICT queue);
|
||||
static inline void bw_note_queue_reset(
|
||||
bw_note_queue * BW_RESTRICT queue);
|
||||
/*! <<<```
|
||||
* Clear both the event queue (no events) and the note statuses (all notes
|
||||
* off, all velocities `0.f`) in `queue`.
|
||||
*
|
||||
* #### bw_note_queue_clear()
|
||||
* ```>>> */
|
||||
static inline void bw_note_queue_clear(bw_note_queue *BW_RESTRICT queue);
|
||||
static inline void bw_note_queue_clear(
|
||||
bw_note_queue * BW_RESTRICT queue);
|
||||
/*! <<<```
|
||||
* Clears the event queue (no events) in `queue` without affecting the note
|
||||
* statuses.
|
||||
*
|
||||
* #### bw_note_queue_add()
|
||||
* ```>>> */
|
||||
static inline void bw_note_queue_add(bw_note_queue *BW_RESTRICT queue, unsigned char note, char pressed, float velocity, char force_went_off);
|
||||
static inline void bw_note_queue_add(
|
||||
bw_note_queue * BW_RESTRICT queue,
|
||||
unsigned char note,
|
||||
char pressed,
|
||||
float velocity,
|
||||
char force_went_off);
|
||||
/*! <<<```
|
||||
* Adds a new event to `queue` with the specified `note` number, `pressed`
|
||||
* value, and `velocity`.
|
||||
@ -139,7 +146,8 @@ static inline void bw_note_queue_add(bw_note_queue *BW_RESTRICT queue, unsigned
|
||||
*
|
||||
* #### bw_note_queue_is_valid()
|
||||
* ```>>> */
|
||||
static inline char bw_note_queue_is_valid(const bw_note_queue *BW_RESTRICT queue);
|
||||
static inline char bw_note_queue_is_valid(
|
||||
const bw_note_queue * BW_RESTRICT queue);
|
||||
/*! <<<```
|
||||
* Tries to determine whether `queue` is valid and returns non-`0` if it
|
||||
* seems to be the case and `0` if it is certainly not. False positives are
|
||||
@ -162,7 +170,8 @@ static inline char bw_note_queue_is_valid(const bw_note_queue *BW_RESTRICT queue
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline void bw_note_queue_reset(bw_note_queue *BW_RESTRICT queue) {
|
||||
static inline void bw_note_queue_reset(
|
||||
bw_note_queue * BW_RESTRICT queue) {
|
||||
BW_ASSERT(queue != NULL);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
queue->status[i].pressed = 0;
|
||||
@ -173,13 +182,19 @@ static inline void bw_note_queue_reset(bw_note_queue *BW_RESTRICT queue) {
|
||||
BW_ASSERT_DEEP(bw_note_queue_is_valid(queue));
|
||||
}
|
||||
|
||||
static inline void bw_note_queue_clear(bw_note_queue *BW_RESTRICT queue) {
|
||||
static inline void bw_note_queue_clear(
|
||||
bw_note_queue * BW_RESTRICT queue) {
|
||||
BW_ASSERT(queue != NULL);
|
||||
BW_ASSERT_DEEP(bw_note_queue_is_valid(queue));
|
||||
queue->n_events = 0;
|
||||
}
|
||||
|
||||
static inline void bw_note_queue_add(bw_note_queue *BW_RESTRICT queue, unsigned char note, char pressed, float velocity, char force_went_off) {
|
||||
static inline void bw_note_queue_add(
|
||||
bw_note_queue * BW_RESTRICT queue,
|
||||
unsigned char note,
|
||||
char pressed,
|
||||
float velocity,
|
||||
char force_went_off) {
|
||||
BW_ASSERT(queue != NULL);
|
||||
BW_ASSERT_DEEP(bw_note_queue_is_valid(queue));
|
||||
BW_ASSERT(note < 128);
|
||||
@ -210,7 +225,8 @@ static inline void bw_note_queue_add(bw_note_queue *BW_RESTRICT queue, unsigned
|
||||
BW_ASSERT_DEEP(bw_note_queue_is_valid(queue));
|
||||
}
|
||||
|
||||
static inline char bw_note_queue_is_valid(const bw_note_queue *BW_RESTRICT queue) {
|
||||
static inline char bw_note_queue_is_valid(
|
||||
const bw_note_queue * BW_RESTRICT queue) {
|
||||
BW_ASSERT(queue != NULL);
|
||||
|
||||
if (queue->n_events >= 128 || queue->n_pressed >= 128)
|
||||
@ -254,9 +270,13 @@ public:
|
||||
NoteQueue();
|
||||
|
||||
void clear();
|
||||
void add(unsigned char note, bool pressed, float velocity, bool force_went_off);
|
||||
void add(
|
||||
unsigned char note,
|
||||
bool pressed,
|
||||
float velocity,
|
||||
bool forceWentOff);
|
||||
|
||||
bw_note_queue queue;
|
||||
bw_note_queue queue;
|
||||
};
|
||||
/*! <<<```
|
||||
* }}} */
|
||||
@ -274,8 +294,12 @@ inline void NoteQueue::clear() {
|
||||
bw_note_queue_clear(&queue);
|
||||
}
|
||||
|
||||
inline void NoteQueue::add(unsigned char note, bool pressed, float velocity, bool force_went_off) {
|
||||
bw_note_queue_add(&queue, note, pressed, velocity, force_went_off);
|
||||
inline void NoteQueue::add(
|
||||
unsigned char note,
|
||||
bool pressed,
|
||||
float velocity,
|
||||
bool forceWentOff) {
|
||||
bw_note_queue_add(&queue, note, pressed, velocity, forceWentOff);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,7 +83,8 @@ extern "C" {
|
||||
/*! api {{{
|
||||
* #### bw_randu32()
|
||||
* ```>>> */
|
||||
static inline uint32_t bw_randu32(uint64_t *BW_RESTRICT state);
|
||||
static inline uint32_t bw_randu32(
|
||||
uint64_t * BW_RESTRICT state);
|
||||
/*! <<<```
|
||||
* Returns a pseudo-random unsigned 32-bit integer in the range
|
||||
* [`0`, `UINT32_MAX`].
|
||||
@ -93,7 +94,8 @@ static inline uint32_t bw_randu32(uint64_t *BW_RESTRICT state);
|
||||
*
|
||||
* #### bw_randf()
|
||||
* ```>>> */
|
||||
static inline float bw_randf(uint64_t *BW_RESTRICT state);
|
||||
static inline float bw_randf(
|
||||
uint64_t * BW_RESTRICT state);
|
||||
/*! <<<```
|
||||
* Returns a pseudo-random unsigned 32-bit floating point number in the range
|
||||
* [`-1.f`, `1.f`].
|
||||
@ -115,7 +117,8 @@ extern "C" {
|
||||
/* WARNING: This part of the file is not part of the public API. Its content may
|
||||
* change at any time in future versions. Please, do not use it directly. */
|
||||
|
||||
static inline uint32_t bw_randu32(uint64_t *BW_RESTRICT state) {
|
||||
static inline uint32_t bw_randu32(
|
||||
uint64_t * BW_RESTRICT state) {
|
||||
BW_ASSERT(state != NULL);
|
||||
// Permuted Congruential Generator,
|
||||
// taken from https://nullprogram.com/blog/2017/09/21/
|
||||
@ -123,7 +126,8 @@ static inline uint32_t bw_randu32(uint64_t *BW_RESTRICT state) {
|
||||
return (uint32_t)(*state >> (29 - (*state >> 61)));
|
||||
}
|
||||
|
||||
static inline float bw_randf(uint64_t *BW_RESTRICT state) {
|
||||
static inline float bw_randf(
|
||||
uint64_t * BW_RESTRICT state) {
|
||||
BW_ASSERT(state != NULL);
|
||||
const float y = (2.f / (float)UINT32_MAX) * (float)bw_randu32(state) - 1.f;
|
||||
BW_ASSERT(bw_is_finite(y));
|
||||
|
@ -84,12 +84,22 @@ typedef enum {
|
||||
* #### bw_voice_alloc_opts
|
||||
* ```>>> */
|
||||
typedef struct {
|
||||
bw_voice_alloc_priority priority;
|
||||
bw_voice_alloc_priority priority;
|
||||
|
||||
void (*note_on)(void *BW_RESTRICT voice, unsigned char note, float velocity);
|
||||
void (*note_off)(void *BW_RESTRICT voice, float velocity);
|
||||
unsigned char (*get_note)(const void *BW_RESTRICT voice);
|
||||
char (*is_free)(const void *BW_RESTRICT voice);
|
||||
void (*note_on)(
|
||||
void * BW_RESTRICT voice,
|
||||
unsigned char note,
|
||||
float velocity);
|
||||
|
||||
void (*note_off)(
|
||||
void * BW_RESTRICT voice,
|
||||
float velocity);
|
||||
|
||||
unsigned char (*get_note)(
|
||||
const void * BW_RESTRICT voice);
|
||||
|
||||
char (*is_free)(
|
||||
const void * BW_RESTRICT voice);
|
||||
} bw_voice_alloc_opts;
|
||||
/*! <<<```
|
||||
* Voice allocation options:
|
||||
@ -108,7 +118,11 @@ typedef struct {
|
||||
*
|
||||
* #### bw_voice_alloc()
|
||||
* ```>>> */
|
||||
void bw_voice_alloc(const bw_voice_alloc_opts *BW_RESTRICT opts, bw_note_queue *BW_RESTRICT queue, void *BW_RESTRICT const *BW_RESTRICT voices, size_t n_voices);
|
||||
void bw_voice_alloc(
|
||||
const bw_voice_alloc_opts * BW_RESTRICT opts,
|
||||
bw_note_queue * BW_RESTRICT queue,
|
||||
void * BW_RESTRICT const * BW_RESTRICT voices,
|
||||
size_t n_voices);
|
||||
/*! <<<```
|
||||
* It performs voice allocation according to `opts` and using the events in
|
||||
* `queue`.
|
||||
@ -130,7 +144,11 @@ void bw_voice_alloc(const bw_voice_alloc_opts *BW_RESTRICT opts, bw_note_queue *
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bw_voice_alloc(const bw_voice_alloc_opts *BW_RESTRICT opts, bw_note_queue *BW_RESTRICT queue, void *BW_RESTRICT const *BW_RESTRICT voices, size_t n_voices) {
|
||||
void bw_voice_alloc(
|
||||
const bw_voice_alloc_opts * BW_RESTRICT opts,
|
||||
bw_note_queue * BW_RESTRICT queue,
|
||||
void * BW_RESTRICT const * BW_RESTRICT voices,
|
||||
size_t n_voices) {
|
||||
BW_ASSERT(opts != NULL);
|
||||
BW_ASSERT(opts->priority == bw_voice_alloc_priority_low || opts->priority == bw_voice_alloc_priority_high);
|
||||
BW_ASSERT(n_voices == 0 || opts->note_on != NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user