Skip to content

Commit

Permalink
Fix incorrect spacing between words and add support for Farsnworth sp…
Browse files Browse the repository at this point in the history
…eed.
  • Loading branch information
stidges authored and ozdemirburak committed Oct 4, 2020
1 parent 73bc4e5 commit 9da7b85
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const japanese = morsify.encode('NEWS', { priority: 10, dash: '-', dot: '・',
const characters = morsify.characters({ dash: '', dot: '' }); // {'1': {'A': '•–', ...}, ..., '11': {'ㄱ': '•–••', ...}}
const arabicAudio = morsify.audio('البراق', { // generates the Morse .- .-.. -... .-. .- --.- then generates the audio from it
unit: 0.1, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
fwUnit: 0.1, // period of one Farnsworth unit to control intercharacter and interword gaps
oscillator: {
type: 'sine', // sine, square, sawtooth, triangle
frequency: 500, // value in hertz
Expand Down
2 changes: 1 addition & 1 deletion dist/morsify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "morsify",
"version": "2.3.2",
"version": "2.4.0",
"description": "Morse code translator, Morse encoder and decoder which can also generate audio.",
"keywords": [
"morsify",
Expand Down
15 changes: 12 additions & 3 deletions src/morsify.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
invalid: options.invalid || '#',
priority: options.priority || 1,
unit: options.unit || 0.08, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
fwUnit: options.fwUnit || options.unit || 0.08, // Farnsworth unit to control intercharacter and interword gaps
oscillator: {
type: options.oscillator.type || 'sine', // sine, square, sawtooth, triangle
frequency: options.oscillator.frequency || 500, // value in hertz
Expand Down Expand Up @@ -211,17 +212,25 @@
t += i * options.unit;
};

const gap = (i) => {
gainNode.gain.setValueAtTime(0, t);
t += i * options.fwUnit;
};

for (let i = 0; i <= morse.length; i++) {
if (morse[i] === options.space) {
silence(7);
gap(7);
} else if (morse[i] === options.dot) {
tone(1);
silence(1);
} else if (morse[i] === options.dash) {
tone(3);
silence(1);
} else {
silence(3);
} else if (
(typeof morse[i + 1] !== 'undefined' && morse[i + 1] !== options.space) &&
(typeof morse[i - 1] !== 'undefined' && morse[i - 1] !== options.space)
) {
gap(3);
}
}

Expand Down

0 comments on commit 9da7b85

Please sign in to comment.