@audio/filter 3.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/LICENSE +40 -0
- package/index.d.ts +121 -0
- package/index.js +16 -0
- package/package.json +89 -0
- package/readme.md +1164 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Kṛṣnized
|
|
2
|
+
|
|
3
|
+
This is a reminder that, in the absolute sense, all results of work belong to the Supreme.
|
|
4
|
+
|
|
5
|
+
While software and intellectual property (IP) require a formal license to define authorship,
|
|
6
|
+
responsibilities, or distribution limitations, these are temporary material designations.
|
|
7
|
+
The origin and destination of all ideas, as well as the ultimate owner of all results,
|
|
8
|
+
is the Supreme. The most meaningful action is to dedicate these results to the Supreme.
|
|
9
|
+
This process is known as Karma-Yoga and is described in BG 3.9, BG 12.10 and BG 18.46.
|
|
10
|
+
|
|
11
|
+
"Work done as a sacrifice for the Supreme must be performed;
|
|
12
|
+
otherwise, work binds one to the material world."
|
|
13
|
+
|
|
14
|
+
This license does not override or alter the terms specified by the material-level license below.
|
|
15
|
+
|
|
16
|
+
ॐ
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
MIT License
|
|
21
|
+
|
|
22
|
+
Copyright (c) Dmitry Iv
|
|
23
|
+
|
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
25
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
26
|
+
in the Software without restriction, including without limitation the rights
|
|
27
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
28
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
29
|
+
furnished to do so, subject to the following conditions:
|
|
30
|
+
|
|
31
|
+
The above copyright notice and this permission notice shall be included in all
|
|
32
|
+
copies or substantial portions of the Software.
|
|
33
|
+
|
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
35
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
37
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
38
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
39
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
40
|
+
SOFTWARE.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// @audio/filter — TypeScript declarations
|
|
2
|
+
|
|
3
|
+
export type Buf = Float32Array | Float64Array | number[]
|
|
4
|
+
export interface BiquadCoef { b0: number; b1: number; b2: number; a1: number; a2: number }
|
|
5
|
+
export type SOS = BiquadCoef[]
|
|
6
|
+
|
|
7
|
+
export interface LadderParams {
|
|
8
|
+
fc?: number // cutoff frequency Hz (default 1000)
|
|
9
|
+
resonance?: number // 0–1, self-oscillation at 1 (moogLadder) / ≈1.15–1.2 (diodeLadder)
|
|
10
|
+
fs?: number // sample rate (default 44100)
|
|
11
|
+
drive?: number // input drive / saturation amount (default 1)
|
|
12
|
+
[key: string]: unknown
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Moog 4-pole transistor ladder lowpass — ZDF, –24 dB/oct, self-oscillates at resonance=1 */
|
|
16
|
+
export function moogLadder(data: Buf, params: LadderParams): Buf
|
|
17
|
+
|
|
18
|
+
/** Diode ladder lowpass (Roland TB-303 style) — bidirectionally-coupled ZDF tridiagonal solve, –24 dB/oct, self-oscillates at resonance≈1.15–1.2 */
|
|
19
|
+
export function diodeLadder(data: Buf, params: LadderParams): Buf
|
|
20
|
+
|
|
21
|
+
export interface Korg35Params extends LadderParams {
|
|
22
|
+
type?: 'lowpass' | 'highpass' // default 'lowpass'. Never self-oscillates (2-pole loop can't reach -180° phase at finite frequency); LP+HP=input holds exactly only at resonance=0
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Korg35 2-pole filter (MS-20 style) — ZDF, –12 dB/oct */
|
|
26
|
+
export function korg35(data: Buf, params: Korg35Params): Buf
|
|
27
|
+
|
|
28
|
+
export interface OberheimParams {
|
|
29
|
+
fc?: number // cutoff frequency Hz (default 1000)
|
|
30
|
+
resonance?: number // 0–1 (default 0), maps to SVF damping R=1-resonance; peak gain 1/(2R)
|
|
31
|
+
type?: 'lowpass' | 'highpass' | 'bandpass' | 'notch' // default 'lowpass'
|
|
32
|
+
fs?: number // sample rate (default 44100)
|
|
33
|
+
[key: string]: unknown
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Oberheim SEM 2-pole state-variable filter — ZDF, –12 dB/oct, multimode. No drive param. */
|
|
37
|
+
export function oberheim(data: Buf, params: OberheimParams): Buf
|
|
38
|
+
|
|
39
|
+
export interface DcBlockerParams { R?: number; [key: string]: unknown } // R default 0.995
|
|
40
|
+
/** DC blocking filter H(z) = (1−z⁻¹)/(1−R·z⁻¹) */
|
|
41
|
+
export function dcBlocker(data: Buf, params?: DcBlockerParams): Buf
|
|
42
|
+
|
|
43
|
+
export interface CombParams {
|
|
44
|
+
delay: number // delay in samples
|
|
45
|
+
gain?: number // feedback/feedforward gain (default 0.5)
|
|
46
|
+
type?: 'feedforward' | 'feedback' // default 'feedforward'
|
|
47
|
+
[key: string]: unknown
|
|
48
|
+
}
|
|
49
|
+
/** Comb filter (feedforward FIR or feedback IIR). Reallocates the delay line when params.delay changes on a reused params object. */
|
|
50
|
+
export function comb(data: Buf, params: CombParams): Buf
|
|
51
|
+
|
|
52
|
+
export interface AllpassParams { a?: number; fc?: number; Q?: number; fs?: number; [key: string]: unknown }
|
|
53
|
+
/** Allpass filters — unity magnitude, frequency-dependent phase shift */
|
|
54
|
+
export declare namespace allpass {
|
|
55
|
+
/** First-order allpass: H(z) = (a + z⁻¹) / (1 + a·z⁻¹). params.a is required for meaningful output. */
|
|
56
|
+
function first(data: Buf, params: AllpassParams): Buf
|
|
57
|
+
/** Second-order allpass via RBJ biquad. params.fc required, Q default 0.707, fs default 44100. */
|
|
58
|
+
function second(data: Buf, params: AllpassParams): Buf
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface EmphasisParams { alpha?: number; [key: string]: unknown } // alpha default 0.97
|
|
62
|
+
/** Pre-emphasis H(z) = 1 − α·z⁻¹ */
|
|
63
|
+
export function emphasis(data: Buf, params?: EmphasisParams): Buf
|
|
64
|
+
/** De-emphasis H(z) = 1/(1 − α·z⁻¹) */
|
|
65
|
+
export function deemphasis(data: Buf, params?: EmphasisParams): Buf
|
|
66
|
+
|
|
67
|
+
export interface ResonatorParams { fc: number; bw?: number; fs?: number; [key: string]: unknown } // bw default 50
|
|
68
|
+
/** Constant-peak-gain resonator (JOS two-zero form) — modal synthesis (bells, drums, formants). Peak gain is exactly 0dB at fc for any bw. Throws if params.fc is omitted. */
|
|
69
|
+
export function resonator(data: Buf, params: ResonatorParams): Buf
|
|
70
|
+
|
|
71
|
+
export interface SpectralTiltParams { slope?: number; fs?: number; [key: string]: unknown } // slope default 0 (dB/octave, positive = boost highs)
|
|
72
|
+
/** Spectral tilt — cascade of octave-spaced first-order shelving sections, ±dB/oct */
|
|
73
|
+
export function spectralTilt(data: Buf, params?: SpectralTiltParams): Buf
|
|
74
|
+
|
|
75
|
+
export interface VariableBandwidthParams {
|
|
76
|
+
fc?: number // default 1000
|
|
77
|
+
Q?: number // default 0.707
|
|
78
|
+
fs?: number // default 44100
|
|
79
|
+
type?: 'lowpass' | 'highpass' | 'bandpass' // default 'lowpass'
|
|
80
|
+
[key: string]: unknown
|
|
81
|
+
}
|
|
82
|
+
/** Variable-bandwidth biquad filter — fc/Q exponentially smoothed (5ms time constant) and coefficients recomputed every sample, eliminating coefficient-jump clicks on mid-stream parameter changes */
|
|
83
|
+
export function variableBandwidth(data: Buf, params?: VariableBandwidthParams): Buf
|
|
84
|
+
|
|
85
|
+
export interface FilterParams {
|
|
86
|
+
fc: number // cutoff/center frequency Hz — required, throws if omitted
|
|
87
|
+
Q?: number // quality factor (default 0.707)
|
|
88
|
+
order?: number // filter order: 2 = biquad, 4+ = Butterworth cascade (default 2)
|
|
89
|
+
fs?: number // sample rate (default 44100)
|
|
90
|
+
[key: string]: unknown
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type Butterworth = (order: number, fc: number, fs: number, type: 'lowpass' | 'highpass') => SOS
|
|
94
|
+
|
|
95
|
+
/** Highpass filter — removes below cutoff. Order 2: RBJ biquad. Order 4+: Butterworth SOS (requires highpass.useButterworth(butterworth) to be called once, see digital-filter/iir/butterworth.js). Throws if params.fc is omitted. */
|
|
96
|
+
export function highpass(data: Buf, params: FilterParams): Buf
|
|
97
|
+
export declare namespace highpass { function useButterworth(bw: Butterworth): void }
|
|
98
|
+
|
|
99
|
+
/** Lowpass filter — removes above cutoff. Order 2: RBJ biquad. Order 4+: Butterworth SOS (requires lowpass.useButterworth(butterworth) to be called once, see digital-filter/iir/butterworth.js). Throws if params.fc is omitted. */
|
|
100
|
+
export function lowpass(data: Buf, params: FilterParams): Buf
|
|
101
|
+
export declare namespace lowpass { function useButterworth(bw: Butterworth): void }
|
|
102
|
+
|
|
103
|
+
export interface BandpassParams {
|
|
104
|
+
fc: number // center frequency Hz — required, throws if omitted
|
|
105
|
+
Q?: number // quality factor (default 0.707)
|
|
106
|
+
fs?: number // sample rate (default 44100)
|
|
107
|
+
[key: string]: unknown
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Bandpass filter — passes around center frequency, rejects rest. RBJ biquad (constant 0dB peak gain). Throws if params.fc is omitted. */
|
|
111
|
+
export function bandpass(data: Buf, params: BandpassParams): Buf
|
|
112
|
+
|
|
113
|
+
export interface NotchParams {
|
|
114
|
+
fc: number // notch frequency Hz — required, throws if omitted
|
|
115
|
+
Q?: number // quality factor (default 30)
|
|
116
|
+
fs?: number // sample rate (default 44100)
|
|
117
|
+
[key: string]: unknown
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Notch (band-reject) filter — unity gain except null at fc. Throws if params.fc is omitted. */
|
|
121
|
+
export function notch(data: Buf, params: NotchParams): Buf
|
package/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// @audio/filter — audio-facing filters umbrella re-exporting every @audio/filter-* atom.
|
|
2
|
+
// For smaller bundles, depend directly on the individual atom.
|
|
3
|
+
// Weighting → @audio/weighting, auditory banks → @audio/auditory, EQ → @audio/eq,
|
|
4
|
+
// crossfeed → @audio/spatial-crossfeed, speech atoms → @audio/speech-* (in this repo).
|
|
5
|
+
|
|
6
|
+
export { highpass, lowpass, bandpass, notch, allpass } from '@audio/filter-biquad'
|
|
7
|
+
export { default as comb } from '@audio/filter-comb'
|
|
8
|
+
export { default as dcBlocker } from '@audio/filter-dcblocker'
|
|
9
|
+
export { default as resonator } from '@audio/filter-resonator'
|
|
10
|
+
export { default as variableBandwidth } from '@audio/filter-variable'
|
|
11
|
+
export { emphasis, deemphasis } from '@audio/filter-preemphasis'
|
|
12
|
+
export { default as spectralTilt } from '@audio/filter-spectral-tilt'
|
|
13
|
+
export { default as moogLadder } from '@audio/filter-moog-ladder'
|
|
14
|
+
export { default as diodeLadder } from '@audio/filter-diode-ladder'
|
|
15
|
+
export { default as korg35 } from '@audio/filter-korg35'
|
|
16
|
+
export { default as oberheim } from '@audio/filter-oberheim'
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audio/filter",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Audio-facing filters — umbrella for @audio/filter-* atoms (biquads, comb, resonator, DC blocker, pre-emphasis, spectral tilt, analog ladder models)",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"default": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node test.js",
|
|
20
|
+
"test:types": "tsc --noEmit --strict --module nodenext --moduleResolution nodenext test/types.ts",
|
|
21
|
+
"test:all": "npm test --workspaces --if-present && npm test",
|
|
22
|
+
"plot": "node plot/generate.js",
|
|
23
|
+
"publish:all": "npm publish --workspaces && npm publish"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"index.js",
|
|
27
|
+
"index.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/audiojs/filter.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/audiojs/filter/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/audiojs/filter#readme",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"audio",
|
|
39
|
+
"dsp",
|
|
40
|
+
"filter",
|
|
41
|
+
"a-weighting",
|
|
42
|
+
"c-weighting",
|
|
43
|
+
"k-weighting",
|
|
44
|
+
"itu-468",
|
|
45
|
+
"riaa",
|
|
46
|
+
"equalizer",
|
|
47
|
+
"parametric-eq",
|
|
48
|
+
"graphic-eq",
|
|
49
|
+
"crossover",
|
|
50
|
+
"crossfeed",
|
|
51
|
+
"moog",
|
|
52
|
+
"korg",
|
|
53
|
+
"diode-ladder",
|
|
54
|
+
"vocoder",
|
|
55
|
+
"formant",
|
|
56
|
+
"gammatone",
|
|
57
|
+
"bark",
|
|
58
|
+
"erb",
|
|
59
|
+
"octave-band",
|
|
60
|
+
"psychoacoustics",
|
|
61
|
+
"signal-processing"
|
|
62
|
+
],
|
|
63
|
+
"author": "Dmitry Iv. <dfcreative@gmail.com>",
|
|
64
|
+
"license": "MIT",
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@audio/filter-biquad": "^1.0.0",
|
|
67
|
+
"@audio/filter-comb": "^1.0.0",
|
|
68
|
+
"@audio/filter-dcblocker": "^1.0.0",
|
|
69
|
+
"@audio/filter-resonator": "^1.0.0",
|
|
70
|
+
"@audio/filter-variable": "^1.0.0",
|
|
71
|
+
"@audio/filter-preemphasis": "^1.0.0",
|
|
72
|
+
"@audio/filter-spectral-tilt": "^1.0.0",
|
|
73
|
+
"@audio/filter-moog-ladder": "^1.0.0",
|
|
74
|
+
"@audio/filter-diode-ladder": "^1.0.0",
|
|
75
|
+
"@audio/filter-korg35": "^1.0.0",
|
|
76
|
+
"@audio/filter-oberheim": "^1.0.0"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"tst": "^9.4.0",
|
|
80
|
+
"typescript": "^5.8.2"
|
|
81
|
+
},
|
|
82
|
+
"workspaces": [
|
|
83
|
+
"packages/*"
|
|
84
|
+
],
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public"
|
|
87
|
+
},
|
|
88
|
+
"main": "index.js"
|
|
89
|
+
}
|