@audio/effect-ringmod 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/package.json +38 -0
  2. package/ring-mod.js +26 -0
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@audio/effect-ringmod",
3
+ "version": "1.0.0",
4
+ "description": "Ring modulator — multiplies signal by a carrier oscillator",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "ring-mod.js",
8
+ "exports": {
9
+ ".": "./ring-mod.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "ring-mod.js"
14
+ ],
15
+ "keywords": [
16
+ "audio",
17
+ "dsp",
18
+ "effect",
19
+ "ringmod"
20
+ ],
21
+ "license": "MIT",
22
+ "author": "Dmitry Iv. <dfcreative@gmail.com>",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/audiojs/effect.git",
26
+ "directory": "packages/effect-ringmod"
27
+ },
28
+ "homepage": "https://github.com/audiojs/effect/tree/main/packages/effect-ringmod",
29
+ "bugs": {
30
+ "url": "https://github.com/audiojs/effect/issues"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }
package/ring-mod.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Ring modulator — multiplies signal by a carrier oscillator
3
+ */
4
+
5
+ let {sin, PI} = Math
6
+
7
+ export default function ringMod (data, params) {
8
+ let fc = params.fc || 440
9
+ let fs = params.fs || 44100
10
+ let mix = params.mix == null ? 1 : params.mix
11
+
12
+ if (params._phase == null) params._phase = 0
13
+ let phase = params._phase
14
+ let inc = 2 * PI * fc / fs
15
+
16
+ for (let i = 0, l = data.length; i < l; i++) {
17
+ let carrier = sin(phase)
18
+ phase += inc
19
+ if (phase > 2 * PI) phase -= 2 * PI
20
+ data[i] = data[i] * (1 - mix) + data[i] * carrier * mix
21
+ }
22
+
23
+ params._phase = phase
24
+
25
+ return data
26
+ }