Skip to content

Nodejs native addon to determine capabilities of ALSA audio devices

Notifications You must be signed in to change notification settings

dmooney65/node-alsa-cardinfo

Repository files navigation

node-alsa-cardinfo

A native module using N-API for determining the playback and/or capture capabilities of ALSA audio devices.

Useful when determining which parameters to pass to, for example, arecord or aplay.

This module depends on 'libasound-dev'.

Usage

Install and use as follows:
$ npm install node-alsa-cardinfo --save

Add require statement:
const cardInfo = require('node-alsa-cardinfo');

The addon has a single method which returns an object. e.g.
let info = cardInfo.get('hw:0,0',cardInfo.PLAYBACK);
let info = cardInfo.get('default', 1);
let info = cardInfo.get();

It takes two optional parameters which correspond to the card name (e.g. hw:0,0 or default) and the device direction ( whether the device is a playback or capture device).
The card name will default to hw if not specified and the device direction defaults to playback (0 or cardInfo.PLAYBACK).

Return values

If the device name requested is valid, an object will be returned of the form:

{ deviceType: 'HW',
  accessTypes: [ 'MMAP_INTERLEAVED', 'RW_INTERLEAVED' ],
  sampleFormats: [ 'S16_LE', 'S32_LE' ],
  channels: [ 2, 4, 6, 8 ],
  sampleRates: [ 44100, 48000, 96000, 192000 ] }

For more information on the returned values, consult the alsaaudio documentation.

If there is an error, an object with error and errorDetails properties will be returned, e.g.
{ error: 'cannot open device: hw:0,0 - Device or resource busy',
   errorDetails: 'pcm_hw.c:1590(snd_pcm_hw_open) open \'hw:0,0\' failed (16)' }

About

Nodejs native addon to determine capabilities of ALSA audio devices

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published