| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head></head> |
| 4 |
<body> |
| 5 |
<script type="module"> |
| 6 |
const url = "/dist/csound.js"; |
| 7 |
import("/dist/csound.js").then(async (module) => { |
| 8 |
/* const [exampleUrl, fileName] = ["https://upload.wikimedia.org/wikipedia/commons/a/a1/Audio_Sample_-_The_Quick_Brown_Fox_Jumps_Over_The_Lazy_Dog.ogg", "test.ogg"] */ |
| 9 |
const [exampleUrl, fileName] = [ |
| 10 |
"https://csound.com/docs/manual/examples/beats.mp3", |
| 11 |
"test.mp3", |
| 12 |
]; |
| 13 |
|
| 14 |
const runIt = async () => { |
| 15 |
const { Csound } = await import(url); |
| 16 |
const csound = await Csound({ useWorker: false, useSAB: false }); |
| 17 |
const response = await fetch(exampleUrl); |
| 18 |
const testSampleArrayBuffer = await response.arrayBuffer(); |
| 19 |
const testSample = new Uint8Array(testSampleArrayBuffer); |
| 20 |
await csound.fs.writeFile(fileName, testSample); |
| 21 |
await csound.setOption("-odac"); |
| 22 |
await csound.compileCsdText(` |
| 23 |
<CsoundSynthesizer> |
| 24 |
<CsOptions> |
| 25 |
-odac |
| 26 |
</CsOptions> |
| 27 |
<CsInstruments> |
| 28 |
0dbfs = 1 |
| 29 |
instr 1 |
| 30 |
ktrans linseg 1, 5, 2, 10, -2 |
| 31 |
a1 diskin2 "${fileName}", ktrans, 0, 1, 0, 32 |
| 32 |
prints "HELLO!\\n" |
| 33 |
outs a1 |
| 34 |
endin |
| 35 |
</CsInstruments> |
| 36 |
<CsScore> |
| 37 |
i 1 0 15 |
| 38 |
i 1 + . |
| 39 |
</CsScore> |
| 40 |
</CsoundSynthesizer> |
| 41 |
`); |
| 42 |
await csound.start(); |
| 43 |
}; |
| 44 |
|
| 45 |
const triggerEvent = "ontouchstart" in document.documentElement ? "touchend" : "click"; |
| 46 |
document.querySelector("#all_tests").addEventListener(triggerEvent, async function () { |
| 47 |
await runIt(); |
| 48 |
}); |
| 49 |
const Csound = await module.Csound; |
| 50 |
}); |
| 51 |
</script> |
| 52 |
<button id="all_tests">Run Diskin Test</button> |
| 53 |
</body> |
| 54 |
</html> |