aubio 0.4.9

Loading...
Searching...
No Matches
test-fvec.c
#include "aubio.h"
#include "utils_tests.h"
void assert_fvec_all_equal(fvec_t *vec, smpl_t scalar)
{
uint_t i;
for (i = 0; i < vec->length; i++) {
assert(vec->data[i] == scalar);
}
}
int main (void)
{
uint_t length = 10;
uint_t i;
fvec_t * vec = new_fvec (length);
fvec_t * other_vec = new_fvec (length);
assert (vec);
assert (other_vec);
// vec->length matches requested size
assert(vec->length == length);
// all elements are initialized to `0.`
for ( i = 0; i < vec->length; i++ ) {
assert(vec->data[i] == 0.);
}
// all elements can be set to `1.`
fvec_ones(vec);
assert_fvec_all_equal(vec, 1.);
// all elements can be set to `0.`
fvec_zeros(vec);
assert_fvec_all_equal(vec, 0.);
// each element can be accessed directly
for ( i = 0; i < vec->length; i++ ) {
vec->data[i] = i;
assert(vec->data[i] == i);
}
fvec_print(vec);
fvec_set_sample(vec, 3, 2);
assert(fvec_get_sample(vec, 2) == 3);
assert(fvec_get_data(vec) == vec->data);
// wrong parameters
assert(new_fvec(-1) == NULL);
// copy to an identical size works
fvec_copy(vec, other_vec);
del_fvec(other_vec);
// copy to a different size fail
other_vec = new_fvec(length + 1);
fvec_copy(vec, other_vec);
del_fvec(other_vec);
// copy to a different size fail
other_vec = new_fvec(length - 1);
fvec_copy(vec, other_vec);
// now destroys the vector
if (vec)
del_fvec(vec);
if (other_vec)
del_fvec(other_vec);
return 0;
}
aubio.h
Global aubio include file.
fvec_copy
void fvec_copy(const fvec_t *s, fvec_t *t)
make a copy of a vector
fvec_get_data
smpl_t * fvec_get_data(const fvec_t *s)
read data from a buffer
fvec_set_sample
void fvec_set_sample(fvec_t *s, smpl_t data, uint_t position)
write sample value in a buffer
new_fvec
fvec_t * new_fvec(uint_t length)
fvec_t buffer creation function
del_fvec
void del_fvec(fvec_t *s)
fvec_t buffer deletion function
fvec_zeros
void fvec_zeros(fvec_t *s)
set all elements to zero
fvec_print
void fvec_print(const fvec_t *s)
print out fvec data
fvec_ones
void fvec_ones(fvec_t *s)
set all elements to ones
fvec_get_sample
smpl_t fvec_get_sample(const fvec_t *s, uint_t position)
read sample value in a buffer
fvec_t
Buffer for real data.
Definition fvec.h:67
fvec_t::data
smpl_t * data
data vector of length fvec_t.length
Definition fvec.h:69
fvec_t::length
uint_t length
length of buffer
Definition fvec.h:68
uint_t
unsigned int uint_t
unsigned integer
Definition types.h:60
smpl_t
float smpl_t
short sample format (32 or 64 bits)
Definition types.h:41