Skip to content

fx_lowcut: keep a bus's chorus, echo and reverb out of its low end - #1261

Open
mateusz28011 wants to merge 2 commits into
shorepine:mainfrom
mateusz28011:feat/fx-lowcut
Open

mateusz28011 wants to merge 2 commits into
shorepine:mainfrom
mateusz28011:feat/fx-lowcut

Conversation

@mateusz28011

Copy link
Copy Markdown
Contributor

Goal: take the bass out of a bus's wet signal (chorus, echo and reverb tails) while leaving the dry bass as it is.

A bus that carries a kick or a bass gets its reverb and echo tails in the low end too. The bus EQ cannot fix that: it runs before the effects, so it changes the dry signal as well. Echo has its own high-pass (a negative filter_coef), but that covers the echo alone, not the chorus or the reverb.

This adds one per-bus parameter, fx_lowcut (wire J, in Hz, 0 = off, the default):

amy.send(bus=1, reverb="0.5,0.85,0.5,3000", echo="0.5,306,,0.4,0", fx_lowcut=200)

How. The bus chain is distortion → EQ → chorus → echo → reverb → external hook. Chorus, echo and reverb each add their output onto the bus (+= in delay.c; stereo_reverb writes input + level × wet), so the bus after the reverb minus the bus before the chorus is their combined wet signal. With fx_lowcut set, amy_fill_buffer copies the bus before the chorus, and after the reverb high-passes that difference and adds it back onto the copy. The dry signal never goes through a filter; distortion and EQ sit before the copy and the hook after the cut, so they are not affected.

The filter is two first-order sections in series (fx_lowcut_coefs / bus_fx_lowcut in filters.c): 12 dB/octave, about 3 dB down at the set frequency, which is clamped to a quarter of the sample rate.

Why one cutoff on the sum, in core. It needs no change inside the three effects, and it is one setting for "keep the effects out of the bass". A bus hook cannot do it: it runs after the effects and never sees the bus before them.

Cost. Off (the default): a flag test per bus per block; nothing is copied or filtered, and a bus's line in a state dump is unchanged (the setting is written only when it is set). On: one block copy and five multiplies per channel sample. One scratch block of AMY_BLOCK_SIZE * AMY_MAX_CHANNELS samples is allocated on first use, shared by all buses (they are processed one after another, after the two cores' blocks are merged) and kept until deinit; if that allocation fails the cut stays off. The loops follow AMY_NCHANS, so mono builds are covered. On an AMYboard (ESP32-S3) with chorus, echo and reverb on two buses, tulip.cpu() read 61.0 % without the cut and 61.1 % with it.

Changing it while a note sounds. Moving the cutoff keeps the filter state. Setting it to 0 crossfades to the unfiltered wet signal over about 250 ms before the stage stops. In host renders of a held 55 Hz note, the largest sample-to-sample step at any of these changes stayed below the largest step elsewhere in the take.

Test. TestFxLowCut has a custom test(): with the effects off, the output is sample-identical with and without the cut; under a 200 Hz cutoff the wet signal drops 16 dB at 55 Hz (±1.5) and is unchanged at 2 kHz (±0.5); switching off under a held note, sent twice, makes no step and ends sample-identical to a bus that never had a cut; the setting shows up in dump_state(). python -m amy.test passes (140 tests) at AMY_TEST_THRESHOLD_DB=-70.0; make check-c-api is clean and godot/amy.gd is regenerated.

Not in this PR: a slope setting, or a cutoff per effect.

Host render, same C code. Left: wet level with the cut at 100 Hz relative to without, against the two-section curve. Right: what reverb and echo add to a bass line (bus minus dry signal) with the cut off, at 100 Hz and at 200 Hz.

fx_lowcut

I opened this as a PR so there is code to look at. If you would rather settle the API in an issue first, or build it another way, I'm glad to go that route.

A reverb or an echo on a bus that carries a bass or a kick puts its tail
into the low end, and nothing on the bus can stop it: the EQ sits before the
effects and would take the lows off the dry signal too.

`fx_lowcut` (wire `J`, Hz, 0 = off) high-passes what those three effects add.
They all mix their output onto the bus on top of the dry signal, so the bus
after them minus the bus before them is their contribution; that difference
goes through two first-order sections (12 dB/octave, 3 dB down at the
cutoff) and back onto the dry signal. Below the cutoff the bus is the dry
signal, and low content the effects generate themselves goes too.

Off by default: nothing is copied or filtered, and the bus line of a state
dump is unchanged. A dump names the cut only when it is set, as it does the
bus distortion.

The cutoff can move under a sounding note: a running cut keeps its filter
state, and set to 0 it fades to the uncut effects over a quarter second
before the stage stops, so the lows come back without a step.
…ed corner

From a review of the first commit:

- Without AMY_HAS_MUL64 (Cortex-M0), FILT_MUL_SS keeps 12 fractional bits of
  each operand, too few for a pole this close to 1: the filter left a DC
  offset. The stage now uses a 64-bit product on every build.
- Switching the cut back on while it was fading out snapped it on. The fade
  is now one position that runs either way, so off and on-again both ramp.
- The section corner was prewarped after scaling instead of before, which
  put the 3 dB point slightly off at high cutoffs (2.3 dB down instead of 3
  at a quarter of the sample rate). Scaled after the tan now.

bus_fx_lowcut takes the whole bus rather than one channel, and the fade and
coefficients are set in one place (fx_lowcut_set). TestFxLowCut also switches
on again half way through a fade.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant