Morse code: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 22: Line 22:
from standard input until EOF is reached.
from standard input until EOF is reached.


<lang asm> cpu 8086
<syntaxhighlight lang="asm"> cpu 8086
bits 16
bits 16
;;; I/O ports
;;; I/O ports
Line 213: Line 213:
section .bss
section .bss
buf: resb 1024 ; 1K buffer
buf: resb 1024 ; 1K buffer
.size: equ $-buf</lang>
.size: equ $-buf</syntaxhighlight>


=={{header|ABAP}}==
=={{header|ABAP}}==
<lang ABAP>REPORT morse_code.
<syntaxhighlight lang="abap">REPORT morse_code.
TYPES: BEGIN OF y_morse_code,
TYPES: BEGIN OF y_morse_code,
letter TYPE string,
letter TYPE string,
Line 287: Line 287:
ELSE LET prev = index - 1 IN to_upper( word+prev(1) ) ) ]-code OPTIONAL )
ELSE LET prev = index - 1 IN to_upper( word+prev(1) ) ) ]-code OPTIONAL )
IN NEXT word_coded = |{ word_coded } { _morse_code }| ) ) ) )
IN NEXT word_coded = |{ word_coded } { _morse_code }| ) ) ) )
)->display( ).</lang>
)->display( ).</syntaxhighlight>


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>DEFINE PTR="CARD"
<syntaxhighlight lang="action!">DEFINE PTR="CARD"
DEFINE COUNT="$60"
DEFINE COUNT="$60"


Line 413: Line 413:
Process("Atari Action!")
Process("Atari Action!")
Process("www.rosettacode.org")
Process("www.rosettacode.org")
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Morse_code.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Morse_code.png Screenshot from Atari 8-bit computer]
Line 432: Line 432:


Specification of the package :
Specification of the package :
<lang Ada>package Morse is
<syntaxhighlight lang="ada">package Morse is


type Symbols is (Nul, '-', '.', ' ');
type Symbols is (Nul, '-', '.', ' ');
Line 471: Line 471:
others => (1, " ")); -- Dummy => Other characters do not need code.
others => (1, " ")); -- Dummy => Other characters do not need code.


end Morse;</lang>
end Morse;</syntaxhighlight>
<lang Ada>with Ada.Strings.Maps, Ada.Characters.Handling, Interfaces.C;
<syntaxhighlight lang="ada">with Ada.Strings.Maps, Ada.Characters.Handling, Interfaces.C;
use Ada, Ada.Strings, Ada.Strings.Maps, Interfaces;
use Ada, Ada.Strings, Ada.Strings.Maps, Interfaces;


Line 543: Line 543:
Dit_ms := C.unsigned (Integer (Dit * 1000));
Dit_ms := C.unsigned (Integer (Dit * 1000));
Dah_ms := C.unsigned (Integer (Dah * 1000));
Dah_ms := C.unsigned (Integer (Dah * 1000));
end Morse;</lang>
end Morse;</syntaxhighlight>
Main program :
Main program :
<lang Ada>with Morse; use Morse;
<syntaxhighlight lang="ada">with Morse; use Morse;
procedure Morse_Tx is
procedure Morse_Tx is
begin
begin
Morsebeep (Convert ("Science sans Conscience"));
Morsebeep (Convert ("Science sans Conscience"));
end Morse_Tx;</lang>
end Morse_Tx;</syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
Line 555: Line 555:
This caters for non-diacritical English letters, numerals, and the punctuation found on the Wikipedia page and makes a burping noise for anything else. The morse sounds brisker and smoother if the script's run as an application or from Script Menu rather than in Script Editor or Script Debugger.
This caters for non-diacritical English letters, numerals, and the punctuation found on the Wikipedia page and makes a burping noise for anything else. The morse sounds brisker and smoother if the script's run as an application or from Script Menu rather than in Script Editor or Script Debugger.


<lang applescript>use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
<syntaxhighlight lang="applescript">use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use framework "Foundation"
use framework "AppKit"
use framework "AppKit"
Line 623: Line 623:


-- Test code:
-- Test code:
morseCode("Coded in AppleScrip†.")</lang>
morseCode("Coded in AppleScrip†.")</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>; set the morse code
<syntaxhighlight lang="rebol">; set the morse code
code: #[
code: #[
Line 660: Line 660:
]
]
print out</lang>
print out</syntaxhighlight>


{{out}}
{{out}}
Line 670: Line 670:
The frequency and element length are stored near the bottom of the script.
The frequency and element length are stored near the bottom of the script.
It uses the short form of if else that is implemented, to not have such a long script
It uses the short form of if else that is implemented, to not have such a long script
<lang AutoHotkey>TestString := "Hello World! abcdefg @\;" ;Create a string to be sent with multiple caps and some punctuation
<syntaxhighlight lang="autohotkey">TestString := "Hello World! abcdefg @\;" ;Create a string to be sent with multiple caps and some punctuation
MorseBeep(teststring) ;Beeps our string after conversion
MorseBeep(teststring) ;Beeps our string after conversion
return ;End Auto-Execute Section
return ;End Auto-Execute Section
Line 691: Line 691:
} ;Spaces are extended. Sleep pauses the script
} ;Spaces are extended. Sleep pauses the script
return morse ;Returns the text in morse code
return morse ;Returns the text in morse code
} ; ---End Function Morse---</lang>
} ; ---End Function Morse---</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
AWK cannot play sounds by itself,
AWK cannot play sounds by itself,
so here we just translate text to dits and dots:
so here we just translate text to dits and dots:
<lang AWK># usage: awk -f morse.awk [inputfile]
<syntaxhighlight lang="awk"># usage: awk -f morse.awk [inputfile]
BEGIN { FS="";
BEGIN { FS="";
m="A.-B-...C-.-.D-..E.F..-.G--.H....I..J.---K-.-L.-..M--N-.";
m="A.-B-...C-.-.D-..E.F..-.G--.H....I..J.---K-.-L.-..M--N-.";
Line 716: Line 716:
printf("\n");
printf("\n");
}
}
</syntaxhighlight>
</lang>


{{Out}} with input "sos sos titanic"
{{Out}} with input "sos sos titanic"
Line 727: Line 727:
{{works with|GNU bash, version 4 + sox (optional)}}
{{works with|GNU bash, version 4 + sox (optional)}}


<lang bash>
<syntaxhighlight lang="bash">
#!/bin/bash
#!/bin/bash
# michaeltd 2019-11-29 https://github.com/michaeltd/dots/blob/master/dot.files/.bashrc.d/.var/morse.sh
# michaeltd 2019-11-29 https://github.com/michaeltd/dots/blob/master/dot.files/.bashrc.d/.var/morse.sh
Line 778: Line 778:
fi
fi


</syntaxhighlight>
</lang>
{{out}} (input: sos titanic sos):
{{out}} (input: sos titanic sos):
<pre>
<pre>
Line 805: Line 805:
Note that this will ''only'' work as-is under [[DOS]] (and [[Windows]] 9x); under NT systems, the <code>player</code> routine must be changed to use the <code>Beep</code> API call. ([http://www.freebasic.net/forum/viewtopic.php?p=20441#20441 This forum post] details how to use the speaker under Linux, DOS, and Windows in FreeBASIC; the Linux & DOS code differs further from the below by require inline assembly.)
Note that this will ''only'' work as-is under [[DOS]] (and [[Windows]] 9x); under NT systems, the <code>player</code> routine must be changed to use the <code>Beep</code> API call. ([http://www.freebasic.net/forum/viewtopic.php?p=20441#20441 This forum post] details how to use the speaker under Linux, DOS, and Windows in FreeBASIC; the Linux & DOS code differs further from the below by require inline assembly.)


<lang qbasic>DECLARE SUB player (what AS STRING)
<syntaxhighlight lang="qbasic">DECLARE SUB player (what AS STRING)


'this determines the length of the notes
'this determines the length of the notes
Line 864: Line 864:
PLAY "p" + LTRIM$(STR$(noteLen))
PLAY "p" + LTRIM$(STR$(noteLen))
NEXT i%
NEXT i%
END SUB</lang>
END SUB</syntaxhighlight>


{{out}} (2 runs):
{{out}} (2 runs):
Line 876: Line 876:
==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> *TEMPO 8
<syntaxhighlight lang="bbcbasic"> *TEMPO 8
DIM morse$(63)
DIM morse$(63)
FOR char% = 0 TO 63 : READ morse$(char%) : NEXT char%
FOR char% = 0 TO 63 : READ morse$(char%) : NEXT char%
Line 901: Line 901:
DATA 33333,13333,11333,11133,11113,11111,31111,33111,33311,33331,333111,313131,6,31113,6,113311
DATA 33333,13333,11333,11133,11113,11111,31111,33111,33311,33331,333111,313131,6,31113,6,113311
DATA 133131,13,3111,3131,311,1,1131,331,1111,11,1333,313,1311,33,31,333
DATA 133131,13,3111,3131,311,1,1131,331,1111,11,1333,313,1311,33,31,333
DATA 1331,3313,131,111,3,113,1113,133,3113,3133,3311,6,6,6,6,113313</lang>
DATA 1331,3313,131,111,3,113,1113,133,3113,3133,3311,6,6,6,6,113313</syntaxhighlight>


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<lang IS-BASIC>100 PROGRAM "Morse.bas"
<syntaxhighlight lang="is-basic">100 PROGRAM "Morse.bas"
110 STRING TONE$(48 TO 90)*5,ST$*254
110 STRING TONE$(48 TO 90)*5,ST$*254
120 SET CHARACTER 46,0,0,0,0,24,24,0,0,0:SET CHARACTER 47,0,0,0,0,126,126,0,0,0
120 SET CHARACTER 46,0,0,0,0,24,24,0,0,0:SET CHARACTER 47,0,0,0,0,126,126,0,0,0
Line 931: Line 931:
350 CLEAR FONT
350 CLEAR FONT
360 DATA .////,..///,...//,..../,.....,/....,//...,///..,////.,/////,"","","","","","",""
360 DATA .////,..///,...//,..../,.....,/....,//...,///..,////.,/////,"","","","","","",""
370 DATA ./,/...,/./.,/..,.,../.,//.,....,..,.///,/./,./..,//,/.,///,.//.,//./,./.,...,/,../,.../,.//,/../,/.//,//..</lang>
370 DATA ./,/...,/./.,/..,.,../.,//.,....,..,.///,/./,./..,//,/.,///,.//.,//./,./.,...,/,../,.../,.//,/../,/.//,//..</syntaxhighlight>
==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
{{works with|Commodore BASIC|7.0}}
{{works with|Commodore BASIC|7.0}}
Line 937: Line 937:
some of its structured programming features, such as DO...LOOP and BEGIN...BEND.</p>
some of its structured programming features, such as DO...LOOP and BEGIN...BEND.</p>


<lang basic>100 DI$="IA" : REM DIT = EIGHTH NOTE
<syntaxhighlight lang="basic">100 DI$="IA" : REM DIT = EIGHTH NOTE
110 DA$="Q.A": REM DA = DOTTED QUARTER NOTE
110 DA$="Q.A": REM DA = DOTTED QUARTER NOTE
120 IS$="IR" : REM SPACE BETWEEN SYMS=1xDOT
120 IS$="IR" : REM SPACE BETWEEN SYMS=1xDOT
Line 989: Line 989:
620 DATA ".",".-.-.-", ",","--..--"
620 DATA ".",".-.-.-", ",","--..--"
630 DATA "?","..--.."
630 DATA "?","..--.."
640 DATA ""</lang>
640 DATA ""</syntaxhighlight>


=={{header|Befunge}}==
=={{header|Befunge}}==
Since Befunge doesn't have a way to output sound, this implementation just generates a text representation of the morse. The string to convert is read from stdin.
Since Befunge doesn't have a way to output sound, this implementation just generates a text representation of the morse. The string to convert is read from stdin.


<lang befunge>>~>48*-:0\`#@_2*::"!"%\"!"/3+g75v
<syntaxhighlight lang="befunge">>~>48*-:0\`#@_2*::"!"%\"!"/3+g75v
^v('_')v!:-*57g+3/"!"\%"!":+1\-*<
^v('_')v!:-*57g+3/"!"\%"!":+1\-*<
^$$,*84_\#!:#:2#-%#15#\9#/*#2+#,<
^$$,*84_\#!:#:2#-%#15#\9#/*#2+#,<
Line 1,002: Line 1,002:
'(&*&#$&&*'$&)'%'/'########6)##$%
'(&*&#$&&*'$&)'%'/'########6)##$%
1'-')&$$.''&2'&%$'%&0'#%%%#&,'''(
1'-')&$$.''&2'&%$'%&0'#%%%#&,'''(
&*&#$&&*'$&)'%'/'################</lang>
&*&#$&&*'$&)'%'/'################</syntaxhighlight>


{{out}}
{{out}}
Line 1,012: Line 1,012:
One could substitute another program for ubuntu beep command.
One could substitute another program for ubuntu beep command.


<syntaxhighlight lang="c">
<lang C>
/*
/*


Line 1,091: Line 1,091:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang CSharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Collections.Generic;


Line 1,132: Line 1,132:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|C++}}==
=={{header|C++}}==
<syntaxhighlight lang="c++">
<lang C++>
/*
/*
Michal Sikorski
Michal Sikorski
Line 1,205: Line 1,205:
}
}


</syntaxhighlight>
</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang Clojure>(import [javax.sound.sampled AudioFormat AudioSystem SourceDataLine])
<syntaxhighlight lang="clojure">(import [javax.sound.sampled AudioFormat AudioSystem SourceDataLine])


(defn play [sample-rate bs]
(defn play [sample-rate bs]
Line 1,262: Line 1,262:
(apply concat ,)
(apply concat ,)
byte-array
byte-array
(play sample-rate ,)))</lang>
(play sample-rate ,)))</syntaxhighlight>


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
<lang coffeescript>class Morse
<syntaxhighlight lang="coffeescript">class Morse
constructor : (@unit=0.05, @freq=700) ->
constructor : (@unit=0.05, @freq=700) ->


Line 1,315: Line 1,315:


morse = new Morse()
morse = new Morse()
morse.send 'hello world 0123456789'</lang>
morse.send 'hello world 0123456789'</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<syntaxhighlight lang="d">
<lang d>
import std.conv;
import std.conv;
import std.stdio;
import std.stdio;
Line 1,377: Line 1,377:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Delphi}}==
=={{header|Delphi}}==
<syntaxhighlight lang="delphi">
<lang Delphi>
program Morse;
program Morse;


Line 1,454: Line 1,454:
Dictionary.Free;
Dictionary.Free;
end;
end;
end.</lang>
end.</syntaxhighlight>


=={{header|EasyLang}}==
=={{header|EasyLang}}==
<lang>txt$ = "sos sos"
<syntaxhighlight lang="text">txt$ = "sos sos"
#
#
chars$[] = strchars "abcdefghijklmnopqrstuvwxyz "
chars$[] = strchars "abcdefghijklmnopqrstuvwxyz "
Line 1,486: Line 1,486:
for ch$ in strchars txt$
for ch$ in strchars txt$
call morse ch$
call morse ch$
.</lang>
.</syntaxhighlight>


=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<lang scheme>
<syntaxhighlight lang="scheme">
(require 'json)
(require 'json)
(require 'hash)
(require 'hash)
Line 1,515: Line 1,515:
(else (writeln) (blink)))
(else (writeln) (blink)))
(set! EMIT (rest EMIT))))
(set! EMIT (rest EMIT))))
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,528: Line 1,528:


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>defmodule Morse do
<syntaxhighlight lang="elixir">defmodule Morse do
@morse %{"!" => "---.", "\"" => ".-..-.", "$" => "...-..-", "'" => ".----.",
@morse %{"!" => "---.", "\"" => ".-..-.", "$" => "...-..-", "'" => ".----.",
"(" => "-.--.", ")" => "-.--.-", "+" => ".-.-.", "," => "--..--",
"(" => "-.--.", ")" => "-.--.-", "+" => ".-.-.", "," => "--..--",
Line 1,552: Line 1,552:
end
end


IO.puts Morse.code("Hello, World!")</lang>
IO.puts Morse.code("Hello, World!")</syntaxhighlight>


{{out}}
{{out}}
Line 1,560: Line 1,560:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang="fsharp">
open System
open System
open System.Threading
open System.Threading
Line 1,595: Line 1,595:


send "Rosetta Code"
send "Rosetta Code"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>._. ___ ... . _ _ ._ _._. ___ _.. .</pre>
<pre>._. ___ ... . _ _ ._ _._. ___ _.. .</pre>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USE: morse
<syntaxhighlight lang="factor">USE: morse
"Hello world!" play-as-morse</lang>
"Hello world!" play-as-morse</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
Line 1,607: Line 1,607:
The Morse code generator could have taken the form of a look-up array with bit patterns cross referencing dits and dahs, but we instead used the Forth dictionary, which is functionally like a big case statement. By making each letter an executable routine in Forth we get a very succinct way to code our Morse. Proper sounding morse code requires precise time delays between the dits, dahs, letters and words. The program uses the Forth word "ms" which delays for n milliseconds and gives us real time control. This morse code sounds right.
The Morse code generator could have taken the form of a look-up array with bit patterns cross referencing dits and dahs, but we instead used the Forth dictionary, which is functionally like a big case statement. By making each letter an executable routine in Forth we get a very succinct way to code our Morse. Proper sounding morse code requires precise time delays between the dits, dahs, letters and words. The program uses the Forth word "ms" which delays for n milliseconds and gives us real time control. This morse code sounds right.
There is a lot accomplished in 75 lines of code for a "low level" language.
There is a lot accomplished in 75 lines of code for a "low level" language.
<lang>
<syntaxhighlight lang="text">
HEX
HEX
\ PC speaker hardware control (requires GIVEIO or DOSBOX for windows operation)
\ PC speaker hardware control (requires GIVEIO or DOSBOX for windows operation)
Line 1,691: Line 1,691:


PREVIOUS DEFINITIONS \ go back to previous namespace
PREVIOUS DEFINITIONS \ go back to previous namespace
: TRANSMIT MORSE TRANSMIT PREVIOUS ;</lang>
: TRANSMIT MORSE TRANSMIT PREVIOUS ;</syntaxhighlight>


Test at the Forth console
Test at the Forth console
Line 1,699: Line 1,699:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>
<syntaxhighlight lang="freebasic">
' FB 1.05.0 Win64
' FB 1.05.0 Win64


Line 1,776: Line 1,776:
DyLibFree(library)
DyLibFree(library)
End
End
</syntaxhighlight>
</lang>




Line 1,783: Line 1,783:
When compiled with FB, this code produces a packaged, stand-alone 64-bit application that will run on either Intel or the newer M-series Macs. It translates a text string into Morse Code and plays back characters along with their respective sounds. The oscillator frequency and volume, along with letter and word spacing, can be adjusted with the definitions at the head of the file. While the code meets the Rosetta Code parameters, it's by no means exhaustive. For instance, it does not include translation of punctuation or prosigns, and the GUI is minimal. It's simply a proof of concept. It's been tested on Catalina (10.15.x) to Monterey (12.4.x) with Ventura still in beta at the time of this post. The free FB compiler is available on the
When compiled with FB, this code produces a packaged, stand-alone 64-bit application that will run on either Intel or the newer M-series Macs. It translates a text string into Morse Code and plays back characters along with their respective sounds. The oscillator frequency and volume, along with letter and word spacing, can be adjusted with the definitions at the head of the file. While the code meets the Rosetta Code parameters, it's by no means exhaustive. For instance, it does not include translation of punctuation or prosigns, and the GUI is minimal. It's simply a proof of concept. It's been tested on Catalina (10.15.x) to Monterey (12.4.x) with Ventura still in beta at the time of this post. The free FB compiler is available on the
[http://www.brilorsoftware.com/fb/pages/home.html FutureBasic] home page.
[http://www.brilorsoftware.com/fb/pages/home.html FutureBasic] home page.
<lang futurebasic>
<syntaxhighlight lang="futurebasic">
include "Tlbx AVKit.incl"
include "Tlbx AVKit.incl"


Line 1,936: Line 1,936:


HandleEvents
HandleEvents
</syntaxhighlight>
</lang>
{{output}}
{{output}}
<pre>
<pre>
Line 1,955: Line 1,955:


=={{header|Gambas}}==
=={{header|Gambas}}==
<lang gambas>'Requires component 'gb.sdl2.audio'
<syntaxhighlight lang="gambas">'Requires component 'gb.sdl2.audio'


Public Sub Main()
Public Sub Main()
Line 2,006: Line 2,006:
Next
Next


End</lang>
End</syntaxhighlight>
Output (plus sound):
Output (plus sound):
<pre>
<pre>
Line 2,014: Line 2,014:
=={{header|Go}}==
=={{header|Go}}==


<lang Go>// Command morse translates an input string into morse code,
<syntaxhighlight lang="go">// Command morse translates an input string into morse code,
// showing the output on the console, and playing it as sound.
// showing the output on the console, and playing it as sound.
// Only works on ubuntu.
// Only works on ubuntu.
Line 2,167: Line 2,167:


}
}
</syntaxhighlight>
</lang>


=={{header|Haskell}}==
=={{header|Haskell}}==
Line 2,176: Line 2,176:


The main program.
The main program.
<syntaxhighlight lang="haskell">
<lang Haskell>
import System.IO
import System.IO
import MorseCode
import MorseCode
Line 2,187: Line 2,187:
text <- getContents
text <- getContents
play $ toMorse text
play $ toMorse text
</syntaxhighlight>
</lang>


The module to convert text to Morse code symbols.
The module to convert text to Morse code symbols.
<syntaxhighlight lang="haskell">
<lang Haskell>
module MorseCode (Morse, MSym(..), toMorse) where
module MorseCode (Morse, MSym(..), toMorse) where


Line 2,227: Line 2,227:
fromChar = fromJust . flip M.lookup dict
fromChar = fromJust . flip M.lookup dict
weed = filter (\c -> c == ' ' || M.member c dict)
weed = filter (\c -> c == ' ' || M.member c dict)
</syntaxhighlight>
</lang>


The module to interpret Morse code symbols as sound.
The module to interpret Morse code symbols as sound.
<syntaxhighlight lang="haskell">
<lang Haskell>
module MorsePlaySox (play) where
module MorsePlaySox (play) where


Line 2,270: Line 2,270:
play :: Morse -> IO ExitCode
play :: Morse -> IO ExitCode
play = simple put none rate . concatMap toSamples
play = simple put none rate . concatMap toSamples
</syntaxhighlight>
</lang>


=={{header|J}}==
=={{header|J}}==


<lang j>require'strings media/wav'
<syntaxhighlight lang="j">require'strings media/wav'
morse=:[:; [:(' ',~' .-' {~ 3&#.inv)&.> (_96{.".0 :0-.LF) {~ a.&i.@toupper
morse=:[:; [:(' ',~' .-' {~ 3&#.inv)&.> (_96{.".0 :0-.LF) {~ a.&i.@toupper
79 448 0 1121 0 0 484 214 644 0 151 692 608 455 205 242 161 134 125 122
79 448 0 1121 0 0 484 214 644 0 151 692 608 455 205 242 161 134 125 122
Line 2,282: Line 2,282:


onoffdur=: 0.01*100<.@*(1.2%[)*(4 4#:2 5 13){~' .-'i.]
onoffdur=: 0.01*100<.@*(1.2%[)*(4 4#:2 5 13){~' .-'i.]
playmorse=: 30&$: :((wavnote&, 63 __"1)@(onoffdur morse))</lang>
playmorse=: 30&$: :((wavnote&, 63 __"1)@(onoffdur morse))</syntaxhighlight>


Example use:
Example use:


<lang> morse'this is an example'
<syntaxhighlight lang="text"> morse'this is an example'
- .... .. ... .. ... .- -. . -..- .- -- .--. .-.. .
- .... .. ... .. ... .- -. . -..- .- -- .--. .-.. .
playmorse'this is an example'
playmorse'this is an example'
1
1
12 playmorse'as is this'
12 playmorse'as is this'
1</lang>
1</syntaxhighlight>


morse converts from text to dot dash notation
morse converts from text to dot dash notation
Line 2,311: Line 2,311:
=={{header|Java}}==
=={{header|Java}}==
{{works with|java|7}}
{{works with|java|7}}
<lang java>import java.util.*;
<syntaxhighlight lang="java">import java.util.*;


public class MorseCode {
public class MorseCode {
Line 2,354: Line 2,354:
System.out.println("\n");
System.out.println("\n");
}
}
}</lang>
}</syntaxhighlight>


<pre>sos
<pre>sos
Line 2,369: Line 2,369:
This implementation utilises the fairly new Web Audio API in the browser for generating tones, as such it only uses one vendor implementation (WebKit). It is split into three modules; 1. translating the characters into morse code. 2. creating timings for the morse code. 3. creating tones with the timings.
This implementation utilises the fairly new Web Audio API in the browser for generating tones, as such it only uses one vendor implementation (WebKit). It is split into three modules; 1. translating the characters into morse code. 2. creating timings for the morse code. 3. creating tones with the timings.


<syntaxhighlight lang="javascript">
<lang JavaScript>
var globalAudioContext = new webkitAudioContext();
var globalAudioContext = new webkitAudioContext();


Line 2,453: Line 2,453:
return cont;
return cont;
}
}
</syntaxhighlight>
</lang>


Usage:
Usage:


<syntaxhighlight lang="javascript">
<lang JavaScript>
morsecode('Hello World');
morsecode('Hello World');
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,467: Line 2,467:
=={{header|Julia}}==
=={{header|Julia}}==
Requires a sound card and the PortAudio libraries.
Requires a sound card and the PortAudio libraries.
<lang Julia>using PortAudio
<syntaxhighlight lang="julia">using PortAudio


const pstream = PortAudioStream(0, 2)
const pstream = PortAudioStream(0, 2)
Line 2,498: Line 2,498:
sendmorse("sos sos sos")
sendmorse("sos sos sos")
sendmorse("The case of letters in Morse coding is ignored."
sendmorse("The case of letters in Morse coding is ignored."
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
Line 2,504: Line 2,504:
Java does not have easy access to the beep method, so we need to create one using the Audio API it provides.
Java does not have easy access to the beep method, so we need to create one using the Audio API it provides.


<lang scala>import javax.sound.sampled.AudioFormat
<syntaxhighlight lang="scala">import javax.sound.sampled.AudioFormat
import javax.sound.sampled.AudioSystem
import javax.sound.sampled.AudioSystem


Line 2,565: Line 2,565:
playMorseCode(toMorseCode(it.toLowerCase()))
playMorseCode(toMorseCode(it.toLowerCase()))
}
}
}</lang>
}</syntaxhighlight>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<lang lb>'The following code relies on the Windows API
<syntaxhighlight lang="lb">'The following code relies on the Windows API
Input "Input the text to translate to Morse Code... "; string$
Input "Input the text to translate to Morse Code... "; string$
Print PlayMorse$(string$)
Print PlayMorse$(string$)
Line 2,622: Line 2,622:
Data "@", ".--.-.", "(", "-.--.", ")", "-.--.-", "_", "..--.-", "$", "...-..-", "&", ".-..."
Data "@", ".--.-.", "(", "-.--.", ")", "-.--.-", "_", "..--.-", "$", "...-..-", "&", ".-..."
Data "=", "-...-", "!", "..--.", " ", " ", "End", ""
Data "=", "-...-", "!", "..--.", " ", " ", "End", ""
End Function </lang>
End Function </syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
The following code is actual eLua code used to beep the speaker in Morse code n the Shenzhou III STM32F103ZET6 evaluation board. eLua is a Lua 5.1.4 implementation paired with libraries for low-level hardware access in embedded systems. The below code could easily be converted to any other Lua 5.n environment (including games), provided some kind of sound library has been installed. Only the functions buzz and pause would have to be modified.
The following code is actual eLua code used to beep the speaker in Morse code n the Shenzhou III STM32F103ZET6 evaluation board. eLua is a Lua 5.1.4 implementation paired with libraries for low-level hardware access in embedded systems. The below code could easily be converted to any other Lua 5.n environment (including games), provided some kind of sound library has been installed. Only the functions buzz and pause would have to be modified.


<lang lua>local M = {}
<syntaxhighlight lang="lua">local M = {}


-- module-local variables
-- module-local variables
Line 2,719: Line 2,719:
init(50000)
init(50000)


return M</lang>
return M</syntaxhighlight>


Using this module is as simple as:
Using this module is as simple as:


<lang lua>morse = require 'morse'
<syntaxhighlight lang="lua">morse = require 'morse'
morse.beep "I am the very model of a modern major-general."</lang>
morse.beep "I am the very model of a modern major-general."</syntaxhighlight>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Line 2,733: Line 2,733:
The function, sonicMorse[s_String], plays the Morse code audio translation of a string.
The function, sonicMorse[s_String], plays the Morse code audio translation of a string.


<lang Mathematica>Dictionary = Join[CharacterRange["a", "z"], CharacterRange["0", "9"]];
<syntaxhighlight lang="mathematica">Dictionary = Join[CharacterRange["a", "z"], CharacterRange["0", "9"]];
mark = 0.1; gap = 0.125; (* gap should be equal to mark. But longer gap makes audio code easier to decode *)
mark = 0.1; gap = 0.125; (* gap should be equal to mark. But longer gap makes audio code easier to decode *)
shortgap = 3*gap; medgap = 7*gap;
shortgap = 3*gap; medgap = 7*gap;
Line 2,765: Line 2,765:
morseCode[s_String] := StringReplace[ToLowerCase@s, codeRules~Join~{x_ /; FreeQ[Flatten@{Dictionary, " "}, x] -> "? "}]
morseCode[s_String] := StringReplace[ToLowerCase@s, codeRules~Join~{x_ /; FreeQ[Flatten@{Dictionary, " "}, x] -> "? "}]
morseDecode[s_String] := StringReplace[s, decodeRules]
morseDecode[s_String] := StringReplace[s, decodeRules]
sonicMorse[s_String] := EmitSound@Sound@Flatten[Characters@morseCode@s /. soundRules]</lang>
sonicMorse[s_String] := EmitSound@Sound@Flatten[Characters@morseCode@s /. soundRules]</syntaxhighlight>


{{out|Text example}}
{{out|Text example}}
Line 2,781: Line 2,781:
This function will remove any characters not defined in the morse code.
This function will remove any characters not defined in the morse code.


<lang MATLAB>function [morseText,morseSound] = text2morse(string,playSound)
<syntaxhighlight lang="matlab">function [morseText,morseSound] = text2morse(string,playSound)


%% Translate AlphaNumeric Text to Morse Text
%% Translate AlphaNumeric Text to Morse Text
Line 2,851: Line 2,851:
end
end
end %text2morse</lang>
end %text2morse</syntaxhighlight>


{{out}} This will play the audio automatically, because the playSound argument is "true".
{{out}} This will play the audio automatically, because the playSound argument is "true".
<lang MATLAB>>> text2morse('Call me Ishmael.',true)
<syntaxhighlight lang="matlab">>> text2morse('Call me Ishmael.',true)


ans =
ans =


-.-.|.-|.-..|.-..| |--|.| |..|...|....|--|.-|.|.-..|</lang>
-.-.|.-|.-..|.-..| |--|.| |..|...|....|--|.-|.|.-..|</syntaxhighlight>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE MorseCode;
<syntaxhighlight lang="modula2">MODULE MorseCode;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;


Line 2,922: Line 2,922:


ReadChar;
ReadChar;
END MorseCode.</lang>
END MorseCode.</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
Text mode only. The text to translate is provided in the command line.
Text mode only. The text to translate is provided in the command line.


<lang Nim>import os, strutils, tables
<syntaxhighlight lang="nim">import os, strutils, tables


const Morse = {'A': ".-", 'B': "-...", 'C': "-.-.", 'D': "-..", 'E': ".",
const Morse = {'A': ".-", 'B': "-...", 'C': "-.-.", 'D': "-..", 'E': ".",
Line 2,950: Line 2,950:
for arg in commandLineParams():
for arg in commandLineParams():
m.add morse(arg)
m.add morse(arg)
echo m.join(" ")</lang>
echo m.join(" ")</syntaxhighlight>


{{out}}
{{out}}
Line 2,959: Line 2,959:
Using <code>/dev/dsp</code>:
Using <code>/dev/dsp</code>:


<lang ocaml>let codes = [
<syntaxhighlight lang="ocaml">let codes = [
'a', ".-"; 'b', "-..."; 'c', "-.-.";
'a', ".-"; 'b', "-..."; 'c', "-.-.";
'd', "-.."; 'e', "."; 'f', "..-.";
'd', "-.."; 'e', "."; 'f', "..-.";
Line 3,004: Line 3,004:
| _ -> prerr_endline "unknown char")
| _ -> prerr_endline "unknown char")


let () = morse "rosettacode morse"</lang>
let () = morse "rosettacode morse"</syntaxhighlight>


=={{header|Ol}}==
=={{header|Ol}}==
Line 3,010: Line 3,010:


To simplify the example will be used only lower letter case.
To simplify the example will be used only lower letter case.
<syntaxhighlight lang="ol">
<lang ol>
(display "Please, enter the string in lower case bounded by \" sign: ")
(display "Please, enter the string in lower case bounded by \" sign: ")
(lfor
(lfor
Line 3,036: Line 3,036:
; <== "hello world"
; <== "hello world"
; ==> ......-...-..--- .-----.-..-..-..
; ==> ......-...-..--- .-----.-..-..-..
</syntaxhighlight>
</lang>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>sleep(ms)={
<syntaxhighlight lang="parigp">sleep(ms)={
while((ms-=gettime()) > 0,);
while((ms-=gettime()) > 0,);
};
};
Line 3,053: Line 3,053:
};
};


Morse("...---...")</lang>
Morse("...---...")</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 3,060: Line 3,060:
This program uses OpenAL for cross-platform PCM audio.
This program uses OpenAL for cross-platform PCM audio.


<syntaxhighlight lang="pascal">
<lang Pascal>
{$mode delphi}
{$mode delphi}
PROGRAM cw;
PROGRAM cw;
Line 3,182: Line 3,182:
AlutExit();
AlutExit();
END.
END.
</syntaxhighlight>
</lang>


=={{header|Perl}}==
=={{header|Perl}}==
<lang Perl>use Acme::AGMorse qw(SetMorseVals SendMorseMsg);
<syntaxhighlight lang="perl">use Acme::AGMorse qw(SetMorseVals SendMorseMsg);
SetMorseVals(20,30,400);
SetMorseVals(20,30,400);
SendMorseMsg('Hello World! abcdefg @\;'); # note, caps are ingnored in Morse Code
SendMorseMsg('Hello World! abcdefg @\;'); # note, caps are ingnored in Morse Code
exit;</lang>
exit;</syntaxhighlight>


The above code requires:
The above code requires:
Line 3,205: Line 3,205:
{{libheader|Phix/online}}
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/Morse_code.htm here].
You can run this online [http://phix.x10.mx/p2js/Morse_code.htm here].
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Morse_code.exw
-- demo\rosetta\Morse_code.exw
Line 3,381: Line 3,381:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
The following simply uses the 'beep' pc-speaker beeper utility.
The following simply uses the 'beep' pc-speaker beeper utility.
<lang PicoLisp># *Morse *Dit *Dah
<syntaxhighlight lang="picolisp"># *Morse *Dit *Dah


(balance '*Morse
(balance '*Morse
Line 3,427: Line 3,427:
(wait (- *Dah *Dit)) ) )
(wait (- *Dah *Dit)) ) )


(morse "Hello world!")</lang>
(morse "Hello world!")</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
/* Sound Morse code via the PC buzzer. June 2011 */
/* Sound Morse code via the PC buzzer. June 2011 */
MORSE: procedure options (main);
MORSE: procedure options (main);
Line 3,481: Line 3,481:
end send_morse;
end send_morse;


END MORSE;</lang>
END MORSE;</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
This function is case insensitive, ignores all non-Morse characters and optionally displays the Morse code.
This function is case insensitive, ignores all non-Morse characters and optionally displays the Morse code.
<syntaxhighlight lang="powershell">
<lang PowerShell>
function Send-MorseCode
function Send-MorseCode
{
{
Line 3,545: Line 3,545:
}
}
}
}
</syntaxhighlight>
</lang>
<syntaxhighlight lang="powershell">
<lang PowerShell>
Send-MorseCode -Message "S.O.S" -ShowCode
Send-MorseCode -Message "S.O.S" -ShowCode
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
... --- ...
... --- ...
</pre>
</pre>
<syntaxhighlight lang="powershell">
<lang PowerShell>
"S.O.S", "Goodbye, cruel world!" | Send-MorseCode -ShowCode
"S.O.S", "Goodbye, cruel world!" | Send-MorseCode -ShowCode
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 3,567: Line 3,567:
=={{header|Prolog}}==
=={{header|Prolog}}==
Runs in SWI Prolog, Edinburgh syntax
Runs in SWI Prolog, Edinburgh syntax
<syntaxhighlight lang="prolog">
<lang Prolog>
% convert text to morse
% convert text to morse
% query text2morse(Text, Morse)
% query text2morse(Text, Morse)
Line 3,638: Line 3,638:
morse('-', "-....-").
morse('-', "-....-").
morse('@', ".--.-.").
morse('@', ".--.-.").
</syntaxhighlight>
</lang>
<syntaxhighlight lang="prolog">
<lang Prolog>
text2morse("Hello World", Morse).
text2morse("Hello World", Morse).
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 3,648: Line 3,648:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>#BaseTime =50
<syntaxhighlight lang="purebasic">#BaseTime =50
#Frequence=1250
#Frequence=1250
#Short = #BaseTime
#Short = #BaseTime
Line 3,776: Line 3,776:
Data.s "Done",""
Data.s "Done",""
EndOfMorseCode:
EndOfMorseCode:
EndDataSection</lang>
EndDataSection</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
<lang python>import time, winsound #, sys
<syntaxhighlight lang="python">import time, winsound #, sys


char2morse = {
char2morse = {
Line 3,840: Line 3,840:
while True:
while True:
windowsmorse(input('A string to change into morse: '))
windowsmorse(input('A string to change into morse: '))
</syntaxhighlight>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==
Using MIDI on Windows for the beeps.
Using MIDI on Windows for the beeps.
<lang racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket
(require ffi/unsafe ffi/unsafe/define)
(require ffi/unsafe ffi/unsafe/define)
Line 3,885: Line 3,885:


(morse "Say something here")
(morse "Say something here")
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
Line 3,893: Line 3,893:
Just read the output, leaving extra pauses where indicated
Just read the output, leaving extra pauses where indicated
by either whitespace or underscore.
by either whitespace or underscore.
<lang perl6>my %m = ' ', '_ _ ',
<syntaxhighlight lang="raku" line>my %m = ' ', '_ _ ',
|<
|<
! ---.
! ---.
Line 3,956: Line 3,956:
}
}


say prompt("Gimme a string: ").uc.comb.map: { %m{$_} // "<scratch> " }</lang>
say prompt("Gimme a string: ").uc.comb.map: { %m{$_} // "<scratch> " }</syntaxhighlight>
Sample run:
Sample run:
<p>Gimme a string: <b>Howdy, World!</b>
<p>Gimme a string: <b>Howdy, World!</b>
Line 3,966: Line 3,966:
or "red.exe -r morse.red " to compile to single .exe file <br>
or "red.exe -r morse.red " to compile to single .exe file <br>
each character will be printed with its corresponding code before played
each character will be printed with its corresponding code before played
<lang Red>Red [
<syntaxhighlight lang="red">Red [
file: %morse.red ;; filename, could be ommited
file: %morse.red ;; filename, could be ommited
]
]
Line 4,026: Line 4,026:
morse-text "rosetta code"
morse-text "rosetta code"
morse-text "hello world"
morse-text "hello world"
</syntaxhighlight>
</lang>
<lang Red>Red/System [
<syntaxhighlight lang="red">Red/System [
file: %api.reds ;; filename, could be ommited
file: %api.reds ;; filename, could be ommited
]
]
Line 4,052: Line 4,052:
] [ wsleep duration ]
] [ wsleep duration ]
;;----------------------------------------------
;;----------------------------------------------
</syntaxhighlight>
</lang>


=={{header|REXX}}==
=={{header|REXX}}==
Line 4,081: Line 4,081:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">


Line 4,139: Line 4,139:
strmorse = left(strmorse,len(strmorse)-1)
strmorse = left(strmorse,len(strmorse)-1)
see strmorse + nl
see strmorse + nl
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 4,148: Line 4,148:
{{works with|Ruby|1.8.7+}} (uses <code>each_char</code>)
{{works with|Ruby|1.8.7+}} (uses <code>each_char</code>)
{{libheader|win32-utils}}
{{libheader|win32-utils}}
<lang ruby>require 'win32/sound'
<syntaxhighlight lang="ruby">require 'win32/sound'


class MorseCode
class MorseCode
Line 4,212: Line 4,212:


MorseCode.new('sos').send
MorseCode.new('sos').send
MorseCode.new('this is a test.').send</lang>
MorseCode.new('this is a test.').send</syntaxhighlight>


{{out}}
{{out}}
Line 4,229: Line 4,229:
morse_code/src/main.rs file:
morse_code/src/main.rs file:


<lang rust>
<syntaxhighlight lang="rust">
//!
//!
//! morse_code/src/main.rs
//! morse_code/src/main.rs
Line 4,259: Line 4,259:
}
}
}
}
</syntaxhighlight>
</lang>


morse_code/src/lib.rs file:
morse_code/src/lib.rs file:


<lang rust>
<syntaxhighlight lang="rust">
//!
//!
//! morse_code/src/lib.rs
//! morse_code/src/lib.rs
Line 4,380: Line 4,380:
morse_map
morse_map
}
}
</syntaxhighlight>
</lang>


=={{header|Scala}}==
=={{header|Scala}}==
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/9Dsd74J/1 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/68KAarvEQQafYevTkWaCWg Scastie (remote JVM)].
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/9Dsd74J/1 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/68KAarvEQQafYevTkWaCWg Scastie (remote JVM)].
<lang Scala>object MorseCode extends App {
<syntaxhighlight lang="scala">object MorseCode extends App {


private val code = Map(
private val code = Map(
Line 4,411: Line 4,411:
printMorse("Rosetta Code")
printMorse("Rosetta Code")


}</lang>
}</syntaxhighlight>


=={{header|sed}}==
=={{header|sed}}==
Translation of AWK:
Translation of AWK:
<lang sed>#!/bin/sed -rf
<syntaxhighlight lang="sed">#!/bin/sed -rf
# Convert to uppercase
# Convert to uppercase
s/.*/\U&/
s/.*/\U&/
Line 4,425: Line 4,425:
ta
ta
# Remove lookup table
# Remove lookup table
s/\n.*//</lang>
s/\n.*//</syntaxhighlight>
Example:
Example:
<lang bash>
<syntaxhighlight lang="bash">
$ echo hello world! | ./morse.sed
$ echo hello world! | ./morse.sed
.... . .-.. .-.. --- .-- --- .-. .-.. -.. !</lang>
.... . .-.. .-.. --- .-- --- .-. .-.. -.. !</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
{{libheader|Snack}}
{{libheader|Snack}}
<lang tcl># This uses the GUI-free part of the Snack library
<syntaxhighlight lang="tcl"># This uses the GUI-free part of the Snack library
package require sound
package require sound
Line 4,494: Line 4,494:
set frequency 700
set frequency 700
morse "Morse code with Tcl and Snack." 20</lang>
morse "Morse code with Tcl and Snack." 20</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
$$ MODE TUSCRIPT
MODE DATA
MODE DATA
Line 4,531: Line 4,531:
mc=EXCHANGE (mc,space2split)
mc=EXCHANGE (mc,space2split)
BEEP $mc
BEEP $mc
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 4,549: Line 4,549:
=={{header|Ursa}}==
=={{header|Ursa}}==
{{trans|Python}}
{{trans|Python}}
<lang ursa>decl ursa.util.sound snd
<syntaxhighlight lang="ursa">decl ursa.util.sound snd
decl string<> chars
decl string<> chars
decl string<> morse
decl string<> morse
Line 4,645: Line 4,645:
out "A string to change into morse: " console
out "A string to change into morse: " console
encode_morse (in string console)
encode_morse (in string console)
end while</lang>
end while</syntaxhighlight>


=={{header|VBA}}==
=={{header|VBA}}==


<lang vb>Option Explicit
<syntaxhighlight lang="vb">Option Explicit


Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Line 4,708: Line 4,708:
Sleep DELAY
Sleep DELAY
Next i
Next i
End Sub</lang>
End Sub</syntaxhighlight>
{{out}}
{{out}}
Play the sound's morse and display :
Play the sound's morse and display :
Line 4,719: Line 4,719:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Module Module1
<syntaxhighlight lang="vbnet">Module Module1


Sub Main()
Sub Main()
Line 4,748: Line 4,748:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 4,756: Line 4,756:


Any characters which do not appear in the Morse alphabet are simply ignored.
Any characters which do not appear in the Morse alphabet are simply ignored.
<lang ecmascript>import "/str" for Str
<syntaxhighlight lang="ecmascript">import "/str" for Str
import "/sound" for Wav
import "/sound" for Wav


Line 4,812: Line 4,812:
}
}
}
}
Wav.create("morse_code.wav", data, sampleRate)</lang>
Wav.create("morse_code.wav", data, sampleRate)</syntaxhighlight>


{{out}}
{{out}}
Line 4,821: Line 4,821:
It's also possible to play .wav files which (preferably) have a sample rate of 44.1 kHz using DOME:
It's also possible to play .wav files which (preferably) have a sample rate of 44.1 kHz using DOME:
{{libheader|DOME}}
{{libheader|DOME}}
<lang ecmascript>import "audio" for AudioEngine
<syntaxhighlight lang="ecmascript">import "audio" for AudioEngine


class Main {
class Main {
Line 4,836: Line 4,836:
}
}


var Game = Main.new()</lang>
var Game = Main.new()</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
Line 4,845: Line 4,845:
when its volume parameter is set to zero.
when its volume parameter is set to zero.


<lang XPL0>code ChOut=8, CrLf=9, Sound=39;
<syntaxhighlight lang="xpl0">code ChOut=8, CrLf=9, Sound=39;
string 0; \use zero-terminated strings
string 0; \use zero-terminated strings


Line 4,886: Line 4,886:
CrLf(0);
CrLf(0);
Morse("Hello, world!");
Morse("Hello, world!");
]</lang>
]</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,895: Line 4,895:
=={{header|Yabasic}}==
=={{header|Yabasic}}==
Mixin classic/modern style. In Yabasic, line number is not mandatory.
Mixin classic/modern style. In Yabasic, line number is not mandatory.
<lang Yabasic>10 REM Morse code
<syntaxhighlight lang="yabasic">10 REM Morse code
20 DIM c$(54)
20 DIM c$(54)
30 FOR f = 1 TO 54
30 FOR f = 1 TO 54
Line 4,925: Line 4,925:
1070 DATA "'",".____.","!","_._.__","/","_.._.","(","_.__.",")","_.__._"
1070 DATA "'",".____.","!","_._.__","/","_.._.","(","_.__.",")","_.__._"
1080 DATA "&","._...",":","___...",";","_._._.","=","_..._","+","._._.","-","_...._"
1080 DATA "&","._...",":","___...",";","_._._.","=","_..._","+","._._.","-","_...._"
1090 DATA "_","..__._","\"","._.._.","$","..._.._","@",".__._."</lang>
1090 DATA "_","..__._","\"","._.._.","$","..._.._","@",".__._."</syntaxhighlight>