int main (int argc, char **argv) { uint_t err = 0; if (argc < 2) { err = 2; PRINT_ERR("not enough arguments\n"); PRINT_MSG("read a wave file as a mono vector\n"); PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]); PRINT_MSG("examples:\n"); PRINT_MSG(" - read file.wav at original samplerate\n"); PRINT_MSG(" %s file.wav\n", argv[0]); PRINT_MSG(" - read file.wav at 32000Hz\n"); PRINT_MSG(" %s file.aif 32000\n", argv[0]); PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n"); PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]); return err; } #if __APPLE__ uint_t samplerate = 0; uint_t hop_size = 256; uint_t n_frames = 0, read = 0; if ( argc == 3 ) samplerate = atoi(argv[2]); if ( argc == 4 ) hop_size = atoi(argv[3]); char_t *source_path = argv[1]; aubio_source_apple_audio_t * s = new_aubio_source_apple_audio(source_path, samplerate, hop_size); if (!s) { err = 1; goto beach; } fvec_t *vec = new_fvec(hop_size); if (samplerate == 0 ) samplerate = aubio_source_apple_audio_get_samplerate(s); do { aubio_source_apple_audio_do(s, vec, &read); fvec_print (vec); n_frames += read; } while ( read == hop_size ); PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate, n_frames / hop_size, source_path); del_fvec (vec); del_aubio_source_apple_audio (s); beach: #else err = 3; PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n"); #endif /* __APPLE__ */ return 0; }
aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) { aubio_source_t * s = AUBIO_NEW(aubio_source_t); #ifdef __APPLE__ s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); if (s->source) return s; #else /* __APPLE__ */ #if HAVE_SNDFILE s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); if (s->source) return s; #endif /* HAVE_SNDFILE */ #endif /* __APPLE__ */ AUBIO_ERROR("failed creating aubio source with %s\n", uri); AUBIO_FREE(s); return NULL; }
aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) { aubio_source_t * s = AUBIO_NEW(aubio_source_t); AUBIO_MSG("new aubio source"); #if HAVE_LIBAV AUBIO_MSG("libav"); s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate); s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek); s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec); return s; } #endif /* HAVE_LIBAV */ #ifdef __APPLE__ AUBIO_MSG("apple"); s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate); s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek); s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio); return s; } #endif /* __APPLE__ */ #if HAVE_SNDFILE AUBIO_MSG("sndfile"); s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate); s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek); s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile); return s; } #endif /* HAVE_SNDFILE */ AUBIO_ERROR("failed creating aubio source with %s\n", uri); AUBIO_FREE(s); return NULL; }
int main (int argc, char **argv) { sint_t err = 0; if (argc < 3) { err = 2; PRINT_ERR("not enough arguments\n"); PRINT_MSG("usage: %s <input_path> <output_path> [samplerate]\n", argv[0]); return err; } #ifdef __APPLE__ uint_t samplerate = 44100; uint_t hop_size = 512; uint_t n_frames = 0, read = 0; char_t *source_path = argv[1]; char_t *sink_path = argv[2]; if ( argc == 4 ) samplerate = atoi(argv[3]); fvec_t *vec = new_fvec(hop_size); aubio_source_apple_audio_t *i = new_aubio_source_apple_audio(source_path, samplerate, hop_size); if (samplerate == 0 ) samplerate = aubio_source_apple_audio_get_samplerate(i); aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, samplerate); if (!i || !o) { err = 1; goto beach; } do { aubio_source_apple_audio_do(i, vec, &read); aubio_sink_apple_audio_do(o, vec, read); n_frames += read; } while ( read == hop_size ); PRINT_MSG("%d frames read from %s\n written to %s at %dHz\n", n_frames, source_path, sink_path, samplerate); beach: del_aubio_source_apple_audio(i); del_aubio_sink_apple_audio(o); del_fvec(vec); #else err = 3; PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n"); #endif /* __APPLE__ */ return err; }
aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) { aubio_source_t * s = AUBIO_NEW(aubio_source_t); #ifdef HAVE_LIBAV s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_avcodec_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_avcodec_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate); s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration); s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek); s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close); s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec); return s; } #endif /* HAVE_LIBAV */ #ifdef HAVE_SOURCE_APPLE_AUDIO s->source = (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_apple_audio_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_apple_audio_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate); s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration); s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek); s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close); s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio); return s; } #endif /* HAVE_SOURCE_APPLE_AUDIO */ #ifdef HAVE_SNDFILE s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_sndfile_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_sndfile_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate); s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration); s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek); s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close); s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile); return s; } #endif /* HAVE_SNDFILE */ #ifdef HAVE_WAVREAD s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size); if (s->source) { s->s_do = (aubio_source_do_t)(aubio_source_wavread_do); s->s_do_multi = (aubio_source_do_multi_t)(aubio_source_wavread_do_multi); s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels); s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate); s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration); s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek); s->s_close = (aubio_source_close_t)(aubio_source_wavread_close); s->s_del = (del_aubio_source_t)(del_aubio_source_wavread); return s; } #else /* failover message */ #if !(defined(HAVE_LIBAV) || defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SNDFILE)) AUBIO_ERROR("source: failed creating aubio source with %s" " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size); #endif /* failover */ #endif /* HAVE_WAVREAD */ AUBIO_FREE(s); return NULL; }