我在 HTML 文件的标题中有这个脚本。它工作正常,除了delay.connect(Tone.context.destination);
中途的线路,理论上通过延迟启动其中一个来增加 DuoSynth 中声音的分层。
当它没有被注释掉时,我在控制台中得到这个错误:Uncaught TypeError: Failed to execute 'connect' on 'AudioNode': No function was found that matched the signature provided.
我究竟做错了什么?
<script>
function makeSynth() {
let envelope = {
attack: 0.1,
release: 4,
releaseCurve: 'exponential'
};
let filterEnvelope = {
baseFrequency: 440,
octaves: 3,
attack: 0,
decay: 0,
release: 1000
};
return new Tone.DuoSynth({
harmonicity: .5,
detune : 5000,
volume: -20,
voice0: {
oscillator: { type: 'triangle' },
envelope,
filterEnvelope
},
voice1: {
oscillator: { type: 'sine' },
envelope,
filterEnvelope
},
vibratoRate: 0.5,
vibratoAmount: 0.1 // THIS IS GOOD TO MANIPULATE
});
}
let leftSynth = makeSynth();
let rightSynth = makeSynth();
let leftPanner = new Tone.Panner(-0.5).toMaster();
let rightPanner = new Tone.Panner(0.5).toMaster();
let echo = new Tone.FeedbackDelay('16n', 0.2);
let delay = Tone.context.createDelay(6.0); // Borrow the AudioContext from Tone.js
let delayFade = Tone.context.createGain();
delay.delayTime.value = 6.0;
delayFade.gain.value = 0.75;
leftSynth.connect(leftPanner);
rightSynth.connect(rightPanner);
leftPanner.connect(echo);
rightPanner.connect(echo);
// var c = canvas.getContext('2d');
echo.toMaster();
echo.connect(delay);
delay.connect(Tone.context.destination);
delay.connect(delayFade);
delayFade.connect(delay);
new Tone.Loop(time => {
leftSynth.triggerAttackRelease('C6', '1:2', time);
leftSynth.setNote('G5', '+0:2');
leftSynth.setNote('C4', '+0:4');
leftSynth.triggerAttackRelease('G5', '0:2', '+6:0');
leftSynth.triggerAttackRelease('E4', '0:2', '+11:2');
leftSynth.triggerAttackRelease('E5', '2:0', '+19:0');
leftSynth.setNote('G5', '+19:1:2');
leftSynth.setNote('A5', '+19:3:0');
leftSynth.setNote('G5', '+19:4:2');
}, '34m').start();
new Tone.Loop(time => {
// Trigger D4 after 5 measures and hold for 1 full measure + two 1/4 notes
rightSynth.triggerAttackRelease('G6', '1:2', '+5:0');
// Switch to E4 after one more measure
rightSynth.setNote('B6', '+6:0');
// Trigger B3 after 11 measures + two 1/4 notes + two 1/16 notes. Hold for one measure
rightSynth.triggerAttackRelease('D4', '1m', '+11:2:2');
// Switch to G3 after a 1/2 note more
rightSynth.setNote('G3', '+12:0:2');
// Trigger G4 after 23 measures + two 1/4 notes. Hold for a half note.
rightSynth.triggerAttackRelease('G4', '0:2', '+23:2');
}, '37m').start();
</script>