-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncoder.js
More file actions
48 lines (39 loc) · 932 Bytes
/
Encoder.js
File metadata and controls
48 lines (39 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
angular
.module('hackday')
.factory('Encoder', function($q) {
return {
toWav: toWav
};
function toWav(buffer) {
var defer = $q.defer(),
worker = new Worker('recorderWorker.js');
// initialize the new worker
worker.postMessage({
command: 'init',
config: {
numChannels: 1,
sampleRate: 44100
}
});
// callback for `exportWAV`
worker.onmessage = function(e) {
var blob = e.data;
// our WAV blob
defer.resolve(blob)
};
// send the channel data from our buffer to the worker
worker.postMessage({
command: 'record',
buffer: [
buffer.getChannelData(0)
]
});
// ask the worker for a WAV
worker.postMessage({
command: 'exportWAV',
type: 'audio/wav'
});
return defer.promise;
}
});