kopia lustrzana https://github.com/backface/turtlestitch
use AudioContext to play recorded sounds
rodzic
514ec3a1bf
commit
91f4391509
|
@ -55,6 +55,7 @@
|
||||||
|
|
||||||
### 2019-04-02
|
### 2019-04-02
|
||||||
* Objects, Threads: lazily initialize volume property
|
* Objects, Threads: lazily initialize volume property
|
||||||
|
* Objects: use AudioContext to play recorded sounds
|
||||||
|
|
||||||
### 2019-04-01
|
### 2019-04-01
|
||||||
* Objects: let the Microphone share the Note prototype's AudioContext
|
* Objects: let the Microphone share the Note prototype's AudioContext
|
||||||
|
|
|
@ -3237,16 +3237,25 @@ SpriteMorph.prototype.playSound = function (name) {
|
||||||
this.sounds.asArray(),
|
this.sounds.asArray(),
|
||||||
function (s) {return s.name === name.toString(); }
|
function (s) {return s.name === name.toString(); }
|
||||||
),
|
),
|
||||||
active;
|
ctx = this.audioContext(),
|
||||||
|
gain = this.getGainNode(),
|
||||||
|
aud,
|
||||||
|
source;
|
||||||
if (sound) {
|
if (sound) {
|
||||||
active = sound.play();
|
aud = document.createElement('audio');
|
||||||
|
aud.src = sound.audio.src;
|
||||||
|
source = ctx.createMediaElementSource(aud);
|
||||||
|
source.connect(gain);
|
||||||
|
gain.connect(ctx.destination); // perhaps redundant
|
||||||
|
this.setVolume(this.volume); // probably redundant as well
|
||||||
|
aud.play();
|
||||||
if (stage) {
|
if (stage) {
|
||||||
stage.activeSounds.push(active);
|
stage.activeSounds.push(aud);
|
||||||
stage.activeSounds = stage.activeSounds.filter(function (aud) {
|
stage.activeSounds = stage.activeSounds.filter(function (snd) {
|
||||||
return !aud.ended && !aud.terminated;
|
return !snd.ended && !snd.terminated;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return active;
|
return aud;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8848,6 +8857,8 @@ function Sound(audio, name) {
|
||||||
Sound.prototype.play = function () {
|
Sound.prototype.play = function () {
|
||||||
// return an instance of an audio element which can be terminated
|
// return an instance of an audio element which can be terminated
|
||||||
// externally (i.e. by the stage)
|
// externally (i.e. by the stage)
|
||||||
|
// Note: only to be used by the GUI, not by scripts,
|
||||||
|
// because no effects like volume or panning are applied
|
||||||
var aud = document.createElement('audio');
|
var aud = document.createElement('audio');
|
||||||
aud.src = this.audio.src;
|
aud.src = this.audio.src;
|
||||||
aud.play();
|
aud.play();
|
||||||
|
|
Ładowanie…
Reference in New Issue