百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

node-core-audio

> 编程语言
开源

PortAudio 的绑定,使 JavaScript 可以访问声卡采样(大部分不维护)

339 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

PortAudio 的绑定,使 JavaScript 可以访问声卡采样(大部分不维护)

Node Core Audio

A C++ extension for node.js that gives javascript access to audio buffers and basic audio processing functionality

Right now, it's basically a node.js binding for PortAudio.

NOTE: Looking for help maintaining this repository!

Active contributors:

  • rmedaer

Installation

bash
npm install node-core-audio

Basic Usage

Below is the most basic use of the audio engine. We create a new instance of node-core-audio, and then give it our processing function. The audio engine will call the audio callback whenever it needs an output buffer to send to the sound card.

…

// Alternatively, you can read/write samples to the sound card manually

javascript
var engine = coreAudio.createNewAudioEngine();

// Grab a buffer
var buffer = engine.read();

// Silence the 0th channel
for( var iSample=0; iSample<inputBuffer[0].length; ++iSample )
	buffer[0][iSample] = 0.0;

// Send the buffer back to the sound card
engine.write( buffer );

Important! Processing Thread

When you are writing code inside of your audio callback, you are operating on the processing thread of the application. This high priority environment means you should try to think about performance as much as possible. Allocations and other complex operations are possible, but dangerous.

IF YOU TAKE TOO LONG TO RETURN A BUFFER TO THE SOUND CARD, YOU WILL HAVE AUDIO DROPOUTS

The basic principle is that you should have everything ready to go before you enter the processing function. Buffers, objects, and functions should be created in a constructor or static function outside of the audio callback whenever possible. The examples in this readme are not necessarily good practice as far as performance is concerned.

The callback is only called if all buffers has been processed by the soundcard.

Audio Engine Options

  • sampleRate [default 44100]
    • Sample rate - number of samples per second in the audio stream
  • sampleFormat [default sampleFormatFloat32]
    • Bit depth - Number of bits used to represent sample values
    • formats are sampleFormatFloat32, sampleFormatInt32, sampleFormatInt24, sampleFormatInt16, sampleFormatInt8, sampleFormatUInt8.
  • framesPerBuffer [default 256]
    • Buffer length - Number of samples per buffer
  • interleaved [default false]
    • Interleaved / Deinterleaved - determines whether samples are given to you as a two dimensional array (buffer[channel][sample]) (deinterleaved) or one buffer with samples from alternating channels (interleaved).
  • inputChannels [default 2]
    • Input channels - number of input channels
  • outputChannels [default 2]
    • Output channels - number of output channels
  • inputDevice [default to Pa_GetDefaultInputDevice]
    • Input device - id of the input device
  • outputDevice [default to Pa_GetDefaultOutputDevice]
    • Output device - id of the output device

API

First things first

javascript
var coreAudio = require("node-core-audio");

Create and audio processing function

javascript
function processAudio( inputBuffer ) {
    // Just print the value of the first sample on the left channel
    console.log( inputBuffer[0][0] );
}

Initialize the audio engine and setup the processing loop

javascript
var engine = coreAudio.createNewAudioEngine();

engine.addAudioCallback( processAudio );

General functionality

…

Known Issues / TODO

  • Add FFTW to C++ extension, so you can get fast FFT's from javascript, and also register for the FFT of incoming audio, rather than the audio itself
  • Add support for streaming audio over sockets

License

MIT - See LICENSE file.

Copyright Mike Vegeto, 2013

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言