@jtarrio/signals 0.9.0 → 0.9.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/README.md +5 -5
- package/dist/demod/empty-demodulator.d.ts +2 -1
- package/dist/demod/empty-demodulator.d.ts.map +1 -1
- package/dist/demod/empty-demodulator.js +3 -3
- package/dist/demod/empty-demodulator.js.map +1 -1
- package/dist/demod/sample-counter.d.ts +2 -1
- package/dist/demod/sample-counter.d.ts.map +1 -1
- package/dist/demod/sample-counter.js +2 -2
- package/dist/demod/sample-counter.js.map +1 -1
- package/dist/demod/spectrum.d.ts +2 -1
- package/dist/demod/spectrum.d.ts.map +1 -1
- package/dist/demod/spectrum.js +4 -4
- package/dist/demod/spectrum.js.map +1 -1
- package/dist/dsp/filters.d.ts +1 -0
- package/dist/dsp/filters.d.ts.map +1 -1
- package/dist/dsp/filters.js +6 -3
- package/dist/dsp/filters.js.map +1 -1
- package/dist/radio/radio.d.ts +13 -14
- package/dist/radio/radio.d.ts.map +1 -1
- package/dist/radio/radio.js +70 -81
- package/dist/radio/radio.js.map +1 -1
- package/dist/radio/sample_block.d.ts +18 -0
- package/dist/radio/sample_block.d.ts.map +1 -0
- package/dist/radio/sample_block.js +15 -0
- package/dist/radio/sample_block.js.map +1 -0
- package/dist/radio/sample_receiver.d.ts +3 -2
- package/dist/radio/sample_receiver.d.ts.map +1 -1
- package/dist/radio/sample_receiver.js +2 -2
- package/dist/radio/sample_receiver.js.map +1 -1
- package/dist/radio/signal_source.d.ts +5 -18
- package/dist/radio/signal_source.d.ts.map +1 -1
- package/dist/radio/single_thread.d.ts +18 -0
- package/dist/radio/single_thread.d.ts.map +1 -0
- package/dist/radio/single_thread.js +23 -0
- package/dist/radio/single_thread.js.map +1 -0
- package/dist/radio.d.ts +1 -0
- package/dist/radio.d.ts.map +1 -1
- package/dist/radio.js +1 -0
- package/dist/radio.js.map +1 -1
- package/dist/sources/generated.d.ts +17 -0
- package/dist/sources/generated.d.ts.map +1 -0
- package/dist/sources/generated.js +26 -0
- package/dist/sources/generated.js.map +1 -0
- package/dist/sources/generators.d.ts +1 -1
- package/dist/sources/generators.d.ts.map +1 -1
- package/dist/sources/push.d.ts +2 -1
- package/dist/sources/push.d.ts.map +1 -1
- package/dist/sources/push.js.map +1 -1
- package/dist/sources/read_ring.d.ts +1 -1
- package/dist/sources/read_ring.d.ts.map +1 -1
- package/dist/sources/realtime.d.ts +14 -18
- package/dist/sources/realtime.d.ts.map +1 -1
- package/dist/sources/realtime.js +14 -8
- package/dist/sources/realtime.js.map +1 -1
- package/package.json +1 -1
- package/dist/radio/msgqueue.d.ts +0 -32
- package/dist/radio/msgqueue.d.ts.map +0 -1
- package/dist/radio/msgqueue.js +0 -62
- package/dist/radio/msgqueue.js.map +0 -1
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import { SampleBlock
|
|
1
|
+
import { SampleBlock } from "../radio/sample_block.js";
|
|
2
|
+
import { SignalSource } from "../radio/signal_source.js";
|
|
2
3
|
/**
|
|
3
|
-
* A
|
|
4
|
-
* @param startSample The first sample's number.
|
|
5
|
-
* @param sampleRate The sample rate.
|
|
6
|
-
* @param centerFrequency The signal's center frequency.
|
|
7
|
-
* @param I An array to be populated with the I component values.
|
|
8
|
-
* @param Q An array to be populated with the Q component values.
|
|
9
|
-
*/
|
|
10
|
-
export type SampleGenerator = (startSample: number, sampleRate: number, centerFrequency: number, I: Float32Array, Q: Float32Array) => void;
|
|
11
|
-
/**
|
|
12
|
-
* A SignalSource that gets samples from a SampleGenerator function in real time.
|
|
4
|
+
* A SignalSource that outputs samples in real time.
|
|
13
5
|
*
|
|
14
|
-
* This source holds a small buffer that it feeds by calling the
|
|
15
|
-
*
|
|
16
|
-
*
|
|
6
|
+
* This source holds a small buffer that it feeds by calling the getSamples() method.
|
|
7
|
+
* Then, at periodic intervals, it checks if there are any pending reads and resolves
|
|
8
|
+
* them with the contents of the buffer, refilling it as needed.
|
|
17
9
|
*/
|
|
18
10
|
export declare class RealTimeSource implements SignalSource {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
constructor();
|
|
12
|
+
/** The source's sample rate. */
|
|
13
|
+
protected sampleRate: number;
|
|
14
|
+
/** The source's center frequency. */
|
|
15
|
+
protected centerFrequency: number;
|
|
23
16
|
private I;
|
|
24
17
|
private Q;
|
|
25
18
|
private lastSampleInBuffer;
|
|
@@ -28,6 +21,9 @@ export declare class RealTimeSource implements SignalSource {
|
|
|
28
21
|
private pendingReads;
|
|
29
22
|
private running;
|
|
30
23
|
private firstTs;
|
|
24
|
+
/**
|
|
25
|
+
* Fills the provided I and Q arrays with samples starting at the given firstSample number. */
|
|
26
|
+
protected getSamples(firstSample: number, I: Float32Array, Q: Float32Array): void;
|
|
31
27
|
setParameter<V>(_property: string, _value: V): Promise<void | V>;
|
|
32
28
|
setSampleRate(sampleRate: number): Promise<number>;
|
|
33
29
|
setCenterFrequency(freq: number): Promise<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../../src/sources/realtime.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../../src/sources/realtime.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD;;;;;;GAMG;AACH,qBAAa,cAAe,YAAW,YAAY;;IAcjD,gCAAgC;IAChC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC7B,qCAAqC;IACrC,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC;IAElC,OAAO,CAAC,CAAC,CAAoB;IAC7B,OAAO,CAAC,CAAC,CAAoB;IAC7B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,OAAO,CAAgB;IAE/B;kGAC8F;IAC9F,SAAS,CAAC,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY;IAKpE,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;IAEhE,aAAa,CAAC,UAAU,EAAE,MAAM;IAOhC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjD,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAI3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,gCAAgC;IAChC,OAAO,CAAC,QAAQ;IAIhB,8FAA8F;IAC9F,OAAO,CAAC,KAAK;IAuCb,6DAA6D;IAC7D,OAAO,CAAC,UAAU;CAyBnB"}
|
package/dist/sources/realtime.js
CHANGED
|
@@ -14,16 +14,14 @@
|
|
|
14
14
|
import { Float32RingBuffer, IqPool } from "../dsp/buffers.js";
|
|
15
15
|
import { PendingReadRing } from "./read_ring.js";
|
|
16
16
|
/**
|
|
17
|
-
* A SignalSource that
|
|
17
|
+
* A SignalSource that outputs samples in real time.
|
|
18
18
|
*
|
|
19
|
-
* This source holds a small buffer that it feeds by calling the
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* This source holds a small buffer that it feeds by calling the getSamples() method.
|
|
20
|
+
* Then, at periodic intervals, it checks if there are any pending reads and resolves
|
|
21
|
+
* them with the contents of the buffer, refilling it as needed.
|
|
22
22
|
*/
|
|
23
23
|
export class RealTimeSource {
|
|
24
|
-
|
|
25
|
-
constructor(generator) {
|
|
26
|
-
this.generator = generator;
|
|
24
|
+
constructor() {
|
|
27
25
|
this.sampleRate = 1024000;
|
|
28
26
|
this.centerFrequency = 0;
|
|
29
27
|
this.I = new Float32RingBuffer(Math.max(65536, this.sampleRate / 10));
|
|
@@ -35,7 +33,9 @@ export class RealTimeSource {
|
|
|
35
33
|
this.running = false;
|
|
36
34
|
this.firstTs = null;
|
|
37
35
|
}
|
|
36
|
+
/** The source's sample rate. */
|
|
38
37
|
sampleRate;
|
|
38
|
+
/** The source's center frequency. */
|
|
39
39
|
centerFrequency;
|
|
40
40
|
I;
|
|
41
41
|
Q;
|
|
@@ -45,6 +45,12 @@ export class RealTimeSource {
|
|
|
45
45
|
pendingReads;
|
|
46
46
|
running;
|
|
47
47
|
firstTs;
|
|
48
|
+
/**
|
|
49
|
+
* Fills the provided I and Q arrays with samples starting at the given firstSample number. */
|
|
50
|
+
getSamples(firstSample, I, Q) {
|
|
51
|
+
I.fill(0);
|
|
52
|
+
Q.fill(0);
|
|
53
|
+
}
|
|
48
54
|
async setParameter(_property, _value) { }
|
|
49
55
|
async setSampleRate(sampleRate) {
|
|
50
56
|
this.sampleRate = sampleRate;
|
|
@@ -127,7 +133,7 @@ export class RealTimeSource {
|
|
|
127
133
|
if (fillCount == 0)
|
|
128
134
|
return;
|
|
129
135
|
let [I, Q] = this.inPool.get(fillCount);
|
|
130
|
-
this.
|
|
136
|
+
this.getSamples(fillStart, I, Q);
|
|
131
137
|
this.I.store(I);
|
|
132
138
|
this.Q.store(Q);
|
|
133
139
|
this.lastSampleInBuffer = fillStart + fillCount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime.js","sourceRoot":"","sources":["../../src/sources/realtime.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;AAC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AC;QACjD,CAAC;QACD,IAAI,SAAS,IAAI,CAAC;YAAE,OAAO;QAE3B,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACxC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACjC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC,kBAAkB,GAAG,SAAS,GAAG,SAAS,CAAC;IAClD,CAAC;CACF"}
|
package/package.json
CHANGED
package/dist/radio/msgqueue.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/** The type returned by the Channel.receive() function. */
|
|
2
|
-
type ReceivedMessage<MsgType, AckType = void> = {
|
|
3
|
-
msg: MsgType;
|
|
4
|
-
ack: (_: AckType) => void;
|
|
5
|
-
};
|
|
6
|
-
/** A message channel, in which messages are sent and received asynchronously. */
|
|
7
|
-
export declare class Channel<MsgType, AckType = void> {
|
|
8
|
-
constructor();
|
|
9
|
-
/** Messages waiting to be delivered. */
|
|
10
|
-
private sendQueue;
|
|
11
|
-
/** Clients waiting to receive messages. */
|
|
12
|
-
private rcvQueue;
|
|
13
|
-
/**
|
|
14
|
-
* Sends a message.
|
|
15
|
-
*
|
|
16
|
-
* If there is a client waiting to receive a message, it is delivered straight to it.
|
|
17
|
-
* Otherwise, the message is added to the queue.
|
|
18
|
-
*
|
|
19
|
-
* @returns a promise that resolves when the receiver of the message acknowledges it.
|
|
20
|
-
*/
|
|
21
|
-
send(msg: MsgType): Promise<AckType>;
|
|
22
|
-
/**
|
|
23
|
-
* Receives a message.
|
|
24
|
-
*
|
|
25
|
-
* @returns a promise that resolves to a message and to an acknowledgement function.
|
|
26
|
-
* This acknowledgement function must be called after processing the message so the promise
|
|
27
|
-
* returned by the send() function will be resolved.
|
|
28
|
-
*/
|
|
29
|
-
receive(): Promise<ReceivedMessage<MsgType, AckType>>;
|
|
30
|
-
}
|
|
31
|
-
export {};
|
|
32
|
-
//# sourceMappingURL=msgqueue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"msgqueue.d.ts","sourceRoot":"","sources":["../../src/radio/msgqueue.ts"],"names":[],"mappings":"AAcA,2DAA2D;AAC3D,KAAK,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,IAAI;IAC9C,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC3B,CAAC;AAEF,iFAAiF;AACjF,qBAAa,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;;IAM1C,wCAAwC;IACxC,OAAO,CAAC,SAAS,CAAsC;IACvD,2CAA2C;IAC3C,OAAO,CAAC,QAAQ,CAAyC;IAEzD;;;;;;;OAOG;IACG,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAU1C;;;;;;OAMG;IACH,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAatD"}
|
package/dist/radio/msgqueue.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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 message channel, in which messages are sent and received asynchronously. */
|
|
15
|
-
export class Channel {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.sendQueue = [];
|
|
18
|
-
this.rcvQueue = [];
|
|
19
|
-
}
|
|
20
|
-
/** Messages waiting to be delivered. */
|
|
21
|
-
sendQueue;
|
|
22
|
-
/** Clients waiting to receive messages. */
|
|
23
|
-
rcvQueue;
|
|
24
|
-
/**
|
|
25
|
-
* Sends a message.
|
|
26
|
-
*
|
|
27
|
-
* If there is a client waiting to receive a message, it is delivered straight to it.
|
|
28
|
-
* Otherwise, the message is added to the queue.
|
|
29
|
-
*
|
|
30
|
-
* @returns a promise that resolves when the receiver of the message acknowledges it.
|
|
31
|
-
*/
|
|
32
|
-
async send(msg) {
|
|
33
|
-
let rcv = this.rcvQueue.shift();
|
|
34
|
-
if (rcv !== undefined) {
|
|
35
|
-
return rcv(msg);
|
|
36
|
-
}
|
|
37
|
-
let { promise, resolve } = Promise.withResolvers();
|
|
38
|
-
this.sendQueue.push({ msg, ack: resolve });
|
|
39
|
-
return promise;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Receives a message.
|
|
43
|
-
*
|
|
44
|
-
* @returns a promise that resolves to a message and to an acknowledgement function.
|
|
45
|
-
* This acknowledgement function must be called after processing the message so the promise
|
|
46
|
-
* returned by the send() function will be resolved.
|
|
47
|
-
*/
|
|
48
|
-
receive() {
|
|
49
|
-
let sent = this.sendQueue.shift();
|
|
50
|
-
if (sent !== undefined) {
|
|
51
|
-
return Promise.resolve(sent);
|
|
52
|
-
}
|
|
53
|
-
let msgPR = Promise.withResolvers();
|
|
54
|
-
this.rcvQueue.push((msg) => {
|
|
55
|
-
let ackPR = Promise.withResolvers();
|
|
56
|
-
msgPR.resolve({ msg: msg, ack: ackPR.resolve });
|
|
57
|
-
return ackPR.promise;
|
|
58
|
-
});
|
|
59
|
-
return msgPR.promise;
|
|
60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