We were just talking about this in the CB this morning. You beat me to it, Muskrat (:
Here's an Audio::Beep version I was working out. I think I have the math worked out, but it's kinda hard since I'm not sure of the sample rate of a PC speaker.
#!/usr/local/bin/perl
use strict;
use warnings;
use Audio::Beep;
# Generate DTMF tones
#
use constant SAMPLE_RATE => 8000;
use constant PI => 3.14159;
use constant DURATION => 500;
my %tones = (
1 => [ 1209, 697 ],
2 => [ 1336, 697 ],
3 => [ 1477, 697 ],
a => [ 1633, 697 ],
4 => [ 1209, 770 ],
5 => [ 1336, 770 ],
6 => [ 1477, 770 ],
b => [ 1633, 770 ],
7 => [ 1209, 852 ],
8 => [ 1336, 852 ],
9 => [ 1477, 852 ],
c => [ 1633, 852 ],
* => [ 1209, 697 ],
0 => [ 1336, 697 ],
'#'=> [ 1477, 697 ],
d => [ 1633, 697 ],
);
my $number = pop;
$number =~ s/[-\(\)]//g;
my $i = 1;
foreach (split //, $number) {
my $time = $i / SAMPLE_RATE;
my ($f1, $f2) = @{ $tones{$_} };
my $freq = 63 * sin($time * 2 * PI * $f1);
$freq += 63 * sin($time * 2 * PI * $f2);
$freq += 128;
print "$_: $freq\n";
beep($freq, DURATION);
$i++;
}
----
Reinvent a rounder wheel.
Note: All code is untested, unless otherwise stated
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.