Home | History | Annotate | Download | only in src
      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 {
     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(
     42 char *p_in,
     43 SCALAR *p_out,
     44 int 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(
     71 char *p_in,
     72 SCALAR *p_out,
     73 int 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(
     91 char *p_in,
     92 SCALAR *p_out,
     93 int 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 ***************************************************************************************************/
    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 {
    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 
    162