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 #include <string.h>
22 #include "VectorArithmetic.h"
23
Copy_Float(const LVM_FLOAT * src,LVM_FLOAT * dst,LVM_INT16 n)24 void Copy_Float(const LVM_FLOAT* src, LVM_FLOAT* dst, LVM_INT16 n) {
25 memmove(dst, src, n * sizeof(LVM_FLOAT));
26 return;
27 }
28 // 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)29 void Copy_Float_Mc_Stereo(const LVM_FLOAT* src, LVM_FLOAT* dst,
30 LVM_INT16 NrFrames, /* Number of frames */
31 LVM_INT32 NrChannels) {
32 LVM_INT16 ii;
33
34 if (NrChannels >= 2) {
35 for (ii = NrFrames; ii != 0; ii--) {
36 dst[0] = src[0];
37 dst[1] = src[1];
38 dst += 2;
39 src += NrChannels;
40 }
41 } else if (NrChannels == 1) { // not expected to occur, provided for completeness.
42 src += (NrFrames - 1);
43 dst += 2 * (NrFrames - 1);
44 for (ii = NrFrames; ii != 0; ii--) {
45 dst[0] = src[0];
46 dst[1] = src[0];
47 dst -= 2;
48 src--;
49 }
50 }
51 }
52
53 // Merge a multichannel source with stereo contained in StereoOut, to dst.
Copy_Float_Stereo_Mc(const LVM_FLOAT * src,const LVM_FLOAT * StereoOut,LVM_FLOAT * dst,LVM_INT16 NrFrames,LVM_INT32 NrChannels)54 void Copy_Float_Stereo_Mc(const LVM_FLOAT* src, const LVM_FLOAT* StereoOut, LVM_FLOAT* dst,
55 LVM_INT16 NrFrames, /* Number of frames*/
56 LVM_INT32 NrChannels) {
57 LVM_INT16 ii, jj;
58
59 if (NrChannels >= FCC_2) {
60 // pack dst with stereo information of StereoOut
61 // together with the upper channels of src.
62 StereoOut += 2 * (NrFrames - 1);
63 dst += NrChannels * (NrFrames - 1);
64 src += NrChannels * (NrFrames - 1);
65
66 for (ii = NrFrames; ii != 0; ii--) {
67 dst[1] = StereoOut[1];
68 dst[0] = StereoOut[0]; // copy 1 before 0 is required for NrChannels == 3.
69 for (jj = FCC_2; jj < NrChannels; jj++) {
70 dst[jj] = src[jj];
71 }
72 dst -= NrChannels;
73 src -= NrChannels;
74 StereoOut -= 2;
75 }
76 } else {
77 Copy_Float((const LVM_FLOAT*)StereoOut, /* Source */
78 (LVM_FLOAT*)dst, /* Destination */
79 (LVM_INT16)NrFrames); /* Number of frames */
80 }
81 }
82 /**********************************************************************************/
83