aubio: test-cvec.c

aubio 0.4.9

test-cvec.c
#include "aubio.h"
#include "utils_tests.h"
int main (void)
{
uint_t i, window_size = 16;
cvec_t * complex_vector = new_cvec(window_size);
cvec_t * other_cvector = new_cvec(window_size);
assert(cvec_norm_get_data(complex_vector) == complex_vector->norm);
assert(cvec_phas_get_data(complex_vector) == complex_vector->phas);
assert(complex_vector->length == window_size / 2 + 1);
// all elements are initialized to 0
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->norm[i] == 0. );
assert( complex_vector->phas[i] == 0. );
}
cvec_norm_set_sample(complex_vector, 2., 1);
assert(cvec_norm_get_sample(complex_vector, 1));
cvec_phas_set_sample(complex_vector, 2., 1);
assert(cvec_phas_get_sample(complex_vector, 1));
cvec_print(complex_vector);
// set all norm and phas elements to 0
cvec_zeros(complex_vector);
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->norm[i] == 0. );
assert( complex_vector->phas[i] == 0. );
}
// set all norm elements to 1
cvec_norm_ones(complex_vector);
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->norm[i] == 1. );
}
// set all norm elements to 0
cvec_norm_zeros(complex_vector);
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->norm[i] == 0. );
}
// set all phas elements to 1
cvec_phas_ones(complex_vector);
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->phas[i] == 1. );
}
// set all phas elements to 0
cvec_phas_zeros(complex_vector);
for ( i = 0; i < complex_vector->length; i++ ) {
assert( complex_vector->phas[i] == 0. );
}
cvec_copy(complex_vector, other_cvector);
// copy to self
cvec_copy(complex_vector, complex_vector);
// copy to a different size fails
del_cvec(other_cvector);
other_cvector = new_cvec(window_size + 2);
cvec_copy(complex_vector, other_cvector);
if (complex_vector)
del_cvec(complex_vector);
if (other_cvector)
del_cvec(other_cvector);
// wrong parameters
assert(new_cvec(-1) == NULL);
assert(new_cvec(0) == NULL);
return 0;
}
cvec_phas_zeros
void cvec_phas_zeros(cvec_t *s)
set all phase elements to zero
cvec_zeros
void cvec_zeros(cvec_t *s)
set all norm and phas elements to zero
del_cvec
void del_cvec(cvec_t *s)
cvec_t buffer deletion function
cvec_t::norm
smpl_t * norm
norm array of size cvec_t.length
Definition: cvec.h:65
cvec_norm_ones
void cvec_norm_ones(cvec_t *s)
set all norm elements to one
cvec_t::phas
smpl_t * phas
phase array of size cvec_t.length
Definition: cvec.h:66
cvec_norm_set_sample
void cvec_norm_set_sample(cvec_t *s, smpl_t val, uint_t position)
write norm value in a complex buffer
new_cvec
cvec_t * new_cvec(uint_t length)
cvec_t buffer creation function
cvec_norm_zeros
void cvec_norm_zeros(cvec_t *s)
set all norm elements to zero
cvec_phas_get_sample
smpl_t cvec_phas_get_sample(cvec_t *s, uint_t position)
read phase value from a complex buffer
cvec_phas_ones
void cvec_phas_ones(cvec_t *s)
set all phase elements to one
cvec_phas_get_data
smpl_t * cvec_phas_get_data(const cvec_t *s)
read phase data from a complex buffer
aubio.h
cvec_copy
void cvec_copy(const cvec_t *s, cvec_t *t)
make a copy of a vector
cvec_t::length
uint_t length
length of buffer = (requested length)/2 + 1
Definition: cvec.h:64
cvec_norm_get_sample
smpl_t cvec_norm_get_sample(cvec_t *s, uint_t position)
read norm value from a complex buffer
cvec_t
Vector of real-valued phase and spectrum data.
Definition: cvec.h:63
cvec_norm_get_data
smpl_t * cvec_norm_get_data(const cvec_t *s)
read norm data from a complex buffer
cvec_print
void cvec_print(const cvec_t *s)
print out cvec data
cvec_phas_set_sample
void cvec_phas_set_sample(cvec_t *s, smpl_t val, uint_t position)
write phase value in a complex buffer
uint_t
unsigned int uint_t
unsigned integer
Definition: types.h:60