mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Apply sprite's volume to music extension notes and drums (#1735)
* Use a gain node for volume instead of effects chain * Use a gain node for volume for drums too
This commit is contained in:
parent
5802723dc7
commit
045ebb5026
1 changed files with 15 additions and 10 deletions
|
@ -886,9 +886,10 @@ class Scratch3MusicBlocks {
|
|||
}
|
||||
|
||||
const engine = util.runtime.audioEngine;
|
||||
const chain = engine.createEffectChain();
|
||||
chain.setEffectsFromTarget(util.target);
|
||||
player.connect(chain);
|
||||
const context = engine.audioContext;
|
||||
const volumeGain = context.createGain();
|
||||
volumeGain.gain.setValueAtTime(util.target.volume / 100, engine.currentTime);
|
||||
volumeGain.connect(engine.getInputNode());
|
||||
|
||||
this._concurrencyCounter++;
|
||||
player.once('stop', () => {
|
||||
|
@ -896,6 +897,10 @@ class Scratch3MusicBlocks {
|
|||
});
|
||||
|
||||
player.play();
|
||||
// Connect the player to the gain node.
|
||||
player.connect({getInputNode () {
|
||||
return volumeGain;
|
||||
}});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -997,18 +1002,18 @@ class Scratch3MusicBlocks {
|
|||
player.take();
|
||||
}
|
||||
|
||||
const chain = engine.createEffectChain();
|
||||
chain.setEffectsFromTarget(util.target);
|
||||
|
||||
// Set its pitch.
|
||||
const sampleNote = sampleArray[sampleIndex];
|
||||
const notePitchInterval = this._ratioForPitchInterval(note - sampleNote);
|
||||
|
||||
// Create a gain node for this note, and connect it to the sprite's
|
||||
// simulated effectChain.
|
||||
// Create gain nodes for this note's volume and release, and chain them
|
||||
// to the output.
|
||||
const context = engine.audioContext;
|
||||
const volumeGain = context.createGain();
|
||||
volumeGain.gain.setValueAtTime(util.target.volume / 100, engine.currentTime);
|
||||
const releaseGain = context.createGain();
|
||||
releaseGain.connect(chain.getInputNode());
|
||||
volumeGain.connect(releaseGain);
|
||||
releaseGain.connect(engine.getInputNode());
|
||||
|
||||
// Schedule the release of the note, ramping its gain down to zero,
|
||||
// and then stopping the sound.
|
||||
|
@ -1030,7 +1035,7 @@ class Scratch3MusicBlocks {
|
|||
player.play();
|
||||
// Connect the player to the gain node.
|
||||
player.connect({getInputNode () {
|
||||
return releaseGain;
|
||||
return volumeGain;
|
||||
}});
|
||||
// Set playback now after play creates the outputNode.
|
||||
player.outputNode.playbackRate.value = notePitchInterval;
|
||||
|
|
Loading…
Reference in a new issue