Skip to content

Commit

Permalink
Merge pull request mattdiamond#6 from thomasboyt/master
Browse files Browse the repository at this point in the history
Add a getBuffer method to get the merged recording buffer
  • Loading branch information
mattdiamond committed Nov 9, 2012
2 parents 996955b + e3f7ebd commit fcc3431
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ This will generate a Blob object containing the recording in WAV format. The cal

In addition, you may specify the type of Blob to be returned (defaults to 'audio/wav').

rec.getBuffer([callback])

This will pass the recorded buffer (as a Float32Array) to the callback. It can be played back by creating a new source buffer and setting this as its channel data (i.e. `newSource.buffer.getChannelData(0).set(recordedBuffer)`).

rec.configure(config)

This will set the configuration for Recorder by passing in a config object.
Expand Down
5 changes: 5 additions & 0 deletions recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
worker.postMessage({ command: 'clear' });
}

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

this.exportWAV = function(cb, type){
currCallback = cb || config.callback;
type = type || config.type || 'audio/wav';
Expand Down
8 changes: 8 additions & 0 deletions recorderWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ this.onmessage = function(e){
case 'exportWAV':
exportWAV(e.data.type);
break;
case 'getBuffer':
getBuffer();
break;
case 'clear':
clear();
break;
Expand All @@ -39,6 +42,11 @@ function exportWAV(type){
this.postMessage(audioBlob);
}

function getBuffer() {
var buffer = mergeBuffers(recBuffers, recLength)
this.postMessage(buffer);
}

function clear(){
recLength = 0;
recBuffers = [];
Expand Down

0 comments on commit fcc3431

Please sign in to comment.