From 371769ae4079235e15050c426ae9e02f9ff44cfa Mon Sep 17 00:00:00 2001 From: jmoenig Date: Sun, 20 Oct 2019 14:07:55 +0200 Subject: [PATCH] added sampling rate input to "new sound" primitive --- HISTORY.md | 1 + src/objects.js | 3 ++- src/threads.js | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d9d399de..7f8e1e76 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -15,6 +15,7 @@ ### 2019-10-20 * objects, threads: added "new sound" from list of samples primitive reporter to "sound" category +* objects, threads: added sampling rate input to "new sound" primitive ### 2019-10-18 * objects, blocks, threads: added dimension getters for the stage diff --git a/src/objects.js b/src/objects.js index 38a18488..1b516b39 100644 --- a/src/objects.js +++ b/src/objects.js @@ -481,7 +481,8 @@ SpriteMorph.prototype.initBlocks = function () { reportNewSoundFromSamples: { type: 'reporter', category: 'sound', - spec: 'new sound %l' + spec: 'new sound %l at %rate Hz', + defaults: [null, 44100] }, doRest: { type: 'command', diff --git a/src/threads.js b/src/threads.js index 988a1fa0..de93a07e 100644 --- a/src/threads.js +++ b/src/threads.js @@ -2818,7 +2818,7 @@ Process.prototype.encodeSound = function (samples, rate) { // Process first-class sound creation from samples, interpolated -Process.prototype.reportNewSoundFromSamples = function (samples) { +Process.prototype.reportNewSoundFromSamples = function (samples, rate) { // interpolated var audio, blob, reader, myself = this; @@ -2829,7 +2829,7 @@ Process.prototype.reportNewSoundFromSamples = function (samples) { }; audio = new Audio(); blob = this.audioBufferToWaveBlob( - this.encodeSound(samples, 44100).audioBuffer, + this.encodeSound(samples, rate || 44100).audioBuffer, samples.length() ); reader = new FileReader();