aubio: spectral/test-mfcc.c

aubio 0.4.9

Loading...
Searching...
No Matches
spectral/test-mfcc.c
#include <aubio.h>
#include "utils_tests.h"
int test_wrong_params(void);
int main (int argc, char** argv)
{
sint_t err = 0;
if (argc < 2) {
err = 2;
PRINT_WRN("no arguments, running tests\n");
err = test_wrong_params();
PRINT_MSG("usage: %s <input_path> [samplerate] [hop_size]\n", argv[0]);
return err;
}
uint_t win_s; // fft size
uint_t hop_s = 256; // block size
uint_t samplerate = 0; // samplerate
uint_t n_filters = 40; // number of filters
uint_t n_coeffs = 13; // number of coefficients
uint_t read = 0;
char_t *source_path = argv[1];
if ( argc >= 3 ) samplerate = atoi(argv[2]);
if ( argc >= 4 ) hop_s = atoi(argv[3]);
win_s = 2 * hop_s;
aubio_source_t *source = 0;
aubio_pvoc_t *pv = 0;
aubio_mfcc_t *mfcc = 0;
fvec_t *in = new_fvec (hop_s); // phase vocoder input
cvec_t *fftgrain = new_cvec (win_s); // pvoc output / mfcc input
fvec_t *out = new_fvec (n_coeffs); // mfcc output
if (!in || !fftgrain || !out) { err = 1; goto failure; }
// source
source = new_aubio_source(source_path, samplerate, hop_s);
if (!source) { err = 1; goto failure; }
if (samplerate == 0) samplerate = aubio_source_get_samplerate(source);
// phase vocoder
pv = new_aubio_pvoc(win_s, hop_s);
if (!pv) { err = 1; goto failure; }
// mfcc object
mfcc = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate);
if (!mfcc) { err = 1; goto failure; }
// processing loop
do {
aubio_source_do(source, in, &read);
aubio_pvoc_do(pv, in, fftgrain);
aubio_mfcc_do(mfcc, fftgrain, out);
fvec_print(out);
} while (read == hop_s);
failure:
if (mfcc)
del_aubio_mfcc(mfcc);
if (pv)
del_aubio_pvoc(pv);
if (source)
del_aubio_source(source);
if (in)
del_fvec(in);
if (fftgrain)
del_cvec(fftgrain);
if (out)
del_fvec(out);
aubio_cleanup();
return err;
}
int test_wrong_params()
{
uint_t win_s = 512; // fft size
uint_t n_filters = 40; // number of filters
uint_t n_coeffs = 13; // number of coefficients
smpl_t samplerate = 16000.; // samplerate
if (new_aubio_mfcc( 0, n_filters, n_coeffs, samplerate)) return 1;
if (new_aubio_mfcc(win_s, 0, n_coeffs, samplerate)) return 1;
if (new_aubio_mfcc(win_s, n_filters, 0, samplerate)) return 1;
if (new_aubio_mfcc(win_s, n_filters, n_coeffs, 0)) return 1;
return run_on_default_source(main);
}
aubio.h
Global aubio include file.
new_cvec
cvec_t * new_cvec(uint_t length)
cvec_t buffer creation function
del_cvec
void del_cvec(cvec_t *s)
cvec_t buffer deletion function
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_print
void fvec_print(const fvec_t *s)
print out fvec data
aubio_mfcc_do
void aubio_mfcc_do(aubio_mfcc_t *mf, const cvec_t *in, fvec_t *out)
mfcc object processing
del_aubio_mfcc
void del_aubio_mfcc(aubio_mfcc_t *mf)
delete mfcc object
new_aubio_mfcc
aubio_mfcc_t * new_aubio_mfcc(uint_t buf_size, uint_t n_filters, uint_t n_coeffs, uint_t samplerate)
create mfcc object
aubio_mfcc_t
struct _aubio_mfcc_t aubio_mfcc_t
mfcc object
Definition mfcc.h:47
aubio_cleanup
void aubio_cleanup(void)
clean up cached memory at the end of program
aubio_pvoc_t
struct _aubio_pvoc_t aubio_pvoc_t
phasevocoder object
Definition phasevoc.h:42
aubio_pvoc_do
void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t *in, cvec_t *fftgrain)
compute spectral frame
new_aubio_pvoc
aubio_pvoc_t * new_aubio_pvoc(uint_t win_s, uint_t hop_s)
create phase vocoder object
del_aubio_pvoc
void del_aubio_pvoc(aubio_pvoc_t *pv)
delete phase vocoder object
aubio_source_get_samplerate
uint_t aubio_source_get_samplerate(aubio_source_t *s)
get samplerate of source object
aubio_source_t
struct _aubio_source_t aubio_source_t
media source object
Definition source.h:70
new_aubio_source
aubio_source_t * new_aubio_source(const char_t *uri, uint_t samplerate, uint_t hop_size)
create new aubio_source_t
del_aubio_source
void del_aubio_source(aubio_source_t *s)
close source and cleanup memory
aubio_source_do
void aubio_source_do(aubio_source_t *s, fvec_t *read_to, uint_t *read)
read monophonic vector of length hop_size from source object
cvec_t
Vector of real-valued phase and spectrum data.
Definition cvec.h:63
fvec_t
Buffer for real data.
Definition fvec.h:67
uint_t
unsigned int uint_t
unsigned integer
Definition types.h:60
char_t
char char_t
character
Definition types.h:64
smpl_t
float smpl_t
short sample format (32 or 64 bits)
Definition types.h:41
sint_t
int sint_t
signed integer
Definition types.h:62