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


In reply to Re: DTMF Tone Generator by hardburn
in thread DTMF Tone Generator by Mr. Muskrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.