2007-07-03 Just Whistle

When you’re feeling in the dumps Don’t be silly chumps Just purse your lips and whistle - that’s the thing. – Always Look On the Bright Side of Life by Monthy Python

Always Look On the Bright Side of Life by Monthy Python

A post on the O’Reilly Radar about (purported) magic ¹ led me to Whistle while you work to run commands on your computer. It had a link to sndpeek, which includes a binary for OSX! It looks very cool. 😄

O’Reilly Radar

¹

Whistle while you work to run commands on your computer

sndpeek

looks very cool

I also downloaded the Perl script described in the article – `cmdWhistle.pl`. Unfortunately, it doesn’t work on my system:

Alpinobombus:~/Desktop alex$ sndpeek --print --nodisplay | perl cmdWhistle.pl -c
Can't locate sys/syscall.ph in @INC (did you run h2ph?) (@INC contains: /opt/local/lib/perl5/5.8.8/darwin-2level /opt/local/lib/perl5/5.8.8 /opt/local/lib/perl5/site_perl/5.8.8/darwin-2level /opt/local/lib/perl5/site_perl/5.8.8 /opt/local/lib/perl5/site_perl /opt/local/lib/perl5/vendor_perl/5.8.8/darwin-2level /opt/local/lib/perl5/vendor_perl/5.8.8 /opt/local/lib/perl5/vendor_perl .) at cmdWhistle.pl line 6.

Google to the rescue! Using h2ph to Translate C ​#include Files.

Using h2ph to Translate C ​#include Files

Except that...

Alpinobombus:/usr/include alex$ h2ph *.h */*.h
Destination directory /opt/local/lib/perl5/site_perl/5.8.8/darwin-2level doesn't exist or isn't a directory

Yikes, `/opt/local` is the MacPorts thing I haven’t used in ages...

A quick check tells me that this must be correct:

$ which h2ph
/opt/local/bin/h2ph
$ which perl
/opt/local/bin/perl

So I guess it should be easy to fix:

sudo mkdir -p /opt/local/lib/perl5/site_perl/5.8.8/darwin-2level
sudo h2ph *.h */*.h

At least now `sndpeek --print --nodisplay | perl cmdWhistle.pl -c` produces no error message. It produces no output, either. I guess that I will have to build from source... The IBM article says “Ensure that the output of the program is actually written at the end of every print window by flushing the output. Change the above section to read...”

So I downloaded the sources, unpacked them, switched to the `sndpeek-1.3/src/sndpeek` directory and ran `make osx`... And it worked! 😄

Let’s patch the source... I added `fflush(stdout);` twice, recompiled, and did a `sudo cp sndpeek /usr/local/bin/` to install it.

Test it again! `sndpeek --print --nodisplay | perl cmdWhistle.pl -c` actually produces some output. But unfortunately, every whistle results in an error... Oh no!

enter a tone sequence:
substr outside of string at cmdWhistle.pl line 41, <STDIN> line 471.
Use of uninitialized value in length at cmdWhistle.pl line 43, <STDIN> line 471.
Tone: 24.00 ## last: [0000000000] curr: [0000000000] difference is: 0
substr outside of string at cmdWhistle.pl line 41, <STDIN> line 488.
Use of uninitialized value in length at cmdWhistle.pl line 43, <STDIN> line 488.
...

The problem on line 43 involves getEpochMicroSeconds. Yikes!

sub getEpochMicroSeconds {

  my $TIMEVAL_T = "LL";      # LL for microseconds
  my $timeVal = pack($TIMEVAL_T, ());

  syscall(&SYS_gettimeofday, $timeVal, 0) != -1 or die "micore seconds: $!";
  my @vals =  unpack( $TIMEVAL_T, $timeVal );
...

It seems that `$val[0]` and `$val[1]` are both 0 on my system. 🙁

I don’t think I want to delve into the depths of system calls, and thus I will postpone this project...

Hahaha. You know how it is. Go out for lunch. Talk about life and all that. Come back. See the light.

Perl’s Time::HiRes does just the thing! See cmdWhistle.pl patch.

cmdWhistle.pl patch

Here we go. This is what I added to `~/.toneFile`:

32.00 31.00 _#_ 0 580445 _#_ /bin/echo "Yes Master?" _#_ testing

Now run as a daemon: `sndpeek --print --nodisplay | perl cmdWhistle.pl`

And what do we get? More errors, of course:

Use of uninitialized value in concatenation (.) or string at cmdWhistle.pl line 117, <TONEFILE> line 2.
Use of uninitialized value in concatenation (.) or string at cmdWhistle.pl line 118, <TONEFILE> line 2.
Use of uninitialized value in concatenation (.) or string at cmdWhistle.pl line 119, <TONEFILE> line 2.
...

It turns out that these were caused by an empty line in the `.toneFile`. The parsing of the file could easily be improved, but there’s not enough space left on this post’s margins for me to write down the patch.

So, I’ve been adding a few more lines to my `.toneFile`, and I’ve been sitting in front of my iBook for the last few minutes, whistling at it. No effect.

Noooo!

What a waste of time.

I knew it.

Anyway. If you run `sndpeek --print --nodisplay | perl cmdWhistle.pl -v` you’ll get some debugging output. And if you ask me, there must still be bugs in that scrip. Sometimes I’ll get sudden bursts of activity:

...
TIME MATCH t 0 b 0 c 0 d 0
NOTE DISSONANCE t 0 b 29.00 c 32.00
TIME MATCH t 0 b 0 c 0 d 0
NOTE DISSONANCE t 0 b 29.00 c 32.00
TIME MATCH t 0 b 0 c 0 d 0
listen timeout - resetting tones
listen timeout - resetting tones

Looks like a loop running wild to me.

​#Software ​#Audio ​#sndpeek

Comments

(Please contact me if you want to remove your comment.)

Any luck getting this working... I started down the same path as you, but after googling some errors quickly found your page. Any words of wisdom to get it working? So the problem is with the script?

– madteckhead 2009-05-30 18:14 UTC

madteckhead

---

Sorry, I don’t remember it ever working. I think I was way too frustrated with all the time spent for nothing.

– Alex Schroeder 2009-05-30 21:38 UTC

Alex Schroeder