[tests] add run_on_default_source_and_sink helper
[aubio.git] / examples / aubiomfcc.c
index 02ab75e..0942ade 100644 (file)
@@ -29,8 +29,8 @@ fvec_t * mfcc_out;   // to get the output coefficients
 uint_t n_filters = 40;
 uint_t n_coefs = 13;
 
-static void
-process_block(fvec_t *ibuf, fvec_t *obuf) {
+void process_block (fvec_t *ibuf, fvec_t *obuf)
+{
   fvec_zeros(obuf);
   //compute mag spectrum
   aubio_pvoc_do (pv, ibuf, fftgrain);
@@ -38,13 +38,17 @@ process_block(fvec_t *ibuf, fvec_t *obuf) {
   aubio_mfcc_do(mfcc, fftgrain, mfcc_out);
 }
 
-static void process_print (void) {
-  /* output times in seconds and extracted mfccs */
-  outmsg("%f\t",blocks*hop_size/(float)samplerate);
-  fvec_print(mfcc_out);
+void process_print (void)
+{
+  /* output times in selected format */
+  print_time (blocks * hop_size);
+  outmsg ("\t");
+  /* output extracted mfcc */
+  fvec_print (mfcc_out);
 }
 
 int main(int argc, char **argv) {
+  int ret = 0;
   // change some default params
   buffer_size  = 512;
   hop_size = 256;
@@ -59,6 +63,10 @@ int main(int argc, char **argv) {
   fftgrain = new_cvec (buffer_size);
   mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate);
   mfcc_out = new_fvec(n_coefs);
+  if (pv == NULL || fftgrain == NULL || mfcc == NULL || mfcc_out == NULL) {
+    ret = 1;
+    goto beach;
+  }
 
   examples_common_process((aubio_process_func_t)process_block, process_print);
 
@@ -67,7 +75,7 @@ int main(int argc, char **argv) {
   del_aubio_mfcc(mfcc);
   del_fvec(mfcc_out);
 
+beach:
   examples_common_del();
-  return 0;
+  return ret;
 }
-