Permalink
Browse files

play files

  • Loading branch information...
1 parent 51bbe53 commit 2c68752e46cfa6a8693b8b3158a19083bc478bfd @substack committed Jul 6, 2012
Showing with 33 additions and 0 deletions.
  1. +9 −0 play.js
  2. +24 −0 src/format.cc
View
9 play.js
@@ -0,0 +1,9 @@
+var sox = require('./build/Release/format');
+var Format = sox.Format;
+var Signal = sox.Signal;
+
+var fmt = new Format;
+fmt.readFile('test.wav');
+var sig = new Signal(fmt.getSignal());
+var wf = new Format;
+wf.play(sig, 'alsa');
View
24 src/format.cc
@@ -31,6 +31,7 @@ class Format : public ObjectWrap {
NODE_SET_PROTOTYPE_METHOD(
constructor_template, "writeFile", WriteFile
);
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "play", Play);
NODE_SET_PROTOTYPE_METHOD(
constructor_template, "memstreamWrite", MemstreamWrite
);
@@ -81,6 +82,29 @@ class Format : public ObjectWrap {
return Undefined();
}
+ static Handle<Value> Play(const Arguments &args) {
+ HandleScope scope;
+ Format *fmt = ObjectWrap::Unwrap<Format>(args.This());
+
+ Signal *signal = ObjectWrap::Unwrap<Signal>(
+ Handle<Object>::Cast(args[0])
+ );
+ const char * dev;
+ if (args[1]->IsUndefined()) {
+ dev = "alsa";
+ }
+ else {
+ dev = *String::Utf8Value(args[1]);
+ }
+
+ fmt->format = sox_open_write(
+ "default", signal->signal, NULL, dev, NULL, NULL
+ );
+ fmt->Ref();
+
+ return Undefined();
+ }
+
static Handle<Value> MemstreamWrite (const Arguments &args) {
return Undefined();
}

0 comments on commit 2c68752

Please sign in to comment.