ref: d2af4085e1b9f8c0af6aad661a7059ac8690e037
dir: /examples/devaudioio.c/
#include <aubio.h> #include "config.h" #include "utils.h" #include "aubio_priv.h" #include "devaudioio.h" #include <bio.h> static Biobuf *f; static s16int *fbuf; static fvec_t *ibuf, *obuf; static int nframes; void new_aubio_devaudio(int hop_size) { if((f = Bopen("/dev/audio", OREAD)) == nil){ AUBIO_ERR("failed to open /dev/audio for reading\n"); AUBIO_QUIT(AUBIO_FAIL); } nframes = hop_size; ibuf = new_fvec(hop_size); obuf = new_fvec(hop_size); if(ibuf == nil || obuf == nil || (fbuf = malloc(nframes*2*2)) == nil){ AUBIO_ERR("no memory\n"); AUBIO_QUIT(AUBIO_FAIL); } } int aubio_devaudio_get_samplerate(void) { return 44100; } void aubio_devaudio_activate(aubio_process_func_t func, aubio_print_func_t printf) { double l; int i; while(9){ if(Bread(f, fbuf, nframes*2*2) != nframes*2*2) break; for(i = 0; i < nframes; i++){ fvec_get_sample(obuf, i); l = (fbuf[i*2+0] + fbuf[i*2+1]) / 8192; // ignoring right channel fvec_set_sample(ibuf, l, i); } func(ibuf, obuf); printf(); } }