Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

by giulienk (Curate)
on Feb 11, 2003 at 18:50 UTC ( #234490=perlmeditation: print w/replies, xml ) Need Help??

I ask for some feedback on, a new module i wrote. This is meant to use the computer beeper in some fancier ways.
NB: this module works only on Linux now and requires an external program! (beep)
#functional simple way use Beep; beep($freq, $milliseconds); #OO more musical way use Beep; my $beeper = Beep->new(); #lilypond subset syntax accepted my $music = "g f bes c'8 f d4 c8 f d4 bes, c' g, f2"; # Pictures at an Exhibition by Modest Mussorgsky $beeper->play( $music );
Download the whole thing from my CPAN directory.
Look at for more info about Lilypond format.

Some questions:

  • Is the namespace fine?
  • Is anybody willing to write an XS backend? (maybe even simply porting the beep program inside an XS module)
  • Any other suggestion is gladly accepted

Update: looking at the posts below i decided the namespace should be Audio::Beep (thanks everybody for the suggestions).
The Prima effort is pretty cool. Looking at the code i think we could take the Win32 beep code directly (i wrote "we" cause i think i will need some help in this). For the Linux backend i would stick to a "beep" (the program) implementation as the one found in Prima requires X.
About the problem with Makefile.PL requiring Perl 5.8: i'm sorry, i don't think we require 5.8. It's just that h2xs produced the Makefile.PL with that header and I didn't realize it was bad. I will update it in next version.

Update2: updated the link to point to my CPAN directory. The new version in Audio::Beep namespace also feature a PurePerl backend (doesn't require the beep executable for root users).


Replies are listed 'Best First'.
by tachyon (Chancellor) on Feb 11, 2003 at 19:38 UTC

    Very cute. A better namespace might be Acme::Beep as Acme:: is a namespace filled with fun but not necessarily vital bits and bobs. It is hard to justify Beep:: as a new top level namespace given that there are not likely to be that many related 'submodules' (except for Beep::beep of course). Audio::Beep is another option




by PodMaster (Abbot) on Feb 12, 2003 at 00:35 UTC
    You might wanna check out Prima (, in particular, the sound function in Prima::Utils.

    Here is from the samples

    # # Copyright (c) 1997-2002 The Protein Laboratory, University of Copen +hagen # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyrigh +t # notice, this list of conditions and the following disclaimer in +the # documentation and/or other materials provided with the distribut +ion. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' +AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, T +HE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LI +ABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQ +UENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE G +OODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTIO +N) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN A +NY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + OF # SUCH DAMAGE. # # $Id:,v 1.3 2002/05/14 13:22:26 dk Exp $ use Prima; use Prima::Utils; =pod =item NAME A sound example =item FEATURES Tests the implementation of apc_beep_tone() function. =cut my %octave = ( 'C' => 523, 'B' => 493, 'A#' => 466, 'A' => 440, 'G#' => 415, 'G' => 391, 'F#' => 369, 'F' => 349, 'E' => 329, 'D#' => 311, 'D' => 293, 'C#' => 277, ); $_ = 'E2D#EF2E2 G#2A4'; #$_ = 'AEAEAG#2 2EG#EG#A2 2EAEAG#2 2EG#EG#A2 AB2 BC2 C2BAG#A2 AB2 BC2 +C2BAG#A3'; for ( m/\G([A-G\s][\#\d]*)/g) { my $d = (s/(\d+)$//) ? $1 : 1; $octave{$_} ? Prima::Utils::sound( $octave{$_}, 100 * $d) : select(undef,undef,undef,0.1 * $d); }

    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.

by grantm (Parson) on Feb 11, 2003 at 19:58 UTC
    Is the namespace fine?

    How about Audio::Beep?

    Update And does the module really require Perl 5.8? The first line in Makefile.PL says it does so it won't install on my 5.6.1 system.

by valdez (Monsignor) on Feb 11, 2003 at 19:58 UTC

    Ciao giulienk! What about Audio::Beep?

    Ciao, Valerio

by belg4mit (Prior) on Feb 11, 2003 at 20:42 UTC
    I would think Audio::Speaker or something to that effect (InternalSpeaker?) might be better, since you are clearly doing more than a monotone beep. Audio::Buzz? It's also probably non-optimal to assume beep is in your path (this is a strong reason to switch to XS). Alternatively you could use an environment variable to specify the path, or a parameter to pass to use, falling back on a hardcoded path of the default beep install location.

    I'm not belgian but I play one on TV.

by toma (Vicar) on Feb 12, 2003 at 05:59 UTC
    I think this is a really useful and fun module!

    I suggest Audio::Monophone, since the module is a simple monophonic perl musical instrument, which plays a sequence of single tones. If it played chords, it would be Audio::Polyphone.

    As a module author, you will get many requests for enhancements, especially since you have written such a charming module. I think you will receive suggestions about how to make your module work on other platforms.

    I would like to use your module in a client/server environment. I want programs on several different computers to connect to a computer on my desk and play a tune.

    For example, I would like to sound the 'red alert' when the warp core starts to overheat :-).

    It should work perfectly the first time! - toma

by samtregar (Abbot) on Feb 11, 2003 at 22:26 UTC
    Please consider finding a new name. Sooner or later Perl will definitely need a to support the BEEP network protocol ( Sure, it could be Net::BEEP, but I think it would be needlessly confusing to have a that doesn't have anything to do with BEEP.


by zentara (Archbishop) on Feb 12, 2003 at 23:28 UTC
    I like this. It gives me an easy way to audibly signal different errors. I see just 1 small glitch. On my suse linux system , and probably many other linux systems, beep is a predefined shell function. I got around it by changing the name of the c program to beepme, but it's something to consider. Maybe in your where you take the backtick on beep, you could specify the full path, /usr/bin/beep ?
by t'mo (Pilgrim) on Feb 12, 2003 at 17:47 UTC
      I didn't come up with any particular dialect or notation. I just took one standard i thought as cool, Lilypond. If you look close is also on the page you linked to. I wrote a parser just for a subset of that notation, adding the rpm "note".

      Of course other parsers could be wrote.


        My bad; I should have read your comments more carefully (not just the code sample). :-) (Lillypond is one of the music notations I had heard about and looked at a little, but found abc easier to work with.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://234490]
Approved by broquaint
Front-paged by gmax
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2021-03-05 17:34 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (113 votes). Check out past polls.