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
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ multi-voice mixes.
`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.correction.pitch_bend_semitones` sets the maximum correction pitch
bend, in `0..=24`. The default is 2.

`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
Expand All @@ -203,7 +205,8 @@ with `resynthesis.harmony.source`:
`resynthesis.harmony.voices` sets the number of interval voices, in `0..=4`.
The default is 4. `FixedInterval` and `SmartInterval` use the first `voices`
voices. The other voices release with the usual gain envelope. The chord
and MIDI sources ignore this field.
and MIDI sources ignore this field. `resynthesis.harmony.pitch_bend_semitones`
sets the maximum harmony pitch bend, in `0..=24`. The default is 2.

`resynthesis.harmony_gain` scales the four harmony voices in mono and in
stereo. It does not scale the lead voice.
Expand Down Expand Up @@ -580,7 +583,9 @@ 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
`resynthesis.correction.flexTune` default to 0, and
`resynthesis.correction.flexTune` default to 0,
`resynthesis.correction.pitchBendSemitones` and
`resynthesis.harmony.pitchBendSemitones` default to 2 (in `0..=24`), and
`resynthesis.harmony.voices` defaults to 4. The conversion ignores extra object
properties. The generated declarations contain the parameter documentation from
the Rust types.
Expand Down Expand Up @@ -611,6 +616,16 @@ A harmony Note On event has this form:
{ offset: 0, event: { type: "midi", value: { type: "noteOn", channel: 0, note: 60, velocity: 100 } } }
```

MIDI events also accept `"noteOff"`, `"pitchBend"` (`channel` in `0..=15`,
`value` in `-8192..=8191`), `"sustainPedal"` (`channel` in `0..=15`, `held` as
a `boolean`) and `"allNotesOff"`. For example, these events hold the sustain
pedal and bend the pitch upward:

```ts
{ offset: 0, event: { type: "midi", value: { type: "sustainPedal", channel: 0, held: true } } }
{ offset: 0, event: { type: "midi", value: { type: "pitchBend", channel: 0, value: 4096 } } }
```

Use `correctionMidi` for the separate correction keyboard. The native rules
for event order and for the validation of the whole block also apply to these
bindings.
Expand Down
11 changes: 10 additions & 1 deletion scripts/normalize-jsdoc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const EXACT_REPLACEMENTS = [
],
["[`crate::HarmonyConfig::portamento_ms`]", "`HarmonyConfig.portamentoMs`"],
["[`crate::HarmonyConfig::voices`]", "`HarmonyConfig.voices`"],
[
"[`crate::HarmonyConfig::pitch_bend_semitones`]",
"`HarmonyConfig.pitchBendSemitones`",
],
["[`ReverbConfig::mode`]", "`ReverbConfig.mode`"],
["[`ReverbConfig::mix`]", "`ReverbConfig.mix`"],
["[`ReverbConfig::diffusion`]", "`ReverbConfig.diffusion`"],
Expand All @@ -95,12 +99,17 @@ const EXACT_REPLACEMENTS = [
["[`Self::Echo`]", '`"echo"`'],
["[`ReverbMode::Echo`]", '`"echo"`'],
["[`Self::MidiChannels`]", '`"midiChannels"`'],
["[`crate::HarmonySource::MidiChannels`]", '`"midiChannels"`'],
["[`crate::HarmonySource::MidiOmni`]", '`"midiOmni"`'],
["[`crate::HarmonySource::ChordViaMidi`]", '`"chordViaMidi"`'],
["[`HarmonySource::MidiChannels`]", '`"midiChannels"`'],
["[`HarmonySource::FixedInterval`]", '`"fixedInterval"`'],
["[`HarmonySource::SmartInterval`]", '`"smartInterval"`'],
["[`HarmonySource::ChordByName`]", '`"chordByName"`'],
["[`HarmonySource::ChordByDegree`]", '`"chordByDegree"`'],
["[`MultiVoiceMode::Choir`]", '`"choir"`'],
["[`MidiEvent::PitchBend`]", '`"pitchBend"`'],
["[`Self::NoteOff`]", '`"noteOff"`'],
["`None`", "`undefined`"],
["`u64::MAX`", "`2n ** 64n - 1n`"],
["`0x1234_abcd`", "`0x1234abcdn`"],
Expand Down Expand Up @@ -157,7 +166,7 @@ const PROSE_REPLACEMENTS = [
"The default enables all twelve pitch classes (`true` in every slot). All\ncombinations of flags are valid, which includes all `false` values.",
],
[
/Use\s+\[`crate::ControlEvent::Midi`\]\s+for\s+harmony\.\s+Use\s+\[`crate::ControlEvent::CorrectionMidi`\]\s+for\s+the\s+independent\s+correction\s+keyboard\.\s+The\s+typed\s+representation\s+can\s+contain\s+`u8`\s+values\s+that\s+are\s+not\s+valid\.\s+\[`Self::validate`\]\s+and\s+the\s+event\s+preflight\s+of\s+the\s+processor\s+check\s+the\s+MIDI\s+ranges\./g,
/Use\s+\[`crate::ControlEvent::Midi`\]\s+for\s+harmony\.\s+Use\s+\[`crate::ControlEvent::CorrectionMidi`\]\s+for\s+the\s+independent\s+correction\s+keyboard\.\s+The\s+typed\s+representation\s+can\s+contain\s+`u8`\s+and\s+`i16`\s+values\s+that\s+are\s+not\s+valid\.\s+\[`Self::validate`\]\s+and\s+the\s+event\s+preflight\s+of\s+the\s+processor\s+check\s+the\s+MIDI\s+ranges\./g,
'Use `{ type: "midi", value }` in `ControlEvent` for harmony. Use\n`{ type: "correctionMidi", value }` for the independent correction\nkeyboard. Number fields can hold values outside the MIDI ranges, and\n`Tunelet` checks the ranges before it processes a block.',
],
[
Expand Down
36 changes: 36 additions & 0 deletions scripts/verify-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,18 @@ function verifyRuntimeImport(consumerDir, packageName) {
"const initialConfig = rootModule.defaultConfig();",
"initialConfig.resynthesis.correction.humanize = undefined;",
"initialConfig.resynthesis.correction.flexTune = undefined;",
"initialConfig.resynthesis.correction.pitchBendSemitones = undefined;",
"initialConfig.resynthesis.harmony.voices = undefined;",
"initialConfig.resynthesis.harmony.pitchBendSemitones = undefined;",
"const processor = new rootModule.Tunelet(48000, 128, initialConfig);",
"try {",
" assert.equal(processor.config().resynthesis.correction.humanize, 0);",
" assert.equal(processor.config().resynthesis.correction.flexTune, 0);",
" assert.equal(processor.config().resynthesis.correction.pitchBendSemitones, 2);",
" assert.equal(processor.config().resynthesis.harmony.voices, 4);",
" assert.equal(processor.config().resynthesis.harmony.pitchBendSemitones, 2);",
" assert.equal(typeof processor.controlActivity().choirVoices, \"boolean\");",
" assert.equal(typeof processor.controlActivity().harmonyPitchBendSemitones, \"boolean\");",
" const initialTelemetry = processor.telemetry();",
" assert.ok(initialTelemetry.voiceRatios instanceof Float32Array);",
" assert.ok(initialTelemetry.voiceGains instanceof Float32Array);",
Expand Down Expand Up @@ -354,21 +359,44 @@ function verifyRuntimeImport(consumerDir, packageName) {
" const omittedCorrectionConfig = processor.config();",
" delete omittedCorrectionConfig.resynthesis.correction.humanize;",
" delete omittedCorrectionConfig.resynthesis.correction.flexTune;",
" delete omittedCorrectionConfig.resynthesis.correction.pitchBendSemitones;",
" delete omittedCorrectionConfig.resynthesis.harmony.pitchBendSemitones;",
" processor.setConfig(omittedCorrectionConfig);",
" assert.equal(processor.config().resynthesis.correction.humanize, 0);",
" assert.equal(processor.config().resynthesis.correction.flexTune, 0);",
" assert.equal(processor.config().resynthesis.correction.pitchBendSemitones, 2);",
" assert.equal(processor.config().resynthesis.harmony.pitchBendSemitones, 2);",
"",
" const mono = new Int16Array(128);",
" const eventResynthesis = processor.config().resynthesis;",
" eventResynthesis.correction.humanize = undefined;",
" eventResynthesis.correction.flexTune = undefined;",
" eventResynthesis.correction.pitchBendSemitones = undefined;",
" eventResynthesis.harmony.voices = undefined;",
" eventResynthesis.harmony.pitchBendSemitones = undefined;",
" processor.processMono(mono, [",
' { offset: 0, event: { type: "resynthesis", value: eventResynthesis } },',
" ]);",
" assert.equal(processor.config().resynthesis.correction.humanize, 0);",
" assert.equal(processor.config().resynthesis.correction.flexTune, 0);",
" assert.equal(processor.config().resynthesis.correction.pitchBendSemitones, 2);",
" assert.equal(processor.config().resynthesis.harmony.voices, 4);",
" assert.equal(processor.config().resynthesis.harmony.pitchBendSemitones, 2);",
" processor.processMono(mono, [",
' { offset: 0, event: { type: "midi", value: { type: "sustainPedal", channel: 0, held: true } } },',
' { offset: 0, event: { type: "midi", value: { type: "noteOn", channel: 0, note: 60, velocity: 100 } } },',
' { offset: 16, event: { type: "midi", value: { type: "pitchBend", channel: 0, value: 4096 } } },',
' { offset: 32, event: { type: "midi", value: { type: "noteOff", channel: 0, note: 60 } } },',
' { offset: 48, event: { type: "correctionMidi", value: { type: "sustainPedal", channel: 0, held: true } } },',
' { offset: 48, event: { type: "correctionMidi", value: { type: "noteOn", channel: 0, note: 69, velocity: 100 } } },',
' { offset: 64, event: { type: "correctionMidi", value: { type: "pitchBend", channel: 0, value: -4096 } } },',
' { offset: 80, event: { type: "correctionMidi", value: { type: "noteOff", channel: 0, note: 69 } } },',
' { offset: 96, event: { type: "midi", value: { type: "sustainPedal", channel: 0, held: false } } },',
' { offset: 96, event: { type: "correctionMidi", value: { type: "sustainPedal", channel: 0, held: false } } },',
' { offset: 112, event: { type: "midi", value: { type: "pitchBend", channel: 0, value: 0 } } },',
' { offset: 112, event: { type: "correctionMidi", value: { type: "pitchBend", channel: 0, value: 0 } } },',
" ]);",
" assert.equal(processor.feedback().processedFrames, 256n);",
"",
" const input = new Int16Array(128);",
" const left = new Int16Array(128);",
Expand Down Expand Up @@ -738,6 +766,7 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" TuneletAudioViews,",
" type ControlActivity,",
" type ControlEvent,",
" type MidiEvent,",
" type ParameterControl,",
" type ProcessorConfig,",
" type ResynthesisConfig,",
Expand All @@ -748,6 +777,7 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" initSync as wasmInitSync,",
" type InitInput,",
" type InitOutput,",
" type MidiEvent as WasmMidiEvent,",
" type ParameterControl as WasmParameterControl,",
" type SyncInitInput,",
`} from ${wasmLiteral};`,
Expand Down Expand Up @@ -778,10 +808,12 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" ...baseConfig.resynthesis.correction,",
" humanize: optionalVoices,",
" flexTune: optionalVoices,",
" pitchBendSemitones: optionalVoices,",
" },",
" harmony: {",
" ...baseConfig.resynthesis.harmony,",
" voices: optionalVoices,",
" pitchBendSemitones: optionalVoices,",
" },",
" },",
" };",
Expand Down Expand Up @@ -835,8 +867,12 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" const input = new Int16Array(128);",
" const left = new Int16Array(128);",
" const right = new Int16Array(128);",
' const bendEvent: MidiEvent & WasmMidiEvent = { type: "pitchBend", channel: 0, value: 4096 };',
' const sustainEvent: MidiEvent & WasmMidiEvent = { type: "sustainPedal", channel: 0, held: true };',
" processor.processMono(input, [",
' { offset: 0, event: { type: "resynthesis", value: resynthesisUpdate } },',
' { offset: 0, event: { type: "midi", value: sustainEvent } },',
' { offset: 0, event: { type: "correctionMidi", value: bendEvent } },',
" ]);",
' const dryMixParameter: ParameterControl & WasmParameterControl = { type: "dryMix", value: 0.25 };',
' const humanizeParameter: ParameterControl & WasmParameterControl = { type: "humanize", value: 0.5 };',
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ impl ProcessorConfig {
harmony_voicing_spread_percent: harmony && chord,
harmony_portamento_ms: harmony && (!interval || interval_voices),
harmony_voices: harmony && interval,
harmony_pitch_bend_semitones: harmony && (!interval || interval_voices),
harmony_gain: harmony && (!interval || interval_voices),
reverb_mode: reverb,
reverb_mix: reverb,
Expand Down Expand Up @@ -312,6 +313,8 @@ pub struct ControlActivity {
pub harmony_portamento_ms: bool,
/// `true` if [`crate::HarmonyConfig::voices`] is active.
pub harmony_voices: bool,
/// `true` if [`crate::HarmonyConfig::pitch_bend_semitones`] is active.
pub harmony_pitch_bend_semitones: bool,
/// `true` if [`ResynthesisConfig::harmony_gain`] is active.
pub harmony_gain: bool,
/// `true` if [`ReverbConfig::mode`] is active.
Expand Down
Loading
Loading