kaka.farm

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

annoying-sawtooth-alarm.html (912B)


      1 <!doctype html>
      2 <html>
      3 	<head>
      4 		<meta charset="utf-8">
      5 	<script type="text/javascript">
      6 'use strict';
      7 
      8 
      9 (function() {
     10 	function main() {
     11 		let f = 440;
     12 		let v = 1;
     13 		let audio = new window.AudioContext;
     14 
     15 		let oscillator = audio.createOscillator();
     16 
     17 		oscillator.type = 'sine';
     18 		oscillator.frequency.setValueAtTime(f, audio.currentTime);
     19 		oscillator.connect(audio.destination);
     20 		oscillator.start();
     21 
     22 		function changeFrequency() {
     23 			//alert(f);
     24 			if ((f > 880) || (f < 440)) {
     25 				f = Math.min(Math.max(f, 440), 880);
     26 				v *= -1;
     27 			};
     28 
     29 			f += 10 * v;
     30 
     31 			oscillator.type = 'sawtooth';
     32 			oscillator.frequency.setValueAtTime(f, audio.currentTime);
     33 			oscillator.connect(audio.destination);
     34 			//oscillator.start();
     35 
     36 			window.setTimeout(changeFrequency, 10);
     37 		};
     38 
     39 		window.setTimeout(changeFrequency, 10);
     40 	};
     41 
     42 	window.addEventListener('load', main);
     43 })();
     44 	</script>
     45 	</head>
     46 	<body>
     47 	</body>
     48 </html>