示例#1
0
文件: index.js 项目: NHQ/delayo
module.exports = function(master, uri, cb){
    var master = master;
    var source = Object.create(null);
    var slave = slave || enslave(code);
    var synth;

    slave.postMessage({id: id++, uri: uri, sampleRate: master.sampleRate});

    slave.onmessage = function(evt){
	if(evt.data.type == 'meta'){

	    var data = evt.data.data;
	    source.data = data;
	    source.buffers = new Array(data.channelsPerFrame);

	    for(var x = 0; x < source.buffers.length; x++){
		source.buffers[x] = buffers(6);
	    }

	    var startTime = new Date().getTime();

	    var bufSize = 256 * 2 * 2 * 2 * 2 * 2;

	    synth = master.createScriptProcessor(bufSize, data.channelsPerFrame, data.channelsPerFrame);
	    synth.source = source;
	    synth.bufSize = bufSize;
	    synth.bufIndex = 0;
	    synth.id = id;
	    synth.currentTime = function(t){// t in seconds
		synth.bufIndex = t * master.sampleRate
	    };

	    synth.onaudioprocess = function(evt){
		var outputBuffer = event.outputBuffer;
		var channelCount = outputBuffer.numberOfChannels;
		var channels = new Array(channelCount);
		for (i = _i = 0; _i < channelCount; i = _i += 1) {
		    channels[i] = outputBuffer.getChannelData(i);
		}
		for(var x = 0; x < channels.length; x++){
		    channels[x].set(source.buffers[x].slice(this.bufIndex, this.bufIndex + this.bufSize));
		}
		this.bufIndex+=this.bufSize
	    };

//	    cb(null, synth)

	}
	else if(evt.data.type == 'end'){
	    cb(null, synth)

//	    alert((new Date().getTime() - startTime) / 1000)
	}
	else if(evt.data.type == 'progress'){
	    console.log('progress');
//	    console.log(evt.data.data);
	}
	else {
	    var wsb = source.buffers;
	    for(x in evt.data.buffer){
		wsb[x].push(evt.data.buffer[x]);
	    }
	}
    }


}
示例#2
0
文件: test-client.js 项目: NHQ/delayo
if(!window.URL) window.URL = {createObjectURL: window.webkitURL.createObjectURL}

var fs = require('fs');


var enslave = require('work-slave');
var jsynth = require('jsynth');
var amod = require('amod');
var buffers = require('buffers');
var jdelay = require('jdelay');
var floatConcat = require('./floatConcat.js');
var aurora = fs.readFileSync('./aurora.js');
var aac = fs.readFileSync('./aac.js');
var worker = fs.readFileSync('./worker.js');
var code = aurora + aac + worker;
var slave = enslave(code); 


var master = window.master = new webkitAudioContext()
var source = window.source = Object.create(null);

var uri = 'http://www.youtube.com/watch?v=vftIGU8-uqs';
//var uri = 'http://www.youtube.com/watch?v=vWD7k6TrJ-g';
var id = 0;
var actualSampleCount = 0;

var resample;

var a = document.createElement('a');
a.href="#";
a.textContent = 'click here';