Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
05aad3aa
Commit
05aad3aa
authored
21 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
JS Module to play .ton files (still needs a little work).
parent
b67ac101
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/playtone.js
+139
-0
139 additions, 0 deletions
exec/playtone.js
with
139 additions
and
0 deletions
exec/playtone.js
0 → 100644
+
139
−
0
View file @
05aad3aa
// playtone.js
/* Tone Generation Utility (using PC speaker, not sound card) */
const
REVISION
=
"
$Revision$
"
.
split
(
'
'
)[
1
];
const
NOT_ABORTABLE
=
(
1
<<
0
)
const
SHOW_DOT
=
(
1
<<
1
)
const
SHOW_FREQ
=
(
1
<<
2
)
const
NO_VISUAL
=
(
1
<<
3
)
var
mode
=
0
;
/* Optional modes */
var
t
=
1
;
/* Timing */
var
s
=
0
;
/* Stacato */
var
octave
=
4
;
/* Default octave */
var
pitch
=
523.50
/
32.0
;
/* low 'C' */
function
play
(
freq
,
dur
)
{
var
notes
=
[
'
c
'
,
'
'
,
'
d
'
,
'
'
,
'
e
'
,
'
f
'
,
'
'
,
'
g
'
,
'
'
,
'
a
'
,
'
'
,
'
b
'
];
var
sharp
=
[
'
B
'
,
'
C
'
,
'
'
,
'
D
'
,
'
'
,
'
E
'
,
'
F
'
,
'
'
,
'
G
'
,
'
'
,
'
A
'
,
'
'
];
var
i
,
n
,
o
,
d
;
var
len
;
var
f
;
// writeln("play " + freq + ", " + dur);
if
(
dur
==
undefined
)
dur
=
"
0
"
;
d
=
parseInt
(
dur
);
if
((
f
=
parseInt
(
freq
))
!=
0
)
switch
(
freq
.
charAt
(
0
).
toUpperCase
())
{
case
'
O
'
:
/* default octave */
if
(
parseInt
(
dur
))
octave
=
d
;
else
octave
+=
d
;
return
;
case
'
P
'
:
/* pitch variation */
if
(
parseInt
(
dur
))
pitch
=
atof
(
dur
)
/
32.0
;
else
pitch
+=
atof
(
dur
);
return
;
case
'
Q
'
:
/* quit */
exit
(
0
);
case
'
R
'
:
/* rest */
f
=
0
;
break
;
case
'
S
'
:
/* stacato */
if
(
parseInt
(
dur
))
s
=
d
;
else
s
+=
d
;
return
;
case
'
T
'
:
/* time adjust */
t
=
d
;
return
;
case
'
V
'
:
if
(
mode
&
NO_VISUAL
)
return
;
truncsp
(
dur
);
if
(
dur
.
charAt
(
dur
.
length
-
1
)
==
'
\\
'
)
write
(
dur
);
else
writeln
(
dur
);
return
;
case
'
X
'
:
/* exit */
exit
(
1
);
default
:
for
(
n
=
0
;
notes
[
n
];
n
++
)
if
(
freq
.
charAt
(
0
)
==
notes
[
n
]
||
freq
.
charAt
(
0
)
==
sharp
[
n
])
break
;
if
(
parseInt
(
freq
.
charAt
(
1
)))
o
=
(
freq
.
charAt
(
1
)
&
0xf
);
else
o
=
octave
;
f
=
pitch
*
Math
.
pow
(
2
,
o
+
n
/
12
);
break
;
}
if
(
f
&&
mode
&
SHOW_FREQ
)
{
for
(
i
=
0
;
freq
[
i
]
>
'
'
;
i
++
)
;
freq
[
i
]
=
0
;
printf
(
"
%-4.4s
"
,
freq
);
}
if
(
mode
&
SHOW_DOT
)
printf
(
"
.
"
);
if
(
t
>
10
)
len
=
(
d
*
t
)
-
(
d
*
s
);
else
len
=
d
*
t
;
if
(
isNaN
(
len
))
return
;
if
(
f
)
beep
(
f
,
len
);
else
sleep
(
len
);
if
(
s
)
{
if
(
t
>
10
)
sleep
(
d
*
s
);
else
sleep
(
s
);
}
}
printf
(
"
\n
Tone Generation Module %s Copyright 2003 Rob Swindell
\n\n
"
,
REVISION
);
if
(
argc
<
1
)
{
alert
(
"
!No filename specified
"
);
exit
();
}
file
=
new
File
(
argv
[
0
]);
if
(
!
file
.
exists
)
file
.
name
=
system
.
exec_dir
+
file
.
name
;
writeln
(
"
Opening
"
+
file
.
name
);
if
(
!
file
.
open
(
"
r
"
))
{
alert
(
"
!Error
"
+
file
.
error
+
"
opening
"
+
file
.
name
);
exit
();
}
text
=
file
.
readAll
();
file
.
close
();
for
(
i
in
text
)
{
if
(
js
.
terminated
)
break
;
// writeln(text[i]);
token
=
text
[
i
].
split
(
/
\s
+/
);
cmd
=
token
[
0
];
token
.
shift
();
play
(
cmd
,
token
.
join
(
'
'
));
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment