kopia lustrzana https://github.com/backface/turtlestitch
refactored audio context sharing and lazy initialization
rodzic
bc621b6ca7
commit
da6ae70e7d
|
@ -56,6 +56,7 @@
|
|||
### 2019-04-01
|
||||
* Objects: let the Microphone share the Note prototype's AudioContext
|
||||
* Objects: took out gain node from Note oscillator (will be used for "volume" setting)
|
||||
* Objects: refactored audio context sharing and lazy initialization
|
||||
|
||||
### 2019-03-31
|
||||
* Blocks, Threads: added "stage width" and "stage height" as gettable attributes to MY
|
||||
|
|
|
@ -8886,6 +8886,16 @@ Note.prototype.setupContext = function () {
|
|||
*/
|
||||
};
|
||||
|
||||
Note.prototype.getAudioContext = function () {
|
||||
// lazily initializes and shares the Note prototype's audio context
|
||||
// to be used by all other Snap! objects requiring audio,
|
||||
// e.g. the microphone, the sprites, etc.
|
||||
if (!this.audioContext) {
|
||||
this.setupContext();
|
||||
}
|
||||
return this.audioContext;
|
||||
};
|
||||
|
||||
// Note playing
|
||||
|
||||
Note.prototype.play = function (type) {
|
||||
|
@ -9002,17 +9012,10 @@ Microphone.prototype.setResolution = function (num) {
|
|||
Microphone.prototype.start = function () {
|
||||
var myself = this;
|
||||
|
||||
if (this.isStarted) {
|
||||
return;
|
||||
}
|
||||
if (this.isStarted) {return; }
|
||||
this.isStarted = true;
|
||||
|
||||
this.isReady = false;
|
||||
// share Note's audioContext:
|
||||
if (!Note.prototype.audioContext) {
|
||||
Note.prototype.setupContext();
|
||||
}
|
||||
this.audioContext = Note.prototype.audioContext;
|
||||
this.audioContext = Note.prototype.getAudioContext();
|
||||
|
||||
navigator.mediaDevices.getUserMedia(
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue