Skip to content
Closed
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
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ with `resynthesis.harmony.source`:
| `MidiOmni` | MIDI notes from all channels, on the first free voice |
| `MidiChannels` | MIDI channel `n` for voice `n` (channels 0–3), 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.
`resynthesis.harmony.voices` sets the maximum number of active harmony voices,
in `0..=4`. The default is 4. All harmony sources obey this limit. Extra
voices release with the usual gain envelope.

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

## Process audio

Expand Down Expand Up @@ -304,24 +303,29 @@ These calls read the state of the processor. They do not change the audio.

The telemetry includes these items:

- The pitch ratio and the gain of each voice.
- The active voice count, and the pitch ratio and scaled gain of each voice.
- The peaks of the input, of the two output channels and of the reverb wet
signal.
- The pitch clarity, which is a confidence score from 0 to 1.
- The `tracking` flag and the pitch clarity, inside the `resynthesis.pitch`
bounds.
- The current gains of Punch and Warm, and the position in the Alien loop.
- The generation tag of the active formant model.

The peak windows of the telemetry are independent of the peak window of the
feedback. The latency is nominal. Dry mixes, resampled voices and effects
have different timing.
feedback. If a pitch is outside `min_frequency_hz..=max_frequency_hz`, it
reports as unvoiced, sets `tracking` to `false` and moves correction toward 1.
The latency is nominal. Dry mixes, resampled voices and effects have different
timing.

`formant_envelope()` writes two LPC envelopes into slices of equal length:

- The vocal-tract envelope from the analysis.
- The envelope after the width and stretch controls.
- The envelope after the current width and stretch controls.

The values are linear and have no absolute level. The formant stage must be
enabled. The envelopes are those of the model that the audio used for the
last frame. The method returns `Result<bool, Error>`:
enabled. The envelopes come from the model stamp of the last audio frame. If
`width` or `stretch` changes, the output envelope and `formant_generation`
update immediately. The method returns `Result<bool, Error>`:

| Result | Description |
| ----------- | ---------------------------------------------------------------- |
Expand Down Expand Up @@ -489,7 +493,7 @@ the cases where `voiced` is `false`:

- The kept pitch estimate is unvoiced. This includes the time before the
first detection and after a reset or a drain completion.
- The estimated frequency is outside the inclusive reporting bounds
- The estimated frequency is outside the inclusive frequency bounds
`resynthesis.pitch.minFrequencyHz` and `resynthesis.pitch.maxFrequencyHz`.

`formantEnvelope(maxFrequencyHz, input, output)` fills two `Float32Array`
Expand Down
51 changes: 27 additions & 24 deletions src/effects/reverb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,22 @@ pub struct ReverbConfig {
pub mix: f32,
/// The diffusion control without a unit, 0..=1.
///
/// The default is 0.5. MediumHall and LargeHall scale their allpass
/// coefficients with it. Binaural uses it as the gain of its early taps.
/// In Echo, it sets the distance of the feedback tap. Schroeder and
/// SmallRoom do not use it.
/// The default is 0.5. Schroeder, SmallRoom, MediumHall and LargeHall
/// scale their allpass coefficients with it. Binaural uses it as the gain
/// of its early taps. In Echo, it sets the distance of the feedback tap.
pub diffusion: f32,
/// The feedback control without a unit, 0..=1.
///
/// The default is 0.6. The prepared coefficient is approximately
/// `decay / 1.05`. It is less than unity also at the maximum. This value
/// is not a decay time in seconds. Some paths also use fixed feedback
/// coefficients. Binaural does not use this control.
/// is not a decay time in seconds. All six networks scale feedback paths
/// with this control. Some paths also use fixed feedback coefficients.
pub decay: f32,
/// The low-pass cutoff in hertz for networks with damped paths, 80..=20000.
/// The low-pass cutoff in hertz for the two low-pass filters, 80..=20000.
///
/// The default is 4000 Hz. The preparation also limits it to 0.49 ×
/// sample rate. A change of the cutoff keeps the sample histories of the
/// filters.
/// The default is 4000 Hz. All six networks damp their delay paths with
/// these filters. The preparation also limits the cutoff to 0.49 × sample
/// rate. A change of the cutoff keeps the sample histories of the filters.
pub brightness_hz: f32,
}
impl Default for ReverbConfig {
Expand Down Expand Up @@ -243,20 +242,23 @@ impl Reverb {
let mut result = match self.config.mode {
ReverbMode::Echo => {
d.put(mono, t[0]);
d.lpf(t[2], &mut self.lpf1);
let echo: Fixed<0> = Fixed::<0>::from_bits(t[39] as i32).mul(self.diffuse);
d.comb(t[0], echo.to_bits() as usize, self.decay);
d.comb_lpf(t[0], echo.to_bits() as usize, self.decay, &mut self.lpf2);
[
mul(left, dry) + mul(self.mix, d.get(t[25]) - d.get(t[32])),
mul(right, dry) - mul(self.mix, d.get(t[26]) - d.get(t[31])),
]
}
ReverbMode::Schroeder => {
let input = mono.div::<0, 14>(TWO);
for i in [0, 13, 23, 29] {
d.put(mono.div::<0, 14>(TWO), t[i]);
}
for (a, b, g) in [(0, 12, 0.9), (13, 22, 0.89), (23, 28, 0.87), (29, 34, 0.86)] {
d.comb(t[a], t[b], q14(g));
d.put(input, t[i]);
}
d.comb_lpf(t[0], t[12], self.decay, &mut self.lpf1);
d.comb_lpf(t[13], t[22], q14(0.89), &mut self.lpf2);
d.comb(t[23], t[28], q14(0.87));
d.comb(t[29], t[34], q14(0.86));
d.fir(
t[40],
&[
Expand All @@ -266,20 +268,20 @@ impl Reverb {
(t[34], q14(0.25)),
],
);
d.allpass(t[40], t[43], self.decay);
d.allpass(t[44], t[45], self.decay);
d.allpass(t[40], t[43], mul(self.diffuse, q14(0.7)));
d.allpass(t[44], t[45], mul(self.diffuse, self.decay));
let value = mul(mono, dry) + mul(self.mix, d.get(t[45]));
[value, value]
}
ReverbMode::SmallRoom => {
d.put(left, t[0]);
d.put(right, t[40]);
for (a, b, g) in [(1, 15, 0.3), (2, 7, 0.7), (8, 14, 0.5), (18, 24, 0.5)] {
d.allpass(t[a], t[b], q14(g));
d.allpass(t[a], t[b], mul(self.diffuse, q14(g)));
}
d.comb_lpf(t[40], t[35], self.decay, &mut self.lpf1);
for (a, b, g) in [(41, 50, 0.3), (42, 46, 0.6), (53, 57, 0.5)] {
d.allpass(t[a], t[b], q14(g));
d.allpass(t[a], t[b], mul(self.diffuse, q14(g)));
}
d.comb_lpf(t[0], t[66], self.decay, &mut self.lpf2);
[
Expand All @@ -303,14 +305,16 @@ impl Reverb {
self.diffuse >> 1,
d.get(t[0] + seed) + d.get(t[11] + seed) + d.get(t[21] + seed),
);
d.put(a, tap);
let fb_a = mul(self.decay, d.get(t[35]) + (d.get(t[24]) >> 2));
d.put(a + fb_a, tap);
d.lpf(filter, &mut self.lpf1);
let out = mul(mono, dry) + mul(self.mix, d.get(t[40] + filter) + a);
let b = mul(
self.diffuse >> 1,
d.get(t[47] + seed) + d.get(t[48] + seed) + d.get(t[54] + seed),
);
d.put(b, t[40] + tap);
let fb_b = mul(self.decay, d.get(t[66]) + (d.get(t[57]) >> 2));
d.put(b + fb_b, t[40] + tap);
d.lpf(t[40] + filter, &mut self.lpf2);
[out, mul(mono, dry) + mul(self.mix, d.get(filter) + b)]
}
Expand Down Expand Up @@ -409,10 +413,9 @@ pub(crate) fn tail_frames(rate: SampleRate, config: ReverbConfig) -> usize {
let decay = config.decay as f64 / 1.05;
let diffuse = config.diffusion as f64;
let gain = match config.mode {
ReverbMode::Binaural => 0.0,
ReverbMode::Echo => decay,
ReverbMode::Binaural | ReverbMode::Echo => decay,
ReverbMode::Schroeder => 0.9f64.max(decay),
ReverbMode::SmallRoom => 0.7f64.max(decay),
ReverbMode::SmallRoom => (0.7 * diffuse).max(decay),
ReverbMode::MediumHall => (0.9 * diffuse).max(decay),
ReverbMode::LargeHall => (0.95 * diffuse).max(decay),
};
Expand Down
Loading