ensure buffers are not NULL in bw_buf + remove useless array of nullptr

in synthpp_poly
This commit is contained in:
Stefano D'Angelo 2023-08-14 12:51:53 +02:00
parent 4313cea18c
commit c3d8546e75
3 changed files with 33 additions and 16 deletions

1
TODO
View File

@ -27,7 +27,6 @@ code:
* mem req -> return value of set sample rate?
* peak gain + Q ???
* sr_reduce reset_coeffs? update_coeffs? process_multi?
* allow nullptr in C++ wrappers where process_multi arg can be NULL
* better src filter
* c++ get coeffs/state? or public? src nIn/OutSamples case (array vs single value), delay read/write, process1? process single?
* check unititialized warnings (check fxpp_comp in particular vs fxpp_satur)

View File

@ -167,7 +167,7 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl
const float vcf_mod_k = 0.3f * instance->params[p_vcf_mod];
float *b0[N_VOICES], *b1[N_VOICES], *b2[N_VOICES], *b3[N_VOICES], *b4[N_VOICES], *na[N_VOICES];
float *b0[N_VOICES], *b1[N_VOICES], *b2[N_VOICES], *b3[N_VOICES], *b4[N_VOICES];
char xgates[N_VOICES];
for (int j = 0; j < N_VOICES; j++) {
b0[j] = instance->voices[j].buf[0];
@ -175,7 +175,6 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl
b2[j] = instance->voices[j].buf[2];
b3[j] = instance->voices[j].buf[3];
b4[j] = instance->voices[j].buf[4];
na[j] = nullptr;
xgates[j] = instance->voices[j].gate;
}
@ -258,7 +257,7 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl
bufScale<N_VOICES>(b1, k, b1, n);
bufMix<N_VOICES>(b0, b1, b0, n);
instance->vcfEnvGen.process(xgates, na, n);
instance->vcfEnvGen.process(xgates, {}, n);
for (int j = 0; j < N_VOICES; j++) {
float v = instance->params[p_vcf_cutoff] + instance->params[p_vcf_contour] * instance->vcfEnvGen.getYZ1(j) + vcf_mod[j];
float cutoff = 20.f + (20e3f - 20.f) * v * v * v;

View File

@ -38,6 +38,8 @@
* <li>Added overladed C++ functions taking C-style arrays as
* arguments.</li>
* <li>Removed usage of reserved identifiers.</li>
* <li>Now enforcing that buffers are never <code>NULL</code> in
* debugging code.</li>
* </ul>
* </li>
* <li>Version <strong>0.6.0</strong>:
@ -183,8 +185,8 @@ extern "C" {
#endif
static inline void bw_buf_fill(float k, float *BW_RESTRICT dest, size_t n_elems) {
BW_ASSERT(!(dest == NULL && n_elems != 0));
BW_ASSERT(!bw_is_nan(k));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_elems; i++)
dest[i] = k;
@ -193,8 +195,9 @@ static inline void bw_buf_fill(float k, float *BW_RESTRICT dest, size_t n_elems)
}
static inline void bw_buf_neg(const float *src, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0));
BW_ASSERT(src != NULL);
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_elems; i++)
dest[i] = -src[i];
@ -203,9 +206,10 @@ static inline void bw_buf_neg(const float *src, 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(!((dest == NULL || src == NULL) && n_elems != 0));
BW_ASSERT(src != NULL);
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
BW_ASSERT(!bw_is_nan(k));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_elems; i++)
dest[i] = k + src[i];
@ -214,9 +218,10 @@ static inline void bw_buf_add(const float *src, float k, float *dest, size_t n_e
}
static inline void bw_buf_scale(const float *src, float k, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0));
BW_ASSERT(src != NULL);
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
BW_ASSERT(!bw_is_nan(k));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_elems; i++)
dest[i] = k * src[i];
@ -225,9 +230,11 @@ static inline void bw_buf_scale(const float *src, float k, float *dest, size_t n
}
static inline void bw_buf_mix(const float *src1, const float *src2, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_elems != 0));
BW_ASSERT(src1 != NULL);
BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems));
BW_ASSERT(src2 != NULL);
BW_ASSERT_DEEP(!bw_has_nan(src2, n_elems));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_elems; i++)
dest[i] = src1[i] + src2[i];
@ -236,9 +243,11 @@ static inline void bw_buf_mix(const float *src1, const float *src2, float *dest,
}
static inline void bw_buf_mul(const float *src1, const float *src2, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_elems != 0));
BW_ASSERT(src1 != NULL);
BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems));
BW_ASSERT(src2 != NULL);
BW_ASSERT_DEEP(!bw_has_nan(src2, n_elems));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_elems; i++)
dest[i] = src1[i] * src2[i];
@ -247,42 +256,52 @@ static inline void bw_buf_mul(const float *src1, const float *src2, float *dest,
}
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(!(dest == NULL && n_channels != 0));
BW_ASSERT(!bw_is_nan(k));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_channels; i++)
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) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0));
BW_ASSERT(src != NULL);
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_channels; i++)
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) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0));
BW_ASSERT(src != NULL);
BW_ASSERT(!bw_is_nan(k));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_channels; i++)
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) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0));
BW_ASSERT(src != NULL);
BW_ASSERT(!bw_is_nan(k));
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_channels; i++)
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) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_channels != 0));
BW_ASSERT(src1 != NULL);
BW_ASSERT(src2 != NULL);
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_channels; i++)
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) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_channels != 0));
BW_ASSERT(src1 != NULL);
BW_ASSERT(src2 != NULL);
BW_ASSERT(dest != NULL);
for (size_t i = 0; i < n_channels; i++)
bw_buf_mul(src1[i], src2[i], dest[i], n_elems);