提交 8a007475 authored 作者: Bret McDanel's avatar Bret McDanel

refactor, fixed some timing issues


git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@14816 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 d8541172
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
// supplied // supplied
// //
// examples: // examples:
// jsapi conference 123 morse code is great // jsapi morse.js conference 123 CQ CQ CQ this is FreeSWITCH
// jsapi uuid b0b05504-97be-11de-a116-611fa158f341 morse code is great // jsapi morse.js uuid b0b05504-97be-11de-a116-611fa158f341 morse code is great
var cw_wpm=20; var cw_wpm=20;
var cw_freq=900; // in Hz var cw_freq=900; // in Hz
...@@ -38,14 +38,16 @@ var cw_vol=-15; // -63.0dB to 0.0dB ...@@ -38,14 +38,16 @@ var cw_vol=-15; // -63.0dB to 0.0dB
// you probably do not need to edit anything below here // you probably do not need to edit anything below here
var cw_unit=parseInt(1000/cw_wpm);
// international standard is 50 symbols per word - we need units in ms
var cw_unit=parseInt(60000/(50*cw_wpm));
var DIT = "%("+cw_unit+","+cw_unit+","+cw_freq+");"; var DIT = "%("+cw_unit+","+cw_unit+","+cw_freq+");";
var DAH = "%("+cw_unit*3+","+cw_unit*3+","+cw_freq+");"; var DAH = "%("+cw_unit*3+","+cw_unit+","+cw_freq+");";
var SYM_SPACE = "%(0,"+cw_unit*3+","+cw_freq+");";
var WORD_SPACE = "%(0,"+cw_unit*7+","+cw_freq+");";
// so far there are not any prosigns which are just made up from // I do not have the non-officially defined characters
// the letters below, but the spacing needs to be adjusted
// I also do not have the non-officially defined characters
var charCodes = new Array(); var charCodes = new Array();
charCodes["a"]="._"; charCodes["a"]="._";
charCodes["b"]="_..."; charCodes["b"]="_...";
...@@ -92,6 +94,45 @@ function usage() ...@@ -92,6 +94,45 @@ function usage()
} }
function makeMorse(c)
{
var morseStr="";
if(c==" ") {
return WORD_SPACE;
}
if(typeof charCodes[c] == "undefined") {
console_log("DEBUG","Invalid character "+c+"\n");
return;
}
for(var j=0;j<charCodes[c].length;j++) {
if(charCodes[c][j] == ".") {
morseStr+=DIT;
} else {
morseStr+=DAH;
}
}
return morseStr;
}
function playMorse(command,target,message)
{
var newStr="tone_stream://v="+cw_vol+";";
for(var i=0;i<message.length;i++) {
newStr+=makeMorse(message[i].toLowerCase());
if(i<(message.length-1) && message[i+1]!=" " && message[i]!=" ") {
newStr+=SYM_SPACE;
}
}
newStr+=WORD_SPACE;
apiExecute(command, target+newStr);
}
if(typeof argv[2] == "undefined" || argv[2].length==0) { if(typeof argv[2] == "undefined" || argv[2].length==0) {
usage(); usage();
} }
...@@ -112,22 +153,6 @@ if(argv[0] == "conference") { ...@@ -112,22 +153,6 @@ if(argv[0] == "conference") {
} }
while(typeof argv[0] != "undefined") { if(typeof argv[0] != "undefined") {
var newStr="tone_stream://v="+cw_vol+";"; playMorse(command,target,argv.join(" "));
for(var i=0;i<argv[0].length;i++) {
for(var j=0;j<charCodes[argv[0][i]].length;j++) {
if(charCodes[argv[0][i]][j] == ".") {
newStr+=DIT;
} else {
newStr+=DAH;
}
}
// symbol space
newStr+="%(0,"+cw_unit*3+","+cw_freq+")";
}
// word space
// we only do a cw_unit*4 here because we have a cw_unit*3 already
newStr+="%(0,"+cw_unit*4+","+cw_freq+")";
apiExecute(command, target+newStr);
argv.shift();
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论