Changeset 3a96d3d


Ignore:
Timestamp:
Dec 6, 2018, 11:32:11 AM (4 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/pitchshift, feature/timestretch
Children:
dec789b
Parents:
283a619a
Message:

[tests] improve pitchshift tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/src/effects/test-pitchshift.c

    r283a619a r3a96d3d  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5int test_wrong_params(void);
    46
    57int main (int argc, char **argv)
     
    79  sint_t err = 0;
    810
    9   if (argc < 4) {
    10     err = 2;
    11     PRINT_ERR("not enough arguments\n");
    12     PRINT_MSG("usage: %s <input_path> <output_path> <transpose> [mode] [hop_size] [samplerate]\n", argv[0]);
    13     PRINT_MSG(" with <transpose> a number of semi tones in the range [-24, 24]\n");
    14     PRINT_MSG(" and [mode] in 'default', 'crispness:0', ..., 'crispness:6'\n");
     11  if (argc < 3) {
     12    PRINT_ERR("not enough arguments, running tests\n");
     13    err = test_wrong_params();
     14    PRINT_MSG("usage: %s <input_path> <output_path> [transpose] ", argv[0]);
     15    PRINT_MSG("[mode] [hop_size] [samplerate]\n");
     16    PRINT_MSG(" with [transpose] a number of semi tones in the range "
     17        " [-24, 24], and [mode] in 'default', 'crispness:0',"
     18        " 'crispness:1', ... 'crispness:6'\n");
    1519    return err;
    1620  }
     
    2529  char_t *mode = "default";
    2630
    27   transpose = atof(argv[3]);
     31  transpose = 0.;
    2832
     33  if ( argc >= 4 ) transpose = atof(argv[3]);
    2934  if ( argc >= 5 ) mode = argv[4];
    3035  if ( argc >= 6 ) hop_size = atoi(argv[5]);
    3136  if ( argc >= 7 ) samplerate = atoi(argv[6]);
    32   if ( argc >= 8 ) {
    33     err = 2;
    34     PRINT_ERR("too many arguments\n");
    35     return err;
    36   }
    3737
    3838  fvec_t *vec = new_fvec(hop_size);
     
    4848  if (!o) { err = 1; goto beach_sink; }
    4949
    50   aubio_pitchshift_t *ps = new_aubio_pitchshift(mode, transpose, hop_size, samplerate);
     50  aubio_pitchshift_t *ps =
     51    new_aubio_pitchshift(mode, transpose, hop_size, samplerate);
    5152  if (!ps) { err = 1; goto beach_pitchshift; }
    5253
     
    5960  } while ( read == hop_size );
    6061
    61   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
     62  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n",
    6263      n_frames, samplerate, n_frames / hop_size,
    63       source_path, sink_path);
     64      source_path);
     65  PRINT_MSG("wrote to %s with hop_size: %d, samplerate: %d, latency %d\n",
     66      sink_path, hop_size, samplerate, aubio_pitchshift_get_latency(ps));
    6467
    6568  del_aubio_pitchshift(ps);
     
    7477  return err;
    7578}
     79
     80int test_wrong_params(void)
     81{
     82  const char_t *mode = "default";
     83  smpl_t transpose = 0.;
     84  uint_t hop_size = 256;
     85  uint_t samplerate = 44100;
     86
     87  if (new_aubio_pitchshift("??", transpose, hop_size, samplerate)) return 1;
     88  if (new_aubio_pitchshift(mode,       28., hop_size, samplerate)) return 1;
     89  if (new_aubio_pitchshift(mode, transpose,        0, samplerate)) return 1;
     90  if (new_aubio_pitchshift(mode, transpose, hop_size,          0)) return 1;
     91
     92  aubio_pitchshift_t *p = new_aubio_pitchshift(mode, transpose,
     93      hop_size, samplerate);
     94  if (!p) return 1;
     95  if (!aubio_pitchshift_set_pitchscale(p, 0.1)) return 1;
     96  if (!aubio_pitchshift_set_transpose(p, -30)) return 1;
     97  del_aubio_pitchshift(p);
     98
     99  return run_on_default_source_and_sink(main);
     100}
Note: See TracChangeset for help on using the changeset viewer.