Copy audio-related files into js/ instead of symlinking them (#1456)
This adds a new copy:deps task into the overall default task, and it needs to be run before running the product for the first time, and after upgrading audio-related deps. FREEBIE
This commit is contained in:
parent
272955b9d6
commit
02571b7ae9
3 changed files with 46801 additions and 4 deletions
13
Gruntfile.js
13
Gruntfile.js
|
@ -126,6 +126,15 @@ module.exports = function(grunt) {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
copy: {
|
copy: {
|
||||||
|
deps: {
|
||||||
|
files: [{
|
||||||
|
src: 'components/mp3lameencoder/lib/Mp3LameEncoder.js',
|
||||||
|
dest: 'js/Mp3LameEncoder.min.js'
|
||||||
|
}, {
|
||||||
|
src: 'components/webaudiorecorder/lib/WebAudioRecorderMp3.js',
|
||||||
|
dest: 'js/WebAudioRecorderMp3.js'
|
||||||
|
}],
|
||||||
|
},
|
||||||
res: {
|
res: {
|
||||||
files: [{ expand: true, dest: 'dist/', src: ['<%= dist.res %>'] }],
|
files: [{ expand: true, dest: 'dist/', src: ['<%= dist.res %>'] }],
|
||||||
},
|
},
|
||||||
|
@ -491,9 +500,9 @@ module.exports = function(grunt) {
|
||||||
grunt.registerTask('tx', ['exec:tx-pull', 'locale-patch']);
|
grunt.registerTask('tx', ['exec:tx-pull', 'locale-patch']);
|
||||||
grunt.registerTask('dev', ['default', 'connect', 'watch']);
|
grunt.registerTask('dev', ['default', 'connect', 'watch']);
|
||||||
grunt.registerTask('test', ['jshint', 'jscs', 'unit-tests']);
|
grunt.registerTask('test', ['jshint', 'jscs', 'unit-tests']);
|
||||||
grunt.registerTask('copy_dist', ['gitinfo', 'copy']);
|
grunt.registerTask('copy_dist', ['gitinfo', 'copy:res', 'copy:src']);
|
||||||
grunt.registerTask('date', ['gitinfo', 'getExpireTime']);
|
grunt.registerTask('date', ['gitinfo', 'getExpireTime']);
|
||||||
grunt.registerTask('prep-release', ['gitinfo', 'clean-release', 'fetch-release']);
|
grunt.registerTask('prep-release', ['gitinfo', 'clean-release', 'fetch-release']);
|
||||||
grunt.registerTask('default', ['concat', 'sass', 'date']);
|
grunt.registerTask('default', ['concat', 'copy:deps', 'sass', 'date']);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
1
js/Mp3LameEncoder.min.js
vendored
1
js/Mp3LameEncoder.min.js
vendored
|
@ -1 +0,0 @@
|
||||||
../components/mp3lameencoder/lib/Mp3LameEncoder.js
|
|
46699
js/Mp3LameEncoder.min.js
vendored
Normal file
46699
js/Mp3LameEncoder.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
||||||
../components/webaudiorecorder/lib/WebAudioRecorderMp3.js
|
|
91
js/WebAudioRecorderMp3.js
Normal file
91
js/WebAudioRecorderMp3.js
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
importScripts("Mp3LameEncoder.min.js");
|
||||||
|
|
||||||
|
var NUM_CH = 2, // constant
|
||||||
|
sampleRate = 44100,
|
||||||
|
options = undefined,
|
||||||
|
maxBuffers = undefined,
|
||||||
|
encoder = undefined,
|
||||||
|
recBuffers = undefined,
|
||||||
|
bufferCount = 0;
|
||||||
|
|
||||||
|
function error(message) {
|
||||||
|
self.postMessage({ command: "error", message: "mp3: " + message });
|
||||||
|
}
|
||||||
|
|
||||||
|
function init(data) {
|
||||||
|
if (data.config.numChannels === NUM_CH) {
|
||||||
|
sampleRate = data.config.sampleRate;
|
||||||
|
options = data.options;
|
||||||
|
} else
|
||||||
|
error("numChannels must be " + NUM_CH);
|
||||||
|
};
|
||||||
|
|
||||||
|
function setOptions(opt) {
|
||||||
|
if (encoder || recBuffers)
|
||||||
|
error("cannot set options during recording");
|
||||||
|
else
|
||||||
|
options = opt;
|
||||||
|
}
|
||||||
|
|
||||||
|
function start(bufferSize) {
|
||||||
|
maxBuffers = Math.ceil(options.timeLimit * sampleRate / bufferSize);
|
||||||
|
if (options.encodeAfterRecord)
|
||||||
|
recBuffers = [];
|
||||||
|
else
|
||||||
|
encoder = new Mp3LameEncoder(sampleRate, options.mp3.bitRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
function record(buffer) {
|
||||||
|
if (bufferCount++ < maxBuffers)
|
||||||
|
if (encoder)
|
||||||
|
encoder.encode(buffer);
|
||||||
|
else
|
||||||
|
recBuffers.push(buffer);
|
||||||
|
else
|
||||||
|
self.postMessage({ command: "timeout" });
|
||||||
|
};
|
||||||
|
|
||||||
|
function postProgress(progress) {
|
||||||
|
self.postMessage({ command: "progress", progress: progress });
|
||||||
|
};
|
||||||
|
|
||||||
|
function finish() {
|
||||||
|
if (recBuffers) {
|
||||||
|
postProgress(0);
|
||||||
|
encoder = new Mp3LameEncoder(sampleRate, options.mp3.bitRate);
|
||||||
|
var timeout = Date.now() + options.progressInterval;
|
||||||
|
while (recBuffers.length > 0) {
|
||||||
|
encoder.encode(recBuffers.shift());
|
||||||
|
var now = Date.now();
|
||||||
|
if (now > timeout) {
|
||||||
|
postProgress((bufferCount - recBuffers.length) / bufferCount);
|
||||||
|
timeout = now + options.progressInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
postProgress(1);
|
||||||
|
}
|
||||||
|
self.postMessage({
|
||||||
|
command: "complete",
|
||||||
|
blob: encoder.finish(options.mp3.mimeType)
|
||||||
|
});
|
||||||
|
cleanup();
|
||||||
|
};
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
encoder = recBuffers = undefined;
|
||||||
|
bufferCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.onmessage = function(event) {
|
||||||
|
var data = event.data;
|
||||||
|
switch (data.command) {
|
||||||
|
case "init": init(data); break;
|
||||||
|
case "options": setOptions(data.options); break;
|
||||||
|
case "start": start(data.bufferSize); break;
|
||||||
|
case "record": record(data.buffer); break;
|
||||||
|
case "finish": finish(); break;
|
||||||
|
case "cancel": cleanup();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
self.postMessage({ command: "loaded" });
|
Loading…
Reference in a new issue