Skip to content

Conversation

@purelygrey
Copy link

image

This is a rework of softclip functionality. I've been playing with it for a while and figured how to better organize it and make it nicer and (hopefully) less confusing/annoying.

This should go after #171

Changes

  • Changed signal flow, moved things around
  • Simplified gain compensation math
  • Precalculated static values for soft clipping algorithm, so they don't get recalculated for every sample anymore
  • Added a max value for int variables, so old projects with incorrect values do not result in broken sound (very crude so far, not sure about it, see Variable.cpp)

Some things got a little dirty, I don't know how to make it any better at this point, so feedback is welcome! Also there's some weirdness with formatting, not sure what's going on

Reasoning

Mainly there are three things that feel confusing/clunky:

  • Master control isn't actually a master fader -- it applies gain to each of the tracks, goes before saturation stage, and can get hard clipped
  • Soft clip modes all boost the volume behind the scenes, and there's no way to properly A/B when it's on and off, unless Atten is set manually, which is a pain to do and it differs for each mode;
  • Atten control only works when soft clip is on, so there's no way to control volume when you drive hard clip intentionally; it is also a linear slider and doesn't feel natural as a volume slider, there's not a lot of precision when it gets quiet

These changes should address all of these issues:

  • Old master is now pre-gain, and it does what it says, which is pretty much driving the clipping stage
  • Soft clip gain boost is turned off by default, so there's no jump in volume, unless you want it, and it's hard to accidentally switch it on or off. Easy to a/b when it's off, and boost (maximize) volume if needed
  • Atten control is now Master fader, as it should be -- works regardless of soft clip mode and feels nice to use

Signal flow explanations

Pre-gain (boost/cut)SaturationAuto-gain (boost)Hard clipMaster (cut)

This shouldn't affect old projects too much, only pre-gain will be reset to 100, which doesn't seem too bad.

Pre-gain is previous master, can cut or boost volume and does so across all 8 tracks; it'll be reset to 100 for old projects because of the internal name changes.

Saturation is the same control as before, I decided to rename it because it looked better this way :-)

Auto-gain is a switch for gain compensation algorithm, which was hidden before.

By default Auto-gain is set to normal, so there's no gain added when switching between saturation modes -- this should be generally a safer volume-wise and easier to A/B between modes. Another value, boosted, is the current behaviour.

Auto-gain control goes after Saturation control and shifted to the right, so when scrolling down normally Auto-gain control never gets active. That makes it difficult to accidentally change Auto-gain, it has to be an intentional change, which seems good because it could result in a sudden volume jump.

Hard clip is always on -- it can be used as effect when Saturation is Bypass/Subtle/Medium. When using Heavy/Insane samples should never exceed -1/1, there should be no hard clipping even if auto-gain is set to boosted.

Master is a cut-only volume fader. It is meant to be used to balance tracks against each other for playing live, etc. Because of this it goes after hard clip, so the sound of the track doesn't change (when it was hard clipped for effect). It uses x^4 curve, which feels more natural than linear, and it can go down to 0, which allows it to be used a a simple fade-in/fade-out control. 100 is unity gain as before.

Looking forward to hear your thoughts!

@purelygrey
Copy link
Author

I will update the documentation a bit later

@djdiskmachine
Copy link
Owner

Looks very promising!
I'll add it for the release candidate.
Can you elaborate on what you mean by weirdness with formatting?

Disagree that the minmaxing thing is supposedly crude, looks fine to me.
I'll remove the minmax.cpp as i don't see what it's for and will add the header to the visual studio and Xcode projects respectively.
GJ!

@purelygrey
Copy link
Author

Looks very promising! I'll add it for the release candidate. Can you elaborate on what you mean by weirdness with formatting?

Disagree that the minmaxing thing is supposedly crude, looks fine to me. I'll remove the minmax.cpp as i don't see what it's for and will add the header to the visual studio and Xcode projects respectively. GJ!

Glad to hear, thanks! I think I meant tabs/spaces indentation mess, not sure how it's supposed to be, I might have to retab it. As for the minmax remark -- you must be right, I'm new to this and not really in the place to judge such things yet

I will return to this and add to readme as mentioned later this month

@djdiskmachine
Copy link
Owner

I will return to this and add to readme as mentioned later this month

Cool!

@djdiskmachine
Copy link
Owner

I've thought about it a little I think I'd prefer some more self-descriptive name for the auto gain. I considered "make-up" but it's not a great name since it's the opposite of make-up in a compressor context. Maybe something like "boost: off" and "boost: on" could be good?

Also I just realized Master gain no longer goes beyond 100 to make head room for a boosted volume. So if an older project used a volume of 130, that would be the same as having master at 100 and a pre-gain of 130 with saturation set at bypass and boost on?

@purelygrey
Copy link
Author

I've thought about it a little I think I'd prefer some more self-descriptive name for the auto gain. I considered "make-up" but it's not a great name since it's the opposite of make-up in a compressor context. Maybe something like "boost: off" and "boost: on" could be good?

Also I just realized Master gain no longer goes beyond 100 to make head room for a boosted volume. So if an older project used a volume of 130, that would be the same as having master at 100 and a pre-gain of 130 with saturation set at bypass and boost on?

Looking at it now I agree it is cryptic, I think "auto-gain" would be less confusing, because it doesn't do anything when there's no soft clipping and it actually is a crude AGC, but the text might be too long. Maybe agc: on/off? I've seen some VSTs abbreviate it as just "A"

That is correct, I don't remember if boost defaults to "on", it should default to "off". Old projects should load just fine and sound exactly the same.

I treated hard clip stage as an effect and because it always clips at +1/-1 it didn't make sense to me to have master fader go above 0db, because this would end up in more hard clipping, or worse, overflow. But I did miss a final volume control so I could balance multiple tracks, and also a sort of a fader to do fade ins/out on the fly, so capping it at unity gain seemed right at the time. I'm not opposed to making it go above 0db and moving the hard clipping part to the very end -- makes sense either way to me, depends on how you look at it. It would be clunky to do a fade in because it'd end up in clipping, but if the master volume is used to match loudness of multiple tracks it is already clunky, because one would need to "fade in" into whatever number that was there before

@djdiskmachine
Copy link
Owner

Very good, I'll add it to the 1.5.0 release candidate.
I'm leaning towards calling it unity/boost. Due to the character/GUI limitations almost any name will be some version of obscure though =D

@djdiskmachine djdiskmachine mentioned this pull request Apr 7, 2025
@djdiskmachine
Copy link
Owner

djdiskmachine commented Apr 8, 2025

Noticed some strange behavior on MacOS build yesterday
While trying out different saturation types the audio suddenly stopped.
Song continues to play but there's no audio. No indicators in lgpt.log either
Reloading the project fixes the issue.
I've seen this intermittently on other platforms but that happens very rarely and with no obvious trigger, yesterday was obviously when going back and forth between types.
Switching to 1.4.3 build does not have this issue.

Tried the rework now on Ubuntu x64 and I'm not seeing this at all. @_@

@purelygrey
Copy link
Author

Noticed some strange behavior on MacOS build yesterday While trying out different saturation types the audio suddenly stopped. Song continues to play but there's no audio. No indicators in lgpt.log either Reloading the project fixes the issue. I've seen this intermittently on other platforms but that happens very rarely and with no obvious trigger, yesterday was obviously when going back and forth between types. Switching to 1.4.3 build does not have this issue.

Tried the rework now on Ubuntu x64 and I'm not seeing this at all. @_@

I don't have any means to test Mac OS builds, but I'll try to investigate nonetheless. You mean bacon-5, right? Might be something to do with optimizations

@djdiskmachine
Copy link
Owner

djdiskmachine commented Apr 8, 2025

You mean bacon-5, right? Might be something to do with optimizations

Yes correct, I made a particular audio routing for a stream which might have something to do with it but it seems strange that it would only affect the rework.

@djdiskmachine
Copy link
Owner

djdiskmachine commented Apr 8, 2025

Cannot reproduce this error in PPSSPP, however I noticed this project doesn't sound very good when loaded with this rework.

This probably needs a conditional when loading older projects, don't want the unexpecting user to blow their ears ou😅t
lgpt_BASH.zip

@purelygrey
Copy link
Author

Cannot reproduce this error in PPSSPP, however I noticed this project doesn't sound very good when loaded with this rework.

This probably needs a conditional when loading older projects, don't want the unexpecting user to blow their ears out lgpt_BASH.zip

Noted, will look into it, this shouldn't be the case, there's definitely something very wrong

@djdiskmachine
Copy link
Owner

djdiskmachine commented Apr 8, 2025

OK one mea culpa and one found the issue.
I seem to have messed up your rework when I cherry picked it. The project loads with 100 for the master volume with this build and a master of 200 with 1.5.0. Sorry about that!

The audio going silent seems to happen only when a MIDI device is selected, it plays audio for up to 30 seconds then goes silent.
If I enable a MIDI device then start playback again, this issue occurs quite quickly.
This issue is there for 1.4.3-bacon5 too so it's not due to your rework =)

@maks
Copy link

maks commented Apr 10, 2025

Hope you both don't mind me chiming in as I only just learnt about this today from @djdiskmachine posting in the picoTracker Discord.

I first off wanted to say that I think the use of the Master volume per channel to me is a bug as I recently came across it when adding a new Mixer screen to pT and I plan to fix it by having per channel volume settings. I also think of these as attenuation per channel to balance the mix given that instruments themselves have thier own volume settings so thats how I plan to implement it and it will also fit nicely into the UI of the our new mixer screen.

In regards to Master vol itself, I agree that it doesn't make sense to me to allow higher than 0dB and likewise I hand't noticed til now that the scale was linear but thats also not a good idea as in audio linear scales are not usually used so I have made an issue to fix that in pT too, my thanks for highlighting those issues with your work here! 👍🏻

@purelygrey
Copy link
Author

OK one mea culpa and one found the issue. I seem to have messed up your rework when I cherry picked it. The project loads with 100 for the master volume with this build and a master of 200 with 1.5.0. Sorry about that!

The audio going silent seems to happen only when a MIDI device is selected, it plays audio for up to 30 seconds then goes silent. If I enable a MIDI device then start playback again, this issue occurs quite quickly. This issue is there for 1.4.3-bacon5 too so it's not due to your rework =)

That's a relies, thanks! I was worried I majorly messed up something. Should I do cosmetic/readme changes separately, or is it ok to add another commit in this branch?

Hope you both don't mind me chiming in as I only just learnt about this today from @djdiskmachine posting in the picoTracker Discord.

I first off wanted to say that I think the use of the Master volume per channel to me is a bug as I recently came across it when adding a new Mixer screen to pT and I plan to fix it by having per channel volume settings. I also think of these as attenuation per channel to balance the mix given that instruments themselves have thier own volume settings so thats how I plan to implement it and it will also fit nicely into the UI of the our new mixer screen.

In regards to Master vol itself, I agree that it doesn't make sense to me to allow higher than 0dB and likewise I hand't noticed til now that the scale was linear but thats also not a good idea as in audio linear scales are not usually used so I have made an issue to fix that in pT too, my thanks for highlighting those issues with your work here! 👍🏻

You're welcome! Yeah I agree, I wanted to tackle the volume per channel thing next, I also believe it shouldn't be this way. The worst thing about it to me is how easy it is to push it into overflow distortion with just a few samples at max volume and that sounds real bad :) it doesn't make a lot of sense to me to multiply every channel by the same amount before adding everything together in fixed point math, unless it's the only way to do it for very old devices like gp2x, which afaik this fork doesn't officially support

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.

3 participants