@rfkit/spectrum-analyzer 0.4.0 → 0.6.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.
Files changed (62) hide show
  1. package/README.md +22 -30
  2. package/core/LevelStreamAnalyzer/constants.d.ts +0 -1
  3. package/core/LevelStreamAnalyzer/index.d.ts +0 -38
  4. package/core/LevelStreamAnalyzer/types.d.ts +0 -1
  5. package/core/SeriesManager/constants.d.ts +2 -3
  6. package/core/SeriesManager/index.d.ts +0 -88
  7. package/core/SeriesManager/types.d.ts +0 -1
  8. package/core/SpectrumAnalyzer/constants.d.ts +6 -7
  9. package/core/SpectrumAnalyzer/errors.d.ts +2 -6
  10. package/core/SpectrumAnalyzer/index.d.ts +2 -184
  11. package/core/SpectrumAnalyzer/tools.d.ts +0 -36
  12. package/core/SpectrumAnalyzer/types.d.ts +4 -5
  13. package/core/WaterfallAnalyzer/index.d.ts +0 -4
  14. package/core/WaterfallAnalyzer/types.d.ts +0 -7
  15. package/index.d.ts +2 -2
  16. package/index.js +1 -1
  17. package/package.json +1 -1
  18. package/wasm/core/LevelStreamAnalyzer/constants.d.ts +0 -1
  19. package/wasm/core/LevelStreamAnalyzer/index.d.ts +0 -38
  20. package/wasm/core/LevelStreamAnalyzer/types.d.ts +0 -1
  21. package/wasm/core/SeriesManager/constants.d.ts +2 -3
  22. package/wasm/core/SeriesManager/index.d.ts +0 -88
  23. package/wasm/core/SeriesManager/types.d.ts +0 -1
  24. package/wasm/core/SpectrumAnalyzer/constants.d.ts +6 -7
  25. package/wasm/core/SpectrumAnalyzer/errors.d.ts +2 -6
  26. package/wasm/core/SpectrumAnalyzer/index.d.ts +2 -184
  27. package/wasm/core/SpectrumAnalyzer/tools.d.ts +0 -36
  28. package/wasm/core/SpectrumAnalyzer/types.d.ts +4 -5
  29. package/wasm/core/WaterfallAnalyzer/index.d.ts +0 -4
  30. package/wasm/core/WaterfallAnalyzer/types.d.ts +0 -7
  31. package/wasm/index.d.ts +2 -2
  32. package/wasm/index.js +1 -1
  33. package/wasm/src-rust/pkg/rfkit_spectrum_analyzer_wasm.js +2 -2
  34. package/wasm/src-rust/pkg/rfkit_spectrum_analyzer_wasm_bg.wasm +0 -0
  35. package/core/LevelStreamAnalyzer/constants.d.ts.map +0 -1
  36. package/core/LevelStreamAnalyzer/index.d.ts.map +0 -1
  37. package/core/LevelStreamAnalyzer/types.d.ts.map +0 -1
  38. package/core/SeriesManager/constants.d.ts.map +0 -1
  39. package/core/SeriesManager/index.d.ts.map +0 -1
  40. package/core/SeriesManager/types.d.ts.map +0 -1
  41. package/core/SpectrumAnalyzer/constants.d.ts.map +0 -1
  42. package/core/SpectrumAnalyzer/errors.d.ts.map +0 -1
  43. package/core/SpectrumAnalyzer/index.d.ts.map +0 -1
  44. package/core/SpectrumAnalyzer/tools.d.ts.map +0 -1
  45. package/core/SpectrumAnalyzer/types.d.ts.map +0 -1
  46. package/core/WaterfallAnalyzer/index.d.ts.map +0 -1
  47. package/core/WaterfallAnalyzer/types.d.ts.map +0 -1
  48. package/index.d.ts.map +0 -1
  49. package/wasm/core/LevelStreamAnalyzer/constants.d.ts.map +0 -1
  50. package/wasm/core/LevelStreamAnalyzer/index.d.ts.map +0 -1
  51. package/wasm/core/LevelStreamAnalyzer/types.d.ts.map +0 -1
  52. package/wasm/core/SeriesManager/constants.d.ts.map +0 -1
  53. package/wasm/core/SeriesManager/index.d.ts.map +0 -1
  54. package/wasm/core/SeriesManager/types.d.ts.map +0 -1
  55. package/wasm/core/SpectrumAnalyzer/constants.d.ts.map +0 -1
  56. package/wasm/core/SpectrumAnalyzer/errors.d.ts.map +0 -1
  57. package/wasm/core/SpectrumAnalyzer/index.d.ts.map +0 -1
  58. package/wasm/core/SpectrumAnalyzer/tools.d.ts.map +0 -1
  59. package/wasm/core/SpectrumAnalyzer/types.d.ts.map +0 -1
  60. package/wasm/core/WaterfallAnalyzer/index.d.ts.map +0 -1
  61. package/wasm/core/WaterfallAnalyzer/types.d.ts.map +0 -1
  62. package/wasm/index.d.ts.map +0 -1
package/README.md CHANGED
@@ -18,6 +18,7 @@ pnpm add @rfkit/spectrum-analyzer
18
18
 
19
19
  ```typescript
20
20
  import {
21
+ ExtraDataMode,
21
22
  SpectrumAnalyzer,
22
23
  LevelStreamAnalyzer,
23
24
  type SpectrumConfig,
@@ -37,15 +38,32 @@ const analyzer = new SpectrumAnalyzer({
37
38
  analyzer.process({ data: Float32Array, timestamp: Date.now() });
38
39
  ```
39
40
 
41
+ ### 分段额外数据
42
+
43
+ `setExtraData` 默认保持完整数组设置语义。传入第三个参数后,每条额外数据会独立维护全长缓冲区,并按 `segmentOffset + offset` 局部写入;未写入的位置保留为 `NaN`。
44
+
45
+ ```typescript
46
+ analyzer.setExtraData(
47
+ {
48
+ traceA: traceAChunk,
49
+ traceB: traceBChunk,
50
+ },
51
+ ExtraDataMode.MERGE,
52
+ { segmentOffset: 1, offset: 200 },
53
+ );
54
+ ```
55
+
40
56
  ### WASM 高性能版本
41
57
 
42
- `SpectrumAnalyzer` 和 `LevelStreamAnalyzer` 的 WASM API 与 JS 版本一致;`WaterfallAnalyzer` 当前仅提供 JS 版本。
58
+ `SpectrumAnalyzer` 和 `LevelStreamAnalyzer` 的 WASM API 与 JS 版本一致;`WaterfallAnalyzer` `SeriesManager` 为纯 JS 实现,同样可从 `/wasm` 入口导入(重导出)。
43
59
 
44
60
  ```typescript
45
61
  import {
46
62
  initWasm,
47
63
  SpectrumAnalyzer,
48
64
  LevelStreamAnalyzer,
65
+ WaterfallAnalyzer,
66
+ SeriesManager,
49
67
  } from '@rfkit/spectrum-analyzer/wasm';
50
68
 
51
69
  // 应用启动时初始化(仅需一次)
@@ -64,15 +82,6 @@ const analyzer = new SpectrumAnalyzer({
64
82
  analyzer.process({ data: Float32Array, timestamp: Date.now() });
65
83
  ```
66
84
 
67
- ## 性能对比
68
-
69
- | 场景 | JS 版本 | WASM 版本 | 提升 |
70
- |------|---------|-----------|------|
71
- | 8192 点数据 | 0.032 ms | 0.020 ms | **35%** |
72
- | 2000 点 / 300Hz | 0.023 ms | 0.020 ms | **13%** |
73
-
74
- 两个版本在 300Hz 更新频率下都能轻松满足,CPU 占用 < 1%。
75
-
76
85
  ## 核心组件
77
86
 
78
87
  ### SpectrumAnalyzer
@@ -85,7 +94,7 @@ analyzer.process({ data: Float32Array, timestamp: Date.now() });
85
94
  - 模板超限检测
86
95
  - 多段频率扫描
87
96
 
88
- ### WaterfallAnalyzer(仅 JS 版本)
97
+ ### WaterfallAnalyzer
89
98
 
90
99
  独立瀑布图数据分析器,支持完整矩阵更新、增量帧,以及 X/Y 二维裁剪与降采样。采样范围使用原始矩阵索引的半开区间 `[start, end)`:
91
100
 
@@ -107,11 +116,9 @@ analyzer.updateSamplingRange({
107
116
  });
108
117
  ```
109
118
 
110
- `setData()` 要求数据为非空等宽矩阵,传入空数组表示清空;它只浅拷贝外层数组,因此调用方必须将输入帧以及 `getSnapshot()` 返回的帧和索引按只读数据处理。`appendFrame()` 会复制单个新增帧,实时增量场景应配置 `maxFrames`,避免缓存无限增长。
111
-
112
- 小数采样范围会对 `start` 向下取整、对 `end` 向上取整,并夹紧到矩阵边界;夹紧后为空的范围会报错。`columnIndices` 表示每个 X 输出 bin 的代表中心列,不表示该 bin 最大值的真实来源列。
119
+ `setData()` 要求数据为非空等宽矩阵,传入空数组表示清空;`appendFrame()` 用于实时增量场景,应配置 `maxFrames` 避免缓存无限增长。采样范围会夹紧到矩阵边界,夹紧后为空的范围会报错。
113
120
 
114
- `WaterfallAnalyzer` 首期仅从默认 JS 入口导出,暂不从 `/wasm` 入口提供。
121
+ `WaterfallAnalyzer` 为纯 JS 实现,可从默认入口或 `/wasm` 入口导入。
115
122
 
116
123
  ### LevelStreamAnalyzer
117
124
 
@@ -119,21 +126,6 @@ analyzer.updateSamplingRange({
119
126
  - 电平概率分布统计
120
127
  - 时间/点数缓存模式
121
128
 
122
- ## 构建命令
123
-
124
- ```bash
125
- pnpm build # 构建 JS 版本
126
- pnpm build:wasm # 构建 WASM 版本
127
- pnpm build:all # 构建全部
128
- ```
129
-
130
- ## 发版约定
131
-
132
- - 发布级改动默认需要在 PR 中携带 `.changeset/*.md`
133
- - `patch` / `minor` / `major` 由 changeset 决定,不要手改 `package.json.version`
134
- - PR 合并到 `main` 后会自动创建或更新 Release PR;合并 Release PR 后才会正式发布 npm
135
- - 若 GitHub Actions 在 `npm publish` 阶段报 `E404` 或权限类错误,先检查 npm 包设置里的 Trusted Publisher 是否精确匹配 `Hxgh/rfkit-spectrum-analyzer`、`release.yml`、`npm-release`,并确认 `package.json.repository.url` 仍是当前 GitHub 仓库;修配置后直接重跑当前未发布版本,不要继续 bump 版本
136
-
137
129
  ## License
138
130
 
139
131
  MIT
@@ -10,4 +10,3 @@ export declare const DEFAULT_LEVEL_STREAM_CONFIG: {
10
10
  maxPoints: undefined;
11
11
  onLevelStreamUpdate: (data: Map<number, number>) => void;
12
12
  };
13
- //# sourceMappingURL=constants.d.ts.map
@@ -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
@@ -10,4 +10,3 @@ export interface LevelStreamOutputData {
10
10
  spectrumData: Float32Array;
11
11
  timestampData: Float64Array;
12
12
  }
13
- //# sourceMappingURL=types.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: "#00000000";
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
@@ -40,4 +40,3 @@ export interface SubscriptionOptions {
40
40
  eventTypes?: SeriesEventType[];
41
41
  seriesNames?: string[];
42
42
  }
43
- //# sourceMappingURL=types.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: "必须且只能配置 segments 或 bandwidthConfig 其中之一";
43
- readonly EMPTY_BANDWIDTH: "bandwidthConfig 不能为空";
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: "点数必须大于0";
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 | undefined;
4
- constructor(message: string, code: string, details?: unknown | undefined);
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 { isValidFloat32Array, ProcessInput, ProcessingOptions, ScanSegment, SpectrumConfig, SpectrumOutputData, TemplateOverData, ThresholdDataOptions, TimestampedFloat32Array } from './types';
1
+ import type { ExtraDataOptions, isValidFloat32Array, ProcessInput, ProcessingOptions, ScanSegment, SpectrumConfig, SpectrumOutputData, TemplateOverData, ThresholdDataOptions, TimestampedFloat32Array } from './types';
2
2
  import { ExtraDataMode } from './types';
3
3
  export default class SpectrumAnalyzer {
4
4
  config: Required<Omit<SpectrumConfig, 'segments' | 'bandwidthConfig' | 'onSpectrumUpdate'>>;
@@ -40,227 +40,45 @@ export default class SpectrumAnalyzer {
40
40
  private isProcessing;
41
41
  private readonly onSpectrumUpdate?;
42
42
  constructor(config: Partial<SpectrumConfig>);
43
- /**
44
- * 处理输入数据,包括验证、拼接、统计、采样等操作。
45
- * @param {ProcessInput} input - 输入数据,包含数据、时间戳、分段偏移和偏移量。
46
- */
47
43
  process({ data, timestamp, segmentOffset, offset, fluorescenceData, fluorescenceMaxCount }: ProcessInput): void;
48
- /**
49
- * 初始化扫描分段信息,并更新最大点数。
50
- * @param {ScanSegment[]} segments - 扫描分段信息数组。
51
- */
52
44
  initializeSegments(segments: ScanSegment[]): void;
53
- /**
54
- * 设置天线因子数据,并根据开关状态重新输出数据。
55
- * @param {Float32Array} data - 天线因子数据,默认为根据最大点数创建的数组。
56
- */
57
45
  setAntennaFactor(d: Float32Array | number[]): void;
58
- /**
59
- * 设置天线因子开关,并根据开关状态重新输出数据。
60
- * @param {boolean} newAntennaFactorSwitch - 新的天线因子开关状态。
61
- */
62
46
  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
47
  updateProcessing(next: Partial<ProcessingOptions>): void;
75
- /**
76
- * 清空统计指标数据 (Max/Min/Avg)
77
- * 将相关数组重置为初始值,并通知更新。
78
- */
79
48
  clearMetricsData(): void;
80
- /**
81
- * 初始化 metrics 缓冲区(max/min/avg 及其输出缓存)。
82
- * 仅负责分配内存,不负责填充初始值。
83
- */
84
49
  private allocateMetricsBuffers;
85
- /**
86
- * 清空 metrics 缓冲区(max/min/avg 及其输出缓存),并重置 allValid 标记。
87
- * 不会调整数组长度。
88
- */
89
50
  private clearMetricsBuffers;
90
- /**
91
- * 设置瀑布图数据,用于从外部导入已缓存的瀑布图数据。
92
- * @param {TimestampedFloat32Array[]} data - 瀑布图数据数组。
93
- */
94
51
  setWaterfallData(newWaterfallData: TimestampedFloat32Array[]): void;
95
- /**
96
- * 设置荧光累积数据,用于传入预先计算好的荧光累积数据。
97
- * @param {Uint32Array} fluorescenceData - 荧光累积数据
98
- * @param {number} fluorescenceMaxCount - 荧光数据中的最大计数值
99
- */
100
52
  setFluorescenceData(fluorescenceData: Uint32Array, fluorescenceMaxCount: number): void;
101
- /**
102
- * 设置实时值数据,用于从外部导入已缓存的实时值数据。
103
- * @param {TimestampedFloat32Array} data - 实时值数据。
104
- */
105
53
  setRealData(data: TimestampedFloat32Array): void;
106
- /**
107
- * 设置最大值数据,用于从外部导入已缓存的最大值数据。
108
- * @param {Float32Array} data - 最大值数据。
109
- */
110
54
  setMaxData(data: Float32Array): void;
111
- /**
112
- * 设置最小值数据,用于从外部导入已缓存的最小值数据。
113
- * @param {Float32Array} data - 最小值数据。
114
- */
115
55
  setMinData(data: Float32Array): void;
116
- /**
117
- * 设置平均值数据,用于从外部导入已缓存的平均值数据。
118
- * @param {Float32Array} data - 平均值数据。
119
- */
120
56
  setAvgData(data: Float32Array): void;
121
- /**
122
- * 设置占用度数据
123
- * @param {Float32Array | number[]} data - 占用度数据
124
- */
125
57
  setOccupancyData(data?: Float32Array | number[]): void;
126
- /**
127
- * 重置频谱分析器的状态,包括数据和进度。
128
- */
129
- /**
130
- * 设置额外数据
131
- * @param data 数据对象
132
- * @param mode 操作模式:ExtraDataMode.REPLACE(替换全部), ExtraDataMode.MERGE(合并), ExtraDataMode.UPDATE(更新已存在的键)
133
- */
134
- setExtraData(data: Record<string, Float32Array | number[]> | null, mode?: ExtraDataMode): void;
58
+ setExtraData(data: Record<string, Float32Array | number[]> | null, mode?: ExtraDataMode, options?: ExtraDataOptions): void;
135
59
  reset(preserveProcessedFlag?: boolean): void;
136
- /**
137
- * 获取频谱分析器的性能指标,包括处理时间、数据点数、瀑布图帧数、初始化状态和内存使用情况。
138
- * @returns {Readonly<Record<string, number | boolean>>} - 包含性能指标的对象。
139
- */
140
60
  getPerformanceMetrics(): Readonly<Record<string, number | boolean>>;
141
- /**
142
- * 获取当前实时数据的峰值统计信息
143
- * @returns {PeakStats | undefined} - 峰值统计信息,如果未启用峰值检测则返回 undefined
144
- */
145
61
  getPeakStats(): import('./types').PeakStats | undefined;
146
- /**
147
- * 更新采样范围,并重新输出数据。
148
- * @param {number} start - 采样范围的起始位置。
149
- * @param {number} end - 采样范围的结束位置。
150
- * @returns {Uint32Array} - 输出值对应的原始数据索引数组。
151
- */
152
62
  updateSamplingRange(start: number, end: number): Uint32Array;
153
- /**
154
- * 设置模板数据
155
- * @param {Float32Array | number[]} data - 模板数据
156
- * @param {number} templateTolerance - 可选,模板超出计算的容差值
157
- */
158
63
  setTemplateData(data?: Float32Array | number[], templateTolerance?: number): void;
159
- /**
160
- * 设置背景噪声数据
161
- * @param {Float32Array | number[]} data - 背景噪声数据
162
- */
163
64
  setBackgroundNoiseData(data?: Float32Array | number[]): void;
164
- /**
165
- * 设置阈值数据
166
- * @param {Float32Array | number[]} data - 阈值数据
167
- * @param {ThresholdDataOptions} options - 可选,使用 segmentOffset/offset 进行局部门限写入
168
- */
169
65
  setThresholdData(data?: Float32Array | number[], options?: ThresholdDataOptions): void;
170
- /**
171
- * 统一的超出数据段计算和缓存更新方法
172
- * @param forceFullCalculation - 是否强制进行全量计算
173
- * @param incrementalRange - 增量计算的范围
174
- * @returns 计算得到的超出数据段
175
- */
176
66
  private updateTemplateOverData;
177
- /**
178
- * 将分段偏移转换为全局数据索引。
179
- */
180
67
  private resolveGlobalIndex;
181
68
  private clearThresholdDataState;
182
- /**
183
- * 对数据进行重采样,生成频谱输出数据。
184
- * @returns {Partial<SpectrumOutputData>} - 包含重采样后的实时数据、最大值、最小值和平均值的对象。
185
- */
186
69
  protected resampleDataSeries(): Partial<SpectrumOutputData>;
187
- /**
188
- * 处理 extraData 的重采样,生成 extraOutputData
189
- * 利用现有的 srcIndexCache 进行高效重采样
190
- */
191
- /**
192
- * 对瀑布图输出数据进行重采样。
193
- */
194
70
  protected resampleWaterfallOutputData(): void;
195
- /**
196
- * 更新瀑布图数据,包括添加新数据和移除旧数据。
197
- * @param {TimestampedFloat32Array} data - 输入的实时数据。
198
- * @param {TimestampedFloat32Array} outputData - 输出的实时数据。
199
- */
200
71
  protected updateWaterfallData(data: TimestampedFloat32Array, outputData: TimestampedFloat32Array): void;
201
- /**
202
- * 更新最大点数,并重置。
203
- * @param {number} maxPoints - 新的最大点数。
204
- */
205
72
  protected updateMaxPoints(maxPoints: number, preserveProcessedFlag?: boolean): void;
206
- /**
207
- * 验证输入数据的索引是否在有效范围内。
208
- * @param {Float32Array} data - 输入数据。
209
- * @param {number} index - 数据的起始索引。
210
- */
211
73
  protected validateInput(data: Float32Array, index: number): void;
212
- /**
213
- * 统计计算,处理数据点,更新统计值(最大值、最小值、平均值)。
214
- * @param {Float32Array} data - 输入数据。
215
- * @param {number} index - 数据的起始索引。
216
- * @param {boolean} isOver - 数据是否处理完成。
217
- */
218
74
  private processDataPoints;
219
- /**
220
- * 更新荧光谱统计数据
221
- */
222
75
  private updateFluorescenceStats;
223
- /**
224
- * 设置待处理标记并更新快速检查标记
225
- */
226
76
  private setPendingFlag;
227
- /**
228
- * 重采样单个数据数组(统一的重采样逻辑,避免代码重复)
229
- */
230
77
  private resampleSingleData;
231
- /**
232
- * 处理待处理的数据(在 srcIndexCache 生成后)
233
- * 用于解决数据设置和实时数据处理的时序问题
234
- */
235
78
  private processPendingData;
236
- /**
237
- * 通知频谱数据更新,调用回调函数。
238
- * @param {SpectrumOutputData} processedData - 处理后的频谱数据。
239
- */
240
79
  private notifySpectrumUpdate;
241
- /**
242
- * 计算当前频谱分析器的内存使用情况。
243
- * @returns {number} - 内存使用量(字节)。
244
- */
245
80
  private calculateMemoryUsage;
246
- /**
247
- * 获取输出数据,根据配置的输出范围截取数据。
248
- * @param {TimestampedFloat32Array} [data] - 可选的输入数据,默认为实时数据。
249
- * @returns {Readonly<TimestampedFloat32Array>} - 输出数据。
250
- */
251
81
  private getOutputData;
252
- /**
253
- * 获取指定范围的荧光谱数据。
254
- * @param {Map<number, number>[] | undefined} data - 荧光谱数据,如果未提供则使用实例的荧光谱数据。
255
- * @returns {Map<number, number>[] | undefined} - 输出范围内的荧光谱数据。
256
- */
257
82
  private getFluorescenceOutputData;
258
- /**
259
- * 获取数据快照:
260
- * - 输出数据(重采样后)保持原有语义
261
- * - rawData 提供原始全长数据引用(零拷贝)
262
- * - 传入 left 时,返回 cursorIndex 便于光标统一索引
263
- */
264
83
  getAllRawData(left?: number): Readonly<SpectrumOutputData>;
265
84
  }
266
- //# 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
@@ -3,6 +3,10 @@ export declare enum ExtraDataMode {
3
3
  MERGE = "merge",
4
4
  CLEAR = "clear"
5
5
  }
6
+ export interface ExtraDataOptions {
7
+ segmentOffset?: number;
8
+ offset?: number;
9
+ }
6
10
  export interface ScanSegment {
7
11
  startFrequency: number;
8
12
  stopFrequency: number;
@@ -26,10 +30,6 @@ export interface ProcessingConfig {
26
30
  readonly enablePeakStats: boolean;
27
31
  readonly fluorescenceUpdateInterval: number;
28
32
  }
29
- /**
30
- * ProcessingOptions - 用于动态更新处理选项的类型。
31
- * 仅包含允许在运行时更新的字段。
32
- */
33
33
  export type ProcessingOptions = Pick<ProcessingConfig, 'enableMetrics' | 'enableFluorescence' | 'enablePeakStats' | 'fluorescenceUpdateInterval'>;
34
34
  export interface PeakDetectionConfig {
35
35
  maxPeaks?: number;
@@ -123,4 +123,3 @@ export interface ISpectrumAnalyzer {
123
123
  readonly antennaFactorSwitch: boolean;
124
124
  readonly srcIndexCache: Uint32Array;
125
125
  }
126
- //# sourceMappingURL=types.d.ts.map