diff --git a/LICENSE b/LICENSE index 48cb98f..8b39a60 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Joshua Jung +Copyright (c) 2015 Vail Systems (Chicago, IL) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index cad48a5..39863c9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ # node-mfcc -Node.JS implementation of the MFCC algorithm +Node.JS implementation of the MFCC algorithm. + +The MIT License (MIT) + +Copyright (c) 2015 Vail Systems + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/mfcc.js b/mfcc.js index d98d3ca..ecdde55 100644 --- a/mfcc.js +++ b/mfcc.js @@ -48,7 +48,10 @@ for (var i = 0; i < fftBins; i++) bins[i] = []; var wr = new wav.Reader(), filterBank = mfcc.constructFilterBank(fftBins, nMelSpecBins, minFreq, maxFreq, sampleRate), - dct = new mfcc.DCT(); + dct = new mfcc.DCT({ + lifter: undefined, + numCoefficients: 12 + }); wr.on('data', function (buffer, offset, length) { framer.frame(buffer, function (frame) { diff --git a/src/mfcc.js b/src/mfcc.js index 08480f0..b9d6d2c 100644 --- a/src/mfcc.js +++ b/src/mfcc.js @@ -8,26 +8,25 @@ \*===========================================================================*/ var DCT = function (options) { this.cosMap = null, - this.options = options || { - numMfccBins: 12 - }; + this.options = options || {}; + this.options.numCoefficients = this.options.numCoefficients || 12; this.options.lifter = this.options.lifter || this.lifterLinear; }; DCT.prototype = { lifterLinear: function (scalar, ix) { - return scalar * ix; + return scalar * (ix+1); }, // Builds a cosine map for the given block size. This allows multiple block sizes to be // memoized automagically. - memoizeCosines: function(blockSize) { + memoizeCosines: function(melSpecBins) { DCT.cosMap = DCT.cosMap || {}; - DCT.cosMap[blockSize] = new Array(blockSize * 12); + DCT.cosMap[melSpecBins] = new Array(melSpecBins* 12); for (var i = 0; i < 12; i++) { - for (var m = 0; m < blockSize; m++) { - DCT.cosMap[blockSize][m + (i * blockSize)] = Math.cos(Math.PI * (i / blockSize) * (m + 0.5)); + for (var melBin = 0; melBin < melSpecBins; melBin++) { + DCT.cosMap[melSpecBins][melBin + (i * melSpecBins)] = Math.cos(Math.PI * ((i+1) / melSpecBins) * (melBin + 0.5)); } } }, @@ -41,10 +40,10 @@ DCT.prototype = { // n: number of MFCC bins // m: number of Spectrum bins // Usually n == 12 and 20 <= m <= 40 - var bins = []; - while (bins.length < this.options.numMfccBins) bins.push(0); + var coefficients = []; + while (coefficients.length < this.options.numCoefficients) coefficients.push(0); - return bins.map(function (bin, ix) { + return coefficients.map(function (__, ix) { var scalar = spectrum.reduce(function (prev, cur, ix_, arr) { return prev + (cur * DCT.cosMap[L][ix_ + (ix * L)]); });