From 7b77e03a3222510fafd49e29b0996dcc5c900738 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Mon, 9 Jul 2018 16:38:02 +0200 Subject: [PATCH] resolved name conflicts in pixels- and audio- libraries --- libraries/audioComp_module.xml | 8 ++++---- libraries/pixel_module.xml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/audioComp_module.xml b/libraries/audioComp_module.xml index 1352cbd1..495076e5 100644 --- a/libraries/audioComp_module.xml +++ b/libraries/audioComp_module.xml @@ -1,12 +1,12 @@ -
durationname +
durationname duration length number of channels sample rate -samplessamplessoundvar base64, binaryString, len, bytes, i, arrayBuffer, audioCtx; if (sound.audioBuffer) { return; } base64 = sound.audio.src.split(',')[1]; binaryString = window.atob(base64); len = binaryString.length; bytes = new Uint8Array(len); for (i = 0; i < len; i += 1) { bytes[i] = binaryString.charCodeAt(i); } arrayBuffer = bytes.buffer; Note.prototype.setupContext(); audioCtx = Note.prototype.audioContext; audioCtx.decodeAudioData(arrayBuffer, function(buffer) { sound.audioBuffer = buffer; });soundreturn !isNil(sound.audioBuffer);soundchoiceswitch (choice) { case 'sample rate': return sound.audioBuffer.sampleRate; case 'duration': return sound.audioBuffer.duration; case 'length': return sound.audioBuffer.length; case 'number of channels': return sound.audioBuffer.numberOfChannels; default: return sound.audioBuffer; }
play back a sound, a list of samples (single channel), or a list of lists (multiple channels) at the given sample rate. for demo purposes this block also fast-plots the samples on the stage
4410022.05 kHz=22050 +samplessamplessoundvar base64, binaryString, len, bytes, i, arrayBuffer, audioCtx; if (sound.audioBuffer) { return; } base64 = sound.audio.src.split(',')[1]; binaryString = window.atob(base64); len = binaryString.length; bytes = new Uint8Array(len); for (i = 0; i < len; i += 1) { bytes[i] = binaryString.charCodeAt(i); } arrayBuffer = bytes.buffer; Note.prototype.setupContext(); audioCtx = Note.prototype.audioContext; audioCtx.decodeAudioData(arrayBuffer, function(buffer) { sound.audioBuffer = buffer; });soundreturn !isNil(sound.audioBuffer);soundchoiceswitch (choice) { case 'sample rate': return sound.audioBuffer.sampleRate; case 'duration': return sound.audioBuffer.duration; case 'length': return sound.audioBuffer.length; case 'number of channels': return sound.audioBuffer.numberOfChannels; default: return sound.audioBuffer; }
play back a sound, a list of samples (single channel), or a list of lists (multiple channels) at the given sample rate. for demo purposes this block also fast-plots the samples on the stage
4410022.05 kHz=22050 44.1 kHz=44100 88.2 kHz=88200 -96 kHz=96000samplesratevar audioCtx, channels, frameCount, arrayBuffer, i, source; Note.prototype.setupContext(); audioCtx = Note.prototype.audioContext; channels = (samples.at(1) instanceof List) ? samples.length() : 1; frameCount = (channels === 1) ? samples.length() : samples.at(1).length(); arrayBuffer = audioCtx.createBuffer(channels, frameCount, rate); if (!arrayBuffer.copyToChannel) { arrayBuffer.copyToChannel = function (src, channel) { var buffer = this.getChannelData(channel); for (i = 0; i < src.length; i += 1) { buffer[i] = src[i]; } } } if (channels === 1) { arrayBuffer.copyToChannel(Float32Array.from(samples.asArray()), 0, 0); } else { for (i = 0; i < channels; i += 1) { arrayBuffer.copyToChannel(Float32Array.from(samples.at(i + 1).asArray()), i, 0); } } source = audioCtx.createBufferSource(); source.buffer = arrayBuffer; source.connect(audioCtx.destination); source.start(); source.pause = source.stop; this.parentThatIsA(StageMorph).activeSounds.push(source);
generate a list of samples representing a sine wave at the given frequency, duration and sample rate
440a 55=55 +96 kHz=96000samplesratevar audioCtx, channels, frameCount, arrayBuffer, i, source; Note.prototype.setupContext(); audioCtx = Note.prototype.audioContext; channels = (samples.at(1) instanceof List) ? samples.length() : 1; frameCount = (channels === 1) ? samples.length() : samples.at(1).length(); arrayBuffer = audioCtx.createBuffer(channels, frameCount, rate); if (!arrayBuffer.copyToChannel) { arrayBuffer.copyToChannel = function (src, channel) { var buffer = this.getChannelData(channel); for (i = 0; i < src.length; i += 1) { buffer[i] = src[i]; } } } if (channels === 1) { arrayBuffer.copyToChannel(Float32Array.from(samples.asArray()), 0, 0); } else { for (i = 0; i < channels; i += 1) { arrayBuffer.copyToChannel(Float32Array.from(samples.at(i + 1).asArray()), i, 0); } } source = audioCtx.createBufferSource(); source.buffer = arrayBuffer; source.connect(audioCtx.destination); source.start(); source.pause = source.stop; this.parentThatIsA(StageMorph).activeSounds.push(source);
generate a list of samples representing a sine wave at the given frequency, duration and sample rate
440a 55=55 a 110=110 a 220=220 a 440=440 @@ -15,4 +15,4 @@ a 1760=1760 a 3520=352014410022.05 kHz=22050 44.1 kHz=44100 88.2 kHz=88200 -96 kHz=96000
0.5
1
quickly plot the samples of a sound, a list of samples (single channel), or a list of lists (multiple channels) to the stage at a lower resolution.
1offset-2
records an audio snippet and reports it as a new sound, or zero if the user cancels
\ No newline at end of file +96 kHz=96000
0.5
1
quickly plot the samples of a sound, a list of samples (single channel), or a list of lists (multiple channels) to the stage at a lower resolution.
1offset-2
records an audio snippet and reports it as a new sound, or zero if the user cancels
\ No newline at end of file diff --git a/libraries/pixel_module.xml b/libraries/pixel_module.xml index 90aaef6d..76fd3701 100644 --- a/libraries/pixel_module.xml +++ b/libraries/pixel_module.xml @@ -1,4 +1,4 @@ -reports a list of all pixels in the given costume. Each pixel is represented by a 4-item sublist of RGBA values
pixelsname +reports a list of all pixels in the given costume. Each pixel is represented by a 4-item sublist of RGBA values
pixelsname pixels width -heightwidthheightcostume var i, pixels = [], src = costume.contents.getContext('2d').getImageData( 0, 0, costume.width(), costume.height() ); for (i = 0; i < src.data.length; i += 4) { pixels.push(new List([ src.data[i], src.data[i + 1], src.data[i + 2], src.data[i + 3] ])); } return new List(pixels);
overwrite the pixels in the given costume with another list of pixels. Caution! This operation directly changes the costume. Make sure to use a copy in case you would like to revert changes later.
reports the sprite's actual current costume, which may or may not be part of its wardrobe e.g. if it is a copy
reports a copy of the given costume. This is especially useful when modifying a costume, so you can keep the original around
display the given bitmap in a copy of the current costume (so you can switch back to the original costume again)
takes a snapshot with the webcam and reports it as a new costume, or zero if the user cancels
\ No newline at end of file +height
widthheightcostume var i, pixels = [], src = costume.contents.getContext('2d').getImageData( 0, 0, costume.width(), costume.height() ); for (i = 0; i < src.data.length; i += 4) { pixels.push(new List([ src.data[i], src.data[i + 1], src.data[i + 2], src.data[i + 3] ])); } return new List(pixels);
overwrite the pixels in the given costume with another list of pixels. Caution! This operation directly changes the costume. Make sure to use a copy in case you would like to revert changes later.
reports the sprite's actual current costume, which may or may not be part of its wardrobe e.g. if it is a copy
reports a copy of the given costume. This is especially useful when modifying a costume, so you can keep the original around
display the given bitmap in a copy of the current costume (so you can switch back to the original costume again)
takes a snapshot with the webcam and reports it as a new costume, or zero if the user cancels
\ No newline at end of file