summaryrefslogtreecommitdiff
path: root/src/airecord.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/airecord.cc')
-rw-r--r--src/airecord.cc146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/airecord.cc b/src/airecord.cc
new file mode 100644
index 0000000..8a40edc
--- /dev/null
+++ b/src/airecord.cc
@@ -0,0 +1,146 @@
+/* -*- 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.
+ *
+ * libaudioin is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * libaudioin 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with libaudioin; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
+}