From 8df458e5eeb44d43b991cb29c36325701903f4f7 Mon Sep 17 00:00:00 2001 From: bcaller Date: Tue, 29 Jul 2014 18:06:03 +0100 Subject: [PATCH 1/2] Add getAudioBuffer(cb, [optional: context]) --- recorder.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/recorder.js b/recorder.js index 52f3d0cd..63b67005 100644 --- a/recorder.js +++ b/recorder.js @@ -54,6 +54,16 @@ currCallback = cb || config.callback; worker.postMessage({ command: 'getBuffer' }) } + + this.getAudioBuffer = function (cb, context) { + var ctx = context || this.context + this.getBuffer(function (buffers) { + var newBuffer = ctx.createBuffer(2, buffers[0].length, ctx.sampleRate); + newBuffer.getChannelData(0).set(buffers[0]); + newBuffer.getChannelData(1).set(buffers[1]); + cb(newBuffer) + }) + } this.exportWAV = function(cb, type){ currCallback = cb || config.callback; From 7e00f4821a7087e1aa7536ece3571d282349ddf0 Mon Sep 17 00:00:00 2001 From: bcaller Date: Tue, 29 Jul 2014 18:12:22 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3830a91d..5e6f55c0 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,21 @@ This will pass the recorded stereo buffer (as an array of two Float32Arrays, for } This sample code will play back the stereo buffer. +More simply: + + rec.getAudioBuffer([callback]) + +This will pass the recorded AudioBuffer to the callback. + + function getAudioBufferCallback( buffer ) { + var newSource = audioContext.createBufferSource(); + newSource.buffer = newBuffer; + newSource.connect( audioContext.destination ); + newSource.start(0); + } + +This sample code will also play back the stereo buffer. + rec.configure(config) @@ -73,4 +88,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.