@jtarrio/signals 0.9.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 +203 -0
- package/README.md +54 -0
- package/dist/demod/demod-am.d.ts +55 -0
- package/dist/demod/demod-am.d.ts.map +1 -0
- package/dist/demod/demod-am.js +118 -0
- package/dist/demod/demod-am.js.map +1 -0
- package/dist/demod/demod-cw.d.ts +49 -0
- package/dist/demod/demod-cw.d.ts.map +1 -0
- package/dist/demod/demod-cw.js +106 -0
- package/dist/demod/demod-cw.js.map +1 -0
- package/dist/demod/demod-nbfm.d.ts +55 -0
- package/dist/demod/demod-nbfm.d.ts.map +1 -0
- package/dist/demod/demod-nbfm.js +119 -0
- package/dist/demod/demod-nbfm.js.map +1 -0
- package/dist/demod/demod-ssb.d.ts +56 -0
- package/dist/demod/demod-ssb.d.ts.map +1 -0
- package/dist/demod/demod-ssb.js +118 -0
- package/dist/demod/demod-ssb.js.map +1 -0
- package/dist/demod/demod-wbfm.d.ts +114 -0
- package/dist/demod/demod-wbfm.d.ts.map +1 -0
- package/dist/demod/demod-wbfm.js +226 -0
- package/dist/demod/demod-wbfm.js.map +1 -0
- package/dist/demod/demodulator.d.ts +3 -0
- package/dist/demod/demodulator.d.ts.map +1 -0
- package/dist/demod/demodulator.js +28 -0
- package/dist/demod/demodulator.js.map +1 -0
- package/dist/demod/empty-demodulator.d.ts +78 -0
- package/dist/demod/empty-demodulator.d.ts.map +1 -0
- package/dist/demod/empty-demodulator.js +148 -0
- package/dist/demod/empty-demodulator.js.map +1 -0
- package/dist/demod/modes.d.ts +113 -0
- package/dist/demod/modes.d.ts.map +1 -0
- package/dist/demod/modes.js +107 -0
- package/dist/demod/modes.js.map +1 -0
- package/dist/demod/player.d.ts +19 -0
- package/dist/demod/player.d.ts.map +1 -0
- package/dist/demod/player.js +15 -0
- package/dist/demod/player.js.map +1 -0
- package/dist/demod/sample-counter.d.ts +22 -0
- package/dist/demod/sample-counter.d.ts.map +1 -0
- package/dist/demod/sample-counter.js +57 -0
- package/dist/demod/sample-counter.js.map +1 -0
- package/dist/demod/spectrum.d.ts +23 -0
- package/dist/demod/spectrum.d.ts.map +1 -0
- package/dist/demod/spectrum.js +76 -0
- package/dist/demod/spectrum.js.map +1 -0
- package/dist/dsp/buffers.d.ts +127 -0
- package/dist/dsp/buffers.d.ts.map +1 -0
- package/dist/dsp/buffers.js +171 -0
- package/dist/dsp/buffers.js.map +1 -0
- package/dist/dsp/coefficients.d.ts +23 -0
- package/dist/dsp/coefficients.d.ts.map +1 -0
- package/dist/dsp/coefficients.js +81 -0
- package/dist/dsp/coefficients.js.map +1 -0
- package/dist/dsp/converters.d.ts +15 -0
- package/dist/dsp/converters.d.ts.map +1 -0
- package/dist/dsp/converters.js +43 -0
- package/dist/dsp/converters.js.map +1 -0
- package/dist/dsp/demodulators.d.ts +68 -0
- package/dist/dsp/demodulators.d.ts.map +1 -0
- package/dist/dsp/demodulators.js +149 -0
- package/dist/dsp/demodulators.js.map +1 -0
- package/dist/dsp/fft.d.ts +54 -0
- package/dist/dsp/fft.d.ts.map +1 -0
- package/dist/dsp/fft.js +175 -0
- package/dist/dsp/fft.js.map +1 -0
- package/dist/dsp/filters.d.ts +197 -0
- package/dist/dsp/filters.d.ts.map +1 -0
- package/dist/dsp/filters.js +486 -0
- package/dist/dsp/filters.js.map +1 -0
- package/dist/dsp/math.d.ts +10 -0
- package/dist/dsp/math.d.ts.map +1 -0
- package/dist/dsp/math.js +55 -0
- package/dist/dsp/math.js.map +1 -0
- package/dist/dsp/power.d.ts +2 -0
- package/dist/dsp/power.d.ts.map +1 -0
- package/dist/dsp/power.js +23 -0
- package/dist/dsp/power.js.map +1 -0
- package/dist/dsp/resamplers.d.ts +45 -0
- package/dist/dsp/resamplers.d.ts.map +1 -0
- package/dist/dsp/resamplers.js +85 -0
- package/dist/dsp/resamplers.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/players/audioplayer.d.ts +25 -0
- package/dist/players/audioplayer.d.ts.map +1 -0
- package/dist/players/audioplayer.js +68 -0
- package/dist/players/audioplayer.js.map +1 -0
- package/dist/radio/msgqueue.d.ts +32 -0
- package/dist/radio/msgqueue.d.ts.map +1 -0
- package/dist/radio/msgqueue.js +62 -0
- package/dist/radio/msgqueue.js.map +1 -0
- package/dist/radio/radio.d.ts +107 -0
- package/dist/radio/radio.d.ts.map +1 -0
- package/dist/radio/radio.js +279 -0
- package/dist/radio/radio.js.map +1 -0
- package/dist/radio/sample_receiver.d.ts +17 -0
- package/dist/radio/sample_receiver.d.ts.map +1 -0
- package/dist/radio/sample_receiver.js +52 -0
- package/dist/radio/sample_receiver.js.map +1 -0
- package/dist/radio/signal_source.d.ts +53 -0
- package/dist/radio/signal_source.d.ts.map +1 -0
- package/dist/radio/signal_source.js +15 -0
- package/dist/radio/signal_source.js.map +1 -0
- package/dist/radio.d.ts +4 -0
- package/dist/radio.d.ts.map +1 -0
- package/dist/radio.js +4 -0
- package/dist/radio.js.map +1 -0
- package/dist/sources/generators.d.ts +41 -0
- package/dist/sources/generators.d.ts.map +1 -0
- package/dist/sources/generators.js +238 -0
- package/dist/sources/generators.js.map +1 -0
- package/dist/sources/provider.d.ts +7 -0
- package/dist/sources/provider.d.ts.map +1 -0
- package/dist/sources/provider.js +23 -0
- package/dist/sources/provider.js.map +1 -0
- package/dist/sources/push.d.ts +30 -0
- package/dist/sources/push.d.ts.map +1 -0
- package/dist/sources/push.js +106 -0
- package/dist/sources/push.js.map +1 -0
- package/dist/sources/read_ring.d.ts +14 -0
- package/dist/sources/read_ring.d.ts.map +1 -0
- package/dist/sources/read_ring.js +59 -0
- package/dist/sources/read_ring.js.map +1 -0
- package/dist/sources/realtime.d.ts +44 -0
- package/dist/sources/realtime.d.ts.map +1 -0
- package/dist/sources/realtime.js +136 -0
- package/dist/sources/realtime.js.map +1 -0
- package/package.json +25 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright 2024 Jacobo Tarrio Barreiro. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
/** A SampleReceiver that counts received samples to send a `sample-click` event periodically. */
|
|
15
|
+
export class SampleCounter extends EventTarget {
|
|
16
|
+
clicksPerSecond;
|
|
17
|
+
/**
|
|
18
|
+
* @param sampleRate The initial sample rate.
|
|
19
|
+
* @param clicksPerSecond The number of events per second.
|
|
20
|
+
*/
|
|
21
|
+
constructor(clicksPerSecond) {
|
|
22
|
+
super();
|
|
23
|
+
this.clicksPerSecond = clicksPerSecond;
|
|
24
|
+
this.sampleRate = 1024000;
|
|
25
|
+
this.samplesPerClick = this.getSamplesPerClick();
|
|
26
|
+
this.countedSamples = 0;
|
|
27
|
+
}
|
|
28
|
+
sampleRate;
|
|
29
|
+
samplesPerClick;
|
|
30
|
+
countedSamples;
|
|
31
|
+
getSamplesPerClick() {
|
|
32
|
+
return this.clicksPerSecond === undefined
|
|
33
|
+
? undefined
|
|
34
|
+
: Math.floor(this.sampleRate / this.clicksPerSecond);
|
|
35
|
+
}
|
|
36
|
+
setSampleRate(sampleRate) {
|
|
37
|
+
this.sampleRate = sampleRate;
|
|
38
|
+
this.samplesPerClick = this.getSamplesPerClick();
|
|
39
|
+
}
|
|
40
|
+
receiveSamples(I, Q) {
|
|
41
|
+
this.countedSamples += I.length;
|
|
42
|
+
if (this.samplesPerClick === undefined ||
|
|
43
|
+
this.samplesPerClick > this.countedSamples)
|
|
44
|
+
return;
|
|
45
|
+
this.countedSamples %= this.samplesPerClick;
|
|
46
|
+
this.dispatchEvent(new SampleClickEvent());
|
|
47
|
+
}
|
|
48
|
+
addEventListener(type, callback, options) {
|
|
49
|
+
super.addEventListener(type, callback, options);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class SampleClickEvent extends Event {
|
|
53
|
+
constructor() {
|
|
54
|
+
super("sample-click");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=sample-counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample-counter.js","sourceRoot":"","sources":["../../src/demod/sample-counter.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,iGAAiG;AACjG,MAAM,OAAO,aAAc,SAAQ,WAAW;IAKxB;IAJpB;;;OAGG;IACH,YAAoB,eAAwB;QAC1C,KAAK,EAAE,CAAC;QADU,oBAAe,GAAf,eAAe,CAAS;QAE1C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC;QAC1B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACjD,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEO,UAAU,CAAS;IACnB,eAAe,CAAU;IACzB,cAAc,CAAS;IAEvB,kBAAkB;QACxB,OAAO,IAAI,CAAC,eAAe,KAAK,SAAS;YACvC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC;IACzD,CAAC;IAED,aAAa,CAAC,UAAkB;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;IACnD,CAAC;IAED,cAAc,CAAC,CAAe,EAAE,CAAe;QAC7C,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC,MAAM,CAAC;QAChC,IACE,IAAI,CAAC,eAAe,KAAK,SAAS;YAClC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,cAAc;YAE1C,OAAO;QACT,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,eAAe,CAAC;QAC5C,IAAI,CAAC,aAAa,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAC;IAC7C,CAAC;IAYD,gBAAgB,CACd,IAAY,EACZ,QAAa,EACb,OAAuD;QAEvD,KAAK,CAAC,gBAAgB,CACpB,IAAI,EACJ,QAAqD,EACrD,OAAO,CACR,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,cAAc,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SampleReceiver } from "../radio/sample_receiver.js";
|
|
2
|
+
/** A sample receiver that computes the received signal's spectrum. */
|
|
3
|
+
export declare class Spectrum implements SampleReceiver {
|
|
4
|
+
constructor(fftSize?: number);
|
|
5
|
+
private I;
|
|
6
|
+
private Q;
|
|
7
|
+
private lastFrequency;
|
|
8
|
+
private fft;
|
|
9
|
+
private lastOutput;
|
|
10
|
+
private dirty;
|
|
11
|
+
set size(newSize: number);
|
|
12
|
+
get size(): number;
|
|
13
|
+
setSampleRate(_: number): void;
|
|
14
|
+
receiveSamples(I: Float32Array, Q: Float32Array, frequency: number): void;
|
|
15
|
+
frequency(): number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Populates the given array with the spectrum of the latest received signals.
|
|
18
|
+
* For best results, the array should have at least `size` entries; if it's smaller,
|
|
19
|
+
* it will be filled with whatever fits.
|
|
20
|
+
*/
|
|
21
|
+
getSpectrum(spectrum: Float32Array): void;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=spectrum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spectrum.d.ts","sourceRoot":"","sources":["../../src/demod/spectrum.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,sEAAsE;AACtE,qBAAa,QAAS,YAAW,cAAc;gBACjC,OAAO,CAAC,EAAE,MAAM;IAc5B,OAAO,CAAC,CAAC,CAAoB;IAC7B,OAAO,CAAC,CAAC,CAAoB;IAC7B,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,KAAK,CAAU;IAEvB,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,EAKvB;IAED,IAAI,IAAI,IAPU,MAAM,CASvB;IAED,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAE9B,cAAc,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAOzE,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,YAAY;CAWnC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright 2024 Jacobo Tarrio Barreiro. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
// Continuous spectrum analyzer.
|
|
15
|
+
import { Float32RingBuffer } from "../dsp/buffers.js";
|
|
16
|
+
import { makeBlackmanWindow } from "../dsp/coefficients.js";
|
|
17
|
+
import { FFT } from "../dsp/fft.js";
|
|
18
|
+
/** A sample receiver that computes the received signal's spectrum. */
|
|
19
|
+
export class Spectrum {
|
|
20
|
+
constructor(fftSize) {
|
|
21
|
+
if (fftSize === undefined) {
|
|
22
|
+
fftSize = 2048;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
fftSize = Math.max(32, Math.min(131072, fftSize));
|
|
26
|
+
}
|
|
27
|
+
this.I = new Float32RingBuffer(131072);
|
|
28
|
+
this.Q = new Float32RingBuffer(131072);
|
|
29
|
+
this.fft = FFT.ofLength(fftSize);
|
|
30
|
+
this.fft.setWindow(makeBlackmanWindow(this.fft.length));
|
|
31
|
+
this.lastOutput = new Float32Array(this.fft.length);
|
|
32
|
+
this.dirty = true;
|
|
33
|
+
}
|
|
34
|
+
I;
|
|
35
|
+
Q;
|
|
36
|
+
lastFrequency;
|
|
37
|
+
fft;
|
|
38
|
+
lastOutput;
|
|
39
|
+
dirty;
|
|
40
|
+
set size(newSize) {
|
|
41
|
+
this.fft = FFT.ofLength(newSize);
|
|
42
|
+
this.fft.setWindow(makeBlackmanWindow(this.fft.length));
|
|
43
|
+
this.lastOutput = new Float32Array(this.fft.length);
|
|
44
|
+
this.dirty = true;
|
|
45
|
+
}
|
|
46
|
+
get size() {
|
|
47
|
+
return this.fft.length;
|
|
48
|
+
}
|
|
49
|
+
setSampleRate(_) { }
|
|
50
|
+
receiveSamples(I, Q, frequency) {
|
|
51
|
+
this.I.store(I);
|
|
52
|
+
this.Q.store(Q);
|
|
53
|
+
this.lastFrequency = frequency;
|
|
54
|
+
this.dirty = true;
|
|
55
|
+
}
|
|
56
|
+
frequency() {
|
|
57
|
+
return this.lastFrequency;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Populates the given array with the spectrum of the latest received signals.
|
|
61
|
+
* For best results, the array should have at least `size` entries; if it's smaller,
|
|
62
|
+
* it will be filled with whatever fits.
|
|
63
|
+
*/
|
|
64
|
+
getSpectrum(spectrum) {
|
|
65
|
+
if (this.dirty) {
|
|
66
|
+
let fft = this.fft.transformCircularBuffers(this.I, this.Q);
|
|
67
|
+
this.lastOutput.fill(-Infinity);
|
|
68
|
+
for (let i = 0; i < this.lastOutput.length; ++i) {
|
|
69
|
+
this.lastOutput[i] = 20 * Math.log10(Math.hypot(fft[0][i], fft[1][i]));
|
|
70
|
+
}
|
|
71
|
+
this.dirty = false;
|
|
72
|
+
}
|
|
73
|
+
spectrum.set(this.lastOutput.subarray(0, spectrum.length));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=spectrum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spectrum.js","sourceRoot":"","sources":["../../src/demod/spectrum.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,gCAAgC;AAEhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,sEAAsE;AACtE,MAAM,OAAO,QAAQ;IACnB,YAAY,OAAgB;QAC1B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,GAAG,IA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AE,SAAiB;QAChE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,QAAsB;QAChC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YAC5D,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;YAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;gBAChD,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACzE,CAAC;YACD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fixed-size pool of pre-allocated arrays.
|
|
3
|
+
*
|
|
4
|
+
* Each call to get() returns the next array of the pool, if it's already the requested size.
|
|
5
|
+
* If the next array is larger than the requested size, the function returns a subarray.
|
|
6
|
+
* If the next array is smaller than the requested size, the function allocates a new array,
|
|
7
|
+
* replaces the old array with the new array, and returns that one.
|
|
8
|
+
*/
|
|
9
|
+
declare abstract class Pool<T extends TypedArray<T>> {
|
|
10
|
+
private make;
|
|
11
|
+
/**
|
|
12
|
+
* @param make A function that returns an array of the given length.
|
|
13
|
+
* @param count The number of arrays to keep around. Having more than 1 lets you modify one array while you use another.
|
|
14
|
+
* @param length An optional initial length for the arrays.
|
|
15
|
+
*/
|
|
16
|
+
constructor(make: (length: number) => T, count: number, length?: number);
|
|
17
|
+
private buffers;
|
|
18
|
+
private current;
|
|
19
|
+
/** Returns an array of the given size. You may need to clear it manually. */
|
|
20
|
+
get(length: number): T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A fixed-size pool of pre-allocated Uint8Arrays.
|
|
24
|
+
*/
|
|
25
|
+
export declare class U8Pool extends Pool<Uint8Array> {
|
|
26
|
+
/**
|
|
27
|
+
* @param count The number of arrays to keep around. Having more than 1 lets you modify one array while you use another.
|
|
28
|
+
* @param length An optional initial size for the arrays.
|
|
29
|
+
*/
|
|
30
|
+
constructor(count: number, length?: number);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A fixed-size pool of pre-allocated Float32Arrays.
|
|
34
|
+
*/
|
|
35
|
+
export declare class Float32Pool extends Pool<Float32Array> {
|
|
36
|
+
/**
|
|
37
|
+
* @param count The number of arrays to keep around. Having more than 1 lets you modify one array while you use another.
|
|
38
|
+
* @param length An optional initial size for the arrays.
|
|
39
|
+
*/
|
|
40
|
+
constructor(count: number, length?: number);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A pool of pre-allocated [Float32Array, Float32Array] array pairs.
|
|
44
|
+
*/
|
|
45
|
+
export declare class IqPool {
|
|
46
|
+
/**
|
|
47
|
+
* @param count The number of array pairs to keep around. Having more than 1 lets you modify one pair while you use another.
|
|
48
|
+
* @param length An optional initial size for the arrays.
|
|
49
|
+
*/
|
|
50
|
+
constructor(count: number, length?: number);
|
|
51
|
+
private pools;
|
|
52
|
+
/** Returns a pair of arrays of the given size. You may need to clear them manually. */
|
|
53
|
+
get(length: number): [Float32Array, Float32Array];
|
|
54
|
+
}
|
|
55
|
+
interface TypedArray<T> {
|
|
56
|
+
readonly BYTES_PER_ELEMENT: number;
|
|
57
|
+
readonly buffer: ArrayBufferLike;
|
|
58
|
+
readonly byteLength: number;
|
|
59
|
+
readonly byteOffset: number;
|
|
60
|
+
copyWithin(target: number, start: number, end?: number): this;
|
|
61
|
+
every(predicate: (value: number, index: number, array: this) => unknown, thisArg?: any): boolean;
|
|
62
|
+
fill(value: number, start?: number, end?: number): this;
|
|
63
|
+
filter(predicate: (value: number, index: number, array: this) => any, thisArg?: any): T;
|
|
64
|
+
find(predicate: (value: number, index: number, obj: this) => boolean, thisArg?: any): number | undefined;
|
|
65
|
+
findIndex(predicate: (value: number, index: number, obj: this) => boolean, thisArg?: any): number;
|
|
66
|
+
forEach(callbackfn: (value: number, index: number, array: this) => void, thisArg?: any): void;
|
|
67
|
+
indexOf(searchElement: number, fromIndex?: number): number;
|
|
68
|
+
join(separator?: string): string;
|
|
69
|
+
lastIndexOf(searchElement: number, fromIndex?: number): number;
|
|
70
|
+
readonly length: number;
|
|
71
|
+
map(callbackfn: (value: number, index: number, array: this) => number, thisArg?: any): T;
|
|
72
|
+
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number): number;
|
|
73
|
+
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number, initialValue: number): number;
|
|
74
|
+
reduce<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: this) => U, initialValue: U): U;
|
|
75
|
+
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number): number;
|
|
76
|
+
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: this) => number, initialValue: number): number;
|
|
77
|
+
reduceRight<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: this) => U, initialValue: U): U;
|
|
78
|
+
reverse(): this;
|
|
79
|
+
set(array: ArrayLike<number>, offset?: number): void;
|
|
80
|
+
slice(start?: number, end?: number): T;
|
|
81
|
+
some(predicate: (value: number, index: number, array: this) => unknown, thisArg?: any): boolean;
|
|
82
|
+
sort(compareFn?: (a: number, b: number) => number): this;
|
|
83
|
+
subarray(begin?: number, end?: number): T;
|
|
84
|
+
toLocaleString(): string;
|
|
85
|
+
toString(): string;
|
|
86
|
+
valueOf(): this;
|
|
87
|
+
[index: number]: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A variable-size ring buffer, where you can store data and then access up to the latest N values.
|
|
91
|
+
*/
|
|
92
|
+
declare class RingBuffer<T extends TypedArray<T>> {
|
|
93
|
+
private buffer;
|
|
94
|
+
constructor(buffer: T);
|
|
95
|
+
private readPos;
|
|
96
|
+
private writePos;
|
|
97
|
+
private filled;
|
|
98
|
+
/** Returns the ring buffer's capacity. */
|
|
99
|
+
get capacity(): number;
|
|
100
|
+
/** Returns the number of values that can be accessed using moveTo. */
|
|
101
|
+
get available(): number;
|
|
102
|
+
/** Empties the ring buffer. */
|
|
103
|
+
clear(): void;
|
|
104
|
+
/** Copies the provided data into the ring buffer. */
|
|
105
|
+
store(data: T): void;
|
|
106
|
+
/**
|
|
107
|
+
* Fills the provided array with values from the ring buffer,
|
|
108
|
+
* consuming it in the same order as the values were written.
|
|
109
|
+
* Returns the number of values copied.
|
|
110
|
+
*/
|
|
111
|
+
moveTo(data: T): number;
|
|
112
|
+
/**
|
|
113
|
+
* Fills the provided array with the latest values stored in the ring buffer,
|
|
114
|
+
* without consuming it and without taking into account the values consumed
|
|
115
|
+
* by moveTo.
|
|
116
|
+
*/
|
|
117
|
+
copyTo(data: T): void;
|
|
118
|
+
private doCopy;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A Float32 variable-size ring buffer, where you can store data and then retrieve the latest N values.
|
|
122
|
+
*/
|
|
123
|
+
export declare class Float32RingBuffer extends RingBuffer<Float32Array> {
|
|
124
|
+
constructor(size: number);
|
|
125
|
+
}
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=buffers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffers.d.ts","sourceRoot":"","sources":["../../src/dsp/buffers.ts"],"names":[],"mappings":"AAcA;;;;;;;GAOG;AACH,uBAAe,IAAI,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC;IAOvC,OAAO,CAAC,IAAI;IANd;;;;OAIG;gBAEO,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,EACnC,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM;IAMjB,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,OAAO,CAAS;IAExB,6EAA6E;IAC7E,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC;CAUvB;AAED;;GAEG;AACH,qBAAa,MAAO,SAAQ,IAAI,CAAC,UAAU,CAAC;IAC1C;;;OAGG;gBACS,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAG3C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,IAAI,CAAC,YAAY,CAAC;IACjD;;;OAGG;gBACS,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAG3C;AAED;;GAEG;AACH,qBAAa,MAAM;IACjB;;;OAGG;gBACS,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAI1C,OAAO,CAAC,KAAK,CAAc;IAE3B,uFAAuF;IACvF,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC;CAGlD;AAED,UAAU,UAAU,CAAC,CAAC;IAClB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ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,WAEZ;IAED,+BAA+B;IAC/B,KAAK;IAML,qDAAqD;IACrD,KAAK,CAAC,IAAI,EAAE,CAAC;IAgBb;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM;IASvB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC;IAOd,OAAO,CAAC,MAAM;CAoBf;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,UAAU,CAAC,YAAY,CAAC;gBACjD,IAAI,EAAE,MAAM;CAGzB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Copyright 2024 Jacobo Tarrio Barreiro. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
/**
|
|
15
|
+
* A fixed-size pool of pre-allocated arrays.
|
|
16
|
+
*
|
|
17
|
+
* Each call to get() returns the next array of the pool, if it's already the requested size.
|
|
18
|
+
* If the next array is larger than the requested size, the function returns a subarray.
|
|
19
|
+
* If the next array is smaller than the requested size, the function allocates a new array,
|
|
20
|
+
* replaces the old array with the new array, and returns that one.
|
|
21
|
+
*/
|
|
22
|
+
class Pool {
|
|
23
|
+
make;
|
|
24
|
+
/**
|
|
25
|
+
* @param make A function that returns an array of the given length.
|
|
26
|
+
* @param count The number of arrays to keep around. Having more than 1 lets you modify one array while you use another.
|
|
27
|
+
* @param length An optional initial length for the arrays.
|
|
28
|
+
*/
|
|
29
|
+
constructor(make, count, length) {
|
|
30
|
+
this.make = make;
|
|
31
|
+
this.buffers = [...Array(count).keys()].map(() => make(length || 0));
|
|
32
|
+
this.current = 0;
|
|
33
|
+
}
|
|
34
|
+
buffers;
|
|
35
|
+
current;
|
|
36
|
+
/** Returns an array of the given size. You may need to clear it manually. */
|
|
37
|
+
get(length) {
|
|
38
|
+
let out = this.buffers[this.current];
|
|
39
|
+
if (out.length < length) {
|
|
40
|
+
out = this.make(length);
|
|
41
|
+
this.buffers[this.current] = out;
|
|
42
|
+
}
|
|
43
|
+
this.current = (this.current + 1) % this.buffers.length;
|
|
44
|
+
if (out.length == length)
|
|
45
|
+
return out;
|
|
46
|
+
return out.subarray(0, length);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A fixed-size pool of pre-allocated Uint8Arrays.
|
|
51
|
+
*/
|
|
52
|
+
export class U8Pool extends Pool {
|
|
53
|
+
/**
|
|
54
|
+
* @param count The number of arrays to keep around. Having more than 1 lets you modify one array while you use another.
|
|
55
|
+
* @param length An optional initial size for the arrays.
|
|
56
|
+
*/
|
|
57
|
+
constructor(count, length) {
|
|
58
|
+
super((l) => new Uint8Array(l), count, length);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A fixed-size pool of pre-allocated Float32Arrays.
|
|
63
|
+
*/
|
|
64
|
+
export class Float32Pool extends Pool {
|
|
65
|
+
/**
|
|
66
|
+
* @param count The number of arrays to keep around. Having more than 1 lets you modify one array while you use another.
|
|
67
|
+
* @param length An optional initial size for the arrays.
|
|
68
|
+
*/
|
|
69
|
+
constructor(count, length) {
|
|
70
|
+
super((l) => new Float32Array(l), count, length);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A pool of pre-allocated [Float32Array, Float32Array] array pairs.
|
|
75
|
+
*/
|
|
76
|
+
export class IqPool {
|
|
77
|
+
/**
|
|
78
|
+
* @param count The number of array pairs to keep around. Having more than 1 lets you modify one pair while you use another.
|
|
79
|
+
* @param length An optional initial size for the arrays.
|
|
80
|
+
*/
|
|
81
|
+
constructor(count, length) {
|
|
82
|
+
this.pools = new Float32Pool(count * 2, length);
|
|
83
|
+
}
|
|
84
|
+
pools;
|
|
85
|
+
/** Returns a pair of arrays of the given size. You may need to clear them manually. */
|
|
86
|
+
get(length) {
|
|
87
|
+
return [this.pools.get(length), this.pools.get(length)];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A variable-size ring buffer, where you can store data and then access up to the latest N values.
|
|
92
|
+
*/
|
|
93
|
+
class RingBuffer {
|
|
94
|
+
buffer;
|
|
95
|
+
constructor(buffer) {
|
|
96
|
+
this.buffer = buffer;
|
|
97
|
+
this.readPos = 0;
|
|
98
|
+
this.writePos = 0;
|
|
99
|
+
this.filled = 0;
|
|
100
|
+
}
|
|
101
|
+
readPos;
|
|
102
|
+
writePos;
|
|
103
|
+
filled;
|
|
104
|
+
/** Returns the ring buffer's capacity. */
|
|
105
|
+
get capacity() {
|
|
106
|
+
return this.buffer.length;
|
|
107
|
+
}
|
|
108
|
+
/** Returns the number of values that can be accessed using moveTo. */
|
|
109
|
+
get available() {
|
|
110
|
+
return this.filled;
|
|
111
|
+
}
|
|
112
|
+
/** Empties the ring buffer. */
|
|
113
|
+
clear() {
|
|
114
|
+
this.readPos = 0;
|
|
115
|
+
this.writePos = 0;
|
|
116
|
+
this.filled = 0;
|
|
117
|
+
}
|
|
118
|
+
/** Copies the provided data into the ring buffer. */
|
|
119
|
+
store(data) {
|
|
120
|
+
let count = Math.min(data.length, this.buffer.length);
|
|
121
|
+
let { dstOffset } = this.doCopy(count, data, data.length - count, this.buffer, this.writePos);
|
|
122
|
+
this.writePos = dstOffset;
|
|
123
|
+
this.filled = Math.min(this.buffer.length, this.filled + count);
|
|
124
|
+
if (this.filled == this.buffer.length) {
|
|
125
|
+
this.readPos = this.writePos;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Fills the provided array with values from the ring buffer,
|
|
130
|
+
* consuming it in the same order as the values were written.
|
|
131
|
+
* Returns the number of values copied.
|
|
132
|
+
*/
|
|
133
|
+
moveTo(data) {
|
|
134
|
+
let count = Math.min(data.length, this.buffer.length, this.filled);
|
|
135
|
+
if (count == 0)
|
|
136
|
+
return 0;
|
|
137
|
+
let { srcOffset } = this.doCopy(count, this.buffer, this.readPos, data, 0);
|
|
138
|
+
this.readPos = srcOffset;
|
|
139
|
+
this.filled -= count;
|
|
140
|
+
return count;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Fills the provided array with the latest values stored in the ring buffer,
|
|
144
|
+
* without consuming it and without taking into account the values consumed
|
|
145
|
+
* by moveTo.
|
|
146
|
+
*/
|
|
147
|
+
copyTo(data) {
|
|
148
|
+
let count = Math.min(data.length, this.buffer.length);
|
|
149
|
+
let srcOffset = (this.writePos + this.buffer.length - count) % this.buffer.length;
|
|
150
|
+
this.doCopy(count, this.buffer, srcOffset, data, 0);
|
|
151
|
+
}
|
|
152
|
+
doCopy(count, src, srcOffset, dst, dstOffset) {
|
|
153
|
+
while (count > 0) {
|
|
154
|
+
const copyCount = Math.min(count, src.length - srcOffset, dst.length - dstOffset);
|
|
155
|
+
dst.set(src.subarray(srcOffset, srcOffset + copyCount), dstOffset);
|
|
156
|
+
srcOffset = (srcOffset + copyCount) % src.length;
|
|
157
|
+
dstOffset = (dstOffset + copyCount) % dst.length;
|
|
158
|
+
count -= copyCount;
|
|
159
|
+
}
|
|
160
|
+
return { srcOffset, dstOffset };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* A Float32 variable-size ring buffer, where you can store data and then retrieve the latest N values.
|
|
165
|
+
*/
|
|
166
|
+
export class Float32RingBuffer extends RingBuffer {
|
|
167
|
+
constructor(size) {
|
|
168
|
+
super(new Float32Array(size));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//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,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAwB;IAC7D,YAAY,IAAY;QACtB,KAAK,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates coefficients for a FIR low-pass filter with the given
|
|
3
|
+
* corner frequency and kernel length at the given sample rate.
|
|
4
|
+
* @param sampleRate The signal's sample rate.
|
|
5
|
+
* @param cornerFreq The -6dB frequency in Hz.
|
|
6
|
+
* @param length The filter kernel's length. Should be an odd number.
|
|
7
|
+
* @param gain An optional output gain for the kernel. 1 by default.
|
|
8
|
+
* @returns The FIR coefficients for the filter.
|
|
9
|
+
*/
|
|
10
|
+
export declare function makeLowPassKernel(sampleRate: number, cornerFreq: number, length: number, gain?: number): Float32Array;
|
|
11
|
+
/**
|
|
12
|
+
* Returns coefficients for a Hilbert transform.
|
|
13
|
+
* @param length The length of the kernel.
|
|
14
|
+
* @returns The kernel coefficients.
|
|
15
|
+
*/
|
|
16
|
+
export declare function makeHilbertKernel(length: number): Float32Array;
|
|
17
|
+
/**
|
|
18
|
+
* Returns coefficients for a Blackman window.
|
|
19
|
+
* @param length The length of the kernel.
|
|
20
|
+
* @returns The kernel coefficients.
|
|
21
|
+
*/
|
|
22
|
+
export declare function makeBlackmanWindow(length: number): Float32Array;
|
|
23
|
+
//# sourceMappingURL=coefficients.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coefficients.d.ts","sourceRoot":"","sources":["../../src/dsp/coefficients.ts"],"names":[],"mappings":"AAeA;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,YAAY,CAuBd;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAU9D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAS/D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright 2024 Jacobo Tarrio Barreiro. All rights reserved.
|
|
2
|
+
// Copyright 2013 Google Inc. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
/**
|
|
16
|
+
* Generates coefficients for a FIR low-pass filter with the given
|
|
17
|
+
* corner frequency and kernel length at the given sample rate.
|
|
18
|
+
* @param sampleRate The signal's sample rate.
|
|
19
|
+
* @param cornerFreq The -6dB frequency in Hz.
|
|
20
|
+
* @param length The filter kernel's length. Should be an odd number.
|
|
21
|
+
* @param gain An optional output gain for the kernel. 1 by default.
|
|
22
|
+
* @returns The FIR coefficients for the filter.
|
|
23
|
+
*/
|
|
24
|
+
export function makeLowPassKernel(sampleRate, cornerFreq, length, gain) {
|
|
25
|
+
if (gain === undefined)
|
|
26
|
+
gain = 1;
|
|
27
|
+
length += (length + 1) % 2;
|
|
28
|
+
const freq = cornerFreq / sampleRate;
|
|
29
|
+
let coefs = new Float32Array(length);
|
|
30
|
+
const center = Math.floor(length / 2);
|
|
31
|
+
let sum = 0;
|
|
32
|
+
for (let i = 0; i < length; ++i) {
|
|
33
|
+
let val;
|
|
34
|
+
if (i == center) {
|
|
35
|
+
val = 2 * Math.PI * freq;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
val = Math.sin(2 * Math.PI * freq * (i - center)) / (i - center);
|
|
39
|
+
val *= 0.54 - 0.46 * Math.cos((2 * Math.PI * i) / (length - 1));
|
|
40
|
+
}
|
|
41
|
+
sum += val;
|
|
42
|
+
coefs[i] = val;
|
|
43
|
+
}
|
|
44
|
+
sum /= gain;
|
|
45
|
+
for (let i = 0; i < length; ++i) {
|
|
46
|
+
coefs[i] /= sum;
|
|
47
|
+
}
|
|
48
|
+
return coefs;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns coefficients for a Hilbert transform.
|
|
52
|
+
* @param length The length of the kernel.
|
|
53
|
+
* @returns The kernel coefficients.
|
|
54
|
+
*/
|
|
55
|
+
export function makeHilbertKernel(length) {
|
|
56
|
+
length += (length + 1) % 2;
|
|
57
|
+
const center = Math.floor(length / 2);
|
|
58
|
+
let out = new Float32Array(length);
|
|
59
|
+
for (let i = 0; i < out.length; ++i) {
|
|
60
|
+
if (i % 2 == 0) {
|
|
61
|
+
out[i] = 2 / (Math.PI * (center - i));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns coefficients for a Blackman window.
|
|
68
|
+
* @param length The length of the kernel.
|
|
69
|
+
* @returns The kernel coefficients.
|
|
70
|
+
*/
|
|
71
|
+
export function makeBlackmanWindow(length) {
|
|
72
|
+
let window = new Float32Array(length);
|
|
73
|
+
for (let n = 0; n < length; ++n) {
|
|
74
|
+
window[n] =
|
|
75
|
+
0.42 -
|
|
76
|
+
0.5 * Math.cos((2 * Math.PI * n) / (length - 1)) +
|
|
77
|
+
0.08 * Math.cos((4 * Math.PI * n) / (length - 1));
|
|
78
|
+
}
|
|
79
|
+
return window;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=coefficients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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AAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBAChD,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the given buffer of unsigned 8-bit samples into a pair of
|
|
3
|
+
* 32-bit floating-point sample streams.
|
|
4
|
+
*/
|
|
5
|
+
export declare class U8ToFloat32 {
|
|
6
|
+
/** @param length The expected length of each sample block. */
|
|
7
|
+
constructor(length?: number);
|
|
8
|
+
private pool;
|
|
9
|
+
/**
|
|
10
|
+
* @param input A buffer containing the unsigned 8-bit samples.
|
|
11
|
+
* @returns An array that contains first the I stream and then the Q stream.
|
|
12
|
+
*/
|
|
13
|
+
convert(input: ArrayBuffer): [Float32Array, Float32Array];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../src/dsp/converters.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,qBAAa,WAAW;IACtB,8DAA8D;gBAClD,MAAM,CAAC,EAAE,MAAM;IAI3B,OAAO,CAAC,IAAI,CAAS;IAErB;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC;CAY1D"}
|