blob: 50e3ed98d11ee76ede14f51f0d501607942ca554 [file] [log] [blame]
Chisato Kenmochi94704432017-01-10 11:56:48 +09001/*
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(
23char *p_in,
24SCALAR *p_out,
25int nsmpl)
26{
27 int i;
28 short *p_s;
29
30 p_s = (short *)p_in;
31 for (i = 0; i < nsmpl; i++) {
32 *p_out++ = (SCALAR)*p_s++;
33 }
34
35 return;
36}
37
38/***************************************************************************************************
39 Subfunction: Convert from 24bit Signed Integer PCM
40***************************************************************************************************/
41__inline static void byte_data_to_scalar_s24_ldac(
42char *p_in,
43SCALAR *p_out,
44int nsmpl)
45{
46 int i, val;
47 char *p_c;
48 SCALAR scale = _scalar(1.0) / _scalar(65536.0);
49
50 p_c = (char *)p_in;
51 for (i = 0; i < nsmpl; i++) {
52#ifdef LDAC_HOST_ENDIAN_LITTLE
53 val = 0x000000ff & (*p_c++);
54 val |= 0x0000ff00 & (*p_c++ << 8);
55 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 *p_out++ = scale * (SCALAR)(val << 8); /* Sign Extension */
62 }
63
64 return;
65}
66
67/***************************************************************************************************
68 Subfunction: Convert from 32bit Signed Integer PCM
69***************************************************************************************************/
70__inline static void byte_data_to_scalar_s32_ldac(
71char *p_in,
72SCALAR *p_out,
73int nsmpl)
74{
75 int i;
76 int *p_l;
77 SCALAR scale = _scalar(1.0) / _scalar(65536.0);
78
79 p_l = (int *)p_in;
80 for (i = 0; i < nsmpl; i++) {
81 *p_out++ = scale * (SCALAR)*p_l++;
82 }
83
84 return;
85}
86
87/***************************************************************************************************
88 Subfunction: Convert from 32bit Float PCM
89***************************************************************************************************/
90__inline static void byte_data_to_scalar_f32_ldac(
91char *p_in,
92SCALAR *p_out,
93int nsmpl)
94{
95 int i;
96 float *p_f;
97 SCALAR scale = _scalar(32768.0);
98
99 p_f = (float *)p_in;
100 for (i = 0; i < nsmpl; i++) {
101 *p_out++ = scale * (SCALAR)*p_f++;
102 }
103
104 return;
105}
106
107/***************************************************************************************************
108 Set Input PCM
109***************************************************************************************************/
110DECLFUNC void set_input_pcm_ldac(
111SFINFO *p_sfinfo,
112char *pp_pcm[],
113LDAC_SMPL_FMT_T format,
114int nlnn)
115{
116 int ich, isp;
117 int nchs = p_sfinfo->cfg.ch;
118 int nsmpl = npow2_ldac(nlnn);
119 SCALAR *p_time;
120
121 if (format == LDAC_SMPL_FMT_S16) {
122 for (ich = 0; ich < nchs; ich++) {
123 p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
124 for (isp = 0; isp < nsmpl; isp++) {
125 p_time[isp] = p_time[nsmpl+isp];
126 }
127 byte_data_to_scalar_s16_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
128 }
129 }
130 else if (format == LDAC_SMPL_FMT_S24) {
131 for (ich = 0; ich < nchs; ich++) {
132 p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
133 for (isp = 0; isp < nsmpl; isp++) {
134 p_time[isp] = p_time[nsmpl+isp];
135 }
136 byte_data_to_scalar_s24_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
137 }
138 }
139 else if (format == LDAC_SMPL_FMT_S32) {
140 for (ich = 0; ich < nchs; ich++) {
141 p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
142 for (isp = 0; isp < nsmpl; isp++) {
143 p_time[isp] = p_time[nsmpl+isp];
144 }
145 byte_data_to_scalar_s32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
146 }
147 }
148 else if (format == LDAC_SMPL_FMT_F32) {
149 for (ich = 0; ich < nchs; ich++) {
150 p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
151 for (isp = 0; isp < nsmpl; isp++) {
152 p_time[isp] = p_time[nsmpl+isp];
153 }
154 byte_data_to_scalar_f32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
155 }
156 }
157
158 return;
159}
160
161