@audio/synth-dtmf 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 (2) hide show
  1. package/dtmf.js +16 -0
  2. package/package.json +29 -0
package/dtmf.js ADDED
@@ -0,0 +1,16 @@
1
+ // DTMF — ITU-T Q.23 dual tones per key, with inter-digit gaps.
2
+
3
+ const ROW = { 1: 697, 2: 697, 3: 697, A: 697, 4: 770, 5: 770, 6: 770, B: 770, 7: 852, 8: 852, 9: 852, C: 852, '*': 941, 0: 941, '#': 941, D: 941 }
4
+ const COL = { 1: 1209, 4: 1209, 7: 1209, '*': 1209, 2: 1336, 5: 1336, 8: 1336, 0: 1336, 3: 1477, 6: 1477, 9: 1477, '#': 1477, A: 1633, B: 1633, C: 1633, D: 1633 }
5
+
6
+ export default function dtmf (digits, { fs = 44100, tone = 0.08, gap = 0.04, amp = 0.45 } = {}) {
7
+ let toneN = Math.round(tone * fs), gapN = Math.round(gap * fs)
8
+ let out = new Float32Array(digits.length * (toneN + gapN))
9
+ let pos = 0
10
+ for (let d of String(digits).toUpperCase()) {
11
+ let r = ROW[d], c = COL[d]
12
+ if (r) for (let i = 0; i < toneN; i++) out[pos + i] = amp * (Math.sin(2 * Math.PI * r * i / fs) + Math.sin(2 * Math.PI * c * i / fs))
13
+ pos += toneN + gapN
14
+ }
15
+ return out
16
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@audio/synth-dtmf",
3
+ "version": "1.0.0",
4
+ "description": "DTMF dial tones — ITU-T Q.23 row/column pairs per digit",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "dtmf.js",
8
+ "exports": {
9
+ ".": "./dtmf.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "dtmf.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "synth",
19
+ "dtmf"
20
+ ],
21
+ "license": "MIT",
22
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }