Permalink
Browse files

write to outfiles

  • Loading branch information...
1 parent 31b22e4 commit 9d754998c99ad2758452d9f80b66309024f2a5f9 @substack committed Jun 4, 2012
Showing with 18 additions and 3 deletions.
  1. +15 −1 sox.cc
  2. +3 −2 test.js
View
16 sox.cc
@@ -9,6 +9,12 @@ using namespace node;
#include <sox.h>
#include <assert.h>
+#include <string>
+
+static inline std::string SaveString(const v8::Handle<v8::Value>& value) {
+ v8::String::Utf8Value v(value);
+ return std::string(*v, v.length());
+}
struct node_sox_request {
sox_format_t *in, *out;
@@ -84,7 +90,15 @@ class Player : public ObjectWrap {
opts->Get(String::NewSymbol("ondata"))
);
- if (ondata_->IsUndefined()) {
+ Local<Value> outfile = opts->Get(String::NewSymbol("outfile"));
+
+ if (!outfile->IsUndefined()) {
+ out = sox_open_write(
+ SaveString(outfile).c_str(),
+ &in->signal, NULL, NULL, NULL, NULL
+ );
+ }
+ else if (ondata_->IsUndefined()) {
out = sox_open_write(
"default", &in->signal, NULL, "alsa", NULL, NULL
);
View
@@ -1,13 +1,14 @@
var Player = require('./build/Release/sox').Player;
-var fs = require('fs');
-var ws = fs.createWriteStream('out.wav');
var player = new Player;
player.play({
+ outfile : 'woo.wav',
+ /*
ondata : function (buf) {
console.log(buf.length);
ws.write(buf);
},
+ */
onend : function () {
console.log('end');
ws.end();

0 comments on commit 9d75499

Please sign in to comment.