summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-10-03 10:31:26 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-10-03 10:31:26 +0200
commitc64848b8ed70ae5931fb1cf12ef55088cc752a14 (patch)
tree18022beb53da689647d587b6b49575f4c65ac368
parent74ab445f767366c03424cacab5bda23a6e204944 (diff)
New aiorecord/aioplay stub programs.
-rw-r--r--src/Makefile.am5
-rw-r--r--src/aiorecord.cc135
-rw-r--r--src/airecord.cc146
3 files changed, 139 insertions, 147 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 78d117b..74ae706 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = aiomixer aioloop
+bin_PROGRAMS = aiomixer aioloop aiorecord
lib_LTLIBRARIES = libaudioio.la
libaudioio_la_LIBADD = $(ALSA_LIBS)
@@ -37,3 +37,6 @@ EXTRA_DIST = \
sink.h \
source.h
+install-exec-hook:
+ ln -s $(DESTDIR)$(bindir)/aiorecord$(EXEEXT) \
+ $(DESTDIR)$(bindir)/aioplay$(EXEEXT)
diff --git a/src/aiorecord.cc b/src/aiorecord.cc
new file mode 100644
index 0000000..4da5366
--- /dev/null
+++ b/src/aiorecord.cc
@@ -0,0 +1,135 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * aiorecord.cc
+ *
+ * Fri Oct 3 09:58:45 CEST 2014
+ * Copyright 2014 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of LibAudioIO.
+ *
+ * LibAudioIO is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * LibAudioIO is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with LibAudioIO; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "audioin.h"
+
+#include <stdio.h>
+#include <getopt.h>
+#include <config.h>
+
+#include "device.h"
+#include "mixer.h"
+
+static const char version_str[] =
+"aiomixer v" VERSION "\n"
+;
+
+static const char copyright_str[] =
+"Copyright (C) 2014 Bent Bisballe Nyeng - Aasimon.org.\n"
+"This is free software. You may redistribute copies of it under the terms of\n"
+"the GNU Lesser General Public License "
+"<http://www.gnu.org/licenses/lgpl.html>.\n"
+"There is NO WARRANTY, to the extent permitted by law.\n"
+"\n"
+"Written by Bent Bisballe Nyeng (deva@aasimon.org)\n"
+;
+
+static const char usage_str[] =
+"Usage: %s options\n"
+"Options:\n"
+" -L, --list List cards.\n"
+" -d, --device s Set device to s (default 'default').\n"
+" -c, --channels n Set number of channels to n (default 2).\n"
+" -s, --samplerate n Set samplerate to n (default 48000).\n"
+" -f, --file s Set output file to s (default '/dev/stdout').\n"
+" -v, --version Print version information and exit.\n"
+" -h, --help Print this message and exit.\n"
+;
+
+int main(int argc, char *argv[])
+{
+ std::string device = "default";
+ std::string file = "/dev/stdout";
+ int samplerate = 48000;
+ int channels = 2;
+
+ int c;
+ int option_index = 0;
+ while(1) {
+ static struct option long_options[] = {
+ {"list", no_argument, 0, 'L'},
+ {"device", required_argument, 0, 'd'},
+ {"channels", required_argument, 0, 'c'},
+ {"samplerate", required_argument, 0, 's'},
+ {"file", required_argument, 0, 'f'},
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "hvLd:c:s:f:",
+ long_options, &option_index);
+
+ if (c == -1)
+ break;
+
+ switch(c) {
+ case 'L':
+ list = true;
+ break;
+
+ case 'd':
+ device = optarg;
+ break;
+
+ case 'c':
+ channels = atoi(optarg);
+ break;
+
+ case 's':
+ samplerate = atoi(optarg);
+ break;
+
+ case 'f':
+ file = optarg;
+ break;
+
+ case '?':
+ case 'h':
+ printf("%s", version_str);
+ printf(usage_str, argv[0]);
+ return 0;
+
+ case 'v':
+ printf("%s", version_str);
+ printf("%s", copyright_str);
+ return 0;
+
+ default:
+ break;
+ }
+ }
+
+ Device dev(device);
+
+ Source *src = dev.getSource(device);
+ if(!src) {
+ printf("Could not find source device: %s\n", device.c_str());
+ }
+
+ return 0;
+}
diff --git a/src/airecord.cc b/src/airecord.cc
deleted file mode 100644
index e340832..0000000
--- a/src/airecord.cc
+++ /dev/null
@@ -1,146 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * audioin.h
- *
- * Fri Apr 8 15:37:21 CEST 2011
- * Copyright 2011 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of libaudioin.
- *
- * LibAudioIO is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * LibAudioIO is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with LibAudioIO; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "audioin.h"
-
-int main(int argc, char *argv[])
-{
- int err = 0;
-
- if(argc < 4) {
- printf("Usage %s samplerate num_channels output_file\n", argv[0]);
- return 1;
- }
-
- int samplerate = atoi(argv[1]);
- int channels = atoi(argv[2]);
- char *fname = argv[3];
-
- struct ai_t *ai = ai_init(&err, "default", "Capture", samplerate, channels);
- if(ai == NULL || err) printf("Error: %d\n", err);
-
- if(!ai) {
- printf("Trying alternative mixer interface (not running on an InterCom)\n");
- //ai = ai_init(&err, "default", "H/W Multi", samplerate, channels);
- ai = ai_init(&err, "default", "Capture", samplerate, channels);
- if(ai == NULL || err) printf("Error: %d\n", err);
- }
-
- /** Chip: IDT 92HD83C1C5
-Simple mixer control 'Master',0
-Simple mixer control 'Headphone',0
-Simple mixer control 'Speaker',0
-Simple mixer control 'Front',0
-Simple mixer control 'Front Mic Jack Mode',0
-Simple mixer control 'Line',0
-Simple mixer control 'Line Jack Mode',0
-Simple mixer control 'Line',1
-Simple mixer control 'Mic',0
-Simple mixer control 'IEC958',0
-Simple mixer control 'IEC958 Default PCM',0
-Simple mixer control 'Capture',0
-Simple mixer control 'Capture',1
-Simple mixer control 'Input Source',0
-Simple mixer control 'Input Source',1
-Simple mixer control 'Internal Mic',0
- **/
-
- /** Chip: Realtek ALC662 rev1
-Simple mixer control 'Master',0
-Simple mixer control 'Headphone',0
-Simple mixer control 'Front',0
-Simple mixer control 'Front Mic',0
-Simple mixer control 'Front Mic Boost',0
-Simple mixer control 'Surround',0
-Simple mixer control 'Center',0
-Simple mixer control 'LFE',0
-Simple mixer control 'Line',0
-Simple mixer control 'IEC958',0
-Simple mixer control 'IEC958 Default PCM',0
-Simple mixer control 'Capture',0
-Simple mixer control 'Capture',1
-Simple mixer control 'Auto-Mute Mode',0
-Simple mixer control 'Input Source',0
-Simple mixer control 'Input Source',1
-Simple mixer control 'Rear Mic',0
-Simple mixer control 'Rear Mic Boost',0
- **/
- // 'Capture' record enabled, Input Source: 'Line'
-
-
-
-
- ai_set_mixer_level(&err, ai, 0, 1.0);
- ai_set_mixer_level(&err, ai, 1, 1.0);
-
- short pcm[4096 * 10];
- FILE *fp = fopen(fname, "w");
- if(!fp) {
- printf("Could not write %s\n", fname);
- return 1;
- }
-
- for(size_t i = 0; i < 500; i++) {
- memset(pcm, 0, sizeof(pcm));
- int r = ai_read(&err, ai, pcm, sizeof(pcm));
- if(r < 0 || err) printf("Error: %d\n", err);
-
- // for(int j = 0; j < 20; j++) pcm[j] = 0;
-
- int bufsz = r / (sizeof(short) * channels) ;
- int offset = 160 / (1024 / bufsz);
- int len = 16;
- short start[] = {
- pcm[ (bufsz - offset - 2) * 2],
- pcm[ (bufsz - offset - 2) * 2 + 1]
- };
- short stop[] = {
- pcm[ (bufsz - offset + len + 1) * 2],
- pcm[ (bufsz - offset + len + 1) * 2 + 1]
- };
- for(int j = 0; j < len; j++) {
- float d = (float)j / (float)len;
- pcm[(bufsz - offset + j - 1) * 2] = start[0] * (1 - d) + stop[0] * d;
- pcm[(bufsz - offset + j - 1) * 2 + 1] = start[1] * (1 - d) + stop[1] * d;
- }
- /*
- short m = 32000;
- pcm[(bufsz - offset) * 2] = m;
- pcm[(bufsz - offset) * 2 + 1] = m;
- pcm[(bufsz - offset + len) * 2] = m;
- pcm[(bufsz - offset + len) * 2 + 1] = m;
- */
- if(fwrite(pcm, r, 1, fp)) {}
- }
- fclose(fp);
- ai_close(&err, ai);
-
- return 0;
-}