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

Add output format options to the mpg123 decoder #83

Closed
wants to merge 6 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
75 changes: 38 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,48 @@
node-lame
node-addon-mpg123
=========
### NodeJS native bindings to libmp3lame & libmpg123
[![Build Status](https://travis-ci.org/TooTallNate/node-lame.svg?branch=master)](https://travis-ci.org/TooTallNate/node-lame)

For all your async streaming MP3 encoding/decoding needs, there's `node-lame`!
This module hooks into libmp3lame, the library that the `lame` command uses, to
provide `Encoder` and `Decoder` streams to NodeJS.
### NodeJS addon & native bindings to libmpg123
[![Build Status](https://travis-ci.org/mdluo/node-addon-mpg123.svg?branch=master)](https://travis-ci.org/mdluo/node-addon-mpg123)

`node-addon-mpg123` is based on [TooTallNate/node-lame](https://github.com/TooTallNate/node-lame) and removed `lame` related code to keep it simple. *And extended the `Decoder` to support decoding format options.*

For all your async streaming MP3 decoding needs, there's `node-addon-mpg123`!
This module hooks into libmpg123, the library that the `mpg123` command uses, to
provide `Decoder` streams to NodeJS.


Installation
------------

`node-lame` comes bundled with its own copy of `libmp3lame` and `libmpg123`, so
`node-addon-mpg123` comes bundled with its own copy of `libmpg123`, so
there's no need to have them installed on your system.

Simply compile and install `node-lame` using `npm`:
Simply compile and install `node-addon-mpg123` using `npm`:

``` bash
$ npm install lame
$ npm install node-addon-mpg123
```


Example
-------

Here's an example of using `node-lame` to encode some raw PCM data coming from
`process.stdin` to an MP3 file that gets piped to `process.stdout`:
Here's an example of using `node-addon-mpg123` to decode an MP3 file coming from
`process.stdin` to some raw PCM data that gets piped to `process.stdout`:

``` javascript
var lame = require('lame');

// create the Encoder instance
var encoder = new lame.Encoder({
// input
channels: 2, // 2 channels (left and right)
bitDepth: 16, // 16-bit samples
sampleRate: 44100, // 44,100 Hz sample rate

// output
bitRate: 128,
outSampleRate: 22050,
mode: lame.STEREO // STEREO (default), JOINTSTEREO, DUALCHANNEL or MONO
});
const mpg123 = require('node-addon-mpg123');

// raw PCM data from stdin gets piped into the encoder
process.stdin.pipe(encoder);
// create the Decoder instance
const decoder = new mpg123.Decoder();

// the generated MP3 file gets piped to stdout
encoder.pipe(process.stdout);
// MP3 data from stdin gets piped into the decoder
process.stdin.pipe(decoder);

// the raw PCM data gets piped to stdout
decoder.pipe(process.stdout);
```

See the `examples` directory for some more example code.
See `test/decoder.js` for some more example code.

API
---
Expand All @@ -59,11 +51,20 @@ API

The `Decoder` class is a `Stream` subclass that accepts MP3 data written to it,
and outputs raw PCM data. It also emits a `"format"` event when the format of
the MP3 file is determined (usually right at the beginning).
the MP3 file is determined (usually right at the beginning). You can specify
the output PCM data format when creating the decoder instance.

```javascript
const mpg123 = require('node-addon-mpg123');
const decoder = new mpg123.Decoder({
sampleRate: 44100, // [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000]
channels: mpg123.STEREO, // [mpg123.MONO, mpg123.STEREO, mpg123.MONO | mpg123.STEREO]
signed: false, // [true, false]
float: true, // [true, false]
bitDepth: 32, // [8, 16, 24, 32]
});
```

### Encoder class
⚠️ The `channels` option is different from the `TooTallNate/node-lame` encoder.

The `Encoder` class is a `Stream` subclass that accepts raw PCM data written to
it, and outputs a valid MP3 file. You must specify the PCM data format when
creating the encoder instance. Only 16-bit signed samples are currently
supported (rescale before passing to the encoder if necessary)...
See more about mpg123 encoding formats: https://github.com/mdluo/node-addon-mpg123/blob/master/deps/mpg123/src/libmpg123/mpg123.h.in#L348-L395
4 changes: 1 addition & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
'target_name': 'bindings',
'sources': [
'src/bindings.cc',
'src/node_lame.cc',
'src/node_mpg123.cc'
],
"include_dirs" : [
'<!(node -e "require(\'nan\')")'
],
'dependencies': [
'deps/lame/libmp3lame.gyp:mp3lame',
'deps/mpg123/mpg123.gyp:mpg123'
],
'conditions':[
['OS=="win"', {
['OS=="win"', {
'defines':[
'NOMINMAX'
]
Expand Down
Loading