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
46 changes: 32 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,36 @@ modes keep the stereo dry signal.
Set `resynthesis.mode` to `Harmony`. Then select the source of the voices
with `resynthesis.harmony.source`:

| Source | The voices follow |
| --------------- | ------------------------------------------------------ |
| `FixedInterval` | A fixed number of semitones from the singer |
| `SmartInterval` | An interval in scale steps, in a key and a scale |
| `ChordByDegree` | A chord on a scale degree |
| `ChordByName` | A named chord, for example `MinorSeventh` |
| `ChordViaMidi` | The active MIDI notes, as a chord |
| `MidiOmni` | MIDI notes from all channels, on the first free voice |
| `MidiChannels` | MIDI channel `n` for voice `n` (channels 0–3), default |
| Source | The voices follow |
| --------------- | ----------------------------------------------------------------- |
| `FixedInterval` | A fixed number of semitones from the singer |
| `SmartInterval` | An interval in scale steps, in a key and a scale |
| `ChordByDegree` | A chord on a scale degree |
| `ChordByName` | A named chord, for example `MinorSeventh` |
| `ChordViaMidi` | The active MIDI notes, as a chord |
| `MidiOmni` | MIDI notes from all channels, on the first free voice |
| `MidiChannels` | MIDI channels from `midi_channel_map` for four voices, default |

`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.

For `MidiChannels`, `resynthesis.harmony.midi_channel_map` selects `BaseWindow`
(default) or `WrapFour`. `BaseWindow` assigns channels
`midi_base_channel..=midi_base_channel + 3` to the four voices, with
`midi_base_channel` in `0..=12` (default 0). `WrapFour` assigns channel `c` in
`0..=15` to voice `c % 4` and ignores `midi_base_channel`. Other harmony sources
ignore both fields. A 16-channel keybed keeps held notes across live changes
among `MidiOmni`, `ChordViaMidi` and `MidiChannels`. On legato release, a voice
resumes the next newest held note.

For `ControlEvent::CorrectionMidi`, `resynthesis.correction.midi_mode` selects
`Momentary` (default) or `Latch` across notes `0..=127`. If all keys release in
`Momentary` mode, `resynthesis.correction.notes` loads again. `Latch` keeps the
chord after key release until `MidiEvent::AllNotesOff`, `reset()` or a scale
change.

`resynthesis.harmony_gain` scales the four harmony voices in mono and in
stereo. It does not scale the lead voice.

Expand Down Expand Up @@ -365,8 +380,8 @@ These calls read the state of the processor. They do not change the audio.

`Processor::control_activity()` and `ProcessorConfig::control_activity()`
return a `ControlActivity` struct. A `false` flag means that the related
control makes no sample change in the active voice mode, harmony source or
reverb network.
control makes no sample change in the active voice mode, harmony source,
channel map or reverb network.

The telemetry includes these items:

Expand Down Expand Up @@ -581,9 +596,12 @@ 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.harmony.voices` defaults to 4. The conversion ignores extra object
properties. The generated declarations contain the parameter documentation from
the Rust types.
`resynthesis.correction.midiMode` defaults to `"momentary"`.
`resynthesis.harmony.voices` defaults to 4,
`resynthesis.harmony.midiChannelMap` defaults to `"baseWindow"` and
`resynthesis.harmony.midiBaseChannel` defaults to 0. The conversion ignores
extra object properties. The generated declarations contain the parameter
documentation from the Rust types.

`resynthesis.randomSeed` and the `processedFrames` field of feedback and
telemetry use `bigint`. Frame offsets, block lengths and latency use
Expand Down
36 changes: 36 additions & 0 deletions scripts/normalize-jsdoc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ const EXACT_REPLACEMENTS = [
],
["[`crate::HarmonyConfig::portamento_ms`]", "`HarmonyConfig.portamentoMs`"],
["[`crate::HarmonyConfig::voices`]", "`HarmonyConfig.voices`"],
[
"[`crate::HarmonyConfig::midi_channel_map`]",
"`HarmonyConfig.midiChannelMap`",
],
["[`HarmonyConfig::midi_channel_map`]", "`HarmonyConfig.midiChannelMap`"],
[
"[`crate::HarmonyConfig::midi_base_channel`]",
"`HarmonyConfig.midiBaseChannel`",
],
["[`HarmonyConfig::midi_base_channel`]", "`HarmonyConfig.midiBaseChannel`"],
["[`crate::CorrectionConfig::notes`]", "`CorrectionConfig.notes`"],
["[`CorrectionConfig::notes`]", "`CorrectionConfig.notes`"],
[
"[`crate::ControlEvent::CorrectionMidi`]",
'`{ type: "correctionMidi", value }`',
],
["[`MidiEvent::AllNotesOff`]", '`{ type: "allNotesOff" }`'],
["[`ReverbConfig::mode`]", "`ReverbConfig.mode`"],
["[`ReverbConfig::mix`]", "`ReverbConfig.mix`"],
["[`ReverbConfig::diffusion`]", "`ReverbConfig.diffusion`"],
Expand All @@ -85,7 +102,10 @@ const EXACT_REPLACEMENTS = [
["[`TimedEvent`]", "`TimedEvent`"],
["[`HarmonyScale`]", "`HarmonyScale`"],
["[`Feedback`]", "`Feedback`"],
["[`crate::HarmonyConfig`]", "`HarmonyConfig`"],
["[`HarmonyConfig`]", "`HarmonyConfig`"],
["[`MidiChannelMap`]", "`MidiChannelMap`"],
["[`CorrectionMidiMode`]", "`CorrectionMidiMode`"],
[
"[`ControlEvent::Parameter`]",
'`{ type: "parameter", value }` in `ControlEvent`',
Expand All @@ -94,12 +114,20 @@ const EXACT_REPLACEMENTS = [
["[`Self::I`]", '`"i"`'],
["[`Self::Echo`]", '`"echo"`'],
["[`ReverbMode::Echo`]", '`"echo"`'],
["[`Self::MidiOmni`]", '`"midiOmni"`'],
["[`HarmonySource::MidiOmni`]", '`"midiOmni"`'],
["[`Self::MidiChannels`]", '`"midiChannels"`'],
["[`HarmonySource::MidiChannels`]", '`"midiChannels"`'],
["[`HarmonySource::FixedInterval`]", '`"fixedInterval"`'],
["[`HarmonySource::SmartInterval`]", '`"smartInterval"`'],
["[`HarmonySource::ChordByName`]", '`"chordByName"`'],
["[`HarmonySource::ChordByDegree`]", '`"chordByDegree"`'],
["[`MidiChannelMap::BaseWindow`]", '`"baseWindow"`'],
["[`MidiChannelMap::WrapFour`]", '`"wrapFour"`'],
["[`crate::CorrectionMidiMode::Momentary`]", '`"momentary"`'],
["[`CorrectionMidiMode::Momentary`]", '`"momentary"`'],
["[`crate::CorrectionMidiMode::Latch`]", '`"latch"`'],
["[`CorrectionMidiMode::Latch`]", '`"latch"`'],
["[`MultiVoiceMode::Choir`]", '`"choir"`'],
["`None`", "`undefined`"],
["`u64::MAX`", "`2n ** 64n - 1n`"],
Expand All @@ -108,6 +136,14 @@ const EXACT_REPLACEMENTS = [
["`min_frequency_hz`", "`minFrequencyHz`"],
["`stereo_output`", "`stereoOutput`"],
["`retune_ms`", "`retuneMs`"],
["`pitch_ratio`", "`pitchRatio`"],
["`flex_tune`", "`flexTune`"],
["`midi_channel_map`", "`midiChannelMap`"],
["`midi_base_channel..=midi_base_channel + 3`", "`midiBaseChannel..=midiBaseChannel + 3`"],
["`c - midi_base_channel`", "`c - midiBaseChannel`"],
["`midi_base_channel + n`", "`midiBaseChannel + n`"],
["`midi_base_channel`", "`midiBaseChannel`"],
["`midi_mode`", "`midiMode`"],
["`attack_ms`", "`attackMs`"],
["`gain_db`", "`gainDb`"],
["`ceiling_db`", "`ceilingDb`"],
Expand Down
48 changes: 47 additions & 1 deletion scripts/verify-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,18 @@ function verifyRuntimeImport(consumerDir, packageName) {
"const initialConfig = rootModule.defaultConfig();",
"initialConfig.resynthesis.correction.humanize = undefined;",
"initialConfig.resynthesis.correction.flexTune = undefined;",
"initialConfig.resynthesis.correction.midiMode = undefined;",
"initialConfig.resynthesis.harmony.voices = undefined;",
"initialConfig.resynthesis.harmony.midiChannelMap = undefined;",
"initialConfig.resynthesis.harmony.midiBaseChannel = 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.midiMode, "momentary");',
" assert.equal(processor.config().resynthesis.harmony.voices, 4);",
' assert.equal(processor.config().resynthesis.harmony.midiChannelMap, "baseWindow");',
" assert.equal(processor.config().resynthesis.harmony.midiBaseChannel, 0);",
" assert.equal(typeof processor.controlActivity().choirVoices, \"boolean\");",
" const initialTelemetry = processor.telemetry();",
" assert.ok(initialTelemetry.voiceRatios instanceof Float32Array);",
Expand Down Expand Up @@ -354,9 +360,15 @@ function verifyRuntimeImport(consumerDir, packageName) {
" const omittedCorrectionConfig = processor.config();",
" delete omittedCorrectionConfig.resynthesis.correction.humanize;",
" delete omittedCorrectionConfig.resynthesis.correction.flexTune;",
" delete omittedCorrectionConfig.resynthesis.correction.midiMode;",
" delete omittedCorrectionConfig.resynthesis.harmony.midiChannelMap;",
" delete omittedCorrectionConfig.resynthesis.harmony.midiBaseChannel;",
" 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.midiMode, "momentary");',
' assert.equal(processor.config().resynthesis.harmony.midiChannelMap, "baseWindow");',
" assert.equal(processor.config().resynthesis.harmony.midiBaseChannel, 0);",
"",
" const mono = new Int16Array(128);",
" const eventResynthesis = processor.config().resynthesis;",
Expand All @@ -381,6 +393,23 @@ function verifyRuntimeImport(consumerDir, packageName) {
" assert.equal(processor.config().resynthesis.dryMix, 0.25);",
" assert.equal(processor.config().resynthesis.correction.humanize, 0.5);",
" assert.equal(processor.config().resynthesis.correction.flexTune, 0.25);",
" assert.equal(processor.controlActivity().harmonyMidiChannelMap, false);",
" assert.equal(processor.controlActivity().harmonyMidiBaseChannel, false);",
" const harmonyActivityConfig = processor.config();",
' harmonyActivityConfig.resynthesis.mode = "harmony";',
' harmonyActivityConfig.resynthesis.harmony.source = "midiChannels";',
' harmonyActivityConfig.resynthesis.harmony.midiChannelMap = "baseWindow";',
" processor.setConfig(harmonyActivityConfig);",
" assert.equal(processor.controlActivity().harmonyMidiChannelMap, true);",
" assert.equal(processor.controlActivity().harmonyMidiBaseChannel, true);",
' harmonyActivityConfig.resynthesis.harmony.midiChannelMap = "wrapFour";',
" processor.setConfig(harmonyActivityConfig);",
" assert.equal(processor.controlActivity().harmonyMidiChannelMap, true);",
" assert.equal(processor.controlActivity().harmonyMidiBaseChannel, false);",
' harmonyActivityConfig.resynthesis.harmony.source = "midiOmni";',
" processor.setConfig(harmonyActivityConfig);",
" assert.equal(processor.controlActivity().harmonyMidiChannelMap, false);",
" assert.equal(processor.controlActivity().harmonyMidiBaseChannel, false);",
"} finally {",
" processor.free();",
"}",
Expand Down Expand Up @@ -738,6 +767,8 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" TuneletAudioViews,",
" type ControlActivity,",
" type ControlEvent,",
" type CorrectionMidiMode,",
" type MidiChannelMap,",
" type ParameterControl,",
" type ProcessorConfig,",
" type ResynthesisConfig,",
Expand Down Expand Up @@ -778,10 +809,13 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" ...baseConfig.resynthesis.correction,",
" humanize: optionalVoices,",
" flexTune: optionalVoices,",
' midiMode: optionalVoices === undefined ? undefined : ("latch" satisfies CorrectionMidiMode),',
" },",
" harmony: {",
" ...baseConfig.resynthesis.harmony,",
" voices: optionalVoices,",
' midiChannelMap: optionalVoices === undefined ? undefined : ("wrapFour" satisfies MidiChannelMap),',
" midiBaseChannel: optionalVoices,",
" },",
" },",
" };",
Expand All @@ -801,6 +835,10 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" const processor = new Tunelet(48000, 128, configWithUndefined);",
" processor.setConfig(configWithUndefined);",
" const activity: ControlActivity = processor.controlActivity();",
" const channelMapFlags: [boolean, boolean] = [",
" activity.harmonyMidiChannelMap,",
" activity.harmonyMidiBaseChannel,",
" ];",
" const telemetry: Telemetry = processor.telemetry();",
" const voiceSlices: [Float32Array, Float32Array] = [",
" telemetry.voiceRatios,",
Expand Down Expand Up @@ -865,6 +903,7 @@ function verifyTypeDeclarations(consumerDir, packageName) {
" views.dispose();",
" processor.free();",
" void activity;",
" void channelMapFlags;",
" void voiceSlices;",
" void ptrs;",
" void stereoOut;",
Expand Down Expand Up @@ -1156,7 +1195,7 @@ function verifyNormalizedJsDoc(consumerDir, packageName) {
);
assert.doesNotMatch(
text,
/`(?:max_frequency_hz|min_frequency_hz|stereo_output|retune_ms|attack_ms|gain_db|ceiling_db)`/,
/`(?:max_frequency_hz|min_frequency_hz|stereo_output|retune_ms|midi_channel_map|midi_base_channel|midi_mode|attack_ms|gain_db|ceiling_db)`/,
`Unexpected snake_case config field in ${filePath}`,
);
}
Expand Down Expand Up @@ -1211,12 +1250,19 @@ function verifyNormalizedJsDoc(consumerDir, packageName) {
)[0].replace(/\s+/g, " ");
assert.ok(controlActivityDoc.includes("`ProcessorConfig`"));
assert.ok(controlActivityDoc.includes("`Tunelet.controlActivity`"));
assert.ok(controlActivityDoc.includes("channel map"));
assert.ok(
controlActivityInterfaceMatch[2].includes("`ResynthesisConfig.choirVoices`"),
);
assert.ok(
controlActivityInterfaceMatch[2].includes("`HarmonyConfig.source`"),
);
assert.ok(
controlActivityInterfaceMatch[2].includes("`HarmonyConfig.midiChannelMap`"),
);
assert.ok(
controlActivityInterfaceMatch[2].includes("`HarmonyConfig.midiBaseChannel`"),
);
assert.ok(
controlActivityInterfaceMatch[2].includes("`ReverbConfig.brightnessHz`"),
);
Expand Down
16 changes: 12 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::effects::punch::PunchConfig;
use crate::effects::reverb::{ReverbConfig, ReverbMode};
use crate::effects::warm::WarmConfig;
use crate::error::{check_range, ConfigProblem};
use crate::harmony::HarmonySource;
use crate::harmony::{HarmonySource, MidiChannelMap};
use crate::resynthesis::MultiVoiceMode;
use crate::Error;
use crate::ResynthesisConfig;
Expand Down Expand Up @@ -210,13 +210,14 @@ impl ProcessorConfig {
/// the active modes.
///
/// A `false` flag means that the related control makes no sample change in
/// the active voice mode, harmony source or reverb network. This method
/// does not allocate memory and does not validate ranges.
/// the active voice mode, harmony source, channel map or reverb network.
/// This method does not allocate memory and does not validate ranges.
pub fn control_activity(self) -> ControlActivity {
let choir = self.resynthesis.mode == MultiVoiceMode::Choir;
let multi_choir = choir && self.resynthesis.choir_voices > 1;
let harmony = self.resynthesis.mode == MultiVoiceMode::Harmony;
let source = self.resynthesis.harmony.source;
let midi_channels = harmony && source == HarmonySource::MidiChannels;
let interval = matches!(
source,
HarmonySource::FixedInterval | HarmonySource::SmartInterval
Expand Down Expand Up @@ -253,6 +254,9 @@ impl ProcessorConfig {
harmony_voicing_spread_percent: harmony && chord,
harmony_portamento_ms: harmony && (!interval || interval_voices),
harmony_voices: harmony && interval,
harmony_midi_channel_map: midi_channels,
harmony_midi_base_channel: midi_channels
&& self.resynthesis.harmony.midi_channel_map == MidiChannelMap::BaseWindow,
harmony_gain: harmony && (!interval || interval_voices),
reverb_mode: reverb,
reverb_mix: reverb,
Expand All @@ -271,7 +275,7 @@ impl ProcessorConfig {
/// Get this snapshot from [`ProcessorConfig::control_activity`] or
/// [`crate::Processor::control_activity`]. A `false` flag means that the
/// related control makes no sample change in the active voice mode, harmony
/// source or reverb network. `Default` sets all flags to `false`.
/// source, channel map or reverb network. `Default` sets all flags to `false`.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
#[cfg_attr(
Expand Down Expand Up @@ -312,6 +316,10 @@ pub struct ControlActivity {
pub harmony_portamento_ms: bool,
/// `true` if [`crate::HarmonyConfig::voices`] is active.
pub harmony_voices: bool,
/// `true` if [`crate::HarmonyConfig::midi_channel_map`] is active.
pub harmony_midi_channel_map: bool,
/// `true` if [`crate::HarmonyConfig::midi_base_channel`] is active.
pub harmony_midi_base_channel: bool,
/// `true` if [`ResynthesisConfig::harmony_gain`] is active.
pub harmony_gain: bool,
/// `true` if [`ReverbConfig::mode`] is active.
Expand Down
21 changes: 11 additions & 10 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,21 @@ pub enum ControlEvent {
/// Validation, quantization, state retention and drain cancellation are
/// identical to an equivalent stage event.
Parameter(ParameterControl),
/// This event sends a note control to the harmony source that
/// [`crate::HarmonyConfig`] selects.
/// This event sends a note control to the MIDI keybed of
/// [`crate::HarmonyConfig`].
///
/// MIDI-channel mode uses channels 0..=3. Omni mode and MIDI-chord mode
/// combine channels.
/// The keybed records all 16 channels. MIDI-channel mode assigns channels
/// with [`crate::HarmonyConfig::midi_channel_map`]. Omni mode and
/// MIDI-chord mode combine all channels.
Midi(MidiEvent),
/// This event changes the correction keyboard independently of harmony MIDI.
///
/// While at least one key in 0..=127 is held, the held keys become the
/// active pitch classes. Channels and nonzero velocities do not change the
/// selected classes. When all keys release, or on All Notes Off, the
/// configured mask loads again. If a later change sets new configured
/// notes, or enables or disables correction, the configured mask also
/// loads again.
/// The held keys 0..=127 select the active pitch classes. Channels and
/// nonzero velocities do not change the selected classes. In
/// [`crate::CorrectionMidiMode::Momentary`], when all keys release, the
/// configured [`crate::CorrectionConfig::notes`] load again. In
/// [`crate::CorrectionMidiMode::Latch`], the chord stays active until
/// [`MidiEvent::AllNotesOff`], a reset or a change to `notes` or `enabled`.
CorrectionMidi(MidiEvent),
/// This event resets immediately before the event frame, with the semantics of
/// [`crate::Processor::reset`].
Expand Down
Loading
Loading