Skip to content

Commit c22c641

Browse files
committed
source nodes extend P5SoundSourceNode
1 parent eb7d04b commit c22c641

File tree

5 files changed

+274
-390
lines changed

5 files changed

+274
-390
lines changed

src/Noise.js

Lines changed: 0 additions & 116 deletions
This file was deleted.

src/AudioIn.js renamed to src/nodes/source/P5SoundAudioIn.js

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
* @for p5.sound
55
*/
66

7-
import { Context as ToneContext } from "tone/build/esm/core/context/Context.js";
8-
import { gainToDb as ToneGainToDb } from "tone/build/esm/core/type/Conversions.js";
97
import { UserMedia as ToneUserMedia} from "tone/build/esm/source/UserMedia.js";
108
import { start as ToneStart } from "tone/build/esm/core/Global.js";
9+
import { P5SoundSourceNode } from "../core/P5SoundSourceNode.js";
1110
/**
1211
* Get sound from an input source, typically a computer microphone.
1312
* @class AudioIn
@@ -23,8 +22,8 @@ import { start as ToneStart } from "tone/build/esm/core/Global.js";
2322
* background(220);
2423
*
2524
* mic = new p5.AudioIn();
26-
* delay = new p5.Delay(0.74, 0.1);
27-
* filter = new p5.Biquad(600, "bandpass");
25+
* delay = new p5.P5SoundDelay(0.74, 0.1);
26+
* filter = new p5.P5SoundBiquad(600, "bandpass");
2827
*
2928
* mic.disconnect();
3029
* mic.connect(delay);
@@ -49,61 +48,47 @@ import { start as ToneStart } from "tone/build/esm/core/Global.js";
4948
* </code>
5049
* </div>
5150
*/
52-
class AudioIn {
53-
constructor() {
54-
this.audioIn = new ToneUserMedia();
51+
export class P5SoundAudioIn extends P5SoundSourceNode
52+
{
53+
constructor()
54+
{
55+
super();
56+
57+
this._toneUserMediaNode = new ToneUserMedia();
58+
59+
this.configureOutput(this._toneUserMediaNode);
5560
}
61+
62+
isP5SoundAudioIn = true;
63+
5664
/**
5765
* Start the audio input.
5866
* @method start
5967
* @for AudioIn
6068
*/
61-
start() {
69+
start()
70+
{
6271
ToneStart();
63-
this.audioIn.open().then(() => {
72+
73+
this._toneUserMediaNode.open().then(() =>
74+
{
6475
// promise resolves when input is available
6576
console.log("mic open");
6677
// print the incoming mic levels in decibels
67-
}).catch(e => {
78+
}).catch(e =>
79+
{
6880
// promise is rejected when the user doesn't have or allow mic access
6981
console.log("mic not open");
7082
});
7183
}
84+
7285
/**
7386
* Stop the audio input.
7487
* @method stop
7588
* @for AudioIn
7689
*/
77-
stop() {
78-
this.audioIn.close();
90+
stop()
91+
{
92+
this._toneUserMediaNode.close();
7993
}
80-
81-
/**
82-
* Set amplitude (volume) of a mic input between 0 and 1.0.
83-
* @method amp
84-
* @for AudioIn
85-
* @param {Number} amplitudeAmount An amplitude value between 0 and 1.
86-
*/
87-
amp(value) {
88-
let dbValue = ToneGainToDb(value);
89-
this.delay.volume.rampTo(dbValue, 0.1);
90-
}
91-
92-
getNode() {
93-
return this.audioIn;
94-
}
95-
96-
connect(destination) {
97-
if (typeof destination.getNode === 'function') {
98-
this.audioIn.connect(destination.getNode());
99-
} else {
100-
this.audioIn.connect(destination);
101-
}
102-
}
103-
104-
disconnect() {
105-
this.audioIn.disconnect(ToneContext.destination);
106-
}
107-
}
108-
109-
export default AudioIn;
94+
}

0 commit comments

Comments
 (0)