Skip to content

Commit 2a3fcf7

Browse files
committed
(Docs) : resolved confilcts
Signed-off-by: Abhijay Jain <[email protected]>
2 parents 9f3561e + 401120d commit 2a3fcf7

File tree

10 files changed

+156
-56
lines changed

10 files changed

+156
-56
lines changed

src/audioin.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,47 @@ p5sound.inputSources = [];
5050
*/
5151
class AudioIn {
5252
constructor(errorCallback) {
53-
// set up audio input
5453
/**
54+
* Set up audio input
5555
* @property {GainNode} input
5656
*/
5757
this.input = p5sound.audiocontext.createGain();
5858
/**
59+
* Send audio as an output, i.e. your computer's speaker.
5960
* @property {GainNode} output
6061
*/
6162
this.output = p5sound.audiocontext.createGain();
62-
6363
/**
64+
* Used to store the MediaStream object that is returned from the getUserMedia() API,
65+
* which allows access to the user's microphone. The stream is used to create a MediaStreamAudioSourceNode,
66+
* which is used as the audio source for the input and output gain nodes.
67+
* The stream is also used to check if the browser supports the MediaStreamTrack and mediaDevices API,
68+
* and if not, an errorCallback function is called or an alert is displayed.
6469
* @property {MediaStream|null} stream
6570
*/
6671
this.stream = null;
6772
/**
73+
* Used to access the "audio input" from the user's microphone.
74+
* It creates a MediaStream object that can be used to start and stop the mic and measure its volume using the getLevel() method or by connecting it to an FFT object.
75+
* MediaStream object can also be use to check if the browser supports MediaStreamTrack and mediaDevices and to add the AudioIn object to the soundArray for disposal on close.
6876
* @property {MediaStreamAudioSourceNode|null} mediaStream
6977
*/
7078
this.mediaStream = null;
7179
/**
80+
* Used to store the "current source of audio input", such as the user's microphone.
81+
* Initially set to "null" and can be updated as the user selects different audio sources.
82+
* Also used in conjunction with the "input" and "mediaStream" properties to control audio input.
7283
* @property {Number|null} currentSource
7384
*/
7485
this.currentSource = null;
75-
7686
/**
7787
* Client must allow browser to access their microphone / audioin source.
7888
* Default: false. Will become true when the client enables access.
79-
*
8089
* @property {Boolean} enabled
8190
*/
8291
this.enabled = false;
83-
8492
/**
8593
* Input amplitude, connect to it by default but not to master out
86-
*
8794
* @property {p5.Amplitude} amplitude
8895
*/
8996
this.amplitude = new Amplitude();

src/effect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import CrossFade from 'Tone/component/CrossFade.js';
1313
* <a href="/reference/#/p5.Filter">p5.Filter</a>,
1414
* <a href="/reference/#/p5.Reverb">p5.Reverb</a>,
1515
* <a href="/reference/#/p5.EQ">p5.EQ</a>,
16+
* <a href="/reference/#/p5.Panner">p5.Panner</a>.
1617
* <a href="/reference/#/p5.Panner3D">p5.Panner3D</a>.
1718
*
1819
* @class p5.Effect

src/monosynth.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,21 @@ class MonoSynth extends AudioVoice {
7777
* @for p5.MonoSynth
7878
*/
7979
/**
80+
* Allows user to set the decay time of the envelope (ADSR) of the MonoSynth class.
81+
* It is a getter and setter that can be used to retrieve or change the decay time.
82+
* Used in conjunction with the attack, sustain, and release fields/functions to set the full envelope of the synthesizer.
8083
* @property {Number} decay
8184
* @for p5.MonoSynth
8285
*/
8386
/**
87+
* Allows the user to retrieve and adjust the sustain level of the envelope,
88+
* which controls the level at which the sound is sustained during the sustain phase of the envelope.
89+
* The default sustain level is set to 0.15.
8490
* @property {Number} sustain
8591
* @for p5.MonoSynth
8692
*/
8793
/**
94+
* Allows the user to access and change the release time of the envelope.
8895
* @property {Number} release
8996
* @for p5.MonoSynth
9097
*/

src/oscillator.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ class Oscillator {
133133

134134
this.oscillator.connect(this.output);
135135
// stereo panning
136-
this.panPosition = 0.0;
137136
this.connection = p5sound.input; // connect to p5sound by default
138-
this.panner = new Panner(this.output, this.connection, 1);
139137

138+
if (typeof p5sound.audiocontext.createStereoPanner !== 'undefined') {
139+
this.panner = new Panner();
140+
this.output.connect(this.panner);
141+
} else {
142+
this.panner = new Panner(this.output, this.connection, 1);
143+
}
140144
//array of math operation signal chaining
141145
this.mathOps = [this.output];
142146

@@ -415,21 +419,20 @@ class Oscillator {
415419
* seconds from now
416420
*/
417421
pan(pval, tFromNow) {
418-
this.panPosition = pval;
419422
this.panner.pan(pval, tFromNow);
420423
}
421424

422425
/**
423-
* Returns the current value of panPosition , between Left (-1) and Right (1)
426+
* Returns the current value of pan position , between Left (-1) and Right (1)
424427
*
425428
* @method getPan
426429
* @for p5.Oscillator
427430
*
428-
* @returns {number} panPosition of oscillator , between Left (-1) and Right (1)
431+
* @returns {number} pan position of oscillator , between Left (-1) and Right (1)
429432
*/
430433

431434
getPan() {
432-
return this.panPosition;
435+
return this.panner.getPan();
433436
}
434437

435438
// get rid of the oscillator
@@ -442,6 +445,7 @@ class Oscillator {
442445
var now = p5sound.audiocontext.currentTime;
443446
this.stop(now);
444447
this.disconnect();
448+
this.panner.dispose();
445449
this.panner = null;
446450
this.oscillator = null;
447451
}

src/panner.js

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,85 @@
1+
import Effect from './effect.js';
2+
13
import p5sound from './main';
24
var ac = p5sound.audiocontext;
35
var panner;
46
// Stereo panner
57
// if there is a stereo panner node use it
68
if (typeof ac.createStereoPanner !== 'undefined') {
7-
class Panner {
8-
constructor(input, output) {
9-
this.stereoPanner = this.input = ac.createStereoPanner();
10-
input.connect(this.stereoPanner);
11-
this.stereoPanner.connect(output);
9+
/**
10+
* The Panner class allows you to control the stereo
11+
* panning of a sound source. It uses the [StereoPannerNode](https://developer.mozilla.org/en-US/docs/Web/API/StereoPannerNode),
12+
* which allows you to adjust the balance between the left and right channels of a sound source.
13+
*
14+
* This class extends <a href = "/reference/#/p5.Effect">p5.Effect</a>.
15+
* Methods <a href = "/reference/#/p5.Effect/amp">amp()</a>, <a href = "/reference/#/p5.Effect/chain">chain()</a>,
16+
* <a href = "/reference/#/p5.Effect/drywet">drywet()</a>, <a href = "/reference/#/p5.Effect/connect">connect()</a>, and
17+
* <a href = "/reference/#/p5.Effect/disconnect">disconnect()</a> are available.
18+
*
19+
* @class p5.Panner
20+
* @extends p5.Effect
21+
*/
22+
class Panner extends Effect {
23+
constructor() {
24+
super();
25+
this.stereoPanner = this.ac.createStereoPanner();
26+
27+
this.input.connect(this.stereoPanner);
28+
this.stereoPanner.connect(this.wet);
1229
}
1330

31+
/**
32+
* Set the stereo pan position, a value of -1 means the sound will be fully panned
33+
* to the left, a value of 0 means the sound will be centered, and a value of 1 means
34+
* the sound will be fully panned to the right.
35+
* @method pan
36+
* @for p5.Panner
37+
* @param {Number} value A value between -1 and 1 that sets the pan position.
38+
*
39+
* @param {Number} [time] time in seconds that it will take for the panning to change to the specified value.
40+
*/
1441
pan(val, tFromNow) {
15-
var time = tFromNow || 0;
16-
var t = ac.currentTime + time;
17-
18-
this.stereoPanner.pan.linearRampToValueAtTime(val, t);
42+
if (typeof val === 'number') {
43+
let time = tFromNow || 0;
44+
this.stereoPanner.pan.linearRampToValueAtTime(
45+
val,
46+
this.ac.currentTime + time
47+
);
48+
} else if (typeof val !== 'undefined') {
49+
val.connect(this.stereoPanner.pan);
50+
}
1951
}
2052

21-
//not implemented because stereopanner
22-
//node does not require this and will automatically
23-
//convert single channel or multichannel to stereo.
24-
//tested with single and stereo, not with (>2) multichannel
25-
inputChannels() {}
26-
27-
connect(obj) {
28-
this.stereoPanner.connect(obj);
53+
/**
54+
* Return the current panning value.
55+
*
56+
* @method getPan
57+
* @for p5.Panner
58+
* @return {Number} current panning value, number between -1 (left) and 1 (right).
59+
*/
60+
getPan() {
61+
return this.stereoPanner.pan.value;
2962
}
3063

31-
disconnect() {
64+
/**
65+
* Get rid of the Panner and free up its resources / memory.
66+
*
67+
* @method dispose
68+
* @for p5.Panner
69+
*/
70+
dispose() {
71+
super.dispose();
3272
if (this.stereoPanner) {
3373
this.stereoPanner.disconnect();
74+
delete this.stereoPanner;
3475
}
3576
}
77+
78+
//not implemented because stereopanner
79+
//node does not require this and will automatically
80+
//convert single channel or multichannel to stereo.
81+
//tested with single and stereo, not with (>2) multichannel
82+
inputChannels() {}
3683
}
3784

3885
panner = Panner;
@@ -45,6 +92,7 @@ if (typeof ac.createStereoPanner !== 'undefined') {
4592
this.input = ac.createGain();
4693
input.connect(this.input);
4794

95+
this.panValue = 0;
4896
this.left = ac.createGain();
4997
this.right = ac.createGain();
5098
this.left.channelInterpretation = 'discrete';
@@ -70,6 +118,7 @@ if (typeof ac.createStereoPanner !== 'undefined') {
70118

71119
// -1 is left, +1 is right
72120
pan(val, tFromNow) {
121+
this.panValue = val;
73122
var time = tFromNow || 0;
74123
var t = ac.currentTime + time;
75124
var v = (val + 1) / 2;
@@ -79,6 +128,10 @@ if (typeof ac.createStereoPanner !== 'undefined') {
79128
this.right.gain.linearRampToValueAtTime(rightVal, t);
80129
}
81130

131+
getPan() {
132+
return this.panValue;
133+
}
134+
82135
inputChannels(numChannels) {
83136
if (numChannels === 1) {
84137
this.input.disconnect();
@@ -104,6 +157,29 @@ if (typeof ac.createStereoPanner !== 'undefined') {
104157
this.output.disconnect();
105158
}
106159
}
160+
161+
dispose() {
162+
if (this.input) {
163+
this.input.disconnect();
164+
delete this.input;
165+
}
166+
if (this.output) {
167+
this.output.disconnect();
168+
delete this.output;
169+
}
170+
if (this.left) {
171+
this.left.disconnect();
172+
delete this.left;
173+
}
174+
if (this.right) {
175+
this.right.disconnect();
176+
delete this.right;
177+
}
178+
if (this.splitter) {
179+
this.splitter.disconnect();
180+
delete this.splitter;
181+
}
182+
}
107183
}
108184
panner = Panner;
109185
}

src/peakDetect.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ class PeakDetect {
111111
this.currentValue = 0;
112112

113113
/**
114-
* isDetected is set to true when a peak is detected.
115-
*
114+
* It returns a boolean indicating whether a peak in the audio frequency spectrum has been detected or not.
116115
* @attribute isDetected {Boolean}
117116
* @default false
117+
* @property {Number} isDetected
118+
* @for p5.PeakDetect
118119
*/
119120
this.isDetected = false;
120121

src/soundfile.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ class SoundFile {
182182
this.startMillis = null;
183183

184184
// stereo panning
185-
this.panPosition = 0.0;
186-
this.panner = new Panner(this.output, p5sound.input, 2);
185+
if (typeof p5sound.audiocontext.createStereoPanner !== 'undefined') {
186+
this.panner = new Panner();
187+
this.output.connect(this.panner);
188+
} else {
189+
this.panner = new Panner(this.output, p5sound.input, 2);
190+
}
187191

188192
// it is possible to instantiate a soundfile with no path
189193
if (this.url || this.file) {
@@ -795,7 +799,6 @@ class SoundFile {
795799
* </div></code>
796800
*/
797801
pan(pval, tFromNow) {
798-
this.panPosition = pval;
799802
this.panner.pan(pval, tFromNow);
800803
}
801804

@@ -809,7 +812,7 @@ class SoundFile {
809812
* 0.0 is center and default.
810813
*/
811814
getPan() {
812-
return this.panPosition;
815+
return this.panner.getPan();
813816
}
814817

815818
/**
@@ -1264,7 +1267,7 @@ class SoundFile {
12641267
this.output = null;
12651268
}
12661269
if (this.panner) {
1267-
this.panner.disconnect();
1270+
this.panner.dispose();
12681271
this.panner = null;
12691272
}
12701273
}

test/tests/p5.Oscillator.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,8 @@ describe('p5.Oscillator', function () {
214214
it('can be panned without any delay', function (done) {
215215
let osc = new p5.Oscillator();
216216
let panner = osc.panner;
217-
expect(osc.panPosition).to.equal(0); //default value
218217
expect(osc.getPan()).to.equal(0);
219218
osc.pan(-0.3);
220-
expect(osc.panPosition).to.equal(-0.3);
221-
expect(osc.getPan()).to.equal(-0.3);
222219
if (typeof p5.soundOut.audiocontext.createStereoPanner !== 'undefined') {
223220
setTimeout(() => {
224221
expect(panner.stereoPanner.pan.value).to.be.approximately(-0.3, 0.01);
@@ -236,8 +233,6 @@ describe('p5.Oscillator', function () {
236233
let osc = new p5.Oscillator();
237234
osc.pan(0.7, 0.1);
238235
let panner = osc.panner;
239-
expect(osc.panPosition).to.equal(0.7);
240-
expect(osc.getPan()).to.equal(0.7);
241236
if (typeof p5.soundOut.audiocontext.createStereoPanner !== 'undefined') {
242237
setTimeout(() => {
243238
expect(panner.stereoPanner.pan.value).to.not.be.approximately(
@@ -250,7 +245,7 @@ describe('p5.Oscillator', function () {
250245
0.01
251246
);
252247
done();
253-
}, 50);
248+
}, 60);
254249
}, 50);
255250
} else {
256251
setTimeout(() => {
@@ -266,7 +261,7 @@ describe('p5.Oscillator', function () {
266261
expect(panner.left.gain.value).to.be.approximately(0.972, 0.001);
267262
expect(panner.right.gain.value).to.be.approximately(0.233, 0.001);
268263
done();
269-
}, 100);
264+
}, 60);
270265
}, 50);
271266
}
272267
});

0 commit comments

Comments
 (0)