1 /*
2 * Copyright (C) 2004-2010 NXP Software
3 * Copyright (C) 2010 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 /**********************************************************************************
19 INCLUDE FILES
20 ***********************************************************************************/
21
22 #include "VectorArithmetic.h"
23
24 /**********************************************************************************
25 FUNCTION COPY_16
26 ***********************************************************************************/
27
Copy_16(const LVM_INT16 * src,LVM_INT16 * dst,LVM_INT16 n)28 void Copy_16( const LVM_INT16 *src,
29 LVM_INT16 *dst,
30 LVM_INT16 n )
31 {
32 LVM_INT16 ii;
33
34 if (src > dst)
35 {
36 for (ii = n; ii != 0; ii--)
37 {
38 *dst = *src;
39 dst++;
40 src++;
41 }
42 }
43 else
44 {
45 src += n - 1;
46 dst += n - 1;
47 for (ii = n; ii != 0; ii--)
48 {
49 *dst = *src;
50 dst--;
51 src--;
52 }
53 }
54
55 return;
56 }
Copy_Float(const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 n)57 void Copy_Float( const LVM_FLOAT *src,
58 LVM_FLOAT *dst,
59 LVM_INT16 n )
60 {
61 LVM_INT16 ii;
62
63 if (src > dst)
64 {
65 for (ii = n; ii != 0; ii--)
66 {
67 *dst = *src;
68 dst++;
69 src++;
70 }
71 }
72 else
73 {
74 src += n - 1;
75 dst += n - 1;
76 for (ii = n; ii != 0; ii--)
77 {
78 *dst = *src;
79 dst--;
80 src--;
81 }
82 }
83
84 return;
85 }
86 #ifdef SUPPORT_MC
87 // Extract out the stereo channel pair from multichannel source.
Copy_Float_Mc_Stereo(const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 NrFrames,LVM_INT32 NrChannels)88 void Copy_Float_Mc_Stereo(const LVM_FLOAT *src,
89 LVM_FLOAT *dst,
90 LVM_INT16 NrFrames, /* Number of frames */
91 LVM_INT32 NrChannels)
92 {
93 LVM_INT16 ii;
94
95 if (NrChannels >= 2)
96 {
97 for (ii = NrFrames; ii != 0; ii--)
98 {
99 dst[0] = src[0];
100 dst[1] = src[1];
101 dst += 2;
102 src += NrChannels;
103 }
104 }
105 else if (NrChannels == 1)
106 { // not expected to occur, provided for completeness.
107 src += (NrFrames - 1);
108 dst += 2 * (NrFrames - 1);
109 for (ii = NrFrames; ii != 0; ii--)
110 {
111 dst[0] = src[0];
112 dst[1] = src[0];
113 dst -= 2;
114 src --;
115 }
116 }
117 }
118
119 // Merge a multichannel source with stereo contained in StereoOut, to dst.
Copy_Float_Stereo_Mc(const LVM_FLOAT * src,LVM_FLOAT * StereoOut,LVM_FLOAT * dst,LVM_INT16 NrFrames,LVM_INT32 NrChannels)120 void Copy_Float_Stereo_Mc(const LVM_FLOAT *src,
121 LVM_FLOAT *StereoOut,
122 LVM_FLOAT *dst,
123 LVM_INT16 NrFrames, /* Number of frames*/
124 LVM_INT32 NrChannels)
125 {
126 LVM_INT16 ii, jj;
127
128 // pack dst with stereo information of StereoOut
129 // together with the upper channels of src.
130 StereoOut += 2 * (NrFrames - 1);
131 dst += NrChannels * (NrFrames - 1);
132 src += NrChannels * (NrFrames - 1);
133 for (ii = NrFrames; ii != 0; ii--)
134 {
135 dst[1] = StereoOut[1];
136 dst[0] = StereoOut[0]; // copy 1 before 0 is required for NrChannels == 3.
137 for (jj = 2; jj < NrChannels; jj++)
138 {
139 dst[jj] = src[jj];
140 }
141 dst -= NrChannels;
142 src -= NrChannels;
143 StereoOut -= 2;
144 }
145 }
146 #endif
147 /**********************************************************************************/
148