Skip to content

Latest commit

 

History

History
150 lines (139 loc) · 8.14 KB

corrMatrix_FIX.c

File metadata and controls

150 lines (139 loc) · 8.14 KB
 
1
2
3
4
5
6
7
8
9
10
/***********************************************************************
Copyright (c) 2006-2011, Skype Limited. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Oct 6, 2019
Oct 6, 2019
11
- Neither the name of Internet Society, IETF or IETF Trust, nor the
12
13
14
names of specific contributors, may be used to endorse or promote
products derived from this software without specific prior written
permission.
Oct 6, 2019
Oct 6, 2019
15
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/**********************************************************************
* Correlation Matrix Computations for LS estimate.
**********************************************************************/
#include "main_FIX.h"
/* Calculates correlation vector X'*t */
void silk_corrVector_FIX(
const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
const opus_int16 *t, /* I Target vector [L] */
const opus_int L, /* I Length of vectors */
const opus_int order, /* I Max lag for correlation */
opus_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */
Oct 6, 2019
Oct 6, 2019
45
46
const opus_int rshifts, /* I Right shifts of correlations */
int arch /* I Run-time architecture */
47
48
49
50
51
52
53
54
55
56
57
58
59
60
)
{
opus_int lag, i;
const opus_int16 *ptr1, *ptr2;
opus_int32 inner_prod;
ptr1 = &x[ order - 1 ]; /* Points to first sample of column 0 of X: X[:,0] */
ptr2 = t;
/* Calculate X'*t */
if( rshifts > 0 ) {
/* Right shifting used */
for( lag = 0; lag < order; lag++ ) {
inner_prod = 0;
for( i = 0; i < L; i++ ) {
Oct 6, 2019
Oct 6, 2019
61
inner_prod = silk_ADD_RSHIFT32( inner_prod, silk_SMULBB( ptr1[ i ], ptr2[i] ), rshifts );
62
63
64
65
66
67
68
}
Xt[ lag ] = inner_prod; /* X[:,lag]'*t */
ptr1--; /* Go to next column of X */
}
} else {
silk_assert( rshifts == 0 );
for( lag = 0; lag < order; lag++ ) {
Oct 6, 2019
Oct 6, 2019
69
Xt[ lag ] = silk_inner_prod_aligned( ptr1, ptr2, L, arch ); /* X[:,lag]'*t */
70
71
72
73
74
75
76
77
78
79
80
ptr1--; /* Go to next column of X */
}
}
}
/* Calculates correlation matrix X'*X */
void silk_corrMatrix_FIX(
const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
const opus_int L, /* I Length of vectors */
const opus_int order, /* I Max lag for correlation */
opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */
Oct 6, 2019
Oct 6, 2019
81
82
83
opus_int32 *nrg, /* O Energy of x vector */
opus_int *rshifts, /* O Right shifts of correlations and energy */
int arch /* I Run-time architecture */
Oct 6, 2019
Oct 6, 2019
86
opus_int i, j, lag;
87
88
89
90
opus_int32 energy;
const opus_int16 *ptr1, *ptr2;
/* Calculate energy to find shift used to fit in 32 bits */
Oct 6, 2019
Oct 6, 2019
91
92
silk_sum_sqr_shift( nrg, rshifts, x, L + order - 1 );
energy = *nrg;
93
94
95
96
/* Calculate energy of first column (0) of X: X[:,0]'*X[:,0] */
/* Remove contribution of first order - 1 samples */
for( i = 0; i < order - 1; i++ ) {
Oct 6, 2019
Oct 6, 2019
97
energy -= silk_RSHIFT32( silk_SMULBB( x[ i ], x[ i ] ), *rshifts );
98
99
100
101
102
}
/* Calculate energy of remaining columns of X: X[:,j]'*X[:,j] */
/* Fill out the diagonal of the correlation matrix */
matrix_ptr( XX, 0, 0, order ) = energy;
Oct 6, 2019
Oct 6, 2019
103
silk_assert( energy >= 0 );
104
105
ptr1 = &x[ order - 1 ]; /* First sample of column 0 of X */
for( j = 1; j < order; j++ ) {
Oct 6, 2019
Oct 6, 2019
106
107
energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr1[ L - j ] ), *rshifts ) );
energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr1[ -j ] ), *rshifts ) );
108
matrix_ptr( XX, j, j, order ) = energy;
Oct 6, 2019
Oct 6, 2019
109
silk_assert( energy >= 0 );
110
111
112
113
}
ptr2 = &x[ order - 2 ]; /* First sample of column 1 of X */
/* Calculate the remaining elements of the correlation matrix */
Oct 6, 2019
Oct 6, 2019
114
if( *rshifts > 0 ) {
115
116
117
118
119
/* Right shifting used */
for( lag = 1; lag < order; lag++ ) {
/* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */
energy = 0;
for( i = 0; i < L; i++ ) {
Oct 6, 2019
Oct 6, 2019
120
energy += silk_RSHIFT32( silk_SMULBB( ptr1[ i ], ptr2[i] ), *rshifts );
121
122
123
124
125
}
/* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */
matrix_ptr( XX, lag, 0, order ) = energy;
matrix_ptr( XX, 0, lag, order ) = energy;
for( j = 1; j < ( order - lag ); j++ ) {
Oct 6, 2019
Oct 6, 2019
126
127
energy = silk_SUB32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ), *rshifts ) );
energy = silk_ADD32( energy, silk_RSHIFT32( silk_SMULBB( ptr1[ -j ], ptr2[ -j ] ), *rshifts ) );
128
129
130
131
132
133
134
135
matrix_ptr( XX, lag + j, j, order ) = energy;
matrix_ptr( XX, j, lag + j, order ) = energy;
}
ptr2--; /* Update pointer to first sample of next column (lag) in X */
}
} else {
for( lag = 1; lag < order; lag++ ) {
/* Inner product of column 0 and column lag: X[:,0]'*X[:,lag] */
Oct 6, 2019
Oct 6, 2019
136
energy = silk_inner_prod_aligned( ptr1, ptr2, L, arch );
137
138
139
140
141
142
143
144
145
146
147
148
149
matrix_ptr( XX, lag, 0, order ) = energy;
matrix_ptr( XX, 0, lag, order ) = energy;
/* Calculate remaining off diagonal: X[:,j]'*X[:,j + lag] */
for( j = 1; j < ( order - lag ); j++ ) {
energy = silk_SUB32( energy, silk_SMULBB( ptr1[ L - j ], ptr2[ L - j ] ) );
energy = silk_SMLABB( energy, ptr1[ -j ], ptr2[ -j ] );
matrix_ptr( XX, lag + j, j, order ) = energy;
matrix_ptr( XX, j, lag + j, order ) = energy;
}
ptr2--;/* Update pointer to first sample of next column (lag) in X */
}
}
}