Skip to content

Commit

Permalink
Return GainNode as well since it may be used for disconnecting, v0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ozdemirburak committed May 23, 2018
1 parent 464342f commit 276542a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var morsify = require('morsify');
var encoded = morsify.encode('SOS'); // .../---/...
var decoded = morsify.decode('.../---/...'); // S O S
var characters = morsify.characters(); // {'1': {'A': '.-', ...}, ..., '11': {'ㄱ': '.-..', ...}}
var audio = morsify.audio('SOS'), oscillator = audio.oscillator; // OscillatorNode
var audio = morsify.audio('SOS');
audio.play(); // play audio
audio.stop(); // stop audio
```
Expand All @@ -44,6 +44,7 @@ Or alternatively, you can also use the library directly with including the sourc
var audio = morsify.audio('SOS');
var oscillator = audio.oscillator; // OscillatorNode
var context = audio.context; // AudioContext
var gainNode = audio.gainNode; // GainNode
audio.play(); // play audio
audio.stop(); // stop audio
</script>
Expand Down Expand Up @@ -85,11 +86,12 @@ var arabicAudio = morsify.audio('البُراق‎‎', { // generates the morse
frequency: 500, // value in hertz
onended: function () { // event that fires when the tone has stopped playing
console.log('ended');
},
}
}
});
var oscillator = arabicAudio.oscillator; // OscillatorNode
var context = arabicAudio.context; // AudioContext;
var gainNode = audio.gainNode; // GainNode
arabicAudio.play(); // will start playing morse audio
arabicAudio.stop(); // will stop playing morse audio
```
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.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "morsify",
"version": "0.5.0",
"version": "0.5.1",
"description": "Morse code translator and decoder which also generates audio.",
"keywords": [
"morse",
Expand All @@ -19,7 +19,7 @@
],
"license": "MIT",
"homepage": "https://github.com/ozdemirburak/morsify",
"author": "Burak Özdemir <mail@burakozdemir.co.uk> (https://burakozdemir.co.uk)",
"author": "Burak Özdemir <mail@burakozdemir.co.uk> (https://ozdemirburak.com)",
"repository": {
"type": "git",
"url": "https://github.com/ozdemirburak/morsify.git"
Expand All @@ -31,6 +31,7 @@
"gulp-uglify": "^3.0.0",
"istanbul": "^0.4.5",
"jshint": "^2.9.0",
"lodash": "^4.17.10",
"mocha": "^3.4.0",
"pump": "^1.0.2"
},
Expand Down
17 changes: 7 additions & 10 deletions src/morsify.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@
'ื': '0011', 'ุ': '00101', 'ู': '1110', 'เ': '0', 'แ': '0101',
'ไ': '01001', 'โ': '111', 'ำ': '00010', '่': '001', '้': '0001',
'๊': '11000', '๋':'01010', 'ั': '01101', '็': '11100', '์': '11001',
'ๆ': '10111', 'ฯ': '11010',
// 'ฃ': '1010', => duplicated with ข | 'ฅ': '101', 'ฆ': '101', => duplicated with ค | 'ฎ': '100', => duplicated with ด
// 'ฏ': '1', => duplicated with ต | 'ฐ': '10100', => duplicated with ถ | 'ธ': '10011', 'ฑ': '10011', 'ฒ': '10011', => duplicated with ท
// 'ณ': '10', => duplicated with ณ | 'ภ': '01100', => duplicated with พ | 'ฬ': '0100', => duplicated with ล
// 'ษ': '000', 'ศ': '000', => duplicated with ส | 'ฤๅ': '01011', => duplicated with ฤ | 'ใ': '01001', => duplicated with ไ | 'ฯลฯ': '11101' => conflicts with ฯ
'ๆ': '10111', 'ฯ': '11010'
}
};

Expand Down Expand Up @@ -194,8 +190,8 @@

var audio = function (text, opts) {
var options = getOptions(opts), morse = encode(text, opts),
AudioContext = window.AudioContext || window.webkitAudioContext, ctx = new AudioContext(),
t = ctx.currentTime, oscillator = ctx.createOscillator(), gainNode = ctx.createGain();
AudioContext = window.AudioContext || window.webkitAudioContext, context = new AudioContext(),
t = context.currentTime, oscillator = context.createOscillator(), gainNode = context.createGain();

oscillator.type = options.oscillator.type;
oscillator.frequency.value = options.oscillator.frequency;
Expand Down Expand Up @@ -226,7 +222,7 @@
}

oscillator.connect(gainNode);
gainNode.connect(ctx.destination);
gainNode.connect(context.destination);

return {
play: function () {
Expand All @@ -236,8 +232,9 @@
stop: function () {
oscillator.stop();
},
context: ctx,
oscillator: oscillator
context: context,
oscillator: oscillator,
gainNode: gainNode
};
};

Expand Down
Loading

0 comments on commit 276542a

Please sign in to comment.