ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.65k stars 2.53k forks source link

fuzzer web interface: play a little jingle when it finds a bug! #20995

Open andrewrk opened 2 months ago

andrewrk commented 2 months ago

Extracted from https://github.com/ziglang/zig/pull/20958.

What if there was a setting in the web UI where you could get a little sound notification to play if the fuzzer found a bug? It would be like a little cherry on top of a big bowl of ice cream.

Of course, we're not going to commit any sampled audio to the zig source repository, so the jingle would need to be procedurally generated by some DSP golf zig code that runs in wasm populating a buffer that gets played with the browser's audio API :sunglasses:

And it should probably be disabled by default, but have a persistent setting so that someone could toggle it on and it would stay on. Or perhaps it could be on by default, but only plays if a long time has passed between starting fuzzing and finding the bug, and rate limited to 1 per hour or something like that.

geon commented 2 months ago

You don't even need to generate a buffer. You can just use an oscillator.

Mario coin sound: https://mohayonao.github.io/web-audio-sound-examples/

function coin(destination, playbackTime, opts) {
  opts = opts || {};
  var t0 = playbackTime;
  var t1 = t0 + 0.075;
  var t2 = t1 + 0.825;
  var audioContext = destination.context;
  var oscillator = audioContext.createOscillator();
  var gain = audioContext.createGain();
  var volume = opts.volume || 0.25;

  oscillator.type = "square";
  oscillator.frequency.setValueAtTime(990, t0);
  oscillator.frequency.setValueAtTime(1320, t1);
  oscillator.start(t0);
  oscillator.stop(t2);
  oscillator.connect(gain);

  gain.gain.setValueAtTime(volume, t0);
  gain.gain.setValueAtTime(volume, t1);
  gain.gain.linearRampToValueAtTime(0, t2);
  gain.connect(destination);
}

function example01(audioContext, coin) {
  var destination = audioContext.destination;
  var t0 = audioContext.currentTime;

  coin(destination, t0);
}
andrewrk commented 1 month ago

Mario coin sound is a great example! For this issue however, it is a chance to exercise a little creativity and produce a unique sound.

Rexicon226 commented 1 month ago

Moving my suggestion from the Discord, I thought it'd be cool if the sound was generated as a normalization of the bytes that were used to find the bug 😄 .