correction/improvement Re: GUI wrapper for timidity -ig with Firefox

Peter Garrett peter.garrett at optusnet.com.au
Fri Sep 14 04:18:12 BST 2007


I think my explanation and reasoning below are wrong :) So I'm posting a
better solution to the "sometimes start-up sounds glitchy" problem. The
fact that I'm hearing this may be because my machine is not very
up-to-date and powerful, so it may not be an issue for you. If it is, I
found a much better solution in "man timidity".

You can set the audio buffer - so if timidity starts too "early", you can
change the script to something like:

#!/bin/bash

TMP="$@"   

/usr/bin/timidity -ig -q 7/100 "$TMP"


the -q setting lets timidity buffer a bit before playing. (You can set this
lower or higher - for instance " -q 5/100"  or " -q 10/100 "  - small
changes make a large difference.

> > You wrote:
> >
> > > You may have wondered why it took me so long to put your script into
> > effect
> > > - apart from other chores, I had a rather steep learning curve to follow
> > to
> > > understand why and how this script works.  At least, I now know what a
> > > 'shebang' does.
> > >
> >
> > Ah, perhaps I should have explained more clearly. Actually I worked it out
> > by  trial and error ( only two errors - first the PATH error, which was
> > pretty spectacular, then the argument to timidity -ig . Just calling
> > timidity -ig without the "$@" does not work - it appears that when Firefox
> > uses an external "helper" app , it downloads  to a file in /tmp/ first ,
> > and passes the path to the file as argument to the application's command.
> >
> > If there is only one argument, "$1" should work as a substitute - but "$@"
> > includes all arguments, so a grouping of midis, for example, would be
> > loaded as a playlist. You can confirm this by running the wrapper script
> > on a directory containing a collection of midis.
> >
> > I have a directory named  "mid" containing only some midis I either made
> > or
> > downloaded a few years ago - running the wrapper script with the directory
> > as argument results in timidity loading all the midis as a "playlist".
> >
> > "timidity-wrapper" is in ~/bin, which is in my $PATH .  Thus:
> >
> > timidity-wrapper ~/mid/ &
> >
> > plays all the midis in ~/mid/
> >
> > This only works when the "script" uses "$@" - which includes all the
> > files.
> > Putting the arguments ( "$@" ) in a variable TMP just enables the sleep
> > statement on the second line - we've stored the arguments somewhere
> > temporarily.  After the "sleep" pause, timidity uses the contents of that
> > variable as its argument. If the pause is not included, timidity starts
> > ( as you know, quite quickly), and tries to begin playing while the
> > download is perhaps not quite complete.

Actually I am wrong here - all the sleep does is delay the start: it has
no apparent effect on the problem I originally thought it solved.

That's logical if you think more than a few seconds about it, as I failed
to do ...   ;-)

The issue is buffering rather than delaying the start. The hiccup
in the sound is apparently caused by the sharp spike in cpu that happens
at the beginning. Buffering appears to allow that spike to subside before
the actual playing begins.

> >
> > The quotes around "$@" and "$TMP" could be important - especially for odd
> > file names, lists as in the directory example, or file names with spaces.
> > Otherwise timidity would only "see" the first word rather than the whole
> > thing.

This appears to be wrong too :) Timidity seems to be more clever at
parsing file names than I thought it was.

Peter



More information about the ubuntu-au mailing list