Skip to content

Commit 3e5c085

Browse files
authored
Merge pull request #305 from therewasaguy/patch/monosynth-velocity
patch monosynth velocity
2 parents 0db6b7d + 2354b75 commit 3e5c085

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/master.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ define(function () {
1212

1313
//put a hard limiter on the output
1414
this.limiter = audiocontext.createDynamicsCompressor();
15-
this.limiter.threshold.value = 0;
15+
this.limiter.threshold.value = -3;
1616
this.limiter.ratio.value = 20;
17+
this.limiter.knee.value = 1;
1718

1819
this.audiocontext = audiocontext;
1920

src/monosynth.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ define(function (require) {
5050
AudioVoice.call(this);
5151

5252
this.oscillator = new p5.Oscillator();
53-
// this.oscillator.disconnect();
5453

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

62-
// filter
63-
this.filter = new p5.Filter('highpass');
64-
this.filter.set(5, 1);
65-
66-
// oscillator --> env --> filter --> this.output (gain) --> p5.soundOut
61+
// oscillator --> env --> this.output (gain) --> p5.soundOut
6762
this.oscillator.disconnect();
68-
this.oscillator.connect(this.filter);
63+
this.oscillator.connect(this.output);
64+
6965
this.env.disconnect();
70-
this.env.setInput(this.oscillator);
71-
// this.env.connect(this.filter);
72-
this.filter.connect(this.output);
66+
this.env.setInput(this.output.gain);
67+
68+
// reset oscillator gain to 1.0
69+
this.oscillator.output.gain.value = 1.0;
7370

7471
this.oscillator.start();
7572
this.connect();
7673

77-
//Audiovoices are connected to soundout by default
78-
79-
this._isOn = false;
80-
8174
p5sound.soundArray.push(this);
8275
};
8376

@@ -162,9 +155,8 @@ define(function (require) {
162155
var secondsFromNow = ~~secondsFromNow;
163156
var freq = noteToFreq(note);
164157
var vel = velocity || 0.1;
165-
this._isOn = true;
166158
this.oscillator.freq(freq, 0, secondsFromNow);
167-
this.env.ramp(this.output, secondsFromNow, vel);
159+
this.env.ramp(this.output.gain, secondsFromNow, vel);
168160
};
169161

170162
/**
@@ -189,8 +181,7 @@ define(function (require) {
189181
*/
190182
p5.MonoSynth.prototype.triggerRelease = function (secondsFromNow) {
191183
var secondsFromNow = secondsFromNow || 0;
192-
this.env.ramp(this.output, secondsFromNow, 0);
193-
this._isOn = false;
184+
this.env.ramp(this.output.gain, secondsFromNow, 0);
194185
};
195186

196187
/**
@@ -319,9 +310,6 @@ define(function (require) {
319310
p5.MonoSynth.prototype.dispose = function() {
320311
AudioVoice.prototype.dispose.apply(this);
321312

322-
if (this.filter) {
323-
this.filter.dispose();
324-
}
325313
if (this.env) {
326314
this.env.dispose();
327315
}

0 commit comments

Comments
 (0)