Skip to content

Commit

Permalink
Commit lib files as some were deleted from npm
Browse files Browse the repository at this point in the history
  • Loading branch information
lukephills committed May 2, 2022
1 parent e3e70a1 commit f9c6097
Show file tree
Hide file tree
Showing 2,325 changed files with 391,868 additions and 6 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Expand Up @@ -3,8 +3,5 @@
.vscode
node_modules
app/.build
app/lib
.DS_Store
npm-debug.log
dist
dist.zip
npm-debug.log
32 changes: 32 additions & 0 deletions app/lib/RecorderJS/.bower.json
@@ -0,0 +1,32 @@
{
"name": "RecorderJS",
"homepage": "https://github.com/lukephills/Recorderjs",
"authors": [
"Luke Phillips <luke@femurdesign.com>"
],
"description": "Recording from web audio API and exporting to wav",
"main": "recorder.js",
"keywords": [
"Audio",
"Wav",
"Sound",
"Record",
"Recording"
],
"license": "MIT",
"ignore": [
"node_modules",
"bower_components",
"test",
"tests"
],
"_release": "1edf02ae47",
"_resolution": {
"type": "branch",
"branch": "master",
"commit": "1edf02ae47cd93d060adda2176f99b5afc39cdc8"
},
"_source": "git://github.com/lukephills/Recorderjs.git",
"_target": "master",
"_originalSource": "lukephills/Recorderjs"
}
1 change: 1 addition & 0 deletions app/lib/RecorderJS/.gitignore
@@ -0,0 +1 @@
.idea
23 changes: 23 additions & 0 deletions app/lib/RecorderJS/bower.json
@@ -0,0 +1,23 @@
{
"name": "RecorderJS",
"homepage": "https://github.com/lukephills/Recorderjs",
"authors": [
"Luke Phillips <luke@femurdesign.com>"
],
"description": "Recording from web audio API and exporting to wav",
"main": "recorder.js",
"keywords": [
"Audio",
"Wav",
"Sound",
"Record",
"Recording"
],
"license": "MIT",
"ignore": [
"node_modules",
"bower_components",
"test",
"tests"
]
}
14 changes: 14 additions & 0 deletions app/lib/RecorderJS/recorder.d.ts
@@ -0,0 +1,14 @@
declare var RecorderJS: {
new(AudioSource: any, config?: any): RecorderJS;
};

interface RecorderJS {
record(): void;
stop(): void;
clear(): void;
exportWAV(callback?: any, type?: string);
exportMonoWAV(callback?: any, type?: string);
setupDownload(blob, filename?): void;
getBuffer(callback?: any)
configure(any): void;
}
106 changes: 106 additions & 0 deletions app/lib/RecorderJS/recorder.js
@@ -0,0 +1,106 @@
(function(window){

var WORKER_PATH = 'recorderWorker.js';

var RecorderJS = function(source, cfg){
var config = cfg || {};
var bufferLen = config.bufferLen || 4096;
this.context = source.context;
if(!this.context.createScriptProcessor){
this.node = this.context.createJavaScriptNode(bufferLen, 2, 2);
} else {
this.node = this.context.createScriptProcessor(bufferLen, 2, 2);
}

var worker = new Worker(config.workerPath || WORKER_PATH);
worker.postMessage({
command: 'init',
config: {
sampleRate: this.context.sampleRate
}
});
var recording = false,
currCallback;

this.node.onaudioprocess = function(e){
if (!recording) return;
worker.postMessage({
command: 'record',
buffer: [
e.inputBuffer.getChannelData(0),
e.inputBuffer.getChannelData(1)
]
});
}

this.configure = function(cfg){
for (var prop in cfg){
if (cfg.hasOwnProperty(prop)){
config[prop] = cfg[prop];
}
}
}

this.record = function(){
recording = true;
}

this.stop = function(){
recording = false;
}

this.clear = function(){
worker.postMessage({ command: 'clear' });
}

this.getBuffers = function(cb) {
currCallback = cb || config.callback;
worker.postMessage({ command: 'getBuffers' })
}

this.exportWAV = function(cb, type){
currCallback = cb || config.callback;
type = type || config.type || 'audio/wav';
if (!currCallback) throw new Error('Callback not set');
worker.postMessage({
command: 'exportWAV',
type: type
});
}

this.exportMonoWAV = function(cb, type){
currCallback = cb || config.callback;
type = type || config.type || 'audio/wav';
if (!currCallback) throw new Error('Callback not set');
worker.postMessage({
command: 'exportMonoWAV',
type: type
});
}

this.setupDownload = function(blob, filename){
var url = (window.URL || window.webkitURL).createObjectURL(blob);
var link = window.document.createElement('a');
link.href = url;
link.download = filename || 'output.wav';
document.body.appendChild(link);
link.innerHTML = 'DOWNLOAD'

// CHROME DOESNT ALLOW THIS ANY MORE
var click = document.createEvent("Event");
click.initEvent("click", true, true);
link.dispatchEvent(click);
}

worker.onmessage = function(e){
var blob = e.data;
currCallback(blob);
}

source.connect(this.node);
this.node.connect(this.context.destination); // if the script node is not connected to an output the "onaudioprocess" event is not triggered in chrome.
};

window.RecorderJS = RecorderJS;

})(window);
142 changes: 142 additions & 0 deletions app/lib/RecorderJS/recorderWorker.js
@@ -0,0 +1,142 @@
var recLength = 0,
recBuffersL = [],
recBuffersR = [],
sampleRate;

this.onmessage = function(e){
switch(e.data.command){
case 'init':
init(e.data.config);
break;
case 'record':
record(e.data.buffer);
break;
case 'exportWAV':
exportWAV(e.data.type);
break;
case 'exportMonoWAV':
exportMonoWAV(e.data.type);
break;
case 'getBuffers':
getBuffers();
break;
case 'clear':
clear();
break;
}
};

function init(config){
sampleRate = config.sampleRate;
}

function record(inputBuffer){
recBuffersL.push(inputBuffer[0]);
recBuffersR.push(inputBuffer[1]);
recLength += inputBuffer[0].length;
}

function exportWAV(type){
var bufferL = mergeBuffers(recBuffersL, recLength);
var bufferR = mergeBuffers(recBuffersR, recLength);
var interleaved = interleave(bufferL, bufferR);
var dataview = encodeWAV(interleaved);
var audioBlob = new Blob([dataview], { type: type });

this.postMessage(audioBlob);
}

function exportMonoWAV(type){
var bufferL = mergeBuffers(recBuffersL, recLength);
var dataview = encodeWAV(bufferL, true);
var audioBlob = new Blob([dataview], { type: type });

this.postMessage(audioBlob);
}

function getBuffers() {
var buffers = [];
buffers.push( mergeBuffers(recBuffersL, recLength) );
buffers.push( mergeBuffers(recBuffersR, recLength) );
this.postMessage(buffers);
}

function clear(){
recLength = 0;
recBuffersL = [];
recBuffersR = [];
}

function mergeBuffers(recBuffers, recLength){
var result = new Float32Array(recLength);
var offset = 0;
for (var i = 0; i < recBuffers.length; i++){
result.set(recBuffers[i], offset);
offset += recBuffers[i].length;
}
return result;
}

function interleave(inputL, inputR){
var length = inputL.length + inputR.length;
var result = new Float32Array(length);

var index = 0,
inputIndex = 0;

while (index < length){
result[index++] = inputL[inputIndex];
result[index++] = inputR[inputIndex];
inputIndex++;
}
return result;
}

function floatTo16BitPCM(output, offset, input){
for (var i = 0; i < input.length; i++, offset+=2){
var s = Math.max(-1, Math.min(1, input[i]));
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
}
}

function writeString(view, offset, string){
for (var i = 0; i < string.length; i++){
view.setUint8(offset + i, string.charCodeAt(i));
}
}

function encodeWAV(samples, mono){
var buffer = new ArrayBuffer(44 + samples.length * 2);
var view = new DataView(buffer);

/* RIFF identifier */
writeString(view, 0, 'RIFF');
/* file length */
view.setUint32(4, 32 + samples.length * 2, true);
/* RIFF type */
writeString(view, 8, 'WAVE');
/* format chunk identifier */
writeString(view, 12, 'fmt ');
/* format chunk length */
view.setUint32(16, 16, true);
/* sample format (raw) */
view.setUint16(20, 1, true);
/* channel count */
view.setUint16(22, mono?1:2, true);
/* sample rate */
view.setUint32(24, sampleRate, true);
/* byte rate (sample rate * block align) */
view.setUint32(28, sampleRate * 4, true);
/* block align (channel count * bytes per sample) */
view.setUint16(32, 4, true);
/* bits per sample */
view.setUint16(34, 16, true);
/* data chunk identifier */
writeString(view, 36, 'data');
/* data chunk length */
view.setUint32(40, samples.length * 2, true);

floatTo16BitPCM(view, 44, samples);

return view;
}
16 changes: 16 additions & 0 deletions app/lib/bower-webfontloader/.bower.json
@@ -0,0 +1,16 @@
{
"name": "bower-webfontloader",
"version": "1.5.16",
"main": "webfont.js",
"license": "Apache-2.0",
"homepage": "https://github.com/mdarse/bower-webfontloader",
"_release": "1.5.16",
"_resolution": {
"type": "version",
"tag": "v1.5.16",
"commit": "006087cf80f07706e493644107be22df7cb570ad"
},
"_source": "git://github.com/mdarse/bower-webfontloader.git",
"_target": "~1.5.16",
"_originalSource": "bower-webfontloader"
}

0 comments on commit f9c6097

Please sign in to comment.