Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate db_to_gain before smoothing the parameter #18

Closed
BillyDM opened this issue Jul 21, 2022 · 6 comments
Closed

Translate db_to_gain before smoothing the parameter #18

BillyDM opened this issue Jul 21, 2022 · 6 comments

Comments

@BillyDM
Copy link
Contributor

BillyDM commented Jul 21, 2022

You should definitely add the ability for a parameter to translate its value using util::db_to_gain before smoothing it.

The current gain example is woefully inefficient since it is converting from db to gain every single sample:

for channel_samples in buffer.iter_samples() {
    // Smoothing is optionally built into the parameters themselves
    let gain = self.params.gain.smoothed.next();

    for sample in channel_samples {
        *sample *= util::db_to_gain(gain);
    }
}

This is how baseplug implements this: https://github.com/wrl/baseplug/blob/trunk/src/parameter.rs#L116

@BillyDM
Copy link
Contributor Author

BillyDM commented Jul 21, 2022

Essentially I'm saying that the actual parameter should store its value in raw amplitude, and only do the translation between db and amplitude when interacting with the UI/host.

@BillyDM BillyDM changed the title Translate db_to_gain before smoothing the parameter Translate parameter before smoothing the parameter Jul 21, 2022
@BillyDM BillyDM changed the title Translate parameter before smoothing the parameter Translate db_to_gain before smoothing the parameter Jul 21, 2022
@BillyDM BillyDM changed the title Translate db_to_gain before smoothing the parameter Translate parameter before smoothing the parameter Jul 21, 2022
@BillyDM BillyDM changed the title Translate parameter before smoothing the parameter Translate db_to_gain before smoothing the parameter Jul 21, 2022
@BillyDM
Copy link
Contributor Author

BillyDM commented Jul 21, 2022

(Sorry for all the title changes, lol. I kept thinking there was more to add when looking at the code, but then I realized it was fine).

@robbert-vdh
Copy link
Owner

This is intentional. Check out the other non-example plugins in the repo. The examples have gain parameters in the logarithmic domain, while the non-example plugins have the parameters in linear space using formatters::{v2s,s2v}_f32_gain_to_db and util::db_to_gain for ranges. In these example plugins you really won't notice the DSP load difference from one extra powf per sample and I think it mamkes everything a bit clearer. I should probably change at least one of the examples to have linear gain parameters though just to show off how to use those formatters.

@BillyDM
Copy link
Contributor Author

BillyDM commented Jul 21, 2022

Ah, I see. That makes perfect sense. Thanks for the help!

@BillyDM BillyDM closed this as completed Jul 21, 2022
@robbert-vdh
Copy link
Owner

But thanks for bringing this to my attention! I'll probably update the gain example and leave the sine example alone because showing off those formatters is probably also a good idea. (so I'm reopening this issue as a reminder for myself 😄)

@robbert-vdh robbert-vdh reopened this Jul 21, 2022
robbert-vdh added a commit that referenced this issue Jul 24, 2022
@robbert-vdh
Copy link
Owner

Okay, the basic and GUI gain examples now use linear gain to show off all of the utilities there. Makes things more complex, but it's probably good to show this off. There's a new FloatRange::gain_skew_factor(min_db, max_db) function that can be used together with FloatRange::Skewed to make the gain range appear as if it is linear on a decibel/logarithmic scale.

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

No branches or pull requests

2 participants