Morse Code sounder

The following LB code plays a supplied string variable as Morse code. There is no provision for variable rate.

It requires three wav files, for 'dit', 'dah' and space. These are available as Morse.zip along with the program text. NB this is a work-in-progress, so for example the quote mark code is not handled correctly. This was created for the Rosetta Code task, and the data is copied from the PureBASIC example there.

Omit or rem-out the 'nomainwin' line to see the screen output. If you don't like the tones, which I edited from a recorded Morse transmission in Audacity, you can easily make your own of different frequency or duration. And/or add random hiss for verisimilitude. Fading might be harder...



    nomainwin

    dim code$( 255)

    for i =1 to 61
        read a$
        code =asc( a$)
        read b$
        code$( code) =b$
    next i

  data "A",  ".-"
  data "B",  "-..."
  data "C",  "-.-."
  data "D",  "-.."
  data "E",  "."
  data "F",  "..-."
  data "G",  "--."
  data "H",  "...."
  data "I",  ".."
  data "J",  ".---"
  data "K",  "-.-"
  data "L",  ".-.."
  data "M",  "--"
  data "N",  "-."
  data "O",  "---"
  data "P",  ".--."
  data "Q",  "--.-"
  data "R",  ".-."
  data "S",  "..."
  data "T",  "-"
  data "U",  "..-"
  data "V",  "...-"
  data "W",  ".--"
  data "X",  "-..-"
  data "Y",  "-.--"
  data "Z",  "--.."
  data "Á",  "--.-"
  data "Ä",  ".-.-"
  data "É",  "..-.."
  data "Ñ",  "--.--"
  data "Ö",  "---."
  data "Ü",  "..--"
  data "1",  ".----"
  data "2",  "..---"
  data "3",  "...--"
  data "4",  "....-"
  data "5",  "....."
  data "6",  "-...."
  data "7",  "--..."
  data "8",  "---.."
  data "9",  "----."
  data "0",  "-----"
  data ",",  "--..--"
  data ".",  ".-.-.-"
  data "?",  "..--.."
  data ";",  "-.-.-"
  data ":",  "---..."
  data "/",  "-..-."
  data "-",  "-....-"
  data "'",  ".----."
  data "+",  ".-.-."
  data "-",  "-....-"
  data #DOUBLEQUOTE$, ".-..-."
  data "@",  ".--.-."
  data "(",  "-.--."
  data ")",  "-.--.-"
  data "_",  "..--.-"
  data "$",  "...-..-"
  data "&",  ".-..."
  data "=",  "---..."
  data " ",  " "
  ' data  "Done",""


    Send$ ="Hello World"
    Send$ =upper$( Send$)

    call SoundOut Send$

    end

    sub SoundOut i$
        for i =1 to len( i$)
            c$ =mid$( i$, i, 1)
            Morse$ =code$( asc( c$))
            print " "; c$; " ";
            call audio Morse$
        next i
    end sub

    sub audio m$
        for i =1 to len( m$)
            c$ =mid$( m$, i, 1)
            if c$ ="." then playwave "dit.wav", sync: print "."; else playwave "dah.wav", sync: print "-";
        next i
        playwave "gap.wav", sync
        playwave "gap.wav", sync
        print
    end sub