tunelet 0.1.1 → 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/pkg/tunelet.d.ts DELETED
@@ -1,1084 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * A configuration or MIDI control that applies before a frame in the block.
5
- *
6
- * Give controls to a process call as [`TimedEvent`] values. The call borrows
7
- * the slice only for that call. There is no heap allocation and no deferred
8
- * queue. A stage event replaces all settings of that stage. To change one
9
- * field, start from the current configuration of the processor.
10
- * Configuration changes have the same effects on state as
11
- * [`crate::Processor::set_config`].
12
- */
13
- export type ControlEvent = { type: "configure"; value: ProcessorConfig } | { type: "resynthesis"; value: ResynthesisConfig } | { type: "punch"; value: PunchConfig } | { type: "warm"; value: WarmConfig } | { type: "alien"; value: AlienConfig } | { type: "reverb"; value: ReverbConfig } | { type: "outputGain"; value: number } | { type: "midi"; value: MidiEvent } | { type: "correctionMidi"; value: MidiEvent } | { type: "reset" };
14
-
15
- /**
16
- * A control that applies immediately before the zero-based input frame
17
- * `offset`.
18
- *
19
- * Offsets must be less than the current block length. They must not decrease
20
- * in the event slice. Events with equal offsets execute in slice order. Thus,
21
- * a later change at the same frame sees the earlier changes. An empty block
22
- * accepts no events.
23
- *
24
- * Offsets are local to this call, not a total count of processed frames.
25
- * This timing tells when the state changes. Smoothing, the analysis interval
26
- * and the signal latency also control when the audible result occurs.
27
- *
28
- * The processor validates each event before it starts to process the block.
29
- * If one event is not valid, the processor rejects the full block. This
30
- * includes the valid events that are earlier in the slice.
31
- */
32
- export interface TimedEvent {
33
- /**
34
- * The frame offset in the block.
35
- */
36
- offset: number;
37
- /**
38
- * The control change.
39
- */
40
- event: ControlEvent;
41
- }
42
-
43
- /**
44
- * A diatonic chord with its root on a degree of the selected
45
- * [`HarmonyScale`].
46
- *
47
- * Triads use the root, third and fifth scale degrees. Seventh chords also
48
- * use the seventh. Degrees above the seventh go into higher octaves. The
49
- * degree names do not set a major or minor quality. The selected scale
50
- * supplies the tones. The default is the tonic triad, [`Self::I`].
51
- */
52
- export type ChordDegree = "i" | "ii" | "iiSeventh" | "iii" | "iiiSeventh" | "iv" | "ivSeventh" | "v" | "vSeventh" | "vi" | "viSeventh" | "vii" | "viiSeventh";
53
-
54
- /**
55
- * A named chord for [`HarmonySource::ChordByName`].
56
- *
57
- * Each variant lists the semitones above the root. These values do not
58
- * include the inversion, the key transposition, the register or the voicing
59
- * spread. Triads use three voices.
60
- */
61
- export type ChordName = "major" | "majorSixth" | "majorSeventh" | "majorSeventhSuspendedFourth" | "minor" | "minorSixth" | "minorSeventh" | "minorSeventhFlatFifth" | "diminished" | "diminishedSeventh" | "dominantSeventh" | "dominantSeventhFlatFifth" | "augmented" | "augmentedSeventh" | "suspendedFourth" | "suspendedSecond" | "suspendedSeventh";
62
-
63
- /**
64
- * A scale for [`NoteMask::from_key_scale`].
65
- */
66
- export type CorrectionScale = "major" | "minor" | "chromatic";
67
-
68
- /**
69
- * A snapshot of the pitch analysis and the output level that you can copy.
70
- *
71
- * Get it with [`Processor::feedback`] or [`Processor::take_feedback`]. The
72
- * pitch fields describe the tracked input and the correction target. The
73
- * peak measures the final clipped stereo output. `Default` gives a snapshot
74
- * with all zeros and no target. It does not read the nominal latency of a
75
- * prepared processor.
76
- */
77
- export interface Feedback {
78
- /**
79
- * The pitch-correction ratio from the last processed frame, where 1 is
80
- * unity.
81
- *
82
- * It does not include the configured pitch shift or the ratios of
83
- * individual voices. It is zero before processing, after a reset or after
84
- * a change of stereo output.
85
- */
86
- resampleRatio: number;
87
- /**
88
- * The reported input pitch period in samples, with fractional samples.
89
- *
90
- * It is zero if the input is unvoiced or outside the reporting bounds of
91
- * [`crate::PitchConfig`].
92
- */
93
- periodSamples: number;
94
- /**
95
- * The reported input pitch frequency in hertz.
96
- *
97
- * The value comes from the sample rate and the current tracked period.
98
- * It is zero if the estimate is not reported.
99
- */
100
- frequencyHz: number;
101
- /**
102
- * The correction target or the input pitch, as a MIDI note number.
103
- *
104
- * The value is the selected correction pitch class if all of these
105
- * conditions are true:
106
- *
107
- * - Correction is enabled.
108
- * - The active note table is not empty.
109
- * - A tracking update selected a target after the last table change,
110
- * reset or tracking restart.
111
- *
112
- * The pitch class is in the octave nearest to the reported input. In
113
- * other cases, the value is the input pitch as a fractional MIDI note. It
114
- * is not the final pitch of shifted output or harmony output.
115
- *
116
- * The value is `None` if [`voiced`](Self::voiced) is `false`, and only
117
- * then. This occurs if the input is unvoiced or if its frequency is
118
- * outside the current reporting bounds. A target table that has no
119
- * selected target does not give `None`.
120
- */
121
- targetMidiNote: number | undefined;
122
- /**
123
- * This field is `true` if the current pitch estimate is positive and
124
- * inside the current reporting bounds.
125
- *
126
- * This is not an amplitude gate or a confidence score. A tracking result
127
- * can stay between detector updates.
128
- */
129
- voiced: boolean;
130
- /**
131
- * The largest absolute clipped stereo sample, divided by 32768.
132
- *
133
- * The peak window starts at construction, at a reset, at a change of
134
- * stereo output or at a call to [`Processor::take_feedback`]. The value
135
- * is in 0..=32767/32768. The mono downmix occurs after this measurement.
136
- * [`Processor::feedback`] does not clear the value.
137
- */
138
- peakLevel: number;
139
- /**
140
- * The number of frames processed since construction or the last reset,
141
- * with drain frames included.
142
- *
143
- * The count saturates at `u64::MAX`. Drain completion resets it in the
144
- * last drain call.
145
- */
146
- processedFrames: bigint;
147
- /**
148
- * The nominal resynthesis latency, as [`Processor::latency_frames`] gives.
149
- */
150
- latencyFrames: number;
151
- }
152
-
153
- /**
154
- * Asymmetric input saturation, followed by a 50 Hz high-pass filter.
155
- *
156
- * Warm operates after Punch and before pitch detection. Its adaptive
157
- * normalization updates every 100 enabled frames. When Warm is disabled,
158
- * the envelope and filter histories do not change. When Warm is enabled
159
- * again, they continue from their last state, unless the processor was
160
- * reset.
161
- */
162
- export interface WarmConfig {
163
- /**
164
- * Enables the saturation stage. The default is `false`.
165
- */
166
- enabled: boolean;
167
- /**
168
- * The drive in decibels, 0..=6. The default is 3 dB.
169
- * The output gain changes by -0.35 dB for each dB of drive. At 0 dB, the
170
- * envelope normalization and the output high-pass filter still operate.
171
- */
172
- driveDb: number;
173
- }
174
-
175
- /**
176
- * One of the twelve notes in an octave.
177
- */
178
- export type PitchClass = "c" | "cSharp" | "d" | "dSharp" | "e" | "f" | "fSharp" | "g" | "gSharp" | "a" | "aSharp" | "b";
179
-
180
- /**
181
- * Reverse playback of recent stereo audio in repeated loops with fades.
182
- *
183
- * Alien comes after resynthesis. Its input history and loop phase advance
184
- * also when Alien is disabled. Thus, when you enable Alien, it can play
185
- * audio that it recorded during bypass. A change of the loop length keeps
186
- * the history and clamps the current phase into the new loop. The boundary
187
- * fades are 200 frames long at all sample rates.
188
- */
189
- export interface AlienConfig {
190
- /**
191
- * Selects reversed playback instead of the direct input. The default is
192
- * `false`. The recording and the phase continue to advance in both
193
- * states.
194
- */
195
- enabled: boolean;
196
- /**
197
- * The loop length in frames, 1..=96000. The default is 95,999.
198
- * This value is a frame count at the two rates. Thus, its duration in
199
- * seconds changes with the sample rate. A short loop can be fully inside
200
- * the fades.
201
- */
202
- loopFrames: number;
203
- }
204
-
205
- /**
206
- * The acquisition sensitivity and the bounds for pitch reports to the host.
207
- */
208
- export interface PitchConfig {
209
- /**
210
- * The normalized cycle-difference threshold for acquisition, 0.002..=0.2.
211
- *
212
- * The default is 0.1. Larger values accept less exact cycle agreement.
213
- * This value controls acquisition. It is not an output gain or an
214
- * amplitude gate.
215
- */
216
- threshold: number;
217
- /**
218
- * The lower bound of the feedback in hertz (inclusive), 40..=2000.
219
- *
220
- * The default is 40. It must be strictly less than `max_frequency_hz`.
221
- * These bounds do not change the tracking, the correction or the
222
- * resampling. A feedback query applies the current bounds to the kept
223
- * analysis. It does not process another sample.
224
- */
225
- minFrequencyHz: number;
226
- /**
227
- * The upper bound of the feedback in hertz (inclusive), 40..=2000.
228
- *
229
- * The default is 1100. It must be strictly greater than
230
- * `min_frequency_hz`. Results outside the bounds are reported as
231
- * unvoiced, with zero frequency and zero period.
232
- */
233
- maxFrequencyHz: number;
234
- }
235
-
236
- /**
237
- * The chord inversion raises the lowest chord tones by one octave.
238
- *
239
- * The inversion applies before the register and the spread. It applies
240
- * only to named chords and degree chords. Root position is the default.
241
- * The first inversion moves one tone and the second inversion moves two
242
- * tones. The voicing of MIDI chords uses the played notes, not this control.
243
- */
244
- export type Inversion = "root" | "first" | "second";
245
-
246
- /**
247
- * The configuration of four harmony voices that follow intervals, chords or
248
- * MIDI.
249
- *
250
- * Positive intervals make the pitch higher. The defaults are:
251
- *
252
- * - MIDI channels 0..=3 as the source.
253
- * - The key of C and the major scale.
254
- * - Unison intervals.
255
- * - A tonic major chord in root position.
256
- * - A register of 50%.
257
- * - A closed voicing and zero portamento.
258
- *
259
- * These settings configure all sources. Only the fields for the selected
260
- * source change the target notes. Validation always checks all fields.
261
- *
262
- * Harmony makes its voices from the tracked input. MIDI controls the pitch
263
- * and the gain. It is not an independent oscillator. The gain in decibels
264
- * is linear in the velocity: velocities 1..=127 give approximately -23.72
265
- * to +12 dB. A velocity of zero releases the note.
266
- *
267
- * The gain attack, the gain release and the period portamento advance at
268
- * the controller cadence. This cadence is usually every 101 frames. A MIDI
269
- * event can make the next control step occur sooner. The envelopes and the
270
- * portamento advance only while the input is voiced.
271
- */
272
- export interface HarmonyConfig {
273
- /**
274
- * The pitch source. The default is [`HarmonySource::MidiChannels`].
275
- */
276
- source: HarmonySource;
277
- /**
278
- * The pitch class of the tonic. The default is C. Smart intervals, named
279
- * chords and degree chords use it. It does not transpose direct MIDI
280
- * notes.
281
- */
282
- key: PitchClass;
283
- /**
284
- * The scale for smart intervals and degree chords. The default is major.
285
- */
286
- scale: HarmonyScale;
287
- /**
288
- * Four fixed semitone offsets, each in -24..=24. The default is all
289
- * zeros. [`HarmonySource::FixedInterval`] uses them. A value of 12 makes
290
- * the pitch one octave higher.
291
- */
292
- chromaticIntervals: [number, number, number, number];
293
- /**
294
- * Four offsets in scale steps, each in -14..=14. The default is all
295
- * zeros. [`HarmonySource::SmartInterval`] uses them. Seven steps make
296
- * the pitch one octave higher.
297
- */
298
- diatonicIntervals: [number, number, number, number];
299
- /**
300
- * The named chord for [`HarmonySource::ChordByName`]. The default is
301
- * major.
302
- */
303
- chord: ChordName;
304
- /**
305
- * The chord on a scale degree for [`HarmonySource::ChordByDegree`]. The
306
- * default is I.
307
- */
308
- degree: ChordDegree;
309
- /**
310
- * The inversion for named chords and degree chords. The default is root
311
- * position.
312
- */
313
- inversion: Inversion;
314
- /**
315
- * The chord register from low to high, 0..=100%.
316
- *
317
- * The default is 50%. All chord sources use it, which includes MIDI chords.
318
- * The value is truncated to a whole percentage before it selects the
319
- * octave shift.
320
- */
321
- registerPercent: number;
322
- /**
323
- * The chord voicing from close to open, 0..=100%.
324
- *
325
- * The default is 0%. All chord sources use it. The value is truncated to a
326
- * whole percentage. The result selects discrete octave positions, not
327
- * continuous detuning.
328
- */
329
- voicingSpreadPercent: number;
330
- /**
331
- * The half-life of the target-period smoothing in milliseconds,
332
- * 0..=10000. The default is 0. The smoothing applies at each control
333
- * step. The coefficient assumes 100 frames for each step. At the usual
334
- * cadence of 101 frames, the half-life is approximately 1% longer. If
335
- * the value is zero, the voice uses the target period immediately. The
336
- * gain envelopes still apply. A note on a free voice can start without
337
- * a glide. In the interval sources, if the input moves more than one
338
- * semitone bin, each voice starts at its new target without a glide.
339
- */
340
- portamentoMs: number;
341
- }
342
-
343
- /**
344
- * The controls for pitch correction, pitch shift, voice arrangement and
345
- * formants.
346
- *
347
- * The defaults render one choir voice with these settings:
348
- * - Chromatic correction.
349
- * - A pitch shift of 1.0.
350
- * - Disabled formants.
351
- * - No harmonic modulation.
352
- * - No dry mix.
353
- * - No stereo pan.
354
- *
355
- * Validation applies to all controls, also when their stage or voice mode
356
- * is not active.
357
- *
358
- * The dry path takes the audio after Punch and Warm and delays it by 1,543
359
- * frames. The wet voice readers have more delay, which changes with the
360
- * pitch. After this stage, the two paths go through Alien, reverb and the
361
- * final output gain.
362
- */
363
- export interface ResynthesisConfig {
364
- /**
365
- * The acquisition sensitivity and the reporting bounds. The
366
- * default is [`PitchConfig::default`].
367
- */
368
- pitch: PitchConfig;
369
- /**
370
- * The target notes and the retune time. The default is enabled
371
- * chromatic correction with a retune time of zero.
372
- */
373
- correction: CorrectionConfig;
374
- /**
375
- * The pitch multiplier, 0.25..=4. The default is 1.
376
- *
377
- * A value of 0.5 lowers the pitch by one octave. A value of 2 raises the
378
- * pitch by one octave. This value multiplies the correction ratio and
379
- * the ratio of each voice. A value above 1 also enables the anti-alias
380
- * low-pass filters.
381
- */
382
- pitchRatio: number;
383
- /**
384
- * The vocal-tract changes and aspiration. They are disabled by default.
385
- */
386
- formant: FormantConfig;
387
- /**
388
- * The voice arrangement. The default is [`MultiVoiceMode::Choir`].
389
- *
390
- * Harmony renders the lead voice and a maximum of four harmony voices.
391
- */
392
- mode: MultiVoiceMode;
393
- /**
394
- * The total number of choir voices, with the lead voice, 1..=16. The
395
- * default is 1.
396
- *
397
- * The other voices read the delayed lead history with random pitch
398
- * drift. The code adds the voices and does not divide the sum by the
399
- * number of voices. Thus, more voices can increase the output level and
400
- * the clipping. Harmony does not use this value.
401
- */
402
- choirVoices: number;
403
- /**
404
- * The drift control for secondary voices, 10..=100, without a unit. The
405
- * default is 50.
406
- *
407
- * The unit is not cents. The lead voice has no random choir drift. Thus,
408
- * a choir with one voice does not get this detune.
409
- */
410
- choirDetune: number;
411
- /**
412
- * The scale of the choir delay table, 20..=200, without a unit. The
413
- * default is 60.
414
- *
415
- * A value of 200 uses the full fixed table of frame offsets. The unit is
416
- * not milliseconds. The table offset of the lead voice is zero at all
417
- * settings.
418
- */
419
- choirDelay: number;
420
- /**
421
- * The stereo width of the choir, 0..=100%. The default is 100%.
422
- *
423
- * The code uses this value only if `stereo_output` enables the voice pan
424
- * and the choir has more than one voice.
425
- */
426
- choirSpreadPercent: number;
427
- /**
428
- * Enables a stereo pan for each voice. The default is `false`.
429
- *
430
- * This value is independent of the buffer layout of the process method.
431
- * A change to this value resets some audio histories and the feedback.
432
- * [`crate::Processor::set_config`] gives the details.
433
- */
434
- stereoOutput: boolean;
435
- /**
436
- * The controls for the four harmony voices. The default is MIDI-channel
437
- * allocation.
438
- *
439
- * Validation applies to these controls, and they can receive MIDI, also
440
- * while Choir is selected.
441
- */
442
- harmony: HarmonyConfig;
443
- /**
444
- * The pan gain of the harmony voices, 0..=1. The default is 0.5.
445
- *
446
- * The code applies this gain only if `stereo_output` is `true`. The
447
- * harmony path without pan does not use this control. It does not scale
448
- * the lead voice.
449
- */
450
- harmonyGain: number;
451
- /**
452
- * The modulation depth, 0..=24, without a unit. The default is 0 (off).
453
- *
454
- * The code multiplies the control by two and truncates it to an integer.
455
- * Then it uses the result for a cosine modulation after the wet voices
456
- * are mixed. The value is not an interval in semitones.
457
- */
458
- harmonicModulation: number;
459
- /**
460
- * The dry fraction at the resynthesis stage, 0..=1. The default is 0.
461
- *
462
- * The code truncates this value to Q8. The wet weight is 1.0 minus the
463
- * Q8 dry weight. The dry path starts after Punch and Warm and has a
464
- * delay of 1,543 frames. Alien, reverb and the output gain still occur
465
- * after this stage.
466
- */
467
- dryMix: number;
468
- /**
469
- * The seed for choir drift and aspiration, which use the same stream.
470
- * The default is `0x1234_abcd`.
471
- *
472
- * Only the low 32 bits select the sequence. If a configuration change
473
- * gives a different 64-bit value, the processor starts the stream again
474
- * from the low 32 bits. This is also true for a change to only the high
475
- * bits. Reset keeps the current position in the stream. The enabled
476
- * stages set the number of random values that the code reads.
477
- */
478
- randomSeed: bigint;
479
- }
480
-
481
- /**
482
- * The controls for pitch-class correction, with target selection in the
483
- * period domain.
484
- *
485
- * Correction is enabled by default, with all chromatic notes and a retune
486
- * time of zero. Target selection and the smoothing of the correction ratio
487
- * occur at each update of the pitch tracking. When a period is tracked,
488
- * this update usually occurs every five frames. If the active note table is
489
- * empty or correction is disabled, the ratio moves toward 1.0 at the same
490
- * rate.
491
- *
492
- * Correction MIDI replaces the active note table. It does not change this
493
- * configuration. A change to `notes` or to `enabled` loads the configured
494
- * mask again. Reset releases the correction keys 0..=126. It keeps key 127
495
- * and the active note table. Key 127 has no effect on the note table.
496
- *
497
- * At construction, the chromatic table uses 44.1 kHz periods, also for a
498
- * 48 kHz processor. Each of these events loads the periods for the prepared
499
- * rate:
500
- * - An initial mask that is not chromatic.
501
- * - A later change to the mask or to `enabled`.
502
- * - A correction MIDI event.
503
- */
504
- export interface CorrectionConfig {
505
- /**
506
- * Enables the selection of correction targets. The default is `true`.
507
- *
508
- * If you disable correction, the ratio moves toward 1.0 with `retune_ms`
509
- * at the next tracking updates. The ratio does not change to 1.0
510
- * immediately.
511
- */
512
- enabled: boolean;
513
- /**
514
- * The configured target pitch classes. The default is
515
- * [`NoteMask::CHROMATIC`].
516
- *
517
- * All boolean masks are valid. MIDI can replace the active table. This
518
- * replacement stays until this mask or `enabled` changes.
519
- */
520
- notes: NoteMask;
521
- /**
522
- * The half-life of the smoothing in milliseconds, 0..=400. The default
523
- * is 0.
524
- *
525
- * If the value is zero, the ratio changes to the target at the next
526
- * tracking update. A value that is not zero is a half-life. It is not a
527
- * fixed time to get exactly to the target.
528
- */
529
- retuneMs: number;
530
- }
531
-
532
- /**
533
- * The controls for vocal-tract changes and synthesized aspiration during
534
- * resynthesis.
535
- *
536
- * This stage is disabled by default. If it is enabled, it does these steps:
537
- * 1. It estimates an LPC model.
538
- * 2. It removes the spectral envelope of the input.
539
- * 3. It applies a changed model to the resampled audio.
540
- *
541
- * If width and stretch are 1, the model dimensions do not change. But the
542
- * fixed-point analysis and synthesis path does not give a bit-identical
543
- * copy of the input. Aspiration occurs only if the formant path is enabled.
544
- */
545
- export interface FormantConfig {
546
- /**
547
- * Enables formant analysis and synthesis. The default is `false`.
548
- */
549
- enabled: boolean;
550
- /**
551
- * The vocal-tract width factor, 0.5..=2. The default is 1.
552
- *
553
- * The square of the width scales the estimated tract areas. The width
554
- * also scales the amplitude of the synthesized output.
555
- */
556
- width: number;
557
- /**
558
- * The vocal-tract length factor, 0.5..=2. The default is 1.
559
- *
560
- * It controls the interpolation of the area model and thus the filter
561
- * order.
562
- */
563
- stretch: number;
564
- /**
565
- * The aspiration level, 0..=1, without a unit. The default is 0.
566
- *
567
- * If the value is 0.01 or less, the stage makes no noise. Active
568
- * aspiration follows the signal amplitude. It uses the random stream of
569
- * the processor, together with other stages. During each drain call,
570
- * the processor sets the aspiration to zero. The configuration that the
571
- * host sees does not change.
572
- */
573
- aspirationMix: number;
574
- /**
575
- * The high-pass cutoff for aspiration in hertz, 500..=10000. The default
576
- * is 4000.
577
- *
578
- * The stage limits the cutoff to 0.48 × sample rate and truncates it to
579
- * whole hertz. A change to this value updates the coefficients. The
580
- * filter history does not change.
581
- */
582
- aspirationCutoffHz: number;
583
- }
584
-
585
- /**
586
- * The echo or reverberation network. The default is [`Self::Echo`].
587
- *
588
- * All modes share one delay buffer. A mode change uses the same buffer
589
- * contents and damping filter memories. Thus a transition can play audio
590
- * from the previous network. The stereo layout of the buffer does not make
591
- * all modes give different left and right signals. Schroeder gives the same
592
- * value on the two channels.
593
- */
594
- export type ReverbMode = "echo" | "schroeder" | "smallRoom" | "binaural" | "mediumHall" | "largeHall";
595
-
596
- /**
597
- * The events for one call that processes audio (`TimedEvent[]` in TypeScript).
598
- *
599
- * Each offset is a zero-based frame index in the current block. Each offset
600
- * must be in the block and must not be less than the offset before it. Events
601
- * with equal offsets execute in array order. An empty block accepts no
602
- * events. If there are no events, omit the optional argument. Then the
603
- * binding does not decode an array.
604
- */
605
- export type BlockEvents = TimedEvent[];
606
-
607
- /**
608
- * The input gain and the transient enhancement with arctangent saturation.
609
- *
610
- * Punch comes before Warm and before pitch detection. It finds the peak of
611
- * each window of 100 processed frames. Two envelope followers set the drive
612
- * from these peaks. When Punch is disabled, it does not process audio, and
613
- * its envelope and window state do not change.
614
- *
615
- * A gain change updates the cached drive at the next boundary of the peak
616
- * window. A reset calculates that drive again immediately from the
617
- * configured gain.
618
- */
619
- export interface PunchConfig {
620
- /**
621
- * Enables this input stage. The default is `false`.
622
- */
623
- enabled: boolean;
624
- /**
625
- * The input gain in decibels, -96..=12.
626
- *
627
- * The default is 0 dB. The saturation drive from this gain changes at the
628
- * next 100-frame peak boundary.
629
- */
630
- gainDb: number;
631
- /**
632
- * The transient emphasis without a unit, 0..=1.
633
- *
634
- * The default is 0.5. It sets the release half-life of the adaptive
635
- * follower: 5000 ms at 0, 250 ms at 0.5 and 1 ms at 1. The attack uses
636
- * `attack_ms`.
637
- */
638
- impact: number;
639
- /**
640
- * The output ceiling of the saturation in dBFS, -96..=0.
641
- *
642
- * The default is -3 dBFS. Later stages and the final gain can make the
643
- * final output higher than this level.
644
- */
645
- ceilingDb: number;
646
- /**
647
- * The attack half-life of the peak follower in milliseconds, 0.01..=5000.
648
- *
649
- * The default is 10 ms. The coefficients include the effect of the
650
- * 100-frame update interval.
651
- */
652
- attackMs: number;
653
- }
654
-
655
- /**
656
- * The method that resynthesis uses to render its voices.
657
- */
658
- export type MultiVoiceMode = "choir" | "harmony";
659
-
660
- /**
661
- * The permitted correction pitch classes, in the order C, C♯, D, D♯, E, F,
662
- * F♯, G, G♯, A, A♯, B.
663
- *
664
- * A `true` flag enables that pitch class in all octaves.
665
- *
666
- * The default is [`Self::CHROMATIC`]. All combinations of flags are valid.
667
- * This includes [`Self::NONE`]. If the mask is empty, the correction ratio
668
- * moves toward unity with the configured retune half-life. An empty mask
669
- * does not clear the histories.
670
- */
671
- export type NoteMask = [boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean];
672
-
673
- /**
674
- * The reverb after Alien, with controls for the network, the wet mix and the
675
- * decay.
676
- *
677
- * The reverb is disabled by default. In bypass, the stage returns the input
678
- * and does not advance the delay network or the damping filters. If the
679
- * stage is enabled and the mix is zero, the network still operates. A reset
680
- * clears the delay buffer but keeps the memories of the damping filters. The
681
- * mix, diffusion and decay controls are quantized to Q14. The function of
682
- * each control changes with the network.
683
- */
684
- export interface ReverbConfig {
685
- /**
686
- * Enables the selected network. The default is `false`. In bypass, the
687
- * histories do not change.
688
- */
689
- enabled: boolean;
690
- /**
691
- * The topology of the delay network. The default is
692
- * [`ReverbMode::Echo`].
693
- */
694
- mode: ReverbMode;
695
- /**
696
- * The wet fraction, 0..=1.
697
- *
698
- * The default is 0.5. The dry weight is `1 - mix`. Schroeder and Binaural
699
- * use a mono dry signal. The other modes keep the stereo dry input. If
700
- * the network is enabled, a zero mix still advances it.
701
- */
702
- mix: number;
703
- /**
704
- * The diffusion control without a unit, 0..=1.
705
- *
706
- * The default is 0.5. MediumHall and LargeHall scale their allpass
707
- * coefficients with it. Binaural uses it as the gain of its early taps.
708
- * In Echo, it sets the distance of the feedback tap. Schroeder and
709
- * SmallRoom do not use it.
710
- */
711
- diffusion: number;
712
- /**
713
- * The feedback control without a unit, 0..=1.
714
- *
715
- * The default is 0.6. The prepared coefficient is approximately
716
- * `decay / 1.05`. It is less than unity also at the maximum. This value
717
- * is not a decay time in seconds. Some paths also use fixed feedback
718
- * coefficients. Binaural does not use this control.
719
- */
720
- decay: number;
721
- /**
722
- * The low-pass cutoff in hertz for networks with damped paths, 80..=20000.
723
- *
724
- * The default is 4000 Hz. The preparation also limits it to 0.49 ×
725
- * sample rate. A change of the cutoff keeps the sample histories of the
726
- * filters.
727
- */
728
- brightnessHz: number;
729
- }
730
-
731
- /**
732
- * The scale that smart intervals and chords by degree use.
733
- */
734
- export type HarmonyScale = "major" | "majorWithoutSeventh" | "majorFlatSeventh" | "minor" | "harmonicMinor" | "minorNaturalSixth" | "minorMajorSeventh";
735
-
736
- /**
737
- * The settings for the complete signal chain, in the order of the stages.
738
- *
739
- * The default enables chromatic pitch correction, one choir voice and unity
740
- * output gain. Punch, Warm, formants, Alien and reverb are disabled. This
741
- * configuration does active pitch processing. It is not a bypass with zero
742
- * latency.
743
- *
744
- * Change a copy, then apply it with [`crate::Processor::set_config`] or
745
- * [`crate::ControlEvent::Configure`]. The validation examines all fields
746
- * before a change has an effect. This includes the fields of disabled stages.
747
- */
748
- export interface ProcessorConfig {
749
- /**
750
- * The input dynamics and saturation stage, which applies first.
751
- *
752
- * It is disabled by default.
753
- */
754
- punch: PunchConfig;
755
- /**
756
- * The asymmetric saturation stage after Punch.
757
- *
758
- * It is disabled by default.
759
- */
760
- warm: WarmConfig;
761
- /**
762
- * The stage for pitch tracking, correction, voice resynthesis and
763
- * formant control.
764
- *
765
- * The default is [`ResynthesisConfig::default`].
766
- */
767
- resynthesis: ResynthesisConfig;
768
- /**
769
- * The reverse-loop effect after resynthesis.
770
- *
771
- * It is disabled by default.
772
- */
773
- alien: AlienConfig;
774
- /**
775
- * The echo or reverberation stage after Alien.
776
- *
777
- * It is disabled by default.
778
- */
779
- reverb: ReverbConfig;
780
- /**
781
- * The linear gain after all effects, 0..=64.
782
- *
783
- * The default is 1 (unity). Zero mutes the output, but the internal
784
- * processing continues. The gain is quantized in steps of 1/256 before
785
- * the fixed-point multiplication and the final PCM clipping. Thus, a
786
- * positive value below 1/256 also mutes the output.
787
- */
788
- outputGain: number;
789
- }
790
-
791
- /**
792
- * The source of target periods for the four harmony voices.
793
- *
794
- * The default is [`Self::MidiChannels`]. The static interval and chord
795
- * sources use the related [`HarmonyConfig`] fields. The MIDI sources use
796
- * [`crate::ControlEvent::Midi`]. The configuration of the sources that are
797
- * not selected is still validated and kept.
798
- */
799
- export type HarmonySource = "fixedInterval" | "smartInterval" | "chordByDegree" | "chordByName" | "chordViaMidi" | "midiOmni" | "midiChannels";
800
-
801
- /**
802
- * The supported MIDI note controls, with zero-based channel numbers.
803
- *
804
- * Use [`crate::ControlEvent::Midi`] for harmony. Use
805
- * [`crate::ControlEvent::CorrectionMidi`] for the independent correction
806
- * keyboard. The typed representation can contain `u8` values that are not
807
- * valid. [`Self::validate`] and the event preflight of the processor check
808
- * the MIDI ranges. Note numbers use A4 = 69 at 440 Hz.
809
- */
810
- export type MidiEvent = { type: "noteOn"; channel: number; note: number; velocity: number } | { type: "noteOff"; channel: number; note: number } | { type: "allNotesOff" };
811
-
812
-
813
- /**
814
- * A stateful PCM processor that JavaScript uses as the `Tunelet` class.
815
- *
816
- * The input is signed 16-bit mono PCM. The output is planar stereo or an
817
- * in-place mono downmix. The quantization, latency and configuration behavior
818
- * are the same as in the native processor. Buffer lengths count frames, not
819
- * bytes.
820
- *
821
- * These rules apply to the buffers:
822
- *
823
- * - Separate stereo output arrays must not overlap.
824
- * - The input can overlap an output, because the class copies the input
825
- * first.
826
- * - All buffers must stay attached until each call is complete.
827
- *
828
- * If a call that processes audio fails, it throws a JavaScript `Error` before
829
- * the audio state or the output changes. The class rejects malformed
830
- * configuration objects and malformed event objects. It also rejects values
831
- * that are out of range. The class decodes objects inside the methods that
832
- * can fail. Thus, if a conversion fails, Rust releases the temporary values
833
- * as usual.
834
- */
835
- export class Tunelet {
836
- free(): void;
837
- [Symbol.dispose](): void;
838
- /**
839
- * Starts a finite tail budget and returns its frame count as a number.
840
- *
841
- * Call this method one time after the final input block. Another call
842
- * starts the full budget again, but it does not clear the histories. See
843
- * `beginDrain` for completion.
844
- */
845
- beginDrain(): number;
846
- /**
847
- * Returns a copy of the active configuration as a new JavaScript object.
848
- *
849
- * A change to the object has no effect until `setConfig` or a timed event
850
- * applies it.
851
- *
852
- * # Errors
853
- *
854
- * If the conversion to a JavaScript object fails, this method throws.
855
- */
856
- config(): ProcessorConfig;
857
- /**
858
- * Renders a mono tail block and returns its frame count.
859
- *
860
- * The method fills the unused output with zeros. The downmix, completion
861
- * and feedback behavior are the same as for `drainMono`.
862
- *
863
- * # Errors
864
- *
865
- * If the block is larger than `maxBlockFrames`, this method throws before
866
- * the output or the state changes.
867
- */
868
- drainMono(audio: Int16Array): number;
869
- /**
870
- * Renders stereo tail frames into `Int16Array` buffers of equal length.
871
- *
872
- * The method returns the number of rendered frames and fills the unused
873
- * output with zeros. If the drain is not active or is complete, the method
874
- * returns zero. Empty arrays do not use the budget. Completion resets the
875
- * histories and the feedback in the final drain call, also when that call
876
- * returns audio.
877
- *
878
- * # Errors
879
- *
880
- * The method throws if the channel lengths are not equal or if a block is
881
- * larger than `maxBlockFrames`. After an error, both output arrays and the
882
- * drain state do not change.
883
- */
884
- drain(left: Int16Array, right: Int16Array): number;
885
- /**
886
- * Returns a new feedback object and does not clear the peak window.
887
- *
888
- * `processedFrames` is a `bigint`, so its 64-bit count stays exact.
889
- * `latencyFrames` is a number. See `Feedback` for each measurement.
890
- *
891
- * `targetMidiNote` is `undefined` in these cases, which are also the
892
- * cases where `voiced` is `false`:
893
- *
894
- * - The kept pitch estimate is unvoiced. This includes the time before
895
- * the first detection and after a reset or a drain completion.
896
- * - The estimated frequency is outside the inclusive reporting bounds
897
- * `minFrequencyHz` and `maxFrequencyHz` of the pitch configuration.
898
- *
899
- * # Errors
900
- *
901
- * If the conversion to a JavaScript object fails, this method throws.
902
- */
903
- feedback(): Feedback;
904
- /**
905
- * Prepares a processor and its reusable PCM buffers.
906
- *
907
- * `sample_rate` must be 44100 or 48000. `max_block_frames` must be an
908
- * integer in 1..=4294967295. It is a limit for each call, and smaller
909
- * blocks and empty blocks are also valid. If you omit `config`, the
910
- * processor uses the default configuration. The constructor validates
911
- * the settings before it allocates the processor or the PCM buffers. In
912
- * TypeScript, use `new Tunelet(sampleRate, maxBlockFrames, config)`.
913
- *
914
- * # Errors
915
- *
916
- * The constructor throws if one of these conditions occurs:
917
- *
918
- * - The rate is not 44100 or 48000.
919
- * - The block limit is not an integer or is out of range.
920
- * - The configuration object is malformed or a field is missing.
921
- * - The configuration is not valid.
922
- * - The reservation of a PCM buffer fails.
923
- *
924
- * The available Wasm memory must also have sufficient space for the DSP
925
- * histories.
926
- */
927
- constructor(sample_rate: number, max_block_frames: number, config?: ProcessorConfig | null);
928
- /**
929
- * Replaces the audio in a mono `Int16Array` with the stereo downmix.
930
- *
931
- * The timing, the events and the drain cancellation are the same as for
932
- * `process`. Peak feedback measures the stereo output before the downmix,
933
- * as in the native processor.
934
- *
935
- * # Errors
936
- *
937
- * The method throws if the block is too large or an event is not valid.
938
- * It throws before the audio of the caller or the DSP state changes.
939
- */
940
- processMono(audio: Int16Array, events?: BlockEvents | null): void;
941
- /**
942
- * Processes mono input into left and right `Int16Array` buffers of equal
943
- * length.
944
- *
945
- * If the call is successful, it writes every output sample. Optional
946
- * events apply before their frame, and their offsets obey the rules of
947
- * `TimedEvent[]`. An empty block must have no events. A successful call
948
- * cancels a drain, also for an empty block. The call uses the existing
949
- * JavaScript and Rust PCM buffers again.
950
- *
951
- * # Errors
952
- *
953
- * The method throws if the channel lengths are not equal. It also throws
954
- * if the block is larger than `maxBlockFrames` or an event is not valid.
955
- * The call checks the lengths and the block size before it decodes and
956
- * validates the events. If an error occurs, the output buffers and the DSP
957
- * state do not change.
958
- */
959
- process(input: Int16Array, left: Int16Array, right: Int16Array, events?: BlockEvents | null): void;
960
- /**
961
- * Resets the audio histories and feedback, as the native processor does.
962
- *
963
- * The configuration, the random stream and some controller and filter
964
- * state do not change. This method cancels any active drain. For a fully
965
- * new instance, construct a new `Tunelet`.
966
- */
967
- reset(): void;
968
- /**
969
- * Decodes and validates a configuration, then replaces the complete
970
- * configuration with it.
971
- *
972
- * State retention and drain cancellation follow the native processor.
973
- * The conversion ignores additional properties of the JavaScript object.
974
- *
975
- * # Errors
976
- *
977
- * The method throws if an object is not valid or a field is missing.
978
- * After an error, all processor state and any active drain stay the same.
979
- */
980
- setConfig(config: ProcessorConfig): void;
981
- /**
982
- * Returns the tail budget of the current configuration, not the remaining
983
- * drain count.
984
- */
985
- tailFrames(): number;
986
- /**
987
- * Returns the feedback and clears only the stereo peak window.
988
- *
989
- * The other feedback fields and all audio histories do not change.
990
- *
991
- * # Errors
992
- *
993
- * If the conversion to a JavaScript object fails, this method throws. The
994
- * method clears the peak only after it successfully makes a feedback
995
- * object.
996
- */
997
- takeFeedback(): Feedback;
998
- /**
999
- * The nominal resynthesis delay in frames.
1000
- *
1001
- * Other signal paths have different timing. See the `latencyFrames`
1002
- * property for the timing of the dry path and the voices.
1003
- */
1004
- readonly latencyFrames: number;
1005
- /**
1006
- * The maximum frame count for each call that processes or drains audio.
1007
- *
1008
- * The constructor sets this value, and the value does not change.
1009
- */
1010
- readonly maxBlockFrames: number;
1011
- /**
1012
- * The sample rate of the input and the output in hertz.
1013
- *
1014
- * The constructor sets this value, and the value does not change.
1015
- */
1016
- readonly sampleRate: number;
1017
- }
1018
-
1019
- /**
1020
- * Returns a complete, independent default configuration for JavaScript.
1021
- *
1022
- * Change its fields and give it to `Tunelet` or to `setConfig`. The
1023
- * `randomSeed` field is a JavaScript `bigint`, so it keeps all 64 bits. After
1024
- * the binding decodes them, floating-point controls have the precision of the
1025
- * Rust `f32` type.
1026
- *
1027
- * # Errors
1028
- *
1029
- * If the conversion to a JavaScript object fails, this function returns a
1030
- * JavaScript `Error`.
1031
- */
1032
- export function defaultConfig(): ProcessorConfig;
1033
-
1034
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
1035
-
1036
- export interface InitOutput {
1037
- readonly memory: WebAssembly.Memory;
1038
- readonly __wbg_tunelet_free: (a: number, b: number) => void;
1039
- readonly defaultConfig: () => [number, number, number];
1040
- readonly tunelet_beginDrain: (a: number) => number;
1041
- readonly tunelet_config: (a: number) => [number, number, number];
1042
- readonly tunelet_drain: (a: number, b: any, c: any) => [number, number, number];
1043
- readonly tunelet_drainMono: (a: number, b: any) => [number, number, number];
1044
- readonly tunelet_feedback: (a: number) => [number, number, number];
1045
- readonly tunelet_latencyFrames: (a: number) => number;
1046
- readonly tunelet_maxBlockFrames: (a: number) => number;
1047
- readonly tunelet_new: (a: number, b: number, c: number) => [number, number, number];
1048
- readonly tunelet_process: (a: number, b: any, c: any, d: any, e: number) => [number, number];
1049
- readonly tunelet_processMono: (a: number, b: any, c: number) => [number, number];
1050
- readonly tunelet_reset: (a: number) => void;
1051
- readonly tunelet_sampleRate: (a: number) => number;
1052
- readonly tunelet_setConfig: (a: number, b: any) => [number, number];
1053
- readonly tunelet_tailFrames: (a: number) => number;
1054
- readonly tunelet_takeFeedback: (a: number) => [number, number, number];
1055
- readonly __wbindgen_malloc: (a: number, b: number) => number;
1056
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
1057
- readonly __wbindgen_exn_store: (a: number) => void;
1058
- readonly __externref_table_alloc: () => number;
1059
- readonly __wbindgen_externrefs: WebAssembly.Table;
1060
- readonly __externref_table_dealloc: (a: number) => void;
1061
- readonly __wbindgen_start: () => void;
1062
- }
1063
-
1064
- export type SyncInitInput = BufferSource | WebAssembly.Module;
1065
-
1066
- /**
1067
- * Instantiates the given `module`, which can either be bytes or
1068
- * a precompiled `WebAssembly.Module`.
1069
- *
1070
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
1071
- *
1072
- * @returns {InitOutput}
1073
- */
1074
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
1075
-
1076
- /**
1077
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
1078
- * for everything else, calls `WebAssembly.instantiate` directly.
1079
- *
1080
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
1081
- *
1082
- * @returns {Promise<InitOutput>}
1083
- */
1084
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;