我设法使滑块更改为振荡器频率,但不适用于振荡器类型。
这是 jsfiddle 链接 http://jsfiddle.net/ehsanziya/aKDkf/1/
这是JavaScript
$(document).ready(function () {
var context = new webkitAudioContext();
var osc = context.createOscillator();
//initializing oscillator type to 0 (Sinewave)
osc.type=0;
$('oscType').change(function(){
osc.type = $(this).val();
})
//setting initial OSC frequency to 440.
osc.frequency.value = 440;
//changing Oscillator's frequency with the range input
$('#oscFreq').change(function(){
osc.frequency.value = $(this).val()
})
$('#onOff').click(function () {
this.value = this.value === 'ON' ? 'OFF' : 'ON';
});
$('#onOff').click(function () {
var buttonValue = $('#onOff').val();
// creating AudioContext
if (buttonValue === 'OFF') {
osc.connect(context.destination);
osc.noteOn(0);
} else if (buttonValue === 'ON') {
osc.disconnect(0);
}
});
});