Permalink
Browse files

effect wrapper

  • Loading branch information...
1 parent 181299c commit 665643a87f18763bfb4788295bc72d35dec7ae83 @substack committed Jul 7, 2012
Showing with 63 additions and 0 deletions.
  1. +2 −0 play.js
  2. +59 −0 src/effect.hpp
  3. +2 −0 src/format.cc
View
@@ -1,10 +1,12 @@
var sox = require('./build/Release/format');
var Format = sox.Format;
var Signal = sox.Signal;
+var Effect = sox.Effect;
var fmt = new Format;
fmt.readFile('test.wav');
var sig = new Signal(fmt.getSignal());
var wf = new Format;
+var e = new Effect('input', ['test.wav']);
//wf.play(sig, 'alsa');
wf.play(sig);
View
@@ -0,0 +1,59 @@
+#ifndef NODE_SOX_EFFECT
+#define NODE_SOX_EFFECT
+
+#include <node.h>
+#include <v8.h>
+#include <node_buffer.h>
+
+using namespace v8;
+using namespace node;
+
+#include <sox.h>
+
+class Effect : public ObjectWrap {
+public:
+ static Persistent<FunctionTemplate> constructor_template;
+ sox_effect_t *effect;
+
+ 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("Effect"));
+
+ target->Set(
+ String::NewSymbol("Effect"),
+ constructor_template->GetFunction()
+ );
+ }
+
+ static Handle<Value> New(const Arguments &args) {
+ HandleScope scope;
+ Effect *e = new Effect();
+ String::Utf8Value name(args[0]);
+ e->effect = sox_create_effect(sox_find_effect(*name));
+
+ Local<Array> xs;
+ char * argv[10];
+
+ if (args[1]->IsArray()) {
+ xs = Local<Array>::Cast(args[1]);
+ }
+ else {
+ xs = Array::New();
+ }
+
+ for (unsigned int i = 0; i < 10 && i < xs->Length(); i++) {
+ argv[i] = *String::Utf8Value(xs->Get(Integer::New(i)));
+ }
+
+ sox_effect_options(e->effect, xs->Length(), argv);
+
+ e->Wrap(args.This());
+ return args.This();
+ }
+};
+
+Persistent<FunctionTemplate> Effect::constructor_template;
+
+#endif
View
@@ -10,6 +10,7 @@ using namespace node;
#include <sox.h>
#include "signal.hpp"
+#include "effect.hpp"
class Format : public ObjectWrap {
public:
@@ -116,6 +117,7 @@ void init(Handle<Object> target) {
HandleScope scope;
Format::Initialize(target);
Signal::Initialize(target);
+ Effect::Initialize(target);
}
NODE_MODULE(format, init);

0 comments on commit 665643a

Please sign in to comment.