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

Decoder input mp3 info #31

Open
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion examples/mp32wav.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ decoder.on('format', onFormat);
input.pipe(decoder);

function onFormat (format) {
console.error('MP3 format: %j', format);
console.error('MP3 info: %j', decoder.info());
console.error('output format: %j', format);

// write the decoded MP3 data into a WAV file
var writer = new wav.Writer(format);
Expand Down
10 changes: 10 additions & 0 deletions lib/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,13 @@ Decoder.prototype._transform = function (chunk, encoding, done) {
read();
}
};

/**
* Calls `mpg123_info()` to get info about the input mp3 format.
*/

Decoder.prototype.info = function () {
var info = binding.mpg123_info(this.mh);
debug('info: %j', info);
return info;
};
25 changes: 25 additions & 0 deletions src/node_mpg123.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ Handle<Value> node_mpg123_getformat (const Arguments& args) {
return scope.Close(rtn);
}

Handle<Value> node_mpg123_info (const Arguments& args) {
UNWRAP_MH;
mpg123_frameinfo info;
int ret;
Local<Value> rtn;
ret = mpg123_info(mh, &info);
if (ret == MPG123_OK) {
Local<Object> o = Object::New();
o->Set(String::NewSymbol("version"), Number::New(info.version));
Copy link
Author

Choose a reason for hiding this comment

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

version, vbr and modeExtension match standard mp3 header values, there are no constants exposes at node-lame for these, but I can add them if necessary.

o->Set(String::NewSymbol("layer"), Number::New(info.layer));
o->Set(String::NewSymbol("bitRate"), Number::New(info.bitrate));
o->Set(String::NewSymbol("sampleRate"), Number::New(info.rate));
o->Set(String::NewSymbol("mode"), Number::New(info.mode));
Copy link
Author

Choose a reason for hiding this comment

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

this one will match lame.MONO|STEREO|etc.

o->Set(String::NewSymbol("modeExtension"), Number::New(info.mode_ext));
o->Set(String::NewSymbol("frameSize"), Number::New(info.framesize));
o->Set(String::NewSymbol("emphasis"), Number::New(info.emphasis));
o->Set(String::NewSymbol("vbr"), Number::New(info.vbr));
o->Set(String::NewSymbol("averageBitRate"), Number::New(info.abr_rate));
rtn = o;
} else {
rtn = Integer::New(ret);
}
return scope.Close(rtn);
}

Handle<Value> node_mpg123_safe_buffer (const Arguments& args) {
HandleScope scope;
Expand Down Expand Up @@ -502,6 +526,7 @@ void InitMPG123(Handle<Object> target) {
NODE_SET_METHOD(target, "mpg123_current_decoder", node_mpg123_current_decoder);
NODE_SET_METHOD(target, "mpg123_supported_decoders", node_mpg123_supported_decoders);
NODE_SET_METHOD(target, "mpg123_getformat", node_mpg123_getformat);
NODE_SET_METHOD(target, "mpg123_info", node_mpg123_info);
NODE_SET_METHOD(target, "mpg123_safe_buffer", node_mpg123_safe_buffer);
NODE_SET_METHOD(target, "mpg123_outblock", node_mpg123_outblock);
NODE_SET_METHOD(target, "mpg123_framepos", node_mpg123_framepos);
Expand Down