1 // morse.hxx -- Morse code generation class 2 // 3 // Written by Curtis Olson, started March 2001. 4 // 5 // Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License as 9 // published by the Free Software Foundation; either version 2 of the 10 // License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, but 13 // WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 // General Public License for more details. 16 // 17 // You should have received a copy of the GNU General Public License 18 // along with this program; if not, write to the Free Software 19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 // 21 22 23 #ifndef _MORSE_HXX 24 #define _MORSE_HXX 25 26 #include "soundgenerator.hxx" 27 #include <simgear/compiler.h> 28 #include <simgear/sound/soundmgr.hxx> 29 30 31 // Quoting from http://www.kluft.com/~ikluft/ham/morse-intro.html by 32 // Ian Kluft KO6YQ <ikluft@kluft.com> 33 // 34 // [begin quote] 35 // 36 // What is the Standard for Measuring Morse Code Speed? 37 // 38 // [This was adapted from the Ham Radio FAQ which used to be posted on UseNet.] 39 // 40 // The word PARIS was chosen as the standard length for CW code 41 // speed. Each dit counts for one count, each dah counts for three 42 // counts, intra-character spacing is one count, inter-character 43 // spacing is three counts and inter-word spacing is seven counts, so 44 // the word PARIS is exactly 50 counts: 45 // 46 // PPPPPPPPPPPPPP AAAAAA RRRRRRRRRR IIIIII SSSSSSSSSS 47 // di da da di di da di da di di di di di di 48 // 1 1 3 1 3 1 1 3 1 1 3 3 1 1 3 1 1 3 1 1 1 3 1 1 1 1 1 7 = 50 49 // ^ ^ ^ 50 // ^Intra-character ^Inter-character Inter-word^ 51 // 52 // So 5 words-per-minute = 250 counts-per-minute / 50 counts-per-word 53 // or one count every 240 milliseconds. 13 words-per-minute is one 54 // count every ~92.3 milliseconds. This method of sending code is 55 // sometimes called "Slow Code", because at 5 wpm it sounds VERY SLOW. 56 // 57 // The "Farnsworth" method is accomplished by sending the dits and 58 // dahs and intra-character spacing at a higher speed, then increasing 59 // the inter-character and inter-word spacing to slow the sending 60 // speed down to the desired speed. For example, to send at 5 wpm with 61 // 13 wpm characters in Farnsworth method, the dits and 62 // intra-character spacing would be 92.3 milliseconds, the dah would 63 // be 276.9 milliseconds, the inter-character spacing would be 1.443 64 // seconds and inter-word spacing would be 3.367 seconds. 65 // 66 // [end quote] 67 68 // Ok, back to Curt 69 70 // My formulation is based dit = 1 count, dah = 3 counts, 1 count for 71 // intRA-character space, 3 counts for intER-character space. Target 72 // is 5 wpm which by the above means 1 count = 240 milliseconds. 73 // 74 // AIM 1-1-7 (f) states that the frequency of the tone should be 1020 75 // Hz for the VOR ident. 76 77 78 // manages everything we need to know for an individual sound sample 79 class FGMorse : public FGSoundGenerator { 80 81 private: 82 83 unsigned char hi_dit[ DIT_SIZE ] ; 84 unsigned char lo_dit[ DIT_SIZE ] ; 85 unsigned char hi_dah[ DAH_SIZE ] ; 86 unsigned char lo_dah[ DAH_SIZE ] ; 87 unsigned char space[ SPACE_SIZE ] ; 88 89 unsigned char cust_dit[ DIT_SIZE ] ; 90 unsigned char cust_dah[ DAH_SIZE ] ; 91 92 static FGMorse * _instance; 93 94 bool cust_init( const int freq ); 95 // allocate and initialize sound samples 96 bool init(); 97 98 public: 99 static const int BYTES_PER_SECOND = 22050; 100 // static const int BEAT_LENGTH = 240; // milleseconds (5 wpm) 101 static const int BEAT_LENGTH = 92; // milleseconds (13 wpm) 102 static const int TRANSITION_BYTES = BYTES_PER_SECOND/200; // aka (int)(0.005 * BYTES_PER_SECOND); 103 static const int COUNT_SIZE = BYTES_PER_SECOND * BEAT_LENGTH / 1000; 104 static const int DIT_SIZE = 2 * COUNT_SIZE; // 2 counts 105 static const int DAH_SIZE = 4 * COUNT_SIZE; // 4 counts 106 static const int SPACE_SIZE = 3 * COUNT_SIZE; // 3 counts 107 static const int LO_FREQUENCY = 1020; // AIM 1-1-7 (f) specified in Hz 108 static const int HI_FREQUENCY = 1350; // AIM 1-1-7 (f) specified in Hz 109 110 111 FGMorse(); 112 ~FGMorse(); 113 114 static FGMorse * instance(); 115 116 // make a SimpleSound morse code transmission for the specified string 117 SGSoundSample *make_ident( const std::string& id, 118 const int freq = LO_FREQUENCY ); 119 }; 120 121 122 123 #endif // _MORSE_HXX 124 125 126