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 stage4410022.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 rate440a 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=960000.51quickly 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-2records an audio snippet and reports it as a new sound, or zero if the user cancelsca:volum del so
es:volumen del sonido
return typeof meter != 'undefined'return Math.floor(meter.volume * 100);