![]() |
<!DOCTYPE HTML> <HTML LANG="ja"> <HEAD> <META CHARSET="Shift_JIS"> <TITLE>蓄音機</TITLE> </HEAD> <BODY STYLE="background-color:#CCFFFF"> <DIV STYLE="text-align:center"> <BR> <B><SPAN STYLE="color:#CC0000">蓄音機</SPAN></B> <BR><BR> <FORM> <TABLE STYLE="margin-left:auto; margin-right:auto"><TR><TD STYLE="text-align:left; white-space:nowrap"> <B>ファイル:</B><BR> <INPUT TYPE=FILE ID="file" onChange="sel_file()" STYLE="min-width:30em"><BR><BR> <INPUT TYPE=BUTTON ID="play" VALUE="再生" DISABLED onClick="play_stop()"> </TD></TR></TABLE> </FORM> </DIV> <SCRIPT TYPE="text/javascript"> <!-- function sel_file() { r_s_time = 10000000000; if(url_cre) URL.revokeObjectURL(elem_aud.src); elem_aud.src = URL.createObjectURL(elem_file.files.item(0)); url_cre = true; elem_play.disabled = false; } function play_stop() { if(playing) { // 再生中 // 停止 elem_aud.pause() playing = 2; stop(); return; } elem_file.disabled = true; elem_play.value = "停止"; playing = 1; noise = aud_ctx.createBufferSource(); noise.loop = true; noise.buffer = noise_buf; noise.connect(limiter); noise.start(0); // Opera では,パラメータをすべて省略するとエラーになる r_s = 0; r_s_time = 0; elem_aud.currentTime = 0; to_id = setTimeout(aud_start, 1500); } function aud_start() { elem_aud.play(); to_id = undefined; } function source_timeupdate() { // 針とび if(elem_aud.currentTime < r_s_time) return; if(r_s > 0) { // リピート elem_aud.currentTime -= 0.7692; r_s--; return; } if(r_s) // スキップ elem_aud.currentTime += 0.7692; r_s = Math.floor(Math.random() * 10); if(r_s < 5) r_s = -1; else r_s -= 4; r_s_time += 0.7692 + Math.random() * 120; } function source_ended() { if(playing == 2) { stop(); return; } to_id = setTimeout(stop, 1500); } function stop() { if(!playing) return; if(to_id != undefined) { clearTimeout(to_id); to_id = undefined; } noise.stop(0); // Opera では,パラメータをすべて省略するとエラーになる noise.disconnect(); noise = undefined; elem_play.value = "再生"; playing = 0; elem_file.disabled = false; } function source_error() { elem_play.disabled = true; if(playing) stop(); alert("再生できません。"); } elem_aud = new Audio(); elem_aud.addEventListener("ended", source_ended, false); elem_aud.addEventListener("timeupdate", source_timeupdate, false); elem_aud.addEventListener("error", source_error, false); with(aud_ctx = (window.webkitAudioContext == undefined) ? new AudioContext() : new webkitAudioContext()) { limiter = createDynamicsCompressor() limiter.threshold.value = 0; limiter.knee.value = 0; limiter.ratio.value = 20; limiter.attack.value = 0; limiter.release.value = 0; limiter.connect(destination); lpf1 = createBiquadFilter(); lpf2 = createBiquadFilter(); lpf3 = createBiquadFilter(); lpf4 = createBiquadFilter(); lpf5 = createBiquadFilter(); lpf1.type = lpf2.type = lpf3.type = lpf4.type = lpf5.type = "lowpass"; lpf1.frequency.value = lpf2.frequency.value = lpf3.frequency.value = lpf4.frequency.value = lpf5.frequency.value = 2500; lpf1.Q.value = lpf2.Q.value = lpf3.Q.value = lpf4.Q.value = lpf5.Q.value = 1; lpf1.connect(limiter); lpf2.connect(lpf1); lpf3.connect(lpf2); lpf4.connect(lpf3); lpf5.connect(lpf4); gain = createGain(); gain.channelCountMode = "explicit"; gain.channelCount = 1; gain.gain.value = 0.9; gain.connect(lpf5); source = createMediaElementSource(elem_aud); source.connect(gain); // ノイズ noise_buf = createBuffer(1, 100000, 22050); pcm = noise_buf.getChannelData(0); j = 0; for(i = 0; i < 100000; i++) { if(i == j) { pcm[i] = Math.random() * 0.6 - 0.3; j = i + Math.floor(Math.random() * 3000); } else { pcm[i] = Math.random() * 0.02 - 0.01; } } } playing = 0; url_cre = false; elem_file = document.getElementById("file"); elem_play = document.getElementById("play"); // ページを再ロードしたときのため document.forms[0].reset(); elem_file.disabled = false; elem_play.disabled = true; //--> </SCRIPT> </BODY> </HTML> |