Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch the backend from mpg123 to libao #111

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- libasound2-dev
- libao-dev

language: node_js

Expand All @@ -17,12 +17,16 @@ node_js:
- "6"
- "7"
- "8"
- "9"

install:
- PATH="`npm bin`:`npm bin -g`:$PATH"
# Install dependencies and build
- npm install

before_script:
- "echo 'default_driver=null' | sudo tee /etc/libao.conf"

script:
# Output useful info for debugging
- node --version
Expand Down
53 changes: 19 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@
[![Build Status](https://ci.appveyor.com/api/projects/status/wix7wml3v55670kw?svg=true)](https://ci.appveyor.com/project/TooTallNate/node-speaker)

A Writable stream instance that accepts [PCM audio][pcm] data and outputs it
to the speakers. The output is backed by `mpg123`'s audio output modules, which
in turn use any number of audio backends commonly found on Operating Systems
these days.
to the speakers. The output is backed by [libao][ao], which supports
a ton of audio backends.


## Installation

Simply compile and install `node-speaker` using `npm`:
You need `libao` installed on your system before installig `node-speaker`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possibly a bit of a drawback, I kind of liked the approach of bundling the source to the lib.

How do we feel about just adding the libao source code to this repo?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bundle of joy

Hum, well, I always thought bundling was a Bad Idea, but I see your point about ease of use. So, I've done some thinking and reviewing my stand on bundling dependencies.

Here's what I've come up with

The whole point of switching to libao is to avoid bundled sources. The tl;dr version of why is because once you bundle the sources, you kind of own the dependency and get all the maintenance burden (which we already have, as the issues show). On the other side, proper external dependencies allow us to report issues in the right place and let the proper owners deal with it.

Conclusion

It is comforting for users, but I'm not willing the pay the price.

References:


- Debian
```sh
$ apt-get install libao-dev
```

- OSX:
```sh
npm install speaker
$ brew install libao
```

On Debian/Ubuntu, the [ALSA][alsa] backend is selected by default, so be sure
to have the `alsa.h` header file in place:
Now, simply compile and install `node-speaker` using `npm`:

```sh
sudo apt-get install libasound2-dev
$ npm install speaker
```

## Example
Expand Down Expand Up @@ -58,44 +63,24 @@ base class options, as well as any of these PCM formatting options:
* `channels` - The number of audio channels. PCM data must be interleaved. Defaults to `2`.
* `bitDepth` - The number of bits per sample. Defaults to `16` (16-bit).
* `sampleRate` - The number of samples per second per channel. Defaults to `44100`.
* `signed` - Boolean specifying if the samples are signed or unsigned. Defaults to `true` when bit depth is 8-bit, `false` otherwise.
* `float` - Boolean specifying if the samples are floating-point values. Defaults to `false`.
* `samplesPerFrame` - The number of samples to send to the audio backend at a time. You likely don't need to mess with this value. Defaults to `1024`.

#### "open" event

Fired when the backend `open()` call has completed. This happens once the first
`write()` call happens on the speaker instance.

#### "flush" event

Fired after the speaker instance has had `end()` called, and after the audio data
has been flushed to the speakers.

#### "close" event

Fired after the "flush" event, after the backend `close()` call has completed.
This speaker instance is essentially finished after this point.

## Audio Backend Selection

`node-speaker` is backed by `mpg123`'s "output modules", which in turn use one of
many popular audio backends like ALSA, OSS, SDL, and lots more. The default
backends for each operating system are described in the table below:

| **Operating System** | **Audio Backend** | **Description**
|:---------------------|:------------------|:----------------------------------
| Linux | `alsa` | Output audio using [Advanced Linux Sound Architecture (ALSA)][alsa].
| Mac OS X | `coreaudio` | Output audio using Mac OS X's CoreAudio.
| Windows | `win32` | Audio output for Windows (winmm).
| Solaris | `sun` | Audio output for Sun Audio.

To manually override the default backend, pass the `--mpg123-backend` switch to
`npm`/`node-gyp`:

```sh
npm install speaker --mpg123-backend=openal
```
`node-speaker` is backed by `libao`'s "output modules", which in turn use one of
many popular audio backends like ALSA, pulseaudio, and lots more. The default
backends for each operating system depend on libao configuration. Please check
[libao's documentation][aodoc] for more information.

[pcm]: http://en.wikipedia.org/wiki/Pulse-code_modulation
[alsa]: http://www.alsa-project.org/
[ao]: https://www.xiph.org/ao/
[aodoc]: https://xiph.org/ao/doc/config.html
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ environment:
- nodejs_version: "6"
- nodejs_version: "7"
- nodejs_version: "8"
- nodejs_version: "9"

platform:
- x86
Expand Down
17 changes: 13 additions & 4 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
'sources': [
'src/binding.cc',
],
"include_dirs" : [
'include_dirs' : [
'<!(node -e "require(\'nan\')")'
],
'dependencies': [
'deps/mpg123/mpg123.gyp:output'
],
'conditions': [
['OS=="linux"', {
'cflags': [
'<!@(pkg-config --cflags ao)'
],
'ldflags': [
'<!@(pkg-config --libs-only-L ao)'
],
'libraries': [
'<!@(pkg-config --libs-only-l ao)'
]
}]]
}
]
}
150 changes: 0 additions & 150 deletions deps/mpg123/AUTHORS

This file was deleted.

Loading