ScriptProcessorNode: audioprocess-Ereignis
Deprecated
Avoid using this feature in new projects. This feature may be a candidate for removal from web standards or browsers.>
Das audioprocess-Ereignis der ScriptProcessorNode-Schnittstelle wird ausgelöst, wenn ein Eingabepuffer eines Skriptprozessors zur Verarbeitung bereit ist.
Hinweis:
Diese Funktion wurde durch AudioWorklets und die AudioWorkletNode-Schnittstelle ersetzt.
Dieses Ereignis ist nicht stornierbar und blubbert nicht.
Syntax
Verwenden Sie den Ereignisnamen in Methoden wie addEventListener() oder setzen Sie eine Ereignisbehandlungseigenschaft.
js
addEventListener("audioprocess", (event) => { })
onaudioprocess = (event) => { }
Ereignistyp
Ein AudioProcessingEvent. Erbt von Event.
Beispiele
js
scriptNode.addEventListener("audioprocess", (audioProcessingEvent) => {
// The input buffer is a song we loaded earlier
const inputBuffer = audioProcessingEvent.inputBuffer;
// The output buffer contains the samples that will be modified and played
const outputBuffer = audioProcessingEvent.outputBuffer;
// Loop through the output channels (in this case there is only one)
for (let channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
const inputData = inputBuffer.getChannelData(channel);
const outputData = outputBuffer.getChannelData(channel);
// Loop through the 4096 samples
for (let sample = 0; sample < inputBuffer.length; sample++) {
// make output equal to the same as the input
outputData[sample] = inputData[sample];
// add noise to each output sample
outputData[sample] += (Math.random() * 2 - 1) * 0.2;
}
}
});
Sie könnten den Ereignishandler auch über die onaudioprocess-Eigenschaft einrichten:
js
scriptNode.onaudioprocess = (audioProcessingEvent) => {
// …
};
Spezifikationen
| Spezifikation |
|---|
| Web Audio API> # eventdef-scriptprocessornode-audioprocess> |