@audio/denoise-core 0.1.2 → 0.1.3

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.
Files changed (4) hide show
  1. package/index.js +0 -2
  2. package/package.json +4 -11
  3. package/noise.js +0 -119
  4. package/vad.js +0 -3
package/index.js CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from './stft.js'
2
2
  export * from './util.js'
3
- export * from './noise.js'
4
- export * from './vad.js'
5
3
  export * from './ar.js'
6
4
  export * from './quality.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@audio/denoise-core",
3
- "version": "0.1.2",
4
- "description": "Internal glue for @audio/denoise-* atoms — STFT (batch/stream/analyse), noise estimation (min-stats, IMCRA), AR modeling, quality metrics. VAD lives in @audio/vad (re-exported here).",
3
+ "version": "0.1.3",
4
+ "description": "Internal glue for @audio/denoise-* atoms — STFT (batch/stream/analyse), AR modeling, quality metrics, dB/linear + stream-writer utils. VAD @audio/vad, noise estimation → @audio/noise-estimate.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "index.js",
@@ -10,8 +10,6 @@
10
10
  "./package.json": "./package.json",
11
11
  "./stft": "./stft.js",
12
12
  "./util": "./util.js",
13
- "./noise": "./noise.js",
14
- "./vad": "./vad.js",
15
13
  "./ar": "./ar.js",
16
14
  "./quality": "./quality.js"
17
15
  },
@@ -19,22 +17,17 @@
19
17
  "index.js",
20
18
  "stft.js",
21
19
  "util.js",
22
- "noise.js",
23
- "vad.js",
24
20
  "ar.js",
25
21
  "quality.js"
26
22
  ],
27
23
  "dependencies": {
28
- "fourier-transform": "^2.0.0",
29
- "@audio/vad": "^1.0.0"
24
+ "fourier-transform": "^2.0.0"
30
25
  },
31
26
  "keywords": [
32
27
  "audio",
33
28
  "dsp",
34
29
  "denoise",
35
- "stft",
36
- "vad",
37
- "noise-estimation"
30
+ "stft"
38
31
  ],
39
32
  "license": "MIT",
40
33
  "author": "Dmitry Iv. <dfcreative@gmail.com>",
package/noise.js DELETED
@@ -1,119 +0,0 @@
1
- // Noise PSD estimators feeding the statistical denoisers (Wiener, OM-LSA, MMSE).
2
- // - profile: average |X|² over a user-chosen quiet segment (manual baseline)
3
- // - minimumStatistics: Martin (2001) — track minima of smoothed |X|² in sliding window
4
- // - imcra: Cohen (2003) — Improved MCRA, two-iteration smoothing + speech-presence-driven
5
- //
6
- // All estimators are stateful: pass the same params object across frames in stream mode.
7
-
8
- import { stftAnalyse } from './stft.js'
9
-
10
- // One-shot batch profile from a quiet segment of `data`. Returns Float64Array(N/2+1).
11
- export function noiseProfile(data, opts = {}) {
12
- let N = opts.frameSize || 2048
13
- let hop = opts.hopSize || (N >> 2)
14
- let half = N >> 1
15
- let from = Math.max(0, opts.from ?? 0)
16
- let to = Math.min(data.length, opts.to ?? Math.min(data.length, from + N * 8))
17
- let seg = data.subarray(from, to)
18
- let psd = new Float64Array(half + 1)
19
- let count = 0
20
- stftAnalyse(seg, mag => {
21
- for (let k = 0; k <= half; k++) psd[k] += mag[k] * mag[k]
22
- count++
23
- }, { frameSize: N, hopSize: hop })
24
- let scale = count ? 1 / count : 0
25
- for (let k = 0; k <= half; k++) psd[k] *= scale
26
- return psd
27
- }
28
-
29
- // Minimum Statistics (Martin 2001) — frame-by-frame online updater.
30
- // Keeps a rolling D-frame minimum of smoothed PSD per bin; multiplies by a bias
31
- // compensation factor so the minimum tracks E{|N|²} rather than the lower-tail.
32
- //
33
- // Usage:
34
- // let est = minStats(half, { D: 96 })
35
- // stftAnalyse(data, m => est.update(m))
36
- // let psd = est.psd // current noise PSD
37
- //
38
- // D ≈ 1.5 s of frames at hop = N/4 ≈ 96 frames @ 44.1k / N=2048.
39
- export function minStats(half, opts = {}) {
40
- let D = opts.D || 96
41
- let alpha = opts.alpha ?? 0.7 // smoothing on PSD
42
- let bias = opts.bias ?? 1.5 // empirical comp from Martin §VII
43
- let smoothed = new Float64Array(half + 1)
44
- let psd = new Float64Array(half + 1)
45
- let buf = [] // ring of recent smoothed frames
46
-
47
- return {
48
- psd,
49
- update(mag) {
50
- let p = new Float64Array(half + 1)
51
- for (let k = 0; k <= half; k++) {
52
- let pk = mag[k] * mag[k]
53
- smoothed[k] = alpha * smoothed[k] + (1 - alpha) * pk
54
- p[k] = smoothed[k]
55
- }
56
- buf.push(p)
57
- if (buf.length > D) buf.shift()
58
- for (let k = 0; k <= half; k++) {
59
- let mn = Infinity
60
- for (let i = 0; i < buf.length; i++) if (buf[i][k] < mn) mn = buf[i][k]
61
- psd[k] = mn * bias
62
- }
63
- }
64
- }
65
- }
66
-
67
- // IMCRA — Improved Minima Controlled Recursive Averaging (Cohen 2003).
68
- // Drives noise PSD via speech-presence probability (SPP) so it stops updating
69
- // during voiced regions. SPP itself is supplied by the caller (see vad.js spp())
70
- // or computed internally from the smoothed-to-min PSD ratio.
71
- export function imcra(half, opts = {}) {
72
- let alpha = opts.alpha ?? 0.92
73
- let alphaD = opts.alphaD ?? 0.85
74
- let beta = opts.beta ?? 1.47
75
- let psd = new Float64Array(half + 1)
76
- let psdInit = false
77
- let smoothed = new Float64Array(half + 1)
78
- let mins = new Float64Array(half + 1)
79
- let prevMins = new Float64Array(half + 1)
80
- let frameCount = 0
81
- let resetEvery = opts.resetEvery || 80 // ≈ 0.9 s @ 44.1k, hop=512
82
-
83
- return {
84
- psd,
85
- update(mag, sppOverride) {
86
- let init = !psdInit
87
- for (let k = 0; k <= half; k++) {
88
- let pk = mag[k] * mag[k]
89
- smoothed[k] = init ? pk : alpha * smoothed[k] + (1 - alpha) * pk
90
- if (init || smoothed[k] < mins[k]) mins[k] = smoothed[k]
91
- if (!init && smoothed[k] < prevMins[k]) prevMins[k] = smoothed[k]
92
- }
93
- frameCount++
94
- if (frameCount >= resetEvery) {
95
- for (let k = 0; k <= half; k++) {
96
- let mn = Math.min(mins[k], prevMins[k])
97
- prevMins[k] = mins[k]
98
- mins[k] = smoothed[k]
99
- // bias-compensated minimum tracker
100
- if (init) psd[k] = mn * beta
101
- }
102
- frameCount = 0
103
- psdInit = true
104
- }
105
-
106
- if (!psdInit) return
107
-
108
- for (let k = 0; k <= half; k++) {
109
- let mn = Math.min(mins[k], prevMins[k]) * beta
110
- // SPP from local SNR vs minimum: high if smoothed >> minimum.
111
- let snr = smoothed[k] / Math.max(mn, 1e-30)
112
- let p = sppOverride !== undefined ? sppOverride : 1 / (1 + Math.exp(-3 * (snr - 5)))
113
- let alphaTilde = alphaD + (1 - alphaD) * p
114
- let pk = mag[k] * mag[k]
115
- psd[k] = alphaTilde * psd[k] + (1 - alphaTilde) * pk
116
- }
117
- }
118
- }
119
- }
package/vad.js DELETED
@@ -1,3 +0,0 @@
1
- // vad/spp/ddSnr were promoted to the standalone @audio/vad atom.
2
- // Re-exported here so restoration code (and the @audio/denoise umbrella) keep working.
3
- export * from '@audio/vad'