• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ***************************************************************************************************/
byte_data_to_int_s16_ldac(char * p_in,INT32 * p_out,int nsmpl)22 __inline static void byte_data_to_int_s16_ldac(
23 char *p_in,
24 INT32 *p_out,
25 int 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++ = lsft_ldac((INT32)*p_s++, LDAC_Q_SETPCM);
33     }
34 
35     return;
36 }
37 
38 /***************************************************************************************************
39     Subfunction: Convert from 24bit Signed Integer PCM
40 ***************************************************************************************************/
byte_data_to_int_s24_ldac(char * p_in,INT32 * p_out,int nsmpl)41 __inline static void byte_data_to_int_s24_ldac(
42 char *p_in,
43 INT32 *p_out,
44 int nsmpl)
45 {
46     int i, val;
47     char *p_c;
48 
49     p_c = (char *)p_in;
50     for (i = 0; i < nsmpl; i++) {
51 #ifdef LDAC_HOST_ENDIAN_LITTLE
52         val  = 0x000000ff & (*p_c++);
53         val |= 0x0000ff00 & (*p_c++ << 8);
54         val |= 0xffff0000 & (*p_c++ << 16);
55 #else /* LDAC_HOST_ENDIAN_LITTLE */
56         val  = 0xffff0000 & (*p_c++ << 16);
57         val |= 0x0000ff00 & (*p_c++ << 8);
58         val |= 0x000000ff & (*p_c++);
59 #endif /* LDAC_HOST_ENDIAN_LITTLE */
60         *p_out++ = (INT32)((val << 8) >> 1); /* Sign Extension */
61     }
62 
63     return;
64 }
65 
66 /***************************************************************************************************
67     Subfunction: Convert from 32bit Signed Integer PCM
68 ***************************************************************************************************/
byte_data_to_int_s32_ldac(char * p_in,INT32 * p_out,int nsmpl)69 __inline static void byte_data_to_int_s32_ldac(
70 char *p_in,
71 INT32 *p_out,
72 int nsmpl)
73 {
74     int i;
75     int *p_l;
76 
77     p_l = (int *)p_in;
78     for (i = 0; i < nsmpl; i++) {
79         *p_out++ = rsft_ldac((INT32)*p_l++, 16-LDAC_Q_SETPCM);
80     }
81 
82     return;
83 }
84 
85 /***************************************************************************************************
86     Set Input PCM
87 ***************************************************************************************************/
set_input_pcm_ldac(SFINFO * p_sfinfo,char * pp_pcm[],LDAC_SMPL_FMT_T format,int nlnn)88 DECLFUNC void set_input_pcm_ldac(
89 SFINFO *p_sfinfo,
90 char *pp_pcm[],
91 LDAC_SMPL_FMT_T format,
92 int nlnn)
93 {
94     int ich, isp;
95     int nchs = p_sfinfo->cfg.ch;
96     int nsmpl = npow2_ldac(nlnn);
97     INT32 *p_time;
98 
99     if (format == LDAC_SMPL_FMT_S16) {
100         for (ich = 0; ich < nchs; ich++) {
101             p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
102             for (isp = 0; isp < nsmpl; isp++) {
103                 p_time[isp] = p_time[nsmpl+isp];
104             }
105             byte_data_to_int_s16_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
106         }
107     }
108     else if (format == LDAC_SMPL_FMT_S24) {
109         for (ich = 0; ich < nchs; ich++) {
110             p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
111             for (isp = 0; isp < nsmpl; isp++) {
112                 p_time[isp] = p_time[nsmpl+isp];
113             }
114             byte_data_to_int_s24_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
115         }
116     }
117     else if (format == LDAC_SMPL_FMT_S32) {
118         for (ich = 0; ich < nchs; ich++) {
119             p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
120             for (isp = 0; isp < nsmpl; isp++) {
121                 p_time[isp] = p_time[nsmpl+isp];
122             }
123             byte_data_to_int_s32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
124         }
125     }
126 
127     return;
128 }
129 
130 
131