Skip to content

Commit

Permalink
Refactoring of depan functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sadko4u committed Nov 12, 2024
1 parent 3162823 commit 50215f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
21 changes: 17 additions & 4 deletions include/lsp-plug.in/dsp/common/pan.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,38 @@
#include <lsp-plug.in/dsp/common/types.h>

/**
* Calculate the linear panorama position between left and right channels:
* Definition for the panorama calulation function
*
* @param dst destination buffer to store value
* @param l left channel data
* @param r right channel data
* @param dfl default value if it is not possible to compute panorama
* @param count number of samples to process
*/
typedef void (* LSP_DSP_LIB_TYPE(depan_t))(float *dst, const float *l, const float *r, float dfl, size_t count);

/**
* Calculate the linear pan law panorama position between left and right channels:
* pan = abs(R) / (abs(L) + abs(R))
*
* @param dst destination buffer to store value
* @param l left channel data
* @param r right channel data
* @param dfl default value if it is not possible to compute panorama
* @param count number of samples to process
*/
LSP_DSP_LIB_SYMBOL(void, depan_lin, float *dst, const float *l, const float *r, size_t count);
LSP_DSP_LIB_SYMBOL(void, depan_lin, float *dst, const float *l, const float *r, float dfl, size_t count);

/**
* Calculate the pan-law (quadratic) panorama position between left and right channels:
* Calculate the equal power pan law (quadratic) panorama position between left and right channels:
* pan = R^2 / (L^2 + R^2)
*
* @param dst destination buffer to store value
* @param l left channel data
* @param r right channel data
* @param dfl default value if it is not possible to compute panorama
* @param count number of samples to process
*/
LSP_DSP_LIB_SYMBOL(void, depan_panl, float *dst, const float *l, const float *r, size_t count);
LSP_DSP_LIB_SYMBOL(void, depan_eqpow, float *dst, const float *l, const float *r, float dfl, size_t count);

#endif /* LSP_PLUG_IN_DSP_COMMON_PAN_H_ */
9 changes: 4 additions & 5 deletions include/private/dsp/arch/generic/pan.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,25 @@ namespace lsp
{
namespace generic
{

void depan_lin(float *dst, const float *l, const float *r, size_t count)
void depan_lin(float *dst, const float *l, const float *r, float dfl, size_t count)
{
for (size_t i=0; i<count; ++i)
{
const float sl = fabsf(l[i]);
const float sr = fabsf(r[i]);
const float den = sl + sr;
dst[i] = (den > 1e-5f) ? sr / den : 0.5f;
dst[i] = (den > 1e-5f) ? sr / den : dfl;
}
}

void depan_panl(float *dst, const float *l, const float *r, size_t count)
void depan_eqpow(float *dst, const float *l, const float *r, float dfl, size_t count)
{
for (size_t i=0; i<count; ++i)
{
const float sl = l[i] * l[i];
const float sr = r[i] * r[i];
const float den = sl + sr;
dst[i] = (den > 1e-10f) ? sr / den : 0.5f;
dst[i] = (den > 1e-10f) ? sr / den : dfl;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/generic/generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ namespace lsp
EXPORT1(mix_add4);

EXPORT1(depan_lin);
EXPORT1(depan_panl);
EXPORT1(depan_eqpow);

EXPORT1(reverse1);
EXPORT1(reverse2);
Expand Down

0 comments on commit 50215f6

Please sign in to comment.