Page 1 of 1

text to morse transmitter

Posted: Mon Nov 30, 2015 2:46 pm
by Henko

Code: Select all

' test morsecode generator
' parameters hereafter
'
txt$ = "Hello Moscow, do you read me?"   ' text to be transmitted
instr = 18             ' melody instrument number for the signals
freq = 2000             ' pitch of the signals, frequency in Herz
wpm = 10   ' speed in words/minute ("PARIS" is the standard word)

dim morse$(123),notes$(12)
morse_init
m$=text2morse$(txt$) ! print txt$ ! print ! print m$
a$=morse2notes$(m$,instr,freq) ! print ! print a$
notes tempo 21.5*wpm ! notes set a$ ! notes play
go_on: if notes_time()<notes_length() then go_on 
end

' get the morse code for a piece of text
' space between caracters within a word is one space
' space between words consists of 3 spaces
' no check on permissible caracters
'
def text2morse$(t$)
if t$="" then return t$
last=len(t$)-1 ! m$=""
for i=0 to last
  tok$=mid$(t$,i,1)
  if tok$=" " then m$&="  " else m$&=.morse$(asc(tok$)) & " "
  next i
return m$
end def

' conversion of a morse coded string to a NOTES string
' mo$ = the morse coded string
' instr = the instrument number to be used for the sound
' freq = the frequency (pitch) to be used (in Herz)
' wpm = the speed in words ("PARIS") per minute
'
def morse2notes$(mo$,instr,freq)
n$=freq2note$(freq) ! n3$="Q." & n$ & "I"
not$=str$(instr) & ":" & "I"
for i=0 to len(mo$)-1
  t$=mid$(mo$,i,1)
  if t$="." then not$ &= n$
  if t$="-" then not$ &= n3$
  if t$=" " then not$ &= "R"
  not$ &= "R"
  next i
return not$
end def

' get the morse code for one caracter (token$)
' no check on permissible caracter
'
def get_morse$(token$) = .morse$(asc(token$))

' initialize the morse table
' permissible caracters can be found in the array :
'    morse_init.tok$() after initialization
' for convenience, lower case caracters are also accepted
'    they get the same code as their upper case companions
'
def morse_init
dim tok$(51),m$(51)
for i=0 to 11 ! read .notes$(i) ! next i
for i=1 to 50
  read tok$(i),m$(i) ! .morse$(asc(tok$(i)))=m$(i)
  if i<=26 then .morse$(asc(lowstr$(tok$(i))))=m$(i)
  next i
data "C","C#","D","D#","E","F","F#","G","G#","A","A#","B"
data "A",".-","B","-...","C","-.-.","D","-..","E","."
data "F","..-.","G","--.","H","....","I","..","J",".---"
data "K","-.-","L",".-..","M","--","N","-.","O","---"
data "P",".--.","Q","--.-","R",".-.","S","...","T","-"
data "U","..-","V","...-","W",".--","X","-..-","Y","-.--"
data "Z","--..","0","-----","1",".----","2","..---"
data "3","...--","4","....-","5",".....","6","-...."
data "7","--...","8","---..","9","-...."
data ".",".-.-.-",",","--..--","?","..--..","!","-.-.--"
data "-","-....-","/","-..-.",":","---...","'",".----."
data ")","-.--.-",";","-.-.-","(","-.--.","=","-...-"
data "@",".--.-.","&",".-..."
end def

' produce note and octave for a given frequency
'
def freq2note$(herz)
if herz<16.35 or herz>7902.13 then return ""
note=int(17.31234*ln(herz)-96.3763)
doct=floor(note/12) ! oct=4+doct ! note-=12*doct
return .notes$(note) & oct
end def

Re: text to morse transmitter

Posted: Mon Nov 30, 2015 3:00 pm
by Mr. Kibernetik
nice software
wpm=20 seems to be more realistic
maybe there are someone from Moscow, who knows... :D

Re: text to morse transmitter

Posted: Mon Nov 30, 2015 3:55 pm
by rbytes
Excellent, very precise. The pitch and precision are perfect. I agree that 20 wpm is closer to what I remember from my youth. I added my Dad's call letters to the message. :)

Re: text to morse transmitter

Posted: Thu Dec 03, 2015 1:59 pm
by Dav
You've been posting some great stuff. I've been trying them all. Thanks for your sharing.

- Dav