refactored audio context sharing and lazy initialization

pull/89/head
jmoenig 2019-04-01 15:33:45 +02:00
rodzic bc621b6ca7
commit da6ae70e7d
2 zmienionych plików z 13 dodań i 9 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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(
{