Changeset 7e2eef4 for tests


Ignore:
Timestamp:
Dec 17, 2018, 3:12:01 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
d81e16d
Parents:
dc72476
Message:

[tests] sync test-sink_vorbis

File:
1 edited

Legend:

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

    rdc72476 r7e2eef4  
    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}
Note: See TracChangeset for help on using the changeset viewer.