]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Added option for mono output 277/head
authormike <mike@qtunes.org>
Sun, 24 Apr 2016 20:25:24 +0000 (21:25 +0100)
committermike <mike@qtunes.org>
Sun, 24 Apr 2016 20:25:24 +0000 (21:25 +0100)
common.h
player.c
shairport.c

index 7520b0c0e2bd6804d0f17d1a41f738ea46a287bf..25e24bbd50d5aa263b42252b12f7b79bcd338af2 100644 (file)
--- a/common.h
+++ b/common.h
@@ -77,6 +77,7 @@ typedef struct {
   int32_t ForkedDaapdLatency; // supplied with --ForkedDaapdLatency option
   int daemonise;
   int statistics_requested,use_negotiated_latencies;
+  int mono;
   char *cmd_start, *cmd_stop;
   int cmd_blocking;
   int tolerance; // allow this much drift before attempting to correct it
index a09030250ad56357dbcdd25dbcf0b50f32152940..041b02d65b72f3dacdbcd09499c88ab1ca36a867 100644 (file)
--- a/player.c
+++ b/player.c
@@ -378,6 +378,24 @@ void player_put_packet(seq_t seqno, uint32_t timestamp, uint8_t *data, int len)
                                        abuf->ready = 1;
                                        abuf->timestamp = timestamp;
                                        abuf->sequence_number = seqno;
+
+          if (config.mono) {
+            signed short *v = abuf->data;
+            int i;
+            int both;
+            for (i=frame_size;i;i--) {
+              int both = *v + *(v+1);
+              if (both > INT16_MAX) {
+                both = INT16_MAX;
+              } else if (both < INT16_MIN) {
+                both = INT16_MIN;
+              }
+              short sboth = (short)both;
+              *v++ = sboth;
+              *v++ = sboth;
+            }
+          }
+
         } else {
                debug(1,"Bad audio packet detected and discarded.");
                                        abuf->ready = 0;
index 931c270b61f4eaacbe1ff3b42312a22090eccad6..2bf7649d61b2abece19f106242c168020bb8950b 100644 (file)
@@ -207,6 +207,7 @@ void usage(char *progname) {
   printf("                            Executable scripts work, but must have #!/bin/sh (or "
          "whatever) in the headline.\n");
   printf("    -w, --wait-cmd          wait until the -B or -E programs finish before continuing.\n");
+  printf("    --mono                   convert all outgoing audio to mono.\n");
   printf("    -o, --output=BACKEND    select audio output method.\n");
   printf("    -m, --mdns=BACKEND      force the use of BACKEND to advertize the service.\n");
   printf("                            if no mdns provider is specified,\n");
@@ -253,6 +254,7 @@ int parse_options(int argc, char **argv) {
       {"on-start", 'B', POPT_ARG_STRING, &config.cmd_start, 0, NULL},
       {"on-stop", 'E', POPT_ARG_STRING, &config.cmd_stop, 0, NULL},
       {"wait-cmd", 'w', POPT_ARG_NONE, &config.cmd_blocking, 0, NULL},
+      {"mono", 0, POPT_ARG_NONE, &config.mono, 0, NULL},
       {"mdns", 'm', POPT_ARG_STRING, &config.mdns_name, 0, NULL},
       {"latency", 'L', POPT_ARG_INT, &config.userSuppliedLatency, 0, NULL},
       {"AirPlayLatency", 'A', POPT_ARG_INT, &config.AirPlayLatency, 0, NULL},
@@ -411,6 +413,16 @@ int parse_options(int argc, char **argv) {
           die("Invalid ignore_volume_control option choice \"%s\". It should be \"yes\" or \"no\"");
       }
 
+      /* Get the mono setting */
+      if (config_lookup_string(config.cfg, "general.mono", &str)) {
+        if (strcasecmp(str, "no") == 0)
+          config.mono = 0;
+        else if (strcasecmp(str, "yes") == 0)
+          config.mono = 1;
+        else
+          die("Invalid mono option choice \"%s\". It should be \"yes\" or \"no\"");
+      }
+
       /* Get the regtype -- the service type and protocol, separated by a dot. Default is "_raop._tcp" */
       if (config_lookup_string(config.cfg, "general.regtype", &str))
         config.regtype = strdup(str);
@@ -960,6 +972,7 @@ int main(int argc, char **argv) {
   debug(1, "drift tolerance is %d frames.", config.tolerance);
   debug(1, "password is \"%s\".", config.password);
   debug(1, "ignore_volume_control is %d.", config.ignore_volume_control);
+  debug(1, "mono is %d.", config.mono);
   debug(1, "disable_synchronization is %d.", config.no_sync);
   debug(1, "audio backend desired buffer length is %d.",
         config.audio_backend_buffer_desired_length);