xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_sbr_misc.c (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
1 /******************************************************************************
2  *                                                                            *
3  * Copyright (C) 2023 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19  */
20 
21 #include "ixheaac_type_def.h"
22 #include "ixheaace_sbr_misc.h"
23 
ixheaace_shellsort_int(WORD32 * ptr_in,WORD32 n)24 VOID ixheaace_shellsort_int(WORD32 *ptr_in, WORD32 n) {
25   WORD32 i, j, v;
26   WORD32 inc = 1;
27 
28   do {
29     inc = 3 * inc + 1;
30   } while (inc <= n);
31 
32   do {
33     inc = inc / 3;
34 
35     for (i = inc + 1; i <= n; i++) {
36       v = ptr_in[i - 1];
37       j = i;
38 
39       while (ptr_in[j - inc - 1] > v) {
40         ptr_in[j - 1] = ptr_in[j - inc - 1];
41         j -= inc;
42 
43         if (j <= inc) {
44           break;
45         }
46       }
47 
48       ptr_in[j - 1] = v;
49     }
50   } while (inc > 1);
51 }
52 
ixheaace_add_vec_left(WORD32 * ptr_dst,WORD32 * ptr_length_dst,WORD32 * ptr_src,WORD32 length_src)53 VOID ixheaace_add_vec_left(WORD32 *ptr_dst, WORD32 *ptr_length_dst, WORD32 *ptr_src,
54                            WORD32 length_src) {
55   WORD32 i;
56 
57   for (i = length_src - 1; i >= 0; i--) {
58     ixheaace_add_left(ptr_dst, ptr_length_dst, ptr_src[i]);
59   }
60 }
61 
ixheaace_add_left(WORD32 * ptr_vector,WORD32 * ptr_length_vector,WORD32 value)62 VOID ixheaace_add_left(WORD32 *ptr_vector, WORD32 *ptr_length_vector, WORD32 value) {
63   WORD32 i;
64 
65   for (i = *ptr_length_vector; i > 0; i--) {
66     ptr_vector[i] = ptr_vector[i - 1];
67   }
68 
69   ptr_vector[0] = value;
70 
71   (*ptr_length_vector)++;
72 }
73 
ixheaace_add_right(WORD32 * ptr_vector,WORD32 * ptr_length_vector,WORD32 value)74 VOID ixheaace_add_right(WORD32 *ptr_vector, WORD32 *ptr_length_vector, WORD32 value) {
75   ptr_vector[*ptr_length_vector] = value;
76 
77   (*ptr_length_vector)++;
78 }
79