[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [FIXED] saytime kills sound



Hugo Vanwoerkom wrote:
Camaleón wrote:
On Fri, 31 Dec 2010 11:42:42 +0100, Elimar Riesebieter wrote:

* Camaleón [101230 17:23 +0000]:
[...]
Nope, it's not even visible :-?
Don't bother us with wasteful stuff.

That sounds a bit rough... what do you exactly consider is "wasteful" in helping people?

See [0]. Saytime is actually
unusable.

[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=587124

Well, that can explain some things (distorted sound output) but once you are stuck and lost your sound at all, it would be nice to know how to restore it without the needing of restarting the system.


There is something funny going on: when you get the source you do not get the Debian version: because that mentions using sox and there is no sox call through execl in saytime.c.


So I took the source that one gets with 'apt-get source saytime' and
changed it:

1. Don't write to /dev/audio but use excl to call sox to write to /dev/dsp.
2. Generate the deb with 'dpkg-buildpackage -uc -us -rfakeroot' and then execute the binary through the alsa-oss wrapper, like so: 'aoss saytime'

That says the time clearly and does not kill the sound.

I enclose the patch as an attachment, if such a thing is possible.

Hugo







--- saytime.c	2010-12-30 10:15:26.000000000 -0600
+++ /home/hugo/saytime.1.0-22.build/saytime-1.0/saytime.c	2010-12-31 17:04:54.000000000 -0600
@@ -12,6 +12,7 @@
 */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <time.h>
 #include <sys/file.h>
 #include <sys/fcntl.h>
@@ -30,6 +31,7 @@
 ** Then use Sun's sound demo to dissect the lines into separate files.
 ** It's not really that much work, it took me about an hour.
 */
+#define MAX_STR_LEN 512
 
 #define PH_ONE		1
 #define PH_TWO		2
@@ -63,6 +65,7 @@
 #define PH_SECONDS	30
 
 void saynumber(), saydigit(), sayphrase(), sayfile(), sayclose();
+char * 		call_program_and_get_last_line_of_output 	(char *call);
 
 main( argc, argv )
 int argc;
@@ -387,60 +390,26 @@
 char *filename;
     {
     int filefd;
-    int r, w;
-    unsigned char buf[1024];
     char pathname[200];
 
-    if ( audiofd == -1 )
-	{
-	audiofd = open( "/dev/audio", O_WRONLY | O_NDELAY );
-	if ( audiofd < 0 )
-	    {
-	    perror( "opening /dev/audio" );
-	    exit( 1 );
-	    }
-	}
+    char parm1[200];
+    char parm2[200];
 
-//    (void) sprintf( pathname, "%s/%s", SOUND_DIR, filename );
     (void) sprintf( pathname, "%s/%s", "/home/hugo/saytime.1.0-22.build/saytime-1.0/sounds", filename );
+
     filefd = open( pathname, O_RDONLY );
-    if ( filefd < 0 )
-	{
+    if ( filefd < 0 ) {
 	perror( "opening audio file" );
 	exit( 1 );
-	}
+    }
+    close( filefd );
 
-    for ( ; ; )
-	{
-	r = read( filefd, buf, sizeof(buf) );
-	if ( r < 0 )
-	    {
-	    perror( "reading from audio file" );
-	    exit( 1 );
-	    }
-	if ( r == 0 )
-	    break;
+    sprintf(parm1,"cat %s | sox -t.ul - -t ossdsp /dev/dsp",pathname);
+    sprintf(parm2,"%s",call_program_and_get_last_line_of_output(parm1));
 
-	for ( ; ; )
-	    {
-	    w = write( audiofd, buf, r );
-	    if ( w < 0 )
-		{
-		perror( "writing to audio device" );
-		exit( 1 );
-		}
-	    if ( w != 0 )
-		break;
-	    usleep( 1000 );
-	    }
-	if ( w != r )
-	    {
-	    (void) fprintf( stderr, "read returned %d, write returned %d\n", r, w );
-	    exit( 1 );
-	    }
-	}
-    close( filefd );
-    }
+    usleep( 1000 );
+
+}
 
 void
 sayclose( )
@@ -449,3 +418,40 @@
 	close( audiofd );
     audiofd = -1;
     }
+
+/*************************************************************************
+ * *call_program_and_get_last_line_of_ouput() -- Hugo Rabson             *
+ *                                                                       *
+ * Purpose:  Run a program. Save its last line of output. Return it.     *
+ * Called by:...                                                         *
+ * Params:   call         call to executable w/params                    *
+ * Returns:  char*        pointer to static string containing last line  *
+ *                        of output of executable (stdout+stderr)        *   
+ *************************************************************************/
+
+char *
+call_program_and_get_last_line_of_output (char *call)
+{
+    /** buffers ******************************************************/
+    static char result[MAX_STR_LEN];
+    char tmp[MAX_STR_LEN];
+
+    /** pointers *****************************************************/
+    FILE *fin;
+
+    /** initialize data **********************************************/
+    result[0] = '\0';
+
+    /***********************************************************************/
+    if ((fin = popen (call, "r"))) {
+	for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin); fgets (tmp, MAX_STR_LEN, fin)) {
+	    if (strlen (tmp) > 1) {
+		strcpy (result, tmp);
+	    }
+	}
+	pclose (fin);
+    }
+//  strip_spaces (result);
+    return (result);
+}
+

Reply to: