source: tests/src/spectral/test-awhitening.c @ 4b943729

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since 4b943729 was 986131d, checked in by Eduard Müller <mueller.eduard@googlemail.com>, 8 years ago

Intel IPP support for aubio

See emuell/aubio/ intel_ipp2 for details please

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include <aubio.h>
2#include "utils_tests.h"
3
4int main (int argc, char **argv)
5{
6  aubio_init();
7
8  sint_t err = 0;
9
10  if (argc < 3) {
11    err = 2;
12    PRINT_ERR("not enough arguments\n");
13    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
14    return err;
15  }
16
17  uint_t samplerate = 0;
18  uint_t win_size = 1024;
19  uint_t hop_size = 512;
20  uint_t n_frames = 0, read = 0;
21
22  char_t *source_path = argv[1];
23  char_t *sink_path = argv[2];
24
25  if ( argc >= 4 ) samplerate = atoi(argv[3]);
26  if ( argc >= 5 ) hop_size = atoi(argv[4]);
27  if ( argc >= 6 ) {
28    err = 2;
29    PRINT_ERR("too many arguments\n");
30    return err;
31  }
32
33  fvec_t *vec = new_fvec(hop_size);
34  fvec_t *out = new_fvec(hop_size); // output buffer
35  fvec_t *scale = new_fvec(hop_size);
36  cvec_t *fftgrain = new_cvec(win_size); // fft norm and phase
37  if (!vec) { err = 1; goto beach_fvec; }
38
39  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
40  if (!i) { err = 1; goto beach_source; }
41
42  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
43
44  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
45  if (!o) { err = 1; goto beach_sink; }
46
47  aubio_pvoc_t *pv = new_aubio_pvoc(win_size, hop_size);
48
49  aubio_spectral_whitening_t *awhitening =
50    new_aubio_spectral_whitening (win_size, hop_size, samplerate);
51
52  aubio_spectral_whitening_set_relax_time(awhitening, 20.);
53  fvec_set_all(scale, 3.);
54
55  PRINT_MSG("spectral whitening relaxation time is %f\n",
56      aubio_spectral_whitening_get_relax_time(awhitening));
57
58  do {
59    aubio_source_do(i, vec, &read);
60    aubio_pvoc_do(pv, vec, fftgrain);
61    // apply spectral whitening
62    aubio_spectral_whitening_do(awhitening, fftgrain);
63    // rebuild the signal
64    aubio_pvoc_rdo(pv, fftgrain, out);
65    // make louder
66    fvec_weight(out, scale);
67    // make sure we dont saturate
68    fvec_clamp(out, 1.);
69    // write output
70    aubio_sink_do(o, out, read);
71    n_frames += read;
72  } while ( read == hop_size );
73
74  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
75      n_frames, samplerate, n_frames / hop_size,
76      source_path, sink_path);
77
78  del_aubio_sink(o);
79beach_sink:
80  del_aubio_source(i);
81beach_source:
82  del_fvec(vec);
83beach_fvec:
84  aubio_cleanup();
85  return err;
86}
87
Note: See TracBrowser for help on using the repository browser.