Permalink
Browse files

separate signal source file, writeFile

  • Loading branch information...
1 parent 5b5eecd commit 73aa1d7570c7ac78fc50b9c036ccf1834503550a @substack committed Jul 6, 2012
Showing with 95 additions and 2 deletions.
  1. +38 −2 src/format.cc
  2. +57 −0 src/signal.cc
View
@@ -1,3 +1,6 @@
+#ifndef NODE_SOX_FORMAT
+#define NODE_SOX_FORMAT
+
#include <node.h>
#include <v8.h>
#include <node_buffer.h>
@@ -6,6 +9,7 @@ using namespace v8;
using namespace node;
#include <sox.h>
+#include "signal.cc"
class Format : public ObjectWrap {
public:
@@ -18,7 +22,15 @@ class Format : public ObjectWrap {
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Format"));
- NODE_SET_PROTOTYPE_METHOD(constructor_template, "openRead", OpenRead);
+ NODE_SET_PROTOTYPE_METHOD(
+ constructor_template, "readFile", ReadFile
+ );
+ NODE_SET_PROTOTYPE_METHOD(
+ constructor_template, "writeFile", WriteFile
+ );
+ NODE_SET_PROTOTYPE_METHOD(
+ constructor_template, "memstreamWrite", MemstreamWrite
+ );
target->Set(
String::NewSymbol("Format"),
@@ -33,7 +45,7 @@ class Format : public ObjectWrap {
return args.This();
}
- static Handle<Value> OpenRead(const Arguments &args) {
+ static Handle<Value> ReadFile(const Arguments &args) {
HandleScope scope;
Format *fmt = ObjectWrap::Unwrap<Format>(args.This());
String::Utf8Value path(args[0]);
@@ -42,13 +54,37 @@ class Format : public ObjectWrap {
return Undefined();
}
+
+ static Handle<Value> WriteFile(const Arguments &args) {
+ HandleScope scope;
+ Format *fmt = ObjectWrap::Unwrap<Format>(args.This());
+
+ String::Utf8Value path(args[0]);
+ Signal *signal = ObjectWrap::Unwrap<Signal>(
+ Handle<Object>::Cast(args[1])
+ );
+
+ fmt->format = sox_open_write(
+ *path, signal->signal, NULL, NULL, NULL, NULL
+ );
+ fmt->Ref();
+
+ return Undefined();
+ }
+
+ static Handle<Value> MemstreamWrite (const Arguments &args) {
+ return Undefined();
+ }
};
Persistent<FunctionTemplate> Format::constructor_template;
void init(Handle<Object> target) {
HandleScope scope;
Format::Initialize(target);
+ Signal::Initialize(target);
}
NODE_MODULE(format, init);
+
+#endif
View
@@ -0,0 +1,57 @@
+#ifndef NODE_SOX_SIGNAL
+#define NODE_SOX_SIGNAL
+
+#include <node.h>
+#include <v8.h>
+#include <node_buffer.h>
+
+using namespace v8;
+using namespace node;
+
+#include <sox.h>
+
+class Signal : public ObjectWrap {
+public:
+ static Persistent<FunctionTemplate> constructor_template;
+ sox_signalinfo_t *signal;
+
+ static void Initialize (Handle<Object> target) {
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
+ constructor_template = Persistent<FunctionTemplate>::New(t);
+ constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor_template->SetClassName(String::NewSymbol("Signal"));
+
+ target->Set(
+ String::NewSymbol("Signal"),
+ constructor_template->GetFunction()
+ );
+ }
+
+ static Handle<Value> New(const Arguments &args) {
+ HandleScope scope;
+ 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();
+
+ if (args[4]->IsUndefined()) {
+ sig->signal->mult = NULL;
+ }
+ else {
+ double * mult = (double *) malloc(sizeof(double));
+ *mult = args[4]->NumberValue();
+ sig->signal->mult = mult;
+ }
+
+ sig->Wrap(args.This());
+ return args.This();
+ }
+
+};
+
+Persistent<FunctionTemplate> Signal::constructor_template;
+
+#endif

0 comments on commit 73aa1d7

Please sign in to comment.