commit dd774bb10b4e8e20bd10a41a1cfa740feeb14232 Author: Djkato Date: Sat Feb 18 18:51:49 2023 +0100 init diff --git a/Jamie xx - Sleep Sound.mp3 b/Jamie xx - Sleep Sound.mp3 new file mode 100644 index 0000000..15e7832 Binary files /dev/null and b/Jamie xx - Sleep Sound.mp3 differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..676fd22 --- /dev/null +++ b/index.html @@ -0,0 +1,34 @@ + + + + + + + + Mute and Unmute me + + + +
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..eb0a839 --- /dev/null +++ b/index.js @@ -0,0 +1,80 @@ +/** + * Initialise web audio api + */ +let audio_context +const audio_element = document.querySelector("#audio") +audio_element.src = "Jamie xx - Sleep Sound.mp3" + +//audio nodes +let track +let audio_context_analyzer + +let prev_data = new Array() + +function main() { + audio_context = new AudioContext() + + track = audio_context.createMediaElementSource(audio_element) + audio_context_analyzer = audio_context.createAnalyser(audio_element) + + audio_context_analyzer.fftSize = 1024 + audio_context_analyzer.smoothingTimeConstant = .2 + track.connect(audio_context_analyzer).connect(audio_context.destination) + + audio_element.play() + animate() + +} + +function animate() { + const svg_canvas = document.querySelector("#svgCanvas") + let initial_shape = new Array() + for (let i = 0; i < 200; i++) { + initial_shape.push({ + x: (svg_canvas.viewBox.baseVal.width / 200) * i, + y: svg_canvas.viewBox.baseVal.height / 2 - (0 / 200) * i + }) + } + + let fft_data_array = new Float32Array(200) + audio_context_analyzer.getFloatFrequencyData(fft_data_array) + /** + * mutate svg default shape by audio + */ + let mutated_shape = new Array() + for (let i = 0; i < fft_data_array.length; i++) { + mutated_shape.push({ + x: (initial_shape[i].x /** ((Math.max(this.#FFTDataArray[i] + 100)) * 4)*/), + y: (initial_shape[i].y - Math.min(initial_shape[i].y, Math.max(fft_data_array[i] * 2 + 200, 0))) + }) + } + + /** + * create svg element + */ + let path = `M ${0} ${svg_canvas.viewBox.baseVal.height} ` + for (let i = 0; i < mutated_shape.length; i++) { + path += `L ${mutated_shape[i].x},${mutated_shape[i].y} ` + } + path += `L ${svg_canvas.viewBox.baseVal.height} ${svg_canvas.viewBox.baseVal.height / 2} ` + path += `L ${svg_canvas.viewBox.baseVal.height} ${svg_canvas.viewBox.baseVal.height} ` + path += `Z ` + path = `` + + /** + * compare FFTData to previous ones + */ + let matched_amount = 0 + for (let prev_dat in prev_data) { + if (prev_dat == fft_data_array) { + matched_amount += 1 + } + } + console.log(`Matched ${matched_amount} times!`) + + prev_data.push(fft_data_array) + + svg_canvas.innerHTML = path + + const drawVisual = requestAnimationFrame(animate) +} \ No newline at end of file diff --git a/node_modules/.bin/tiny-server b/node_modules/.bin/tiny-server new file mode 100644 index 0000000..712330c --- /dev/null +++ b/node_modules/.bin/tiny-server @@ -0,0 +1,12 @@ +#!/bin/sh +basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") + +case `uname` in + *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; +esac + +if [ -x "$basedir/node" ]; then + exec "$basedir/node" "$basedir/../tiny-server/bin/index" "$@" +else + exec node "$basedir/../tiny-server/bin/index" "$@" +fi diff --git a/node_modules/.bin/tiny-server.cmd b/node_modules/.bin/tiny-server.cmd new file mode 100644 index 0000000..323f330 --- /dev/null +++ b/node_modules/.bin/tiny-server.cmd @@ -0,0 +1,17 @@ +@ECHO off +GOTO start +:find_dp0 +SET dp0=%~dp0 +EXIT /b +:start +SETLOCAL +CALL :find_dp0 + +IF EXIST "%dp0%\node.exe" ( + SET "_prog=%dp0%\node.exe" +) ELSE ( + SET "_prog=node" + SET PATHEXT=%PATHEXT:;.JS;=;% +) + +endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\tiny-server\bin\index" %* diff --git a/node_modules/.bin/tiny-server.ps1 b/node_modules/.bin/tiny-server.ps1 new file mode 100644 index 0000000..ed7cc4b --- /dev/null +++ b/node_modules/.bin/tiny-server.ps1 @@ -0,0 +1,28 @@ +#!/usr/bin/env pwsh +$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent + +$exe="" +if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { + # Fix case when both the Windows and Linux builds of Node + # are installed in the same directory + $exe=".exe" +} +$ret=0 +if (Test-Path "$basedir/node$exe") { + # Support pipeline input + if ($MyInvocation.ExpectingInput) { + $input | & "$basedir/node$exe" "$basedir/../tiny-server/bin/index" $args + } else { + & "$basedir/node$exe" "$basedir/../tiny-server/bin/index" $args + } + $ret=$LASTEXITCODE +} else { + # Support pipeline input + if ($MyInvocation.ExpectingInput) { + $input | & "node$exe" "$basedir/../tiny-server/bin/index" $args + } else { + & "node$exe" "$basedir/../tiny-server/bin/index" $args + } + $ret=$LASTEXITCODE +} +exit $ret diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 0000000..b282be4 --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,16 @@ +{ + "name": "performance-bug-unmuted-window", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "node_modules/tiny-server": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/tiny-server/-/tiny-server-1.1.1.tgz", + "integrity": "sha512-UZdFJFqms0+mvWOs1LRuf2C/ONjERZvaAXXyvqHXGGZtFeFUfeunmVi7OFdI8OgCiBUM1Rq+BfYJ2guVUeXnUg==", + "bin": { + "tiny-server": "bin/index" + } + } + } +} diff --git a/node_modules/tiny-server/README.md b/node_modules/tiny-server/README.md new file mode 100644 index 0000000..4bd6497 --- /dev/null +++ b/node_modules/tiny-server/README.md @@ -0,0 +1,43 @@ +# tiny-server + +A tiny Web Server + + +## Install + +You can install to global + +```shell +npm install -g tiny-server +``` + +or as a module + +```shell +npm install tiny-server +``` + + +## Usage + +### global + +```shell +tiny-server +``` + +It will use terminal's current working directory as the web server's root directory. +And the server's port is 3000. + +You can specify a path as web server's root directory: + +```shell +tiny-server ./www +``` + +You can export environment `PORT` value as the server's port: + +```shell +export PORT=3001 && tiny-server; +``` + diff --git a/node_modules/tiny-server/bin/index b/node_modules/tiny-server/bin/index new file mode 100644 index 0000000..5d01018 --- /dev/null +++ b/node_modules/tiny-server/bin/index @@ -0,0 +1,24 @@ +#!/usr/bin/env node + +var Server = require("../lib/server"); + +var argv = process.argv.slice(2); + +var cwd = argv[0] || process.cwd(); + +var port = process.env["PORT"] || 3000; + +var server = new Server(cwd); + +server.listen(port, function () { + console.log("============= start ============"); + console.log(cwd); + console.log("http://localhost:" + port); +}).once("error", function (err) { + if (err.code === "EADDRINUSE") { + console.log("=============== ERROR ==============="); + console.error("Port: " + port + " already in use"); + console.log("====================================="); + } + process.exit(1); +}); diff --git a/node_modules/tiny-server/index.js b/node_modules/tiny-server/index.js new file mode 100644 index 0000000..9164f12 --- /dev/null +++ b/node_modules/tiny-server/index.js @@ -0,0 +1 @@ +module.exports = require("./lib/server"); diff --git a/node_modules/tiny-server/lib/detect.js b/node_modules/tiny-server/lib/detect.js new file mode 100644 index 0000000..0dafed7 --- /dev/null +++ b/node_modules/tiny-server/lib/detect.js @@ -0,0 +1,42 @@ +module.exports = function () { + var unknowMIMEType = "application/octet-stream"; + var mimeTypes = new Map([ + ["txt", "text/plain"], + ["htm", "text/html"], + ["html", "text/html"], + ["xml", "text/xml"], + ["css", "text/css"], + ["js", "application/javascript"], + ["json", "application/json"], + + ["mp3", "audio/mpeg"], + ["wav", "audio/wav"], + + ["gif", "image/gif"], + ["jpg", "image/jpeg"], + ["jpeg", "image/jpeg"], + ["png", "image/png"], + ["bmp", "image/bmp"], + ["svg", "image/svg+xml"], + + ["avi", "video/avi"], + ["mp4", "video/mpeg"], + ]); + + return function (ext) { + if (!ext || typeof ext !== "string") { + return unknowMIMEType; + } + if (/^\./.test(ext)) { + ext = ext.slice(1); + } + + ext = ext.toLowerCase(); + + if (mimeTypes.has(ext)) { + return mimeTypes.get(ext); + } else { + return unknowMIMEType; + } + }; +}; diff --git a/node_modules/tiny-server/lib/mime.js b/node_modules/tiny-server/lib/mime.js new file mode 100644 index 0000000..1c4f6a7 --- /dev/null +++ b/node_modules/tiny-server/lib/mime.js @@ -0,0 +1,24 @@ +"use strict"; + +var detect = require("./detect")(); + +module.exports = function () { + var mimeTypes = new Map(); + var unknowMIMEType = "application/octet-stream"; + + return function (ext) { + if (!ext) { + return unknowMIMEType; + } + if (mimeTypes.has(ext)) { + return mimeTypes.get(ext); + } else { + var mimeType = detect(ext); + if (!mimeType) { + mimeType = unknowMIMEType; + } + mimeTypes.set(ext, mimeType); + return mimeType; + } + }; +}; diff --git a/node_modules/tiny-server/lib/server.js b/node_modules/tiny-server/lib/server.js new file mode 100644 index 0000000..a235a5d --- /dev/null +++ b/node_modules/tiny-server/lib/server.js @@ -0,0 +1,170 @@ +"use strict"; + +var fs = require("fs"); +var http = require("http"); +var path = require("path"); +var querystring = require("querystring"); +var stream = require("stream"); +var util = require("util"); +var url = require("url"); + +var mime = require("./mime")(); + +var Server = function Server(cwd, middlewares) { + if (!(this instanceof Server)) { + return new Server(cwd, middlewares); + } + if (!cwd) { + cwd = process.cwd(); + } + if (typeof middlewares === "function") { + middlewares = [middlewares]; + } else if (!Array.isArray(middlewares)) { + middlewares = []; + } + + http.Server.call(this); + + this.cwd = cwd; + this.middlewares = middlewares; + + var requestHandler = this.handler.bind(this); + this.on("request", requestHandler); + this.once("close", function () { + this.removeListener("request", requestHandler); + }); +}; +util.inherits(Server, http.Server); + +Server.prototype.handler = function (req, res) { + + var pathname = url.parse(req.url).pathname; + var filename = path.join(this.cwd, path.normalize(querystring.unescape(pathname))); + + var that = this; + fs.exists(filename, function (exists) { + if (exists) { + fs.stat(filename, function (err, stats) { + if (err) { + return that.notFound(res); + } + if (stats.isFile()) { + var ext = path.extname(filename); + var mimeType = mime(ext); + res.writeHead(200, { + "Content-Type": mimeType, + "Access-Control-Allow-Origin": "*" + }); + fs.createReadStream(filename).pipe(res); + } else if (stats.isDirectory()) { + if (!/\/$/.test(pathname)) { + res.writeHead(301, { + "Location": path.join(pathname, "/") + }); + res.end(); + return; + } + fs.readdir(filename, function (err, files) { + if (err) { + return that.notFound(res); + } + + var len = files.length; + if (!len) { + dir(files); + return; + } + + var items = []; + + files.forEach(function (file) { + fs.stat(path.join(filename, file), function (err, stats) { + if (!err) { + items.push(stats.isDirectory() ? path.join(file, "/") : file); + } + --len; + if (!len) { + dir(items); + } + }); + }); + + function dir(files) { + res.writeHead(200, { + "Content-Type": "text/html", + "Access-Control-Allow-Origin": "*" + }); + res.end(["", + '', + '', + ' ', + ' ', + ' ', + ' Index of ' + pathname + '', + ' ', + ' ', + '

Index of ' + pathname + '

', + '
', + ' ', + '
', + ' ', + '', + ""].join("\n")); + } + }); + + } else { + that.notFound(res); + } + }); + } else { + that.notFound(res); + } + }); + +}; +Server.prototype.notFound = function (res) { + res.writeHead(404, { + "Content-Type": "text/html", + "Access-Control-Allow-Origin": "*" + }); + + var file = path.join(this.cwd, "404.html"); + fs.exists(file, function (exists) { + if (exists) { + fs.createReadStream(file).pipe(res); + } else { + default404Reader().pipe(res); + } + }); + + function default404Reader() { + var f404 = new stream.Readable(); + f404._read = function () { + + this.push(["", + '', + '', + ' ', + ' ', + ' Not Found!', + ' ', + ' ', + '

File Not Found!

', + ' ', + '', + ""].join("\n")); + this.push(null); + + }; + return f404; + } +}; + + +module.exports = Server; diff --git a/node_modules/tiny-server/package.json b/node_modules/tiny-server/package.json new file mode 100644 index 0000000..4688c6b --- /dev/null +++ b/node_modules/tiny-server/package.json @@ -0,0 +1,34 @@ +{ + "name": "tiny-server", + "version": "1.1.1", + "description": "a tiny Web Server", + "main": "index.js", + "scripts": { + "test": "mocha ./test/index.js" + }, + "bin": { + "tiny-server": "./bin/index" + }, + "keywords": [ + "http", + "web", + "server", + "tiny" + ], + "author": "zbinlin", + "license": "MIT", + "directories": { + "test": "test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/zbinlin/tiny-server.git" + }, + "bugs": { + "url": "https://github.com/zbinlin/tiny-server/issues" + }, + "homepage": "https://github.com/zbinlin/tiny-server#readme", + "devDependencies": { + "mocha": "^10.0.0" + } +} diff --git a/node_modules/tiny-server/test/detect-test.js b/node_modules/tiny-server/test/detect-test.js new file mode 100644 index 0000000..1148648 --- /dev/null +++ b/node_modules/tiny-server/test/detect-test.js @@ -0,0 +1,23 @@ +"use strict"; + +var assert = require("assert"); + +var detect = require("../lib/detect")(); + +describe("test lib/detect", function () { + it("非法参数时,返回 application/octet-stream", function () { + assert.equal(detect(), "application/octet-stream"); + }); + it("扩展名不区别大小写", function () { + var mimeType = "text/plain"; + assert.equal(detect("txt"), mimeType); + assert.equal(detect("TXT"), mimeType); + }); + it("扩展名前可带 .,如 .txt", function () { + var mimeType = "text/plain"; + assert.equal(detect(".txt"), mimeType); + }); + it("未知扩展名,返回 application/octet-stream", function () { + assert.equal(detect(".xxx"), "application/octet-stream"); + }); +}); diff --git a/node_modules/tiny-server/test/index.js b/node_modules/tiny-server/test/index.js new file mode 100644 index 0000000..4d0799a --- /dev/null +++ b/node_modules/tiny-server/test/index.js @@ -0,0 +1,5 @@ +"use strict"; + +require("./detect-test"); +require("./mime-test"); +require("./server-test"); diff --git a/node_modules/tiny-server/test/mime-test.js b/node_modules/tiny-server/test/mime-test.js new file mode 100644 index 0000000..3278c55 --- /dev/null +++ b/node_modules/tiny-server/test/mime-test.js @@ -0,0 +1,19 @@ +"use strict"; + +var assert = require("assert"); + +var mime = require("../lib/mime")(); + +describe("test lib/mime", function () { + it("非法参数时,返回 application/octet-stream", function () { + assert.equal(mime(), "application/octet-stream"); + }); + it(".txt 返回 text/plain", function () { + assert.equal(mime(".txt"), "text/plain"); + assert.equal(mime(".txt"), "text/plain"); + }); + it("未知扩展名,返回 application/octet-stream", function () { + assert.equal(mime(".xxx"), "application/octet-stream"); + }); +}); + diff --git a/node_modules/tiny-server/test/server-test.js b/node_modules/tiny-server/test/server-test.js new file mode 100644 index 0000000..e69de29 diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..26f4b76 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,31 @@ +{ + "name": "performance-bug-unmuted-window", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "performance-bug-unmuted-window", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "tiny-server": "^1.1.1" + } + }, + "node_modules/tiny-server": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/tiny-server/-/tiny-server-1.1.1.tgz", + "integrity": "sha512-UZdFJFqms0+mvWOs1LRuf2C/ONjERZvaAXXyvqHXGGZtFeFUfeunmVi7OFdI8OgCiBUM1Rq+BfYJ2guVUeXnUg==", + "bin": { + "tiny-server": "bin/index" + } + } + }, + "dependencies": { + "tiny-server": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/tiny-server/-/tiny-server-1.1.1.tgz", + "integrity": "sha512-UZdFJFqms0+mvWOs1LRuf2C/ONjERZvaAXXyvqHXGGZtFeFUfeunmVi7OFdI8OgCiBUM1Rq+BfYJ2guVUeXnUg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0cbcb34 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "performance-bug-unmuted-window", + "version": "1.0.0", + "description": "", + "scripts": { + "serve": "tiny-server" + }, + "author": "", + "license": "ISC", + "dependencies": { + "tiny-server": "^1.1.1" + } +} \ No newline at end of file