@rfkit/spectrum-analyzer 0.5.0 → 0.7.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/README.md +6 -30
- package/core/LevelStreamAnalyzer/constants.d.ts +0 -1
- package/core/LevelStreamAnalyzer/index.d.ts +0 -38
- package/core/LevelStreamAnalyzer/types.d.ts +0 -1
- package/core/SeriesManager/constants.d.ts +2 -3
- package/core/SeriesManager/index.d.ts +0 -88
- package/core/SeriesManager/types.d.ts +0 -1
- package/core/SpectrumAnalyzer/constants.d.ts +6 -7
- package/core/SpectrumAnalyzer/errors.d.ts +2 -6
- package/core/SpectrumAnalyzer/index.d.ts +10 -184
- package/core/SpectrumAnalyzer/tools.d.ts +0 -36
- package/core/SpectrumAnalyzer/types.d.ts +5 -5
- package/core/WaterfallAnalyzer/index.d.ts +0 -4
- package/core/WaterfallAnalyzer/types.d.ts +0 -7
- package/index.d.ts +2 -3
- package/index.js +1 -1
- package/package.json +1 -1
- package/wasm/core/LevelStreamAnalyzer/constants.d.ts +0 -1
- package/wasm/core/LevelStreamAnalyzer/index.d.ts +0 -38
- package/wasm/core/LevelStreamAnalyzer/types.d.ts +0 -1
- package/wasm/core/SeriesManager/constants.d.ts +2 -3
- package/wasm/core/SeriesManager/index.d.ts +0 -88
- package/wasm/core/SeriesManager/types.d.ts +0 -1
- package/wasm/core/SpectrumAnalyzer/constants.d.ts +6 -7
- package/wasm/core/SpectrumAnalyzer/errors.d.ts +2 -6
- package/wasm/core/SpectrumAnalyzer/index.d.ts +10 -184
- package/wasm/core/SpectrumAnalyzer/tools.d.ts +0 -36
- package/wasm/core/SpectrumAnalyzer/types.d.ts +5 -5
- package/wasm/core/WaterfallAnalyzer/index.d.ts +0 -4
- package/wasm/core/WaterfallAnalyzer/types.d.ts +0 -7
- package/wasm/index.d.ts +2 -3
- package/wasm/index.js +1 -1
- package/wasm/src-rust/pkg/rfkit_spectrum_analyzer_wasm.js +2 -2
- package/wasm/src-rust/pkg/rfkit_spectrum_analyzer_wasm_bg.wasm +0 -0
- package/core/LevelStreamAnalyzer/constants.d.ts.map +0 -1
- package/core/LevelStreamAnalyzer/index.d.ts.map +0 -1
- package/core/LevelStreamAnalyzer/types.d.ts.map +0 -1
- package/core/SeriesManager/constants.d.ts.map +0 -1
- package/core/SeriesManager/index.d.ts.map +0 -1
- package/core/SeriesManager/types.d.ts.map +0 -1
- package/core/SpectrumAnalyzer/constants.d.ts.map +0 -1
- package/core/SpectrumAnalyzer/errors.d.ts.map +0 -1
- package/core/SpectrumAnalyzer/index.d.ts.map +0 -1
- package/core/SpectrumAnalyzer/tools.d.ts.map +0 -1
- package/core/SpectrumAnalyzer/types.d.ts.map +0 -1
- package/core/WaterfallAnalyzer/index.d.ts.map +0 -1
- package/core/WaterfallAnalyzer/types.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/wasm/core/LevelStreamAnalyzer/constants.d.ts.map +0 -1
- package/wasm/core/LevelStreamAnalyzer/index.d.ts.map +0 -1
- package/wasm/core/LevelStreamAnalyzer/types.d.ts.map +0 -1
- package/wasm/core/SeriesManager/constants.d.ts.map +0 -1
- package/wasm/core/SeriesManager/index.d.ts.map +0 -1
- package/wasm/core/SeriesManager/types.d.ts.map +0 -1
- package/wasm/core/SpectrumAnalyzer/constants.d.ts.map +0 -1
- package/wasm/core/SpectrumAnalyzer/errors.d.ts.map +0 -1
- package/wasm/core/SpectrumAnalyzer/index.d.ts.map +0 -1
- package/wasm/core/SpectrumAnalyzer/tools.d.ts.map +0 -1
- package/wasm/core/SpectrumAnalyzer/types.d.ts.map +0 -1
- package/wasm/core/WaterfallAnalyzer/index.d.ts.map +0 -1
- package/wasm/core/WaterfallAnalyzer/types.d.ts.map +0 -1
- package/wasm/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -55,13 +55,15 @@ analyzer.setExtraData(
|
|
|
55
55
|
|
|
56
56
|
### WASM 高性能版本
|
|
57
57
|
|
|
58
|
-
`SpectrumAnalyzer` 和 `LevelStreamAnalyzer` 的 WASM API 与 JS 版本一致;`WaterfallAnalyzer`
|
|
58
|
+
`SpectrumAnalyzer` 和 `LevelStreamAnalyzer` 的 WASM API 与 JS 版本一致;`WaterfallAnalyzer` 和 `SeriesManager` 为纯 JS 实现,同样可从 `/wasm` 入口导入(重导出)。
|
|
59
59
|
|
|
60
60
|
```typescript
|
|
61
61
|
import {
|
|
62
62
|
initWasm,
|
|
63
63
|
SpectrumAnalyzer,
|
|
64
64
|
LevelStreamAnalyzer,
|
|
65
|
+
WaterfallAnalyzer,
|
|
66
|
+
SeriesManager,
|
|
65
67
|
} from '@rfkit/spectrum-analyzer/wasm';
|
|
66
68
|
|
|
67
69
|
// 应用启动时初始化(仅需一次)
|
|
@@ -80,15 +82,6 @@ const analyzer = new SpectrumAnalyzer({
|
|
|
80
82
|
analyzer.process({ data: Float32Array, timestamp: Date.now() });
|
|
81
83
|
```
|
|
82
84
|
|
|
83
|
-
## 性能对比
|
|
84
|
-
|
|
85
|
-
| 场景 | JS 版本 | WASM 版本 | 提升 |
|
|
86
|
-
|------|---------|-----------|------|
|
|
87
|
-
| 8192 点数据 | 0.032 ms | 0.020 ms | **35%** |
|
|
88
|
-
| 2000 点 / 300Hz | 0.023 ms | 0.020 ms | **13%** |
|
|
89
|
-
|
|
90
|
-
两个版本在 300Hz 更新频率下都能轻松满足,CPU 占用 < 1%。
|
|
91
|
-
|
|
92
85
|
## 核心组件
|
|
93
86
|
|
|
94
87
|
### SpectrumAnalyzer
|
|
@@ -101,7 +94,7 @@ analyzer.process({ data: Float32Array, timestamp: Date.now() });
|
|
|
101
94
|
- 模板超限检测
|
|
102
95
|
- 多段频率扫描
|
|
103
96
|
|
|
104
|
-
### WaterfallAnalyzer
|
|
97
|
+
### WaterfallAnalyzer
|
|
105
98
|
|
|
106
99
|
独立瀑布图数据分析器,支持完整矩阵更新、增量帧,以及 X/Y 二维裁剪与降采样。采样范围使用原始矩阵索引的半开区间 `[start, end)`:
|
|
107
100
|
|
|
@@ -123,11 +116,9 @@ analyzer.updateSamplingRange({
|
|
|
123
116
|
});
|
|
124
117
|
```
|
|
125
118
|
|
|
126
|
-
`setData()`
|
|
119
|
+
`setData()` 要求数据为非空等宽矩阵,传入空数组表示清空;`appendFrame()` 用于实时增量场景,应配置 `maxFrames` 避免缓存无限增长。采样范围会夹紧到矩阵边界,夹紧后为空的范围会报错。
|
|
127
120
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
`WaterfallAnalyzer` 首期仅从默认 JS 入口导出,暂不从 `/wasm` 入口提供。
|
|
121
|
+
`WaterfallAnalyzer` 为纯 JS 实现,可从默认入口或 `/wasm` 入口导入。
|
|
131
122
|
|
|
132
123
|
### LevelStreamAnalyzer
|
|
133
124
|
|
|
@@ -135,21 +126,6 @@ analyzer.updateSamplingRange({
|
|
|
135
126
|
- 电平概率分布统计
|
|
136
127
|
- 时间/点数缓存模式
|
|
137
128
|
|
|
138
|
-
## 构建命令
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
pnpm build # 构建 JS 版本
|
|
142
|
-
pnpm build:wasm # 构建 WASM 版本
|
|
143
|
-
pnpm build:all # 构建全部
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## 发版约定
|
|
147
|
-
|
|
148
|
-
- 发布级改动默认需要在 PR 中携带 `.changeset/*.md`
|
|
149
|
-
- `patch` / `minor` / `major` 由 changeset 决定,不要手改 `package.json.version`
|
|
150
|
-
- PR 合并到 `main` 后会自动创建或更新 Release PR;合并 Release PR 后才会正式发布 npm
|
|
151
|
-
- 若 GitHub Actions 在 `npm publish` 阶段报 `E404` 或权限类错误,先检查 npm 包设置里的 Trusted Publisher 是否精确匹配 `Hxgh/rfkit-spectrum-analyzer`、`release.yml`、`npm-release`,并确认 `package.json.repository.url` 仍是当前 GitHub 仓库;修配置后直接重跑当前未发布版本,不要继续 bump 版本
|
|
152
|
-
|
|
153
129
|
## License
|
|
154
130
|
|
|
155
131
|
MIT
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import type { LevelStreamConfig } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* [SYNC-WASM] 电平流分析器
|
|
4
|
-
* @sync src-rust/src/level_stream/core.rs:WasmLevelStreamAnalyzer
|
|
5
|
-
*
|
|
6
|
-
* 用于统计电平流数据的分析器。
|
|
7
|
-
* 支持设置缓存时间、颗粒度和统计范围,并提供数据处理和概率计算功能。
|
|
8
|
-
*/
|
|
9
2
|
export default class LevelStreamAnalyzer {
|
|
10
3
|
protected config: Required<Omit<LevelStreamConfig, 'maxPoints'>> & {
|
|
11
4
|
maxPoints?: number;
|
|
@@ -14,43 +7,12 @@ export default class LevelStreamAnalyzer {
|
|
|
14
7
|
private probabilityData;
|
|
15
8
|
private count;
|
|
16
9
|
constructor(config: LevelStreamConfig);
|
|
17
|
-
/**
|
|
18
|
-
* 重置分析器的状态,清空频谱数据和概率数据,但保留配置信息。
|
|
19
|
-
*/
|
|
20
10
|
reset(): void;
|
|
21
11
|
setConfig(config: Partial<LevelStreamConfig>): void;
|
|
22
|
-
/**
|
|
23
|
-
* 处理一个新的电平值,更新频谱数据并重新计算概率。
|
|
24
|
-
* @param level 新的电平值
|
|
25
|
-
* @param timestamp 时间戳
|
|
26
|
-
*/
|
|
27
12
|
process(level: number, timestamp: number): void;
|
|
28
|
-
/**
|
|
29
|
-
* 更新新数据对应的区间概率
|
|
30
|
-
* @param level 新的电平值
|
|
31
|
-
*/
|
|
32
13
|
private updateProbability;
|
|
33
|
-
/**
|
|
34
|
-
* 查询所有统计的概率数据。
|
|
35
|
-
* @returns 概率数据的 Map 对象
|
|
36
|
-
*/
|
|
37
14
|
getAll(): Map<number, number>;
|
|
38
|
-
/**
|
|
39
|
-
* 移除过期的频谱数据。
|
|
40
|
-
* 支持两种模式:
|
|
41
|
-
* 1. 点模式(maxPoints):保留最新的 N 个点
|
|
42
|
-
* 2. 时间模式(cacheTime):保留指定时间范围内的数据
|
|
43
|
-
*/
|
|
44
15
|
private removeExpiredData;
|
|
45
|
-
/**
|
|
46
|
-
* 添加新的电平值到频谱数据中。
|
|
47
|
-
* @param level 新的电平值
|
|
48
|
-
* @param timestamp 时间戳
|
|
49
|
-
*/
|
|
50
16
|
private addNewData;
|
|
51
|
-
/**
|
|
52
|
-
* 输出符合统计范围的概率数据。
|
|
53
|
-
*/
|
|
54
17
|
private outputData;
|
|
55
18
|
}
|
|
56
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -4,7 +4,6 @@ export declare const DEFAULT_SERIES_CONFIG: {
|
|
|
4
4
|
readonly orientation: OrientationType.Horizontal;
|
|
5
5
|
readonly display: true;
|
|
6
6
|
readonly type: GraphicType.Line;
|
|
7
|
-
readonly color:
|
|
8
|
-
readonly label:
|
|
7
|
+
readonly color: '#00000000';
|
|
8
|
+
readonly label: '';
|
|
9
9
|
};
|
|
10
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,112 +1,24 @@
|
|
|
1
1
|
import type { SeriesChangeCallback, SeriesConfig, SeriesSubscriber, SubscriptionOptions } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Series 处理工具,用于管理图形系列的配置
|
|
4
|
-
* 支持初始化、属性设置、变更回调和订阅功能
|
|
5
|
-
*/
|
|
6
2
|
export default class SeriesManager {
|
|
7
3
|
private seriesMap;
|
|
8
4
|
private changeCallbacks;
|
|
9
5
|
private subscribers;
|
|
10
|
-
/**
|
|
11
|
-
* 构造函数,支持初始化系列配置
|
|
12
|
-
* @param initialSeries 初始系列配置数组
|
|
13
|
-
*/
|
|
14
6
|
constructor(initialSeries?: SeriesConfig[]);
|
|
15
|
-
/**
|
|
16
|
-
* 初始化系列配置
|
|
17
|
-
* @param seriesConfigs 系列配置数组
|
|
18
|
-
*/
|
|
19
7
|
private initializeSeries;
|
|
20
|
-
/**
|
|
21
|
-
* 添加新的系列配置
|
|
22
|
-
* @param config 系列配置
|
|
23
|
-
*/
|
|
24
8
|
addSeries(config: SeriesConfig): void;
|
|
25
|
-
/**
|
|
26
|
-
* 获取指定名称的系列配置
|
|
27
|
-
* @param name 系列名称
|
|
28
|
-
* @returns 系列配置或 undefined
|
|
29
|
-
*/
|
|
30
9
|
getSeries(name: string): SeriesConfig | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* 获取所有系列配置
|
|
33
|
-
* @returns 所有系列配置的数组
|
|
34
|
-
*/
|
|
35
10
|
getAllSeries(): SeriesConfig[];
|
|
36
|
-
/**
|
|
37
|
-
* 获取当前所有配置
|
|
38
|
-
* @returns 包含所有系列配置的对象,以系列名为键
|
|
39
|
-
*/
|
|
40
11
|
getAllConfigs(): Record<string, SeriesConfig>;
|
|
41
|
-
/**
|
|
42
|
-
* 设置指定系列的某个属性
|
|
43
|
-
* @param name 系列名称
|
|
44
|
-
* @param property 属性名
|
|
45
|
-
* @param value 属性值
|
|
46
|
-
* @returns 是否设置成功
|
|
47
|
-
*/
|
|
48
12
|
setSeriesProperty<K extends keyof SeriesConfig>(name: string, property: K, value: SeriesConfig[K]): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* 删除指定名称的系列
|
|
51
|
-
* @param name 系列名称
|
|
52
|
-
* @returns 是否删除成功
|
|
53
|
-
*/
|
|
54
13
|
removeSeries(name: string): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* 检查系列是否存在
|
|
57
|
-
* @param name 系列名称
|
|
58
|
-
* @returns 是否存在
|
|
59
|
-
*/
|
|
60
14
|
hasSeries(name: string): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* 添加变更回调函数
|
|
63
|
-
* @param callback 回调函数
|
|
64
|
-
*/
|
|
65
15
|
onChange(callback: SeriesChangeCallback): void;
|
|
66
|
-
/**
|
|
67
|
-
* 移除变更回调函数
|
|
68
|
-
* @param callback 要移除的回调函数
|
|
69
|
-
*/
|
|
70
16
|
offChange(callback: SeriesChangeCallback): void;
|
|
71
|
-
/**
|
|
72
|
-
* 通知所有回调函数属性变更
|
|
73
|
-
* @param name 系列名称
|
|
74
|
-
* @param property 属性名
|
|
75
|
-
* @param value 新值
|
|
76
|
-
*/
|
|
77
17
|
private notifyChange;
|
|
78
|
-
/**
|
|
79
|
-
* 清空所有系列配置
|
|
80
|
-
*/
|
|
81
18
|
clear(): void;
|
|
82
|
-
/**
|
|
83
|
-
* 获取系列数量
|
|
84
|
-
* @returns 系列数量
|
|
85
|
-
*/
|
|
86
19
|
size(): number;
|
|
87
|
-
/**
|
|
88
|
-
* 订阅系列变更事件
|
|
89
|
-
* @param subscriber 订阅回调函数
|
|
90
|
-
* @param options 订阅选项
|
|
91
|
-
* @returns 取消订阅的函数
|
|
92
|
-
*/
|
|
93
20
|
subscribe(subscriber: SeriesSubscriber, options?: SubscriptionOptions): () => void;
|
|
94
|
-
/**
|
|
95
|
-
* 取消订阅
|
|
96
|
-
* @param subscriber 要取消的订阅回调函数
|
|
97
|
-
*/
|
|
98
21
|
unsubscribe(subscriber: SeriesSubscriber): void;
|
|
99
|
-
/**
|
|
100
|
-
* 发送事件给所有订阅者
|
|
101
|
-
* @param event 事件数据
|
|
102
|
-
*/
|
|
103
22
|
private emitEvent;
|
|
104
|
-
/**
|
|
105
|
-
* 判断是否应该通知订阅者
|
|
106
|
-
* @param subscriber 订阅者
|
|
107
|
-
* @param event 事件数据
|
|
108
|
-
* @returns 是否应该通知
|
|
109
|
-
*/
|
|
110
23
|
private shouldNotifySubscriber;
|
|
111
24
|
}
|
|
112
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -38,15 +38,14 @@ export declare const DEFAULT_SPECTRUM_CONFIG: {
|
|
|
38
38
|
readonly templateTolerance: 0;
|
|
39
39
|
};
|
|
40
40
|
export declare const ERROR_MESSAGES: {
|
|
41
|
-
readonly EMPTY_SEGMENTS:
|
|
42
|
-
readonly INVALID_CONFIG:
|
|
43
|
-
readonly EMPTY_BANDWIDTH:
|
|
41
|
+
readonly EMPTY_SEGMENTS: '频段配置不能为空';
|
|
42
|
+
readonly INVALID_CONFIG: '必须且只能配置 segments 或 bandwidthConfig 其中之一';
|
|
43
|
+
readonly EMPTY_BANDWIDTH: 'bandwidthConfig 不能为空';
|
|
44
44
|
readonly INVALID_SEGMENT: (index: number) => string;
|
|
45
45
|
readonly INDEX_OUT_OF_BOUNDS: (index: number) => string;
|
|
46
46
|
readonly INVALID_ANTENNA_FACTOR_LENGTH: (points: number) => string;
|
|
47
|
-
readonly INVALID_ANTENNA_FACTOR:
|
|
48
|
-
readonly INVALID_SAMPLING_RANGE:
|
|
49
|
-
readonly INVALID_MAX_POINTS:
|
|
47
|
+
readonly INVALID_ANTENNA_FACTOR: '天线因子数据必须是有效的正数';
|
|
48
|
+
readonly INVALID_SAMPLING_RANGE: '采样范围无效';
|
|
49
|
+
readonly INVALID_MAX_POINTS: '点数必须大于0';
|
|
50
50
|
readonly INVALID_LENGTH: (expected: number) => string;
|
|
51
51
|
};
|
|
52
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
export declare class SpectrumError extends Error {
|
|
2
2
|
readonly code: string;
|
|
3
|
-
readonly details?: unknown
|
|
4
|
-
constructor(message: string, code: string, details?: unknown
|
|
3
|
+
readonly details?: unknown;
|
|
4
|
+
constructor(message: string, code: string, details?: unknown);
|
|
5
5
|
}
|
|
6
6
|
export declare class DataValidationError extends SpectrumError {
|
|
7
7
|
constructor(message: string, details?: unknown);
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
* 索引越界错误
|
|
11
|
-
*/
|
|
12
9
|
export declare class IndexOutOfBoundsError extends SpectrumError {
|
|
13
10
|
readonly index: number;
|
|
14
11
|
constructor(message: string, index: number, details?: unknown);
|
|
15
12
|
}
|
|
16
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtraDataOptions, isValidFloat32Array, ProcessInput, ProcessingOptions, ScanSegment, SpectrumConfig, SpectrumOutputData, TemplateOverData, ThresholdDataOptions, TimestampedFloat32Array } from './types';
|
|
1
|
+
import type { ExtraDataOptions, isValidFloat32Array, ProcessInput, ProcessingOptions, ScanSegment, SpectrumConfig, SpectrumOutputData, TemplateOverData, ThresholdDataOptions, TimestampedFloat32Array, WaterfallSink } from './types';
|
|
2
2
|
import { ExtraDataMode } from './types';
|
|
3
3
|
export default class SpectrumAnalyzer {
|
|
4
4
|
config: Required<Omit<SpectrumConfig, 'segments' | 'bandwidthConfig' | 'onSpectrumUpdate'>>;
|
|
@@ -29,6 +29,9 @@ export default class SpectrumAnalyzer {
|
|
|
29
29
|
protected processTimes: number;
|
|
30
30
|
protected lastProcessTime: number;
|
|
31
31
|
protected cachedExceedingDatas: TemplateOverData[];
|
|
32
|
+
private waterfallHead;
|
|
33
|
+
private waterfallCount;
|
|
34
|
+
private waterfallSink?;
|
|
32
35
|
protected fluorescenceData: Uint32Array;
|
|
33
36
|
protected fluorescenceMaxCount: number;
|
|
34
37
|
protected fluorescenceUpdateCounter: number;
|
|
@@ -40,228 +43,51 @@ export default class SpectrumAnalyzer {
|
|
|
40
43
|
private isProcessing;
|
|
41
44
|
private readonly onSpectrumUpdate?;
|
|
42
45
|
constructor(config: Partial<SpectrumConfig>);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* @param {ProcessInput} input - 输入数据,包含数据、时间戳、分段偏移和偏移量。
|
|
46
|
-
*/
|
|
46
|
+
setWaterfallSink(sink: WaterfallSink | null): void;
|
|
47
|
+
getWaterfallTimestamps(sampleCount: number): Array<TimestampedFloat32Array['timestamp'] | undefined>;
|
|
47
48
|
process({ data, timestamp, segmentOffset, offset, fluorescenceData, fluorescenceMaxCount }: ProcessInput): void;
|
|
48
|
-
/**
|
|
49
|
-
* 初始化扫描分段信息,并更新最大点数。
|
|
50
|
-
* @param {ScanSegment[]} segments - 扫描分段信息数组。
|
|
51
|
-
*/
|
|
52
49
|
initializeSegments(segments: ScanSegment[]): void;
|
|
53
|
-
/**
|
|
54
|
-
* 设置天线因子数据,并根据开关状态重新输出数据。
|
|
55
|
-
* @param {Float32Array} data - 天线因子数据,默认为根据最大点数创建的数组。
|
|
56
|
-
*/
|
|
57
50
|
setAntennaFactor(d: Float32Array | number[]): void;
|
|
58
|
-
/**
|
|
59
|
-
* 设置天线因子开关,并根据开关状态重新输出数据。
|
|
60
|
-
* @param {boolean} newAntennaFactorSwitch - 新的天线因子开关状态。
|
|
61
|
-
*/
|
|
62
51
|
setAntennaFactorSwitch(newAntennaFactorSwitch: boolean): void;
|
|
63
|
-
/**
|
|
64
|
-
* 动态更新处理选项
|
|
65
|
-
* @param {Partial<ProcessingOptions>} next - 要更新的处理选项
|
|
66
|
-
*
|
|
67
|
-
* 语义:
|
|
68
|
-
* - enableMetrics 从 false→true 后从后续帧开始累计;true→false 立即停止累计
|
|
69
|
-
* - enableFluorescence 同理
|
|
70
|
-
* - enablePeakStats 同理,控制峰值检测开关
|
|
71
|
-
*
|
|
72
|
-
* 注意:此方法会进行浅比较,只有值真正变化时才会更新配置和通知数据更新。
|
|
73
|
-
*/
|
|
74
52
|
updateProcessing(next: Partial<ProcessingOptions>): void;
|
|
75
|
-
/**
|
|
76
|
-
* 清空统计指标数据 (Max/Min/Avg)
|
|
77
|
-
* 将相关数组重置为初始值,并通知更新。
|
|
78
|
-
*/
|
|
79
53
|
clearMetricsData(): void;
|
|
80
|
-
/**
|
|
81
|
-
* 初始化 metrics 缓冲区(max/min/avg 及其输出缓存)。
|
|
82
|
-
* 仅负责分配内存,不负责填充初始值。
|
|
83
|
-
*/
|
|
84
54
|
private allocateMetricsBuffers;
|
|
85
|
-
/**
|
|
86
|
-
* 清空 metrics 缓冲区(max/min/avg 及其输出缓存),并重置 allValid 标记。
|
|
87
|
-
* 不会调整数组长度。
|
|
88
|
-
*/
|
|
89
55
|
private clearMetricsBuffers;
|
|
90
|
-
/**
|
|
91
|
-
* 设置瀑布图数据,用于从外部导入已缓存的瀑布图数据。
|
|
92
|
-
* @param {TimestampedFloat32Array[]} data - 瀑布图数据数组。
|
|
93
|
-
*/
|
|
94
56
|
setWaterfallData(newWaterfallData: TimestampedFloat32Array[]): void;
|
|
95
|
-
/**
|
|
96
|
-
* 设置荧光累积数据,用于传入预先计算好的荧光累积数据。
|
|
97
|
-
* @param {Uint32Array} fluorescenceData - 荧光累积数据
|
|
98
|
-
* @param {number} fluorescenceMaxCount - 荧光数据中的最大计数值
|
|
99
|
-
*/
|
|
100
57
|
setFluorescenceData(fluorescenceData: Uint32Array, fluorescenceMaxCount: number): void;
|
|
101
|
-
/**
|
|
102
|
-
* 设置实时值数据,用于从外部导入已缓存的实时值数据。
|
|
103
|
-
* @param {TimestampedFloat32Array} data - 实时值数据。
|
|
104
|
-
*/
|
|
105
58
|
setRealData(data: TimestampedFloat32Array): void;
|
|
106
|
-
/**
|
|
107
|
-
* 设置最大值数据,用于从外部导入已缓存的最大值数据。
|
|
108
|
-
* @param {Float32Array} data - 最大值数据。
|
|
109
|
-
*/
|
|
110
59
|
setMaxData(data: Float32Array): void;
|
|
111
|
-
/**
|
|
112
|
-
* 设置最小值数据,用于从外部导入已缓存的最小值数据。
|
|
113
|
-
* @param {Float32Array} data - 最小值数据。
|
|
114
|
-
*/
|
|
115
60
|
setMinData(data: Float32Array): void;
|
|
116
|
-
/**
|
|
117
|
-
* 设置平均值数据,用于从外部导入已缓存的平均值数据。
|
|
118
|
-
* @param {Float32Array} data - 平均值数据。
|
|
119
|
-
*/
|
|
120
61
|
setAvgData(data: Float32Array): void;
|
|
121
|
-
/**
|
|
122
|
-
* 设置占用度数据
|
|
123
|
-
* @param {Float32Array | number[]} data - 占用度数据
|
|
124
|
-
*/
|
|
125
62
|
setOccupancyData(data?: Float32Array | number[]): void;
|
|
126
|
-
/**
|
|
127
|
-
* 重置频谱分析器的状态,包括数据和进度。
|
|
128
|
-
*/
|
|
129
|
-
/**
|
|
130
|
-
* 设置额外数据
|
|
131
|
-
* @param data 数据对象
|
|
132
|
-
* @param mode 操作模式:ExtraDataMode.REPLACE(替换全部), ExtraDataMode.MERGE(合并), ExtraDataMode.CLEAR(清空)
|
|
133
|
-
* @param options 可选,使用 segmentOffset/offset 对每条额外数据独立进行局部写入
|
|
134
|
-
*/
|
|
135
63
|
setExtraData(data: Record<string, Float32Array | number[]> | null, mode?: ExtraDataMode, options?: ExtraDataOptions): void;
|
|
136
64
|
reset(preserveProcessedFlag?: boolean): void;
|
|
137
|
-
/**
|
|
138
|
-
* 获取频谱分析器的性能指标,包括处理时间、数据点数、瀑布图帧数、初始化状态和内存使用情况。
|
|
139
|
-
* @returns {Readonly<Record<string, number | boolean>>} - 包含性能指标的对象。
|
|
140
|
-
*/
|
|
141
65
|
getPerformanceMetrics(): Readonly<Record<string, number | boolean>>;
|
|
142
|
-
/**
|
|
143
|
-
* 获取当前实时数据的峰值统计信息
|
|
144
|
-
* @returns {PeakStats | undefined} - 峰值统计信息,如果未启用峰值检测则返回 undefined
|
|
145
|
-
*/
|
|
146
66
|
getPeakStats(): import('./types').PeakStats | undefined;
|
|
147
|
-
/**
|
|
148
|
-
* 更新采样范围,并重新输出数据。
|
|
149
|
-
* @param {number} start - 采样范围的起始位置。
|
|
150
|
-
* @param {number} end - 采样范围的结束位置。
|
|
151
|
-
* @returns {Uint32Array} - 输出值对应的原始数据索引数组。
|
|
152
|
-
*/
|
|
153
67
|
updateSamplingRange(start: number, end: number): Uint32Array;
|
|
154
|
-
/**
|
|
155
|
-
* 设置模板数据
|
|
156
|
-
* @param {Float32Array | number[]} data - 模板数据
|
|
157
|
-
* @param {number} templateTolerance - 可选,模板超出计算的容差值
|
|
158
|
-
*/
|
|
159
68
|
setTemplateData(data?: Float32Array | number[], templateTolerance?: number): void;
|
|
160
|
-
/**
|
|
161
|
-
* 设置背景噪声数据
|
|
162
|
-
* @param {Float32Array | number[]} data - 背景噪声数据
|
|
163
|
-
*/
|
|
164
69
|
setBackgroundNoiseData(data?: Float32Array | number[]): void;
|
|
165
|
-
/**
|
|
166
|
-
* 设置阈值数据
|
|
167
|
-
* @param {Float32Array | number[]} data - 阈值数据
|
|
168
|
-
* @param {ThresholdDataOptions} options - 可选,使用 segmentOffset/offset 进行局部门限写入
|
|
169
|
-
*/
|
|
170
70
|
setThresholdData(data?: Float32Array | number[], options?: ThresholdDataOptions): void;
|
|
171
|
-
/**
|
|
172
|
-
* 统一的超出数据段计算和缓存更新方法
|
|
173
|
-
* @param forceFullCalculation - 是否强制进行全量计算
|
|
174
|
-
* @param incrementalRange - 增量计算的范围
|
|
175
|
-
* @returns 计算得到的超出数据段
|
|
176
|
-
*/
|
|
177
71
|
private updateTemplateOverData;
|
|
178
|
-
/**
|
|
179
|
-
* 将分段偏移转换为全局数据索引。
|
|
180
|
-
*/
|
|
181
72
|
private resolveGlobalIndex;
|
|
182
73
|
private clearThresholdDataState;
|
|
183
|
-
/**
|
|
184
|
-
* 对数据进行重采样,生成频谱输出数据。
|
|
185
|
-
* @returns {Partial<SpectrumOutputData>} - 包含重采样后的实时数据、最大值、最小值和平均值的对象。
|
|
186
|
-
*/
|
|
187
74
|
protected resampleDataSeries(): Partial<SpectrumOutputData>;
|
|
188
|
-
/**
|
|
189
|
-
* 处理 extraData 的重采样,生成 extraOutputData
|
|
190
|
-
* 利用现有的 srcIndexCache 进行高效重采样
|
|
191
|
-
*/
|
|
192
|
-
/**
|
|
193
|
-
* 对瀑布图输出数据进行重采样。
|
|
194
|
-
*/
|
|
195
75
|
protected resampleWaterfallOutputData(): void;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
*/
|
|
76
|
+
private getOrderedWaterfallData;
|
|
77
|
+
private getWaterfallFrameAt;
|
|
78
|
+
private notifyWaterfallAppend;
|
|
79
|
+
private notifyWaterfallReplace;
|
|
201
80
|
protected updateWaterfallData(data: TimestampedFloat32Array, outputData: TimestampedFloat32Array): void;
|
|
202
|
-
/**
|
|
203
|
-
* 更新最大点数,并重置。
|
|
204
|
-
* @param {number} maxPoints - 新的最大点数。
|
|
205
|
-
*/
|
|
206
81
|
protected updateMaxPoints(maxPoints: number, preserveProcessedFlag?: boolean): void;
|
|
207
|
-
/**
|
|
208
|
-
* 验证输入数据的索引是否在有效范围内。
|
|
209
|
-
* @param {Float32Array} data - 输入数据。
|
|
210
|
-
* @param {number} index - 数据的起始索引。
|
|
211
|
-
*/
|
|
212
82
|
protected validateInput(data: Float32Array, index: number): void;
|
|
213
|
-
/**
|
|
214
|
-
* 统计计算,处理数据点,更新统计值(最大值、最小值、平均值)。
|
|
215
|
-
* @param {Float32Array} data - 输入数据。
|
|
216
|
-
* @param {number} index - 数据的起始索引。
|
|
217
|
-
* @param {boolean} isOver - 数据是否处理完成。
|
|
218
|
-
*/
|
|
219
83
|
private processDataPoints;
|
|
220
|
-
/**
|
|
221
|
-
* 更新荧光谱统计数据
|
|
222
|
-
*/
|
|
223
84
|
private updateFluorescenceStats;
|
|
224
|
-
/**
|
|
225
|
-
* 设置待处理标记并更新快速检查标记
|
|
226
|
-
*/
|
|
227
85
|
private setPendingFlag;
|
|
228
|
-
/**
|
|
229
|
-
* 重采样单个数据数组(统一的重采样逻辑,避免代码重复)
|
|
230
|
-
*/
|
|
231
86
|
private resampleSingleData;
|
|
232
|
-
/**
|
|
233
|
-
* 处理待处理的数据(在 srcIndexCache 生成后)
|
|
234
|
-
* 用于解决数据设置和实时数据处理的时序问题
|
|
235
|
-
*/
|
|
236
87
|
private processPendingData;
|
|
237
|
-
/**
|
|
238
|
-
* 通知频谱数据更新,调用回调函数。
|
|
239
|
-
* @param {SpectrumOutputData} processedData - 处理后的频谱数据。
|
|
240
|
-
*/
|
|
241
88
|
private notifySpectrumUpdate;
|
|
242
|
-
/**
|
|
243
|
-
* 计算当前频谱分析器的内存使用情况。
|
|
244
|
-
* @returns {number} - 内存使用量(字节)。
|
|
245
|
-
*/
|
|
246
89
|
private calculateMemoryUsage;
|
|
247
|
-
/**
|
|
248
|
-
* 获取输出数据,根据配置的输出范围截取数据。
|
|
249
|
-
* @param {TimestampedFloat32Array} [data] - 可选的输入数据,默认为实时数据。
|
|
250
|
-
* @returns {Readonly<TimestampedFloat32Array>} - 输出数据。
|
|
251
|
-
*/
|
|
252
90
|
private getOutputData;
|
|
253
|
-
/**
|
|
254
|
-
* 获取指定范围的荧光谱数据。
|
|
255
|
-
* @param {Map<number, number>[] | undefined} data - 荧光谱数据,如果未提供则使用实例的荧光谱数据。
|
|
256
|
-
* @returns {Map<number, number>[] | undefined} - 输出范围内的荧光谱数据。
|
|
257
|
-
*/
|
|
258
91
|
private getFluorescenceOutputData;
|
|
259
|
-
/**
|
|
260
|
-
* 获取数据快照:
|
|
261
|
-
* - 输出数据(重采样后)保持原有语义
|
|
262
|
-
* - rawData 提供原始全长数据引用(零拷贝)
|
|
263
|
-
* - 传入 left 时,返回 cursorIndex 便于光标统一索引
|
|
264
|
-
*/
|
|
265
92
|
getAllRawData(left?: number): Readonly<SpectrumOutputData>;
|
|
266
93
|
}
|
|
267
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SpectrumAnalyzer 工具函数
|
|
3
|
-
*
|
|
4
|
-
* [SYNC-WASM] 本文件包含需要与 Rust WASM 版本同步维护的核心算法
|
|
5
|
-
* @see src-rust/src/spectrum_analyzer/resampler.rs
|
|
6
|
-
* @see src-rust/src/spectrum_analyzer/template.rs
|
|
7
|
-
*/
|
|
8
1
|
import type { CursorIndexData, TemplateOverData, TimestampedFloat32Array } from './types';
|
|
9
2
|
export declare const arrayKeepAttribute: (source: Float32Array & {
|
|
10
3
|
max?: number;
|
|
@@ -17,17 +10,8 @@ export declare const arrayKeepAttribute: (source: Float32Array & {
|
|
|
17
10
|
timestamp?: number;
|
|
18
11
|
progress?: number;
|
|
19
12
|
}) => void;
|
|
20
|
-
/**
|
|
21
|
-
* 将数值约束到指定范围
|
|
22
|
-
*/
|
|
23
13
|
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
24
|
-
/**
|
|
25
|
-
* 将百分比 left 映射为索引
|
|
26
|
-
*/
|
|
27
14
|
export declare const leftToIndex: (left: number, length: number) => number;
|
|
28
|
-
/**
|
|
29
|
-
* 计算光标索引信息
|
|
30
|
-
*/
|
|
31
15
|
export declare const resolveCursorIndexByLeft: (left: number | undefined, outputLength: number, maxPoints: number) => CursorIndexData | undefined;
|
|
32
16
|
export declare const resample: ({ realData, antennaFactorData, antennaFactorSwitch, outputPoints }: {
|
|
33
17
|
realData: TimestampedFloat32Array;
|
|
@@ -38,14 +22,6 @@ export declare const resample: ({ realData, antennaFactorData, antennaFactorSwit
|
|
|
38
22
|
realOutputData: TimestampedFloat32Array;
|
|
39
23
|
srcIndexCache: Uint32Array;
|
|
40
24
|
};
|
|
41
|
-
/**
|
|
42
|
-
* [SYNC-WASM] 多数据系列重采样
|
|
43
|
-
* @sync src-rust/src/spectrum_analyzer/resampler.rs:resample_multiple
|
|
44
|
-
*
|
|
45
|
-
* 从 maxPoints 重采样到 outputPoints,对每个区间取最大值
|
|
46
|
-
* 支持同时处理 real/max/min/avg/template/occupancy/backgroundNoise/threshold/fluorescence 数据
|
|
47
|
-
* 支持在重采样过程中同时检测峰值(零性能损耗)
|
|
48
|
-
*/
|
|
49
25
|
export declare const resampleMultiple: ({ antennaFactorData, antennaFactorSwitch, outputPoints, realData, maxData, minData, avgData, templateData, backgroundNoiseData, thresholdData, fluorescenceData, occupancyData, enablePeakStats, maxPeaks, outputRangeStart }: {
|
|
50
26
|
antennaFactorData: Float32Array;
|
|
51
27
|
antennaFactorSwitch?: boolean;
|
|
@@ -74,18 +50,7 @@ export declare const resampleMultiple: ({ antennaFactorData, antennaFactorSwitch
|
|
|
74
50
|
srcIndexCache: Uint32Array;
|
|
75
51
|
fluorescenceOutputData: Map<number, number>[];
|
|
76
52
|
};
|
|
77
|
-
/**
|
|
78
|
-
* [SYNC-WASM] 额外数据重采样
|
|
79
|
-
* @sync src-rust/src/spectrum_analyzer/resampler.rs:resample_extra_data
|
|
80
|
-
*
|
|
81
|
-
* 专门用于处理 extraData 的重采样,支持天线因子应用
|
|
82
|
-
* 高性能优化版本:预分配内存,消除重复代码,集成 getOutputData 处理
|
|
83
|
-
*/
|
|
84
53
|
export declare const resampleExtraData: (extraData: Record<string, Float32Array>, antennaFactorData: Float32Array, antennaFactorSwitch: boolean, srcIndexCache: Uint32Array, getOutputData: (data: Float32Array) => Float32Array) => Record<string, Float32Array>;
|
|
85
|
-
/**
|
|
86
|
-
* [SYNC-WASM] 全量版本:使用预分配优化的完整数据扫描
|
|
87
|
-
* @sync src-rust/src/spectrum_analyzer/template.rs:find_exceeding_datas
|
|
88
|
-
*/
|
|
89
54
|
export declare const findExceedingDatas: ({ realData, maxData, minData, templateData, tolerance }: {
|
|
90
55
|
realData: TimestampedFloat32Array;
|
|
91
56
|
maxData: Float32Array;
|
|
@@ -104,4 +69,3 @@ export declare const findExceedingDatasIncremental: ({ realData, maxData, minDat
|
|
|
104
69
|
previousSegments?: TemplateOverData[];
|
|
105
70
|
}) => TemplateOverData[];
|
|
106
71
|
export declare function isAllValid(arr: Float32Array): boolean;
|
|
107
|
-
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -30,10 +30,6 @@ export interface ProcessingConfig {
|
|
|
30
30
|
readonly enablePeakStats: boolean;
|
|
31
31
|
readonly fluorescenceUpdateInterval: number;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* ProcessingOptions - 用于动态更新处理选项的类型。
|
|
35
|
-
* 仅包含允许在运行时更新的字段。
|
|
36
|
-
*/
|
|
37
33
|
export type ProcessingOptions = Pick<ProcessingConfig, 'enableMetrics' | 'enableFluorescence' | 'enablePeakStats' | 'fluorescenceUpdateInterval'>;
|
|
38
34
|
export interface PeakDetectionConfig {
|
|
39
35
|
maxPeaks?: number;
|
|
@@ -82,6 +78,11 @@ export type TimestampedFloat32Array = isValidFloat32Array & {
|
|
|
82
78
|
timestamp: ProcessInput['timestamp'];
|
|
83
79
|
peaks?: PeakStats;
|
|
84
80
|
};
|
|
81
|
+
export interface WaterfallSink {
|
|
82
|
+
append(frame: TimestampedFloat32Array, capacity: number): void;
|
|
83
|
+
replace(frames: readonly TimestampedFloat32Array[], capacity: number): void;
|
|
84
|
+
reset(): void;
|
|
85
|
+
}
|
|
85
86
|
export interface CursorIndexData {
|
|
86
87
|
left: number;
|
|
87
88
|
globalIndex: number;
|
|
@@ -127,4 +128,3 @@ export interface ISpectrumAnalyzer {
|
|
|
127
128
|
readonly antennaFactorSwitch: boolean;
|
|
128
129
|
readonly srcIndexCache: Uint32Array;
|
|
129
130
|
}
|
|
130
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -7,9 +7,6 @@ export default class WaterfallAnalyzer {
|
|
|
7
7
|
private samplingOptions?;
|
|
8
8
|
private snapshot;
|
|
9
9
|
constructor(config?: WaterfallAnalyzerConfig);
|
|
10
|
-
/**
|
|
11
|
-
* 替换完整瀑布矩阵。仅复制外层数组,调用方在分析器持有期间不得修改帧内容。
|
|
12
|
-
*/
|
|
13
10
|
setData(frames: readonly TimestampedFloat32Array[]): Readonly<WaterfallSnapshot>;
|
|
14
11
|
appendFrame(source: TimestampedFloat32Array): Readonly<WaterfallSnapshot>;
|
|
15
12
|
updateSamplingRange(options: WaterfallSamplingOptions): Readonly<WaterfallSnapshot>;
|
|
@@ -19,4 +16,3 @@ export default class WaterfallAnalyzer {
|
|
|
19
16
|
private getSourceSize;
|
|
20
17
|
private publishSnapshot;
|
|
21
18
|
}
|
|
22
|
-
//# sourceMappingURL=index.d.ts.map
|