Skip to content

Commit

Permalink
Did more work on voices. had trouble eliminating pops from pure sine …
Browse files Browse the repository at this point in the history
…waves
  • Loading branch information
sloumdrone committed Jul 3, 2018
1 parent eb31699 commit 392601e
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions lib/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

window.audioContext = new (window.AudioContext || window.webkitAudioContext)();
var ctx = new AudioContext();
var masterGain = ctx.createGain();
masterGain.value = 0.5;
masterGain.connect(ctx.destination);
// var masterGain = ctx.createGain();
// masterGain.value = 0.5;
// masterGain.connect(ctx.destination);
var oscs = {}

const currentBuffer = {
Expand Down Expand Up @@ -207,7 +207,7 @@ $('.bankButton').on('click',function(){
//----]
//--|
$('.play').on('click',function(){
var noteLength = 1 / (currentBuffer['tempo'][0]/60) * 0.5 * 1000;
var noteLength = getNoteLength();
if (!$(this).hasClass('playing')){
$(this).addClass('playing');
state.playing = true;
Expand All @@ -217,6 +217,7 @@ $('.play').on('click',function(){
oscs[x][1].stop(0);
oscs[x][0].disconnect();
oscs[x][1].disconnect();
oscs[x][2].disconnect();
}
oscs = {};
$('.padColHolder.active').removeClass('active');
Expand All @@ -242,8 +243,6 @@ $('.stop').on('click',function(){
oscs[x][1].disconnect();
}

// $('.padColHolder.active').removeClass('active');

if ($('.play').hasClass('playing')){
$('.play').removeClass('playing');
state.playing = false;
Expand Down Expand Up @@ -276,13 +275,14 @@ $('.knob').on('click',function(){
function playNote(note,voice){
var osc = ctx.createOscillator();
var osc2 = ctx.createOscillator();
var gain = ctx.createGain();

osc.frequency.value = note;
osc2.frequency.value = note;
gain.gain.value = 0.8;


if (voice == 1){
console.log('test');
osc.type = 'square';
osc2.type = 'square';
osc.detune.value = -10;
Expand All @@ -294,9 +294,9 @@ function playNote(note,voice){
osc2.detune.value = 10;
} else if (voice == 3){
osc.type = 'sine';
osc2.type = 'sine';
osc.detune.value = -15;
osc2.detune.value = 15;
osc2.type = 'sawtooth';
osc.detune.value = 0;
osc2.detune.value = 0;
} else if (voice == 4){
osc.type = 'triangle';
osc2.type = 'triangle';
Expand All @@ -321,17 +321,23 @@ function playNote(note,voice){



osc.connect(masterGain);
osc2.connect(masterGain);
osc.connect(gain);
osc2.connect(gain);
gain.connect(ctx.destination);

masterGain.connect(ctx.destination);

oscs[note] = [osc,osc2];
oscs[note] = [osc,osc2,gain];

osc.start(ctx.currentTime);
osc2.start(ctx.currentTime);
// gain.gain.setValueAtTime(gain.gain.value,ctx.currentTime);
// gain.gain.exponentialRampToValueAtTime(0.00001, ctx.currentTime + 0.24);

}

function stopNote(note){
oscs[note].stop(ctx.currentTime);
}

function getNoteLength(){
return 1 / (currentBuffer['tempo'][0]/60) * 0.5 * 1000;
}

0 comments on commit 392601e

Please sign in to comment.