@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
package/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Signals
|
|
2
|
+
|
|
3
|
+
Demodulate radio signals in real time from your JavaScript or TypeScript application.
|
|
4
|
+
|
|
5
|
+
## What is this
|
|
6
|
+
|
|
7
|
+
This is a library that provides functions to receive or generate radio signals, demodulate them, and play the result through the computer's speakers or headphones.
|
|
8
|
+
|
|
9
|
+
<!-- This library powers Radio Receiver, my browser-based SDR application, which you can try at [radio.ea1iti.es](https://radio.ea1iti.es). -->
|
|
10
|
+
|
|
11
|
+
## How to install
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install @jtarrio/signals
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## How to use
|
|
18
|
+
|
|
19
|
+
See [the `docs` directory](docs/README.md) for the documentation, or check out the following examples.
|
|
20
|
+
|
|
21
|
+
### The Radio API (demodulate and play through the computer's speakers)
|
|
22
|
+
|
|
23
|
+
This program generates an AM signal, demodulates it, and plays it through the computer's speakers.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Demodulator } from "@jtarrio/signals/demod/demodulator.js";
|
|
27
|
+
import { getMode } from "@jtarrio/signals/demod/modes.js";
|
|
28
|
+
import { Radio } from "@jtarrio/signals/radio.js";
|
|
29
|
+
import { modulateAM, tone } from "@jtarrio/signals/sources/generators.js";
|
|
30
|
+
import { SimpleProvider } from "@jtarrio/signals/sources/provider.js";
|
|
31
|
+
import { RealTimeSource } from "@jtarrio/signals/sources/realtime.js";
|
|
32
|
+
|
|
33
|
+
// Create the source, demodulator, and radio and connect them.
|
|
34
|
+
let source = new RealTimeSource(modulateAM(810000, 0.1, tone(600, 0.5)));
|
|
35
|
+
let demodulator = new Demodulator();
|
|
36
|
+
let radio = new Radio(new SimpleProvider(source), demodulator);
|
|
37
|
+
|
|
38
|
+
radio.setFrequency(810000);
|
|
39
|
+
demodulator.setVolume(1);
|
|
40
|
+
demodulator.setMode(getMode("AM"));
|
|
41
|
+
|
|
42
|
+
document
|
|
43
|
+
.getElementById("playButton")
|
|
44
|
+
.addEventListener("click", () => radio.start());
|
|
45
|
+
document
|
|
46
|
+
.getElementById("stopButton")
|
|
47
|
+
.addEventListener("click", () => radio.stop());
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
You can also see a full example at [`examples/highlevel`](examples/highlevel/script.js).
|
|
51
|
+
|
|
52
|
+
## Acknowledgements
|
|
53
|
+
|
|
54
|
+
This is a spinoff of https://github.com/jtarrio/webrtlsdr, itself a spinoff of https://github.com/jtarrio/radioreceiver, which is, in turn, a fork of https://github.com/google/radioreceiver, (of which I am the original author, but I was employed by Google at the time.)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Configurator, Demod, Demodulated } from "./modes.js";
|
|
2
|
+
/** Mode parameters for AM. */
|
|
3
|
+
export type ModeAM = {
|
|
4
|
+
scheme: "AM";
|
|
5
|
+
bandwidth: number;
|
|
6
|
+
squelch: number;
|
|
7
|
+
};
|
|
8
|
+
/** Mode options for AM. */
|
|
9
|
+
export type OptionsAM = {
|
|
10
|
+
/** Number of taps for the downsampler filter. Must be an odd number. 151 by default. */
|
|
11
|
+
downsamplerTaps?: number;
|
|
12
|
+
/** Number of taps for the RF filter. Must be an odd number. 151 by default. */
|
|
13
|
+
rfTaps?: number;
|
|
14
|
+
};
|
|
15
|
+
/** A demodulator for amplitude modulated signals. */
|
|
16
|
+
export declare class DemodAM implements Demod<ModeAM> {
|
|
17
|
+
private outRate;
|
|
18
|
+
private mode;
|
|
19
|
+
/**
|
|
20
|
+
* @param inRate The sample rate of the input samples.
|
|
21
|
+
* @param outRate The sample rate of the output audio.
|
|
22
|
+
* @param mode The mode to use initially.
|
|
23
|
+
* @param options Options for the demodulator.
|
|
24
|
+
*/
|
|
25
|
+
constructor(inRate: number, outRate: number, mode: ModeAM, options?: OptionsAM);
|
|
26
|
+
private rfTaps;
|
|
27
|
+
private shifter;
|
|
28
|
+
private downsampler;
|
|
29
|
+
private filterI;
|
|
30
|
+
private filterQ;
|
|
31
|
+
private demodulator;
|
|
32
|
+
private outPool;
|
|
33
|
+
getMode(): ModeAM;
|
|
34
|
+
setMode(mode: ModeAM): void;
|
|
35
|
+
/**
|
|
36
|
+
* Demodulates the signal.
|
|
37
|
+
* @param samplesI The I components of the samples.
|
|
38
|
+
* @param samplesQ The Q components of the samples.
|
|
39
|
+
* @param freqOffset The offset of the signal in the samples.
|
|
40
|
+
* @returns The demodulated audio signal.
|
|
41
|
+
*/
|
|
42
|
+
demodulate(samplesI: Float32Array, samplesQ: Float32Array, freqOffset: number): Demodulated;
|
|
43
|
+
}
|
|
44
|
+
/** Configurator for the AM mode. */
|
|
45
|
+
export declare class ConfigAM extends Configurator<ModeAM> {
|
|
46
|
+
constructor(mode: ModeAM | string);
|
|
47
|
+
protected create(): ModeAM;
|
|
48
|
+
hasBandwidth(): boolean;
|
|
49
|
+
getBandwidth(): number;
|
|
50
|
+
setBandwidth(bandwidth: number): ConfigAM;
|
|
51
|
+
hasSquelch(): boolean;
|
|
52
|
+
getSquelch(): number;
|
|
53
|
+
setSquelch(squelch: number): ConfigAM;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=demod-am.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demod-am.d.ts","sourceRoot":"","sources":["../../src/demod/demod-am.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,K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AU,IAAI,OAAO;IAGrB,UAAU,IAAI,MAAM;IAGpB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ;CAItC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright 2026 Jacobo Tarrio Barreiro. All rights reserved.
|
|
2
|
+
// Copyright 2014 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
|
+
import { Float32Pool } from "../dsp/buffers.js";
|
|
16
|
+
import { makeLowPassKernel } from "../dsp/coefficients.js";
|
|
17
|
+
import { AMDemodulator } from "../dsp/demodulators.js";
|
|
18
|
+
import { FrequencyShifter, FIRFilter } from "../dsp/filters.js";
|
|
19
|
+
import { getPower } from "../dsp/power.js";
|
|
20
|
+
import { ComplexDownsampler } from "../dsp/resamplers.js";
|
|
21
|
+
import { Configurator } from "./modes.js";
|
|
22
|
+
/** A demodulator for amplitude modulated signals. */
|
|
23
|
+
export class DemodAM {
|
|
24
|
+
outRate;
|
|
25
|
+
mode;
|
|
26
|
+
/**
|
|
27
|
+
* @param inRate The sample rate of the input samples.
|
|
28
|
+
* @param outRate The sample rate of the output audio.
|
|
29
|
+
* @param mode The mode to use initially.
|
|
30
|
+
* @param options Options for the demodulator.
|
|
31
|
+
*/
|
|
32
|
+
constructor(inRate, outRate, mode, options) {
|
|
33
|
+
this.outRate = outRate;
|
|
34
|
+
this.mode = mode;
|
|
35
|
+
const downsamplerTaps = options?.downsamplerTaps || 151;
|
|
36
|
+
this.rfTaps = options?.rfTaps || 151;
|
|
37
|
+
this.shifter = new FrequencyShifter(inRate);
|
|
38
|
+
this.downsampler = new ComplexDownsampler(inRate, outRate, downsamplerTaps);
|
|
39
|
+
const kernel = makeLowPassKernel(outRate, this.mode.bandwidth / 2, this.rfTaps);
|
|
40
|
+
this.filterI = new FIRFilter(kernel);
|
|
41
|
+
this.filterQ = new FIRFilter(kernel);
|
|
42
|
+
this.demodulator = new AMDemodulator(outRate);
|
|
43
|
+
this.outPool = new Float32Pool(1);
|
|
44
|
+
}
|
|
45
|
+
rfTaps;
|
|
46
|
+
shifter;
|
|
47
|
+
downsampler;
|
|
48
|
+
filterI;
|
|
49
|
+
filterQ;
|
|
50
|
+
demodulator;
|
|
51
|
+
outPool;
|
|
52
|
+
getMode() {
|
|
53
|
+
return this.mode;
|
|
54
|
+
}
|
|
55
|
+
setMode(mode) {
|
|
56
|
+
this.mode = mode;
|
|
57
|
+
const kernel = makeLowPassKernel(this.outRate, mode.bandwidth / 2, this.rfTaps);
|
|
58
|
+
this.filterI.setCoefficients(kernel);
|
|
59
|
+
this.filterQ.setCoefficients(kernel);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Demodulates the signal.
|
|
63
|
+
* @param samplesI The I components of the samples.
|
|
64
|
+
* @param samplesQ The Q components of the samples.
|
|
65
|
+
* @param freqOffset The offset of the signal in the samples.
|
|
66
|
+
* @returns The demodulated audio signal.
|
|
67
|
+
*/
|
|
68
|
+
demodulate(samplesI, samplesQ, freqOffset) {
|
|
69
|
+
this.shifter.inPlace(samplesI, samplesQ, -freqOffset);
|
|
70
|
+
const [I, Q] = this.downsampler.downsample(samplesI, samplesQ);
|
|
71
|
+
let allPower = getPower(I, Q);
|
|
72
|
+
this.filterI.inPlace(I);
|
|
73
|
+
this.filterQ.inPlace(Q);
|
|
74
|
+
let signalPower = (getPower(I, Q) * this.outRate) / this.mode.bandwidth;
|
|
75
|
+
this.demodulator.demodulate(I, Q, I);
|
|
76
|
+
let right = this.outPool.get(I.length);
|
|
77
|
+
right.set(I);
|
|
78
|
+
return {
|
|
79
|
+
left: I,
|
|
80
|
+
right,
|
|
81
|
+
stereo: false,
|
|
82
|
+
snr: signalPower / allPower,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Configurator for the AM mode. */
|
|
87
|
+
export class ConfigAM extends Configurator {
|
|
88
|
+
constructor(mode) {
|
|
89
|
+
super(mode);
|
|
90
|
+
}
|
|
91
|
+
create() {
|
|
92
|
+
return { scheme: "AM", bandwidth: 15000, squelch: 0 };
|
|
93
|
+
}
|
|
94
|
+
hasBandwidth() {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
getBandwidth() {
|
|
98
|
+
return this.mode.bandwidth;
|
|
99
|
+
}
|
|
100
|
+
setBandwidth(bandwidth) {
|
|
101
|
+
this.mode = {
|
|
102
|
+
...this.mode,
|
|
103
|
+
bandwidth: Math.max(250, Math.min(bandwidth, 30000)),
|
|
104
|
+
};
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
hasSquelch() {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
getSquelch() {
|
|
111
|
+
return this.mode.squelch;
|
|
112
|
+
}
|
|
113
|
+
setSquelch(squelch) {
|
|
114
|
+
this.mode = { ...this.mode, squelch: Math.max(0, Math.min(squelch, 6)) };
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=demod-am.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demod-am.js","sourceRoot":"","sources":["../../src/demod/demod-am.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,kDAAkD;AAClD,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE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QACzE,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Configurator, Demod, Demodulated } from "./modes.js";
|
|
2
|
+
/** Mode parameters for CW. */
|
|
3
|
+
export type ModeCW = {
|
|
4
|
+
scheme: "CW";
|
|
5
|
+
bandwidth: number;
|
|
6
|
+
};
|
|
7
|
+
/** Mode options for CW. */
|
|
8
|
+
export type OptionsCW = {
|
|
9
|
+
/** Tone frequency of the zero-beat CW signals, in Hertz. 600 by default. */
|
|
10
|
+
toneFrequency?: number;
|
|
11
|
+
/** Number of taps for the downsampler filter. Must be an odd number. 151 by default. */
|
|
12
|
+
downsamplerTaps?: number;
|
|
13
|
+
/** Number of taps for the audio filter. Must be an odd number. 351 by default. */
|
|
14
|
+
audioTaps?: number;
|
|
15
|
+
};
|
|
16
|
+
/** A demodulator for continuous wave signals. */
|
|
17
|
+
export declare class DemodCW implements Demod<ModeCW> {
|
|
18
|
+
private outRate;
|
|
19
|
+
private mode;
|
|
20
|
+
/**
|
|
21
|
+
* @param inRate The sample rate of the input samples.
|
|
22
|
+
* @param outRate The sample rate of the output audio.
|
|
23
|
+
* @param mode The mode to use initially.
|
|
24
|
+
* @param options Options for the demodulator.
|
|
25
|
+
*/
|
|
26
|
+
constructor(inRate: number, outRate: number, mode: ModeCW, options?: OptionsCW);
|
|
27
|
+
private audioTaps;
|
|
28
|
+
private shifter;
|
|
29
|
+
private downsampler;
|
|
30
|
+
private filterI;
|
|
31
|
+
private filterQ;
|
|
32
|
+
private toneShifter;
|
|
33
|
+
private toneFrequency;
|
|
34
|
+
private agc;
|
|
35
|
+
private outPool;
|
|
36
|
+
getMode(): ModeCW;
|
|
37
|
+
setMode(mode: ModeCW): void;
|
|
38
|
+
/** Demodulates the given I/Q samples into the real output. */
|
|
39
|
+
demodulate(samplesI: Float32Array, samplesQ: Float32Array, freqOffset: number): Demodulated;
|
|
40
|
+
}
|
|
41
|
+
/** Configurator for the CW mode. */
|
|
42
|
+
export declare class ConfigCW extends Configurator<ModeCW> {
|
|
43
|
+
constructor(mode: ModeCW | string);
|
|
44
|
+
protected create(): ModeCW;
|
|
45
|
+
hasBandwidth(): boolean;
|
|
46
|
+
getBandwidth(): number;
|
|
47
|
+
setBandwidth(bandwidth: number): ConfigCW;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=demod-cw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demod-cw.d.ts","sourceRoot":"","sources":["../../src/demod/demod-cw.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,8BAA8B;AAC9B,MAAM,MAAM,MAAM,GAAG;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD,2BAA2B;AAC3B,MAAM,MAAM,SAAS,GAAG;IACtB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,iDAAiD;AACjD,qBAAa,OAAQ,YAAW,KAAK,CAAC,MAAM,CAAC;IASzC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IATd;;;;;OAKG;gBAED,MAAM,EAAE,MAAM,EACN,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,SAAS;IAoBrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,OAAO,CAAc;IAE7B,OAAO,IAAI,MAAM;IAIjB,OAAO,CAAC,IAAI,EAAE,MAAM;IAWpB,8DAA8D;IAC9D,UAAU,CACR,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,GACjB,WAAW;CAkBf;AAED,oCAAoC;AACpC,qBAAa,QAAS,SAAQ,YAAY,CAAC,MAAM,CAAC;gBACpC,IAAI,EAAE,MAAM,GAAG,MAAM;IAGjC,SAAS,CAAC,MAAM,IAAI,MAAM;IAG1B,YAAY,IAAI,OAAO;IAGvB,YAAY,IAAI,MAAM;IAGtB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ;CAO1C"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
import { Float32Pool } from "../dsp/buffers.js";
|
|
15
|
+
import { makeLowPassKernel } from "../dsp/coefficients.js";
|
|
16
|
+
import { AGC, FIRFilter, FrequencyShifter } from "../dsp/filters.js";
|
|
17
|
+
import { getPower } from "../dsp/power.js";
|
|
18
|
+
import { ComplexDownsampler } from "../dsp/resamplers.js";
|
|
19
|
+
import { Configurator } from "./modes.js";
|
|
20
|
+
/** A demodulator for continuous wave signals. */
|
|
21
|
+
export class DemodCW {
|
|
22
|
+
outRate;
|
|
23
|
+
mode;
|
|
24
|
+
/**
|
|
25
|
+
* @param inRate The sample rate of the input samples.
|
|
26
|
+
* @param outRate The sample rate of the output audio.
|
|
27
|
+
* @param mode The mode to use initially.
|
|
28
|
+
* @param options Options for the demodulator.
|
|
29
|
+
*/
|
|
30
|
+
constructor(inRate, outRate, mode, options) {
|
|
31
|
+
this.outRate = outRate;
|
|
32
|
+
this.mode = mode;
|
|
33
|
+
const downsamplerTaps = options?.downsamplerTaps || 151;
|
|
34
|
+
this.audioTaps = options?.audioTaps || 351;
|
|
35
|
+
const toneFrequency = options?.toneFrequency || 600;
|
|
36
|
+
this.shifter = new FrequencyShifter(inRate);
|
|
37
|
+
this.downsampler = new ComplexDownsampler(inRate, outRate, downsamplerTaps);
|
|
38
|
+
const kernel = makeLowPassKernel(outRate, mode.bandwidth / 2, this.audioTaps);
|
|
39
|
+
this.filterI = new FIRFilter(kernel);
|
|
40
|
+
this.filterQ = new FIRFilter(kernel);
|
|
41
|
+
this.toneShifter = new FrequencyShifter(outRate);
|
|
42
|
+
this.toneFrequency = toneFrequency;
|
|
43
|
+
this.agc = new AGC(outRate, 10);
|
|
44
|
+
this.outPool = new Float32Pool(1);
|
|
45
|
+
}
|
|
46
|
+
audioTaps;
|
|
47
|
+
shifter;
|
|
48
|
+
downsampler;
|
|
49
|
+
filterI;
|
|
50
|
+
filterQ;
|
|
51
|
+
toneShifter;
|
|
52
|
+
toneFrequency;
|
|
53
|
+
agc;
|
|
54
|
+
outPool;
|
|
55
|
+
getMode() {
|
|
56
|
+
return this.mode;
|
|
57
|
+
}
|
|
58
|
+
setMode(mode) {
|
|
59
|
+
this.mode = mode;
|
|
60
|
+
const kernel = makeLowPassKernel(this.outRate, mode.bandwidth / 2, this.audioTaps);
|
|
61
|
+
this.filterI.setCoefficients(kernel);
|
|
62
|
+
this.filterQ.setCoefficients(kernel);
|
|
63
|
+
}
|
|
64
|
+
/** Demodulates the given I/Q samples into the real output. */
|
|
65
|
+
demodulate(samplesI, samplesQ, freqOffset) {
|
|
66
|
+
this.shifter.inPlace(samplesI, samplesQ, -freqOffset);
|
|
67
|
+
const [I, Q] = this.downsampler.downsample(samplesI, samplesQ);
|
|
68
|
+
let allPower = getPower(I, Q);
|
|
69
|
+
this.filterI.inPlace(I);
|
|
70
|
+
this.filterQ.inPlace(Q);
|
|
71
|
+
let signalPower = (getPower(I, Q) * this.outRate) / this.mode.bandwidth;
|
|
72
|
+
this.toneShifter.inPlace(I, Q, this.toneFrequency);
|
|
73
|
+
this.agc.inPlace(I);
|
|
74
|
+
let right = this.outPool.get(I.length);
|
|
75
|
+
right.set(I);
|
|
76
|
+
return {
|
|
77
|
+
left: I,
|
|
78
|
+
right,
|
|
79
|
+
stereo: false,
|
|
80
|
+
snr: signalPower / allPower,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Configurator for the CW mode. */
|
|
85
|
+
export class ConfigCW extends Configurator {
|
|
86
|
+
constructor(mode) {
|
|
87
|
+
super(mode);
|
|
88
|
+
}
|
|
89
|
+
create() {
|
|
90
|
+
return { scheme: "CW", bandwidth: 50 };
|
|
91
|
+
}
|
|
92
|
+
hasBandwidth() {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
getBandwidth() {
|
|
96
|
+
return this.mode.bandwidth;
|
|
97
|
+
}
|
|
98
|
+
setBandwidth(bandwidth) {
|
|
99
|
+
this.mode = {
|
|
100
|
+
...this.mode,
|
|
101
|
+
bandwidth: Math.max(5, Math.min(bandwidth, 1000)),
|
|
102
|
+
};
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=demod-cw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"demod-cw.js","sourceRoot":"","sources":["../../src/demod/demod-cw.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,kEAAkE;AAClE,mEAAmE;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
|
1
|
+
import { Configurator, Demod, Demodulated } from "./modes.js";
|
|
2
|
+
/** Mode parameters for NBFM. */
|
|
3
|
+
export type ModeNBFM = {
|
|
4
|
+
scheme: "NBFM";
|
|
5
|
+
maxF: number;
|
|
6
|
+
squelch: number;
|
|
7
|
+
};
|
|
8
|
+
/** Mode options for NBFM. */
|
|
9
|
+
export type OptionsNBFM = {
|
|
10
|
+
/** Number of taps for the downsampler filter. Must be an odd number. 151 by default. */
|
|
11
|
+
downsamplerTaps?: number;
|
|
12
|
+
/** Number of taps for the RF filter. Must be an odd number. 151 by default. */
|
|
13
|
+
rfTaps?: number;
|
|
14
|
+
};
|
|
15
|
+
/** A demodulator for narrowband FM signals. */
|
|
16
|
+
export declare class DemodNBFM implements Demod<ModeNBFM> {
|
|
17
|
+
private outRate;
|
|
18
|
+
private mode;
|
|
19
|
+
/**
|
|
20
|
+
* @param inRate The sample rate of the input samples.
|
|
21
|
+
* @param outRate The sample rate of the output audio.
|
|
22
|
+
* @param mode The mode to use initially.
|
|
23
|
+
* @param options Options for the demodulator.
|
|
24
|
+
*/
|
|
25
|
+
constructor(inRate: number, outRate: number, mode: ModeNBFM, options?: OptionsNBFM);
|
|
26
|
+
private rfTaps;
|
|
27
|
+
private shifter;
|
|
28
|
+
private downsampler;
|
|
29
|
+
private filterI;
|
|
30
|
+
private filterQ;
|
|
31
|
+
private demodulator;
|
|
32
|
+
private outPool;
|
|
33
|
+
getMode(): ModeNBFM;
|
|
34
|
+
setMode(mode: ModeNBFM): void;
|
|
35
|
+
/**
|
|
36
|
+
* Demodulates the signal.
|
|
37
|
+
* @param samplesI The I components of the samples.
|
|
38
|
+
* @param samplesQ The Q components of the samples.
|
|
39
|
+
* @param freqOffset The offset of the signal in the samples.
|
|
40
|
+
* @returns The demodulated audio signal.
|
|
41
|
+
*/
|
|
42
|
+
demodulate(samplesI: Float32Array, samplesQ: Float32Array, freqOffset: number): Demodulated;
|
|
43
|
+
}
|
|
44
|
+
/** Configurator for the NBFM mode. */
|
|
45
|
+
export declare class ConfigNBFM extends Configurator<ModeNBFM> {
|
|
46
|
+
constructor(mode: ModeNBFM | string);
|
|
47
|
+
protected create(): ModeNBFM;
|
|
48
|
+
hasBandwidth(): boolean;
|
|
49
|
+
getBandwidth(): number;
|
|
50
|
+
setBandwidth(bandwidth: number): ConfigNBFM;
|
|
51
|
+
hasSquelch(): boolean;
|
|
52
|
+
getSquelch(): number;
|
|
53
|
+
setSquelch(squelch: number): ConfigNBFM;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=demod-nbfm.d.ts.map
|