Changeset d013a93 for tests


Ignore:
Timestamp:
Dec 17, 2018, 4:42:29 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
d286fe4
Parents:
2de7cfa (diff), 09b4be9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'feature/sink_flac' into feature/autosink

Location:
tests
Files:
2 added
6 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • tests/src/io/test-sink.c

    r2de7cfa rd013a93  
    22#include "utils_tests.h"
    33
    4 int main (int argc, char **argv)
     4int test_wrong_params(void);
     5
     6int main(int argc, char **argv)
    57{
    6   sint_t err = 0;
    7 
    8   if (argc < 3) {
    9     PRINT_ERR("not enough arguments, running tests\n");
    10     err = run_on_default_source_and_sink(main);
    11     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
     8  uint_t err = 0;
     9  if (argc < 3 || argc >= 6) {
     10    PRINT_ERR("wrong number of arguments, running tests\n");
     11    err = test_wrong_params();
     12    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
     13        argv[0]);
    1214    return err;
    1315  }
     
    2224  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    2325  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    24   if ( argc >= 6 ) {
    25     err = 2;
    26     PRINT_ERR("too many arguments\n");
    27     return err;
    28   }
    2926
    3027  fvec_t *vec = new_fvec(hop_size);
    31   if (!vec) { err = 1; goto beach_fvec; }
    3228
    3329  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    34   if (!i) { err = 1; goto beach_source; }
    35 
    3630  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    3731
    3832  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
    39   if (!o) { err = 1; goto beach_sink; }
     33
     34  if (!vec || !i || !o) { err = 1; goto failure; }
    4035
    4136  do {
     
    4540  } while ( read == hop_size );
    4641
    47   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
     42  PRINT_MSG("%d frames read at %dHz (%d blocks) from %s and written to %s\n",
    4843      n_frames, samplerate, n_frames / hop_size,
    4944      source_path, sink_path);
    5045
    51   del_aubio_sink(o);
    52 beach_sink:
    53   del_aubio_source(i);
    54 beach_source:
    55   del_fvec(vec);
    56 beach_fvec:
     46  // close sink now (optional)
     47  aubio_sink_close(o);
     48
     49failure:
     50  if (o)
     51    del_aubio_sink(o);
     52  if (i)
     53    del_aubio_source(i);
     54  if (vec)
     55    del_fvec(vec);
     56
    5757  return err;
    5858}
     59
     60int test_wrong_params(void)
     61{
     62  fvec_t *vec;
     63  fmat_t *mat;
     64  aubio_sink_t *s;
     65  char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
     66  uint_t samplerate = 44100;
     67  uint_t hop_size = 256;
     68  uint_t oversized_hop_size = 4097;
     69  uint_t oversized_samplerate = 192000 * 8 + 1;
     70  uint_t channels = 3;
     71  uint_t oversized_channels = 1025;
     72  // create temp file
     73  int fd = create_temp_sink(sink_path);
     74
     75  if (!fd) return 1;
     76
     77  if (new_aubio_sink(   0,   samplerate)) return 1;
     78  if (new_aubio_sink("\0",   samplerate)) return 1;
     79  if (new_aubio_sink(sink_path,      -1)) return 1;
     80
     81  s = new_aubio_sink(sink_path, 0);
     82
     83  // check setting wrong parameters fails
     84  if (!aubio_sink_preset_samplerate(s, oversized_samplerate)) return 1;
     85  if (!aubio_sink_preset_channels(s, oversized_channels)) return 1;
     86  if (!aubio_sink_preset_channels(s, -1)) return 1;
     87
     88  // check setting valid parameters passes
     89  if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
     90  if (aubio_sink_preset_channels(s, 1)) return 1;
     91
     92  // check writing a vector with valid length
     93  vec = new_fvec(hop_size);
     94  aubio_sink_do(s, vec, hop_size);
     95  // check writing more than in the input
     96  aubio_sink_do(s, vec, hop_size+1);
     97  // check write 0 frames
     98  aubio_sink_do(s, vec, 0);
     99  del_fvec(vec);
     100
     101  // check writing an oversized vector
     102  vec = new_fvec(oversized_hop_size);
     103  aubio_sink_do(s, vec, oversized_hop_size);
     104  del_fvec(vec);
     105
     106  // test delete without closing
     107  del_aubio_sink(s);
     108
     109  s = new_aubio_sink(sink_path, 0);
     110
     111  // preset channels first
     112  if (aubio_sink_preset_channels(s, channels)) return 1;
     113  if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
     114
     115  if (aubio_sink_get_samplerate(s) != samplerate) return 1;
     116  if (aubio_sink_get_channels(s) != channels) return 1;
     117
     118  mat = new_fmat(channels, hop_size);
     119  // check writing a vector with valid length
     120  aubio_sink_do_multi(s, mat, hop_size);
     121  // check writing 0 frames
     122  aubio_sink_do_multi(s, mat, 0);
     123  // check writing more than in the input
     124  aubio_sink_do_multi(s, mat, hop_size+1);
     125  del_fmat(mat);
     126
     127  // check writing oversized input
     128  mat = new_fmat(channels, oversized_hop_size);
     129  aubio_sink_do_multi(s, mat, oversized_hop_size);
     130  del_fmat(mat);
     131
     132  // check writing undersized input
     133  mat = new_fmat(channels - 1, hop_size);
     134  aubio_sink_do_multi(s, mat, hop_size);
     135  del_fmat(mat);
     136
     137  aubio_sink_close(s);
     138  // test closing twice
     139  aubio_sink_close(s);
     140
     141  del_aubio_sink(s);
     142
     143  // delete temp file
     144  close_temp_sink(sink_path, fd);
     145
     146  return run_on_default_source_and_sink(main);
     147}
  • tests/src/io/test-sink_apple_audio.c

    r2de7cfa rd013a93  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_sink_custom "apple_audio"
     6
     7#ifdef HAVE_SINK_APPLE_AUDIO
     8#define HAVE_AUBIO_SINK_CUSTOM
     9#define aubio_sink_custom_t aubio_sink_apple_audio_t
     10#define new_aubio_sink_custom new_aubio_sink_apple_audio
     11#define del_aubio_sink_custom del_aubio_sink_apple_audio
     12#define aubio_sink_custom_do aubio_sink_apple_audio_do
     13#define aubio_sink_custom_do_multi aubio_sink_apple_audio_do_multi
     14#define aubio_sink_custom_close aubio_sink_apple_audio_close
     15#define aubio_sink_custom_preset_samplerate aubio_sink_apple_audio_preset_samplerate
     16#define aubio_sink_custom_preset_channels aubio_sink_apple_audio_preset_channels
     17#define aubio_sink_custom_get_samplerate aubio_sink_apple_audio_get_samplerate
     18#define aubio_sink_custom_get_channels aubio_sink_apple_audio_get_channels
     19#endif /* HAVE_SINK_APPLE_AUDIO */
     20
     21#include "base-sink_custom.h"
    422
    523// this file uses the unstable aubio api, please use aubio_sink instead
     
    826int main (int argc, char **argv)
    927{
    10   sint_t err = 0;
    11 
    12   if (argc < 3) {
    13     PRINT_ERR("not enough arguments, running tests\n");
    14     err = run_on_default_source_and_sink(main);
    15     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    16     return err;
    17   }
    18 
    19 #ifdef HAVE_SINK_APPLE_AUDIO
    20   uint_t samplerate = 0;
    21   uint_t hop_size = 512;
    22   uint_t n_frames = 0, read = 0;
    23 
    24   char_t *source_path = argv[1];
    25   char_t *sink_path = argv[2];
    26 
    27   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    28   if ( argc >= 5 ) hop_size = atoi(argv[4]);
    29   if ( argc >= 6 ) {
    30     err = 2;
    31     PRINT_ERR("too many arguments\n");
    32     return err;
    33   }
    34 
    35   fvec_t *vec = new_fvec(hop_size);
    36   if (!vec) { err = 1; goto beach_fvec; }
    37 
    38   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    39   if (!i) { err = 1; goto beach_source; }
    40 
    41   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    42 
    43   aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, samplerate);
    44   if (!o) { err = 1; goto beach_sink; }
    45 
    46   do {
    47     aubio_source_do(i, vec, &read);
    48     aubio_sink_apple_audio_do(o, vec, read);
    49     n_frames += read;
    50   } while ( read == hop_size );
    51 
    52   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
    53       n_frames, samplerate, n_frames / hop_size,
    54       source_path, sink_path);
    55 
    56   del_aubio_sink_apple_audio(o);
    57 beach_sink:
    58   del_aubio_source(i);
    59 beach_source:
    60   del_fvec(vec);
    61 beach_fvec:
    62 #else /* HAVE_SINK_APPLE_AUDIO */
    63   err = 0;
    64   PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
    65 #endif /* HAVE_SINK_APPLE_AUDIO */
    66   return err;
     28  return base_main(argc, argv);
    6729}
  • tests/src/io/test-sink_flac.c

    r2de7cfa rd013a93  
    33#include "utils_tests.h"
    44
    5 #if 1 // test without inclusion in headers
     5#define aubio_sink_custom "flac"
     6
     7#ifdef HAVE_FLAC
     8// functions not exposed in the headers, declared here
    69typedef struct _aubio_sink_flac_t aubio_sink_flac_t;
    710extern aubio_sink_flac_t * new_aubio_sink_flac(const char_t *uri,
     
    912extern void del_aubio_sink_flac (aubio_sink_flac_t *s);
    1013extern uint_t aubio_sink_flac_open(aubio_sink_flac_t *s);
     14extern uint_t aubio_sink_flac_close(aubio_sink_flac_t *s);
    1115extern uint_t aubio_sink_flac_preset_channels(aubio_sink_flac_t *s,
    1216    uint_t channels);
    1317extern uint_t aubio_sink_flac_preset_samplerate(aubio_sink_flac_t *s,
    1418    uint_t samplerate);
     19extern void aubio_sink_flac_do(aubio_sink_flac_t *s, fvec_t* write_data,
     20    uint_t write);
     21extern void aubio_sink_flac_do_multi(aubio_sink_flac_t *s,
     22    fmat_t *write_data, uint_t write);
    1523extern uint_t aubio_sink_flac_get_channels(aubio_sink_flac_t *s);
    1624extern uint_t aubio_sink_flac_get_samplerate(aubio_sink_flac_t *s);
    17 extern void aubio_sink_flac_do_multi(aubio_sink_flac_t *s, fmat_t*
    18     write_data, uint_t write);
    19 #endif
    2025
    21 // this file uses the unstable aubio api to test aubio_sink_flac, please
    22 // use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c
     26#define HAVE_AUBIO_SINK_CUSTOM
     27#define aubio_sink_custom_t aubio_sink_flac_t
     28#define new_aubio_sink_custom new_aubio_sink_flac
     29#define del_aubio_sink_custom del_aubio_sink_flac
     30#define aubio_sink_custom_do aubio_sink_flac_do
     31#define aubio_sink_custom_do_multi aubio_sink_flac_do_multi
     32#define aubio_sink_custom_close aubio_sink_flac_close
     33#define aubio_sink_custom_preset_samplerate aubio_sink_flac_preset_samplerate
     34#define aubio_sink_custom_preset_channels aubio_sink_flac_preset_channels
     35#define aubio_sink_custom_get_samplerate aubio_sink_flac_get_samplerate
     36#define aubio_sink_custom_get_channels aubio_sink_flac_get_channels
     37#endif /* HAVE_FLAC */
     38
     39#include "base-sink_custom.h"
     40
     41// this file uses the unstable aubio api, please use aubio_sink instead
     42// see src/io/sink.h and tests/src/sink/test-sink.c
    2343
    2444int main (int argc, char **argv)
    2545{
    26   sint_t err = 0;
    27 
    28   if (argc < 3) {
    29     PRINT_ERR("not enough arguments, running tests\n");
    30     err = run_on_default_source_and_sink(main);
    31     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
    32     return err;
    33   }
    34 
    35 #ifdef HAVE_FLAC
    36   uint_t samplerate = 0;
    37   uint_t channels = 0;
    38   uint_t hop_size = 512;
    39   uint_t n_frames = 0, read = 0;
    40 
    41   char_t *source_path = argv[1];
    42   char_t *sink_path = argv[2];
    43 
    44   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    45   if ( argc >= 5 ) channels = atoi(argv[4]);
    46   if ( argc >= 6 ) hop_size = atoi(argv[5]);
    47   if ( argc >= 7 ) {
    48     err = 2;
    49     PRINT_ERR("too many arguments\n");
    50     return err;
    51   }
    52 
    53   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    54   if (!i) { err = 1; goto beach_source; }
    55 
    56   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    57   if (channels == 0 ) channels = aubio_source_get_channels(i);
    58 
    59   fmat_t *mat = new_fmat(channels, hop_size);
    60   if (!mat) { err = 1; goto beach_fmat; }
    61 
    62   aubio_sink_flac_t *o = new_aubio_sink_flac(sink_path, 0);
    63   if (!o) { err = 1; goto beach_sink; }
    64   err = aubio_sink_flac_preset_samplerate(o, samplerate);
    65   if (err) { goto beach; }
    66   err = aubio_sink_flac_preset_channels(o, channels);
    67   if (err) { goto beach; }
    68 
    69   do {
    70     aubio_source_do_multi(i, mat, &read);
    71     aubio_sink_flac_do_multi(o, mat, read);
    72     n_frames += read;
    73   } while ( read == hop_size );
    74 
    75   PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
    76       n_frames, samplerate, channels, n_frames / hop_size,
    77       source_path, sink_path);
    78   PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
    79       aubio_sink_flac_get_samplerate(o),
    80       aubio_sink_flac_get_channels(o) );
    81 
    82 beach:
    83   del_aubio_sink_flac(o);
    84 beach_sink:
    85   del_fmat(mat);
    86 beach_fmat:
    87   del_aubio_source(i);
    88 beach_source:
    89 #else /* HAVE_FLAC */
    90   err = 0;
    91   PRINT_ERR("aubio was not compiled with aubio_sink_flac\n");
    92 #endif /* HAVE_FLAC */
    93   return err;
     46  return base_main(argc, argv);
    9447}
  • tests/src/io/test-sink_sndfile.c

    r2de7cfa rd013a93  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_sink_custom "sndfile"
     6
     7#ifdef HAVE_SNDFILE
     8#define HAVE_AUBIO_SINK_CUSTOM
     9#define aubio_sink_custom_t aubio_sink_sndfile_t
     10#define new_aubio_sink_custom new_aubio_sink_sndfile
     11#define del_aubio_sink_custom del_aubio_sink_sndfile
     12#define aubio_sink_custom_do aubio_sink_sndfile_do
     13#define aubio_sink_custom_do_multi aubio_sink_sndfile_do_multi
     14#define aubio_sink_custom_close aubio_sink_sndfile_close
     15#define aubio_sink_custom_preset_samplerate aubio_sink_sndfile_preset_samplerate
     16#define aubio_sink_custom_preset_channels aubio_sink_sndfile_preset_channels
     17#define aubio_sink_custom_get_samplerate aubio_sink_sndfile_get_samplerate
     18#define aubio_sink_custom_get_channels aubio_sink_sndfile_get_channels
     19#endif /* HAVE_SNDFILE */
     20
     21#include "base-sink_custom.h"
    422
    523// this file uses the unstable aubio api, please use aubio_sink instead
     
    826int main (int argc, char **argv)
    927{
    10   sint_t err = 0;
    11 
    12   if (argc < 3) {
    13     PRINT_ERR("not enough arguments, running tests\n");
    14     err = run_on_default_source_and_sink(main);
    15     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    16     return err;
    17   }
    18 
    19 #ifdef HAVE_SNDFILE
    20   uint_t samplerate = 0;
    21   uint_t hop_size = 512;
    22   uint_t n_frames = 0, read = 0;
    23 
    24   char_t *source_path = argv[1];
    25   char_t *sink_path = argv[2];
    26 
    27   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    28   if ( argc >= 5 ) hop_size = atoi(argv[4]);
    29   if ( argc >= 6 ) {
    30     err = 2;
    31     PRINT_ERR("too many arguments\n");
    32     return err;
    33   }
    34 
    35   fvec_t *vec = new_fvec(hop_size);
    36   if (!vec) { err = 1; goto beach_fvec; }
    37 
    38   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    39   if (!i) { err = 1; goto beach_source; }
    40 
    41   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    42 
    43   aubio_sink_sndfile_t *o = new_aubio_sink_sndfile(sink_path, samplerate);
    44   if (!o) { err = 1; goto beach_sink; }
    45 
    46   do {
    47     aubio_source_do(i, vec, &read);
    48     aubio_sink_sndfile_do(o, vec, read);
    49     n_frames += read;
    50   } while ( read == hop_size );
    51 
    52   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
    53       n_frames, samplerate, n_frames / hop_size,
    54       source_path, sink_path);
    55 
    56   del_aubio_sink_sndfile(o);
    57 beach_sink:
    58   del_aubio_source(i);
    59 beach_source:
    60   del_fvec(vec);
    61 beach_fvec:
    62 #else
    63   err = 0;
    64   PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
    65 #endif /* HAVE_SNDFILE */
    66   return err;
     28  return base_main(argc, argv);
    6729}
  • tests/src/io/test-sink_vorbis.c

    r2de7cfa rd013a93  
    33#include "utils_tests.h"
    44
    5 #if 1 // test without inclusion in headers
     5#define aubio_sink_custom "vorbis"
     6
     7#ifdef HAVE_VORBISENC
     8// functions not exposed in the headers, declared here
    69typedef struct _aubio_sink_vorbis_t aubio_sink_vorbis_t;
    710extern aubio_sink_vorbis_t * new_aubio_sink_vorbis(const char_t *uri,
     
    912extern void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s);
    1013extern uint_t aubio_sink_vorbis_open(aubio_sink_vorbis_t *s);
     14extern uint_t aubio_sink_vorbis_close(aubio_sink_vorbis_t *s);
    1115extern uint_t aubio_sink_vorbis_preset_channels(aubio_sink_vorbis_t *s,
    1216    uint_t channels);
    1317extern uint_t aubio_sink_vorbis_preset_samplerate(aubio_sink_vorbis_t *s,
    1418    uint_t samplerate);
     19extern void aubio_sink_vorbis_do(aubio_sink_vorbis_t *s, fvec_t *write_data,
     20    uint_t write);
     21extern void aubio_sink_vorbis_do_multi(aubio_sink_vorbis_t *s,
     22    fmat_t *write_data, uint_t write);
    1523extern uint_t aubio_sink_vorbis_get_channels(aubio_sink_vorbis_t *s);
    1624extern uint_t aubio_sink_vorbis_get_samplerate(aubio_sink_vorbis_t *s);
    17 extern void aubio_sink_vorbis_do_multi(aubio_sink_vorbis_t *s, fmat_t*
    18     write_data, uint_t write);
    19 #endif
    2025
    21 // this file uses the unstable aubio api to test aubio_sink_vorbis, please
    22 // use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c
     26#define HAVE_AUBIO_SINK_CUSTOM
     27#define aubio_sink_custom_t aubio_sink_vorbis_t
     28#define new_aubio_sink_custom new_aubio_sink_vorbis
     29#define del_aubio_sink_custom del_aubio_sink_vorbis
     30#define aubio_sink_custom_do aubio_sink_vorbis_do
     31#define aubio_sink_custom_do_multi aubio_sink_vorbis_do_multi
     32#define aubio_sink_custom_close aubio_sink_vorbis_close
     33#define aubio_sink_custom_preset_samplerate aubio_sink_vorbis_preset_samplerate
     34#define aubio_sink_custom_preset_channels aubio_sink_vorbis_preset_channels
     35#define aubio_sink_custom_get_samplerate aubio_sink_vorbis_get_samplerate
     36#define aubio_sink_custom_get_channels aubio_sink_vorbis_get_channels
     37#endif /* HAVE_VORBISENC */
     38
     39#include "base-sink_custom.h"
     40
     41// this file uses the unstable aubio api, please use aubio_sink instead
     42// see src/io/sink.h and tests/src/sink/test-sink.c
    2343
    2444int main (int argc, char **argv)
    2545{
    26   sint_t err = 0;
    27 
    28   if (argc < 3) {
    29     PRINT_ERR("not enough arguments, running tests\n");
    30     err = run_on_default_source_and_sink(main);
    31     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
    32     return err;
    33   }
    34 
    35 #ifdef HAVE_VORBISENC
    36   uint_t samplerate = 0;
    37   uint_t channels = 0;
    38   uint_t hop_size = 512;
    39   uint_t n_frames = 0, read = 0;
    40 
    41   char_t *source_path = argv[1];
    42   char_t *sink_path = argv[2];
    43 
    44   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    45   if ( argc >= 5 ) channels = atoi(argv[4]);
    46   if ( argc >= 6 ) hop_size = atoi(argv[5]);
    47   if ( argc >= 7 ) {
    48     err = 2;
    49     PRINT_ERR("too many arguments\n");
    50     return err;
    51   }
    52 
    53   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    54   if (!i) { err = 1; goto beach_source; }
    55 
    56   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    57   if (channels == 0 ) channels = aubio_source_get_channels(i);
    58 
    59   fmat_t *mat = new_fmat(channels, hop_size);
    60   if (!mat) { err = 1; goto beach_fmat; }
    61 
    62   aubio_sink_vorbis_t *o = new_aubio_sink_vorbis(sink_path, 0);
    63   if (!o) { err = 1; goto beach_sink; }
    64   err = aubio_sink_vorbis_preset_samplerate(o, samplerate);
    65   if (err) { goto beach; }
    66   err = aubio_sink_vorbis_preset_channels(o, channels);
    67   if (err) { goto beach; }
    68 
    69   do {
    70     aubio_source_do_multi(i, mat, &read);
    71     aubio_sink_vorbis_do_multi(o, mat, read);
    72     n_frames += read;
    73   } while ( read == hop_size );
    74 
    75   PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
    76       n_frames, samplerate, channels, n_frames / hop_size,
    77       source_path, sink_path);
    78   PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
    79       aubio_sink_vorbis_get_samplerate(o),
    80       aubio_sink_vorbis_get_channels(o) );
    81 
    82 beach:
    83   del_aubio_sink_vorbis(o);
    84 beach_sink:
    85   del_fmat(mat);
    86 beach_fmat:
    87   del_aubio_source(i);
    88 beach_source:
    89 #else /* HAVE_VORBISENC */
    90   err = 0;
    91   PRINT_ERR("aubio was not compiled with aubio_sink_vorbis\n");
    92 #endif /* HAVE_VORBISENC */
    93   return err;
     46  return base_main(argc, argv);
    9447}
  • tests/src/io/test-sink_wavwrite.c

    r2de7cfa rd013a93  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_sink_custom "wavwrite"
     6
     7#ifdef HAVE_WAVWRITE
     8#define HAVE_AUBIO_SINK_CUSTOM
     9#define aubio_sink_custom_t aubio_sink_wavwrite_t
     10#define new_aubio_sink_custom new_aubio_sink_wavwrite
     11#define del_aubio_sink_custom del_aubio_sink_wavwrite
     12#define aubio_sink_custom_do aubio_sink_wavwrite_do
     13#define aubio_sink_custom_do_multi aubio_sink_wavwrite_do_multi
     14#define aubio_sink_custom_close aubio_sink_wavwrite_close
     15#define aubio_sink_custom_preset_samplerate aubio_sink_wavwrite_preset_samplerate
     16#define aubio_sink_custom_preset_channels aubio_sink_wavwrite_preset_channels
     17#define aubio_sink_custom_get_samplerate aubio_sink_wavwrite_get_samplerate
     18#define aubio_sink_custom_get_channels aubio_sink_wavwrite_get_channels
     19#endif /* HAVE_WAVWRITE */
     20
     21#include "base-sink_custom.h"
    422
    523// this file uses the unstable aubio api, please use aubio_sink instead
     
    826int main (int argc, char **argv)
    927{
    10   sint_t err = 0;
    11 
    12   if (argc < 3) {
    13     PRINT_ERR("not enough arguments, running tests\n");
    14     err = run_on_default_source_and_sink(main);
    15     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    16     return err;
    17   }
    18 
    19 #ifdef HAVE_WAVWRITE
    20   uint_t samplerate = 0;
    21   uint_t hop_size = 512;
    22   uint_t n_frames = 0, read = 0;
    23 
    24   char_t *source_path = argv[1];
    25   char_t *sink_path = argv[2];
    26 
    27   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    28   if ( argc >= 5 ) hop_size = atoi(argv[4]);
    29   if ( argc >= 6 ) {
    30     err = 2;
    31     PRINT_ERR("too many arguments\n");
    32     return err;
    33   }
    34 
    35   fvec_t *vec = new_fvec(hop_size);
    36   if (!vec) { err = 1; goto beach_fvec; }
    37 
    38   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    39   if (!i) { err = 1; goto beach_source; }
    40 
    41   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    42 
    43   aubio_sink_wavwrite_t *o = new_aubio_sink_wavwrite(sink_path, samplerate);
    44   if (!o) { err = 1; goto beach_sink; }
    45 
    46   do {
    47     aubio_source_do(i, vec, &read);
    48     aubio_sink_wavwrite_do(o, vec, read);
    49     n_frames += read;
    50   } while ( read == hop_size );
    51 
    52   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
    53       n_frames, samplerate, n_frames / hop_size,
    54       source_path, sink_path);
    55 
    56   del_aubio_sink_wavwrite(o);
    57 beach_sink:
    58   del_aubio_source(i);
    59 beach_source:
    60   del_fvec(vec);
    61 beach_fvec:
    62 #else
    63   err = 0;
    64   PRINT_ERR("aubio was not compiled with aubio_sink_wavwrite\n");
    65 #endif /* HAVE_WAVWRITE */
    66   return err;
     28  return base_main(argc, argv);
    6729}
  • tests/src/io/test-source.c

    r2de7cfa rd013a93  
    22#include "utils_tests.h"
    33
    4 int main (int argc, char **argv)
     4int test_wrong_params(void);
     5
     6int main(int argc, char **argv)
    57{
    68  uint_t err = 0;
    79  if (argc < 2) {
    810    PRINT_ERR("not enough arguments, running tests\n");
    9     err = run_on_default_source(main);
     11    err = test_wrong_params();
    1012    PRINT_MSG("read a wave file as a mono vector\n");
    1113    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     
    2830  char_t *source_path = argv[1];
    2931
    30 
    3132  aubio_source_t* s =
    3233    new_aubio_source(source_path, samplerate, hop_size);
    33   if (!s) { err = 1; goto beach; }
    3434  fvec_t *vec = new_fvec(hop_size);
     35  if (!s || !vec) { err = 1; goto beach; }
    3536
    3637  uint_t n_frames_expected = aubio_source_get_duration(s);
     
    5051  // close the file (optional)
    5152  aubio_source_close(s);
     53
     54beach:
     55  if (vec)
     56    del_fvec(vec);
     57  if (s)
     58    del_aubio_source(s);
     59  return err;
     60}
     61
     62int test_wrong_params(void)
     63{
     64  char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
     65  uint_t samplerate = 44100;
     66  uint_t hop_size = 512;
     67  uint_t channels, read = 0;
     68  fvec_t *vec;
     69  fmat_t *mat;
     70  aubio_source_t *s;
     71
     72  if (new_aubio_source(0,    samplerate, hop_size)) return 1;
     73  if (new_aubio_source("\0", samplerate, hop_size)) return 1;
     74  if (new_aubio_source(uri,          -1, hop_size)) return 1;
     75  if (new_aubio_source(uri,           0,        0)) return 1;
     76
     77  s = new_aubio_source(uri, samplerate, hop_size);
     78  if (!s) return 1;
     79  channels = aubio_source_get_channels(s);
     80
     81  // vector to read downmixed samples
     82  vec = new_fvec(hop_size);
     83  // matrix to read individual channels
     84  mat = new_fmat(channels, hop_size);
     85
     86  if (aubio_source_get_samplerate(s) != samplerate) return 1;
     87
     88  // read first hop_size frames
     89  aubio_source_do(s, vec, &read);
     90  if (read != hop_size) return 1;
     91
     92  // seek to 0
     93  if(aubio_source_seek(s, 0)) return 1;
     94
     95  // read again as multiple channels
     96  aubio_source_do_multi(s, mat, &read);
     97  if (read != hop_size) return 1;
     98
     99  // close the file (optional)
     100  aubio_source_close(s);
    52101  // test closing the file a second time
    53102  aubio_source_close(s);
    54103
    55   del_fvec (vec);
    56   del_aubio_source (s);
    57 beach:
    58   return err;
     104  del_aubio_source(s);
     105  del_fmat(mat);
     106  del_fvec(vec);
     107
     108  return run_on_default_source(main);
    59109}
  • tests/src/io/test-source_apple_audio.c

    r2de7cfa rd013a93  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "apple_audio"
     6
     7#ifdef HAVE_SOURCE_APPLE_AUDIO
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_apple_audio_t
     10#define new_aubio_source_custom new_aubio_source_apple_audio
     11#define del_aubio_source_custom del_aubio_source_apple_audio
     12#define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_apple_audio_get_duration
     14#define aubio_source_custom_do aubio_source_apple_audio_do
     15#define aubio_source_custom_do_multi aubio_source_apple_audio_do_multi
     16#define aubio_source_custom_seek aubio_source_apple_audio_seek
     17#define aubio_source_custom_close aubio_source_apple_audio_close
     18#define aubio_source_custom_get_channels aubio_source_apple_audio_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
     20#endif /* HAVE_SOURCE_APPLE_AUDIO */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     PRINT_ERR("not enough arguments, running tests\n");
    13     err = run_on_default_source(main);
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.aif at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.mp3 at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.mp3 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #if HAVE_SOURCE_APPLE_AUDIO
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc >= 3 ) samplerate = atoi(argv[2]);
    31   if ( argc >= 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_apple_audio_t * s =
    37     new_aubio_source_apple_audio(source_path, samplerate, hop_size);
    38   if (!s) { err = 1; goto beach; }
    39   fvec_t *vec = new_fvec(hop_size);
    40 
    41   uint_t n_frames_expected = aubio_source_apple_audio_get_duration(s);
    42 
    43   samplerate = aubio_source_apple_audio_get_samplerate(s);
    44 
    45   do {
    46     aubio_source_apple_audio_do(s, vec, &read);
    47     fvec_print (vec);
    48     n_frames += read;
    49   } while ( read == hop_size );
    50 
    51   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    52             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    53             source_path);
    54 
    55   del_fvec (vec);
    56   del_aubio_source_apple_audio (s);
    57 beach:
    58 #else /* HAVE_SOURCE_APPLE_AUDIO */
    59   err = 0;
    60   PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
    61 #endif /* HAVE_SOURCE_APPLE_AUDIO */
    62   return err;
     29  return base_main(argc, argv);
    6330}
  • tests/src/io/test-source_avcodec.c

    r2de7cfa rd013a93  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "avcodec"
     6
     7#ifdef HAVE_LIBAV
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_avcodec_t
     10#define new_aubio_source_custom new_aubio_source_avcodec
     11#define del_aubio_source_custom del_aubio_source_avcodec
     12#define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_avcodec_get_duration
     14#define aubio_source_custom_do aubio_source_avcodec_do
     15#define aubio_source_custom_do_multi aubio_source_avcodec_do_multi
     16#define aubio_source_custom_seek aubio_source_avcodec_seek
     17#define aubio_source_custom_close aubio_source_avcodec_close
     18#define aubio_source_custom_get_channels aubio_source_avcodec_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
     20#endif /* HAVE_LIBAV */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     PRINT_ERR("not enough arguments, running tests\n");
    13     err = run_on_default_source(main);
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.wav at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #ifdef HAVE_LIBAV
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc >= 3 ) samplerate = atoi(argv[2]);
    31   if ( argc >= 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_avcodec_t * s =
    37     new_aubio_source_avcodec(source_path, samplerate, hop_size);
    38   if (!s) { err = 1; goto beach; }
    39   fvec_t *vec = new_fvec(hop_size);
    40 
    41   uint_t n_frames_expected = aubio_source_avcodec_get_duration(s);
    42 
    43   samplerate = aubio_source_avcodec_get_samplerate(s);
    44 
    45   do {
    46     aubio_source_avcodec_do(s, vec, &read);
    47     fvec_print (vec);
    48     n_frames += read;
    49   } while ( read == hop_size );
    50 
    51   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    52             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    53             source_path);
    54 
    55   del_fvec (vec);
    56   del_aubio_source_avcodec (s);
    57 beach:
    58 #else /* HAVE_LIBAV */
    59   err = 0;
    60   PRINT_ERR("aubio was not compiled with aubio_source_avcodec\n");
    61 #endif /* HAVE_LIBAV */
    62   return err;
     29  return base_main(argc, argv);
    6330}
  • tests/src/io/test-source_sndfile.c

    r2de7cfa rd013a93  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "sndfile"
     6
     7#ifdef HAVE_SNDFILE
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_sndfile_t
     10#define new_aubio_source_custom new_aubio_source_sndfile
     11#define del_aubio_source_custom del_aubio_source_sndfile
     12#define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_sndfile_get_duration
     14#define aubio_source_custom_do aubio_source_sndfile_do
     15#define aubio_source_custom_do_multi aubio_source_sndfile_do_multi
     16#define aubio_source_custom_seek aubio_source_sndfile_seek
     17#define aubio_source_custom_close aubio_source_sndfile_close
     18#define aubio_source_custom_get_channels aubio_source_sndfile_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
     20#endif /* HAVE_LIBAV */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     PRINT_ERR("not enough arguments, running tests\n");
    13     err = run_on_default_source(main);
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.wav at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #ifdef HAVE_SNDFILE
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc >= 3 ) samplerate = atoi(argv[2]);
    31   if ( argc >= 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_sndfile_t * s =
    37     new_aubio_source_sndfile(source_path, samplerate, hop_size);
    38   if (!s) { err = 1; goto beach; }
    39   fvec_t *vec = new_fvec(hop_size);
    40 
    41   uint_t n_frames_expected = aubio_source_sndfile_get_duration(s);
    42 
    43   samplerate = aubio_source_sndfile_get_samplerate(s);
    44 
    45   do {
    46     aubio_source_sndfile_do(s, vec, &read);
    47     fvec_print (vec);
    48     n_frames += read;
    49   } while ( read == hop_size );
    50 
    51   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    52             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    53             source_path);
    54 
    55   del_fvec (vec);
    56   del_aubio_source_sndfile (s);
    57 beach:
    58 #else
    59   err = 0;
    60   PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
    61 #endif /* HAVE_SNDFILE */
    62   return err;
     29  return base_main(argc, argv);
    6330}
  • tests/src/io/test-source_wavread.c

    r2de7cfa rd013a93  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "wavread"
     6
     7#ifdef HAVE_WAVREAD
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_wavread_t
     10#define new_aubio_source_custom new_aubio_source_wavread
     11#define del_aubio_source_custom del_aubio_source_wavread
     12#define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_wavread_get_duration
     14#define aubio_source_custom_do aubio_source_wavread_do
     15#define aubio_source_custom_do_multi aubio_source_wavread_do_multi
     16#define aubio_source_custom_seek aubio_source_wavread_seek
     17#define aubio_source_custom_close aubio_source_wavread_close
     18#define aubio_source_custom_get_channels aubio_source_wavread_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
     20#endif /* HAVE_WAVREAD */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     PRINT_ERR("not enough arguments, running tests\n");
    13     err = run_on_default_source(main);
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.wav at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #ifdef HAVE_WAVREAD
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc >= 3 ) samplerate = atoi(argv[2]);
    31   if ( argc >= 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_wavread_t * s =
    37     new_aubio_source_wavread(source_path, samplerate, hop_size);
    38   if (!s) { err = 1; goto beach; }
    39   fvec_t *vec = new_fvec(hop_size);
    40 
    41   uint_t n_frames_expected = aubio_source_wavread_get_duration(s);
    42 
    43   samplerate = aubio_source_wavread_get_samplerate(s);
    44 
    45   do {
    46     aubio_source_wavread_do(s, vec, &read);
    47     fvec_print (vec);
    48     n_frames += read;
    49   } while ( read == hop_size );
    50 
    51   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    52             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    53             source_path);
    54 
    55   del_fvec (vec);
    56   del_aubio_source_wavread (s);
    57 beach:
    58 #else
    59   err = 0;
    60   PRINT_ERR("aubio was not compiled with aubio_source_wavread\n");
    61 #endif /* HAVE_WAVREAD */
    62   return err;
     29  return base_main(argc, argv);
    6330}
  • tests/utils_tests.h

    r2de7cfa rd013a93  
    5656#endif
    5757
    58 // are we on windows ? or are we using -std=c99 ?
    59 #if defined(HAVE_WIN_HACKS) || defined(__STRICT_ANSI__)
    60 // http://en.wikipedia.org/wiki/Linear_congruential_generator
    61 // no srandom/random on win32
     58#if defined(HAVE_WIN_HACKS)
    6259
    63 uint_t srandom_seed = 1029;
     60// use srand/rand on windows
     61#define srandom srand
     62#define random rand
    6463
    65 void srandom(uint_t new_seed) {
    66     srandom_seed = new_seed;
    67 }
     64#elif defined(__STRICT_ANSI__)
    6865
    69 uint_t random(void) {
    70     srandom_seed = 1664525 * srandom_seed + 1013904223;
    71     return srandom_seed;
    72 }
     66// workaround to build with -std=c99 (for instance with older cygwin),
     67// assuming libbc is recent enough to supports these functions.
     68extern void srandom(unsigned);
     69extern int random(void);
     70extern char mkstemp(const char *pat);
     71
    7372#endif
    7473
Note: See TracChangeset for help on using the changeset viewer.