@audio/auditory-mel 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mel-bank.js +47 -0
- package/package.json +30 -0
package/mel-bank.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mel-frequency triangular filter bank.
|
|
3
|
+
* Bands spaced according to the mel scale, used in MFCC feature extraction
|
|
4
|
+
* for speech recognition and music information retrieval.
|
|
5
|
+
*
|
|
6
|
+
* Reference: O'Shaughnessy, "Speech Communications: Human and Machine",
|
|
7
|
+
* IEEE Press, 2000. mel(f) = 2595 * log10(1 + f/700).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
let mel = f => 2595 * Math.log10(1 + f / 700)
|
|
11
|
+
let hz = m => 700 * (Math.pow(10, m / 2595) - 1)
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate mel-spaced triangular filter bank.
|
|
15
|
+
* @param {number} fs - Sample rate (default 44100)
|
|
16
|
+
* @param {object} opts - { fmin: 0, fmax: fs/2, nFilters: 26 }
|
|
17
|
+
* @returns {Array<{fc: number, fLow: number, fHigh: number, mel: number}>}
|
|
18
|
+
*/
|
|
19
|
+
export default function melBank (fs, opts) {
|
|
20
|
+
if (!fs) fs = 44100
|
|
21
|
+
if (!opts) opts = {}
|
|
22
|
+
let fmin = opts.fmin || 0
|
|
23
|
+
let fmax = opts.fmax || fs / 2
|
|
24
|
+
let nFilters = opts.nFilters || 26
|
|
25
|
+
|
|
26
|
+
// nFilters+2 equally-spaced points in mel scale
|
|
27
|
+
let mMin = mel(fmin)
|
|
28
|
+
let mMax = mel(fmax)
|
|
29
|
+
let step = (mMax - mMin) / (nFilters + 1)
|
|
30
|
+
let points = []
|
|
31
|
+
for (let i = 0; i < nFilters + 2; i++) points.push(hz(mMin + i * step))
|
|
32
|
+
|
|
33
|
+
let bands = []
|
|
34
|
+
for (let i = 0; i < nFilters; i++) {
|
|
35
|
+
let fLow = points[i]
|
|
36
|
+
let fc = points[i + 1]
|
|
37
|
+
let fHigh = points[i + 2]
|
|
38
|
+
bands.push({
|
|
39
|
+
fc: Math.round(fc * 10) / 10,
|
|
40
|
+
fLow: Math.round(fLow * 10) / 10,
|
|
41
|
+
fHigh: Math.round(fHigh * 10) / 10,
|
|
42
|
+
mel: Math.round(mel(fc) * 10) / 10
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return bands
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/auditory-mel",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Mel-frequency triangular filter bank",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "mel-bank.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./mel-bank.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"mel-bank.js"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"audio",
|
|
17
|
+
"dsp",
|
|
18
|
+
"auditory",
|
|
19
|
+
"filterbank",
|
|
20
|
+
"mel"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|