kaka.farm

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/kaka.farm
Log | Files | Refs | README

commit 9b743f002b62dde31a3a9697c7fd34aac0d8071a
parent c70179e7bc3756da5ec9170e34a503e59f9e49ef
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Sun, 28 Jun 2020 21:20:08 +0300

Add an annoying audio api page.

Diffstat:
Ahtml/annoying-sawtooth-alarm.html | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/html/annoying-sawtooth-alarm.html b/html/annoying-sawtooth-alarm.html @@ -0,0 +1,48 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <script type="text/javascript"> +'use strict'; + + +(function() { + function main() { + let f = 440; + let v = 1; + let audio = new window.AudioContext; + + let oscillator = audio.createOscillator(); + + oscillator.type = 'sine'; + oscillator.frequency.setValueAtTime(f, audio.currentTime); + oscillator.connect(audio.destination); + oscillator.start(); + + function changeFrequency() { + //alert(f); + if ((f > 880) || (f < 440)) { + f = Math.min(Math.max(f, 440), 880); + v *= -1; + }; + + f += 10 * v; + + oscillator.type = 'sawtooth'; + oscillator.frequency.setValueAtTime(f, audio.currentTime); + oscillator.connect(audio.destination); + //oscillator.start(); + + window.setTimeout(changeFrequency, 10); + }; + + window.setTimeout(changeFrequency, 10); + }; + + window.addEventListener('load', main); +})(); + </script> + </head> + <body> + </body> +</html>