1 /* 2 * Copyright (C) 2013 - 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 "ldacBT_internal.h" 18 19 20 21 enum { 22 /* 2-DH5 */ 23 LDACBT_2DH5_02, LDACBT_2DH5_03, LDACBT_2DH5_04, LDACBT_2DH5_05, 24 LDACBT_2DH5_06, LDACBT_2DH5_07, LDACBT_2DH5_08, LDACBT_2DH5_09, LDACBT_2DH5_10, 25 LDACBT_2DH5_11, LDACBT_2DH5_12, LDACBT_2DH5_13, LDACBT_2DH5_14, 26 }; 27 28 #define LDACBT_NO_DEF_ -1 29 DECLFUNC const LDACBT_EQMID_PROPERTY tbl_ldacbt_eqmid_property[] = { 30 /* kbps, ID , label, ID for 2DH5 */ 31 /* 990 */ { LDACBT_EQMID_HQ, "HQ" , LDACBT_2DH5_02 }, 32 /* 660 */ { LDACBT_EQMID_SQ, "SQ" , LDACBT_2DH5_03 }, 33 /* 492 */ { LDACBT_EQMID_Q0, "Q0" , LDACBT_2DH5_04 }, 34 /* 396 */ { LDACBT_EQMID_Q1, "Q1" , LDACBT_2DH5_05 }, 35 /* 330 */ { LDACBT_EQMID_MQ, "MQ" , LDACBT_2DH5_06 }, 36 /* 282 */ { LDACBT_EQMID_Q2, "Q2" , LDACBT_2DH5_07 }, 37 /* 246 */ { LDACBT_EQMID_Q3, "Q3" , LDACBT_2DH5_08 }, 38 /* 216 */ { LDACBT_EQMID_Q4, "Q4" , LDACBT_2DH5_09 }, 39 /* 198 */ { LDACBT_EQMID_Q5, "Q5" , LDACBT_2DH5_10 }, 40 /* 180 */ { LDACBT_EQMID_Q6, "Q6" , LDACBT_2DH5_11 }, 41 /* 162 */ { LDACBT_EQMID_Q7, "Q7" , LDACBT_2DH5_12 }, 42 /* 150 */ { LDACBT_EQMID_Q8, "Q8" , LDACBT_2DH5_13 }, 43 /* 138 */ { LDACBT_EQMID_END, "Q9" , LDACBT_2DH5_14 }, 44 }; 45 46 /* LDAC config table 47 * - NFRM/PCKT must be less than 16. 48 */ 49 DECLFUNC const LDACBT_CONFIG tbl_ldacbt_config[] = { 50 /* 51 * index , NFRM , LDAC , FRM 52 * , ---- , FRM , LEN 53 * , PCKT , LEN , /CH 54 * , , [byte], [byte] 55 */ 56 { LDACBT_2DH5_02, 2, 330, 165}, 57 { LDACBT_2DH5_03, 3, 220, 110}, 58 { LDACBT_2DH5_04, 4, 164, 82}, 59 { LDACBT_2DH5_05, 5, 132, 66}, 60 { LDACBT_2DH5_06, 6, 110, 55}, 61 { LDACBT_2DH5_07, 7, 94, 47}, 62 { LDACBT_2DH5_08, 8, 82, 41}, 63 { LDACBT_2DH5_09, 9, 72, 36}, 64 { LDACBT_2DH5_10, 10, 66, 33}, 65 { LDACBT_2DH5_11, 11, 60, 30}, 66 { LDACBT_2DH5_12, 12, 54, 27}, 67 { LDACBT_2DH5_13, 13, 50, 25}, 68 { LDACBT_2DH5_14, 14, 46, 23}, 69 }; 70 71 72 /* Clear LDAC handle parameters */ 73 DECLFUNC void ldacBT_param_clear(HANDLE_LDAC_BT hLdacBT) 74 { 75 int ich; 76 if( hLdacBT == NULL ) { return ; } 77 hLdacBT->proc_mode = LDACBT_PROCMODE_UNSET; 78 hLdacBT->error_code = LDACBT_ERR_NONE; 79 hLdacBT->error_code_api = LDACBT_ERR_NONE; 80 81 hLdacBT->frm_samples = 0; 82 hLdacBT->sfid = UNSET; 83 hLdacBT->pcm.sf = UNSET; 84 hLdacBT->tx.mtu = UNSET; 85 hLdacBT->tx.tx_size = UNSET; 86 hLdacBT->tx.pkt_hdr_sz = UNSET; 87 hLdacBT->frmlen_tx = UNSET; 88 hLdacBT->tx.nfrm_in_pkt = UNSET; 89 hLdacBT->pcm.ch = 0; 90 hLdacBT->pcm.fmt = LDACBT_SMPL_FMT_S24; 91 hLdacBT->nshift = 0; 92 hLdacBT->frmlen = UNSET; 93 hLdacBT->frm_status = 0; 94 hLdacBT->bitrate = 0; 95 /* for alter frame length */ 96 hLdacBT->tgt_nfrm_in_pkt = UNSET; 97 hLdacBT->tgt_frmlen = UNSET; 98 hLdacBT->tgt_eqmid = UNSET; 99 hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON; 100 101 hLdacBT->cm = UNSET; 102 hLdacBT->cci = UNSET; 103 hLdacBT->eqmid = UNSET; 104 hLdacBT->transport = UNSET; 105 106 clear_data_ldac( hLdacBT->ldac_trns_frm_buf.buf, sizeof(hLdacBT->ldac_trns_frm_buf.buf)); 107 hLdacBT->ldac_trns_frm_buf.used = 0; 108 hLdacBT->ldac_trns_frm_buf.nfrm_in = 0; 109 110 clear_data_ldac( hLdacBT->pcmring.buf, sizeof(hLdacBT->pcmring.buf)); 111 hLdacBT->pcmring.wp = 0; 112 hLdacBT->pcmring.rp = 0; 113 hLdacBT->pcmring.nsmpl = 0; 114 /* work buffer for I/O */ 115 for( ich = 0; ich < LDAC_PRCNCH; ich++ ){ 116 hLdacBT->ap_pcm[ich] = &hLdacBT->a_pcm[ ich * LDACBT_MAX_LSU * LDACBT_PCM_WLEN_MAX ]; 117 } 118 hLdacBT->pp_pcm = hLdacBT->ap_pcm; 119 clear_data_ldac( hLdacBT->a_pcm, LDAC_PRCNCH * LDACBT_MAX_LSU * LDACBT_PCM_WLEN_MAX ); 120 121 } 122 123 /* get ldaclib error code */ 124 DECLFUNC int ldacBT_check_ldaclib_error_code(HANDLE_LDAC_BT hLdacBT) 125 { 126 HANDLE_LDAC hData; 127 int error_code, internal_error_code; 128 129 if( hLdacBT == NULL ){ return LDACBT_E_FAIL; } 130 if( (hData = hLdacBT->hLDAC) == NULL ){ return LDACBT_E_FAIL; } 131 132 ldaclib_get_error_code(hData, &error_code); 133 134 ldaclib_get_internal_error_code(hData, &internal_error_code); 135 136 hLdacBT->error_code = error_code << 10 | internal_error_code; 137 138 return LDACBT_S_OK; 139 } 140 141 /* Assertions. */ 142 DECLFUNC int ldacBT_assert_cm( int cm ) 143 { 144 if( (cm != LDACBT_CHANNEL_MODE_STEREO ) 145 && (cm != LDACBT_CHANNEL_MODE_DUAL_CHANNEL ) 146 && (cm != LDACBT_CHANNEL_MODE_MONO ) 147 ){ 148 return LDACBT_ERR_ASSERT_CHANNEL_MODE; 149 } 150 return LDACBT_ERR_NONE; 151 } 152 UNUSED_ATTR DECLFUNC int ldacBT_assert_cci( int cci ) 153 { 154 if( (cci != LDAC_CCI_STEREO ) 155 && (cci != LDAC_CCI_DUAL_CHANNEL ) 156 && (cci != LDAC_CCI_MONO ) 157 ){ 158 return LDACBT_ERR_ASSERT_CHANNEL_CONFIG; 159 } 160 return LDACBT_ERR_NONE; 161 } 162 DECLFUNC int ldacBT_assert_sample_format( LDACBT_SMPL_FMT_T fmt ) 163 { 164 #ifndef _32BIT_FIXED_POINT 165 if( (fmt != LDACBT_SMPL_FMT_S16) 166 && (fmt != LDACBT_SMPL_FMT_S24) 167 && (fmt != LDACBT_SMPL_FMT_S32) 168 && (fmt != LDACBT_SMPL_FMT_F32) 169 ){ 170 #else /* _32BIT_FIXED_POINT */ 171 if( (fmt != LDACBT_SMPL_FMT_S16) 172 && (fmt != LDACBT_SMPL_FMT_S24) 173 && (fmt != LDACBT_SMPL_FMT_S32) 174 ){ 175 #endif /* _32BIT_FIXED_POINT */ 176 return LDACBT_ERR_ILL_SMPL_FORMAT; 177 } 178 return LDACBT_ERR_NONE; 179 } 180 DECLFUNC int ldacBT_assert_pcm_sampling_freq( int sampling_freq ) 181 { 182 if( (sampling_freq != 1*44100) && (sampling_freq != 1*48000) 183 && (sampling_freq != 2*44100) && (sampling_freq != 2*48000) 184 ){ 185 return LDACBT_ERR_ILL_SAMPLING_FREQ; 186 } 187 return LDACBT_ERR_NONE; 188 } 189 DECLFUNC int ldacBT_assert_mtu( int mtu ) 190 { 191 if( mtu < LDACBT_MTU_REQUIRED ){ 192 return LDACBT_ERR_ILL_MTU_SIZE; 193 } 194 return LDACBT_ERR_NONE; 195 } 196 DECLFUNC int ldacBT_assert_eqmid( int eqmid ) 197 { 198 if( (eqmid == LDACBT_EQMID_HQ) || (eqmid == LDACBT_EQMID_SQ) || (eqmid == LDACBT_EQMID_MQ)){ 199 return LDACBT_ERR_NONE; 200 } 201 202 return LDACBT_ERR_ILL_EQMID; 203 } 204 205 /* LDAC set Encode Quality Mode index core */ 206 DECLFUNC void ldacBT_set_eqmid_core( HANDLE_LDAC_BT hLdacBT, int eqmid ) 207 { 208 /* "eqmid" must be checked before calling this function. */ 209 /* just update tgt_eqmid */ 210 P_LDACBT_CONFIG pCfg; 211 pCfg = ldacBT_get_config( eqmid, hLdacBT->tx.pkt_type ); 212 hLdacBT->tgt_eqmid = eqmid; 213 hLdacBT->tgt_frmlen = hLdacBT->pcm.ch * pCfg->frmlen_1ch; 214 hLdacBT->tgt_frmlen -= LDACBT_FRMHDRBYTES; 215 hLdacBT->tgt_nfrm_in_pkt = pCfg->nfrm_in_pkt; 216 217 } 218 219 /* Split LR interleaved PCM into buffer that for LDAC encode. */ 220 DECLFUNC void ldacBT_prepare_pcm_encode( void *pbuff, char **ap_pcm, int nsmpl, int nch, 221 LDACBT_SMPL_FMT_T fmt ) 222 { 223 int i; 224 if( nch == 2 ){ 225 if( fmt == LDACBT_SMPL_FMT_S16 ){ 226 short *p_pcm_16 = (short *)pbuff; 227 short *p_lch_16 = (short *)ap_pcm[0]; 228 short *p_rch_16 = (short *)ap_pcm[1]; 229 for (i = 0; i < nsmpl; i++) { 230 *p_lch_16++ = p_pcm_16[0]; 231 *p_rch_16++ = p_pcm_16[1]; 232 p_pcm_16+=2; 233 } 234 } 235 else if( fmt == LDACBT_SMPL_FMT_S24 ){ 236 char *p_pcm_8 = (char *)pbuff; 237 char *p_lch_8 = (char *)ap_pcm[0]; 238 char *p_rch_8 = (char *)ap_pcm[1]; 239 #if __BYTE_ORDER == __LITTLE_ENDIAN 240 for (i = 0; i < nsmpl; i++) { 241 *p_lch_8++ = p_pcm_8[0]; 242 *p_lch_8++ = p_pcm_8[1]; 243 *p_lch_8++ = p_pcm_8[2]; 244 p_pcm_8+=3; 245 *p_rch_8++ = p_pcm_8[0]; 246 *p_rch_8++ = p_pcm_8[1]; 247 *p_rch_8++ = p_pcm_8[2]; 248 p_pcm_8+=3; 249 } 250 #else /* __BYTE_ORDER */ 251 #error unsupported byte order 252 #endif /* #if __BYTE_ORDER == __LITTLE_ENDIAN */ 253 } 254 else if ( fmt == LDACBT_SMPL_FMT_S32 ){ 255 char *p_pcm_8 = (char *)pbuff; 256 char *p_lch_8 = (char *)ap_pcm[0]; 257 char *p_rch_8 = (char *)ap_pcm[1]; 258 #if __BYTE_ORDER == __LITTLE_ENDIAN 259 for (i = 0; i < nsmpl; i++) { 260 *p_lch_8++ = p_pcm_8[0]; *p_lch_8++ = p_pcm_8[1]; *p_lch_8++ = p_pcm_8[2]; *p_lch_8++ = p_pcm_8[3]; 261 p_pcm_8+=4; 262 *p_rch_8++ = p_pcm_8[0]; *p_rch_8++ = p_pcm_8[1]; *p_rch_8++ = p_pcm_8[2]; *p_rch_8++ = p_pcm_8[3]; 263 p_pcm_8+=4; 264 } 265 #else /* __BYTE_ORDER */ 266 #error unsupported byte order 267 #endif /* #if __BYTE_ORDER == __LITTLE_ENDIAN */ 268 } 269 else if ( fmt == LDACBT_SMPL_FMT_F32 ){ 270 float *p_pcm = (float *)pbuff; 271 float *p_lch = (float *)ap_pcm[0]; 272 float *p_rch = (float *)ap_pcm[1]; 273 for (i = 0; i < nsmpl; i++) { 274 *p_lch++ = p_pcm[0]; 275 p_pcm++; 276 *p_rch++ = p_pcm[0]; 277 p_pcm++; 278 } 279 } 280 else{;} /* never be happend */ 281 } 282 else if( nch == 1 ){ 283 switch(fmt){ 284 case LDACBT_SMPL_FMT_S16: 285 copy_data_ldac( pbuff, ap_pcm[0], 2*nsmpl ); 286 break; 287 case LDACBT_SMPL_FMT_S24: 288 copy_data_ldac( pbuff, ap_pcm[0], 3*nsmpl ); 289 break; 290 case LDACBT_SMPL_FMT_S32: 291 case LDACBT_SMPL_FMT_F32: 292 copy_data_ldac( pbuff, ap_pcm[0], 4*nsmpl ); 293 break; 294 default: 295 break; 296 } 297 } 298 } 299 300 301 /* update framelength */ 302 DECLFUNC int ldacBT_update_frmlen(HANDLE_LDAC_BT hLdacBT, int frmlen) 303 { 304 int status, sf, ch, fl, fl_per_ch; 305 int nbasebands, grad_mode, grad_qu_l, grad_qu_h, grad_ofst_l, grad_ofst_h, abc_flag; 306 LDACBT_TX_INFO *ptx; 307 LDAC_RESULT result; 308 status = LDACBT_E_FAIL; 309 310 if( hLdacBT == NULL ){ 311 return LDACBT_E_FAIL; 312 } 313 sf = hLdacBT->pcm.sf; /* sampling frequency */ 314 ch = hLdacBT->pcm.ch; /* number of channels */ 315 ptx = &hLdacBT->tx; 316 317 ldac_setup_AGAIN: 318 /* update LDAC parameters. */ 319 320 321 if( frmlen == UNSET ){ 322 goto ldac_setup_END; 323 } 324 325 /* check & update frameLength */ 326 ldaclib_get_encode_frame_length( hLdacBT->hLDAC, &fl ); 327 if( fl == 0 ){ // This meens that the handle was not initialized yet. Shall not happen. 328 329 goto ldac_setup_END; 330 } 331 else if( frmlen == fl ){ 332 /* No need to update frame length. Just update bitrate information. */ 333 status = LDACBT_S_OK; 334 hLdacBT->bitrate = ldacBT_frmlen_to_bitrate( fl, 1, sf, hLdacBT->frm_samples ); 335 goto ldac_setup_END; 336 } 337 338 /* Time to update the frame_length. */ 339 /* Get ldac encoding information for frame_length. */ 340 fl_per_ch = (frmlen+LDACBT_FRMHDRBYTES) / ch; 341 result = ldaclib_get_encode_setting( fl_per_ch, hLdacBT->sfid, &nbasebands, 342 &grad_mode, &grad_qu_l, &grad_qu_h, &grad_ofst_l, &grad_ofst_h, &abc_flag); 343 if (LDAC_FAILED(result)) { 344 goto ldac_setup_END; 345 } 346 /* Set Encoding Information */ 347 result = ldaclib_set_encode_info( hLdacBT->hLDAC, nbasebands, grad_mode, 348 grad_qu_l, grad_qu_h, grad_ofst_l, grad_ofst_h, abc_flag); 349 if (LDAC_FAILED(result)) { 350 ldacBT_check_ldaclib_error_code(hLdacBT); 351 goto ldac_setup_END; 352 } 353 354 if( !LDAC_SUCCEEDED(ldaclib_set_encode_frame_length( hLdacBT->hLDAC, frmlen ))){ 355 goto ldac_setup_END; 356 } 357 358 /* Update parameters in handle. */ 359 hLdacBT->frmlen = frmlen; 360 hLdacBT->frmlen_tx = LDACBT_FRMHDRBYTES + frmlen; 361 ptx->nfrm_in_pkt = ptx->tx_size / hLdacBT->frmlen_tx; 362 if( ptx->nfrm_in_pkt > LDACBT_NFRM_TX_MAX ){ 363 ptx->nfrm_in_pkt = LDACBT_NFRM_TX_MAX; 364 } 365 else if( ptx->nfrm_in_pkt < 2 ){ 366 /* Not allowed 1frame/packet transportation for current version of LDAC A2DP */ 367 if( frmlen <= (ptx->tx_size / 2 - LDACBT_FRMHDRBYTES)){ 368 goto ldac_setup_END; 369 } 370 frmlen = ptx->tx_size / 2 - LDACBT_FRMHDRBYTES; 371 goto ldac_setup_AGAIN; 372 } 373 /* Update bitrate and EQMID. */ 374 hLdacBT->bitrate = ldacBT_frmlen_to_bitrate( frmlen, 1, sf, hLdacBT->frm_samples ); 375 hLdacBT->eqmid = ldacBT_get_eqmid_from_frmlen( frmlen, ch, hLdacBT->transport, ptx->pkt_type ); 376 if( hLdacBT->tgt_eqmid == UNSET){ 377 hLdacBT->eqmid = UNSET; 378 } 379 status = LDACBT_S_OK; 380 381 ldac_setup_END: 382 return status; 383 } 384 385 /* Get channel_config_index from channel_mode. 386 * The argument cm, channel_mode, must be checked by function ldacBT_assert_cm() before calling this 387 * function. 388 */ 389 DECLFUNC int ldacBT_cm_to_cci( int cm ) 390 { 391 if( cm == LDACBT_CHANNEL_MODE_STEREO ){ 392 return LDAC_CCI_STEREO; 393 } 394 else if( cm == LDACBT_CHANNEL_MODE_DUAL_CHANNEL ){ 395 return LDAC_CCI_DUAL_CHANNEL; 396 } 397 else/* if( cm == LDACBT_CHANNEL_MODE_MONO )*/{ 398 return LDAC_CCI_MONO; 399 } 400 } 401 402 /* Get channel_mode from channel_config_index. 403 * The argument cci, channel_config_index, must be checked by the function ldacBT_assert_cci() before 404 * calling this function. 405 */ 406 UNUSED_ATTR DECLFUNC int ldacBT_cci_to_cm( int cci ) 407 { 408 if( cci == LDAC_CCI_STEREO ){ 409 return LDACBT_CHANNEL_MODE_STEREO; 410 } 411 else if( cci == LDAC_CCI_DUAL_CHANNEL ){ 412 return LDACBT_CHANNEL_MODE_DUAL_CHANNEL; 413 } 414 else/* if( cci == LDAC_CCI_MONO )*/{ 415 return LDACBT_CHANNEL_MODE_MONO; 416 } 417 } 418 419 /* Get bitrate from frame length */ 420 DECLFUNC int ldacBT_frmlen_to_bitrate( int frmlen, int flgFrmHdr, int sf, int frame_samples ) 421 { 422 int bitrate; 423 if( (frmlen == UNSET) || (flgFrmHdr == UNSET) || (sf == UNSET) || (frame_samples == UNSET) ){ 424 return LDACBT_E_FAIL; 425 } 426 if( flgFrmHdr ){ 427 frmlen += LDACBT_FRMHDRBYTES; 428 } 429 bitrate = frmlen * sf / frame_samples / (1000 / 8); 430 return bitrate; 431 } 432 433 /* Get Encode Quality Mode index property */ 434 DECLFUNC P_LDACBT_EQMID_PROPERTY ldacBT_get_eqmid_conv_tbl ( int eqmid ) 435 { 436 int i, tbl_size; 437 P_LDACBT_EQMID_PROPERTY pEqmIdProp; 438 439 pEqmIdProp = (P_LDACBT_EQMID_PROPERTY)tbl_ldacbt_eqmid_property; 440 tbl_size = (int)(sizeof(tbl_ldacbt_eqmid_property)/sizeof(tbl_ldacbt_eqmid_property[0])); 441 /* Search current eqmid */ 442 for( i = 0; i < tbl_size; ++i, ++pEqmIdProp ){ 443 if( pEqmIdProp->eqmid == eqmid ){ 444 return pEqmIdProp; 445 } 446 } 447 return NULL; 448 } 449 450 /* Get altered Encode Quality Mode index */ 451 DECLFUNC int ldacBT_get_altered_eqmid ( HANDLE_LDAC_BT hLdacBT, int priority ) 452 { 453 int i, eqmid_0, eqmid_1, eqmid_new, tbl_size; 454 if( priority == 0 ){ return LDACBT_E_FAIL; } 455 switch( hLdacBT->tx.pkt_type ){ 456 case _2_DH5: 457 break; 458 default: 459 return LDACBT_E_FAIL; 460 } 461 tbl_size = (int)(sizeof(tbl_ldacbt_eqmid_property)/sizeof(tbl_ldacbt_eqmid_property[0])); 462 /* Search target eqmid */ 463 for( i = 0; i < tbl_size; ++i ){ 464 if( tbl_ldacbt_eqmid_property[i].eqmid == hLdacBT->tgt_eqmid ){ 465 break; 466 } 467 } 468 eqmid_0 = i; 469 eqmid_1 = eqmid_0 - priority; 470 if( eqmid_1 < 0 ){ return LDACBT_E_FAIL; } 471 if( eqmid_1 >= tbl_size ){ return LDACBT_E_FAIL; } 472 473 eqmid_new = tbl_ldacbt_eqmid_property[eqmid_1].eqmid; 474 for( i = 0; i < tbl_size; ++i ){ 475 if( tbl_ldacbt_eqmid_property[i].eqmid == LDACBT_LIMIT_ALTER_EQMID_PRIORITY ){ 476 break; 477 } 478 } 479 if( eqmid_1 > i ){ return LDACBT_E_FAIL; } 480 return eqmid_new; 481 482 } 483 484 /* Get LDAC bitrate info from Encode Quality Mode Index */ 485 DECLFUNC P_LDACBT_CONFIG ldacBT_get_config( int ldac_bt_mode, int pkt_type ) 486 { 487 int i, tbl_size, ldac_mode_id; 488 P_LDACBT_EQMID_PROPERTY pEqmIdProp; 489 P_LDACBT_CONFIG pCfg; 490 491 if( (pEqmIdProp = ldacBT_get_eqmid_conv_tbl( ldac_bt_mode )) == NULL ){ 492 return NULL; 493 } 494 495 if( pkt_type == _2_DH5 ){ ldac_mode_id = pEqmIdProp->id_for_2DH5;} 496 else{ 497 return NULL; 498 } 499 500 pCfg = (P_LDACBT_CONFIG)tbl_ldacbt_config; 501 tbl_size = (int)(sizeof(tbl_ldacbt_config)/sizeof(tbl_ldacbt_config[0])); 502 for( i = 0; i < tbl_size; ++i, ++pCfg ){ 503 if( ldac_mode_id == pCfg->id ){ 504 return pCfg; 505 } 506 } 507 return NULL; /* not found */ 508 } 509 510 /* Get Encode Quality Mode Index from framelength */ 511 DECLFUNC int ldacBT_get_eqmid_from_frmlen( int frmlen, int nch, int flgFrmHdr, int pktType ) 512 { 513 int i, n, eqmid; 514 P_LDACBT_CONFIG pCfg; 515 516 if( flgFrmHdr ){ 517 frmlen += LDACBT_FRMHDRBYTES; 518 } 519 if( nch > 0 ){ 520 frmlen /= nch; 521 } 522 523 eqmid = LDACBT_EQMID_END; 524 n = (int)(sizeof(tbl_ldacbt_eqmid_property)/sizeof(tbl_ldacbt_eqmid_property[0])); 525 for( i = 0; i < n; ++i ){ 526 if( (pCfg = ldacBT_get_config( tbl_ldacbt_eqmid_property[i].eqmid, pktType )) != NULL ){ 527 if( frmlen >= pCfg->frmlen_1ch){ 528 eqmid = tbl_ldacbt_eqmid_property[i].eqmid; 529 break; 530 } 531 } 532 } 533 return eqmid; 534 } 535 536