/src/libldac/src/setpcm_ldac.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2003 - 2016 Sony Corporation |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #include "ldac.h" |
18 | | |
19 | | /*************************************************************************************************** |
20 | | Subfunction: Convert from 16bit Signed Integer PCM |
21 | | ***************************************************************************************************/ |
22 | | __inline static void byte_data_to_scalar_s16_ldac( |
23 | | char *p_in, |
24 | | SCALAR *p_out, |
25 | | int nsmpl) |
26 | 44 | { |
27 | 44 | int i; |
28 | 44 | short *p_s; |
29 | | |
30 | 44 | p_s = (short *)p_in; |
31 | 5.67k | for (i = 0; i < nsmpl; i++) { |
32 | 5.63k | *p_out++ = (SCALAR)*p_s++; |
33 | 5.63k | } |
34 | | |
35 | 44 | return; |
36 | 44 | } |
37 | | |
38 | | /*************************************************************************************************** |
39 | | Subfunction: Convert from 24bit Signed Integer PCM |
40 | | ***************************************************************************************************/ |
41 | | __inline static void byte_data_to_scalar_s24_ldac( |
42 | | char *p_in, |
43 | | SCALAR *p_out, |
44 | | int nsmpl) |
45 | 0 | { |
46 | 0 | int i, val; |
47 | 0 | char *p_c; |
48 | 0 | SCALAR scale = _scalar(1.0) / _scalar(65536.0); |
49 | |
|
50 | 0 | p_c = (char *)p_in; |
51 | 0 | for (i = 0; i < nsmpl; i++) { |
52 | 0 | #ifdef LDAC_HOST_ENDIAN_LITTLE |
53 | 0 | val = 0x000000ff & (*p_c++); |
54 | 0 | val |= 0x0000ff00 & (*p_c++ << 8); |
55 | 0 | val |= 0xffff0000 & (*p_c++ << 16); |
56 | | #else /* LDAC_HOST_ENDIAN_LITTLE */ |
57 | | val = 0xffff0000 & (*p_c++ << 16); |
58 | | val |= 0x0000ff00 & (*p_c++ << 8); |
59 | | val |= 0x000000ff & (*p_c++); |
60 | | #endif /* LDAC_HOST_ENDIAN_LITTLE */ |
61 | 0 | *p_out++ = scale * (SCALAR)(val << 8); /* Sign Extension */ |
62 | 0 | } |
63 | |
|
64 | 0 | return; |
65 | 0 | } |
66 | | |
67 | | /*************************************************************************************************** |
68 | | Subfunction: Convert from 32bit Signed Integer PCM |
69 | | ***************************************************************************************************/ |
70 | | __inline static void byte_data_to_scalar_s32_ldac( |
71 | | char *p_in, |
72 | | SCALAR *p_out, |
73 | | int nsmpl) |
74 | 0 | { |
75 | 0 | int i; |
76 | 0 | int *p_l; |
77 | 0 | SCALAR scale = _scalar(1.0) / _scalar(65536.0); |
78 | |
|
79 | 0 | p_l = (int *)p_in; |
80 | 0 | for (i = 0; i < nsmpl; i++) { |
81 | 0 | *p_out++ = scale * (SCALAR)*p_l++; |
82 | 0 | } |
83 | |
|
84 | 0 | return; |
85 | 0 | } |
86 | | |
87 | | /*************************************************************************************************** |
88 | | Subfunction: Convert from 32bit Float PCM |
89 | | ***************************************************************************************************/ |
90 | | __inline static void byte_data_to_scalar_f32_ldac( |
91 | | char *p_in, |
92 | | SCALAR *p_out, |
93 | | int nsmpl) |
94 | 0 | { |
95 | 0 | int i; |
96 | 0 | float *p_f; |
97 | 0 | SCALAR scale = _scalar(32768.0); |
98 | |
|
99 | 0 | p_f = (float *)p_in; |
100 | 0 | for (i = 0; i < nsmpl; i++) { |
101 | 0 | *p_out++ = scale * (SCALAR)*p_f++; |
102 | 0 | } |
103 | |
|
104 | 0 | return; |
105 | 0 | } |
106 | | |
107 | | /*************************************************************************************************** |
108 | | Set Input PCM |
109 | | ***************************************************************************************************/ |
110 | | DECLFUNC void set_input_pcm_ldac( |
111 | | SFINFO *p_sfinfo, |
112 | | char *pp_pcm[], |
113 | | LDAC_SMPL_FMT_T format, |
114 | | int nlnn) |
115 | 22 | { |
116 | 22 | int ich, isp; |
117 | 22 | int nchs = p_sfinfo->cfg.ch; |
118 | 22 | int nsmpl = npow2_ldac(nlnn); |
119 | 22 | SCALAR *p_time; |
120 | | |
121 | 22 | if (format == LDAC_SMPL_FMT_S16) { |
122 | 66 | for (ich = 0; ich < nchs; ich++) { |
123 | 44 | p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time; |
124 | 5.67k | for (isp = 0; isp < nsmpl; isp++) { |
125 | 5.63k | p_time[isp] = p_time[nsmpl+isp]; |
126 | 5.63k | } |
127 | 44 | byte_data_to_scalar_s16_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl); |
128 | 44 | } |
129 | 22 | } |
130 | 0 | else if (format == LDAC_SMPL_FMT_S24) { |
131 | 0 | for (ich = 0; ich < nchs; ich++) { |
132 | 0 | p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time; |
133 | 0 | for (isp = 0; isp < nsmpl; isp++) { |
134 | 0 | p_time[isp] = p_time[nsmpl+isp]; |
135 | 0 | } |
136 | 0 | byte_data_to_scalar_s24_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl); |
137 | 0 | } |
138 | 0 | } |
139 | 0 | else if (format == LDAC_SMPL_FMT_S32) { |
140 | 0 | for (ich = 0; ich < nchs; ich++) { |
141 | 0 | p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time; |
142 | 0 | for (isp = 0; isp < nsmpl; isp++) { |
143 | 0 | p_time[isp] = p_time[nsmpl+isp]; |
144 | 0 | } |
145 | 0 | byte_data_to_scalar_s32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl); |
146 | 0 | } |
147 | 0 | } |
148 | 0 | else if (format == LDAC_SMPL_FMT_F32) { |
149 | 0 | for (ich = 0; ich < nchs; ich++) { |
150 | 0 | p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time; |
151 | 0 | for (isp = 0; isp < nsmpl; isp++) { |
152 | 0 | p_time[isp] = p_time[nsmpl+isp]; |
153 | 0 | } |
154 | 0 | byte_data_to_scalar_f32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl); |
155 | 0 | } |
156 | 0 | } |
157 | | |
158 | 22 | return; |
159 | 22 | } |
160 | | |
161 | | |