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
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ browsers and Node.js.
[GitHub Packages](https://github.com/ByteLandTechnology/tunelet/pkgs/npm/tunelet) ·
[API documentation](https://docs.rs/tunelet)

![The tunelet signal chain: Punch, Warm, pitch tracking and resynthesis, Alien, reverb and the output gain](docs/images/signal-chain.svg)
![The tunelet signal chain: Punch, Warm, pitch tracking and resynthesis, Alien, reverb, the output gain, the global mix, the global bypass and the dry paths](docs/images/signal-chain.svg)

## Contents

Expand Down Expand Up @@ -170,20 +170,25 @@ voice. It disables the effects and the formant stage.
| Formant | Changes the vocal tract with an LPC model and aspiration | Disabled | `resynthesis.formant` |
| Alien | Plays recent audio in reverse loops | Disabled | `alien` |
| Reverb | Echo, Schroeder, SmallRoom, Binaural, MediumHall, LargeHall | Disabled | `reverb` |
| Output gain | Linear gain, 0..=64, before `-32767..=32767` clipping | 1 | `output_gain` |
| Output gain | Linear gain, 0..=64, before `-32767..=32767` wet clamp | 1 | `output_gain` |
| Global mix | Wet fraction, 0..=1, with 1,593-frame raw dry path | 1 | `mix` |
| Global bypass | 200-frame crossfade to 1,593-frame raw dry path | Disabled | `bypass` |

The internal Q14 stages use `i64` products and saturate at the `i32`
limits. Decrease `output_gain` to prevent `-32767..=32767` clipping on
limits. Decrease `output_gain` to prevent `-32767..=32767` saturation on
multi-voice mixes.

`resynthesis.correction.humanize` sets the relaxation on sustained notes, in
`0..=1`. The default is 0. `resynthesis.correction.flex_tune` sets the outer
fraction of each half-bin where pull toward the target decreases, in `0..=1`.
The default is 0, which applies full pull across the whole bin.

`resynthesis.dry_mix` sets the dry fraction at the resynthesis stage. The
dry path starts after Warm and has a delay of 1,593 frames. All six reverb
modes keep the stereo dry signal.
`punch.mix`, `warm.mix`, `alien.mix` and `reverb.mix` set the Q14 wet
fraction of each effect stage, in `0..=1`. In Warm, the 50 Hz high-pass
filter operates only on the wet path. All six reverb modes keep the stereo
dry signal. `resynthesis.dry_mix` sets the dry fraction after Warm, with a
delay of 1,593 frames. `mix` and `bypass` use the raw input before Punch,
with the same 1,593-frame delay.

### Harmony sources

Expand Down Expand Up @@ -261,8 +266,9 @@ These rules apply to the offsets:
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()`.
`ParameterControl` variant. `ControlEvent::OutputGain`, `ControlEvent::Mix` and
`ControlEvent::Bypass` update `output_gain`, `mix` and `bypass` directly. For
other fields, 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 @@ -579,7 +585,8 @@ and show enums as string literals. To change the configuration, do these steps:

If a required field is absent or a value is not valid, the call throws a
JavaScript `Error`. If an optional field is absent or `undefined`, it gets its
default. `resynthesis.correction.humanize` and
default. `mix`, `punch.mix`, `warm.mix` and `alien.mix` default to 1, and
`bypass` defaults to `false`. `resynthesis.correction.humanize` and
`resynthesis.correction.flexTune` default to 0, and
`resynthesis.harmony.voices` defaults to 4. The conversion ignores extra object
properties. The generated declarations contain the parameter documentation from
Expand All @@ -592,8 +599,10 @@ telemetry use `bigint`. Frame offsets, block lengths and latency use
### Events

The optional event argument is a `TimedEvent[]`. Controls use a `type`
discriminant and a `value` payload. The reset control has no payload. For
example, this event changes the final gain before the first frame:
discriminant and a `value` payload (`configure`, `resynthesis`, `punch`,
`warm`, `alien`, `reverb`, `outputGain`, `mix`, `bypass`, `parameter`, `midi`
and `correctionMidi`). The `reset` control has no payload. For example, this
event changes the final gain before the first frame:

```ts
{ offset: 0, event: { type: "outputGain", value: 0.5 } }
Expand Down
119 changes: 67 additions & 52 deletions docs/images/signal-chain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions scripts/verify-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,21 @@ function verifyRuntimeImport(consumerDir, packageName) {
"assert.ok(wasmExports.memory instanceof WebAssembly.Memory);",
"",
"const initialConfig = rootModule.defaultConfig();",
"initialConfig.mix = undefined;",
"initialConfig.bypass = undefined;",
"initialConfig.punch.mix = undefined;",
"initialConfig.warm.mix = undefined;",
"initialConfig.alien.mix = undefined;",
"initialConfig.resynthesis.correction.humanize = undefined;",
"initialConfig.resynthesis.correction.flexTune = undefined;",
"initialConfig.resynthesis.harmony.voices = undefined;",
"const processor = new rootModule.Tunelet(48000, 128, initialConfig);",
"try {",
" assert.equal(processor.config().mix, 1);",
" assert.equal(processor.config().bypass, false);",
" assert.equal(processor.config().punch.mix, 1);",
" assert.equal(processor.config().warm.mix, 1);",
" assert.equal(processor.config().alien.mix, 1);",
" assert.equal(processor.config().resynthesis.correction.humanize, 0);",
" assert.equal(processor.config().resynthesis.correction.flexTune, 0);",
" assert.equal(processor.config().resynthesis.harmony.voices, 4);",
Expand Down Expand Up @@ -352,9 +362,19 @@ function verifyRuntimeImport(consumerDir, packageName) {
" assert.equal(processor.config().resynthesis.correction.flexTune, 0.25);",
"",
" const omittedCorrectionConfig = processor.config();",
" delete omittedCorrectionConfig.mix;",
" delete omittedCorrectionConfig.bypass;",
" delete omittedCorrectionConfig.punch.mix;",
" delete omittedCorrectionConfig.warm.mix;",
" delete omittedCorrectionConfig.alien.mix;",
" delete omittedCorrectionConfig.resynthesis.correction.humanize;",
" delete omittedCorrectionConfig.resynthesis.correction.flexTune;",
" processor.setConfig(omittedCorrectionConfig);",
" assert.equal(processor.config().mix, 1);",
" assert.equal(processor.config().bypass, false);",
" assert.equal(processor.config().punch.mix, 1);",
" assert.equal(processor.config().warm.mix, 1);",
" assert.equal(processor.config().alien.mix, 1);",
" assert.equal(processor.config().resynthesis.correction.humanize, 0);",
" assert.equal(processor.config().resynthesis.correction.flexTune, 0);",
"",
Expand All @@ -365,7 +385,11 @@ function verifyRuntimeImport(consumerDir, packageName) {
" eventResynthesis.harmony.voices = undefined;",
" processor.processMono(mono, [",
' { offset: 0, event: { type: "resynthesis", value: eventResynthesis } },',
' { offset: 1, event: { type: "mix", value: 0.5 } },',
' { offset: 2, event: { type: "bypass", value: true } },',
" ]);",
" assert.equal(processor.config().mix, 0.5);",
" assert.equal(processor.config().bypass, true);",
" assert.equal(processor.config().resynthesis.correction.humanize, 0);",
" assert.equal(processor.config().resynthesis.correction.flexTune, 0);",
" assert.equal(processor.config().resynthesis.harmony.voices, 4);",
Expand Down Expand Up @@ -772,6 +796,20 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" const baseConfig: ProcessorConfig = defaultConfig();",
" const configWithUndefined: ProcessorConfig = {",
" ...baseConfig,",
" mix: optionalVoices,",
" bypass: undefined,",
" punch: {",
" ...baseConfig.punch,",
" mix: optionalVoices,",
" },",
" warm: {",
" ...baseConfig.warm,",
" mix: optionalVoices,",
" },",
" alien: {",
" ...baseConfig.alien,",
" mix: optionalVoices,",
" },",
" resynthesis: {",
" ...baseConfig.resynthesis,",
" correction: {",
Expand Down Expand Up @@ -856,6 +894,8 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" processor.processF32(inputF32, leftF32, rightF32);",
" processor.processF32(inputF32, leftF32, rightF32, [",
' { offset: 0, event: { type: "outputGain", value: 1 } },',
' { offset: 0, event: { type: "mix", value: 1 } },',
' { offset: 0, event: { type: "bypass", value: false } },',
" { offset: 0, event: parameterEvent },",
" ]);",
" processor.processMonoF32(inputF32);",
Expand Down
Loading
Loading