source: tests/src/io/base-source_custom.h @ ee463f9

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since ee463f9 was 7fc8406, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] use double quotes for \0

  • Property mode set to 100644
File size: 3.5 KB
Line 
1// this should be included *after* custom functions have been defined
2
3#ifndef aubio_source_custom
4#define aubio_source_custom "undefined"
5#endif /* aubio_source_custom */
6
7#ifdef HAVE_AUBIO_SOURCE_CUSTOM
8int test_wrong_params(void);
9
10int base_main(int argc, char **argv)
11{
12  uint_t err = 0;
13  if (argc < 2) {
14    PRINT_ERR("not enough arguments, running tests\n");
15    err = test_wrong_params();
16    PRINT_MSG("read a wave file as a mono vector\n");
17    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
18    PRINT_MSG("examples:\n");
19    PRINT_MSG(" - read file.wav at original samplerate\n");
20    PRINT_MSG("       %s file.wav\n", argv[0]);
21    PRINT_MSG(" - read file.wav at 32000Hz\n");
22    PRINT_MSG("       %s file.aif 32000\n", argv[0]);
23    PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
24    PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
25    return err;
26  }
27
28  uint_t samplerate = 0;
29  uint_t hop_size = 256;
30  uint_t n_frames = 0, read = 0;
31  if ( argc >= 3 ) samplerate = atoi(argv[2]);
32  if ( argc >= 4 ) hop_size = atoi(argv[3]);
33
34  char_t *source_path = argv[1];
35
36  aubio_source_custom_t * s =
37    new_aubio_source_custom(source_path, samplerate, hop_size);
38  fvec_t *vec = new_fvec(hop_size);
39  if (!s || !vec) { err = 1; goto beach; }
40
41  uint_t n_frames_expected = aubio_source_custom_get_duration(s);
42
43  samplerate = aubio_source_custom_get_samplerate(s);
44
45  do {
46    aubio_source_custom_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  // close the file (optional)
56  aubio_source_custom_close(s);
57
58beach:
59  if (vec)
60    del_fvec(vec);
61  if (s)
62    del_aubio_source_custom(s);
63  return err;
64}
65
66int test_wrong_params(void)
67{
68  char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
69  uint_t samplerate = 44100;
70  uint_t hop_size = 512;
71  uint_t channels, read = 0;
72  fvec_t *vec;
73  fmat_t *mat;
74  aubio_source_custom_t *s;
75
76  if (new_aubio_source_custom(0,    samplerate, hop_size)) return 1;
77  if (new_aubio_source_custom("\0", samplerate, hop_size)) return 1;
78  if (new_aubio_source_custom(uri,          -1, hop_size)) return 1;
79  if (new_aubio_source_custom(uri,           0,        0)) return 1;
80
81  s = new_aubio_source_custom(uri, samplerate, hop_size);
82  if (!s) return 1;
83  channels = aubio_source_custom_get_channels(s);
84
85  // vector to read downmixed samples
86  vec = new_fvec(hop_size);
87  // matrix to read individual channels
88  mat = new_fmat(channels, hop_size);
89
90  if (aubio_source_custom_get_samplerate(s) != samplerate) return 1;
91
92  // read first hop_size frames
93  aubio_source_custom_do(s, vec, &read);
94  if (read != hop_size) return 1;
95
96  // seek to 0
97  if(aubio_source_custom_seek(s, 0)) return 1;
98
99  // read again as multiple channels
100  aubio_source_custom_do_multi(s, mat, &read);
101  if (read != hop_size) return 1;
102
103  // close the file (optional)
104  aubio_source_custom_close(s);
105  // test closing the file a second time
106  aubio_source_custom_close(s);
107
108  del_aubio_source_custom(s);
109  del_fmat(mat);
110  del_fvec(vec);
111
112  return run_on_default_source(base_main);
113}
114
115#else /* HAVE_AUBIO_SOURCE_CUSTOM */
116
117int base_main(int argc, char** argv)
118{
119  PRINT_ERR("aubio was not compiled with aubio_source_"
120          aubio_source_custom ", failed running %s with %d args\n",
121          argv[0], argc);
122  return 0;
123}
124
125#endif /* HAVE_AUBIO_SOURCE_CUSTOM */
Note: See TracBrowser for help on using the repository browser.