Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

getSignal() works after reading a file

  • Loading branch information...
commit 51bbe53a573e9547f4b2a86aecd24af41e473f84 1 parent 73aa1d7
@substack authored
Showing with 39 additions and 10 deletions.
  1. +2 −1  binding.gyp
  2. +9 −0 src/format.cc
  3. +28 −9 src/signal.cc
View
3  binding.gyp
@@ -8,7 +8,8 @@
{
"target_name": "format",
"sources": [ "src/format.cc" ],
- "libraries" : [ "-lsox" ]
+ "libraries" : [ "-lsox" ],
+ "include_dirs" : [ "src" ]
}
]
}
View
9 src/format.cc
@@ -26,6 +26,9 @@ class Format : public ObjectWrap {
constructor_template, "readFile", ReadFile
);
NODE_SET_PROTOTYPE_METHOD(
+ constructor_template, "getSignal", GetSignal
+ );
+ NODE_SET_PROTOTYPE_METHOD(
constructor_template, "writeFile", WriteFile
);
NODE_SET_PROTOTYPE_METHOD(
@@ -55,6 +58,12 @@ class Format : public ObjectWrap {
return Undefined();
}
+ static Handle<Value> GetSignal(const Arguments &args) {
+ HandleScope scope;
+ Format *fmt = ObjectWrap::Unwrap<Format>(args.This());
+ return Signal::Properties(fmt->format->signal);
+ }
+
static Handle<Value> WriteFile(const Arguments &args) {
HandleScope scope;
Format *fmt = ObjectWrap::Unwrap<Format>(args.This());
View
37 src/signal.cc
@@ -32,17 +32,21 @@ class Signal : public ObjectWrap {
Signal *sig = new Signal();
sig->signal = (sox_signalinfo_t *) malloc(sizeof(sox_signalinfo_t));
- sig->signal->rate = (double) args[0]->NumberValue();
- sig->signal->channels = (unsigned) args[1]->Int32Value();
- sig->signal->precision = (unsigned) args[2]->Int32Value();
- sig->signal->length = (size_t) args[3]->Int32Value();
+ Handle<Object> opts = Handle<Object>::Cast(args[0]);
- if (args[4]->IsUndefined()) {
- sig->signal->mult = NULL;
- }
- else {
+ sig->signal->rate = (double)
+ opts->Get(String::NewSymbol("rate"))->NumberValue();
+ sig->signal->channels = (unsigned)
+ opts->Get(String::NewSymbol("channels"))->Int32Value();
+ sig->signal->precision = (unsigned)
+ opts->Get(String::NewSymbol("precision"))->Int32Value();
+ sig->signal->length = (size_t)
+ opts->Get(String::NewSymbol("length"))->Int32Value();
+
+ sig->signal->mult = NULL;
+ if (!opts->Get(String::NewSymbol("mult"))->IsUndefined()) {
double * mult = (double *) malloc(sizeof(double));
- *mult = args[4]->NumberValue();
+ *mult = opts->Get(String::NewSymbol("mult"))->NumberValue();
sig->signal->mult = mult;
}
@@ -50,6 +54,21 @@ class Signal : public ObjectWrap {
return args.This();
}
+ static Handle<Value> Properties(sox_signalinfo_t sig) {
+ Handle<Object> target = Object::New();
+ target->Set(String::NewSymbol("rate"), Number::New(sig.rate));
+ target->Set(String::NewSymbol("channels"), Int32::New(sig.channels));
+ target->Set(String::NewSymbol("precision"), Int32::New(sig.precision));
+ target->Set(String::NewSymbol("length"), Int32::New(sig.length));
+
+ if (sig.mult == NULL) {
+ target->Set(String::NewSymbol("mult"), Undefined());
+ }
+ else {
+ target->Set(String::NewSymbol("mult"), Number::New(*sig.mult));
+ }
+ return target;
+ }
};
Persistent<FunctionTemplate> Signal::constructor_template;
Please sign in to comment.
Something went wrong with that request. Please try again.