wsjtx-lib 1.0.4 → 1.1.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.
@@ -1,4004 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
-
28
- // node_modules/stream-parser/node_modules/ms/index.js
29
- var require_ms = __commonJS({
30
- "node_modules/stream-parser/node_modules/ms/index.js"(exports2, module2) {
31
- "use strict";
32
- var s = 1e3;
33
- var m = s * 60;
34
- var h = m * 60;
35
- var d = h * 24;
36
- var y = d * 365.25;
37
- module2.exports = function(val, options) {
38
- options = options || {};
39
- var type = typeof val;
40
- if (type === "string" && val.length > 0) {
41
- return parse(val);
42
- } else if (type === "number" && isNaN(val) === false) {
43
- return options.long ? fmtLong(val) : fmtShort(val);
44
- }
45
- throw new Error(
46
- "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
47
- );
48
- };
49
- function parse(str) {
50
- str = String(str);
51
- if (str.length > 100) {
52
- return;
53
- }
54
- var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
55
- str
56
- );
57
- if (!match) {
58
- return;
59
- }
60
- var n = parseFloat(match[1]);
61
- var type = (match[2] || "ms").toLowerCase();
62
- switch (type) {
63
- case "years":
64
- case "year":
65
- case "yrs":
66
- case "yr":
67
- case "y":
68
- return n * y;
69
- case "days":
70
- case "day":
71
- case "d":
72
- return n * d;
73
- case "hours":
74
- case "hour":
75
- case "hrs":
76
- case "hr":
77
- case "h":
78
- return n * h;
79
- case "minutes":
80
- case "minute":
81
- case "mins":
82
- case "min":
83
- case "m":
84
- return n * m;
85
- case "seconds":
86
- case "second":
87
- case "secs":
88
- case "sec":
89
- case "s":
90
- return n * s;
91
- case "milliseconds":
92
- case "millisecond":
93
- case "msecs":
94
- case "msec":
95
- case "ms":
96
- return n;
97
- default:
98
- return void 0;
99
- }
100
- }
101
- function fmtShort(ms) {
102
- if (ms >= d) {
103
- return Math.round(ms / d) + "d";
104
- }
105
- if (ms >= h) {
106
- return Math.round(ms / h) + "h";
107
- }
108
- if (ms >= m) {
109
- return Math.round(ms / m) + "m";
110
- }
111
- if (ms >= s) {
112
- return Math.round(ms / s) + "s";
113
- }
114
- return ms + "ms";
115
- }
116
- function fmtLong(ms) {
117
- return plural(ms, d, "day") || plural(ms, h, "hour") || plural(ms, m, "minute") || plural(ms, s, "second") || ms + " ms";
118
- }
119
- function plural(ms, n, name) {
120
- if (ms < n) {
121
- return;
122
- }
123
- if (ms < n * 1.5) {
124
- return Math.floor(ms / n) + " " + name;
125
- }
126
- return Math.ceil(ms / n) + " " + name + "s";
127
- }
128
- }
129
- });
130
-
131
- // node_modules/stream-parser/node_modules/debug/src/debug.js
132
- var require_debug = __commonJS({
133
- "node_modules/stream-parser/node_modules/debug/src/debug.js"(exports2, module2) {
134
- "use strict";
135
- exports2 = module2.exports = createDebug.debug = createDebug["default"] = createDebug;
136
- exports2.coerce = coerce;
137
- exports2.disable = disable;
138
- exports2.enable = enable;
139
- exports2.enabled = enabled;
140
- exports2.humanize = require_ms();
141
- exports2.names = [];
142
- exports2.skips = [];
143
- exports2.formatters = {};
144
- var prevTime;
145
- function selectColor(namespace) {
146
- var hash = 0, i;
147
- for (i in namespace) {
148
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
149
- hash |= 0;
150
- }
151
- return exports2.colors[Math.abs(hash) % exports2.colors.length];
152
- }
153
- function createDebug(namespace) {
154
- function debug() {
155
- if (!debug.enabled) return;
156
- var self = debug;
157
- var curr = +/* @__PURE__ */ new Date();
158
- var ms = curr - (prevTime || curr);
159
- self.diff = ms;
160
- self.prev = prevTime;
161
- self.curr = curr;
162
- prevTime = curr;
163
- var args = new Array(arguments.length);
164
- for (var i = 0; i < args.length; i++) {
165
- args[i] = arguments[i];
166
- }
167
- args[0] = exports2.coerce(args[0]);
168
- if ("string" !== typeof args[0]) {
169
- args.unshift("%O");
170
- }
171
- var index = 0;
172
- args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
173
- if (match === "%%") return match;
174
- index++;
175
- var formatter = exports2.formatters[format];
176
- if ("function" === typeof formatter) {
177
- var val = args[index];
178
- match = formatter.call(self, val);
179
- args.splice(index, 1);
180
- index--;
181
- }
182
- return match;
183
- });
184
- exports2.formatArgs.call(self, args);
185
- var logFn = debug.log || exports2.log || console.log.bind(console);
186
- logFn.apply(self, args);
187
- }
188
- debug.namespace = namespace;
189
- debug.enabled = exports2.enabled(namespace);
190
- debug.useColors = exports2.useColors();
191
- debug.color = selectColor(namespace);
192
- if ("function" === typeof exports2.init) {
193
- exports2.init(debug);
194
- }
195
- return debug;
196
- }
197
- function enable(namespaces) {
198
- exports2.save(namespaces);
199
- exports2.names = [];
200
- exports2.skips = [];
201
- var split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
202
- var len = split.length;
203
- for (var i = 0; i < len; i++) {
204
- if (!split[i]) continue;
205
- namespaces = split[i].replace(/\*/g, ".*?");
206
- if (namespaces[0] === "-") {
207
- exports2.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
208
- } else {
209
- exports2.names.push(new RegExp("^" + namespaces + "$"));
210
- }
211
- }
212
- }
213
- function disable() {
214
- exports2.enable("");
215
- }
216
- function enabled(name) {
217
- var i, len;
218
- for (i = 0, len = exports2.skips.length; i < len; i++) {
219
- if (exports2.skips[i].test(name)) {
220
- return false;
221
- }
222
- }
223
- for (i = 0, len = exports2.names.length; i < len; i++) {
224
- if (exports2.names[i].test(name)) {
225
- return true;
226
- }
227
- }
228
- return false;
229
- }
230
- function coerce(val) {
231
- if (val instanceof Error) return val.stack || val.message;
232
- return val;
233
- }
234
- }
235
- });
236
-
237
- // node_modules/stream-parser/node_modules/debug/src/browser.js
238
- var require_browser = __commonJS({
239
- "node_modules/stream-parser/node_modules/debug/src/browser.js"(exports2, module2) {
240
- "use strict";
241
- exports2 = module2.exports = require_debug();
242
- exports2.log = log;
243
- exports2.formatArgs = formatArgs;
244
- exports2.save = save;
245
- exports2.load = load;
246
- exports2.useColors = useColors;
247
- exports2.storage = "undefined" != typeof chrome && "undefined" != typeof chrome.storage ? chrome.storage.local : localstorage();
248
- exports2.colors = [
249
- "lightseagreen",
250
- "forestgreen",
251
- "goldenrod",
252
- "dodgerblue",
253
- "darkorchid",
254
- "crimson"
255
- ];
256
- function useColors() {
257
- if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
258
- return true;
259
- }
260
- return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // is firebug? http://stackoverflow.com/a/398120/376773
261
- typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // is firefox >= v31?
262
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
263
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // double check webkit in userAgent just in case we are in a worker
264
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
265
- }
266
- exports2.formatters.j = function(v) {
267
- try {
268
- return JSON.stringify(v);
269
- } catch (err) {
270
- return "[UnexpectedJSONParseError]: " + err.message;
271
- }
272
- };
273
- function formatArgs(args) {
274
- var useColors2 = this.useColors;
275
- args[0] = (useColors2 ? "%c" : "") + this.namespace + (useColors2 ? " %c" : " ") + args[0] + (useColors2 ? "%c " : " ") + "+" + exports2.humanize(this.diff);
276
- if (!useColors2) return;
277
- var c = "color: " + this.color;
278
- args.splice(1, 0, c, "color: inherit");
279
- var index = 0;
280
- var lastC = 0;
281
- args[0].replace(/%[a-zA-Z%]/g, function(match) {
282
- if ("%%" === match) return;
283
- index++;
284
- if ("%c" === match) {
285
- lastC = index;
286
- }
287
- });
288
- args.splice(lastC, 0, c);
289
- }
290
- function log() {
291
- return "object" === typeof console && console.log && Function.prototype.apply.call(console.log, console, arguments);
292
- }
293
- function save(namespaces) {
294
- try {
295
- if (null == namespaces) {
296
- exports2.storage.removeItem("debug");
297
- } else {
298
- exports2.storage.debug = namespaces;
299
- }
300
- } catch (e) {
301
- }
302
- }
303
- function load() {
304
- var r;
305
- try {
306
- r = exports2.storage.debug;
307
- } catch (e) {
308
- }
309
- if (!r && typeof process !== "undefined" && "env" in process) {
310
- r = process.env.DEBUG;
311
- }
312
- return r;
313
- }
314
- exports2.enable(load());
315
- function localstorage() {
316
- try {
317
- return window.localStorage;
318
- } catch (e) {
319
- }
320
- }
321
- }
322
- });
323
-
324
- // node_modules/stream-parser/node_modules/debug/src/node.js
325
- var require_node = __commonJS({
326
- "node_modules/stream-parser/node_modules/debug/src/node.js"(exports2, module2) {
327
- "use strict";
328
- var tty = require("tty");
329
- var util = require("util");
330
- exports2 = module2.exports = require_debug();
331
- exports2.init = init;
332
- exports2.log = log;
333
- exports2.formatArgs = formatArgs;
334
- exports2.save = save;
335
- exports2.load = load;
336
- exports2.useColors = useColors;
337
- exports2.colors = [6, 2, 3, 4, 5, 1];
338
- exports2.inspectOpts = Object.keys(process.env).filter(function(key) {
339
- return /^debug_/i.test(key);
340
- }).reduce(function(obj, key) {
341
- var prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, function(_, k) {
342
- return k.toUpperCase();
343
- });
344
- var val = process.env[key];
345
- if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
346
- else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
347
- else if (val === "null") val = null;
348
- else val = Number(val);
349
- obj[prop] = val;
350
- return obj;
351
- }, {});
352
- var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
353
- if (1 !== fd && 2 !== fd) {
354
- util.deprecate(function() {
355
- }, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();
356
- }
357
- var stream = 1 === fd ? process.stdout : 2 === fd ? process.stderr : createWritableStdioStream(fd);
358
- function useColors() {
359
- return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(fd);
360
- }
361
- exports2.formatters.o = function(v) {
362
- this.inspectOpts.colors = this.useColors;
363
- return util.inspect(v, this.inspectOpts).split("\n").map(function(str) {
364
- return str.trim();
365
- }).join(" ");
366
- };
367
- exports2.formatters.O = function(v) {
368
- this.inspectOpts.colors = this.useColors;
369
- return util.inspect(v, this.inspectOpts);
370
- };
371
- function formatArgs(args) {
372
- var name = this.namespace;
373
- var useColors2 = this.useColors;
374
- if (useColors2) {
375
- var c = this.color;
376
- var prefix = " \x1B[3" + c + ";1m" + name + " \x1B[0m";
377
- args[0] = prefix + args[0].split("\n").join("\n" + prefix);
378
- args.push("\x1B[3" + c + "m+" + exports2.humanize(this.diff) + "\x1B[0m");
379
- } else {
380
- args[0] = (/* @__PURE__ */ new Date()).toUTCString() + " " + name + " " + args[0];
381
- }
382
- }
383
- function log() {
384
- return stream.write(util.format.apply(util, arguments) + "\n");
385
- }
386
- function save(namespaces) {
387
- if (null == namespaces) {
388
- delete process.env.DEBUG;
389
- } else {
390
- process.env.DEBUG = namespaces;
391
- }
392
- }
393
- function load() {
394
- return process.env.DEBUG;
395
- }
396
- function createWritableStdioStream(fd2) {
397
- var stream2;
398
- var tty_wrap = process.binding("tty_wrap");
399
- switch (tty_wrap.guessHandleType(fd2)) {
400
- case "TTY":
401
- stream2 = new tty.WriteStream(fd2);
402
- stream2._type = "tty";
403
- if (stream2._handle && stream2._handle.unref) {
404
- stream2._handle.unref();
405
- }
406
- break;
407
- case "FILE":
408
- var fs3 = require("fs");
409
- stream2 = new fs3.SyncWriteStream(fd2, { autoClose: false });
410
- stream2._type = "fs";
411
- break;
412
- case "PIPE":
413
- case "TCP":
414
- var net = require("net");
415
- stream2 = new net.Socket({
416
- fd: fd2,
417
- readable: false,
418
- writable: true
419
- });
420
- stream2.readable = false;
421
- stream2.read = null;
422
- stream2._type = "pipe";
423
- if (stream2._handle && stream2._handle.unref) {
424
- stream2._handle.unref();
425
- }
426
- break;
427
- default:
428
- throw new Error("Implement me. Unknown stream file type!");
429
- }
430
- stream2.fd = fd2;
431
- stream2._isStdio = true;
432
- return stream2;
433
- }
434
- function init(debug) {
435
- debug.inspectOpts = {};
436
- var keys = Object.keys(exports2.inspectOpts);
437
- for (var i = 0; i < keys.length; i++) {
438
- debug.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
439
- }
440
- }
441
- exports2.enable(load());
442
- }
443
- });
444
-
445
- // node_modules/stream-parser/node_modules/debug/src/index.js
446
- var require_src = __commonJS({
447
- "node_modules/stream-parser/node_modules/debug/src/index.js"(exports2, module2) {
448
- "use strict";
449
- if (typeof process !== "undefined" && process.type === "renderer") {
450
- module2.exports = require_browser();
451
- } else {
452
- module2.exports = require_node();
453
- }
454
- }
455
- });
456
-
457
- // node_modules/stream-parser/index.js
458
- var require_stream_parser = __commonJS({
459
- "node_modules/stream-parser/index.js"(exports2, module2) {
460
- "use strict";
461
- var assert2 = require("assert");
462
- var debug = require_src()("stream-parser");
463
- module2.exports = Parser;
464
- var INIT = -1;
465
- var BUFFERING = 0;
466
- var SKIPPING = 1;
467
- var PASSTHROUGH = 2;
468
- function Parser(stream) {
469
- var isTransform = stream && "function" == typeof stream._transform;
470
- var isWritable = stream && "function" == typeof stream._write;
471
- if (!isTransform && !isWritable) throw new Error("must pass a Writable or Transform stream in");
472
- debug("extending Parser into stream");
473
- stream._bytes = _bytes;
474
- stream._skipBytes = _skipBytes;
475
- if (isTransform) stream._passthrough = _passthrough;
476
- if (isTransform) {
477
- stream._transform = transform;
478
- } else {
479
- stream._write = write;
480
- }
481
- }
482
- function init(stream) {
483
- debug("initializing parser stream");
484
- stream._parserBytesLeft = 0;
485
- stream._parserBuffers = [];
486
- stream._parserBuffered = 0;
487
- stream._parserState = INIT;
488
- stream._parserCallback = null;
489
- if ("function" == typeof stream.push) {
490
- stream._parserOutput = stream.push.bind(stream);
491
- }
492
- stream._parserInit = true;
493
- }
494
- function _bytes(n, fn) {
495
- assert2(!this._parserCallback, 'there is already a "callback" set!');
496
- assert2(isFinite(n) && n > 0, 'can only buffer a finite number of bytes > 0, got "' + n + '"');
497
- if (!this._parserInit) init(this);
498
- debug("buffering %o bytes", n);
499
- this._parserBytesLeft = n;
500
- this._parserCallback = fn;
501
- this._parserState = BUFFERING;
502
- }
503
- function _skipBytes(n, fn) {
504
- assert2(!this._parserCallback, 'there is already a "callback" set!');
505
- assert2(n > 0, 'can only skip > 0 bytes, got "' + n + '"');
506
- if (!this._parserInit) init(this);
507
- debug("skipping %o bytes", n);
508
- this._parserBytesLeft = n;
509
- this._parserCallback = fn;
510
- this._parserState = SKIPPING;
511
- }
512
- function _passthrough(n, fn) {
513
- assert2(!this._parserCallback, 'There is already a "callback" set!');
514
- assert2(n > 0, 'can only pass through > 0 bytes, got "' + n + '"');
515
- if (!this._parserInit) init(this);
516
- debug("passing through %o bytes", n);
517
- this._parserBytesLeft = n;
518
- this._parserCallback = fn;
519
- this._parserState = PASSTHROUGH;
520
- }
521
- function write(chunk, encoding, fn) {
522
- if (!this._parserInit) init(this);
523
- debug("write(%o bytes)", chunk.length);
524
- if ("function" == typeof encoding) fn = encoding;
525
- data(this, chunk, null, fn);
526
- }
527
- function transform(chunk, output, fn) {
528
- if (!this._parserInit) init(this);
529
- debug("transform(%o bytes)", chunk.length);
530
- if ("function" != typeof output) {
531
- output = this._parserOutput;
532
- }
533
- data(this, chunk, output, fn);
534
- }
535
- function _data(stream, chunk, output, fn) {
536
- if (stream._parserBytesLeft <= 0) {
537
- return fn(new Error("got data but not currently parsing anything"));
538
- }
539
- if (chunk.length <= stream._parserBytesLeft) {
540
- return function() {
541
- return process2(stream, chunk, output, fn);
542
- };
543
- } else {
544
- return function() {
545
- var b = chunk.slice(0, stream._parserBytesLeft);
546
- return process2(stream, b, output, function(err) {
547
- if (err) return fn(err);
548
- if (chunk.length > b.length) {
549
- return function() {
550
- return _data(stream, chunk.slice(b.length), output, fn);
551
- };
552
- }
553
- });
554
- };
555
- }
556
- }
557
- function process2(stream, chunk, output, fn) {
558
- stream._parserBytesLeft -= chunk.length;
559
- debug("%o bytes left for stream piece", stream._parserBytesLeft);
560
- if (stream._parserState === BUFFERING) {
561
- stream._parserBuffers.push(chunk);
562
- stream._parserBuffered += chunk.length;
563
- } else if (stream._parserState === PASSTHROUGH) {
564
- output(chunk);
565
- }
566
- if (0 === stream._parserBytesLeft) {
567
- var cb = stream._parserCallback;
568
- if (cb && stream._parserState === BUFFERING && stream._parserBuffers.length > 1) {
569
- chunk = Buffer.concat(stream._parserBuffers, stream._parserBuffered);
570
- }
571
- if (stream._parserState !== BUFFERING) {
572
- chunk = null;
573
- }
574
- stream._parserCallback = null;
575
- stream._parserBuffered = 0;
576
- stream._parserState = INIT;
577
- stream._parserBuffers.splice(0);
578
- if (cb) {
579
- var args = [];
580
- if (chunk) {
581
- args.push(chunk);
582
- } else {
583
- }
584
- if (output) {
585
- args.push(output);
586
- }
587
- var async = cb.length > args.length;
588
- if (async) {
589
- args.push(trampoline(fn));
590
- }
591
- var rtn = cb.apply(stream, args);
592
- if (!async || fn === rtn) return fn;
593
- }
594
- } else {
595
- return fn;
596
- }
597
- }
598
- var data = trampoline(_data);
599
- function trampoline(fn) {
600
- return function() {
601
- var result = fn.apply(this, arguments);
602
- while ("function" == typeof result) {
603
- result = result();
604
- }
605
- return result;
606
- };
607
- }
608
- }
609
- });
610
-
611
- // node_modules/core-util-is/lib/util.js
612
- var require_util = __commonJS({
613
- "node_modules/core-util-is/lib/util.js"(exports2) {
614
- "use strict";
615
- function isArray(arg) {
616
- if (Array.isArray) {
617
- return Array.isArray(arg);
618
- }
619
- return objectToString(arg) === "[object Array]";
620
- }
621
- exports2.isArray = isArray;
622
- function isBoolean(arg) {
623
- return typeof arg === "boolean";
624
- }
625
- exports2.isBoolean = isBoolean;
626
- function isNull(arg) {
627
- return arg === null;
628
- }
629
- exports2.isNull = isNull;
630
- function isNullOrUndefined(arg) {
631
- return arg == null;
632
- }
633
- exports2.isNullOrUndefined = isNullOrUndefined;
634
- function isNumber(arg) {
635
- return typeof arg === "number";
636
- }
637
- exports2.isNumber = isNumber;
638
- function isString(arg) {
639
- return typeof arg === "string";
640
- }
641
- exports2.isString = isString;
642
- function isSymbol(arg) {
643
- return typeof arg === "symbol";
644
- }
645
- exports2.isSymbol = isSymbol;
646
- function isUndefined(arg) {
647
- return arg === void 0;
648
- }
649
- exports2.isUndefined = isUndefined;
650
- function isRegExp(re) {
651
- return objectToString(re) === "[object RegExp]";
652
- }
653
- exports2.isRegExp = isRegExp;
654
- function isObject(arg) {
655
- return typeof arg === "object" && arg !== null;
656
- }
657
- exports2.isObject = isObject;
658
- function isDate(d) {
659
- return objectToString(d) === "[object Date]";
660
- }
661
- exports2.isDate = isDate;
662
- function isError(e) {
663
- return objectToString(e) === "[object Error]" || e instanceof Error;
664
- }
665
- exports2.isError = isError;
666
- function isFunction(arg) {
667
- return typeof arg === "function";
668
- }
669
- exports2.isFunction = isFunction;
670
- function isPrimitive(arg) {
671
- return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || // ES6 symbol
672
- typeof arg === "undefined";
673
- }
674
- exports2.isPrimitive = isPrimitive;
675
- exports2.isBuffer = require("buffer").Buffer.isBuffer;
676
- function objectToString(o) {
677
- return Object.prototype.toString.call(o);
678
- }
679
- }
680
- });
681
-
682
- // node_modules/inherits/inherits_browser.js
683
- var require_inherits_browser = __commonJS({
684
- "node_modules/inherits/inherits_browser.js"(exports2, module2) {
685
- "use strict";
686
- if (typeof Object.create === "function") {
687
- module2.exports = function inherits(ctor, superCtor) {
688
- if (superCtor) {
689
- ctor.super_ = superCtor;
690
- ctor.prototype = Object.create(superCtor.prototype, {
691
- constructor: {
692
- value: ctor,
693
- enumerable: false,
694
- writable: true,
695
- configurable: true
696
- }
697
- });
698
- }
699
- };
700
- } else {
701
- module2.exports = function inherits(ctor, superCtor) {
702
- if (superCtor) {
703
- ctor.super_ = superCtor;
704
- var TempCtor = function() {
705
- };
706
- TempCtor.prototype = superCtor.prototype;
707
- ctor.prototype = new TempCtor();
708
- ctor.prototype.constructor = ctor;
709
- }
710
- };
711
- }
712
- }
713
- });
714
-
715
- // node_modules/inherits/inherits.js
716
- var require_inherits = __commonJS({
717
- "node_modules/inherits/inherits.js"(exports2, module2) {
718
- "use strict";
719
- try {
720
- util = require("util");
721
- if (typeof util.inherits !== "function") throw "";
722
- module2.exports = util.inherits;
723
- } catch (e) {
724
- module2.exports = require_inherits_browser();
725
- }
726
- var util;
727
- }
728
- });
729
-
730
- // node_modules/isarray/index.js
731
- var require_isarray = __commonJS({
732
- "node_modules/isarray/index.js"(exports2, module2) {
733
- "use strict";
734
- module2.exports = Array.isArray || function(arr) {
735
- return Object.prototype.toString.call(arr) == "[object Array]";
736
- };
737
- }
738
- });
739
-
740
- // node_modules/wav/node_modules/string_decoder/index.js
741
- var require_string_decoder = __commonJS({
742
- "node_modules/wav/node_modules/string_decoder/index.js"(exports2) {
743
- "use strict";
744
- var Buffer2 = require("buffer").Buffer;
745
- var isBufferEncoding = Buffer2.isEncoding || function(encoding) {
746
- switch (encoding && encoding.toLowerCase()) {
747
- case "hex":
748
- case "utf8":
749
- case "utf-8":
750
- case "ascii":
751
- case "binary":
752
- case "base64":
753
- case "ucs2":
754
- case "ucs-2":
755
- case "utf16le":
756
- case "utf-16le":
757
- case "raw":
758
- return true;
759
- default:
760
- return false;
761
- }
762
- };
763
- function assertEncoding(encoding) {
764
- if (encoding && !isBufferEncoding(encoding)) {
765
- throw new Error("Unknown encoding: " + encoding);
766
- }
767
- }
768
- var StringDecoder = exports2.StringDecoder = function(encoding) {
769
- this.encoding = (encoding || "utf8").toLowerCase().replace(/[-_]/, "");
770
- assertEncoding(encoding);
771
- switch (this.encoding) {
772
- case "utf8":
773
- this.surrogateSize = 3;
774
- break;
775
- case "ucs2":
776
- case "utf16le":
777
- this.surrogateSize = 2;
778
- this.detectIncompleteChar = utf16DetectIncompleteChar;
779
- break;
780
- case "base64":
781
- this.surrogateSize = 3;
782
- this.detectIncompleteChar = base64DetectIncompleteChar;
783
- break;
784
- default:
785
- this.write = passThroughWrite;
786
- return;
787
- }
788
- this.charBuffer = new Buffer2(6);
789
- this.charReceived = 0;
790
- this.charLength = 0;
791
- };
792
- StringDecoder.prototype.write = function(buffer) {
793
- var charStr = "";
794
- while (this.charLength) {
795
- var available = buffer.length >= this.charLength - this.charReceived ? this.charLength - this.charReceived : buffer.length;
796
- buffer.copy(this.charBuffer, this.charReceived, 0, available);
797
- this.charReceived += available;
798
- if (this.charReceived < this.charLength) {
799
- return "";
800
- }
801
- buffer = buffer.slice(available, buffer.length);
802
- charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
803
- var charCode = charStr.charCodeAt(charStr.length - 1);
804
- if (charCode >= 55296 && charCode <= 56319) {
805
- this.charLength += this.surrogateSize;
806
- charStr = "";
807
- continue;
808
- }
809
- this.charReceived = this.charLength = 0;
810
- if (buffer.length === 0) {
811
- return charStr;
812
- }
813
- break;
814
- }
815
- this.detectIncompleteChar(buffer);
816
- var end = buffer.length;
817
- if (this.charLength) {
818
- buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
819
- end -= this.charReceived;
820
- }
821
- charStr += buffer.toString(this.encoding, 0, end);
822
- var end = charStr.length - 1;
823
- var charCode = charStr.charCodeAt(end);
824
- if (charCode >= 55296 && charCode <= 56319) {
825
- var size = this.surrogateSize;
826
- this.charLength += size;
827
- this.charReceived += size;
828
- this.charBuffer.copy(this.charBuffer, size, 0, size);
829
- buffer.copy(this.charBuffer, 0, 0, size);
830
- return charStr.substring(0, end);
831
- }
832
- return charStr;
833
- };
834
- StringDecoder.prototype.detectIncompleteChar = function(buffer) {
835
- var i = buffer.length >= 3 ? 3 : buffer.length;
836
- for (; i > 0; i--) {
837
- var c = buffer[buffer.length - i];
838
- if (i == 1 && c >> 5 == 6) {
839
- this.charLength = 2;
840
- break;
841
- }
842
- if (i <= 2 && c >> 4 == 14) {
843
- this.charLength = 3;
844
- break;
845
- }
846
- if (i <= 3 && c >> 3 == 30) {
847
- this.charLength = 4;
848
- break;
849
- }
850
- }
851
- this.charReceived = i;
852
- };
853
- StringDecoder.prototype.end = function(buffer) {
854
- var res = "";
855
- if (buffer && buffer.length)
856
- res = this.write(buffer);
857
- if (this.charReceived) {
858
- var cr = this.charReceived;
859
- var buf = this.charBuffer;
860
- var enc = this.encoding;
861
- res += buf.slice(0, cr).toString(enc);
862
- }
863
- return res;
864
- };
865
- function passThroughWrite(buffer) {
866
- return buffer.toString(this.encoding);
867
- }
868
- function utf16DetectIncompleteChar(buffer) {
869
- this.charReceived = buffer.length % 2;
870
- this.charLength = this.charReceived ? 2 : 0;
871
- }
872
- function base64DetectIncompleteChar(buffer) {
873
- this.charReceived = buffer.length % 3;
874
- this.charLength = this.charReceived ? 3 : 0;
875
- }
876
- }
877
- });
878
-
879
- // node_modules/wav/node_modules/readable-stream/lib/_stream_readable.js
880
- var require_stream_readable = __commonJS({
881
- "node_modules/wav/node_modules/readable-stream/lib/_stream_readable.js"(exports2, module2) {
882
- "use strict";
883
- module2.exports = Readable;
884
- var isArray = require_isarray();
885
- var Buffer2 = require("buffer").Buffer;
886
- Readable.ReadableState = ReadableState;
887
- var EE = require("events").EventEmitter;
888
- if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
889
- return emitter.listeners(type).length;
890
- };
891
- var Stream = require("stream");
892
- var util = require_util();
893
- util.inherits = require_inherits();
894
- var StringDecoder;
895
- var debug = require("util");
896
- if (debug && debug.debuglog) {
897
- debug = debug.debuglog("stream");
898
- } else {
899
- debug = function() {
900
- };
901
- }
902
- util.inherits(Readable, Stream);
903
- function ReadableState(options, stream) {
904
- var Duplex = require_stream_duplex();
905
- options = options || {};
906
- var hwm = options.highWaterMark;
907
- var defaultHwm = options.objectMode ? 16 : 16 * 1024;
908
- this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
909
- this.highWaterMark = ~~this.highWaterMark;
910
- this.buffer = [];
911
- this.length = 0;
912
- this.pipes = null;
913
- this.pipesCount = 0;
914
- this.flowing = null;
915
- this.ended = false;
916
- this.endEmitted = false;
917
- this.reading = false;
918
- this.sync = true;
919
- this.needReadable = false;
920
- this.emittedReadable = false;
921
- this.readableListening = false;
922
- this.objectMode = !!options.objectMode;
923
- if (stream instanceof Duplex)
924
- this.objectMode = this.objectMode || !!options.readableObjectMode;
925
- this.defaultEncoding = options.defaultEncoding || "utf8";
926
- this.ranOut = false;
927
- this.awaitDrain = 0;
928
- this.readingMore = false;
929
- this.decoder = null;
930
- this.encoding = null;
931
- if (options.encoding) {
932
- if (!StringDecoder)
933
- StringDecoder = require_string_decoder().StringDecoder;
934
- this.decoder = new StringDecoder(options.encoding);
935
- this.encoding = options.encoding;
936
- }
937
- }
938
- function Readable(options) {
939
- var Duplex = require_stream_duplex();
940
- if (!(this instanceof Readable))
941
- return new Readable(options);
942
- this._readableState = new ReadableState(options, this);
943
- this.readable = true;
944
- Stream.call(this);
945
- }
946
- Readable.prototype.push = function(chunk, encoding) {
947
- var state = this._readableState;
948
- if (util.isString(chunk) && !state.objectMode) {
949
- encoding = encoding || state.defaultEncoding;
950
- if (encoding !== state.encoding) {
951
- chunk = new Buffer2(chunk, encoding);
952
- encoding = "";
953
- }
954
- }
955
- return readableAddChunk(this, state, chunk, encoding, false);
956
- };
957
- Readable.prototype.unshift = function(chunk) {
958
- var state = this._readableState;
959
- return readableAddChunk(this, state, chunk, "", true);
960
- };
961
- function readableAddChunk(stream, state, chunk, encoding, addToFront) {
962
- var er = chunkInvalid(state, chunk);
963
- if (er) {
964
- stream.emit("error", er);
965
- } else if (util.isNullOrUndefined(chunk)) {
966
- state.reading = false;
967
- if (!state.ended)
968
- onEofChunk(stream, state);
969
- } else if (state.objectMode || chunk && chunk.length > 0) {
970
- if (state.ended && !addToFront) {
971
- var e = new Error("stream.push() after EOF");
972
- stream.emit("error", e);
973
- } else if (state.endEmitted && addToFront) {
974
- var e = new Error("stream.unshift() after end event");
975
- stream.emit("error", e);
976
- } else {
977
- if (state.decoder && !addToFront && !encoding)
978
- chunk = state.decoder.write(chunk);
979
- if (!addToFront)
980
- state.reading = false;
981
- if (state.flowing && state.length === 0 && !state.sync) {
982
- stream.emit("data", chunk);
983
- stream.read(0);
984
- } else {
985
- state.length += state.objectMode ? 1 : chunk.length;
986
- if (addToFront)
987
- state.buffer.unshift(chunk);
988
- else
989
- state.buffer.push(chunk);
990
- if (state.needReadable)
991
- emitReadable(stream);
992
- }
993
- maybeReadMore(stream, state);
994
- }
995
- } else if (!addToFront) {
996
- state.reading = false;
997
- }
998
- return needMoreData(state);
999
- }
1000
- function needMoreData(state) {
1001
- return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
1002
- }
1003
- Readable.prototype.setEncoding = function(enc) {
1004
- if (!StringDecoder)
1005
- StringDecoder = require_string_decoder().StringDecoder;
1006
- this._readableState.decoder = new StringDecoder(enc);
1007
- this._readableState.encoding = enc;
1008
- return this;
1009
- };
1010
- var MAX_HWM = 8388608;
1011
- function roundUpToNextPowerOf2(n) {
1012
- if (n >= MAX_HWM) {
1013
- n = MAX_HWM;
1014
- } else {
1015
- n--;
1016
- for (var p = 1; p < 32; p <<= 1) n |= n >> p;
1017
- n++;
1018
- }
1019
- return n;
1020
- }
1021
- function howMuchToRead(n, state) {
1022
- if (state.length === 0 && state.ended)
1023
- return 0;
1024
- if (state.objectMode)
1025
- return n === 0 ? 0 : 1;
1026
- if (isNaN(n) || util.isNull(n)) {
1027
- if (state.flowing && state.buffer.length)
1028
- return state.buffer[0].length;
1029
- else
1030
- return state.length;
1031
- }
1032
- if (n <= 0)
1033
- return 0;
1034
- if (n > state.highWaterMark)
1035
- state.highWaterMark = roundUpToNextPowerOf2(n);
1036
- if (n > state.length) {
1037
- if (!state.ended) {
1038
- state.needReadable = true;
1039
- return 0;
1040
- } else
1041
- return state.length;
1042
- }
1043
- return n;
1044
- }
1045
- Readable.prototype.read = function(n) {
1046
- debug("read", n);
1047
- var state = this._readableState;
1048
- var nOrig = n;
1049
- if (!util.isNumber(n) || n > 0)
1050
- state.emittedReadable = false;
1051
- if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
1052
- debug("read: emitReadable", state.length, state.ended);
1053
- if (state.length === 0 && state.ended)
1054
- endReadable(this);
1055
- else
1056
- emitReadable(this);
1057
- return null;
1058
- }
1059
- n = howMuchToRead(n, state);
1060
- if (n === 0 && state.ended) {
1061
- if (state.length === 0)
1062
- endReadable(this);
1063
- return null;
1064
- }
1065
- var doRead = state.needReadable;
1066
- debug("need readable", doRead);
1067
- if (state.length === 0 || state.length - n < state.highWaterMark) {
1068
- doRead = true;
1069
- debug("length less than watermark", doRead);
1070
- }
1071
- if (state.ended || state.reading) {
1072
- doRead = false;
1073
- debug("reading or ended", doRead);
1074
- }
1075
- if (doRead) {
1076
- debug("do read");
1077
- state.reading = true;
1078
- state.sync = true;
1079
- if (state.length === 0)
1080
- state.needReadable = true;
1081
- this._read(state.highWaterMark);
1082
- state.sync = false;
1083
- }
1084
- if (doRead && !state.reading)
1085
- n = howMuchToRead(nOrig, state);
1086
- var ret;
1087
- if (n > 0)
1088
- ret = fromList(n, state);
1089
- else
1090
- ret = null;
1091
- if (util.isNull(ret)) {
1092
- state.needReadable = true;
1093
- n = 0;
1094
- }
1095
- state.length -= n;
1096
- if (state.length === 0 && !state.ended)
1097
- state.needReadable = true;
1098
- if (nOrig !== n && state.ended && state.length === 0)
1099
- endReadable(this);
1100
- if (!util.isNull(ret))
1101
- this.emit("data", ret);
1102
- return ret;
1103
- };
1104
- function chunkInvalid(state, chunk) {
1105
- var er = null;
1106
- if (!util.isBuffer(chunk) && !util.isString(chunk) && !util.isNullOrUndefined(chunk) && !state.objectMode) {
1107
- er = new TypeError("Invalid non-string/buffer chunk");
1108
- }
1109
- return er;
1110
- }
1111
- function onEofChunk(stream, state) {
1112
- if (state.decoder && !state.ended) {
1113
- var chunk = state.decoder.end();
1114
- if (chunk && chunk.length) {
1115
- state.buffer.push(chunk);
1116
- state.length += state.objectMode ? 1 : chunk.length;
1117
- }
1118
- }
1119
- state.ended = true;
1120
- emitReadable(stream);
1121
- }
1122
- function emitReadable(stream) {
1123
- var state = stream._readableState;
1124
- state.needReadable = false;
1125
- if (!state.emittedReadable) {
1126
- debug("emitReadable", state.flowing);
1127
- state.emittedReadable = true;
1128
- if (state.sync)
1129
- process.nextTick(function() {
1130
- emitReadable_(stream);
1131
- });
1132
- else
1133
- emitReadable_(stream);
1134
- }
1135
- }
1136
- function emitReadable_(stream) {
1137
- debug("emit readable");
1138
- stream.emit("readable");
1139
- flow(stream);
1140
- }
1141
- function maybeReadMore(stream, state) {
1142
- if (!state.readingMore) {
1143
- state.readingMore = true;
1144
- process.nextTick(function() {
1145
- maybeReadMore_(stream, state);
1146
- });
1147
- }
1148
- }
1149
- function maybeReadMore_(stream, state) {
1150
- var len = state.length;
1151
- while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
1152
- debug("maybeReadMore read 0");
1153
- stream.read(0);
1154
- if (len === state.length)
1155
- break;
1156
- else
1157
- len = state.length;
1158
- }
1159
- state.readingMore = false;
1160
- }
1161
- Readable.prototype._read = function(n) {
1162
- this.emit("error", new Error("not implemented"));
1163
- };
1164
- Readable.prototype.pipe = function(dest, pipeOpts) {
1165
- var src = this;
1166
- var state = this._readableState;
1167
- switch (state.pipesCount) {
1168
- case 0:
1169
- state.pipes = dest;
1170
- break;
1171
- case 1:
1172
- state.pipes = [state.pipes, dest];
1173
- break;
1174
- default:
1175
- state.pipes.push(dest);
1176
- break;
1177
- }
1178
- state.pipesCount += 1;
1179
- debug("pipe count=%d opts=%j", state.pipesCount, pipeOpts);
1180
- var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
1181
- var endFn = doEnd ? onend : cleanup;
1182
- if (state.endEmitted)
1183
- process.nextTick(endFn);
1184
- else
1185
- src.once("end", endFn);
1186
- dest.on("unpipe", onunpipe);
1187
- function onunpipe(readable) {
1188
- debug("onunpipe");
1189
- if (readable === src) {
1190
- cleanup();
1191
- }
1192
- }
1193
- function onend() {
1194
- debug("onend");
1195
- dest.end();
1196
- }
1197
- var ondrain = pipeOnDrain(src);
1198
- dest.on("drain", ondrain);
1199
- function cleanup() {
1200
- debug("cleanup");
1201
- dest.removeListener("close", onclose);
1202
- dest.removeListener("finish", onfinish);
1203
- dest.removeListener("drain", ondrain);
1204
- dest.removeListener("error", onerror);
1205
- dest.removeListener("unpipe", onunpipe);
1206
- src.removeListener("end", onend);
1207
- src.removeListener("end", cleanup);
1208
- src.removeListener("data", ondata);
1209
- if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain))
1210
- ondrain();
1211
- }
1212
- src.on("data", ondata);
1213
- function ondata(chunk) {
1214
- debug("ondata");
1215
- var ret = dest.write(chunk);
1216
- if (false === ret) {
1217
- debug(
1218
- "false write response, pause",
1219
- src._readableState.awaitDrain
1220
- );
1221
- src._readableState.awaitDrain++;
1222
- src.pause();
1223
- }
1224
- }
1225
- function onerror(er) {
1226
- debug("onerror", er);
1227
- unpipe();
1228
- dest.removeListener("error", onerror);
1229
- if (EE.listenerCount(dest, "error") === 0)
1230
- dest.emit("error", er);
1231
- }
1232
- if (!dest._events || !dest._events.error)
1233
- dest.on("error", onerror);
1234
- else if (isArray(dest._events.error))
1235
- dest._events.error.unshift(onerror);
1236
- else
1237
- dest._events.error = [onerror, dest._events.error];
1238
- function onclose() {
1239
- dest.removeListener("finish", onfinish);
1240
- unpipe();
1241
- }
1242
- dest.once("close", onclose);
1243
- function onfinish() {
1244
- debug("onfinish");
1245
- dest.removeListener("close", onclose);
1246
- unpipe();
1247
- }
1248
- dest.once("finish", onfinish);
1249
- function unpipe() {
1250
- debug("unpipe");
1251
- src.unpipe(dest);
1252
- }
1253
- dest.emit("pipe", src);
1254
- if (!state.flowing) {
1255
- debug("pipe resume");
1256
- src.resume();
1257
- }
1258
- return dest;
1259
- };
1260
- function pipeOnDrain(src) {
1261
- return function() {
1262
- var state = src._readableState;
1263
- debug("pipeOnDrain", state.awaitDrain);
1264
- if (state.awaitDrain)
1265
- state.awaitDrain--;
1266
- if (state.awaitDrain === 0 && EE.listenerCount(src, "data")) {
1267
- state.flowing = true;
1268
- flow(src);
1269
- }
1270
- };
1271
- }
1272
- Readable.prototype.unpipe = function(dest) {
1273
- var state = this._readableState;
1274
- if (state.pipesCount === 0)
1275
- return this;
1276
- if (state.pipesCount === 1) {
1277
- if (dest && dest !== state.pipes)
1278
- return this;
1279
- if (!dest)
1280
- dest = state.pipes;
1281
- state.pipes = null;
1282
- state.pipesCount = 0;
1283
- state.flowing = false;
1284
- if (dest)
1285
- dest.emit("unpipe", this);
1286
- return this;
1287
- }
1288
- if (!dest) {
1289
- var dests = state.pipes;
1290
- var len = state.pipesCount;
1291
- state.pipes = null;
1292
- state.pipesCount = 0;
1293
- state.flowing = false;
1294
- for (var i = 0; i < len; i++)
1295
- dests[i].emit("unpipe", this);
1296
- return this;
1297
- }
1298
- var i = indexOf(state.pipes, dest);
1299
- if (i === -1)
1300
- return this;
1301
- state.pipes.splice(i, 1);
1302
- state.pipesCount -= 1;
1303
- if (state.pipesCount === 1)
1304
- state.pipes = state.pipes[0];
1305
- dest.emit("unpipe", this);
1306
- return this;
1307
- };
1308
- Readable.prototype.on = function(ev, fn) {
1309
- var res = Stream.prototype.on.call(this, ev, fn);
1310
- if (ev === "data" && false !== this._readableState.flowing) {
1311
- this.resume();
1312
- }
1313
- if (ev === "readable" && this.readable) {
1314
- var state = this._readableState;
1315
- if (!state.readableListening) {
1316
- state.readableListening = true;
1317
- state.emittedReadable = false;
1318
- state.needReadable = true;
1319
- if (!state.reading) {
1320
- var self = this;
1321
- process.nextTick(function() {
1322
- debug("readable nexttick read 0");
1323
- self.read(0);
1324
- });
1325
- } else if (state.length) {
1326
- emitReadable(this, state);
1327
- }
1328
- }
1329
- }
1330
- return res;
1331
- };
1332
- Readable.prototype.addListener = Readable.prototype.on;
1333
- Readable.prototype.resume = function() {
1334
- var state = this._readableState;
1335
- if (!state.flowing) {
1336
- debug("resume");
1337
- state.flowing = true;
1338
- if (!state.reading) {
1339
- debug("resume read 0");
1340
- this.read(0);
1341
- }
1342
- resume(this, state);
1343
- }
1344
- return this;
1345
- };
1346
- function resume(stream, state) {
1347
- if (!state.resumeScheduled) {
1348
- state.resumeScheduled = true;
1349
- process.nextTick(function() {
1350
- resume_(stream, state);
1351
- });
1352
- }
1353
- }
1354
- function resume_(stream, state) {
1355
- state.resumeScheduled = false;
1356
- stream.emit("resume");
1357
- flow(stream);
1358
- if (state.flowing && !state.reading)
1359
- stream.read(0);
1360
- }
1361
- Readable.prototype.pause = function() {
1362
- debug("call pause flowing=%j", this._readableState.flowing);
1363
- if (false !== this._readableState.flowing) {
1364
- debug("pause");
1365
- this._readableState.flowing = false;
1366
- this.emit("pause");
1367
- }
1368
- return this;
1369
- };
1370
- function flow(stream) {
1371
- var state = stream._readableState;
1372
- debug("flow", state.flowing);
1373
- if (state.flowing) {
1374
- do {
1375
- var chunk = stream.read();
1376
- } while (null !== chunk && state.flowing);
1377
- }
1378
- }
1379
- Readable.prototype.wrap = function(stream) {
1380
- var state = this._readableState;
1381
- var paused = false;
1382
- var self = this;
1383
- stream.on("end", function() {
1384
- debug("wrapped end");
1385
- if (state.decoder && !state.ended) {
1386
- var chunk = state.decoder.end();
1387
- if (chunk && chunk.length)
1388
- self.push(chunk);
1389
- }
1390
- self.push(null);
1391
- });
1392
- stream.on("data", function(chunk) {
1393
- debug("wrapped data");
1394
- if (state.decoder)
1395
- chunk = state.decoder.write(chunk);
1396
- if (!chunk || !state.objectMode && !chunk.length)
1397
- return;
1398
- var ret = self.push(chunk);
1399
- if (!ret) {
1400
- paused = true;
1401
- stream.pause();
1402
- }
1403
- });
1404
- for (var i in stream) {
1405
- if (util.isFunction(stream[i]) && util.isUndefined(this[i])) {
1406
- this[i] = /* @__PURE__ */ function(method) {
1407
- return function() {
1408
- return stream[method].apply(stream, arguments);
1409
- };
1410
- }(i);
1411
- }
1412
- }
1413
- var events = ["error", "close", "destroy", "pause", "resume"];
1414
- forEach(events, function(ev) {
1415
- stream.on(ev, self.emit.bind(self, ev));
1416
- });
1417
- self._read = function(n) {
1418
- debug("wrapped _read", n);
1419
- if (paused) {
1420
- paused = false;
1421
- stream.resume();
1422
- }
1423
- };
1424
- return self;
1425
- };
1426
- Readable._fromList = fromList;
1427
- function fromList(n, state) {
1428
- var list = state.buffer;
1429
- var length = state.length;
1430
- var stringMode = !!state.decoder;
1431
- var objectMode = !!state.objectMode;
1432
- var ret;
1433
- if (list.length === 0)
1434
- return null;
1435
- if (length === 0)
1436
- ret = null;
1437
- else if (objectMode)
1438
- ret = list.shift();
1439
- else if (!n || n >= length) {
1440
- if (stringMode)
1441
- ret = list.join("");
1442
- else
1443
- ret = Buffer2.concat(list, length);
1444
- list.length = 0;
1445
- } else {
1446
- if (n < list[0].length) {
1447
- var buf = list[0];
1448
- ret = buf.slice(0, n);
1449
- list[0] = buf.slice(n);
1450
- } else if (n === list[0].length) {
1451
- ret = list.shift();
1452
- } else {
1453
- if (stringMode)
1454
- ret = "";
1455
- else
1456
- ret = new Buffer2(n);
1457
- var c = 0;
1458
- for (var i = 0, l = list.length; i < l && c < n; i++) {
1459
- var buf = list[0];
1460
- var cpy = Math.min(n - c, buf.length);
1461
- if (stringMode)
1462
- ret += buf.slice(0, cpy);
1463
- else
1464
- buf.copy(ret, c, 0, cpy);
1465
- if (cpy < buf.length)
1466
- list[0] = buf.slice(cpy);
1467
- else
1468
- list.shift();
1469
- c += cpy;
1470
- }
1471
- }
1472
- }
1473
- return ret;
1474
- }
1475
- function endReadable(stream) {
1476
- var state = stream._readableState;
1477
- if (state.length > 0)
1478
- throw new Error("endReadable called on non-empty stream");
1479
- if (!state.endEmitted) {
1480
- state.ended = true;
1481
- process.nextTick(function() {
1482
- if (!state.endEmitted && state.length === 0) {
1483
- state.endEmitted = true;
1484
- stream.readable = false;
1485
- stream.emit("end");
1486
- }
1487
- });
1488
- }
1489
- }
1490
- function forEach(xs, f) {
1491
- for (var i = 0, l = xs.length; i < l; i++) {
1492
- f(xs[i], i);
1493
- }
1494
- }
1495
- function indexOf(xs, x) {
1496
- for (var i = 0, l = xs.length; i < l; i++) {
1497
- if (xs[i] === x) return i;
1498
- }
1499
- return -1;
1500
- }
1501
- }
1502
- });
1503
-
1504
- // node_modules/wav/node_modules/readable-stream/lib/_stream_writable.js
1505
- var require_stream_writable = __commonJS({
1506
- "node_modules/wav/node_modules/readable-stream/lib/_stream_writable.js"(exports2, module2) {
1507
- "use strict";
1508
- module2.exports = Writable;
1509
- var Buffer2 = require("buffer").Buffer;
1510
- Writable.WritableState = WritableState;
1511
- var util = require_util();
1512
- util.inherits = require_inherits();
1513
- var Stream = require("stream");
1514
- util.inherits(Writable, Stream);
1515
- function WriteReq(chunk, encoding, cb) {
1516
- this.chunk = chunk;
1517
- this.encoding = encoding;
1518
- this.callback = cb;
1519
- }
1520
- function WritableState(options, stream) {
1521
- var Duplex = require_stream_duplex();
1522
- options = options || {};
1523
- var hwm = options.highWaterMark;
1524
- var defaultHwm = options.objectMode ? 16 : 16 * 1024;
1525
- this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
1526
- this.objectMode = !!options.objectMode;
1527
- if (stream instanceof Duplex)
1528
- this.objectMode = this.objectMode || !!options.writableObjectMode;
1529
- this.highWaterMark = ~~this.highWaterMark;
1530
- this.needDrain = false;
1531
- this.ending = false;
1532
- this.ended = false;
1533
- this.finished = false;
1534
- var noDecode = options.decodeStrings === false;
1535
- this.decodeStrings = !noDecode;
1536
- this.defaultEncoding = options.defaultEncoding || "utf8";
1537
- this.length = 0;
1538
- this.writing = false;
1539
- this.corked = 0;
1540
- this.sync = true;
1541
- this.bufferProcessing = false;
1542
- this.onwrite = function(er) {
1543
- onwrite(stream, er);
1544
- };
1545
- this.writecb = null;
1546
- this.writelen = 0;
1547
- this.buffer = [];
1548
- this.pendingcb = 0;
1549
- this.prefinished = false;
1550
- this.errorEmitted = false;
1551
- }
1552
- function Writable(options) {
1553
- var Duplex = require_stream_duplex();
1554
- if (!(this instanceof Writable) && !(this instanceof Duplex))
1555
- return new Writable(options);
1556
- this._writableState = new WritableState(options, this);
1557
- this.writable = true;
1558
- Stream.call(this);
1559
- }
1560
- Writable.prototype.pipe = function() {
1561
- this.emit("error", new Error("Cannot pipe. Not readable."));
1562
- };
1563
- function writeAfterEnd(stream, state, cb) {
1564
- var er = new Error("write after end");
1565
- stream.emit("error", er);
1566
- process.nextTick(function() {
1567
- cb(er);
1568
- });
1569
- }
1570
- function validChunk(stream, state, chunk, cb) {
1571
- var valid = true;
1572
- if (!util.isBuffer(chunk) && !util.isString(chunk) && !util.isNullOrUndefined(chunk) && !state.objectMode) {
1573
- var er = new TypeError("Invalid non-string/buffer chunk");
1574
- stream.emit("error", er);
1575
- process.nextTick(function() {
1576
- cb(er);
1577
- });
1578
- valid = false;
1579
- }
1580
- return valid;
1581
- }
1582
- Writable.prototype.write = function(chunk, encoding, cb) {
1583
- var state = this._writableState;
1584
- var ret = false;
1585
- if (util.isFunction(encoding)) {
1586
- cb = encoding;
1587
- encoding = null;
1588
- }
1589
- if (util.isBuffer(chunk))
1590
- encoding = "buffer";
1591
- else if (!encoding)
1592
- encoding = state.defaultEncoding;
1593
- if (!util.isFunction(cb))
1594
- cb = function() {
1595
- };
1596
- if (state.ended)
1597
- writeAfterEnd(this, state, cb);
1598
- else if (validChunk(this, state, chunk, cb)) {
1599
- state.pendingcb++;
1600
- ret = writeOrBuffer(this, state, chunk, encoding, cb);
1601
- }
1602
- return ret;
1603
- };
1604
- Writable.prototype.cork = function() {
1605
- var state = this._writableState;
1606
- state.corked++;
1607
- };
1608
- Writable.prototype.uncork = function() {
1609
- var state = this._writableState;
1610
- if (state.corked) {
1611
- state.corked--;
1612
- if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.buffer.length)
1613
- clearBuffer(this, state);
1614
- }
1615
- };
1616
- function decodeChunk(state, chunk, encoding) {
1617
- if (!state.objectMode && state.decodeStrings !== false && util.isString(chunk)) {
1618
- chunk = new Buffer2(chunk, encoding);
1619
- }
1620
- return chunk;
1621
- }
1622
- function writeOrBuffer(stream, state, chunk, encoding, cb) {
1623
- chunk = decodeChunk(state, chunk, encoding);
1624
- if (util.isBuffer(chunk))
1625
- encoding = "buffer";
1626
- var len = state.objectMode ? 1 : chunk.length;
1627
- state.length += len;
1628
- var ret = state.length < state.highWaterMark;
1629
- if (!ret)
1630
- state.needDrain = true;
1631
- if (state.writing || state.corked)
1632
- state.buffer.push(new WriteReq(chunk, encoding, cb));
1633
- else
1634
- doWrite(stream, state, false, len, chunk, encoding, cb);
1635
- return ret;
1636
- }
1637
- function doWrite(stream, state, writev, len, chunk, encoding, cb) {
1638
- state.writelen = len;
1639
- state.writecb = cb;
1640
- state.writing = true;
1641
- state.sync = true;
1642
- if (writev)
1643
- stream._writev(chunk, state.onwrite);
1644
- else
1645
- stream._write(chunk, encoding, state.onwrite);
1646
- state.sync = false;
1647
- }
1648
- function onwriteError(stream, state, sync, er, cb) {
1649
- if (sync)
1650
- process.nextTick(function() {
1651
- state.pendingcb--;
1652
- cb(er);
1653
- });
1654
- else {
1655
- state.pendingcb--;
1656
- cb(er);
1657
- }
1658
- stream._writableState.errorEmitted = true;
1659
- stream.emit("error", er);
1660
- }
1661
- function onwriteStateUpdate(state) {
1662
- state.writing = false;
1663
- state.writecb = null;
1664
- state.length -= state.writelen;
1665
- state.writelen = 0;
1666
- }
1667
- function onwrite(stream, er) {
1668
- var state = stream._writableState;
1669
- var sync = state.sync;
1670
- var cb = state.writecb;
1671
- onwriteStateUpdate(state);
1672
- if (er)
1673
- onwriteError(stream, state, sync, er, cb);
1674
- else {
1675
- var finished = needFinish(stream, state);
1676
- if (!finished && !state.corked && !state.bufferProcessing && state.buffer.length) {
1677
- clearBuffer(stream, state);
1678
- }
1679
- if (sync) {
1680
- process.nextTick(function() {
1681
- afterWrite(stream, state, finished, cb);
1682
- });
1683
- } else {
1684
- afterWrite(stream, state, finished, cb);
1685
- }
1686
- }
1687
- }
1688
- function afterWrite(stream, state, finished, cb) {
1689
- if (!finished)
1690
- onwriteDrain(stream, state);
1691
- state.pendingcb--;
1692
- cb();
1693
- finishMaybe(stream, state);
1694
- }
1695
- function onwriteDrain(stream, state) {
1696
- if (state.length === 0 && state.needDrain) {
1697
- state.needDrain = false;
1698
- stream.emit("drain");
1699
- }
1700
- }
1701
- function clearBuffer(stream, state) {
1702
- state.bufferProcessing = true;
1703
- if (stream._writev && state.buffer.length > 1) {
1704
- var cbs = [];
1705
- for (var c = 0; c < state.buffer.length; c++)
1706
- cbs.push(state.buffer[c].callback);
1707
- state.pendingcb++;
1708
- doWrite(stream, state, true, state.length, state.buffer, "", function(err) {
1709
- for (var i = 0; i < cbs.length; i++) {
1710
- state.pendingcb--;
1711
- cbs[i](err);
1712
- }
1713
- });
1714
- state.buffer = [];
1715
- } else {
1716
- for (var c = 0; c < state.buffer.length; c++) {
1717
- var entry = state.buffer[c];
1718
- var chunk = entry.chunk;
1719
- var encoding = entry.encoding;
1720
- var cb = entry.callback;
1721
- var len = state.objectMode ? 1 : chunk.length;
1722
- doWrite(stream, state, false, len, chunk, encoding, cb);
1723
- if (state.writing) {
1724
- c++;
1725
- break;
1726
- }
1727
- }
1728
- if (c < state.buffer.length)
1729
- state.buffer = state.buffer.slice(c);
1730
- else
1731
- state.buffer.length = 0;
1732
- }
1733
- state.bufferProcessing = false;
1734
- }
1735
- Writable.prototype._write = function(chunk, encoding, cb) {
1736
- cb(new Error("not implemented"));
1737
- };
1738
- Writable.prototype._writev = null;
1739
- Writable.prototype.end = function(chunk, encoding, cb) {
1740
- var state = this._writableState;
1741
- if (util.isFunction(chunk)) {
1742
- cb = chunk;
1743
- chunk = null;
1744
- encoding = null;
1745
- } else if (util.isFunction(encoding)) {
1746
- cb = encoding;
1747
- encoding = null;
1748
- }
1749
- if (!util.isNullOrUndefined(chunk))
1750
- this.write(chunk, encoding);
1751
- if (state.corked) {
1752
- state.corked = 1;
1753
- this.uncork();
1754
- }
1755
- if (!state.ending && !state.finished)
1756
- endWritable(this, state, cb);
1757
- };
1758
- function needFinish(stream, state) {
1759
- return state.ending && state.length === 0 && !state.finished && !state.writing;
1760
- }
1761
- function prefinish(stream, state) {
1762
- if (!state.prefinished) {
1763
- state.prefinished = true;
1764
- stream.emit("prefinish");
1765
- }
1766
- }
1767
- function finishMaybe(stream, state) {
1768
- var need = needFinish(stream, state);
1769
- if (need) {
1770
- if (state.pendingcb === 0) {
1771
- prefinish(stream, state);
1772
- state.finished = true;
1773
- stream.emit("finish");
1774
- } else
1775
- prefinish(stream, state);
1776
- }
1777
- return need;
1778
- }
1779
- function endWritable(stream, state, cb) {
1780
- state.ending = true;
1781
- finishMaybe(stream, state);
1782
- if (cb) {
1783
- if (state.finished)
1784
- process.nextTick(cb);
1785
- else
1786
- stream.once("finish", cb);
1787
- }
1788
- state.ended = true;
1789
- }
1790
- }
1791
- });
1792
-
1793
- // node_modules/wav/node_modules/readable-stream/lib/_stream_duplex.js
1794
- var require_stream_duplex = __commonJS({
1795
- "node_modules/wav/node_modules/readable-stream/lib/_stream_duplex.js"(exports2, module2) {
1796
- "use strict";
1797
- module2.exports = Duplex;
1798
- var objectKeys = Object.keys || function(obj) {
1799
- var keys = [];
1800
- for (var key in obj) keys.push(key);
1801
- return keys;
1802
- };
1803
- var util = require_util();
1804
- util.inherits = require_inherits();
1805
- var Readable = require_stream_readable();
1806
- var Writable = require_stream_writable();
1807
- util.inherits(Duplex, Readable);
1808
- forEach(objectKeys(Writable.prototype), function(method) {
1809
- if (!Duplex.prototype[method])
1810
- Duplex.prototype[method] = Writable.prototype[method];
1811
- });
1812
- function Duplex(options) {
1813
- if (!(this instanceof Duplex))
1814
- return new Duplex(options);
1815
- Readable.call(this, options);
1816
- Writable.call(this, options);
1817
- if (options && options.readable === false)
1818
- this.readable = false;
1819
- if (options && options.writable === false)
1820
- this.writable = false;
1821
- this.allowHalfOpen = true;
1822
- if (options && options.allowHalfOpen === false)
1823
- this.allowHalfOpen = false;
1824
- this.once("end", onend);
1825
- }
1826
- function onend() {
1827
- if (this.allowHalfOpen || this._writableState.ended)
1828
- return;
1829
- process.nextTick(this.end.bind(this));
1830
- }
1831
- function forEach(xs, f) {
1832
- for (var i = 0, l = xs.length; i < l; i++) {
1833
- f(xs[i], i);
1834
- }
1835
- }
1836
- }
1837
- });
1838
-
1839
- // node_modules/wav/node_modules/readable-stream/lib/_stream_transform.js
1840
- var require_stream_transform = __commonJS({
1841
- "node_modules/wav/node_modules/readable-stream/lib/_stream_transform.js"(exports2, module2) {
1842
- "use strict";
1843
- module2.exports = Transform;
1844
- var Duplex = require_stream_duplex();
1845
- var util = require_util();
1846
- util.inherits = require_inherits();
1847
- util.inherits(Transform, Duplex);
1848
- function TransformState(options, stream) {
1849
- this.afterTransform = function(er, data) {
1850
- return afterTransform(stream, er, data);
1851
- };
1852
- this.needTransform = false;
1853
- this.transforming = false;
1854
- this.writecb = null;
1855
- this.writechunk = null;
1856
- }
1857
- function afterTransform(stream, er, data) {
1858
- var ts = stream._transformState;
1859
- ts.transforming = false;
1860
- var cb = ts.writecb;
1861
- if (!cb)
1862
- return stream.emit("error", new Error("no writecb in Transform class"));
1863
- ts.writechunk = null;
1864
- ts.writecb = null;
1865
- if (!util.isNullOrUndefined(data))
1866
- stream.push(data);
1867
- if (cb)
1868
- cb(er);
1869
- var rs = stream._readableState;
1870
- rs.reading = false;
1871
- if (rs.needReadable || rs.length < rs.highWaterMark) {
1872
- stream._read(rs.highWaterMark);
1873
- }
1874
- }
1875
- function Transform(options) {
1876
- if (!(this instanceof Transform))
1877
- return new Transform(options);
1878
- Duplex.call(this, options);
1879
- this._transformState = new TransformState(options, this);
1880
- var stream = this;
1881
- this._readableState.needReadable = true;
1882
- this._readableState.sync = false;
1883
- this.once("prefinish", function() {
1884
- if (util.isFunction(this._flush))
1885
- this._flush(function(er) {
1886
- done(stream, er);
1887
- });
1888
- else
1889
- done(stream);
1890
- });
1891
- }
1892
- Transform.prototype.push = function(chunk, encoding) {
1893
- this._transformState.needTransform = false;
1894
- return Duplex.prototype.push.call(this, chunk, encoding);
1895
- };
1896
- Transform.prototype._transform = function(chunk, encoding, cb) {
1897
- throw new Error("not implemented");
1898
- };
1899
- Transform.prototype._write = function(chunk, encoding, cb) {
1900
- var ts = this._transformState;
1901
- ts.writecb = cb;
1902
- ts.writechunk = chunk;
1903
- ts.writeencoding = encoding;
1904
- if (!ts.transforming) {
1905
- var rs = this._readableState;
1906
- if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark)
1907
- this._read(rs.highWaterMark);
1908
- }
1909
- };
1910
- Transform.prototype._read = function(n) {
1911
- var ts = this._transformState;
1912
- if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) {
1913
- ts.transforming = true;
1914
- this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
1915
- } else {
1916
- ts.needTransform = true;
1917
- }
1918
- };
1919
- function done(stream, er) {
1920
- if (er)
1921
- return stream.emit("error", er);
1922
- var ws = stream._writableState;
1923
- var ts = stream._transformState;
1924
- if (ws.length)
1925
- throw new Error("calling transform done when ws.length != 0");
1926
- if (ts.transforming)
1927
- throw new Error("calling transform done when still transforming");
1928
- return stream.push(null);
1929
- }
1930
- }
1931
- });
1932
-
1933
- // node_modules/wav/node_modules/readable-stream/transform.js
1934
- var require_transform = __commonJS({
1935
- "node_modules/wav/node_modules/readable-stream/transform.js"(exports2, module2) {
1936
- "use strict";
1937
- module2.exports = require_stream_transform();
1938
- }
1939
- });
1940
-
1941
- // node_modules/wav/node_modules/ms/index.js
1942
- var require_ms2 = __commonJS({
1943
- "node_modules/wav/node_modules/ms/index.js"(exports2, module2) {
1944
- "use strict";
1945
- var s = 1e3;
1946
- var m = s * 60;
1947
- var h = m * 60;
1948
- var d = h * 24;
1949
- var y = d * 365.25;
1950
- module2.exports = function(val, options) {
1951
- options = options || {};
1952
- var type = typeof val;
1953
- if (type === "string" && val.length > 0) {
1954
- return parse(val);
1955
- } else if (type === "number" && isNaN(val) === false) {
1956
- return options.long ? fmtLong(val) : fmtShort(val);
1957
- }
1958
- throw new Error(
1959
- "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
1960
- );
1961
- };
1962
- function parse(str) {
1963
- str = String(str);
1964
- if (str.length > 100) {
1965
- return;
1966
- }
1967
- var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
1968
- str
1969
- );
1970
- if (!match) {
1971
- return;
1972
- }
1973
- var n = parseFloat(match[1]);
1974
- var type = (match[2] || "ms").toLowerCase();
1975
- switch (type) {
1976
- case "years":
1977
- case "year":
1978
- case "yrs":
1979
- case "yr":
1980
- case "y":
1981
- return n * y;
1982
- case "days":
1983
- case "day":
1984
- case "d":
1985
- return n * d;
1986
- case "hours":
1987
- case "hour":
1988
- case "hrs":
1989
- case "hr":
1990
- case "h":
1991
- return n * h;
1992
- case "minutes":
1993
- case "minute":
1994
- case "mins":
1995
- case "min":
1996
- case "m":
1997
- return n * m;
1998
- case "seconds":
1999
- case "second":
2000
- case "secs":
2001
- case "sec":
2002
- case "s":
2003
- return n * s;
2004
- case "milliseconds":
2005
- case "millisecond":
2006
- case "msecs":
2007
- case "msec":
2008
- case "ms":
2009
- return n;
2010
- default:
2011
- return void 0;
2012
- }
2013
- }
2014
- function fmtShort(ms) {
2015
- if (ms >= d) {
2016
- return Math.round(ms / d) + "d";
2017
- }
2018
- if (ms >= h) {
2019
- return Math.round(ms / h) + "h";
2020
- }
2021
- if (ms >= m) {
2022
- return Math.round(ms / m) + "m";
2023
- }
2024
- if (ms >= s) {
2025
- return Math.round(ms / s) + "s";
2026
- }
2027
- return ms + "ms";
2028
- }
2029
- function fmtLong(ms) {
2030
- return plural(ms, d, "day") || plural(ms, h, "hour") || plural(ms, m, "minute") || plural(ms, s, "second") || ms + " ms";
2031
- }
2032
- function plural(ms, n, name) {
2033
- if (ms < n) {
2034
- return;
2035
- }
2036
- if (ms < n * 1.5) {
2037
- return Math.floor(ms / n) + " " + name;
2038
- }
2039
- return Math.ceil(ms / n) + " " + name + "s";
2040
- }
2041
- }
2042
- });
2043
-
2044
- // node_modules/wav/node_modules/debug/src/debug.js
2045
- var require_debug2 = __commonJS({
2046
- "node_modules/wav/node_modules/debug/src/debug.js"(exports2, module2) {
2047
- "use strict";
2048
- exports2 = module2.exports = createDebug.debug = createDebug["default"] = createDebug;
2049
- exports2.coerce = coerce;
2050
- exports2.disable = disable;
2051
- exports2.enable = enable;
2052
- exports2.enabled = enabled;
2053
- exports2.humanize = require_ms2();
2054
- exports2.names = [];
2055
- exports2.skips = [];
2056
- exports2.formatters = {};
2057
- var prevTime;
2058
- function selectColor(namespace) {
2059
- var hash = 0, i;
2060
- for (i in namespace) {
2061
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
2062
- hash |= 0;
2063
- }
2064
- return exports2.colors[Math.abs(hash) % exports2.colors.length];
2065
- }
2066
- function createDebug(namespace) {
2067
- function debug() {
2068
- if (!debug.enabled) return;
2069
- var self = debug;
2070
- var curr = +/* @__PURE__ */ new Date();
2071
- var ms = curr - (prevTime || curr);
2072
- self.diff = ms;
2073
- self.prev = prevTime;
2074
- self.curr = curr;
2075
- prevTime = curr;
2076
- var args = new Array(arguments.length);
2077
- for (var i = 0; i < args.length; i++) {
2078
- args[i] = arguments[i];
2079
- }
2080
- args[0] = exports2.coerce(args[0]);
2081
- if ("string" !== typeof args[0]) {
2082
- args.unshift("%O");
2083
- }
2084
- var index = 0;
2085
- args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
2086
- if (match === "%%") return match;
2087
- index++;
2088
- var formatter = exports2.formatters[format];
2089
- if ("function" === typeof formatter) {
2090
- var val = args[index];
2091
- match = formatter.call(self, val);
2092
- args.splice(index, 1);
2093
- index--;
2094
- }
2095
- return match;
2096
- });
2097
- exports2.formatArgs.call(self, args);
2098
- var logFn = debug.log || exports2.log || console.log.bind(console);
2099
- logFn.apply(self, args);
2100
- }
2101
- debug.namespace = namespace;
2102
- debug.enabled = exports2.enabled(namespace);
2103
- debug.useColors = exports2.useColors();
2104
- debug.color = selectColor(namespace);
2105
- if ("function" === typeof exports2.init) {
2106
- exports2.init(debug);
2107
- }
2108
- return debug;
2109
- }
2110
- function enable(namespaces) {
2111
- exports2.save(namespaces);
2112
- exports2.names = [];
2113
- exports2.skips = [];
2114
- var split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
2115
- var len = split.length;
2116
- for (var i = 0; i < len; i++) {
2117
- if (!split[i]) continue;
2118
- namespaces = split[i].replace(/\*/g, ".*?");
2119
- if (namespaces[0] === "-") {
2120
- exports2.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
2121
- } else {
2122
- exports2.names.push(new RegExp("^" + namespaces + "$"));
2123
- }
2124
- }
2125
- }
2126
- function disable() {
2127
- exports2.enable("");
2128
- }
2129
- function enabled(name) {
2130
- var i, len;
2131
- for (i = 0, len = exports2.skips.length; i < len; i++) {
2132
- if (exports2.skips[i].test(name)) {
2133
- return false;
2134
- }
2135
- }
2136
- for (i = 0, len = exports2.names.length; i < len; i++) {
2137
- if (exports2.names[i].test(name)) {
2138
- return true;
2139
- }
2140
- }
2141
- return false;
2142
- }
2143
- function coerce(val) {
2144
- if (val instanceof Error) return val.stack || val.message;
2145
- return val;
2146
- }
2147
- }
2148
- });
2149
-
2150
- // node_modules/wav/node_modules/debug/src/browser.js
2151
- var require_browser2 = __commonJS({
2152
- "node_modules/wav/node_modules/debug/src/browser.js"(exports2, module2) {
2153
- "use strict";
2154
- exports2 = module2.exports = require_debug2();
2155
- exports2.log = log;
2156
- exports2.formatArgs = formatArgs;
2157
- exports2.save = save;
2158
- exports2.load = load;
2159
- exports2.useColors = useColors;
2160
- exports2.storage = "undefined" != typeof chrome && "undefined" != typeof chrome.storage ? chrome.storage.local : localstorage();
2161
- exports2.colors = [
2162
- "lightseagreen",
2163
- "forestgreen",
2164
- "goldenrod",
2165
- "dodgerblue",
2166
- "darkorchid",
2167
- "crimson"
2168
- ];
2169
- function useColors() {
2170
- if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
2171
- return true;
2172
- }
2173
- return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // is firebug? http://stackoverflow.com/a/398120/376773
2174
- typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // is firefox >= v31?
2175
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
2176
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // double check webkit in userAgent just in case we are in a worker
2177
- typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
2178
- }
2179
- exports2.formatters.j = function(v) {
2180
- try {
2181
- return JSON.stringify(v);
2182
- } catch (err) {
2183
- return "[UnexpectedJSONParseError]: " + err.message;
2184
- }
2185
- };
2186
- function formatArgs(args) {
2187
- var useColors2 = this.useColors;
2188
- args[0] = (useColors2 ? "%c" : "") + this.namespace + (useColors2 ? " %c" : " ") + args[0] + (useColors2 ? "%c " : " ") + "+" + exports2.humanize(this.diff);
2189
- if (!useColors2) return;
2190
- var c = "color: " + this.color;
2191
- args.splice(1, 0, c, "color: inherit");
2192
- var index = 0;
2193
- var lastC = 0;
2194
- args[0].replace(/%[a-zA-Z%]/g, function(match) {
2195
- if ("%%" === match) return;
2196
- index++;
2197
- if ("%c" === match) {
2198
- lastC = index;
2199
- }
2200
- });
2201
- args.splice(lastC, 0, c);
2202
- }
2203
- function log() {
2204
- return "object" === typeof console && console.log && Function.prototype.apply.call(console.log, console, arguments);
2205
- }
2206
- function save(namespaces) {
2207
- try {
2208
- if (null == namespaces) {
2209
- exports2.storage.removeItem("debug");
2210
- } else {
2211
- exports2.storage.debug = namespaces;
2212
- }
2213
- } catch (e) {
2214
- }
2215
- }
2216
- function load() {
2217
- var r;
2218
- try {
2219
- r = exports2.storage.debug;
2220
- } catch (e) {
2221
- }
2222
- if (!r && typeof process !== "undefined" && "env" in process) {
2223
- r = process.env.DEBUG;
2224
- }
2225
- return r;
2226
- }
2227
- exports2.enable(load());
2228
- function localstorage() {
2229
- try {
2230
- return window.localStorage;
2231
- } catch (e) {
2232
- }
2233
- }
2234
- }
2235
- });
2236
-
2237
- // node_modules/wav/node_modules/debug/src/node.js
2238
- var require_node2 = __commonJS({
2239
- "node_modules/wav/node_modules/debug/src/node.js"(exports2, module2) {
2240
- "use strict";
2241
- var tty = require("tty");
2242
- var util = require("util");
2243
- exports2 = module2.exports = require_debug2();
2244
- exports2.init = init;
2245
- exports2.log = log;
2246
- exports2.formatArgs = formatArgs;
2247
- exports2.save = save;
2248
- exports2.load = load;
2249
- exports2.useColors = useColors;
2250
- exports2.colors = [6, 2, 3, 4, 5, 1];
2251
- exports2.inspectOpts = Object.keys(process.env).filter(function(key) {
2252
- return /^debug_/i.test(key);
2253
- }).reduce(function(obj, key) {
2254
- var prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, function(_, k) {
2255
- return k.toUpperCase();
2256
- });
2257
- var val = process.env[key];
2258
- if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
2259
- else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
2260
- else if (val === "null") val = null;
2261
- else val = Number(val);
2262
- obj[prop] = val;
2263
- return obj;
2264
- }, {});
2265
- var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
2266
- if (1 !== fd && 2 !== fd) {
2267
- util.deprecate(function() {
2268
- }, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();
2269
- }
2270
- var stream = 1 === fd ? process.stdout : 2 === fd ? process.stderr : createWritableStdioStream(fd);
2271
- function useColors() {
2272
- return "colors" in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(fd);
2273
- }
2274
- exports2.formatters.o = function(v) {
2275
- this.inspectOpts.colors = this.useColors;
2276
- return util.inspect(v, this.inspectOpts).split("\n").map(function(str) {
2277
- return str.trim();
2278
- }).join(" ");
2279
- };
2280
- exports2.formatters.O = function(v) {
2281
- this.inspectOpts.colors = this.useColors;
2282
- return util.inspect(v, this.inspectOpts);
2283
- };
2284
- function formatArgs(args) {
2285
- var name = this.namespace;
2286
- var useColors2 = this.useColors;
2287
- if (useColors2) {
2288
- var c = this.color;
2289
- var prefix = " \x1B[3" + c + ";1m" + name + " \x1B[0m";
2290
- args[0] = prefix + args[0].split("\n").join("\n" + prefix);
2291
- args.push("\x1B[3" + c + "m+" + exports2.humanize(this.diff) + "\x1B[0m");
2292
- } else {
2293
- args[0] = (/* @__PURE__ */ new Date()).toUTCString() + " " + name + " " + args[0];
2294
- }
2295
- }
2296
- function log() {
2297
- return stream.write(util.format.apply(util, arguments) + "\n");
2298
- }
2299
- function save(namespaces) {
2300
- if (null == namespaces) {
2301
- delete process.env.DEBUG;
2302
- } else {
2303
- process.env.DEBUG = namespaces;
2304
- }
2305
- }
2306
- function load() {
2307
- return process.env.DEBUG;
2308
- }
2309
- function createWritableStdioStream(fd2) {
2310
- var stream2;
2311
- var tty_wrap = process.binding("tty_wrap");
2312
- switch (tty_wrap.guessHandleType(fd2)) {
2313
- case "TTY":
2314
- stream2 = new tty.WriteStream(fd2);
2315
- stream2._type = "tty";
2316
- if (stream2._handle && stream2._handle.unref) {
2317
- stream2._handle.unref();
2318
- }
2319
- break;
2320
- case "FILE":
2321
- var fs3 = require("fs");
2322
- stream2 = new fs3.SyncWriteStream(fd2, { autoClose: false });
2323
- stream2._type = "fs";
2324
- break;
2325
- case "PIPE":
2326
- case "TCP":
2327
- var net = require("net");
2328
- stream2 = new net.Socket({
2329
- fd: fd2,
2330
- readable: false,
2331
- writable: true
2332
- });
2333
- stream2.readable = false;
2334
- stream2.read = null;
2335
- stream2._type = "pipe";
2336
- if (stream2._handle && stream2._handle.unref) {
2337
- stream2._handle.unref();
2338
- }
2339
- break;
2340
- default:
2341
- throw new Error("Implement me. Unknown stream file type!");
2342
- }
2343
- stream2.fd = fd2;
2344
- stream2._isStdio = true;
2345
- return stream2;
2346
- }
2347
- function init(debug) {
2348
- debug.inspectOpts = {};
2349
- var keys = Object.keys(exports2.inspectOpts);
2350
- for (var i = 0; i < keys.length; i++) {
2351
- debug.inspectOpts[keys[i]] = exports2.inspectOpts[keys[i]];
2352
- }
2353
- }
2354
- exports2.enable(load());
2355
- }
2356
- });
2357
-
2358
- // node_modules/wav/node_modules/debug/src/index.js
2359
- var require_src2 = __commonJS({
2360
- "node_modules/wav/node_modules/debug/src/index.js"(exports2, module2) {
2361
- "use strict";
2362
- if (typeof process !== "undefined" && process.type === "renderer") {
2363
- module2.exports = require_browser2();
2364
- } else {
2365
- module2.exports = require_node2();
2366
- }
2367
- }
2368
- });
2369
-
2370
- // node_modules/wav/lib/reader.js
2371
- var require_reader = __commonJS({
2372
- "node_modules/wav/lib/reader.js"(exports2, module2) {
2373
- "use strict";
2374
- var util = require("util");
2375
- var Parser = require_stream_parser();
2376
- var Transform = require_transform();
2377
- var debug = require_src2()("wave:reader");
2378
- var inherits = util.inherits;
2379
- var f = util.format;
2380
- var formats = {
2381
- WAVE_FORMAT_UNKNOWN: 0,
2382
- // Microsoft Unknown Wave Format
2383
- WAVE_FORMAT_PCM: 1,
2384
- // Microsoft PCM Format
2385
- WAVE_FORMAT_ADPCM: 2,
2386
- // Microsoft ADPCM Format
2387
- WAVE_FORMAT_IEEE_FLOAT: 3,
2388
- // IEEE float
2389
- WAVE_FORMAT_VSELP: 4,
2390
- // Compaq Computer's VSELP
2391
- WAVE_FORMAT_IBM_CVSD: 5,
2392
- // IBM CVSD
2393
- WAVE_FORMAT_ALAW: 6,
2394
- // 8-bit ITU-T G.711 A-law
2395
- WAVE_FORMAT_MULAW: 7,
2396
- // 8-bit ITU-T G.711 µ-law
2397
- WAVE_FORMAT_EXTENSIBLE: 65534
2398
- // Determined by SubFormat
2399
- };
2400
- module2.exports = Reader2;
2401
- function Reader2(opts) {
2402
- if (!(this instanceof Reader2)) {
2403
- return new Reader2(opts);
2404
- }
2405
- Transform.call(this, opts);
2406
- this._bytes(4, this._onRiffID);
2407
- }
2408
- inherits(Reader2, Transform);
2409
- Parser(Reader2.prototype);
2410
- Reader2.prototype._onRiffID = function(chunk) {
2411
- debug("onRiffID: %o", chunk);
2412
- var id = this.riffId = chunk.toString("ascii");
2413
- if (id === "RIFF") {
2414
- debug("detected little-endian WAVE file");
2415
- this.endianness = "LE";
2416
- this._bytes(4, this._onChunkSize);
2417
- } else if (id === "RIFX") {
2418
- debug("detected big-endian WAVE file");
2419
- this.endianness = "BE";
2420
- this._bytes(4, this._onChunkSize);
2421
- } else {
2422
- this.emit("error", new Error(f('bad "chunk id": expected "RIFF" or "RIFX", got %j', id)));
2423
- }
2424
- };
2425
- Reader2.prototype._onChunkSize = function(chunk) {
2426
- debug("onChunkSize: %o", chunk);
2427
- this.chunkSize = chunk["readUInt32" + this.endianness](0);
2428
- this._bytes(4, this._onFormat);
2429
- };
2430
- Reader2.prototype._onFormat = function(chunk) {
2431
- debug("onFormat: %o", chunk);
2432
- this.waveId = chunk.toString("ascii");
2433
- if (this.waveId === "WAVE") {
2434
- this._bytes(4, this._onSubchunk1ID);
2435
- } else {
2436
- this.emit("error", new Error(f('bad "format": expected "WAVE", got %j', this.waveId)));
2437
- }
2438
- };
2439
- Reader2.prototype._onSubchunk1ID = function(chunk) {
2440
- debug("onSubchunk1ID: %o", chunk);
2441
- var subchunk1ID = chunk.toString("ascii");
2442
- this.chunkId = subchunk1ID;
2443
- if (subchunk1ID === "fmt ") {
2444
- this._bytes(4, this._onSubchunk1Size);
2445
- } else {
2446
- this.emit("error", new Error(f('bad "fmt id": expected "fmt ", got %j', subchunk1ID)));
2447
- }
2448
- };
2449
- Reader2.prototype._onSubchunk1Size = function(chunk) {
2450
- debug("onSubchunk1Size: %o", chunk);
2451
- this.subchunk1Size = chunk["readUInt32" + this.endianness](0);
2452
- this._bytes(this.subchunk1Size, this._onSubchunk1);
2453
- };
2454
- Reader2.prototype._onSubchunk1 = function(chunk) {
2455
- debug("onSubchunk1: %o", chunk);
2456
- this.audioFormat = chunk["readUInt16" + this.endianness](0);
2457
- this.channels = chunk["readUInt16" + this.endianness](2);
2458
- this.sampleRate = chunk["readUInt32" + this.endianness](4);
2459
- this.byteRate = chunk["readUInt32" + this.endianness](8);
2460
- this.blockAlign = chunk["readUInt16" + this.endianness](12);
2461
- this.bitDepth = chunk["readUInt16" + this.endianness](14);
2462
- this.signed = this.bitDepth !== 8;
2463
- var format = {
2464
- audioFormat: this.audioFormat,
2465
- endianness: this.endianness,
2466
- channels: this.channels,
2467
- sampleRate: this.sampleRate,
2468
- byteRate: this.byteRate,
2469
- blockAlign: this.blockAlign,
2470
- bitDepth: this.bitDepth,
2471
- signed: this.signed
2472
- };
2473
- switch (format.audioFormat) {
2474
- case formats.WAVE_FORMAT_PCM:
2475
- break;
2476
- case formats.WAVE_FORMAT_IEEE_FLOAT:
2477
- format.float = true;
2478
- break;
2479
- case formats.WAVE_FORMAT_ALAW:
2480
- format.alaw = true;
2481
- break;
2482
- case formats.WAVE_FORMAT_MULAW:
2483
- format.ulaw = true;
2484
- break;
2485
- }
2486
- this.emit("format", format);
2487
- this._bytes(4, this._onSubchunk2ID);
2488
- };
2489
- Reader2.prototype._onSubchunk2ID = function(chunk) {
2490
- debug("onSubchunk2ID: %o", chunk);
2491
- var subchunk2ID = chunk.toString("ascii");
2492
- if (subchunk2ID === "data") {
2493
- this._bytes(4, this._onDataChunkSize);
2494
- } else if (subchunk2ID === "fact") {
2495
- this._bytes(4, this._onFactChunkSize);
2496
- } else {
2497
- debug("parsing unknown %o chunk", subchunk2ID);
2498
- this.unknownID = subchunk2ID;
2499
- this._bytes(4, this._onUnknownChunkSize);
2500
- }
2501
- };
2502
- Reader2.prototype._onDataChunkSize = function(chunk) {
2503
- debug("onDataChunkSize: %o", chunk);
2504
- var chunkSize = chunk["readUInt32" + this.endianness](0);
2505
- if (chunkSize === 0) {
2506
- chunkSize = Infinity;
2507
- }
2508
- this._passthrough(chunkSize, this._onDataChunkDone);
2509
- };
2510
- Reader2.prototype._onDataChunkDone = function() {
2511
- debug("onFactChunkDone");
2512
- this._bytes(4, this._onSubchunk2ID);
2513
- };
2514
- Reader2.prototype._onFactChunkSize = function(chunk) {
2515
- debug("onFactChunkSize: %o", chunk);
2516
- var chunkDataSize = chunk["readUInt32" + this.endianness](0);
2517
- this._bytes(chunkDataSize, this._onFactChunkData);
2518
- };
2519
- Reader2.prototype._onFactChunkData = function(chunk) {
2520
- debug("onFactChunkData: %o", chunk);
2521
- var numSamples = chunk["readUInt32" + this.endianness](0);
2522
- debug("number of samples: %o", numSamples);
2523
- this.numSamples = numSamples;
2524
- this._bytes(4, this._onSubchunk2ID);
2525
- };
2526
- Reader2.prototype._onUnknownChunkSize = function(chunk) {
2527
- debug("onUnknownChunkSize: %o", chunk);
2528
- var chunkSize = chunk["readUInt32" + this.endianness](0);
2529
- this._bytes(chunkSize, this._onUnknownChunkData);
2530
- };
2531
- Reader2.prototype._onUnknownChunkData = function(chunk) {
2532
- debug("onUnknownChunkData: %o", chunk);
2533
- this.emit("chunk", {
2534
- id: this.unknownID,
2535
- data: chunk
2536
- });
2537
- this._bytes(4, this._onSubchunk2ID);
2538
- };
2539
- }
2540
- });
2541
-
2542
- // node_modules/buffer-fill/index.js
2543
- var require_buffer_fill = __commonJS({
2544
- "node_modules/buffer-fill/index.js"(exports2, module2) {
2545
- "use strict";
2546
- var hasFullSupport = function() {
2547
- try {
2548
- if (!Buffer.isEncoding("latin1")) {
2549
- return false;
2550
- }
2551
- var buf = Buffer.alloc ? Buffer.alloc(4) : new Buffer(4);
2552
- buf.fill("ab", "ucs2");
2553
- return buf.toString("hex") === "61006200";
2554
- } catch (_) {
2555
- return false;
2556
- }
2557
- }();
2558
- function isSingleByte(val) {
2559
- return val.length === 1 && val.charCodeAt(0) < 256;
2560
- }
2561
- function fillWithNumber(buffer, val, start, end) {
2562
- if (start < 0 || end > buffer.length) {
2563
- throw new RangeError("Out of range index");
2564
- }
2565
- start = start >>> 0;
2566
- end = end === void 0 ? buffer.length : end >>> 0;
2567
- if (end > start) {
2568
- buffer.fill(val, start, end);
2569
- }
2570
- return buffer;
2571
- }
2572
- function fillWithBuffer(buffer, val, start, end) {
2573
- if (start < 0 || end > buffer.length) {
2574
- throw new RangeError("Out of range index");
2575
- }
2576
- if (end <= start) {
2577
- return buffer;
2578
- }
2579
- start = start >>> 0;
2580
- end = end === void 0 ? buffer.length : end >>> 0;
2581
- var pos = start;
2582
- var len = val.length;
2583
- while (pos <= end - len) {
2584
- val.copy(buffer, pos);
2585
- pos += len;
2586
- }
2587
- if (pos !== end) {
2588
- val.copy(buffer, pos, 0, end - pos);
2589
- }
2590
- return buffer;
2591
- }
2592
- function fill(buffer, val, start, end, encoding) {
2593
- if (hasFullSupport) {
2594
- return buffer.fill(val, start, end, encoding);
2595
- }
2596
- if (typeof val === "number") {
2597
- return fillWithNumber(buffer, val, start, end);
2598
- }
2599
- if (typeof val === "string") {
2600
- if (typeof start === "string") {
2601
- encoding = start;
2602
- start = 0;
2603
- end = buffer.length;
2604
- } else if (typeof end === "string") {
2605
- encoding = end;
2606
- end = buffer.length;
2607
- }
2608
- if (encoding !== void 0 && typeof encoding !== "string") {
2609
- throw new TypeError("encoding must be a string");
2610
- }
2611
- if (encoding === "latin1") {
2612
- encoding = "binary";
2613
- }
2614
- if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) {
2615
- throw new TypeError("Unknown encoding: " + encoding);
2616
- }
2617
- if (val === "") {
2618
- return fillWithNumber(buffer, 0, start, end);
2619
- }
2620
- if (isSingleByte(val)) {
2621
- return fillWithNumber(buffer, val.charCodeAt(0), start, end);
2622
- }
2623
- val = new Buffer(val, encoding);
2624
- }
2625
- if (Buffer.isBuffer(val)) {
2626
- return fillWithBuffer(buffer, val, start, end);
2627
- }
2628
- return fillWithNumber(buffer, 0, start, end);
2629
- }
2630
- module2.exports = fill;
2631
- }
2632
- });
2633
-
2634
- // node_modules/buffer-alloc-unsafe/index.js
2635
- var require_buffer_alloc_unsafe = __commonJS({
2636
- "node_modules/buffer-alloc-unsafe/index.js"(exports2, module2) {
2637
- "use strict";
2638
- function allocUnsafe(size) {
2639
- if (typeof size !== "number") {
2640
- throw new TypeError('"size" argument must be a number');
2641
- }
2642
- if (size < 0) {
2643
- throw new RangeError('"size" argument must not be negative');
2644
- }
2645
- if (Buffer.allocUnsafe) {
2646
- return Buffer.allocUnsafe(size);
2647
- } else {
2648
- return new Buffer(size);
2649
- }
2650
- }
2651
- module2.exports = allocUnsafe;
2652
- }
2653
- });
2654
-
2655
- // node_modules/buffer-alloc/index.js
2656
- var require_buffer_alloc = __commonJS({
2657
- "node_modules/buffer-alloc/index.js"(exports2, module2) {
2658
- "use strict";
2659
- var bufferFill = require_buffer_fill();
2660
- var allocUnsafe = require_buffer_alloc_unsafe();
2661
- module2.exports = function alloc(size, fill, encoding) {
2662
- if (typeof size !== "number") {
2663
- throw new TypeError('"size" argument must be a number');
2664
- }
2665
- if (size < 0) {
2666
- throw new RangeError('"size" argument must not be negative');
2667
- }
2668
- if (Buffer.alloc) {
2669
- return Buffer.alloc(size, fill, encoding);
2670
- }
2671
- var buffer = allocUnsafe(size);
2672
- if (size === 0) {
2673
- return buffer;
2674
- }
2675
- if (fill === void 0) {
2676
- return bufferFill(buffer, 0);
2677
- }
2678
- if (typeof encoding !== "string") {
2679
- encoding = void 0;
2680
- }
2681
- return bufferFill(buffer, fill, encoding);
2682
- };
2683
- }
2684
- });
2685
-
2686
- // node_modules/buffer-from/index.js
2687
- var require_buffer_from = __commonJS({
2688
- "node_modules/buffer-from/index.js"(exports2, module2) {
2689
- "use strict";
2690
- var toString = Object.prototype.toString;
2691
- var isModern = typeof Buffer !== "undefined" && typeof Buffer.alloc === "function" && typeof Buffer.allocUnsafe === "function" && typeof Buffer.from === "function";
2692
- function isArrayBuffer(input) {
2693
- return toString.call(input).slice(8, -1) === "ArrayBuffer";
2694
- }
2695
- function fromArrayBuffer(obj, byteOffset, length) {
2696
- byteOffset >>>= 0;
2697
- var maxLength = obj.byteLength - byteOffset;
2698
- if (maxLength < 0) {
2699
- throw new RangeError("'offset' is out of bounds");
2700
- }
2701
- if (length === void 0) {
2702
- length = maxLength;
2703
- } else {
2704
- length >>>= 0;
2705
- if (length > maxLength) {
2706
- throw new RangeError("'length' is out of bounds");
2707
- }
2708
- }
2709
- return isModern ? Buffer.from(obj.slice(byteOffset, byteOffset + length)) : new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)));
2710
- }
2711
- function fromString(string, encoding) {
2712
- if (typeof encoding !== "string" || encoding === "") {
2713
- encoding = "utf8";
2714
- }
2715
- if (!Buffer.isEncoding(encoding)) {
2716
- throw new TypeError('"encoding" must be a valid string encoding');
2717
- }
2718
- return isModern ? Buffer.from(string, encoding) : new Buffer(string, encoding);
2719
- }
2720
- function bufferFrom(value, encodingOrOffset, length) {
2721
- if (typeof value === "number") {
2722
- throw new TypeError('"value" argument must not be a number');
2723
- }
2724
- if (isArrayBuffer(value)) {
2725
- return fromArrayBuffer(value, encodingOrOffset, length);
2726
- }
2727
- if (typeof value === "string") {
2728
- return fromString(value, encodingOrOffset);
2729
- }
2730
- return isModern ? Buffer.from(value) : new Buffer(value);
2731
- }
2732
- module2.exports = bufferFrom;
2733
- }
2734
- });
2735
-
2736
- // node_modules/wav/lib/writer.js
2737
- var require_writer = __commonJS({
2738
- "node_modules/wav/lib/writer.js"(exports2, module2) {
2739
- "use strict";
2740
- var inherits = require("util").inherits;
2741
- var Transform = require_transform();
2742
- var debug = require_src2()("wave:writer");
2743
- var bufferAlloc = require_buffer_alloc();
2744
- var bufferFrom = require_buffer_from();
2745
- module2.exports = Writer;
2746
- var RIFF = bufferFrom("RIFF");
2747
- var WAVE = bufferFrom("WAVE");
2748
- var fmt = bufferFrom("fmt ");
2749
- var data = bufferFrom("data");
2750
- var MAX_WAV = 4294967295 - 100;
2751
- function Writer(opts) {
2752
- if (!(this instanceof Writer)) {
2753
- return new Writer(opts);
2754
- }
2755
- Transform.call(this, opts);
2756
- this.endianness = "LE";
2757
- this.format = 1;
2758
- this.channels = 2;
2759
- this.sampleRate = 44100;
2760
- this.bitDepth = 16;
2761
- this.bytesProcessed = 0;
2762
- if (opts) {
2763
- if (opts.format != null) this.format = opts.format;
2764
- if (opts.channels != null) this.channels = opts.channels;
2765
- if (opts.sampleRate != null) this.sampleRate = opts.sampleRate;
2766
- if (opts.bitDepth != null) this.bitDepth = opts.bitDepth;
2767
- }
2768
- this._writeHeader();
2769
- }
2770
- inherits(Writer, Transform);
2771
- Writer.prototype._writeHeader = function() {
2772
- debug("_writeHeader()");
2773
- var headerLength = 44;
2774
- var dataLength = this.dataLength;
2775
- if (dataLength == null) {
2776
- debug('using default "dataLength" of %d', MAX_WAV);
2777
- dataLength = MAX_WAV;
2778
- }
2779
- var fileSize = dataLength + headerLength;
2780
- var header = bufferAlloc(headerLength);
2781
- var offset = 0;
2782
- RIFF.copy(header, offset);
2783
- offset += RIFF.length;
2784
- header["writeUInt32" + this.endianness](fileSize - 8, offset);
2785
- offset += 4;
2786
- WAVE.copy(header, offset);
2787
- offset += WAVE.length;
2788
- fmt.copy(header, offset);
2789
- offset += fmt.length;
2790
- header["writeUInt32" + this.endianness](16, offset);
2791
- offset += 4;
2792
- header["writeUInt16" + this.endianness](this.format, offset);
2793
- offset += 2;
2794
- header["writeUInt16" + this.endianness](this.channels, offset);
2795
- offset += 2;
2796
- header["writeUInt32" + this.endianness](this.sampleRate, offset);
2797
- offset += 4;
2798
- var byteRate = this.byteRate;
2799
- if (byteRate == null) {
2800
- byteRate = this.sampleRate * this.channels * this.bitDepth / 8;
2801
- }
2802
- header["writeUInt32" + this.endianness](byteRate, offset);
2803
- offset += 4;
2804
- var blockAlign = this.blockAlign;
2805
- if (blockAlign == null) {
2806
- blockAlign = this.channels * this.bitDepth / 8;
2807
- }
2808
- header["writeUInt16" + this.endianness](blockAlign, offset);
2809
- offset += 2;
2810
- header["writeUInt16" + this.endianness](this.bitDepth, offset);
2811
- offset += 2;
2812
- data.copy(header, offset);
2813
- offset += data.length;
2814
- header["writeUInt32" + this.endianness](dataLength, offset);
2815
- offset += 4;
2816
- this._header = header;
2817
- this.headerLength = headerLength;
2818
- this.push(header);
2819
- };
2820
- Writer.prototype._onEnd = function(write) {
2821
- debug("_onEnd()");
2822
- };
2823
- Writer.prototype._transform = function(chunk, enc, done) {
2824
- this.push(chunk);
2825
- this.bytesProcessed += chunk.length;
2826
- done();
2827
- };
2828
- Writer.prototype._flush = function(done) {
2829
- debug("_flush()");
2830
- done();
2831
- this.dataLength = this.bytesProcessed;
2832
- process.nextTick(this._emitHeader.bind(this));
2833
- };
2834
- Writer.prototype._emitHeader = function() {
2835
- debug("_emitHeader()");
2836
- var dataLength = this.dataLength;
2837
- var headerLength = this.headerLength;
2838
- var header = this._header;
2839
- header["writeUInt32" + this.endianness](dataLength + headerLength - 8, 4);
2840
- header["writeUInt32" + this.endianness](dataLength, headerLength - 4);
2841
- this.emit("header", header);
2842
- };
2843
- }
2844
- });
2845
-
2846
- // node_modules/wav/lib/file-writer.js
2847
- var require_file_writer = __commonJS({
2848
- "node_modules/wav/lib/file-writer.js"(exports2, module2) {
2849
- "use strict";
2850
- var fs3 = require("fs");
2851
- var Writer = require_writer();
2852
- var inherits = require("util").inherits;
2853
- module2.exports = FileWriter2;
2854
- function FileWriter2(path3, opts) {
2855
- if (!(this instanceof FileWriter2)) return new FileWriter2(path3, opts);
2856
- Writer.call(this, opts);
2857
- this.path = path3;
2858
- this.file = fs3.createWriteStream(path3, opts);
2859
- this.pipe(this.file);
2860
- this.on("header", this._onHeader);
2861
- }
2862
- inherits(FileWriter2, Writer);
2863
- FileWriter2.prototype._onHeader = function(header) {
2864
- var self = this;
2865
- var fd;
2866
- function onOpen(err, f) {
2867
- if (err) return self.emit("error", err);
2868
- fd = f;
2869
- fs3.write(fd, header, 0, header.length, 0, onWrite);
2870
- }
2871
- function onWrite(err, bytesWritten) {
2872
- if (err) return self.emit("error", err);
2873
- if (bytesWritten !== header.length) {
2874
- return self.emit("error", new Error('problem writing "header" data'));
2875
- }
2876
- fs3.close(fd, onClose);
2877
- }
2878
- function onClose(err) {
2879
- if (err) return self.emit("error", err);
2880
- self.emit("done");
2881
- }
2882
- fs3.open(self.path, "r+", onOpen);
2883
- };
2884
- }
2885
- });
2886
-
2887
- // node_modules/wav/index.js
2888
- var require_wav = __commonJS({
2889
- "node_modules/wav/index.js"(exports2) {
2890
- "use strict";
2891
- exports2.Reader = require_reader();
2892
- exports2.Writer = require_writer();
2893
- exports2.FileWriter = require_file_writer();
2894
- }
2895
- });
2896
-
2897
- // test/wsjtx.test.ts
2898
- var import_node_test = require("test");
2899
- var import_node_assert = __toESM(require("assert"), 1);
2900
- var import_node_fs2 = __toESM(require("fs"), 1);
2901
- var import_node_path2 = __toESM(require("path"), 1);
2902
- var import_node_url2 = require("url");
2903
- var wav = __toESM(require_wav(), 1);
2904
-
2905
- // src/types.ts
2906
- var WSJTXMode = /* @__PURE__ */ ((WSJTXMode2) => {
2907
- WSJTXMode2[WSJTXMode2["FT8"] = 0] = "FT8";
2908
- WSJTXMode2[WSJTXMode2["FT4"] = 1] = "FT4";
2909
- WSJTXMode2[WSJTXMode2["JT4"] = 2] = "JT4";
2910
- WSJTXMode2[WSJTXMode2["JT65"] = 3] = "JT65";
2911
- WSJTXMode2[WSJTXMode2["JT9"] = 4] = "JT9";
2912
- WSJTXMode2[WSJTXMode2["FST4"] = 5] = "FST4";
2913
- WSJTXMode2[WSJTXMode2["Q65"] = 6] = "Q65";
2914
- WSJTXMode2[WSJTXMode2["FST4W"] = 7] = "FST4W";
2915
- WSJTXMode2[WSJTXMode2["WSPR"] = 8] = "WSPR";
2916
- return WSJTXMode2;
2917
- })(WSJTXMode || {});
2918
- var WSJTXError = class extends Error {
2919
- constructor(message, code) {
2920
- super(message);
2921
- this.code = code;
2922
- this.name = "WSJTXError";
2923
- }
2924
- };
2925
-
2926
- // src/index.ts
2927
- var import_node_module = require("module");
2928
- var import_node_url = require("url");
2929
- var import_node_path = __toESM(require("path"), 1);
2930
- var import_node_fs = __toESM(require("fs"), 1);
2931
- var import_meta = {};
2932
- function getModuleContext() {
2933
- try {
2934
- if (typeof import_meta !== "undefined" && import_meta.url) {
2935
- return {
2936
- require: (0, import_node_module.createRequire)(import_meta.url),
2937
- __filename: (0, import_node_url.fileURLToPath)(import_meta.url),
2938
- __dirname: import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url))
2939
- };
2940
- }
2941
- } catch {
2942
- }
2943
- return {
2944
- require: typeof require2 !== "undefined" ? require2 : (0, import_node_module.createRequire)("file://"),
2945
- __filename: typeof __filename !== "undefined" ? __filename : "",
2946
- __dirname: typeof __dirname !== "undefined" ? __dirname : ""
2947
- };
2948
- }
2949
- var moduleContext = getModuleContext();
2950
- var { require: require2, __filename, __dirname } = moduleContext;
2951
- function findNativeModule() {
2952
- const platform = process.platform;
2953
- const arch = process.arch;
2954
- const isPkgEnvironment = !!process.pkg || __dirname.includes("/snapshot/") || __dirname.includes("\\snapshot\\");
2955
- if (isPkgEnvironment) {
2956
- console.log("Detected pkg packaged environment");
2957
- const execDir = import_node_path.default.dirname(process.execPath);
2958
- const pkgPaths = [
2959
- // 1. 与可执行文件同目录(最常见的打包方式)
2960
- import_node_path.default.join(execDir, "wsjtx_lib_nodejs.node"),
2961
- import_node_path.default.join(execDir, `wsjtx_lib_nodejs-${platform}-${arch}.node`),
2962
- // 2. prebuilds 子目录(保持结构的打包方式)
2963
- import_node_path.default.join(execDir, "prebuilds", `${platform}-${arch}`, "wsjtx_lib_nodejs.node"),
2964
- // 3. 相对于可执行文件的其他可能位置
2965
- import_node_path.default.join(execDir, "..", "prebuilds", `${platform}-${arch}`, "wsjtx_lib_nodejs.node"),
2966
- import_node_path.default.join(execDir, "lib", "wsjtx_lib_nodejs.node"),
2967
- import_node_path.default.join(execDir, "native", "wsjtx_lib_nodejs.node")
2968
- ];
2969
- console.log("PKG environment - searching for native module:");
2970
- pkgPaths.forEach((p) => console.log(` - ${p}`));
2971
- for (const modulePath of pkgPaths) {
2972
- if (import_node_fs.default.existsSync(modulePath)) {
2973
- console.log(`Found native module at: ${modulePath}`);
2974
- return modulePath;
2975
- }
2976
- }
2977
- const pathList2 = pkgPaths.map((p) => ` - ${p}`).join("\n");
2978
- throw new Error(
2979
- `Native module not found in pkg packaged environment for ${platform}-${arch}.
2980
- Searched in:
2981
- ${pathList2}
2982
-
2983
- Solutions:
2984
- 1. Ensure the native module is included in your pkg configuration
2985
- 2. Copy wsjtx_lib_nodejs.node to the same directory as your executable
2986
- 3. Check if the native module was properly bundled during packaging`
2987
- );
2988
- }
2989
- const moduleRoot = import_node_path.default.resolve(__dirname, "..");
2990
- const possiblePaths = [
2991
- // 1. Prebuilt binaries (npm packages) - highest priority
2992
- import_node_path.default.join(moduleRoot, "prebuilds", `${platform}-${arch}`, "wsjtx_lib_nodejs.node"),
2993
- // 2. GitHub Actions legacy format (for backward compatibility)
2994
- import_node_path.default.join(moduleRoot, "prebuilds", `${platform}-latest-${arch}`, "wsjtx_lib_nodejs.node"),
2995
- import_node_path.default.join(moduleRoot, "prebuilds", `ubuntu-latest-${arch}`, "wsjtx_lib_nodejs.node"),
2996
- // Linux
2997
- import_node_path.default.join(moduleRoot, "prebuilds", `macos-latest-${arch}`, "wsjtx_lib_nodejs.node"),
2998
- // macOS
2999
- import_node_path.default.join(moduleRoot, "prebuilds", `windows-latest-${arch}`, "wsjtx_lib_nodejs.node"),
3000
- // Windows
3001
- // 3. Local development builds - third priority
3002
- import_node_path.default.join(moduleRoot, "build", "wsjtx_lib_nodejs.node"),
3003
- import_node_path.default.join(moduleRoot, "build", "Release", "wsjtx_lib_nodejs.node")
3004
- ];
3005
- console.log("Normal environment - searching for native module:");
3006
- possiblePaths.forEach((p) => console.log(` - ${p}`));
3007
- for (const modulePath of possiblePaths) {
3008
- if (import_node_fs.default.existsSync(modulePath)) {
3009
- console.log(`Found native module at: ${modulePath}`);
3010
- return modulePath;
3011
- }
3012
- }
3013
- const pathList = possiblePaths.map((p) => ` - ${p}`).join("\n");
3014
- throw new Error(
3015
- `Native module not found for ${platform}-${arch}.
3016
- Searched in:
3017
- ${pathList}
3018
-
3019
- Solutions:
3020
- 1. If you installed via npm, this may be a missing prebuilt binary
3021
- 2. For development, run "npm run build" to compile the native module
3022
- 3. Check if your platform/architecture is supported`
3023
- );
3024
- }
3025
- var nativeModulePath = findNativeModule();
3026
- var { WSJTXLib: NativeWSJTXLib } = require2(nativeModulePath);
3027
- var WSJTXLib = class _WSJTXLib {
3028
- native;
3029
- config;
3030
- /**
3031
- * Create a new WSJTX library instance
3032
- *
3033
- * @param config Optional configuration options
3034
- * @throws {WSJTXError} If the native library fails to initialize
3035
- */
3036
- constructor(config = {}) {
3037
- this.config = {
3038
- maxThreads: 4,
3039
- debug: false,
3040
- ...config
3041
- };
3042
- try {
3043
- this.native = new NativeWSJTXLib();
3044
- } catch (error) {
3045
- throw new WSJTXError(
3046
- `Failed to initialize WSJTX library: ${error instanceof Error ? error.message : String(error)}`,
3047
- "INIT_ERROR"
3048
- );
3049
- }
3050
- }
3051
- /**
3052
- * Decode digital radio signals from audio data
3053
- *
3054
- * This method processes audio samples and attempts to decode digital
3055
- * messages using the specified protocol mode. The operation is performed
3056
- * asynchronously to avoid blocking the Node.js event loop.
3057
- *
3058
- * @param mode The digital mode to use for decoding
3059
- * @param audioData Audio samples (Float32Array or Int16Array)
3060
- * @param frequency Center frequency in Hz
3061
- * @param threads Number of threads to use (1-16, default: 4)
3062
- * @returns Promise that resolves when decoding is complete
3063
- *
3064
- * @throws {WSJTXError} If parameters are invalid or decoding fails
3065
- *
3066
- * @example
3067
- * ```typescript
3068
- * const audioData = new Float32Array(48000 * 13); // 13 seconds
3069
- * await lib.decode(WSJTXMode.FT8, audioData, 1500);
3070
- * const messages = lib.pullMessages();
3071
- * ```
3072
- */
3073
- async decode(mode, audioData, frequency, threads = this.config.maxThreads || 4) {
3074
- this.validateMode(mode);
3075
- this.validateFrequency(frequency);
3076
- this.validateThreads(threads);
3077
- this.validateAudioData(audioData);
3078
- if (!this.isDecodingSupported(mode)) {
3079
- throw new WSJTXError(`Decoding not supported for mode: ${WSJTXMode[mode]}`, "UNSUPPORTED_MODE");
3080
- }
3081
- return new Promise((resolve, reject) => {
3082
- const callback = (error, result) => {
3083
- if (error) {
3084
- reject(new WSJTXError(error.message, "DECODE_ERROR"));
3085
- } else {
3086
- resolve({ success: result });
3087
- }
3088
- };
3089
- try {
3090
- this.native.decode(mode, audioData, frequency, threads, callback);
3091
- } catch (error) {
3092
- reject(new WSJTXError(
3093
- `Decode operation failed: ${error instanceof Error ? error.message : String(error)}`,
3094
- "DECODE_ERROR"
3095
- ));
3096
- }
3097
- });
3098
- }
3099
- /**
3100
- * Encode a message into audio waveform for transmission
3101
- *
3102
- * Generates the audio waveform that represents the specified message
3103
- * using the given digital mode. The resulting audio can be fed to
3104
- * a radio transmitter or audio interface.
3105
- *
3106
- * @param mode The digital mode to use for encoding
3107
- * @param message The message text to encode (mode-specific format)
3108
- * @param frequency Center frequency in Hz
3109
- * @param threads Number of threads to use (1-16, default: 4)
3110
- * @returns Promise that resolves with encoded audio data and actual message sent
3111
- *
3112
- * @throws {WSJTXError} If parameters are invalid or encoding fails
3113
- *
3114
- * @example
3115
- * ```typescript
3116
- * const result = await lib.encode(WSJTXMode.FT8, 'CQ DX K1ABC FN20', 1500);
3117
- * console.log('Generated audio samples:', result.audioData.length);
3118
- * console.log('Actual message sent:', result.messageSent);
3119
- * ```
3120
- */
3121
- async encode(mode, message, frequency, threads = this.config.maxThreads || 4) {
3122
- this.validateMode(mode);
3123
- this.validateMessage(message);
3124
- this.validateFrequency(frequency);
3125
- this.validateThreads(threads);
3126
- if (!this.isEncodingSupported(mode)) {
3127
- throw new WSJTXError(`Encoding not supported for mode: ${WSJTXMode[mode]}`, "UNSUPPORTED_MODE");
3128
- }
3129
- return new Promise((resolve, reject) => {
3130
- const callback = (error, result) => {
3131
- if (error) {
3132
- reject(new WSJTXError(error.message, "ENCODE_ERROR"));
3133
- } else {
3134
- resolve(result);
3135
- }
3136
- };
3137
- try {
3138
- this.native.encode(mode, message, frequency, threads, callback);
3139
- } catch (error) {
3140
- reject(new WSJTXError(
3141
- `Encode operation failed: ${error instanceof Error ? error.message : String(error)}`,
3142
- "ENCODE_ERROR"
3143
- ));
3144
- }
3145
- });
3146
- }
3147
- /**
3148
- * Decode WSPR signals from IQ data
3149
- *
3150
- * WSPR (Weak Signal Propagation Reporter) is a specialized protocol
3151
- * for studying radio propagation. This method takes IQ (complex)
3152
- * samples and attempts to decode WSPR transmissions.
3153
- *
3154
- * @param iqData Interleaved I,Q samples as Float32Array
3155
- * @param options Decoder options (frequency, callsign, etc.)
3156
- * @returns Promise that resolves with array of decoded WSPR results
3157
- *
3158
- * @throws {WSJTXError} If parameters are invalid or decoding fails
3159
- *
3160
- * @example
3161
- * ```typescript
3162
- * const iqData = new Float32Array(2 * 12000 * 111); // 2 minutes of IQ data
3163
- * const options = {
3164
- * dialFrequency: 14095600, // 20m WSPR frequency
3165
- * callsign: 'K1ABC',
3166
- * locator: 'FN20'
3167
- * };
3168
- * const results = await lib.decodeWSPR(iqData, options);
3169
- * ```
3170
- */
3171
- async decodeWSPR(iqData, options = {}) {
3172
- this.validateIQData(iqData);
3173
- const defaultOptions = {
3174
- dialFrequency: 14095600,
3175
- // 20m WSPR frequency
3176
- callsign: "",
3177
- locator: "",
3178
- quickMode: false,
3179
- useHashTable: true,
3180
- passes: 2,
3181
- subtraction: true,
3182
- ...options
3183
- };
3184
- return new Promise((resolve, reject) => {
3185
- const callback = (error, results) => {
3186
- if (error) {
3187
- reject(new WSJTXError(error.message, "WSPR_DECODE_ERROR"));
3188
- } else {
3189
- resolve(results);
3190
- }
3191
- };
3192
- try {
3193
- this.native.decodeWSPR(iqData, defaultOptions, callback);
3194
- } catch (error) {
3195
- reject(new WSJTXError(
3196
- `WSPR decode failed: ${error instanceof Error ? error.message : String(error)}`,
3197
- "WSPR_DECODE_ERROR"
3198
- ));
3199
- }
3200
- });
3201
- }
3202
- /**
3203
- * Retrieve decoded messages from the internal queue
3204
- *
3205
- * Messages are added to an internal queue as they are decoded.
3206
- * This method retrieves and removes all pending messages from the queue.
3207
- *
3208
- * @returns Array of decoded messages
3209
- *
3210
- * @example
3211
- * ```typescript
3212
- * const messages = lib.pullMessages();
3213
- * messages.forEach(msg => {
3214
- * console.log(`${msg.text} (SNR: ${msg.snr} dB, ΔT: ${msg.deltaTime}s)`);
3215
- * });
3216
- * ```
3217
- */
3218
- pullMessages() {
3219
- try {
3220
- return this.native.pullMessages();
3221
- } catch (error) {
3222
- throw new WSJTXError(
3223
- `Failed to pull messages: ${error instanceof Error ? error.message : String(error)}`,
3224
- "PULL_ERROR"
3225
- );
3226
- }
3227
- }
3228
- /**
3229
- * Check if encoding is supported for a specific mode
3230
- *
3231
- * @param mode The mode to check
3232
- * @returns True if encoding is supported
3233
- */
3234
- isEncodingSupported(mode) {
3235
- return this.native.isEncodingSupported(mode);
3236
- }
3237
- /**
3238
- * Check if decoding is supported for a specific mode
3239
- *
3240
- * @param mode The mode to check
3241
- * @returns True if decoding is supported
3242
- */
3243
- isDecodingSupported(mode) {
3244
- return this.native.isDecodingSupported(mode);
3245
- }
3246
- /**
3247
- * Get the required sample rate for a specific mode
3248
- *
3249
- * @param mode The mode to query
3250
- * @returns Sample rate in Hz
3251
- */
3252
- getSampleRate(mode) {
3253
- return this.native.getSampleRate(mode);
3254
- }
3255
- /**
3256
- * Get the transmission duration for a specific mode
3257
- *
3258
- * @param mode The mode to query
3259
- * @returns Duration in seconds
3260
- */
3261
- getTransmissionDuration(mode) {
3262
- return this.native.getTransmissionDuration(mode);
3263
- }
3264
- /**
3265
- * Get capabilities for all supported modes
3266
- *
3267
- * @returns Array of mode capability information
3268
- */
3269
- getAllModeCapabilities() {
3270
- const modes = Object.values(WSJTXMode).filter((v) => typeof v === "number");
3271
- return modes.map((mode) => ({
3272
- mode,
3273
- encodingSupported: this.isEncodingSupported(mode),
3274
- decodingSupported: this.isDecodingSupported(mode),
3275
- sampleRate: this.getSampleRate(mode),
3276
- duration: this.getTransmissionDuration(mode)
3277
- }));
3278
- }
3279
- /**
3280
- * Convert audio format between Float32Array and Int16Array
3281
- *
3282
- * @param audioData Input audio data
3283
- * @param targetFormat Target format ('float32' or 'int16')
3284
- * @returns Converted audio data
3285
- */
3286
- static convertAudioFormat(audioData, targetFormat) {
3287
- if (targetFormat !== "float32" && targetFormat !== "int16") {
3288
- throw new Error(`Invalid target format: ${targetFormat}. Must be 'float32' or 'int16'`);
3289
- }
3290
- if (targetFormat === "float32") {
3291
- if (audioData instanceof Float32Array) {
3292
- return audioData;
3293
- }
3294
- const result = new Float32Array(audioData.length);
3295
- for (let i = 0; i < audioData.length; i++) {
3296
- result[i] = audioData[i] / 32768;
3297
- }
3298
- return result;
3299
- } else {
3300
- if (audioData instanceof Int16Array) {
3301
- return audioData;
3302
- }
3303
- const result = new Int16Array(audioData.length);
3304
- for (let i = 0; i < audioData.length; i++) {
3305
- result[i] = Math.max(-32768, Math.min(32767, Math.round(audioData[i] * 32768)));
3306
- }
3307
- return result;
3308
- }
3309
- }
3310
- /**
3311
- * Static convenience helper for async audio format conversion.
3312
- */
3313
- static async convertAudioFormatAsync(audioData, targetFormat) {
3314
- const lib = new _WSJTXLib();
3315
- return lib.convertAudioFormatAsync(audioData, targetFormat);
3316
- }
3317
- /**
3318
- * Asynchronously convert audio data format without blocking the event loop
3319
- *
3320
- * Uses native thread pool to offload conversion.
3321
- */
3322
- async convertAudioFormatAsync(audioData, targetFormat) {
3323
- if (targetFormat !== "float32" && targetFormat !== "int16") {
3324
- throw new Error(`Invalid target format: ${targetFormat}. Must be 'float32' or 'int16'`);
3325
- }
3326
- this.validateAudioData(audioData);
3327
- return new Promise((resolve, reject) => {
3328
- const callback = (error, result) => {
3329
- if (error) {
3330
- reject(new WSJTXError(error.message ?? String(error), "CONVERT_ERROR"));
3331
- } else {
3332
- resolve(result);
3333
- }
3334
- };
3335
- try {
3336
- this.native.convertAudioAsync(audioData, targetFormat, callback);
3337
- } catch (error) {
3338
- reject(new WSJTXError(
3339
- `Convert operation failed: ${error instanceof Error ? error.message : String(error)}`,
3340
- "CONVERT_ERROR"
3341
- ));
3342
- }
3343
- });
3344
- }
3345
- // Validation methods
3346
- validateMode(mode) {
3347
- if (!Object.values(WSJTXMode).includes(mode)) {
3348
- throw new WSJTXError(`Invalid mode: ${mode}`, "INVALID_MODE");
3349
- }
3350
- }
3351
- validateFrequency(frequency) {
3352
- if (!Number.isInteger(frequency) || frequency < 0 || frequency > 3e7) {
3353
- throw new WSJTXError(
3354
- `Invalid frequency: ${frequency}. Must be between 0 and 30,000,000 Hz`,
3355
- "INVALID_FREQUENCY"
3356
- );
3357
- }
3358
- }
3359
- validateThreads(threads) {
3360
- if (!Number.isInteger(threads) || threads < 1 || threads > 16) {
3361
- throw new WSJTXError(
3362
- `Invalid thread count: ${threads}. Must be between 1 and 16`,
3363
- "INVALID_THREADS"
3364
- );
3365
- }
3366
- }
3367
- validateMessage(message) {
3368
- if (typeof message !== "string" || message.length === 0 || message.length > 22) {
3369
- throw new WSJTXError(
3370
- `Invalid message: "${message}". Must be 1-22 characters long`,
3371
- "INVALID_MESSAGE"
3372
- );
3373
- }
3374
- }
3375
- validateAudioData(audioData) {
3376
- if (!(audioData instanceof Float32Array) && !(audioData instanceof Int16Array)) {
3377
- throw new WSJTXError(
3378
- "Invalid audio data: must be Float32Array or Int16Array",
3379
- "INVALID_AUDIO_DATA"
3380
- );
3381
- }
3382
- if (audioData.length === 0) {
3383
- throw new WSJTXError("Audio data cannot be empty", "INVALID_AUDIO_DATA");
3384
- }
3385
- }
3386
- validateIQData(iqData) {
3387
- if (!(iqData instanceof Float32Array)) {
3388
- throw new WSJTXError(
3389
- "Invalid IQ data: must be Float32Array with interleaved I,Q samples",
3390
- "INVALID_IQ_DATA"
3391
- );
3392
- }
3393
- if (iqData.length === 0 || iqData.length % 2 !== 0) {
3394
- throw new WSJTXError(
3395
- "IQ data length must be even (interleaved I,Q samples)",
3396
- "INVALID_IQ_DATA"
3397
- );
3398
- }
3399
- }
3400
- };
3401
-
3402
- // test/wsjtx.test.ts
3403
- var import_meta2 = {};
3404
- var __filename2 = (0, import_node_url2.fileURLToPath)(import_meta2.url);
3405
- var __dirname2 = import_node_path2.default.dirname(__filename2);
3406
- var testOutputDir = import_node_path2.default.join(__dirname2, "output");
3407
- (0, import_node_test.describe)("WSJTX Library Comprehensive Tests", () => {
3408
- let lib;
3409
- (0, import_node_test.before)(() => {
3410
- if (!import_node_fs2.default.existsSync(testOutputDir)) {
3411
- import_node_fs2.default.mkdirSync(testOutputDir, { recursive: true });
3412
- }
3413
- });
3414
- (0, import_node_test.beforeEach)(() => {
3415
- lib = new WSJTXLib({
3416
- maxThreads: 4,
3417
- debug: true
3418
- });
3419
- });
3420
- (0, import_node_test.afterEach)(() => {
3421
- });
3422
- (0, import_node_test.after)(() => {
3423
- try {
3424
- if (import_node_fs2.default.existsSync(testOutputDir)) {
3425
- const files = import_node_fs2.default.readdirSync(testOutputDir);
3426
- files.forEach((file) => {
3427
- if (file.endsWith(".wav")) {
3428
- import_node_fs2.default.unlinkSync(import_node_path2.default.join(testOutputDir, file));
3429
- }
3430
- });
3431
- const remainingFiles = import_node_fs2.default.readdirSync(testOutputDir);
3432
- if (remainingFiles.length === 0) {
3433
- import_node_fs2.default.rmdirSync(testOutputDir);
3434
- }
3435
- }
3436
- } catch (error) {
3437
- }
3438
- });
3439
- (0, import_node_test.describe)("Basic Functionality Tests", () => {
3440
- (0, import_node_test.it)("should create library instance", () => {
3441
- import_node_assert.default.ok(lib instanceof WSJTXLib);
3442
- });
3443
- (0, import_node_test.it)("should support custom configuration", () => {
3444
- const customLib = new WSJTXLib({
3445
- maxThreads: 8,
3446
- debug: false
3447
- });
3448
- import_node_assert.default.ok(customLib instanceof WSJTXLib);
3449
- });
3450
- (0, import_node_test.it)("should return correct FT8 sample rate", () => {
3451
- const sampleRate = lib.getSampleRate(0 /* FT8 */);
3452
- import_node_assert.default.strictEqual(sampleRate, 48e3);
3453
- });
3454
- (0, import_node_test.it)("should return correct FT8 transmission duration", () => {
3455
- const duration = lib.getTransmissionDuration(0 /* FT8 */);
3456
- import_node_assert.default.ok(Math.abs(duration - 12.64) < 0.1);
3457
- });
3458
- (0, import_node_test.it)("should correctly check encoding support", () => {
3459
- import_node_assert.default.strictEqual(lib.isEncodingSupported(0 /* FT8 */), true);
3460
- import_node_assert.default.strictEqual(lib.isDecodingSupported(0 /* FT8 */), true);
3461
- });
3462
- (0, import_node_test.it)("should return all mode capabilities", () => {
3463
- const capabilities = lib.getAllModeCapabilities();
3464
- import_node_assert.default.ok(capabilities.length > 0);
3465
- import_node_assert.default.ok("mode" in capabilities[0]);
3466
- import_node_assert.default.ok("encodingSupported" in capabilities[0]);
3467
- import_node_assert.default.ok("decodingSupported" in capabilities[0]);
3468
- import_node_assert.default.ok("sampleRate" in capabilities[0]);
3469
- import_node_assert.default.ok("duration" in capabilities[0]);
3470
- });
3471
- });
3472
- (0, import_node_test.describe)("Parameter Validation Tests", () => {
3473
- (0, import_node_test.it)("should validate mode parameter", async () => {
3474
- const audioData = new Float32Array(1e3);
3475
- await import_node_assert.default.rejects(
3476
- lib.decode(999, audioData, 1e3),
3477
- WSJTXError
3478
- );
3479
- });
3480
- (0, import_node_test.it)("should validate frequency parameter", async () => {
3481
- const audioData = new Float32Array(1e3);
3482
- await import_node_assert.default.rejects(
3483
- lib.decode(0 /* FT8 */, audioData, -1e3),
3484
- WSJTXError
3485
- );
3486
- });
3487
- (0, import_node_test.it)("should validate audio data parameter", async () => {
3488
- await import_node_assert.default.rejects(
3489
- lib.decode(0 /* FT8 */, new Float32Array(0), 1e3),
3490
- WSJTXError
3491
- );
3492
- });
3493
- (0, import_node_test.it)("should validate message parameter", async () => {
3494
- await import_node_assert.default.rejects(
3495
- lib.encode(0 /* FT8 */, "", 1e3),
3496
- WSJTXError
3497
- );
3498
- await import_node_assert.default.rejects(
3499
- lib.encode(0 /* FT8 */, "x".repeat(30), 1e3),
3500
- WSJTXError
3501
- );
3502
- });
3503
- });
3504
- (0, import_node_test.describe)("FT8 Encoding Functionality Tests", () => {
3505
- (0, import_node_test.it)("should successfully encode FT8 message", async () => {
3506
- const message = "CQ TEST BH1ABC OM88";
3507
- const audioFrequency = 1e3;
3508
- const result = await lib.encode(0 /* FT8 */, message, audioFrequency);
3509
- import_node_assert.default.ok("audioData" in result);
3510
- import_node_assert.default.ok("messageSent" in result);
3511
- import_node_assert.default.ok(result.audioData instanceof Float32Array);
3512
- import_node_assert.default.ok(result.audioData.length > 0);
3513
- import_node_assert.default.strictEqual(typeof result.messageSent, "string");
3514
- const sampleRate = lib.getSampleRate(0 /* FT8 */);
3515
- const duration = lib.getTransmissionDuration(0 /* FT8 */);
3516
- const expectedLength = Math.floor(sampleRate * duration);
3517
- import_node_assert.default.ok(Math.abs(result.audioData.length - expectedLength) < 1e3);
3518
- let minVal = Infinity, maxVal = -Infinity;
3519
- for (let i = 0; i < result.audioData.length; i++) {
3520
- const val = result.audioData[i];
3521
- if (val < minVal) minVal = val;
3522
- if (val > maxVal) maxVal = val;
3523
- }
3524
- import_node_assert.default.ok(minVal >= -1);
3525
- import_node_assert.default.ok(maxVal <= 1);
3526
- });
3527
- (0, import_node_test.it)("should encode different FT8 message formats", async () => {
3528
- const testMessages = [
3529
- "CQ DX BH1ABC OM88",
3530
- "BH1ABC BH2DEF +05",
3531
- "BH2DEF BH1ABC R-12",
3532
- "BH1ABC BH2DEF RRR",
3533
- "BH2DEF BH1ABC 73"
3534
- ];
3535
- const audioFrequency = 1e3;
3536
- for (const message of testMessages) {
3537
- const result = await lib.encode(0 /* FT8 */, message, audioFrequency);
3538
- import_node_assert.default.ok(result.audioData instanceof Float32Array);
3539
- import_node_assert.default.ok(result.audioData.length > 0);
3540
- import_node_assert.default.strictEqual(typeof result.messageSent, "string");
3541
- }
3542
- });
3543
- });
3544
- (0, import_node_test.describe)("WAV File Operations Tests", () => {
3545
- let encodedAudioData;
3546
- let testMessage;
3547
- let audioFrequency;
3548
- (0, import_node_test.beforeEach)(async () => {
3549
- testMessage = "CQ TEST BH1ABC OM88";
3550
- audioFrequency = 1e3;
3551
- const encodeResult = await lib.encode(0 /* FT8 */, testMessage, audioFrequency);
3552
- encodedAudioData = encodeResult.audioData;
3553
- });
3554
- (0, import_node_test.it)("should save audio data as WAV file", async () => {
3555
- const wavFilePath = import_node_path2.default.join(testOutputDir, "test_encode.wav");
3556
- const audioInt16 = new Int16Array(encodedAudioData.length);
3557
- for (let i = 0; i < encodedAudioData.length; i++) {
3558
- audioInt16[i] = Math.round(encodedAudioData[i] * 32767);
3559
- }
3560
- await new Promise((resolve, reject) => {
3561
- const writer = new wav.FileWriter(wavFilePath, {
3562
- channels: 1,
3563
- sampleRate: lib.getSampleRate(0 /* FT8 */),
3564
- bitDepth: 16
3565
- });
3566
- writer.on("error", reject);
3567
- writer.on("done", () => resolve());
3568
- const buffer = Buffer.from(audioInt16.buffer);
3569
- writer.write(buffer);
3570
- writer.end();
3571
- });
3572
- import_node_assert.default.ok(import_node_fs2.default.existsSync(wavFilePath));
3573
- const stats = import_node_fs2.default.statSync(wavFilePath);
3574
- import_node_assert.default.ok(stats.size > 1e5);
3575
- });
3576
- (0, import_node_test.it)("should read audio data from WAV file", async () => {
3577
- const wavFilePath = import_node_path2.default.join(testOutputDir, "test_read.wav");
3578
- const audioInt16 = new Int16Array(encodedAudioData.length);
3579
- for (let i = 0; i < encodedAudioData.length; i++) {
3580
- audioInt16[i] = Math.round(encodedAudioData[i] * 32767);
3581
- }
3582
- await new Promise((resolve, reject) => {
3583
- const writer = new wav.FileWriter(wavFilePath, {
3584
- channels: 1,
3585
- sampleRate: lib.getSampleRate(0 /* FT8 */),
3586
- bitDepth: 16
3587
- });
3588
- writer.on("error", reject);
3589
- writer.on("done", () => resolve());
3590
- const buffer = Buffer.from(audioInt16.buffer);
3591
- writer.write(buffer);
3592
- writer.end();
3593
- });
3594
- const audioData = await new Promise((resolve, reject) => {
3595
- const reader = new wav.Reader();
3596
- const chunks = [];
3597
- reader.on("data", (chunk) => chunks.push(chunk));
3598
- reader.on("end", () => {
3599
- const buffer = Buffer.concat(chunks);
3600
- const audioInt162 = new Int16Array(buffer.buffer, buffer.byteOffset, buffer.length / 2);
3601
- const audioFloat32 = new Float32Array(audioInt162.length);
3602
- for (let i = 0; i < audioInt162.length; i++) {
3603
- audioFloat32[i] = audioInt162[i] / 32767;
3604
- }
3605
- resolve(audioFloat32);
3606
- });
3607
- reader.on("error", reject);
3608
- import_node_fs2.default.createReadStream(wavFilePath).pipe(reader);
3609
- });
3610
- import_node_assert.default.strictEqual(audioData.length, encodedAudioData.length);
3611
- let maxDiff = 0;
3612
- for (let i = 0; i < audioData.length; i++) {
3613
- const diff = Math.abs(audioData[i] - encodedAudioData[i]);
3614
- if (diff > maxDiff) maxDiff = diff;
3615
- }
3616
- import_node_assert.default.ok(maxDiff < 1e-3);
3617
- });
3618
- });
3619
- (0, import_node_test.describe)("FT8 Decoding Functionality Tests", () => {
3620
- function resampleTo12kHz(audioData48k) {
3621
- const audioData12k = new Float32Array(Math.floor(audioData48k.length / 4));
3622
- for (let i = 0; i < audioData12k.length; i++) {
3623
- audioData12k[i] = audioData48k[i * 4];
3624
- }
3625
- return audioData12k;
3626
- }
3627
- (0, import_node_test.it)("should decode FT8 audio data (Float32Array)", async () => {
3628
- const message = "CQ TEST BH1ABC OM88";
3629
- const audioFrequency = 1e3;
3630
- const encodeResult = await lib.encode(0 /* FT8 */, message, audioFrequency);
3631
- const decodeResult = await lib.decode(
3632
- 0 /* FT8 */,
3633
- encodeResult.audioData,
3634
- audioFrequency
3635
- );
3636
- import_node_assert.default.ok("success" in decodeResult);
3637
- import_node_assert.default.strictEqual(decodeResult.success, true);
3638
- });
3639
- (0, import_node_test.it)("should decode FT8 audio data (Int16Array)", async () => {
3640
- const message = "CQ DX BH1ABC OM88";
3641
- const audioFrequency = 1e3;
3642
- const encodeResult = await lib.encode(0 /* FT8 */, message, audioFrequency);
3643
- const resampled = resampleTo12kHz(encodeResult.audioData);
3644
- const audioInt16 = new Int16Array(resampled.length);
3645
- for (let i = 0; i < resampled.length; i++) {
3646
- audioInt16[i] = Math.round(resampled[i] * 32767);
3647
- }
3648
- lib.pullMessages();
3649
- const decodeResult = await lib.decode(
3650
- 0 /* FT8 */,
3651
- audioInt16,
3652
- audioFrequency
3653
- );
3654
- import_node_assert.default.ok("success" in decodeResult);
3655
- import_node_assert.default.strictEqual(decodeResult.success, true);
3656
- const messages = lib.pullMessages();
3657
- if (messages.length > 0) {
3658
- console.log(`Successfully decoded: "${messages[0].text}"`);
3659
- import_node_assert.default.strictEqual(typeof messages[0].text, "string");
3660
- import_node_assert.default.strictEqual(typeof messages[0].snr, "number");
3661
- import_node_assert.default.strictEqual(typeof messages[0].deltaTime, "number");
3662
- import_node_assert.default.strictEqual(typeof messages[0].deltaFrequency, "number");
3663
- }
3664
- });
3665
- (0, import_node_test.it)("should handle decode with no messages", async () => {
3666
- const audioData = new Float32Array(48e3);
3667
- for (let i = 0; i < audioData.length; i++) {
3668
- audioData[i] = (Math.random() - 0.5) * 0.01;
3669
- }
3670
- const decodeResult = await lib.decode(
3671
- 0 /* FT8 */,
3672
- audioData,
3673
- 1e3
3674
- );
3675
- import_node_assert.default.ok("success" in decodeResult);
3676
- });
3677
- });
3678
- (0, import_node_test.describe)("WSPR Functionality Tests", () => {
3679
- (0, import_node_test.it)("should handle WSPR decode with minimal data", async () => {
3680
- const sampleCount = 1e3;
3681
- const iqData = new Float32Array(sampleCount * 2);
3682
- for (let i = 0; i < iqData.length; i++) {
3683
- iqData[i] = (Math.random() - 0.5) * 1e-3;
3684
- }
3685
- const options = {
3686
- dialFrequency: 14095600,
3687
- callsign: "TEST",
3688
- locator: "AA00"
3689
- };
3690
- const results = await lib.decodeWSPR(iqData, options);
3691
- import_node_assert.default.ok(Array.isArray(results));
3692
- });
3693
- });
3694
- (0, import_node_test.describe)("Message Queue Tests", () => {
3695
- (0, import_node_test.it)("should pull messages from queue", () => {
3696
- const messages = lib.pullMessages();
3697
- import_node_assert.default.ok(Array.isArray(messages));
3698
- });
3699
- (0, import_node_test.it)("should clear message queue", () => {
3700
- lib.pullMessages();
3701
- const messages = lib.pullMessages();
3702
- import_node_assert.default.strictEqual(messages.length, 0);
3703
- });
3704
- });
3705
- (0, import_node_test.describe)("Audio Format Conversion Tests", () => {
3706
- (0, import_node_test.it)("should convert Float32Array to Int16Array", () => {
3707
- const floatData = new Float32Array([0, 0.5, -0.5, 1, -1]);
3708
- const intData = WSJTXLib.convertAudioFormat(floatData, "int16");
3709
- import_node_assert.default.ok(intData instanceof Int16Array);
3710
- import_node_assert.default.strictEqual(intData.length, floatData.length);
3711
- import_node_assert.default.strictEqual(intData[0], 0);
3712
- import_node_assert.default.ok(Math.abs(intData[1] - 16384) < 10);
3713
- import_node_assert.default.ok(Math.abs(intData[2] + 16384) < 10);
3714
- import_node_assert.default.ok(Math.abs(intData[3] - 32767) < 10);
3715
- import_node_assert.default.ok(Math.abs(intData[4] + 32767) < 10);
3716
- });
3717
- (0, import_node_test.it)("should convert Int16Array to Float32Array", () => {
3718
- const intData = new Int16Array([0, 16384, -16384, 32767, -32767]);
3719
- const floatData = WSJTXLib.convertAudioFormat(intData, "float32");
3720
- import_node_assert.default.ok(floatData instanceof Float32Array);
3721
- import_node_assert.default.strictEqual(floatData.length, intData.length);
3722
- import_node_assert.default.ok(Math.abs(floatData[0] - 0) < 1e-3);
3723
- import_node_assert.default.ok(Math.abs(floatData[1] - 0.5) < 1e-3);
3724
- import_node_assert.default.ok(Math.abs(floatData[2] + 0.5) < 1e-3);
3725
- import_node_assert.default.ok(Math.abs(floatData[3] - 1) < 1e-3);
3726
- import_node_assert.default.ok(Math.abs(floatData[4] + 1) < 1e-3);
3727
- });
3728
- (0, import_node_test.it)("should handle edge cases in conversion", () => {
3729
- const emptyFloat = new Float32Array(0);
3730
- const emptyInt = WSJTXLib.convertAudioFormat(emptyFloat, "int16");
3731
- import_node_assert.default.strictEqual(emptyInt.length, 0);
3732
- const emptyInt16 = new Int16Array(0);
3733
- const emptyFloat32 = WSJTXLib.convertAudioFormat(emptyInt16, "float32");
3734
- import_node_assert.default.strictEqual(emptyFloat32.length, 0);
3735
- });
3736
- (0, import_node_test.it)("should maintain precision in round-trip conversion", () => {
3737
- const originalData = new Float32Array(1e3);
3738
- for (let i = 0; i < originalData.length; i++) {
3739
- originalData[i] = (Math.random() - 0.5) * 2;
3740
- }
3741
- const intData = WSJTXLib.convertAudioFormat(originalData, "int16");
3742
- const convertedData = WSJTXLib.convertAudioFormat(intData, "float32");
3743
- let maxError = 0;
3744
- for (let i = 0; i < originalData.length; i++) {
3745
- const error = Math.abs(originalData[i] - convertedData[i]);
3746
- maxError = Math.max(maxError, error);
3747
- }
3748
- import_node_assert.default.ok(maxError < 1e-3);
3749
- });
3750
- (0, import_node_test.it)("should handle invalid format parameter", () => {
3751
- const floatData = new Float32Array([0.5]);
3752
- import_node_assert.default.throws(() => {
3753
- WSJTXLib.convertAudioFormat(floatData, "invalid");
3754
- });
3755
- });
3756
- });
3757
- (0, import_node_test.describe)("TypeScript Type Safety Tests", () => {
3758
- (0, import_node_test.it)("should provide complete type support", async () => {
3759
- const capabilities = lib.getAllModeCapabilities();
3760
- import_node_assert.default.ok(capabilities.length > 0);
3761
- capabilities.forEach((cap) => {
3762
- const modeName = WSJTXMode[cap.mode];
3763
- import_node_assert.default.strictEqual(typeof modeName, "string");
3764
- import_node_assert.default.strictEqual(typeof cap.sampleRate, "number");
3765
- import_node_assert.default.strictEqual(typeof cap.duration, "number");
3766
- import_node_assert.default.strictEqual(typeof cap.encodingSupported, "boolean");
3767
- import_node_assert.default.strictEqual(typeof cap.decodingSupported, "boolean");
3768
- });
3769
- });
3770
- (0, import_node_test.it)("should provide type-safe encode results", async () => {
3771
- const result = await lib.encode(
3772
- 0 /* FT8 */,
3773
- "CQ TEST K1ABC FN20",
3774
- 1e3
3775
- // Use 1000Hz
3776
- );
3777
- import_node_assert.default.ok(result.audioData instanceof Float32Array);
3778
- import_node_assert.default.strictEqual(typeof result.messageSent, "string");
3779
- });
3780
- (0, import_node_test.it)("should provide type-safe decode results", async () => {
3781
- const audioData = new Float32Array(48e3);
3782
- const result = await lib.decode(
3783
- 0 /* FT8 */,
3784
- audioData,
3785
- 1e3
3786
- );
3787
- import_node_assert.default.strictEqual(typeof result.success, "boolean");
3788
- });
3789
- (0, import_node_test.it)("should provide type-safe message objects", () => {
3790
- const messages = lib.pullMessages();
3791
- messages.forEach((msg) => {
3792
- import_node_assert.default.strictEqual(typeof msg.text, "string");
3793
- import_node_assert.default.strictEqual(typeof msg.snr, "number");
3794
- import_node_assert.default.strictEqual(typeof msg.deltaTime, "number");
3795
- import_node_assert.default.strictEqual(typeof msg.deltaFrequency, "number");
3796
- });
3797
- });
3798
- (0, import_node_test.it)("should enforce enum constraints", () => {
3799
- const validMode = 0 /* FT8 */;
3800
- import_node_assert.default.strictEqual(typeof validMode, "number");
3801
- import_node_assert.default.ok(validMode >= 0);
3802
- });
3803
- });
3804
- (0, import_node_test.describe)("Error Handling Tests", () => {
3805
- (0, import_node_test.it)("should throw WSJTXError for invalid operations", async () => {
3806
- try {
3807
- await lib.decode(999, new Float32Array(1e3), 1e3);
3808
- import_node_assert.default.fail("Should have thrown WSJTXError");
3809
- } catch (error) {
3810
- import_node_assert.default.ok(error instanceof WSJTXError);
3811
- import_node_assert.default.strictEqual(typeof error.message, "string");
3812
- if (error instanceof WSJTXError) {
3813
- import_node_assert.default.strictEqual(typeof error.code, "string");
3814
- }
3815
- }
3816
- });
3817
- (0, import_node_test.it)("should provide meaningful error messages", async () => {
3818
- try {
3819
- await lib.encode(0 /* FT8 */, "", 1e3);
3820
- import_node_assert.default.fail("Should have thrown WSJTXError");
3821
- } catch (error) {
3822
- import_node_assert.default.ok(error instanceof WSJTXError);
3823
- import_node_assert.default.ok(error.message.length > 0);
3824
- if (error instanceof WSJTXError && error.code) {
3825
- import_node_assert.default.ok(error.code.length > 0);
3826
- }
3827
- }
3828
- });
3829
- (0, import_node_test.it)("should handle resource cleanup on errors", async () => {
3830
- try {
3831
- await lib.decode(0 /* FT8 */, new Float32Array(0), 1e3);
3832
- } catch (error) {
3833
- const sampleRate = lib.getSampleRate(0 /* FT8 */);
3834
- import_node_assert.default.strictEqual(sampleRate, 48e3);
3835
- }
3836
- });
3837
- (0, import_node_test.it)("should validate all error codes are strings", async () => {
3838
- const testCases = [
3839
- () => lib.decode(999, new Float32Array(1e3), 1e3),
3840
- () => lib.decode(0 /* FT8 */, new Float32Array(1e3), -1e3),
3841
- () => lib.decode(0 /* FT8 */, new Float32Array(0), 1e3),
3842
- () => lib.encode(0 /* FT8 */, "", 1e3),
3843
- () => lib.encode(0 /* FT8 */, "x".repeat(50), 1e3)
3844
- ];
3845
- for (const testCase of testCases) {
3846
- try {
3847
- await testCase();
3848
- import_node_assert.default.fail("Should have thrown WSJTXError");
3849
- } catch (error) {
3850
- import_node_assert.default.ok(error instanceof WSJTXError);
3851
- if (error instanceof WSJTXError && error.code) {
3852
- import_node_assert.default.strictEqual(typeof error.code, "string");
3853
- import_node_assert.default.ok(error.code.length > 0);
3854
- }
3855
- }
3856
- }
3857
- });
3858
- });
3859
- (0, import_node_test.describe)("Complete Encode-Decode Cycle Test", () => {
3860
- (0, import_node_test.it)("should complete full FT8 encode-decode cycle", async () => {
3861
- const originalMessage = "CQ DX BH1ABC OM88";
3862
- const audioFrequency = 1e3;
3863
- console.log(`
3864
- \u{1F50D} Starting complete encode-decode cycle test:`);
3865
- console.log(` Original message: "${originalMessage}" (verified successful message)`);
3866
- console.log(` Audio frequency: ${audioFrequency} Hz (consistent with original C++ example)`);
3867
- console.log(`
3868
- \u{1F4E4} Step 1: Encoding message...`);
3869
- const encodeResult = await lib.encode(0 /* FT8 */, originalMessage, audioFrequency);
3870
- import_node_assert.default.ok(encodeResult.audioData instanceof Float32Array);
3871
- import_node_assert.default.ok(encodeResult.audioData.length > 0);
3872
- console.log(` \u2705 Encoding successful!`);
3873
- console.log(` Actual message sent: "${encodeResult.messageSent}"`);
3874
- console.log(` Audio samples: ${encodeResult.audioData.length}`);
3875
- console.log(` Audio duration: ${(encodeResult.audioData.length / lib.getSampleRate(0 /* FT8 */)).toFixed(2)} seconds`);
3876
- let minVal = Infinity, maxVal = -Infinity;
3877
- for (let i = 0; i < encodeResult.audioData.length; i++) {
3878
- const val = encodeResult.audioData[i];
3879
- if (val < minVal) minVal = val;
3880
- if (val > maxVal) maxVal = val;
3881
- }
3882
- console.log(` Audio amplitude range: ${minVal.toFixed(4)} to ${maxVal.toFixed(4)}`);
3883
- console.log(`
3884
- \u{1F4BE} Step 2: Saving as WAV file...`);
3885
- const wavFilePath = import_node_path2.default.join(testOutputDir, "cycle_test.wav");
3886
- const audioInt16 = new Int16Array(encodeResult.audioData.length);
3887
- for (let i = 0; i < encodeResult.audioData.length; i++) {
3888
- audioInt16[i] = Math.round(encodeResult.audioData[i] * 32767);
3889
- }
3890
- await new Promise((resolve, reject) => {
3891
- const writer = new wav.FileWriter(wavFilePath, {
3892
- channels: 1,
3893
- sampleRate: lib.getSampleRate(0 /* FT8 */),
3894
- bitDepth: 16
3895
- });
3896
- writer.on("error", reject);
3897
- writer.on("done", () => resolve());
3898
- const buffer = Buffer.from(audioInt16.buffer);
3899
- writer.write(buffer);
3900
- writer.end();
3901
- });
3902
- const stats = import_node_fs2.default.statSync(wavFilePath);
3903
- console.log(` \u2705 WAV file saved successfully: ${import_node_path2.default.basename(wavFilePath)}`);
3904
- console.log(` File size: ${(stats.size / 1024).toFixed(2)} KB`);
3905
- console.log(`
3906
- \u{1F4C2} Step 3: Reading from WAV file...`);
3907
- const audioData = await new Promise((resolve, reject) => {
3908
- const reader = new wav.Reader();
3909
- const chunks = [];
3910
- reader.on("format", (format) => {
3911
- console.log(` WAV format: ${format.channels} channel(s), ${format.sampleRate}Hz, ${format.bitDepth}-bit`);
3912
- });
3913
- reader.on("data", (chunk) => chunks.push(chunk));
3914
- reader.on("end", () => {
3915
- const buffer = Buffer.concat(chunks);
3916
- const audioInt162 = new Int16Array(buffer.buffer, buffer.byteOffset, buffer.length / 2);
3917
- const audioFloat32 = new Float32Array(audioInt162.length);
3918
- for (let i = 0; i < audioInt162.length; i++) {
3919
- audioFloat32[i] = audioInt162[i] / 32767;
3920
- }
3921
- resolve(audioFloat32);
3922
- });
3923
- reader.on("error", reject);
3924
- import_node_fs2.default.createReadStream(wavFilePath).pipe(reader);
3925
- });
3926
- console.log(` \u2705 Audio data read successfully`);
3927
- console.log(` Samples read: ${audioData.length}`);
3928
- console.log(`
3929
- \u{1F50D} Step 4: Decoding audio data...`);
3930
- lib.pullMessages();
3931
- console.log(` Message queue cleared`);
3932
- console.log(`
3933
- \u{1F50D} Step 4a: Direct Float32Array decode...`);
3934
- const decodeResult = await lib.decode(0 /* FT8 */, audioData, audioFrequency);
3935
- console.log(` Direct decode result: ${decodeResult.success ? "Success" : "Failed"}`);
3936
- let messages = lib.pullMessages();
3937
- console.log(` Direct decode found ${messages.length} message(s)`);
3938
- if (messages.length === 0) {
3939
- let resampleTo12kHz2 = function(audioData48k) {
3940
- const audioData12k = new Float32Array(Math.floor(audioData48k.length / 4));
3941
- for (let i = 0; i < audioData12k.length; i++) {
3942
- audioData12k[i] = audioData48k[i * 4];
3943
- }
3944
- return audioData12k;
3945
- };
3946
- var resampleTo12kHz = resampleTo12kHz2;
3947
- console.log(`
3948
- \u{1F50D} Step 4b: Resampled Int16Array decode...`);
3949
- const resampled = resampleTo12kHz2(audioData);
3950
- console.log(` Resampled: ${audioData.length} -> ${resampled.length} samples (48kHz -> 12kHz)`);
3951
- const audioInt16ForDecode = new Int16Array(resampled.length);
3952
- for (let i = 0; i < resampled.length; i++) {
3953
- audioInt16ForDecode[i] = Math.round(resampled[i] * 32767);
3954
- }
3955
- console.log(` Converted to Int16Array: ${audioInt16ForDecode.length} samples`);
3956
- lib.pullMessages();
3957
- const decodeResult2 = await lib.decode(0 /* FT8 */, audioInt16ForDecode, audioFrequency);
3958
- console.log(` Resampled decode result: ${decodeResult2.success ? "Success" : "Failed"}`);
3959
- messages = lib.pullMessages();
3960
- console.log(` Resampled decode found ${messages.length} message(s)`);
3961
- }
3962
- console.log(`
3963
- \u{1F4E8} Step 5: Checking decode results...`);
3964
- console.log(` Total messages decoded: ${messages.length}`);
3965
- if (messages.length > 0) {
3966
- messages.forEach((msg, index) => {
3967
- console.log(` Message ${index + 1}:`);
3968
- console.log(` Text: "${msg.text}"`);
3969
- console.log(` SNR: ${msg.snr} dB`);
3970
- console.log(` Time offset: ${msg.deltaTime.toFixed(2)} seconds`);
3971
- console.log(` Frequency offset: ${msg.deltaFrequency} Hz`);
3972
- });
3973
- const decodedMessage = messages[0].text;
3974
- const isMatch = decodedMessage.trim() === originalMessage.trim();
3975
- console.log(`
3976
- \u{1F3AF} Message verification:`);
3977
- console.log(` Original message: "${originalMessage}"`);
3978
- console.log(` Decoded message: "${decodedMessage}"`);
3979
- console.log(` Perfect match: ${isMatch ? "\u2705" : "\u274C"}`);
3980
- if (isMatch) {
3981
- console.log(`
3982
- \u{1F389} Complete encode-decode cycle test successful!`);
3983
- }
3984
- }
3985
- import_node_assert.default.ok(decodeResult.success, "Decode process should succeed");
3986
- console.log(`
3987
- \u2705 Encode-decode cycle test completed successfully`);
3988
- });
3989
- });
3990
- });
3991
- /**
3992
- * WSJTX Digital Radio Protocol Library for Node.js
3993
- *
3994
- * This library provides encoding and decoding capabilities for various
3995
- * digital amateur radio protocols including FT8, FT4, WSPR, and others.
3996
- *
3997
- * The library is a Node.js C++ extension that wraps the wsjtx_lib C library,
3998
- * providing high-performance digital signal processing capabilities with
3999
- * multi-platform support (Windows, macOS, Linux).
4000
- *
4001
- * @version 1.0.0
4002
- * @author WSJTX Development Team
4003
- * @license GPL-3.0
4004
- */