source: main/trunk/model-sites-dev/respooled/collect/popup-video-respooled/js/in-the-groove.js@ 29867

Last change on this file since 29867 was 29867, checked in by davidb, 9 years ago

Next round of improvements. More open-close bars. Drums with better images. Drums played on mousedown + key mappings. Playbar layout changed. Timing info when playing added.

File size: 1.8 KB
Line 
1
2// https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createScriptProcessor
3
4var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
5
6var InTheGroove = false;
7var MissingTheGroovePending = false;
8
9//var bufferSize = 4096;
10var bufferSize = 512;
11
12
13//window.addEventListener('load', onLoad, false);
14
15
16var prev_input = [0,0];
17
18$(document).ready(function() {
19 $('#video').on('loadedmetadata', function() {
20
21 displayDuration(this.duration);
22
23 // Create a MediaElementAudioSourceNode
24 // Feed the HTMLMediaElement into it
25 var source = audioCtx.createMediaElementSource(this);
26
27 // connect the AudioBufferSourceNode to the tinnyEffectNode
28 // and the tinnyEffectNode to the destination, so we can play the
29 // music and have the filter 'kick in' when 'Missing Out' button
30 // pressed
31
32 var tinnyEffectNode = audioCtx.createScriptProcessor(bufferSize, 2, 2);
33 tinnyEffectNode.onaudioprocess = function(e) {
34
35 for (var c = 0; c<2; c++) {
36 var input = e.inputBuffer.getChannelData(c);
37 var output = e.outputBuffer.getChannelData(c);
38
39
40 for (var i = 0; i < bufferSize; i++) {
41 if (InTheGroove) {
42 if (c==0) {
43 output[i] = input[i];
44 }
45 else {
46 output[i] = 0;
47 }
48 }
49 else {
50 // Make sound 'tinny' through simple high-pass filter
51 output[i] = input[i] - prev_input[c];
52 }
53 prev_input[c] = input[i];
54 }
55 }
56 }
57
58 source.connect(tinnyEffectNode);
59 tinnyEffectNode.connect(audioCtx.destination);
60
61 console.log("onLoadMetadata done");
62 });
63
64});
65
66function inTheGroove()
67{
68 InTheGroove = true;
69 MissingTheGroovePending = false;
70}
71
72function missingTheGroove()
73{
74 if (MissingTheGroovePending) {
75 InTheGroove = false;
76 }
77 MissingTheGroovePending = false;
78}
79
80function delayedMissingTheGroove(delay)
81{
82 MissingTheGroovePending = true;
83 setTimeout(missingTheGroove,delay || 400);
84}
85
86
Note: See TracBrowser for help on using the repository browser.