diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-10-03 11:27:07 +0200 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2014-10-03 11:27:07 +0200 | 
| commit | e065e802b91ef146a882e0dd7fd080453542e09a (patch) | |
| tree | 2c3507920442f976994d47a6a799ab2b44edbd2b | |
| parent | 39209db5e36d77641bbf431042d433c13f2cf666 (diff) | |
New aiorecord/aioplay stub programs.
| -rw-r--r-- | src/aiorecord.cc | 53 | 
1 files changed, 51 insertions, 2 deletions
diff --git a/src/aiorecord.cc b/src/aiorecord.cc index 215d6b5..82cc9a1 100644 --- a/src/aiorecord.cc +++ b/src/aiorecord.cc @@ -28,6 +28,7 @@  #include <stdio.h>  #include <getopt.h>  #include <config.h> +#include <signal.h>  #include "device.h"  #include "mixer.h" @@ -54,6 +55,7 @@ static const char usage_str[] =  "  -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, --verbose       Print info while working\n"  "  -v, --version       Print version information and exit.\n"  "  -h, --help          Print this message and exit.\n"  ; @@ -64,6 +66,12 @@ typedef enum {    MODE_PLAY,  } aiomode_t; +volatile bool running = true; +void ctrl_c(int) +{ +  running = false; +} +  int main(int argc, char *argv[])  {    // This program acts as both a recorder and a player depending on which name @@ -82,6 +90,7 @@ int main(int argc, char *argv[])    int samplerate = 48000;    int channels = 2;    bool list = false; +  bool verbose = false;    int c;    int option_index = 0; @@ -92,12 +101,13 @@ int main(int argc, char *argv[])        {"channels", required_argument, 0, 'c'},        {"samplerate", required_argument, 0, 's'},        {"file", required_argument, 0, 'f'}, +      {"verbose", no_argument, 0, 'V'},        {"version", no_argument, 0, 'v'},        {"help", no_argument, 0, 'h'},        {0, 0, 0, 0}      }; -    c = getopt_long (argc, argv, "hvLd:c:s:f:", +    c = getopt_long (argc, argv, "hvLd:c:s:f:V",                       long_options, &option_index);      if (c == -1) @@ -124,6 +134,10 @@ int main(int argc, char *argv[])        file = optarg;        break; +    case 'V': +      verbose = true; +      break; +      case '?':      case 'h':        printf("%s", version_str); @@ -144,6 +158,8 @@ int main(int argc, char *argv[])      // TODO    } +  signal(SIGINT, ctrl_c); +    Device dev(device);    switch(mode) { @@ -153,17 +169,50 @@ int main(int argc, char *argv[])        if(!src) {          printf("Could not find source device: %s\n", device.c_str());        } + +      FILE *fp = fopen(file.c_str(), "w"); +      if(!fp) { +        printf("Could not open %s for writing: ", file.c_str()); +        perror(""); +        return 1; +      } + +      while(running) { +        char pcm[1024]; +        size_t size = src->readSamples(pcm, sizeof(pcm)); +        if(verbose) { +          short *p = (short*)pcm; +          size_t sz = size / sizeof(short); +          short max = 0; +          for(int i = 0; i < sz; i++) { +            if(abs(p[i]) > max) max = abs(p[i]); +          } +          printf("%d\n", (int)max); +        } +      } +      fclose(fp); + +      printf("done\n");      }      break; +    case MODE_PLAY:      {        Sink *sink = dev.getSink(device, samplerate, channels);        if(!sink) {          printf("Could not find sink device: %s\n", device.c_str());        } + +      FILE *fp = fopen(file.c_str(), "r"); +      if(!fp) { +        printf("Could not open %s for reading: ", file.c_str()); +        perror(""); +        return 1; +      }      }      break; -  default: + +  case MODE_UNKNOWN:      printf("Unknown mode '%s'.\n", prog);      return 1;    }  | 
