Skip to content

Commit

Permalink
Merge branch 'dynamics' into devel
Browse files Browse the repository at this point in the history
* Implemented SIMD-optimized gate functions for x86
  • Loading branch information
sadko4u committed Oct 19, 2023
2 parents 91ec083 + 9c1c89a commit f7607fd
Show file tree
Hide file tree
Showing 16 changed files with 2,431 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/lsp-plug.in/dsp/common/dynamics.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <lsp-plug.in/dsp/common/dynamics/types.h>
#include <lsp-plug.in/dsp/common/dynamics/compressor.h>
#include <lsp-plug.in/dsp/common/dynamics/gate.h>


#endif /* LSP_PLUG_IN_DSP_COMMON_DYNAMICS_H_ */
33 changes: 33 additions & 0 deletions include/lsp-plug.in/dsp/common/dynamics/gate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2023 Vladimir Sadovnikov <[email protected]>
*
* This file is part of lsp-dsp-lib
* Created on: 19 окт. 2023 г.
*
* lsp-dsp-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef LSP_PLUG_IN_DSP_COMMON_DYNAMICS_GATE_H_
#define LSP_PLUG_IN_DSP_COMMON_DYNAMICS_GATE_H_

#include <lsp-plug.in/dsp/common/types.h>
#include <lsp-plug.in/dsp/common/dynamics/types.h>

LSP_DSP_LIB_SYMBOL(void, gate_x1_gain, float *dst, const float *src, const LSP_DSP_LIB_TYPE(gate_knee_t) *c, size_t count);

LSP_DSP_LIB_SYMBOL(void, gate_x1_curve, float *dst, const float *src, const LSP_DSP_LIB_TYPE(gate_knee_t) *c, size_t count);


#endif /* LSP_PLUG_IN_DSP_COMMON_DYNAMICS_GATE_H_ */
28 changes: 26 additions & 2 deletions include/lsp-plug.in/dsp/common/dynamics/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LSP_DSP_LIB_BEGIN_NAMESPACE
#pragma pack(push, 1)

/**
* Compressor knee is a curve that constists of three parts:
* Compressor knee is a curve that consists of three parts:
* 1. Part with constant gain amplification in the range [-inf .. start] dB
* 2. Soft compression knee in the range (start .. end) dB present by the quadratic function (2nd-order polynom)
* 3. Gain reduction part in the range [end .. +inf] dB present by the linear function (1st-order polynom)
Expand All @@ -40,7 +40,7 @@ LSP_DSP_LIB_BEGIN_NAMESPACE
* 3. Compute the natural logarithm of the x: lx = logf(x).
* 4. If x < end then compute the gain using the 2nd-order polynom: gain = (herm[0]*lx + herm[1])*lx + herm[2]
* 5. Otherwise compute the gain using the 1st-order polynom: gain = tilt[0]*lx + tilt[1]
* 6. return expf(gain)
* 6. return expf(gain) * x
*/
typedef struct LSP_DSP_LIB_TYPE(compressor_knee_t)
{
Expand All @@ -61,6 +61,30 @@ typedef struct LSP_DSP_LIB_TYPE(compressor_x2_t)
LSP_DSP_LIB_TYPE(compressor_knee_t) k[2];
} LSP_DSP_LIB_TYPE(compressor_x2_t);


/**
* Gate knee is a curve that consists of three parts:
* 1. Part with constant gain amplification in the range [-inf .. start] dB
* 2. Transition zone in the range (start .. end) dB present by the quadratic function (2nd-order polynom)
* 3. Part with constant gain amplification in the range [end .. +inf] dB
*
* The typical algorithm of computing the gate's curve:
* 1. Take absolute value of the sample: x = fabfs(in)
* 2. If x <= start then return gain_start * x
* 3. If x <= end then return gain_end * x
* 4. Compute the natural logarithm of the x: lx = logf(x).
* 5. Compute the gain using the 3rd-order polynom: gain = ((herm[0]*lx + herm[1])*lx + herm[2]*lx) + herm[3]
* 6. return expf(gain) * x
*/
typedef struct LSP_DSP_LIB_TYPE(gate_knee_t)
{
float start; // The start of the knee, in gain units
float end; // The end of the knee, in gain units
float gain_start; // Gain below the start threshold
float gain_end; // Gain above the end threshold
float herm[4]; // Hermite interpolation of the knee with the 3rd-order polynom
} LSP_DSP_LIB_TYPE(gate_knee_t);

#pragma pack(pop)

LSP_DSP_LIB_END_NAMESPACE
Expand Down
1 change: 1 addition & 0 deletions include/private/dsp/arch/generic/dynamics.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
#endif /* PRIVATE_DSP_ARCH_GENERIC_IMPL */

#include <private/dsp/arch/generic/dynamics/compressor.h>
#include <private/dsp/arch/generic/dynamics/gate.h>

#endif /* PRIVATE_DSP_ARCH_GENERIC_DYNAMICS_H_ */
73 changes: 73 additions & 0 deletions include/private/dsp/arch/generic/dynamics/gate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2023 Vladimir Sadovnikov <[email protected]>
*
* This file is part of lsp-dsp-lib
* Created on: 19 окт. 2023 г.
*
* lsp-dsp-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef PRIVATE_DSP_ARCH_GENERIC_DYNAMICS_GATE_H_
#define PRIVATE_DSP_ARCH_GENERIC_DYNAMICS_GATE_H_

#ifndef PRIVATE_DSP_ARCH_GENERIC_IMPL
#error "This header should not be included directly"
#endif /* PRIVATE_DSP_ARCH_GENERIC_IMPL */

namespace lsp
{
namespace generic
{
void gate_x1_gain(float *dst, const float *src, const dsp::gate_knee_t *c, size_t count)
{
for (size_t i=0; i<count; ++i)
{
float x = fabsf(src[i]);
if (x <= c->start)
x = c->gain_start;
else if (x >= c->end)
x = c->gain_end;
else
{
float lx = logf(x);
x = expf(((c->herm[0]*lx + c->herm[1])*lx + c->herm[2])*lx + c->herm[3]);
}
dst[i] = x;
}
}

void gate_x1_curve(float *dst, const float *src, const dsp::gate_knee_t *c, size_t count)
{
for (size_t i=0; i<count; ++i)
{
float x = fabsf(src[i]);
if (x <= c->start)
x *= c->gain_start;
else if (x >= c->end)
x *= c->gain_end;
else
{
float lx = logf(x);
x *= expf(((c->herm[0]*lx + c->herm[1])*lx + c->herm[2])*lx + c->herm[3]);
}
dst[i] = x;
}
}
} /* namespace generic */
} /* namespace lsp */



#endif /* PRIVATE_DSP_ARCH_GENERIC_DYNAMICS_GATE_H_ */
1 change: 1 addition & 0 deletions include/private/dsp/arch/x86/avx2/dynamics.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif /* PRIVATE_DSP_ARCH_X86_AVX2_IMPL */

#include <private/dsp/arch/x86/avx2/dynamics/compressor.h>
#include <private/dsp/arch/x86/avx2/dynamics/gate.h>


#endif /* PRIVATE_DSP_ARCH_X86_AVX2_DYNAMICS_H_ */
Loading

0 comments on commit f7607fd

Please sign in to comment.