/node-portaudio

Node.js wrapper around PortAudio

Primary LanguageCApache License 2.0Apache-2.0

node-portaudio

Node.js wrapper around PortAudio.

This library is a (lot more messy) fork of naudiodon (itself a fork of node-portaudio), with the following modifications:

  • Changing the stream model to a pull model with double buffering, this change intends to provide a more responsive environment and a better clock stability for real-time usages;
  • Updating from Nan to N-API API.

Unless you really need this features (aka most of the time) please use naudiodon or similar stream-based library

Installation

warning: not on npm yet, install from github:

npm install [--save] b-ma/node-portaudio

Example

const portaudio = require('node-portaudio');

// retrieve the list of devices
console.log(portaudio.getDevices());

// do some synthesis
const frequency = 400;
const sampleRate = 44100;
let phase = 0;

function sine(output, frameSize, channelCount) {
  for (let i = 0; i < frameSize; i++) {
    output[i] = Math.sin(phase * Math.PI * 2);
    phase = (phase + frequency / sampleRate) % 1;
  }
}

portaudio.output.configure({
  sampleRate: sampleRate,
  channelCount: 1,
  process: (output, framesPerBuffer, channelCount) => {
    sine(output, framesPerBuffer, channelCount);
  }
});
// start audio rendering
portaudio.output.start();
// stop audio rendering
setTimeout(() => portaudio.output.stop(), 3000);

@todo

  • figure out what happens with stereo output
  • implement non interleaved mode
  • implement input

License

BSD-3-Clause