mirror of https://gitee.com/openkylin/libldac.git
Import Upstream version 2.0.2.3+git20200429+ed310a0
This commit is contained in:
commit
168bb7925c
|
@ -0,0 +1,37 @@
|
|||
cc_library_shared {
|
||||
name: "libldacBT_enc",
|
||||
vendor_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
arch: {
|
||||
arm: {
|
||||
instruction_set: "arm",
|
||||
},
|
||||
},
|
||||
export_include_dirs: ["inc"],
|
||||
srcs: [
|
||||
"src/ldaclib.c",
|
||||
"src/ldacBT.c",
|
||||
],
|
||||
// -D_32BIT_FIXED_POINT should be added to cflags for devices without a FPU
|
||||
// unit such as ARM Cortex-R series or external 32-bit DSPs.
|
||||
cflags: ["-O2", "-Werror", "-Wall", "-Wextra"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libldacBT_abr",
|
||||
vendor_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
arch: {
|
||||
arm: {
|
||||
instruction_set: "arm",
|
||||
},
|
||||
},
|
||||
export_include_dirs: ["abr/inc"],
|
||||
srcs: ["abr/src/ldacBT_abr.c"],
|
||||
shared_libs: ["libldacBT_enc"],
|
||||
cflags: ["-O2", "-Werror", "-Wall", "-Wextra"]
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,7 @@
|
|||
---------------
|
||||
Certification
|
||||
---------------
|
||||
Taking the certification process is required to use LDAC in your products.
|
||||
For the detail of certification process, see the following URL:
|
||||
https://www.sony.net/Products/LDAC/aosp/
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# This project does not need newer update?
|
||||
# Please update this list if you find better candidates.
|
||||
jeffbailey@google.com
|
||||
rtenneti@google.com
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Copyright (C) 2014 - 2017 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LDACBT_ABR_H_
|
||||
#define _LDACBT_ABR_H_
|
||||
|
||||
/* This file contains the definitions, declarations and macros for an implementation of
|
||||
* LDAC Adaptive Bit Rate (hereinafter ABR) processing.
|
||||
*
|
||||
* The basic flow of the ABR processing is as follows:
|
||||
* - The program creates a handle of LDAC ABR API using ldac_ABR_get_handle().
|
||||
* - The program initializes the handle by setting the ldac_ABR_Proc() call interval to
|
||||
* ldac_ABR_Init().
|
||||
* The interval shall be as short as possible at the timing without accumulation
|
||||
* of packet in the buffer if propagation environment is fine.
|
||||
* - The program reinitializes the handle by calling ldac_ABR_Init() again when the
|
||||
* state of the TX queue changes greatly, such as clearing the queue.
|
||||
* - If the program demands to control the thresholds, then ldac_ABR_set_thresholds()
|
||||
* should be called.
|
||||
* - The program sets flagEnable to "1" when allowing LDAC encode bitrate to be
|
||||
* adjusted by ABR, and sets it to "0" if it is not allowed.
|
||||
* - The program calls ldac_ABR_Proc() at the interval set to ldac_ABR_Init() even if
|
||||
* flagEnable is "0".
|
||||
* The program passes TxQueueDepth and flagEnable to ldac_ABR_Proc() at this call,
|
||||
* LDAC encode bitrate is adjusted only when flagEnable is "1".
|
||||
* Otherwise, the internal parameters are updated and analyzed then returned.
|
||||
* The ABR handle adjusts eqmid based on TxQueueDepth which is passed from the program.
|
||||
* The ABR handle calls LDAC encode API ldacBT_alter_eqmid_priority() to adjust eqmid.
|
||||
* The ABR handle calls LDAC encode API ldacBT_get_eqmid() to get current eqmid.
|
||||
* - The handle may be released with ldac_ABR_free_handle().
|
||||
*
|
||||
* Notes on debugging LDAC ABR:
|
||||
* The meaning of "works fine" is that the bit rate will be low in case of bad radio situation
|
||||
* and high in case of good radio situation.
|
||||
*
|
||||
* The bit rate transition can be debug by checking logcat messages from LDAC ABR library which
|
||||
* built with the following changes in Android.bp:
|
||||
* - Adding "liblog" to shared_libs.
|
||||
* - Adding "-DLOCAL_DEBUG" to cflags.
|
||||
* The messages are formated as follows:
|
||||
* [LDAC ABR] - abrQualityModeID : 0 -- eqmid : 0 -- TxQue : 0
|
||||
* where abrQualityModeID and eqmid related to the current bit rate and TxQue shows the depth
|
||||
* of current Tx queue.
|
||||
* The relationship between abrQualityModeID, eqmid and the bit rate is described in
|
||||
* "ldacBT_abr.c".
|
||||
*
|
||||
* The bit rate transition can be estimated/debug by listening to the audio played on the SNK
|
||||
* device. This method cannot use to confirm the details of the bit rate transition, but useful
|
||||
* to know how LDAC ABR algorithm works in a field test without checking the log.
|
||||
* To try this method, rebuilding of the "libldacBT_enc" library with the following change in
|
||||
* Android.bp is required:
|
||||
* - Adding "-DUSE_LDAC_ENC_SETTING_FOR_ABR_DEBUG" to cflags.
|
||||
* By defining the above macro, the lower the bit rate, the greatly lower the bandwidth of the audio
|
||||
* played on the SNK device. Therefore, the audio played on the SNK device will sounds like a
|
||||
* low-pass filtered sound when the bit rate is low and will sounds as usual when the bit rate is
|
||||
* enough high. It is recommend using sound such as white noise to hear those changes for the first
|
||||
* time.
|
||||
*
|
||||
* IMPORTANT:
|
||||
* These libraries modified as described above shall be used only to confirm the bit rate transition
|
||||
* and SHALL NOT BE USED FOR FINAL PRODUCTS.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef LDAC_ABR_API
|
||||
#define LDAC_ABR_API
|
||||
#endif /* LDAC_ABR_API */
|
||||
|
||||
#include <ldacBT.h> /* HANDLE_LDAC_BT */
|
||||
|
||||
/* LDAC ABR handle type*/
|
||||
typedef struct _ldacbt_abr_param * HANDLE_LDAC_ABR;
|
||||
|
||||
/* Allocation of LDAC ABR handle.
|
||||
* Format
|
||||
* HANDLE_LDAC_ABR ldacBT_get_handle( void );
|
||||
* Arguments
|
||||
* None.
|
||||
* Return value
|
||||
* HANDLE_LDAC_ABR for success, NULL for failure.
|
||||
*/
|
||||
LDAC_ABR_API HANDLE_LDAC_ABR ldac_ABR_get_handle(void);
|
||||
|
||||
/* Release of LDAC ABR handle.
|
||||
* Format
|
||||
* void ldac_ABR_free_handle( HANDLE_LDAC_ABR );
|
||||
* Arguments
|
||||
* hLdacAbr HANDLE_LDAC_ABR LDAC ABR handle.
|
||||
* Return value
|
||||
* None.
|
||||
*/
|
||||
LDAC_ABR_API void ldac_ABR_free_handle(HANDLE_LDAC_ABR hLdacAbr);
|
||||
|
||||
/* Initialize LDAC ABR.
|
||||
* Format
|
||||
* int ldac_ABR_Init( HANDLE_LDAC_ABR, unsigned int );
|
||||
* Arguments
|
||||
* hLdacAbr HANDLE_LDAC_ABR LDAC ABR handle.
|
||||
* interval_ms unsigned int interval in ms for calling ldac_ABR_Proc().
|
||||
* interval of 1ms to 500ms is valid.
|
||||
* Return value
|
||||
* int: 0 for success, -1 for failure.
|
||||
*/
|
||||
LDAC_ABR_API int ldac_ABR_Init(HANDLE_LDAC_ABR hLdacAbr, unsigned int interval_ms);
|
||||
|
||||
/* Setup thresholds for LDAC ABR.
|
||||
* Format
|
||||
* int ldac_ABR_set_thresholds( HANDLE_LDAC_ABR, unsigned int, unsigned int, unsigned int );
|
||||
* Arguments
|
||||
* hLdacAbr HANDLE_LDAC_ABR LDAC ABR handle.
|
||||
* thCritical unsigned int threshold for critical TxQueueDepth status.
|
||||
* thDangerousTrend unsigned int threshold for dangerous trend of TxQueueDepth.
|
||||
* thSafety4HQSQ unsigned int safety threshold for LDACBT_EQMID_HQ and
|
||||
* LDACBT_EQMID_SQ.
|
||||
* Return value
|
||||
* int: 0 for success, -1 for failure.
|
||||
* Remarks
|
||||
* Those thresholds should be the number of packets stored in the TX queue and should be
|
||||
* greater than 0.
|
||||
* The thCritical and thDangerousTrend are used for all eqmid and thSafety4HQSQ is used
|
||||
* only for LDACBT_EQMID_HQ and LDACBT_EQMID_SQ. Therefore, those thresholds must satisfy
|
||||
* the following releationship:
|
||||
* thCritical >= thDangerousTrend >= thSafety4HQSQ
|
||||
*/
|
||||
LDAC_ABR_API int ldac_ABR_set_thresholds(HANDLE_LDAC_ABR hLdacAbr, unsigned int thCritical,
|
||||
unsigned int thDangerousTrend, unsigned int thSafety4HQSQ);
|
||||
|
||||
/* LDAC ABR main process.
|
||||
* Format
|
||||
* int ldac_ABR_Proc( HANDLE_LDAC_BT, HANDLE_LDAC_ABR, unsigned int, unsigned int );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* hLdacAbr HANDLE_LDAC_ABR LDAC ABR handle.
|
||||
* TxQueueDepth unsigned int depth of TX queue.
|
||||
* flagEnable unsigned int flag indicating whether ABR is allowed to adjust LDAC
|
||||
* encode bitrate
|
||||
* Return value
|
||||
* int: updated Encode Quality Mode Index for success, -1 for failure.
|
||||
*/
|
||||
LDAC_ABR_API int ldac_ABR_Proc(HANDLE_LDAC_BT hLdacBt, HANDLE_LDAC_ABR hLdacAbr,
|
||||
unsigned int TxQueueDepth, unsigned int flagEnable);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LDACBT_ABR_H_ */
|
||||
|
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
* Copyright (C) 2014 - 2017 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldacBT_abr.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LDAC_ABR_OBSERVING_TIME_MS 500 /* [ms] the time length for storing Tx Queue Depth */
|
||||
#define LDAC_ABR_PENALTY_MAX 4
|
||||
|
||||
/* Number of observing count to judge whether EQMID may be increase.
|
||||
* Those count can convert in time by following formula:
|
||||
* Time [ms] = (Count - abrQualityModeID) * LDAC_ABR_OBSERVING_TIME_MS
|
||||
* where abrQualityModeID is the value which converted EQMID by aEqmidToAbrQualityModeID[].
|
||||
* Therefore, using the default value of 12, the observation time in each abrQualityModeID is
|
||||
* as follows:
|
||||
* ----------------------------------------------------
|
||||
* | abrQualityModeID | 0 | 1 | 2 | 3 | 4 |
|
||||
* | observation time [s] | 6 | 5 | 4 | 3 | 2 |
|
||||
* ----------------------------------------------------
|
||||
*/
|
||||
#define LDAC_ABR_OBSERVING_COUNT_TO_JUDGE_INC_QUALITY 12
|
||||
#define LDAC_ABR_OBSERVING_COUNT_FOR_INIT 6 /* = 3sec. keep same EQMID in first 3sec */
|
||||
/* Default value for thresholds */
|
||||
#define LDAC_ABR_THRESHOLD_CRITICAL_DEFAULT 6
|
||||
#define LDAC_ABR_THRESHOLD_DANGEROUSTREND_DEFAULT 4
|
||||
#define LDAC_ABR_THRESHOLD_SAFETY_FOR_HQSQ_DEFAULT 2
|
||||
/* Number of steady state count to judge */
|
||||
#define LDAC_ABR_NUM_STEADY_STATE_TO_JUDGE_STEADY 3
|
||||
/* Number of steady state count to reset for LDACBT_EQMID_HQ */
|
||||
#define LDAC_ABR_NUM_STEADY_STATE_TO_RESET_PENALTY_FOR_HQ 60
|
||||
|
||||
|
||||
typedef struct _tx_queue_param
|
||||
{
|
||||
unsigned char *pHist;
|
||||
unsigned int szHist;
|
||||
int sum;
|
||||
unsigned int cnt;
|
||||
unsigned int idx;
|
||||
} TxQ_INFO;
|
||||
|
||||
typedef struct _ldacbt_abr_param
|
||||
{
|
||||
TxQ_INFO TxQD_Info;
|
||||
int cntToIncQuality;
|
||||
int nSteadyState;
|
||||
int nPenalty;
|
||||
int abrQualityModeIdSteady;
|
||||
unsigned int numToEvaluate;
|
||||
/* thresholds */
|
||||
unsigned int thCritical;
|
||||
unsigned int thDangerousTrend;
|
||||
unsigned int thSafety4HQSQ;
|
||||
} LDAC_ABR_PARAMS;
|
||||
|
||||
#define clear_data(ptr, n) memset(ptr, 0, n)
|
||||
|
||||
#ifdef LOCAL_DEBUG
|
||||
#include <android/log.h>
|
||||
#define ABRDBG(fmt, ... ) \
|
||||
__android_log_print( ANDROID_LOG_INFO, "******** LDAC ABR ********",\
|
||||
"%s@%s:%d::"fmt, __func__, __FILE__, __LINE__, ## __VA_ARGS__ )
|
||||
#else
|
||||
#define ABRDBG(fmt, ...)
|
||||
#endif /* LOCAL_DEBUG */
|
||||
|
||||
/* A table for converting EQMID to abrQualityModeID which is sorted in descending order by bit rate.
|
||||
* The relationship between EQMID, bit rate and abrQualityModeID when the sampling frequency is
|
||||
* 96 kHz is as follows:
|
||||
* ----------------------------------------------------
|
||||
* | EQMID | 0 | 1 | 2 | 3 | 4 |
|
||||
* | bit rate [kbps] | 990 | 660 | 330 | 492 | 396 |
|
||||
* | abrQualityModeID | 0 | 1 | 4 | 2 | 3 |
|
||||
* ----------------------------------------------------
|
||||
*/
|
||||
static const int aEqmidToAbrQualityModeID[]={ 0, 1, 4, 2, 3};
|
||||
static const int sizeOfEqmidToBitrateSortedIdTable = (int)(sizeof(aEqmidToAbrQualityModeID)
|
||||
/ sizeof(aEqmidToAbrQualityModeID[0]));
|
||||
|
||||
/* Get LDAC ABR handle */
|
||||
HANDLE_LDAC_ABR ldac_ABR_get_handle(void)
|
||||
{
|
||||
HANDLE_LDAC_ABR hLdacAbr;
|
||||
ABRDBG( "" );
|
||||
if ((hLdacAbr = (HANDLE_LDAC_ABR)malloc(sizeof(LDAC_ABR_PARAMS))) == NULL) {
|
||||
ABRDBG( "[ERR] Failed to allocate memory for handle." );
|
||||
return NULL;
|
||||
}
|
||||
hLdacAbr->TxQD_Info.pHist = NULL;
|
||||
return hLdacAbr;
|
||||
}
|
||||
|
||||
/* Free LDAC ABR handle */
|
||||
void ldac_ABR_free_handle(HANDLE_LDAC_ABR hLdacAbr)
|
||||
{
|
||||
ABRDBG( "" );
|
||||
if (hLdacAbr != NULL) {
|
||||
if (hLdacAbr->TxQD_Info.pHist) {
|
||||
free(hLdacAbr->TxQD_Info.pHist);
|
||||
}
|
||||
free(hLdacAbr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize LDAC ABR */
|
||||
int ldac_ABR_Init( HANDLE_LDAC_ABR hLdacAbr, unsigned int interval_ms )
|
||||
{
|
||||
ABRDBG( "hLdacAbr:0x%x, interval_ms:%u", (unsigned int)hLdacAbr, interval_ms );
|
||||
if (hLdacAbr == NULL) return -1;
|
||||
if (interval_ms == 0) return -1;
|
||||
if (interval_ms > LDAC_ABR_OBSERVING_TIME_MS) return -1;
|
||||
|
||||
hLdacAbr->numToEvaluate = LDAC_ABR_OBSERVING_TIME_MS / interval_ms;
|
||||
hLdacAbr->TxQD_Info.sum = 0;
|
||||
hLdacAbr->TxQD_Info.cnt = 0;
|
||||
hLdacAbr->TxQD_Info.idx = 0;
|
||||
hLdacAbr->TxQD_Info.szHist = hLdacAbr->numToEvaluate + 1;
|
||||
if (hLdacAbr->TxQD_Info.pHist) free(hLdacAbr->TxQD_Info.pHist);
|
||||
if ((hLdacAbr->TxQD_Info.pHist =
|
||||
(unsigned char*)malloc(hLdacAbr->TxQD_Info.szHist * sizeof(unsigned char))) == NULL){
|
||||
return -1;
|
||||
}
|
||||
clear_data(hLdacAbr->TxQD_Info.pHist, hLdacAbr->TxQD_Info.szHist * sizeof(unsigned char));
|
||||
|
||||
hLdacAbr->nSteadyState = 0;
|
||||
hLdacAbr->nPenalty = 1;
|
||||
hLdacAbr->abrQualityModeIdSteady = aEqmidToAbrQualityModeID[LDACBT_EQMID_HQ];
|
||||
hLdacAbr->cntToIncQuality = LDAC_ABR_OBSERVING_COUNT_FOR_INIT;
|
||||
/* thresholds */
|
||||
hLdacAbr->thCritical = LDAC_ABR_THRESHOLD_CRITICAL_DEFAULT;
|
||||
hLdacAbr->thDangerousTrend = LDAC_ABR_THRESHOLD_DANGEROUSTREND_DEFAULT;
|
||||
hLdacAbr->thSafety4HQSQ = LDAC_ABR_THRESHOLD_SAFETY_FOR_HQSQ_DEFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Setup thresholds for LDAC ABR */
|
||||
int ldac_ABR_set_thresholds( HANDLE_LDAC_ABR hLdacAbr, unsigned int thCritical,
|
||||
unsigned int thDangerousTrend, unsigned int thSafety4HQSQ )
|
||||
{
|
||||
ABRDBG( "thCritical=%u, thDangerousTrend=%u, thSafety4HQSQ=%u",
|
||||
thCritical, thDangerousTrend, thSafety4HQSQ);
|
||||
if (hLdacAbr == NULL) return -1;
|
||||
if (thCritical < thDangerousTrend) return -1;
|
||||
if (thDangerousTrend < thSafety4HQSQ) return -1;
|
||||
hLdacAbr->thCritical = thCritical;
|
||||
hLdacAbr->thDangerousTrend = thDangerousTrend;
|
||||
hLdacAbr->thSafety4HQSQ = thSafety4HQSQ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* LDAC ABR main process */
|
||||
int ldac_ABR_Proc( HANDLE_LDAC_BT hLDAC, HANDLE_LDAC_ABR hLdacAbr,
|
||||
unsigned int TxQueueDepth, unsigned int flagEnable)
|
||||
{
|
||||
int nStepsToChangeEQMID, abrQualityModeID, eqmid, i;
|
||||
unsigned int TxQD_curr, TxQD_prev;
|
||||
#ifdef LOCAL_DEBUG
|
||||
int qd, TxQ; // for debug
|
||||
#endif
|
||||
|
||||
if (hLDAC == NULL) return -1;
|
||||
if (hLdacAbr == NULL) return -1;
|
||||
|
||||
eqmid = ldacBT_get_eqmid(hLDAC);
|
||||
abrQualityModeID = -1;
|
||||
if ((LDACBT_EQMID_HQ <= eqmid) && (eqmid < sizeOfEqmidToBitrateSortedIdTable)) {
|
||||
abrQualityModeID = aEqmidToAbrQualityModeID[eqmid];
|
||||
}
|
||||
#ifdef LOCAL_DEBUG
|
||||
ABRDBG( "[LDAC ABR] - abrQualityModeID : %d -- eqmid : %d -- TxQue : %d --------------",
|
||||
abrQualityModeID, eqmid, TxQueueDepth);
|
||||
#endif
|
||||
/* check for the situation when unsupported eqmid was return from ldacBT_get_eqmid(). */
|
||||
if (abrQualityModeID < 0) return eqmid; /* return current eqmid. */
|
||||
|
||||
/* update */
|
||||
TxQD_curr = TxQueueDepth;
|
||||
if ((i = hLdacAbr->TxQD_Info.idx - 1) < 0 ) i = hLdacAbr->TxQD_Info.szHist - 1;
|
||||
TxQD_prev = hLdacAbr->TxQD_Info.pHist[i];
|
||||
|
||||
hLdacAbr->TxQD_Info.sum -= hLdacAbr->TxQD_Info.pHist[hLdacAbr->TxQD_Info.idx];
|
||||
hLdacAbr->TxQD_Info.pHist[hLdacAbr->TxQD_Info.idx] = (unsigned char)TxQD_curr;
|
||||
if (++hLdacAbr->TxQD_Info.idx >= hLdacAbr->TxQD_Info.szHist) hLdacAbr->TxQD_Info.idx = 0;
|
||||
|
||||
hLdacAbr->TxQD_Info.sum += TxQD_curr;
|
||||
++hLdacAbr->TxQD_Info.cnt;
|
||||
|
||||
#ifdef LOCAL_DEBUG
|
||||
qd = (abrQualityModeID * 100000000);
|
||||
qd += (hLdacAbr->nPenalty * 1000000);
|
||||
qd += (hLdacAbr->cntToIncQuality *1000);
|
||||
qd += (hLdacAbr->nSteadyState);
|
||||
TxQ = TxQD_prev * 100 + TxQD_curr;
|
||||
#endif
|
||||
|
||||
/* judge */
|
||||
nStepsToChangeEQMID = 0;
|
||||
if (TxQD_curr >= hLdacAbr->thCritical) {
|
||||
/* for Critical situation */
|
||||
ABRDBG("Critical: %d, %d", TxQ, qd);
|
||||
nStepsToChangeEQMID = -1;
|
||||
if ((eqmid == LDACBT_EQMID_HQ) || (eqmid == LDACBT_EQMID_SQ)) {
|
||||
nStepsToChangeEQMID = -2;
|
||||
}
|
||||
}
|
||||
else if ((TxQD_curr > hLdacAbr->thDangerousTrend) && (TxQD_curr > TxQD_prev)) {
|
||||
ABRDBG("Dangerous: %d, %d", TxQ, qd);
|
||||
nStepsToChangeEQMID = -1;
|
||||
}
|
||||
else if ((TxQD_curr > hLdacAbr->thSafety4HQSQ) &&
|
||||
((eqmid == LDACBT_EQMID_HQ) || (eqmid == LDACBT_EQMID_SQ))) {
|
||||
ABRDBG("Safety4HQSQ: %d, %d", TxQ, qd);
|
||||
nStepsToChangeEQMID = -1;
|
||||
}
|
||||
else if (hLdacAbr->TxQD_Info.cnt >= hLdacAbr->numToEvaluate) {
|
||||
int ave10;
|
||||
hLdacAbr->TxQD_Info.cnt = hLdacAbr->numToEvaluate;
|
||||
/* eanble average process */
|
||||
ave10 = (hLdacAbr->TxQD_Info.sum * 10) / hLdacAbr->TxQD_Info.cnt;
|
||||
|
||||
if (ave10 > 15) { /* if average of TxQue_Count in 0.5[s] was larger than 1.5 */
|
||||
ABRDBG("ave: %d, %d, %d", TxQ, qd, ave10);
|
||||
nStepsToChangeEQMID = -1;
|
||||
}
|
||||
else {
|
||||
++hLdacAbr->nSteadyState;
|
||||
#ifdef LOCAL_DEBUG
|
||||
qd = (abrQualityModeID * 100000000);
|
||||
qd += (hLdacAbr->nPenalty * 1000000);
|
||||
qd += (hLdacAbr->cntToIncQuality *1000);
|
||||
qd += (hLdacAbr->nSteadyState);
|
||||
#endif
|
||||
|
||||
if (hLdacAbr->TxQD_Info.sum == 0) {
|
||||
if (--hLdacAbr->cntToIncQuality <= 0) {
|
||||
ABRDBG("inc1: %d, %d, %d", TxQ, qd, ave10);
|
||||
nStepsToChangeEQMID = 1;
|
||||
}
|
||||
else {
|
||||
ABRDBG("reset: %d, %d, %d", TxQ, qd, ave10);
|
||||
hLdacAbr->TxQD_Info.cnt = 0; // reset the number of sample for average proc.
|
||||
}
|
||||
}
|
||||
else {
|
||||
ABRDBG( "reset cntToIncQuality, %d,%d, %d", TxQ,qd, ave10);
|
||||
hLdacAbr->cntToIncQuality = LDAC_ABR_OBSERVING_COUNT_TO_JUDGE_INC_QUALITY
|
||||
- 2 * abrQualityModeID;
|
||||
if (abrQualityModeID >= hLdacAbr->abrQualityModeIdSteady) {
|
||||
hLdacAbr->cntToIncQuality *= hLdacAbr->nPenalty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef LOCAL_DEBUG
|
||||
else {
|
||||
ABRDBG("Nothing %d, hLdacAbr->TxQD_Info.cnt %u", TxQ, hLdacAbr->TxQD_Info.cnt);
|
||||
}
|
||||
#endif
|
||||
if (flagEnable) {
|
||||
if (nStepsToChangeEQMID) {
|
||||
int abrQualityModeIDNew;
|
||||
if (nStepsToChangeEQMID < 0) {
|
||||
for (i = 0; i > nStepsToChangeEQMID; --i) {
|
||||
if (ldacBT_alter_eqmid_priority(hLDAC, LDACBT_EQMID_INC_CONNECTION)) {
|
||||
#ifdef LOCAL_DEBUG
|
||||
int err;
|
||||
err = ldacBT_get_error_code(hLDAC);
|
||||
ABRDBG("Info@%d : %d ,%d, %d", __LINE__,
|
||||
LDACBT_API_ERR(err), LDACBT_HANDLE_ERR(err), LDACBT_BLOCK_ERR(err));
|
||||
#endif
|
||||
break;// EQMID was already the ID of the highest connectivity.
|
||||
}
|
||||
}
|
||||
|
||||
eqmid = ldacBT_get_eqmid(hLDAC);
|
||||
abrQualityModeIDNew = abrQualityModeID;
|
||||
if (eqmid >= 0) {
|
||||
if (eqmid < sizeOfEqmidToBitrateSortedIdTable) {
|
||||
abrQualityModeIDNew = aEqmidToAbrQualityModeID[eqmid];
|
||||
}
|
||||
}
|
||||
|
||||
if (hLdacAbr->nSteadyState < LDAC_ABR_NUM_STEADY_STATE_TO_JUDGE_STEADY) {
|
||||
hLdacAbr->abrQualityModeIdSteady = abrQualityModeIDNew - 1;
|
||||
if (hLdacAbr->abrQualityModeIdSteady < 0) hLdacAbr->abrQualityModeIdSteady = 0;
|
||||
hLdacAbr->nPenalty *= 2;
|
||||
if(hLdacAbr->nPenalty > LDAC_ABR_PENALTY_MAX) {
|
||||
hLdacAbr->nPenalty = LDAC_ABR_PENALTY_MAX; // MAX PENALTY
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ldacBT_alter_eqmid_priority( hLDAC, LDACBT_EQMID_INC_QUALITY )) {
|
||||
#ifdef LOCAL_DEBUG
|
||||
int err;
|
||||
err = ldacBT_get_error_code(hLDAC);
|
||||
ABRDBG("Info@%d : %d ,%d, %d", __LINE__,
|
||||
LDACBT_API_ERR(err), LDACBT_HANDLE_ERR(err), LDACBT_BLOCK_ERR(err));
|
||||
#endif
|
||||
;// EQMID was already the ID of the highest sound quality.
|
||||
}
|
||||
eqmid = ldacBT_get_eqmid(hLDAC);
|
||||
abrQualityModeIDNew = abrQualityModeID;
|
||||
if (eqmid >= 0) {
|
||||
if (eqmid < sizeOfEqmidToBitrateSortedIdTable) {
|
||||
abrQualityModeIDNew = aEqmidToAbrQualityModeID[eqmid];
|
||||
}
|
||||
}
|
||||
if (abrQualityModeIDNew < hLdacAbr->abrQualityModeIdSteady) {
|
||||
hLdacAbr->nPenalty = 1;
|
||||
}
|
||||
if (abrQualityModeIDNew == aEqmidToAbrQualityModeID[0]) { /* for HQ */
|
||||
if (hLdacAbr->nSteadyState > LDAC_ABR_NUM_STEADY_STATE_TO_RESET_PENALTY_FOR_HQ) {
|
||||
hLdacAbr->nPenalty = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hLdacAbr->nSteadyState = 0;
|
||||
// reset the number of sample for average proc.
|
||||
hLdacAbr->TxQD_Info.cnt = 0;
|
||||
hLdacAbr->cntToIncQuality = LDAC_ABR_OBSERVING_COUNT_TO_JUDGE_INC_QUALITY
|
||||
- 2 * abrQualityModeIDNew;
|
||||
if (hLdacAbr->cntToIncQuality <= 0) {
|
||||
// set minimum value. e1 f == 0.5[s]
|
||||
hLdacAbr->cntToIncQuality = 1;
|
||||
}
|
||||
hLdacAbr->cntToIncQuality *= hLdacAbr->nPenalty;
|
||||
ABRDBG("EQMID NOW %d", eqmid);
|
||||
}
|
||||
}
|
||||
#ifdef LOCAL_DEBUG
|
||||
else if (TxQueueDepth) {
|
||||
ABRDBG("flagEnable false: %d ,%d", TxQ, qd);
|
||||
}
|
||||
#endif
|
||||
|
||||
return eqmid;
|
||||
}
|
|
@ -0,0 +1,540 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LDACBT_H_
|
||||
#define _LDACBT_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifndef LDACBT_API
|
||||
#define LDACBT_API
|
||||
#endif /* LDACBT_API */
|
||||
|
||||
/* This file contains the definitions, declarations and macros for an implimentation of
|
||||
* LDAC encode processing.
|
||||
*
|
||||
* The basic flow of the encode processing is as follows:
|
||||
* - The program creates an handle of an LDAC api using ldacBT_get_handle().
|
||||
* - The program initialize the handle for encode using ldacBT_init_handle_encode().
|
||||
* - The program calls ldacBT_encode() to encode data.
|
||||
* - If the program demands to control the Encode Quality Mode Index, then one of the following
|
||||
* should be called:
|
||||
* - ldacBT_set_eqmid()
|
||||
* - ldacBT_alter_eqmid()
|
||||
* - The program finishes the encoding with passing NULL to input pcm buffer for ldacBT_encode(),
|
||||
* which enables the encoder to encode remaining data in its input buffers.
|
||||
* - The handle may be closed using ldacBT_close_handle() then used again, or released with
|
||||
* ldacBT_free_handle().
|
||||
* - The rest of the set functions should be called only if it is needed by the client.
|
||||
*
|
||||
*
|
||||
* Note for an implimentation
|
||||
* - Error processing
|
||||
* When continuous processing for next frame is performed after error detection, following
|
||||
* processing must be carried out using C function provided in the library.
|
||||
* - Release of internal variables in encode processing using ldacBT_close_handle().
|
||||
* - Allocation and initialization of internal variables in encode processing using
|
||||
* ldacBT_init_handle_encode().
|
||||
* Note that the encoded output for a few frames will not be present just after error recovery.
|
||||
*
|
||||
* - Resuming of the encode processing from an interruption
|
||||
* In case of resuming of the encode processing from interruption (such as changing
|
||||
* configuration, seeking and playback), initialization of internal variables in encode
|
||||
* processing must be carried out as error processing described above.
|
||||
* Note that the encoded output for a few frames will not be present just after initialization
|
||||
* as above.
|
||||
*
|
||||
*
|
||||
* Glossary
|
||||
* channel_config_index (cci)
|
||||
* The channel setting information for ldaclib.
|
||||
* See ldacBT_cm_to_cci() to get value from channel_mode.
|
||||
*
|
||||
* channel_mode (cm)
|
||||
* The channel setting information for LDAC specification of Bluetooth A2DP.
|
||||
* See ldacBT_cci_to_cm() to get value from channel_config_index.
|
||||
*
|
||||
* ldac_transport_frame
|
||||
* See LDAC specification of bluetooth A2DP.
|
||||
*
|
||||
* Maximum Transmission Unit (MTU)
|
||||
* The minimum MTU that a L2CAP implementation for LDAC shall support is 679 bytes, because LDAC
|
||||
* is optimized with 2-DH5 packet as its target.
|
||||
*
|
||||
* frame
|
||||
* An audio signal sequence representing a certain number of PCM audio signals.
|
||||
* Encoding and decoding are processed frame by frame in LDAC. Number of samples in a frame is
|
||||
* determined by sampling frequency as described below.
|
||||
*
|
||||
* Sampling frequency and frame sample.
|
||||
* Supported sampling frequencies are 44.1, 48, 88.2 and 96 kHz.
|
||||
* The relationship between sampling frequency and frame sample in LDAC are shown below.
|
||||
* --------------------------------------------------------
|
||||
* | sampling frequency [kHz] | 44.1 | 48 | 88.2 | 96 |
|
||||
* | frame sample [samples/channel] | 128 | 256 |
|
||||
* --------------------------------------------------------
|
||||
* Though the frame size varies in LDAC core as described in the table, the number of samples in
|
||||
* input PCM signal for encoding is fixed to 128 sample/channel, and it is not affected by
|
||||
* sampling frequency.
|
||||
*/
|
||||
#define LDACBT_ENC_LSU 128
|
||||
#define LDACBT_MAX_LSU 512
|
||||
|
||||
/* channel_config_index.
|
||||
* Supported value are below.
|
||||
*/
|
||||
#define LDAC_CCI_MONO 0 /* MONO */
|
||||
#define LDAC_CCI_DUAL_CHANNEL 1 /* DUAL CHANNEL */
|
||||
#define LDAC_CCI_STEREO 2 /* STEREO */
|
||||
|
||||
/* PCM format.
|
||||
* Supported PCM format are shown below.
|
||||
* - LDACBT_SMPL_FMT_S16 : signed 16bits little endian.
|
||||
* - LDACBT_SMPL_FMT_S24 : signed 24bits little endian.
|
||||
* - LDACBT_SMPL_FMT_S32 : signed 32bits little endian.
|
||||
* - LDACBT_SMPL_FMT_F32 : single-precision floating point.
|
||||
* The data sequency must be interleaved format by 1 sample.
|
||||
* Ex) 2 channel audio, the data sequences are aligned as below.
|
||||
* seq : |L[0]|R[0]|L[1]|R[1]|...
|
||||
*/
|
||||
typedef enum {
|
||||
LDACBT_SMPL_FMT_S16 = 0x2,
|
||||
LDACBT_SMPL_FMT_S24 = 0x3,
|
||||
LDACBT_SMPL_FMT_S32 = 0x4,
|
||||
LDACBT_SMPL_FMT_F32 = 0x5,
|
||||
} LDACBT_SMPL_FMT_T;
|
||||
|
||||
/* Encode Quality Mode Index. (EQMID)
|
||||
* The configuration of encoding in LDAC will be coordinated by "Encode Quality Mode Index"
|
||||
* parameter. Configurable values are shown below.
|
||||
* - LDACBT_EQMID_HQ : Encode setting for High Quality.
|
||||
* - LDACBT_EQMID_SQ : Encode setting for Standard Quality.
|
||||
* - LDACBT_EQMID_MQ : Encode setting for Mobile use Quality.
|
||||
* - LDACBT_EQMID_ABR: Reserved EQMID for ABR. The value shall be 0x7F.
|
||||
*/
|
||||
enum {
|
||||
LDACBT_EQMID_HQ = 0,
|
||||
LDACBT_EQMID_SQ,
|
||||
LDACBT_EQMID_MQ,
|
||||
LDACBT_EQMID_NUM, /* terminator */
|
||||
LDACBT_EQMID_ABR = 0x7F,
|
||||
};
|
||||
|
||||
/* Bit rates
|
||||
* Bit rates in each EQMID are depend on sampling frequency.
|
||||
* In this API specification, these relations are shown below.
|
||||
* ___________________________________________
|
||||
* | | Sampling Frequency[kHz] |
|
||||
* | EQMID | 44.1, 88.2 | 48, 96 |
|
||||
* +-----------------+------------+------------+
|
||||
* | LDACBT_EQMID_HQ | 909kbps | 990kbps |
|
||||
* | LDACBT_EQMID_SQ | 606kbps | 660kbps |
|
||||
* | LDACBT_EQMID_MQ | 303kbps | 330kbps |
|
||||
* -------------------------------------------
|
||||
*/
|
||||
|
||||
/* Maximum size of the "ldac_transport_frame" sequence at transportation. */
|
||||
#define LDACBT_MAX_NBYTES 1024 /* byte */
|
||||
|
||||
/* Maximum number of channel for LDAC */
|
||||
#define LDAC_PRCNCH 2
|
||||
|
||||
/* LDAC handle type */
|
||||
typedef struct _st_ldacbt_handle * HANDLE_LDAC_BT;
|
||||
|
||||
/* Allocation of LDAC handle.
|
||||
* Format
|
||||
* HANDLE_LDAC_BT ldacBT_get_handle( void );
|
||||
* Arguments
|
||||
* None.
|
||||
* Return value
|
||||
* HANDLE_LDAC_BT for success, NULL for failure.
|
||||
*/
|
||||
LDACBT_API HANDLE_LDAC_BT ldacBT_get_handle( void );
|
||||
|
||||
/* Release of LDAC handle.
|
||||
* Format
|
||||
* void ldacBT_free_handle( HANDLE_LDAC_BT hLdacBt );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* Return value
|
||||
* None.
|
||||
*/
|
||||
LDACBT_API void ldacBT_free_handle( HANDLE_LDAC_BT hLdacBt );
|
||||
|
||||
/* Closing of initialized LDAC handle.
|
||||
* Closed handle can be initialized and used again.
|
||||
* Format
|
||||
* void ldacBT_close_handle( HANDLE_LDAC_BT hLdacBt );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* Return value
|
||||
* None.
|
||||
*/
|
||||
LDACBT_API void ldacBT_close_handle( HANDLE_LDAC_BT hLdacBt );
|
||||
|
||||
/* Acquisition of the library version.
|
||||
* Format
|
||||
* int ldacBT_get_version( void );
|
||||
* Arguments
|
||||
* None.
|
||||
* Return value
|
||||
* int : version number.
|
||||
* 23-16 bit : major version
|
||||
* 15- 8 bit : minor version
|
||||
* 7- 0 bit : branch version
|
||||
* Ex) 0x00010203 -> version 1.02.03
|
||||
*/
|
||||
LDACBT_API int ldacBT_get_version( void );
|
||||
|
||||
/* Acquisition of the sampling frequency in current configuration.
|
||||
* The LDAC handle must be initialized by API function ldacBT_init_handle_encode() prior to
|
||||
* calling this function.
|
||||
* Format
|
||||
* int ldacBT_get_sampling_freq( HANDLE_LDAC_BT hLdacBt );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* Return value
|
||||
* int : sampling frequency in current configuration. -1 for failure.
|
||||
*/
|
||||
LDACBT_API int ldacBT_get_sampling_freq( HANDLE_LDAC_BT hLdacBt );
|
||||
|
||||
/* Acquisition of the Bit-rate.
|
||||
* The LDAC handle must be initialized by API function ldacBT_init_handle_encode() prior to
|
||||
* calling this function.
|
||||
* Format
|
||||
* int ldacBT_get_bitrate( HANDLE_LDAC_BT hLdacBt );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* Return value
|
||||
* int : Bit-rate for previously processed ldac_transport_frame for success. -1 for failure.
|
||||
*/
|
||||
LDACBT_API int ldacBT_get_bitrate( HANDLE_LDAC_BT hLdacBt );
|
||||
|
||||
/* Initialization of a LDAC handle for encode processing.
|
||||
* The LDAC handle must be allocated by API function ldacBT_get_handle() prior to calling this API.
|
||||
* "mtu" value should be configured to MTU size of AVDTP Transport Channel, which is determined by
|
||||
* SRC and SNK devices in Bluetooth transmission.
|
||||
* "eqmid" is configured to desired value of "Encode Quality Mode Index".
|
||||
* "cm" is configured to channel_mode in LDAC, which is determined by SRC and SNK devices in
|
||||
* Bluetooth transmission.
|
||||
* "fmt" is configured to input pcm audio format.
|
||||
* When the configuration of "mtu", "cm", or "sf" changed, the re-initialization is required.
|
||||
*
|
||||
* Format
|
||||
* int ldacBT_init_handle_encode( HANDLE_LDAC_BT hLdacBt, int mtu, int eqmid, int cm,
|
||||
* LDACBT_SMPL_FMT_T fmt, int sf );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* mtu int MTU value. Unit:Byte.
|
||||
* eqmid int Encode Quality Mode Index.
|
||||
* cm int Information of the channel_mode.
|
||||
* fmt LDACBT_SMPL_FMT_T Audio format type of input pcm.
|
||||
* sf int Sampling frequency of input pcm.
|
||||
* Return value
|
||||
* int : 0 for success, -1 for failure.
|
||||
*/
|
||||
LDACBT_API int ldacBT_init_handle_encode( HANDLE_LDAC_BT hLdacBt, int mtu, int eqmid, int cm,
|
||||
LDACBT_SMPL_FMT_T fmt, int sf );
|
||||
|
||||
/* Configuration of Encode Quality Mode Index.
|
||||
* The LDAC handle must be initialized by API function ldacBT_init_handle_encode() prior to
|
||||
* calling this function.
|
||||
* The API function can be called at any time, after the completion of initializing.
|
||||
* Format
|
||||
* int ldacBT_set_eqmid( HANDLE_LDAC_BT hLdacBt, int eqmid );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* eqmid int Encode Quality Mode Index.
|
||||
* Return value
|
||||
* int : 0 for success, -1 for failure.
|
||||
*/
|
||||
LDACBT_API int ldacBT_set_eqmid( HANDLE_LDAC_BT hLdacBt, int eqmid );
|
||||
|
||||
/* Acquisition of prescribed Encode Quality Mode Index in current configuration.
|
||||
* The LDAC handle must be initialized by API function ldacBT_init_handle_encode() prior to
|
||||
* calling this function.
|
||||
* Format
|
||||
* int ldacBT_get_eqmid( HANDLE_LDAC_BT hLdacBt );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* Return value
|
||||
* int : Encode Quality Mode Index for success, -1 for failure.
|
||||
*/
|
||||
LDACBT_API int ldacBT_get_eqmid( HANDLE_LDAC_BT hLdacBt );
|
||||
|
||||
/* Changing of configuration for Encode Quality Mode Index by one step.
|
||||
* The LDAC handle must be initialized by API function ldacBT_init_handle_encode() prior to
|
||||
* calling this function.
|
||||
* Configuralbe values for "priority" are shown below.
|
||||
* - LDACBT_EQMID_INC_QUALITY : Adjustment for EQMID by one step for the direction of
|
||||
* getting close to LDACBT_EQMID_HQ.
|
||||
* - LDACBT_EQMID_INC_CONNECTION : Adjustment for EQMID by one step for the direction of
|
||||
* getting away from LDACBT_EQMID_HQ.
|
||||
* For restoring prescribed value for "Encode Quality Mode Index", it must be configured again by
|
||||
* API function ldacBT_init_handle_encode() or ldacBT_set_qmode().
|
||||
* A transition to the state other than "Encode Quality Mode Index" mention before may be occurred
|
||||
* caused by an adjustment using this API function.
|
||||
* The API function can be called at any time, after the completion of initializing.
|
||||
* Format
|
||||
* int ldacBT_alter_eqmid_priority( HANDLE_LDAC_BT hLdacBt, int priority );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* priority int The direction of changing EQMID.
|
||||
* Return value
|
||||
* int : 0 for success, -1 for failure.
|
||||
*/
|
||||
#define LDACBT_EQMID_INC_QUALITY 1
|
||||
#define LDACBT_EQMID_INC_CONNECTION -1
|
||||
LDACBT_API int ldacBT_alter_eqmid_priority( HANDLE_LDAC_BT hLdacBt, int priority );
|
||||
|
||||
|
||||
/* LDAC encode processing.
|
||||
* The LDAC handle must be initialized by API function ldacBT_init_handle_encode() prior to calling
|
||||
* this API function.
|
||||
* <Regarding on a input PCM signal>
|
||||
* Number of samples in input PCM signal for encoding is fixed to 128 samples per channel, and it
|
||||
* is not affected by sampling frequency.
|
||||
*
|
||||
* The region in input signal buffer without any PCM signal must be filled with zero, if the
|
||||
* number of samples is less than 128 samples.
|
||||
*
|
||||
* The format of PCM signal is determined by "fmt" configured by API function
|
||||
* ldacBT_init_handle_encode().
|
||||
*
|
||||
* Total size of referenced PCM signal (in byte) will be set in "pcm_used" on return. The value of
|
||||
* "Number of input samples * Number of channels * sizeof(PCM word length)" will be set in normal.
|
||||
*
|
||||
* Finalize processing of encode will be carried out with setting "p_pcm" as zero.
|
||||
*
|
||||
* <Regarding on output encoded data>
|
||||
* An output data in "ldac_transport_frame" sequence will be set to "p_stream" after several frame
|
||||
* processing. So the output is not necessarily present at each calling of this API function.
|
||||
*
|
||||
* The presence of the output can be verified by checking whether the value of "stream_wrote",
|
||||
* representing the number of written bytes for "p_stream", is positive or not.
|
||||
*
|
||||
* In addition, encoded data size for output will be determined by the value of "mtu" configured
|
||||
* by API function ldacBT_init_handle_encode().
|
||||
*
|
||||
* The number of "ldac_transport_frame" corresponding to "ldac_transport_frame" sequence as output
|
||||
* will be set to "frame_num".
|
||||
*
|
||||
* Format
|
||||
* int ldacBT_encode( HANDLE_LDAC_BT hLdacBt, void *p_pcm, int *pcm_used,
|
||||
* unsigned char *p_stream, int *stream_sz, int *frame_num );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* p_pcm void * Input PCM signal sequence
|
||||
* pcm_used int * Data size of referenced PCM singnal. Unit:Byte.
|
||||
* p_stream unsigned char * Output "ldac_transport_frame" sequence.
|
||||
* stream_sz int * Size of output data. Unit:Byte.
|
||||
* frame_num int * Number of output "ldac_transport_frame"
|
||||
* Return value
|
||||
* int : 0 for success, -1 for failure.
|
||||
*/
|
||||
LDACBT_API int ldacBT_encode( HANDLE_LDAC_BT hLdacBt, void *p_pcm, int *pcm_used,
|
||||
unsigned char *p_stream, int *stream_sz, int *frame_num );
|
||||
|
||||
/* Acquisition of previously established error code.
|
||||
* The LDAC handle must be allocated by API function ldacBT_get_handle() prior to calling this function.
|
||||
* The details of error code are described below at the end of this header file.
|
||||
* Tips for error code handling.
|
||||
* The macro function LDACBT_FATAL() is useful to determine whether the error code is Fatal or not.
|
||||
* Ex.) if( LDACBT_FATAL(err) ) // Fatal Error occurred.
|
||||
*
|
||||
* The macro function LDACBT_ERROR() is useful to determine whether the error occurred or not.
|
||||
* Ex.) if( LDACBT_ERROR(err) ) // Error occurred.
|
||||
*
|
||||
* The macro function LDACBT_HANDLE_ERR() is useful to get the handle level error code.
|
||||
* Ex.) err_handle_lv = LDACBT_HANDLE_ERR(err);
|
||||
*
|
||||
* The macro function LDACBT_BLOCK_ERR() is useful to get the block level error code.
|
||||
* Ex.) err_block_lv = LDACBT_BLOCK_ERR(err);
|
||||
*
|
||||
* Format
|
||||
* int ldacBT_get_error_code( HANDLE_LDAC_BT hLdacBt );
|
||||
* Arguments
|
||||
* hLdacBt HANDLE_LDAC_BT LDAC handle.
|
||||
* Return value
|
||||
* int : Error code.
|
||||
*/
|
||||
LDACBT_API int ldacBT_get_error_code( HANDLE_LDAC_BT hLdacBt );
|
||||
|
||||
/*******************************************************************************
|
||||
Error Code
|
||||
*******************************************************************************/
|
||||
#define LDACBT_ERR_NONE 0
|
||||
|
||||
/* Non Fatal Error ***********************************************************/
|
||||
#define LDACBT_ERR_NON_FATAL 1
|
||||
|
||||
/* Non Fatal Error (Block Level) *********************************************/
|
||||
#define LDACBT_ERR_BIT_ALLOCATION 5
|
||||
|
||||
/* Non Fatal Error (Handle Level) ********************************************/
|
||||
#define LDACBT_ERR_NOT_IMPLEMENTED 128
|
||||
#define LDACBT_ERR_NON_FATAL_ENCODE 132
|
||||
|
||||
/* Fatal Error ***************************************************************/
|
||||
#define LDACBT_ERR_FATAL 256
|
||||
|
||||
/* Fatal Error (Block Level) *************************************************/
|
||||
#define LDACBT_ERR_SYNTAX_BAND 260
|
||||
#define LDACBT_ERR_SYNTAX_GRAD_A 261
|
||||
#define LDACBT_ERR_SYNTAX_GRAD_B 262
|
||||
#define LDACBT_ERR_SYNTAX_GRAD_C 263
|
||||
#define LDACBT_ERR_SYNTAX_GRAD_D 264
|
||||
#define LDACBT_ERR_SYNTAX_GRAD_E 265
|
||||
#define LDACBT_ERR_SYNTAX_IDSF 266
|
||||
#define LDACBT_ERR_SYNTAX_SPEC 267
|
||||
|
||||
#define LDACBT_ERR_BIT_PACKING 280
|
||||
|
||||
#define LDACBT_ERR_ALLOC_MEMORY 300
|
||||
|
||||
/* Fatal Error (Handle Level) ************************************************/
|
||||
#define LDACBT_ERR_FATAL_HANDLE 512
|
||||
|
||||
#define LDACBT_ERR_ILL_SYNCWORD 516
|
||||
#define LDACBT_ERR_ILL_SMPL_FORMAT 517
|
||||
#define LDACBT_ERR_ILL_PARAM 518
|
||||
|
||||
#define LDACBT_ERR_ASSERT_SAMPLING_FREQ 530
|
||||
#define LDACBT_ERR_ASSERT_SUP_SAMPLING_FREQ 531
|
||||
#define LDACBT_ERR_CHECK_SAMPLING_FREQ 532
|
||||
#define LDACBT_ERR_ASSERT_CHANNEL_CONFIG 533
|
||||
#define LDACBT_ERR_CHECK_CHANNEL_CONFIG 534
|
||||
#define LDACBT_ERR_ASSERT_FRAME_LENGTH 535
|
||||
#define LDACBT_ERR_ASSERT_SUP_FRAME_LENGTH 536
|
||||
#define LDACBT_ERR_ASSERT_FRAME_STATUS 537
|
||||
#define LDACBT_ERR_ASSERT_NSHIFT 538
|
||||
#define LDACBT_ERR_ASSERT_CHANNEL_MODE 539
|
||||
|
||||
#define LDACBT_ERR_ENC_INIT_ALLOC 550
|
||||
#define LDACBT_ERR_ENC_ILL_GRADMODE 551
|
||||
#define LDACBT_ERR_ENC_ILL_GRADPAR_A 552
|
||||
#define LDACBT_ERR_ENC_ILL_GRADPAR_B 553
|
||||
#define LDACBT_ERR_ENC_ILL_GRADPAR_C 554
|
||||
#define LDACBT_ERR_ENC_ILL_GRADPAR_D 555
|
||||
#define LDACBT_ERR_ENC_ILL_NBANDS 556
|
||||
#define LDACBT_ERR_PACK_BLOCK_FAILED 557
|
||||
|
||||
#define LDACBT_ERR_DEC_INIT_ALLOC 570
|
||||
#define LDACBT_ERR_INPUT_BUFFER_SIZE 571
|
||||
#define LDACBT_ERR_UNPACK_BLOCK_FAILED 572
|
||||
#define LDACBT_ERR_UNPACK_BLOCK_ALIGN 573
|
||||
#define LDACBT_ERR_UNPACK_FRAME_ALIGN 574
|
||||
#define LDACBT_ERR_FRAME_LENGTH_OVER 575
|
||||
#define LDACBT_ERR_FRAME_ALIGN_OVER 576
|
||||
|
||||
|
||||
/* LDAC API for Encode */
|
||||
#define LDACBT_ERR_ALTER_EQMID_LIMITED 21
|
||||
#define LDACBT_ERR_HANDLE_NOT_INIT 1000
|
||||
#define LDACBT_ERR_ILL_EQMID 1024
|
||||
#define LDACBT_ERR_ILL_SAMPLING_FREQ 1025
|
||||
#define LDACBT_ERR_ILL_NUM_CHANNEL 1026
|
||||
#define LDACBT_ERR_ILL_MTU_SIZE 1027
|
||||
/* LDAC API for Decode */
|
||||
#define LDACBT_ERR_DEC_CONFIG_UPDATED 40
|
||||
|
||||
|
||||
/* Macro Functions for Error Code ********************************************/
|
||||
#define LDACBT_API_ERR(err) ((err >> 20) & 0x0FFF)
|
||||
#define LDACBT_HANDLE_ERR(err) ((err >> 10) & 0x03FF)
|
||||
#define LDACBT_BLOCK_ERR(err) ( err & 0x03FF)
|
||||
#define LDACBT_ERROR(err) ((LDACBT_ERR_NON_FATAL) <= LDACBT_API_ERR(err) ? 1 : 0)
|
||||
#define LDACBT_FATAL(err) ((LDACBT_ERR_FATAL) <= LDACBT_API_ERR(err) ? 1 : 0)
|
||||
|
||||
|
||||
|
||||
/* Codec Specific Information Elements for LDAC
|
||||
* (based on "LDAC Specification of Bluetooth A2DP Rev.2.0.1")
|
||||
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
||||
* service_caps[4] | SONY ID | Octet0
|
||||
* service_caps[5] | SONY ID | Octet1
|
||||
* service_caps[6] | SONY ID | Octet2
|
||||
* service_caps[7] | SONY ID | Octet3
|
||||
* service_caps[8] | SONY Specific Codec ID | Octet4
|
||||
* service_caps[9] | SONY Specific Codec ID | Octet5
|
||||
* service_caps[A] | RFA | Sampling Frequency | Octet6
|
||||
* service_caps[B] | RFA | Channel Mode ID | Octet7
|
||||
*/
|
||||
#define LDACBT_MEDIA_CODEC_SC_SZ (10+2)
|
||||
|
||||
/* [Octet 0-3] Vendor ID for SONY */
|
||||
#define LDACBT_VENDOR_ID0 0x2D
|
||||
#define LDACBT_VENDOR_ID1 0x01
|
||||
#define LDACBT_VENDOR_ID2 0x0
|
||||
#define LDACBT_VENDOR_ID3 0x0
|
||||
|
||||
/* [Octet 4-5] Vendor Specific A2DP Codec ID for LDAC */
|
||||
#define LDACBT_CODEC_ID0 0xAA
|
||||
#define LDACBT_CODEC_ID1 0x00
|
||||
|
||||
/* [Octet 6]
|
||||
* [b7,b6] : RFA
|
||||
* Reserved for future additions.
|
||||
* Bits with this designation shall be set to zero.
|
||||
* Receivers shall ignore these bits.
|
||||
* -----------------------------------------------------
|
||||
* [b5-b0] : Sampling frequency and its associated bit field in LDAC are shown below.
|
||||
* | 5 | 4 | 3 | 2 | 1 | 0 |
|
||||
* | o | | | | | | 44100
|
||||
* | | o | | | | | 48000
|
||||
* | | | o | | | | 88200
|
||||
* | | | | o | | | 96000
|
||||
* | | | | | o | | 176400
|
||||
* | | | | | | o | 192000
|
||||
*
|
||||
*/
|
||||
/* Support for 44.1kHz sampling frequency */
|
||||
#define LDACBT_SAMPLING_FREQ_044100 0x20
|
||||
/* Support for 48kHz sampling frequency */
|
||||
#define LDACBT_SAMPLING_FREQ_048000 0x10
|
||||
/* Support for 88.2kHz sampling frequency */
|
||||
#define LDACBT_SAMPLING_FREQ_088200 0x08
|
||||
/* Support for 96kHz sampling frequency */
|
||||
#define LDACBT_SAMPLING_FREQ_096000 0x04
|
||||
/* Support for 176.4kHz sampling frequency */
|
||||
#define LDACBT_SAMPLING_FREQ_176400 0x02
|
||||
/* Support for 192kHz sampling frequency */
|
||||
#define LDACBT_SAMPLING_FREQ_192000 0x01
|
||||
|
||||
/* [Octet 7]
|
||||
* [b7-b3] : RFA
|
||||
* Reserved for future additions.
|
||||
* Bits with this designation shall be set to zero.
|
||||
* Receivers shall ignore these bits.
|
||||
* ------------------------------------------------------
|
||||
* [b2-b0] : Channel mode and its associated bit field in LDAC are shown below.
|
||||
* | 2 | 1 | 0 |
|
||||
* | o | | | MONO
|
||||
* | | o | | DUAL CHANNEL
|
||||
* | | | o | STEREO
|
||||
*/
|
||||
/* Support for MONO */
|
||||
#define LDACBT_CHANNEL_MODE_MONO 0x04
|
||||
/* Support for DUAL CHANNEL */
|
||||
#define LDACBT_CHANNEL_MODE_DUAL_CHANNEL 0x02
|
||||
/* Support for STEREO */
|
||||
#define LDACBT_CHANNEL_MODE_STEREO 0x01
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _LDACBT_H_ */
|
|
@ -0,0 +1,733 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Calculate Bits for Audio Block
|
||||
***************************************************************************************************/
|
||||
static int encode_audio_block_a_ldac(
|
||||
AB *p_ab,
|
||||
int hqu)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich, iqu;
|
||||
int nchs = p_ab->blk_nchs;
|
||||
int tmp, nbits = 0;
|
||||
int idsp, idwl1, idwl2;
|
||||
int grad_mode = p_ab->grad_mode;
|
||||
int grad_qu_l = p_ab->grad_qu_l;
|
||||
int grad_qu_h = p_ab->grad_qu_h;
|
||||
int grad_os_l = p_ab->grad_os_l;
|
||||
int grad_os_h = p_ab->grad_os_h;
|
||||
int *p_grad = p_ab->a_grad;
|
||||
int *p_idsf, *p_addwl, *p_idwl1, *p_idwl2;
|
||||
const unsigned char *p_t;
|
||||
|
||||
/* Calculate Gradient Curve */
|
||||
tmp = grad_qu_h - grad_qu_l;
|
||||
|
||||
for (iqu = 0; iqu < grad_qu_h; iqu++) {
|
||||
p_grad[iqu] = -grad_os_l;
|
||||
}
|
||||
for (iqu = grad_qu_h; iqu < hqu; iqu++) {
|
||||
p_grad[iqu] = -grad_os_h;
|
||||
}
|
||||
|
||||
if (tmp > 0) {
|
||||
p_t = gaa_resamp_grad_ldac[tmp-1];
|
||||
|
||||
tmp = grad_os_h - grad_os_l;
|
||||
if (tmp > 0) {
|
||||
tmp = tmp-1;
|
||||
for (iqu = grad_qu_l; iqu < grad_qu_h; iqu++) {
|
||||
p_grad[iqu] -= ((*p_t++ * tmp) >> 8) + 1;
|
||||
}
|
||||
}
|
||||
else if (tmp < 0) {
|
||||
tmp = -tmp-1;
|
||||
for (iqu = grad_qu_l; iqu < grad_qu_h; iqu++) {
|
||||
p_grad[iqu] += ((*p_t++ * tmp) >> 8) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate Bits */
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_ab->ap_ac[ich];
|
||||
p_idsf = p_ac->a_idsf;
|
||||
p_addwl = p_ac->a_addwl;
|
||||
p_idwl1 = p_ac->a_idwl1;
|
||||
p_idwl2 = p_ac->a_idwl2;
|
||||
|
||||
if (grad_mode == LDAC_MODE_0) {
|
||||
for (iqu = 0; iqu < hqu; iqu++) {
|
||||
idwl1 = p_idsf[iqu] + p_grad[iqu];
|
||||
if (idwl1 < LDAC_MINIDWL1) {
|
||||
idwl1 = LDAC_MINIDWL1;
|
||||
}
|
||||
idwl2 = 0;
|
||||
if (idwl1 > LDAC_MAXIDWL1) {
|
||||
idwl2 = idwl1 - LDAC_MAXIDWL1;
|
||||
if (idwl2 > LDAC_MAXIDWL2) {
|
||||
idwl2 = LDAC_MAXIDWL2;
|
||||
}
|
||||
idwl1 = LDAC_MAXIDWL1;
|
||||
}
|
||||
p_idwl1[iqu] = idwl1;
|
||||
p_idwl2[iqu] = idwl2;
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
}
|
||||
}
|
||||
else if (grad_mode == LDAC_MODE_1) {
|
||||
for (iqu = 0; iqu < hqu; iqu++) {
|
||||
idwl1 = p_idsf[iqu] + p_grad[iqu] + p_addwl[iqu];
|
||||
if (idwl1 > 0) {
|
||||
idwl1 = idwl1 >> 1;
|
||||
}
|
||||
if (idwl1 < LDAC_MINIDWL1) {
|
||||
idwl1 = LDAC_MINIDWL1;
|
||||
}
|
||||
idwl2 = 0;
|
||||
if (idwl1 > LDAC_MAXIDWL1) {
|
||||
idwl2 = idwl1 - LDAC_MAXIDWL1;
|
||||
if (idwl2 > LDAC_MAXIDWL2) {
|
||||
idwl2 = LDAC_MAXIDWL2;
|
||||
}
|
||||
idwl1 = LDAC_MAXIDWL1;
|
||||
}
|
||||
p_idwl1[iqu] = idwl1;
|
||||
p_idwl2[iqu] = idwl2;
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
}
|
||||
}
|
||||
else if (grad_mode == LDAC_MODE_2) {
|
||||
for (iqu = 0; iqu < hqu; iqu++) {
|
||||
idwl1 = p_idsf[iqu] + p_grad[iqu] + p_addwl[iqu];
|
||||
if (idwl1 > 0) {
|
||||
idwl1 = (idwl1*3) >> 3;
|
||||
}
|
||||
if (idwl1 < LDAC_MINIDWL1) {
|
||||
idwl1 = LDAC_MINIDWL1;
|
||||
}
|
||||
idwl2 = 0;
|
||||
if (idwl1 > LDAC_MAXIDWL1) {
|
||||
idwl2 = idwl1 - LDAC_MAXIDWL1;
|
||||
if (idwl2 > LDAC_MAXIDWL2) {
|
||||
idwl2 = LDAC_MAXIDWL2;
|
||||
}
|
||||
idwl1 = LDAC_MAXIDWL1;
|
||||
}
|
||||
p_idwl1[iqu] = idwl1;
|
||||
p_idwl2[iqu] = idwl2;
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
}
|
||||
}
|
||||
else if (grad_mode == LDAC_MODE_3) {
|
||||
for (iqu = 0; iqu < hqu; iqu++) {
|
||||
idwl1 = p_idsf[iqu] + p_grad[iqu] + p_addwl[iqu];
|
||||
if (idwl1 > 0) {
|
||||
idwl1 = idwl1 >> 2;
|
||||
}
|
||||
if (idwl1 < LDAC_MINIDWL1) {
|
||||
idwl1 = LDAC_MINIDWL1;
|
||||
}
|
||||
idwl2 = 0;
|
||||
if (idwl1 > LDAC_MAXIDWL1) {
|
||||
idwl2 = idwl1 - LDAC_MAXIDWL1;
|
||||
if (idwl2 > LDAC_MAXIDWL2) {
|
||||
idwl2 = LDAC_MAXIDWL2;
|
||||
}
|
||||
idwl1 = LDAC_MAXIDWL1;
|
||||
}
|
||||
p_idwl1[iqu] = idwl1;
|
||||
p_idwl2[iqu] = idwl2;
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Calculate Bits for Audio Block
|
||||
***************************************************************************************************/
|
||||
static int encode_audio_block_b_ldac(
|
||||
AB *p_ab,
|
||||
int nadjqus)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich, iqu;
|
||||
int nchs = p_ab->blk_nchs;
|
||||
int nqus = min_ldac(LDAC_MAXNADJQUS, p_ab->nqus);
|
||||
int nbits = 0;
|
||||
int idsp, idwl1, idwl2;
|
||||
int *p_idwl1, *p_idwl2, *p_tmp;
|
||||
|
||||
/* Calculate Bits */
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_ab->ap_ac[ich];
|
||||
p_idwl1 = p_ac->a_idwl1;
|
||||
p_idwl2 = p_ac->a_idwl2;
|
||||
p_tmp = p_ac->a_tmp;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
idwl1 = p_tmp[iqu];
|
||||
if (iqu < nadjqus) {
|
||||
idwl1++;
|
||||
}
|
||||
idwl2 = 0;
|
||||
if (idwl1 > LDAC_MAXIDWL1) {
|
||||
idwl2 = idwl1 - LDAC_MAXIDWL1;
|
||||
if (idwl2 > LDAC_MAXIDWL2) {
|
||||
idwl2 = LDAC_MAXIDWL2;
|
||||
}
|
||||
idwl1 = LDAC_MAXIDWL1;
|
||||
}
|
||||
p_idwl1[iqu] = idwl1;
|
||||
p_idwl2[iqu] = idwl2;
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
}
|
||||
}
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Decrease Lower Offset of Gradient Curve
|
||||
***************************************************************************************************/
|
||||
static int decrease_offset_low_ldac(
|
||||
AB *p_ab,
|
||||
int limit,
|
||||
int *p_nbits_spec)
|
||||
{
|
||||
int ncalls = 0;
|
||||
int nqus = p_ab->nqus;
|
||||
int grad_os_l = p_ab->grad_os_l;
|
||||
int nbits_avail = p_ab->nbits_avail;
|
||||
int step = limit - grad_os_l;
|
||||
int a_checked[LDAC_MAXGRADOS+1];
|
||||
|
||||
if (*p_nbits_spec > nbits_avail) {
|
||||
memset(a_checked, 0, (LDAC_MAXGRADOS+1)*sizeof(int));
|
||||
|
||||
while (grad_os_l < limit) {
|
||||
if (step > 1) {
|
||||
step = (step+1)/2;
|
||||
}
|
||||
|
||||
if (*p_nbits_spec < nbits_avail) {
|
||||
grad_os_l -= step;
|
||||
if (grad_os_l < 0) {
|
||||
grad_os_l += step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_os_l]) {
|
||||
grad_os_l += step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*p_nbits_spec > nbits_avail) {
|
||||
grad_os_l += step;
|
||||
if (grad_os_l > LDAC_MAXGRADOS) {
|
||||
grad_os_l -= step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_os_l]) {
|
||||
grad_os_l -= step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
|
||||
p_ab->grad_os_l = grad_os_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
a_checked[grad_os_l] = *p_nbits_spec;
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
while ((*p_nbits_spec > nbits_avail) && (grad_os_l < limit)) {
|
||||
p_ab->grad_os_l = ++grad_os_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
ncalls++;
|
||||
}
|
||||
}
|
||||
|
||||
return ncalls;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Decrease Higher Offset of Gradient Curve
|
||||
***************************************************************************************************/
|
||||
static int decrease_offset_high_ldac(
|
||||
AB *p_ab,
|
||||
int *p_nbits_spec)
|
||||
{
|
||||
int ncalls = 0;
|
||||
int nqus = p_ab->nqus;
|
||||
int grad_os_h = p_ab->grad_os_h;
|
||||
int nbits_avail = p_ab->nbits_avail;
|
||||
int step = LDAC_MAXGRADOS - grad_os_h;
|
||||
int a_checked[LDAC_MAXGRADOS+1];
|
||||
|
||||
if (*p_nbits_spec > nbits_avail) {
|
||||
memset(a_checked, 0, (LDAC_MAXGRADOS+1)*sizeof(int));
|
||||
|
||||
while (grad_os_h < LDAC_MAXGRADOS) {
|
||||
if (step > 1) {
|
||||
step = (step+1)/2;
|
||||
}
|
||||
|
||||
if (*p_nbits_spec < nbits_avail) {
|
||||
grad_os_h -= step;
|
||||
if (grad_os_h < 0) {
|
||||
grad_os_h += step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_os_h]) {
|
||||
grad_os_h += step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*p_nbits_spec > nbits_avail) {
|
||||
grad_os_h += step;
|
||||
if (grad_os_h > LDAC_MAXGRADOS) {
|
||||
grad_os_h -= step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_os_h]) {
|
||||
grad_os_h -= step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
|
||||
p_ab->grad_os_h = grad_os_h;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
a_checked[grad_os_h] = *p_nbits_spec;
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
while ((*p_nbits_spec > nbits_avail) && (grad_os_h < LDAC_MAXGRADOS)) {
|
||||
p_ab->grad_os_h = ++grad_os_h;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
ncalls++;
|
||||
}
|
||||
}
|
||||
|
||||
return ncalls;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Increase Lower Offset of Gradient Curve
|
||||
***************************************************************************************************/
|
||||
static int increase_offset_low_ldac(
|
||||
AB *p_ab,
|
||||
int *p_nbits_spec)
|
||||
{
|
||||
int ncalls = 0;
|
||||
int nqus = p_ab->nqus;
|
||||
int grad_os_l = p_ab->grad_os_l;
|
||||
int nbits_avail = p_ab->nbits_avail;
|
||||
int step = grad_os_l;
|
||||
int a_checked[LDAC_MAXGRADOS+1];
|
||||
|
||||
memset(a_checked, 0, (LDAC_MAXGRADOS+1)*sizeof(int));
|
||||
|
||||
while (grad_os_l > 0) {
|
||||
if (step > 1) {
|
||||
step = (step+1)/2;
|
||||
}
|
||||
|
||||
if (*p_nbits_spec < nbits_avail) {
|
||||
grad_os_l -= step;
|
||||
if (grad_os_l < 0) {
|
||||
grad_os_l += step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_os_l]) {
|
||||
grad_os_l += step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*p_nbits_spec > nbits_avail) {
|
||||
grad_os_l += step;
|
||||
if (grad_os_l > LDAC_MAXGRADOS) {
|
||||
grad_os_l -= step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_os_l]) {
|
||||
grad_os_l -= step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
|
||||
p_ab->grad_os_l = grad_os_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
a_checked[grad_os_l] = *p_nbits_spec;
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
while ((*p_nbits_spec > nbits_avail) && (grad_os_l < LDAC_MAXGRADOS)) {
|
||||
p_ab->grad_os_l = ++grad_os_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
return ncalls;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Increase Lower QU of Gradient Curve
|
||||
***************************************************************************************************/
|
||||
static int increase_qu_low_ldac(
|
||||
AB *p_ab,
|
||||
int *p_nbits_spec)
|
||||
{
|
||||
int ncalls = 0;
|
||||
int nqus = p_ab->nqus;
|
||||
int grad_qu_l = p_ab->grad_qu_l;
|
||||
int grad_qu_h = p_ab->grad_qu_h;
|
||||
int nbits_avail = p_ab->nbits_avail;
|
||||
int step = grad_qu_h - grad_qu_l;
|
||||
int a_checked[LDAC_DEFGRADQUH+1];
|
||||
|
||||
memset(a_checked, 0, (LDAC_DEFGRADQUH+1)*sizeof(int));
|
||||
|
||||
while ((grad_qu_l > 0) && (grad_qu_l < LDAC_DEFGRADQUH)) {
|
||||
if (step > 1) {
|
||||
step = (step+1)/2;
|
||||
}
|
||||
|
||||
if (*p_nbits_spec < nbits_avail) {
|
||||
grad_qu_l += step;
|
||||
if (grad_qu_l > LDAC_DEFGRADQUH) {
|
||||
grad_qu_l -= step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_qu_l]) {
|
||||
grad_qu_l -= step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*p_nbits_spec > nbits_avail) {
|
||||
grad_qu_l -= step;
|
||||
if (grad_qu_l < 0) {
|
||||
grad_qu_l += step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_qu_l]) {
|
||||
grad_qu_l += step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
|
||||
p_ab->grad_qu_l = grad_qu_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
a_checked[grad_qu_l] = *p_nbits_spec;
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
while ((*p_nbits_spec > nbits_avail) && (grad_qu_l <= LDAC_DEFGRADQUH)) {
|
||||
p_ab->grad_qu_l = --grad_qu_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
return ncalls;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Increase Lower QU of Gradient Curve
|
||||
***************************************************************************************************/
|
||||
static int increase_qu_low_0_ldac(
|
||||
AB *p_ab,
|
||||
int *p_nbits_spec)
|
||||
{
|
||||
int ncalls = 0;
|
||||
int nqus = p_ab->nqus;
|
||||
int grad_qu_l = p_ab->grad_qu_l;
|
||||
int grad_qu_h = p_ab->grad_qu_h;
|
||||
int nbits_avail = p_ab->nbits_avail;
|
||||
int step = grad_qu_h - grad_qu_l;
|
||||
int a_checked[LDAC_MAXGRADQU+1];
|
||||
|
||||
memset(a_checked, 0, (LDAC_MAXGRADQU+1)*sizeof(int));
|
||||
|
||||
while ((grad_qu_l > 0) && (grad_qu_l < grad_qu_h)) {
|
||||
if (step > 1) {
|
||||
step = step/2;
|
||||
}
|
||||
|
||||
if (*p_nbits_spec < nbits_avail) {
|
||||
grad_qu_l += step;
|
||||
if (grad_qu_l >= grad_qu_h) {
|
||||
grad_qu_l -= step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_qu_l]) {
|
||||
grad_qu_l -= step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*p_nbits_spec > nbits_avail) {
|
||||
grad_qu_l -= step;
|
||||
if (grad_qu_l < 0) {
|
||||
grad_qu_l += step;
|
||||
break;
|
||||
}
|
||||
else if (a_checked[grad_qu_l]) {
|
||||
grad_qu_l += step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
|
||||
p_ab->grad_qu_l = grad_qu_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
a_checked[grad_qu_l] = *p_nbits_spec;
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
while ((*p_nbits_spec > nbits_avail) && (grad_qu_l > 0)) {
|
||||
p_ab->grad_qu_l = --grad_qu_l;
|
||||
*p_nbits_spec = encode_audio_block_a_ldac(p_ab, nqus);
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
return ncalls;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Adjust Remaining Bits
|
||||
***************************************************************************************************/
|
||||
static int adjust_remain_bits_ldac(
|
||||
AB *p_ab,
|
||||
int *p_nbits_spec,
|
||||
int *p_nadjqus)
|
||||
{
|
||||
int ich, iqu;
|
||||
int ncalls = 0;
|
||||
int nbits_fix, nbits_spec;
|
||||
int nbits_avail = p_ab->nbits_avail;
|
||||
int idsp, idwl1, idwl2, tmp;
|
||||
int step = LDAC_MAXNADJQUS>>1;
|
||||
int nadjqus = LDAC_MAXNADJQUS>>1;
|
||||
int nchs = p_ab->blk_nchs;
|
||||
int nqus = min_ldac(LDAC_MAXNADJQUS, p_ab->nqus);
|
||||
int grad_mode = p_ab->grad_mode;
|
||||
int *p_grad = p_ab->a_grad;
|
||||
int *p_idsf, *p_addwl, *p_idwl1, *p_idwl2, *p_tmp;
|
||||
AC *p_ac;
|
||||
|
||||
nbits_fix = 0;
|
||||
for (ich = 0; ich < nchs; ich++){
|
||||
p_ac = p_ab->ap_ac[ich];
|
||||
p_idsf = p_ac->a_idsf;
|
||||
p_addwl = p_ac->a_addwl;
|
||||
p_idwl1 = p_ac->a_idwl1;
|
||||
p_idwl2 = p_ac->a_idwl2;
|
||||
p_tmp = p_ac->a_tmp;
|
||||
|
||||
if (grad_mode == LDAC_MODE_0) {
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
idwl1 = p_idwl1[iqu];
|
||||
idwl2 = p_idwl2[iqu];
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits_fix += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
tmp = p_idsf[iqu] + p_grad[iqu];
|
||||
if (tmp < LDAC_MINIDWL1) {
|
||||
tmp = LDAC_MINIDWL1;
|
||||
}
|
||||
p_tmp[iqu] = tmp;
|
||||
}
|
||||
}
|
||||
else if (grad_mode == LDAC_MODE_1) {
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
idwl1 = p_idwl1[iqu];
|
||||
idwl2 = p_idwl2[iqu];
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits_fix += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
tmp = p_idsf[iqu] + p_grad[iqu] + p_addwl[iqu];
|
||||
if (tmp > 0) {
|
||||
tmp = tmp >> 1;
|
||||
}
|
||||
if (tmp < LDAC_MINIDWL1) {
|
||||
tmp = LDAC_MINIDWL1;
|
||||
}
|
||||
p_tmp[iqu] = tmp;
|
||||
}
|
||||
}
|
||||
else if (grad_mode == LDAC_MODE_2) {
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
idwl1 = p_idwl1[iqu];
|
||||
idwl2 = p_idwl2[iqu];
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits_fix += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
tmp = p_idsf[iqu] + p_grad[iqu] + p_addwl[iqu];
|
||||
if (tmp > 0) {
|
||||
tmp = (tmp*3) >> 3;
|
||||
}
|
||||
if (tmp < LDAC_MINIDWL1) {
|
||||
tmp = LDAC_MINIDWL1;
|
||||
}
|
||||
p_tmp[iqu] = tmp;
|
||||
}
|
||||
}
|
||||
else if (grad_mode == LDAC_MODE_3) {
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
idwl1 = p_idwl1[iqu];
|
||||
idwl2 = p_idwl2[iqu];
|
||||
idsp = ga_idsp_ldac[iqu];
|
||||
nbits_fix += gaa_ndim_wls_ldac[idsp][idwl1] + ga_wl_ldac[idwl2] * ga_nsps_ldac[iqu];
|
||||
tmp = p_idsf[iqu] + p_grad[iqu] + p_addwl[iqu];
|
||||
if (tmp > 0) {
|
||||
tmp = tmp >> 2;
|
||||
}
|
||||
if (tmp < LDAC_MINIDWL1) {
|
||||
tmp = LDAC_MINIDWL1;
|
||||
}
|
||||
p_tmp[iqu] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nbits_fix = *p_nbits_spec - nbits_fix;
|
||||
nbits_spec = nbits_fix + encode_audio_block_b_ldac(p_ab, nadjqus);
|
||||
ncalls++;
|
||||
|
||||
while (step > 1) {
|
||||
step >>= 1;
|
||||
|
||||
if (nbits_spec < nbits_avail) {
|
||||
nadjqus += step;
|
||||
if (nadjqus > p_ab->nqus) {
|
||||
nadjqus = p_ab->nqus;
|
||||
}
|
||||
}
|
||||
else if (nbits_spec > nbits_avail) {
|
||||
nadjqus -= step;
|
||||
}
|
||||
else {
|
||||
if (nadjqus > p_ab->nqus) {
|
||||
nadjqus = p_ab->nqus;
|
||||
}
|
||||
break;
|
||||
}
|
||||
nbits_spec = nbits_fix + encode_audio_block_b_ldac(p_ab, nadjqus);
|
||||
ncalls++;
|
||||
}
|
||||
|
||||
if (nbits_spec > nbits_avail) {
|
||||
nadjqus--;
|
||||
nbits_spec = nbits_fix + encode_audio_block_b_ldac(p_ab, nadjqus);
|
||||
ncalls++;
|
||||
}
|
||||
*p_nadjqus = nadjqus;
|
||||
*p_nbits_spec = nbits_spec;
|
||||
|
||||
return ncalls;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Allocate Bits
|
||||
***************************************************************************************************/
|
||||
#define LDAC_UPPER_NOISE_LEVEL 20
|
||||
#define LDAC_LOWER_NOISE_LEVEL 5
|
||||
|
||||
DECLFUNC int alloc_bits_ldac(
|
||||
AB *p_ab)
|
||||
{
|
||||
int nbits_avail, nbits_side = 0, nbits_spec = 0;
|
||||
int nbits_ab = p_ab->nbits_ab;
|
||||
|
||||
nbits_side = encode_side_info_ldac(p_ab);
|
||||
p_ab->nbits_avail = nbits_avail = nbits_ab - nbits_side;
|
||||
|
||||
nbits_spec = encode_audio_block_a_ldac(p_ab, p_ab->nqus);
|
||||
|
||||
if (nbits_spec > nbits_avail) {
|
||||
if (p_ab->grad_mode == LDAC_MODE_0) {
|
||||
decrease_offset_low_ldac(p_ab, LDAC_UPPER_NOISE_LEVEL, &nbits_spec);
|
||||
|
||||
decrease_offset_high_ldac(p_ab, &nbits_spec);
|
||||
|
||||
decrease_offset_low_ldac(p_ab, LDAC_MAXGRADOS, &nbits_spec);
|
||||
}
|
||||
else {
|
||||
decrease_offset_low_ldac(p_ab, LDAC_MAXGRADOS, &nbits_spec);
|
||||
}
|
||||
|
||||
while ((nbits_spec > nbits_avail) && (p_ab->nbands > LDAC_BAND_OFFSET)) {
|
||||
p_ab->nbands--;
|
||||
p_ab->nqus = ga_nqus_ldac[p_ab->nbands];
|
||||
|
||||
nbits_side = encode_side_info_ldac(p_ab);
|
||||
p_ab->nbits_avail = nbits_avail = nbits_ab - nbits_side;
|
||||
|
||||
nbits_spec = encode_audio_block_a_ldac(p_ab, p_ab->nqus);
|
||||
}
|
||||
}
|
||||
|
||||
if (nbits_spec < nbits_avail) {
|
||||
if (p_ab->grad_mode == LDAC_MODE_0) {
|
||||
increase_offset_low_ldac(p_ab, &nbits_spec);
|
||||
|
||||
increase_qu_low_0_ldac(p_ab, &nbits_spec);
|
||||
}
|
||||
else {
|
||||
increase_offset_low_ldac(p_ab, &nbits_spec);
|
||||
|
||||
increase_qu_low_ldac(p_ab, &nbits_spec);
|
||||
}
|
||||
}
|
||||
|
||||
p_ab->nadjqus = 0;
|
||||
adjust_remain_bits_ldac(p_ab, &nbits_spec, &p_ab->nadjqus);
|
||||
|
||||
if (nbits_spec > nbits_avail) {
|
||||
*p_ab->p_error_code = LDAC_ERR_BIT_ALLOCATION;
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
p_ab->nbits_spec = nbits_spec;
|
||||
p_ab->nbits_used = nbits_spec + nbits_side;
|
||||
|
||||
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,339 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2017 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Bits for Band Info
|
||||
***************************************************************************************************/
|
||||
static int encode_band_info_ldac(
|
||||
__attribute__((unused)) AB *p_ab)
|
||||
{
|
||||
int nbits;
|
||||
|
||||
nbits = LDAC_NBANDBITS + LDAC_FLAGBITS;
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Bits for Gradient Data
|
||||
***************************************************************************************************/
|
||||
static int encode_gradient_ldac(
|
||||
AB *p_ab)
|
||||
{
|
||||
int nbits;
|
||||
|
||||
if (p_ab->grad_mode == LDAC_MODE_0) {
|
||||
nbits = LDAC_GRADMODEBITS + LDAC_GRADQU0BITS*2 + LDAC_GRADOSBITS*2 + LDAC_NADJQUBITS;
|
||||
}
|
||||
else {
|
||||
nbits = LDAC_GRADMODEBITS + LDAC_GRADQU1BITS + LDAC_GRADOSBITS + LDAC_NADJQUBITS;
|
||||
}
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Get Index of Minimum Value
|
||||
***************************************************************************************************/
|
||||
__inline static int get_minimum_id_ldac(
|
||||
int *p_nbits,
|
||||
int n)
|
||||
{
|
||||
int i;
|
||||
int id, nbits;
|
||||
|
||||
id = 0;
|
||||
nbits = p_nbits[0];
|
||||
|
||||
for (i = 1; i < n; i++) {
|
||||
if (nbits > p_nbits[i]) {
|
||||
id = i;
|
||||
nbits = p_nbits[i];
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int bitlen;
|
||||
int offset;
|
||||
int weight;
|
||||
} SFCINF;
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Calculate Bits for Scale Factor Data - Mode 0
|
||||
***************************************************************************************************/
|
||||
static const unsigned char sa_bitlen_maxdif_0_ldac[LDAC_NIDSF] = {
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
};
|
||||
|
||||
static int encode_scale_factor_0_ldac(
|
||||
AC *p_ac,
|
||||
SFCINF *p_sfcinf)
|
||||
{
|
||||
HCENC *p_hcsf;
|
||||
int iqu, iwt;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int nbits = LDAC_MAXBITNUM;
|
||||
int bitlen, vmin, vmax, val0, val1;
|
||||
int *p_idsf = p_ac->a_idsf;
|
||||
int *p_idsf_dif = p_ac->a_tmp;
|
||||
const unsigned char *p_tbl;
|
||||
|
||||
for (iwt = 0; iwt < LDAC_NSFCWTBL; iwt++) {
|
||||
p_tbl = gaa_sfcwgt_ldac[iwt];
|
||||
vmin = vmax = val0 = p_idsf[0] + p_tbl[0];
|
||||
for (iqu = 1; iqu < nqus; iqu++) {
|
||||
val1 = p_idsf[iqu] + p_tbl[iqu];
|
||||
if (vmin > val1) {
|
||||
vmin = val1;
|
||||
}
|
||||
if (vmax < val1) {
|
||||
vmax = val1;
|
||||
}
|
||||
p_idsf_dif[iqu] = val1 - val0;
|
||||
val0 = val1;
|
||||
}
|
||||
|
||||
val1 = bitlen = sa_bitlen_maxdif_0_ldac[(vmax-vmin)>>1];
|
||||
p_hcsf = ga_hcenc_sf0_ldac + (bitlen-LDAC_MINSFCBLEN_0);
|
||||
for (iqu = 1; iqu < nqus; iqu++) {
|
||||
val0 = p_idsf_dif[iqu] & p_hcsf->mask;
|
||||
val1 += hc_len_ldac(p_hcsf->p_tbl+val0);
|
||||
}
|
||||
|
||||
if (nbits > val1) {
|
||||
p_sfcinf->bitlen = bitlen;
|
||||
p_sfcinf->offset = vmin;
|
||||
p_sfcinf->weight = iwt;
|
||||
nbits = val1;
|
||||
}
|
||||
}
|
||||
nbits += LDAC_SFCBLENBITS + LDAC_IDSFBITS + LDAC_SFCWTBLBITS;
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Calculate Bits for Scale Factor Data - Mode 1
|
||||
***************************************************************************************************/
|
||||
static const unsigned char sa_bitlen_maxdif_1_ldac[LDAC_NIDSF] = {
|
||||
2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
};
|
||||
|
||||
static int encode_scale_factor_1_ldac(
|
||||
AC *p_ac,
|
||||
SFCINF *p_sfcinf)
|
||||
{
|
||||
int iqu, iwt;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int nbits = LDAC_MAXBITNUM;
|
||||
int bitlen, vmin, vmax, val;
|
||||
int *p_idsf = p_ac->a_idsf;
|
||||
const unsigned char *p_tbl;
|
||||
|
||||
for (iwt = 0; iwt < LDAC_NSFCWTBL; iwt++) {
|
||||
p_tbl = gaa_sfcwgt_ldac[iwt];
|
||||
vmin = vmax = p_idsf[0] + p_tbl[0];
|
||||
for (iqu = 1; iqu < nqus; iqu++) {
|
||||
val = p_idsf[iqu] + p_tbl[iqu];
|
||||
if (vmin > val) {
|
||||
vmin = val;
|
||||
}
|
||||
if (vmax < val) {
|
||||
vmax = val;
|
||||
}
|
||||
}
|
||||
|
||||
bitlen = sa_bitlen_maxdif_1_ldac[(vmax-vmin)>>1];
|
||||
if (bitlen > 4) {
|
||||
val = LDAC_SFCBLENBITS;
|
||||
}
|
||||
else {
|
||||
val = LDAC_SFCBLENBITS + LDAC_IDSFBITS + LDAC_SFCWTBLBITS;
|
||||
}
|
||||
val += bitlen * nqus;
|
||||
|
||||
if (nbits > val) {
|
||||
p_sfcinf->bitlen = bitlen;
|
||||
p_sfcinf->offset = vmin;
|
||||
p_sfcinf->weight = iwt;
|
||||
nbits = val;
|
||||
}
|
||||
}
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Calculate Bits for Scale Factor Data - Mode 2
|
||||
***************************************************************************************************/
|
||||
static const unsigned char sa_bitlen_absmax_2_ldac[LDAC_NIDSF>>1] = {
|
||||
2, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
};
|
||||
|
||||
static int encode_scale_factor_2_ldac(
|
||||
AC *p_ac,
|
||||
SFCINF *p_sfcinf)
|
||||
{
|
||||
HCENC *p_hcsf;
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int nbits, bitlen, vmax, val;
|
||||
int *p_idsf_dif = p_ac->a_tmp;
|
||||
|
||||
p_idsf_dif[0] = p_ac->a_idsf[0] - p_ac->p_ab->ap_ac[0]->a_idsf[0];
|
||||
vmax = abs(p_idsf_dif[0]);
|
||||
for (iqu = 1; iqu < nqus; iqu++) {
|
||||
p_idsf_dif[iqu] = p_ac->a_idsf[iqu] - p_ac->p_ab->ap_ac[0]->a_idsf[iqu];
|
||||
val = abs(p_idsf_dif[iqu]);
|
||||
if (vmax < val) {
|
||||
vmax = val;
|
||||
}
|
||||
}
|
||||
|
||||
nbits = LDAC_SFCBLENBITS;
|
||||
bitlen = sa_bitlen_absmax_2_ldac[vmax>>1];
|
||||
p_hcsf = ga_hcenc_sf1_ldac + (bitlen-LDAC_MINSFCBLEN_2);
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
val = p_idsf_dif[iqu] & p_hcsf->mask;
|
||||
nbits += hc_len_ldac(p_hcsf->p_tbl+val);
|
||||
}
|
||||
|
||||
p_sfcinf->bitlen = bitlen;
|
||||
p_sfcinf->offset = 0;
|
||||
p_sfcinf->weight = 0;
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Bits for Scale Factor Data
|
||||
***************************************************************************************************/
|
||||
static int encode_scale_factor_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
SFCINF a_sfcinf[LDAC_NSFCMODE];
|
||||
SFCINF *p_sfcinf;
|
||||
int nbits, sfc_mode;
|
||||
int a_nbits[LDAC_NSFCMODE];
|
||||
|
||||
if (p_ac->ich == 0) {
|
||||
a_nbits[LDAC_MODE_0] = encode_scale_factor_0_ldac(p_ac, a_sfcinf+LDAC_MODE_0);
|
||||
a_nbits[LDAC_MODE_1] = encode_scale_factor_1_ldac(p_ac, a_sfcinf+LDAC_MODE_1);
|
||||
}
|
||||
else {
|
||||
a_nbits[LDAC_MODE_0] = encode_scale_factor_0_ldac(p_ac, a_sfcinf+LDAC_MODE_0);
|
||||
a_nbits[LDAC_MODE_1] = encode_scale_factor_2_ldac(p_ac, a_sfcinf+LDAC_MODE_1);
|
||||
}
|
||||
|
||||
p_ac->sfc_mode = sfc_mode = get_minimum_id_ldac(a_nbits, LDAC_MODE_1+1);
|
||||
p_sfcinf = a_sfcinf + sfc_mode;
|
||||
p_ac->sfc_bitlen = p_sfcinf->bitlen;
|
||||
p_ac->sfc_offset = p_sfcinf->offset;
|
||||
p_ac->sfc_weight = p_sfcinf->weight;
|
||||
nbits = a_nbits[sfc_mode] + LDAC_SFCMODEBITS;
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Bits for Side Information (Band Info, Gradient Data & Scale Factor Data)
|
||||
***************************************************************************************************/
|
||||
DECLFUNC int encode_side_info_ldac(
|
||||
AB *p_ab)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich;
|
||||
int nchs = p_ab->blk_nchs;
|
||||
int nbits, nbits_band, nbits_grad, nbits_scfc = 0;
|
||||
|
||||
p_ab->nbits_band = nbits_band = encode_band_info_ldac(p_ab);
|
||||
p_ab->nbits_grad = nbits_grad = encode_gradient_ldac(p_ab);
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_ab->ap_ac[ich];
|
||||
nbits_scfc += encode_scale_factor_ldac(p_ac);
|
||||
calc_add_word_length_ldac(p_ac);
|
||||
}
|
||||
p_ab->nbits_scfc = nbits_scfc;
|
||||
|
||||
nbits = nbits_band + nbits_grad + nbits_scfc;
|
||||
|
||||
return nbits;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Additional Word Length Data
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void calc_add_word_length_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int dif;
|
||||
int *p_idsf = p_ac->a_idsf;
|
||||
int *p_addwl = p_ac->a_addwl;
|
||||
|
||||
clear_data_ldac(p_addwl, LDAC_MAXNQUS*sizeof(int));
|
||||
|
||||
if (p_ac->p_ab->grad_mode != LDAC_MODE_0) {
|
||||
for (iqu = 1; iqu < nqus; iqu++) {
|
||||
dif = p_idsf[iqu] - p_idsf[iqu-1];
|
||||
|
||||
if (dif > 0) {
|
||||
if (dif > 5) {
|
||||
p_addwl[iqu] += 5;
|
||||
}
|
||||
else if (dif > 4) {
|
||||
p_addwl[iqu] += 4;
|
||||
}
|
||||
else if (dif > 3) {
|
||||
p_addwl[iqu] += 3;
|
||||
}
|
||||
else if (dif > 2) {
|
||||
p_addwl[iqu] += 2;
|
||||
}
|
||||
else if (dif > 1) {
|
||||
p_addwl[iqu] += 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (dif < -5) {
|
||||
p_addwl[iqu-1] += 5;
|
||||
}
|
||||
else if (dif < -4) {
|
||||
p_addwl[iqu-1] += 4;
|
||||
}
|
||||
else if (dif < -3) {
|
||||
p_addwl[iqu-1] += 3;
|
||||
}
|
||||
else if (dif < -2) {
|
||||
p_addwl[iqu-1] += 2;
|
||||
}
|
||||
else if (dif < -1) {
|
||||
p_addwl[iqu-1] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,237 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Allocate Memory
|
||||
***************************************************************************************************/
|
||||
static LDAC_RESULT alloc_encode_ldac(
|
||||
SFINFO *p_sfinfo)
|
||||
{
|
||||
LDAC_RESULT result = LDAC_S_OK;
|
||||
CFG *p_cfg = &p_sfinfo->cfg;
|
||||
int ich;
|
||||
int nchs = p_cfg->ch;
|
||||
int nbks = gaa_block_setting_ldac[p_cfg->chconfig_id][1];
|
||||
|
||||
/* Allocate AC */
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_sfinfo->ap_ac[ich] = (AC *)calloc_ldac(p_sfinfo, 1, sizeof(AC));
|
||||
if (p_sfinfo->ap_ac[ich] != (AC *)NULL) {
|
||||
p_sfinfo->ap_ac[ich]->p_acsub = (ACSUB *)calloc_ldac(p_sfinfo, 1, sizeof(ACSUB));
|
||||
if (p_sfinfo->ap_ac[ich]->p_acsub == (ACSUB *)NULL) {
|
||||
result = LDAC_E_FAIL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = LDAC_E_FAIL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != LDAC_S_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Allocate AB */
|
||||
p_sfinfo->p_ab = (AB *)calloc_ldac(p_sfinfo, nbks, sizeof(AB));
|
||||
if (p_sfinfo->p_ab == (AB *)NULL) {
|
||||
result = LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Initialize Memory
|
||||
***************************************************************************************************/
|
||||
DECLFUNC LDAC_RESULT init_encode_ldac(
|
||||
SFINFO *p_sfinfo)
|
||||
{
|
||||
LDAC_RESULT result = LDAC_S_OK;
|
||||
CFG *p_cfg = &p_sfinfo->cfg;
|
||||
AB *p_ab;
|
||||
int ibk, ich;
|
||||
int blk_type, blk_nchs;
|
||||
int ch_offset = 0;
|
||||
int chconfig_id = p_cfg->chconfig_id;
|
||||
int nbks = gaa_block_setting_ldac[chconfig_id][1];
|
||||
|
||||
if (alloc_encode_ldac(p_sfinfo) == LDAC_E_FAIL) {
|
||||
p_sfinfo->error_code = LDAC_ERR_ALLOC_MEMORY;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
p_sfinfo->error_code = LDAC_ERR_NONE;
|
||||
p_cfg->frame_status = LDAC_FRMSTAT_LEV_0;
|
||||
|
||||
/* Set AB information */
|
||||
p_ab = p_sfinfo->p_ab;
|
||||
for (ibk = 0; ibk < nbks; ibk++){
|
||||
p_ab->blk_type = blk_type = gaa_block_setting_ldac[chconfig_id][ibk+2];
|
||||
p_ab->blk_nchs = blk_nchs = get_block_nchs_ldac(blk_type);
|
||||
p_ab->p_smplrate_id = &p_cfg->smplrate_id;
|
||||
p_ab->p_error_code = &p_sfinfo->error_code;
|
||||
|
||||
/* Set AC Information */
|
||||
for (ich = 0; ich < blk_nchs; ich++) {
|
||||
p_ab->ap_ac[ich] = p_sfinfo->ap_ac[ch_offset++];
|
||||
p_ab->ap_ac[ich]->p_ab = p_ab;
|
||||
p_ab->ap_ac[ich]->ich = ich;
|
||||
p_ab->ap_ac[ich]->frmana_cnt = 0;
|
||||
}
|
||||
|
||||
p_ab++;
|
||||
}
|
||||
|
||||
calc_initial_bits_ldac(p_sfinfo);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Initial Bits
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void calc_initial_bits_ldac(
|
||||
SFINFO *p_sfinfo)
|
||||
{
|
||||
CFG *p_cfg = &p_sfinfo->cfg;
|
||||
AB *p_ab = p_sfinfo->p_ab;
|
||||
int ibk;
|
||||
int blk_type;
|
||||
int nbits_ab, nbits_ac;
|
||||
int chconfig_id = p_cfg->chconfig_id;
|
||||
int nbks = gaa_block_setting_ldac[chconfig_id][1];
|
||||
|
||||
nbits_ac = p_cfg->frame_length * LDAC_BYTESIZE / p_cfg->ch;
|
||||
|
||||
for (ibk = 0; ibk < nbks; ibk++){
|
||||
blk_type = gaa_block_setting_ldac[chconfig_id][ibk+2];
|
||||
|
||||
if (blk_type == LDAC_BLKID_STEREO){
|
||||
nbits_ab = (nbits_ac * 2 / LDAC_BYTESIZE) * LDAC_BYTESIZE;
|
||||
}
|
||||
else{
|
||||
nbits_ab = (nbits_ac / LDAC_BYTESIZE) * LDAC_BYTESIZE;
|
||||
}
|
||||
p_ab->nbits_ab = nbits_ab;
|
||||
|
||||
p_ab++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Free Memory
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void free_encode_ldac(
|
||||
SFINFO *p_sfinfo)
|
||||
{
|
||||
int ich;
|
||||
int nchs = p_sfinfo->cfg.ch;
|
||||
|
||||
/* Free AB */
|
||||
if (p_sfinfo->p_ab != (AB *)NULL) {
|
||||
free(p_sfinfo->p_ab);
|
||||
p_sfinfo->p_ab = (AB *)NULL;
|
||||
}
|
||||
|
||||
/* Free AC */
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
if (p_sfinfo->ap_ac[ich] != (AC *)NULL) {
|
||||
if (p_sfinfo->ap_ac[ich]->p_acsub != (ACSUB *)NULL) {
|
||||
free(p_sfinfo->ap_ac[ich]->p_acsub);
|
||||
p_sfinfo->ap_ac[ich]->p_acsub = (ACSUB *)NULL;
|
||||
}
|
||||
free(p_sfinfo->ap_ac[ich]);
|
||||
p_sfinfo->ap_ac[ich] = (AC *)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Encode Audio Block
|
||||
***************************************************************************************************/
|
||||
static int encode_audio_block_ldac(
|
||||
AB *p_ab)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich;
|
||||
int nchs = p_ab->blk_nchs;
|
||||
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_ab->ap_ac[ich];
|
||||
|
||||
norm_spectrum_ldac(p_ac);
|
||||
}
|
||||
|
||||
if (!alloc_bits_ldac(p_ab)) {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_ab->ap_ac[ich];
|
||||
|
||||
quant_spectrum_ldac(p_ac);
|
||||
|
||||
quant_residual_ldac(p_ac);
|
||||
}
|
||||
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Encode
|
||||
***************************************************************************************************/
|
||||
DECLFUNC int encode_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
int nbands,
|
||||
int grad_mode,
|
||||
int grad_qu_l,
|
||||
int grad_qu_h,
|
||||
int grad_os_l,
|
||||
int grad_os_h,
|
||||
int abc_status)
|
||||
{
|
||||
AB *p_ab = p_sfinfo->p_ab;
|
||||
int ibk;
|
||||
int nbks = gaa_block_setting_ldac[p_sfinfo->cfg.chconfig_id][1];
|
||||
|
||||
for (ibk = 0; ibk < nbks; ibk++){
|
||||
p_ab->nbands = nbands;
|
||||
p_ab->nqus = ga_nqus_ldac[nbands];
|
||||
p_ab->grad_mode = grad_mode;
|
||||
p_ab->grad_qu_l = grad_qu_l;
|
||||
p_ab->grad_qu_h = grad_qu_h;
|
||||
p_ab->grad_os_l = grad_os_l;
|
||||
p_ab->grad_os_h = grad_os_h;
|
||||
p_ab->abc_status = abc_status;
|
||||
|
||||
if (!encode_audio_block_ldac(p_ab)) {
|
||||
return LDAC_ERR_NON_FATAL_ENCODE;
|
||||
}
|
||||
|
||||
p_ab++;
|
||||
}
|
||||
|
||||
return LDAC_ERR_NONE;
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _FIXP_LDAC_H
|
||||
#define _FIXP_LDAC_H
|
||||
|
||||
/***************************************************************************************************
|
||||
Macro Definitions
|
||||
***************************************************************************************************/
|
||||
|
||||
#define LDAC_MAX_32BIT ((INT32)0x7fffffffL)
|
||||
#define LDAC_MIN_32BIT ((INT32)0x80000000L)
|
||||
|
||||
#define LDAC_C_BLKFLT 31
|
||||
|
||||
#define LDAC_Q_SETPCM 15
|
||||
|
||||
#define LDAC_Q_MDCT_WIN 30
|
||||
#define LDAC_Q_MDCT_COS 31
|
||||
#define LDAC_Q_MDCT_SIN 31
|
||||
|
||||
#define LDAC_Q_NORM1 15
|
||||
#define LDAC_Q_NORM2 31
|
||||
|
||||
#define LDAC_Q_QUANT1 47
|
||||
#define LDAC_Q_QUANT2 0
|
||||
#define LDAC_Q_QUANT3 15
|
||||
#define LDAC_Q_QUANT4 47
|
||||
|
||||
#define LDAC_Q_DEQUANT1 0
|
||||
#define LDAC_Q_DEQUANT2 0
|
||||
#define LDAC_Q_DEQUANT3 31
|
||||
|
||||
#define LDAC_Q_NORM (15+(LDAC_Q_NORM2-LDAC_Q_NORM1))
|
||||
|
||||
/***************************************************************************************************
|
||||
Function Declarations
|
||||
***************************************************************************************************/
|
||||
/* func_fixp_ldac.c */
|
||||
DECLFUNC INT32 sftrnd_ldac(INT32, int);
|
||||
#define lsft_ldac(x, n) ((x) << (n))
|
||||
#define rsft_ldac(x, n) ((x) >> (n))
|
||||
#define rsft_ro_ldac(x, n) (((x) + (1 << (n-1))) >> (n))
|
||||
|
||||
#define lsftrnd_ldac(x, n) (INT32)((INT64)(x) << (-(n)))
|
||||
#define rsftrnd_ldac(x, n) (INT32)(((INT64)(x) + ((INT64)1 << ((n)-1))) >> (n))
|
||||
#define mul_lsftrnd_ldac(x, y, n) (INT32)(((INT64)(x) * (INT64)(y)) << (-(n)))
|
||||
#define mul_rsftrnd_ldac(x, y, n) (INT32)((((INT64)(x) * (INT64)(y)) + ((INT64)1 << ((n)-1))) >> (n))
|
||||
|
||||
DECLFUNC int get_bit_length_ldac(INT32);
|
||||
DECLFUNC INT32 get_absmax_ldac(INT32 *, int);
|
||||
|
||||
#endif /* _FIXP_LDAC_H */
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Subfunction: Check Saturation
|
||||
*******************************************************************************/
|
||||
__inline static INT32 check_sature_ldac(
|
||||
INT64 val)
|
||||
{
|
||||
|
||||
return (INT32)val;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
Shift and Round
|
||||
*******************************************************************************/
|
||||
DECLFUNC INT32 sftrnd_ldac(
|
||||
INT32 in,
|
||||
int shift)
|
||||
{
|
||||
INT64 out;
|
||||
|
||||
if (shift > 0) {
|
||||
out = ((INT64)in + ((INT64)1 << (shift-1))) >> shift;
|
||||
}
|
||||
else {
|
||||
out = (INT64)in << (-shift);
|
||||
}
|
||||
|
||||
return check_sature_ldac(out);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Get Bit Length of Value
|
||||
*******************************************************************************/
|
||||
DECLFUNC int get_bit_length_ldac(
|
||||
INT32 val)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
while (val > 0) {
|
||||
val >>= 1;
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
Get Maximum Absolute Value
|
||||
*******************************************************************************/
|
||||
DECLFUNC INT32 get_absmax_ldac(
|
||||
INT32 *p_x,
|
||||
int num)
|
||||
{
|
||||
int i;
|
||||
INT32 abmax, val;
|
||||
|
||||
abmax = abs(p_x[0]);
|
||||
for (i = 1; i < num; i++) {
|
||||
val = abs(p_x[i]);
|
||||
if (abmax < val) {
|
||||
abmax = val;
|
||||
}
|
||||
}
|
||||
|
||||
return abmax;
|
||||
}
|
||||
|
|
@ -0,0 +1,292 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LDAC_H
|
||||
#define _LDAC_H
|
||||
|
||||
#include "ldaclib.h"
|
||||
#include "struct_ldac.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Macro Definitions
|
||||
***************************************************************************************************/
|
||||
/* Configuration */
|
||||
#define LDAC_SYNCWORDBITS 8
|
||||
#define LDAC_SYNCWORD 0xAA
|
||||
/** Sampling Rate **/
|
||||
#define LDAC_SMPLRATEBITS 3
|
||||
#define LDAC_NSMPLRATEID 6
|
||||
#define LDAC_NSUPSMPLRATEID 4
|
||||
#define LDAC_SMPLRATEID_0 0x0
|
||||
#define LDAC_SMPLRATEID_1 0x1
|
||||
#define LDAC_SMPLRATEID_2 0x2
|
||||
#define LDAC_SMPLRATEID_3 0x3
|
||||
/** Channel **/
|
||||
#define LDAC_CHCONFIG1BITS 3
|
||||
#define LDAC_CHCONFIG2BITS 2
|
||||
#define LDAC_NCHCONFIGID 8
|
||||
#define LDAC_MAXNCH 2
|
||||
#define LDAC_CHANNEL_1CH 1
|
||||
#define LDAC_CHANNEL_2CH 2
|
||||
#define LDAC_CHCONFIGID_MN 0
|
||||
#define LDAC_CHCONFIGID_DL 1
|
||||
#define LDAC_CHCONFIGID_ST 2
|
||||
/** Frame Length **/
|
||||
#define LDAC_FRAMELEN1BITS 11
|
||||
#define LDAC_FRAMELEN2BITS 9
|
||||
#define LDAC_MAXNBYTES 1024
|
||||
#define LDAC_MAXSUPNBYTES 512
|
||||
#define LDAC_MINSUPNBYTES 22
|
||||
/** Frame Status **/
|
||||
#define LDAC_FRAMESTATBITS 2
|
||||
#define LDAC_FRMSTAT_LEV_0 0
|
||||
#define LDAC_FRMSTAT_LEV_1 1
|
||||
#define LDAC_FRMSTAT_LEV_2 2
|
||||
#define LDAC_FRMSTAT_LEV_3 3
|
||||
/** Other **/
|
||||
#define LDAC_RESERVE1BITS 2
|
||||
#define LDAC_RESERVE2BITS 5
|
||||
#define LDAC_DUMMYCODE 0x00
|
||||
|
||||
/* Signal Processing */
|
||||
#define LDAC_NFRAME 2
|
||||
#define LDAC_NSFTSTEP 5
|
||||
/** Frame Samples (log base 2 of) **/
|
||||
#define LDAC_NUMLNN 2
|
||||
#define LDAC_MAXLNN 8
|
||||
#define LDAC_2FSLNN 8
|
||||
#define LDAC_1FSLNN 7
|
||||
/** Frame Samples **/
|
||||
#define LDAC_MAXLSU (1<<LDAC_MAXLNN)
|
||||
#define LDAC_2FSLSU (1<<LDAC_2FSLNN)
|
||||
#define LDAC_1FSLSU (1<<LDAC_1FSLNN)
|
||||
/** Band **/
|
||||
#define LDAC_MAXNBANDS 16
|
||||
#define LDAC_2FSNBANDS 16
|
||||
#define LDAC_1FSNBANDS 12
|
||||
/** QU **/
|
||||
#define LDAC_MAXGRADQU 50
|
||||
#define LDAC_MAXNQUS 34
|
||||
#define LDAC_2FSNQUS 34
|
||||
#define LDAC_1FSNQUS 26
|
||||
#define LDAC_MAXNSPS 16
|
||||
/** Frame Status Analysis **/
|
||||
#define LDAC_NSP_PSEUDOANA 128
|
||||
#define LDAC_NSP_LOWENERGY 12
|
||||
#define LDAC_TH_ZCROSNUM 90
|
||||
#define LDAC_MAXCNT_FRMANA 10
|
||||
|
||||
/* Stream Syntax */
|
||||
#define LDAC_BLKID_MONO 0
|
||||
#define LDAC_BLKID_STEREO 1
|
||||
#define LDAC_FILLCODE 0x01
|
||||
/** Band Info **/
|
||||
#define LDAC_NBANDBITS 4
|
||||
#define LDAC_BAND_OFFSET 2
|
||||
/** Gradient Data **/
|
||||
#define LDAC_GRADMODEBITS 2
|
||||
#define LDAC_GRADOSBITS 5
|
||||
#define LDAC_MAXGRADOS 31
|
||||
#define LDAC_DEFGRADOSH 31
|
||||
#define LDAC_GRADQU0BITS 6
|
||||
#define LDAC_GRADQU1BITS 5
|
||||
#define LDAC_DEFGRADQUH 26
|
||||
#define LDAC_NADJQUBITS 5
|
||||
#define LDAC_MAXNADJQUS 32
|
||||
/** Scale Factor Data **/
|
||||
#define LDAC_IDSFBITS 5
|
||||
#define LDAC_NIDSF 32
|
||||
#define LDAC_SFCMODEBITS 1
|
||||
#define LDAC_NSFCMODE 2
|
||||
#define LDAC_SFCWTBLBITS 3
|
||||
#define LDAC_NSFCWTBL 8
|
||||
#define LDAC_SFCBLENBITS 2
|
||||
#define LDAC_MINSFCBLEN_0 3
|
||||
#define LDAC_MAXSFCBLEN_0 6
|
||||
#define LDAC_MINSFCBLEN_1 2
|
||||
#define LDAC_MAXSFCBLEN_1 5
|
||||
#define LDAC_MINSFCBLEN_2 2
|
||||
#define LDAC_MAXSFCBLEN_2 5
|
||||
/** Spectrum/Residual Data **/
|
||||
#define LDAC_NIDWL 16
|
||||
#define LDAC_MINIDWL1 1
|
||||
#define LDAC_MAXIDWL1 15
|
||||
#define LDAC_MAXIDWL2 15
|
||||
#define LDAC_2DIMSPECBITS 3
|
||||
#define LDAC_N2DIMSPECENCTBL 16
|
||||
#define LDAC_N2DIMSPECDECTBL 8
|
||||
#define LDAC_4DIMSPECBITS 7
|
||||
#define LDAC_N4DIMSPECENCTBL 256
|
||||
#define LDAC_N4DIMSPECDECTBL 81
|
||||
/** Bit Operation **/
|
||||
#define LDAC_LOC_SHIFT 3
|
||||
#define LDAC_LOC_MASK 0x7
|
||||
#define LDAC_BYTESIZE 8
|
||||
#define LDAC_MAXBITNUM 8192
|
||||
|
||||
/* Flag */
|
||||
#define LDAC_FLAGBITS 1
|
||||
#define LDAC_TRUE 1
|
||||
#define LDAC_FALSE 0
|
||||
|
||||
/* Mode */
|
||||
#define LDAC_MODE_0 0
|
||||
#define LDAC_MODE_1 1
|
||||
#define LDAC_MODE_2 2
|
||||
#define LDAC_MODE_3 3
|
||||
|
||||
/***************************************************************************************************
|
||||
Structure Definitions
|
||||
***************************************************************************************************/
|
||||
typedef struct _sfinfo_ldac SFINFO;
|
||||
typedef struct _config_info_ldac CFG;
|
||||
typedef struct _audio_block_ldac AB;
|
||||
typedef struct _audio_channel_ldac AC;
|
||||
typedef struct _audio_channel_sub_ldac ACSUB;
|
||||
|
||||
/* Configuration Information Structure */
|
||||
struct _config_info_ldac {
|
||||
int syncword;
|
||||
int smplrate_id;
|
||||
int chconfig_id;
|
||||
int ch;
|
||||
int frame_length;
|
||||
int frame_status;
|
||||
};
|
||||
|
||||
/* Audio Channel (AC) Sub Structure */
|
||||
#ifndef _32BIT_FIXED_POINT
|
||||
struct _audio_channel_sub_ldac {
|
||||
SCALAR a_time[LDAC_MAXLSU*LDAC_NFRAME];
|
||||
SCALAR a_spec[LDAC_MAXLSU];
|
||||
};
|
||||
#else /* _32BIT_FIXED_POINT */
|
||||
struct _audio_channel_sub_ldac {
|
||||
INT32 a_time[LDAC_MAXLSU*LDAC_NFRAME];
|
||||
INT32 a_spec[LDAC_MAXLSU];
|
||||
};
|
||||
#endif /* _32BIT_FIXED_POINT */
|
||||
|
||||
/* Audio Channel (AC) Structure */
|
||||
struct _audio_channel_ldac {
|
||||
int ich;
|
||||
int frmana_cnt;
|
||||
int sfc_mode;
|
||||
int sfc_bitlen;
|
||||
int sfc_offset;
|
||||
int sfc_weight;
|
||||
int a_idsf[LDAC_MAXNQUS];
|
||||
int a_idwl1[LDAC_MAXNQUS];
|
||||
int a_idwl2[LDAC_MAXNQUS];
|
||||
int a_addwl[LDAC_MAXNQUS];
|
||||
int a_tmp[LDAC_MAXNQUS];
|
||||
int a_qspec[LDAC_MAXLSU];
|
||||
int a_rspec[LDAC_MAXLSU];
|
||||
AB *p_ab;
|
||||
ACSUB *p_acsub;
|
||||
};
|
||||
|
||||
/* Audio Block (AB) Structure */
|
||||
struct _audio_block_ldac {
|
||||
int blk_type;
|
||||
int blk_nchs;
|
||||
int nbands;
|
||||
int nqus;
|
||||
int grad_mode;
|
||||
int grad_qu_l;
|
||||
int grad_qu_h;
|
||||
int grad_os_l;
|
||||
int grad_os_h;
|
||||
int a_grad[LDAC_MAXGRADQU];
|
||||
int nadjqus;
|
||||
int abc_status;
|
||||
int nbits_ab;
|
||||
int nbits_band;
|
||||
int nbits_grad;
|
||||
int nbits_scfc;
|
||||
int nbits_spec;
|
||||
int nbits_avail;
|
||||
int nbits_used;
|
||||
int *p_smplrate_id;
|
||||
int *p_error_code;
|
||||
AC *ap_ac[2];
|
||||
};
|
||||
|
||||
/* Sound Frame Structure */
|
||||
struct _sfinfo_ldac {
|
||||
CFG cfg;
|
||||
AB *p_ab;
|
||||
AC *ap_ac[LDAC_MAXNCH];
|
||||
char *p_mempos;
|
||||
int error_code;
|
||||
};
|
||||
|
||||
/* LDAC Handle */
|
||||
typedef struct _handle_ldac_struct {
|
||||
int nlnn;
|
||||
int nbands;
|
||||
int grad_mode;
|
||||
int grad_qu_l;
|
||||
int grad_qu_h;
|
||||
int grad_os_l;
|
||||
int grad_os_h;
|
||||
int abc_status;
|
||||
int error_code;
|
||||
SFINFO sfinfo;
|
||||
} HANDLE_LDAC_STRUCT;
|
||||
|
||||
/* Huffman Codeword */
|
||||
typedef struct {
|
||||
unsigned char word;
|
||||
unsigned char len;
|
||||
} HC;
|
||||
|
||||
/* Huffman Encoding Structure */
|
||||
typedef struct _hcenc_ldac HCENC;
|
||||
struct _hcenc_ldac {
|
||||
const HC *p_tbl;
|
||||
unsigned char ncodes;
|
||||
unsigned char wl;
|
||||
unsigned char mask;
|
||||
};
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
Function Declarations
|
||||
*******************************************************************************/
|
||||
#define npow2_ldac(n) (1 << (n))
|
||||
#define min_ldac(a, b) (((a)<(b)) ? (a) : (b))
|
||||
#define max_ldac(a, b) (((a)>(b)) ? (a) : (b))
|
||||
|
||||
/* Get Huffman Codeword Property */
|
||||
#define hc_len_ldac(p) ((p)->len)
|
||||
#define hc_word_ldac(p) ((p)->word)
|
||||
|
||||
/* Convert a Signed Number with nbits to a Signed Integer */
|
||||
#define bs_to_int_ldac(bs, nbits) (((bs)&(0x1<<((nbits)-1))) ? ((bs)|((~0x0)<<(nbits))) : bs)
|
||||
|
||||
#ifdef _32BIT_FIXED_POINT
|
||||
#include "fixp_ldac.h"
|
||||
#endif /* _32BIT_FIXED_POINT */
|
||||
#include "proto_ldac.h"
|
||||
|
||||
|
||||
#endif /* _LDAC_H */
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldacBT.h"
|
||||
|
||||
#include "ldacBT_internal.c"
|
||||
#include "ldacBT_api.c"
|
||||
|
|
@ -0,0 +1,626 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2017 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldacBT_internal.h"
|
||||
|
||||
|
||||
/* Get LDAC library version */
|
||||
#define LDACBT_LIB_VER_MAJOR 2
|
||||
#define LDACBT_LIB_VER_MINOR 0
|
||||
#define LDACBT_LIB_VER_BRANCH 2
|
||||
LDACBT_API int ldacBT_get_version( void )
|
||||
{
|
||||
return ((LDACBT_LIB_VER_MAJOR)<<16)|((LDACBT_LIB_VER_MINOR)<<8)|(LDACBT_LIB_VER_BRANCH);
|
||||
}
|
||||
|
||||
/* Get LDAC handle */
|
||||
LDACBT_API HANDLE_LDAC_BT ldacBT_get_handle( void )
|
||||
{
|
||||
HANDLE_LDAC_BT hLdacBT;
|
||||
hLdacBT = (HANDLE_LDAC_BT)malloc( sizeof(STRUCT_LDACBT_HANDLE) );
|
||||
if( hLdacBT == NULL ){ return NULL; }
|
||||
|
||||
/* Get ldaclib Handler */
|
||||
if( (hLdacBT->hLDAC = ldaclib_get_handle()) == NULL ){
|
||||
ldacBT_free_handle( hLdacBT );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ldacBT_param_clear( hLdacBT );
|
||||
return hLdacBT;
|
||||
}
|
||||
|
||||
/* Free LDAC handle */
|
||||
LDACBT_API void ldacBT_free_handle( HANDLE_LDAC_BT hLdacBT )
|
||||
{
|
||||
if( hLdacBT == NULL ){ return; }
|
||||
|
||||
if( hLdacBT->hLDAC != NULL ){
|
||||
/* close ldaclib handle */
|
||||
if( hLdacBT->proc_mode == LDACBT_PROCMODE_ENCODE ){
|
||||
ldaclib_free_encode( hLdacBT->hLDAC );
|
||||
}
|
||||
/* free ldaclib handle */
|
||||
ldaclib_free_handle( hLdacBT->hLDAC );
|
||||
hLdacBT->hLDAC = NULL;
|
||||
}
|
||||
/* free ldacbt handle */
|
||||
free( hLdacBT );
|
||||
}
|
||||
|
||||
/* Close LDAC handle */
|
||||
LDACBT_API void ldacBT_close_handle( HANDLE_LDAC_BT hLdacBT )
|
||||
{
|
||||
if( hLdacBT == NULL ){ return; }
|
||||
|
||||
if( hLdacBT->hLDAC != NULL ){
|
||||
/* close ldaclib handle */
|
||||
if( hLdacBT->proc_mode == LDACBT_PROCMODE_ENCODE ){
|
||||
ldaclib_free_encode( hLdacBT->hLDAC );
|
||||
}
|
||||
/* clear error code */
|
||||
ldaclib_clear_error_code(hLdacBT->hLDAC);
|
||||
ldaclib_clear_internal_error_code(hLdacBT->hLDAC);
|
||||
}
|
||||
/* clear ldacbt handle */
|
||||
ldacBT_param_clear( hLdacBT );
|
||||
}
|
||||
|
||||
|
||||
/* Get ERROR CODE */
|
||||
LDACBT_API int ldacBT_get_error_code( HANDLE_LDAC_BT hLdacBT )
|
||||
{
|
||||
int error_code;
|
||||
if( hLdacBT == NULL ){return LDACBT_ERR_FATAL_HANDLE<<10;}
|
||||
ldacBT_check_ldaclib_error_code( hLdacBT );
|
||||
if( hLdacBT->error_code_api == LDACBT_GET_LDACLIB_ERROR_CODE ){
|
||||
error_code = LDACBT_ERR_FATAL << 20 | hLdacBT->error_code;
|
||||
}else if( hLdacBT->error_code_api != LDACBT_ERR_NONE ){
|
||||
error_code = hLdacBT->error_code_api << 20 | hLdacBT->error_code;
|
||||
}else{
|
||||
error_code = hLdacBT->error_code_api << 20;
|
||||
}
|
||||
return error_code;
|
||||
}
|
||||
|
||||
|
||||
/* Get Configured Sampling frequency */
|
||||
LDACBT_API int ldacBT_get_sampling_freq( HANDLE_LDAC_BT hLdacBT )
|
||||
{
|
||||
if( hLdacBT == NULL ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( hLdacBT->proc_mode != LDACBT_PROCMODE_ENCODE )
|
||||
{
|
||||
hLdacBT->error_code_api = LDACBT_ERR_HANDLE_NOT_INIT;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
return hLdacBT->pcm.sf;
|
||||
}
|
||||
|
||||
/* Get bitrate */
|
||||
LDACBT_API int ldacBT_get_bitrate( HANDLE_LDAC_BT hLdacBT )
|
||||
{
|
||||
if( hLdacBT == NULL ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( hLdacBT->proc_mode != LDACBT_PROCMODE_ENCODE )
|
||||
{
|
||||
hLdacBT->error_code_api = LDACBT_ERR_HANDLE_NOT_INIT;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
return hLdacBT->bitrate;
|
||||
}
|
||||
|
||||
/* Init LDAC handle for ENCODE */
|
||||
LDACBT_API int ldacBT_init_handle_encode( HANDLE_LDAC_BT hLdacBT, int mtu, int eqmid,
|
||||
int cm, LDACBT_SMPL_FMT_T fmt, int sf )
|
||||
{
|
||||
LDAC_RESULT result;
|
||||
int sfid, frame_samples, cci;
|
||||
int nbasebands, grad_mode, grad_qu_l, grad_qu_h, grad_ofst_l, grad_ofst_h, abc_flag;
|
||||
P_LDACBT_CONFIG pCfg;
|
||||
const int a_cci_nch[] = { 1, 2, 2 };
|
||||
|
||||
/* check arguments */
|
||||
if( hLdacBT == NULL ){ return LDACBT_E_FAIL; }
|
||||
if( (hLdacBT->error_code_api = ldacBT_assert_mtu( mtu )) != LDACBT_ERR_NONE ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( (hLdacBT->error_code_api = ldacBT_assert_eqmid( eqmid )) != LDACBT_ERR_NONE ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( (hLdacBT->error_code_api = ldacBT_assert_cm( cm )) != LDACBT_ERR_NONE ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( (hLdacBT->error_code_api = ldacBT_assert_sample_format( fmt )) != LDACBT_ERR_NONE ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( (hLdacBT->error_code_api = ldacBT_assert_pcm_sampling_freq( sf )) != LDACBT_ERR_NONE ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
|
||||
ldacBT_close_handle( hLdacBT );
|
||||
|
||||
/* initialize handle for encode processing */
|
||||
hLdacBT->proc_mode = LDACBT_PROCMODE_ENCODE;
|
||||
hLdacBT->flg_encode_flushed = FALSE;
|
||||
|
||||
/* transport setting */
|
||||
/* The ldac frame header is REQUIRED for A2DP streaming. */
|
||||
hLdacBT->transport = TRUE;
|
||||
hLdacBT->tx.mtu = mtu;
|
||||
hLdacBT->tx.pkt_hdr_sz = LDACBT_TX_HEADER_SIZE;
|
||||
hLdacBT->tx.tx_size = LDACBT_MTU_REQUIRED;
|
||||
hLdacBT->tx.pkt_type = _2_DH5;
|
||||
/* - BT TRANS HEADER etc */
|
||||
hLdacBT->tx.tx_size -= hLdacBT->tx.pkt_hdr_sz;
|
||||
if( hLdacBT->tx.tx_size > (hLdacBT->tx.mtu - hLdacBT->tx.pkt_hdr_sz) ){
|
||||
/* never happen, mtu must be larger than LDACBT_MTU_REQUIRED(2DH5) */
|
||||
hLdacBT->tx.tx_size = (hLdacBT->tx.mtu - hLdacBT->tx.pkt_hdr_sz);
|
||||
}
|
||||
|
||||
/* channel configration */
|
||||
cci = ldacBT_cm_to_cci(cm);
|
||||
hLdacBT->cm = cm;
|
||||
hLdacBT->cci = cci;
|
||||
/* input pcm configuration */
|
||||
hLdacBT->pcm.ch = a_cci_nch[cci];
|
||||
hLdacBT->pcm.sf = sf;
|
||||
hLdacBT->pcm.fmt = fmt;
|
||||
switch(hLdacBT->pcm.fmt){
|
||||
case LDACBT_SMPL_FMT_S16:
|
||||
hLdacBT->pcm.wl = 2;
|
||||
break;
|
||||
case LDACBT_SMPL_FMT_S24:
|
||||
hLdacBT->pcm.wl = 3;
|
||||
break;
|
||||
case LDACBT_SMPL_FMT_S32:
|
||||
case LDACBT_SMPL_FMT_F32:
|
||||
hLdacBT->pcm.wl = 4;
|
||||
break;
|
||||
default:
|
||||
// must be rejected by ldacBT_assert_sample_format()
|
||||
hLdacBT->pcm.wl = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
/* initilize ldac encode */
|
||||
/* Get sampling frequency index */
|
||||
result = ldaclib_get_sampling_rate_index( hLdacBT->pcm.sf, &sfid );
|
||||
if( LDAC_FAILED ( result ) ){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_ILL_SAMPLING_FREQ;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
hLdacBT->sfid = sfid;
|
||||
|
||||
/* Get number of frame samples */
|
||||
result = ldaclib_get_frame_samples(sfid, &frame_samples);
|
||||
if (LDAC_FAILED(result)) {
|
||||
hLdacBT->error_code_api = LDACBT_ERR_ILL_SAMPLING_FREQ;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
hLdacBT->frm_samples = frame_samples;
|
||||
|
||||
|
||||
/* Set Parameters by Encode Quality Mode Index */
|
||||
hLdacBT->eqmid = eqmid;
|
||||
/* get frame_length of EQMID */
|
||||
pCfg = ldacBT_get_config( hLdacBT->eqmid, hLdacBT->tx.pkt_type );
|
||||
/* set frame_length */
|
||||
hLdacBT->frmlen_tx = hLdacBT->pcm.ch * pCfg->frmlen_1ch;
|
||||
hLdacBT->frmlen = hLdacBT->frmlen_tx;
|
||||
if (hLdacBT->transport) {
|
||||
/* Adjust frame_length for Transport Header Data */
|
||||
hLdacBT->frmlen -= LDACBT_FRMHDRBYTES;
|
||||
}
|
||||
|
||||
/* Calculate how many LDAC frames fit into payload packet */
|
||||
hLdacBT->tx.nfrm_in_pkt = hLdacBT->tx.tx_size / hLdacBT->frmlen_tx;
|
||||
|
||||
|
||||
/* Get ldac encode setting */
|
||||
result = ldaclib_get_encode_setting( pCfg->frmlen_1ch, sfid, &nbasebands, &grad_mode,
|
||||
&grad_qu_l, &grad_qu_h, &grad_ofst_l, &grad_ofst_h, &abc_flag);
|
||||
if (LDAC_FAILED(result)) {
|
||||
hLdacBT->error_code_api = LDACBT_ERR_ILL_PARAM;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
|
||||
/* Set Configuration Information */
|
||||
result = ldaclib_set_config_info( hLdacBT->hLDAC, hLdacBT->sfid, hLdacBT->cci,
|
||||
hLdacBT->frmlen, hLdacBT->frm_status);
|
||||
if (LDAC_FAILED(result)) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
else if (result != LDAC_S_OK) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
}
|
||||
|
||||
/* Set Encoding Information */
|
||||
result = ldaclib_set_encode_info(hLdacBT->hLDAC, nbasebands, grad_mode,
|
||||
grad_qu_l, grad_qu_h, grad_ofst_l, grad_ofst_h, abc_flag);
|
||||
if (LDAC_FAILED(result)) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
else if (result != LDAC_S_OK) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
}
|
||||
|
||||
/* Initialize ldaclib for Encoding */
|
||||
result = ldaclib_init_encode(hLdacBT->hLDAC);
|
||||
if (LDAC_FAILED(result)) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
else if (result != LDAC_S_OK) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
}
|
||||
|
||||
/* reset target eqmid as current setting */
|
||||
hLdacBT->tgt_eqmid = hLdacBT->eqmid;
|
||||
hLdacBT->tgt_nfrm_in_pkt = hLdacBT->tx.nfrm_in_pkt;
|
||||
hLdacBT->tgt_frmlen = hLdacBT->frmlen;
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON;
|
||||
|
||||
/* get bitrate */
|
||||
hLdacBT->bitrate = ldacBT_frmlen_to_bitrate( hLdacBT->frmlen, hLdacBT->transport,
|
||||
hLdacBT->pcm.sf, hLdacBT->frm_samples );
|
||||
|
||||
return (hLdacBT->error_code_api==LDACBT_ERR_NONE?LDACBT_S_OK:LDACBT_E_FAIL);
|
||||
}
|
||||
|
||||
/* Set Encode Quality Mode index */
|
||||
LDACBT_API int ldacBT_set_eqmid( HANDLE_LDAC_BT hLdacBT, int eqmid )
|
||||
{
|
||||
if( hLdacBT == NULL ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( hLdacBT->proc_mode != LDACBT_PROCMODE_ENCODE ){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_HANDLE_NOT_INIT;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
|
||||
if( (hLdacBT->error_code_api = ldacBT_assert_eqmid( eqmid )) != LDACBT_ERR_NONE ){
|
||||
return LDACBT_E_FAIL; /* fatal */
|
||||
}
|
||||
ldacBT_set_eqmid_core( hLdacBT, eqmid );
|
||||
|
||||
return LDACBT_S_OK;
|
||||
}
|
||||
|
||||
/* Get Encode Quality Mode index */
|
||||
LDACBT_API int ldacBT_get_eqmid( HANDLE_LDAC_BT hLdacBT )
|
||||
{
|
||||
if( hLdacBT == NULL ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( hLdacBT->proc_mode != LDACBT_PROCMODE_ENCODE ){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_HANDLE_NOT_INIT;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
return hLdacBT->tgt_eqmid;
|
||||
}
|
||||
|
||||
/* Alter encode quality mode index */
|
||||
LDACBT_API int ldacBT_alter_eqmid_priority( HANDLE_LDAC_BT hLdacBT, int priority )
|
||||
{
|
||||
int target_eqmid;
|
||||
if( hLdacBT == NULL ){ return LDACBT_E_FAIL; }
|
||||
if( hLdacBT->proc_mode != LDACBT_PROCMODE_ENCODE ){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_HANDLE_NOT_INIT;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( (priority != LDACBT_EQMID_INC_QUALITY) &&
|
||||
(priority != LDACBT_EQMID_INC_CONNECTION )
|
||||
){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_ILL_PARAM;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
|
||||
target_eqmid = ldacBT_get_altered_eqmid( hLdacBT, priority);
|
||||
if( target_eqmid < 0 ){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_ALTER_EQMID_LIMITED;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
|
||||
ldacBT_set_eqmid_core( hLdacBT, target_eqmid );
|
||||
return LDACBT_S_OK;
|
||||
}
|
||||
|
||||
/* LDAC encode proccess */
|
||||
LDACBT_API int ldacBT_encode( HANDLE_LDAC_BT hLdacBT, void *p_pcm, int *pcm_used,
|
||||
unsigned char *p_stream, int *stream_sz, int *frame_num )
|
||||
{
|
||||
LDAC_RESULT result;
|
||||
LDACBT_SMPL_FMT_T fmt;
|
||||
LDACBT_TRANSPORT_FRM_BUF *ptfbuf;
|
||||
LDACBT_PCM_RING_BUF *ppcmring;
|
||||
P_LDACBT_CONFIG pCfg;
|
||||
int frmlen, frmlen_wrote, frmlen_adj;
|
||||
int frm_status, flg_Do_Encode;
|
||||
int nFrmToPkt, ch, wl;
|
||||
unsigned char *p_ldac_transport_frame;
|
||||
unsigned char a_frm_header[LDACBT_FRMHDRBYTES + 2];
|
||||
if( hLdacBT == NULL ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( hLdacBT->hLDAC == NULL ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( hLdacBT->proc_mode != LDACBT_PROCMODE_ENCODE ){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_HANDLE_NOT_INIT;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
/* Clear Error Codes */
|
||||
hLdacBT->error_code_api = LDACBT_ERR_NONE;
|
||||
ldaclib_clear_error_code( hLdacBT->hLDAC );
|
||||
ldaclib_clear_internal_error_code( hLdacBT->hLDAC );
|
||||
|
||||
if( ( pcm_used == NULL) ||
|
||||
( p_stream == NULL ) ||
|
||||
( stream_sz == NULL ) ||
|
||||
( frame_num == NULL )
|
||||
){
|
||||
hLdacBT->error_code_api = LDACBT_ERR_ILL_PARAM;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
/* reset parameters */
|
||||
*pcm_used = 0;
|
||||
*stream_sz = 0;
|
||||
*frame_num = 0;
|
||||
flg_Do_Encode = 0;
|
||||
fmt = hLdacBT->pcm.fmt;
|
||||
ch = hLdacBT->pcm.ch;
|
||||
wl = hLdacBT->pcm.wl;
|
||||
ptfbuf = &hLdacBT->ldac_trns_frm_buf;
|
||||
ppcmring = &hLdacBT->pcmring;
|
||||
|
||||
/* update input pcm data */
|
||||
if( p_pcm != NULL ){
|
||||
int nByteCpy, sz;
|
||||
nByteCpy = LDACBT_ENC_LSU * wl * ch;
|
||||
sz = ppcmring->nsmpl * wl * ch + nByteCpy;
|
||||
if( sz < LDACBT_ENC_PCM_BUF_SZ ){
|
||||
copy_data_ldac( p_pcm, ppcmring->buf + ppcmring->wp, nByteCpy );
|
||||
ppcmring->wp += nByteCpy;
|
||||
if( ppcmring->wp >= LDACBT_ENC_PCM_BUF_SZ ){
|
||||
ppcmring->wp = 0;
|
||||
}
|
||||
ppcmring->nsmpl += LDACBT_ENC_LSU;
|
||||
*pcm_used = nByteCpy;
|
||||
}else{
|
||||
/* Not enough space to copy.
|
||||
* This will happen when the last encode process failed.
|
||||
*/
|
||||
*pcm_used = 0;
|
||||
}
|
||||
|
||||
if( ppcmring->nsmpl >= hLdacBT->frm_samples )
|
||||
{
|
||||
flg_Do_Encode = 1;
|
||||
}
|
||||
}else{
|
||||
if (hLdacBT->flg_encode_flushed != TRUE){
|
||||
flg_Do_Encode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( !flg_Do_Encode ){
|
||||
/* nothing to do */
|
||||
return LDACBT_S_OK;
|
||||
}
|
||||
|
||||
/* update frame_length if needed */
|
||||
if( (hLdacBT->tgt_eqmid != UNSET) && (hLdacBT->tgt_eqmid != hLdacBT->eqmid) ){
|
||||
if( ptfbuf->nfrm_in == 0 ){
|
||||
ldacBT_update_frmlen( hLdacBT, hLdacBT->tgt_frmlen );
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON;
|
||||
}
|
||||
else if( hLdacBT->tgt_nfrm_in_pkt > hLdacBT->tx.nfrm_in_pkt ){
|
||||
/* for better connectivity, apply ASAP */
|
||||
if( !hLdacBT->stat_alter_op ){
|
||||
nFrmToPkt = hLdacBT->tgt_nfrm_in_pkt - ptfbuf->nfrm_in;
|
||||
if( nFrmToPkt > 0 ){
|
||||
pCfg = ldacBT_get_config(LDACBT_EQMID_END, hLdacBT->tx.pkt_type);
|
||||
if( pCfg != NULL ){
|
||||
do{
|
||||
frmlen_adj = (hLdacBT->tx.tx_size - ptfbuf->used) / nFrmToPkt;
|
||||
if( frmlen_adj > hLdacBT->tgt_frmlen ) {
|
||||
frmlen_adj = hLdacBT->tgt_frmlen;
|
||||
}
|
||||
frmlen_adj -= LDACBT_FRMHDRBYTES;
|
||||
if( frmlen_adj >= pCfg->frmlen ){
|
||||
if( ldacBT_update_frmlen( hLdacBT, frmlen_adj ) == LDACBT_S_OK ){
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__ACTIVE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}while( --nFrmToPkt > 0 );
|
||||
}
|
||||
if( !hLdacBT->stat_alter_op ){
|
||||
/* force to flash streams */
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__FLASH;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
/* wait the condition ptfbuf->nfrm_in == 0 for apply new frame_length */
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__STANDBY;
|
||||
}
|
||||
|
||||
}
|
||||
else if( hLdacBT->tgt_frmlen != hLdacBT->frmlen ){
|
||||
if( ptfbuf->nfrm_in == 0 ){
|
||||
ldacBT_update_frmlen( hLdacBT, hLdacBT->tgt_frmlen );
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON;
|
||||
}else{
|
||||
if( hLdacBT->tgt_nfrm_in_pkt == hLdacBT->tx.nfrm_in_pkt ){
|
||||
ldacBT_update_frmlen( hLdacBT, hLdacBT->tgt_frmlen );
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON;
|
||||
}else{
|
||||
if( hLdacBT->tgt_nfrm_in_pkt > hLdacBT->tx.nfrm_in_pkt ){
|
||||
/* for better connectivity, apply ASAP */
|
||||
if( !hLdacBT->stat_alter_op ){
|
||||
nFrmToPkt = hLdacBT->tgt_nfrm_in_pkt - ptfbuf->nfrm_in;
|
||||
if( nFrmToPkt > 0 ){
|
||||
frmlen_adj = (hLdacBT->tx.tx_size - ptfbuf->used) / nFrmToPkt;
|
||||
if( frmlen_adj > hLdacBT->tgt_frmlen ) {
|
||||
frmlen_adj = hLdacBT->tgt_frmlen;
|
||||
}
|
||||
if( ldacBT_update_frmlen( hLdacBT, frmlen_adj ) == LDACBT_S_OK ){
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__ACTIVE;
|
||||
}
|
||||
if( !hLdacBT->stat_alter_op ){
|
||||
/* flash streams */
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__FLASH;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
/* wait the condition ptfbuf->nfrm_in == 0 for apply new frame_length */
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__STANDBY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check write space for encoded data */
|
||||
ldaclib_get_encode_frame_length( hLdacBT->hLDAC, &frmlen );
|
||||
|
||||
if( (( ptfbuf->used + frmlen + LDACBT_FRMHDRBYTES) > hLdacBT->tx.tx_size) ||
|
||||
(hLdacBT->stat_alter_op == LDACBT_ALTER_OP__FLASH) || /* need to flash streams? */
|
||||
(( ptfbuf->used + frmlen + LDACBT_FRMHDRBYTES) >= LDACBT_ENC_STREAM_BUF_SZ )
|
||||
)
|
||||
{
|
||||
copy_data_ldac( ptfbuf->buf, p_stream, ptfbuf->used );
|
||||
*stream_sz = ptfbuf->used;
|
||||
*frame_num = ptfbuf->nfrm_in;
|
||||
clear_data_ldac( ptfbuf->buf, sizeof(char)*LDACBT_ENC_STREAM_BUF_SZ);
|
||||
ptfbuf->used = 0;
|
||||
ptfbuf->nfrm_in = 0;
|
||||
if( hLdacBT->stat_alter_op != LDACBT_ALTER_OP__NON ){
|
||||
/* update frame length */
|
||||
ldacBT_update_frmlen( hLdacBT, hLdacBT->tgt_frmlen );
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON;
|
||||
}
|
||||
}
|
||||
p_ldac_transport_frame = ptfbuf->buf + ptfbuf->used;
|
||||
|
||||
/* Encode Frame */
|
||||
if( ppcmring->nsmpl > 0 ){
|
||||
char *p_pcm_ring_r;
|
||||
int nsmpl_to_clr;
|
||||
nsmpl_to_clr = hLdacBT->frm_samples - ppcmring->nsmpl;
|
||||
if( nsmpl_to_clr > 0 ){
|
||||
int pos, nBytesToZero;
|
||||
pos = ppcmring->rp + ppcmring->nsmpl * wl * ch;
|
||||
nBytesToZero = nsmpl_to_clr * wl * ch;
|
||||
while( nBytesToZero > 0 ){
|
||||
int clearBytes;
|
||||
clearBytes = nBytesToZero;
|
||||
if ( pos + clearBytes >= LDACBT_ENC_PCM_BUF_SZ ){
|
||||
clearBytes = (LDACBT_ENC_PCM_BUF_SZ - pos);
|
||||
}
|
||||
clear_data_ldac( ppcmring->buf + pos, clearBytes);
|
||||
nBytesToZero -= clearBytes;
|
||||
if( (pos += clearBytes) >= LDACBT_ENC_PCM_BUF_SZ ){
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
p_pcm_ring_r = ppcmring->buf + ppcmring->rp;
|
||||
ldacBT_prepare_pcm_encode( p_pcm_ring_r, hLdacBT->pp_pcm, hLdacBT->frm_samples, ch, fmt );
|
||||
result = ldaclib_encode(hLdacBT->hLDAC, hLdacBT->pp_pcm, (LDAC_SMPL_FMT_T)fmt,
|
||||
p_ldac_transport_frame+LDACBT_FRMHDRBYTES, &frmlen_wrote);
|
||||
if( !LDAC_FAILED(result) ){
|
||||
ppcmring->rp += hLdacBT->frm_samples * wl * ch;
|
||||
ppcmring->nsmpl -= hLdacBT->frm_samples;
|
||||
if( ppcmring->rp >= LDACBT_ENC_PCM_BUF_SZ ){ ppcmring->rp = 0; }
|
||||
if( ppcmring->nsmpl < 0 ){ ppcmring->nsmpl = 0; }
|
||||
}
|
||||
}else{
|
||||
result = ldaclib_flush_encode(hLdacBT->hLDAC, (LDAC_SMPL_FMT_T)fmt,
|
||||
p_ldac_transport_frame+LDACBT_FRMHDRBYTES, &frmlen_wrote);
|
||||
hLdacBT->flg_encode_flushed = TRUE;
|
||||
}
|
||||
|
||||
if( LDAC_FAILED(result) ){
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
else if( result != LDAC_S_OK ){
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
}
|
||||
|
||||
if( frmlen_wrote > 0 ){
|
||||
if( hLdacBT->transport == TRUE ){
|
||||
/* Set Frame Header Data */
|
||||
clear_data_ldac( a_frm_header, LDACBT_FRMHDRBYTES+2 );
|
||||
/* Get Frame Header Information */
|
||||
result = ldaclib_get_config_info(hLdacBT->hLDAC, &hLdacBT->sfid, &hLdacBT->cci,
|
||||
&frmlen, &frm_status);
|
||||
if( LDAC_FAILED(result) ){
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
else if (result != LDAC_S_OK) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
}
|
||||
|
||||
/* Set Frame Header */
|
||||
result = ldaclib_set_frame_header(hLdacBT->hLDAC, a_frm_header, hLdacBT->sfid,
|
||||
hLdacBT->cci, frmlen, frm_status);
|
||||
if( LDAC_FAILED(result) ){
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
else if (result != LDAC_S_OK) {
|
||||
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
|
||||
}
|
||||
copy_data_ldac( a_frm_header, p_ldac_transport_frame, LDACBT_FRMHDRBYTES );
|
||||
frmlen_wrote += LDACBT_FRMHDRBYTES;
|
||||
}
|
||||
ptfbuf->used += frmlen_wrote;
|
||||
ptfbuf->nfrm_in ++;
|
||||
}
|
||||
|
||||
/* check for next frame buffer status */
|
||||
if( *stream_sz == 0 ){
|
||||
if( (( ptfbuf->used + frmlen_wrote) > hLdacBT->tx.tx_size) ||
|
||||
( ptfbuf->nfrm_in >= LDACBT_NFRM_TX_MAX ) ||
|
||||
(( ptfbuf->used + frmlen_wrote) >= LDACBT_ENC_STREAM_BUF_SZ ) ||
|
||||
( p_pcm == NULL ) /* flush encode */
|
||||
)
|
||||
{
|
||||
copy_data_ldac( ptfbuf->buf, p_stream, ptfbuf->used );
|
||||
*stream_sz = ptfbuf->used;
|
||||
*frame_num = ptfbuf->nfrm_in;
|
||||
clear_data_ldac( ptfbuf->buf, sizeof(char)*LDACBT_ENC_STREAM_BUF_SZ);
|
||||
ptfbuf->used = 0;
|
||||
ptfbuf->nfrm_in = 0;
|
||||
if( hLdacBT->stat_alter_op != LDACBT_ALTER_OP__NON ){
|
||||
ldacBT_update_frmlen( hLdacBT, hLdacBT->tgt_frmlen );
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return LDACBT_S_OK;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LDACBT_EX_H_
|
||||
#define _LDACBT_EX_H_
|
||||
|
||||
#include "ldacBT.h"
|
||||
|
||||
enum {
|
||||
/* undocumented settings. for internal use only */
|
||||
LDACBT_EQMID_Q0 = LDACBT_EQMID_MQ + 1,
|
||||
LDACBT_EQMID_Q1,
|
||||
LDACBT_EQMID_Q2,
|
||||
LDACBT_EQMID_Q3,
|
||||
LDACBT_EQMID_Q4,
|
||||
LDACBT_EQMID_Q5,
|
||||
LDACBT_EQMID_Q6,
|
||||
LDACBT_EQMID_Q7,
|
||||
LDACBT_EQMID_Q8,
|
||||
LDACBT_EQMID_END,
|
||||
};
|
||||
|
||||
|
||||
#endif /* _LDACBT_EX_H_ */
|
||||
|
|
@ -0,0 +1,535 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldacBT_internal.h"
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
/* 2-DH5 */
|
||||
LDACBT_2DH5_02, LDACBT_2DH5_03, LDACBT_2DH5_04, LDACBT_2DH5_05,
|
||||
LDACBT_2DH5_06, LDACBT_2DH5_07, LDACBT_2DH5_08, LDACBT_2DH5_09, LDACBT_2DH5_10,
|
||||
LDACBT_2DH5_11, LDACBT_2DH5_12, LDACBT_2DH5_13, LDACBT_2DH5_14,
|
||||
};
|
||||
|
||||
#define LDACBT_NO_DEF_ -1
|
||||
DECLFUNC const LDACBT_EQMID_PROPERTY tbl_ldacbt_eqmid_property[] = {
|
||||
/* kbps, ID , label, ID for 2DH5 */
|
||||
/* 990 */ { LDACBT_EQMID_HQ, "HQ" , LDACBT_2DH5_02 },
|
||||
/* 660 */ { LDACBT_EQMID_SQ, "SQ" , LDACBT_2DH5_03 },
|
||||
/* 492 */ { LDACBT_EQMID_Q0, "Q0" , LDACBT_2DH5_04 },
|
||||
/* 396 */ { LDACBT_EQMID_Q1, "Q1" , LDACBT_2DH5_05 },
|
||||
/* 330 */ { LDACBT_EQMID_MQ, "MQ" , LDACBT_2DH5_06 },
|
||||
/* 282 */ { LDACBT_EQMID_Q2, "Q2" , LDACBT_2DH5_07 },
|
||||
/* 246 */ { LDACBT_EQMID_Q3, "Q3" , LDACBT_2DH5_08 },
|
||||
/* 216 */ { LDACBT_EQMID_Q4, "Q4" , LDACBT_2DH5_09 },
|
||||
/* 198 */ { LDACBT_EQMID_Q5, "Q5" , LDACBT_2DH5_10 },
|
||||
/* 180 */ { LDACBT_EQMID_Q6, "Q6" , LDACBT_2DH5_11 },
|
||||
/* 162 */ { LDACBT_EQMID_Q7, "Q7" , LDACBT_2DH5_12 },
|
||||
/* 150 */ { LDACBT_EQMID_Q8, "Q8" , LDACBT_2DH5_13 },
|
||||
/* 138 */ { LDACBT_EQMID_END, "Q9" , LDACBT_2DH5_14 },
|
||||
};
|
||||
|
||||
/* LDAC config table
|
||||
* - NFRM/PCKT must be less than 16.
|
||||
*/
|
||||
DECLFUNC const LDACBT_CONFIG tbl_ldacbt_config[] = {
|
||||
/*
|
||||
* index , NFRM , LDAC , FRM
|
||||
* , ---- , FRM , LEN
|
||||
* , PCKT , LEN , /CH
|
||||
* , , [byte], [byte]
|
||||
*/
|
||||
{ LDACBT_2DH5_02, 2, 330, 165},
|
||||
{ LDACBT_2DH5_03, 3, 220, 110},
|
||||
{ LDACBT_2DH5_04, 4, 164, 82},
|
||||
{ LDACBT_2DH5_05, 5, 132, 66},
|
||||
{ LDACBT_2DH5_06, 6, 110, 55},
|
||||
{ LDACBT_2DH5_07, 7, 94, 47},
|
||||
{ LDACBT_2DH5_08, 8, 82, 41},
|
||||
{ LDACBT_2DH5_09, 9, 72, 36},
|
||||
{ LDACBT_2DH5_10, 10, 66, 33},
|
||||
{ LDACBT_2DH5_11, 11, 60, 30},
|
||||
{ LDACBT_2DH5_12, 12, 54, 27},
|
||||
{ LDACBT_2DH5_13, 13, 50, 25},
|
||||
{ LDACBT_2DH5_14, 14, 46, 23},
|
||||
};
|
||||
|
||||
|
||||
/* Clear LDAC handle parameters */
|
||||
DECLFUNC void ldacBT_param_clear(HANDLE_LDAC_BT hLdacBT)
|
||||
{
|
||||
int ich;
|
||||
if( hLdacBT == NULL ) { return ; }
|
||||
hLdacBT->proc_mode = LDACBT_PROCMODE_UNSET;
|
||||
hLdacBT->error_code = LDACBT_ERR_NONE;
|
||||
hLdacBT->error_code_api = LDACBT_ERR_NONE;
|
||||
|
||||
hLdacBT->frm_samples = 0;
|
||||
hLdacBT->sfid = UNSET;
|
||||
hLdacBT->pcm.sf = UNSET;
|
||||
hLdacBT->tx.mtu = UNSET;
|
||||
hLdacBT->tx.tx_size = UNSET;
|
||||
hLdacBT->tx.pkt_hdr_sz = UNSET;
|
||||
hLdacBT->frmlen_tx = UNSET;
|
||||
hLdacBT->tx.nfrm_in_pkt = UNSET;
|
||||
hLdacBT->pcm.ch = 0;
|
||||
hLdacBT->pcm.fmt = LDACBT_SMPL_FMT_S24;
|
||||
hLdacBT->nshift = 0;
|
||||
hLdacBT->frmlen = UNSET;
|
||||
hLdacBT->frm_status = 0;
|
||||
hLdacBT->bitrate = 0;
|
||||
/* for alter frame length */
|
||||
hLdacBT->tgt_nfrm_in_pkt = UNSET;
|
||||
hLdacBT->tgt_frmlen = UNSET;
|
||||
hLdacBT->tgt_eqmid = UNSET;
|
||||
hLdacBT->stat_alter_op = LDACBT_ALTER_OP__NON;
|
||||
|
||||
hLdacBT->cm = UNSET;
|
||||
hLdacBT->cci = UNSET;
|
||||
hLdacBT->eqmid = UNSET;
|
||||
hLdacBT->transport = UNSET;
|
||||
|
||||
clear_data_ldac( hLdacBT->ldac_trns_frm_buf.buf, sizeof(hLdacBT->ldac_trns_frm_buf.buf));
|
||||
hLdacBT->ldac_trns_frm_buf.used = 0;
|
||||
hLdacBT->ldac_trns_frm_buf.nfrm_in = 0;
|
||||
|
||||
clear_data_ldac( hLdacBT->pcmring.buf, sizeof(hLdacBT->pcmring.buf));
|
||||
hLdacBT->pcmring.wp = 0;
|
||||
hLdacBT->pcmring.rp = 0;
|
||||
hLdacBT->pcmring.nsmpl = 0;
|
||||
/* work buffer for I/O */
|
||||
for( ich = 0; ich < LDAC_PRCNCH; ich++ ){
|
||||
hLdacBT->ap_pcm[ich] = &hLdacBT->a_pcm[ ich * LDACBT_MAX_LSU * LDACBT_PCM_WLEN_MAX ];
|
||||
}
|
||||
hLdacBT->pp_pcm = hLdacBT->ap_pcm;
|
||||
clear_data_ldac( hLdacBT->a_pcm, LDAC_PRCNCH * LDACBT_MAX_LSU * LDACBT_PCM_WLEN_MAX );
|
||||
|
||||
}
|
||||
|
||||
/* get ldaclib error code */
|
||||
DECLFUNC int ldacBT_check_ldaclib_error_code(HANDLE_LDAC_BT hLdacBT)
|
||||
{
|
||||
HANDLE_LDAC hData;
|
||||
int error_code, internal_error_code;
|
||||
|
||||
if( hLdacBT == NULL ){ return LDACBT_E_FAIL; }
|
||||
if( (hData = hLdacBT->hLDAC) == NULL ){ return LDACBT_E_FAIL; }
|
||||
|
||||
ldaclib_get_error_code(hData, &error_code);
|
||||
|
||||
ldaclib_get_internal_error_code(hData, &internal_error_code);
|
||||
|
||||
hLdacBT->error_code = error_code << 10 | internal_error_code;
|
||||
|
||||
return LDACBT_S_OK;
|
||||
}
|
||||
|
||||
/* Assertions. */
|
||||
DECLFUNC int ldacBT_assert_cm( int cm )
|
||||
{
|
||||
if( (cm != LDACBT_CHANNEL_MODE_STEREO )
|
||||
&& (cm != LDACBT_CHANNEL_MODE_DUAL_CHANNEL )
|
||||
&& (cm != LDACBT_CHANNEL_MODE_MONO )
|
||||
){
|
||||
return LDACBT_ERR_ASSERT_CHANNEL_MODE;
|
||||
}
|
||||
return LDACBT_ERR_NONE;
|
||||
}
|
||||
UNUSED_ATTR DECLFUNC int ldacBT_assert_cci( int cci )
|
||||
{
|
||||
if( (cci != LDAC_CCI_STEREO )
|
||||
&& (cci != LDAC_CCI_DUAL_CHANNEL )
|
||||
&& (cci != LDAC_CCI_MONO )
|
||||
){
|
||||
return LDACBT_ERR_ASSERT_CHANNEL_CONFIG;
|
||||
}
|
||||
return LDACBT_ERR_NONE;
|
||||
}
|
||||
DECLFUNC int ldacBT_assert_sample_format( LDACBT_SMPL_FMT_T fmt )
|
||||
{
|
||||
#ifndef _32BIT_FIXED_POINT
|
||||
if( (fmt != LDACBT_SMPL_FMT_S16)
|
||||
&& (fmt != LDACBT_SMPL_FMT_S24)
|
||||
&& (fmt != LDACBT_SMPL_FMT_S32)
|
||||
&& (fmt != LDACBT_SMPL_FMT_F32)
|
||||
){
|
||||
#else /* _32BIT_FIXED_POINT */
|
||||
if( (fmt != LDACBT_SMPL_FMT_S16)
|
||||
&& (fmt != LDACBT_SMPL_FMT_S24)
|
||||
&& (fmt != LDACBT_SMPL_FMT_S32)
|
||||
){
|
||||
#endif /* _32BIT_FIXED_POINT */
|
||||
return LDACBT_ERR_ILL_SMPL_FORMAT;
|
||||
}
|
||||
return LDACBT_ERR_NONE;
|
||||
}
|
||||
DECLFUNC int ldacBT_assert_pcm_sampling_freq( int sampling_freq )
|
||||
{
|
||||
if( (sampling_freq != 1*44100) && (sampling_freq != 1*48000)
|
||||
&& (sampling_freq != 2*44100) && (sampling_freq != 2*48000)
|
||||
){
|
||||
return LDACBT_ERR_ILL_SAMPLING_FREQ;
|
||||
}
|
||||
return LDACBT_ERR_NONE;
|
||||
}
|
||||
DECLFUNC int ldacBT_assert_mtu( int mtu )
|
||||
{
|
||||
if( mtu < LDACBT_MTU_REQUIRED ){
|
||||
return LDACBT_ERR_ILL_MTU_SIZE;
|
||||
}
|
||||
return LDACBT_ERR_NONE;
|
||||
}
|
||||
DECLFUNC int ldacBT_assert_eqmid( int eqmid )
|
||||
{
|
||||
if( (eqmid == LDACBT_EQMID_HQ) || (eqmid == LDACBT_EQMID_SQ) || (eqmid == LDACBT_EQMID_MQ)){
|
||||
return LDACBT_ERR_NONE;
|
||||
}
|
||||
|
||||
return LDACBT_ERR_ILL_EQMID;
|
||||
}
|
||||
|
||||
/* LDAC set Encode Quality Mode index core */
|
||||
DECLFUNC void ldacBT_set_eqmid_core( HANDLE_LDAC_BT hLdacBT, int eqmid )
|
||||
{
|
||||
/* "eqmid" must be checked before calling this function. */
|
||||
/* just update tgt_eqmid */
|
||||
P_LDACBT_CONFIG pCfg;
|
||||
pCfg = ldacBT_get_config( eqmid, hLdacBT->tx.pkt_type );
|
||||
hLdacBT->tgt_eqmid = eqmid;
|
||||
hLdacBT->tgt_frmlen = hLdacBT->pcm.ch * pCfg->frmlen_1ch;
|
||||
hLdacBT->tgt_frmlen -= LDACBT_FRMHDRBYTES;
|
||||
hLdacBT->tgt_nfrm_in_pkt = pCfg->nfrm_in_pkt;
|
||||
|
||||
}
|
||||
|
||||
/* Split LR interleaved PCM into buffer that for LDAC encode. */
|
||||
DECLFUNC void ldacBT_prepare_pcm_encode( void *pbuff, char **ap_pcm, int nsmpl, int nch,
|
||||
LDACBT_SMPL_FMT_T fmt )
|
||||
{
|
||||
int i;
|
||||
if( nch == 2 ){
|
||||
if( fmt == LDACBT_SMPL_FMT_S16 ){
|
||||
short *p_pcm_16 = (short *)pbuff;
|
||||
short *p_lch_16 = (short *)ap_pcm[0];
|
||||
short *p_rch_16 = (short *)ap_pcm[1];
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_lch_16++ = p_pcm_16[0];
|
||||
*p_rch_16++ = p_pcm_16[1];
|
||||
p_pcm_16+=2;
|
||||
}
|
||||
}
|
||||
else if( fmt == LDACBT_SMPL_FMT_S24 ){
|
||||
char *p_pcm_8 = (char *)pbuff;
|
||||
char *p_lch_8 = (char *)ap_pcm[0];
|
||||
char *p_rch_8 = (char *)ap_pcm[1];
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_lch_8++ = p_pcm_8[0];
|
||||
*p_lch_8++ = p_pcm_8[1];
|
||||
*p_lch_8++ = p_pcm_8[2];
|
||||
p_pcm_8+=3;
|
||||
*p_rch_8++ = p_pcm_8[0];
|
||||
*p_rch_8++ = p_pcm_8[1];
|
||||
*p_rch_8++ = p_pcm_8[2];
|
||||
p_pcm_8+=3;
|
||||
}
|
||||
#else /* __BYTE_ORDER */
|
||||
#error unsupported byte order
|
||||
#endif /* #if __BYTE_ORDER == __LITTLE_ENDIAN */
|
||||
}
|
||||
else if ( fmt == LDACBT_SMPL_FMT_S32 ){
|
||||
char *p_pcm_8 = (char *)pbuff;
|
||||
char *p_lch_8 = (char *)ap_pcm[0];
|
||||
char *p_rch_8 = (char *)ap_pcm[1];
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*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];
|
||||
p_pcm_8+=4;
|
||||
*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];
|
||||
p_pcm_8+=4;
|
||||
}
|
||||
#else /* __BYTE_ORDER */
|
||||
#error unsupported byte order
|
||||
#endif /* #if __BYTE_ORDER == __LITTLE_ENDIAN */
|
||||
}
|
||||
else if ( fmt == LDACBT_SMPL_FMT_F32 ){
|
||||
float *p_pcm = (float *)pbuff;
|
||||
float *p_lch = (float *)ap_pcm[0];
|
||||
float *p_rch = (float *)ap_pcm[1];
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_lch++ = p_pcm[0];
|
||||
p_pcm++;
|
||||
*p_rch++ = p_pcm[0];
|
||||
p_pcm++;
|
||||
}
|
||||
}
|
||||
else{;} /* never be happend */
|
||||
}
|
||||
else if( nch == 1 ){
|
||||
switch(fmt){
|
||||
case LDACBT_SMPL_FMT_S16:
|
||||
copy_data_ldac( pbuff, ap_pcm[0], 2*nsmpl );
|
||||
break;
|
||||
case LDACBT_SMPL_FMT_S24:
|
||||
copy_data_ldac( pbuff, ap_pcm[0], 3*nsmpl );
|
||||
break;
|
||||
case LDACBT_SMPL_FMT_S32:
|
||||
case LDACBT_SMPL_FMT_F32:
|
||||
copy_data_ldac( pbuff, ap_pcm[0], 4*nsmpl );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* update framelength */
|
||||
DECLFUNC int ldacBT_update_frmlen(HANDLE_LDAC_BT hLdacBT, int frmlen)
|
||||
{
|
||||
int status, sf, ch, fl, fl_per_ch;
|
||||
int nbasebands, grad_mode, grad_qu_l, grad_qu_h, grad_ofst_l, grad_ofst_h, abc_flag;
|
||||
LDACBT_TX_INFO *ptx;
|
||||
LDAC_RESULT result;
|
||||
status = LDACBT_E_FAIL;
|
||||
|
||||
if( hLdacBT == NULL ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
sf = hLdacBT->pcm.sf; /* sampling frequency */
|
||||
ch = hLdacBT->pcm.ch; /* number of channels */
|
||||
ptx = &hLdacBT->tx;
|
||||
|
||||
ldac_setup_AGAIN:
|
||||
/* update LDAC parameters. */
|
||||
|
||||
|
||||
if( frmlen == UNSET ){
|
||||
goto ldac_setup_END;
|
||||
}
|
||||
|
||||
/* check & update frameLength */
|
||||
ldaclib_get_encode_frame_length( hLdacBT->hLDAC, &fl );
|
||||
if( fl == 0 ){ // This meens that the handle was not initialized yet. Shall not happen.
|
||||
|
||||
goto ldac_setup_END;
|
||||
}
|
||||
else if( frmlen == fl ){
|
||||
/* No need to update frame length. Just update bitrate information. */
|
||||
status = LDACBT_S_OK;
|
||||
hLdacBT->bitrate = ldacBT_frmlen_to_bitrate( fl, 1, sf, hLdacBT->frm_samples );
|
||||
goto ldac_setup_END;
|
||||
}
|
||||
|
||||
/* Time to update the frame_length. */
|
||||
/* Get ldac encoding information for frame_length. */
|
||||
fl_per_ch = (frmlen+LDACBT_FRMHDRBYTES) / ch;
|
||||
result = ldaclib_get_encode_setting( fl_per_ch, hLdacBT->sfid, &nbasebands,
|
||||
&grad_mode, &grad_qu_l, &grad_qu_h, &grad_ofst_l, &grad_ofst_h, &abc_flag);
|
||||
if (LDAC_FAILED(result)) {
|
||||
goto ldac_setup_END;
|
||||
}
|
||||
/* Set Encoding Information */
|
||||
result = ldaclib_set_encode_info( hLdacBT->hLDAC, nbasebands, grad_mode,
|
||||
grad_qu_l, grad_qu_h, grad_ofst_l, grad_ofst_h, abc_flag);
|
||||
if (LDAC_FAILED(result)) {
|
||||
ldacBT_check_ldaclib_error_code(hLdacBT);
|
||||
goto ldac_setup_END;
|
||||
}
|
||||
|
||||
if( !LDAC_SUCCEEDED(ldaclib_set_encode_frame_length( hLdacBT->hLDAC, frmlen ))){
|
||||
goto ldac_setup_END;
|
||||
}
|
||||
|
||||
/* Update parameters in handle. */
|
||||
hLdacBT->frmlen = frmlen;
|
||||
hLdacBT->frmlen_tx = LDACBT_FRMHDRBYTES + frmlen;
|
||||
ptx->nfrm_in_pkt = ptx->tx_size / hLdacBT->frmlen_tx;
|
||||
if( ptx->nfrm_in_pkt > LDACBT_NFRM_TX_MAX ){
|
||||
ptx->nfrm_in_pkt = LDACBT_NFRM_TX_MAX;
|
||||
}
|
||||
else if( ptx->nfrm_in_pkt < 2 ){
|
||||
/* Not allowed 1frame/packet transportation for current version of LDAC A2DP */
|
||||
if( frmlen <= (ptx->tx_size / 2 - LDACBT_FRMHDRBYTES)){
|
||||
goto ldac_setup_END;
|
||||
}
|
||||
frmlen = ptx->tx_size / 2 - LDACBT_FRMHDRBYTES;
|
||||
goto ldac_setup_AGAIN;
|
||||
}
|
||||
/* Update bitrate and EQMID. */
|
||||
hLdacBT->bitrate = ldacBT_frmlen_to_bitrate( frmlen, 1, sf, hLdacBT->frm_samples );
|
||||
hLdacBT->eqmid = ldacBT_get_eqmid_from_frmlen( frmlen, ch, hLdacBT->transport, ptx->pkt_type );
|
||||
if( hLdacBT->tgt_eqmid == UNSET){
|
||||
hLdacBT->eqmid = UNSET;
|
||||
}
|
||||
status = LDACBT_S_OK;
|
||||
|
||||
ldac_setup_END:
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Get channel_config_index from channel_mode.
|
||||
* The argument cm, channel_mode, must be checked by function ldacBT_assert_cm() before calling this
|
||||
* function.
|
||||
*/
|
||||
DECLFUNC int ldacBT_cm_to_cci( int cm )
|
||||
{
|
||||
if( cm == LDACBT_CHANNEL_MODE_STEREO ){
|
||||
return LDAC_CCI_STEREO;
|
||||
}
|
||||
else if( cm == LDACBT_CHANNEL_MODE_DUAL_CHANNEL ){
|
||||
return LDAC_CCI_DUAL_CHANNEL;
|
||||
}
|
||||
else/* if( cm == LDACBT_CHANNEL_MODE_MONO )*/{
|
||||
return LDAC_CCI_MONO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get channel_mode from channel_config_index.
|
||||
* The argument cci, channel_config_index, must be checked by the function ldacBT_assert_cci() before
|
||||
* calling this function.
|
||||
*/
|
||||
UNUSED_ATTR DECLFUNC int ldacBT_cci_to_cm( int cci )
|
||||
{
|
||||
if( cci == LDAC_CCI_STEREO ){
|
||||
return LDACBT_CHANNEL_MODE_STEREO;
|
||||
}
|
||||
else if( cci == LDAC_CCI_DUAL_CHANNEL ){
|
||||
return LDACBT_CHANNEL_MODE_DUAL_CHANNEL;
|
||||
}
|
||||
else/* if( cci == LDAC_CCI_MONO )*/{
|
||||
return LDACBT_CHANNEL_MODE_MONO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get bitrate from frame length */
|
||||
DECLFUNC int ldacBT_frmlen_to_bitrate( int frmlen, int flgFrmHdr, int sf, int frame_samples )
|
||||
{
|
||||
int bitrate;
|
||||
if( (frmlen == UNSET) || (flgFrmHdr == UNSET) || (sf == UNSET) || (frame_samples == UNSET) ){
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
if( flgFrmHdr ){
|
||||
frmlen += LDACBT_FRMHDRBYTES;
|
||||
}
|
||||
bitrate = frmlen * sf / frame_samples / (1000 / 8);
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
/* Get Encode Quality Mode index property */
|
||||
DECLFUNC P_LDACBT_EQMID_PROPERTY ldacBT_get_eqmid_conv_tbl ( int eqmid )
|
||||
{
|
||||
int i, tbl_size;
|
||||
P_LDACBT_EQMID_PROPERTY pEqmIdProp;
|
||||
|
||||
pEqmIdProp = (P_LDACBT_EQMID_PROPERTY)tbl_ldacbt_eqmid_property;
|
||||
tbl_size = (int)(sizeof(tbl_ldacbt_eqmid_property)/sizeof(tbl_ldacbt_eqmid_property[0]));
|
||||
/* Search current eqmid */
|
||||
for( i = 0; i < tbl_size; ++i, ++pEqmIdProp ){
|
||||
if( pEqmIdProp->eqmid == eqmid ){
|
||||
return pEqmIdProp;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get altered Encode Quality Mode index */
|
||||
DECLFUNC int ldacBT_get_altered_eqmid ( HANDLE_LDAC_BT hLdacBT, int priority )
|
||||
{
|
||||
int i, eqmid_0, eqmid_1, eqmid_new, tbl_size;
|
||||
if( priority == 0 ){ return LDACBT_E_FAIL; }
|
||||
switch( hLdacBT->tx.pkt_type ){
|
||||
case _2_DH5:
|
||||
break;
|
||||
default:
|
||||
return LDACBT_E_FAIL;
|
||||
}
|
||||
tbl_size = (int)(sizeof(tbl_ldacbt_eqmid_property)/sizeof(tbl_ldacbt_eqmid_property[0]));
|
||||
/* Search target eqmid */
|
||||
for( i = 0; i < tbl_size; ++i ){
|
||||
if( tbl_ldacbt_eqmid_property[i].eqmid == hLdacBT->tgt_eqmid ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
eqmid_0 = i;
|
||||
eqmid_1 = eqmid_0 - priority;
|
||||
if( eqmid_1 < 0 ){ return LDACBT_E_FAIL; }
|
||||
if( eqmid_1 >= tbl_size ){ return LDACBT_E_FAIL; }
|
||||
|
||||
eqmid_new = tbl_ldacbt_eqmid_property[eqmid_1].eqmid;
|
||||
for( i = 0; i < tbl_size; ++i ){
|
||||
if( tbl_ldacbt_eqmid_property[i].eqmid == LDACBT_LIMIT_ALTER_EQMID_PRIORITY ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( eqmid_1 > i ){ return LDACBT_E_FAIL; }
|
||||
return eqmid_new;
|
||||
|
||||
}
|
||||
|
||||
/* Get LDAC bitrate info from Encode Quality Mode Index */
|
||||
DECLFUNC P_LDACBT_CONFIG ldacBT_get_config( int ldac_bt_mode, int pkt_type )
|
||||
{
|
||||
int i, tbl_size, ldac_mode_id;
|
||||
P_LDACBT_EQMID_PROPERTY pEqmIdProp;
|
||||
P_LDACBT_CONFIG pCfg;
|
||||
|
||||
if( (pEqmIdProp = ldacBT_get_eqmid_conv_tbl( ldac_bt_mode )) == NULL ){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( pkt_type == _2_DH5 ){ ldac_mode_id = pEqmIdProp->id_for_2DH5;}
|
||||
else{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCfg = (P_LDACBT_CONFIG)tbl_ldacbt_config;
|
||||
tbl_size = (int)(sizeof(tbl_ldacbt_config)/sizeof(tbl_ldacbt_config[0]));
|
||||
for( i = 0; i < tbl_size; ++i, ++pCfg ){
|
||||
if( ldac_mode_id == pCfg->id ){
|
||||
return pCfg;
|
||||
}
|
||||
}
|
||||
return NULL; /* not found */
|
||||
}
|
||||
|
||||
/* Get Encode Quality Mode Index from framelength */
|
||||
DECLFUNC int ldacBT_get_eqmid_from_frmlen( int frmlen, int nch, int flgFrmHdr, int pktType )
|
||||
{
|
||||
int i, n, eqmid;
|
||||
P_LDACBT_CONFIG pCfg;
|
||||
|
||||
if( flgFrmHdr ){
|
||||
frmlen += LDACBT_FRMHDRBYTES;
|
||||
}
|
||||
if( nch > 0 ){
|
||||
frmlen /= nch;
|
||||
}
|
||||
|
||||
eqmid = LDACBT_EQMID_END;
|
||||
n = (int)(sizeof(tbl_ldacbt_eqmid_property)/sizeof(tbl_ldacbt_eqmid_property[0]));
|
||||
for( i = 0; i < n; ++i ){
|
||||
if( (pCfg = ldacBT_get_config( tbl_ldacbt_eqmid_property[i].eqmid, pktType )) != NULL ){
|
||||
if( frmlen >= pCfg->frmlen_1ch){
|
||||
eqmid = tbl_ldacbt_eqmid_property[i].eqmid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return eqmid;
|
||||
}
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LDACBT_INTERNAL_H_
|
||||
#define _LDACBT_INTERNAL_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include "struct_ldac.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Function declaration */
|
||||
#define DECLFUNC static
|
||||
|
||||
/* Limit for alter EQMID process */
|
||||
#define LDACBT_LIMIT_ALTER_EQMID_PRIORITY LDACBT_EQMID_MQ
|
||||
|
||||
|
||||
#include "ldaclib.h"
|
||||
#include "ldacBT.h"
|
||||
#include "ldacBT_ex.h"
|
||||
|
||||
/* macro value */
|
||||
/* The size of LDAC transport header. Unit:Byte. */
|
||||
#define LDACBT_FRMHDRBYTES LDAC_FRMHDRBYTES
|
||||
/* The Maximum number of frames that can transrate in one packet.(LDAC A2DP spec) */
|
||||
#define LDACBT_NFRM_TX_MAX 15
|
||||
/* Lowest Common Multiple of (2,3,4)Bytes * 2ch * 256samples */
|
||||
#define LDACBT_ENC_PCM_BUF_SZ 6144
|
||||
/* The maximum pcm word length allowed. Unit:Byte */
|
||||
#define LDACBT_PCM_WLEN_MAX 4
|
||||
/* The size of LDACBT_TRANSPORT_FRM_BUF's buffer. Unit:Byte */
|
||||
#define LDACBT_ENC_STREAM_BUF_SZ 1024
|
||||
/* The size of rtp header and so on. Unit:Byte */
|
||||
/* = sizeof(struct rtp_header) + sizeof(struct rtp_payload) + 1 (scms-t). */
|
||||
#define LDACBT_TX_HEADER_SIZE 18
|
||||
/* The MTU size required for LDAC A2DP streaming. */
|
||||
#define LDACBT_MTU_REQUIRED 679
|
||||
#define LDACBT_MTU_3DH5 (990+LDACBT_TX_HEADER_SIZE)
|
||||
|
||||
/* The state for alter operation */
|
||||
#define LDACBT_ALTER_OP__NON 0
|
||||
#define LDACBT_ALTER_OP__ACTIVE 1
|
||||
#define LDACBT_ALTER_OP__STANDBY 2
|
||||
#define LDACBT_ALTER_OP__FLASH 9
|
||||
|
||||
/* other */
|
||||
#ifndef LDACBT_S_OK
|
||||
#define LDACBT_S_OK (0)
|
||||
#endif
|
||||
#ifndef LDACBT_E_FAIL
|
||||
#define LDACBT_E_FAIL (-1)
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef UNSET
|
||||
#define UNSET -1
|
||||
#endif
|
||||
#define LDACBT_GET_LDACLIB_ERROR_CODE 9999
|
||||
|
||||
/* The index for A2DP packets */
|
||||
enum {
|
||||
___DH1, ___DH3, ___DH5, /* basic rate */
|
||||
_2_DH1, _2_DH3, _2_DH5, /* EDR2M */
|
||||
_3_DH1, _3_DH3, _3_DH5, /* EDR3M */
|
||||
};
|
||||
|
||||
/* The state for LDACBT handle processing mode. */
|
||||
typedef enum {
|
||||
LDACBT_PROCMODE_UNSET = -1,
|
||||
LDACBT_PROCMODE_ENCODE = 1,
|
||||
LDACBT_PROCMODE_DECODE = 2,
|
||||
} LDACBT_PROCMODE;
|
||||
|
||||
/* Structs */
|
||||
/* The structure for the property of EQMID. */
|
||||
typedef struct _st_ldacbt_eqmid_property
|
||||
{
|
||||
int eqmid;
|
||||
char strModeName[4];
|
||||
int id_for_2DH5;
|
||||
} LDACBT_EQMID_PROPERTY, * P_LDACBT_EQMID_PROPERTY;
|
||||
|
||||
/* The structure for the configuration of LDAC. */
|
||||
typedef struct _st_ldacbt_config
|
||||
{
|
||||
int id;
|
||||
int nfrm_in_pkt; /* number of ldac frame in packet */
|
||||
int frmlen; /* ldac frame length */
|
||||
int frmlen_1ch; /* ldac frame length per channel */
|
||||
} LDACBT_CONFIG, * P_LDACBT_CONFIG;
|
||||
|
||||
/* The structure for the pcm information. */
|
||||
typedef struct _ldacbt_pcm_info {
|
||||
int sf; /* sampling frequency */
|
||||
int ch; /* number of channel */
|
||||
int wl;
|
||||
LDACBT_SMPL_FMT_T fmt; /* sample format */
|
||||
} LDACBT_PCM_INFO;
|
||||
|
||||
/* The structure for the A2DP streaming. */
|
||||
typedef struct _ldacbt_tx_info {
|
||||
int mtu;
|
||||
int tx_size; /* size for ldac stream */
|
||||
int pkt_type; /* packet type */
|
||||
int pkt_hdr_sz; /* packet header size */
|
||||
int nfrm_in_pkt; /* number of ldac frame in packet */
|
||||
} LDACBT_TX_INFO;
|
||||
/* The structure for the ldac_transport_frame sequence. */
|
||||
typedef struct _ldacbt_transport_frame_buf {
|
||||
unsigned char buf[LDACBT_ENC_STREAM_BUF_SZ];
|
||||
int used;
|
||||
int nfrm_in;
|
||||
} LDACBT_TRANSPORT_FRM_BUF;
|
||||
/* The structure of ring buffer for the input PCM. */
|
||||
typedef struct _ldacbt_pcm_ring_buf {
|
||||
char buf[LDACBT_ENC_PCM_BUF_SZ];
|
||||
int wp;
|
||||
int rp;
|
||||
int nsmpl;
|
||||
} LDACBT_PCM_RING_BUF;
|
||||
|
||||
/* The LDACBT handle. */
|
||||
typedef struct _st_ldacbt_handle {
|
||||
HANDLE_LDAC hLDAC;
|
||||
LDACBT_PROCMODE proc_mode;
|
||||
int error_code;
|
||||
int error_code_api;
|
||||
/* common */
|
||||
/* pcm */
|
||||
LDACBT_PCM_INFO pcm;
|
||||
/* tx */
|
||||
LDACBT_TX_INFO tx;
|
||||
/* ldaclib config */
|
||||
int frm_samples; /* frame samples */
|
||||
int sfid; /* sampling frequency index */
|
||||
int nshift;
|
||||
int flg_encode_flushed;
|
||||
int frm_status;
|
||||
int frmlen; /* Frame Length */
|
||||
int frmlen_tx; /* Frame Length with transport header */
|
||||
int bitrate;
|
||||
|
||||
int eqmid; /* Encode Quality Mode Index */
|
||||
/* for alter frame length */
|
||||
int tgt_eqmid; /* target Encode Quality Mode Index */
|
||||
int tgt_nfrm_in_pkt;/* target number of frame in packet */
|
||||
int tgt_frmlen; /* target frame length */
|
||||
int stat_alter_op; /* status of alter operation */
|
||||
|
||||
int cm; /* Channel Mode */
|
||||
int cci; /* Channel Config Index */
|
||||
int transport; /* Transport Stream ( with frame header) */
|
||||
/* buffer for "ldac_transport_frame" sequence */
|
||||
LDACBT_TRANSPORT_FRM_BUF ldac_trns_frm_buf;
|
||||
/* buffer for input pcm */
|
||||
LDACBT_PCM_RING_BUF pcmring;
|
||||
|
||||
/* work buffer for LDACLIB I/O */
|
||||
char **pp_pcm;
|
||||
char *ap_pcm[LDAC_PRCNCH];
|
||||
char a_pcm[LDAC_PRCNCH * LDACBT_MAX_LSU * LDACBT_PCM_WLEN_MAX];
|
||||
} STRUCT_LDACBT_HANDLE;
|
||||
|
||||
|
||||
|
||||
/* subfunctions */
|
||||
DECLFUNC void ldacBT_param_clear(HANDLE_LDAC_BT hLdacBT);
|
||||
DECLFUNC int ldacBT_check_ldaclib_error_code(HANDLE_LDAC_BT hLdacBT);
|
||||
DECLFUNC int ldacBT_assert_cm( int cm );
|
||||
DECLFUNC int ldacBT_assert_cci( int cci );
|
||||
DECLFUNC int ldacBT_assert_sample_format( LDACBT_SMPL_FMT_T fmt );
|
||||
DECLFUNC int ldacBT_assert_pcm_sampling_freq( int sf );
|
||||
DECLFUNC int ldacBT_assert_mtu( int mtu );
|
||||
DECLFUNC int ldacBT_assert_eqmid( int eqmid );
|
||||
DECLFUNC void ldacBT_set_eqmid_core( HANDLE_LDAC_BT hLdacBT, int eqmid );
|
||||
DECLFUNC void ldacBT_prepare_pcm_encode( void *pbuff, char **ap_pcm, int nsmpl, int nch,
|
||||
LDACBT_SMPL_FMT_T fmt );
|
||||
DECLFUNC int ldacBT_frmlen_to_bitrate( int frmlen, int flgFrmHdr, int sf, int frame_samples );
|
||||
DECLFUNC int ldacBT_cm_to_cci( int cm );
|
||||
DECLFUNC int ldacBT_cci_to_cm( int cci );
|
||||
DECLFUNC int ldacBT_get_altered_eqmid ( HANDLE_LDAC_BT hLdacBT, int priority );
|
||||
DECLFUNC int ldacBT_get_eqmid_from_frmlen( int frmlen, int nch, int flgFrmHdr, int pktType );
|
||||
DECLFUNC int ldacBT_update_frmlen(HANDLE_LDAC_BT hLdacBT, int frmlen);
|
||||
DECLFUNC P_LDACBT_EQMID_PROPERTY ldacBT_get_eqmid_conv_tbl ( int ldac_bt_mode );
|
||||
DECLFUNC P_LDACBT_CONFIG ldacBT_get_config( int ldac_bt_mode, int pkt_type );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _LDACBT_INTERNAL_H_ */
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/* Common Files */
|
||||
#include "tables_ldac.c"
|
||||
#ifndef _32BIT_FIXED_POINT
|
||||
#include "tables_sigproc_ldac.c"
|
||||
#include "setpcm_ldac.c"
|
||||
#else /* _32BIT_FIXED_POINT */
|
||||
#include "tables_sigproc_fixp_ldac.c"
|
||||
#include "setpcm_fixp_ldac.c"
|
||||
#include "func_fixp_ldac.c"
|
||||
#endif /* _32BIT_FIXED_POINT */
|
||||
#include "bitalloc_sub_ldac.c"
|
||||
#include "memory_ldac.c"
|
||||
#include "ldaclib_api.c"
|
||||
|
||||
/* Encoder Files */
|
||||
#ifndef _32BIT_FIXED_POINT
|
||||
#include "mdct_ldac.c"
|
||||
#include "sigana_ldac.c"
|
||||
#include "quant_ldac.c"
|
||||
#else /* _32BIT_FIXED_POINT */
|
||||
#include "mdct_fixp_ldac.c"
|
||||
#include "sigana_fixp_ldac.c"
|
||||
#include "quant_fixp_ldac.c"
|
||||
#endif /* _32BIT_FIXED_POINT */
|
||||
#include "bitalloc_ldac.c"
|
||||
#include "pack_ldac.c"
|
||||
#include "encode_ldac.c"
|
||||
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Copyright (C) 2013 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LDACLIB_H
|
||||
#define _LDACLIB_H
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/***************************************************************************************************
|
||||
Macro Definitions
|
||||
***************************************************************************************************/
|
||||
#define LDAC_HOST_ENDIAN_LITTLE
|
||||
|
||||
#define LDAC_PRCNCH 2
|
||||
#define LDAC_FRMHDRBYTES 3
|
||||
#define LDAC_CONFIGBYTES 4
|
||||
|
||||
typedef int LDAC_RESULT;
|
||||
#define LDAC_S_OK ((LDAC_RESULT)0x00000000L)
|
||||
#define LDAC_S_FALSE ((LDAC_RESULT)0x00000001L)
|
||||
#define LDAC_E_UNEXPECTED ((LDAC_RESULT)0x8000FFFFL)
|
||||
#define LDAC_E_OUTOFMEMORY ((LDAC_RESULT)0x8007000EL)
|
||||
#define LDAC_E_INVALIDARG ((LDAC_RESULT)0x80070057L)
|
||||
#define LDAC_E_FAIL ((LDAC_RESULT)0x80004005L)
|
||||
#define LDAC_E_NOTIMPL ((LDAC_RESULT)0x80004001L)
|
||||
|
||||
#define LDAC_SUCCEEDED(result) ((LDAC_RESULT)(result)>=0)
|
||||
#define LDAC_FAILED(result) ((LDAC_RESULT)(result)<0)
|
||||
|
||||
#define DECLSPEC
|
||||
|
||||
typedef struct _handle_ldac_struct *HANDLE_LDAC;
|
||||
|
||||
typedef enum {
|
||||
LDAC_SMPL_FMT_NONE,
|
||||
LDAC_SMPL_FMT_S08,
|
||||
LDAC_SMPL_FMT_S16,
|
||||
LDAC_SMPL_FMT_S24,
|
||||
LDAC_SMPL_FMT_S32,
|
||||
LDAC_SMPL_FMT_F32,
|
||||
LDAC_SMPL_FMT_NUM,
|
||||
LDAC_SMPL_FMT_MAX = 0x7fffffff
|
||||
} LDAC_SMPL_FMT_T;
|
||||
|
||||
/***************************************************************************************************
|
||||
Function Declarations
|
||||
***************************************************************************************************/
|
||||
/* Common API Functions */
|
||||
DECLSPEC int ldaclib_get_version(void);
|
||||
DECLSPEC int ldaclib_get_major_version(void);
|
||||
DECLSPEC int ldaclib_get_minor_version(void);
|
||||
DECLSPEC int ldaclib_get_branch_version(void);
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_sampling_rate_index(int, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_sampling_rate(int, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_frame_samples(int, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_nlnn(int, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_channel(int, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_channel_config_index(int, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_check_nlnn_shift(int, int);
|
||||
|
||||
DECLSPEC HANDLE_LDAC ldaclib_get_handle(void);
|
||||
DECLSPEC LDAC_RESULT ldaclib_free_handle(HANDLE_LDAC);
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_config_info(HANDLE_LDAC, int, int, int, int);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_config_info(HANDLE_LDAC, int *, int *, int *, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_frame_header(HANDLE_LDAC, unsigned char *, int, int, int, int);
|
||||
|
||||
/* Encoder API Functions */
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_encode_setting(int, int, int *, int *, int *, int *, int *, int *, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_encode_frame_length(HANDLE_LDAC, int);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_encode_frame_length(HANDLE_LDAC, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_encode_info(HANDLE_LDAC, int, int, int, int, int, int, int);
|
||||
DECLSPEC LDAC_RESULT ldaclib_init_encode(HANDLE_LDAC);
|
||||
DECLSPEC LDAC_RESULT ldaclib_free_encode(HANDLE_LDAC);
|
||||
DECLSPEC LDAC_RESULT ldaclib_encode(HANDLE_LDAC, char *[], LDAC_SMPL_FMT_T, unsigned char *, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_flush_encode(HANDLE_LDAC, LDAC_SMPL_FMT_T, unsigned char *, int *);
|
||||
|
||||
|
||||
/* Error Code Dispatch */
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_error_code(HANDLE_LDAC, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_internal_error_code(HANDLE_LDAC, int *);
|
||||
DECLSPEC LDAC_RESULT ldaclib_clear_error_code(HANDLE_LDAC);
|
||||
DECLSPEC LDAC_RESULT ldaclib_clear_internal_error_code(HANDLE_LDAC);
|
||||
|
||||
/***************************************************************************************************
|
||||
Error Code Definitions
|
||||
***************************************************************************************************/
|
||||
#define LDAC_ERR_NONE 0
|
||||
|
||||
/* Non Fatal Error */
|
||||
#define LDAC_ERR_NON_FATAL 1
|
||||
|
||||
/* Non Fatal Error (Block Level) */
|
||||
#define LDAC_ERR_BIT_ALLOCATION 5
|
||||
|
||||
/* Non Fatal Error (Handle Level) */
|
||||
#define LDAC_ERR_NOT_IMPLEMENTED 128
|
||||
#define LDAC_ERR_NON_FATAL_ENCODE 132
|
||||
|
||||
/* Fatal Error */
|
||||
#define LDAC_ERR_FATAL 256
|
||||
|
||||
/* Fatal Error (Block Level) */
|
||||
#define LDAC_ERR_SYNTAX_BAND 260
|
||||
#define LDAC_ERR_SYNTAX_GRAD_A 261
|
||||
#define LDAC_ERR_SYNTAX_GRAD_B 262
|
||||
#define LDAC_ERR_SYNTAX_GRAD_C 263
|
||||
#define LDAC_ERR_SYNTAX_GRAD_D 264
|
||||
#define LDAC_ERR_SYNTAX_GRAD_E 265
|
||||
#define LDAC_ERR_SYNTAX_IDSF 266
|
||||
#define LDAC_ERR_SYNTAX_SPEC 267
|
||||
|
||||
#define LDAC_ERR_BIT_PACKING 280
|
||||
|
||||
#define LDAC_ERR_ALLOC_MEMORY 300
|
||||
|
||||
/* Fatal Error (Handle Level) */
|
||||
#define LDAC_ERR_FATAL_HANDLE 512
|
||||
|
||||
#define LDAC_ERR_ILL_SYNCWORD 516
|
||||
#define LDAC_ERR_ILL_SMPL_FORMAT 517
|
||||
|
||||
#define LDAC_ERR_ASSERT_SAMPLING_RATE 530
|
||||
#define LDAC_ERR_ASSERT_SUP_SAMPLING_RATE 531
|
||||
#define LDAC_ERR_CHECK_SAMPLING_RATE 532
|
||||
#define LDAC_ERR_ASSERT_CHANNEL_CONFIG 533
|
||||
#define LDAC_ERR_CHECK_CHANNEL_CONFIG 534
|
||||
#define LDAC_ERR_ASSERT_FRAME_LENGTH 535
|
||||
#define LDAC_ERR_ASSERT_SUP_FRAME_LENGTH 536
|
||||
#define LDAC_ERR_ASSERT_FRAME_STATUS 537
|
||||
#define LDAC_ERR_ASSERT_NSHIFT 538
|
||||
|
||||
#define LDAC_ERR_ENC_INIT_ALLOC 550
|
||||
#define LDAC_ERR_ENC_ILL_GRADMODE 551
|
||||
#define LDAC_ERR_ENC_ILL_GRADPAR_A 552
|
||||
#define LDAC_ERR_ENC_ILL_GRADPAR_B 553
|
||||
#define LDAC_ERR_ENC_ILL_GRADPAR_C 554
|
||||
#define LDAC_ERR_ENC_ILL_GRADPAR_D 555
|
||||
#define LDAC_ERR_ENC_ILL_NBANDS 556
|
||||
#define LDAC_ERR_PACK_BLOCK_FAILED 557
|
||||
|
||||
#define LDAC_ERR_DEC_INIT_ALLOC 570
|
||||
#define LDAC_ERR_INPUT_BUFFER_SIZE 571
|
||||
#define LDAC_ERR_UNPACK_BLOCK_FAILED 572
|
||||
#define LDAC_ERR_UNPACK_BLOCK_ALIGN 573
|
||||
#define LDAC_ERR_UNPACK_FRAME_ALIGN 574
|
||||
#define LDAC_ERR_FRAME_LENGTH_OVER 575
|
||||
#define LDAC_ERR_FRAME_ALIGN_OVER 576
|
||||
|
||||
#define LDAC_ERR_FRAME_LIMIT 998
|
||||
#define LDAC_ERR_TIME_EXPIRED 999
|
||||
|
||||
#define LDAC_ERROR(err) ((LDAC_ERR_NON_FATAL) <= (err) ? 1 : 0)
|
||||
#define LDAC_FATAL_ERROR(err) ((LDAC_ERR_FATAL) <= (err) ? 1 : 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* _LDACLIB_H */
|
||||
|
|
@ -0,0 +1,810 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldaclib.h"
|
||||
#include "ldac.h"
|
||||
|
||||
#define LDACLIB_MAJOR_VERSION 01
|
||||
#define LDACLIB_MINOR_VERSION 00
|
||||
#define LDACLIB_BRANCH_VERSION 00
|
||||
|
||||
/***************************************************************************************************
|
||||
Local Assert Functions
|
||||
***************************************************************************************************/
|
||||
static int ldaclib_assert_sampling_rate_index(
|
||||
int smplrate_id)
|
||||
{
|
||||
if ((LDAC_SMPLRATEID_0 <= smplrate_id) && (smplrate_id < LDAC_NSMPLRATEID)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_supported_sampling_rate_index(
|
||||
int smplrate_id)
|
||||
{
|
||||
if ((LDAC_SMPLRATEID_0 <= smplrate_id) && (smplrate_id < LDAC_NSUPSMPLRATEID)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_channel_config_index(
|
||||
int chconfig_id)
|
||||
{
|
||||
if ((chconfig_id == LDAC_CHCONFIGID_MN)
|
||||
|| (chconfig_id == LDAC_CHCONFIGID_DL) || (chconfig_id == LDAC_CHCONFIGID_ST)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_channel(
|
||||
int ch)
|
||||
{
|
||||
if ((ch == LDAC_CHANNEL_1CH) || (ch == LDAC_CHANNEL_2CH)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_frame_length(
|
||||
int frame_length)
|
||||
{
|
||||
if ((0 < frame_length) && (frame_length <= LDAC_MAXNBYTES)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_supported_frame_length(
|
||||
int frame_length,
|
||||
int chconfig_id)
|
||||
{
|
||||
if (chconfig_id == LDAC_CHCONFIGID_MN) {
|
||||
if ((LDAC_MINSUPNBYTES/2 <= frame_length) && (frame_length <= LDAC_MAXSUPNBYTES/2)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
else if ((chconfig_id == LDAC_CHCONFIGID_DL) || (chconfig_id == LDAC_CHCONFIGID_ST)) {
|
||||
if ((LDAC_MINSUPNBYTES <= frame_length) && (frame_length <= LDAC_MAXSUPNBYTES)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_frame_status(
|
||||
int frame_status)
|
||||
{
|
||||
if ((LDAC_FRMSTAT_LEV_0 <= frame_status) && (frame_status <= LDAC_FRMSTAT_LEV_3)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_nlnn_shift(
|
||||
int nlnn_shift)
|
||||
{
|
||||
if ((-2 <= nlnn_shift) && (nlnn_shift < LDAC_NSFTSTEP-2)) {
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static int ldaclib_assert_sample_format(
|
||||
LDAC_SMPL_FMT_T sample_format)
|
||||
{
|
||||
#ifndef _32BIT_FIXED_POINT
|
||||
if ((LDAC_SMPL_FMT_S16 <= sample_format) && (sample_format <= LDAC_SMPL_FMT_F32)) {
|
||||
#else /* _32BIT_FIXED_POINT */
|
||||
if ((LDAC_SMPL_FMT_S16 <= sample_format) && (sample_format <= LDAC_SMPL_FMT_S32)) {
|
||||
#endif /* _32BIT_FIXED_POINT */
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
else {
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Common API Functions
|
||||
***************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Library Version
|
||||
***************************************************************************************************/
|
||||
DECLSPEC int ldaclib_get_version(void) {
|
||||
return (LDACLIB_MAJOR_VERSION<<16) | (LDACLIB_MINOR_VERSION<<8) | LDACLIB_BRANCH_VERSION;
|
||||
}
|
||||
|
||||
DECLSPEC int ldaclib_get_major_version(void) {
|
||||
return LDACLIB_MAJOR_VERSION;
|
||||
}
|
||||
|
||||
DECLSPEC int ldaclib_get_minor_version(void) {
|
||||
return LDACLIB_MINOR_VERSION;
|
||||
}
|
||||
|
||||
DECLSPEC int ldaclib_get_branch_version(void) {
|
||||
return LDACLIB_BRANCH_VERSION;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Basic Parameters
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_sampling_rate_index(
|
||||
int smplrate,
|
||||
int *p_smplrate_id)
|
||||
{
|
||||
if (smplrate == 44100) {
|
||||
*p_smplrate_id = LDAC_SMPLRATEID_0;
|
||||
}
|
||||
else if (smplrate == 48000) {
|
||||
*p_smplrate_id = LDAC_SMPLRATEID_1;
|
||||
}
|
||||
else if (smplrate == 88200) {
|
||||
*p_smplrate_id = LDAC_SMPLRATEID_2;
|
||||
}
|
||||
else if (smplrate == 96000) {
|
||||
*p_smplrate_id = LDAC_SMPLRATEID_3;
|
||||
}
|
||||
else {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_sampling_rate(
|
||||
int smplrate_id,
|
||||
int *p_smplrate)
|
||||
{
|
||||
if (!ldaclib_assert_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
if (!ldaclib_assert_supported_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
*p_smplrate = ga_smplrate_ldac[smplrate_id];
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_frame_samples(
|
||||
int smplrate_id,
|
||||
int *p_framesmpls)
|
||||
{
|
||||
if (!ldaclib_assert_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
if (!ldaclib_assert_supported_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
*p_framesmpls = ga_framesmpls_ldac[smplrate_id];
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_nlnn(
|
||||
int smplrate_id,
|
||||
int *p_nlnn)
|
||||
{
|
||||
if (!ldaclib_assert_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
if (!ldaclib_assert_supported_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
*p_nlnn = ga_ln_framesmpls_ldac[smplrate_id];
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_channel(
|
||||
int chconfig_id,
|
||||
int *p_ch)
|
||||
{
|
||||
if (!ldaclib_assert_channel_config_index(chconfig_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
*p_ch = ga_ch_ldac[chconfig_id];
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_channel_config_index(
|
||||
int ch,
|
||||
int *p_chconfig_id)
|
||||
{
|
||||
if (!ldaclib_assert_channel(ch)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
*p_chconfig_id = ga_chconfig_id_ldac[ch];
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_check_nlnn_shift(
|
||||
int smplrate_id,
|
||||
int nlnn_shift)
|
||||
{
|
||||
if (!ldaclib_assert_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
if (!ldaclib_assert_supported_sampling_rate_index(smplrate_id)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
if (!ldaclib_assert_nlnn_shift(nlnn_shift)) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (gaa_nlnn_shift_ldac[smplrate_id][nlnn_shift+2] < 0) {
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Handle
|
||||
***************************************************************************************************/
|
||||
DECLSPEC HANDLE_LDAC ldaclib_get_handle(
|
||||
void)
|
||||
{
|
||||
HANDLE_LDAC hData;
|
||||
|
||||
hData = (HANDLE_LDAC)malloc(sizeof(HANDLE_LDAC_STRUCT));
|
||||
if (hData != (HANDLE_LDAC)NULL) {
|
||||
clear_data_ldac(hData, sizeof(HANDLE_LDAC_STRUCT));
|
||||
hData->sfinfo.p_mempos = (char *)NULL;
|
||||
hData->error_code = LDAC_ERR_NONE;
|
||||
}
|
||||
|
||||
return hData;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Free Handle
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_free_handle(
|
||||
HANDLE_LDAC hData)
|
||||
{
|
||||
if (hData != (HANDLE_LDAC)NULL) {
|
||||
if (hData->sfinfo.p_mempos != (char *)NULL) {
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
free(hData);
|
||||
}
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Set Configuration Information
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_config_info(
|
||||
HANDLE_LDAC hData,
|
||||
int smplrate_id,
|
||||
int chconfig_id,
|
||||
int frame_length,
|
||||
int frame_status)
|
||||
{
|
||||
CFG *p_cfg = &hData->sfinfo.cfg;
|
||||
|
||||
if (!ldaclib_assert_sampling_rate_index(smplrate_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_SAMPLING_RATE;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_supported_sampling_rate_index(smplrate_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_SUP_SAMPLING_RATE;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_channel_config_index(chconfig_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_CHANNEL_CONFIG;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_frame_length(frame_length)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_FRAME_LENGTH;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_supported_frame_length(frame_length, chconfig_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_SUP_FRAME_LENGTH;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_frame_status(frame_status)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_FRAME_STATUS;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
p_cfg->smplrate_id = smplrate_id;
|
||||
p_cfg->chconfig_id = chconfig_id;
|
||||
p_cfg->frame_length = frame_length;
|
||||
p_cfg->frame_status = frame_status;
|
||||
|
||||
ldaclib_get_channel(chconfig_id, &p_cfg->ch);
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Configuration Information
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_config_info(
|
||||
HANDLE_LDAC hData,
|
||||
int *p_smplrate_id,
|
||||
int *p_chconfig_id,
|
||||
int *p_frame_length,
|
||||
int *p_frame_status)
|
||||
{
|
||||
CFG *p_cfg = &hData->sfinfo.cfg;
|
||||
|
||||
*p_smplrate_id = p_cfg->smplrate_id;
|
||||
*p_chconfig_id = p_cfg->chconfig_id;
|
||||
*p_frame_length = p_cfg->frame_length;
|
||||
*p_frame_status = p_cfg->frame_status;
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Set Frame Header
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_frame_header(
|
||||
HANDLE_LDAC hData,
|
||||
unsigned char *p_stream,
|
||||
int smplrate_id,
|
||||
int chconfig_id,
|
||||
int frame_length,
|
||||
int frame_status)
|
||||
{
|
||||
if (!ldaclib_assert_sampling_rate_index(smplrate_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_SAMPLING_RATE;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_supported_sampling_rate_index(smplrate_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_SUP_SAMPLING_RATE;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_channel_config_index(chconfig_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_CHANNEL_CONFIG;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_frame_length(frame_length)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_FRAME_LENGTH;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_supported_frame_length(frame_length, chconfig_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_SUP_FRAME_LENGTH;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_frame_status(frame_status)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_FRAME_STATUS;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
pack_frame_header_ldac(smplrate_id, chconfig_id, frame_length, frame_status,
|
||||
(STREAM *)p_stream);
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Encoder API Functions
|
||||
***************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Encoder Setting
|
||||
***************************************************************************************************/
|
||||
#define LDAC_ENC_NSETTING 15
|
||||
#define LDAC_ENC_NPROPERTY 9
|
||||
|
||||
static const int saa_encode_setting_ldac[LDAC_ENC_NSETTING][LDAC_ENC_NPROPERTY] = {
|
||||
{0, 512, 17, 0, 28, 44, 8, 24, 0},
|
||||
{0, 256, 17, 0, 28, 44, 6, 22, 0},
|
||||
#ifdef MODIFY_LDAC_ENC_SETTING_FOR_ABR_DEBUG // See file "ldacBT_abr.h" for description
|
||||
{0, 164, 16, 0, 18, 32, 7, 23, 0},
|
||||
{0, 110, 8, 0, 16, 32, 10, 31, 0},
|
||||
{0, 82, 6, 0, 16, 32, 12, 31, 0},
|
||||
{0, 66, 4, 0, 14, 26, 12, 31, 0},
|
||||
{0, 54, 2, 0, 14, 26, 12, 31, 0},
|
||||
{0, 46, 2, 1, 10, 26, 12, 31, 0},
|
||||
{0, 40, 2, 2, 10, 26, 12, 31, 0},
|
||||
{0, 36, 2, 2, 8, 26, 12, 31, 0},
|
||||
{0, 32, 2, 2, 8, 26, 16, 31, 0},
|
||||
{0, 30, 2, 2, 4, 26, 16, 31, 0},
|
||||
{0, 26, 2, 3, 4, 26, 16, 31, 0},
|
||||
{0, 24, 2, 3, 4, 26, 16, 31, 0},
|
||||
#else
|
||||
{0, 164, 16, 0, 18, 32, 7, 23, 0},
|
||||
{0, 110, 13, 0, 16, 32, 10, 31, 0},
|
||||
{0, 82, 12, 0, 16, 32, 12, 31, 0},
|
||||
{0, 66, 11, 0, 14, 26, 12, 31, 0},
|
||||
{0, 54, 10, 0, 14, 26, 12, 31, 0},
|
||||
{0, 46, 9, 1, 10, 26, 12, 31, 0},
|
||||
{0, 40, 8, 2, 10, 26, 12, 31, 0},
|
||||
{0, 36, 7, 2, 8, 26, 12, 31, 0},
|
||||
{0, 32, 6, 2, 8, 26, 16, 31, 0},
|
||||
{0, 30, 5, 2, 4, 26, 16, 31, 0},
|
||||
{0, 26, 4, 3, 4, 26, 16, 31, 0},
|
||||
{0, 24, 3, 3, 4, 26, 16, 31, 0},
|
||||
#endif
|
||||
{0, 22, 2, 3, 4, 26, 16, 31, 0},
|
||||
};
|
||||
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_encode_setting(
|
||||
int nbytes_ch,
|
||||
int smplrate_id,
|
||||
int *p_nbands,
|
||||
int *p_grad_mode,
|
||||
int *p_grad_qu_l,
|
||||
int *p_grad_qu_h,
|
||||
int *p_grad_os_l,
|
||||
int *p_grad_os_h,
|
||||
int *p_abc_status)
|
||||
{
|
||||
int i, id;
|
||||
|
||||
id = LDAC_ENC_NSETTING-1;
|
||||
for (i = LDAC_ENC_NSETTING-1; i >= 0; i--) {
|
||||
if (nbytes_ch >= saa_encode_setting_ldac[i][1]) {
|
||||
id = i;
|
||||
}
|
||||
}
|
||||
|
||||
*p_nbands = min_ldac(saa_encode_setting_ldac[id][2], ga_max_nbands_ldac[smplrate_id]);
|
||||
*p_grad_mode = saa_encode_setting_ldac[id][3];
|
||||
*p_grad_qu_l = saa_encode_setting_ldac[id][4];
|
||||
*p_grad_qu_h = saa_encode_setting_ldac[id][5];
|
||||
*p_grad_os_l = saa_encode_setting_ldac[id][6];
|
||||
*p_grad_os_h = saa_encode_setting_ldac[id][7];
|
||||
*p_abc_status = saa_encode_setting_ldac[id][8];
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Set Frame Length
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_encode_frame_length(
|
||||
HANDLE_LDAC hData,
|
||||
int frame_length)
|
||||
{
|
||||
CFG *p_cfg = &hData->sfinfo.cfg;
|
||||
|
||||
if (!ldaclib_assert_frame_length(frame_length)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_FRAME_LENGTH;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (!ldaclib_assert_supported_frame_length(frame_length, p_cfg->chconfig_id)) {
|
||||
hData->error_code = LDAC_ERR_ASSERT_SUP_FRAME_LENGTH;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
p_cfg->frame_length = frame_length;
|
||||
|
||||
calc_initial_bits_ldac(&hData->sfinfo);
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Frame Length
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_encode_frame_length(
|
||||
HANDLE_LDAC hData,
|
||||
int *p_frame_length)
|
||||
{
|
||||
CFG *p_cfg = &hData->sfinfo.cfg;
|
||||
|
||||
*p_frame_length = p_cfg->frame_length;
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Set Information
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_set_encode_info(
|
||||
HANDLE_LDAC hData,
|
||||
int nbands,
|
||||
int grad_mode,
|
||||
int grad_qu_l,
|
||||
int grad_qu_h,
|
||||
int grad_os_l,
|
||||
int grad_os_h,
|
||||
int abc_status)
|
||||
{
|
||||
if ((nbands < LDAC_BAND_OFFSET) ||
|
||||
(ga_max_nbands_ldac[hData->sfinfo.cfg.smplrate_id] < nbands)) {
|
||||
hData->error_code = LDAC_ERR_ENC_ILL_NBANDS;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if ((grad_mode < LDAC_MODE_0) || (LDAC_MODE_3 < grad_mode)) {
|
||||
hData->error_code = LDAC_ERR_ENC_ILL_GRADMODE;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if (grad_mode == LDAC_MODE_0) {
|
||||
if ((grad_qu_l < 0) || (LDAC_MAXGRADQU <= grad_qu_l)) {
|
||||
hData->error_code = LDAC_ERR_ENC_ILL_GRADPAR_A;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if ((grad_qu_h < 1) || (LDAC_MAXGRADQU+1 <= grad_qu_h) || (grad_qu_h < grad_qu_l)) {
|
||||
hData->error_code = LDAC_ERR_ENC_ILL_GRADPAR_B;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
if ((grad_os_h < 0) || (LDAC_NIDSF <= grad_os_h)) {
|
||||
hData->error_code = LDAC_ERR_ENC_ILL_GRADPAR_C;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((grad_qu_l < 0) || (LDAC_DEFGRADQUH < grad_qu_l)) {
|
||||
hData->error_code = LDAC_ERR_ENC_ILL_GRADPAR_A;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if ((grad_os_l < 0) || (LDAC_NIDSF <= grad_os_l)) {
|
||||
hData->error_code = LDAC_ERR_ENC_ILL_GRADPAR_D;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
hData->nbands = nbands;
|
||||
hData->grad_mode = grad_mode;
|
||||
hData->grad_qu_l = grad_qu_l;
|
||||
hData->grad_os_l = grad_os_l;
|
||||
if (grad_mode == LDAC_MODE_0) {
|
||||
hData->grad_qu_h = grad_qu_h;
|
||||
hData->grad_os_h = grad_os_h;
|
||||
}
|
||||
else {
|
||||
hData->grad_qu_h = LDAC_DEFGRADQUH;
|
||||
hData->grad_os_h = LDAC_DEFGRADOSH;
|
||||
}
|
||||
hData->abc_status = abc_status;
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Initialize
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_init_encode(
|
||||
HANDLE_LDAC hData)
|
||||
{
|
||||
SFINFO *p_sfinfo = &hData->sfinfo;
|
||||
LDAC_RESULT result;
|
||||
|
||||
|
||||
ldaclib_get_nlnn(p_sfinfo->cfg.smplrate_id, &hData->nlnn);
|
||||
|
||||
set_mdct_table_ldac(hData->nlnn);
|
||||
|
||||
result = init_encode_ldac(p_sfinfo);
|
||||
if (result != LDAC_S_OK) {
|
||||
hData->error_code = LDAC_ERR_ENC_INIT_ALLOC;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Free
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_free_encode(
|
||||
HANDLE_LDAC hData)
|
||||
{
|
||||
if (hData->sfinfo.p_mempos == NULL) {
|
||||
free_encode_ldac(&hData->sfinfo);
|
||||
}
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Encode
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_encode(
|
||||
HANDLE_LDAC hData,
|
||||
char *ap_pcm[],
|
||||
LDAC_SMPL_FMT_T sample_format,
|
||||
unsigned char *p_stream,
|
||||
int *p_nbytes_used)
|
||||
{
|
||||
SFINFO *p_sfinfo = &hData->sfinfo;
|
||||
int loc = 0;
|
||||
int error_code;
|
||||
int frame_length;
|
||||
|
||||
|
||||
if (!ldaclib_assert_sample_format(sample_format)) {
|
||||
hData->error_code = LDAC_ERR_ILL_SMPL_FORMAT;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
frame_length = p_sfinfo->cfg.frame_length;
|
||||
clear_data_ldac(p_stream, frame_length*sizeof(unsigned char));
|
||||
|
||||
set_input_pcm_ldac(p_sfinfo, ap_pcm, sample_format, hData->nlnn);
|
||||
|
||||
proc_mdct_ldac(p_sfinfo, hData->nlnn);
|
||||
|
||||
p_sfinfo->cfg.frame_status = ana_frame_status_ldac(p_sfinfo, hData->nlnn);
|
||||
|
||||
error_code = encode_ldac(p_sfinfo, hData->nbands, hData->grad_mode,
|
||||
hData->grad_qu_l, hData->grad_qu_h, hData->grad_os_l, hData->grad_os_h,
|
||||
hData->abc_status);
|
||||
if (LDAC_ERROR(error_code) && !LDAC_FATAL_ERROR(error_code)) {
|
||||
int error_code2;
|
||||
error_code2 = pack_null_data_frame_ldac(p_sfinfo, (STREAM *)p_stream, &loc, p_nbytes_used);
|
||||
if (LDAC_FATAL_ERROR(error_code2)) {
|
||||
clear_data_ldac(p_stream, frame_length*sizeof(unsigned char));
|
||||
hData->error_code = error_code2;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
hData->error_code = error_code;
|
||||
return LDAC_S_FALSE;
|
||||
}
|
||||
|
||||
error_code = pack_raw_data_frame_ldac(p_sfinfo, (STREAM *)p_stream, &loc, p_nbytes_used);
|
||||
if (LDAC_FATAL_ERROR(error_code)) {
|
||||
int error_code2;
|
||||
loc = 0;
|
||||
clear_data_ldac(p_stream, frame_length*sizeof(unsigned char));
|
||||
error_code2 = pack_null_data_frame_ldac(p_sfinfo, (STREAM *)p_stream, &loc, p_nbytes_used);
|
||||
if (LDAC_FATAL_ERROR(error_code2)) {
|
||||
clear_data_ldac(p_stream, frame_length*sizeof(unsigned char));
|
||||
hData->error_code = error_code2;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
hData->error_code = error_code;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Flush Encode
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_flush_encode(
|
||||
HANDLE_LDAC hData,
|
||||
LDAC_SMPL_FMT_T sample_format,
|
||||
unsigned char *p_stream,
|
||||
int *p_nbytes_used)
|
||||
{
|
||||
LDAC_RESULT result;
|
||||
int ich;
|
||||
char *ap_buf[LDAC_PRCNCH];
|
||||
int a_buf[LDAC_MAXLSU*LDAC_PRCNCH];
|
||||
|
||||
if (!ldaclib_assert_sample_format(sample_format)) {
|
||||
hData->error_code = LDAC_ERR_ILL_SMPL_FORMAT;
|
||||
return LDAC_E_FAIL;
|
||||
}
|
||||
|
||||
clear_data_ldac(a_buf, (LDAC_MAXLSU*LDAC_PRCNCH)*sizeof(int));
|
||||
|
||||
for (ich = 0; ich < LDAC_PRCNCH; ich++) {
|
||||
ap_buf[ich] = (char *)(a_buf + ich * LDAC_MAXLSU);
|
||||
}
|
||||
|
||||
result = ldaclib_encode(hData, ap_buf, sample_format, p_stream, p_nbytes_used);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Error Code Dispatch
|
||||
***************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
Clear Error Code at Handle Level
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_clear_error_code(
|
||||
HANDLE_LDAC hData)
|
||||
{
|
||||
hData->error_code = LDAC_ERR_NONE;
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Error Code at Handle Level
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_error_code(
|
||||
HANDLE_LDAC hData,
|
||||
int *p_error_code)
|
||||
{
|
||||
*p_error_code = hData->error_code;
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Clear Error Code at Internal Block Level
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_clear_internal_error_code(
|
||||
HANDLE_LDAC hData)
|
||||
{
|
||||
hData->sfinfo.error_code = LDAC_ERR_NONE;
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Get Error Code at Internal Block Level
|
||||
***************************************************************************************************/
|
||||
DECLSPEC LDAC_RESULT ldaclib_get_internal_error_code(
|
||||
HANDLE_LDAC hData,
|
||||
int *p_error_code)
|
||||
{
|
||||
*p_error_code = hData->sfinfo.error_code;
|
||||
|
||||
return LDAC_S_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Process MDCT Core
|
||||
***************************************************************************************************/
|
||||
static void proc_mdct_core_ldac(
|
||||
INT32 *p_x,
|
||||
INT32 *p_y,
|
||||
int nlnn)
|
||||
{
|
||||
INT32 i, j, k;
|
||||
INT32 loop1, loop2;
|
||||
INT32 coef, index0, index1, offset;
|
||||
int nsmpl = npow2_ldac(nlnn);
|
||||
int shift;
|
||||
const int *p_p;
|
||||
const INT32 *p_w, *p_c, *p_s;
|
||||
INT32 a_work[LDAC_MAXLSU];
|
||||
INT32 g0, g1, g2, g3;
|
||||
|
||||
i = nlnn - LDAC_1FSLNN;
|
||||
p_w = gaa_fwin_ldac[i];
|
||||
p_c = gaa_wcos_ldac[i];
|
||||
p_s = gaa_wsin_ldac[i];
|
||||
p_p = gaa_perm_ldac[i];
|
||||
|
||||
/* Block Floating */
|
||||
shift = LDAC_C_BLKFLT - get_bit_length_ldac(get_absmax_ldac(p_x, nsmpl<<1)) - 1;
|
||||
if (shift < 0) {
|
||||
shift = 0;
|
||||
}
|
||||
|
||||
/* Windowing */
|
||||
if (LDAC_Q_MDCT_WIN-shift > 0){
|
||||
for (i = 0; i < nsmpl>>1; i++) {
|
||||
g0 = mul_rsftrnd_ldac(-p_x[3*nsmpl/2-1-i], p_w[nsmpl/2+i], LDAC_Q_MDCT_WIN-shift);
|
||||
g1 = mul_rsftrnd_ldac(-p_x[3*nsmpl/2+i], p_w[nsmpl/2-1-i], LDAC_Q_MDCT_WIN-shift);
|
||||
a_work[p_p[i]] = g0 + g1;
|
||||
|
||||
g0 = mul_rsftrnd_ldac(p_x[i], p_w[i], LDAC_Q_MDCT_WIN-shift);
|
||||
g1 = mul_rsftrnd_ldac(-p_x[nsmpl-1-i], p_w[nsmpl-1-i], LDAC_Q_MDCT_WIN-shift);
|
||||
a_work[p_p[nsmpl/2+i]] = g0 + g1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
for (i = 0; i < nsmpl>>1; i++) {
|
||||
g0 = mul_lsftrnd_ldac(-p_x[3*nsmpl/2-1-i], p_w[nsmpl/2+i], LDAC_Q_MDCT_WIN-shift);
|
||||
g1 = mul_lsftrnd_ldac(-p_x[3*nsmpl/2+i], p_w[nsmpl/2-1-i], LDAC_Q_MDCT_WIN-shift);
|
||||
a_work[p_p[i]] = g0 + g1;
|
||||
|
||||
g0 = mul_lsftrnd_ldac(p_x[i], p_w[i], LDAC_Q_MDCT_WIN-shift);
|
||||
g1 = mul_lsftrnd_ldac(-p_x[nsmpl-1-i], p_w[nsmpl-1-i], LDAC_Q_MDCT_WIN-shift);
|
||||
a_work[p_p[nsmpl/2+i]] = g0 + g1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Butterfly */
|
||||
coef = 0;
|
||||
for (i = 0; i < nlnn-1; i++) {
|
||||
loop1 = 1 << (nlnn-2-i);
|
||||
loop2 = 1 << i;
|
||||
index0 = 0;
|
||||
index1 = 1 << (i+1);
|
||||
offset = 1 << (i+1);
|
||||
|
||||
for (j = 0; j < loop1; j++) {
|
||||
for (k = 0; k < loop2; k++) {
|
||||
g0 = mul_rsftrnd_ldac(a_work[index1], p_c[coef], LDAC_Q_MDCT_COS+1);
|
||||
g1 = mul_rsftrnd_ldac(a_work[index1+1], p_s[coef], LDAC_Q_MDCT_SIN+1);
|
||||
g2 = g0 + g1;
|
||||
|
||||
g0 = mul_rsftrnd_ldac(a_work[index1], p_s[coef], LDAC_Q_MDCT_SIN+1);
|
||||
g1 = mul_rsftrnd_ldac(a_work[index1+1], p_c[coef], LDAC_Q_MDCT_COS+1);
|
||||
g3 = g0 - g1;
|
||||
|
||||
g0 = a_work[index0] >> 1;
|
||||
g1 = a_work[index0+1] >> 1;
|
||||
|
||||
a_work[index0] = g0 + g2;
|
||||
a_work[index0+1] = g1 + g3;
|
||||
a_work[index1] = g0 - g2;
|
||||
a_work[index1+1] = g1 - g3;
|
||||
|
||||
index0 += 2;
|
||||
index1 += 2;
|
||||
coef++;
|
||||
}
|
||||
index0 += offset;
|
||||
index1 += offset;
|
||||
coef -= loop2;
|
||||
}
|
||||
coef += loop2;
|
||||
}
|
||||
|
||||
for (i = 0; i < nsmpl>>1; i++) {
|
||||
index0 = i << 1;
|
||||
|
||||
g0 = mul_rsftrnd_ldac(a_work[index0], p_c[coef], LDAC_Q_MDCT_COS+shift);
|
||||
g1 = mul_rsftrnd_ldac(a_work[index0+1], p_s[coef], LDAC_Q_MDCT_SIN+shift);
|
||||
p_y[index0] = g0 + g1;
|
||||
|
||||
g0 = mul_rsftrnd_ldac(a_work[index0], p_s[coef], LDAC_Q_MDCT_SIN+shift);
|
||||
g1 = mul_rsftrnd_ldac(a_work[index0+1], p_c[coef], LDAC_Q_MDCT_COS+shift);
|
||||
p_y[nsmpl-index0-1] = g0 - g1;
|
||||
|
||||
coef++;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Process MDCT
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void proc_mdct_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
int nlnn)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich;
|
||||
int nchs = p_sfinfo->cfg.ch;
|
||||
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_sfinfo->ap_ac[ich];
|
||||
proc_mdct_core_ldac(p_ac->p_acsub->a_time, p_ac->p_acsub->a_spec, nlnn);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Process MDCT Core
|
||||
***************************************************************************************************/
|
||||
static void proc_mdct_core_ldac(
|
||||
SCALAR *p_x,
|
||||
SCALAR *p_y,
|
||||
int nlnn)
|
||||
{
|
||||
int i, j, k;
|
||||
int loop1, loop2;
|
||||
int coef, index0, index1, offset;
|
||||
int nsmpl = npow2_ldac(nlnn);
|
||||
const int *p_p;
|
||||
const SCALAR *p_w, *p_c, *p_s;
|
||||
SCALAR a_work[LDAC_MAXLSU];
|
||||
SCALAR *p_work = a_work;
|
||||
SCALAR a, b, c, d, tmp;
|
||||
SCALAR cc, cs;
|
||||
|
||||
i = nlnn - LDAC_1FSLNN;
|
||||
p_w = gaa_fwin_ldac[i];
|
||||
p_c = gaa_wcos_ldac[i];
|
||||
p_s = gaa_wsin_ldac[i];
|
||||
p_p = gaa_perm_ldac[i];
|
||||
|
||||
/* Windowing */
|
||||
for (i = 0; i < nsmpl>>1; i++) {
|
||||
p_work[p_p[i]] = -p_x[3*nsmpl/2-1-i] * p_w[nsmpl/2+i] - p_x[3*nsmpl/2+i] * p_w[nsmpl/2-1-i];
|
||||
|
||||
p_work[p_p[nsmpl/2+i]] = p_x[i] * p_w[i] - p_x[nsmpl-1-i] * p_w[nsmpl-1-i];
|
||||
}
|
||||
|
||||
/* Butterfly */
|
||||
coef = 0;
|
||||
for (i = 0; i < nlnn-1; ++i) {
|
||||
loop1 = 1 << (nlnn-2-i);
|
||||
loop2 = 1 << i;
|
||||
index0 = 0;
|
||||
index1 = 1 << (i+1);
|
||||
offset = 1 << (i+2);
|
||||
|
||||
for (k = 0; k < loop2; ++k) {
|
||||
cc = p_c[coef];
|
||||
cs = p_s[coef++];
|
||||
for (j = 0; j < loop1; ++j) {
|
||||
a = p_work[index0+0];
|
||||
b = p_work[index0+1];
|
||||
c = p_work[index1+0] * cc + p_work[index1+1] * cs;
|
||||
d = p_work[index1+0] * cs - p_work[index1+1] * cc;
|
||||
|
||||
p_work[index0+0] = a + c;
|
||||
p_work[index0+1] = b + d;
|
||||
p_work[index1+0] = a - c;
|
||||
p_work[index1+1] = b - d;
|
||||
index0 += offset;
|
||||
index1 += offset;
|
||||
}
|
||||
index0 += 2 - nsmpl;
|
||||
index1 += 2 - nsmpl;
|
||||
}
|
||||
}
|
||||
|
||||
tmp = _scalar(1.0) / (SCALAR)(nsmpl>>1);
|
||||
for (i = 0; i < nsmpl>>1; i++) {
|
||||
cc = p_c[coef];
|
||||
cs = p_s[coef++];
|
||||
|
||||
index0 = i << 1;
|
||||
a = p_work[index0] * cc + p_work[index0+1] * cs;
|
||||
b = p_work[index0] * cs - p_work[index0+1] * cc;
|
||||
|
||||
p_y[index0] = a * tmp;
|
||||
p_y[nsmpl-index0-1] = b * tmp;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Process MDCT
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void proc_mdct_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
int nlnn)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich;
|
||||
int nchs = p_sfinfo->cfg.ch;
|
||||
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_sfinfo->ap_ac[ich];
|
||||
proc_mdct_core_ldac(p_ac->p_acsub->a_time, p_ac->p_acsub->a_spec, nlnn);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Align Memory
|
||||
***************************************************************************************************/
|
||||
#define LDAC_ALLOC_LINE 8
|
||||
|
||||
DECLFUNC size_t align_ldac(
|
||||
size_t size)
|
||||
{
|
||||
if (LDAC_ALLOC_LINE != 0) {
|
||||
size = (((size-1)/LDAC_ALLOC_LINE)+1) * LDAC_ALLOC_LINE;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Clear Allocate Memory
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void *calloc_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
size_t nmemb,
|
||||
size_t size)
|
||||
{
|
||||
char *p_tmp;
|
||||
|
||||
if (p_sfinfo->p_mempos != (char *)NULL) {
|
||||
p_tmp = p_sfinfo->p_mempos;
|
||||
p_sfinfo->p_mempos += nmemb * align_ldac(size);
|
||||
}
|
||||
else {
|
||||
p_tmp = calloc(nmemb, size);
|
||||
}
|
||||
|
||||
return (void *)p_tmp;
|
||||
}
|
||||
|
|
@ -0,0 +1,493 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack and Store from MSB
|
||||
***************************************************************************************************/
|
||||
static void pack_store_ldac(
|
||||
int idata,
|
||||
int nbits,
|
||||
STREAM *p_block,
|
||||
int *p_loc)
|
||||
{
|
||||
STREAM *p_bufptr;
|
||||
register int bpos;
|
||||
register unsigned int tmp;
|
||||
|
||||
p_bufptr = p_block + (*p_loc >> LDAC_LOC_SHIFT);
|
||||
bpos = *p_loc & LDAC_LOC_MASK;
|
||||
|
||||
tmp = (idata << (24-nbits)) & 0xffffff;
|
||||
tmp >>= bpos;
|
||||
*p_bufptr++ |= (tmp>>16);
|
||||
*p_bufptr++ = (tmp>>8) & 0xff;
|
||||
*p_bufptr = tmp & 0xff;
|
||||
|
||||
*p_loc += nbits;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Frame Header
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void pack_frame_header_ldac(
|
||||
int smplrate_id,
|
||||
int chconfig_id,
|
||||
int frame_length,
|
||||
int frame_status,
|
||||
STREAM *p_stream)
|
||||
{
|
||||
int loc = 0;
|
||||
|
||||
pack_store_ldac(LDAC_SYNCWORD, LDAC_SYNCWORDBITS, p_stream, &loc);
|
||||
|
||||
pack_store_ldac(smplrate_id, LDAC_SMPLRATEBITS, p_stream, &loc);
|
||||
|
||||
pack_store_ldac(chconfig_id, LDAC_CHCONFIG2BITS, p_stream, &loc);
|
||||
|
||||
pack_store_ldac(frame_length-1, LDAC_FRAMELEN2BITS, p_stream, &loc);
|
||||
|
||||
pack_store_ldac(frame_status, LDAC_FRAMESTATBITS, p_stream, &loc);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Frame Alignment
|
||||
***************************************************************************************************/
|
||||
static void pack_frame_alignment_ldac(
|
||||
STREAM *p_stream,
|
||||
int *p_loc,
|
||||
int nbytes_frame)
|
||||
{
|
||||
int i;
|
||||
int nbytes_filled;
|
||||
|
||||
nbytes_filled = nbytes_frame - *p_loc / LDAC_BYTESIZE;
|
||||
|
||||
for (i = 0; i < nbytes_filled; i++) {
|
||||
pack_store_ldac(LDAC_FILLCODE, LDAC_BYTESIZE, p_stream, p_loc);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Byte Alignment
|
||||
***************************************************************************************************/
|
||||
#define pack_block_alignment_ldac(p_stream, p_loc) pack_byte_alignment_ldac((p_stream), (p_loc))
|
||||
|
||||
static void pack_byte_alignment_ldac(
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
int nbits_padding;
|
||||
|
||||
nbits_padding = ((*p_loc + LDAC_BYTESIZE - 1) / LDAC_BYTESIZE) * LDAC_BYTESIZE - *p_loc;
|
||||
|
||||
if (nbits_padding > 0) {
|
||||
pack_store_ldac(0, nbits_padding, p_stream, p_loc);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Band Info
|
||||
***************************************************************************************************/
|
||||
static void pack_band_info_ldac(
|
||||
AB *p_ab,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
pack_store_ldac(p_ab->nbands-LDAC_BAND_OFFSET, LDAC_NBANDBITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(LDAC_FALSE, LDAC_FLAGBITS, p_stream, p_loc);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Gradient Data
|
||||
***************************************************************************************************/
|
||||
static void pack_gradient_ldac(
|
||||
AB *p_ab,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
pack_store_ldac(p_ab->grad_mode, LDAC_GRADMODEBITS, p_stream, p_loc);
|
||||
|
||||
if (p_ab->grad_mode == LDAC_MODE_0) {
|
||||
pack_store_ldac(p_ab->grad_qu_l, LDAC_GRADQU0BITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(p_ab->grad_qu_h-1, LDAC_GRADQU0BITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(p_ab->grad_os_l, LDAC_GRADOSBITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(p_ab->grad_os_h, LDAC_GRADOSBITS, p_stream, p_loc);
|
||||
}
|
||||
else {
|
||||
pack_store_ldac(p_ab->grad_qu_l, LDAC_GRADQU1BITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(p_ab->grad_os_l, LDAC_GRADOSBITS, p_stream, p_loc);
|
||||
}
|
||||
|
||||
pack_store_ldac(p_ab->nadjqus, LDAC_NADJQUBITS, p_stream, p_loc);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Pack Scale Factor Data - Mode 0
|
||||
***************************************************************************************************/
|
||||
static void pack_scale_factor_0_ldac(
|
||||
AC *p_ac,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
HCENC *p_hcsf;
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int dif, val0, val1;
|
||||
const unsigned char *p_tbl;
|
||||
|
||||
pack_store_ldac(p_ac->sfc_bitlen-LDAC_MINSFCBLEN_0, LDAC_SFCBLENBITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(p_ac->sfc_offset, LDAC_IDSFBITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(p_ac->sfc_weight, LDAC_SFCWTBLBITS, p_stream, p_loc);
|
||||
|
||||
p_tbl = gaa_sfcwgt_ldac[p_ac->sfc_weight];
|
||||
val0 = p_ac->a_idsf[0] + p_tbl[0];
|
||||
|
||||
pack_store_ldac(val0-p_ac->sfc_offset, p_ac->sfc_bitlen, p_stream, p_loc);
|
||||
|
||||
p_hcsf = ga_hcenc_sf0_ldac + (p_ac->sfc_bitlen-LDAC_MINSFCBLEN_0);
|
||||
for (iqu = 1; iqu < nqus; iqu++) {
|
||||
val1 = p_ac->a_idsf[iqu] + p_tbl[iqu];
|
||||
dif = (val1 - val0) & p_hcsf->mask;
|
||||
pack_store_ldac(hc_word_ldac(p_hcsf->p_tbl+dif), hc_len_ldac(p_hcsf->p_tbl+dif), p_stream, p_loc);
|
||||
val0 = val1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Pack Scale Factor Data - Mode 1
|
||||
***************************************************************************************************/
|
||||
static void pack_scale_factor_1_ldac(
|
||||
AC *p_ac,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
const unsigned char *p_tbl;
|
||||
|
||||
pack_store_ldac(p_ac->sfc_bitlen-LDAC_MINSFCBLEN_1, LDAC_SFCBLENBITS, p_stream, p_loc);
|
||||
|
||||
if (p_ac->sfc_bitlen > 4) {
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
pack_store_ldac(p_ac->a_idsf[iqu], LDAC_IDSFBITS, p_stream, p_loc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pack_store_ldac(p_ac->sfc_offset, LDAC_IDSFBITS, p_stream, p_loc);
|
||||
|
||||
pack_store_ldac(p_ac->sfc_weight, LDAC_SFCWTBLBITS, p_stream, p_loc);
|
||||
|
||||
p_tbl = gaa_sfcwgt_ldac[p_ac->sfc_weight];
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
pack_store_ldac(p_ac->a_idsf[iqu]+p_tbl[iqu]-p_ac->sfc_offset, p_ac->sfc_bitlen, p_stream, p_loc);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Pack Scale Factor Data - Mode 2
|
||||
***************************************************************************************************/
|
||||
static void pack_scale_factor_2_ldac(
|
||||
AC *p_ac,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
HCENC *p_hcsf;
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int dif;
|
||||
|
||||
pack_store_ldac(p_ac->sfc_bitlen-LDAC_MINSFCBLEN_2, LDAC_SFCBLENBITS, p_stream, p_loc);
|
||||
|
||||
p_hcsf = ga_hcenc_sf1_ldac + (p_ac->sfc_bitlen-LDAC_MINSFCBLEN_2);
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
dif = (p_ac->a_idsf[iqu] - p_ac->p_ab->ap_ac[0]->a_idsf[iqu]) & p_hcsf->mask;
|
||||
pack_store_ldac(hc_word_ldac(p_hcsf->p_tbl+dif), hc_len_ldac(p_hcsf->p_tbl+dif), p_stream, p_loc);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Scale Factor Data
|
||||
***************************************************************************************************/
|
||||
static void pack_scale_factor_ldac(
|
||||
AC *p_ac,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
int sfc_mode = p_ac->sfc_mode;
|
||||
|
||||
pack_store_ldac(sfc_mode, LDAC_SFCMODEBITS, p_stream, p_loc);
|
||||
|
||||
if (p_ac->ich == 0) {
|
||||
if (sfc_mode == LDAC_MODE_0) {
|
||||
pack_scale_factor_0_ldac(p_ac, p_stream, p_loc);
|
||||
}
|
||||
else {
|
||||
pack_scale_factor_1_ldac(p_ac, p_stream, p_loc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sfc_mode == LDAC_MODE_0) {
|
||||
pack_scale_factor_0_ldac(p_ac, p_stream, p_loc);
|
||||
}
|
||||
else {
|
||||
pack_scale_factor_2_ldac(p_ac, p_stream, p_loc);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Spectrum Data
|
||||
***************************************************************************************************/
|
||||
static void pack_spectrum_ldac(
|
||||
AC *p_ac,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
int iqu, isp, i;
|
||||
int lsp, hsp;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int nsps, idwl1, wl, val;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
lsp = ga_isp_ldac[iqu];
|
||||
hsp = ga_isp_ldac[iqu+1];
|
||||
nsps = ga_nsps_ldac[iqu];
|
||||
idwl1 = p_ac->a_idwl1[iqu];
|
||||
wl = ga_wl_ldac[idwl1];
|
||||
|
||||
if (idwl1 == 1) {
|
||||
isp = lsp;
|
||||
|
||||
if (nsps == 2) {
|
||||
val = (p_ac->a_qspec[isp ]+1) << 2;
|
||||
val += (p_ac->a_qspec[isp+1]+1);
|
||||
pack_store_ldac(ga_2dimenc_spec_ldac[val], LDAC_2DIMSPECBITS, p_stream, p_loc);
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < nsps>>2; i++, isp+=4) {
|
||||
val = (p_ac->a_qspec[isp ]+1) << 6;
|
||||
val += (p_ac->a_qspec[isp+1]+1) << 4;
|
||||
val += (p_ac->a_qspec[isp+2]+1) << 2;
|
||||
val += (p_ac->a_qspec[isp+3]+1);
|
||||
pack_store_ldac(ga_4dimenc_spec_ldac[val], LDAC_4DIMSPECBITS, p_stream, p_loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (isp = lsp; isp < hsp; isp++) {
|
||||
pack_store_ldac(p_ac->a_qspec[isp], wl, p_stream, p_loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Residual Data
|
||||
***************************************************************************************************/
|
||||
static void pack_residual_ldac(
|
||||
AC *p_ac,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
int iqu, isp;
|
||||
int lsp, hsp;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int idwl2, wl;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
idwl2 = p_ac->a_idwl2[iqu];
|
||||
|
||||
if (idwl2 > 0) {
|
||||
lsp = ga_isp_ldac[iqu];
|
||||
hsp = ga_isp_ldac[iqu+1];
|
||||
wl = ga_wl_ldac[idwl2];
|
||||
|
||||
for (isp = lsp; isp < hsp; isp++) {
|
||||
pack_store_ldac(p_ac->a_rspec[isp], wl, p_stream, p_loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Audio Block
|
||||
***************************************************************************************************/
|
||||
static int pack_audio_block_ldac(
|
||||
AB *p_ab,
|
||||
STREAM *p_stream,
|
||||
int *p_loc)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich;
|
||||
int nchs = p_ab->blk_nchs;
|
||||
int nbits_band, nbits_grad, a_nbits_scfc[2], a_nbits_spec[2], nbits_used;
|
||||
int loc;
|
||||
|
||||
for (ich = 0; ich < 2; ich++) {
|
||||
a_nbits_scfc[ich] = 0;
|
||||
a_nbits_spec[ich] = 0;
|
||||
}
|
||||
|
||||
loc = *p_loc;
|
||||
pack_band_info_ldac(p_ab, p_stream, p_loc);
|
||||
nbits_band = *p_loc - loc;
|
||||
|
||||
loc = *p_loc;
|
||||
pack_gradient_ldac(p_ab, p_stream, p_loc);
|
||||
nbits_grad = *p_loc - loc;
|
||||
|
||||
nbits_used = nbits_band + nbits_grad;
|
||||
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_ab->ap_ac[ich];
|
||||
|
||||
loc = *p_loc;
|
||||
pack_scale_factor_ldac(p_ac, p_stream, p_loc);
|
||||
a_nbits_scfc[ich] = *p_loc - loc;
|
||||
|
||||
loc = *p_loc;
|
||||
pack_spectrum_ldac(p_ac, p_stream, p_loc);
|
||||
a_nbits_spec[ich] = *p_loc - loc;
|
||||
|
||||
loc = *p_loc;
|
||||
pack_residual_ldac(p_ac, p_stream, p_loc);
|
||||
a_nbits_spec[ich] += *p_loc - loc;
|
||||
|
||||
nbits_used += a_nbits_scfc[ich] + a_nbits_spec[ich];
|
||||
}
|
||||
|
||||
if (nbits_used > p_ab->nbits_used) {
|
||||
*p_ab->p_error_code = LDAC_ERR_BIT_PACKING;
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
else if (nbits_used < p_ab->nbits_used) {
|
||||
*p_ab->p_error_code = LDAC_ERR_BIT_PACKING;
|
||||
return LDAC_FALSE;
|
||||
}
|
||||
|
||||
return LDAC_TRUE;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Raw Data Frame
|
||||
***************************************************************************************************/
|
||||
DECLFUNC int pack_raw_data_frame_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
STREAM *p_stream,
|
||||
int *p_loc,
|
||||
int *p_nbytes_used)
|
||||
{
|
||||
CFG *p_cfg = &p_sfinfo->cfg;
|
||||
AB *p_ab = p_sfinfo->p_ab;
|
||||
int ibk;
|
||||
int nbks = gaa_block_setting_ldac[p_cfg->chconfig_id][1];
|
||||
|
||||
for (ibk = 0; ibk < nbks; ibk++) {
|
||||
if (!pack_audio_block_ldac(p_ab, p_stream, p_loc)) {
|
||||
return LDAC_ERR_PACK_BLOCK_FAILED;
|
||||
}
|
||||
|
||||
pack_block_alignment_ldac(p_stream, p_loc);
|
||||
|
||||
p_ab++;
|
||||
}
|
||||
|
||||
pack_frame_alignment_ldac(p_stream, p_loc, p_cfg->frame_length);
|
||||
|
||||
*p_nbytes_used = *p_loc / LDAC_BYTESIZE;
|
||||
|
||||
return LDAC_ERR_NONE;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Pack Null Data Frame
|
||||
***************************************************************************************************/
|
||||
static const int sa_null_data_size_ldac[2] = {
|
||||
11, 15,
|
||||
};
|
||||
static const STREAM saa_null_data_ldac[2][15] = {
|
||||
{0x07, 0xa0, 0x16, 0x00, 0x20, 0xad, 0x51, 0x45, 0x14, 0x50, 0x49},
|
||||
{0x07, 0xa0, 0x0a, 0x00, 0x20, 0xad, 0x51, 0x41, 0x24, 0x93, 0x00, 0x28, 0xa0, 0x92, 0x49},
|
||||
};
|
||||
|
||||
DECLFUNC int pack_null_data_frame_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
STREAM *p_stream,
|
||||
int *p_loc,
|
||||
int *p_nbytes_used)
|
||||
{
|
||||
CFG *p_cfg = &p_sfinfo->cfg;
|
||||
AB *p_ab = p_sfinfo->p_ab;
|
||||
int ibk;
|
||||
int nbks = gaa_block_setting_ldac[p_cfg->chconfig_id][1];
|
||||
int blk_type, size, offset = 0;
|
||||
|
||||
for (ibk = 0; ibk < nbks; ibk++) {
|
||||
blk_type = p_ab->blk_type;
|
||||
size = sa_null_data_size_ldac[blk_type];
|
||||
|
||||
copy_data_ldac(saa_null_data_ldac[blk_type], p_stream+offset, size*sizeof(STREAM));
|
||||
*p_loc += size*LDAC_BYTESIZE;
|
||||
|
||||
offset += size;
|
||||
p_ab++;
|
||||
}
|
||||
if (p_cfg->frame_length < offset) {
|
||||
return LDAC_ERR_PACK_BLOCK_FAILED;
|
||||
}
|
||||
|
||||
pack_frame_alignment_ldac(p_stream, p_loc, p_cfg->frame_length);
|
||||
|
||||
*p_nbytes_used = *p_loc / LDAC_BYTESIZE;
|
||||
|
||||
return LDAC_ERR_NONE;
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _PROTO_LDAC_H
|
||||
#define _PROTO_LDAC_H
|
||||
|
||||
/***************************************************************************************************
|
||||
Function Declarations
|
||||
***************************************************************************************************/
|
||||
/* encode_ldac.c */
|
||||
DECLFUNC LDAC_RESULT init_encode_ldac(SFINFO *);
|
||||
DECLFUNC void calc_initial_bits_ldac(SFINFO *);
|
||||
DECLFUNC void free_encode_ldac(SFINFO *);
|
||||
DECLFUNC int encode_ldac(SFINFO *, int, int, int, int, int, int, int);
|
||||
|
||||
|
||||
/* setpcm_ldac.c */
|
||||
DECLFUNC void set_input_pcm_ldac(SFINFO *, char *[], LDAC_SMPL_FMT_T, int);
|
||||
|
||||
/* mdct_ldac.c */
|
||||
DECLFUNC void proc_mdct_ldac(SFINFO *, int);
|
||||
|
||||
|
||||
/* sigana_ldac.c */
|
||||
DECLFUNC int ana_frame_status_ldac(SFINFO *, int);
|
||||
|
||||
/* bitalloc_ldac.c */
|
||||
DECLFUNC int alloc_bits_ldac(AB *);
|
||||
|
||||
/* bitalloc_sub_ldac.c */
|
||||
DECLFUNC int encode_side_info_ldac(AB *);
|
||||
DECLFUNC void calc_add_word_length_ldac(AC *);
|
||||
|
||||
/* quant_ldac.c */
|
||||
DECLFUNC void norm_spectrum_ldac(AC *);
|
||||
DECLFUNC void quant_spectrum_ldac(AC *);
|
||||
DECLFUNC void quant_residual_ldac(AC *);
|
||||
|
||||
|
||||
/* pack_ldac.c */
|
||||
DECLFUNC void pack_frame_header_ldac(int, int, int, int, STREAM *);
|
||||
DECLFUNC int pack_raw_data_frame_ldac(SFINFO *, STREAM *, int *, int *);
|
||||
DECLFUNC int pack_null_data_frame_ldac(SFINFO *, STREAM *, int *, int *);
|
||||
|
||||
|
||||
/* tables_ldac.c */
|
||||
DECLFUNC int get_block_nchs_ldac(int);
|
||||
|
||||
/* tables_sigproc_ldac.c */
|
||||
DECLFUNC void set_mdct_table_ldac(int);
|
||||
|
||||
/* memory_ldac.c */
|
||||
DECLFUNC size_t align_ldac(size_t);
|
||||
DECLFUNC void *calloc_ldac(SFINFO *, size_t, size_t);
|
||||
|
||||
#endif /* _PROTO_LDAC_H */
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Get Scale Factor Index
|
||||
***************************************************************************************************/
|
||||
__inline static int get_scale_factor_id_ldac(
|
||||
INT32 val)
|
||||
{
|
||||
int i;
|
||||
int id, step;
|
||||
|
||||
if (ga_sf_ldac[0] > val) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
id = LDAC_NIDSF >> 1;
|
||||
step = LDAC_NIDSF >> 2;
|
||||
for (i = 0; i < LDAC_IDSFBITS-1; i++) {
|
||||
if (ga_sf_ldac[id] > val) {
|
||||
id -= step;
|
||||
}
|
||||
else {
|
||||
id += step;
|
||||
}
|
||||
step >>= 1;
|
||||
}
|
||||
|
||||
if ((ga_sf_ldac[id] <= val) && (id < LDAC_NIDSF-1)) {
|
||||
id++;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Normalize Spectrum
|
||||
***************************************************************************************************/
|
||||
static INT32 sa_val_ldac[LDAC_MAXNSPS] = { /* Q31 */
|
||||
0xa0000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
};
|
||||
|
||||
DECLFUNC void norm_spectrum_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
int iqu, isp;
|
||||
int lsp, hsp;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int idsf;
|
||||
INT32 maxspec, tmp;
|
||||
INT32 *p_spec = p_ac->p_acsub->a_spec;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
lsp = ga_isp_ldac[iqu];
|
||||
hsp = ga_isp_ldac[iqu+1];
|
||||
|
||||
maxspec = abs(p_spec[lsp]);
|
||||
for (isp = lsp+1; isp < hsp; isp++) {
|
||||
tmp = abs(p_spec[isp]);
|
||||
if (maxspec < tmp) {
|
||||
maxspec = tmp;
|
||||
}
|
||||
}
|
||||
idsf = get_scale_factor_id_ldac(maxspec);
|
||||
|
||||
if (idsf > 0) {
|
||||
for (isp = lsp; isp < hsp; isp++) {
|
||||
p_spec[isp] = sftrnd_ldac(p_spec[isp], idsf-LDAC_Q_NORM);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (isp = lsp; isp < hsp; isp++) {
|
||||
p_spec[isp] = sa_val_ldac[isp-lsp];
|
||||
}
|
||||
}
|
||||
|
||||
p_ac->a_idsf[iqu] = idsf;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Quantize Spectrum Core
|
||||
***************************************************************************************************/
|
||||
__inline static void quant_spectrum_core_ldac(
|
||||
AC *p_ac,
|
||||
int iqu)
|
||||
{
|
||||
int i;
|
||||
int isp = ga_isp_ldac[iqu];
|
||||
int nsps = ga_nsps_ldac[iqu];
|
||||
int *p_qspec = p_ac->a_qspec+isp;
|
||||
INT32 qf = ga_qf_ldac[p_ac->a_idwl1[iqu]];
|
||||
INT32 *p_nspec = p_ac->p_acsub->a_spec+isp;
|
||||
|
||||
for (i = 0; i < nsps; i++) {
|
||||
/* Q00 <- Q31 * Q16 */
|
||||
p_qspec[i] = mul_rsftrnd_ldac(p_nspec[i], qf, LDAC_Q_QUANT1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Quantize Spectrum
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void quant_spectrum_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
quant_spectrum_core_ldac(p_ac, iqu);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Quantize Residual Spectrum Core
|
||||
***************************************************************************************************/
|
||||
__inline static void quant_residual_core_ldac(
|
||||
AC *p_ac,
|
||||
int iqu)
|
||||
{
|
||||
int i;
|
||||
int isp = ga_isp_ldac[iqu];
|
||||
int nsps = ga_nsps_ldac[iqu];
|
||||
int *p_qspec = p_ac->a_qspec+isp;
|
||||
int *p_rspec = p_ac->a_rspec+isp;
|
||||
INT32 ldqspec, rnspec;
|
||||
INT32 iqf = ga_iqf_ldac[LDAC_MAXIDWL1];
|
||||
INT32 rqf = ga_qf_ldac[p_ac->a_idwl2[iqu]];
|
||||
INT32 irsf = ga_irsf_ldac[LDAC_MAXIDWL1];
|
||||
INT32 *p_nspec = p_ac->p_acsub->a_spec+isp;
|
||||
|
||||
for (i = 0; i < nsps; i++) {
|
||||
/* Q31 <- Q00 * Q31 */
|
||||
ldqspec = mul_lsftrnd_ldac(p_qspec[i], iqf, LDAC_Q_QUANT2);
|
||||
/* Q31 <- (Q31 - Q31) * Q15 */
|
||||
rnspec = mul_rsftrnd_ldac(p_nspec[i]-ldqspec, irsf, LDAC_Q_QUANT3);
|
||||
/* Q00 <- Q31 * Q16 */
|
||||
p_rspec[i] = mul_rsftrnd_ldac(rnspec, rqf, LDAC_Q_QUANT4);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Quantize Residual Spectrum
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void quant_residual_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int *p_idwl2 = p_ac->a_idwl2;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
if (p_idwl2[iqu] > 0) {
|
||||
quant_residual_core_ldac(p_ac, iqu);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Get Scale Factor Index
|
||||
***************************************************************************************************/
|
||||
__inline static int get_scale_factor_id_ldac(
|
||||
SCALAR val)
|
||||
{
|
||||
int id;
|
||||
IEEE754_FI fi;
|
||||
|
||||
fi.f = val;
|
||||
id = ((fi.i & 0x7fffffff) >> 23) - 111;
|
||||
|
||||
if (id < 0) {
|
||||
id = 0;
|
||||
}
|
||||
if (id > LDAC_NIDSF-1) {
|
||||
id = LDAC_NIDSF-1;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Normalize Spectrum
|
||||
***************************************************************************************************/
|
||||
static SCALAR sa_val_ldac[LDAC_MAXNSPS] = {
|
||||
-0.75, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||
};
|
||||
|
||||
DECLFUNC void norm_spectrum_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
int iqu, isp;
|
||||
int lsp, hsp;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int idsf;
|
||||
int *p_idsf = p_ac->a_idsf;
|
||||
SCALAR maxspec, tmp;
|
||||
SCALAR *p_spec = p_ac->p_acsub->a_spec;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
lsp = ga_isp_ldac[iqu];
|
||||
hsp = ga_isp_ldac[iqu+1];
|
||||
|
||||
maxspec = fabs(p_spec[lsp]);
|
||||
for (isp = lsp+1; isp < hsp; isp++) {
|
||||
tmp = fabs(p_spec[isp]);
|
||||
if (maxspec < tmp) {
|
||||
maxspec = tmp;
|
||||
}
|
||||
}
|
||||
idsf = get_scale_factor_id_ldac(maxspec);
|
||||
|
||||
if (idsf > 0) {
|
||||
tmp = ga_isf_ldac[idsf];
|
||||
for (isp = lsp; isp < hsp; isp++) {
|
||||
p_spec[isp] *= tmp;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (isp = lsp; isp < hsp; isp++) {
|
||||
p_spec[isp] = sa_val_ldac[isp-lsp];
|
||||
}
|
||||
}
|
||||
|
||||
p_idsf[iqu] = idsf;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Quantize Spectrum Core
|
||||
***************************************************************************************************/
|
||||
__inline static void quant_spectrum_core_ldac(
|
||||
AC *p_ac,
|
||||
int iqu)
|
||||
{
|
||||
int i;
|
||||
int isp = ga_isp_ldac[iqu];
|
||||
int nsps = ga_nsps_ldac[iqu];
|
||||
int *p_qspec = p_ac->a_qspec+isp;
|
||||
SCALAR qf = ga_qf_ldac[p_ac->a_idwl1[iqu]];
|
||||
SCALAR *p_nspec = p_ac->p_acsub->a_spec+isp;
|
||||
|
||||
IEEE754_FI fi;
|
||||
const float fc = (float)((1 << 23) + (1 << 22));
|
||||
|
||||
for (i = 0; i < nsps; i++) {
|
||||
fi.f = p_nspec[i] * qf + fc;
|
||||
p_qspec[i] = (short)fi.i;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Quantize Spectrum
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void quant_spectrum_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
quant_spectrum_core_ldac(p_ac, iqu);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Quantize Residual Spectrum Core
|
||||
***************************************************************************************************/
|
||||
__inline static void quant_residual_core_ldac(
|
||||
AC *p_ac,
|
||||
int iqu)
|
||||
{
|
||||
int i;
|
||||
int isp = ga_isp_ldac[iqu];
|
||||
int nsps = ga_nsps_ldac[iqu];
|
||||
int *p_qspec = p_ac->a_qspec+isp;
|
||||
int *p_rspec = p_ac->a_rspec+isp;
|
||||
SCALAR ldqspec;
|
||||
SCALAR iqf = ga_iqf_ldac[LDAC_MAXIDWL1];
|
||||
SCALAR rqsf = ga_qf_ldac[p_ac->a_idwl2[iqu]] * ga_irsf_ldac[LDAC_MAXIDWL1]
|
||||
* _scalar(0.996093750);
|
||||
SCALAR *p_nspec = p_ac->p_acsub->a_spec+isp;
|
||||
|
||||
IEEE754_FI fi;
|
||||
const float fc = (float)((1 << 23) + (1 << 22));
|
||||
|
||||
for (i = 0; i < nsps; i++) {
|
||||
ldqspec = p_qspec[i] * iqf;
|
||||
fi.f = (p_nspec[i] - ldqspec) * rqsf + fc;
|
||||
p_rspec[i] = (short)fi.i;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Quantize Residual Spectrum
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void quant_residual_ldac(
|
||||
AC *p_ac)
|
||||
{
|
||||
int iqu;
|
||||
int nqus = p_ac->p_ab->nqus;
|
||||
int *p_idwl2 = p_ac->a_idwl2;
|
||||
|
||||
for (iqu = 0; iqu < nqus; iqu++) {
|
||||
if (p_idwl2[iqu] > 0) {
|
||||
quant_residual_core_ldac(p_ac, iqu);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Convert from 16bit Signed Integer PCM
|
||||
***************************************************************************************************/
|
||||
__inline static void byte_data_to_int_s16_ldac(
|
||||
char *p_in,
|
||||
INT32 *p_out,
|
||||
int nsmpl)
|
||||
{
|
||||
int i;
|
||||
short *p_s;
|
||||
|
||||
p_s = (short *)p_in;
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_out++ = lsft_ldac((INT32)*p_s++, LDAC_Q_SETPCM);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Convert from 24bit Signed Integer PCM
|
||||
***************************************************************************************************/
|
||||
__inline static void byte_data_to_int_s24_ldac(
|
||||
char *p_in,
|
||||
INT32 *p_out,
|
||||
int nsmpl)
|
||||
{
|
||||
int i, val;
|
||||
char *p_c;
|
||||
|
||||
p_c = (char *)p_in;
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
#ifdef LDAC_HOST_ENDIAN_LITTLE
|
||||
val = 0x000000ff & (*p_c++);
|
||||
val |= 0x0000ff00 & (*p_c++ << 8);
|
||||
val |= 0xffff0000 & (*p_c++ << 16);
|
||||
#else /* LDAC_HOST_ENDIAN_LITTLE */
|
||||
val = 0xffff0000 & (*p_c++ << 16);
|
||||
val |= 0x0000ff00 & (*p_c++ << 8);
|
||||
val |= 0x000000ff & (*p_c++);
|
||||
#endif /* LDAC_HOST_ENDIAN_LITTLE */
|
||||
*p_out++ = (INT32)((val << 8) >> 1); /* Sign Extension */
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Convert from 32bit Signed Integer PCM
|
||||
***************************************************************************************************/
|
||||
__inline static void byte_data_to_int_s32_ldac(
|
||||
char *p_in,
|
||||
INT32 *p_out,
|
||||
int nsmpl)
|
||||
{
|
||||
int i;
|
||||
int *p_l;
|
||||
|
||||
p_l = (int *)p_in;
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_out++ = rsft_ldac((INT32)*p_l++, 16-LDAC_Q_SETPCM);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Set Input PCM
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void set_input_pcm_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
char *pp_pcm[],
|
||||
LDAC_SMPL_FMT_T format,
|
||||
int nlnn)
|
||||
{
|
||||
int ich, isp;
|
||||
int nchs = p_sfinfo->cfg.ch;
|
||||
int nsmpl = npow2_ldac(nlnn);
|
||||
INT32 *p_time;
|
||||
|
||||
if (format == LDAC_SMPL_FMT_S16) {
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
|
||||
for (isp = 0; isp < nsmpl; isp++) {
|
||||
p_time[isp] = p_time[nsmpl+isp];
|
||||
}
|
||||
byte_data_to_int_s16_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
|
||||
}
|
||||
}
|
||||
else if (format == LDAC_SMPL_FMT_S24) {
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
|
||||
for (isp = 0; isp < nsmpl; isp++) {
|
||||
p_time[isp] = p_time[nsmpl+isp];
|
||||
}
|
||||
byte_data_to_int_s24_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
|
||||
}
|
||||
}
|
||||
else if (format == LDAC_SMPL_FMT_S32) {
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
|
||||
for (isp = 0; isp < nsmpl; isp++) {
|
||||
p_time[isp] = p_time[nsmpl+isp];
|
||||
}
|
||||
byte_data_to_int_s32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Convert from 16bit Signed Integer PCM
|
||||
***************************************************************************************************/
|
||||
__inline static void byte_data_to_scalar_s16_ldac(
|
||||
char *p_in,
|
||||
SCALAR *p_out,
|
||||
int nsmpl)
|
||||
{
|
||||
int i;
|
||||
short *p_s;
|
||||
|
||||
p_s = (short *)p_in;
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_out++ = (SCALAR)*p_s++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Convert from 24bit Signed Integer PCM
|
||||
***************************************************************************************************/
|
||||
__inline static void byte_data_to_scalar_s24_ldac(
|
||||
char *p_in,
|
||||
SCALAR *p_out,
|
||||
int nsmpl)
|
||||
{
|
||||
int i, val;
|
||||
char *p_c;
|
||||
SCALAR scale = _scalar(1.0) / _scalar(65536.0);
|
||||
|
||||
p_c = (char *)p_in;
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
#ifdef LDAC_HOST_ENDIAN_LITTLE
|
||||
val = 0x000000ff & (*p_c++);
|
||||
val |= 0x0000ff00 & (*p_c++ << 8);
|
||||
val |= 0xffff0000 & (*p_c++ << 16);
|
||||
#else /* LDAC_HOST_ENDIAN_LITTLE */
|
||||
val = 0xffff0000 & (*p_c++ << 16);
|
||||
val |= 0x0000ff00 & (*p_c++ << 8);
|
||||
val |= 0x000000ff & (*p_c++);
|
||||
#endif /* LDAC_HOST_ENDIAN_LITTLE */
|
||||
*p_out++ = scale * (SCALAR)(val << 8); /* Sign Extension */
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Convert from 32bit Signed Integer PCM
|
||||
***************************************************************************************************/
|
||||
__inline static void byte_data_to_scalar_s32_ldac(
|
||||
char *p_in,
|
||||
SCALAR *p_out,
|
||||
int nsmpl)
|
||||
{
|
||||
int i;
|
||||
int *p_l;
|
||||
SCALAR scale = _scalar(1.0) / _scalar(65536.0);
|
||||
|
||||
p_l = (int *)p_in;
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_out++ = scale * (SCALAR)*p_l++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Convert from 32bit Float PCM
|
||||
***************************************************************************************************/
|
||||
__inline static void byte_data_to_scalar_f32_ldac(
|
||||
char *p_in,
|
||||
SCALAR *p_out,
|
||||
int nsmpl)
|
||||
{
|
||||
int i;
|
||||
float *p_f;
|
||||
SCALAR scale = _scalar(32768.0);
|
||||
|
||||
p_f = (float *)p_in;
|
||||
for (i = 0; i < nsmpl; i++) {
|
||||
*p_out++ = scale * (SCALAR)*p_f++;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Set Input PCM
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void set_input_pcm_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
char *pp_pcm[],
|
||||
LDAC_SMPL_FMT_T format,
|
||||
int nlnn)
|
||||
{
|
||||
int ich, isp;
|
||||
int nchs = p_sfinfo->cfg.ch;
|
||||
int nsmpl = npow2_ldac(nlnn);
|
||||
SCALAR *p_time;
|
||||
|
||||
if (format == LDAC_SMPL_FMT_S16) {
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
|
||||
for (isp = 0; isp < nsmpl; isp++) {
|
||||
p_time[isp] = p_time[nsmpl+isp];
|
||||
}
|
||||
byte_data_to_scalar_s16_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
|
||||
}
|
||||
}
|
||||
else if (format == LDAC_SMPL_FMT_S24) {
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
|
||||
for (isp = 0; isp < nsmpl; isp++) {
|
||||
p_time[isp] = p_time[nsmpl+isp];
|
||||
}
|
||||
byte_data_to_scalar_s24_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
|
||||
}
|
||||
}
|
||||
else if (format == LDAC_SMPL_FMT_S32) {
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
|
||||
for (isp = 0; isp < nsmpl; isp++) {
|
||||
p_time[isp] = p_time[nsmpl+isp];
|
||||
}
|
||||
byte_data_to_scalar_s32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
|
||||
}
|
||||
}
|
||||
else if (format == LDAC_SMPL_FMT_F32) {
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_time = p_sfinfo->ap_ac[ich]->p_acsub->a_time;
|
||||
for (isp = 0; isp < nsmpl; isp++) {
|
||||
p_time[isp] = p_time[nsmpl+isp];
|
||||
}
|
||||
byte_data_to_scalar_f32_ldac(pp_pcm[ich], p_time+nsmpl, nsmpl);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,369 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
|
||||
#define LDAC_Q_LOWENERGY 11
|
||||
#define LDAC_Q_ADD_LOWENERGY 4
|
||||
|
||||
#define LDAC_TH_LOWENERGY_L (0x070bc28f>>LDAC_Q_ADD_LOWENERGY) /* Q15, _scalar(225.47)(Q19)>>4 */
|
||||
#define LDAC_TH_LOWENERGY_M (0x1c0ce148>>LDAC_Q_ADD_LOWENERGY) /* Q15, _scalar(897.61)(Q19)>>4 */
|
||||
#define LDAC_TH_LOWENERGY_H (0x6fab851f>>LDAC_Q_ADD_LOWENERGY) /* Q15, _scalar(3573.44)(Q19)>>4 */
|
||||
|
||||
#define LDAC_TH_CENTROID 0x00168000 /* Q15, _scalar(45.0) */
|
||||
|
||||
/***************************************************************************************************
|
||||
Lookup Table for Calculating Square Root Value
|
||||
***************************************************************************************************/
|
||||
static INT16 sa_sqrt_ldac[97] = { /* Q14 */
|
||||
0x2d41, 0x2df4, 0x2ea5, 0x2f54, 0x3000, 0x30a9, 0x3150, 0x31f5,
|
||||
0x3298, 0x3339, 0x33d8, 0x3475, 0x3510, 0x35aa, 0x3642, 0x36d8,
|
||||
0x376c, 0x3800, 0x3891, 0x3921, 0x39b0, 0x3a3d, 0x3ac9, 0x3b54,
|
||||
0x3bdd, 0x3c66, 0x3ced, 0x3d72, 0x3df7, 0x3e7b, 0x3efd, 0x3f7f,
|
||||
0x4000, 0x407f, 0x40fe, 0x417b, 0x41f8, 0x4273, 0x42ee, 0x4368,
|
||||
0x43e1, 0x445a, 0x44d1, 0x4548, 0x45be, 0x4633, 0x46a7, 0x471b,
|
||||
0x478d, 0x4800, 0x4871, 0x48e2, 0x4952, 0x49c1, 0x4a30, 0x4a9e,
|
||||
0x4b0b, 0x4b78, 0x4be5, 0x4c50, 0x4cbb, 0x4d26, 0x4d90, 0x4df9,
|
||||
0x4e62, 0x4eca, 0x4f32, 0x4f99, 0x5000, 0x5066, 0x50cb, 0x5130,
|
||||
0x5195, 0x51f9, 0x525d, 0x52c0, 0x5323, 0x5385, 0x53e7, 0x5449,
|
||||
0x54a9, 0x550a, 0x556a, 0x55ca, 0x5629, 0x5688, 0x56e6, 0x5745,
|
||||
0x57a2, 0x5800, 0x585c, 0x58b9, 0x5915, 0x5971, 0x59cc, 0x5a27,
|
||||
0x5a82,
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Multiply
|
||||
***************************************************************************************************/
|
||||
__inline static INT32 mul_ldac(
|
||||
INT32 in1,
|
||||
INT32 in2)
|
||||
{
|
||||
INT32 out;
|
||||
INT64 acc;
|
||||
|
||||
/* Q30 <- Q30 * Q30 */
|
||||
acc = (INT64)in1 * in2;
|
||||
acc >>= 30;
|
||||
|
||||
if (acc > LDAC_MAX_32BIT) {
|
||||
out = LDAC_MAX_32BIT;
|
||||
}
|
||||
else if (acc < LDAC_MIN_32BIT) {
|
||||
out = LDAC_MIN_32BIT;
|
||||
}
|
||||
else {
|
||||
out = (INT32)acc;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Subtract
|
||||
***************************************************************************************************/
|
||||
__inline static INT32 sub_ldac(
|
||||
INT32 in1,
|
||||
INT32 in2)
|
||||
{
|
||||
INT32 out;
|
||||
|
||||
out = in1 - in2;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Add
|
||||
***************************************************************************************************/
|
||||
__inline static INT32 add_ldac(
|
||||
INT32 in1,
|
||||
INT32 in2)
|
||||
{
|
||||
INT32 out;
|
||||
|
||||
out = in1 + in2;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Multiply and Add
|
||||
***************************************************************************************************/
|
||||
__inline static INT32 mad_ldac(
|
||||
INT32 in1,
|
||||
INT32 in2,
|
||||
INT32 in3)
|
||||
{
|
||||
INT32 out;
|
||||
|
||||
out = mul_ldac(in2, in3);
|
||||
out = add_ldac(in1, out);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Normalize
|
||||
***************************************************************************************************/
|
||||
__inline static INT16 norm_ldac(
|
||||
UINT32 val)
|
||||
{
|
||||
INT16 len;
|
||||
|
||||
len = 0;
|
||||
while (val > 0) {
|
||||
val >>= 1;
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Calculate Exponential
|
||||
***************************************************************************************************/
|
||||
__inline static INT16 calc_exp_ldac(
|
||||
INT32 in_h,
|
||||
UINT32 in_l)
|
||||
{
|
||||
INT16 e;
|
||||
|
||||
if (in_h) {
|
||||
e = norm_ldac((UINT32)in_h) + 32;
|
||||
}
|
||||
else {
|
||||
e = norm_ldac(in_l);
|
||||
}
|
||||
e = (63 - e) & 0xfffe;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Subfunction: Calculate Square Root
|
||||
***************************************************************************************************/
|
||||
__inline static INT32 calc_sqrt_ldac(
|
||||
INT32 in,
|
||||
INT16 e)
|
||||
{
|
||||
INT16 i;
|
||||
INT32 val, dif, a;
|
||||
|
||||
if (in <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = (INT16)(in >> 24);
|
||||
a = in & 0x00ffffffL;
|
||||
|
||||
i = i - 32;
|
||||
val = sa_sqrt_ldac[i] << 16; /* Q30 <- Q14 << 16 */
|
||||
dif = sub_ldac(sa_sqrt_ldac[i+1]<<16, val); /* Q30 */
|
||||
a = (INT32)(((INT64)a << 30) >> 24); /* Q30 a = a / 0x1000000 */
|
||||
val = mad_ldac(val, dif, a);
|
||||
val = val >> (e >> 1);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Pseudo Spectrum and Low Band Energy
|
||||
***************************************************************************************************/
|
||||
static INT32 calc_mdct_pseudo_spectrum_ldac(
|
||||
INT32 *p_spec,
|
||||
INT32 *p_psd,
|
||||
UINT32 nsp)
|
||||
{
|
||||
UINT32 isp;
|
||||
INT16 e;
|
||||
INT32 y0, y1, y2;
|
||||
INT32 tmp;
|
||||
INT64 low_energy;
|
||||
INT64 acc1, acc2;
|
||||
|
||||
{
|
||||
y1 = p_spec[0];
|
||||
y2 = p_spec[1];
|
||||
acc1 = (INT64)y1 * (INT64)y1;
|
||||
acc2 = (INT64)y2 * (INT64)y2;
|
||||
acc1 = acc1 + acc2;
|
||||
low_energy = acc1 >> LDAC_Q_ADD_LOWENERGY; /* Q26 <- (Q15 * Q15) >> 4 */
|
||||
e = calc_exp_ldac((INT32)(acc1>>32), (UINT32)(acc1&0xffffffff));
|
||||
tmp = (INT32)((acc1 << e) >> 32);
|
||||
*p_psd++ = calc_sqrt_ldac(tmp, e);
|
||||
}
|
||||
|
||||
for (isp = 1; isp < LDAC_NSP_LOWENERGY; isp++) {
|
||||
y0 = y1;
|
||||
y1 = y2;
|
||||
y2 = p_spec[isp+1];
|
||||
acc1 = (INT64)y1 * (INT64)y1;
|
||||
acc2 = (INT64)(y0-y2) * (INT64)(y0-y2);
|
||||
acc1 = acc1 + acc2;
|
||||
low_energy += acc1 >> LDAC_Q_ADD_LOWENERGY; /* Q26 <- (Q15 * Q15) >> 4 */
|
||||
e = calc_exp_ldac((INT32)(acc1>>32), (UINT32)(acc1&0xffffffff));
|
||||
tmp = (INT32)((acc1 << e) >> 32);
|
||||
*p_psd++ = calc_sqrt_ldac(tmp, e);
|
||||
}
|
||||
|
||||
for (isp = LDAC_NSP_LOWENERGY; isp < nsp-1; isp++) {
|
||||
y0 = y1;
|
||||
y1 = y2;
|
||||
y2 = p_spec[isp+1];
|
||||
acc1 = (INT64)y1 * (INT64)y1;
|
||||
acc2 = (INT64)(y0-y2) * (INT64)(y0-y2);
|
||||
acc1 = acc1 + acc2;
|
||||
e = calc_exp_ldac((INT32)(acc1 >> 32), (UINT32)(acc1&0xffffffff));
|
||||
tmp = (INT32) ((acc1 << e) >> 32);
|
||||
*p_psd++ = calc_sqrt_ldac(tmp, e);
|
||||
}
|
||||
|
||||
{
|
||||
acc1 = (INT64)y1 * (INT64)y1;
|
||||
acc2 = (INT64)y2 * (INT64)y2;
|
||||
acc1 = acc1 + acc2;
|
||||
e = calc_exp_ldac((INT32)(acc1 >> 32), (UINT32)(acc1&0xffffffff));
|
||||
tmp = (INT32)((acc1 << e) >> 32);
|
||||
*p_psd++ = calc_sqrt_ldac(tmp, e);
|
||||
}
|
||||
|
||||
low_energy >>= LDAC_Q_LOWENERGY; /* Q15 <- Q26 >> 11 */
|
||||
if (low_energy > LDAC_MAX_32BIT) {
|
||||
low_energy = LDAC_MAX_32BIT;
|
||||
}
|
||||
|
||||
return (INT32)low_energy;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Pseudo Spectrum Centroid
|
||||
***************************************************************************************************/
|
||||
static INT32 calc_spectral_centroid_ldac(
|
||||
INT32 *p_spec,
|
||||
UINT32 nsp)
|
||||
{
|
||||
UINT32 isp;
|
||||
INT32 centroid = 0;
|
||||
INT64 s1, s2;
|
||||
|
||||
s1 = s2 = 0;
|
||||
for (isp = 0; isp < nsp; isp++) {
|
||||
s1 += ((INT64)isp * (INT64)*p_spec); /* Q15 <- Q00 * Q15 */
|
||||
s2 += (INT64)*p_spec++; /* Q15 */
|
||||
}
|
||||
|
||||
if (s2 != 0) {
|
||||
centroid = (INT32)((s1<<15) / s2); /* Q15 <- (Q15<<15) / Q15 */
|
||||
}
|
||||
|
||||
return centroid;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Number of Zero Cross
|
||||
***************************************************************************************************/
|
||||
static UINT32 calc_zero_cross_number_ldac(
|
||||
INT32 *p_time,
|
||||
UINT32 n)
|
||||
{
|
||||
UINT32 i;
|
||||
UINT32 zero_cross = 0;
|
||||
INT32 prev, tmp;
|
||||
|
||||
prev = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
if ((prev == 0) || (*p_time == 0)) {
|
||||
tmp = 0;
|
||||
}
|
||||
else {
|
||||
tmp = prev ^ (*p_time);
|
||||
}
|
||||
|
||||
if (tmp < 0) {
|
||||
zero_cross++;
|
||||
}
|
||||
prev = *p_time++;
|
||||
}
|
||||
|
||||
return zero_cross;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Analyze Frame Status
|
||||
***************************************************************************************************/
|
||||
DECLSPEC int ana_frame_status_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
int nlnn)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich;
|
||||
int nchs = p_sfinfo->cfg.ch;
|
||||
int nsmpl = npow2_ldac(nlnn+1);
|
||||
int cnt;
|
||||
int a_status[LDAC_PRCNCH];
|
||||
UINT32 zero_cross;
|
||||
INT32 low_energy, centroid;
|
||||
INT32 a_psd_spec[LDAC_NSP_PSEUDOANA];
|
||||
|
||||
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_sfinfo->ap_ac[ich];
|
||||
|
||||
low_energy = calc_mdct_pseudo_spectrum_ldac(p_ac->p_acsub->a_spec, a_psd_spec, LDAC_NSP_PSEUDOANA);
|
||||
|
||||
centroid = calc_spectral_centroid_ldac(a_psd_spec, LDAC_NSP_PSEUDOANA);
|
||||
|
||||
zero_cross = calc_zero_cross_number_ldac(p_ac->p_acsub->a_time, nsmpl);
|
||||
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_0;
|
||||
if (low_energy < LDAC_TH_LOWENERGY_L) {
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_3;
|
||||
}
|
||||
else {
|
||||
if (low_energy < LDAC_TH_LOWENERGY_M) {
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_2;
|
||||
}
|
||||
else if (low_energy < LDAC_TH_LOWENERGY_H) {
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_1;
|
||||
}
|
||||
|
||||
cnt = p_ac->frmana_cnt;
|
||||
if ((centroid > LDAC_TH_CENTROID) && (zero_cross >= LDAC_TH_ZCROSNUM)) {
|
||||
cnt++;
|
||||
|
||||
if (cnt >= LDAC_MAXCNT_FRMANA) {
|
||||
cnt = LDAC_MAXCNT_FRMANA;
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_2;
|
||||
}
|
||||
else if (a_status[ich] <= LDAC_FRMSTAT_LEV_1) {
|
||||
a_status[ich]++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cnt = 0;
|
||||
}
|
||||
p_ac->frmana_cnt = cnt;
|
||||
}
|
||||
}
|
||||
|
||||
if (nchs == LDAC_CHANNEL_1CH) {
|
||||
return a_status[0];
|
||||
} else {
|
||||
return min_ldac(a_status[0], a_status[1]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
|
||||
#define LDAC_TH_LOWENERGY_L _scalar(225.47)
|
||||
#define LDAC_TH_LOWENERGY_M _scalar(897.61)
|
||||
#define LDAC_TH_LOWENERGY_H _scalar(3573.44)
|
||||
|
||||
#define LDAC_TH_CENTROID _scalar(45.0)
|
||||
#define LDAC_TH_ZERODIV _scalar(1.0e-6)
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Pseudo Spectrum and Low Band Energy
|
||||
***************************************************************************************************/
|
||||
static SCALAR calc_mdct_pseudo_spectrum_ldac(
|
||||
SCALAR *p_spec,
|
||||
SCALAR *p_psd,
|
||||
int n)
|
||||
{
|
||||
int isp;
|
||||
SCALAR low_energy, tmp;
|
||||
SCALAR y0, y1, y2;
|
||||
|
||||
{
|
||||
y1 = p_spec[0];
|
||||
y2 = p_spec[1];
|
||||
tmp = y1 * y1 + y2 * y2;
|
||||
low_energy = tmp;
|
||||
p_psd[0] = sqrt(tmp);
|
||||
}
|
||||
|
||||
for (isp = 1; isp < LDAC_NSP_LOWENERGY; isp++) {
|
||||
y0 = y1;
|
||||
y1 = y2;
|
||||
y2 = p_spec[isp+1];
|
||||
tmp = y1 * y1 + (y0-y2) * (y0-y2);
|
||||
low_energy += tmp;
|
||||
p_psd[isp] = sqrt(tmp);
|
||||
}
|
||||
|
||||
for (isp = LDAC_NSP_LOWENERGY; isp < n-1; isp++) {
|
||||
y0 = y1;
|
||||
y1 = y2;
|
||||
y2 = p_spec[isp+1];
|
||||
tmp = y1 * y1 + (y0-y2) * (y0-y2);
|
||||
p_psd[isp] = sqrt(tmp);
|
||||
}
|
||||
|
||||
{
|
||||
tmp = y1 * y1 + y2 * y2;
|
||||
p_psd[n-1] = sqrt(tmp);
|
||||
}
|
||||
|
||||
return low_energy;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Pseudo Spectrum Centroid
|
||||
***************************************************************************************************/
|
||||
static SCALAR calc_spectral_centroid_ldac(
|
||||
SCALAR *p_spec,
|
||||
int nsp)
|
||||
{
|
||||
int isp;
|
||||
SCALAR centroid;
|
||||
SCALAR s1, s2;
|
||||
|
||||
s1 = s2 = _scalar(0.0);
|
||||
for (isp = 0; isp < nsp; isp++) {
|
||||
s1 += (SCALAR)isp * *p_spec;
|
||||
s2 += *p_spec++;
|
||||
}
|
||||
|
||||
if (s2 < LDAC_TH_ZERODIV) {
|
||||
centroid = _scalar(0.0);
|
||||
}
|
||||
else {
|
||||
centroid = s1 / s2;
|
||||
}
|
||||
|
||||
return centroid;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Calculate Number of Zero Cross
|
||||
***************************************************************************************************/
|
||||
static int calc_zero_cross_number_ldac(
|
||||
SCALAR *p_time,
|
||||
int n)
|
||||
{
|
||||
int i;
|
||||
int zero_cross = 0;
|
||||
SCALAR prev;
|
||||
|
||||
prev = _scalar(0.0);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (prev * *p_time < _scalar(0.0)) {
|
||||
zero_cross++;
|
||||
}
|
||||
prev = *p_time++;
|
||||
}
|
||||
|
||||
return zero_cross;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Analyze Frame Status
|
||||
***************************************************************************************************/
|
||||
DECLSPEC int ana_frame_status_ldac(
|
||||
SFINFO *p_sfinfo,
|
||||
int nlnn)
|
||||
{
|
||||
AC *p_ac;
|
||||
int ich;
|
||||
int nchs = p_sfinfo->cfg.ch;
|
||||
int nsmpl = npow2_ldac(nlnn+1);
|
||||
int cnt, zero_cross;
|
||||
int a_status[LDAC_PRCNCH];
|
||||
SCALAR low_energy, centroid;
|
||||
SCALAR a_psd_spec[LDAC_NSP_PSEUDOANA];
|
||||
|
||||
for (ich = 0; ich < nchs; ich++) {
|
||||
p_ac = p_sfinfo->ap_ac[ich];
|
||||
|
||||
low_energy = calc_mdct_pseudo_spectrum_ldac(p_ac->p_acsub->a_spec, a_psd_spec, LDAC_NSP_PSEUDOANA);
|
||||
|
||||
centroid = calc_spectral_centroid_ldac(a_psd_spec, LDAC_NSP_PSEUDOANA);
|
||||
|
||||
zero_cross = calc_zero_cross_number_ldac(p_ac->p_acsub->a_time, nsmpl);
|
||||
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_0;
|
||||
if (low_energy < LDAC_TH_LOWENERGY_L) {
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_3;
|
||||
}
|
||||
else {
|
||||
if (low_energy < LDAC_TH_LOWENERGY_M) {
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_2;
|
||||
}
|
||||
else if (low_energy < LDAC_TH_LOWENERGY_H) {
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_1;
|
||||
}
|
||||
|
||||
cnt = p_ac->frmana_cnt;
|
||||
if ((centroid > LDAC_TH_CENTROID) && (zero_cross >= LDAC_TH_ZCROSNUM)) {
|
||||
cnt++;
|
||||
|
||||
if (cnt >= LDAC_MAXCNT_FRMANA) {
|
||||
cnt = LDAC_MAXCNT_FRMANA;
|
||||
a_status[ich] = LDAC_FRMSTAT_LEV_2;
|
||||
}
|
||||
else if (a_status[ich] <= LDAC_FRMSTAT_LEV_1) {
|
||||
a_status[ich]++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cnt = 0;
|
||||
}
|
||||
p_ac->frmana_cnt = cnt;
|
||||
}
|
||||
}
|
||||
|
||||
if (nchs == LDAC_CHANNEL_1CH) {
|
||||
return a_status[0];
|
||||
}
|
||||
else {
|
||||
return min_ldac(a_status[0], a_status[1]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _STRUCT_H
|
||||
#define _STRUCT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
/***************************************************************************************************
|
||||
Macro Definition
|
||||
***************************************************************************************************/
|
||||
|
||||
#define DECLFUNC static
|
||||
#define UNUSED_ATTR __attribute__((unused))
|
||||
|
||||
#ifndef PI
|
||||
#ifdef M_PI
|
||||
#define PI M_PI
|
||||
#else /* M_PI */
|
||||
#define PI (double)(3.14159265358979323846)
|
||||
#endif /* M_PI */
|
||||
#endif /* PI */
|
||||
|
||||
/***************************************************************************************************
|
||||
Type Definition
|
||||
***************************************************************************************************/
|
||||
typedef unsigned char STREAM;
|
||||
|
||||
typedef short INT16;
|
||||
typedef int INT32;
|
||||
typedef unsigned int UINT32;
|
||||
typedef long long INT64;
|
||||
|
||||
typedef float SCALAR;
|
||||
#define _scalar(x) x##f
|
||||
typedef union {
|
||||
float f;
|
||||
int i;
|
||||
} IEEE754_FI;
|
||||
|
||||
/***************************************************************************************************
|
||||
Macro Functions
|
||||
***************************************************************************************************/
|
||||
/* Buffer Operations */
|
||||
#define clear_data_ldac(p, n) memset((p), 0, (n))
|
||||
#define clear_seq_s_ldac(p, n) memset((char *)(p), 0, (n)*sizeof(short))
|
||||
#define clear_seq_l_ldac(p, n) memset((char *)(p), 0, (n)*sizeof(int))
|
||||
#define clear_seq_f_ldac(p, n) memset((char *)(p), 0, (n)*sizeof(SCALAR))
|
||||
|
||||
#if _MSC_VER >=1400
|
||||
/* Secured CRT Functions */
|
||||
#define copy_data_ldac(p1, p2, n) memcpy_s((p2), (n), (p1), (n))
|
||||
#define copy_seq_s_ldac(p1, p2, n) memcpy_s((p2), (n)*sizeof(short), (p1), (n)*sizeof(short))
|
||||
#define copy_seq_l_ldac(p1, p2, n) memcpy_s((p2), (n)*sizeof(int), (p1), (n)*sizeof(int))
|
||||
#define copy_seq_f_ldac(p1, p2, n) memcpy_s((p2), (n)*sizeof(SCALAR), (p1), (n)*sizeof(SCALAR))
|
||||
#define move_seq_f_ldac(p1, p2, n) memmove_s((p2), (n)*sizeof(SCALAR), (p1), (n)*sizeof(SCALAR))
|
||||
#else
|
||||
#define copy_data_ldac(p1, p2, n) memcpy((p2), (p1), (n))
|
||||
#define copy_seq_s_ldac(p1, p2, n) memcpy((p2), (p1), (n)*sizeof(short))
|
||||
#define copy_seq_l_ldac(p1, p2, n) memcpy((p2), (p1), (n)*sizeof(int))
|
||||
#define copy_seq_f_ldac(p1, p2, n) memcpy((p2), (p1), (n)*sizeof(SCALAR))
|
||||
#define move_seq_f_ldac(p1, p2, n) memmove((p2), (p1), (n)*sizeof(SCALAR))
|
||||
#endif
|
||||
|
||||
#endif /* _STRUCT_H */
|
||||
|
|
@ -0,0 +1,505 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Tables related to Sampling Rate Indices
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const unsigned int ga_smplrate_ldac[LDAC_NSUPSMPLRATEID] = {
|
||||
44100, 48000, 88200, 96000,
|
||||
};
|
||||
|
||||
DECLFUNC const unsigned short ga_framesmpls_ldac[LDAC_NSUPSMPLRATEID] = {
|
||||
LDAC_1FSLSU, LDAC_1FSLSU, LDAC_2FSLSU, LDAC_2FSLSU,
|
||||
};
|
||||
|
||||
DECLFUNC const unsigned char ga_ln_framesmpls_ldac[LDAC_NSUPSMPLRATEID] = {
|
||||
LDAC_1FSLNN, LDAC_1FSLNN, LDAC_2FSLNN, LDAC_2FSLNN,
|
||||
};
|
||||
|
||||
DECLFUNC const unsigned char ga_max_nbands_ldac[LDAC_NSUPSMPLRATEID] = {
|
||||
LDAC_1FSNBANDS, LDAC_1FSNBANDS, LDAC_2FSNBANDS, LDAC_2FSNBANDS,
|
||||
};
|
||||
|
||||
DECLFUNC const char gaa_nlnn_shift_ldac[LDAC_NSUPSMPLRATEID][LDAC_NSFTSTEP] = {
|
||||
{-1, -1, 0, 0, -1},
|
||||
{-1, -1, 0, 0, -1},
|
||||
{-1, 0, 0, -1, -1},
|
||||
{-1, 0, 0, -1, -1},
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Tables related to Channel Config Indices
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const unsigned char ga_ch_ldac[LDAC_NCHCONFIGID] = {
|
||||
LDAC_CHANNEL_1CH, LDAC_CHANNEL_2CH, LDAC_CHANNEL_2CH, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
DECLFUNC const unsigned char ga_chconfig_id_ldac[LDAC_MAXNCH+1] = {
|
||||
0, LDAC_CHCONFIGID_MN, LDAC_CHCONFIGID_ST
|
||||
};
|
||||
|
||||
DECLFUNC const char gaa_block_setting_ldac[LDAC_NCHCONFIGID][LDAC_MAXNCH+2]=
|
||||
{
|
||||
{LDAC_CHANNEL_1CH, 1, LDAC_BLKID_MONO},
|
||||
{LDAC_CHANNEL_2CH, 2, LDAC_BLKID_MONO, LDAC_BLKID_MONO},
|
||||
{LDAC_CHANNEL_2CH, 1, LDAC_BLKID_STEREO},
|
||||
{0, 0, 0},
|
||||
};
|
||||
|
||||
DECLFUNC int get_block_nchs_ldac(
|
||||
int blk_type)
|
||||
{
|
||||
int blk_nchs;
|
||||
|
||||
if (blk_type == LDAC_BLKID_MONO) {
|
||||
blk_nchs = 1;
|
||||
}
|
||||
else if (blk_type == LDAC_BLKID_STEREO) {
|
||||
blk_nchs = 2;
|
||||
}
|
||||
else {
|
||||
blk_nchs = -1;
|
||||
}
|
||||
|
||||
return blk_nchs;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
Tables related to Quantization Units
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const unsigned char ga_idsp_ldac[LDAC_MAXNQUS] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1,
|
||||
1, 1, 1, 1,
|
||||
1, 1, 1, 1,
|
||||
2, 2,
|
||||
2, 2,
|
||||
3, 3,
|
||||
3, 3,
|
||||
3, 3,
|
||||
3, 3,
|
||||
3, 3,
|
||||
};
|
||||
|
||||
DECLFUNC const unsigned char ga_nsps_ldac[LDAC_MAXNQUS] = {
|
||||
2, 2, 2, 2, 2, 2, 2, 2,
|
||||
4, 4, 4, 4,
|
||||
4, 4, 4, 4,
|
||||
4, 4, 4, 4,
|
||||
8, 8,
|
||||
8, 8,
|
||||
16, 16,
|
||||
16, 16,
|
||||
16, 16,
|
||||
16, 16,
|
||||
16, 16,
|
||||
};
|
||||
|
||||
DECLFUNC const unsigned short ga_isp_ldac[LDAC_MAXNQUS+1] = {
|
||||
0, 2, 4, 6, 8, 10, 12, 14,
|
||||
16, 20, 24, 28,
|
||||
32, 36, 40, 44,
|
||||
48, 52, 56, 60,
|
||||
64, 72,
|
||||
80, 88,
|
||||
96,112,
|
||||
128,144,
|
||||
160,176,
|
||||
192,208,
|
||||
224,240,
|
||||
256,
|
||||
};
|
||||
|
||||
DECLFUNC const unsigned char ga_nqus_ldac[LDAC_MAXNBANDS+1] = {
|
||||
0, 4, 8, 10, 12, 14, 16, 18, 20, 22, 24, 25, 26, 28, 30, 32, 34,
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Encoding/Decoding Tables for Spectrum Data
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const unsigned char ga_wl_ldac[LDAC_NIDWL] = {
|
||||
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
};
|
||||
|
||||
DECLFUNC const short gaa_ndim_wls_ldac[4][LDAC_NIDWL] = {
|
||||
{0, 3, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32},
|
||||
{0, 7, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64},
|
||||
{0, 14, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96,104,112,120,128},
|
||||
{0, 28, 48, 64, 80, 96,112,128,144,160,176,192,208,224,240,256},
|
||||
};
|
||||
|
||||
DECLFUNC const int ga_2dimenc_spec_ldac[LDAC_N2DIMSPECENCTBL] = {
|
||||
0, 1, 2, 0, 3, 0, 4, 0, 5, 6, 7, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
DECLFUNC const int ga_4dimenc_spec_ldac[LDAC_N4DIMSPECENCTBL] = {
|
||||
0, 1, 2, 0, 3, 4, 5, 0, 6, 7, 8, 0, 0, 0, 0, 0,
|
||||
9, 10, 11, 0, 12, 13, 14, 0, 15, 16, 17, 0, 0, 0, 0, 0,
|
||||
18, 19, 20, 0, 21, 22, 23, 0, 24, 25, 26, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
27, 28, 29, 0, 30, 31, 32, 0, 33, 34, 35, 0, 0, 0, 0, 0,
|
||||
36, 37, 38, 0, 39, 40, 41, 0, 42, 43, 44, 0, 0, 0, 0, 0,
|
||||
45, 46, 47, 0, 48, 49, 50, 0, 51, 52, 53, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
54, 55, 56, 0, 57, 58, 59, 0, 60, 61, 62, 0, 0, 0, 0, 0,
|
||||
63, 64, 65, 0, 66, 67, 68, 0, 69, 70, 71, 0, 0, 0, 0, 0,
|
||||
72, 73, 74, 0, 75, 76, 77, 0, 78, 79, 80, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Resampled Gradient Table
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const unsigned char gaa_resamp_grad_ldac[LDAC_MAXGRADQU][LDAC_MAXGRADQU] = {
|
||||
{
|
||||
128,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
31,225,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
17,128,239,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
12, 69,187,244,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
10, 43,128,213,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
9, 31, 87,169,225,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
8, 24, 62,128,194,232,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
8, 19, 47, 97,159,209,237,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
7, 17, 37, 75,128,181,219,239,249,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
7, 15, 31, 59,103,153,197,225,241,249,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
7, 13, 26, 48, 83,128,173,208,230,243,249,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 12, 23, 41, 69,107,149,187,215,233,244,250,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 11, 20, 35, 58, 90,128,166,198,221,236,245,250,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 11, 18, 31, 49, 76,110,146,180,207,225,238,245,250,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 10, 17, 27, 43, 66, 95,128,161,190,213,229,239,246,250,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 10, 15, 24, 38, 57, 82,112,144,174,199,218,232,241,246,250,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 9, 14, 22, 34, 50, 72, 98,128,158,184,206,222,234,242,247,250,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 9, 13, 20, 31, 45, 63, 87,114,142,169,193,211,225,236,243,247,250,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 9, 13, 19, 28, 40, 56, 77,101,128,155,179,200,216,228,237,243,247,250,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 8, 12, 18, 26, 36, 51, 69, 91,115,141,165,187,205,220,230,238,244,248,250,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 8, 12, 17, 24, 33, 46, 62, 81,104,128,152,175,194,210,223,232,239,244,248,250,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
6, 8, 11, 16, 22, 31, 42, 56, 74, 94,116,140,162,182,200,214,225,234,240,245,248,250,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 8, 11, 15, 21, 28, 38, 51, 67, 85,106,128,150,171,189,205,218,228,235,241,245,248,251,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 8, 10, 14, 19, 26, 35, 47, 61, 78, 97,117,139,159,178,195,209,221,230,237,242,246,248,251,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 10, 14, 18, 25, 33, 43, 56, 71, 88,108,128,148,168,185,200,213,223,231,238,242,246,249,251,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 10, 13, 17, 23, 31, 40, 51, 65, 81, 99,118,138,157,175,191,205,216,225,233,239,243,246,249,
|
||||
251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 9, 13, 17, 22, 29, 37, 47, 60, 75, 91,109,128,147,165,181,196,209,219,227,234,239,243,247,
|
||||
249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 9, 12, 16, 21, 27, 35, 44, 55, 69, 84,101,119,137,155,172,187,201,212,221,229,235,240,244,
|
||||
247,249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 9, 12, 15, 20, 25, 32, 41, 51, 64, 78, 94,110,128,146,162,178,192,205,215,224,231,236,241,
|
||||
244,247,249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 9, 11, 15, 19, 24, 31, 38, 48, 59, 72, 87,103,119,137,153,169,184,197,208,218,225,232,237,
|
||||
241,245,247,249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 9, 11, 14, 18, 23, 29, 36, 45, 55, 67, 81, 96,112,128,144,160,175,189,201,211,220,227,233,
|
||||
238,242,245,247,249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 8, 11, 14, 17, 22, 27, 34, 42, 52, 63, 75, 89,104,120,136,152,167,181,193,204,214,222,229,
|
||||
234,239,242,245,248,249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 8, 11, 13, 17, 21, 26, 32, 40, 48, 59, 70, 83, 98,113,128,143,158,173,186,197,208,216,224,
|
||||
230,235,239,243,245,248,249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 7, 8, 10, 13, 16, 20, 25, 31, 37, 46, 55, 66, 78, 91,106,120,136,150,165,178,190,201,210,219,
|
||||
225,231,236,240,243,246,248,249,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 8, 10, 12, 15, 19, 24, 29, 35, 43, 52, 62, 73, 86, 99,113,128,143,157,170,183,194,204,213,
|
||||
221,227,232,237,241,244,246,248,250,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 8, 10, 12, 15, 18, 23, 28, 34, 41, 49, 58, 69, 81, 93,107,121,135,149,163,175,187,198,207,
|
||||
215,222,228,233,238,241,244,246,248,250,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 8, 10, 12, 15, 18, 22, 26, 32, 39, 46, 55, 65, 76, 88,101,114,128,142,155,168,180,191,201,
|
||||
210,217,224,230,234,238,241,244,246,248,250,251,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 8, 9, 12, 14, 17, 21, 25, 31, 37, 44, 52, 61, 72, 83, 95,108,121,135,148,161,173,184,195,
|
||||
204,212,219,225,231,235,239,242,244,247,248,250,251,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 8, 9, 11, 14, 17, 20, 24, 29, 35, 42, 49, 58, 68, 78, 90,102,115,128,141,154,166,178,188,
|
||||
198,207,214,221,227,232,236,239,242,245,247,248,250,251,255,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 8, 9, 11, 13, 16, 19, 23, 28, 33, 40, 47, 55, 64, 74, 85, 97,109,122,134,147,159,171,182,
|
||||
192,201,209,216,223,228,233,237,240,243,245,247,248,250,251,255,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 9, 11, 13, 16, 19, 22, 27, 32, 38, 44, 52, 61, 70, 80, 92,103,116,128,140,153,164,176,
|
||||
186,195,204,212,218,224,229,234,237,240,243,245,247,249,250,251,255,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 9, 11, 13, 15, 18, 22, 26, 31, 36, 42, 49, 58, 66, 76, 87, 98,110,122,134,146,158,169,
|
||||
180,190,198,207,214,220,225,230,234,238,241,243,245,247,249,250,251,255,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 9, 10, 12, 15, 18, 21, 25, 29, 34, 40, 47, 55, 63, 72, 82, 93,104,116,128,140,152,163,
|
||||
174,184,193,201,209,216,222,227,231,235,238,241,244,246,247,249,250,251,255,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 9, 10, 12, 14, 17, 20, 24, 28, 33, 39, 45, 52, 60, 69, 78, 89, 99,111,122,134,145,157,
|
||||
167,178,187,196,204,211,217,223,228,232,236,239,242,244,246,247,249,250,251,255,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 8, 10, 12, 14, 17, 20, 23, 27, 32, 37, 43, 50, 57, 66, 75, 84, 95,105,117,128,139,151,
|
||||
161,172,181,190,199,206,213,219,224,229,233,236,239,242,244,246,248,249,250,251,255,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 8, 10, 12, 14, 16, 19, 22, 26, 31, 36, 41, 48, 55, 62, 71, 80, 90,101,111,122,134,145,
|
||||
155,166,176,185,194,201,208,215,220,225,230,234,237,240,242,244,246,248,249,250,251,255,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 8, 10, 11, 13, 16, 18, 22, 25, 29, 34, 39, 45, 52, 60, 68, 77, 86, 96,106,117,128,139,
|
||||
150,160,170,179,188,196,204,211,217,222,227,231,234,238,240,243,245,246,248,249,250,251,255,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 8, 10, 11, 13, 15, 18, 21, 24, 28, 33, 38, 44, 50, 57, 65, 73, 82, 92,102,112,123,133,
|
||||
144,154,164,174,183,191,199,206,212,218,223,228,232,235,238,241,243,245,246,248,249,250,251,255,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 8, 9, 11, 13, 15, 17, 20, 24, 27, 32, 36, 42, 48, 55, 62, 70, 78, 88, 97,107,118,128,
|
||||
138,149,159,168,178,186,194,201,208,214,220,224,229,232,236,239,241,243,245,247,248,249,250,251,255,
|
||||
},
|
||||
{
|
||||
5, 6, 7, 8, 9, 11, 13, 15, 17, 20, 23, 26, 31, 35, 40, 46, 52, 59, 67, 75, 84, 93,103,113,123,
|
||||
133,143,153,163,172,181,189,197,204,210,216,221,225,230,233,236,239,241,243,245,247,248,249,250,251,
|
||||
},
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Weighting Tables for Scale Factor Data
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const unsigned char gaa_sfcwgt_ldac[LDAC_NSFCWTBL][LDAC_MAXNQUS] = {
|
||||
{
|
||||
1, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 8,
|
||||
},
|
||||
{
|
||||
0, 1, 1, 2, 3, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7,
|
||||
7, 7, 7, 7, 7, 7, 8, 8, 8, 9, 10, 10, 11, 11, 12, 12, 12, 12,
|
||||
},
|
||||
{
|
||||
0, 1, 1, 2, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 6, 6, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11,
|
||||
},
|
||||
{
|
||||
0, 1, 3, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10,
|
||||
},
|
||||
{
|
||||
0, 1, 3, 4, 5, 5, 6, 7, 7, 8, 8, 9, 9, 10, 10, 10,
|
||||
10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13,
|
||||
},
|
||||
{
|
||||
1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 7, 8, 8, 8,
|
||||
9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
|
||||
},
|
||||
{
|
||||
0, 0, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
|
||||
4, 4, 4, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 9, 9, 9, 9,
|
||||
},
|
||||
{
|
||||
0, 0, 1, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 8, 8,
|
||||
9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12,
|
||||
},
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Huffman Codewords for Scale Factor Data
|
||||
***************************************************************************************************/
|
||||
static const HC sa_hc_sf0_blen3_ldac[8] = {
|
||||
{ 0, 2}, { 1, 2}, { 14, 4}, { 62, 6},
|
||||
{ 63, 6}, { 30, 5}, { 6, 3}, { 2, 2},
|
||||
};
|
||||
|
||||
static const HC sa_hc_sf0_blen4_ldac[16] = {
|
||||
{ 1, 2}, { 2, 2}, { 0, 4}, { 6, 5},
|
||||
{ 15, 6}, { 19, 7}, { 35, 8}, { 36, 8},
|
||||
{ 37, 8}, { 34, 8}, { 33, 8}, { 32, 8},
|
||||
{ 14, 6}, { 5, 5}, { 1, 4}, { 3, 2},
|
||||
};
|
||||
|
||||
static const HC sa_hc_sf0_blen5_ldac[32] = {
|
||||
{ 2, 2}, { 1, 3}, { 7, 3}, { 13, 4},
|
||||
{ 12, 5}, { 24, 5}, { 27, 6}, { 33, 7},
|
||||
{ 63, 7}, {106, 8}, {107, 8}, {104, 8},
|
||||
{115, 8}, {121, 8}, {124, 8}, {125, 8},
|
||||
{122, 8}, {123, 8}, {120, 8}, {114, 8},
|
||||
{ 68, 8}, { 69, 8}, { 71, 8}, { 70, 8},
|
||||
{105, 8}, { 56, 7}, { 32, 7}, { 29, 6},
|
||||
{ 25, 5}, { 9, 5}, { 5, 4}, { 0, 3},
|
||||
};
|
||||
|
||||
static const HC sa_hc_sf0_blen6_ldac[64] = {
|
||||
{ 0, 3}, { 1, 3}, { 4, 4}, { 5, 4},
|
||||
{ 18, 5}, { 19, 5}, { 46, 6}, { 47, 6},
|
||||
{ 48, 6}, {102, 7}, {103, 7}, {214, 8},
|
||||
{215, 8}, {216, 8}, {217, 8}, {218, 8},
|
||||
{219, 8}, {220, 8}, {221, 8}, {222, 8},
|
||||
{223, 8}, {224, 8}, {225, 8}, {226, 8},
|
||||
{227, 8}, {228, 8}, {229, 8}, {230, 8},
|
||||
{231, 8}, {232, 8}, {233, 8}, {234, 8},
|
||||
{235, 8}, {236, 8}, {237, 8}, {238, 8},
|
||||
{239, 8}, {240, 8}, {241, 8}, {242, 8},
|
||||
{243, 8}, {244, 8}, {245, 8}, {246, 8},
|
||||
{247, 8}, {248, 8}, {249, 8}, {250, 8},
|
||||
{251, 8}, {252, 8}, {253, 8}, {254, 8},
|
||||
{255, 8}, {104, 7}, {105, 7}, {106, 7},
|
||||
{ 49, 6}, { 50, 6}, { 20, 5}, { 21, 5},
|
||||
{ 22, 5}, { 6, 4}, { 7, 4}, { 8, 4},
|
||||
};
|
||||
|
||||
static const HC sa_hc_sf1_blen2_ldac[4] = {
|
||||
{ 0, 1}, { 3, 2}, { 0, 0}, { 2, 2},
|
||||
};
|
||||
|
||||
static const HC sa_hc_sf1_blen3_ldac[8] = {
|
||||
{ 1, 1}, { 0, 3}, { 4, 5}, { 11, 6},
|
||||
{ 0, 0}, { 10, 6}, { 3, 4}, { 1, 2},
|
||||
};
|
||||
|
||||
static const HC sa_hc_sf1_blen4_ldac[16] = {
|
||||
{ 1, 1}, { 1, 3}, { 4, 4}, { 14, 5},
|
||||
{ 15, 5}, { 44, 7}, { 90, 8}, { 93, 8},
|
||||
{ 0, 0}, { 92, 8}, { 91, 8}, { 47, 7},
|
||||
{ 21, 6}, { 20, 6}, { 6, 4}, { 0, 3},
|
||||
};
|
||||
|
||||
static const HC sa_hc_sf1_blen5_ldac[32] = {
|
||||
{ 0, 3}, { 5, 3}, { 7, 4}, { 12, 4},
|
||||
{ 4, 4}, { 2, 4}, { 3, 4}, { 5, 4},
|
||||
{ 9, 4}, { 16, 5}, { 35, 6}, { 51, 7},
|
||||
{ 54, 7}, {110, 7}, { 96, 8}, {101, 8},
|
||||
{ 98, 8}, { 97, 8}, { 99, 8}, {100, 8},
|
||||
{111, 7}, {109, 7}, {108, 7}, {107, 7},
|
||||
{106, 7}, {104, 7}, {105, 7}, { 69, 7},
|
||||
{ 68, 7}, { 55, 7}, { 26, 6}, { 7, 3},
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Huffman Encoding/Decoding Structures for Scale Factor Data
|
||||
***************************************************************************************************/
|
||||
DECLFUNC HCENC ga_hcenc_sf0_ldac[LDAC_MAXSFCBLEN_0-LDAC_MINSFCBLEN_0+1] = {
|
||||
{sa_hc_sf0_blen3_ldac, 8, 3, 7},
|
||||
{sa_hc_sf0_blen4_ldac, 16, 4, 15},
|
||||
{sa_hc_sf0_blen5_ldac, 32, 5, 31},
|
||||
{sa_hc_sf0_blen6_ldac, 64, 6, 63},
|
||||
};
|
||||
|
||||
DECLFUNC HCENC ga_hcenc_sf1_ldac[LDAC_MAXSFCBLEN_2-LDAC_MINSFCBLEN_2+1] = {
|
||||
{sa_hc_sf1_blen2_ldac, 4, 2, 3},
|
||||
{sa_hc_sf1_blen3_ldac, 8, 3, 7},
|
||||
{sa_hc_sf1_blen4_ldac, 16, 4, 15},
|
||||
{sa_hc_sf1_blen5_ldac, 32, 5, 31},
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,284 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Window Tables
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const INT32 *gaa_fwin_ldac[LDAC_NUMLNN];
|
||||
static const INT32 sa_fwin_1fs_ldac[LDAC_1FSLSU] = { /* Q30 */
|
||||
0x00009de9, 0x00058d10, 0x000f6a9a, 0x001e3503, 0x0031ea03, 0x004a868e, 0x006806db, 0x008a665c,
|
||||
0x00b19fc5, 0x00ddad09, 0x010e875c, 0x01442737, 0x017e8455, 0x01bd95b5, 0x0201519e, 0x0249ad9e,
|
||||
0x02969e8c, 0x02e8188c, 0x033e0f0c, 0x039874cb, 0x03f73bda, 0x045a5599, 0x04c1b2c1, 0x052d4362,
|
||||
0x059cf6e5, 0x0610bc11, 0x0688810b, 0x0704335c, 0x0783bff0, 0x0807131d, 0x088e18a1, 0x0918bbab,
|
||||
0x09a6e6da, 0x0a388442, 0x0acd7d6d, 0x0b65bb64, 0x0c0126ad, 0x0c9fa74f, 0x0d4124da, 0x0de58667,
|
||||
0x0e8cb29c, 0x0f368fb3, 0x0fe30379, 0x1091f357, 0x11434452, 0x11f6db14, 0x12ac9bea, 0x13646ace,
|
||||
0x141e2b67, 0x14d9c111, 0x15970edf, 0x1655f79f, 0x17165de0, 0x17d823f9, 0x189b2c07, 0x195f57f7,
|
||||
0x1a248988, 0x1aeaa254, 0x1bb183cc, 0x1c790f47, 0x1d4125ff, 0x1e09a918, 0x1ed279a9, 0x1f9b78b8,
|
||||
0x20648748, 0x212d8657, 0x21f656e8, 0x22beda01, 0x2386f0b9, 0x244e7c34, 0x25155dac, 0x25db7678,
|
||||
0x26a0a809, 0x2764d3f9, 0x2827dc07, 0x28e9a220, 0x29aa0861, 0x2a68f121, 0x2b263eef, 0x2be1d499,
|
||||
0x2c9b9532, 0x2d536416, 0x2e0924ec, 0x2ebcbbae, 0x2f6e0ca9, 0x301cfc87, 0x30c9704d, 0x31734d64,
|
||||
0x321a7999, 0x32bedb26, 0x336058b1, 0x33fed953, 0x349a449c, 0x35328293, 0x35c77bbe, 0x36591926,
|
||||
0x36e74455, 0x3771e75f, 0x37f8ece3, 0x387c4010, 0x38fbcca4, 0x39777ef5, 0x39ef43ef, 0x3a63091b,
|
||||
0x3ad2bc9e, 0x3b3e4d3f, 0x3ba5aa67, 0x3c08c426, 0x3c678b35, 0x3cc1f0f4, 0x3d17e774, 0x3d696174,
|
||||
0x3db65262, 0x3dfeae62, 0x3e426a4b, 0x3e817bab, 0x3ebbd8c9, 0x3ef178a4, 0x3f2252f7, 0x3f4e603b,
|
||||
0x3f7599a4, 0x3f97f925, 0x3fb57972, 0x3fce15fd, 0x3fe1cafd, 0x3ff09566, 0x3ffa72f0, 0x3fff6217,
|
||||
};
|
||||
static const INT32 sa_fwin_2fs_ldac[LDAC_2FSLSU] = { /* Q30 */
|
||||
0x0000277a, 0x0001634c, 0x0003dae2, 0x00078e25, 0x000c7cf0, 0x0012a713, 0x001a0c51, 0x0022ac60,
|
||||
0x002c86ec, 0x00379b93, 0x0043e9e8, 0x00517172, 0x006031aa, 0x00702a00, 0x008159d6, 0x0093c082,
|
||||
0x00a75d4f, 0x00bc2f7a, 0x00d23637, 0x00e970ac, 0x0101ddf4, 0x011b7d1e, 0x01364d2c, 0x01524d17,
|
||||
0x016f7bca, 0x018dd825, 0x01ad60fc, 0x01ce1518, 0x01eff336, 0x0212fa08, 0x02372835, 0x025c7c57,
|
||||
0x0282f4fd, 0x02aa90ad, 0x02d34ddf, 0x02fd2b01, 0x03282676, 0x03543e96, 0x038171ae, 0x03afbdff,
|
||||
0x03df21c0, 0x040f9b1f, 0x0441283b, 0x0473c72e, 0x04a77601, 0x04dc32b9, 0x0511fb4c, 0x0548cda7,
|
||||
0x0580a7ad, 0x05b98738, 0x05f36a15, 0x062e4e0a, 0x066a30d1, 0x06a7101b, 0x06e4e990, 0x0723bacd,
|
||||
0x07638166, 0x07a43ae5, 0x07e5e4cc, 0x08287c93, 0x086bffa9, 0x08b06b72, 0x08f5bd4d, 0x093bf28c,
|
||||
0x0983087b, 0x09cafc5d, 0x0a13cb6a, 0x0a5d72d6, 0x0aa7efc7, 0x0af33f61, 0x0b3f5eba, 0x0b8c4ae4,
|
||||
0x0bda00e8, 0x0c287dc7, 0x0c77be7a, 0x0cc7bff3, 0x0d187f1c, 0x0d69f8d9, 0x0dbc2a04, 0x0e0f0f74,
|
||||
0x0e62a5f6, 0x0eb6ea51, 0x0f0bd945, 0x0f616f8c, 0x0fb7a9d9, 0x100e84da, 0x1065fd35, 0x10be0f8b,
|
||||
0x1116b876, 0x116ff48c, 0x11c9c05b, 0x1224186e, 0x127ef94a, 0x12da5f6c, 0x1336474f, 0x1392ad69,
|
||||
0x13ef8e28, 0x144ce5f8, 0x14aab141, 0x1508ec64, 0x156793c0, 0x15c6a3ad, 0x16261883, 0x1685ee93,
|
||||
0x16e6222a, 0x1746af94, 0x17a79318, 0x1808c8f9, 0x186a4d78, 0x18cc1cd3, 0x192e3344, 0x19908d03,
|
||||
0x19f32646, 0x1a55fb3f, 0x1ab9081f, 0x1b1c4914, 0x1b7fba4b, 0x1be357ee, 0x1c471e27, 0x1cab091b,
|
||||
0x1d0f14f3, 0x1d733dd1, 0x1dd77fd9, 0x1e3bd72f, 0x1ea03ff3, 0x1f04b646, 0x1f69364a, 0x1fcdbc1e,
|
||||
0x203243e2, 0x2096c9b6, 0x20fb49ba, 0x215fc00d, 0x21c428d1, 0x22288027, 0x228cc22f, 0x22f0eb0d,
|
||||
0x2354f6e5, 0x23b8e1d9, 0x241ca812, 0x248045b5, 0x24e3b6ec, 0x2546f7e1, 0x25aa04c1, 0x260cd9ba,
|
||||
0x266f72fd, 0x26d1ccbc, 0x2733e32d, 0x2795b288, 0x27f73707, 0x28586ce8, 0x28b9506c, 0x2919ddd6,
|
||||
0x297a116d, 0x29d9e77d, 0x2a395c53, 0x2a986c40, 0x2af7139c, 0x2b554ebf, 0x2bb31a08, 0x2c1071d8,
|
||||
0x2c6d5297, 0x2cc9b8b1, 0x2d25a094, 0x2d8106b6, 0x2ddbe792, 0x2e363fa5, 0x2e900b74, 0x2ee9478a,
|
||||
0x2f41f075, 0x2f9a02cb, 0x2ff17b26, 0x30485627, 0x309e9074, 0x30f426bb, 0x314915af, 0x319d5a0a,
|
||||
0x31f0f08c, 0x3243d5fc, 0x32960727, 0x32e780e4, 0x3338400d, 0x33884186, 0x33d78239, 0x3425ff18,
|
||||
0x3473b51c, 0x34c0a146, 0x350cc09f, 0x35581039, 0x35a28d2a, 0x35ec3496, 0x363503a3, 0x367cf785,
|
||||
0x36c40d74, 0x370a42b3, 0x374f948e, 0x37940057, 0x37d7836d, 0x381a1b34, 0x385bc51b, 0x389c7e9a,
|
||||
0x38dc4533, 0x391b1670, 0x3958efe5, 0x3995cf2f, 0x39d1b1f6, 0x3a0c95eb, 0x3a4678c8, 0x3a7f5853,
|
||||
0x3ab73259, 0x3aee04b4, 0x3b23cd47, 0x3b5889ff, 0x3b8c38d2, 0x3bbed7c5, 0x3bf064e1, 0x3c20de40,
|
||||
0x3c504201, 0x3c7e8e52, 0x3cabc16a, 0x3cd7d98a, 0x3d02d4ff, 0x3d2cb221, 0x3d556f53, 0x3d7d0b03,
|
||||
0x3da383a9, 0x3dc8d7cb, 0x3ded05f8, 0x3e100cca, 0x3e31eae8, 0x3e529f04, 0x3e7227db, 0x3e908436,
|
||||
0x3eadb2e9, 0x3ec9b2d4, 0x3ee482e2, 0x3efe220c, 0x3f168f54, 0x3f2dc9c9, 0x3f43d086, 0x3f58a2b1,
|
||||
0x3f6c3f7e, 0x3f7ea62a, 0x3f8fd600, 0x3f9fce56, 0x3fae8e8e, 0x3fbc1618, 0x3fc8646d, 0x3fd37914,
|
||||
0x3fdd53a0, 0x3fe5f3af, 0x3fed58ed, 0x3ff38310, 0x3ff871db, 0x3ffc251e, 0x3ffe9cb4, 0x3fffd886,
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
MDCT/IMDCT Tables
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const INT32 *gaa_wcos_ldac[LDAC_NUMLNN];
|
||||
static const INT32 sa_wcos_1fs_ldac[LDAC_1FSLSU] = { /* Q31 */
|
||||
0x5a82799a, 0x7641af3d, 0xcf043ab3, 0x7d8a5f40, 0x471cece7, 0xe70747c4, 0x9592675c, 0x7f62368f,
|
||||
0x70e2cbc6, 0x5133cc94, 0x25280c5e, 0xf3742ca2, 0xc3a94590, 0x9d0dfe54, 0x8582faa5, 0x7fd8878e,
|
||||
0x7c29fbee, 0x73b5ebd1, 0x66cf8120, 0x55f5a4d2, 0x41ce1e65, 0x2b1f34eb, 0x12c8106f, 0xf9b82684,
|
||||
0xe0e60685, 0xc945dfec, 0xb3c0200c, 0xa1288376, 0x9235f2ec, 0x877b7bec, 0x8162aa04, 0x7ff62182,
|
||||
0x7f0991c4, 0x7ce3ceb2, 0x798a23b1, 0x7504d345, 0x6f5f02b2, 0x68a69e81, 0x60ec3830, 0x5842dd54,
|
||||
0x4ebfe8a5, 0x447acd50, 0x398cdd32, 0x2e110a62, 0x2223a4c5, 0x15e21445, 0x096a9049, 0xfcdbd541,
|
||||
0xf054d8d5, 0xe3f47d96, 0xd7d946d8, 0xcc210d79, 0xc0e8b648, 0xb64beacd, 0xac64d510, 0xa34bdf20,
|
||||
0x9b1776da, 0x93dbd6a0, 0x8daad37b, 0x8893b125, 0x84a2fc62, 0x81e26c16, 0x8058c94c, 0x7fff6216,
|
||||
0x7ff09478, 0x7fce0c3e, 0x7f97cebd, 0x7f4de451, 0x7ef05860, 0x7e7f3957, 0x7dfa98a8, 0x7d628ac6,
|
||||
0x7cb72724, 0x7bf88830, 0x7b26cb4f, 0x7a4210d8, 0x794a7c12, 0x78403329, 0x77235f2d, 0x75f42c0b,
|
||||
0x74b2c884, 0x735f6626, 0x71fa3949, 0x708378ff, 0x6efb5f12, 0x6d6227fa, 0x6bb812d1, 0x69fd614a,
|
||||
0x683257ab, 0x66573cbb, 0x646c59bf, 0x6271fa69, 0x60686ccf, 0x5e50015d, 0x5c290acc, 0x59f3de12,
|
||||
0x57b0d256, 0x556040e2, 0x53028518, 0x5097fc5e, 0x4e210617, 0x4b9e0390, 0x490f57ee, 0x46756828,
|
||||
0x43d09aed, 0x4121589b, 0x3e680b2c, 0x3ba51e29, 0x38d8fe93, 0x36041ad9, 0x3326e2c3, 0x3041c761,
|
||||
0x2d553afc, 0x2a61b101, 0x27679df4, 0x24677758, 0x2161b3a0, 0x1e56ca1e, 0x1b4732ef, 0x183366e9,
|
||||
0x151bdf86, 0x120116d5, 0x0ee38766, 0x0bc3ac35, 0x08a2009a, 0x057f0035, 0x025b26d7, 0x00000000,
|
||||
};
|
||||
static const INT32 sa_wcos_2fs_ldac[LDAC_2FSLSU] = { /* Q31 */
|
||||
0x5a82799a, 0x7641af3d, 0xcf043ab3, 0x7d8a5f40, 0x471cece7, 0xe70747c4, 0x9592675c, 0x7f62368f,
|
||||
0x70e2cbc6, 0x5133cc94, 0x25280c5e, 0xf3742ca2, 0xc3a94590, 0x9d0dfe54, 0x8582faa5, 0x7fd8878e,
|
||||
0x7c29fbee, 0x73b5ebd1, 0x66cf8120, 0x55f5a4d2, 0x41ce1e65, 0x2b1f34eb, 0x12c8106f, 0xf9b82684,
|
||||
0xe0e60685, 0xc945dfec, 0xb3c0200c, 0xa1288376, 0x9235f2ec, 0x877b7bec, 0x8162aa04, 0x7ff62182,
|
||||
0x7f0991c4, 0x7ce3ceb2, 0x798a23b1, 0x7504d345, 0x6f5f02b2, 0x68a69e81, 0x60ec3830, 0x5842dd54,
|
||||
0x4ebfe8a5, 0x447acd50, 0x398cdd32, 0x2e110a62, 0x2223a4c5, 0x15e21445, 0x096a9049, 0xfcdbd541,
|
||||
0xf054d8d5, 0xe3f47d96, 0xd7d946d8, 0xcc210d79, 0xc0e8b648, 0xb64beacd, 0xac64d510, 0xa34bdf20,
|
||||
0x9b1776da, 0x93dbd6a0, 0x8daad37b, 0x8893b125, 0x84a2fc62, 0x81e26c16, 0x8058c94c, 0x7ffd885a,
|
||||
0x7fc25596, 0x7f3857f6, 0x7e5fe493, 0x7d3980ec, 0x7bc5e290, 0x7a05eead, 0x77fab989, 0x75a585cf,
|
||||
0x7307c3d0, 0x7023109a, 0x6cf934fc, 0x698c246c, 0x65ddfbd3, 0x61f1003f, 0x5dc79d7c, 0x59646498,
|
||||
0x54ca0a4b, 0x4ffb654d, 0x4afb6c98, 0x45cd358f, 0x4073f21d, 0x3af2eeb7, 0x354d9057, 0x2f875262,
|
||||
0x29a3c485, 0x23a6887f, 0x1d934fe5, 0x176dd9de, 0x1139f0cf, 0x0afb6805, 0x04b6195d, 0xfe6de2e0,
|
||||
0xf826a462, 0xf1e43d1c, 0xebaa894f, 0xe57d5fda, 0xdf608fe4, 0xd957de7a, 0xd3670446, 0xcd91ab39,
|
||||
0xc7db6c50, 0xc247cd5a, 0xbcda3ecb, 0xb796199b, 0xb27e9d3c, 0xad96ed92, 0xa8e21106, 0xa462eeac,
|
||||
0xa01c4c73, 0x9c10cd70, 0x9842f043, 0x94b50d87, 0x91695663, 0x8e61d32e, 0x8ba0622f, 0x8926b677,
|
||||
0x86f656d3, 0x85109cdd, 0x8376b422, 0x82299971, 0x812a1a3a, 0x8078d40d, 0x80163440, 0x7fffd886,
|
||||
0x7ffc250f, 0x7ff38274, 0x7fe5f108, 0x7fd37153, 0x7fbc040a, 0x7f9faa15, 0x7f7e648c, 0x7f5834b7,
|
||||
0x7f2d1c0e, 0x7efd1c3c, 0x7ec8371a, 0x7e8e6eb2, 0x7e4fc53e, 0x7e0c3d29, 0x7dc3d90d, 0x7d769bb5,
|
||||
0x7d24881b, 0x7ccda169, 0x7c71eaf9, 0x7c116853, 0x7bac1d31, 0x7b420d7a, 0x7ad33d45, 0x7a5fb0d8,
|
||||
0x79e76ca7, 0x796a7554, 0x78e8cfb2, 0x786280bf, 0x77d78daa, 0x7747fbce, 0x76b3d0b4, 0x761b1211,
|
||||
0x757dc5ca, 0x74dbf1ef, 0x74359cbd, 0x738acc9e, 0x72db8828, 0x7227d61c, 0x716fbd68, 0x70b34525,
|
||||
0x6ff27497, 0x6f2d532c, 0x6e63e87f, 0x6d963c54, 0x6cc45698, 0x6bee3f62, 0x6b13fef5, 0x6a359db9,
|
||||
0x69532442, 0x686c9b4b, 0x67820bb7, 0x66937e91, 0x65a0fd0b, 0x64aa907f, 0x63b0426d, 0x62b21c7b,
|
||||
0x61b02876, 0x60aa7050, 0x5fa0fe1f, 0x5e93dc1f, 0x5d8314b1, 0x5c6eb258, 0x5b56bfbd, 0x5a3b47ab,
|
||||
0x591c550e, 0x57f9f2f8, 0x56d42c99, 0x55ab0d46, 0x547ea073, 0x534ef1b5, 0x521c0cc2, 0x50e5fd6d,
|
||||
0x4faccfab, 0x4e708f8f, 0x4d31494b, 0x4bef092d, 0x4aa9dba2, 0x4961cd33, 0x4816ea86, 0x46c9405c,
|
||||
0x4578db93, 0x4425c923, 0x42d0161e, 0x4177cfb1, 0x401d0321, 0x3ebfbdcd, 0x3d600d2c, 0x3bfdfecd,
|
||||
0x3a99a057, 0x3932ff87, 0x37ca2a30, 0x365f2e3b, 0x34f219a8, 0x3382fa88, 0x3211df04, 0x309ed556,
|
||||
0x2f29ebcc, 0x2db330c7, 0x2c3ab2b9, 0x2ac08026, 0x2944a7a2, 0x27c737d3, 0x26483f6c, 0x24c7cd33,
|
||||
0x2345eff8, 0x21c2b69c, 0x203e300d, 0x1eb86b46, 0x1d31774d, 0x1ba96335, 0x1a203e1b, 0x18961728,
|
||||
0x170afd8d, 0x157f0086, 0x13f22f58, 0x1264994e, 0x10d64dbd, 0x0f475bff, 0x0db7d376, 0x0c27c389,
|
||||
0x0a973ba5, 0x09064b3a, 0x077501be, 0x05e36ea9, 0x0451a177, 0x02bfa9a4, 0x012d96b1, 0x00000000,
|
||||
};
|
||||
|
||||
DECLFUNC const INT32 *gaa_wsin_ldac[LDAC_NUMLNN];
|
||||
static const INT32 sa_wsin_1fs_ldac[LDAC_1FSLSU] = { /* Q31 */
|
||||
0x5a82799a, 0x30fbc54d, 0x7641af3d, 0x18f8b83c, 0x6a6d98a4, 0x7d8a5f40, 0x471cece7, 0x0c8bd35e,
|
||||
0x3c56ba70, 0x62f201ac, 0x7a7d055b, 0x7f62368f, 0x70e2cbc6, 0x5133cc94, 0x25280c5e, 0x0647d97c,
|
||||
0x1f19f97b, 0x36ba2014, 0x4c3fdff4, 0x5ed77c8a, 0x6dca0d14, 0x78848414, 0x7e9d55fc, 0x7fd8878e,
|
||||
0x7c29fbee, 0x73b5ebd1, 0x66cf8120, 0x55f5a4d2, 0x41ce1e65, 0x2b1f34eb, 0x12c8106f, 0x03242abf,
|
||||
0x0fab272b, 0x1c0b826a, 0x2826b928, 0x33def287, 0x3f1749b8, 0x49b41533, 0x539b2af0, 0x5cb420e0,
|
||||
0x64e88926, 0x6c242960, 0x72552c85, 0x776c4edb, 0x7b5d039e, 0x7e1d93ea, 0x7fa736b4, 0x7ff62182,
|
||||
0x7f0991c4, 0x7ce3ceb2, 0x798a23b1, 0x7504d345, 0x6f5f02b2, 0x68a69e81, 0x60ec3830, 0x5842dd54,
|
||||
0x4ebfe8a5, 0x447acd50, 0x398cdd32, 0x2e110a62, 0x2223a4c5, 0x15e21445, 0x096a9049, 0x00c90f88,
|
||||
0x03ed26e6, 0x0710a345, 0x0a3308bd, 0x0d53db92, 0x1072a048, 0x138edbb1, 0x16a81305, 0x19bdcbf3,
|
||||
0x1ccf8cb3, 0x1fdcdc1b, 0x22e541af, 0x25e845b6, 0x28e5714b, 0x2bdc4e6f, 0x2ecc681e, 0x31b54a5e,
|
||||
0x34968250, 0x376f9e46, 0x3a402dd2, 0x3d07c1d6, 0x3fc5ec98, 0x427a41d0, 0x452456bd, 0x47c3c22f,
|
||||
0x4a581c9e, 0x4ce10034, 0x4f5e08e3, 0x51ced46e, 0x5433027d, 0x568a34a9, 0x58d40e8c, 0x5b1035cf,
|
||||
0x5d3e5237, 0x5f5e0db3, 0x616f146c, 0x637114cc, 0x6563bf92, 0x6746c7d8, 0x6919e320, 0x6adcc964,
|
||||
0x6c8f351c, 0x6e30e34a, 0x6fc19385, 0x71410805, 0x72af05a7, 0x740b53fb, 0x7555bd4c, 0x768e0ea6,
|
||||
0x77b417df, 0x78c7aba2, 0x79c89f6e, 0x7ab6cba4, 0x7b920b89, 0x7c5a3d50, 0x7d0f4218, 0x7db0fdf8,
|
||||
0x7e3f57ff, 0x7eba3a39, 0x7f2191b4, 0x7f754e80, 0x7fb563b3, 0x7fe1c76b, 0x7ffa72d1, 0x00000000,
|
||||
};
|
||||
static const INT32 sa_wsin_2fs_ldac[LDAC_2FSLSU] = { /* Q31 */
|
||||
0x5a82799a, 0x30fbc54d, 0x7641af3d, 0x18f8b83c, 0x6a6d98a4, 0x7d8a5f40, 0x471cece7, 0x0c8bd35e,
|
||||
0x3c56ba70, 0x62f201ac, 0x7a7d055b, 0x7f62368f, 0x70e2cbc6, 0x5133cc94, 0x25280c5e, 0x0647d97c,
|
||||
0x1f19f97b, 0x36ba2014, 0x4c3fdff4, 0x5ed77c8a, 0x6dca0d14, 0x78848414, 0x7e9d55fc, 0x7fd8878e,
|
||||
0x7c29fbee, 0x73b5ebd1, 0x66cf8120, 0x55f5a4d2, 0x41ce1e65, 0x2b1f34eb, 0x12c8106f, 0x03242abf,
|
||||
0x0fab272b, 0x1c0b826a, 0x2826b928, 0x33def287, 0x3f1749b8, 0x49b41533, 0x539b2af0, 0x5cb420e0,
|
||||
0x64e88926, 0x6c242960, 0x72552c85, 0x776c4edb, 0x7b5d039e, 0x7e1d93ea, 0x7fa736b4, 0x7ff62182,
|
||||
0x7f0991c4, 0x7ce3ceb2, 0x798a23b1, 0x7504d345, 0x6f5f02b2, 0x68a69e81, 0x60ec3830, 0x5842dd54,
|
||||
0x4ebfe8a5, 0x447acd50, 0x398cdd32, 0x2e110a62, 0x2223a4c5, 0x15e21445, 0x096a9049, 0x01921d20,
|
||||
0x07d95b9e, 0x0e1bc2e4, 0x145576b1, 0x1a82a026, 0x209f701c, 0x26a82186, 0x2c98fbba, 0x326e54c7,
|
||||
0x382493b0, 0x3db832a6, 0x4325c135, 0x4869e665, 0x4d8162c4, 0x5269126e, 0x571deefa, 0x5b9d1154,
|
||||
0x5fe3b38d, 0x63ef3290, 0x67bd0fbd, 0x6b4af279, 0x6e96a99d, 0x719e2cd2, 0x745f9dd1, 0x76d94989,
|
||||
0x7909a92d, 0x7aef6323, 0x7c894bde, 0x7dd6668f, 0x7ed5e5c6, 0x7f872bf3, 0x7fe9cbc0, 0x7ffd885a,
|
||||
0x7fc25596, 0x7f3857f6, 0x7e5fe493, 0x7d3980ec, 0x7bc5e290, 0x7a05eead, 0x77fab989, 0x75a585cf,
|
||||
0x7307c3d0, 0x7023109a, 0x6cf934fc, 0x698c246c, 0x65ddfbd3, 0x61f1003f, 0x5dc79d7c, 0x59646498,
|
||||
0x54ca0a4b, 0x4ffb654d, 0x4afb6c98, 0x45cd358f, 0x4073f21d, 0x3af2eeb7, 0x354d9057, 0x2f875262,
|
||||
0x29a3c485, 0x23a6887f, 0x1d934fe5, 0x176dd9de, 0x1139f0cf, 0x0afb6805, 0x04b6195d, 0x006487e3,
|
||||
0x01f6a297, 0x0388a9ea, 0x051a8e5c, 0x06ac406f, 0x083db0a7, 0x09cecf89, 0x0b5f8d9f, 0x0cefdb76,
|
||||
0x0e7fa99e, 0x100ee8ad, 0x119d8941, 0x132b7bf9, 0x14b8b17f, 0x16451a83, 0x17d0a7bc, 0x195b49ea,
|
||||
0x1ae4f1d6, 0x1c6d9053, 0x1df5163f, 0x1f7b7481, 0x21009c0c, 0x22847de0, 0x24070b08, 0x2588349d,
|
||||
0x2707ebc7, 0x288621b9, 0x2a02c7b8, 0x2b7dcf17, 0x2cf72939, 0x2e6ec792, 0x2fe49ba7, 0x3158970e,
|
||||
0x32caab6f, 0x343aca87, 0x35a8e625, 0x3714f02a, 0x387eda8e, 0x39e6975e, 0x3b4c18ba, 0x3caf50da,
|
||||
0x3e10320d, 0x3f6eaeb8, 0x40cab958, 0x42244481, 0x437b42e1, 0x44cfa740, 0x4621647d, 0x47706d93,
|
||||
0x48bcb599, 0x4a062fbd, 0x4b4ccf4d, 0x4c9087b1, 0x4dd14c6e, 0x4f0f1126, 0x5049c999, 0x518169a5,
|
||||
0x52b5e546, 0x53e73097, 0x55153fd4, 0x56400758, 0x57677b9d, 0x588b9140, 0x59ac3cfd, 0x5ac973b5,
|
||||
0x5be32a67, 0x5cf95638, 0x5e0bec6e, 0x5f1ae274, 0x60262dd6, 0x612dc447, 0x62319b9d, 0x6331a9d4,
|
||||
0x642de50d, 0x6526438f, 0x661abbc5, 0x670b4444, 0x67f7d3c5, 0x68e06129, 0x69c4e37a, 0x6aa551e9,
|
||||
0x6b81a3cd, 0x6c59d0a9, 0x6d2dd027, 0x6dfd9a1c, 0x6ec92683, 0x6f906d84, 0x70536771, 0x71120cc5,
|
||||
0x71cc5626, 0x72823c67, 0x7333b883, 0x73e0c3a3, 0x7489571c, 0x752d6c6c, 0x75ccfd42, 0x76680376,
|
||||
0x76fe790e, 0x7790583e, 0x781d9b65, 0x78a63d11, 0x792a37fe, 0x79a98715, 0x7a24256f, 0x7a9a0e50,
|
||||
0x7b0b3d2c, 0x7b77ada8, 0x7bdf5b94, 0x7c4242f2, 0x7ca05ff1, 0x7cf9aef0, 0x7d4e2c7f, 0x7d9dd55a,
|
||||
0x7de8a670, 0x7e2e9cdf, 0x7e6fb5f4, 0x7eabef2c, 0x7ee34636, 0x7f15b8ee, 0x7f434563, 0x7f6be9d4,
|
||||
0x7f8fa4b0, 0x7fae7495, 0x7fc85854, 0x7fdd4eec, 0x7fed5791, 0x7ff871a2, 0x7ffe9cb2, 0x00000000,
|
||||
};
|
||||
|
||||
DECLFUNC const int *gaa_perm_ldac[LDAC_NUMLNN];
|
||||
static const int sa_perm_1fs_ldac[LDAC_1FSLSU] = {
|
||||
0, 64, 96, 32, 48, 112, 80, 16, 24, 88, 120, 56, 40, 104, 72, 8,
|
||||
12, 76, 108, 44, 60, 124, 92, 28, 20, 84, 116, 52, 36, 100, 68, 4,
|
||||
6, 70, 102, 38, 54, 118, 86, 22, 30, 94, 126, 62, 46, 110, 78, 14,
|
||||
10, 74, 106, 42, 58, 122, 90, 26, 18, 82, 114, 50, 34, 98, 66, 2,
|
||||
3, 67, 99, 35, 51, 115, 83, 19, 27, 91, 123, 59, 43, 107, 75, 11,
|
||||
15, 79, 111, 47, 63, 127, 95, 31, 23, 87, 119, 55, 39, 103, 71, 7,
|
||||
5, 69, 101, 37, 53, 117, 85, 21, 29, 93, 125, 61, 45, 109, 77, 13,
|
||||
9, 73, 105, 41, 57, 121, 89, 25, 17, 81, 113, 49, 33, 97, 65, 1,
|
||||
};
|
||||
static const int sa_perm_2fs_ldac[LDAC_2FSLSU] = {
|
||||
0, 128, 192, 64, 96, 224, 160, 32, 48, 176, 240, 112, 80, 208, 144, 16,
|
||||
24, 152, 216, 88, 120, 248, 184, 56, 40, 168, 232, 104, 72, 200, 136, 8,
|
||||
12, 140, 204, 76, 108, 236, 172, 44, 60, 188, 252, 124, 92, 220, 156, 28,
|
||||
20, 148, 212, 84, 116, 244, 180, 52, 36, 164, 228, 100, 68, 196, 132, 4,
|
||||
6, 134, 198, 70, 102, 230, 166, 38, 54, 182, 246, 118, 86, 214, 150, 22,
|
||||
30, 158, 222, 94, 126, 254, 190, 62, 46, 174, 238, 110, 78, 206, 142, 14,
|
||||
10, 138, 202, 74, 106, 234, 170, 42, 58, 186, 250, 122, 90, 218, 154, 26,
|
||||
18, 146, 210, 82, 114, 242, 178, 50, 34, 162, 226, 98, 66, 194, 130, 2,
|
||||
3, 131, 195, 67, 99, 227, 163, 35, 51, 179, 243, 115, 83, 211, 147, 19,
|
||||
27, 155, 219, 91, 123, 251, 187, 59, 43, 171, 235, 107, 75, 203, 139, 11,
|
||||
15, 143, 207, 79, 111, 239, 175, 47, 63, 191, 255, 127, 95, 223, 159, 31,
|
||||
23, 151, 215, 87, 119, 247, 183, 55, 39, 167, 231, 103, 71, 199, 135, 7,
|
||||
5, 133, 197, 69, 101, 229, 165, 37, 53, 181, 245, 117, 85, 213, 149, 21,
|
||||
29, 157, 221, 93, 125, 253, 189, 61, 45, 173, 237, 109, 77, 205, 141, 13,
|
||||
9, 137, 201, 73, 105, 233, 169, 41, 57, 185, 249, 121, 89, 217, 153, 25,
|
||||
17, 145, 209, 81, 113, 241, 177, 49, 33, 161, 225, 97, 65, 193, 129, 1,
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Normalization Tables
|
||||
***************************************************************************************************/
|
||||
/* Scale Factor for Spectrum Normalization */
|
||||
DECLFUNC const INT32 ga_sf_ldac[LDAC_NIDSF] = { /* Q15 */
|
||||
0x00000001, 0x00000002, 0x00000004, 0x00000008,
|
||||
0x00000010, 0x00000020, 0x00000040, 0x00000080,
|
||||
0x00000100, 0x00000200, 0x00000400, 0x00000800,
|
||||
0x00001000, 0x00002000, 0x00004000, 0x00008000,
|
||||
0x00010000, 0x00020000, 0x00040000, 0x00080000,
|
||||
0x00100000, 0x00200000, 0x00400000, 0x00800000,
|
||||
0x01000000, 0x02000000, 0x04000000, 0x08000000,
|
||||
0x10000000, 0x20000000, 0x40000000, 0x7fffffff,
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Quantization Tables
|
||||
***************************************************************************************************/
|
||||
/* Quantize Factor for Spectrum/Residual Quantization */
|
||||
DECLFUNC const INT32 ga_qf_ldac[LDAC_NIDWL] = { /* Q16 */
|
||||
0x00008000, 0x00018000, 0x00038000, 0x00078000,
|
||||
0x000f8000, 0x001f8000, 0x003f8000, 0x007f8000,
|
||||
0x00ff8000, 0x01ff8000, 0x03ff8000, 0x07ff8000,
|
||||
0x0fff8000, 0x1fff8000, 0x3fff8000, 0x7fff8000,
|
||||
};
|
||||
|
||||
/* Inverse of Quantize Factor for Spectrum/Residual Quantization */
|
||||
DECLFUNC const INT32 ga_iqf_ldac[LDAC_NIDWL] = { /* Q31 */
|
||||
0x80000000, 0x55555555, 0x24924925, 0x11111111,
|
||||
0x08421084, 0x04104104, 0x02040810, 0x01010101,
|
||||
0x00804020, 0x00401004, 0x00200401, 0x00100100,
|
||||
0x00080040, 0x00040010, 0x00020004, 0x00010001,
|
||||
};
|
||||
|
||||
/* Inverse of Scale Factor for Residual Normalization */
|
||||
DECLFUNC const INT32 ga_irsf_ldac[LDAC_NIDWL] = { /* Q15 */
|
||||
0x00007f80, 0x00017e80, 0x00037c80, 0x00077880,
|
||||
0x000f7080, 0x001f6080, 0x003f4080, 0x007f0080,
|
||||
0x00fe8080, 0x01fd8080, 0x03fb8080, 0x07f78080,
|
||||
0x0fef8080, 0x1fdf8080, 0x3fbf8080, 0x7f7f8080,
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Set MDCT Tables
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void set_mdct_table_ldac(
|
||||
int nlnn)
|
||||
{
|
||||
int index = nlnn - LDAC_1FSLNN;
|
||||
|
||||
if (nlnn == LDAC_1FSLNN) {
|
||||
gaa_fwin_ldac[index] = sa_fwin_1fs_ldac;
|
||||
gaa_wcos_ldac[index] = sa_wcos_1fs_ldac;
|
||||
gaa_wsin_ldac[index] = sa_wsin_1fs_ldac;
|
||||
gaa_perm_ldac[index] = sa_perm_1fs_ldac;
|
||||
}
|
||||
else if (nlnn == LDAC_2FSLNN) {
|
||||
gaa_fwin_ldac[index] = sa_fwin_2fs_ldac;
|
||||
gaa_wcos_ldac[index] = sa_wcos_2fs_ldac;
|
||||
gaa_wsin_ldac[index] = sa_wsin_2fs_ldac;
|
||||
gaa_perm_ldac[index] = sa_perm_2fs_ldac;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,431 @@
|
|||
/*
|
||||
* Copyright (C) 2003 - 2016 Sony Corporation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ldac.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
Window Tables
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const SCALAR *gaa_fwin_ldac[LDAC_NUMLNN];
|
||||
static const SCALAR sa_fwin_1fs_ldac[LDAC_1FSLSU] = {
|
||||
3.7649080427729667e-05, 3.3880770582525241e-04, 9.4094354992539870e-04, 1.8436939086109933e-03,
|
||||
3.0465149988219862e-03, 4.5486822861099899e-03, 6.3492909210708052e-03, 8.4472562843918454e-03,
|
||||
1.0841314640186185e-02, 1.3530023897219945e-02, 1.6511764477573954e-02, 1.9784740292217093e-02,
|
||||
2.3346979822903100e-02, 2.7196337309739343e-02, 3.1330494043712527e-02, 3.5746959763392233e-02,
|
||||
4.0443074154971129e-02, 4.5416008454738845e-02, 5.0662767153023092e-02, 5.6180189798573019e-02,
|
||||
6.1964952902296720e-02, 6.8013571939206638e-02, 7.4322403447367416e-02, 8.0887647222581002e-02,
|
||||
8.7705348607487368e-02, 9.4771400873702616e-02, 1.0208154769555824e-01, 1.0963138571395278e-01,
|
||||
1.1741636718877053e-01, 1.2543180273827034e-01, 1.3367286416379359e-01, 1.4213458735809070e-01,
|
||||
1.5081187529551357e-01, 1.5969950110227349e-01, 1.6879211120491414e-01, 1.7808422855510431e-01,
|
||||
1.8757025592880680e-01, 1.9724447929783726e-01, 2.0710107127178060e-01, 2.1713409460819344e-01,
|
||||
2.2733750578897677e-01, 2.3770515866076555e-01, 2.4823080813714124e-01, 2.5890811396043867e-01,
|
||||
2.6973064452088003e-01, 2.8069188073073620e-01, 2.9178521995118140e-01, 3.0300397996947592e-01,
|
||||
3.1434140302408126e-01, 3.2579065987528272e-01, 3.3734485391886854e-01, 3.4899702534038596e-01,
|
||||
3.6074015530747344e-01, 3.7256717019774271e-01, 3.8447094585966446e-01, 3.9644431190389073e-01,
|
||||
4.0848005602242954e-01, 4.2057092833306925e-01, 4.3270964574643694e-01, 4.4488889635305845e-01,
|
||||
4.5710134382778006e-01, 4.6933963184889571e-01, 4.8159638852932057e-01, 4.9386423085714004e-01,
|
||||
5.0613576914285996e-01, 5.1840361147067937e-01, 5.3066036815110429e-01, 5.4289865617222000e-01,
|
||||
5.5511110364694149e-01, 5.6729035425356311e-01, 5.7942907166693070e-01, 5.9151994397757046e-01,
|
||||
6.0355568809610927e-01, 6.1552905414033554e-01, 6.2743282980225734e-01, 6.3925984469252650e-01,
|
||||
6.5100297465961399e-01, 6.6265514608113141e-01, 6.7420934012471734e-01, 6.8565859697591880e-01,
|
||||
6.9699602003052408e-01, 7.0821478004881855e-01, 7.1930811926926386e-01, 7.3026935547911997e-01,
|
||||
7.4109188603956133e-01, 7.5176919186285873e-01, 7.6229484133923442e-01, 7.7266249421102318e-01,
|
||||
7.8286590539180656e-01, 7.9289892872821943e-01, 8.0275552070216272e-01, 8.1242974407119317e-01,
|
||||
8.2191577144489569e-01, 8.3120788879508589e-01, 8.4030049889772651e-01, 8.4918812470448646e-01,
|
||||
8.5786541264190930e-01, 8.6632713583620635e-01, 8.7456819726172963e-01, 8.8258363281122942e-01,
|
||||
8.9036861428604719e-01, 8.9791845230444178e-01, 9.0522859912629738e-01, 9.1229465139251265e-01,
|
||||
9.1911235277741898e-01, 9.2567759655263260e-01, 9.3198642806079335e-01, 9.3803504709770325e-01,
|
||||
9.4381981020142702e-01, 9.4933723284697691e-01, 9.5458399154526119e-01, 9.5955692584502883e-01,
|
||||
9.6425304023660774e-01, 9.6866950595628742e-01, 9.7280366269026064e-01, 9.7665302017709688e-01,
|
||||
9.8021525970778289e-01, 9.8348823552242604e-01, 9.8646997610278009e-01, 9.8915868535981377e-01,
|
||||
9.9155274371560820e-01, 9.9365070907892916e-01, 9.9545131771389006e-01, 9.9695348500117797e-01,
|
||||
9.9815630609138906e-01, 9.9905905645007465e-01, 9.9966119229417472e-01, 9.9996235091957231e-01,
|
||||
};
|
||||
static const SCALAR sa_fwin_2fs_ldac[LDAC_2FSLSU] = {
|
||||
9.4123586994287859e-06, 8.4709102088288972e-05, 2.3529124945341780e-04, 4.6113612367731146e-04,
|
||||
7.6220971335262645e-04, 1.1384666779041968e-03, 1.5898503544171428e-03, 2.1162927661701014e-03,
|
||||
2.7177146328722815e-03, 3.3940253826027396e-03, 4.1451231654502426e-03, 4.9708948688514491e-03,
|
||||
5.8712161346252531e-03, 6.8459513777006896e-03, 7.8949538065354735e-03, 9.0180654452223750e-03,
|
||||
1.0215117157279735e-02, 1.1485928671122823e-02, 1.2830308607212064e-02, 1.4248054506874127e-02,
|
||||
1.5738952862791353e-02, 1.7302779151155318e-02, 1.8939297865479203e-02, 2.0648262552064218e-02,
|
||||
2.2429415847114661e-02, 2.4282489515495831e-02, 2.6207204491129441e-02, 2.8203270919019821e-02,
|
||||
3.0270388198905041e-02, 3.2408245030526237e-02, 3.4616519460508151e-02, 3.6894878930844345e-02,
|
||||
3.9242980328979035e-02, 4.1660470039478668e-02, 4.4146983997285061e-02, 4.6702147742542340e-02,
|
||||
4.9325576476989007e-02, 5.2016875121907433e-02, 5.4775638377621054e-02, 5.7601450784531098e-02,
|
||||
6.0493886785683293e-02, 6.3452510790854968e-02, 6.6476877242153690e-02, 6.9566530681116359e-02,
|
||||
7.2721005817299733e-02, 7.5939827598351411e-02, 7.9222511281550820e-02, 8.2568562506809995e-02,
|
||||
8.5977477371122130e-02, 8.9448742504447690e-02, 9.2981835147025835e-02, 9.6576223228100361e-02,
|
||||
1.0023136544604751e-01, 1.0394671134989383e-01, 1.0772170142221238e-01, 1.1155576716338379e-01,
|
||||
1.1544833117721018e-01, 1.1939880725786912e-01, 1.2340660047819377e-01, 1.2747110727926703e-01,
|
||||
1.3159171556131508e-01, 1.3576780477588740e-01, 1.3999874601930917e-01, 1.4428390212739181e-01,
|
||||
1.4862262777138735e-01, 1.5301426955517303e-01, 1.5745816611364982e-01, 1.6195364821234201e-01,
|
||||
1.6650003884818126e-01, 1.7109665335146068e-01, 1.7574279948894378e-01, 1.8043777756811213e-01,
|
||||
1.8518088054253648e-01, 1.8997139411835545e-01, 1.9480859686184529e-01, 1.9969176030806554e-01,
|
||||
2.0462014907056292e-01, 2.0959302095211774e-01, 2.1460962705651634e-01, 2.1966921190133201e-01,
|
||||
2.2477101353169759e-01, 2.2991426363505360e-01, 2.3509818765685267e-01, 2.4032200491720521e-01,
|
||||
2.4558492872844651e-01, 2.5088616651360907e-01, 2.5622491992578200e-01, 2.6160038496833893e-01,
|
||||
2.6701175211601691e-01, 2.7245820643682811e-01, 2.7793892771478540e-01, 2.8345309057342405e-01,
|
||||
2.8899986460010013e-01, 2.9457841447104804e-01, 3.0018790007717661e-01, 3.0582747665058685e-01,
|
||||
3.1149629489179087e-01, 3.1719350109761307e-01, 3.2291823728975483e-01, 3.2866964134400284e-01,
|
||||
3.3444684712006179e-01, 3.4024898459199215e-01, 3.4607517997923254e-01, 3.5192455587818811e-01,
|
||||
3.5779623139436406e-01, 3.6368932227502548e-01, 3.6960294104236224e-01, 3.7553619712713993e-01,
|
||||
3.8148819700281639e-01, 3.8745804432010356e-01, 3.9344484004195435e-01, 3.9944768257895402e-01,
|
||||
4.0546566792509692e-01, 4.1149788979392560e-01, 4.1754343975501507e-01, 4.2360140737077828e-01,
|
||||
4.2967088033357537e-01, 4.3575094460310343e-01, 4.4184068454404762e-01, 4.4793918306397273e-01,
|
||||
4.5404552175143365e-01, 4.6015878101428492e-01, 4.6627804021816799e-01, 4.7240237782515504e-01,
|
||||
4.7853087153252960e-01, 4.8466259841168169e-01, 4.9079663504709758e-01, 4.9693205767542276e-01,
|
||||
5.0306794232457719e-01, 5.0920336495290242e-01, 5.1533740158831831e-01, 5.2146912846747040e-01,
|
||||
5.2759762217484496e-01, 5.3372195978183201e-01, 5.3984121898571502e-01, 5.4595447824856635e-01,
|
||||
5.5206081693602727e-01, 5.5815931545595243e-01, 5.6424905539689663e-01, 5.7032911966642463e-01,
|
||||
5.7639859262922166e-01, 5.8245656024498493e-01, 5.8850211020607435e-01, 5.9453433207490314e-01,
|
||||
6.0055231742104598e-01, 6.0655515995804565e-01, 6.1254195567989644e-01, 6.1851180299718356e-01,
|
||||
6.2446380287286007e-01, 6.3039705895763776e-01, 6.3631067772497452e-01, 6.4220376860563588e-01,
|
||||
6.4807544412181195e-01, 6.5392482002076746e-01, 6.5975101540800785e-01, 6.6555315287993821e-01,
|
||||
6.7133035865599722e-01, 6.7708176271024523e-01, 6.8280649890238698e-01, 6.8850370510820913e-01,
|
||||
6.9417252334941315e-01, 6.9981209992282345e-01, 7.0542158552895196e-01, 7.1100013539989981e-01,
|
||||
7.1654690942657595e-01, 7.2206107228521466e-01, 7.2754179356317195e-01, 7.3298824788398309e-01,
|
||||
7.3839961503166107e-01, 7.4377508007421800e-01, 7.4911383348639093e-01, 7.5441507127155349e-01,
|
||||
7.5967799508279477e-01, 7.6490181234314736e-01, 7.7008573636494637e-01, 7.7522898646830241e-01,
|
||||
7.8033078809866796e-01, 7.8539037294348368e-01, 7.9040697904788226e-01, 7.9537985092943708e-01,
|
||||
8.0030823969193443e-01, 8.0519140313815474e-01, 8.1002860588164460e-01, 8.1481911945746355e-01,
|
||||
8.1956222243188781e-01, 8.2425720051105622e-01, 8.2890334664853937e-01, 8.3349996115181868e-01,
|
||||
8.3804635178765796e-01, 8.4254183388635018e-01, 8.4698573044482695e-01, 8.5137737222861265e-01,
|
||||
8.5571609787260816e-01, 8.6000125398069083e-01, 8.6423219522411254e-01, 8.6840828443868490e-01,
|
||||
8.7252889272073297e-01, 8.7659339952180626e-01, 8.8060119274213089e-01, 8.8455166882278979e-01,
|
||||
8.8844423283661622e-01, 8.9227829857778762e-01, 8.9605328865010614e-01, 8.9976863455395251e-01,
|
||||
9.0342377677189967e-01, 9.0701816485297415e-01, 9.1055125749555232e-01, 9.1402252262887784e-01,
|
||||
9.1743143749319001e-01, 9.2077748871844922e-01, 9.2406017240164862e-01, 9.2727899418270032e-01,
|
||||
9.3043346931888360e-01, 9.3352312275784632e-01, 9.3654748920914499e-01, 9.3950611321431676e-01,
|
||||
9.4239854921546895e-01, 9.4522436162237899e-01, 9.4798312487809255e-01, 9.5067442352301101e-01,
|
||||
9.5329785225745767e-01, 9.5585301600271488e-01, 9.5833952996052130e-01, 9.6075701967102101e-01,
|
||||
9.6310512106915569e-01, 9.6538348053949186e-01, 9.6759175496947381e-01, 9.6972961180109496e-01,
|
||||
9.7179672908098014e-01, 9.7379279550887055e-01, 9.7571751048450417e-01, 9.7757058415288534e-01,
|
||||
9.7935173744793580e-01, 9.8106070213452079e-01, 9.8269722084884470e-01, 9.8426104713720863e-01,
|
||||
9.8575194549312584e-01, 9.8716969139278798e-01, 9.8851407132887714e-01, 9.8978488284272026e-01,
|
||||
9.9098193455477768e-01, 9.9210504619346451e-01, 9.9315404862229928e-01, 9.9412878386537473e-01,
|
||||
9.9502910513114851e-01, 9.9585487683454976e-01, 9.9660597461739731e-01, 9.9728228536712771e-01,
|
||||
9.9788370723382991e-01, 9.9841014964558283e-01, 9.9886153332209582e-01, 9.9923779028664739e-01,
|
||||
9.9953886387632274e-01, 9.9976470875054657e-01, 9.9991529089791176e-01, 9.9999058764130055e-01,
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
MDCT/IMDCT Tables
|
||||
***************************************************************************************************/
|
||||
DECLFUNC const SCALAR *gaa_wcos_ldac[LDAC_NUMLNN];
|
||||
static const SCALAR sa_wcos_1fs_ldac[LDAC_1FSLSU] = {
|
||||
7.0710678118654757e-01, 9.2387953251128674e-01,-3.8268343236508973e-01, 9.8078528040323043e-01,
|
||||
5.5557023301960229e-01,-1.9509032201612819e-01,-8.3146961230254535e-01, 9.9518472667219693e-01,
|
||||
8.8192126434835505e-01, 6.3439328416364549e-01, 2.9028467725446233e-01,-9.8017140329560645e-02,
|
||||
-4.7139673682599770e-01,-7.7301045336273699e-01,-9.5694033573220882e-01, 9.9879545620517241e-01,
|
||||
9.7003125319454397e-01, 9.0398929312344334e-01, 8.0320753148064494e-01, 6.7155895484701833e-01,
|
||||
5.1410274419322166e-01, 3.3688985339222005e-01, 1.4673047445536175e-01,-4.9067674327418008e-02,
|
||||
-2.4298017990326387e-01,-4.2755509343028186e-01,-5.9569930449243336e-01,-7.4095112535495888e-01,
|
||||
-8.5772861000027201e-01,-9.4154406518302070e-01,-9.8917650996478101e-01, 9.9969881869620425e-01,
|
||||
9.9247953459870997e-01, 9.7570213003852857e-01, 9.4952818059303667e-01, 9.1420975570353069e-01,
|
||||
8.7008699110871146e-01, 8.1758481315158371e-01, 7.5720884650648457e-01, 6.8954054473706694e-01,
|
||||
6.1523159058062682e-01, 5.3499761988709726e-01, 4.4961132965460660e-01, 3.5989503653498828e-01,
|
||||
2.6671275747489842e-01, 1.7096188876030136e-01, 7.3564563599667454e-02,-2.4541228522912142e-02,
|
||||
-1.2241067519921615e-01,-2.1910124015686966e-01,-3.1368174039889141e-01,-4.0524131400498975e-01,
|
||||
-4.9289819222978398e-01,-5.7580819141784534e-01,-6.5317284295377653e-01,-7.2424708295146678e-01,
|
||||
-7.8834642762660623e-01,-8.4485356524970712e-01,-8.9322430119551521e-01,-9.3299279883473885e-01,
|
||||
-9.6377606579543984e-01,-9.8527764238894122e-01,-9.9729045667869021e-01, 9.9998117528260111e-01,
|
||||
9.9952941750109314e-01, 9.9847558057329477e-01, 9.9682029929116567e-01, 9.9456457073425542e-01,
|
||||
9.9170975366909953e-01, 9.8825756773074946e-01, 9.8421009238692903e-01, 9.7956976568544052e-01,
|
||||
9.7433938278557586e-01, 9.6852209427441738e-01, 9.6212140426904158e-01, 9.5514116830577078e-01,
|
||||
9.4758559101774109e-01, 9.3945922360218992e-01, 9.3076696107898371e-01, 9.2151403934204201e-01,
|
||||
9.1170603200542988e-01, 9.0134884704602203e-01, 8.9044872324475788e-01, 8.7901222642863353e-01,
|
||||
8.6704624551569265e-01, 8.5455798836540053e-01, 8.4155497743689844e-01, 8.2804504525775580e-01,
|
||||
8.1403632970594841e-01, 7.9953726910790501e-01, 7.8455659715557524e-01, 7.6910333764557970e-01,
|
||||
7.5318679904361252e-01, 7.3681656887736990e-01, 7.2000250796138165e-01, 7.0275474445722530e-01,
|
||||
6.8508366777270036e-01, 6.6699992230363747e-01, 6.4851440102211255e-01, 6.2963823891492710e-01,
|
||||
6.1038280627630948e-01, 5.9075970185887428e-01, 5.7078074588696737e-01, 5.5045797293660481e-01,
|
||||
5.2980362468629483e-01, 5.0883014254310699e-01, 4.8755016014843605e-01, 4.6597649576796613e-01,
|
||||
4.4412214457042926e-01, 4.2200027079979979e-01, 3.9962419984564679e-01, 3.7700741021641831e-01,
|
||||
3.5416352542049051e-01, 3.3110630575987643e-01, 3.0784964004153498e-01, 2.8440753721127182e-01,
|
||||
2.6079411791527557e-01, 2.3702360599436734e-01, 2.1311031991609136e-01, 1.8906866414980628e-01,
|
||||
1.6491312048997009e-01, 1.4065823933284924e-01, 1.1631863091190488e-01, 9.1908956497132696e-02,
|
||||
6.7443919563664106e-02, 4.2938256934940959e-02, 1.8406729905804820e-02, 0.0000000000000000e+00,
|
||||
};
|
||||
static const SCALAR sa_wcos_2fs_ldac[LDAC_2FSLSU] = {
|
||||
7.0710678118654757e-01, 9.2387953251128674e-01,-3.8268343236508973e-01, 9.8078528040323043e-01,
|
||||
5.5557023301960229e-01,-1.9509032201612819e-01,-8.3146961230254535e-01, 9.9518472667219693e-01,
|
||||
8.8192126434835505e-01, 6.3439328416364549e-01, 2.9028467725446233e-01,-9.8017140329560645e-02,
|
||||
-4.7139673682599770e-01,-7.7301045336273699e-01,-9.5694033573220882e-01, 9.9879545620517241e-01,
|
||||
9.7003125319454397e-01, 9.0398929312344334e-01, 8.0320753148064494e-01, 6.7155895484701833e-01,
|
||||
5.1410274419322166e-01, 3.3688985339222005e-01, 1.4673047445536175e-01,-4.9067674327418008e-02,
|
||||
-2.4298017990326387e-01,-4.2755509343028186e-01,-5.9569930449243336e-01,-7.4095112535495888e-01,
|
||||
-8.5772861000027201e-01,-9.4154406518302070e-01,-9.8917650996478101e-01, 9.9969881869620425e-01,
|
||||
9.9247953459870997e-01, 9.7570213003852857e-01, 9.4952818059303667e-01, 9.1420975570353069e-01,
|
||||
8.7008699110871146e-01, 8.1758481315158371e-01, 7.5720884650648457e-01, 6.8954054473706694e-01,
|
||||
6.1523159058062682e-01, 5.3499761988709726e-01, 4.4961132965460660e-01, 3.5989503653498828e-01,
|
||||
2.6671275747489842e-01, 1.7096188876030136e-01, 7.3564563599667454e-02,-2.4541228522912142e-02,
|
||||
-1.2241067519921615e-01,-2.1910124015686966e-01,-3.1368174039889141e-01,-4.0524131400498975e-01,
|
||||
-4.9289819222978398e-01,-5.7580819141784534e-01,-6.5317284295377653e-01,-7.2424708295146678e-01,
|
||||
-7.8834642762660623e-01,-8.4485356524970712e-01,-8.9322430119551521e-01,-9.3299279883473885e-01,
|
||||
-9.6377606579543984e-01,-9.8527764238894122e-01,-9.9729045667869021e-01, 9.9992470183914450e-01,
|
||||
9.9811811290014918e-01, 9.9390697000235606e-01, 9.8730141815785843e-01, 9.7831737071962765e-01,
|
||||
9.6697647104485207e-01, 9.5330604035419386e-01, 9.3733901191257496e-01, 9.1911385169005777e-01,
|
||||
8.9867446569395382e-01, 8.7607009419540660e-01, 8.5135519310526520e-01, 8.2458930278502529e-01,
|
||||
7.9583690460888357e-01, 7.6516726562245896e-01, 7.3265427167241282e-01, 6.9837624940897292e-01,
|
||||
6.6241577759017178e-01, 6.2485948814238645e-01, 5.8579785745643886e-01, 5.4532498842204646e-01,
|
||||
5.0353838372571758e-01, 4.6053871095824001e-01, 4.1642956009763732e-01, 3.7131719395183760e-01,
|
||||
3.2531029216226298e-01, 2.7851968938505306e-01, 2.3105810828067128e-01, 1.8303988795514106e-01,
|
||||
1.3458070850712622e-01, 8.5797312344439880e-02, 3.6807222941358991e-02,-1.2271538285719823e-02,
|
||||
-6.1320736302208530e-02,-1.1022220729388306e-01,-1.5885814333386128e-01,-2.0711137619221845e-01,
|
||||
-2.5486565960451452e-01,-3.0200594931922808e-01,-3.4841868024943440e-01,-3.9399204006104799e-01,
|
||||
-4.3861623853852738e-01,-4.8218377207912272e-01,-5.2458968267846873e-01,-5.6573181078361323e-01,
|
||||
-6.0551104140432543e-01,-6.4383154288979128e-01,-6.8060099779545302e-01,-7.1573082528381859e-01,
|
||||
-7.4913639452345915e-01,-7.8073722857209449e-01,-8.1045719825259466e-01,-8.3822470555483808e-01,
|
||||
-8.6397285612158670e-01,-8.8763962040285382e-01,-9.0916798309052238e-01,-9.2850608047321548e-01,
|
||||
-9.4560732538052117e-01,-9.6043051941556579e-01,-9.7293995220556007e-01,-9.8310548743121629e-01,
|
||||
-9.9090263542778001e-01,-9.9631261218277800e-01,-9.9932238458834954e-01, 9.9999529380957619e-01,
|
||||
9.9988234745421256e-01, 9.9961882249517864e-01, 9.9920475861836389e-01, 9.9864021818026527e-01,
|
||||
9.9792528619859600e-01, 9.9706007033948296e-01, 9.9604470090125197e-01, 9.9487933079480562e-01,
|
||||
9.9356413552059530e-01, 9.9209931314219180e-01, 9.9048508425645709e-01, 9.8872169196032378e-01,
|
||||
9.8680940181418553e-01, 9.8474850180190421e-01, 9.8253930228744124e-01, 9.8018213596811743e-01,
|
||||
9.7767735782450993e-01, 9.7502534506699412e-01, 9.7222649707893627e-01, 9.6928123535654853e-01,
|
||||
9.6619000344541250e-01, 9.6295326687368388e-01, 9.5957151308198452e-01, 9.5604525134999641e-01,
|
||||
9.5237501271976588e-01, 9.4856134991573027e-01, 9.4460483726148026e-01, 9.4050607059326830e-01,
|
||||
9.3626566717027826e-01, 9.3188426558166815e-01, 9.2736252565040111e-01, 9.2270112833387863e-01,
|
||||
9.1790077562139050e-01, 9.1296219042839821e-01, 9.0788611648766626e-01, 9.0267331823725883e-01,
|
||||
8.9732458070541832e-01, 8.9184070939234272e-01, 8.8622253014888064e-01, 8.8047088905216075e-01,
|
||||
8.7458665227817611e-01, 8.6857070597134090e-01, 8.6242395611104061e-01, 8.5614732837519447e-01,
|
||||
8.4974176800085255e-01, 8.4320823964184544e-01, 8.3654772722351201e-01, 8.2976123379452305e-01,
|
||||
8.2284978137582643e-01, 8.1581441080673378e-01, 8.0865618158817498e-01, 8.0137617172314024e-01,
|
||||
7.9397547755433717e-01, 7.8645521359908577e-01, 7.7881651238147598e-01, 7.7106052426181382e-01,
|
||||
7.6318841726338127e-01, 7.5520137689653655e-01, 7.4710060598018013e-01, 7.3888732446061511e-01,
|
||||
7.3056276922782759e-01, 7.2212819392921535e-01, 7.1358486878079364e-01, 7.0493408037590499e-01,
|
||||
6.9617713149146299e-01, 6.8731534089175916e-01, 6.7835004312986158e-01, 6.6928258834663601e-01,
|
||||
6.6011434206742048e-01, 6.5084668499638099e-01, 6.4148101280858316e-01, 6.3201873593980906e-01,
|
||||
6.2246127937415008e-01, 6.1281008242940971e-01, 6.0306659854034828e-01, 5.9323229503979980e-01,
|
||||
5.8330865293769829e-01, 5.7329716669804232e-01, 5.6319934401383409e-01, 5.5301670558002758e-01,
|
||||
5.4275078486451600e-01, 5.3240312787719801e-01, 5.2197529293715439e-01, 5.1146885043797052e-01,
|
||||
5.0088538261124094e-01, 4.9022648328829110e-01, 4.7949375766015301e-01, 4.6868882203582796e-01,
|
||||
4.5781330359887729e-01, 4.4686884016237433e-01, 4.3585707992225547e-01, 4.2477968120910881e-01,
|
||||
4.1363831223843456e-01, 4.0243465085941854e-01, 3.9117038430225398e-01, 3.7984720892405111e-01,
|
||||
3.6846682995337232e-01, 3.5703096123343003e-01, 3.4554132496398915e-01, 3.3399965144200949e-01,
|
||||
3.2240767880107002e-01, 3.1076715274961147e-01, 2.9907982630804048e-01, 2.8734745954472957e-01,
|
||||
2.7557181931095825e-01, 2.6375467897483151e-01, 2.5189781815421691e-01, 2.4000302244874150e-01,
|
||||
2.2807208317088579e-01, 2.1610679707621960e-01, 2.0410896609281701e-01, 1.9208039704989238e-01,
|
||||
1.8002290140569951e-01, 1.6793829497473123e-01, 1.5582839765426532e-01, 1.4369503315029458e-01,
|
||||
1.3154002870288328e-01, 1.1936521481099135e-01, 1.0717242495680887e-01, 9.4963495329639061e-02,
|
||||
8.2740264549375803e-02, 7.0504573389614009e-02, 5.8258264500435732e-02, 4.6003182130914644e-02,
|
||||
3.3741171851377642e-02, 2.1474080275469605e-02, 9.2037547820599599e-03, 0.0000000000000000e+00,
|
||||
};
|
||||
|
||||
DECLFUNC const SCALAR *gaa_wsin_ldac[LDAC_NUMLNN];
|
||||
static const SCALAR sa_wsin_1fs_ldac[LDAC_1FSLSU] = {
|
||||
7.0710678118654746e-01, 3.8268343236508978e-01, 9.2387953251128674e-01, 1.9509032201612825e-01,
|
||||
8.3146961230254524e-01, 9.8078528040323043e-01, 5.5557023301960218e-01, 9.8017140329560604e-02,
|
||||
4.7139673682599764e-01, 7.7301045336273699e-01, 9.5694033573220894e-01, 9.9518472667219693e-01,
|
||||
8.8192126434835505e-01, 6.3439328416364549e-01, 2.9028467725446239e-01, 4.9067674327418015e-02,
|
||||
2.4298017990326387e-01, 4.2755509343028208e-01, 5.9569930449243336e-01, 7.4095112535495911e-01,
|
||||
8.5772861000027212e-01, 9.4154406518302081e-01, 9.8917650996478101e-01, 9.9879545620517241e-01,
|
||||
9.7003125319454397e-01, 9.0398929312344345e-01, 8.0320753148064494e-01, 6.7155895484701855e-01,
|
||||
5.1410274419322177e-01, 3.3688985339222033e-01, 1.4673047445536180e-01, 2.4541228522912288e-02,
|
||||
1.2241067519921620e-01, 2.1910124015686980e-01, 3.1368174039889152e-01, 4.0524131400498986e-01,
|
||||
4.9289819222978404e-01, 5.7580819141784534e-01, 6.5317284295377676e-01, 7.2424708295146689e-01,
|
||||
7.8834642762660623e-01, 8.4485356524970701e-01, 8.9322430119551532e-01, 9.3299279883473885e-01,
|
||||
9.6377606579543984e-01, 9.8527764238894122e-01, 9.9729045667869021e-01, 9.9969881869620425e-01,
|
||||
9.9247953459870997e-01, 9.7570213003852857e-01, 9.4952818059303667e-01, 9.1420975570353069e-01,
|
||||
8.7008699110871146e-01, 8.1758481315158371e-01, 7.5720884650648468e-01, 6.8954054473706705e-01,
|
||||
6.1523159058062693e-01, 5.3499761988709715e-01, 4.4961132965460687e-01, 3.5989503653498833e-01,
|
||||
2.6671275747489848e-01, 1.7096188876030122e-01, 7.3564563599667732e-02, 6.1358846491544753e-03,
|
||||
3.0674803176636626e-02, 5.5195244349689934e-02, 7.9682437971430126e-02, 1.0412163387205459e-01,
|
||||
1.2849811079379317e-01, 1.5279718525844344e-01, 1.7700422041214875e-01, 2.0110463484209190e-01,
|
||||
2.2508391135979283e-01, 2.4892760574572015e-01, 2.7262135544994898e-01, 2.9615088824362379e-01,
|
||||
3.1950203081601569e-01, 3.4266071731199438e-01, 3.6561299780477385e-01, 3.8834504669882625e-01,
|
||||
4.1084317105790391e-01, 4.3309381885315196e-01, 4.5508358712634384e-01, 4.7679923006332209e-01,
|
||||
4.9822766697278187e-01, 5.1935599016558964e-01, 5.4017147272989285e-01, 5.6066157619733603e-01,
|
||||
5.8081395809576453e-01, 6.0061647938386897e-01, 6.2005721176328910e-01, 6.3912444486377573e-01,
|
||||
6.5780669329707864e-01, 6.7609270357531592e-01, 6.9397146088965400e-01, 7.1143219574521643e-01,
|
||||
7.2846439044822520e-01, 7.4505778544146595e-01, 7.6120238548426178e-01, 7.7688846567323244e-01,
|
||||
7.9210657730021239e-01, 8.0684755354379922e-01, 8.2110251499110465e-01, 8.3486287498638001e-01,
|
||||
8.4812034480329712e-01, 8.6086693863776731e-01, 8.7309497841829009e-01, 8.8479709843093779e-01,
|
||||
8.9596624975618511e-01, 9.0659570451491533e-01, 9.1667905992104270e-01, 9.2621024213831127e-01,
|
||||
9.3518350993894750e-01, 9.4359345816196039e-01, 9.5143502096900834e-01, 9.5870347489587160e-01,
|
||||
9.6539444169768940e-01, 9.7150389098625178e-01, 9.7702814265775439e-01, 9.8196386910955524e-01,
|
||||
9.8630809724459867e-01, 9.9005821026229712e-01, 9.9321194923479450e-01, 9.9576741446765982e-01,
|
||||
9.9772306664419164e-01, 9.9907772775264536e-01, 9.9983058179582340e-01, 0.0000000000000000e+00,
|
||||
};
|
||||
static const SCALAR sa_wsin_2fs_ldac[LDAC_2FSLSU] = {
|
||||
7.0710678118654746e-01, 3.8268343236508978e-01, 9.2387953251128674e-01, 1.9509032201612825e-01,
|
||||
8.3146961230254524e-01, 9.8078528040323043e-01, 5.5557023301960218e-01, 9.8017140329560604e-02,
|
||||
4.7139673682599764e-01, 7.7301045336273699e-01, 9.5694033573220894e-01, 9.9518472667219693e-01,
|
||||
8.8192126434835505e-01, 6.3439328416364549e-01, 2.9028467725446239e-01, 4.9067674327418015e-02,
|
||||
2.4298017990326387e-01, 4.2755509343028208e-01, 5.9569930449243336e-01, 7.4095112535495911e-01,
|
||||
8.5772861000027212e-01, 9.4154406518302081e-01, 9.8917650996478101e-01, 9.9879545620517241e-01,
|
||||
9.7003125319454397e-01, 9.0398929312344345e-01, 8.0320753148064494e-01, 6.7155895484701855e-01,
|
||||
5.1410274419322177e-01, 3.3688985339222033e-01, 1.4673047445536180e-01, 2.4541228522912288e-02,
|
||||
1.2241067519921620e-01, 2.1910124015686980e-01, 3.1368174039889152e-01, 4.0524131400498986e-01,
|
||||
4.9289819222978404e-01, 5.7580819141784534e-01, 6.5317284295377676e-01, 7.2424708295146689e-01,
|
||||
7.8834642762660623e-01, 8.4485356524970701e-01, 8.9322430119551532e-01, 9.3299279883473885e-01,
|
||||
9.6377606579543984e-01, 9.8527764238894122e-01, 9.9729045667869021e-01, 9.9969881869620425e-01,
|
||||
9.9247953459870997e-01, 9.7570213003852857e-01, 9.4952818059303667e-01, 9.1420975570353069e-01,
|
||||
8.7008699110871146e-01, 8.1758481315158371e-01, 7.5720884650648468e-01, 6.8954054473706705e-01,
|
||||
6.1523159058062693e-01, 5.3499761988709715e-01, 4.4961132965460687e-01, 3.5989503653498833e-01,
|
||||
2.6671275747489848e-01, 1.7096188876030122e-01, 7.3564563599667732e-02, 1.2271538285719925e-02,
|
||||
6.1320736302208578e-02, 1.1022220729388306e-01, 1.5885814333386145e-01, 2.0711137619221856e-01,
|
||||
2.5486565960451457e-01, 3.0200594931922808e-01, 3.4841868024943456e-01, 3.9399204006104810e-01,
|
||||
4.3861623853852766e-01, 4.8218377207912272e-01, 5.2458968267846895e-01, 5.6573181078361312e-01,
|
||||
6.0551104140432555e-01, 6.4383154288979139e-01, 6.8060099779545302e-01, 7.1573082528381859e-01,
|
||||
7.4913639452345926e-01, 7.8073722857209438e-01, 8.1045719825259477e-01, 8.3822470555483797e-01,
|
||||
8.6397285612158670e-01, 8.8763962040285393e-01, 9.0916798309052227e-01, 9.2850608047321548e-01,
|
||||
9.4560732538052128e-01, 9.6043051941556579e-01, 9.7293995220556007e-01, 9.8310548743121629e-01,
|
||||
9.9090263542778001e-01, 9.9631261218277800e-01, 9.9932238458834954e-01, 9.9992470183914450e-01,
|
||||
9.9811811290014918e-01, 9.9390697000235606e-01, 9.8730141815785843e-01, 9.7831737071962765e-01,
|
||||
9.6697647104485207e-01, 9.5330604035419386e-01, 9.3733901191257496e-01, 9.1911385169005777e-01,
|
||||
8.9867446569395393e-01, 8.7607009419540660e-01, 8.5135519310526520e-01, 8.2458930278502518e-01,
|
||||
7.9583690460888357e-01, 7.6516726562245907e-01, 7.3265427167241282e-01, 6.9837624940897292e-01,
|
||||
6.6241577759017201e-01, 6.2485948814238634e-01, 5.8579785745643898e-01, 5.4532498842204635e-01,
|
||||
5.0353838372571769e-01, 4.6053871095824023e-01, 4.1642956009763715e-01, 3.7131719395183771e-01,
|
||||
3.2531029216226326e-01, 2.7851968938505317e-01, 2.3105810828067133e-01, 1.8303988795514090e-01,
|
||||
1.3458070850712628e-01, 8.5797312344440158e-02, 3.6807222941358832e-02, 3.0679567629659761e-03,
|
||||
1.5339206284988100e-02, 2.7608145778965740e-02, 3.9872927587739811e-02, 5.2131704680283324e-02,
|
||||
6.4382630929857465e-02, 7.6623861392031492e-02, 8.8853552582524600e-02, 1.0106986275482782e-01,
|
||||
1.1327095217756435e-01, 1.2545498341154623e-01, 1.3762012158648604e-01, 1.4976453467732151e-01,
|
||||
1.6188639378011183e-01, 1.7398387338746382e-01, 1.8605515166344663e-01, 1.9809841071795356e-01,
|
||||
2.1011183688046961e-01, 2.2209362097320351e-01, 2.3404195858354343e-01, 2.4595505033579459e-01,
|
||||
2.5783110216215899e-01, 2.6966832557291509e-01, 2.8146493792575794e-01, 2.9321916269425863e-01,
|
||||
3.0492922973540237e-01, 3.1659337555616585e-01, 3.2820984357909250e-01, 3.3977688440682685e-01,
|
||||
3.5129275608556709e-01, 3.6275572436739723e-01, 3.7416406297145793e-01, 3.8551605384391885e-01,
|
||||
3.9680998741671031e-01, 4.0804416286497869e-01, 4.1921688836322391e-01, 4.3032648134008261e-01,
|
||||
4.4137126873171667e-01, 4.5234958723377089e-01, 4.6325978355186015e-01, 4.7410021465054997e-01,
|
||||
4.8486924800079106e-01, 4.9556526182577254e-01, 5.0618664534515523e-01, 5.1673179901764987e-01,
|
||||
5.2719913478190128e-01, 5.3758707629564539e-01, 5.4789405917310019e-01, 5.5811853122055610e-01,
|
||||
5.6825895267013149e-01, 5.7831379641165559e-01, 5.8828154822264522e-01, 5.9816070699634227e-01,
|
||||
6.0794978496777363e-01, 6.1764730793780387e-01, 6.2725181549514408e-01, 6.3676186123628420e-01,
|
||||
6.4617601298331628e-01, 6.5549285299961535e-01, 6.6471097820334479e-01, 6.7382900037875604e-01,
|
||||
6.8284554638524808e-01, 6.9175925836415775e-01, 7.0056879394324834e-01, 7.0927282643886558e-01,
|
||||
7.1787004505573171e-01, 7.2635915508434601e-01, 7.3473887809596339e-01, 7.4300795213512172e-01,
|
||||
7.5116513190968637e-01, 7.5920918897838796e-01, 7.6713891193582040e-01, 7.7495310659487382e-01,
|
||||
7.8265059616657573e-01, 7.9023022143731003e-01, 7.9769084094339104e-01, 8.0503133114296366e-01,
|
||||
8.1225058658520388e-01, 8.1934752007679690e-01, 8.2632106284566342e-01, 8.3317016470191319e-01,
|
||||
8.3989379419599941e-01, 8.4649093877405202e-01, 8.5296060493036363e-01, 8.5930181835700836e-01,
|
||||
8.6551362409056898e-01, 8.7159508665595109e-01, 8.7754529020726124e-01, 8.8336333866573158e-01,
|
||||
8.8904835585466457e-01, 8.9459948563138258e-01, 9.0001589201616028e-01, 9.0529675931811882e-01,
|
||||
9.1044129225806714e-01, 9.1544871608826783e-01, 9.2031827670911048e-01, 9.2504924078267758e-01,
|
||||
9.2964089584318133e-01, 9.3409255040425887e-01, 9.3840353406310806e-01, 9.4257319760144687e-01,
|
||||
9.4660091308328353e-01, 9.5048607394948170e-01, 9.5422809510910567e-01, 9.5782641302753291e-01,
|
||||
9.6128048581132064e-01, 9.6458979328981265e-01, 9.6775383709347551e-01, 9.7077214072895035e-01,
|
||||
9.7364424965081187e-01, 9.7636973133002114e-01, 9.7894817531906220e-01, 9.8137919331375456e-01,
|
||||
9.8366241921173025e-01, 9.8579750916756737e-01, 9.8778414164457218e-01, 9.8962201746320078e-01,
|
||||
9.9131085984611544e-01, 9.9285041445986510e-01, 9.9424044945318790e-01, 9.9548075549192694e-01,
|
||||
9.9657114579055484e-01, 9.9751145614030345e-01, 9.9830154493389289e-01, 9.9894129318685687e-01,
|
||||
9.9943060455546173e-01, 9.9976940535121528e-01, 9.9995764455196390e-01, 0.0000000000000000e+00,
|
||||
};
|
||||
|
||||
DECLFUNC const int *gaa_perm_ldac[LDAC_NUMLNN];
|
||||
static const int sa_perm_1fs_ldac[LDAC_1FSLSU] = {
|
||||
0, 64, 96, 32, 48, 112, 80, 16, 24, 88, 120, 56, 40, 104, 72, 8,
|
||||
12, 76, 108, 44, 60, 124, 92, 28, 20, 84, 116, 52, 36, 100, 68, 4,
|
||||
6, 70, 102, 38, 54, 118, 86, 22, 30, 94, 126, 62, 46, 110, 78, 14,
|
||||
10, 74, 106, 42, 58, 122, 90, 26, 18, 82, 114, 50, 34, 98, 66, 2,
|
||||
3, 67, 99, 35, 51, 115, 83, 19, 27, 91, 123, 59, 43, 107, 75, 11,
|
||||
15, 79, 111, 47, 63, 127, 95, 31, 23, 87, 119, 55, 39, 103, 71, 7,
|
||||
5, 69, 101, 37, 53, 117, 85, 21, 29, 93, 125, 61, 45, 109, 77, 13,
|
||||
9, 73, 105, 41, 57, 121, 89, 25, 17, 81, 113, 49, 33, 97, 65, 1,
|
||||
};
|
||||
static const int sa_perm_2fs_ldac[LDAC_2FSLSU] = {
|
||||
0, 128, 192, 64, 96, 224, 160, 32, 48, 176, 240, 112, 80, 208, 144, 16,
|
||||
24, 152, 216, 88, 120, 248, 184, 56, 40, 168, 232, 104, 72, 200, 136, 8,
|
||||
12, 140, 204, 76, 108, 236, 172, 44, 60, 188, 252, 124, 92, 220, 156, 28,
|
||||
20, 148, 212, 84, 116, 244, 180, 52, 36, 164, 228, 100, 68, 196, 132, 4,
|
||||
6, 134, 198, 70, 102, 230, 166, 38, 54, 182, 246, 118, 86, 214, 150, 22,
|
||||
30, 158, 222, 94, 126, 254, 190, 62, 46, 174, 238, 110, 78, 206, 142, 14,
|
||||
10, 138, 202, 74, 106, 234, 170, 42, 58, 186, 250, 122, 90, 218, 154, 26,
|
||||
18, 146, 210, 82, 114, 242, 178, 50, 34, 162, 226, 98, 66, 194, 130, 2,
|
||||
3, 131, 195, 67, 99, 227, 163, 35, 51, 179, 243, 115, 83, 211, 147, 19,
|
||||
27, 155, 219, 91, 123, 251, 187, 59, 43, 171, 235, 107, 75, 203, 139, 11,
|
||||
15, 143, 207, 79, 111, 239, 175, 47, 63, 191, 255, 127, 95, 223, 159, 31,
|
||||
23, 151, 215, 87, 119, 247, 183, 55, 39, 167, 231, 103, 71, 199, 135, 7,
|
||||
5, 133, 197, 69, 101, 229, 165, 37, 53, 181, 245, 117, 85, 213, 149, 21,
|
||||
29, 157, 221, 93, 125, 253, 189, 61, 45, 173, 237, 109, 77, 205, 141, 13,
|
||||
9, 137, 201, 73, 105, 233, 169, 41, 57, 185, 249, 121, 89, 217, 153, 25,
|
||||
17, 145, 209, 81, 113, 241, 177, 49, 33, 161, 225, 97, 65, 193, 129, 1,
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Normalization Tables
|
||||
***************************************************************************************************/
|
||||
|
||||
/* Inverse of Scale Factor for Spectrum Normalization */
|
||||
DECLFUNC const SCALAR ga_isf_ldac[LDAC_NIDSF] = {
|
||||
3.2768000000000000e+04, 1.6384000000000000e+04, 8.1920000000000000e+03, 4.0960000000000000e+03,
|
||||
2.0480000000000000e+03, 1.0240000000000000e+03, 5.1200000000000000e+02, 2.5600000000000000e+02,
|
||||
1.2800000000000000e+02, 6.4000000000000000e+01, 3.2000000000000000e+01, 1.6000000000000000e+01,
|
||||
8.0000000000000000e+00, 4.0000000000000000e+00, 2.0000000000000000e+00, 1.0000000000000000e+00,
|
||||
5.0000000000000000e-01, 2.5000000000000000e-01, 1.2500000000000000e-01, 6.2500000000000000e-02,
|
||||
3.1250000000000000e-02, 1.5625000000000000e-02, 7.8125000000000000e-03, 3.9062500000000000e-03,
|
||||
1.9531250000000000e-03, 9.7656250000000000e-04, 4.8828125000000000e-04, 2.4414062500000000e-04,
|
||||
1.2207031250000000e-04, 6.1035156250000000e-05, 3.0517578125000000e-05, 1.5258789062500000e-05,
|
||||
};
|
||||
|
||||
/***************************************************************************************************
|
||||
Quantization Tables
|
||||
***************************************************************************************************/
|
||||
/* Quantize Factor for Spectrum/Residual Quantization */
|
||||
DECLFUNC const SCALAR ga_qf_ldac[LDAC_NIDWL] = {
|
||||
5.0000000000000000e-01, 1.5000000000000000e+00, 3.5000000000000000e+00, 7.5000000000000000e+00,
|
||||
1.5500000000000000e+01, 3.1500000000000000e+01, 6.3500000000000000e+01, 1.2750000000000000e+02,
|
||||
2.5550000000000000e+02, 5.1150000000000000e+02, 1.0235000000000000e+03, 2.0475000000000000e+03,
|
||||
4.0955000000000000e+03, 8.1915000000000000e+03, 1.6383500000000000e+04, 3.2767500000000000e+04,
|
||||
};
|
||||
|
||||
/* Inverse of Quantize Factor for Spectrum/Residual Quantization */
|
||||
DECLFUNC const SCALAR ga_iqf_ldac[LDAC_NIDWL] = {
|
||||
2.0000000000000000e+00, 6.6666666666666663e-01, 2.8571428571428570e-01, 1.3333333333333333e-01,
|
||||
6.4516129032258063e-02, 3.1746031746031744e-02, 1.5748031496062992e-02, 7.8431372549019607e-03,
|
||||
3.9138943248532287e-03, 1.9550342130987292e-03, 9.7703957010258913e-04, 4.8840048840048840e-04,
|
||||
2.4417043096081065e-04, 1.2207776353537203e-04, 6.1037018951994385e-05, 3.0518043793392844e-05,
|
||||
};
|
||||
|
||||
/* Inverse of Scale Factor for Residual Normalization */
|
||||
DECLFUNC const SCALAR ga_irsf_ldac[LDAC_NIDWL] = {
|
||||
1.0000000000000000e+00, 3.0000000000000000e+00, 7.0000000000000000e+00, 1.5000000000000000e+01,
|
||||
3.1000000000000000e+01, 6.3000000000000000e+01, 1.2700000000000000e+02, 2.5500000000000000e+02,
|
||||
5.1100000000000000e+02, 1.0230000000000000e+03, 2.0470000000000000e+03, 4.0950000000000000e+03,
|
||||
8.1910000000000000e+03, 1.6383000000000000e+04, 3.2767000000000000e+04, 6.5535000000000000e+04,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
Set MDCT Tables
|
||||
***************************************************************************************************/
|
||||
DECLFUNC void set_mdct_table_ldac(
|
||||
int nlnn)
|
||||
{
|
||||
int index = nlnn - LDAC_1FSLNN;
|
||||
|
||||
if (nlnn == LDAC_1FSLNN) {
|
||||
gaa_fwin_ldac[index] = sa_fwin_1fs_ldac;
|
||||
gaa_wcos_ldac[index] = sa_wcos_1fs_ldac;
|
||||
gaa_wsin_ldac[index] = sa_wsin_1fs_ldac;
|
||||
gaa_perm_ldac[index] = sa_perm_1fs_ldac;
|
||||
}
|
||||
else if (nlnn == LDAC_2FSLNN) {
|
||||
gaa_fwin_ldac[index] = sa_fwin_2fs_ldac;
|
||||
gaa_wcos_ldac[index] = sa_wcos_2fs_ldac;
|
||||
gaa_wsin_ldac[index] = sa_wsin_2fs_ldac;
|
||||
gaa_perm_ldac[index] = sa_perm_2fs_ldac;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue