mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 15:02:06 -05:00
playing with quantization
This commit is contained in:
parent
27184762bd
commit
d5e46535e8
4 changed files with 12 additions and 7 deletions
BIN
playground/sounds/this_is_a_test.mp3
Normal file
BIN
playground/sounds/this_is_a_test.mp3
Normal file
Binary file not shown.
BIN
playground/sounds/who_put_the_bomp.mp3
Normal file
BIN
playground/sounds/who_put_the_bomp.mp3
Normal file
Binary file not shown.
|
@ -48,7 +48,7 @@ Scratch3SoundBlocks.prototype.playNoteForBeats = function (args, util) {
|
|||
return new Promise(function(resolve) {
|
||||
setTimeout(function() {
|
||||
resolve();
|
||||
}, 1000 * args.BEATS);
|
||||
}, (1000 * args.BEATS) );
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -61,7 +61,7 @@ Scratch3SoundBlocks.prototype.playDrumForBeats = function (args, util) {
|
|||
return new Promise(function(resolve) {
|
||||
setTimeout(function() {
|
||||
resolve();
|
||||
}, 1000 * args.BEATS);
|
||||
}, (1000 * args.BEATS) );
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,11 @@ function VirtualMachine () {
|
|||
|
||||
var tone = new Tone();
|
||||
|
||||
Tone.Transport.start();
|
||||
|
||||
var quantizeUnit = '@8n';
|
||||
// var quantizeUnit = '';
|
||||
|
||||
// effects
|
||||
|
||||
var delay = new Tone.FeedbackDelay(0.25, 0.5);
|
||||
|
@ -43,7 +48,7 @@ function VirtualMachine () {
|
|||
|
||||
// sounds
|
||||
|
||||
var soundFileNames = ['meow', 'boing', 'cave', 'drip_drop', 'drum_machine', 'eggs', 'zoop'];
|
||||
var soundFileNames = ['meow','boing','this_is_a_test','who_put_the_bomp','cave','drip_drop','drum_machine','eggs','zoop'];
|
||||
var soundSamplers = loadSoundFiles(soundFileNames);
|
||||
|
||||
// polyphonic samplers
|
||||
|
@ -112,17 +117,17 @@ function VirtualMachine () {
|
|||
function playNoteForBeats(note, beats) {
|
||||
var midiNote = scaleNoteToMidiNote(note, currentScale, rootNote);
|
||||
var freq = midiToFreq(midiNote);
|
||||
synth.triggerAttackRelease(freq, beats);
|
||||
synth.triggerAttackRelease(freq, beats, quantizeUnit);
|
||||
}
|
||||
|
||||
// onmessage calls are converted into emitted events.
|
||||
instance.vmWorker.onmessage = function (e) {
|
||||
switch (e.data.method) {
|
||||
case 'playsound':
|
||||
soundSamplers[e.data.soundnum].nextVoice().triggerAttack();
|
||||
soundSamplers[e.data.soundnum].nextVoice().triggerAttack(0, quantizeUnit);
|
||||
break;
|
||||
case 'playsoundwithpitch':
|
||||
soundSamplers[e.data.soundnum].nextVoice().triggerAttack(e.data.pitch);
|
||||
soundSamplers[e.data.soundnum].nextVoice().triggerAttack(e.data.pitch, quantizeUnit);
|
||||
break;
|
||||
case 'playnoteforbeats':
|
||||
playNoteForBeats(e.data.note, e.data.beats);
|
||||
|
@ -137,7 +142,7 @@ function VirtualMachine () {
|
|||
case 'playdrumforbeats':
|
||||
case 'playdrum':
|
||||
var drumNum = e.data.drum - 1; // one-indexing
|
||||
drumSamplers[drumNum].nextVoice().triggerAttack();
|
||||
drumSamplers[drumNum].nextVoice().triggerAttack(0, quantizeUnit);
|
||||
break;
|
||||
case 'seteffect' :
|
||||
switch (e.data.effect) {
|
||||
|
|
Loading…
Reference in a new issue