@thi.ng/dsp 4.1.5 → 4.2.2

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-03-11T12:13:49Z
3
+ - **Last updated**: 2022-05-07T11:33:35Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [4.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@4.2.0) (2022-04-07)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add opt Osc() ctor phase arg, fix [#340](https://github.com/thi-ng/umbrella/issues/340) ([f798c9d](https://github.com/thi-ng/umbrella/commit/f798c9d))
17
+ - update osc() factory fn
18
+ - update Osc.setFreq() signatures
19
+ - add tests
20
+ - add/update docs
21
+
12
22
  ## [4.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/dsp@4.1.0) (2021-11-17)
13
23
 
14
24
  #### 🚀 Features
package/README.md CHANGED
@@ -86,7 +86,7 @@ node --experimental-repl-await
86
86
  > const dsp = await import("@thi.ng/dsp");
87
87
  ```
88
88
 
89
- Package sizes (gzipped, pre-treeshake): ESM: 7.54 KB
89
+ Package sizes (gzipped, pre-treeshake): ESM: 7.56 KB
90
90
 
91
91
  ## Dependencies
92
92
 
package/osc.d.ts CHANGED
@@ -1,29 +1,28 @@
1
1
  import { AGen } from "./agen.js";
2
2
  import type { IGen, StatelessOscillator } from "./api.js";
3
3
  /**
4
- * Higher order oscillator gen, wrapping a {@link StatelessOscillator}
5
- * function and supporting either constant or {@link IGen}-based
6
- * frequency and amplitude, thus allowing for FM/AM modulation.
7
- * Furthermore, a constant `dc` offset (center value) can be specified
8
- * (default: 0).
4
+ * Higher order oscillator gen, wrapping a {@link StatelessOscillator} function
5
+ * and supporting either constant or {@link IGen}-based frequency and amplitude,
6
+ * thus allowing for FM/AM modulation. Furthermore, a constant `dc` offset
7
+ * (center value) and/or start `phase` can be specified (both default to: 0).
9
8
  *
10
9
  * @remarks
11
- * If `freq` is a number, it must be given as normalized frequency. If
12
- * `freq` is an `IGen`, it must be configured to produce normalized
13
- * frequency values (e.g. if using an `Osc` by setting its `amp` to a
14
- * normalized freq and its `dc` offset to `baseFreq * TAU`). Also see
15
- * {@link fmodOsc} for syntax sugar.
10
+ * If `freq` is a number, it must be given as normalized frequency (same for
11
+ * `phase`). If `freq` is an `IGen`, it must be configured to produce normalized
12
+ * frequency values (e.g. if using an `Osc` by setting its `amp` to a normalized
13
+ * freq and its `dc` offset to `baseFreq * TAU`). Also see {@link fmodOsc} for
14
+ * syntax sugar. The `phase` arg is only used if `freq` is NOT an `IGen`.
16
15
  *
17
- * The oscillator initializes to zero and its
18
- * {@link @thi.ng/api#IDeref.deref} value is only available / valid
19
- * after the first invocation of {@link IGen.next}.
16
+ * The oscillator initializes to zero and its {@link @thi.ng/api#IDeref.deref}
17
+ * value is only available / valid after the first invocation of
18
+ * {@link IGen.next}.
20
19
  *
21
20
  * @param osc - stateless osc
22
21
  * @param freq - normalized freq
23
22
  * @param amp - amplitude
24
23
  * @param dc - DC offset / center value
25
24
  */
26
- export declare const osc: (osc: StatelessOscillator, freq: IGen<number> | number, amp?: number | IGen<number> | undefined, dc?: number | undefined) => Osc;
25
+ export declare const osc: (osc: StatelessOscillator, freq: IGen<number> | number, amp?: number | IGen<number> | undefined, dc?: number | undefined, phase?: number | undefined) => Osc;
27
26
  /**
28
27
  * Syntax sugar for creating frequency modulated `Osc` gens.
29
28
  *
@@ -52,9 +51,10 @@ export declare class Osc extends AGen<number> {
52
51
  protected _dc: number;
53
52
  protected _phase: IGen<number>;
54
53
  protected _amp: IGen<number>;
55
- constructor(_osc: StatelessOscillator, freq: IGen<number> | number, amp?: IGen<number> | number, _dc?: number);
54
+ constructor(_osc: StatelessOscillator, freq: IGen<number> | number, amp?: IGen<number> | number, _dc?: number, phase?: number);
56
55
  next(): number;
57
- setFreq(freq: IGen<number> | number, phase?: number): void;
56
+ setFreq(freq: IGen<number>): void;
57
+ setFreq(freq: number, phase?: number): void;
58
58
  setAmp(amp: IGen<number> | number): void;
59
59
  }
60
60
  //# sourceMappingURL=osc.d.ts.map
package/osc.js CHANGED
@@ -4,29 +4,28 @@ import { AGen } from "./agen.js";
4
4
  import { Const } from "./const.js";
5
5
  import { sum } from "./sum.js";
6
6
  /**
7
- * Higher order oscillator gen, wrapping a {@link StatelessOscillator}
8
- * function and supporting either constant or {@link IGen}-based
9
- * frequency and amplitude, thus allowing for FM/AM modulation.
10
- * Furthermore, a constant `dc` offset (center value) can be specified
11
- * (default: 0).
7
+ * Higher order oscillator gen, wrapping a {@link StatelessOscillator} function
8
+ * and supporting either constant or {@link IGen}-based frequency and amplitude,
9
+ * thus allowing for FM/AM modulation. Furthermore, a constant `dc` offset
10
+ * (center value) and/or start `phase` can be specified (both default to: 0).
12
11
  *
13
12
  * @remarks
14
- * If `freq` is a number, it must be given as normalized frequency. If
15
- * `freq` is an `IGen`, it must be configured to produce normalized
16
- * frequency values (e.g. if using an `Osc` by setting its `amp` to a
17
- * normalized freq and its `dc` offset to `baseFreq * TAU`). Also see
18
- * {@link fmodOsc} for syntax sugar.
13
+ * If `freq` is a number, it must be given as normalized frequency (same for
14
+ * `phase`). If `freq` is an `IGen`, it must be configured to produce normalized
15
+ * frequency values (e.g. if using an `Osc` by setting its `amp` to a normalized
16
+ * freq and its `dc` offset to `baseFreq * TAU`). Also see {@link fmodOsc} for
17
+ * syntax sugar. The `phase` arg is only used if `freq` is NOT an `IGen`.
19
18
  *
20
- * The oscillator initializes to zero and its
21
- * {@link @thi.ng/api#IDeref.deref} value is only available / valid
22
- * after the first invocation of {@link IGen.next}.
19
+ * The oscillator initializes to zero and its {@link @thi.ng/api#IDeref.deref}
20
+ * value is only available / valid after the first invocation of
21
+ * {@link IGen.next}.
23
22
  *
24
23
  * @param osc - stateless osc
25
24
  * @param freq - normalized freq
26
25
  * @param amp - amplitude
27
26
  * @param dc - DC offset / center value
28
27
  */
29
- export const osc = (osc, freq, amp, dc) => new Osc(osc, freq, amp, dc);
28
+ export const osc = (osc, freq, amp, dc, phase) => new Osc(osc, freq, amp, dc, phase);
30
29
  /**
31
30
  * Syntax sugar for creating frequency modulated `Osc` gens.
32
31
  *
@@ -51,18 +50,18 @@ export const osc = (osc, freq, amp, dc) => new Osc(osc, freq, amp, dc);
51
50
  */
52
51
  export const modOsc = (osc, freq, fmod, amod = 1) => new Osc(osc, sum(fmod, isNumber(freq) ? add(freq) : freq), amod);
53
52
  export class Osc extends AGen {
54
- constructor(_osc, freq, amp = 1, _dc = 0) {
53
+ constructor(_osc, freq, amp = 1, _dc = 0, phase = 0) {
55
54
  super(0);
56
55
  this._osc = _osc;
57
56
  this._dc = _dc;
58
- this.setFreq(freq);
57
+ isNumber(freq) ? this.setFreq(freq, phase) : this.setFreq(freq);
59
58
  this.setAmp(amp);
60
59
  }
61
60
  next() {
62
61
  return (this._val = this._osc(this._phase.next(), 1, this._amp.next(), this._dc));
63
62
  }
64
- setFreq(freq, phase = 0) {
65
- this._phase = isNumber(freq) ? new Add(freq, phase) : freq;
63
+ setFreq(freq, phase) {
64
+ this._phase = isNumber(freq) ? new Add(freq, phase || 0) : freq;
66
65
  }
67
66
  setAmp(amp) {
68
67
  this._amp = isNumber(amp) ? new Const(amp) : amp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/dsp",
3
- "version": "4.1.5",
3
+ "version": "4.2.2",
4
4
  "description": "Composable signal generators, oscillators, filters, FFT, spectrum, windowing & related DSP utils",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,20 +34,20 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.3.4",
38
- "@thi.ng/checks": "^3.1.4",
39
- "@thi.ng/errors": "^2.1.4",
40
- "@thi.ng/math": "^5.3.0",
41
- "@thi.ng/random": "^3.2.4",
42
- "@thi.ng/transducers": "^8.3.0"
37
+ "@thi.ng/api": "^8.3.6",
38
+ "@thi.ng/checks": "^3.1.6",
39
+ "@thi.ng/errors": "^2.1.6",
40
+ "@thi.ng/math": "^5.3.2",
41
+ "@thi.ng/random": "^3.3.0",
42
+ "@thi.ng/transducers": "^8.3.3"
43
43
  },
44
44
  "devDependencies": {
45
- "@microsoft/api-extractor": "^7.19.4",
46
- "@thi.ng/testament": "^0.2.4",
45
+ "@microsoft/api-extractor": "^7.23.1",
46
+ "@thi.ng/testament": "^0.2.7",
47
47
  "rimraf": "^3.0.2",
48
48
  "tools": "^0.0.1",
49
- "typedoc": "^0.22.13",
50
- "typescript": "^4.6.2"
49
+ "typedoc": "^0.22.15",
50
+ "typescript": "^4.6.4"
51
51
  },
52
52
  "keywords": [
53
53
  "allpass",
@@ -92,178 +92,178 @@
92
92
  ],
93
93
  "exports": {
94
94
  ".": {
95
- "import": "./index.js"
95
+ "default": "./index.js"
96
96
  },
97
97
  "./add": {
98
- "import": "./add.js"
98
+ "default": "./add.js"
99
99
  },
100
100
  "./addg": {
101
- "import": "./addg.js"
101
+ "default": "./addg.js"
102
102
  },
103
103
  "./adsr": {
104
- "import": "./adsr.js"
104
+ "default": "./adsr.js"
105
105
  },
106
106
  "./agen": {
107
- "import": "./agen.js"
107
+ "default": "./agen.js"
108
108
  },
109
109
  "./allpass": {
110
- "import": "./allpass.js"
110
+ "default": "./allpass.js"
111
111
  },
112
112
  "./alt": {
113
- "import": "./alt.js"
113
+ "default": "./alt.js"
114
114
  },
115
115
  "./anti-alias": {
116
- "import": "./anti-alias.js"
116
+ "default": "./anti-alias.js"
117
117
  },
118
118
  "./api": {
119
- "import": "./api.js"
119
+ "default": "./api.js"
120
120
  },
121
121
  "./aproc": {
122
- "import": "./aproc.js"
122
+ "default": "./aproc.js"
123
123
  },
124
124
  "./biquad": {
125
- "import": "./biquad.js"
125
+ "default": "./biquad.js"
126
126
  },
127
127
  "./bounce": {
128
- "import": "./bounce.js"
128
+ "default": "./bounce.js"
129
129
  },
130
130
  "./complex": {
131
- "import": "./complex.js"
131
+ "default": "./complex.js"
132
132
  },
133
133
  "./const": {
134
- "import": "./const.js"
134
+ "default": "./const.js"
135
135
  },
136
136
  "./convert": {
137
- "import": "./convert.js"
137
+ "default": "./convert.js"
138
138
  },
139
139
  "./cosine": {
140
- "import": "./cosine.js"
140
+ "default": "./cosine.js"
141
141
  },
142
142
  "./curve": {
143
- "import": "./curve.js"
143
+ "default": "./curve.js"
144
144
  },
145
145
  "./dcblock": {
146
- "import": "./dcblock.js"
146
+ "default": "./dcblock.js"
147
147
  },
148
148
  "./delay": {
149
- "import": "./delay.js"
149
+ "default": "./delay.js"
150
150
  },
151
151
  "./feedback-delay": {
152
- "import": "./feedback-delay.js"
152
+ "default": "./feedback-delay.js"
153
153
  },
154
154
  "./fft": {
155
- "import": "./fft.js"
155
+ "default": "./fft.js"
156
156
  },
157
157
  "./filter-response": {
158
- "import": "./filter-response.js"
158
+ "default": "./filter-response.js"
159
159
  },
160
160
  "./foldback": {
161
- "import": "./foldback.js"
161
+ "default": "./foldback.js"
162
162
  },
163
163
  "./impulse-train": {
164
- "import": "./impulse-train.js"
164
+ "default": "./impulse-train.js"
165
165
  },
166
166
  "./impulse": {
167
- "import": "./impulse.js"
167
+ "default": "./impulse.js"
168
168
  },
169
169
  "./integrator": {
170
- "import": "./integrator.js"
170
+ "default": "./integrator.js"
171
171
  },
172
172
  "./iterable": {
173
- "import": "./iterable.js"
173
+ "default": "./iterable.js"
174
174
  },
175
175
  "./line": {
176
- "import": "./line.js"
176
+ "default": "./line.js"
177
177
  },
178
178
  "./madd": {
179
- "import": "./madd.js"
179
+ "default": "./madd.js"
180
180
  },
181
181
  "./mapg": {
182
- "import": "./mapg.js"
182
+ "default": "./mapg.js"
183
183
  },
184
184
  "./mix": {
185
- "import": "./mix.js"
185
+ "default": "./mix.js"
186
186
  },
187
187
  "./mul": {
188
- "import": "./mul.js"
188
+ "default": "./mul.js"
189
189
  },
190
190
  "./multiplex": {
191
- "import": "./multiplex.js"
191
+ "default": "./multiplex.js"
192
192
  },
193
193
  "./onepole": {
194
- "import": "./onepole.js"
194
+ "default": "./onepole.js"
195
195
  },
196
196
  "./osc-additive": {
197
- "import": "./osc-additive.js"
197
+ "default": "./osc-additive.js"
198
198
  },
199
199
  "./osc-cos": {
200
- "import": "./osc-cos.js"
200
+ "default": "./osc-cos.js"
201
201
  },
202
202
  "./osc-dsf": {
203
- "import": "./osc-dsf.js"
203
+ "default": "./osc-dsf.js"
204
204
  },
205
205
  "./osc-mix": {
206
- "import": "./osc-mix.js"
206
+ "default": "./osc-mix.js"
207
207
  },
208
208
  "./osc-parabolic": {
209
- "import": "./osc-parabolic.js"
209
+ "default": "./osc-parabolic.js"
210
210
  },
211
211
  "./osc-rect": {
212
- "import": "./osc-rect.js"
212
+ "default": "./osc-rect.js"
213
213
  },
214
214
  "./osc-saw": {
215
- "import": "./osc-saw.js"
215
+ "default": "./osc-saw.js"
216
216
  },
217
217
  "./osc-sin": {
218
- "import": "./osc-sin.js"
218
+ "default": "./osc-sin.js"
219
219
  },
220
220
  "./osc-tri": {
221
- "import": "./osc-tri.js"
221
+ "default": "./osc-tri.js"
222
222
  },
223
223
  "./osc-wavetable": {
224
- "import": "./osc-wavetable.js"
224
+ "default": "./osc-wavetable.js"
225
225
  },
226
226
  "./osc": {
227
- "import": "./osc.js"
227
+ "default": "./osc.js"
228
228
  },
229
229
  "./pink-noise": {
230
- "import": "./pink-noise.js"
230
+ "default": "./pink-noise.js"
231
231
  },
232
232
  "./pipe": {
233
- "import": "./pipe.js"
233
+ "default": "./pipe.js"
234
234
  },
235
235
  "./power": {
236
- "import": "./power.js"
236
+ "default": "./power.js"
237
237
  },
238
238
  "./product": {
239
- "import": "./product.js"
239
+ "default": "./product.js"
240
240
  },
241
241
  "./reciprocal": {
242
- "import": "./reciprocal.js"
242
+ "default": "./reciprocal.js"
243
243
  },
244
244
  "./serial": {
245
- "import": "./serial.js"
245
+ "default": "./serial.js"
246
246
  },
247
247
  "./sincos": {
248
- "import": "./sincos.js"
248
+ "default": "./sincos.js"
249
249
  },
250
250
  "./sum": {
251
- "import": "./sum.js"
251
+ "default": "./sum.js"
252
252
  },
253
253
  "./svf": {
254
- "import": "./svf.js"
254
+ "default": "./svf.js"
255
255
  },
256
256
  "./sweep": {
257
- "import": "./sweep.js"
257
+ "default": "./sweep.js"
258
258
  },
259
259
  "./waveshaper": {
260
- "import": "./waveshaper.js"
260
+ "default": "./waveshaper.js"
261
261
  },
262
262
  "./white-noise": {
263
- "import": "./white-noise.js"
263
+ "default": "./white-noise.js"
264
264
  },
265
265
  "./window": {
266
- "import": "./window.js"
266
+ "default": "./window.js"
267
267
  }
268
268
  },
269
269
  "thi.ng": {
@@ -272,5 +272,5 @@
272
272
  ],
273
273
  "year": 2015
274
274
  },
275
- "gitHead": "0fc692a3225c068aacafdc4cb6140cf603c67ad8\n"
275
+ "gitHead": "e23901b8582af71d8a29e0ce4929f15ac509f9e5\n"
276
276
  }