Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ These rules apply to the offsets:
- An offset must not be less than the offset before it.

Events with equal offsets execute in slice order. An empty block accepts no
events. A stage event replaces all settings of that stage. To change one scalar
field without a stage copy, use `ControlEvent::Parameter` with a
`ParameterControl` variant. For fields that are not scalar parameters, start
from `processor.config()`.
events. A stage event replaces all settings of that stage. Use
`ControlEvent::Parameter` with `ParameterControl` to change one scalar field.
Use `ControlEvent::Patch` to change selected fields, or start from
`processor.config()`.

Harmony MIDI uses `ControlEvent::Midi`. MIDI for the correction keyboard uses
`ControlEvent::CorrectionMidi`. For example, these events change the resynthesis
Expand Down Expand Up @@ -498,7 +498,7 @@ page that opens the JavaScript.
| Cached `Float32` memory views | `new TuneletAudioViews(memory, processor)` |
| Zero-copy `Float32` stereo | `processF32InPlace(frames, events?)` |
| Zero-copy `Float32` mono | `processMonoF32InPlace(frames, events?)` |
| Configuration | `config()`, `setConfig(config)`, `defaultConfig()` |
| Configuration | `config()`, `setConfig(config)`, `patchConfig(patch)`, `defaultConfig()` |
| Control activity | `controlActivity()` |
| Information about the preparation | `sampleRate`, `maxBlockFrames`, `latencyFrames` |
| Feedback | `feedback()`, `takeFeedback()` |
Expand Down Expand Up @@ -557,8 +557,8 @@ and `views.right`.

These lifetime rules apply to `Float32` views:

- A new `Tunelet`, `setConfig`, `events`, `controlActivity`, feedback,
telemetry or `formantEnvelope` can grow Wasm memory and detach
- A new `Tunelet`, `setConfig`, `patchConfig`, `events`, `controlActivity`,
feedback, telemetry or `formantEnvelope` can grow Wasm memory and detach
`memory.buffer`.
- Read `views.input` before each input write so `TuneletAudioViews` checks
`memory.buffer` and refreshes detached views.
Expand All @@ -585,6 +585,13 @@ default. `resynthesis.correction.humanize` and
properties. The generated declarations contain the parameter documentation from
the Rust types.

To change selected fields without a full configuration copy, give a
`ProcessorConfigPatch` object to `patchConfig(patch)`. All fields in
`ProcessorConfigPatch` and the stage patches are optional. Absent or `undefined`
fields keep their active values on the processor. `patchConfig()` validates the
supplied fields and the pitch bounds before any state changes. Each successful
call cancels an active drain, also for an empty `{}` patch.

`resynthesis.randomSeed` and the `processedFrames` field of feedback and
telemetry use `bigint`. Frame offsets, block lengths and latency use
`number`.
Expand All @@ -599,6 +606,13 @@ example, this event changes the final gain before the first frame:
{ offset: 0, event: { type: "outputGain", value: 0.5 } }
```

To merge selected configuration fields before a frame, use
`ControlEvent::Patch` (`type: "patch"`):

```ts
{ offset: 0, event: { type: "patch", value: { resynthesis: { dryMix: 0.2 } } } }
```

A scalar parameter event nests a `ParameterControl` object:

```ts
Expand Down Expand Up @@ -655,7 +669,7 @@ allocate and grow Wasm memory:
- A new `Tunelet` instance.
- Configuration conversion.
- Supplied events when a call gives more events than before, or when an event
converts a stage configuration.
converts a configuration or a patch.
- Errors.
- Control activity, feedback and telemetry.
- The formant envelopes.
Expand Down
16 changes: 16 additions & 0 deletions scripts/normalize-jsdoc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const EXACT_REPLACEMENTS = [
["[`voice_count`](Self::voice_count)", "`voiceCount`"],
["[`alien_loop_frames`](Self::alien_loop_frames)", "`alienLoopFrames`"],
["[`crate::Processor::set_config`]", "`Tunelet.setConfig`"],
["[`crate::Processor::patch_config`]", "`Tunelet.patchConfig`"],
["[`crate::ControlEvent::Patch`]", '`{ type: "patch", value }`'],
["[`crate::Processor::control_activity`]", "`Tunelet.controlActivity`"],
["[`Processor::control_activity`]", "`Tunelet.controlActivity`"],
["[`ProcessorConfig::control_activity`]", "`Tunelet.controlActivity`"],
Expand Down Expand Up @@ -80,7 +82,15 @@ const EXACT_REPLACEMENTS = [
["[`ReverbConfig::brightness_hz`]", "`ReverbConfig.brightnessHz`"],
["[`crate::AlienConfig::loop_frames`]", "`AlienConfig.loopFrames`"],
["[`crate::PitchConfig`]", "`PitchConfig`"],
["[`PitchConfig`]", "`PitchConfig`"],
["[`ProcessorConfig`]", "`ProcessorConfig`"],
["[`PunchConfig`]", "`PunchConfig`"],
["[`WarmConfig`]", "`WarmConfig`"],
["[`ResynthesisConfig`]", "`ResynthesisConfig`"],
["[`CorrectionConfig`]", "`CorrectionConfig`"],
["[`FormantConfig`]", "`FormantConfig`"],
["[`AlienConfig`]", "`AlienConfig`"],
["[`ReverbConfig`]", "`ReverbConfig`"],
["[`ControlActivity`]", "`ControlActivity`"],
["[`TimedEvent`]", "`TimedEvent`"],
["[`HarmonyScale`]", "`HarmonyScale`"],
Expand All @@ -90,6 +100,7 @@ const EXACT_REPLACEMENTS = [
"[`ControlEvent::Parameter`]",
'`{ type: "parameter", value }` in `ControlEvent`',
],
["[`Self::Patch`]", '`{ type: "patch", value }`'],
["[`Self::Parameter`]", '`{ type: "parameter", value }`'],
["[`Self::I`]", '`"i"`'],
["[`Self::Echo`]", '`"echo"`'],
Expand All @@ -102,6 +113,7 @@ const EXACT_REPLACEMENTS = [
["[`HarmonySource::ChordByDegree`]", '`"chordByDegree"`'],
["[`MultiVoiceMode::Choir`]", '`"choir"`'],
["`None`", "`undefined`"],
["`0..=u64::MAX`", "from `0n` to `2n ** 64n - 1n` (inclusive)"],
["`u64::MAX`", "`2n ** 64n - 1n`"],
["`0x1234_abcd`", "`0x1234abcdn`"],
["`max_frequency_hz`", "`maxFrequencyHz`"],
Expand Down Expand Up @@ -164,6 +176,10 @@ const PROSE_REPLACEMENTS = [
/Change\s+a\s+copy,\s+then\s+apply\s+it\s+with\s+\[`crate::Processor::set_config`\]\s+or\s+\[`crate::ControlEvent::Configure`\]\./g,
'Change a copy, then apply it with `Tunelet.setConfig` or\n`{ type: "configure", value }` in `ControlEvent`.',
],
[
/Apply\s+a\s+patch\s+with\s+\[`crate::Processor::patch_config`\]\s+or\s+\[`crate::ControlEvent::Patch`\]\./g,
'Apply a patch with `Tunelet.patchConfig` or\n`{ type: "patch", value }` in `ControlEvent`.',
],
[
/The\s+MIDI\s+sources\s+use\s+\[`crate::ControlEvent::Midi`\]\./g,
'The MIDI sources use\n`{ type: "midi", value }` in `ControlEvent`.',
Expand Down
165 changes: 163 additions & 2 deletions scripts/verify-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,59 @@ function verifyRuntimeImport(consumerDir, packageName) {
" assert.equal(processor.config().resynthesis.correction.flexTune, 0);",
" assert.equal(processor.config().resynthesis.harmony.voices, 4);",
"",
" processor.patchConfig({",
" outputGain: 0.9,",
" resynthesis: {",
" correction: { humanize: 0.4, flexTune: 0.3 },",
" harmony: { chromaticIntervals: [3, 7, 10, 12] },",
" randomSeed: 7n,",
" },",
" });",
" assert.equal(Math.fround(processor.config().outputGain), Math.fround(0.9));",
" assert.equal(Math.fround(processor.config().resynthesis.correction.humanize), Math.fround(0.4));",
" assert.equal(Math.fround(processor.config().resynthesis.correction.flexTune), Math.fround(0.3));",
" assert.deepEqual(processor.config().resynthesis.harmony.chromaticIntervals, [3, 7, 10, 12]);",
" assert.equal(processor.config().resynthesis.randomSeed, 7n);",
" processor.patchConfig({",
" punch: undefined,",
" warm: { enabled: undefined, driveDb: undefined },",
" resynthesis: {",
" pitch: undefined,",
" correction: {",
" enabled: undefined,",
" notes: undefined,",
" retuneMs: undefined,",
" humanize: undefined,",
" flexTune: undefined,",
" },",
" formant: undefined,",
" harmony: {",
" chromaticIntervals: undefined,",
" diatonicIntervals: undefined,",
" voices: undefined,",
" },",
" randomSeed: undefined,",
" },",
" alien: undefined,",
" reverb: undefined,",
" outputGain: undefined,",
" });",
" assert.equal(Math.fround(processor.config().outputGain), Math.fround(0.9));",
" assert.equal(Math.fround(processor.config().resynthesis.correction.humanize), Math.fround(0.4));",
" assert.equal(Math.fround(processor.config().resynthesis.correction.flexTune), Math.fround(0.3));",
" assert.deepEqual(processor.config().resynthesis.harmony.chromaticIntervals, [3, 7, 10, 12]);",
" assert.equal(processor.config().resynthesis.randomSeed, 7n);",
" assert.equal(processor.controlActivity().choirVoices, true);",
' processor.patchConfig({ resynthesis: { mode: "harmony" } });',
" assert.equal(processor.controlActivity().choirVoices, false);",
"",
" const input = new Int16Array(128);",
" const left = new Int16Array(128);",
" const right = new Int16Array(128);",
' processor.process(input, left, right, [{ offset: 0, event: { type: "patch", value: { outputGain: undefined, resynthesis: { dryMix: 0.2, randomSeed: undefined } } } }]);',
" assert.equal(Math.fround(processor.config().outputGain), Math.fround(0.9));",
" assert.equal(Math.fround(processor.config().resynthesis.dryMix), Math.fround(0.2));",
" assert.equal(processor.config().resynthesis.randomSeed, 7n);",
' processor.process(input, left, right, [',
' { offset: 0, event: { type: "parameter", value: { type: "dryMix", value: 0.25 } } },',
' { offset: 0, event: { type: "parameter", value: { type: "humanize", value: 0.5 } } },',
Expand Down Expand Up @@ -736,19 +786,30 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" loadTunelet as namedLoadTunelet,",
" Tunelet,",
" TuneletAudioViews,",
" type AlienConfigPatch,",
" type ControlActivity,",
" type ControlEvent,",
" type CorrectionConfigPatch,",
" type FormantConfigPatch,",
" type HarmonyConfigPatch,",
" type ParameterControl,",
" type PitchConfigPatch,",
" type ProcessorConfig,",
" type ProcessorConfigPatch,",
" type PunchConfigPatch,",
" type ResynthesisConfig,",
" type ResynthesisConfigPatch,",
" type ReverbConfigPatch,",
" type SyncInitInput as RootSyncInitInput,",
" type Telemetry,",
" type WarmConfigPatch,",
`} from ${pkgLiteral};`,
"import init, {",
" initSync as wasmInitSync,",
" type InitInput,",
" type InitOutput,",
" type ParameterControl as WasmParameterControl,",
" type ProcessorConfigPatch as WasmProcessorConfigPatch,",
" type SyncInitInput,",
`} from ${wasmLiteral};`,
"",
Expand Down Expand Up @@ -800,6 +861,103 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" }",
" const processor = new Tunelet(48000, 128, configWithUndefined);",
" processor.setConfig(configWithUndefined);",
" const punchPatch: PunchConfigPatch = {",
" enabled: true,",
" gainDb: optionalVoices,",
" impact: undefined,",
" ceilingDb: undefined,",
" attackMs: undefined,",
" };",
" const warmPatch: WarmConfigPatch = {",
" enabled: undefined,",
" driveDb: optionalVoices ?? 2,",
" };",
" const pitchPatch: PitchConfigPatch = {",
" threshold: undefined,",
" minFrequencyHz: 80,",
" maxFrequencyHz: optionalVoices,",
" };",
" const correctionPatch: CorrectionConfigPatch = {",
" enabled: undefined,",
" notes: undefined,",
" retuneMs: 15,",
" humanize: optionalVoices,",
" flexTune: optionalVoices,",
" };",
" const formantPatch: FormantConfigPatch = {",
" enabled: undefined,",
" width: 1.1,",
" stretch: undefined,",
" aspirationMix: optionalVoices,",
" aspirationCutoffHz: undefined,",
" };",
" const harmonyPatch: HarmonyConfigPatch = {",
" source: undefined,",
" key: undefined,",
" scale: undefined,",
" chromaticIntervals: undefined,",
" diatonicIntervals: undefined,",
" chord: undefined,",
" degree: undefined,",
" inversion: undefined,",
" registerPercent: optionalVoices,",
" voicingSpreadPercent: undefined,",
" portamentoMs: undefined,",
" voices: optionalVoices,",
" };",
" const resynthesisPatch: ResynthesisConfigPatch = {",
" pitch: pitchPatch,",
" correction: correctionPatch,",
" pitchRatio: optionalVoices,",
" formant: formantPatch,",
" mode: undefined,",
" choirVoices: optionalVoices,",
" choirDetune: undefined,",
" choirDelay: undefined,",
" choirSpreadPercent: undefined,",
" stereoOutput: undefined,",
" harmony: harmonyPatch,",
" harmonyGain: undefined,",
" harmonicModulation: undefined,",
" dryMix: 0.2,",
" randomSeed: undefined,",
" };",
" const alienPatch: AlienConfigPatch = {",
" enabled: undefined,",
" loopFrames: 1000,",
" };",
" const reverbPatch: ReverbConfigPatch = {",
" enabled: undefined,",
" mode: undefined,",
" mix: 0.4,",
" diffusion: optionalVoices,",
" decay: undefined,",
" brightnessHz: undefined,",
" };",
" const patch: ProcessorConfigPatch & WasmProcessorConfigPatch = {",
" punch: punchPatch,",
" warm: warmPatch,",
" resynthesis: resynthesisPatch,",
" alien: alienPatch,",
" reverb: reverbPatch,",
" outputGain: optionalVoices,",
" };",
" const emptyUndefinedPatch: ProcessorConfigPatch & WasmProcessorConfigPatch = {",
" punch: undefined,",
" warm: undefined,",
" resynthesis: {",
" pitch: undefined,",
" correction: undefined,",
" formant: undefined,",
" harmony: undefined,",
" },",
" alien: undefined,",
" reverb: undefined,",
" outputGain: undefined,",
" };",
' const patchEvent: ControlEvent = { type: "patch", value: patch };',
" processor.patchConfig(patch);",
" processor.patchConfig(emptyUndefinedPatch);",
" const activity: ControlActivity = processor.controlActivity();",
" const telemetry: Telemetry = processor.telemetry();",
" const voiceSlices: [Float32Array, Float32Array] = [",
Expand Down Expand Up @@ -843,6 +1001,7 @@ function verifyTypeDeclarations(consumerDir, packageName) {
' const flexTuneParameter: ParameterControl & WasmParameterControl = { type: "flexTune", value: 0.25 };',
' const parameterEvent: ControlEvent = { type: "parameter", value: dryMixParameter };',
" processor.process(input, left, right, [",
" { offset: 0, event: patchEvent },",
" { offset: 0, event: parameterEvent },",
' { offset: 0, event: { type: "parameter", value: humanizeParameter } },',
' { offset: 0, event: { type: "parameter", value: flexTuneParameter } },',
Expand All @@ -857,6 +1016,7 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" processor.processF32(inputF32, leftF32, rightF32, [",
' { offset: 0, event: { type: "outputGain", value: 1 } },',
" { offset: 0, event: parameterEvent },",
" { offset: 64, event: patchEvent },",
" ]);",
" processor.processMonoF32(inputF32);",
" processor.beginDrain();",
Expand Down Expand Up @@ -1176,8 +1336,8 @@ function verifyNormalizedJsDoc(consumerDir, packageName) {

const throwsCount = [...dts.matchAll(/\* @throws /g)].length;
assert.ok(
throwsCount >= 14,
`Expected at least 14 @throws tags, found ${throwsCount}`,
throwsCount >= 15,
`Expected at least 15 @throws tags, found ${throwsCount}`,
);

const fallibleSignatures = [
Expand All @@ -1188,6 +1348,7 @@ function verifyNormalizedJsDoc(consumerDir, packageName) {
["feedback", /(\/\*\*(?:(?!\*\/)[\s\S])*\*\/)\s+feedback\(\): Feedback;/],
["formantEnvelope", /(\/\*\*(?:(?!\*\/)[\s\S])*\*\/)\s+formantEnvelope\([^)]*\): boolean;/],
["constructor", /(\/\*\*(?:(?!\*\/)[\s\S])*\*\/)\s+constructor\([^)]*\);/],
["patchConfig", /(\/\*\*(?:(?!\*\/)[\s\S])*\*\/)\s+patchConfig\(patch: ProcessorConfigPatch\): void;/],
["processMono", /(\/\*\*(?:(?!\*\/)[\s\S])*\*\/)\s+processMono\([^)]*\): void;/],
["process", /(\/\*\*(?:(?!\*\/)[\s\S])*\*\/)\s+process\([^)]*\): void;/],
["setConfig", /(\/\*\*(?:(?!\*\/)[\s\S])*\*\/)\s+setConfig\(config: ProcessorConfig\): void;/],
Expand Down
Loading
Loading