我能夠發揮利用synth.noteOnWithFreq()
音符,然後使用synth.noteOff()
的代碼是基於timbre.js項目頁面上的Synthesizer例子結束它們。確保您包含keyboard.js庫,如下所示。
運行的代碼片段,點擊輸入框,並輸入一些字母
var synth = T("OscGen", {
wave: "saw",
mul: 0.25
}).play();
var keydict = T("ndict.key");
var midicps = T("midicps");
T("keyboard").on("keydown", function(e) {
var midi = keydict.at(e.keyCode);
if (midi) {
var freq = midicps.at(midi);
synth.noteOnWithFreq(freq, 100);
window.key.innerHTML = midi;
window.freq.innerHTML = freq.toFixed(2);
}
}).on("keyup", function(e) {
var midi = keydict.at(e.keyCode);
if (midi) {
synth.noteOff(midi, 100);
}
}).start();
<script src="http://mohayonao.github.io/timbre.js/timbre.js"></script>
<script src="http://mohayonao.github.io/timbre.js/src/extras/keyboard.js"></script>
<div>KeyCode: <span id="key"></span>, Freq: <span id="freq"></span></div>
<input id="keyboard" placeholder="Type some letters here">
你有你使用的是什麼已經產生聲音 – user2950720
它的任何代碼在timbre.js庫中(我無法閱讀)https://gitlab.com/mdahmen/Laterreestron.de/blob/master/pagesandapps/partgenie/js/libs/timbre/timbre.js – manueldahmen