@audio/resample-linear 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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/linear.js +20 -0
  3. package/package.json +30 -0
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @audio/resample-linear
2
+
3
+ > Linear-interpolation resampling — cheap, real-time
4
+
5
+ Planned — not implemented yet. See the umbrella README for status and sources.
package/linear.js ADDED
@@ -0,0 +1,20 @@
1
+ // Linear-interpolation resampling — cheap, real-time.
2
+ // No anti-alias filter: use @audio/resample-sinc when downsampling.
3
+
4
+ export default function resample (data, { from, to } = {}) {
5
+ if (!(from > 0) || !(to > 0)) throw new RangeError('resample: from/to must be positive sample rates')
6
+ if (from === to) return Float32Array.from(data)
7
+
8
+ let rate = from / to
9
+ let n = Math.round(data.length * to / from)
10
+ let out = new Float32Array(n)
11
+
12
+ for (let i = 0; i < n; i++) {
13
+ let pos = i * rate
14
+ let base = Math.floor(pos), frac = pos - base
15
+ let a = data[base] ?? 0
16
+ let b = base + 1 < data.length ? data[base + 1] : a
17
+ out[i] = a + (b - a) * frac
18
+ }
19
+ return out
20
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@audio/resample-linear",
3
+ "version": "1.0.0",
4
+ "description": "Linear-interpolation resampling — cheap, real-time (no anti-alias; use resample-sinc for downsampling)",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "linear.js",
8
+ "exports": {
9
+ ".": "./linear.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "linear.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "resample",
19
+ "linear",
20
+ "sample-rate"
21
+ ],
22
+ "license": "MIT",
23
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }