ref: d2af4085e1b9f8c0af6aad661a7059ac8690e037
parent: e00515a9d7d03b30af0d55f8b217e3fff28a0fdf
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Mon Aug 21 11:45:41 EDT 2023
examples: add a dumb /dev/audio support
--- /dev/null
+++ b/examples/devaudioio.c
@@ -1,0 +1,53 @@
+#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();
+ }
+}
--- /dev/null
+++ b/examples/devaudioio.h
@@ -1,0 +1,3 @@
+void new_aubio_devaudio(int hop_size);
+int aubio_devaudio_get_samplerate(void);
+void aubio_devaudio_activate(aubio_process_func_t f, aubio_print_func_t print);
--- a/examples/mkfile
+++ b/examples/mkfile
@@ -1,13 +1,15 @@
</$objtype/mkfile
TARG=aubiomfcc aubionotes aubioonset aubiopitch aubioquiet aubiotrack
-CFLAGS=$CFLAGS -DHAVE_CONFIG_H=1 -DHAVE_AUBIO_DOUBLE=1 -D__plan9__ -p -I../src/plan9 -I../src -I/sys/include/npe
+CFLAGS=$CFLAGS -DHAVE_CONFIG_H=1 -DHAVE_AUBIO_DOUBLE=1 -DHAVE_DEVAUDIO=1 -D__plan9__ -p -I../src/plan9 -I../src -I/sys/include/npe
LIB=../src/libaubio.a$O
OFILES=\
- utils.$O
+ devaudioio.$O\
+ utils.$O\
HFILES=\
+ devaudioio.h\
parse_args.h\
utils.h\
--- a/examples/parse_args.h
+++ b/examples/parse_args.h
@@ -28,6 +28,7 @@
extern int quiet;
// input / output
extern int usejack;
+extern int usedevaudio;
extern char_t *source_uri;
extern char_t *sink_uri;
// general stuff
@@ -234,6 +235,7 @@
break;
case 'j':
usejack = 1;
+ usedevaudio = 1;
break;
case 'N':
miditap_note = (smpl_t) atoi (optarg);
@@ -331,6 +333,9 @@
#if HAVE_JACK
verbmsg("No input source given, using jack\n");
usejack = 1;
+#elif HAVE_DEVAUDIO
+ verbmsg("No input source given, using devaudio\n");
+ usedevaudio = 1;
#else
errmsg("Error: no arguments given (and no available audio input)\n");
errmsg(" consider recompiling with jack support (--enable-jack)\n");
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -31,10 +31,14 @@
#ifdef HAVE_JACK
#include "jackio.h"
#endif /* HAVE_JACK */
+#ifdef HAVE_DEVAUDIO
+#include "devaudioio.h"
+#endif /* HAVE_DEVAUDIO */
int verbose = 0;
int quiet = 0;
int usejack = 0;
+int usedevaudio = 0;
// input / output
char_t *sink_uri = NULL;
char_t *source_uri = NULL;
@@ -97,7 +101,7 @@
/* parse command line arguments */
parse_args (argc, argv);
- if (!usejack) {
+ if (!usejack && !usedevaudio) {
debug ("Opening files ...\n");
this_source = new_aubio_source ((char_t*)source_uri, samplerate, hop_size);
if (this_source == NULL) {
@@ -127,6 +131,13 @@
samplerate = aubio_jack_get_samplerate (jack_setup);
source_uri = "jack";
#endif /* HAVE_JACK */
+#ifdef HAVE_DEVAUDIO
+ } else {
+ debug ("devaudio init ...\n");
+ new_aubio_devaudio (hop_size);
+ samplerate = aubio_devaudio_get_samplerate ();
+ source_uri = "devaudio";
+#endif /* HAVE_DEVAUDIO */
}
input_buffer = new_fvec (hop_size);
output_buffer = new_fvec (hop_size);
@@ -147,7 +158,7 @@
{
uint_t read = 0;
- if (usejack) {
+ if (usejack || usedevaudio) {
#ifdef HAVE_JACK
ev.size = MAX_MIDI_EVENT_SIZE;
@@ -157,6 +168,10 @@
debug ("Processing (Ctrl+C to quit) ...\n");
pause ();
aubio_jack_close (jack_setup);
+#elif HAVE_DEVAUDIO
+ debug ("devaudio activation ...\n");
+ debug ("Processing (Del to quit) ...\n");
+ aubio_devaudio_activate (process_func, print);
#else /* HAVE_JACK */
usage (stderr, 1);
outmsg ("Compiled without jack output, exiting.\n");