2015-10-12 59 views
1

我試圖調製saw頻率與來自慢振盪器sine的脈衝。我究竟做錯了什麼? jsFiddle here:https://jsfiddle.net/06ua9zLo/WebAudio FM調製

window.AudioContext = window.AudioContext||window.webkitAudioContext; 

var context = new AudioContext(); 

var saw  = context.createOscillator(), 
    sine  = context.createOscillator(), 
    sineGain = context.createGain(); 

//set up our oscillator types 
saw.type = 'sawtooth'; 
sine.type = 'sine'; 

//set the amplitude of the modulation 
sineGain.gain.value = 10; 

//connect the dots 
sine.connect(sineGain); 
sineGain.connect(saw.frequency); 

saw.connect(context.destination); 

sine.start(); 
saw.start(); 

回答

3

你的設置很好。試着改變調製器的頻率並增加一點點的增益,你會發現你實際上在做FM。例如:

sine.frequency.value = 15; 
sineGain.gain.value = 100; 

肯定會告訴你,它的工作原理。

+0

準確地說 - 您必須記住每個點的範圍。振盪器從-1變爲1,但只有+/- 1Hz的頻率變化可能沒有多大區別。 – cwilso