Permalink
Browse files

README++

  • Loading branch information...
1 parent 5176f01 commit 11422ea697c21d988f4f66753776d8718aa0d89d @TooTallNate committed Feb 19, 2013
Showing with 28 additions and 1 deletion.
  1. +28 −1 README.md
View
@@ -22,6 +22,8 @@ $ npm install vorbis
Example
-------
+Decoder example:
+
``` javascript
var fs = require('fs');
var ogg = require('ogg');
@@ -30,7 +32,7 @@ var file = __dirname + '/Hydrate-Kenny_Beltrey.ogg';
var od = new ogg.Decoder();
od.on('stream', function (stream) {
- var vd = new vorbis.Decoder(stream);
+ var vd = new vorbis.Decoder();
// the "format" event contains the raw PCM format
vd.on('format', function (format) {
@@ -43,11 +45,36 @@ od.on('stream', function (stream) {
vd.on('error', function (err) {
// maybe try another decoder...
});
+
+ stream.pipe(vd);
});
fs.createReadStream(file).pipe(od);
```
+Encoder example:
+
+``` javascript
+var ogg = require('ogg');
+var vorbis = require('vorbis');
+
+var oe = new ogg.Encoder();
+var ve = new vorbis.Encoder();
+
+// not yet implemented...
+ve.addComment('ARTIST', 'Bob Marley');
+
+// `process.stdin` *MUST* be PCM float 32-bit signed little-endian samples.
+// channels and sample rate are configurable but default to 2 and 44,100hz.
+process.stdin.pipe(ve)
+
+// send the encoded Vorbis pages to the Ogg encoder
+ve.pipe(oe.stream());
+
+// write the produced Ogg file with Vorbis audio to `process.stdout`
+oe.pipe(process.stdout);
+```
+
See the `examples` directory for some more example code.
API

0 comments on commit 11422ea

Please sign in to comment.