Skip to content

Commit

Permalink
Release 1.0.22
Browse files Browse the repository at this point in the history
* Implemented functions for computing correlation between two signals.
* Fixed error in AVX and AVX-512 implementation of lr_to_ms functions.
* Updated build scripts.
* Updated module versions in dependencies.
  • Loading branch information
sadko4u committed Apr 26, 2024
2 parents a5d84cc + be5243b commit 12d93ce
Show file tree
Hide file tree
Showing 32 changed files with 3,484 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
* RECENT CHANGES
*******************************************************************************

=== 1.0.22 ===
* Implemented functions for computing correlation between two signals.
* Fixed error in AVX and AVX-512 implementation of lr_to_ms functions.
* Updated build scripts.
* Updated module versions in dependencies.

=== 1.0.21 ===
* Updated build scripts.
* Updated module versions in dependencies.
Expand Down
87 changes: 87 additions & 0 deletions include/lsp-plug.in/dsp/common/correlation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <[email protected]>
*
* This file is part of lsp-dsp-lib
* Created on: 7 мар. 2024 г.
*
* 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_CORRELATION_H_
#define LSP_PLUG_IN_DSP_COMMON_CORRELATION_H_

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

LSP_DSP_LIB_BEGIN_NAMESPACE

#pragma pack(push, 1)

/**
* Object to store correlation state.
*
* The correlation is computed using the following formula:
*
* sum(a[i] * b[i])
* corr = ---------------------------------------
* sqrt(sum(a[i]*a[i]) * sum(b[i]*b[i]))
*
* where i is in range of 0 to count-1.
*
*/
typedef struct LSP_DSP_LIB_TYPE(correlation_t)
{
float v; // the aggregated value of sum(a*b)
float a; // the aggregated value of sum(a*a)
float b; // the aggregated value of sum(b*b)
} LSP_DSP_LIB_TYPE(correlation_t);

#pragma pack(pop)

LSP_DSP_LIB_END_NAMESPACE

/**
* Compute the initial intermediate values of correlation between two signals,
* the function can be called multiple times, so the value of corr structure
* should be cleared before first call.
*
* @param corr the object to initialize with intermediate results
* @param a the pointer to the first signal buffer
* @param b the pointer to the second signal buffer
* @param count number of samples to process
*/
LSP_DSP_LIB_SYMBOL(void, corr_init,
LSP_DSP_LIB_TYPE(correlation_t) *corr,
const float *a, const float *b,
size_t count);

/**
* Compute incremental value of normalized correlation between two signals
*
* @param corr the object that holds intermediate results
* @param dst destination buffer to store result
* @param a_head the pointer to the head of the first signal buffer
* @param b_head the pointer to the head of the second signal buffer
* @param a_tail the pointer to the tail of the first signal buffer
* @param b_tail the pointer to the tail of the second signal buffer
* @param head the offset of the head element relative to the first one in correlation (length of the window minus one)
* @param count number of samples to process
*/
LSP_DSP_LIB_SYMBOL(void, corr_incr,
LSP_DSP_LIB_TYPE(correlation_t) *corr,
float *dst,
const float *a_head, const float *b_head,
const float *a_tail, const float *b_tail,
size_t count);

#endif /* LSP_PLUG_IN_DSP_COMMON_CORRELATION_H_ */
1 change: 1 addition & 0 deletions include/lsp-plug.in/dsp/dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <lsp-plug.in/dsp/common/complex.h>
#include <lsp-plug.in/dsp/common/context.h>
#include <lsp-plug.in/dsp/common/convolution.h>
#include <lsp-plug.in/dsp/common/correlation.h>
#include <lsp-plug.in/dsp/common/copy.h>
#include <lsp-plug.in/dsp/common/dynamics.h>
#include <lsp-plug.in/dsp/common/fastconv.h>
Expand Down
2 changes: 1 addition & 1 deletion include/lsp-plug.in/dsp/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Define version of headers
#define LSP_DSP_LIB_MAJOR 1
#define LSP_DSP_LIB_MINOR 0
#define LSP_DSP_LIB_MICRO 21
#define LSP_DSP_LIB_MICRO 22

#if defined(__WINDOWS__) || defined(__WIN32__) || defined(__WIN64__) || defined(_WIN64) || defined(_WIN32) || defined(__WINNT) || defined(__WINNT__)
#define LSP_DSP_LIB_EXPORT_MODIFIER __declspec(dllexport)
Expand Down
361 changes: 361 additions & 0 deletions include/private/dsp/arch/aarch64/asimd/correlation.h

Large diffs are not rendered by default.

337 changes: 337 additions & 0 deletions include/private/dsp/arch/arm/neon-d32/correlation.h

Large diffs are not rendered by default.

198 changes: 198 additions & 0 deletions include/private/dsp/arch/generic/correlation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <[email protected]>
*
* This file is part of lsp-dsp-lib
* Created on: 8 мар. 2024 г.
*
* 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 deheads.
*
* 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_CORRELATION_H_
#define PRIVATE_DSP_ARCH_GENERIC_CORRELATION_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 corr_init(dsp::correlation_t *corr, const float *a, const float *b, size_t count)
{
float xv = 0.0f;
float xa = 0.0f;
float xb = 0.0f;

if (count >= 4)
{
float T[4], A[4], B[4];

T[0] = 0.0f;
T[1] = 0.0f;
T[2] = 0.0f;
T[3] = 0.0f;

A[0] = 0.0f;
A[1] = 0.0f;
A[2] = 0.0f;
A[3] = 0.0f;

B[0] = 0.0f;
B[1] = 0.0f;
B[2] = 0.0f;
B[3] = 0.0f;

for ( ; count >= 4; count -= 4)
{
T[0] += a[0] * b[0];
T[1] += a[1] * b[1];
T[2] += a[2] * b[2];
T[3] += a[3] * b[3];

A[0] += a[0] * a[0];
A[1] += a[1] * a[1];
A[2] += a[2] * a[2];
A[3] += a[3] * a[3];

B[0] += b[0] * b[0];
B[1] += b[1] * b[1];
B[2] += b[2] * b[2];
B[3] += b[3] * b[3];

a += 4;
b += 4;
}

xv = T[0] + T[1] + T[2] + T[3];
xa = A[0] + A[1] + A[2] + A[3];
xb = B[0] + B[1] + B[2] + B[3];
}

for ( ; count > 0; --count)
{
xv += a[0] * b[0];
xa += a[0] * a[0];
xb += b[0] * b[0];

a += 1;
b += 1;
}

corr->v += xv;
corr->a += xa;
corr->b += xb;
}

void corr_incr(dsp::correlation_t *corr, float *dst,
const float *a_head, const float *b_head,
const float *a_tail, const float *b_tail,
size_t count)
{
float T[4], BA[4], BB[4], B[4], DV[4], DA[4], DB[4];

float vv = corr->v;
float va = corr->a;
float vb = corr->b;

for ( ; count >= 4; count -= 4)
{
DV[0] = a_head[0]*b_head[0] - a_tail[0]*b_tail[0];
DV[1] = a_head[1]*b_head[1] - a_tail[1]*b_tail[1];
DV[2] = a_head[2]*b_head[2] - a_tail[2]*b_tail[2];
DV[3] = a_head[3]*b_head[3] - a_tail[3]*b_tail[3];

DA[0] = a_head[0]*a_head[0] - a_tail[0]*a_tail[0];
DA[1] = a_head[1]*a_head[1] - a_tail[1]*a_tail[1];
DA[2] = a_head[2]*a_head[2] - a_tail[2]*a_tail[2];
DA[3] = a_head[3]*a_head[3] - a_tail[3]*a_tail[3];

DB[0] = b_head[0]*b_head[0] - b_tail[0]*b_tail[0];
DB[1] = b_head[1]*b_head[1] - b_tail[1]*b_tail[1];
DB[2] = b_head[2]*b_head[2] - b_tail[2]*b_tail[2];
DB[3] = b_head[3]*b_head[3] - b_tail[3]*b_tail[3];

T[0] = vv + DV[0];
T[1] = T[0] + DV[1];
T[2] = T[1] + DV[2];
T[3] = T[2] + DV[3];

BA[0] = va + DA[0];
BA[1] = BA[0] + DA[1];
BA[2] = BA[1] + DA[2];
BA[3] = BA[2] + DA[3];

BB[0] = vb + DB[0];
BB[1] = BB[0] + DB[1];
BB[2] = BB[1] + DB[2];
BB[3] = BB[2] + DB[3];

B[0] = BA[0] * BB[0];
B[1] = BA[1] * BB[1];
B[2] = BA[2] * BB[2];
B[3] = BA[3] * BB[3];

dst[0] = (B[0] >= 1e-10f) ? T[0] / sqrtf(B[0]) : 0.0f;
dst[1] = (B[1] >= 1e-10f) ? T[1] / sqrtf(B[1]) : 0.0f;
dst[2] = (B[2] >= 1e-10f) ? T[2] / sqrtf(B[2]) : 0.0f;
dst[3] = (B[3] >= 1e-10f) ? T[3] / sqrtf(B[3]) : 0.0f;

vv = T[3];
va = BA[3];
vb = BB[3];

a_head += 4;
b_head += 4;
a_tail += 4;
b_tail += 4;
dst += 4;
}

for (; count > 0; --count)
{
DV[0] = a_head[0]*b_head[0] - a_tail[0]*b_tail[0];
DA[0] = a_head[0]*a_head[0] - a_tail[0]*a_tail[0];
DB[0] = b_head[0]*b_head[0] - b_tail[0]*b_tail[0];

T[0] = vv + DV[0];
BA[0] = va + DA[0];
BB[0] = vb + DB[0];
B[0] = BA[0] * BB[0];

dst[0] = (B[0] >= 1e-10f) ? T[0] / sqrtf(B[0]) : 0.0f;

vv = T[0];
va = BA[0];
vb = BB[0];

a_head += 1;
b_head += 1;
a_tail += 1;
b_tail += 1;
dst += 1;
}

corr->v = vv;
corr->a = va;
corr->b = vb;
}

} /* namespace generic */
} /* namespace lsp */



#endif /* PRIVATE_DSP_ARCH_GENERIC_CORRELATION_H_ */
Loading

0 comments on commit 12d93ce

Please sign in to comment.