MCPcopy
hub / github.com/processing/p5.js / connect

Method connect

src/dom/p5.MediaElement.js:918–953  ·  view source on GitHub ↗

* Sends the element's audio to an output. * * The parameter, `audioNode`, can be an `AudioNode` or an object from the * `p5.sound` library. * * If no element is provided, as in `myElement.connect()`, the element * connects to the main output. All connections are removed by the *

(obj)

Source from the content-addressed store, hash-verified

916 * or an object from the p5.sound library
917 */
918 connect(obj) {
919 let audioContext, mainOutput;
920
921 // if p5.sound exists, same audio context
922 if (this._getAudioContext() && this._getSoundOut()) {
923 audioContext = this._getAudioContext();
924 mainOutput = this._getSoundOut().input;
925 } else {
926 try {
927 audioContext = obj.context;
928 mainOutput = audioContext.destination;
929 } catch (e) {
930 throw 'connect() is meant to be used with Web Audio API or p5.sound.js';
931 }
932 }
933
934 // create a Web Audio MediaElementAudioSourceNode if none already exists
935 if (!this.audioSourceNode) {
936 this.audioSourceNode = audioContext.createMediaElementSource(this.elt);
937
938 // connect to main output when this method is first called
939 this.audioSourceNode.connect(mainOutput);
940 }
941
942 // connect to object if provided
943 if (obj) {
944 if (obj.input) {
945 this.audioSourceNode.connect(obj.input);
946 } else {
947 this.audioSourceNode.connect(obj);
948 }
949 } else {
950 // otherwise connect to main output of p5.sound / AudioContext
951 this.audioSourceNode.connect(mainOutput);
952 }
953 }
954
955 /**
956 * Disconnect all Web Audio routing, including to the main output.

Callers 15

p5.sound.min.jsFile · 0.80
tFunction · 0.80
nFunction · 0.80
iFunction · 0.80
eFunction · 0.80
$Function · 0.80
rFunction · 0.80
sFunction · 0.80
p5.sound.jsFile · 0.80
tFunction · 0.80
rFunction · 0.80
main_MainFunction · 0.80

Calls 2

_getAudioContextMethod · 0.95
_getSoundOutMethod · 0.95

Tested by

no test coverage detected