edfcore 0.6.95 → 0.6.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bytes/latin1.d.ts.map +1 -1
- package/dist/bytes/latin1.js +24 -0
- package/dist/bytes/latin1.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/time/window.d.ts.map +1 -1
- package/dist/time/window.js +20 -0
- package/dist/time/window.js.map +1 -1
- package/docs/CHANGELOG.md +31 -0
- package/package.json +1 -1
- package/src/bytes/latin1.ts +27 -0
- package/src/constants.ts +1 -1
- package/src/time/window.ts +24 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"latin1.d.ts","sourceRoot":"","sources":["../../src/bytes/latin1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"latin1.d.ts","sourceRoot":"","sources":["../../src/bytes/latin1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAgCH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAwB5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAK/D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjD"}
|
package/dist/bytes/latin1.js
CHANGED
|
@@ -26,12 +26,36 @@ function fromCharCodes(bytes) {
|
|
|
26
26
|
// `Function.prototype.apply` signature only admits `number[]`, hence the cast.
|
|
27
27
|
return String.fromCharCode.apply(null, bytes);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The one-byte-per-element tags, written out rather than shared with `io/source.ts`'s `isByteArray`.
|
|
31
|
+
*
|
|
32
|
+
* This module is Layer 0 and imports nothing, which is the property that lets the header decoder be
|
|
33
|
+
* the one thing in the package with no dependencies. `a-header-that-was-never-bytes.test.ts`
|
|
34
|
+
* asserts the two admit the same set, which is the drift `io/bytes.ts` records being bitten by in
|
|
35
|
+
* 0.2.23 when one of its two copies was rewritten and the other was missed.
|
|
36
|
+
*/
|
|
37
|
+
const BYTE_ARRAY_TAGS = new Set(['[object Uint8Array]', '[object Uint8ClampedArray]']);
|
|
29
38
|
/**
|
|
30
39
|
* Decode header bytes as ISO-8859-1: byte `b` becomes code point U+00`b`, always.
|
|
31
40
|
*
|
|
32
41
|
* Never `TextDecoder` — see the module comment.
|
|
33
42
|
*/
|
|
34
43
|
export function decodeHeaderLatin1(bytes) {
|
|
44
|
+
/*
|
|
45
|
+
* The two wrong views both produced text rather than an error, which is the worst pair of
|
|
46
|
+
* outcomes a decoder can have. An `ArrayBuffer` has no `length`, so `undefined <= 4096` is false,
|
|
47
|
+
* the chunk loop never ran, and the whole header decoded to `''`. An `Int8Array` has one byte per
|
|
48
|
+
* element, so it passed every length check and then decoded every byte above 0x7f to a different
|
|
49
|
+
* character — 0xb5, the bare micro sign real equipment writes, came out as U+FFB5. `byteSource`
|
|
50
|
+
* refuses exactly this pair at construction and says why; this is the same refusal one layer
|
|
51
|
+
* down, where the bytes are actually read (fixed in 0.6.96).
|
|
52
|
+
*/
|
|
53
|
+
if (!ArrayBuffer.isView(bytes) || !BYTE_ARRAY_TAGS.has(Object.prototype.toString.call(bytes))) {
|
|
54
|
+
throw new RangeError('decodeHeaderLatin1() needs a Uint8Array. An ArrayBuffer has no length, so it decoded to ' +
|
|
55
|
+
'the empty string; an Int8Array has one byte per element, so it decoded every byte above ' +
|
|
56
|
+
'0x7f to a different character. Next: pass `new Uint8Array(buffer)` for an ArrayBuffer, ' +
|
|
57
|
+
'and `new Uint8Array(view.buffer, view.byteOffset, view.byteLength)` for any other view.');
|
|
58
|
+
}
|
|
35
59
|
if (bytes.length <= CHUNK_BYTES)
|
|
36
60
|
return fromCharCodes(bytes);
|
|
37
61
|
const parts = [];
|
package/dist/bytes/latin1.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"latin1.js","sourceRoot":"","sources":["../../src/bytes/latin1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,2FAA2F;AAC3F,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,oFAAoF;AACpF,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACjC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,SAAS,aAAa,CAAC,KAAiB;IACtC,mFAAmF;IACnF,+EAA+E;IAC/E,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,KAA4B,CAAC,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAiB;IAClD,IAAI,KAAK,CAAC,MAAM,IAAI,WAAW;QAAE,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,WAAW,EAAE,CAAC;QAC/D,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAiB;IACpD,KAAK,MAAM,IAAI,IA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AAY,CAAC,IAAY;IACvC,OAAO,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,QAAQ,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;IACtB,OAAO,GAAG,GAAG,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAAE,GAAG,EAAE,CAAC;IACpE,OAAO,KAAK,GAAG,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAAE,KAAK,EAAE,CAAC;IACpE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -109,5 +109,5 @@ export declare const SIGNAL_FIELD_BLOCK_OFFSETS: {
|
|
|
109
109
|
readonly reserved: 224;
|
|
110
110
|
};
|
|
111
111
|
/** Published package version. Kept in sync with package.json by a test. */
|
|
112
|
-
export declare const VERSION = "0.6.
|
|
112
|
+
export declare const VERSION = "0.6.97";
|
|
113
113
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../src/time/window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../src/time/window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,cAAc,EAEd,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AA+CrB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,cAAc,EACrB,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,GACtB,SAAS,WAAW,EAAE,CA8FxB;AA6ED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,cAAc,EAC3B,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,GACtB,cAAc,CA6EhB"}
|
package/dist/time/window.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { TICKS_PER_SECOND } from '../constants.js';
|
|
19
19
|
import { EdfChannelNotFoundError } from '../errors.js';
|
|
20
20
|
import { ceilDiv, floorDiv, secondsToTicks, ticksToSeconds } from '../tal/ticks.js';
|
|
21
|
+
import { describeValue } from '../text/describe.js';
|
|
21
22
|
const NO_RANGES = Object.freeze([]);
|
|
22
23
|
/** Exact: 10^7 is far below 2^53. */
|
|
23
24
|
const TICKS_PER_SECOND_FLOAT = Number(TICKS_PER_SECOND);
|
|
@@ -29,6 +30,24 @@ function clampToInt(value, low, high) {
|
|
|
29
30
|
return high;
|
|
30
31
|
return Number(value);
|
|
31
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* The chunk signal, before the header is asked anything about its index.
|
|
35
|
+
*
|
|
36
|
+
* `EdfSignal` and `EdfChunkSignal` are the two per-signal shapes in this package, and they name the
|
|
37
|
+
* index differently: `index` on the header's, `signalIndex` on the chunk's. Passing the header's —
|
|
38
|
+
* the one a reader already holds, from `getSignal` or `header.signals[i]` — sent `undefined` into
|
|
39
|
+
* `signalAt` and earned "signalIndex undefined is not one of the 7 signals in this header … Next:
|
|
40
|
+
* pass the header the chunk was read with". The header was the argument that was right, and the
|
|
41
|
+
* advice named it (fixed in 0.6.97).
|
|
42
|
+
*/
|
|
43
|
+
function assertChunkSignal(chunkSignal) {
|
|
44
|
+
if (typeof chunkSignal?.signalIndex === 'number')
|
|
45
|
+
return;
|
|
46
|
+
const headerSignal = typeof chunkSignal?.index === 'number';
|
|
47
|
+
throw new RangeError(`trimToWindow(): the second argument is ${headerSignal
|
|
48
|
+
? 'a header signal, which carries no samples to trim'
|
|
49
|
+
: `${describeValue(chunkSignal)} with no signalIndex on it`}. Next: pass one element of chunk.signals — the array readWindow() and readRecords() fill.`);
|
|
50
|
+
}
|
|
32
51
|
function signalAt(header, signalIndex) {
|
|
33
52
|
const signal = header.signals[signalIndex];
|
|
34
53
|
if (signal !== undefined)
|
|
@@ -222,6 +241,7 @@ function trimmed(chunkSignal, signal, firstIndex, sampleCount, start) {
|
|
|
222
241
|
* that exist; one that misses it entirely yields a zero-length result rather than an error.
|
|
223
242
|
*/
|
|
224
243
|
export function trimToWindow(header, chunkSignal, startSeconds, durationSeconds) {
|
|
244
|
+
assertChunkSignal(chunkSignal);
|
|
225
245
|
const signal = signalAt(header, chunkSignal.signalIndex);
|
|
226
246
|
const samplesPerRecord = signal.samplesPerRecord;
|
|
227
247
|
const durationTicks = header.recordDurationTicks;
|
package/dist/time/window.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.js","sourceRoot":"","sources":["../../src/time/window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"window.js","sourceRoot":"","sources":["../../src/time/window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,QAAQ,E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M,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,UAAU,GAAG,CAAC,CAAC;IAE5E,OAAO,OAAO,CACZ,WAAW,EACX,MAAM,EACN,UAAU,EACV,WAAW,EACX,eAAe,CAAC,eAAe,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,aAAa,EAAE,qBAAqB,CAAC,CAC3F,CAAC;AACJ,CAAC"}
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,37 @@ alone does not tell you whether you were affected.
|
|
|
6
6
|
edfcore is pre-1.0. Patch releases have carried behaviour changes where the old behaviour was a
|
|
7
7
|
defect; those are called out below.
|
|
8
8
|
|
|
9
|
+
## 0.6.97
|
|
10
|
+
|
|
11
|
+
- **Changed** what `trimToWindow` says when it is handed a header signal where a chunk signal
|
|
12
|
+
belongs — and it now names the argument that is wrong.
|
|
13
|
+
- The two per-signal shapes name the index differently: `EdfSignal.index` for a channel the header
|
|
14
|
+
declares, `EdfChunkSignal.signalIndex` for the samples a read returned. The header's is the one a
|
|
15
|
+
reader already holds, so passing it is the natural mistake — and it sent `undefined` into the
|
|
16
|
+
header lookup, which answered "signalIndex undefined is not one of the 7 signals in this header …
|
|
17
|
+
Next: pass the header the chunk was read with". The header was the argument that was right.
|
|
18
|
+
- It now says the second argument is a header signal, which carries no samples to trim, and points
|
|
19
|
+
at `chunk.signals` — the array `readWindow()` and `readRecords()` fill. An out-of-range
|
|
20
|
+
`signalIndex` on a real chunk signal still reports the header lookup it always did.
|
|
21
|
+
- `next-clause-names.test.ts` resolves every field a clause names against a live object, and `chunk`
|
|
22
|
+
was the one root nothing had ever named. Its own note said a clause that started to would need a
|
|
23
|
+
fixture rather than a pass; this is that fixture.
|
|
24
|
+
|
|
25
|
+
## 0.6.96
|
|
26
|
+
|
|
27
|
+
- **Fixed** `decodeHeaderLatin1` decoding two wrong arguments into text instead of refusing them.
|
|
28
|
+
- An `ArrayBuffer` — what `await blob.arrayBuffer()` and `await response.arrayBuffer()` hand you —
|
|
29
|
+
has no `length`, so the chunk loop never ran and the whole header decoded to `''`. An `Int8Array`
|
|
30
|
+
has one byte per element, so it passed every length check and then decoded every byte above 0x7f
|
|
31
|
+
to a different character: 0xb5, the bare micro sign real equipment writes into a physical
|
|
32
|
+
dimension, came out as U+FFB5.
|
|
33
|
+
- `byteSource` refuses that same pair at construction and says why — an Int8Array "would pass every
|
|
34
|
+
length check and then decode to fabricated sample values". This is that refusal one layer down,
|
|
35
|
+
where the bytes are read.
|
|
36
|
+
- The tag test is written out rather than imported, because this module is Layer 0 and imports
|
|
37
|
+
nothing; a test asserts it admits exactly what `isByteArray` does, so the two copies cannot drift
|
|
38
|
+
the way `io/bytes.ts`'s did in 0.2.23.
|
|
39
|
+
|
|
9
40
|
## 0.6.95
|
|
10
41
|
|
|
11
42
|
- **Fixed** `formatDiagnostics` and `formatAnnotations` returning `''` for an argument that is not a
|
package/package.json
CHANGED
package/src/bytes/latin1.ts
CHANGED
|
@@ -31,12 +31,39 @@ function fromCharCodes(bytes: Uint8Array): string {
|
|
|
31
31
|
return String.fromCharCode.apply(null, bytes as unknown as number[]);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* The one-byte-per-element tags, written out rather than shared with `io/source.ts`'s `isByteArray`.
|
|
36
|
+
*
|
|
37
|
+
* This module is Layer 0 and imports nothing, which is the property that lets the header decoder be
|
|
38
|
+
* the one thing in the package with no dependencies. `a-header-that-was-never-bytes.test.ts`
|
|
39
|
+
* asserts the two admit the same set, which is the drift `io/bytes.ts` records being bitten by in
|
|
40
|
+
* 0.2.23 when one of its two copies was rewritten and the other was missed.
|
|
41
|
+
*/
|
|
42
|
+
const BYTE_ARRAY_TAGS = new Set(['[object Uint8Array]', '[object Uint8ClampedArray]']);
|
|
43
|
+
|
|
34
44
|
/**
|
|
35
45
|
* Decode header bytes as ISO-8859-1: byte `b` becomes code point U+00`b`, always.
|
|
36
46
|
*
|
|
37
47
|
* Never `TextDecoder` — see the module comment.
|
|
38
48
|
*/
|
|
39
49
|
export function decodeHeaderLatin1(bytes: Uint8Array): string {
|
|
50
|
+
/*
|
|
51
|
+
* The two wrong views both produced text rather than an error, which is the worst pair of
|
|
52
|
+
* outcomes a decoder can have. An `ArrayBuffer` has no `length`, so `undefined <= 4096` is false,
|
|
53
|
+
* the chunk loop never ran, and the whole header decoded to `''`. An `Int8Array` has one byte per
|
|
54
|
+
* element, so it passed every length check and then decoded every byte above 0x7f to a different
|
|
55
|
+
* character — 0xb5, the bare micro sign real equipment writes, came out as U+FFB5. `byteSource`
|
|
56
|
+
* refuses exactly this pair at construction and says why; this is the same refusal one layer
|
|
57
|
+
* down, where the bytes are actually read (fixed in 0.6.96).
|
|
58
|
+
*/
|
|
59
|
+
if (!ArrayBuffer.isView(bytes) || !BYTE_ARRAY_TAGS.has(Object.prototype.toString.call(bytes))) {
|
|
60
|
+
throw new RangeError(
|
|
61
|
+
'decodeHeaderLatin1() needs a Uint8Array. An ArrayBuffer has no length, so it decoded to ' +
|
|
62
|
+
'the empty string; an Int8Array has one byte per element, so it decoded every byte above ' +
|
|
63
|
+
'0x7f to a different character. Next: pass `new Uint8Array(buffer)` for an ArrayBuffer, ' +
|
|
64
|
+
'and `new Uint8Array(view.buffer, view.byteOffset, view.byteLength)` for any other view.',
|
|
65
|
+
);
|
|
66
|
+
}
|
|
40
67
|
if (bytes.length <= CHUNK_BYTES) return fromCharCodes(bytes);
|
|
41
68
|
const parts: string[] = [];
|
|
42
69
|
for (let start = 0; start < bytes.length; start += CHUNK_BYTES) {
|
package/src/constants.ts
CHANGED
package/src/time/window.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import { TICKS_PER_SECOND } from '../constants.js';
|
|
20
20
|
import { EdfChannelNotFoundError } from '../errors.js';
|
|
21
21
|
import { ceilDiv, floorDiv, secondsToTicks, ticksToSeconds } from '../tal/ticks.js';
|
|
22
|
+
import { describeValue } from '../text/describe.js';
|
|
22
23
|
import type {
|
|
23
24
|
EdfChunkSignal,
|
|
24
25
|
EdfHeader,
|
|
@@ -40,6 +41,28 @@ function clampToInt(value: bigint, low: number, high: number): number {
|
|
|
40
41
|
return Number(value);
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
/**
|
|
45
|
+
* The chunk signal, before the header is asked anything about its index.
|
|
46
|
+
*
|
|
47
|
+
* `EdfSignal` and `EdfChunkSignal` are the two per-signal shapes in this package, and they name the
|
|
48
|
+
* index differently: `index` on the header's, `signalIndex` on the chunk's. Passing the header's —
|
|
49
|
+
* the one a reader already holds, from `getSignal` or `header.signals[i]` — sent `undefined` into
|
|
50
|
+
* `signalAt` and earned "signalIndex undefined is not one of the 7 signals in this header … Next:
|
|
51
|
+
* pass the header the chunk was read with". The header was the argument that was right, and the
|
|
52
|
+
* advice named it (fixed in 0.6.97).
|
|
53
|
+
*/
|
|
54
|
+
function assertChunkSignal(chunkSignal: EdfChunkSignal): void {
|
|
55
|
+
if (typeof chunkSignal?.signalIndex === 'number') return;
|
|
56
|
+
const headerSignal = typeof (chunkSignal as unknown as EdfSignal | undefined)?.index === 'number';
|
|
57
|
+
throw new RangeError(
|
|
58
|
+
`trimToWindow(): the second argument is ${
|
|
59
|
+
headerSignal
|
|
60
|
+
? 'a header signal, which carries no samples to trim'
|
|
61
|
+
: `${describeValue(chunkSignal)} with no signalIndex on it`
|
|
62
|
+
}. Next: pass one element of chunk.signals — the array readWindow() and readRecords() fill.`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
43
66
|
function signalAt(header: EdfHeader, signalIndex: number): EdfSignal {
|
|
44
67
|
const signal = header.signals[signalIndex];
|
|
45
68
|
if (signal !== undefined) return signal;
|
|
@@ -271,6 +294,7 @@ export function trimToWindow(
|
|
|
271
294
|
startSeconds: number,
|
|
272
295
|
durationSeconds: number,
|
|
273
296
|
): EdfChunkSignal {
|
|
297
|
+
assertChunkSignal(chunkSignal);
|
|
274
298
|
const signal = signalAt(header, chunkSignal.signalIndex);
|
|
275
299
|
const samplesPerRecord = signal.samplesPerRecord;
|
|
276
300
|
const durationTicks = header.recordDurationTicks;
|