Skip to content

Commit 9da7b85

Browse files
stidgesozdemirburak
authored andcommitted
Fix incorrect spacing between words and add support for Farsnworth speed.
1 parent 73bc4e5 commit 9da7b85

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const japanese = morsify.encode('NEWS', { priority: 10, dash: '-', dot: '・',
7878
const characters = morsify.characters({ dash: '', dot: '' }); // {'1': {'A': '•–', ...}, ..., '11': {'ㄱ': '•–••', ...}}
7979
const arabicAudio = morsify.audio('البراق', { // generates the Morse .- .-.. -... .-. .- --.- then generates the audio from it
8080
unit: 0.1, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
81+
fwUnit: 0.1, // period of one Farnsworth unit to control intercharacter and interword gaps
8182
oscillator: {
8283
type: 'sine', // sine, square, sawtooth, triangle
8384
frequency: 500, // value in hertz

dist/morsify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "morsify",
3-
"version": "2.3.2",
3+
"version": "2.4.0",
44
"description": "Morse code translator, Morse encoder and decoder which can also generate audio.",
55
"keywords": [
66
"morsify",

src/morsify.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
invalid: options.invalid || '#',
145145
priority: options.priority || 1,
146146
unit: options.unit || 0.08, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
147+
fwUnit: options.fwUnit || options.unit || 0.08, // Farnsworth unit to control intercharacter and interword gaps
147148
oscillator: {
148149
type: options.oscillator.type || 'sine', // sine, square, sawtooth, triangle
149150
frequency: options.oscillator.frequency || 500, // value in hertz
@@ -211,17 +212,25 @@
211212
t += i * options.unit;
212213
};
213214

215+
const gap = (i) => {
216+
gainNode.gain.setValueAtTime(0, t);
217+
t += i * options.fwUnit;
218+
};
219+
214220
for (let i = 0; i <= morse.length; i++) {
215221
if (morse[i] === options.space) {
216-
silence(7);
222+
gap(7);
217223
} else if (morse[i] === options.dot) {
218224
tone(1);
219225
silence(1);
220226
} else if (morse[i] === options.dash) {
221227
tone(3);
222228
silence(1);
223-
} else {
224-
silence(3);
229+
} else if (
230+
(typeof morse[i + 1] !== 'undefined' && morse[i + 1] !== options.space) &&
231+
(typeof morse[i - 1] !== 'undefined' && morse[i - 1] !== options.space)
232+
) {
233+
gap(3);
225234
}
226235
}
227236

0 commit comments

Comments
 (0)