Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
Detect VBR/CBR with cbrEstimate set to true
Browse files Browse the repository at this point in the history
  • Loading branch information
mycoboco committed Jun 14, 2016
1 parent d1cf90b commit abdb1bc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ function mp3Duration(filename, cbrEstimate, callback) {
, offset
, stat
, info
, count = 0
, bitRates = []
;

fd = yield $open(filename, 'r');
Expand All @@ -182,6 +184,7 @@ function mp3Duration(filename, cbrEstimate, callback) {
if (buffer[0] === 0xff && (buffer[1] & 0xe0) === 0xe0) {
info = parseFrameHeader(buffer);
if (info.frameSize && info.samples) {
if (count < 3 && cbrEstimate) bitRates[count++] = info.bitRate
offset += info.frameSize;
duration += ( info.samples / info.sampleRate );
} else {
Expand All @@ -193,7 +196,8 @@ function mp3Duration(filename, cbrEstimate, callback) {
offset++; //Corrupt file?
}

if (cbrEstimate && info) {
if (count == 3 && cbrEstimate &&
bitRates[0] === bitRates[1] && bitRates[1] == bitRates[2]) {
return round(estimateDuration(info.bitRate, offset, stat.size));
}
}
Expand Down

0 comments on commit abdb1bc

Please sign in to comment.