Bug#433643: making timidity's alsaseq interface _powerfriendly_
Package: timidity
Severity: wishlist
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 are TWO approaches to save the battery life.
(hopefully the patches don't get screwed up...)
Thanks,
Chr.
Either FIRST:
--- timidity-2.13.2/interface/alsaseq_c.c.org 2007-07-18 14:44:57.675654262 +0200
+++ timidity-2.13.2/interface/alsaseq_c.c 2007-07-18 14:45:20.324944971 +0200
@@ -529,12 +529,9 @@ static void doit(struct seq_context *ctx
}
if (! ctxp->active || ! IS_STREAM_TRACE) {
fd_set rfds;
- 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)
+ if (select(ctxp->fd + 1, &rfds, NULL, NULL, NULL) < 0)
goto __done;
}
}
-EOP-
or SECOND:
--- 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;
+
}
}
-EOP-
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.22-rc3-git6-wireless (SMP w/2 CPU cores; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Reply to: