Changeset 248da64 for tests/src/io


Ignore:
Timestamp:
Mar 3, 2013, 7:30:40 PM (12 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
26775a3
Parents:
c71aa44
Message:

tests/src/io: improve examples

Location:
tests/src/io
Files:
6 edited

Legend:

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

    rc71aa44 r248da64  
    1 #include <stdio.h>
    21#include <aubio.h>
    3 #include "config.h"
     2#include "utils_tests.h"
    43
    5 char_t *path = "/home/piem/archives/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav";
    6 char_t *outpath = "/var/tmp/test.wav";
     4int main (int argc, char **argv)
     5{
     6  sint_t err = 0;
    77
    8 int main(){
    9   int err = 0;
     8  if (argc < 3) {
     9    err = 2;
     10    PRINT_ERR("not enough arguments\n");
     11    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate]\n", argv[0]);
     12    return err;
     13  }
     14
    1015  uint_t samplerate = 44100;
    1116  uint_t hop_size = 512;
    12   uint_t read = hop_size;
     17  uint_t n_frames = 0, read = 0;
     18
     19  char_t *source_path = argv[1];
     20  char_t *sink_path = argv[2];
     21  if ( argc == 4 ) samplerate = atoi(argv[3]);
     22
    1323  fvec_t *vec = new_fvec(hop_size);
    14   aubio_source_t * i = new_aubio_source(path, samplerate, hop_size);
    15   aubio_sink_t *   o = new_aubio_sink(outpath, samplerate);
     24  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
     25  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
     26  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
    1627
    17   if (!i || !o) { err = -1; goto beach; }
     28  if (!i || !o) { err = 1; goto beach; }
    1829
    19   while ( read == hop_size ) {
     30  do {
    2031    aubio_source_do(i, vec, &read);
    2132    aubio_sink_do(o, vec, read);
    22   }
     33    n_frames += read;
     34  } while ( read == hop_size );
     35
     36  PRINT_MSG("%d frames read from %s\n written to %s at %dHz\n",
     37      n_frames, source_path, sink_path, samplerate);
    2338
    2439beach:
     
    2843  return err;
    2944}
    30 
  • tests/src/io/test-sink_apple_audio_file.c

    rc71aa44 r248da64  
    1 #include <stdio.h>
    21#include <aubio.h>
    3 #include "config.h"
     2#include "utils_tests.h"
    43
    5 char_t *path = "/Users/piem/archives/sounds/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav";
    6 char_t *outpath = "/var/tmp/test.wav";
     4int main (int argc, char **argv)
     5{
     6  sint_t err = 0;
    77
    8 int main(){
    9   int err = 0;
     8  if (argc < 3) {
     9    err = 2;
     10    PRINT_ERR("not enough arguments\n");
     11    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate]\n", argv[0]);
     12    return err;
     13  }
     14
    1015#ifdef __APPLE__
    1116  uint_t samplerate = 44100;
    1217  uint_t hop_size = 512;
    13   uint_t read = hop_size;
     18  uint_t n_frames = 0, read = 0;
     19
     20  char_t *source_path = argv[1];
     21  char_t *sink_path = argv[2];
     22  if ( argc == 4 ) samplerate = atoi(argv[3]);
     23
    1424  fvec_t *vec = new_fvec(hop_size);
    15   aubio_source_apple_audio_t * i = new_aubio_source_apple_audio(path, samplerate, hop_size);
    16   aubio_sink_apple_audio_t *   o = new_aubio_sink_apple_audio(outpath, samplerate);
     25  aubio_source_apple_audio_t *i = new_aubio_source_apple_audio(source_path, samplerate, hop_size);
     26  if (samplerate == 0 ) samplerate = aubio_source_apple_audio_get_samplerate(i);
     27  aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, samplerate);
    1728
    18   if (!i || !o) { err = -1; goto beach; }
     29  if (!i || !o) { err = 1; goto beach; }
    1930
    20   while ( read == hop_size ) {
     31  do {
    2132    aubio_source_apple_audio_do(i, vec, &read);
    2233    aubio_sink_apple_audio_do(o, vec, read);
    23   }
     34    n_frames += read;
     35  } while ( read == hop_size );
     36
     37  PRINT_MSG("%d frames read from %s\n written to %s at %dHz\n",
     38      n_frames, source_path, sink_path, samplerate);
    2439
    2540beach:
     
    2843  del_fvec(vec);
    2944#else
    30   fprintf(stderr, "ERR: aubio was not compiled with aubio_source_apple_audio\n");
     45  PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
     46  err = 3;
    3147#endif /* __APPLE__ */
    3248  return err;
    3349}
    34 
  • tests/src/io/test-sink_sndfile.c

    rc71aa44 r248da64  
    1 #include <stdio.h>
    21#include <aubio.h>
    3 #include "config.h"
     2#include "utils_tests.h"
    43
    5 char_t *path = "/home/piem/archives/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav";
    6 char_t *outpath = "/var/tmp/test.wav";
     4int main (int argc, char **argv)
     5{
     6  sint_t err = 0;
    77
    8 int main(){
    9   int err = 0;
     8  if (argc < 3) {
     9    err = 2;
     10    PRINT_ERR("not enough arguments\n");
     11    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate]\n", argv[0]);
     12    return err;
     13  }
     14
    1015#ifdef HAVE_SNDFILE
    1116  uint_t samplerate = 44100;
    1217  uint_t hop_size = 512;
    13   uint_t read = hop_size;
     18  uint_t n_frames = 0, read = 0;
     19
     20  char_t *source_path = argv[1];
     21  char_t *sink_path = argv[2];
     22  if ( argc == 4 ) samplerate = atoi(argv[3]);
     23
    1424  fvec_t *vec = new_fvec(hop_size);
    1525  aubio_source_sndfile_t * i = new_aubio_source_sndfile(path, samplerate, hop_size);
     26  if (samplerate == 0 ) samplerate = aubio_source_sndfile_get_samplerate(i);
    1627  aubio_sink_sndfile_t *   o = new_aubio_sink_sndfile(outpath, samplerate);
    1728
    18   if (!i || !o) { err = -1; goto beach; }
     29  if (!i || !o) { err = 1; goto beach; }
    1930
    20   while ( read == hop_size ) {
     31  do {
    2132    aubio_source_sndfile_do(i, vec, &read);
    2233    aubio_sink_sndfile_do(o, vec, read);
    23   }
     34    n_frames += read;
     35  } while ( read == hop_size );
     36
     37  PRINT_MSG("%d frames read from %s\n written to %s at %dHz\n",
     38      n_frames, source_path, sink_path, samplerate);
    2439
    2540beach:
     
    2843  del_fvec(vec);
    2944#else
    30   fprintf(stderr, "ERR: aubio was not compiled with aubio_source_sndfile\n");
     45  PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
     46  err = 3;
    3147#endif /* HAVE_SNDFILE */
    3248  return err;
    3349}
    34 
  • tests/src/io/test-source.c

    rc71aa44 r248da64  
    1 #include <stdio.h>
    21#include <aubio.h>
     2#include "utils_tests.h"
    33
    4 char_t *path = "/Users/piem/archives/sounds/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav";
    5 //char_t *path = "/Users/piem/Downloads/Keziah Jones - Where's Life.mp3";
    6 
    7 int main(){
    8   uint_t samplerate = 32000;
    9   uint_t hop_size = 1024;
    10   uint_t read = hop_size;
    11   fvec_t *vec = new_fvec(hop_size);
    12   aubio_source_t* s = new_aubio_source(path, samplerate, hop_size);
    13 
    14   if (!s) return -1;
    15 
    16   while ( read == hop_size ) {
    17     aubio_source_do(s, vec, &read);
    18     fprintf(stdout, "%d [%f, %f, ..., %f]\n", read, vec->data[0], vec->data[1], vec->data[read - 1]);
     4int main (int argc, char **argv)
     5{
     6  uint_t err = 0;
     7  if (argc < 2) {
     8    err = 2;
     9    PRINT_ERR("not enough arguments\n");
     10    PRINT_MSG("usage: %s <source_path> [samplerate]\n", argv[0]);
     11    return err;
    1912  }
    2013
    21   del_aubio_source(s);
     14  uint_t samplerate = 32000;
     15  uint_t hop_size = 256;
     16  uint_t n_frames = 0, read = 0;
     17  if ( argc == 3 ) samplerate = atoi(argv[2]);
    2218
    23   return 0;
     19  char_t *source_path = argv[1];
     20
     21  fvec_t *vec = new_fvec(hop_size);
     22  aubio_source_t* s = new_aubio_source(source_path, samplerate, hop_size);
     23  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(s);
     24
     25  if (!s) { err = 1; goto beach; }
     26
     27  do {
     28    aubio_source_do(s, vec, &read);
     29    // fvec_print (vec);
     30    n_frames += read;
     31  } while ( read == hop_size );
     32
     33beach:
     34  del_aubio_source (s);
     35  del_fvec (vec);
     36
     37  return err;
    2438}
    25 
  • tests/src/io/test-source_apple_audio_file.c

    rc71aa44 r248da64  
    1 #include <stdio.h>
    21#include <aubio.h>
     2#include "utils_tests.h"
    33
    4 char_t *path = "/Users/piem/archives/sounds/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav";
    5 //char_t *path = "/Volumes/moving/moving/photos/gopro2/100GOPRO/GOPR4515.MP4";
    6 
    7 int main(){
    8 #ifdef __APPLE__
    9   uint_t samplerate = 32000;
    10   uint_t hop_size = 1024;
    11   uint_t read = hop_size;
    12   fvec_t *vec = new_fvec(hop_size);
    13   aubio_source_apple_audio_t * s = new_aubio_source_apple_audio(path, samplerate, hop_size);
    14 
    15   if (!s) return -1;
    16 
    17   while ( read == hop_size ) {
    18     aubio_source_apple_audio_do(s, vec, &read);
    19     fprintf(stdout, "%d [%f, %f, ..., %f]\n", read, vec->data[0], vec->data[1], vec->data[read - 1]);
     4int main (int argc, char **argv)
     5{
     6  uint_t err = 0;
     7  if (argc < 2) {
     8    err = 2;
     9    PRINT_ERR("not enough arguments\n");
     10    PRINT_MSG("usage: %s <source_path> [samplerate]\n", argv[0]);
     11    return err;
    2012  }
    2113
    22   del_aubio_source_apple_audio(s);
     14#if __APPLE__
     15  uint_t samplerate = 32000;
     16  uint_t hop_size = 256;
     17  uint_t n_frames = 0, read = 0;
     18  if ( argc == 3 ) samplerate = atoi(argv[2]);
     19
     20  char_t *source_path = argv[1];
     21
     22  fvec_t *vec = new_fvec(hop_size);
     23  aubio_source_apple_audio_t * s = new_aubio_source_apple_audio(source_path, samplerate, hop_size);
     24  if (samplerate == 0 ) samplerate = aubio_source_apple_audio_get_samplerate(s);
     25
     26  if (!s) { err = 1; goto beach; }
     27
     28  do {
     29    aubio_source_apple_audio_do(s, vec, &read);
     30    // fvec_print (vec);
     31    n_frames += read;
     32  } while ( read == hop_size );
     33
     34beach:
     35  del_aubio_source_apple_audio (s);
     36  del_fvec (vec);
    2337#else
    24   fprintf(stderr, "ERR: aubio was not compiled with aubio_source_apple_audio\n");
     38  err = 3;
     39  PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
    2540#endif /* __APPLE__ */
    2641  return 0;
    2742}
    28 
  • tests/src/io/test-source_sndfile.c

    rc71aa44 r248da64  
    1 #include <stdio.h>
    21#include <aubio.h>
    3 #include "config.h"
     2#include "utils_tests.h"
    43
    5 char_t *path = "/home/piem/archives/samples/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav";
     4int main (int argc, char **argv)
     5{
     6  uint_t err = 0;
     7  if (argc < 2) {
     8    err = 2;
     9    PRINT_ERR("not enough arguments\n");
     10    PRINT_MSG("usage: %s <source_path> [samplerate]\n", argv[0]);
     11    return err;
     12  }
    613
    7 int main(){
    8   int err = 0;
    914#ifdef HAVE_SNDFILE
    10   uint_t samplerate = 8000;
    11   uint_t hop_size = 512;
    12   uint_t read = hop_size;
     15  uint_t samplerate = 32000;
     16  uint_t hop_size = 256;
     17  uint_t n_frames = 0, read = 0;
     18  if ( argc == 3 ) samplerate = atoi(argv[2]);
     19
     20  char_t *source_path = argv[1];
     21
    1322  fvec_t *vec = new_fvec(hop_size);
    14   aubio_source_sndfile_t * s = new_aubio_source_sndfile(path, samplerate, hop_size);
     23  aubio_source_sndfile_t * s = new_aubio_source_sndfile(source_path, samplerate, hop_size);
     24  if (samplerate == 0 ) samplerate = aubio_source_sndfile_get_samplerate(s);
    1525
    1626  if (!s) { err = 1; goto beach; }
    1727
    18   while ( read == hop_size ) {
     28  do {
    1929    aubio_source_sndfile_do(s, vec, &read);
    20     if (read == 0) break;
    21     fprintf(stdout, "%d [%f, %f, ..., %f]\n", read, vec->data[0], vec->data[1], vec->data[read - 1]);
    22   }
     30    // fvec_print (vec);
     31    n_frames += read;
     32  } while ( read == hop_size );
    2333
    2434beach:
    25   del_aubio_source_sndfile(s);
    26   del_fvec(vec);
     35  del_aubio_source_sndfile (s);
     36  del_fvec (vec);
    2737#else
    28   fprintf(stderr, "ERR: aubio was not compiled with aubio_source_sndfile\n");
     38  PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
    2939  err = 2;
    3040#endif /* HAVE_SNDFILE */
    3141  return err;
    3242}
    33 
Note: See TracChangeset for help on using the changeset viewer.