diff --git a/HISTORY.md b/HISTORY.md index b61034bf..aee3fa1b 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -74,6 +74,7 @@ * updated tools library (removed "label", because it's now a primitive) * updated text-costumes library (removed "label", because it's now a primitive) * updated pixels-library (removed blocks that are now primitives) +* updated audio-comp library (removed blocks that are now primitives) ### 2019-04-10 * Objects: took out MAP and FOREACH primitives (available in dev mode) diff --git a/libraries/audioComp_module.xml b/libraries/audioComp_module.xml index 2a108150..f5438160 100644 --- a/libraries/audioComp_module.xml +++ b/libraries/audioComp_module.xml @@ -1 +1 @@ -
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.
4410022.05 kHz=22050 44.1 kHz=44100 88.2 kHz=88200 96 kHz=96000samplesratevar audioCtx = this.audioContext(), gain = this.getGainNode(), pan = this.getPannerNode(), channels = (samples.at(1) instanceof List) ? samples.length() : 1, frameCount = (channels === 1) ? samples.length() : samples.at(1).length(), arrayBuffer = audioCtx.createBuffer(channels, frameCount, rate), i, source; 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; this.setVolume(this.volume); source.connect(gain); if (pan) { gain.connect(pan); pan.connect(audioCtx.destination); this.setPan(this.pan); } else { gain.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 a 880=880 a 1760=1760 a 3520=352014410022.05 kHz=22050 44.1 kHz=44100 88.2 kHz=88200 96 kHz=96000
de:für jedes _ von _ _ ca:per cada _ de _ _ es:para cada _ de _ _ fr:pour chaque _ de _ _
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
440
69
69
440
\ No newline at end of file +
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 a 880=880 a 1760=1760 a 3520=352014410022.05 kHz=22050 44.1 kHz=44100 88.2 kHz=88200 96 kHz=96000
de:für jedes _ von _ _ ca:per cada _ de _ _ es:para cada _ de _ _ fr:pour chaque _ de _ _
0.5
1
§_soundsMenu
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.
§_soundsMenu1offsetStage-2
records an audio snippet and reports it as a new sound, or zero if the user cancels
440
69
69
\ No newline at end of file