Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 8e946eb
Author: Simon Rogers <[email protected]>
Date:   Thu Jun 13 12:11:47 2019 +0200

    v2.1.0

commit 8b63203
Author: Simon Rogers <[email protected]>
Date:   Thu Jun 13 12:08:24 2019 +0200

    Streampunk#32 Add support for 32-bit floating point audio streams

commit c027bb3
Author: Simon Rogers <[email protected]>
Date:   Wed May 1 13:54:39 2019 +0200

    Streampunk#29 Fix arm build

commit a93d21c
Author: Simon Rogers <[email protected]>
Date:   Wed May 1 13:52:25 2019 +0200

    Ignore vscode

commit fbccbdb
Merge: 10fe4b3 af34acd
Author: Simon Rogers <[email protected]>
Date:   Thu Apr 11 10:42:16 2019 +0200

    Merge pull request Streampunk#26 from rpahle/master

    fixing config for highwaterMark

commit af34acd
Author: Robert Pahle <[email protected]>
Date:   Wed Apr 10 15:43:52 2019 -0400

    fixing config for highwaterMark

commit 10fe4b3
Author: Simon Rogers <[email protected]>
Date:   Thu Feb 21 18:10:31 2019 +0100

    v2.0.3

commit b8761ac
Merge: 8fcf870 4960ee1
Author: Simon Rogers <[email protected]>
Date:   Thu Feb 21 18:09:01 2019 +0100

    Merge pull request Streampunk#24 from SoTrxII/master

    Correcting a really tiny typo in the include directives

commit 4960ee1
Author: Lucas <[email protected]>
Date:   Thu Feb 21 17:58:54 2019 +0100

    Correcting a really tiny typo in the include directives

commit 8fcf870
Author: Simon Rogers <[email protected]>
Date:   Thu Feb 21 11:37:46 2019 +0100

    v2.0.2

commit 1cafcc9
Author: Simon Rogers <[email protected]>
Date:   Thu Feb 21 11:36:11 2019 +0100

    Add binding for Pa_GetHostApiInfo. Streampunk#23

commit 75c0b48
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 19 12:02:55 2019 +0100

    V2.0.1

commit 66c4180
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 19 12:02:07 2019 +0100

    Fix compile errors - issue Streampunk#22

commit dace615
Merge: 6d0c60f b77d5fd
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 15:35:34 2019 +0100

    Merge pull request Streampunk#21 from Streampunk/napi

commit b77d5fd
Merge: 673235c 6d0c60f
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 15:34:07 2019 +0100

    Merge branch 'master' into napi

commit 673235c
Merge: d4b1166 41b3795
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 15:31:52 2019 +0100

    Update for merge

commit 6d0c60f
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 14:51:08 2019 +0100

    v1.0.0

commit d4b1166
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 14:25:59 2019 +0100

    Update copyright year

commit c59e368
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 14:19:55 2019 +0100

    Small documentation improvements

commit 820ea51
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 12:18:35 2019 +0100

    Add missing status flags

commit 430b0d3
Author: Simon Rogers <[email protected]>
Date:   Mon Feb 18 12:10:26 2019 +0100

    Refactor to use a common AudioIO object for in, out and duplex

commit 9e9c3ab
Author: Simon Rogers <[email protected]>
Date:   Fri Feb 15 17:37:07 2019 +0100

    Check for null

commit 6423fd8
Author: Simon Rogers <[email protected]>
Date:   Fri Feb 15 17:19:28 2019 +0100

    Update to use event to start recording - addresses Issue Streampunk#20

commit 69872b3
Author: Simon Rogers <[email protected]>
Date:   Fri Feb 15 17:17:24 2019 +0100

    Add abort function

commit 4720281
Author: Simon Rogers <[email protected]>
Date:   Fri Feb 15 12:26:48 2019 +0100

    Refactor to add support for full duplex (bi-directional) PortAudio devices

commit 81fe268
Author: Simon Rogers <[email protected]>
Date:   Thu Feb 14 14:28:18 2019 +0100

    Brought up-to-date with latest napi wrapper, improved and simplified error and quit handling

commit 9820f0b
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 13:01:20 2019 +0100

    Visual Studio Code configuration

commit eb3116a
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 13:00:34 2019 +0100

    Improve quit logic

commit 12232eb
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 12:59:50 2019 +0100

    Print version string at startup

commit ecbbc97
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 12:58:58 2019 +0100

    Add segfault-handler, end and error handling for AudioInput

commit ea277f8
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 12:57:28 2019 +0100

    Fix spacing

commit a7d6e5c
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 12:56:32 2019 +0100

    Clearer about node-gyp

commit ed52089
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 12:55:16 2019 +0100

    Updated, add segfault-handler

commit b21bdc2
Author: Simon Rogers <[email protected]>
Date:   Tue Feb 12 12:53:45 2019 +0100

    Update PortAudio to recommended version: pa_stable_v190600_20161030

commit 6c4fb63
Merge: 4c63fa6 1bf376f
Author: Simon Rogers <[email protected]>
Date:   Wed Nov 29 15:54:59 2017 +0100

    Merge pull request Streampunk#9 from scriptorian/napi

    Ported to use N-API

commit 1bf376f
Author: Simon Rogers <[email protected]>
Date:   Wed Nov 29 15:50:54 2017 +0100

    Ported to use N-API
  • Loading branch information
zschreur committed Nov 21, 2019
1 parent 63cf3c1 commit 1627f90
Show file tree
Hide file tree
Showing 34 changed files with 1,345 additions and 1,228 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.idea
/build
/node_modules
/.vscode
test.wav
rawAudio.raw
81 changes: 81 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/atlmfc/include/*",
"C:/Program Files (x86)/Windows Kits/8.1/Include/um",
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt",
"C:/Program Files (x86)/Windows Kits/8.1/Include/shared",
"C:/Program Files (x86)/Windows Kits/8.1/Include/winrt",
"${workspaceRoot}",
"${workspaceRoot}/node_modules/node-addon-api",
"${workspaceRoot}/node_modules/node-addon-api/external-napi",
"${workspaceRoot}/portaudio/include"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/atlmfc/include/*",
"C:/Program Files (x86)/Windows Kits/8.1/Include/um",
"C:/Program Files (x86)/Windows Kits/8.1/Include/shared",
"C:/Program Files (x86)/Windows Kits/8.1/Include/winrt",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
55 changes: 55 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"files.associations": {
"functional": "cpp",
"memory": "cpp",
"istream": "cpp",
"chrono": "cpp",
"ratio": "cpp",
"system_error": "cpp",
"type_traits": "cpp",
"xfunctional": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xlocale": "cpp",
"xstring": "cpp",
"xutility": "cpp",
"algorithm": "cpp",
"cmath": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"deque": "cpp",
"exception": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"limits": "cpp",
"map": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"queue": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"thread": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xmemory0": "cpp",
"xtree": "cpp"
}
}
96 changes: 70 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A [Node.js](http://nodejs.org/) [addon](http://nodejs.org/api/addons.html) that
This is a fork of [node-portaudio](/joeferner/node-portaudio), refactored by:

* changing from an event model to a stream model;
* linking to the v8 libraries through the [Native Abstractions for Node.js (NAN)](/nodejs/nan) library to enable more portability between node versions.
* using the new API for building native Addons [N-API](https://nodejs.org/dist/latest-v8.x/docs/api/n-api.html#n_api_n_api) to enable portability between node versions without recompiling.
* adding in local copies of libraries so that portaudio does not have to be installed preemptively.

Little of the original remains but I am very grateful for Joe Ferner for the inspiration and framework to get started.
Expand All @@ -16,11 +16,11 @@ Note: This is a server side library. It is not intended as a means to play and r

## Installation

Install [Node.js](http://nodejs.org/) for your platform and make sure that node is able to build native modules with [node-gyp](https://github.com/nodejs/node-gyp). This software has been developed against the long term stable (LTS) release. For ease of installation with other node packages, this package includes a copy of the dependent PortAudio library and so has no prerequisites.
Install [Node.js](http://nodejs.org/) for your platform and make sure that node is able to build native modules with [node-gyp](https://github.com/nodejs/node-gyp). This software has been developed against the long term stable (LTS) release. For ease of installation with other node packages, this package includes a copy of the dependent PortAudio library and so has no prerequisites.

Naudiodon is designed to be `require`d to use from your own application to provide async processing. For example:

npm install --save naudiodon
npm install naudiodon

For Raspberry Pi users, please note that this library is not intended for use with the internal sound card. Please use an external USB sound card or GPIO breakout board such as the [_Pi-DAC+ Full-HD Audio Card_](https://www.modmypi.com/raspberry-pi/breakout-boards/iqaudio/pi-dac-plus-full-hd-audio-card/?tag=pi-dac).

Expand Down Expand Up @@ -73,56 +73,74 @@ An example of the output is:

Note that the device `id` parameter index value can be used as to specify which device to use for playback or recording with optional parameter `deviceId`.

### Listing host APIs

To get list of host APIs, call the `getHostAPIs()` function.

```javascript
var portAudio = require('naudiodon');

console.log(portAudio.getHostAPIs());
```
An example of the output is:

```javascript
{ defaultHostAPI: 0,
HostAPIs:
[ { id: 0,
name: 'MME',
deviceCount: 8,
defaultInput: 1,
defaultOutput: 5 },
{ /* ... */ } ] }
```
Note that the `defaultInput` and `defaultOutput` values can be used as to specify which device to use for playback or recording with optional parameter `deviceId`.

### Playing audio

Playing audio involves streaming audio data to an instance of `AudioOutput`.
Playing audio involves streaming audio data to a new instance of `AudioIO` configured with `outOptions` - which returns a Node.js [Writable Stream](https://nodejs.org/dist/latest-v6.x/docs/api/stream.html#stream_writable_streams):

```javascript
const fs = require('fs');
const portAudio = require('naudiodon');

// Create an instance of AudioOutput, which is a WriteableStream
var ao = new portAudio.AudioOutput({
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 48000,
deviceId : -1 // Use -1 or omit the deviceId to select the default device
// Create an instance of AudioIO with outOptions, which will return a WritableStream
var ao = new portAudio.AudioIO({
outOptions: {
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 48000,
deviceId: -1 // Use -1 or omit the deviceId to select the default device
}
});

// handle errors from the AudioOutput
ao.on('error', err => console.error);

// Create a stream to pipe into the AudioOutput
// Note that this does not strip the WAV header so a click will be heard at the beginning
var rs = fs.createReadStream('steam_48000.wav');

// setup to close the output stream at the end of the read stream
rs.on('end', () => ao.end());

// Start piping data and start streaming
rs.pipe(ao);
ao.start();
```

### Recording audio

Recording audio invovles reading from an instance of `AudioInput`.
Recording audio involves streaming audio data from a new instance of `AudioIO` configured with `inOptions` - which returns a Node.js [Readable Stream](https://nodejs.org/dist/latest-v6.x/docs/api/stream.html#stream_readable_streams):

```javascript
var fs = require('fs');
var portAudio = require('../index.js');

// Create an instance of AudioInput, which is a ReadableStream
var ai = new portAudio.AudioInput({
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 44100
deviceId : -1 // Use -1 or omit the deviceId to select the default device
// Create an instance of AudioIO with inOptions, which will return a ReadableStream
var ai = new portAudio.AudioIO({
inOptions: {
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 44100,
deviceId: -1 // Use -1 or omit the deviceId to select the default device
}
});

// handle errors from the AudioInput
ai.on('error', err => console.error);

// Create a write stream to write out to a raw audio file
var ws = fs.createWriteStream('rawAudio.raw');

Expand All @@ -143,6 +161,32 @@ process.on('SIGINT', () => {
});
```

### Bi-directional audio

A bi-directional audio stream is available by creating an instance of `AudioIO` configured with both `inOptions` and `outOptions` - which returns a Node.js [Duplex stream](https://nodejs.org/dist/latest-v6.x/docs/api/stream.html#stream_duplex_and_transform_streams):

```javascript
var portAudio = require('../index.js');

// Create an instance of AudioIO with inOptions and outOptions, which will return a DuplexStream
var aio = new portAudio.AudioIO({
inOptions: {
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 44100,
deviceId: -1 // Use -1 or omit the deviceId to select the default device
},
outOptions: {
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 44100,
deviceId: -1 // Use -1 or omit the deviceId to select the default device
}
});

aio.start();
```

## Troubleshooting

### Linux - No Default Device Found
Expand Down
27 changes: 24 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
"sources": [
"src/naudiodon.cc",
"src/GetDevices.cc",
"src/AudioIn.cc",
"src/AudioOut.cc"
"src/GetHostAPIs.cc",
"src/AudioIO.cc",
"src/PaContext.cc"
],
"include_dirs": [
"<!(node -e \"require('nan')\")", "portaudio/include"
"<!@(node -p \"require('node-addon-api').include\")",
"portaudio/include"
],
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
],
"conditions" : [
[
'OS=="mac"', {
Expand Down Expand Up @@ -70,6 +75,14 @@
'OS=="linux"', {
"conditions": [
['target_arch=="arm"', {
"cflags_cc!": [
"-fno-rtti",
"-fno-exceptions"
],
"cflags_cc": [
"-std=c++11",
"-fexceptions"
],
"link_settings": {
"libraries": [
"<@(module_root_dir)/build/Release/libportaudio.so.2"
Expand All @@ -89,6 +102,14 @@
]
},
{ # ia32 or x64
"cflags_cc!": [
"-fno-rtti",
"-fno-exceptions"
],
"cflags_cc": [
"-std=c++11",
"-fexceptions"
],
"link_settings": {
"libraries": [
"<@(module_root_dir)/build/Release/libportaudio.so.2"
Expand Down
Loading

0 comments on commit 1627f90

Please sign in to comment.