Giter Site home page Giter Site logo

node-portaudio's Introduction

portaudio

Node wrapper around PortAudio

Note: This module has not been tested on windows. If you would like to submit a pull request that would be great.

Note: You must install PortAudio libs first.

Example

var portAudio = require('portaudio');

// create a sine wave lookup table
var sampleRate = 44100;
var tableSize = 200;
var buffer = new Buffer(tableSize);
for (var i = 0; i < tableSize; i++) {
  buffer[i] = (Math.sin((i / tableSize) * 3.1415 * 2.0) * 127) + 127;
}

portAudio.getDevices(function(err, devices) {
  console.log(devices);
});

portAudio.open({
  channelCount: 1,
  sampleFormat: portAudio.SampleFormat8Bit,
  sampleRate: sampleRate
}, function (err, pa) {
  // send samples to be played
  for (var i = 0; i < 5 * sampleRate / tableSize; i++) {
    pa.write(buffer);
  }

  // start playing
  pa.start();

  // stop playing 1 second later
  setTimeout(function () {
    pa.stop();
  }, 1 * 1000);
});

Troubleshooting

error: 'PaStreamCallbackFlags' has not been declared

Try installing "libasound-dev" package. See (http://portaudio.com/docs/v19-doxydocs/compile_linux.html). Then try rebuilding.

If that doesn't fix it try building and installing portaudio from source (http://www.portaudio.com/download.html). I've compiled node-portaudio with pa_stable_v19_20111121.tgz and was successful on Ubunutu.

No Default Device Found

Ensure that when you compile portaudio that the configure scripts says "ALSA" yes.

node-portaudio's People

Contributors

joeferner avatar pabiagioli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-portaudio's Issues

another compile failure

tony@moguya ~/src/node-portaudio(master)$ node-gyp configure build
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn python2
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/tony/src/node-portaudio/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/tony/.node-gyp/0.12.7/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/tony/.node-gyp/0.12.7',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/tony/src/node-portaudio',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/portAudio/src/binding.o
In file included from ../src/binding.cpp:2:
../src/nodePortAudio.h:7:34: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
v8::Handle<v8::Value> Open(const v8::Arguments& args);
                                 ^~~~~~~~~~~~~
                                 v8::internal::Arguments
/Users/tony/.node-gyp/0.12.7/deps/v8/include/v8.h:127:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
In file included from ../src/binding.cpp:2:
../src/nodePortAudio.h:8:40: error: no type named 'Arguments' in namespace 'v8'; did you mean 'v8::internal::Arguments'?
v8::Handle<v8::Value> GetDevices(const v8::Arguments& args);
                                       ^~~~~~~~~~~~~
                                       v8::internal::Arguments
/Users/tony/.node-gyp/0.12.7/deps/v8/include/v8.h:127:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/binding.cpp:7:21: error: calling a protected constructor of class 'v8::HandleScope'
    v8::HandleScope scope;
                    ^
/Users/tony/.node-gyp/0.12.7/deps/v8/include/v8.h:816:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/binding.cpp:8:5: error: no matching function for call to 'NODE_SET_METHOD'
    NODE_SET_METHOD(target, "open", Open);
    ^~~~~~~~~~~~~~~
/Users/tony/.node-gyp/0.12.7/src/node.h:240:25: note: expanded from macro 'NODE_SET_METHOD'
#define NODE_SET_METHOD node::NODE_SET_METHOD
                        ^~~~~~~~~~~~~~~~~~~~~
/Users/tony/.node-gyp/0.12.7/src/node.h:228:13: note: candidate function [with TypeName = v8::Handle<v8::Object>] not viable: no known conversion from
      'v8::Handle<v8::Value> (const v8::internal::Arguments &)' to 'v8::FunctionCallback' (aka 'void (*)(const FunctionCallbackInfo<v8::Value> &)') for 3rd argument
inline void NODE_SET_METHOD(const TypeName& recv,
            ^
../src/binding.cpp:9:5: error: no matching function for call to 'NODE_SET_METHOD'
    NODE_SET_METHOD(target, "getDevices", GetDevices);
    ^~~~~~~~~~~~~~~
/Users/tony/.node-gyp/0.12.7/src/node.h:240:25: note: expanded from macro 'NODE_SET_METHOD'
#define NODE_SET_METHOD node::NODE_SET_METHOD
                        ^~~~~~~~~~~~~~~~~~~~~
/Users/tony/.node-gyp/0.12.7/src/node.h:228:13: note: candidate function [with TypeName = v8::Handle<v8::Object>] not viable: no known conversion from
      'v8::Handle<v8::Value> (const v8::internal::Arguments &)' to 'v8::FunctionCallback' (aka 'void (*)(const FunctionCallbackInfo<v8::Value> &)') for 3rd argument
inline void NODE_SET_METHOD(const TypeName& recv,
            ^
5 errors generated.
make: *** [Release/obj.target/portAudio/src/binding.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Darwin 14.5.0
gyp ERR! command "node" "/usr/local/bin/node-gyp" "configure" "build"
gyp ERR! cwd /Users/tony/src/node-portaudio
gyp ERR! node -v v0.12.7
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok 

Way to install portaudio as a dependency

As it is for now, you have to install portaudio lib as a standalone before using this module but lets say I want to wrap an app with electron and sell it. We shouldn't ask the client to install portaudio. Dependency should already be included.

Failed to compile

The library failed to compile on my ubuntu 12.10. I got the following message : http://pastebin.com/dqH7W8ZL

I don't think I miss any of the portaudio packages needed (I've installed pretty much everything, dev library and so on ...)

Only beeps and boops

Hello,
I'm currently writing bindings for the libspotify C library for node.js and I wanted to use node-portaudio to actually play the music.
It seems that, whatever I'm writing to the portaudio "stream", it only plays a beeping sound.
I'm writing raw PCM data (signed 16 bits, 2 channels, 44100Hz) if that helps.
The beeping changes slightly if I'm writing some other piece of audio data. So my first guess is that portaudio is playing the same buffer over and over but I'm not familiar enough with the code to check about this myself

Thanks

reading from system audio?

howdy! it looks like the portaudio support in nort-portaudio is for writing, not reading.

true?

if so, what's the thinking on that? i'm in the process of writing a simple node.js server that takes the system audio from my mac and makes it available to a sonos in other room, so i think being able to read audio would be handy as well?

what's your thinking? thanks!

uv_work_t and uv_after_work_cb: compatibility with node >= 0.9.4

This is the issue:

node-gyp build configure
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory `/home/pablo/fic/portaudio-node/repo/build'
  CXX(target) Release/obj.target/portAudio/src/nodePortAudio.o
../src/nodePortAudio.cpp: In function ‘int nodePortAudioCallback(const void*, void*, long unsigned int, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void*)’:
../src/nodePortAudio.cpp:352:84: error: invalid conversion from ‘void (*)(uv_work_t*) {aka void (*)(uv_work_s*)}’ to ‘uv_after_work_cb {aka void (*)(uv_work_s*, int)}’ [-fpermissive]
In file included from /home/pablo/.node-gyp/0.10.15/src/node.h:61:0,
                 from ../src/nodePortAudio.h:2,
                 from ../src/nodePortAudio.cpp:2:
/home/pablo/.node-gyp/0.10.15/deps/uv/include/uv.h:1432:15: error:   initializing argument 4 of ‘int uv_queue_work(uv_loop_t*, uv_work_t*, uv_work_cb, uv_after_work_cb)’ [-fpermissive]

There's been some changes in Node since 0.8
Here's the code for compatibility with newer node apis

https://github.com/joyent/node/wiki/Api-changes-between-v0.8-and-v0.10

The uv_after_work_cb signature has changed to take a second integer argument indicating status. For backwards compatibility, explicitly cast the 4th argument to uv_queue_work

This is the example:
node-ffi/node-ffi@fdeff41

I think that changing the call like there fixes it

regards

Capturing audio input

I see in your Open function you have:

 err = Pa_OpenStream(
    &data->stream,
    NULL, // no input
    &outputParameters,
    sampleRate,
    FRAMES_PER_BUFFER,
    paClipOff, // we won't output out of range samples so don't bother clipping them
    nodePortAudioCallback,
    data);

Am I to understand that doing the reverse (e.g. Pa_OpenStream(NULL, &data->stream, ...)) would enable capturing from a system microphone? I would be interested in extending this project if that was the case, I'm new to portaudio and trying to figure out how to capture and play PCM data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.