0
나는 이것이 쉽지만 분명한 것처럼 들리지만이 작업을 할 수는 없다는 것을 알고있다. 웹 오디오 API를 사용하여 oscillatorNodes를 만드는 기능을 만드는 방법 Api
이 조각을 참조하십시오ctx = new AudioContext();
gain = ctx.createGain();
gain.connect(ctx.destination);
gain.gain.value = 0.5;
osc1 = ctx.createOscillator();
osc1.connect(gain);
osc1.frequency.value = 450;
osc1.start();
osc1.stop(2);
osc2 = ctx.createOscillator();
osc2.connect(gain);
osc2.frequency.value = 500;
osc2.start();
osc2.stop(2);
console.log("playing");
그것은 문제없이 한 번에 두 개의 발진기를 재생하지만이 코드를 반복합니다. 중복 코드를 함수에 넣으려고해도 함수가 작동하지 않습니다.
ctx = new AudioContext();
gain = ctx.createGain();
createAndPlayOsc(450);
createAndPlayOsc(500);
function createAndPlayOsc(freq){
console.log("creating osc with freq " + freq);
var osc = ctx.createOscillator();
osc.connect(gain);
osc.frequency.value = freq;
osc.start();
osc.stop(2);
console.log("playing osc with freq " + freq);
}
나는 AudioContext
ctx = new AudioContext();
gain = ctx.createGain();
createAndPlayOsc(450, ctx);
createAndPlayOsc(500, ctx);
function createAndPlayOsc(freq, context){
console.log("creating osc with freq " + freq);
var osc = context.createOscillator();
osc.connect(gain);
osc.frequency.value = freq;
osc.start();
osc.stop(2);
console.log("playing osc with freq " + freq);
}
또는 모두 gainNode 문맥을 보낼 경우에도
ctx = new AudioContext();
gain = ctx.createGain();
createAndPlayOsc(450, ctx, gain);
createAndPlayOsc(500, ctx, gain);
function createAndPlayOsc(freq, context, gainNode){
console.log("creating osc with freq " + freq);
var osc = context.createOscillator();
osc.connect(gainNode);
osc.frequency.value = freq;
osc.start();
osc.stop(2);
console.log("playing osc with freq " + freq);
}
나는 무엇을 놓치고?
gain.connect(ctx.destination);
아 ... 너무 쉽게 ... 감사 : – distante