]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/js/vendor/recorderjs/recorder.js
3 var WORKER_PATH
= 'recorderWorker.js';
5 var Recorder = function(source
, cfg
){
6 var config
= cfg
|| {};
7 var bufferLen
= config
.bufferLen
|| 4096;
8 this.context
= source
.context
;
9 this.node
= (this.context
.createScriptProcessor
||
10 this.context
.createJavaScriptNode
).call(this.context
,
12 var worker
= new Worker(config
.workerPath
|| WORKER_PATH
);
16 sampleRate: this.context
.sampleRate
19 var recording
= false,
23 this.node
.onaudioprocess = function(e
){
24 if (!recording
) return;
25 self
.ondata
&& self
.ondata(e
.inputBuffer
.getChannelData(0));
29 e
.inputBuffer
.getChannelData(0),
30 e
.inputBuffer
.getChannelData(1)
35 this.configure = function(cfg
){
36 for (var prop
in cfg
){
37 if (cfg
.hasOwnProperty(prop
)){
38 config
[prop
] = cfg
[prop
];
43 this.record = function(){
47 this.stop = function(){
51 this.clear = function(){
52 worker
.postMessage({ command: 'clear' });
55 this.getBuffer = function(cb
) {
56 currCallback
= cb
|| config
.callback
;
57 worker
.postMessage({ command: 'getBuffer' })
60 this.exportWAV = function(cb
, type
){
61 currCallback
= cb
|| config
.callback
;
62 type
= type
|| config
.type
|| 'audio/wav';
63 if (!currCallback
) throw new Error('Callback not set');
70 this.shutdown = function(){
73 this.node
.disconnect();
76 worker
.onmessage = function(e
){
81 source
.connect(this.node
);
82 this.node
.connect(this.context
.destination
); //this should not be necessary
85 Recorder
.forceDownload = function(blob
, filename
){
86 var url
= (window
.URL
|| window
.webkitURL
).createObjectURL(blob
);
87 var link
= window
.document
.createElement('a');
89 link
.download
= filename
|| 'output.wav';
90 var click
= document
.createEvent("Event");
91 click
.initEvent("click", true, true);
92 link
.dispatchEvent(click
);
95 window
.Recorder
= Recorder
;