Skip to content
Merged
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
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,19 @@ These calls read the state of the processor. They do not change the audio.

| Call | Data |
| -------------------- | ----------------------------------------------------------------- |
| `control_activity()` | Which choir, harmony and reverb controls are active |
| `feedback()` | The pitch, the output peak, the correction ratio, the frame count |
| `take_feedback()` | The same data as `feedback()`, and clears the peak window |
| `telemetry()` | Data for meters and displays (refer to the list below) |
| `take_telemetry()` | The same data as `telemetry()`, and clears its three peak windows |
| `latency_frames()` | 1,593 frames of nominal resynthesis latency at both sample rates |
| `formant_envelope()` | The LPC envelopes before and after the formant controls |

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

The telemetry includes these items:

- The pitch ratio and the gain of each voice.
Expand Down Expand Up @@ -338,6 +344,7 @@ allocate memory, acquire locks or do I/O:

- Processing
- Configuration
- Control activity
- MIDI
- Feedback
- Telemetry
Expand Down Expand Up @@ -421,6 +428,7 @@ page that opens the JavaScript.
| Mono PCM to planar stereo | `process(input, left, right, events?)` |
| In-place mono downmix | `processMono(audio, events?)` |
| Configuration | `config()`, `setConfig(config)`, `defaultConfig()` |
| Control activity | `controlActivity()` |
| Information about the preparation | `sampleRate`, `maxBlockFrames`, `latencyFrames` |
| Feedback | `feedback()`, `takeFeedback()` |
| Telemetry | `telemetry()`, `takeTelemetry()` |
Expand Down Expand Up @@ -484,7 +492,9 @@ bindings.

### Feedback, telemetry and formant envelopes

`telemetry()` and `takeTelemetry()` return a `Telemetry` object.
`controlActivity()` returns a `ControlActivity` object with camelCase boolean
flags for the choir, harmony and reverb controls. `telemetry()` and
`takeTelemetry()` return a `Telemetry` object.

In feedback, `targetMidiNote` is `undefined` in these cases, which are also
the cases where `voiced` is `false`:
Expand Down Expand Up @@ -514,7 +524,7 @@ Wasm. These items can allocate:
- Supplied events when a call gives more events than before, or when an event
converts a stage configuration.
- Errors.
- Feedback and telemetry.
- Control activity, feedback and telemetry.
- The formant envelopes.

The generated glue can also make temporary views. This binding is for general
Expand Down
123 changes: 122 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

use crate::effects::alien::AlienConfig;
use crate::effects::punch::PunchConfig;
use crate::effects::reverb::ReverbConfig;
use crate::effects::reverb::{ReverbConfig, ReverbMode};
use crate::effects::warm::WarmConfig;
use crate::error::{check_range, ConfigProblem};
use crate::harmony::HarmonySource;
use crate::resynthesis::MultiVoiceMode;
use crate::Error;
use crate::ResynthesisConfig;
use std::num::NonZeroUsize;
Expand Down Expand Up @@ -203,6 +205,125 @@ impl ProcessorConfig {
self.reverb.validate()?;
validate_output_gain(self.output_gain)
}

/// Returns which choir, harmony and reverb controls change the audio in
/// 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.
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 interval = matches!(
source,
HarmonySource::FixedInterval | HarmonySource::SmartInterval
);
let interval_voices = self.resynthesis.harmony.voices > 0;
let named_or_degree = matches!(
source,
HarmonySource::ChordByDegree | HarmonySource::ChordByName
);
let chord = named_or_degree || source == HarmonySource::ChordViaMidi;
let reverb = self.reverb.enabled;
let reverb_mode = self.reverb.mode;
ControlActivity {
choir_voices: choir,
choir_detune: multi_choir,
choir_delay: multi_choir,
choir_spread_percent: multi_choir && self.resynthesis.stereo_output,
harmony_source: harmony,
harmony_key: harmony
&& ((source == HarmonySource::SmartInterval && interval_voices) || named_or_degree),
harmony_scale: harmony
&& ((source == HarmonySource::SmartInterval && interval_voices)
|| source == HarmonySource::ChordByDegree),
harmony_chromatic_intervals: harmony
&& source == HarmonySource::FixedInterval
&& interval_voices,
harmony_diatonic_intervals: harmony
&& source == HarmonySource::SmartInterval
&& interval_voices,
harmony_chord: harmony && source == HarmonySource::ChordByName,
harmony_degree: harmony && source == HarmonySource::ChordByDegree,
harmony_inversion: harmony && named_or_degree,
harmony_register_percent: harmony && chord,
harmony_voicing_spread_percent: harmony && chord,
harmony_portamento_ms: harmony && (!interval || interval_voices),
harmony_voices: harmony && interval,
harmony_gain: harmony && (!interval || interval_voices),
reverb_mode: reverb,
reverb_mix: reverb,
reverb_diffusion: reverb
&& !matches!(reverb_mode, ReverbMode::Schroeder | ReverbMode::SmallRoom),
reverb_decay: reverb && reverb_mode != ReverbMode::Binaural,
reverb_brightness_hz: reverb
&& !matches!(reverb_mode, ReverbMode::Echo | ReverbMode::Schroeder),
}
}
}

/// The flags that show which choir, harmony and reverb controls are active in
/// a [`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`.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
#[cfg_attr(
all(feature = "wasm", target_arch = "wasm32"),
derive(serde::Serialize, serde::Deserialize, tsify::Tsify),
serde(rename_all = "camelCase")
)]
pub struct ControlActivity {
/// `true` if [`ResynthesisConfig::choir_voices`] is active.
pub choir_voices: bool,
/// `true` if [`ResynthesisConfig::choir_detune`] is active.
pub choir_detune: bool,
/// `true` if [`ResynthesisConfig::choir_delay`] is active.
pub choir_delay: bool,
/// `true` if [`ResynthesisConfig::choir_spread_percent`] is active.
pub choir_spread_percent: bool,
/// `true` if [`crate::HarmonyConfig::source`] is active.
pub harmony_source: bool,
/// `true` if [`crate::HarmonyConfig::key`] is active.
pub harmony_key: bool,
/// `true` if [`crate::HarmonyConfig::scale`] is active.
pub harmony_scale: bool,
/// `true` if [`crate::HarmonyConfig::chromatic_intervals`] is active.
pub harmony_chromatic_intervals: bool,
/// `true` if [`crate::HarmonyConfig::diatonic_intervals`] is active.
pub harmony_diatonic_intervals: bool,
/// `true` if [`crate::HarmonyConfig::chord`] is active.
pub harmony_chord: bool,
/// `true` if [`crate::HarmonyConfig::degree`] is active.
pub harmony_degree: bool,
/// `true` if [`crate::HarmonyConfig::inversion`] is active.
pub harmony_inversion: bool,
/// `true` if [`crate::HarmonyConfig::register_percent`] is active.
pub harmony_register_percent: bool,
/// `true` if [`crate::HarmonyConfig::voicing_spread_percent`] is active.
pub harmony_voicing_spread_percent: bool,
/// `true` if [`crate::HarmonyConfig::portamento_ms`] is active.
pub harmony_portamento_ms: bool,
/// `true` if [`crate::HarmonyConfig::voices`] is active.
pub harmony_voices: bool,
/// `true` if [`ResynthesisConfig::harmony_gain`] is active.
pub harmony_gain: bool,
/// `true` if [`ReverbConfig::mode`] is active.
pub reverb_mode: bool,
/// `true` if [`ReverbConfig::mix`] is active.
pub reverb_mix: bool,
/// `true` if [`ReverbConfig::diffusion`] is active.
pub reverb_diffusion: bool,
/// `true` if [`ReverbConfig::decay`] is active.
pub reverb_decay: bool,
/// `true` if [`ReverbConfig::brightness_hz`] is active.
pub reverb_brightness_hz: bool,
}

/// Checks the output gain range.
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* configuration. Both environments use the same generated bindings and the
* same Wasm binary. This module re-exports all named exports of the module
* that wasm-bindgen generates, which include `Tunelet`, `defaultConfig`,
* `initSync` and the configuration, event and feedback types.
* `initSync` and the configuration, control-activity, event and feedback
* types.
*/
import init from "../pkg/tunelet.js";
import type { InitInput, InitOutput } from "../pkg/tunelet.js";
Expand Down
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@
//! resynthesis delay, which the dry path also uses. Voice delays, pitch
//! changes and effects have their own timing.
//!
//! [`Processor::telemetry`] gives data for meters and displays: the ratio and
//! the gain of each voice, the input and output peaks, the pitch clarity and
//! the state of the effects. In mono calls, the feedback and telemetry peaks
//! measure the audio after the downmix. [`Processor::take_telemetry`] also
//! clears the peak windows of the telemetry. [`Processor::formant_envelope`]
//! writes the LPC envelopes before and after the formant controls. These calls
//! do not change the audio.
//! [`Processor::control_activity`] and [`ProcessorConfig::control_activity`]
//! give [`ControlActivity`], which shows the active choir, harmony and reverb
//! controls. [`Processor::telemetry`] gives data for meters and displays: the
//! ratio and the gain of each voice, the input and output peaks, the pitch
//! clarity and the state of the effects. In mono calls, the feedback and
//! telemetry peaks measure the audio after the downmix.
//! [`Processor::take_telemetry`] also clears the peak windows of the
//! telemetry. [`Processor::formant_envelope`] writes the LPC envelopes before
//! and after the formant controls. These calls do not change the audio.
//!
//! After the last input block, call [`Processor::begin_drain`] one time. Then
//! render drain blocks until a call returns zero. Each call fills the unused
Expand Down Expand Up @@ -122,7 +124,7 @@ mod scale;
#[cfg(all(feature = "wasm", target_arch = "wasm32"))]
pub mod wasm;

pub use config::{PrepareConfig, ProcessorConfig, SampleRate};
pub use config::{ControlActivity, PrepareConfig, ProcessorConfig, SampleRate};
pub use effects::alien::AlienConfig;
pub use effects::punch::PunchConfig;
pub use effects::reverb::{ReverbConfig, ReverbMode};
Expand Down
12 changes: 11 additions & 1 deletion src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::events::{ValidatedEvent, ValidatedEvents};
use crate::numeric::rng::RandomStream;
use crate::numeric::NumericContext;
use crate::resynthesis::{self, Resynthesis};
use crate::{ControlEvent, Error, PrepareConfig, ProcessorConfig, TimedEvent};
use crate::{ControlActivity, ControlEvent, Error, PrepareConfig, ProcessorConfig, TimedEvent};

/// Selects the output channel layout for the downmix and the peak meters.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -328,6 +328,16 @@ impl Processor {
self.config
}

/// Returns which choir, harmony and reverb controls change the audio in
/// the current configuration.
///
/// 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 change state.
pub fn control_activity(&self) -> ControlActivity {
self.config.control_activity()
}

/// Returns the nominal resynthesis latency: 1,593 frames at both rates.
///
/// The dry path also has a delay of 1,593 frames. Resampled voices, choir
Expand Down
21 changes: 18 additions & 3 deletions src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
//! - Event decode when a call gives more events than before, or when an event
//! converts a stage configuration.
//! - The conversion of configurations.
//! - Feedback and telemetry objects.
//! - Feedback, control-activity and telemetry objects.
//! - The buffers of the formant envelopes.
//! - Errors.
//!
Expand All @@ -45,8 +45,8 @@

use crate::events::ValidatedEvents;
use crate::{
ControlEvent, Error, Feedback, MidiEvent, PrepareConfig, Processor, ProcessorConfig,
SampleRate, Telemetry, TimedEvent,
ControlActivity, ControlEvent, Error, Feedback, MidiEvent, PrepareConfig, Processor,
ProcessorConfig, SampleRate, Telemetry, TimedEvent,
};
use js_sys::{Array, Float32Array, Int16Array, Reflect};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -406,6 +406,21 @@ impl WasmProcessor {
Ok(feedback)
}

/// Returns which choir, harmony and reverb controls change the audio in
/// the active configuration.
///
/// A `false` flag means that the related control makes no sample change in
/// the active voice mode, harmony source or reverb network. The audio
/// state does not change.
///
/// # Errors
///
/// If the conversion to a JavaScript object fails, this method throws.
#[wasm_bindgen(js_name = controlActivity)]
pub fn control_activity(&self) -> Result<Ts<ControlActivity>, JsError> {
Ok(self.processor.control_activity().into_ts()?)
}

/// Returns a new telemetry object and does not clear its peak windows.
///
/// The telemetry is for meters and displays. It gives the ratio and the
Expand Down