aubio 0.4.9

Loading...
Searching...
No Matches
test-fmat.c
#include "aubio.h"
#include "utils_tests.h"
// create a new matrix and fill it with i * 1. + j * .1, where i is the row,
// and j the column.
void assert_fmat_all_equal(fmat_t *mat, smpl_t scalar)
{
uint_t i, j;
for ( i = 0; i < mat->height; i++ ) {
for ( j = 0; j < mat->length; j++ ) {
assert(mat->data[i][j] == scalar);
}
}
}
int main (void)
{
uint_t i, j;
uint_t height = 3, length = 9;
// create fmat_t object
fmat_t * mat = new_fmat(height, length);
fmat_t * other_mat = new_fmat(height, length);
assert(mat);
assert(other_mat);
assert(mat->length == length);
assert(mat->height == height);
for (i = 0; i < mat->height; i++) {
for (j = 0; j < mat->length; j++) {
// all elements are already initialized to 0.
assert(mat->data[i][j] == 0);
// setting element of row i, column j
mat->data[i][j] = i * 10. + j;
}
}
// print out matrix
fmat_print(mat);
// helpers
fmat_rev(mat);
fmat_print(mat);
for (i = 0; i < mat->height; i++) {
for (j = 0; j < mat->length; j++) {
assert(mat->data[i][j] == i * 10. + mat->length - 1. - j);
}
}
fmat_set_sample(mat, 3, 1, 1);
assert(fmat_get_sample(mat, 1, 1) == 3.);
fmat_ones(mat);
assert_fmat_all_equal(mat, 1.);
fmat_set(other_mat, .5);
assert_fmat_all_equal(other_mat, .5);
fmat_weight(mat, other_mat);
assert_fmat_all_equal(mat, .5);
fvec_t channel_onstack;
fvec_t *channel = &channel_onstack;
fmat_get_channel(mat, 1, channel);
assert(channel->data == mat->data[1]);
// copy of the same size
fmat_copy(mat, other_mat);
del_fmat(other_mat);
// copy to undersized
other_mat = new_fmat(height - 1, length);
fmat_copy(mat, other_mat);
del_fmat(other_mat);
// copy from undersized
other_mat = new_fmat(height, length + 1);
fmat_copy(mat, other_mat);
// wrong parameters
assert(new_fmat(-1, length) == NULL);
assert(new_fmat(height, -1) == NULL);
// methods for wrappers with opaque structure
assert (fmat_get_channel_data(mat, 0) == mat->data[0]);
assert (fmat_get_data(mat) == mat->data);
if (mat)
del_fmat(mat);
if (other_mat)
del_fmat(other_mat);
return 0;
}
aubio.h
Global aubio include file.
fmat_get_channel_data
smpl_t * fmat_get_channel_data(const fmat_t *s, uint_t channel)
get vector buffer from an fmat data
fmat_print
void fmat_print(const fmat_t *s)
print out fmat data
del_fmat
void del_fmat(fmat_t *s)
fmat_t buffer deletion function
fmat_weight
void fmat_weight(fmat_t *s, const fmat_t *weight)
apply weight to vector
fmat_copy
void fmat_copy(const fmat_t *s, fmat_t *t)
make a copy of a matrix
fmat_rev
void fmat_rev(fmat_t *s)
revert order of vector elements
fmat_set_sample
void fmat_set_sample(fmat_t *s, smpl_t data, uint_t channel, uint_t position)
write sample value in a buffer
fmat_get_data
smpl_t ** fmat_get_data(const fmat_t *s)
read data from a buffer
fmat_ones
void fmat_ones(fmat_t *s)
set all elements to ones
fmat_set
void fmat_set(fmat_t *s, smpl_t val)
set all elements to a given value
fmat_get_channel
void fmat_get_channel(const fmat_t *s, uint_t channel, fvec_t *output)
read channel vector from a buffer
new_fmat
fmat_t * new_fmat(uint_t height, uint_t length)
fmat_t buffer creation function
fmat_get_sample
smpl_t fmat_get_sample(const fmat_t *s, uint_t channel, uint_t position)
read sample value in a buffer
fmat_t
Buffer for real data.
Definition: fmat.h:40
fmat_t::data
smpl_t ** data
data array of size [length] * [height]
Definition: fmat.h:43
fmat_t::length
uint_t length
length of matrix
Definition: fmat.h:41
fmat_t::height
uint_t height
height of matrix
Definition: fmat.h:42
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
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