@audio/mir-melody 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/melody.js +22 -0
- package/package.json +32 -0
package/melody.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Melody contour — frame-level F0 track via YIN, with voicing flags.
|
|
2
|
+
// MIREX melody-extraction shape: { times, f0 (Hz, 0 = unvoiced), voiced }.
|
|
3
|
+
|
|
4
|
+
import yin from '@audio/pitch-yin'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Float32Array} data — mono PCM
|
|
8
|
+
* @param {object} opts — { fs=44100, frameSize=2048, hop=512, threshold }
|
|
9
|
+
* @returns {{ times: Float32Array, f0: Float32Array, voiced: Uint8Array }}
|
|
10
|
+
*/
|
|
11
|
+
export default function melody (data, { fs = 44100, frameSize = 2048, hop = 512, threshold } = {}) {
|
|
12
|
+
let nFrames = Math.max(0, Math.floor((data.length - frameSize) / hop) + 1)
|
|
13
|
+
let times = new Float32Array(nFrames)
|
|
14
|
+
let f0 = new Float32Array(nFrames)
|
|
15
|
+
let voiced = new Uint8Array(nFrames)
|
|
16
|
+
for (let i = 0; i < nFrames; i++) {
|
|
17
|
+
let r = yin(data.subarray(i * hop, i * hop + frameSize), { fs, threshold })
|
|
18
|
+
times[i] = (i * hop + frameSize / 2) / fs
|
|
19
|
+
if (r) { f0[i] = r.freq; voiced[i] = 1 }
|
|
20
|
+
}
|
|
21
|
+
return { times, f0, voiced }
|
|
22
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/mir-melody",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Melody contour \u2014 frame-level F0 track via YIN with voicing (MIREX melody shape)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "melody.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./melody.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"melody.js"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@audio/pitch-yin": "^1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"audio",
|
|
20
|
+
"dsp",
|
|
21
|
+
"mir",
|
|
22
|
+
"melody"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|