Skip to content

Commit

Permalink
Update documentation and comments
Browse files Browse the repository at this point in the history
Get it ready for a pull request.
  • Loading branch information
mayppong committed Nov 14, 2014
1 parent 211c62d commit 265d3cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.swp
.DS-Store
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Creates a recorder instance.

- **workerPath** - Path to recorder.js worker script. Defaults to 'js/recorderjs/recorderWorker.js'
- **bufferLen** - The length of the buffer that the internal JavaScriptNode uses to capture the audio. Can be tweaked if experiencing performance issues. Defaults to 4096.
- **callback** - A default callback to be used with `exportWAV`.
- **type** - The type of the Blob generated by `exportWAV`. Defaults to 'audio/wav'.
- **callback** - A default callback to be used with `exportAudio`.
- **type** - The type of the Blob generated by `exportAudio`. Defaults to 'audio/wav'.

---------
#### Instance Methods
Expand All @@ -31,7 +31,7 @@ Pretty self-explanatory... **record** will begin capturing audio and **stop** wi

This will clear the recording.

rec.exportWAV([callback][, type])
rec.exportAudio([callback][, type])

This will generate a Blob object containing the recording in WAV format. The callback will be called with the Blob as its sole argument. If a callback is not specified, the default callback (as defined in the config) will be used. If no default has been set, an error will be thrown.

Expand Down
10 changes: 10 additions & 0 deletions recorderWorkerMP3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ this.onmessage = function(e) {
}
};

// The initilization default sample rate of the input audio at 44k
// and scaled it down to 22k output. Not sure why this is necessary but is
// needed for the sound to come out right.
// The channels is set to mono and listenning to channel 1 which is the left channel.
// There is some problem with stereo channel support.
function init(config) {
if (!config) {
config = {};
Expand All @@ -43,6 +48,9 @@ function record(buffer) {
recLength += mp3data.data.length;
}

// Similar to the original exportWAV, it grabs the mp3 data from Lame encoder
// object and build an mp3 blob with it.
// When done, it posts the audio blob message to the worker.
function exportAudio() {
var mp3data = Lame.encode_flush(mp3codec);

Expand All @@ -59,6 +67,8 @@ function exportAudio() {
this.postMessage(audioBlob);
}

// Close the Lame encoder object stream, empty out the data in buffer and
// reset the buffer length stored.
function clear() {
Lame.close(mp3codec);
mp3codec = null;
Expand Down

0 comments on commit 265d3cc

Please sign in to comment.