Created
July 9, 2012 20:22
-
-
Save smakhtin/3078669 to your computer and use it in GitHub Desktop.
FileStream DShow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VVVV.js -- Visual Web Client Programming | |
// (c) 2011 Matthias Zauner | |
// VVVV.js is freely distributable under the MIT license. | |
// Additional authors of sub components are mentioned at the specific code locations. | |
/* | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
NODE: FileStream (DShow9) | |
Author(s): Vadim Smakhtin | |
Original Node Author(s): VVVV Group | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
*/ | |
VVVV.Nodes.FileStream = function(id, graph) { | |
this.constructor(id, "FileStream (DShow9)", graph); | |
this.meta = { | |
authors: ['Vadim Smakhtin'], | |
original_authors: ['VVVV Group'], | |
credits: [], | |
compatibility_issues: [] | |
}; | |
this.auto_evaluate = false; | |
var playIn = this.addInputPin("Play", [0], this); | |
var loopIn = this.addInputPin("Loop", [0], this); | |
var startTimeIn = this.addInputPin("Start Time", [0.0], this); | |
var endTimeIn = this.addInputPin("End Time", [0.0], this); | |
var doSeekIn = this.addInputPin("Do Seek", [0], this); | |
var seekPositionIn = this.addInputPin("Seek Position", [0.0], this); | |
var speedIn = this.addInputPin("Speed", [1.0], this); | |
var filenameIn = this.addInputPin("Filename", ["file.avi"], this); | |
var audioOut = this.addOutputPin("Audio", [], this); | |
var midiOut = this.addOutputPin("Midi", [], this); | |
var videoOut = this.addOutputPin("Video", [], this); | |
var durationOut = this.addOutputPin("Duration", [0.0], this); | |
var positionOut = this.addOutputPin("Position", [0.0], this); | |
var seekingCapabilitiesOut = this.addOutputPin("Seeking Capabilities", [], this); | |
var bytesToReadOut = this.addOutputPin("Bytes to Read", [0], this); | |
var audioStreams = []; | |
this.evaluate = function() { | |
var maxSize = this.getMaxInputSliceCount(); | |
var fileName; | |
var extension; | |
audioOut.setSliceCount(audioStreams.length); | |
for (var i=0; i<maxSize; i++) { | |
audioOut.setValue(i, audioStreams[i]); | |
if (!filenameIn.pinIsChanged() || !this.contexChanged) | |
{ | |
fileName = filenameIn.getValue(i); | |
extension = fileName.split('.')[0]; | |
switch(extension) | |
{ | |
case: "mp3": | |
audioStreams[i] = new Audio(fileName); | |
break; | |
} | |
} | |
} | |
} | |
} | |
VVVV.Nodes.String2Enum.prototype = new VVVV.Core.Node(); | |
Audio = function(fileName) { | |
this.context = new webkitAudioContext(); | |
this.source = context.createBufferSource(); | |
this.analyser = context.createAnalyser(); | |
analyser.fftSize = 2048; | |
this.audioBuffer = null; | |
source.connect(analyser); | |
analyser.connect(context.destination); | |
loadAudio(fileName); | |
function loadAudio (url) { | |
var request = new XMLHttpRequest(); | |
request.open("GET", url, true); | |
request.responseType = "arraybuffer"; | |
request.onLoad = function () { | |
this.audioBuffer = context.createBuffer(request.response, false /*true*/); | |
finishLoad(); // add in the slider, etc. now that we've loaded the audio | |
} | |
} | |
function finishLoad() { | |
source.buffer = audioBuffer; | |
source.looping = true; | |
source.noteOn(0.0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment