File: 104-Add-alsa-support-allow-selection-of-output-type-via-.patch

package info (click to toggle)
saytime 1.0-36
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 704 kB
  • sloc: sh: 5,750; ansic: 588; makefile: 20
file content (127 lines) | stat: -rw-r--r-- 4,379 bytes parent folder | download | duplicates (8)
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
From 81c5ccf9716d88ef17e7f988747e7ba2ac23d332 Mon Sep 17 00:00:00 2001
From: Rob Browning <rlb@defaultvalue.org>
Date: Sat, 3 Mar 2012 14:45:03 -0600
Subject: [PATCH 3/4] Add alsa support; allow selection of output type via
 '-t'.

See the changes to the saytime.1 manpage for further information.
---
 saytime.c        |   47 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 44 insertions(+), 14 deletions(-)

diff --git a/saytime.c b/saytime.c
index c08e587..d4241eb 100644
--- a/saytime.c
+++ b/saytime.c
@@ -29,7 +29,6 @@
 #include <sys/wait.h>
 #include <signal.h>
 
-#define DEFAULT_SOUND_DEVICE "/dev/audio"
 #define DEFAULT_SOUND_DIR "/usr/share/saytime"
 #define DEFAULT_TIME_FORMAT "%P%l%M%S"
 #define DEFAULT_INTERVAL 1
@@ -94,6 +93,7 @@ It took about 10 minutes.
 #define PH_PM		36
 
 int opt_to_stdout = 0;
+char *opt_output_type = NULL;
 char *opt_sound_device = NULL;
 char *opt_sound_dir = DEFAULT_SOUND_DIR;
 char *opt_time_format = NULL;
@@ -115,9 +115,9 @@ char *argv[];
     long clock;
     struct tm *t;
 #if defined TTEST
-    char *opt_string="v:r:co:d:f:h:H:N:C:";
+    char *opt_string="v:t:r:co:d:f:h:H:N:C:";
 #else
-    char *opt_string="v:r:co:d:f:h";
+    char *opt_string="v:t:r:co:d:f:h";
 #endif
     int  op ;
 	pid_t fpid;
@@ -149,6 +149,8 @@ char *argv[];
 						   break;
                case 'c' :  opt_to_stdout = 1;
                            break;
+               case 't' :  opt_output_type = optarg;
+                           break;
                case 'o' :  opt_sound_device = optarg;
                            break;
                case 'd' :  opt_sound_dir = optarg;
@@ -173,8 +175,11 @@ char *argv[];
 	printf("Specifying alternate device and stdout makes no sense.\n");
 	usage();
     }
-    else if (opt_sound_device == NULL)
-	opt_sound_device = DEFAULT_SOUND_DEVICE;
+
+    if (opt_to_stdout && opt_output_type != NULL) {
+	printf("Specifying output type and stdout makes no sense.\n");
+	usage();
+    }
 
     if (opt_time_format == NULL)
         opt_time_format = DEFAULT_TIME_FORMAT;
@@ -231,7 +236,7 @@ char *argv[];
 void  
 usage( ) 
     {
-    fprintf( stderr, "Usage: saytime [-ch] [-v lvl] [-r sec] [-d dir] [-f fmt] [-o dev]\n" );
+    fprintf( stderr, "Usage: saytime [-ch] [-v lvl] [-r sec] [-d dir] [-f fmt] [-o dev] [-t type]\n" );
     fprintf( stderr, "Speak the current time through the computer's sound device.\n\n" );
     fprintf( stderr, "Options:\n" );
     fprintf( stderr, " -v lvl\tset volume level\n" );
@@ -242,8 +247,8 @@ usage( )
     fprintf( stderr, " -f fmt\tspecify alternate time format [%s]\n",
         DEFAULT_TIME_FORMAT ) ;
     fprintf( stderr, " -h\tbrief help message\n" );
-    fprintf( stderr, " -o dev\tspecify audio device [%s]\n", 
-        DEFAULT_SOUND_DEVICE );
+    fprintf( stderr, " -o dev\tspecify audio device\n");
+    fprintf( stderr, " -t typ\tspecify output type (oss, alsa, ...)\n");
     exit( 1 );
     }
 
@@ -688,16 +693,32 @@ sayfile( filename )
   else if (pid == 0)
   {
     /* child */
+
+    if (opt_output_type == NULL && opt_sound_device == NULL && !opt_to_stdout)
+      /* Use sox's -d to pick a reasonable default output. */
+      execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume,
+            "-t.ul", "-c", "1", pathname, "-d", NULL);
+
     if (opt_to_stdout)
     {
-      execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume,"-t.ul", "-c", "1",
-            pathname, "-t", "raw", "/dev/stdout", NULL);
+      opt_output_type = "raw";
+      opt_sound_device = "/dev/stdout";
     }
-    else
+    else if (opt_sound_device != NULL && opt_output_type == NULL)
     {
-      execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume,"-t.ul", "-c", "1",
-            pathname, "-t", "ossdsp", opt_sound_device, NULL);
+      /* Fall back to historic behavior. */
+      opt_output_type = "ossdsp";
+      opt_sound_device = "/dev/audio";
     }
+
+    if (opt_sound_device != NULL)
+      execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume,
+            "-t.ul", "-c", "1", pathname, "-t", opt_output_type,
+            opt_sound_device, NULL);
+    else
+      execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume,
+            "-t.ul", "-c", "1", pathname, "-t", opt_output_type, NULL);
+
     fprintf(stderr, "execl failed\n");
     exit(1);
   }
-- 
1.7.9.1