Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,9 @@ | ||
0.0.2 / 2012-10-25 | ||
================== | ||
- support for Windows | ||
- support for Linux | ||
- support for Solaris | ||
- call `flush()` and `close()` at the end of the stream | ||
0.0.1 / 2012-10-24 | ||
@@ -2,0 +10,0 @@ ================== |
31
index.js
@@ -6,6 +6,6 @@ | ||
var debug = require('debug')('speaker'); | ||
var binding = require('bindings')('binding'); | ||
var inherits = require('util').inherits; | ||
var Writable = require('stream').Writable; | ||
var debug = require('debug')('speaker'); | ||
var binding = require('bindings')('binding'); | ||
@@ -43,6 +43,6 @@ // node v0.8.x compat | ||
if (!opts) opts = {}; | ||
if (null == opts.signed) opts.signed = true; | ||
if (null == opts.channels) opts.channels = 2; | ||
if (null == opts.bitDepth) opts.bitDepth = 16; | ||
if (null == opts.sampleRate) opts.sampleRate = 44100; | ||
if (null == opts.signed) opts.signed = opts.bitDepth != 8; | ||
@@ -60,7 +60,14 @@ // initialize the audio handle | ||
// copy over the opts | ||
for (var i in opts) this[i] = opts[i]; | ||
// copy over options | ||
this.signed = opts.signed; | ||
this.channels = opts.channels; | ||
this.bitDepth = opts.bitDepth; | ||
this.sampleRate = opts.sampleRate; | ||
this.samplesPerFrame = opts.samplesPerFrame; | ||
// calculate the "block align" | ||
this.blockAlign = this.bitDepth / 8 * this.channels; | ||
// call `flush()` upon the "finish" event | ||
this.on('finish', this._flush); | ||
} | ||
@@ -71,4 +78,2 @@ inherits(Speaker, Writable); | ||
* `_write()` callback for the Writable base class. | ||
* | ||
* TODO: figure out how to flush() and close()... | ||
*/ | ||
@@ -108,1 +113,13 @@ | ||
}; | ||
/** | ||
* Calls the `flush()` and `close()` bindings for the audio backend. | ||
*/ | ||
Speaker.prototype._flush = function () { | ||
debug('_flush()'); | ||
var handle = this.audio_handle; | ||
// TODO: async | ||
binding.flush(handle); | ||
binding.close(handle); | ||
}; |
@@ -10,9 +10,17 @@ { | ||
"speaker", | ||
"headphone" | ||
"headphone", | ||
"alsa", | ||
"coreaudio", | ||
"openal", | ||
"sdl", | ||
"portaudio", | ||
"jack", | ||
"oss", | ||
"pulse" | ||
], | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/TooTallNate/node-audio-output.git" | ||
"url": "git://github.com/TooTallNate/node-speaker.git" | ||
}, | ||
@@ -19,0 +27,0 @@ "main": "./index.js", |
@@ -23,4 +23,7 @@ node-speaker | ||
Here's an example of piping `stdin` to the speaker, which should be 2 channel, | ||
16-bit audio at 44,100 samples per second (a.k.a CD quality audio). | ||
``` javascript | ||
var Speaker = require('speaker') | ||
var Speaker = require('speaker'); | ||
@@ -45,1 +48,23 @@ // Create the Speaker instance | ||
TODO: document... | ||
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). | ||
| 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`: | ||
``` bash | ||
$ npm install speaker --mpg123-backend=openal | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3320126
234
162
69