/*
* Patch from the VCO output into the VCA signal input
* Patch from the Keyboard note output into the VCO CV input
* Patch from the VCA output into a speaker
* Patch from the keyboard gate output into the VCA CV input
*/
// set up our Audio Context
var audioContext = new(window.AudioContext || window.webkitAudioContext);
console.log('audioContext', audioContext)
// set up an oscillator, gain, and master gain
var vco = audioContext.createOscillator(),
vca = audioContext.createGain(),
master = audioContext.createGain();
// keep track of active keys
var activeKeys = {};
// setup controls
var waveType = document.querySelector('.wavetype'),
portamento = document.querySelector('.portamento'),
enablePortamento = true,
masterGain = document.querySelector('.master-gain'),
masterGainDisplay = document.querySelector('.master-gain-display');
// connect all modules together and to the master gain, our speaker
// Step 1: Patch from the VCO output into the VCA signal input
vco.connect(vca); // connect oscillator to gain
// Step A (added): Patch from the VCA putput to the master VCA input
vca.connect(master); // connect gain to master gain
// Step 3: Patch from the master VCA output into a speaker
master.connect(audioContext.destination); // connect master gain to speakers
// start the vco
vco.start(0);
// set initial gain values
vca.gain.value = 0; // set gain to 0, a keypress will set it to 1
master.gain.value = 1; // master gain at full volume
// Controls
waveType.onchange = function () {
changeWaveType(waveType.value);
}
portamento.onchange = function () {
enablePortamento = portamento.checked;
}
masterGain.oninput = function () {
changeMaster(masterGain.value);
}
function changeWaveType(type) {
vco.type = type;
}
function changeMaster(vol) {
master.gain.value = vol;
masterGainDisplay.innerHTML = vol;
}
// helper functions
function frequencyFromNote(note) {
return 440 * Math.pow(2, (note - 69) /...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.