Tone.ExternalInput
↳ EXTENDS Tone.SourceTone.ExternalInput is a WebRTC Audio Input. Check Media Stream API Support to see which browsers are supported. As of writing this, Chrome, Firefox, and Opera support Media Stream. Chrome allows enumeration of the sources, and access to device name over a secure (HTTPS) connection. See https://simpl.info vs http://simple.info on a Chrome browser for the difference.
CONSTRUCTOR
new Tone.ExternalInput ( [If multiple inputs are present, select the input number. Chrome only.
DEFAULTS
EXAMPLE
//select the third input
var motu = new Tone.ExternalInput(3);
//opening the input asks the user to activate their mic
motu.open(function(){
//opening is activates the microphone
//starting lets audio through
motu.start(10);
});Members
.mute
↝ boolean #Mute the output.
EXAMPLE
//mute the output
source.mute = true;.state
↝ Tone.State READONLY #Returns the playback state of the source, either “started” or “stopped”.
.volume
↝ Decibels #The volume of the output in decibels.
EXAMPLE
source.volume.value = -6;Methods
.open ( )
#The callback function to execute when the stream is open
The callback function to execute when the media stream can’t open. This is fired either because the browser doesn’t support the media stream, or the user blocked opening the microphone.
this
Open the media stream
.unsync ( )
#this
Unsync the source to the Transport. See Tone.Source.sync
.start ( )
#When the source should be started.
this
Start the source at the specified time. If no time is given, start the source now.
EXAMPLE
source.start("+0.5"); //starts the source 0.5 seconds from now.stop ( )
#When the source should be stopped.
this
Stop the source at the specified time. If no time is given, stop the source now.
EXAMPLE
source.stop(); // stops the source immediately.sync ( )
#this
Sync the source to the Transport so that all subsequent calls to start and stop are synced to the TransportTime instead of the AudioContext time.
EXAMPLE
//sync the source so that it plays between 0 and 0.3 on the Transport's timeline
source.sync().start(0).stop(0.3);
//start the transport.
Tone.Transport.start();
EXAMPLE
//start the transport with an offset and the sync'ed sources
//will start in the correct position
source.sync().start(0.1);
//the source will be invoked with an offset of 0.4
Tone.Transport.start("+0.5", 0.5);Static Methods
.getSources ( )
#Callback to be executed after populating list
this
Populates the source list. Invokes the callback with an array of possible audio sources.
EXAMPLE
var soundflower = new Tone.ExternalInput();
Tone.ExternalInput.getSources(selectSoundflower);
function selectSoundflower(sources){
for(var i = 0; i < sources.length; i++){
if(sources[i].label === "soundflower"){
soundflower.inputNum = i;
soundflower.open(function(){
soundflower.start();
});
break;
}
}
};