<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Ping</title>
</head>
<script type="text/javascript">
const csoundjs = "../js/csound.js"; // csound.js is the Csound WASM module
let csound = null; // csound is the Csound engine object (null as we start)
const code = ` // csound synthesis code
instr 1
out linenr(oscili(0dbfs*p4,p5),0.01,0.5,0.01)
endin
;schedule(1,0,1,0.2,A4)
instr 3
idur = p3
icps = 440*powoftwo((p4-69)/12.0)
iamp = p5 *60
irad = p6
k1 linseg 0,idur/3,iamp*0.95,idur*2/3, 0
a1 shaker k1, icps*0.998, 8, 0.999, 100, 0
a2 shaker k1, icps*1.002, 8, 0.999, 100, 0
ares1 wguide2 a1, 30, 100, 10, 150, 0.2, 0.27
ares2 wguide2 a2, 1300, 100, 1100, 150, 0.2, 0.28
k2 linseg 0,idur*2/3,iamp*0.95,idur/3,0
a3 shaker k2, icps*0.999, 8, 0.999, 100, 0
a4 shaker k2, icps*1.001, 8, 0.999, 100, 0
ares3 wguide2 a3, 300, 100, 400, 150, 0.2, 0.25
ares4 wguide2 a4, 1300, 100, 1400, 150, 0.2, 0.25
asig = ares1+ares2+ares3+ares4
arev reverb asig, 1.0
adly delay asig, 0.05, 0
aL = $M_SQRT2/2.0*(cos(irad)+sin(irad))*(asig+arev*0.2+adly)
aR = $M_SQRT2/2.0*(cos(irad)-sin(irad))*(asig+arev*0.2+adly)
outs aL, aR
endin
schedule(3,0,15,37,15,-0.7)
`;
async function play() { // this is the JS function to run Csound
if(csound == null) { // if the Csound object is not initialised
const { Csound } = await import(csoundjs); // import the Csound method
csound = await Csound(); // create a Csound engine object
await csound.setOption("-odac"); // set realtime audio (dac) output
await csound.compileOrc(code); // compile csound code
await csound.start(); // start the engine
} else { // if not just send an event to play a sound
score=`i1 0 1 0.2 440
i3 0 12 40 12 0.2
i1 3 1 0.2 340`;
await csound.inputMessage(score);
}
}
</script>
<body>
<div id="click area" onclick="play()">
<h1>Ping</h1>
<p> Click here to hear a sound.</p>
</div>
<hr>
<p><a href="./readme.html">README</a></p>
<!-- hhmts start -->Last modified: Thu Dec 8 16:09:54 GMT 2022 <!-- hhmts end -->
</body>
</html>