From e441706809e22976e579410d2e38eac7f83768fb Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 1 Jan 2018 21:21:18 -0800 Subject: [PATCH] Clean up old experiments --- experiments/audioAbstraction/app.js | 79 ------------------------- experiments/audioAbstraction/index.html | 36 ----------- experiments/createObjectURL/index.html | 13 ---- experiments/createObjectURL/index.js | 70 ---------------------- 4 files changed, 198 deletions(-) delete mode 100644 experiments/audioAbstraction/app.js delete mode 100644 experiments/audioAbstraction/index.html delete mode 100644 experiments/createObjectURL/index.html delete mode 100644 experiments/createObjectURL/index.js diff --git a/experiments/audioAbstraction/app.js b/experiments/audioAbstraction/app.js deleted file mode 100644 index cd13064e..00000000 --- a/experiments/audioAbstraction/app.js +++ /dev/null @@ -1,79 +0,0 @@ -/* global ElementSource BufferSource */ -const play = document.getElementById("play"); -const pause = document.getElementById("pause"); -const stop = document.getElementById("stop"); -const eject = document.getElementById("eject"); -const url = document.getElementById("url"); -const loadUrl = document.getElementById("loadUrl"); -const info = document.getElementById("info"); -const position = document.getElementById("position"); -const sourceType = document.getElementById("sourceType"); -const autoplay = document.getElementById("autoplay"); - -const context = new (window.AudioContext || window.webkitAudioContext)(); - -const getSourceClass = () => - sourceType.value === "buffer" ? BufferSource : ElementSource; - -let source = new (getSourceClass())(context, context.destination); -source.setAutoPlay(true); - -sourceType.addEventListener("change", () => { - source.disconnect(); - source = new (getSourceClass())(context, context.destination); - source.setAutoPlay(true); -}); - -//const source = new BufferSource(context, context.destination); - -play.addEventListener("click", () => { - source.play(); -}); -pause.addEventListener("click", () => { - source.pause(); -}); -stop.addEventListener("click", () => { - source.stop(); -}); -eject.addEventListener("change", e => { - source.loadFile(e.target.files[0]); -}); - -loadUrl.addEventListener("click", () => { - source.loadUrl(url.value); -}); - -position.addEventListener("change", () => { - const percent = position.value / 100; - const newTime = source.getDuration() * percent; - source.seekToTime(newTime); -}); - -autoplay.addEventListener("change", () => { - source.setAutoPlay(autoplay.checked); -}); - -const updateInfo = () => { - const data = { - numberOfChannels: source.getNumberOfChannels(), - status: source.getStatus(), - duration: source.getDuration(), - timeElapsed: source.getTimeElapsed(), - sampleRate: source.getSampleRate(), - loop: source.getLoop(), - autoplay: source.getAutoPlay() - }; - - info.value = JSON.stringify(data, null, 2); -}; -info.addEventListener("click", updateInfo); - -source.on("statusChange", () => { - updateInfo(); -}); - -source.on("positionChange", () => { - const percent = source.getTimeElapsed() / source.getDuration(); - position.value = percent * 100; - updateInfo(); -}); diff --git a/experiments/audioAbstraction/index.html b/experiments/audioAbstraction/index.html deleted file mode 100644 index d43c5d80..00000000 --- a/experiments/audioAbstraction/index.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - Audio Abstraction - - - - - - - -
- -
- - -
- -
Autoplay: - -
- - - - - - - - \ No newline at end of file diff --git a/experiments/createObjectURL/index.html b/experiments/createObjectURL/index.html deleted file mode 100644 index 33b5adec..00000000 --- a/experiments/createObjectURL/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/experiments/createObjectURL/index.js b/experiments/createObjectURL/index.js deleted file mode 100644 index 00d2e259..00000000 --- a/experiments/createObjectURL/index.js +++ /dev/null @@ -1,70 +0,0 @@ -const context = new (window.AudioContext || window.webkitAudioContext)(); -const audio = document.getElementById("audio"); -audio.autoplay = true; -audio.controls = true; - -audio.setAttribute("crossOrigin", "anonymous"); - -const source = context.createMediaElementSource(audio); - -const analyser = context.createAnalyser(); -source.connect(analyser); - -analyser.fftSize = 2048; -const bufferLength = analyser.frequencyBinCount; -const dataArray = new Uint8Array(bufferLength); -analyser.getByteTimeDomainData(dataArray); - -// Get a canvas defined with ID "oscilloscope" -const canvas = document.getElementById("oscilloscope"); -const canvasCtx = canvas.getContext("2d"); - -// draw an oscilloscope of the current audio source - -function draw() { - requestAnimationFrame(draw); - - analyser.getByteTimeDomainData(dataArray); - - canvasCtx.fillStyle = "rgb(200, 200, 200)"; - canvasCtx.fillRect(0, 0, canvas.width, canvas.height); - - canvasCtx.lineWidth = 2; - canvasCtx.strokeStyle = "rgb(0, 0, 0)"; - - canvasCtx.beginPath(); - - const sliceWidth = canvas.width * 1.0 / bufferLength; - let x = 0; - - for (let i = 0; i < bufferLength; i++) { - const v = dataArray[i] / 128.0; - const y = v * canvas.height / 2; - - if (i === 0) { - canvasCtx.moveTo(x, y); - } else { - canvasCtx.lineTo(x, y); - } - - x += sliceWidth; - } - - canvasCtx.lineTo(canvas.width, canvas.height / 2); - canvasCtx.stroke(); -} - -draw(); - -source.connect(context.destination); - -document.getElementById("input").addEventListener("change", e => { - const url = URL.createObjectURL(e.target.files[0]); - audio.src = url; -}); - -document.getElementById("podcast").addEventListener("click", () => { - const url = - "http://cf-media.sndcdn.com/XjYswaAshTWP?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vWGpZc3dhQXNoVFdQIiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNTA2MDA3OTkxfX19XX0_&Signature=rGScfcjqJp3ZFMeeiovou39xp8q78CHEyEYgHtjXQ3rKDhzQza9Bv9JFDexhdWlLD2xw7JQ8OHhRPaG5CKwQy1bojrwBSdwFaXZD2LIRmuQE5gRToNs6Glop89cBpDBbTKRWLFLZ37dH9kB438C-6TKB1yygzLVTSsx6p9Dt1mWldVaKDKxApDYYUuPvVq9ZCLScAoa2-4jOmPzmPjcoyrX~3BdLCRhXYYlxNTFBEKXmWhnBq10ZD01ERz-32WGcM1IydxIIoCsthgNBgDHoig26~YM7vskXswf8khi9i02cuAZcCPLIgKBdbFcHiRRErwd4Qq1hv210gH~hcIXTEg__&Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ"; - audio.src = url; -});