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

Distortion effect #10932

Merged
merged 7 commits into from
Oct 25, 2022
Merged

Distortion effect #10932

merged 7 commits into from
Oct 25, 2022

Conversation

ferranpujolcamins
Copy link
Contributor

I implemented a simple distortion effect with 4 modes (or waveshapes).

The input is normalized to a predefined level for each waveshape in order for the action of the drive know to be independent of the level of the signal.

The output is also normalized by matching the rms of the output to the rms of the input. This output normalization can be improved, but I think it is usable enough for now.

There's also a one line fix for effect parameter push button right-click menu not updating the parameter.

@daschuer
Copy link
Member

This produces some compiler warnings on Ubuntu Focal:

[23/128] Building CXX object CMakeFile.../backends/builtin/builtinbackend.cpp.o
In file included from ../../src/effects/backends/builtin/balanceeffect.h:3,
                 from ../../src/effects/backends/builtin/builtinbackend.cpp:6:
../../src/effects/backends/effectprocessor.h:170:10: warning: ‘void EffectProcessorImpl<EffectSpecificState>::process(const ChannelHandle&, const ChannelHandle&, const CSAMPLE*, CSAMPLE*, const mixxx::EngineParameters&, EffectEnableState, const GroupFeatureState&) [with EffectSpecificState = DistortionGroupState; CSAMPLE = float]’ was hidden [-Woverloaded-virtual]
  170 |     void process(const ChannelHandle& inputHandle,
      |          ^~~~~~~
In file included from ../../src/effects/backends/builtin/builtinbackend.cpp:22:
../../src/effects/backends/builtin/distortioneffect.h:55:10: warning:   by ‘DistortionEffect::process(CSAMPLE, DistortionGroupState*, CSAMPLE*, const CSAMPLE*, const mixxx::EngineParameters&)’ [-Woverloaded-virtual]
   55 |     void process(CSAMPLE driveParam,
      |          ^~~~~~~
[27/128] Building CXX object CMakeFile...ackends/builtin/distortioneffect.cpp.o
In file included from ../../src/effects/backends/builtin/distortioneffect.h:3,
                 from ../../src/effects/backends/builtin/distortioneffect.cpp:1:
../../src/effects/backends/effectprocessor.h:170:10: warning: ‘void EffectProcessorImpl<EffectSpecificState>::process(const ChannelHandle&, const ChannelHandle&, const CSAMPLE*, CSAMPLE*, const mixxx::EngineParameters&, EffectEnableState, const GroupFeatureState&) [with EffectSpecificState = DistortionGroupState; CSAMPLE = float]’ was hidden [-Woverloaded-virtual]
  170 |     void process(const ChannelHandle& inputHandle,
      |          ^~~~~~~
In file included from ../../src/effects/backends/builtin/distortioneffect.cpp:1:
../../src/effects/backends/builtin/distortioneffect.h:55:10: warning:   by ‘DistortionEffect::process(CSAMPLE, DistortionGroupState*, CSAMPLE*, const CSAMPLE*, const mixxx::EngineParameters&)’ [-Woverloaded-virtual]
   55 |     void process(CSAMPLE driveParam,
      |          ^~~~~~~
[96/128] Building CXX object CMakeFiles/mixxx-lib.dir/src/util/sample.cpp.o
../../src/util/sample.cpp: In static member function ‘static CSAMPLE SampleUtil::rms(const CSAMPLE*, SINT)’:
../../src/util/sample.cpp:458:16: warning: conversion from ‘double’ to ‘CSAMPLE’ {aka ‘float’} may change value [-Wfloat-conversion]
  458 |     return sqrt(sumSquared(pBuffer, numSamples) / numSamples);
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@daschuer
Copy link
Member

Currently our skins are not well prepared for multi stage knobs. Did you consider to add two knobs for this?

@daschuer
Copy link
Member

When cuing in the track I have a unwanted loud noise whenever playback starts.

@daschuer
Copy link
Member

This is already a fun to play wit this effect. Thank you.

Here some thoughts:

Compared to this the "soft" using tanh is actually a hard clipping known from transistors. Some guitar player prefer an even softer clipping like coming from tubes. I think the easiest way to achieve this is to cascade more tanh.

In classic stomp boxes they intentionally use slow op-amps that act like low pass taking away some of the the high pitch noise added in the current solution. Some have a tone knob to adjust that a bit. Did you consider to add something like this?

I have chained a "Filter" effect after this effect. But the Filter stops working and the sounds stops after seeks. My guess is that this is a a bug in the filter effect triggered by this effect. Are you able to reproduce it?

The folding effect sounds really crazy. But probably to noisy.

@ferranpujolcamins
Copy link
Contributor Author

Currently our skins are not well prepared for multi stage knobs. Did you consider to add two knobs for this?

What do you mean multistage?

@ferranpujolcamins
Copy link
Contributor Author

When cuing in the track I have a unwanted loud noise whenever playback starts.

I cannot reproduce. Can you provide step-by-step instructions to reproduce it?

@ferranpujolcamins
Copy link
Contributor Author

I think the easiest way to achieve this is to cascade more tanh.

I've tried this and it actually sounds a bit harsher to me!

@ferranpujolcamins
Copy link
Contributor Author

Some have a tone knob to adjust that a bit. Did you consider to add something like this?

That's a good idea, but let's leave it for another PR. As a workaround you can already place a parametric EQ or filter before/after the distortion effect.

@ferranpujolcamins
Copy link
Contributor Author

I have chained a "Filter" effect after this effect. But the Filter stops working and the sounds stops after seeks. My guess is that this is a a bug in the filter effect triggered by this effect. Are you able to reproduce it?

:O no I couldn't

@ferranpujolcamins
Copy link
Contributor Author

I though that I could also ditch the folding algorithms and replace the mode selection with a continuous "shape" parameter that morphs from a super gentle soft curve to hard clipping.

What do you think @daschuer ?

@daschuer
Copy link
Member

I though that I could also ditch the folding algorithms ....

Yes, that would be nice.

@daschuer
Copy link
Member

I need to find time to reproduce my issue step by step. Mab it was a float NAN issue or such.

@ferranpujolcamins
Copy link
Contributor Author

I though that I could also ditch the folding algorithms and replace the mode selection with a continuous "shape" parameter that morphs from a super gentle soft curve to hard clipping.

@daschuer So I removed the folding algorithms, but I haven't implemented the continuous morphing between soft and hard clipping. I'd like to move one to other stuff and maybe implement this in the future.

Is this anything else that need to be changed in this PR?

@daschuer
Copy link
Member

daschuer commented Oct 8, 2022

I need to test again. Mandatory is that follow up effects do not breake. I assume it is cased by a none value that fades not out if the filter memory.

@daschuer
Copy link
Member

Unfortunately the effect still produces nan values wen play after pause. I use this patch to visualize it:

diff --git a/src/effects/backends/builtin/distortioneffect.cpp b/src/effects/backends/builtin/distortioneffect.cpp
index 2e7f45dce4..96f24d0a67 100644
--- a/src/effects/backends/builtin/distortioneffect.cpp
+++ b/src/effects/backends/builtin/distortioneffect.cpp
@@ -122,4 +122,11 @@ void DistortionEffect::processChannel(
         SampleUtil::copy(pOutput, pInput, numSamples);
         return;
     }
+    
+    for (int i = 0; i < numSamples; ++i) {
+       if (pOutput[i] >= -1 && pOutput[i] <= 1) {
+               continue;
+       }
+       qDebug() << "DistortionEffect::processChannel" << i << pOutput[i];    
+    }   
 }

output:

Debug [Engine] DistortionEffect::processChannel 0 nan
Debug [Engine] DistortionEffect::processChannel 1 nan
...
Debug [Engine] DistortionEffect::processChannel 2046 nan
Debug [Engine] DistortionEffect::processChannel 2047 nan

@ferranpujolcamins
Copy link
Contributor Author

feenableexcept has proven very useful for debugging this.

I think the issue is now fixed.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you.

@daschuer daschuer merged commit 6843184 into mixxxdj:main Oct 25, 2022
@ronso0 ronso0 added effects and removed build labels Oct 25, 2022
@ronso0 ronso0 added the changelog This PR should be included in the changelog label Oct 25, 2022
@ronso0 ronso0 added this to the 2.4.0 milestone Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog This PR should be included in the changelog effects ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants