summaryrefslogtreecommitdiff
path: root/src/aiorecord.cc
blob: cfcc3923cc47f4760c0527a2f74e247d911b0013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* -*- 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 <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;
  bool list = false;

  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;
    }
  }

  if(list) {
    // TODO
  }

  Device dev(device);

  Source *src = dev.getSource(device, samplerate, channels);
  if(!src) {
    printf("Could not find source device: %s\n", device.c_str());
  }

  return 0;
}