Skip to content

Commit

Permalink
Merge pull request #305 from therewasaguy/patch/monosynth-velocity
Browse files Browse the repository at this point in the history
patch monosynth velocity
  • Loading branch information
therewasaguy authored Jul 2, 2018
2 parents 0db6b7d + 2354b75 commit 3e5c085
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ define(function () {

//put a hard limiter on the output
this.limiter = audiocontext.createDynamicsCompressor();
this.limiter.threshold.value = 0;
this.limiter.threshold.value = -3;
this.limiter.ratio.value = 20;
this.limiter.knee.value = 1;

this.audiocontext = audiocontext;

Expand Down
30 changes: 9 additions & 21 deletions src/monosynth.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ define(function (require) {
AudioVoice.call(this);

this.oscillator = new p5.Oscillator();
// this.oscillator.disconnect();

this.env = new p5.Envelope();
this.env.setRange(1, 0);
Expand All @@ -59,25 +58,19 @@ define(function (require) {
//set params
this.setADSR(0.02, 0.25, 0.05, 0.35);

// filter
this.filter = new p5.Filter('highpass');
this.filter.set(5, 1);

// oscillator --> env --> filter --> this.output (gain) --> p5.soundOut
// oscillator --> env --> this.output (gain) --> p5.soundOut
this.oscillator.disconnect();
this.oscillator.connect(this.filter);
this.oscillator.connect(this.output);

this.env.disconnect();
this.env.setInput(this.oscillator);
// this.env.connect(this.filter);
this.filter.connect(this.output);
this.env.setInput(this.output.gain);

// reset oscillator gain to 1.0
this.oscillator.output.gain.value = 1.0;

this.oscillator.start();
this.connect();

//Audiovoices are connected to soundout by default

this._isOn = false;

p5sound.soundArray.push(this);
};

Expand Down Expand Up @@ -162,9 +155,8 @@ define(function (require) {
var secondsFromNow = ~~secondsFromNow;
var freq = noteToFreq(note);
var vel = velocity || 0.1;
this._isOn = true;
this.oscillator.freq(freq, 0, secondsFromNow);
this.env.ramp(this.output, secondsFromNow, vel);
this.env.ramp(this.output.gain, secondsFromNow, vel);
};

/**
Expand All @@ -189,8 +181,7 @@ define(function (require) {
*/
p5.MonoSynth.prototype.triggerRelease = function (secondsFromNow) {
var secondsFromNow = secondsFromNow || 0;
this.env.ramp(this.output, secondsFromNow, 0);
this._isOn = false;
this.env.ramp(this.output.gain, secondsFromNow, 0);
};

/**
Expand Down Expand Up @@ -319,9 +310,6 @@ define(function (require) {
p5.MonoSynth.prototype.dispose = function() {
AudioVoice.prototype.dispose.apply(this);

if (this.filter) {
this.filter.dispose();
}
if (this.env) {
this.env.dispose();
}
Expand Down

0 comments on commit 3e5c085

Please sign in to comment.