fist commit
This commit is contained in:
50
test.html
Normal file
50
test.html
Normal file
@ -0,0 +1,50 @@
|
||||
<body>
|
||||
<label for="duration">Duration</label>
|
||||
<input
|
||||
name="duration"
|
||||
id="duration"
|
||||
type="range"
|
||||
min="0"
|
||||
max="2"
|
||||
value="1"
|
||||
step="0.1" />
|
||||
|
||||
<label for="band">Band</label>
|
||||
<input
|
||||
name="band"
|
||||
id="band"
|
||||
type="range"
|
||||
min="400"
|
||||
max="1200"
|
||||
value="1000"
|
||||
step="5" />
|
||||
|
||||
</body>
|
||||
<script>
|
||||
const audioCtx = new AudioContext();
|
||||
|
||||
function playNoise(noiseDuration, bandHz=1000) {
|
||||
const bufferSize = audioCtx.sampleRate * noiseDuration
|
||||
const noiseBuffer = new AudioBuffer({
|
||||
length: bufferSize,
|
||||
sampleRate: audioCtx.sampleRate,
|
||||
})
|
||||
const data = noiseBuffer.getChannelData(0)
|
||||
for (let i = 0; i < bufferSize; i++) {
|
||||
data[i] = Math.random() * 2 - 1;
|
||||
}
|
||||
const noise = new AudioBufferSourceNode(audioCtx, {
|
||||
buffer: noiseBuffer,
|
||||
})
|
||||
const bandpass = new BiquadFilterNode(audioCtx, {
|
||||
type: "bandpass",
|
||||
frequency: bandHz,
|
||||
})
|
||||
const gain = new GainNode(audioCtx)
|
||||
gain.gain.setValueCurveAtTime([0.5, 1/10, 0], audioCtx.currentTime, noiseDuration)
|
||||
noise.connect(bandpass).connect(gain).connect(audioCtx.destination)
|
||||
noise.start()
|
||||
}
|
||||
|
||||
|
||||
</script>
|
Reference in New Issue
Block a user