The code I used to generate the Morse is below: (I got it on the net, the sox line is to convert to unsigned wav for the Audio::Wav object in the Freqext module of toma)... it may have flaws as you point out :-) Also I did some sprintf rounding to make the timestamp and frequencies more readable.... the timestamps are actually more accurate.
#!/usr/bin/perl -w use Audio::Data; use Audio::Play; my $freq = 400; my $dot = 0.07; my $dash = 3*$dot; my %morse = ( A => '.-', B => '-...', C => '-.-.', D => '-..', E => '.', F => '..-.', G => '--.', H => '....', I => '..', J => '.---', K => '-.-', L=> '.-..', M => '--', N => '-.', O => '---', P => '.--.', Q => '--.-', R => '.-.', S => '...', T => '-', U => '..-', V => '...-', W => '.--', X => '-..-', Y => '-.--', Z => '--..', 1 => '.----', 2 => '..---', 3 => '...--', 4 => '....-', 5 => '.....', 6 => '-....', 7 => '--...', 8 => '---..', 9 => '----.', 0 => '-----', ' ' => ' '); my $au = Audio::Data->new(rate => 8000); sub morse { my ($au,$s) = @_; while (length $s) { my $sym = $morse{uc(substr($s,0,1))}; if (defined $sym) { while (length($sym)) { for (substr($sym,0,1)) { $au->tone($freq,$dot) if (/\./); $au->tone($freq,$dash) if (/-/); $au->silence(3*$dash) if (/\s/); } $au->silence($dot); substr($sym,0,1) = ""; } $au->silence($dash); } substr($s,0,1) = ""; } } foreach (@ARGV) { morse($au,$_); } my $svr = Audio::Play->new; $svr->play($au); open(F,">out.au") || die; $au->Save(\*F); close(F); system("sox out.au -u data/out1.wav");

But as I was trying to think of ways to overcome all these obstacles, the thought occurred.... why even use Morse? Frequency Shift Keying (30 different frequencies, separated by 250 Hz), with each freq assigned a letter or punctuation mark, would be so much more reliable, faster, and easier to decode with digital audio analysis.

I guess old Morse still has its uses though.


I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Morse code via sound card input by zentara
in thread Morse code via sound card input by aristotle73

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.