[英]WEB AUDIO API creating rain crackling noises
我正在嘗試在 javascript Web 音頻 API 中制造雨水。 到目前為止,我已經為背景創建了一個低頻隆隆聲,我正在研究一個高頻噪聲,它將模仿雨滴的聲音。 然而,現在的高頻噪聲很像白噪聲,太強而不能成為單個液滴。 有誰知道如何將聲音“分離”一點,使它聽起來幾乎像噼啪聲。 這是一個鏈接,如果您增加最后一個 slider(紫羅蘭色),我希望高頻噪音聽起來像什么,您可以聽到它。
到目前為止,這是我的 HTML 代碼
<script>
let context= new AudioContext();
let context2= new AudioContext();
let lowpass = context.createBiquadFilter();
lowpass.type = 'lowpass';
//lowpass.Q.value = -7.01;
lowpass.frequency.setValueAtTime(80, context2.currentTime);
let gain = new GainNode(context);
gain.gain.value= 0.4;
let gain2 = new GainNode(context2);
gain2.gain.value= 0.02;
let highpass=context2.createBiquadFilter();
highpass.type = 'highpass';
highpass.Q.value = 2;
//highpass.frequency.setValueAtTime(6000, context2.currentTime);
let distortion = context2.createWaveShaper();
let delay = context2.createDelay(90.0);
function StartAudio() {context.resume()};
context.audioWorklet.addModule('basicnoise.js').then(() => {
let myNoise = new AudioWorkletNode(context,'noise-generator');
myNoise.connect(lowpass);
lowpass.connect(gain);
gain.connect(context.destination);
});
function StartAudio2() {context2.resume()};
context2.audioWorklet.addModule('basicnoise.js').then(() => {
let myNoise2 = new AudioWorkletNode(context2,'noise-generator');
myNoise2.connect(highpass);
highpass.connect(gain2);
gain2.connect(delay);
delay.connect(context2.destination);
});
我一直在玩不同的功能,其中一些功能沒有做太多,或者我只是沒有正確使用它們,因為我對音頻 API 場景非常陌生。 感謝任何幫助,因為這是一個學校項目,我知道其他一些學生想要發出火聲,也可以從噼啪聲中受益! 謝謝 !!
如果您將下雨視為一個物理過程,那么它基本上是大量的表面撞擊聲音(可能還有一些由氣流產生的額外氛圍)。 當足夠多的雨滴以足夠快的速度撞擊表面時,最終的結果就是噪音。
我認為一個逼真的雨水發生器會模擬許多單個水滴在距聽者不同距離處撞擊表面(這會導致衰減和過濾)。
也就是說,如果您想嘗試“破解”您現在正在進行的噪聲發生器,請嘗試隨機調制增益節點的增益值; 在這里,發生器有 25% 的機會每 20 毫秒有效地靜音(或者,考慮到計時器並不精確)。
setInterval(() => {
gain.gain.value=(Math.random() < 0.75 ? 0.4 : 0);
}, 20)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.