aboutsummaryrefslogtreecommitdiff
path: root/src/common_audio/signal_processing_library/main/source/min_max_operations.c
blob: cf5e9a7d43deabcf0529574bded5203c87f2a1c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

/*
 * This file contains the implementation of functions
 * WebRtcSpl_MaxAbsValueW16()
 * WebRtcSpl_MaxAbsIndexW16()
 * WebRtcSpl_MaxAbsValueW32()
 * WebRtcSpl_MaxValueW16()
 * WebRtcSpl_MaxIndexW16()
 * WebRtcSpl_MaxValueW32()
 * WebRtcSpl_MaxIndexW32()
 * WebRtcSpl_MinValueW16()
 * WebRtcSpl_MinIndexW16()
 * WebRtcSpl_MinValueW32()
 * WebRtcSpl_MinIndexW32()
 *
 * The description header can be found in signal_processing_library.h.
 *
 */

#include "signal_processing_library.h"

// Maximum absolute value of word16 vector.
WebRtc_Word16 WebRtcSpl_MaxAbsValueW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length)
{
    WebRtc_Word32 tempMax = 0;
    WebRtc_Word32 absVal;
    WebRtc_Word16 totMax;
    int i;
    G_CONST WebRtc_Word16 *tmpvector = vector;

#ifdef _ARM_OPT_
#pragma message("NOTE: _ARM_OPT_ optimizations are used")

    WebRtc_Word16 len4 = (length >> 2) << 2;

    for (i = 0; i < len4; i = i + 4)
    {
        absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
        if (absVal > tempMax)
        {
            tempMax = absVal;
        }
        tmpvector++;
        absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
        if (absVal > tempMax)
        {
            tempMax = absVal;
        }
        tmpvector++;
        absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
        if (absVal > tempMax)
        {
            tempMax = absVal;
        }
        tmpvector++;
        absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
        if (absVal > tempMax)
        {
            tempMax = absVal;
        }
        tmpvector++;
    }

    for (i = len4; i < len; i++)
    {
        absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
        if (absVal > tempMax)
        {
            tempMax = absVal;
        }
        tmpvector++;
    }
#else
    for (i = 0; i < length; i++)
    {
        absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
        if (absVal > tempMax)
        {
            tempMax = absVal;
        }
        tmpvector++;
    }
    totMax = (WebRtc_Word16)WEBRTC_SPL_MIN(tempMax, WEBRTC_SPL_WORD16_MAX);
    return totMax;
#endif
}

// Index of maximum absolute value in a  word16 vector.
WebRtc_Word16 WebRtcSpl_MaxAbsIndexW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length)
{
    WebRtc_Word16 tempMax;
    WebRtc_Word16 absTemp;
    WebRtc_Word16 tempMaxIndex = 0;
    WebRtc_Word16 i = 0;
    G_CONST WebRtc_Word16 *tmpvector = vector;

    tempMax = WEBRTC_SPL_ABS_W16(*tmpvector);
    tmpvector++;
    for (i = 1; i < length; i++)
    {
        absTemp = WEBRTC_SPL_ABS_W16(*tmpvector);
        tmpvector++;
        if (absTemp > tempMax)
        {
            tempMax = absTemp;
            tempMaxIndex = i;
        }
    }
    return tempMaxIndex;
}

// Maximum absolute value of word32 vector.
WebRtc_Word32 WebRtcSpl_MaxAbsValueW32(G_CONST WebRtc_Word32 *vector, WebRtc_Word16 length)
{
    WebRtc_UWord32 tempMax = 0;
    WebRtc_UWord32 absVal;
    WebRtc_Word32 retval;
    int i;
    G_CONST WebRtc_Word32 *tmpvector = vector;

    for (i = 0; i < length; i++)
    {
        absVal = WEBRTC_SPL_ABS_W32((*tmpvector));
        if (absVal > tempMax)
        {
            tempMax = absVal;
        }
        tmpvector++;
    }
    retval = (WebRtc_Word32)(WEBRTC_SPL_MIN(tempMax, WEBRTC_SPL_WORD32_MAX));
    return retval;
}

// Maximum value of word16 vector.
#ifndef XSCALE_OPT
WebRtc_Word16 WebRtcSpl_MaxValueW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length)
{
    WebRtc_Word16 tempMax;
    WebRtc_Word16 i;
    G_CONST WebRtc_Word16 *tmpvector = vector;

    tempMax = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ > tempMax)
            tempMax = vector[i];
    }
    return tempMax;
}
#else
#pragma message(">> WebRtcSpl_MaxValueW16 is excluded from this build")
#endif

// Index of maximum value in a word16 vector.
WebRtc_Word16 WebRtcSpl_MaxIndexW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length)
{
    WebRtc_Word16 tempMax;
    WebRtc_Word16 tempMaxIndex = 0;
    WebRtc_Word16 i = 0;
    G_CONST WebRtc_Word16 *tmpvector = vector;

    tempMax = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ > tempMax)
        {
            tempMax = vector[i];
            tempMaxIndex = i;
        }
    }
    return tempMaxIndex;
}

// Maximum value of word32 vector.
#ifndef XSCALE_OPT
WebRtc_Word32 WebRtcSpl_MaxValueW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length)
{
    WebRtc_Word32 tempMax;
    WebRtc_Word16 i;
    G_CONST WebRtc_Word32 *tmpvector = vector;

    tempMax = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ > tempMax)
            tempMax = vector[i];
    }
    return tempMax;
}
#else
#pragma message(">> WebRtcSpl_MaxValueW32 is excluded from this build")
#endif

// Index of maximum value in a word32 vector.
WebRtc_Word16 WebRtcSpl_MaxIndexW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length)
{
    WebRtc_Word32 tempMax;
    WebRtc_Word16 tempMaxIndex = 0;
    WebRtc_Word16 i = 0;
    G_CONST WebRtc_Word32 *tmpvector = vector;

    tempMax = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ > tempMax)
        {
            tempMax = vector[i];
            tempMaxIndex = i;
        }
    }
    return tempMaxIndex;
}

// Minimum value of word16 vector.
WebRtc_Word16 WebRtcSpl_MinValueW16(G_CONST WebRtc_Word16 *vector, WebRtc_Word16 length)
{
    WebRtc_Word16 tempMin;
    WebRtc_Word16 i;
    G_CONST WebRtc_Word16 *tmpvector = vector;

    // Find the minimum value
    tempMin = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ < tempMin)
            tempMin = (vector[i]);
    }
    return tempMin;
}

// Index of minimum value in a word16 vector.
#ifndef XSCALE_OPT
WebRtc_Word16 WebRtcSpl_MinIndexW16(G_CONST WebRtc_Word16* vector, WebRtc_Word16 length)
{
    WebRtc_Word16 tempMin;
    WebRtc_Word16 tempMinIndex = 0;
    WebRtc_Word16 i = 0;
    G_CONST WebRtc_Word16* tmpvector = vector;

    // Find index of smallest value
    tempMin = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ < tempMin)
        {
            tempMin = vector[i];
            tempMinIndex = i;
        }
    }
    return tempMinIndex;
}
#else
#pragma message(">> WebRtcSpl_MinIndexW16 is excluded from this build")
#endif

// Minimum value of word32 vector.
WebRtc_Word32 WebRtcSpl_MinValueW32(G_CONST WebRtc_Word32 *vector, WebRtc_Word16 length)
{
    WebRtc_Word32 tempMin;
    WebRtc_Word16 i;
    G_CONST WebRtc_Word32 *tmpvector = vector;

    // Find the minimum value
    tempMin = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ < tempMin)
            tempMin = (vector[i]);
    }
    return tempMin;
}

// Index of minimum value in a word32 vector.
#ifndef XSCALE_OPT
WebRtc_Word16 WebRtcSpl_MinIndexW32(G_CONST WebRtc_Word32* vector, WebRtc_Word16 length)
{
    WebRtc_Word32 tempMin;
    WebRtc_Word16 tempMinIndex = 0;
    WebRtc_Word16 i = 0;
    G_CONST WebRtc_Word32 *tmpvector = vector;

    // Find index of smallest value
    tempMin = *tmpvector++;
    for (i = 1; i < length; i++)
    {
        if (*tmpvector++ < tempMin)
        {
            tempMin = vector[i];
            tempMinIndex = i;
        }
    }
    return tempMinIndex;
}
#else
#pragma message(">> WebRtcSpl_MinIndexW32 is excluded from this build")
#endif