51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
const PerimeterWarningSound = (function(){
|
|
|
|
return function(audio_ctx, output_node, volume_multiplier = 1.0){
|
|
const now = audio_ctx.currentTime;
|
|
const duration = 0.14;
|
|
|
|
const preset_bus = audio_ctx.createGain();
|
|
preset_bus.gain.setValueAtTime(volume_multiplier * 0.5, now);
|
|
|
|
// Envolvente seca estilo sonar
|
|
const env = audio_ctx.createGain();
|
|
env.gain.setValueAtTime(0.001, now);
|
|
env.gain.linearRampToValueAtTime(0.85, now + 0.01);
|
|
env.gain.exponentialRampToValueAtTime(0.001, now + duration);
|
|
|
|
// Tono puro resonante de telemetría militar (960Hz descendiendo a 820Hz)
|
|
const osc = audio_ctx.createOscillator();
|
|
osc.type = "sine";
|
|
osc.frequency.setValueAtTime(960, now);
|
|
osc.frequency.exponentialRampToValueAtTime(820, now + duration);
|
|
|
|
// Armónico metálico sutil
|
|
const harm = audio_ctx.createOscillator();
|
|
const harm_gain = audio_ctx.createGain();
|
|
harm.type = "triangle";
|
|
harm.frequency.setValueAtTime(1920, now);
|
|
harm_gain.gain.setValueAtTime(0.2, now);
|
|
|
|
// Filtro de mampara
|
|
const filter = audio_ctx.createBiquadFilter();
|
|
filter.type = "bandpass";
|
|
filter.frequency.setValueAtTime(900, now);
|
|
filter.Q.setValueAtTime(2.5, now);
|
|
|
|
osc.connect(env);
|
|
harm.connect(harm_gain);
|
|
harm_gain.connect(env);
|
|
|
|
env.connect(filter);
|
|
filter.connect(preset_bus);
|
|
preset_bus.connect(output_node);
|
|
|
|
osc.start(now);
|
|
harm.start(now);
|
|
osc.stop(now + duration);
|
|
harm.stop(now + duration);
|
|
};
|
|
|
|
})(); |