鿍奍;: ãã®æ©è½ã¯éæ¨å¥¨ã«ãªãã¾ãããã¾ã 対å¿ãã¦ãããã©ã¦ã¶ã¼ãããããããã¾ãããããã§ã«é¢é£ããã¦ã§ãæ¨æºããåé¤ããã¦ããããåé¤ã®æç¶ãä¸ã§ããããäºææ§ã®ããã ãã«æ®ããã¦ããå¯è½æ§ãããã¾ãã使ç¨ãé¿ããã§ããã°æ¢åã®ã³ã¼ãã¯æ´æ°ãã¦ãã ããããã®ãã¼ã¸ã®ä¸é¨ã«ããäºææ§ä¸è¦§è¡¨ãè¦ã¦å¤æãã¦ãã ããããã®æ©è½ã¯çªç¶åä½ããªããªãå¯è½æ§ããããã¨ã«æ³¨æãã¦ãã ããã
AudioProcessingEvent
ã¯ã¦ã§ããªã¼ãã£ãª API ã®ã¤ã³ã¿ã¼ãã§ã¤ã¹ã§ãScriptProcessorNode
å
¥åãããã¡ã¼ãå¦çå¯è½ãªç¶æ
ã«ãªã£ãã¨ãã«çºçããã¤ãã³ãã表ãã¾ãã
ãã®ã¤ã³ã¿ã¼ãã§ã¤ã¹ãæã¤ audioprocess
ã¤ãã³ãã¯ãé³å£°å¦çãå¿
è¦ãªã¨ãã« ScriptProcessorNode
ã§çºçãã¾ããé³å£°å¦çä¸ãå
¥åãããã¡ã¼ãèªã¿è¾¼ã¾ããå¦çããã¦åºåé³å£°ãã¼ã¿ãçæãããåºåãããã¡ã¼ã«æ¸ãè¾¼ã¾ãã¾ãã
è¦å: ãã®æ©è½ã¯éæ¨å¥¨ã¨ãªã£ãã®ã§ãAudioWorklet
ã§ç½®ãæãã¦ãã ããã
AudioProcessingEvent()
鿍奍;
æ°ãã AudioProcessingEvent
ãªãã¸ã§ã¯ããçæãã¾ãã
親ããããã£ã§ãã Event
ããç¶æ¿ãããããããã£ãå®è£
ãã¦ãã¾ãã
playbackTime
èªåå°ç¨ 鿍奍;
double åã§ãé³å£°ãåçãããæéã表ãã¾ãã AudioContext.currentTime
ã®æå»ã§å®ç¾©ããã¾ãã
inputBuffer
èªåå°ç¨ 鿍奍;
å¦çããå
¥åé³å£°ãã¼ã¿ãå«ããããã¡ã¼ã§ãã AudioBuffer
ãæå®ãã¾ãã ãã£ã³ãã«æ°ã¯ãã¡ã¯ããªã¼ã¡ã½ãã AudioContext.createScriptProcessor()
ã®å¼æ° numberOfInputChannels
ã¨ãã¦å®ç¾©ããã¦ãã¾ãã ãªããè¿ããã AudioBuffer
ã¯ãã¤ãã³ããã³ãã©ã¼ã®ã¹ã³ã¼ãå
ã®ã¿ã§æå¹ã§ãããã¨ã«æ³¨æãã¦ãã ããã
outputBuffer
èªåå°ç¨ 鿍奍;
åºåããé³å£°ãã¼ã¿ãæ¸ãè¾¼ããããã¡ã¼ã§ãã AudioBuffer
ãæå®ãã¾ãã ãã£ã³ãã«æ°ã¯ãã¡ã¯ããªã¼ã¡ã½ãã AudioContext.createScriptProcessor()
ã®å¼æ° numberOutputChannels
ã¨ãã¦å®ç¾©ããã¦ãã¾ãã ãªããè¿ããã AudioBuffer
ã¯ãã¤ãã³ããã³ãã©ã¼ã®ã¹ã³ã¼ãå
ã®ã¿ã§æå¹ã§ãããã¨ã«æ³¨æãã¦ãã ããã
次ã®ä¾ã¯ãScriptProcessorNode
ã使ç¨ãã¦ãAudioContext.decodeAudioData()
ã§èªã¿è¾¼ãã é³å£°ãAudioDestinationNode
ã§å¦çããå
¥åãã©ãã¯ï¼ãããã¡ã¼ï¼ã®åé³å£°ãµã³ãã«ã«ãã¯ã¤ããã¤ãºã追å ããAudioDestinationNode
ãéãã¦åçããæ¹æ³ã示ãã¦ãã¾ãã åãã£ã³ãã«ã¨åãµã³ãã«ãã¬ã¼ã ã«å¯¾ãã¦ãscriptNode.onaudioprocess
颿°ã¯é¢é£ãã audioProcessingEvent
ãåãåãããããç¨ãã¦å
¥åãããã¡ã¼å
ã®åãã£ã³ãã«ã¨åãã£ã³ãã«å
ã®åãµã³ãã«ãã«ã¼ãããå°éã®ãã¯ã¤ããã¤ãºã追å ãã¦ããããã®çµæãããããã®ã±ã¼ã¹ã§åºåãµã³ãã«ã«è¨å®ãã¾ãã
ã¡ã¢: å®å ¨ãªåä½ããä¾ã¯ãGitHub ã® script-processor-node ãªãã¸ããªã¼ãåç §ãã¦ãã ããï¼ã½ã¼ã¹ã³ã¼ãã«ãã¢ã¯ã»ã¹ã§ãã¾ãï¼ã
const myScript = document.querySelector("script");
const myPre = document.querySelector("pre");
const playButton = document.querySelector("button");
// Create AudioContext and buffer source
const audioCtx = new AudioContext();
const source = audioCtx.createBufferSource();
// Create a ScriptProcessorNode with a bufferSize of 4096 and a single input and output channel
const scriptNode = audioCtx.createScriptProcessor(4096, 1, 1);
console.log(scriptNode.bufferSize);
// load in an audio track via XHR and decodeAudioData
function getData() {
request = new XMLHttpRequest();
request.open("GET", "viper.ogg", true);
request.responseType = "arraybuffer";
request.onload = () => {
const audioData = request.response;
audioCtx.decodeAudioData(
audioData,
(buffer) => {
myBuffer = buffer;
source.buffer = myBuffer;
},
(e) => console.error(`Error with decoding audio data: ${e.err}`),
);
};
request.send();
}
// Give the node a function to process audio events
scriptNode.onaudioprocess = (audioProcessingEvent) => {
// The input buffer is the 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;
}
}
};
getData();
// Wire up the play button
playButton.onclick = () => {
source.connect(scriptNode);
scriptNode.connect(audioCtx.destination);
source.start();
};
// When the buffer source stops playing, disconnect everything
source.onended = () => {
source.disconnect(scriptNode);
scriptNode.disconnect(audioCtx.destination);
};
ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4