Skip to content

Commit 1815846

Browse files
committed
cleaned up, added connect, disconnect, dispose
1 parent fefe04f commit 1815846

File tree

3 files changed

+175
-170
lines changed

3 files changed

+175
-170
lines changed

src/audioVoice.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,23 @@ define(function() {
77
* handles note triggering and what not
88
*/
99
p5.AudioVoice = function () {
10-
11-
12-
//this.osctype = 'sine';
13-
//this.volume= 0.33;
14-
//this.note = 60;
15-
this.note;
16-
17-
// this.attack = 0.25;
18-
// this.decay=0.25;
19-
// this.sustain=0.95;
20-
// this.release=0.25;
21-
//this.env = new p5.Env(this.attack,this.volume, this.decay,this.volume, this.sustain, this.volume,this.release);
22-
23-
//this.filter.set(22050, 5);
24-
25-
//this.env.connect(this.filter);
26-
//
2710
this.ac = p5sound.audiocontext;
2811
this.output = this.ac.createGain();
2912
this.connect();
3013

3114
p5sound.soundArray.push(this);
3215
};
3316

34-
p5.AudioVoice.prototype._setNote = function() {
17+
p5.AudioVoice.prototype._setNote = function(note) {
3518
};
3619

37-
p5.AudioVoice.prototype.play = function () {
20+
p5.AudioVoice.prototype.play = function (note, velocity, secondsFromNow, sustime) {
3821
};
3922

4023
p5.AudioVoice.prototype.triggerAttack = function (note, velocity, secondsFromNow) {
4124
};
4225

43-
p5.AudioVoice.prototype.triggerRelease = function () {
26+
p5.AudioVoice.prototype.triggerRelease = function (secondsFromNow) {
4427
};
4528

4629
p5.AudioVoice.prototype.amp = function(vol, rampTime) {

src/monosynth.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,8 @@ define(function (require) {
2222
p5.MonoSynth = function () {
2323
AudioVoice.call(this);
2424

25-
// this.ac = p5sound.audiocontext;
26-
27-
// this.output = this.ac.createGain();
28-
29-
// this.attack = 0.02;
30-
// this.decay=0.25;
31-
// this.sustain=0.05;
32-
// this.release=0.35;
33-
34-
// default voice
3525
this.oscillator = new p5.Oscillator();
3626

37-
// envelope
3827
this.env = new p5.Env();
3928
this.env.setRange(1, 0);
4029
this.env.setExp(true);
@@ -99,9 +88,12 @@ define(function (require) {
9988

10089
// set range of env (TO DO: allow this to be scheduled in advance)
10190
var vel = velocity || 1;
102-
this.env.setRange(vel, 0);
91+
// this.env.setRange(vel, 0);
92+
93+
// this.env.play(this.output, secondsFromNow, susTime);
10394

104-
this.env.play(this.output, secondsFromNow, susTime);
95+
this.triggerAttack(note,velocity,secondsFromNow);
96+
this.triggerRelease(secondsFromNow + susTime);
10597
};
10698

10799
/**
@@ -133,7 +125,6 @@ define(function (require) {
133125
p5.MonoSynth.prototype.triggerRelease = function (secondsFromNow) {
134126
this.env.ramp(this.output, secondsFromNow, 0);
135127
this._isOn = false;
136-
// this.env.triggerRelease(this.output, secondsFromNow);
137128
};
138129

139130

@@ -151,10 +142,13 @@ define(function (require) {
151142
*/
152143

153144
p5.MonoSynth.prototype.setParams = function(params) {
154-
155145
};
156146

157-
147+
/**
148+
* loads preset values
149+
* @param {String} preset A preset that has been written for MonoSynth
150+
* @return {Object} Return the MonoSynth
151+
*/
158152
p5.MonoSynth.prototype.loadPreset = function(preset) {
159153
var options = this[preset];
160154
this.oscillator.setType(options.oscillator.type);
@@ -219,6 +213,7 @@ define(function (require) {
219213
'res' : 1
220214
}
221215
};
216+
222217
/**
223218
* Set values like a traditional
224219
* <a href="https://en.wikipedia.org/wiki/Synthesizer#/media/File:ADSR_parameter.svg">
@@ -246,6 +241,13 @@ define(function (require) {
246241
};
247242

248243

244+
/**
245+
* Getters and Setters
246+
* @param {Number} attack
247+
* @param {Number} decay
248+
* @param {Number} sustain
249+
* @param {Number} release
250+
*/
249251
Object.defineProperties(p5.MonoSynth, {
250252
'attack': {
251253
get : function() {
@@ -285,12 +287,18 @@ define(function (require) {
285287
},
286288
});
287289

290+
/**
291+
* MonoSynth amp
292+
* @method amp
293+
* @param {Number} vol desired volume
294+
* @param {Number} [rampTime] Time to reach new volume
295+
* @return {Number} new volume value
296+
*/
288297
p5.MonoSynth.prototype.amp = function(vol, rampTime) {
289298
var t = rampTime || 0;
290299
if (typeof vol !== 'undefined') {
291300
this.oscillator.amp(vol, t);
292301
}
293-
294302
return this.oscillator.amp().value;
295303
};
296304

@@ -322,7 +330,7 @@ define(function (require) {
322330
* @method dispose
323331
*/
324332
p5.MonoSynth.prototype.dispose = function() {
325-
AudioVoice.prototype.disposed.apply(this);
333+
AudioVoice.prototype.dispose.apply(this);
326334

327335
this.filter.dispose();
328336
this.env.dispose();

0 commit comments

Comments
 (0)