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

[timidity]: question about deep sleep & responsiveness



Hi,

I got a new laptop with a onboard sound system, without any hw synthesizer...
since I'm an MIDI diehard, I tried timidity... (which worked out of the box! THX!!)

Unfortunatly, the 10ms wakeup cycle in interface/alsaseq_c.c kills the battery pretty fast.
-> So, here's a quick patch to address this problem.

Yes, the logic is a bit oversized, a simple NULL instead of &timeout as select's last parameter, 
would do it as well. But I tried to "conserve" the old behaviour... because I don't know 
if some old/slow machines needs it this way.

So, is there any hope for my battery?
--- timidity-2.13.2/interface/alsaseq_c.c	2004-07-10 07:07:00.000000000 +0200
+++ timidity-2.13.2-fix/interface/alsaseq_c.c	2007-07-17 14:55:28.393628042 +0200
@@ -500,6 +500,7 @@ static void stop_playing(void)
 
 static void doit(struct seq_context *ctxp)
 {
+ 	int err, timeout_val = 10;
 	for (;;) {
 		while (snd_seq_event_input_pending(ctxp->handle, 1)) {
 			if (do_sequencer(ctxp))
@@ -532,10 +533,19 @@ static void doit(struct seq_context *ctx
 			struct timeval timeout;
 			FD_ZERO(&rfds);
 			FD_SET(ctxp->fd, &rfds);
-			timeout.tv_sec = 0;
-			timeout.tv_usec = 10000; /* 10ms */
-			if (select(ctxp->fd + 1, &rfds, NULL, NULL, &timeout) < 0)
+			timeout.tv_sec = (timeout_val / 1000);
+			timeout.tv_usec = (timeout_val % 1000) * 1000;
+			err = select(ctxp->fd + 1, &rfds, NULL, NULL, timeout_val < 0 ? NULL : &timeout);
+			if (err < 0)
 				goto __done;
+			else if (err == 0)
+				if (timeout_val < 1024)
+					timeout_val+=timeout_val;
+				else
+					timeout_val = -1;
+			else
+				timeout_val = 10;
+					
 		}
 	}
 

Reply to: