@ac-kit/media-piano-audio 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/LICENSE +28 -0
- package/README.md +246 -2
- package/dist/acoustics/_assert-piano-pitch.d.ts +6 -0
- package/dist/acoustics/_assert-piano-pitch.d.ts.map +1 -0
- package/dist/acoustics/_assert-piano-pitch.js +12 -0
- package/dist/acoustics/_assert-piano-pitch.js.map +1 -0
- package/dist/acoustics/piano-partials.d.ts +27 -0
- package/dist/acoustics/piano-partials.d.ts.map +1 -0
- package/dist/acoustics/piano-partials.js +60 -0
- package/dist/acoustics/piano-partials.js.map +1 -0
- package/dist/calibrate/estimate-input-latency.d.ts +41 -0
- package/dist/calibrate/estimate-input-latency.d.ts.map +1 -0
- package/dist/calibrate/estimate-input-latency.js +58 -0
- package/dist/calibrate/estimate-input-latency.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/synthesize/synthesize-piano.d.ts +97 -0
- package/dist/synthesize/synthesize-piano.d.ts.map +1 -0
- package/dist/synthesize/synthesize-piano.js +132 -0
- package/dist/synthesize/synthesize-piano.js.map +1 -0
- package/dist/synthesize/synthesize-tick.d.ts +39 -0
- package/dist/synthesize/synthesize-tick.d.ts.map +1 -0
- package/dist/synthesize/synthesize-tick.js +64 -0
- package/dist/synthesize/synthesize-tick.js.map +1 -0
- package/dist/verify/_onset-detector.d.ts +58 -0
- package/dist/verify/_onset-detector.d.ts.map +1 -0
- package/dist/verify/_onset-detector.js +206 -0
- package/dist/verify/_onset-detector.js.map +1 -0
- package/dist/verify/_templates.d.ts +37 -0
- package/dist/verify/_templates.d.ts.map +1 -0
- package/dist/verify/_templates.js +113 -0
- package/dist/verify/_templates.js.map +1 -0
- package/dist/verify/piano-chord-verifier.d.ts +204 -0
- package/dist/verify/piano-chord-verifier.d.ts.map +1 -0
- package/dist/verify/piano-chord-verifier.js +938 -0
- package/dist/verify/piano-chord-verifier.js.map +1 -0
- package/dist/verify/tuning.d.ts +126 -0
- package/dist/verify/tuning.d.ts.map +1 -0
- package/dist/verify/tuning.js +133 -0
- package/dist/verify/tuning.js.map +1 -0
- package/dist/verify/types.d.ts +74 -0
- package/dist/verify/types.d.ts.map +1 -0
- package/dist/verify/types.js +2 -0
- package/dist/verify/types.js.map +1 -0
- package/package.json +71 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** One struck key of {@link synthesizePiano}. */
|
|
2
|
+
export interface PianoSynthesisNote {
|
|
3
|
+
/** MIDI pitch, 21–108; fractional values are allowed. */
|
|
4
|
+
readonly pitch: number;
|
|
5
|
+
/**
|
|
6
|
+
* When the key goes down, seconds from the start of the signal. A note struck
|
|
7
|
+
* before the start (a negative time) sounds from its state at the start.
|
|
8
|
+
*/
|
|
9
|
+
readonly time: number;
|
|
10
|
+
/**
|
|
11
|
+
* When the key comes up, seconds from the start, not before `time`; the note
|
|
12
|
+
* then dies away in about 50 ms. Default: never released.
|
|
13
|
+
*/
|
|
14
|
+
readonly release?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Amplitude of the fundamental, finite and non-negative. Default 0.2, a
|
|
17
|
+
* medium-loud note.
|
|
18
|
+
*/
|
|
19
|
+
readonly level?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Options of {@link synthesizePiano}. */
|
|
22
|
+
export interface PianoSynthesisOptions {
|
|
23
|
+
/** Samples per second, finite and positive. */
|
|
24
|
+
readonly sampleRate: number;
|
|
25
|
+
/** Length of the signal, ms, finite and non-negative. */
|
|
26
|
+
readonly durationMs: number;
|
|
27
|
+
/** Frequency of A4, Hz, finite and positive. Default 440. */
|
|
28
|
+
readonly referenceHz?: number;
|
|
29
|
+
/**
|
|
30
|
+
* RMS amplitude of uniform white noise added to the signal, finite and
|
|
31
|
+
* non-negative. Default 0.
|
|
32
|
+
*/
|
|
33
|
+
readonly noise?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Seeds the noise (`@ac-kit/math-random`'s `mulberry32`), a 32-bit unsigned
|
|
36
|
+
* integer; other numbers are converted as by `>>> 0`. Default 1.
|
|
37
|
+
*/
|
|
38
|
+
readonly seed?: number;
|
|
39
|
+
}
|
|
40
|
+
/** Options of {@link chordNotes}. */
|
|
41
|
+
export interface ChordNotesOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Seconds between one key going down and the next, finite and non-negative.
|
|
44
|
+
* Default 0, all at once.
|
|
45
|
+
*/
|
|
46
|
+
readonly spread?: number;
|
|
47
|
+
/**
|
|
48
|
+
* The {@link PianoSynthesisNote.level} of every note. Default: the note's own
|
|
49
|
+
* default.
|
|
50
|
+
*/
|
|
51
|
+
readonly level?: number;
|
|
52
|
+
/** `"up"` strikes the lowest key first, `"down"` the highest. Default `"up"`. */
|
|
53
|
+
readonly direction?: "up" | "down";
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A piano-like signal: each note is the stretched partials of
|
|
57
|
+
* {@link pianoPartialPitches} (up to 20, those within 500 Hz of the Nyquist
|
|
58
|
+
* frequency left out), partial `h` of amplitude `level / h`, under a 3 ms
|
|
59
|
+
* attack and an exponential decay that is faster towards the treble and the
|
|
60
|
+
* upper partials. A released note dies away with a 15 ms time constant. The
|
|
61
|
+
* same notes and options always give the same samples.
|
|
62
|
+
*
|
|
63
|
+
* A synthetic model for tests, demonstrations and loopback tones, not a
|
|
64
|
+
* realistic piano: for rendered piano sound, use a SoundFont.
|
|
65
|
+
*
|
|
66
|
+
* Time O(length × partials × notes) in the worst case (a partial stops once it
|
|
67
|
+
* has decayed below 10⁻⁶), memory O(length) for the result and as much again
|
|
68
|
+
* for the binary64 sum it is rounded from.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* const signal = synthesizePiano(chordNotes([60, 64, 67], 0.5), {
|
|
72
|
+
* sampleRate: 48_000,
|
|
73
|
+
* durationMs: 1500,
|
|
74
|
+
* noise: 1e-4,
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* @returns `Math.round(durationMs · sampleRate / 1000)` samples.
|
|
78
|
+
* @throws {RangeError} On an option or a note field outside its documented
|
|
79
|
+
* range, including a pitch outside 21–108.
|
|
80
|
+
*/
|
|
81
|
+
export declare function synthesizePiano(notes: Iterable<PianoSynthesisNote>, options: PianoSynthesisOptions): Float32Array<ArrayBuffer>;
|
|
82
|
+
/**
|
|
83
|
+
* The notes of a chord struck at `time` (seconds), for {@link synthesizePiano}:
|
|
84
|
+
* with a `spread`, each key goes down that many seconds after the one before
|
|
85
|
+
* it, from the lowest (`direction: "up"`) or the highest (`"down"`). Time O(n
|
|
86
|
+
* log n), memory O(n).
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* chordNotes([67, 60, 64], 1, { spread: 0.01 });
|
|
90
|
+
* // [{ pitch: 60, time: 1 }, { pitch: 64, time: 1.01 }, { pitch: 67, time: 1.02 }]
|
|
91
|
+
*
|
|
92
|
+
* @throws {RangeError} When a pitch is outside 21–108, `time` or the last
|
|
93
|
+
* note's time is not finite, or `spread` or `level` is not finite and
|
|
94
|
+
* non-negative: it never returns a note {@link synthesizePiano} rejects.
|
|
95
|
+
*/
|
|
96
|
+
export declare function chordNotes(pitches: Iterable<number>, time: number, options?: ChordNotesOptions): PianoSynthesisNote[];
|
|
97
|
+
//# sourceMappingURL=synthesize-piano.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesize-piano.d.ts","sourceRoot":"","sources":["../../src/synthesize/synthesize-piano.ts"],"names":[],"mappings":"AAKA,iDAAiD;AACjD,MAAM,WAAW,kBAAkB;IAClC,yDAAyD;IACzD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACrC,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CACnC;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,QAAQ,CAAC,kBAAkB,CAAC,EACnC,OAAO,EAAE,qBAAqB,GAC5B,YAAY,CAAC,WAAW,CAAC,CA0E3B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACzB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAAsB,GAC7B,kBAAkB,EAAE,CA2BtB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { mulberry32 } from "@ac-kit/math-random";
|
|
2
|
+
import { assertPianoPitch } from "../acoustics/_assert-piano-pitch.js";
|
|
3
|
+
import { pianoPartialPitches } from "../acoustics/piano-partials.js";
|
|
4
|
+
const DEFAULT_NOTE_LEVEL_ = 0.2;
|
|
5
|
+
// The partial count, attack, decay curve, release and Nyquist margin are the
|
|
6
|
+
// keylight microphone spike's synthetic piano, set by hand to give the verifier
|
|
7
|
+
// a signal with a piano's stretched partials and treble-fast decay.
|
|
8
|
+
const MAX_PARTIALS_ = 20;
|
|
9
|
+
const ATTACK_SECONDS_ = 0.003;
|
|
10
|
+
const RELEASE_SECONDS_ = 0.015;
|
|
11
|
+
const NYQUIST_MARGIN_HZ_ = 500;
|
|
12
|
+
// A partial whose envelope has fallen this low is stopped there.
|
|
13
|
+
const SILENT_ENVELOPE_ = 1e-6;
|
|
14
|
+
function assertFinite_(name, value, minimum) {
|
|
15
|
+
if (!Number.isFinite(value) || value < minimum) {
|
|
16
|
+
throw new RangeError(`${name} must be finite and at least ${minimum}, got ${value}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A piano-like signal: each note is the stretched partials of
|
|
21
|
+
* {@link pianoPartialPitches} (up to 20, those within 500 Hz of the Nyquist
|
|
22
|
+
* frequency left out), partial `h` of amplitude `level / h`, under a 3 ms
|
|
23
|
+
* attack and an exponential decay that is faster towards the treble and the
|
|
24
|
+
* upper partials. A released note dies away with a 15 ms time constant. The
|
|
25
|
+
* same notes and options always give the same samples.
|
|
26
|
+
*
|
|
27
|
+
* A synthetic model for tests, demonstrations and loopback tones, not a
|
|
28
|
+
* realistic piano: for rendered piano sound, use a SoundFont.
|
|
29
|
+
*
|
|
30
|
+
* Time O(length × partials × notes) in the worst case (a partial stops once it
|
|
31
|
+
* has decayed below 10⁻⁶), memory O(length) for the result and as much again
|
|
32
|
+
* for the binary64 sum it is rounded from.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const signal = synthesizePiano(chordNotes([60, 64, 67], 0.5), {
|
|
36
|
+
* sampleRate: 48_000,
|
|
37
|
+
* durationMs: 1500,
|
|
38
|
+
* noise: 1e-4,
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* @returns `Math.round(durationMs · sampleRate / 1000)` samples.
|
|
42
|
+
* @throws {RangeError} On an option or a note field outside its documented
|
|
43
|
+
* range, including a pitch outside 21–108.
|
|
44
|
+
*/
|
|
45
|
+
export function synthesizePiano(notes, options) {
|
|
46
|
+
const { sampleRate, durationMs, referenceHz = 440, noise = 0 } = options;
|
|
47
|
+
const seed = options.seed ?? 1;
|
|
48
|
+
assertFinite_("sampleRate", sampleRate, Number.MIN_VALUE);
|
|
49
|
+
assertFinite_("durationMs", durationMs, 0);
|
|
50
|
+
assertFinite_("referenceHz", referenceHz, Number.MIN_VALUE);
|
|
51
|
+
assertFinite_("noise", noise, 0);
|
|
52
|
+
const length = Math.round((durationMs * sampleRate) / 1000);
|
|
53
|
+
const signal = new Float64Array(length);
|
|
54
|
+
const partials = new Float64Array(MAX_PARTIALS_);
|
|
55
|
+
for (const note of notes) {
|
|
56
|
+
const level = note.level ?? DEFAULT_NOTE_LEVEL_;
|
|
57
|
+
assertFinite_("note time", note.time, -Infinity);
|
|
58
|
+
assertFinite_("note level", level, 0);
|
|
59
|
+
if (note.release !== undefined) {
|
|
60
|
+
assertFinite_("note release", note.release, note.time);
|
|
61
|
+
}
|
|
62
|
+
pianoPartialPitches(note.pitch, MAX_PARTIALS_, undefined, partials);
|
|
63
|
+
const start = Math.round(note.time * sampleRate);
|
|
64
|
+
const release = note.release === undefined
|
|
65
|
+
? Infinity
|
|
66
|
+
: Math.round(note.release * sampleRate);
|
|
67
|
+
const baseDecay = 0.4 + 2.5 * 2 ** (-(note.pitch - 21) / 24);
|
|
68
|
+
for (let partial = 1; partial <= MAX_PARTIALS_; partial++) {
|
|
69
|
+
const frequency = referenceHz * 2 ** ((partials[partial - 1] - 69) / 12);
|
|
70
|
+
if (frequency >= sampleRate / 2 - NYQUIST_MARGIN_HZ_) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
const amplitude = level / partial;
|
|
74
|
+
const decay = baseDecay / (1 + 0.15 * (partial - 1));
|
|
75
|
+
const omega = (2 * Math.PI * frequency) / sampleRate;
|
|
76
|
+
const phase = partial * 0.7;
|
|
77
|
+
for (let frame = Math.max(0, start); frame < length; frame++) {
|
|
78
|
+
const age = (frame - start) / sampleRate;
|
|
79
|
+
let envelope = Math.min(1, age / ATTACK_SECONDS_) * Math.exp(-age / decay);
|
|
80
|
+
if (frame >= release) {
|
|
81
|
+
envelope *= Math.exp(-(frame - release) / sampleRate / RELEASE_SECONDS_);
|
|
82
|
+
}
|
|
83
|
+
if (envelope < SILENT_ENVELOPE_ && age > 0.01) {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
signal[frame] +=
|
|
87
|
+
amplitude * envelope * Math.sin(omega * (frame - start) + phase);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (noise > 0) {
|
|
92
|
+
const random = mulberry32(seed);
|
|
93
|
+
// Uniform noise of the RMS asked for: its variance is a third of its range's.
|
|
94
|
+
const scale = noise * Math.sqrt(3);
|
|
95
|
+
for (let frame = 0; frame < length; frame++) {
|
|
96
|
+
signal[frame] += (random() * 2 - 1) * scale;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return Float32Array.from(signal);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The notes of a chord struck at `time` (seconds), for {@link synthesizePiano}:
|
|
103
|
+
* with a `spread`, each key goes down that many seconds after the one before
|
|
104
|
+
* it, from the lowest (`direction: "up"`) or the highest (`"down"`). Time O(n
|
|
105
|
+
* log n), memory O(n).
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* chordNotes([67, 60, 64], 1, { spread: 0.01 });
|
|
109
|
+
* // [{ pitch: 60, time: 1 }, { pitch: 64, time: 1.01 }, { pitch: 67, time: 1.02 }]
|
|
110
|
+
*
|
|
111
|
+
* @throws {RangeError} When a pitch is outside 21–108, `time` or the last
|
|
112
|
+
* note's time is not finite, or `spread` or `level` is not finite and
|
|
113
|
+
* non-negative: it never returns a note {@link synthesizePiano} rejects.
|
|
114
|
+
*/
|
|
115
|
+
export function chordNotes(pitches, time, options = {}) {
|
|
116
|
+
const { spread = 0, level, direction = "up" } = options;
|
|
117
|
+
assertFinite_("time", time, -Infinity);
|
|
118
|
+
assertFinite_("spread", spread, 0);
|
|
119
|
+
if (level !== undefined) {
|
|
120
|
+
assertFinite_("level", level, 0);
|
|
121
|
+
}
|
|
122
|
+
const ordered = Array.from(pitches);
|
|
123
|
+
for (const pitch of ordered) {
|
|
124
|
+
assertPianoPitch(pitch);
|
|
125
|
+
}
|
|
126
|
+
ordered.sort((left, right) => direction === "down" ? right - left : left - right);
|
|
127
|
+
assertFinite_("last note time", time + (ordered.length - 1) * spread, -Infinity);
|
|
128
|
+
return ordered.map((pitch, index) => level === undefined
|
|
129
|
+
? { pitch, time: time + index * spread }
|
|
130
|
+
: { pitch, time: time + index * spread, level });
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=synthesize-piano.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesize-piano.js","sourceRoot":"","sources":["../../src/synthesize/synthesize-piano.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AA2DrE,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,6EAA6E;AAC7E,gFAAgF;AAChF,oEAAoE;AACpE,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,iEAAiE;AACjE,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,SAAS,aAAa,CAAC,IAAY,EAAE,KAAa,EAAE,OAAe;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AAK,EAAE,CAChD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Options of {@link synthesizeTick}. */
|
|
2
|
+
export interface TickSynthesisOptions {
|
|
3
|
+
/** Samples per second, finite and positive. */
|
|
4
|
+
readonly sampleRate: number;
|
|
5
|
+
/** The band the burst's energy is in, Hz: `0 ≤ low ≤ high ≤ sampleRate / 2`. */
|
|
6
|
+
readonly band: readonly [low: number, high: number];
|
|
7
|
+
/** Length of the burst, ms, finite and non-negative. */
|
|
8
|
+
readonly durationMs: number;
|
|
9
|
+
/** Peak amplitude, finite and non-negative. Default 0.5. */
|
|
10
|
+
readonly level?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Seeds the burst (`@ac-kit/math-random`'s `mulberry32`), a 32-bit unsigned
|
|
13
|
+
* integer; other numbers are converted as by `>>> 0`. Default 1.
|
|
14
|
+
*/
|
|
15
|
+
readonly seed?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A short burst of noise confined to a band, as a click to count by, such as a
|
|
19
|
+
* metronome tick kept out of the bands a verifier listens to: 80 sinusoids of
|
|
20
|
+
* random frequency within the band and random phase, summed under a midpoint
|
|
21
|
+
* Hann envelope (`@ac-kit/math-signal`'s `applyHannWindow` with `midpoint`) and
|
|
22
|
+
* scaled so its largest sample is `level`. The same options always give the
|
|
23
|
+
* same samples.
|
|
24
|
+
*
|
|
25
|
+
* Time O(length), memory O(length): the result and, while it is made, one
|
|
26
|
+
* binary64 buffer of the same length.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const tick = synthesizeTick({
|
|
30
|
+
* sampleRate: 48_000,
|
|
31
|
+
* band: [12_000, 16_000],
|
|
32
|
+
* durationMs: 15,
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* @returns `Math.round(durationMs · sampleRate / 1000)` samples.
|
|
36
|
+
* @throws {RangeError} On an option outside its documented range.
|
|
37
|
+
*/
|
|
38
|
+
export declare function synthesizeTick(options: TickSynthesisOptions): Float32Array<ArrayBuffer>;
|
|
39
|
+
//# sourceMappingURL=synthesize-tick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesize-tick.d.ts","sourceRoot":"","sources":["../../src/synthesize/synthesize-tick.ts"],"names":[],"mappings":"AAGA,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACpC,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,gFAAgF;IAChF,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACpD,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAC7B,OAAO,EAAE,oBAAoB,GAC3B,YAAY,CAAC,WAAW,CAAC,CAmD3B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { mulberry32 } from "@ac-kit/math-random";
|
|
2
|
+
import { applyHannWindow } from "@ac-kit/math-signal";
|
|
3
|
+
// Enough random-phase sinusoids for the burst to sound like noise rather than a
|
|
4
|
+
// chord: set by hand in keylight.
|
|
5
|
+
const COMPONENT_COUNT_ = 80;
|
|
6
|
+
/**
|
|
7
|
+
* A short burst of noise confined to a band, as a click to count by, such as a
|
|
8
|
+
* metronome tick kept out of the bands a verifier listens to: 80 sinusoids of
|
|
9
|
+
* random frequency within the band and random phase, summed under a midpoint
|
|
10
|
+
* Hann envelope (`@ac-kit/math-signal`'s `applyHannWindow` with `midpoint`) and
|
|
11
|
+
* scaled so its largest sample is `level`. The same options always give the
|
|
12
|
+
* same samples.
|
|
13
|
+
*
|
|
14
|
+
* Time O(length), memory O(length): the result and, while it is made, one
|
|
15
|
+
* binary64 buffer of the same length.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const tick = synthesizeTick({
|
|
19
|
+
* sampleRate: 48_000,
|
|
20
|
+
* band: [12_000, 16_000],
|
|
21
|
+
* durationMs: 15,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* @returns `Math.round(durationMs · sampleRate / 1000)` samples.
|
|
25
|
+
* @throws {RangeError} On an option outside its documented range.
|
|
26
|
+
*/
|
|
27
|
+
export function synthesizeTick(options) {
|
|
28
|
+
const { sampleRate, band, durationMs, level = 0.5 } = options;
|
|
29
|
+
const [low, high] = band;
|
|
30
|
+
if (!Number.isFinite(sampleRate) || !(sampleRate > 0)) {
|
|
31
|
+
throw new RangeError(`sampleRate must be finite and positive, got ${sampleRate}`);
|
|
32
|
+
}
|
|
33
|
+
if (!(low >= 0 && low <= high && high <= sampleRate / 2)) {
|
|
34
|
+
throw new RangeError(`band must satisfy 0 ≤ low ≤ high ≤ ${sampleRate / 2}, got [${low}, ${high}]`);
|
|
35
|
+
}
|
|
36
|
+
if (!Number.isFinite(durationMs) || durationMs < 0) {
|
|
37
|
+
throw new RangeError(`durationMs must be finite and non-negative, got ${durationMs}`);
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isFinite(level) || level < 0) {
|
|
40
|
+
throw new RangeError(`level must be finite and non-negative, got ${level}`);
|
|
41
|
+
}
|
|
42
|
+
const length = Math.round((durationMs * sampleRate) / 1000);
|
|
43
|
+
if (length === 0) {
|
|
44
|
+
return new Float32Array(0);
|
|
45
|
+
}
|
|
46
|
+
const random = mulberry32(options.seed ?? 1);
|
|
47
|
+
const burst = new Float64Array(length);
|
|
48
|
+
for (let component = 0; component < COMPONENT_COUNT_; component++) {
|
|
49
|
+
const frequency = low + random() * (high - low);
|
|
50
|
+
const phase = random() * 2 * Math.PI;
|
|
51
|
+
const omega = (2 * Math.PI * frequency) / sampleRate;
|
|
52
|
+
for (let frame = 0; frame < length; frame++) {
|
|
53
|
+
burst[frame] += Math.sin(omega * frame + phase);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
applyHannWindow(burst, { midpoint: true });
|
|
57
|
+
let peak = 0;
|
|
58
|
+
for (let frame = 0; frame < length; frame++) {
|
|
59
|
+
peak = Math.max(peak, Math.abs(burst[frame]));
|
|
60
|
+
}
|
|
61
|
+
const scale = peak > 0 ? level / peak : 0;
|
|
62
|
+
return Float32Array.from(burst, (value) => value * scale);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=synthesize-tick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesize-tick.js","sourceRoot":"","sources":["../../src/synthesize/synthesize-tick.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAmBtD,gFAAgF;AAChF,kCAAkC;AAClC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,cAAc,CAC7B,OAA6B;IAE7B,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAEzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,UAAU,CACnB,+CAA+C,UAAU,EAAE,CAC3D,CAAC;IACH,CAAC;IACD,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI,IAAI,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;QAC1D,MAAM,IA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K,CAAC,KAAK,CAAE,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC;QAClD,CAAC;IACF,CAAC;IAED,eAAe,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7C,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1C,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PianoVerifierTuning } from "./tuning.js";
|
|
2
|
+
/** Samples between two frames: the AudioWorklet render quantum. */
|
|
3
|
+
export declare const HOP = 128;
|
|
4
|
+
/** Frames of `HOP` samples nearest to `ms`, at least `minimum`. */
|
|
5
|
+
export declare function framesOf(ms: number, sampleRate: number, minimum: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Streaming onset detection, one frame per hop: log-compressed, noise-relative
|
|
8
|
+
* band magnitudes, SuperFlux over all bands and over the expected notes' bands,
|
|
9
|
+
* adaptive-threshold peak picking, then the rise, minimum-interval and
|
|
10
|
+
* replacement rules.
|
|
11
|
+
*/
|
|
12
|
+
export declare class OnsetDetector {
|
|
13
|
+
readonly frameSize: number;
|
|
14
|
+
/** Samples from the reported onset (frame centre) to its confirmation. */
|
|
15
|
+
readonly confirmationDelaySamples: number;
|
|
16
|
+
readonly bandCount: number;
|
|
17
|
+
/** Highest frequency of the onset bands, Hz, after the Nyquist clamp. */
|
|
18
|
+
readonly maxFrequency: number;
|
|
19
|
+
/** Band magnitudes of the latest frame, before compression. */
|
|
20
|
+
readonly bands: Float64Array;
|
|
21
|
+
private readonly sampleRate_;
|
|
22
|
+
private readonly tuning_;
|
|
23
|
+
private readonly fft_;
|
|
24
|
+
private readonly window_;
|
|
25
|
+
private readonly input_;
|
|
26
|
+
private readonly spectrum_;
|
|
27
|
+
private readonly magnitudes_;
|
|
28
|
+
private readonly map_;
|
|
29
|
+
private readonly history_;
|
|
30
|
+
private readonly picker_;
|
|
31
|
+
private readonly fluxLag_;
|
|
32
|
+
private readonly lookahead_;
|
|
33
|
+
private readonly positions_;
|
|
34
|
+
private readonly energies_;
|
|
35
|
+
private readonly novelties_;
|
|
36
|
+
private readonly fluxes_;
|
|
37
|
+
private readonly minInterOnset_;
|
|
38
|
+
private readonly merge_;
|
|
39
|
+
private expectedBands_;
|
|
40
|
+
private frame_;
|
|
41
|
+
private lastOnset_;
|
|
42
|
+
private lastNovelty_;
|
|
43
|
+
/** Whether the latest onset replaces its precursor rather than adding one. */
|
|
44
|
+
replaced: boolean;
|
|
45
|
+
constructor(sampleRate: number, tuning: PianoVerifierTuning);
|
|
46
|
+
/** Magnitude of a full-scale sine in one band: the unit of `bandNoise`. */
|
|
47
|
+
get fullScale(): number;
|
|
48
|
+
/** The bands of the first `expectedPartials` partials of `pitches`. */
|
|
49
|
+
expectedBands(pitches: readonly number[], referenceHz: number): Int32Array;
|
|
50
|
+
setExpectedBands(bands: Int32Array): void;
|
|
51
|
+
/**
|
|
52
|
+
* Analyses the frame ending at `position` and returns the sample position of
|
|
53
|
+
* a confirmed onset, or −1.
|
|
54
|
+
*/
|
|
55
|
+
analyse(ring: Float32Array, mask: number, position: number, bandNoise: Float64Array): number;
|
|
56
|
+
reset(): void;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=_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AU,CAA8B;IACzD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IACxD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA8B;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,cAAc,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,YAAY,CAAK;IAEzB,8EAA8E;IAC9E,QAAQ,UAAS;IAEjB,YAAY,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAsD1D;IAED,2EAA2E;IAC3E,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,uEAAuE;IACvE,aAAa,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAYzE;IAED,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAExC;IAED;;;OAGG;IACH,OAAO,CACN,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,YAAY,GACrB,MAAM,CA8ER;IAED,KAAK,IAAI,IAAI,CAUZ;CACD"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { createLogFrequencyMap, createRealFft, hannWindow, magnitudeSpectrumInto, NoveltyPeakPicker, spectralFluxInto, } from "@ac-kit/math-signal";
|
|
2
|
+
import { pitchFrequency } from "@ac-kit/model-music";
|
|
3
|
+
/** Samples between two frames: the AudioWorklet render quantum. */
|
|
4
|
+
export const HOP = 128;
|
|
5
|
+
// How many of the most recent frames stay out of the adaptive threshold's
|
|
6
|
+
// median, and how many frames before a peak it must dominate: 2 and 3 frames
|
|
7
|
+
// of the spike's 128-sample hop at 48 kHz.
|
|
8
|
+
const THRESHOLD_EXCLUDE_MS_ = 5.3;
|
|
9
|
+
const PEAK_LOOKBEHIND_MS_ = 8;
|
|
10
|
+
// Band history kept for the flux, energies and positions kept for the checks.
|
|
11
|
+
const HISTORY_ = 64;
|
|
12
|
+
/** Frames of `HOP` samples nearest to `ms`, at least `minimum`. */
|
|
13
|
+
export function framesOf(ms, sampleRate, minimum) {
|
|
14
|
+
return Math.max(minimum, Math.round((ms * sampleRate) / 1000 / HOP));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Streaming onset detection, one frame per hop: log-compressed, noise-relative
|
|
18
|
+
* band magnitudes, SuperFlux over all bands and over the expected notes' bands,
|
|
19
|
+
* adaptive-threshold peak picking, then the rise, minimum-interval and
|
|
20
|
+
* replacement rules.
|
|
21
|
+
*/
|
|
22
|
+
export class OnsetDetector {
|
|
23
|
+
frameSize;
|
|
24
|
+
/** Samples from the reported onset (frame centre) to its confirmation. */
|
|
25
|
+
confirmationDelaySamples;
|
|
26
|
+
bandCount;
|
|
27
|
+
/** Highest frequency of the onset bands, Hz, after the Nyquist clamp. */
|
|
28
|
+
maxFrequency;
|
|
29
|
+
/** Band magnitudes of the latest frame, before compression. */
|
|
30
|
+
bands;
|
|
31
|
+
sampleRate_;
|
|
32
|
+
tuning_;
|
|
33
|
+
fft_;
|
|
34
|
+
window_;
|
|
35
|
+
input_;
|
|
36
|
+
spectrum_;
|
|
37
|
+
magnitudes_;
|
|
38
|
+
map_;
|
|
39
|
+
history_;
|
|
40
|
+
picker_;
|
|
41
|
+
fluxLag_;
|
|
42
|
+
lookahead_;
|
|
43
|
+
positions_ = new Float64Array(HISTORY_);
|
|
44
|
+
energies_ = new Float64Array(HISTORY_);
|
|
45
|
+
novelties_ = new Float64Array(HISTORY_);
|
|
46
|
+
fluxes_ = new Float64Array(2);
|
|
47
|
+
minInterOnset_;
|
|
48
|
+
merge_;
|
|
49
|
+
expectedBands_ = new Int32Array(0);
|
|
50
|
+
frame_ = 0;
|
|
51
|
+
lastOnset_ = Number.NEGATIVE_INFINITY;
|
|
52
|
+
lastNovelty_ = 0;
|
|
53
|
+
/** Whether the latest onset replaces its precursor rather than adding one. */
|
|
54
|
+
replaced = false;
|
|
55
|
+
constructor(sampleRate, tuning) {
|
|
56
|
+
this.sampleRate_ = sampleRate;
|
|
57
|
+
this.tuning_ = tuning;
|
|
58
|
+
const size = 2 ** Math.round(Math.log2((tuning.onsetFrameMs * sampleRate) / 1000));
|
|
59
|
+
this.frameSize = Math.max(2, size);
|
|
60
|
+
this.fft_ = createRealFft(this.frameSize);
|
|
61
|
+
this.window_ = hannWindow(this.frameSize, { midpoint: true });
|
|
62
|
+
this.input_ = new Float64Array(this.frameSize);
|
|
63
|
+
this.spectrum_ = new Float64Array(this.frameSize + 2);
|
|
64
|
+
this.magnitudes_ = new Float64Array(this.frameSize / 2 + 1);
|
|
65
|
+
const nyquist = sampleRate / 2;
|
|
66
|
+
this.maxFrequency = Math.min(tuning.onsetMaxHz, nyquist);
|
|
67
|
+
this.map_ = createLogFrequencyMap({
|
|
68
|
+
sampleRate,
|
|
69
|
+
fftSize: this.frameSize,
|
|
70
|
+
minFrequency: tuning.onsetMinHz,
|
|
71
|
+
maxFrequency: this.maxFrequency,
|
|
72
|
+
bandsPerOctave: tuning.onsetBandsPerOctave,
|
|
73
|
+
pooling: "sum",
|
|
74
|
+
emptyBands: "merge",
|
|
75
|
+
});
|
|
76
|
+
this.bandCount = this.map_.bandCount;
|
|
77
|
+
this.bands = new Float64Array(this.bandCount);
|
|
78
|
+
this.fluxLag_ = framesOf(tuning.fluxLagMs, sampleRate, 1);
|
|
79
|
+
this.lookahead_ = framesOf(tuning.lookaheadMs, sampleRate, 0);
|
|
80
|
+
this.confirmationDelaySamples = this.frameSize / 2 + this.lookahead_ * HOP;
|
|
81
|
+
this.history_ = Array.from({ length: this.fluxLag_ + 1 }, () => new Float64Array(this.bandCount));
|
|
82
|
+
const thresholdFrames = framesOf(tuning.thresholdMs, sampleRate, 2);
|
|
83
|
+
this.picker_ = new NoveltyPeakPicker({
|
|
84
|
+
thresholdFrames,
|
|
85
|
+
multiplier: tuning.thresholdMultiplier,
|
|
86
|
+
delta: tuning.thresholdDelta,
|
|
87
|
+
auxiliaryDelta: tuning.expectedThresholdDelta,
|
|
88
|
+
lookahead: this.lookahead_,
|
|
89
|
+
lookbehind: Math.min(thresholdFrames, framesOf(PEAK_LOOKBEHIND_MS_, sampleRate, 1)),
|
|
90
|
+
excludeRecent: Math.min(thresholdFrames - 1, framesOf(THRESHOLD_EXCLUDE_MS_, sampleRate, 0)),
|
|
91
|
+
});
|
|
92
|
+
if (this.lookahead_ + this.fluxLag_ + 2 > HISTORY_) {
|
|
93
|
+
throw new RangeError("tuning.lookaheadMs and tuning.fluxLagMs span too many frames together");
|
|
94
|
+
}
|
|
95
|
+
this.minInterOnset_ = (tuning.minInterOnsetMs * sampleRate) / 1000;
|
|
96
|
+
this.merge_ = (tuning.mergeMs * sampleRate) / 1000;
|
|
97
|
+
}
|
|
98
|
+
/** Magnitude of a full-scale sine in one band: the unit of `bandNoise`. */
|
|
99
|
+
get fullScale() {
|
|
100
|
+
return this.frameSize / 4;
|
|
101
|
+
}
|
|
102
|
+
/** The bands of the first `expectedPartials` partials of `pitches`. */
|
|
103
|
+
expectedBands(pitches, referenceHz) {
|
|
104
|
+
const bands = new Set();
|
|
105
|
+
const { bandOfBin } = this.map_;
|
|
106
|
+
for (const pitch of pitches) {
|
|
107
|
+
const f0 = pitchFrequency(pitch, referenceHz);
|
|
108
|
+
for (let h = 1; h <= this.tuning_.expectedPartials; h++) {
|
|
109
|
+
const bin = Math.round((f0 * h * this.frameSize) / this.sampleRate_);
|
|
110
|
+
const band = bin < bandOfBin.length ? bandOfBin[bin] : -1;
|
|
111
|
+
if (band >= 0)
|
|
112
|
+
bands.add(band);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return Int32Array.from(bands);
|
|
116
|
+
}
|
|
117
|
+
setExpectedBands(bands) {
|
|
118
|
+
this.expectedBands_ = bands;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Analyses the frame ending at `position` and returns the sample position of
|
|
122
|
+
* a confirmed onset, or −1.
|
|
123
|
+
*/
|
|
124
|
+
analyse(ring, mask, position, bandNoise) {
|
|
125
|
+
const size = this.frameSize;
|
|
126
|
+
const input = this.input_;
|
|
127
|
+
const window = this.window_;
|
|
128
|
+
const start = position - size;
|
|
129
|
+
for (let i = 0; i < size; i++) {
|
|
130
|
+
input[i] = ring[(start + i) & mask] * window[i];
|
|
131
|
+
}
|
|
132
|
+
this.fft_.forwardInto(this.spectrum_, input);
|
|
133
|
+
magnitudeSpectrumInto(this.magnitudes_, this.spectrum_);
|
|
134
|
+
this.map_.applyInto(this.bands, this.magnitudes_);
|
|
135
|
+
const history = this.history_;
|
|
136
|
+
const current = history[this.frame_ % history.length];
|
|
137
|
+
const reference = history[(this.frame_ + 1) % history.length];
|
|
138
|
+
const factor = this.tuning_.onsetNoiseFactor;
|
|
139
|
+
let energy = 0;
|
|
140
|
+
for (let band = 0; band < this.bandCount; band++) {
|
|
141
|
+
const magnitude = this.bands[band];
|
|
142
|
+
const noise = bandNoise[band];
|
|
143
|
+
energy += magnitude;
|
|
144
|
+
current[band] = Math.log1p(Math.max(0, magnitude - factor * noise) / noise);
|
|
145
|
+
}
|
|
146
|
+
// Both fluxes reach the picker through a typed array: a double passed to
|
|
147
|
+
// or returned from a call V8 does not inline is boxed into a heap number.
|
|
148
|
+
const fluxes = this.fluxes_;
|
|
149
|
+
fluxes[0] = 0;
|
|
150
|
+
fluxes[1] = 0;
|
|
151
|
+
if (this.frame_ > this.fluxLag_) {
|
|
152
|
+
spectralFluxInto(fluxes, 0, current, reference, 1);
|
|
153
|
+
fluxes[0] = fluxes[0] / this.bandCount;
|
|
154
|
+
const expected = this.expectedBands_;
|
|
155
|
+
if (expected.length > 0) {
|
|
156
|
+
spectralFluxInto(fluxes, 1, current, reference, 1, expected);
|
|
157
|
+
fluxes[1] = fluxes[1] / expected.length;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const slot = this.frame_ & (HISTORY_ - 1);
|
|
161
|
+
this.positions_[slot] = position;
|
|
162
|
+
this.energies_[slot] = energy;
|
|
163
|
+
const candidate = this.picker_.pushFrom(fluxes, 0, 1);
|
|
164
|
+
this.novelties_[slot] = this.picker_.novelty;
|
|
165
|
+
this.frame_++;
|
|
166
|
+
if (candidate < 0)
|
|
167
|
+
return -1;
|
|
168
|
+
const mask_ = HISTORY_ - 1;
|
|
169
|
+
// A key press raises the level; a release click has flux but the level falls.
|
|
170
|
+
const before = candidate - this.fluxLag_ - 1;
|
|
171
|
+
if (before >= 0 &&
|
|
172
|
+
this.energies_[(candidate + this.lookahead_) & mask_] <
|
|
173
|
+
this.tuning_.riseRatio * this.energies_[before & mask_]) {
|
|
174
|
+
return -1;
|
|
175
|
+
}
|
|
176
|
+
// The frame ends at its position; the attack is about its middle.
|
|
177
|
+
const onset = this.positions_[candidate & mask_] - this.frameSize / 2;
|
|
178
|
+
const novelty = this.novelties_[candidate & mask_];
|
|
179
|
+
const gap = onset - this.lastOnset_;
|
|
180
|
+
this.replaced = false;
|
|
181
|
+
if (gap < this.minInterOnset_) {
|
|
182
|
+
// Too close: only a clearly stronger onset replaces its precursor.
|
|
183
|
+
if (gap <= this.merge_ ||
|
|
184
|
+
novelty < this.tuning_.replaceRatio * this.lastNovelty_) {
|
|
185
|
+
return -1;
|
|
186
|
+
}
|
|
187
|
+
this.replaced = true;
|
|
188
|
+
}
|
|
189
|
+
this.lastOnset_ = onset;
|
|
190
|
+
this.lastNovelty_ = novelty;
|
|
191
|
+
return onset;
|
|
192
|
+
}
|
|
193
|
+
reset() {
|
|
194
|
+
for (const bands of this.history_)
|
|
195
|
+
bands.fill(0);
|
|
196
|
+
this.picker_.reset();
|
|
197
|
+
this.positions_.fill(0);
|
|
198
|
+
this.energies_.fill(0);
|
|
199
|
+
this.novelties_.fill(0);
|
|
200
|
+
this.frame_ = 0;
|
|
201
|
+
this.lastOnset_ = Number.NEGATIVE_INFINITY;
|
|
202
|
+
this.lastNovelty_ = 0;
|
|
203
|
+
this.replaced = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=_onset-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_onset-detector.js","sourceRoot":"","sources":["../../src/verify/_onset-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,qBAAqB,EACrB,aAAa,EACb,UAAU,EACV,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GAGhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,mEAAmE;AACnE,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC;AAEvB,0EAA0E;AAC1E,6EAA6E;AAC7E,2CAA2C;AAC3C,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,8EAA8E;AAC9E,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,mEAAmE;AACnE,MAAM,UAAU,QAAQ,CACvB,EAAU,EACV,UAAkB,EAClB,OAAe;IAEf,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,UAAU,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IAChB,SAAS,CAAS;IAC3B,0EAA0E;IACjE,wBAAwB,CAAS;IACjC,SAAS,CAAS;IAC3B,yEAAyE;IAChE,YAAY,CAAS;IAC9B,+DAA+D;IACtD,KAAK,CAAe;IAEZ,WAAW,CAAS;IACpB,OAAO,CAAsB;IAC7B,IAAI,CAAU;IACd,OAAO,CAAe;IACtB,MAAM,CAAe;IACrB,SAAS,CAAe;IACxB,WAAW,CAAe;IAC1B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