commit ad5143f78d1dbf1b0bae2c59ae87d51219da2347 Author: Adam Burns Date: Sun Jul 4 10:00:20 2021 +0200 initial commit from tarball diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..6f962ca --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +Reference implementation: 3GPP TS 26.410 V8.0.0 +Wrapper and library code: Stanislav Brabec , +Adopted for aac+: Sergiy Guriev , +Encoder code: Matteo Croce +Patches and fixes: Rafael Diniz, Edwin van den Oetelaar diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..e9766e3 --- /dev/null +++ b/COPYING @@ -0,0 +1,5 @@ +The 3GPP TS 26.410 V8.0.0 reference code has a commercial license. + +To use package compiled by this code, you may need a license from 3GPP. + +The wrapper code is released under GNU Library General Public License. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..1226d5d --- /dev/null +++ b/ChangeLog @@ -0,0 +1,31 @@ +2010-11-10 Sergiy Guriev + * Added AOT_SBR as extra object type to codec config (now ffplay works fine). + +2010-11-04 Sergiy Guriev + * Fixed aac config creation. + * Add floating point samples as supported input format. + * Decreased export symbols + +2010-10-12 Sergiy Guriev + * New API, incompatible with older libs. + * Removed static data, supported multiple instances in one application. + +2010-10-04 Sergiy Guriev + * fix 64 bit support for SBR+PS encoding. + +2009-08-10 Sergiy Guriev + * update to 8.0.0 core + +2009-03-22 Sergiy Guriev + * added pkg-config file + +2008-11-06 Rafael Diniz + * small namespaces changes (not colide w/ faad ones) + +2008-11-06 Sergiy Guriev + * Autogen added. + * _FFTW3 define is not needed any more. + * adts code moved to c-file (based on faac) + +2008-11-04 Sergiy Guriev + * New package. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..1ca6fd8 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,13 @@ + +SUBDIRS = src include patches frontend + +if HAVE_PKGCONFIG + pkgconfigdir = $(libdir)/pkgconfig + pkgconfig_DATA = aacplus.pc +else + bin_SCRIPTS = aacplus-config +endif + +EXTRA_DIST = autogen.sh aacplus.pc aacplus.spec + +ACLOCAL_AMFLAGS = -I m4 diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..7db63c4 --- /dev/null +++ b/NEWS @@ -0,0 +1,36 @@ +News in version 1.0.0 +===================== +* Repackaged sources from 3GPP. +* Build as shared library. + +News in version 1.0.2 +===================== +* Compatible with FAAC + +News in version 1.0.3 +===================== +* Compatible with ffmpeg +* package-config files added + +News in version 1.0.4 +===================== +* implemented buffer_fullness bits in ADTS header + +News in version 1.0.5 +===================== +* update to 8.0.0 core + +News in version 1.1.0 +===================== +* 64bit systems now supports SBR+PS + +News in version 2.0.0 +===================== +* New API, incompatible with older libs. +* Removed static data, supported multiple instances in one application. + +News in version 2.0.1 +===================== +* Fixed aac config creation. +* Add floating point samples as supported input format. +* Decreased export symbols diff --git a/README b/README new file mode 100644 index 0000000..8c744fd --- /dev/null +++ b/README @@ -0,0 +1,58 @@ +3GPP AAC+ High Efficiency Advanced Audio Codec v2 (HE-AAC+) Encoder Shared Library + +3GPP released reference implementation of 3GPP AAC Advanced Audio - +(HE-AAC+) Encoder (3GPP TS 26.410 V8.0.0). + +http://www.3gpp.org/ftp/Specs/html-info/26410.htm + +Reference implementation is available as a source code, but the code uses +#define to choose code options. In world of GNU-Linux, there is a common +practice to compile such code as a shared library. + +Due to restrictive license, the reference implementation is not part of +this package and it is dowloaded from 3GPP during build. If you want to +build this package without network access, you either have to put the +original source code ZIP file to the unpacked wrapper code directory or +you have to use full source core (see below). + +This package converts 3GPP TS 26.410 V8.0.0 reference implementation of HE-AAC+ +encoder to a shared library. It has exactly the same API, but some calls +are wrapped by macros to call proper variant of the function. + +For more see readme.txt and 26410-800.doc, which comes with the original code. + +This wrapper fixes some bugs of original code. +I will accept patches for it, if 3GPP will not release fixed implementation. + +To use package compiled by this code, you may need a license from 3GPP. + +It is possible to distribute these packages in three source forms: +1. As a wrapper-only source (as you can build by "make extradist"). +2. As a full source code including 3GPP code (as you can build by "make dist"). +3. As a wrapper-only source accompanied by the original zip file. + +Package home page: http://217.20.164.161/~tipok/aacplus + +For problems with the shared library wrapper or building code please contact +Sergiy Guriev + +For problems with the implementation, contact 3GPP. + +Technical notes: + +The code has only one branch with stereo implementation. + +In addition to "make dist", you can also call "make extradist", which +builds distribution package containing LGPL wrapper only. + +Known bugs: +- Not known yet + +Dependencies: +- fftw3 (can be skipped) + +To compile library do: +# ./autogen.sh +# ./configure +# make +# make install diff --git a/TODO b/TODO new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/TODO @@ -0,0 +1 @@ + diff --git a/aacplus-config.in b/aacplus-config.in new file mode 100644 index 0000000..f13dbea --- /dev/null +++ b/aacplus-config.in @@ -0,0 +1,255 @@ +! /bin/sh +# aacplus-config library configuration script +# generated by ac_config_libconfig_in.m4 + +template_version="1.0.0" + +package="@PACKAGE@" + +# usage instructions if no options given +if test "$#" -eq 0; then + cat < /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $package." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +(autoreconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoreconf installed to compile $package." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +(automake --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have automake installed to compile $package." + echo "Download the appropriate package for your system," + echo "or get the source from one of the GNU ftp sites" + echo "listed in http://www.gnu.org/order/ftp.html" + DIE=1 +} + +(libtool --help) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have libtool installed to compile $package." + echo "Download the appropriate package for your system," + echo "or get the source from one of the GNU ftp sites" + echo "listed in http://www.gnu.org/order/ftp.html" + DIE=1 +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." +fi + +echo "Generating configuration files for $package, please wait...." + +echo " aclocal $ACLOCAL_FLAGS" +aclocal $ACLOCAL_FLAGS +echo " autoheader" +autoheader +echo " libtoolize --automake" +libtoolize --automake +echo " automake --add-missing $AUTOMAKE_FLAGS" +automake --add-missing $AUTOMAKE_FLAGS +echo " autoreconf" +autoreconf + +$srcdir/configure "$@" && echo diff --git a/config.bitrate b/config.bitrate new file mode 100644 index 0000000..af210e1 --- /dev/null +++ b/config.bitrate @@ -0,0 +1,90 @@ +src/aacplusenc.c: AacInitDefaultConfig(&aacp->config); +src/aacplusenc.c: aacp->config.nChannelsIn = numChannels; +src/aacplusenc.c: aacp->config.sampleRate = sampleRate; +src/aacplusenc.c: aacp->writeOffset = INPUT_DELAY*MAX_CHANNELS; +src/aacplusenc.c: aacplusEncInitSBRAACRam(&aacp->aacEnc); +src/aacplusenc.c: init_plans(&aacp->fftctx); +src/aacplusenc.c: return &aacp->config; +src/aacplusenc.c: if(cfg != &aacp->config) +src/aacplusenc.c: memcpy(&aacp->config, cfg, sizeof(aacplusEncConfiguration)); +src/aacplusenc.c: int sampleRateAAC = aacp->config.sampleRate; +src/aacplusenc.c: if(!aacp->config.nChannelsOut) +src/aacplusenc.c: aacp->config.nChannelsOut = aacp->config.nChannelsIn; +src/aacplusenc.c: if(!aacp->config.bitRate) +src/aacplusenc.c: if(aacp->config.bandWidth > aacp->config.sampleRate/2) +src/aacplusenc.c: aacp->config.inputSamples = aacp->config.nSamplesPerFrame * 2 * aacp->config.nChannelsIn; +src/aacplusenc.c: if ( (aacp->config.nChannelsOut == 2) && (aacp->config.bitRate >= 16000) && (aacp->config.bitRate < 44001) ) { +src/aacplusenc.c: aacp->config.nChannelsOut=1; +src/aacplusenc.c: aacp->useParametricStereo=1; +src/aacplusenc.c: aacp->envReadOffset = (MAX_DS_FILTER_DELAY + INPUT_DELAY)*MAX_CHANNELS; +src/aacplusenc.c: aacp->coreWriteOffset = CORE_INPUT_OFFSET_PS; +src/aacplusenc.c: aacp->writeOffset = aacp->envReadOffset; +src/aacplusenc.c: InitIIR21_Resampler(&aacp->IIR21_reSampler[0]); +src/aacplusenc.c: InitIIR21_Resampler(&aacp->IIR21_reSampler[1]); +src/aacplusenc.c: assert(aacp->IIR21_reSampler[0].delay <= MAX_DS_FILTER_DELAY); +src/aacplusenc.c: aacp->writeOffset += aacp->IIR21_reSampler[0].delay*MAX_CHANNELS; +src/aacplusenc.c: if(!IsSbrSettingAvail(aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC, &sampleRateAAC)) { +src/aacplusenc.c: aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC); +src/aacplusenc.c: InitializeSbrDefaults (&aacp->sbrConfig); +src/aacplusenc.c: aacp->sbrConfig.usePs = aacp->useParametricStereo; +src/aacplusenc.c: if(!AdjustSbrSettings( &aacp->sbrConfig, aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC, AACENC_TRANS_FAC, 24000)) { +src/aacplusenc.c: aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC, aacp->sbrConfig.usePs); +src/aacplusenc.c: if(EnvOpen(aacp->aacEnc.sbr_ram, +src/aacplusenc.c: &aacp->hEnvEnc, +src/aacplusenc.c: &aacp->inBuf[aacp->coreWriteOffset], +src/aacplusenc.c: &aacp->sbrConfig, +src/aacplusenc.c: &aacp->config.bandWidth) != 0){ +src/aacplusenc.c: EnvClose (&aacp->hEnvEnc); +src/aacplusenc.c: aacp->hEnvEnc.fftctx = &aacp->fftctx; +src/aacplusenc.c: aacp->config.sampleRate = sampleRateAAC; +src/aacplusenc.c: if (AacEncOpen( &aacp->aacEnc, &aacp->config) != 0){ +src/aacplusenc.c: AacEncClose(&aacp->aacEnc); +src/aacplusenc.c: aacp->aacEnc.fftctx = &aacp->fftctx; +src/aacplusenc.c: aacp->adts = calloc(1, sizeof(ADTSContext_t)); +src/aacplusenc.c: if(!aacp->adts) { +src/aacplusenc.c: adts_hdr_init(aacp->adts, &aacp->config, &aacp->aacEnc.bitStream); +src/aacplusenc.c: if(aacp->useParametricStereo) +src/aacplusenc.c: srate_idx = FindSRIndex(aacp->config.sampleRate); +src/aacplusenc.c: ch_idx = FindCHIndex(aacp->config.nChannelsOut); +src/aacplusenc.c: if(aacp->config.nSamplesPerFrame != AACENC_BLOCKSIZE) +src/aacplusenc.c: srate_idx = FindSRIndex(aacp->config.sampleRate * 2); +src/aacplusenc.c: if(samplesInput > aacp->config.inputSamples) +src/aacplusenc.c: switch (aacp->config.inputFormat){ +src/aacplusenc.c: aacp->inBuf[(2/aacp->config.nChannelsIn)*i+aacp->writeOffset+aacp->writtenSamples] = (float) inbuff[i]; +src/aacplusenc.c: aacp->inBuf[(2/aacp->config.nChannelsIn)*i+aacp->writeOffset+aacp->writtenSamples] = inbuff[i] * SHRT_MAX; +src/aacplusenc.c: if((aacp->config.nChannelsIn == 2) && +src/aacplusenc.c: (aacp->config.nChannelsOut == 1) && !aacp->useParametricStereo) { +src/aacplusenc.c: aacp->inBuf[i+aacp->writeOffset+aacp->writtenSamples] = (aacp->inBuf[i+aacp->writeOffset+aacp->writtenSamples] +src/aacplusenc.c: + aacp->inBuf[i+aacp->writeOffset+aacp->writtenSamples+1])*0.5f; +src/aacplusenc.c: aacp->writtenSamples+=samplesInput; +src/aacplusenc.c: if (aacp->writtenSamples < aacp->config.inputSamples) +src/aacplusenc.c: if(aacp->adts) adts_offset=ADTS_HEADER_SIZE; +src/aacplusenc.c: EnvEncodeFrame( &aacp->hEnvEnc, +src/aacplusenc.c: &aacp->inBuf[aacp->envReadOffset], +src/aacplusenc.c: &aacp->inBuf[aacp->coreWriteOffset], +src/aacplusenc.c: &aacp->numAncDataBytes, +src/aacplusenc.c: aacp->ancDataBytes); +src/aacplusenc.c: if (!aacp->useParametricStereo) +src/aacplusenc.c: for( ch=0; chconfig.nChannelsIn; ch++ ) +src/aacplusenc.c: IIR21_Downsample( &aacp->IIR21_reSampler[ch], +src/aacplusenc.c: &aacp->inBuf[aacp->writeOffset+ch], +src/aacplusenc.c: aacp->config.nSamplesPerFrame * 2, //aacp->writtenSamples, +src/aacplusenc.c: &aacp->inBuf[ch], +src/aacplusenc.c: AacEncEncode( &aacp->aacEnc, +src/aacplusenc.c: aacp->inBuf, +src/aacplusenc.c: aacp->useParametricStereo ? 1 : MAX_CHANNELS, /* stride (step) */ +src/aacplusenc.c: aacp->ancDataBytes, +src/aacplusenc.c: &aacp->numAncDataBytes, +src/aacplusenc.c: if (aacp->useParametricStereo) { +src/aacplusenc.c: memcpy( aacp->inBuf,&aacp->inBuf[aacp->config.nSamplesPerFrame],CORE_INPUT_OFFSET_PS*sizeof(float)); +src/aacplusenc.c: memmove( aacp->inBuf,&aacp->inBuf[aacp->config.nSamplesPerFrame*2*MAX_CHANNELS], +src/aacplusenc.c: aacp->writeOffset*sizeof(float)); +src/aacplusenc.c: if(numOutBytes > 0 && aacp->adts) { +src/aacplusenc.c: adts_hdr_up(aacp->adts, outputBuffer, numOutBytes); +src/aacplusenc.c: aacp->writtenSamples=0; +src/aacplusenc.c: AacEncClose(&aacp->aacEnc); +src/aacplusenc.c: EnvClose(&aacp->hEnvEnc); +src/aacplusenc.c: destroy_plans(&aacp->fftctx); +src/aacplusenc.c: aacplusEncFreeSBRAACRam(&aacp->aacEnc); +src/aacplusenc.c: if(aacp->adts) +src/aacplusenc.c: free(aacp->adts); diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..4c112ae --- /dev/null +++ b/configure.ac @@ -0,0 +1,144 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_INIT([libaacplus],[2.0.2],[Sergiy Guriev ]) +#AM_INIT_AUTOMAKE([dist-bzip2]) +AM_INIT_AUTOMAKE + +AM_CONFIG_HEADER(config.h) +AC_CONFIG_MACRO_DIR([m4]) +# Checks for programs. +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AC_LIBTOOL_WIN32_DLL +AM_PROG_LIBTOOL +AC_PATH_PROG([UNZIP],[unzip]) +if test x"$UNZIP" = x -a ! -f "aacenc.c" ; then + AC_MSG_ERROR([You need unzip utility to prepare sources.]) +fi +AC_PATH_PROG([PATCH],[patch]) +if test x"$PATCH" = x -a ! -f "aacenc.c" ; then + AC_MSG_ERROR([You need patch utility to prepare sources.]) +fi +AC_PARAMETER_EXPANSION_STRING_REPLACE_CAPABLE_SHELL +if test x"$PARAMETER_EXPANSION_STRING_REPLACE_CAPABLE_SHELL" = x -a ! "(" -f"26410-800.zip" -o -f "aacenc.c" ")" ; then +dnl number sigh cannot be a part of AC_MSG_ERROR + NUMBER_SIGN="#" + AC_MSG_ERROR([You need parameter expansion string replace (i. e. \${var%string} and \${var${NUMBER_SIGN}string}) capable shell (bash, ash, better sh).]) +fi +AC_CHECK_DOWNLOADER_PROG +if test x"$DOWNLOADER_PROG" = x -a ! "(" -f "26410-800.zip" -o -f "aacenc.c" ")" ; then + AC_MSG_ERROR([You need downloader utility to download sources (wget, fetch or curl).]) +fi + +# Checks for libraries. +AC_SEARCH_LIBS([sqrt],[m]) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([float.h memory.h stdint.h stdlib.h string.h],[],[ + AC_MSG_ERROR([You need standard header files.]) +]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT8_T +AC_TYPE_UINT16_T + +# Checks for library functions. +AC_FUNC_MALLOC +AC_FUNC_MEMCMP +AC_CHECK_FUNCS([floor memmove memset pow sqrt],[],[ + AC_MSG_ERROR([You basic math functions.]) +]) + +dnl----------------------------------------------------------------------------- +dnl link the fftw3 library if requested +dnl----------------------------------------------------------------------------- +AC_SUBST(FFTW3_INCFLAGS) +AC_SUBST(FFTW3_CFLAGS) +AC_SUBST(FFTW3_LIB) +AC_SUBST(FFTW3_LDFLAGS) + +AC_ARG_WITH(fftw3, +[ --with-fftw3 use fftw3 for fast fourier conversion ([default=yes]) ], + USE_FFTW3=${withval}, USE_FFTW3="yes" ) +AC_ARG_WITH(fftw3-prefix, +[ --with-fftw3-prefix=DIR alternate location for fftw3 ([default=/usr]) + look for libraries in FFTW3-PREFIX/lib, + for headers in FFTW3-PREFIX/include], + CONFIG_FFTW3_PREFIX="${withval}", CONFIG_FFTW3_PREFIX="/usr") + +if test "x${USE_FFTW3}" = "xyes" ; then + AC_MSG_CHECKING( [for fftw3 library at ${CONFIG_FFTW3_PREFIX}] ) + LA_SEARCH_LIB( FFTW3_LIB_LOC, FFTW3_INC_LOC, libfftw3f.a libfftw3f.so, fftw3.h, + ${CONFIG_FFTW3_PREFIX}) + if test "x${FFTW3_LIB_LOC}" == "x" ; then + AC_MSG_WARN( [not found]) + CONFIG_FFTW3_PREFIX="/usr/local" + AC_MSG_CHECKING( [for fftw3 library at ${CONFIG_FFTW3_PREFIX}] ) + LA_SEARCH_LIB( FFTW3_LIB_LOC, FFTW3_INC_LOC, libfftw3f.a libfftw3f.so, fftw3.h, + ${CONFIG_FFTW3_PREFIX}) + fi + + if test "x${FFTW3_LIB_LOC}" != "x" ; then + AC_DEFINE( _FFTW3, 1, [build with fftw3 library] ) + if test "x${FFTW3_INC_LOC}" != "x${SYSTEM_INCLUDE}" ; then + FFTW3_INCFLAGS="-I${FFTW3_INC_LOC}" + fi + FFTW3_LIB="-lfftw3f" + FFTW3_LDFLAGS="-L${FFTW3_LIB_LOC} ${FFTW3_LIB}" + FFTW3_CFLAGS="-I${FFTW3_LIB_LOC} ${FFTW3_LIB}" + AC_MSG_RESULT( [found at ${CONFIG_FFTW3_PREFIX}] ) + else + AC_MSG_WARN( [not found, building without fftw3]) + fi +else + AC_MSG_RESULT( [building without fftw3] ) +fi + + +dnl pkgconfig/shout-config. +dnl If pkgconfig is found, use it and disable shout-config, otherwise do the +dnl opposite, unless the user overrides. + +AC_ARG_ENABLE([pkgconfig], + AC_HELP_STRING([--disable-pkgconfig],[disable pkgconfig data files (auto)]), + [dopkgconfig="$enableval"], [dopkgconfig="maybe"]) +if test "$dopkgconfig" = "maybe" +then + AC_CHECK_PROG([PKGCONFIG], [pkg-config], [yes], [no]) +else + AC_MSG_CHECKING([whether pkgconfig should be used]) + PKGCONFIG="$dopkgconfig" + AC_MSG_RESULT([$PKGCONFIG]) +fi +AM_CONDITIONAL([HAVE_PKGCONFIG], [test "$PKGCONFIG" != "no"]) + +AACPLUS_VERSION="$VERSION" +AACPLUS_CPPFLAGS="-I$aacplus_includedir $FFTW3_CPPFLAGS" +AACPLUS_CFLAGS+="$FFTW3_CFLAGS" +AACPLUS_LIBS="-laacplus -lm ${FFTW3_LIB}" + +AC_SUBST(AACPLUS_LIBS) +AC_SUBST(AACPLUS_REQUIRES) +AC_SUBST(AACPLUS_CPPFLAGS) +AC_SUBST(AACPLUS_CFLAGS) + +dnl Make substitutions + +AC_SUBST(LIBTOOL_DEPS) +AC_SUBST(OPT) +AC_SUBST(LIBS) +AC_SUBST(DEBUG) +AC_SUBST(CFLAGS) +AC_SUBST(PROFILE) + +AC_CONFIG_FILES([ aacplus.spec aacplus-config aacplus.pc ]) +AC_OUTPUT([ Makefile src/Makefile patches/Makefile include/Makefile frontend/Makefile ]) diff --git a/docs/aacplusenc.1 b/docs/aacplusenc.1 new file mode 100644 index 0000000..092365b --- /dev/null +++ b/docs/aacplusenc.1 @@ -0,0 +1,46 @@ +.TH AACPLUSENC 1 "2007-10-11" "1.26" "non-Free High Efficiency Advanced Audio Coder" + +.SH NAME +aacplusenc \- proprietary MPEG-4 and MPEG-2 AAC+ encoder + +.SH SYNOPSIS +.B aacplusenc +.I < infile > +.RI \-o\ <\fIoutfile\fP> +.RI [-s] + +.SH DESCRIPTION +.B aacplusenc +is an 3gpp's implementation of MPEG-4 and MPEG-2 AAC+ encoder, it is need to be licensed by owners (Dolby/VIA). + +.SH FEATURES +.TP +* Portable +.TP +* Fast +.TP +* LC support + +.SH OPTIONS +.TP +.BR <\fIinfile\fP> +Set Input wave file, can be "\-", which means stdin. +.TP +.BR \-o\ <\fIoutfile\fP> +Set Output aac file, can be "\-", which means stdout. +.TP +.BR \-s\ +Set stereo encoding mode +.TP + +.SH AUTHORS +.TP +Reference implementation: 3GPP TS 26.410 V8.0.0 +.TP +Wrapper and library code: Stanislav Brabec , +.TP +Adopted for aac+: Sergiy Guriev , +.TP +Encoder code: Matteo Croce +.TP +Patches and fixes: Rafael Diniz, Edwin van den Oetelaar diff --git a/frontend/Makefile.am b/frontend/Makefile.am new file mode 100644 index 0000000..b1babaf --- /dev/null +++ b/frontend/Makefile.am @@ -0,0 +1,9 @@ +bin_PROGRAMS = aacplusenc +man_MANS = ../docs/aacplusenc.1 + +aacplusenc_SOURCES = main.c + +INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/src +LDADD = $(top_builddir)/src/libaacplus.la -lm + +aacplusenc_LDFLAGS = @FFTW3_LDFLAGS@ diff --git a/frontend/au_channel.h b/frontend/au_channel.h new file mode 100644 index 0000000..d471729 --- /dev/null +++ b/frontend/au_channel.h @@ -0,0 +1,66 @@ +#include +#include + +#define WAV_HEADER_SIZE 64 + +#define WAV_FORMAT_FLOAT 0xFFFE + +typedef struct { + int sampleRate; + int nChannels; + long nSamples; + int aFmt; +} WavInfo; + +inline FILE* AuChannelOpen (const char* filename, WavInfo* info) +{ + unsigned char header[12]; + unsigned char data[WAV_HEADER_SIZE]; + FILE *handle; + unsigned int chunksize; + + + if (!strcmp(filename,"-")) + handle = stdin; + else + handle = fopen(filename, "rb"); + + if(!handle) return NULL; + + if(fread(header, 1, 12, handle) != 12) return NULL; + info->nSamples = (header[4] | (header[5] << 8) | (header[6] << 16) | (header[7] << 24)) + 8; + + while (memcmp(header, "data", 4) != 0){ + if(fread(header, 1, 8, handle) != 8) return NULL; + chunksize = (header[4] | (header[5] << 8) | (header[6] << 16) | (header[7] << 24)); + //fprintf(stderr, "%c%c%c%c %d", header[0], header[1], header[2], header[3], chunksize); + if(!memcmp(header, "fmt ", 4)) { + if(chunksize > WAV_HEADER_SIZE) return NULL; + if(fread(data, 1, chunksize, handle) != chunksize) return NULL; + info->aFmt = data[0] | data[1] << 8; + info->nChannels = data[2] | data[3] << 8; + info->sampleRate = data[4] | data[5] << 8 | data[6] << 12 | data[7] << 16; + } else if(memcmp(header, "data", 4) != 0) { + if(fseek(handle, chunksize, SEEK_CUR) != 0) return NULL; + } + } + + return handle; +} + +inline void AuChannelClose (FILE *audioChannel) +{ + fclose(audioChannel); +} + +inline size_t AuChannelReadShort(FILE *audioChannel, short *samples, int nSamples, int *readed) +{ + *readed = fread(samples, 2, nSamples, audioChannel); + return *readed <= 0; +} + +inline size_t AuChannelReadFloat(FILE *audioChannel, float *samples, int nSamples, int *readed) +{ + *readed = fread(samples, 4, nSamples, audioChannel); + return *readed <= 0; +} diff --git a/frontend/main.c b/frontend/main.c new file mode 100644 index 0000000..81f82ac --- /dev/null +++ b/frontend/main.c @@ -0,0 +1,141 @@ +#include +#include +#include +#include + +#include "au_channel.h" +#include "aacplus.h" + +int main(int argc, char *argv[]) +{ + + WavInfo inputInfo; + FILE *inputFile = NULL; + FILE *hADTSFile; + + int error; + int bEncodeMono = 0; + int frmCnt = 0; + + /* + * parse command line arguments + */ + if (argc != 5) { + fprintf(stderr, "\nUsage: %s <(m)ono/(s)tereo>\n", argv[0]); + fprintf(stderr, "\nExample: %s input.wav out.aac 24000 s\n", argv[0]); + return 0; + } + + if ( strcmp (argv[4],"m") == 0 ) { + bEncodeMono = 1; + } + else { + if ( strcmp (argv[4],"s") != 0 ) { + fprintf(stderr, "\nWrong mode %s, use either (m)ono or (s)tereo\n", argv[4]); + return 0; + } + } + fflush(stdout); + + inputFile = AuChannelOpen (argv[1], &inputInfo); + + if(inputFile == NULL){ + fprintf(stderr,"could not open %s\n",argv[1]); + exit(10); + } + + if (inputInfo.nChannels==1 && !bEncodeMono) { + fprintf(stderr,"Need stereo input for stereo coding mode !\n"); + exit(10); + } + + if (strcmp(argv[2],"-")==0) + hADTSFile=stdout; + else + hADTSFile = fopen(argv[2], "wb"); + + if(!hADTSFile) { + fprintf(stderr, "\nFailed to create ADTS file\n") ; + exit(10); + } + + /* + Be verbose + */ + unsigned long inputSamples=0; + unsigned long maxOutputBytes=0; + aacplusEncHandle hEncoder = aacplusEncOpen(inputInfo.sampleRate, + inputInfo.nChannels, + &inputSamples, + &maxOutputBytes); + + aacplusEncConfiguration *cfg = aacplusEncGetCurrentConfiguration(hEncoder); + cfg->bitRate = atoi(argv[3]); + cfg->bandWidth = 0; + cfg->outputFormat = 1; + cfg->nChannelsOut = bEncodeMono ? 1 : inputInfo.nChannels; + if(inputInfo.aFmt == WAV_FORMAT_FLOAT){ + cfg->inputFormat = AACPLUS_INPUT_FLOAT; + } + + fprintf(stdout,"input file %s: \nsr = %d, nc = %d fmt = %d\n\n", + argv[1], inputInfo.sampleRate, inputInfo.nChannels, inputInfo.aFmt); + fprintf(stdout,"output file %s: \nbr = %d inputSamples = %lu maxOutputBytes = %lu nc = %d m = %d\n\n", + argv[2], cfg->bitRate, inputSamples, maxOutputBytes, cfg->nChannelsOut, bEncodeMono); + fflush(stdout); + + int ret = 0; + if((ret = aacplusEncSetConfiguration(hEncoder, cfg)) == 0) { + fprintf(stdout,"setting cfg failed\n", ret); + return -1; + } + + uint8_t *outputBuffer = malloc(maxOutputBytes); + int32_t *TimeDataPcm; + if(inputInfo.aFmt == WAV_FORMAT_FLOAT) { + TimeDataPcm = calloc(inputSamples, sizeof(float)); + } else { + TimeDataPcm = calloc(inputSamples, sizeof(short)); + } + + int stopLoop = 0; + int bytes = 0; + do { + int numSamplesRead = 0; + if(inputInfo.aFmt == WAV_FORMAT_FLOAT) { + if ( AuChannelReadFloat(inputFile, (float *) TimeDataPcm, inputSamples, &numSamplesRead) > 0) { + stopLoop = 1; + break; + } + } else { + if ( AuChannelReadShort(inputFile, (short *) TimeDataPcm, inputSamples, &numSamplesRead) > 0) { + stopLoop = 1; + break; + } + } + + if(numSamplesRead < inputSamples) { + stopLoop = 1; + break; + } + + bytes = aacplusEncEncode(hEncoder, (int32_t *) TimeDataPcm, numSamplesRead, + outputBuffer, + maxOutputBytes); + + if(bytes > 0) fwrite(outputBuffer, bytes, 1, hADTSFile); + + frmCnt++; + fprintf(stderr,"[%d]\r",frmCnt); fflush(stderr); + } while (!stopLoop && bytes >= 0); + + fprintf(stderr,"\n"); + fflush(stderr); + + printf("\nencoding finished\n"); + aacplusEncClose(hEncoder); + fclose(hADTSFile); + free(outputBuffer); + free(TimeDataPcm); + return 0; +} diff --git a/include/Makefile.am b/include/Makefile.am new file mode 100644 index 0000000..424048b --- /dev/null +++ b/include/Makefile.am @@ -0,0 +1 @@ +include_HEADERS = aacplus.h diff --git a/include/aacplus.h b/include/aacplus.h new file mode 100644 index 0000000..ce93c79 --- /dev/null +++ b/include/aacplus.h @@ -0,0 +1,60 @@ + +#ifndef _AACPLUS_H_ +#define _AACPLUS_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef void *aacplusEncHandle; + +typedef enum { + AACPLUS_INPUT_16BIT = 0, + AACPLUS_INPUT_FLOAT, +} aacplusInFormat; + + +typedef struct { + int sampleRate; + int bitRate; ///< bits per second + int nChannelsIn; + int nChannelsOut; + int bandWidth; + aacplusInFormat inputFormat; + int outputFormat; ///< 0 - raw, 1 - adts + int nSamplesPerFrame; ///< 1024 by default, (960 - for dab+/drm not working yet) + int inputSamples; ///< number of input samples to use, usable after aacplusEncSetConfiguration() call +} aacplusEncConfiguration; + +aacplusEncConfiguration *aacplusEncGetCurrentConfiguration(aacplusEncHandle hEncoder); + + +int aacplusEncSetConfiguration(aacplusEncHandle hEncoder, + aacplusEncConfiguration *cfg); + + +aacplusEncHandle aacplusEncOpen(unsigned long sampleRate, + unsigned int numChannels, + unsigned long *inputSamples, + unsigned long *maxOutputBytes); + + +int aacplusEncGetDecoderSpecificInfo(aacplusEncHandle hEncoder, unsigned char **ppBuffer, + unsigned long *pSizeOfDecoderSpecificInfo); + + +int aacplusEncEncode(aacplusEncHandle hEncoder, int32_t *inputBuffer, unsigned int samplesInput, + unsigned char *outputBuffer, + unsigned int bufferSize); + + +int aacplusEncClose(aacplusEncHandle hEncoder); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _AACPLUS_H_ */ diff --git a/m4/acinclude.m4 b/m4/acinclude.m4 new file mode 100644 index 0000000..db1333d --- /dev/null +++ b/m4/acinclude.m4 @@ -0,0 +1,299 @@ +dnl acinclude.m4. Change *this* file to add new or change macros. +dnl When changes have been made, delete aclocal.m4 and run +dnl "aclocal". +dnl +dnl DO NOT change aclocal.m4 ! +dnl + +dnl----------------------------------------------------------------------------- +dnl LA_SEARCH_FILE(variable, filename, PATH) +dnl Search "filename" in the specified "PATH", "variable" will +dnl contain the full pathname or the empty string +dnl PATH is space-separated list of directories. +dnl by Florian Bomers +dnl----------------------------------------------------------------------------- +AC_DEFUN([LA_SEARCH_FILE],[ + $1= + dnl hack: eliminate line feeds in $2 + for FILE in $2; do + for DIR in $3; do + dnl use PATH in order + if test ".$1"="." && test -f "$DIR/$FILE"; then + $1=$DIR + fi + done + done +]) + +dnl----------------------------------------------------------------------------- +dnl LA_SEARCH_LIB(lib-variable, include-variable, lib-filename, header-filename, prefix) +dnl looks for "lib-filename" and "header-filename" in the area of "prefix". +dnl if found, "lib-variable" and "include-variable" are set to the +dnl respective paths. +dnl prefix is a single path +dnl libs are searched in prefix, prefix/lib +dnl headers are searched in prefix, prefix/include, +dnl +dnl If one of them is not found, both "lib-variable", "include-variable" are +dnl set to the empty string. +dnl +dnl TODO: assert function call to verify lib +dnl +dnl by Florian Bomers +dnl----------------------------------------------------------------------------- +AC_DEFUN([LA_SEARCH_LIB],[ + dnl look for lib + LA_SEARCH_FILE($1, $3, $5 $5/lib64 $5/lib ) + dnl look for header. + LA_SEARCH_FILE($2, $4, $5 $5/include ) + if test ".$1" = "." || test ".$2" = "."; then + $1= + $2= + fi +]) + + +dnl----------------------------------------------------------------------------- +dnl funky posix threads checking, thanks to +dnl Steven G. Johnson +dnl and Alejandro Forero Cuervo +dnl see http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html +dnl----------------------------------------------------------------------------- +dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +dnl +dnl This macro figures out how to build C programs using POSIX +dnl threads. It sets the PTHREAD_LIBS output variable to the threads +dnl library and linker flags, and the PTHREAD_CFLAGS output variable +dnl to any special C compiler flags that are needed. (The user can also +dnl force certain compiler flags/libs to be tested by setting these +dnl environment variables.) +dnl +dnl Also sets PTHREAD_CC to any special C compiler that is needed for +dnl multi-threaded programs (defaults to the value of CC otherwise). +dnl (This is necessary on AIX to use the special cc_r compiler alias.) +dnl +dnl NOTE: You are assumed to not only compile your program with these +dnl flags, but also link it with them as well. e.g. you should link +dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +dnl +dnl If you are only building threads programs, you may wish to +dnl use these variables in your default LIBS, CFLAGS, and CC: +dnl +dnl LIBS="$PTHREAD_LIBS $LIBS" +dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +dnl CC="$PTHREAD_CC" +dnl +dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute +dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE +dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +dnl +dnl ACTION-IF-FOUND is a list of shell commands to run if a threads +dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands +dnl to run it if it is not found. If ACTION-IF-FOUND is not specified, +dnl the default action will define HAVE_PTHREAD. +dnl +dnl Please let the authors know if this macro fails on any platform, +dnl or if you have any other suggestions or comments. This macro was +dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org) +dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread +dnl macros posted by AFC to the autoconf macro repository. We are also +dnl grateful for the helpful feedback of numerous users. +dnl +dnl @version $Id: acinclude.m4,v 1.1 2007-11-02 16:01:16 tipok Exp $ +dnl @author Steven G. Johnson and Alejandro Forero Cuervo + +AC_DEFUN([ACX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_SAVE +AC_LANG_C +acx_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) + AC_MSG_RESULT($acx_pthread_ok) + if test x"$acx_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all. + +acx_pthread_flags="pthread-config pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthread-config: use pthread-config program (on NetBSD) +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# pthread: Linux, etcetera +# --thread-safe: KAI C++ + +case "${host_cpu}-${host_os}" in + *solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthread or + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags" + ;; +esac + +if test x"$acx_pthread_ok" = xno; then +for flag in $acx_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + pthread-config) + AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) + if test x"$acx_pthread_config" = xno; then continue; fi + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [acx_pthread_ok=yes]) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($acx_pthread_ok) + if test "x$acx_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$acx_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: threads are created detached by default + # and the JOINABLE attribute has a nonstandard name (UNDETACHED). + AC_MSG_CHECKING([for joinable pthread attribute]) + AC_TRY_LINK([#include ], + [int attr=PTHREAD_CREATE_JOINABLE;], + ok=PTHREAD_CREATE_JOINABLE, ok=unknown) + if test x"$ok" = xunknown; then + AC_TRY_LINK([#include ], + [int attr=PTHREAD_CREATE_UNDETACHED;], + ok=PTHREAD_CREATE_UNDETACHED, ok=unknown) + fi + if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then + AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok, + [Define to the necessary symbol if this constant + uses a non-standard name on your system.]) + fi + AC_MSG_RESULT(${ok}) + if test x"$ok" = xunknown; then + AC_MSG_WARN([we do not know how to create joinable pthreads]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case "${host_cpu}-${host_os}" in + *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";; + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + # More AIX lossage: must compile with cc_r + AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + acx_pthread_ok=no + $2 +fi +AC_LANG_RESTORE +])dnl ACX_PTHREAD diff --git a/m4/advanced_shell.m4 b/m4/advanced_shell.m4 new file mode 100644 index 0000000..830be5f --- /dev/null +++ b/m4/advanced_shell.m4 @@ -0,0 +1,45 @@ +# Find for parameter expansion string replace capable shell +# (i. e. shell supporting ${VAR%bc} and ${VAR#ab}) +# Result is returned in PARAMETER_EXPANSION_STRING_REPLACE_CAPABLE_SHELL +AC_DEFUN([AC_PARAMETER_EXPANSION_STRING_REPLACE_CAPABLE_SHELL], +[ + AC_ARG_WITH([parameter_expansion_string_replace_capable_shell],[AS_HELP_STRING([--with-parameter-expansion-string-replace-capable-shell],[full path to shell that supports parameter expansion string replace (i. e. ${var%string} and ${var#string}) [default=check]])],[ + ac_parameter_expansion_string_replace_capable_shell="$withval" + ],[ + ac_parameter_expansion_string_replace_capable_shell="none" + AC_CHECK_FILE([/bin/bash],[ + BASH="/bin/bash" + ],[ + AC_PATH_PROG([BASH],[bash]) + ]) + if test "x$BASH" != "x" ; then + ac_parameter_expansion_string_replace_capable_shell="$BASH" + else + AC_CHECK_FILE([/bin/ash],[ + ASH="/bin/ash" + ],[ + AC_PATH_PROG([ASH],[ash]) + ]) + if test "x$ASH" != "x" ; then + ac_parameter_expansion_string_replace_capable_shell="$ASH" + fi + fi + ]) + AC_CACHE_CHECK([for parameter expansion string replace capable shell], + [ac_cv_parameter_expansion_string_replace_capable_shell],[ + ac_cv_parameter_expansion_string_replace_capable_shell="none" + if test x"$ac_parameter_expansion_string_replace_capable_shell" = xnone ; then + if test x`/bin/sh -c "exec 2>/dev/null ; VAR=abc ; echo \\${VAR%bc}\\${VAR#ab}"` = xac ; then + ac_cv_parameter_expansion_string_replace_capable_shell="/bin/sh" + fi + else + ac_cv_parameter_expansion_string_replace_capable_shell="$ac_parameter_expansion_string_replace_capable_shell" + fi + ]) + if test x"$ac_cv_parameter_expansion_string_replace_capable_shell" != "xnone" ; then + PARAMETER_EXPANSION_STRING_REPLACE_CAPABLE_SHELL="$ac_cv_parameter_expansion_string_replace_capable_shell" + else + PARAMETER_EXPANSION_STRING_REPLACE_CAPABLE_SHELL="" + fi + AC_SUBST([PARAMETER_EXPANSION_STRING_REPLACE_CAPABLE_SHELL]) +]) diff --git a/m4/downloader_prog.m4 b/m4/downloader_prog.m4 new file mode 100644 index 0000000..6c07d36 --- /dev/null +++ b/m4/downloader_prog.m4 @@ -0,0 +1,42 @@ +# Find web downloading utility +# Result is returned in DOWNLOADER_PROG +AC_DEFUN([AC_CHECK_DOWNLOADER_PROG], +[ + AC_ARG_WITH([downloader],[AS_HELP_STRING([--with-downloader],[http downloading command [default=check]])],[ + ac_downloader_prog="$withval" + ],[ + AC_PATH_PROGS([DOWNLOADER_PROG_CMD],[wget fetch curl]) + ac_downloader_prog="none" + ]) + AC_CACHE_CHECK([for web downloading command], + [ac_cv_downloader_prog], + [ + ac_cv_downloader_prog="$ac_downloader_prog" + ac_downloader_prog_args="" + if test x"$ac_cv_downloader_prog" = "xnone" ; then + case "$DOWNLOADER_PROG_CMD" in + *wget*) + # Does wget does not support -N? + if wget --help 2>/dev/null | grep " -N" >/dev/null ; then + ac_downloader_prog_args=" -N" + else + ac_downloader_prog_args="" + fi + ;; + *fetch*) + ac_downloader_prog_args=" -m" + ;; + *curl*) + ac_downloader_prog_args=" -OR" + ;; + esac + ac_cv_downloader_prog="$DOWNLOADER_PROG_CMD$ac_downloader_prog_args" + fi + ]) + if test x"$ac_cv_downloader_prog" != xnone ; then + DOWNLOADER_PROG="$ac_cv_downloader_prog" + else + DOWNLOADER_PROG="" + fi + AC_SUBST([DOWNLOADER_PROG]) +]) diff --git a/patches/0001-move_headers_at_one_place.patch b/patches/0001-move_headers_at_one_place.patch new file mode 100644 index 0000000..8b9d677 --- /dev/null +++ b/patches/0001-move_headers_at_one_place.patch @@ -0,0 +1,1210 @@ +diff -Nupr src.orig/aacenc.c src.p1/aacenc.c +--- src.orig/aacenc.c 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/aacenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -6,16 +6,7 @@ + #include + #include + +-#include "aacenc.h" +-#include "bitenc.h" +- +-#include "psy_configuration.h" +-#include "psy_main.h" +-#include "qc_main.h" +-#include "psy_main.h" +-#include "channel_map.h" +-#include "stprepro.h" +-#include "minmax.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/aac_rom.c src.p1/aac_rom.c +--- src.orig/aac_rom.c 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/aac_rom.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,9 @@ + */ + + #include +-#include "aac_rom.h" +-#include "FloatFR.h" ++ ++#include "aacplusenc.h" ++ + + #ifdef _WIN32 + #pragma warning(disable : 4305) /* disable truncation from double to float warning */ +diff -Nupr src.orig/aac_rom.h src.p1/aac_rom.h +--- src.orig/aac_rom.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/aac_rom.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef AAC_ROM_H + #define AAC_ROM_H + +-#include "psy_const.h" +-#include "tns_param.h" +- + #define LD_FFT_TWIDDLE_TABLE_SIZE 9 + #define FFT_TWIDDLE_TABLE_SIZE (1 << LD_FFT_TWIDDLE_TABLE_SIZE) + +diff -Nupr src.orig/adj_thr.c src.p1/adj_thr.c +--- src.orig/adj_thr.c 2010-10-11 14:57:30.000000000 +0300 ++++ src.p1/adj_thr.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,11 +5,7 @@ + #include + #include + +-#include "adj_thr_data.h" +-#include "adj_thr.h" +-#include "qc_data.h" +-#include "line_pe.h" +-#include "minmax.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/adj_thr_data.h src.p1/adj_thr_data.h +--- src.orig/adj_thr_data.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/adj_thr_data.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,6 @@ + #ifndef __ADJ_THR_DATA_H + #define __ADJ_THR_DATA_H + +-#include "psy_const.h" +- + typedef struct { + float clipSaveLow, clipSaveHigh; + float minBitSave, maxBitSave; +diff -Nupr src.orig/adj_thr.h src.p1/adj_thr.h +--- src.orig/adj_thr.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/adj_thr.h 2010-10-21 13:06:37.000000000 +0300 +@@ -1,10 +1,6 @@ + #ifndef __ADJ_THR_H + #define __ADJ_THR_H + +-#include "adj_thr_data.h" +-#include "qc_data.h" +-#include "interface.h" +- + float bits2pe(const float bits); + + int AdjThrNew(ADJ_THR_STATE** phAdjThr, +diff -Nupr src.orig/band_nrg.c src.p1/band_nrg.c +--- src.orig/band_nrg.c 2010-10-11 14:57:30.000000000 +0300 ++++ src.p1/band_nrg.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,7 +1,7 @@ + /* + calculation of band energies + */ +-#include "band_nrg.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/bitbuffer.c src.p1/bitbuffer.c +--- src.orig/bitbuffer.c 2010-10-11 14:57:30.000000000 +0300 ++++ src.p1/bitbuffer.c 2010-10-21 13:06:37.000000000 +0300 +@@ -2,10 +2,7 @@ + Bit Buffer Management + */ + +-#include "stdio.h" +-#include "assert.h" +-#include "FFR_bitbuffer.h" +-#include "FloatFR.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/bit_cnt.c src.p1/bit_cnt.c +--- src.orig/bit_cnt.c 2010-10-11 14:57:30.000000000 +0300 ++++ src.p1/bit_cnt.c 2010-10-21 13:06:37.000000000 +0300 +@@ -2,9 +2,8 @@ + Huffman Bitcounter & coder + */ + #include +-#include "bit_cnt.h" +-#include "minmax.h" +-#include "aac_rom.h" ++ ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/bit_cnt.h src.p1/bit_cnt.h +--- src.orig/bit_cnt.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/bit_cnt.h 2010-10-21 13:06:37.000000000 +0300 +@@ -2,7 +2,7 @@ + #define __BITCOUNT_H + + #include +-#include "FFR_bitbuffer.h" ++ + #define INVALID_BITCOUNT (INT_MAX/4) + + /* +diff -Nupr src.orig/bitenc.c src.p1/bitenc.c +--- src.orig/bitenc.c 2010-10-11 14:57:30.000000000 +0300 ++++ src.p1/bitenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,12 +4,8 @@ + #include + #include + +-#include "bitenc.h" +-#include "bit_cnt.h" +-#include "dyn_bits.h" +-#include "qc_data.h" +-#include "interface.h" +-#include "minmax.h" ++#include "aacplusenc.h" ++ + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/bitenc.h src.p1/bitenc.h +--- src.orig/bitenc.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/bitenc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,10 +4,7 @@ + #ifndef _BITENC_H + #define _BITENC_H + +-#include "qc_data.h" +-#include "tns.h" +-#include "channel_map.h" +-#include "interface.h" ++#include "aacplusenc.h" + + struct BITSTREAMENCODER_INIT + { +diff -Nupr src.orig/bit_sbr.c src.p1/bit_sbr.c +--- src.orig/bit_sbr.c 2010-10-11 14:57:30.000000000 +0300 ++++ src.p1/bit_sbr.c 2010-10-21 13:06:37.000000000 +0300 +@@ -3,13 +3,7 @@ + */ + #include + #include +-#include "sbr_def.h" +-#include "FFR_bitbuffer.h" +-#include "bit_sbr.h" +-#include "sbr.h" +-#include "code_env.h" +-#include "cmondata.h" +-#include "ps_bitenc.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/block_switch.c src.p1/block_switch.c +--- src.orig/block_switch.c 2010-10-11 14:57:31.000000000 +0300 ++++ src.p1/block_switch.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,12 +1,11 @@ + /* + Block Switching + */ +-#include "psy_const.h" +-#include "block_switch.h" +-#include "minmax.h" + #include + #include + ++#include "aacplusenc.h" ++ + /* the 3GPP instrumenting tool */ + + +diff -Nupr src.orig/channel_map.c src.p1/channel_map.c +--- src.orig/channel_map.c 2010-10-11 14:57:31.000000000 +0300 ++++ src.p1/channel_map.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,11 +1,8 @@ + /* + Channel Mapping + */ +-#include "channel_map.h" +-#include "bitenc.h" +-#include "psy_const.h" +-#include "qc_data.h" + #include ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/channel_map.h src.p1/channel_map.h +--- src.orig/channel_map.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/channel_map.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,7 @@ + #ifndef _CHANNEL_MAP_H + #define _CHANNEL_MAP_H + +-#include "psy_const.h" +-#include "qc_data.h" ++#include "aacplusenc.h" + + + int InitElementInfo (int nChannels, +diff -Nupr src.orig/cmondata.h src.p1/cmondata.h +--- src.orig/cmondata.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/cmondata.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef __SBR_CMONDATA_H + #define __SBR_CMONDATA_H + +-#include "FFR_bitbuffer.h" +- +- + struct COMMON_DATA { + int sbrHdrBits; + int sbrCrcLen; +diff -Nupr src.orig/code_env.c src.p1/code_env.c +--- src.orig/code_env.c 2010-10-11 14:57:31.000000000 +0300 ++++ src.p1/code_env.c 2010-10-21 13:06:37.000000000 +0300 +@@ -6,9 +6,7 @@ + #include + #include + +-#include "code_env.h" +-#include "sbr.h" +-#include "sbr_rom.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/code_env.h src.p1/code_env.h +--- src.orig/code_env.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/code_env.h 2010-10-21 13:06:37.000000000 +0300 +@@ -5,10 +5,6 @@ + #ifndef __CODE_ENV_H + #define __CODE_ENV_H + +-#include "sbr_main.h" +-#include "sbr_def.h" +-#include "fram_gen.h" +- + typedef struct + { + int offset; +diff -Nupr src.orig/dyn_bits.c src.p1/dyn_bits.c +--- src.orig/dyn_bits.c 2010-10-11 14:57:31.000000000 +0300 ++++ src.p1/dyn_bits.c 2010-10-21 13:06:37.000000000 +0300 +@@ -3,12 +3,7 @@ + */ + #include + #include +-#include "dyn_bits.h" +-#include "bit_cnt.h" +-#include "psy_const.h" +-#include "minmax.h" +-#include "aac_ram.h" +- ++#include "aacplusenc.h" + /* the 3GPP instrumenting tool */ + + +diff -Nupr src.orig/dyn_bits.h src.p1/dyn_bits.h +--- src.orig/dyn_bits.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/dyn_bits.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,10 +4,6 @@ + #ifndef __DYN_BITS_H + #define __DYN_BITS_H + +-#include "psy_const.h" +-#include "tns.h" +-#include "bit_cnt.h" +- + #define MAX_SECTIONS MAX_GROUPED_SFB + #define SECT_ESC_VAL_LONG 31 + #define SECT_ESC_VAL_SHORT 7 +diff -Nupr src.orig/env_bit.c src.p1/env_bit.c +--- src.orig/env_bit.c 2010-10-11 14:57:31.000000000 +0300 ++++ src.p1/env_bit.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,7 @@ + + #include + #include +-#include "env_bit.h" +-#include "cmondata.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/env_bit.h src.p1/env_bit.h +--- src.orig/env_bit.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/env_bit.h 2010-10-21 13:06:37.000000000 +0300 +@@ -5,8 +5,6 @@ + #ifndef BIT_ENV_H + #define BIT_ENV_H + +-#include "FFR_bitbuffer.h" +- + #define SBR_CRC_POLY (0x0233) + #define SBR_CRC_MASK (0x0200) + #define SBR_CRC_RANGE (0x03FF) +diff -Nupr src.orig/env_est.c src.p1/env_est.c +--- src.orig/env_est.c 2010-10-11 14:57:31.000000000 +0300 ++++ src.p1/env_est.c 2010-10-21 13:06:37.000000000 +0300 +@@ -7,15 +7,7 @@ + #include + #include + +-#include "sbr.h" +-#include "env_est.h" +-#include "tran_det.h" +-#include "qmf_enc.h" +-#include "fram_gen.h" +-#include "bit_sbr.h" +-#include "cmondata.h" +-#include "sbr_ram.h" +-#include "ps_enc.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/env_est.h src.p1/env_est.h +--- src.orig/env_est.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/env_est.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,10 +4,6 @@ + #ifndef __ENV_EST_H + #define __ENV_EST_H + +-#include "sbr_def.h" +-#include "aacenc.h" +-#include "qmf_enc.h" +- + typedef struct + { + int pre_transient_info[2]; +diff -Nupr src.orig/fram_gen.c src.p1/fram_gen.c +--- src.orig/fram_gen.c 2010-10-11 14:57:32.000000000 +0300 ++++ src.p1/fram_gen.c 2010-10-21 13:06:37.000000000 +0300 +@@ -6,9 +6,7 @@ + #include + #include + #include +-#include "fram_gen.h" +-#include "sbr_misc.h" +-#include "FloatFR.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/fram_gen.h src.p1/fram_gen.h +--- src.orig/fram_gen.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/fram_gen.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef _FRAM_GEN_H + #define _FRAM_GEN_H + +-#include "sbr_def.h" +-#include "sbr_main.h" +- + #define MAX_ENVELOPES_VARVAR MAX_ENVELOPES + #define MAX_ENVELOPES_FIXVAR_VARFIX 4 + #define MAX_NUM_REL 3 +diff -Nupr src.orig/freq_sca.c src.p1/freq_sca.c +--- src.orig/freq_sca.c 2010-10-11 14:57:32.000000000 +0300 ++++ src.p1/freq_sca.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,8 +5,7 @@ + #include + #include + #include +-#include "freq_sca.h" +-#include "sbr_misc.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/freq_sca.h src.p1/freq_sca.h +--- src.orig/freq_sca.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/freq_sca.h 2010-10-21 13:06:37.000000000 +0300 +@@ -3,7 +3,6 @@ + */ + #ifndef __FREQ_SCA2_H + #define __FREQ_SCA2_H +-#include "sbr_def.h" + + #define MAX_OCTAVE 29 + #define MAX_SECOND_REGION 50 +diff -Nupr src.orig/grp_data.c src.p1/grp_data.c +--- src.orig/grp_data.c 2010-10-11 14:57:32.000000000 +0300 ++++ src.p1/grp_data.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,10 +1,7 @@ + /* + Short block grouping + */ +-#include "psy_const.h" +-#include "interface.h" +-#include "minmax.h" +-#include "grp_data.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/grp_data.h src.p1/grp_data.h +--- src.orig/grp_data.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/grp_data.h 2010-10-21 13:06:37.000000000 +0300 +@@ -3,7 +3,6 @@ + */ + #ifndef __GRP_DATA_H__ + #define __GRP_DATA_H__ +-#include "psy_data.h" + + void + groupShortData(float *mdctSpectrum, +diff -Nupr src.orig/hybrid.c src.p1/hybrid.c +--- src.orig/hybrid.c 2010-10-11 14:57:32.000000000 +0300 ++++ src.p1/hybrid.c 2010-10-21 13:06:37.000000000 +0300 +@@ -6,11 +6,7 @@ + #include + #include + +-#include "hybrid.h" +-#include "sbr_ram.h" +-#include "sbr_rom.h" +-#include "sbr_def.h" +-#include "cfftn.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/interface.c src.p1/interface.c +--- src.orig/interface.c 2010-10-11 14:57:32.000000000 +0300 ++++ src.p1/interface.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,9 +1,7 @@ + /* + Interface psychoaccoustic/quantizer + */ +-#include "minmax.h" +-#include "psy_const.h" +-#include "interface.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/interface.h src.p1/interface.h +--- src.orig/interface.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/interface.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,6 @@ + #ifndef _INTERFACE_H + #define _INTERFACE_H + +-#include "psy_const.h" +-#include "psy_data.h" + + enum + { +diff -Nupr src.orig/invf_est.c src.p1/invf_est.c +--- src.orig/invf_est.c 2010-10-11 14:57:32.000000000 +0300 ++++ src.p1/invf_est.c 2010-10-21 13:06:37.000000000 +0300 +@@ -6,9 +6,7 @@ + #include + #include + #include +-#include "invf_est.h" +-#include "sbr_misc.h" +-#include "sbr_def.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/invf_est.h src.p1/invf_est.h +--- src.orig/invf_est.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/invf_est.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,10 +4,6 @@ + #ifndef _INV_FILT_DET_H + #define _INV_FILT_DET_H + +-#include "sbr_main.h" +-#include "sbr_def.h" +- +- + #define INVF_SMOOTHING_LENGTH 2 + + typedef struct +diff -Nupr src.orig/line_pe.c src.p1/line_pe.c +--- src.orig/line_pe.c 2010-10-11 14:57:32.000000000 +0300 ++++ src.p1/line_pe.c 2010-10-21 13:06:37.000000000 +0300 +@@ -2,8 +2,7 @@ + Perceptual entropie module + */ + #include +-#include "float.h" +-#include "line_pe.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/line_pe.h src.p1/line_pe.h +--- src.orig/line_pe.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/line_pe.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,10 +4,6 @@ + #ifndef __LINE_PE_H + #define __LINE_PE_H + +- +-#include "psy_const.h" +- +- + typedef struct { + /* these two are calculated by prepareSfbPe */ + float sfbLdEnergy[MAX_GROUPED_SFB]; /* log(sfbEnergy)/log(2) */ +diff -Nupr src.orig/mh_det.c src.p1/mh_det.c +--- src.orig/mh_det.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/mh_det.c 2010-10-21 13:06:37.000000000 +0300 +@@ -7,11 +7,7 @@ + #include + #include + #include +-#include "FloatFR.h" +-#include "sbr.h" +-#include "sbr_def.h" +-#include "mh_det.h" +-#include "sbr_ram.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/mh_det.h src.p1/mh_det.h +--- src.orig/mh_det.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/mh_det.h 2010-10-21 13:06:37.000000000 +0300 +@@ -5,12 +5,6 @@ + #ifndef __MH_DETECT_H + #define __MH_DETECT_H + +- +-#include "sbr_main.h" +-#include "fram_gen.h" +- +- +- + typedef struct + { + float* guideVectorDiff; +diff -Nupr src.orig/ms_stereo.c src.p1/ms_stereo.c +--- src.orig/ms_stereo.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/ms_stereo.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,10 +1,8 @@ + /* + MS stereo processing + */ +-#include "psy_const.h" +-#include "ms_stereo.h" +-#include "minmax.h" + #include /* for atan() */ ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/nf_est.c src.p1/nf_est.c +--- src.orig/nf_est.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/nf_est.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,7 @@ + #include + #include + #include +-#include "sbr.h" +-#include "nf_est.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/nf_est.h src.p1/nf_est.h +--- src.orig/nf_est.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/nf_est.h 2010-10-21 13:06:37.000000000 +0300 +@@ -5,10 +5,6 @@ + #ifndef __NF_EST_H + #define __NF_EST_H + +-#include "sbr_main.h" +-#include "sbr_def.h" +-#include "fram_gen.h" +- + + #define NF_SMOOTHING_LENGTH 4 + +diff -Nupr src.orig/pre_echo_control.c src.p1/pre_echo_control.c +--- src.orig/pre_echo_control.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/pre_echo_control.c 2010-10-21 13:06:37.000000000 +0300 +@@ -2,7 +2,7 @@ + Pre echo control + */ + #include +-#include "pre_echo_control.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/ps_bitenc.c src.p1/ps_bitenc.c +--- src.orig/ps_bitenc.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/ps_bitenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -2,12 +2,7 @@ + Parametric stereo bitstream encoder + */ + +-#include "sbr_def.h" +-#include "ps_bitenc.h" +-#include "ps_enc.h" +-#include "env_bit.h" +-#include "sbr_ram.h" +-#include "sbr_rom.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/ps_bitenc.h src.p1/ps_bitenc.h +--- src.orig/ps_bitenc.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/ps_bitenc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,7 @@ + #ifndef __PS_BITENC_H + #define __PS_BITENC_H + +-#include "FFR_bitbuffer.h" +-#include "sbr_main.h" ++#include "aacplusenc.h" + + #define CODE_BOOK_LAV_IID 14 + #define CODE_BOOK_LAV_ICC 7 +diff -Nupr src.orig/ps_enc.c src.p1/ps_enc.c +--- src.orig/ps_enc.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/ps_enc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,11 +5,7 @@ + #include + #include + #include +-#include "ps_enc.h" +-#include "sbr_def.h" +- +-#include "sbr_rom.h" +-#include "sbr_ram.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/ps_enc.h src.p1/ps_enc.h +--- src.orig/ps_enc.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/ps_enc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef __PS_ENC_H + #define __PS_ENC_H + +-#include "ps_bitenc.h" +-#include "hybrid.h" +- + /*############################################################################*/ + /* Constant definitions */ + /*############################################################################*/ +diff -Nupr src.orig/psy_configuration.c src.p1/psy_configuration.c +--- src.orig/psy_configuration.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/psy_configuration.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,10 +5,7 @@ + #include + #include + #include +-#include "psy_configuration.h" +-#include "minmax.h" +-#include "adj_thr.h" +-#include "aac_rom.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/psy_configuration.h src.p1/psy_configuration.h +--- src.orig/psy_configuration.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/psy_configuration.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef _PSY_CONFIGURATION_H + #define _PSY_CONFIGURATION_H + +-#include "psy_const.h" +-#include "tns.h" +- + typedef struct{ + + int sfbCnt; +diff -Nupr src.orig/psy_const.h src.p1/psy_const.h +--- src.orig/psy_const.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/psy_const.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,6 @@ + #ifndef _PSYCONST_H + #define _PSYCONST_H + +-#include "aacenc.h" +- + #define TRUE 1 + #define FALSE 0 + +diff -Nupr src.orig/psy_data.h src.p1/psy_data.h +--- src.orig/psy_data.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/psy_data.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef _PSY_DATA_H + #define _PSY_DATA_H + +-#include "block_switch.h" +-#include "tns.h" +- + /* + the structs can be implemented as unions + */ +diff -Nupr src.orig/psy_main.c src.p1/psy_main.c +--- src.orig/psy_main.c 2010-10-11 14:57:33.000000000 +0300 ++++ src.p1/psy_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -3,22 +3,7 @@ + */ + #include + #include +-#include "psy_const.h" +-#include "block_switch.h" +-#include "transform.h" +-#include "spreading.h" +-#include "pre_echo_control.h" +-#include "band_nrg.h" +-#include "psy_configuration.h" +-#include "psy_data.h" +-#include "ms_stereo.h" +-#include "interface.h" +-#include "psy_main.h" +-#include "grp_data.h" +-#include "tns_func.h" +-#include "minmax.h" +-#include "aac_ram.h" +-#include "sbr_ram.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/psy_main.h src.p1/psy_main.h +--- src.orig/psy_main.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/psy_main.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,10 +4,6 @@ + #ifndef _PSYMAIN_H + #define _PSYMAIN_H + +-#include "psy_configuration.h" +-#include "qc_data.h" +- +- + /* + psy kernel + */ +diff -Nupr src.orig/qc_data.h src.p1/qc_data.h +--- src.orig/qc_data.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/qc_data.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,11 +4,6 @@ + #ifndef _QC_DATA_H + #define _QC_DATA_H + +-#include "psy_const.h" +-#include "dyn_bits.h" +-#include "adj_thr_data.h" +- +- + typedef enum { + ID_SCE=0, /* Single Channel Element */ + ID_CPE=1, /* Channel Pair Element */ +diff -Nupr src.orig/qc_main.c src.p1/qc_main.c +--- src.orig/qc_main.c 2010-10-11 14:57:34.000000000 +0300 ++++ src.p1/qc_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,17 +4,7 @@ + #include + #include + #include +-#include "qc_main.h" +-#include "quantize.h" +-#include "interface.h" +-#include "adj_thr.h" +-#include "sf_estim.h" +-#include "stat_bits.h" +-#include "bit_cnt.h" +-#include "dyn_bits.h" +-#include "minmax.h" +-#include "channel_map.h" +-#include "aac_ram.h" ++#include "aacplusenc.h" + + #include + +diff -Nupr src.orig/qc_main.h src.p1/qc_main.h +--- src.orig/qc_main.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/qc_main.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,6 @@ + #ifndef _QC_MAIN_H + #define _QC_MAIN_H + +-#include "qc_data.h" +-#include "interface.h" + + + int QCOutNew(QC_OUT *hQC, int nChannels); +diff -Nupr src.orig/qmf_enc.c src.p1/qmf_enc.c +--- src.orig/qmf_enc.c 2010-10-11 14:57:34.000000000 +0300 ++++ src.p1/qmf_enc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,10 +4,7 @@ + #include + #include + #include +-#include "qmf_enc.h" +-#include "sbr_rom.h" +-#include "sbr_ram.h" +-#include "sbr_def.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/qmf_enc.h src.p1/qmf_enc.h +--- src.orig/qmf_enc.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/qmf_enc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,6 +4,8 @@ + #ifndef __QMF_ENC_H + #define __QMF_ENC_H + ++#include "aacplusenc.h" ++ + typedef struct + { + const float *p_filter; +diff -Nupr src.orig/quantize.c src.p1/quantize.c +--- src.orig/quantize.c 2010-10-11 14:57:34.000000000 +0300 ++++ src.p1/quantize.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,11 +5,7 @@ + #include + #include + #include +-#include "minmax.h" +-#include "quantize.h" +-#include "float.h" +-#include "aac_rom.h" +-#include "FloatFR.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/resampler.c src.p1/resampler.c +--- src.orig/resampler.c 2010-10-11 14:57:34.000000000 +0300 ++++ src.p1/resampler.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,7 +5,7 @@ + #include + #include + #include +-#include "resampler.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/sbr.h src.p1/sbr.h +--- src.orig/sbr.h 2010-10-11 14:57:28.000000000 +0300 ++++ src.p1/sbr.h 2010-10-21 13:06:37.000000000 +0300 +@@ -5,17 +5,6 @@ + #ifndef __SBR_H + #define __SBR_H + +-#include "qmf_enc.h" +-#include "tran_det.h" +-#include "fram_gen.h" +-#include "nf_est.h" +-#include "mh_det.h" +-#include "invf_est.h" +-#include "env_est.h" +-#include "code_env.h" +-#include "sbr_main.h" +-#include "ton_corr.h" +- + struct SBR_BITSTREAM_DATA + { + int TotalBits; +diff -Nupr src.orig/sbr_main.c src.p1/sbr_main.c +--- src.orig/sbr_main.c 2010-10-11 14:57:34.000000000 +0300 ++++ src.p1/sbr_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,16 +4,7 @@ + #include + #include + #include +-#include "sbr_main.h" +-#include "sbr.h" +-#include "sbr_ram.h" +-#include "freq_sca.h" +-#include "ps_enc.h" +-#include "qmf_enc.h" +-#include "env_est.h" +-#include "env_bit.h" +-#include "cmondata.h" +-#include "FloatFR.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/sbr_misc.c src.p1/sbr_misc.c +--- src.orig/sbr_misc.c 2010-10-11 14:57:34.000000000 +0300 ++++ src.p1/sbr_misc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,7 +1,7 @@ + /* + Sbr miscellaneous helper functions + */ +-#include "sbr_misc.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/sbr_rom.c src.p1/sbr_rom.c +--- src.orig/sbr_rom.c 2010-10-11 14:57:34.000000000 +0300 ++++ src.p1/sbr_rom.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,8 +5,7 @@ + */ + + #include +-#include "sbr_rom.h" +-#include "sbr_main.h" ++#include "aacplusenc.h" + + #define NEGATE_IPD_MASK ( 0x00001000 ) + +diff -Nupr src.orig/sf_estim.c src.p1/sf_estim.c +--- src.orig/sf_estim.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/sf_estim.c 2010-10-21 13:06:37.000000000 +0300 +@@ -3,12 +3,9 @@ + */ + #include + #include +-#include "float.h" +-#include "sf_estim.h" +-#include "minmax.h" +-#include "quantize.h" +-#include "bit_cnt.h" +-#include "aac_ram.h" ++#include ++#include ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/sf_estim.h src.p1/sf_estim.h +--- src.orig/sf_estim.h 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/sf_estim.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,7 @@ + #ifndef __SF_ESTIM_H__ + #define __SF_ESTIM_H__ + +-#include "psy_const.h" +-#include "interface.h" +-#include "qc_data.h" ++#include "aacplusenc.h" + + void + CalcFormFactor(float sfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB], +diff -Nupr src.orig/spreading.c src.p1/spreading.c +--- src.orig/spreading.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/spreading.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,7 @@ + #include + #include + #include +-#include "spreading.h" +-#include "minmax.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/stat_bits.c src.p1/stat_bits.c +--- src.orig/stat_bits.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/stat_bits.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,9 +1,7 @@ + /* + Static bit counter $Revision + */ +-#include "stat_bits.h" +-#include "bitenc.h" +-#include "tns.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/stat_bits.h src.p1/stat_bits.h +--- src.orig/stat_bits.h 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/stat_bits.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef __STAT_BITS_H + #define __STAT_BITS_H + +-#include "psy_const.h" +-#include "interface.h" +- + int countStaticBitdemand(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], + PSY_OUT_ELEMENT *psyOutElement, + int nChannels); +diff -Nupr src.orig/stprepro.c src.p1/stprepro.c +--- src.orig/stprepro.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/stprepro.c 2010-10-21 13:06:37.000000000 +0300 +@@ -3,7 +3,8 @@ + */ + #include + #include +-#include "stprepro.h" ++#include ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/stprepro.h src.p1/stprepro.h +--- src.orig/stprepro.h 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/stprepro.h 2010-10-21 13:06:37.000000000 +0300 +@@ -7,9 +7,6 @@ + struct STEREO_PREPRO; + typedef struct STEREO_PREPRO *HANDLE_STEREO_PREPRO; + +-#include "interface.h" +-#include "channel_map.h" +- + struct STEREO_PREPRO { + + float normPeFac; /*! factor to normalize input PE, depends on bitrate and bandwidth */ +diff -Nupr src.orig/tns.c src.p1/tns.c +--- src.orig/tns.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/tns.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,16 +1,10 @@ + /* + Temporal Noise Shaping + */ +-#include "assert.h" +-#include "psy_const.h" +-#include "tns.h" +-#include "tns_param.h" +-#include "psy_configuration.h" +-#include "tns_func.h" +-#include "minmax.h" +-#include "aac_rom.h" + #include + #include ++#include ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/tns_func.h src.p1/tns_func.h +--- src.orig/tns_func.h 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/tns_func.h 2010-10-21 13:06:37.000000000 +0300 +@@ -3,7 +3,6 @@ + */ + #ifndef _TNS_FUNC_H + #define _TNS_FUNC_H +-#include "psy_configuration.h" + + int InitTnsConfiguration(int bitrate, + long samplerate, +diff -Nupr src.orig/tns.h src.p1/tns.h +--- src.orig/tns.h 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/tns.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,9 +4,6 @@ + #ifndef _TNS_H + #define _TNS_H + +-#include "psy_const.h" +-#include "math.h" +- + #define TNS_MAX_ORDER 12 + #define TNS_MAX_ORDER_SHORT 5 + #define FILTER_DIRECTION 0 +diff -Nupr src.orig/tns_param.c src.p1/tns_param.c +--- src.orig/tns_param.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/tns_param.c 2010-10-21 13:06:37.000000000 +0300 +@@ -2,7 +2,7 @@ + Temporal Noise Shaping parameters + */ + #include +-#include "aac_rom.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/tns_param.h src.p1/tns_param.h +--- src.orig/tns_param.h 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/tns_param.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,8 +4,6 @@ + #ifndef _TNS_PARAM_H + #define _TNS_PARAM_H + +-#include "tns.h" +- + typedef struct{ + int samplingRate; + int maxBandLong; +diff -Nupr src.orig/ton_corr.c src.p1/ton_corr.c +--- src.orig/ton_corr.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/ton_corr.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,12 +5,7 @@ + #include + #include + +-#include "sbr.h" +-#include "sbr_ram.h" +-#include "ton_corr.h" +-#include "invf_est.h" +-#include "sbr_misc.h" +-#include "sbr_def.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/ton_corr.h src.p1/ton_corr.h +--- src.orig/ton_corr.h 2010-10-11 14:57:29.000000000 +0300 ++++ src.p1/ton_corr.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,14 +4,6 @@ + #ifndef _TON_CORR_EST_H + #define _TON_CORR_EST_H + +-#include "sbr.h" +-#include "sbr_main.h" +-#include "sbr_def.h" +-#include "mh_det.h" +-#include "invf_est.h" +-#include "nf_est.h" +- +- + #define MAX_NUM_PATCHES 6 + + /** parameter set for one single patch */ +diff -Nupr src.orig/tran_det.c src.p1/tran_det.c +--- src.orig/tran_det.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/tran_det.c 2010-10-21 13:06:37.000000000 +0300 +@@ -6,11 +6,7 @@ + #include + #include + #include +-#include "FloatFR.h" +-#include "tran_det.h" +-#include "sbr_def.h" +-#include "fram_gen.h" +-#include "sbr_ram.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/transcendent.c src.p1/transcendent.c +--- src.orig/transcendent.c 2010-10-11 14:57:35.000000000 +0300 ++++ src.p1/transcendent.c 2010-10-21 13:06:37.000000000 +0300 +@@ -4,7 +4,7 @@ + + #include + #include +-#include "FloatFR.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + +diff -Nupr src.orig/transform.c src.p1/transform.c +--- src.orig/transform.c 2010-10-11 14:57:36.000000000 +0300 ++++ src.p1/transform.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,15 +1,12 @@ + /* + MDCT transform + */ +-#include "psy_const.h" +-#include "transform.h" + #include + #include + #include + #include + #include +-#include "aac_rom.h" +-#include "cfftn.h" ++#include "aacplusenc.h" + + /* the 3GPP instrumenting tool */ + diff --git a/patches/0002-cfftn-add-fftw3f.patch b/patches/0002-cfftn-add-fftw3f.patch new file mode 100644 index 0000000..5b5a13d --- /dev/null +++ b/patches/0002-cfftn-add-fftw3f.patch @@ -0,0 +1,459 @@ +diff -Nupr src.p1/cfftn.c src.p2/cfftn.c +--- src.p1/cfftn.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/cfftn.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1,10 +1,19 @@ + /* + Complex FFT core for transforms + */ ++#include "cfftn.h" ++#include ++ ++#ifdef HAVE_CONFIG_H ++#include "config.h" ++#endif ++ ++#ifdef _FFTW3 ++#include ++#else + #include + #include + +-#include "cfftn.h" + + /* the 3GPP instrumenting tool */ + +@@ -17,8 +26,29 @@ + #define SIN60 0.86602540378443865 + #define COS72 0.30901699437494742 + #define SIN72 0.95105651629515357 ++#endif ++ ++#ifdef _FFTW3 ++void init_plans(FFTWFContext_t *ctx) ++{ ++ fftwf_complex fft_data; + ++ ctx->plan4 = fftwf_plan_dft_1d(4, &fft_data, &fft_data, FFTW_BACKWARD, FFTW_ESTIMATE); ++ ctx->plan8 = fftwf_plan_dft_1d(8, &fft_data, &fft_data, FFTW_BACKWARD, FFTW_ESTIMATE); ++ ctx->plan64 = fftwf_plan_dft_1d(64, &fft_data, &fft_data, FFTW_FORWARD, FFTW_ESTIMATE); ++ ctx->plan512 = fftwf_plan_dft_1d(512, &fft_data, &fft_data, FFTW_FORWARD, FFTW_ESTIMATE); ++} + ++void destroy_plans(FFTWFContext_t *ctx) ++{ ++ fftwf_destroy_plan(ctx->plan512); ++ fftwf_destroy_plan(ctx->plan64); ++ fftwf_destroy_plan(ctx->plan8); ++ fftwf_destroy_plan(ctx->plan4); ++} ++#endif ++ ++#ifndef _FFTW3 + int cfftn(float Re[], + float Im[], + int nTotal, +@@ -1336,40 +1366,36 @@ Permute_Single_Label: + + return 1; + } ++#endif + + /* + computes complex fourier transform of length len + + returns status + */ +-int CFFTN(float *afftData,int len, int isign) ++int CFFTN(FFTWFContext_t *ctx, float *afftData,int len, int isign) + { +- return(cfftn(afftData,afftData+1,len,len,len,2*isign)); +-} +- +-/* +- computes complex fourier transform of length len +- +- returns status +-*/ +-int CFFTNRI(float *afftDataReal,float *afftDataImag,int len, int isign) +-{ +- return(cfftn(afftDataReal,afftDataImag,len,len,len,isign)); +-} ++#ifdef _FFTW3 ++ switch(len) { ++ case 4: ++ fftwf_execute_dft(ctx->plan4, (fftwf_complex*)afftData, (fftwf_complex*)afftData); ++ break; ++ case 8: ++ fftwf_execute_dft(ctx->plan8, (fftwf_complex*)afftData, (fftwf_complex*)afftData); ++ break; ++ case 64: ++ fftwf_execute_dft(ctx->plan64, (fftwf_complex*)afftData, (fftwf_complex*)afftData); ++ break; ++ case 512: ++ fftwf_execute_dft(ctx->plan512, (fftwf_complex*)afftData, (fftwf_complex*)afftData); ++ break; ++ default: ++ printf("non standard len for FFT: %d\nWill now die", len); ++ exit(1); ++ } + +-/* +- computes complex fourier transform of length len +- +- returns status +-**/ +-int CFFTN_NI(float *InRealData, +- float *InImagData, +- float *OutRealData, +- float *OutImagData, +- int len, int isign) +-{ +- memcpy ( OutRealData, InRealData, len*sizeof(float) ) ; +- memcpy ( OutImagData, InImagData, len*sizeof(float) ) ; +- +- return cfftn(OutRealData,OutImagData,len,len,len,isign); ++ return 1; ++#else ++ return(cfftn(afftData,afftData+1,len,len,len,2*isign)); ++#endif + } +diff -Nupr src.p1/cfftn.h src.p2/cfftn.h +--- src.p1/cfftn.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/cfftn.h 2010-10-21 13:06:37.000000000 +0300 +@@ -5,30 +5,24 @@ + #ifndef __cfftn_h + #define __cfftn_h + +-void forwardFFT( float *data, int length ); +- +-int cfftn(float Re[], +- float Im[], +- int nTotal, +- int nPass, +- int nSpan, +- int iSign); +- +-int CFFTN(float *afftData,int len, int isign); +-int CFFTNRI(float *afftDataReal,float *afftDataImag,int len, int isign); +- +-int CFFTN_NI(float *InRealData, +- float *InImagData, +- float *OutRealData, +- float *OurImagData, +- int len, int isign); +- +-#ifndef min +-#define min(a, b) ((a) < (b) ? (a) : (b)) ++#ifdef HAVE_CONFIG_H ++#include "config.h" + #endif +-#ifndef max +-#define max(a, b) ((a) > (b) ? (a) : (b)) ++ ++#ifdef _FFTW3 ++#include ++typedef struct { ++ fftwf_plan plan4, plan8, plan64, plan512; ++} FFTWFContext_t; ++void init_plans(FFTWFContext_t *ctx); ++void destroy_plans(FFTWFContext_t *ctx); ++#else ++#define init_plans(c); ++#define destroy_plans(c); ++typedef int FFTWFContext_t; + #endif + + ++int CFFTN(FFTWFContext_t *ctx, float *afftData,int len, int isign); ++ + #endif +diff -Nupr src.p1/env_est.c src.p2/env_est.c +--- src.p1/env_est.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/env_est.c 2010-10-21 13:06:37.000000000 +0300 +@@ -582,7 +582,8 @@ calculateSbrEnvelope (float **YBufferLef + + ****************************************************************************/ + void +-extractSbrEnvelope (float *timeInPtr, ++extractSbrEnvelope (FFTWFContext_t *fftctx, ++ float *timeInPtr, + float *pCoreBuffer, + unsigned int timeInStride, + HANDLE_SBR_CONFIG_DATA h_con, +@@ -670,7 +671,7 @@ extractSbrEnvelope (float *timeInPtr, + if (hPsEnc && hSynthesisQmfBank) { + + +- EncodePsFrame(hPsEnc, ++ EncodePsFrame(fftctx, hPsEnc, + h_envChan[0]->sbrExtractEnvelope.iBuffer, + h_envChan[0]->sbrExtractEnvelope.rBuffer, + h_envChan[1]->sbrExtractEnvelope.iBuffer, +diff -Nupr src.p1/env_est.h src.p2/env_est.h +--- src.p1/env_est.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/env_est.h 2010-10-21 13:06:37.000000000 +0300 +@@ -51,7 +51,8 @@ struct PS_ENC; + + + void +-extractSbrEnvelope(float *timeInPtr, ++extractSbrEnvelope(FFTWFContext_t *fftctx, ++ float *timeInPtr, + float *pCoreBuffer, + unsigned int timeInStride, + struct SBR_CONFIG_DATA *h_con, +diff -Nupr src.p1/hybrid.c src.p2/hybrid.c +--- src.p1/hybrid.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/hybrid.c 2010-10-21 13:06:37.000000000 +0300 +@@ -10,7 +10,8 @@ + + /* the 3GPP instrumenting tool */ + +-static void fourChannelFiltering( const float *pQmfReal, ++static void fourChannelFiltering( FFTWFContext_t *fftctx, ++ const float *pQmfReal, + const float *pQmfImag, + float **mHybridReal, + float **mHybridImag, +@@ -77,7 +78,7 @@ static void fourChannelFiltering( const + cum[3] = (real + imag ) * 0.70710678118655f; + + +- CFFTN(cum, 4, 1); ++ CFFTN(fftctx, cum, 4, 1); + + + for(n = 0; n < 4; n++) { +@@ -90,7 +91,8 @@ static void fourChannelFiltering( const + + } + +-static void eightChannelFiltering( const float *pQmfReal, ++static void eightChannelFiltering( FFTWFContext_t *fftctx, ++ const float *pQmfReal, + const float *pQmfImag, + float **mHybridReal, + float **mHybridImag) +@@ -196,7 +198,7 @@ static void eightChannelFiltering( const + cum[3] = real * 0.38268343236509f + imag * 0.92387953251129f; + + +- CFFTN(cum, 8, 1); ++ CFFTN(fftctx, cum, 8, 1); + + + for(n = 0; n < 8; n++) { +@@ -219,7 +221,8 @@ static void eightChannelFiltering( const + */ + /**************************************************************************/ + void +-HybridAnalysis ( const float **mQmfReal, ++HybridAnalysis ( FFTWFContext_t *fftctx, ++ const float **mQmfReal, + const float **mQmfImag, + float **mHybridReal, + float **mHybridImag, +@@ -270,7 +273,8 @@ HybridAnalysis ( const float **mQmfReal, + + /* filtering. */ + +- fourChannelFiltering( hHybrid->pWorkReal, ++ fourChannelFiltering( fftctx, ++ hHybrid->pWorkReal, + hHybrid->pWorkImag, + mHybridReal, + mHybridImag, +@@ -282,7 +286,8 @@ HybridAnalysis ( const float **mQmfReal, + + /* filtering. */ + +- eightChannelFiltering( hHybrid->pWorkReal, ++ eightChannelFiltering( fftctx, ++ hHybrid->pWorkReal, + hHybrid->pWorkImag, + mHybridReal, + mHybridImag); +diff -Nupr src.p1/hybrid.h src.p2/hybrid.h +--- src.p1/hybrid.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/hybrid.h 2010-10-21 13:06:37.000000000 +0300 +@@ -31,7 +31,8 @@ typedef struct + typedef HYBRID *HANDLE_HYBRID; + + void +-HybridAnalysis ( const float **mQmfReal, ++HybridAnalysis ( FFTWFContext_t *fftctx, ++ const float **mQmfReal, + const float **mQmfImag, + float **mHybridReal, + float **mHybridImag, +diff -Nupr src.p1/ps_enc.c src.p2/ps_enc.c +--- src.p1/ps_enc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/ps_enc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -303,7 +303,8 @@ DeletePsEnc(HANDLE_PS_ENC *h_ps_e) + + ****************************************************************************/ + void +-EncodePsFrame(HANDLE_PS_ENC pms, ++EncodePsFrame(FFTWFContext_t *fftctx, ++ HANDLE_PS_ENC pms, + float **iBufferLeft, + float **rBufferLeft, + float **iBufferRight, +@@ -322,14 +323,16 @@ EncodePsFrame(HANDLE_PS_ENC pms, + + + +- HybridAnalysis ( (const float**) rBufferLeft, ++ HybridAnalysis ( fftctx, ++ (const float**) rBufferLeft, + (const float**) iBufferLeft, + pms->mHybridRealLeft, + pms->mHybridImagLeft, + pms->hHybridLeft); + + +- HybridAnalysis ( (const float**) rBufferRight, ++ HybridAnalysis ( fftctx, ++ (const float**) rBufferRight, + (const float**) iBufferRight, + pms->mHybridRealRight, + pms->mHybridImagRight, +diff -Nupr src.p1/ps_enc.h src.p2/ps_enc.h +--- src.p1/ps_enc.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/ps_enc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -93,7 +93,8 @@ DeletePsEnc(HANDLE_PS_ENC *h_ps_e); + + + void +-EncodePsFrame(HANDLE_PS_ENC h_ps_e, ++EncodePsFrame(FFTWFContext_t *fftctx, ++ HANDLE_PS_ENC h_ps_e, + float **iBufferLeft, + float **rBufferLeft, + float **iBufferRight, +diff -Nupr src.p1/psy_main.c src.p2/psy_main.c +--- src.p1/psy_main.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/psy_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -230,7 +230,8 @@ int psyMainInit(PSY_KERNEL *hPsy, + + *****************************************************************************/ + +-int psyMain(int timeInStride, ++int psyMain(FFTWFContext_t *fftctx, ++ int timeInStride, + ELEMENT_INFO *elemInfo, + float *timeSignal, + PSY_DATA psyData[MAX_CHANNELS], +@@ -285,7 +286,8 @@ int psyMain(int timeInStride, + if(psyData[ch].blockSwitchingControl.windowSequence != SHORT_WINDOW){ + + +- Transform_Real( psyData[ch].mdctDelayBuffer, ++ Transform_Real( fftctx, ++ psyData[ch].mdctDelayBuffer, + timeSignal+elemInfo->ChannelIndex[ch], + timeInStride, + psyData[ch].mdctSpectrum, +@@ -294,7 +296,8 @@ int psyMain(int timeInStride, + else { + + +- Transform_Real( psyData[ch].mdctDelayBuffer, ++ Transform_Real( fftctx, ++ psyData[ch].mdctDelayBuffer, + timeSignal+elemInfo->ChannelIndex[ch], + timeInStride, + psyData[ch].mdctSpectrum, +diff -Nupr src.p1/psy_main.h src.p2/psy_main.h +--- src.p1/psy_main.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/psy_main.h 2010-10-21 13:06:37.000000000 +0300 +@@ -30,7 +30,8 @@ int psyMainInit( PSY_KERNEL *hPsy, + int bandwidth); + + +-int psyMain(int nChannels, /*! total number of channels */ ++int psyMain(FFTWFContext_t *fftctx, ++ int nChannels, /*! total number of channels */ + ELEMENT_INFO *elemInfo, + float *timeSignal, /*! interleaved time signal */ + PSY_DATA psyData[MAX_CHANNELS], +diff -Nupr src.p1/transform.c src.p2/transform.c +--- src.p1/transform.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/transform.c 2010-10-21 13:06:37.000000000 +0300 +@@ -111,7 +111,8 @@ static void postModulationDCT(float *x,i + } + + +-static void mdct(float *dctdata, ++static void mdct(FFTWFContext_t *fftctx, ++ float *dctdata, + const float *trigData, + const float *sineWindow, + int n, +@@ -124,7 +125,7 @@ static void mdct(float *dctdata, + preModulationDCT(dctdata,n,sineWindow); + + +- CFFTN(dctdata,n/2,-1); ++ CFFTN(fftctx, dctdata,n/2,-1); + + assert (LD_FFT_TWIDDLE_TABLE_SIZE >= ld_n-1); + +@@ -172,7 +173,7 @@ static void shiftMdctDelayBuffer( + + } + +-int Transform_Real(float *mdctDelayBuffer,float *timeSignal,int chIncrement,float *realOut,int blockType) ++int Transform_Real(FFTWFContext_t *fftctx, float *mdctDelayBuffer,float *timeSignal,int chIncrement,float *realOut,int blockType) + { + int i,w; + float timeSignalSample; +@@ -245,7 +246,7 @@ int Transform_Real(float *mdctDelayBuffe + } + + +- mdct(dctIn, fftTwiddleTab, LongWindowSine, FRAME_LEN_LONG, 10); ++ mdct(fftctx, dctIn, fftTwiddleTab, LongWindowSine, FRAME_LEN_LONG, 10); + + break; + +@@ -323,7 +324,7 @@ int Transform_Real(float *mdctDelayBuffe + } + + +- mdct(dctIn, fftTwiddleTab, LongWindowSine, FRAME_LEN_LONG, 10); ++ mdct(fftctx, dctIn, fftTwiddleTab, LongWindowSine, FRAME_LEN_LONG, 10); + + break; + +@@ -402,7 +403,7 @@ int Transform_Real(float *mdctDelayBuffe + } + + +- mdct(dctIn, fftTwiddleTab, LongWindowSine, FRAME_LEN_LONG, 10); ++ mdct(fftctx, dctIn, fftTwiddleTab, LongWindowSine, FRAME_LEN_LONG, 10); + + break; + +@@ -458,7 +459,7 @@ int Transform_Real(float *mdctDelayBuffe + } + + +- mdct(dctIn, fftTwiddleTab, ShortWindowSine, FRAME_LEN_SHORT, 7); ++ mdct(fftctx, dctIn, fftTwiddleTab, ShortWindowSine, FRAME_LEN_SHORT, 7); + } + + +diff -Nupr src.p1/transform.h src.p2/transform.h +--- src.p1/transform.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p2/transform.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,7 +4,8 @@ + #ifndef __TRANSFORM_H__ + #define __TRANSFORM_H__ + +-int Transform_Real(float *mdctDelayBuffer, ++int Transform_Real(FFTWFContext_t *fftctx, ++ float *mdctDelayBuffer, + float *timeSignal, + int chIncrement, + float *realOut, diff --git a/patches/0003-faac_compatible.patch b/patches/0003-faac_compatible.patch new file mode 100644 index 0000000..a1c1828 --- /dev/null +++ b/patches/0003-faac_compatible.patch @@ -0,0 +1,94 @@ +diff -Nupr src.p2/aacenc.c src.p3/aacenc.c +--- src.p2/aacenc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p3/aacenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -402,7 +402,7 @@ int AacEncEncode(struct AAC_ENCODER *aac + &aacEnc->qcOut); + + +- WriteBitstream( aacEnc->hBitStream, ++ WriteBitstreamData( aacEnc->hBitStream, + *elInfo, + &aacEnc->qcOut, + &aacEnc->psyOut, +diff -Nupr src.p2/bitenc.c src.p3/bitenc.c +--- src.p2/bitenc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p3/bitenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -812,14 +812,14 @@ static void writeFillElement( const unsi + + /***************************************************************************** + +- functionname: WriteBitStream ++ functionname: WriteBitStreamData + description: main function of write process + returns: + input: + output: + + *****************************************************************************/ +-int WriteBitstream (HANDLE_BIT_BUF hBitStream, ++int WriteBitstreamData (HANDLE_BIT_BUF hBitStream, + ELEMENT_INFO elInfo, + QC_OUT *qcOut, + PSY_OUT* psyOut, +diff -Nupr src.p2/bitenc.h src.p3/bitenc.h +--- src.p2/bitenc.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p3/bitenc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -16,7 +16,7 @@ struct BITSTREAMENCODER_INIT + + + +-int WriteBitstream (HANDLE_BIT_BUF hBitstream, ++int WriteBitstreamData (HANDLE_BIT_BUF hBitstream, + ELEMENT_INFO elInfo, + QC_OUT* qcOut, + PSY_OUT* psyOut, +diff -Nupr src.p2/psy_main.c src.p3/psy_main.c +--- src.p2/psy_main.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p3/psy_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -597,7 +597,7 @@ static int advancePsychLong(PSY_DATA* ps + } + + +- TnsEncode( &psyOutChannel->tnsInfo, ++ TnsEncodeData( &psyOutChannel->tnsInfo, + tnsData, + psyConfLong->sfbCnt, + psyConfLong->tnsConf, +@@ -826,7 +826,7 @@ static int advancePsychShort(PSY_DATA* p + } + + +- TnsEncode( &psyOutChannel->tnsInfo, ++ TnsEncodeData( &psyOutChannel->tnsInfo, + tnsData, + psyConfShort->sfbCnt, + psyConfShort->tnsConf, +diff -Nupr src.p2/tns.c src.p3/tns.c +--- src.p2/tns.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p3/tns.c 2010-10-21 13:06:37.000000000 +0300 +@@ -463,11 +463,11 @@ void TnsSync(TNS_DATA *tnsDataDest, + + + /***************************************************************************** +- functionname: TnsEncode ++ functionname: TnsEncodeData + description: + + *****************************************************************************/ +-int TnsEncode(TNS_INFO* tnsInfo, ++int TnsEncodeData(TNS_INFO* tnsInfo, + TNS_DATA* tnsData, + int numOfSfb, + TNS_CONFIG tC, +diff -Nupr src.p2/tns_func.h src.p3/tns_func.h +--- src.p2/tns_func.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p3/tns_func.h 2010-10-21 13:06:37.000000000 +0300 +@@ -33,7 +33,7 @@ void TnsSync(TNS_DATA *tnsDataDest, + const int subBlockNumber, + const int blockType); + +-int TnsEncode(TNS_INFO* tnsInfo, ++int TnsEncodeData(TNS_INFO* tnsInfo, + TNS_DATA* tnsData, + int numOfSfb, + TNS_CONFIG tC, diff --git a/patches/0004-const_where_possible.patch b/patches/0004-const_where_possible.patch new file mode 100644 index 0000000..72a8b6e --- /dev/null +++ b/patches/0004-const_where_possible.patch @@ -0,0 +1,85 @@ +diff -Nupr src.p3/invf_est.c src.p4/invf_est.c +--- src.p3/invf_est.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p4/invf_est.c 2010-10-21 13:06:37.000000000 +0300 +@@ -29,11 +29,11 @@ + + + +-static float quantStepsSbr[4] = {1, 10, 14, 19}; +-static float quantStepsOrig[4] = {0, 3, 7, 10}; +-static float nrgBorders[4] = {25.0f, 30.0f, 35.0f, 40.0f}; ++static const float quantStepsSbr[4] = {1, 10, 14, 19}; ++static const float quantStepsOrig[4] = {0, 3, 7, 10}; ++static const float nrgBorders[4] = {25.0f, 30.0f, 35.0f, 40.0f}; + +-static DETECTOR_PARAMETERS detectorParamsAAC = { ++static const DETECTOR_PARAMETERS detectorParamsAAC = { + quantStepsSbr, + quantStepsOrig, + nrgBorders, +@@ -60,7 +60,7 @@ static DETECTOR_PARAMETERS detectorParam + static const float hysteresis = 1.0f; + + +-static DETECTOR_PARAMETERS detectorParamsAACSpeech = { ++static const DETECTOR_PARAMETERS detectorParamsAACSpeech = { + quantStepsSbr, + quantStepsOrig, + nrgBorders, +@@ -87,13 +87,13 @@ static DETECTOR_PARAMETERS detectorParam + + typedef const float FIR_FILTER[5]; + +-static FIR_FILTER fir_0 = { 1.0f }; +-static FIR_FILTER fir_1 = { 0.3333333f, 0.6666666f }; +-static FIR_FILTER fir_2 = { 0.125f, 0.375f, 0.5f }; +-static FIR_FILTER fir_3 = { 0.0585786f, 0.2f, 0.3414214f, 0.4f }; +-static FIR_FILTER fir_4 = { 0.0318305f, 0.1151638f, 0.2181695f, 0.3015028f, 0.3333333f }; ++static const FIR_FILTER fir_0 = { 1.0f }; ++static const FIR_FILTER fir_1 = { 0.3333333f, 0.6666666f }; ++static const FIR_FILTER fir_2 = { 0.125f, 0.375f, 0.5f }; ++static const FIR_FILTER fir_3 = { 0.0585786f, 0.2f, 0.3414214f, 0.4f }; ++static const FIR_FILTER fir_4 = { 0.0318305f, 0.1151638f, 0.2181695f, 0.3015028f, 0.3333333f }; + +-static FIR_FILTER *fir_table[5] = { ++static const FIR_FILTER *fir_table[5] = { + &fir_0, + &fir_1, + &fir_2, +diff -Nupr src.p3/invf_est.h src.p4/invf_est.h +--- src.p3/invf_est.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p4/invf_est.h 2010-10-21 13:06:37.000000000 +0300 +@@ -8,9 +8,9 @@ + + typedef struct + { +- float *quantStepsSbr; +- float *quantStepsOrig; +- float *nrgBorders; ++ const float *quantStepsSbr; ++ const float *quantStepsOrig; ++ const float *nrgBorders; + int numRegionsSbr; + int numRegionsOrig; + int numRegionsNrg; +@@ -46,7 +46,7 @@ typedef struct + int noDetectorBands; + int noDetectorBandsMax; + +- DETECTOR_PARAMETERS *detectorParams; ++ const DETECTOR_PARAMETERS *detectorParams; + INVF_MODE prevInvfMode[MAX_NUM_NOISE_VALUES]; + DETECTOR_VALUES detectorValues[MAX_NUM_NOISE_VALUES]; + +diff -Nupr src.p3/psy_configuration.c src.p4/psy_configuration.c +--- src.p3/psy_configuration.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p4/psy_configuration.c 2010-10-21 13:06:37.000000000 +0300 +@@ -23,7 +23,7 @@ static const float BARC_THR_QUIET[] = {1 + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 5.0f, 10.0f, 20.0f, 30.0f}; + + +-static SFB_INFO_TAB sfbInfoTab[] ={ ++static const SFB_INFO_TAB sfbInfoTab[] ={ + {11025, sfb_11025_long_1024, sfb_11025_short_128}, + {12000, sfb_12000_long_1024, sfb_12000_short_128}, + {16000, sfb_16000_long_1024, sfb_16000_short_128}, diff --git a/patches/0005-fix_bitbuff_64bit.patch b/patches/0005-fix_bitbuff_64bit.patch new file mode 100644 index 0000000..3805ed1 --- /dev/null +++ b/patches/0005-fix_bitbuff_64bit.patch @@ -0,0 +1,30 @@ +diff -Nupr src.p4/bitbuffer.c src.p5/bitbuffer.c +--- src.p4/bitbuffer.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p5/bitbuffer.c 2010-10-21 13:06:37.000000000 +0300 +@@ -191,7 +191,7 @@ unsigned long ReadBits(HANDLE_BIT_BUF hB + + + +- /* return value is of type unsigned int, it can hold up to 32 bits ++ /* return value is of type unsigned int, it can hold up to 32 bits OETELAAR TODO wat is dit een 64 platform is?? + this optimized code can read upto 25 Bits a time*/ + + if (noBitsToRead >= 25) { +@@ -235,7 +235,7 @@ unsigned long ReadBits(HANDLE_BIT_BUF hB + } + + +- returnValue = returnValue << (31 - noBitsToRead - hBitBuf->rBitPos) >> (32 - noBitsToRead); ++ returnValue = returnValue << ((LongSize-1) - noBitsToRead - hBitBuf->rBitPos) >> (LongSize - noBitsToRead); + + + return (returnValue); +@@ -281,7 +281,7 @@ unsigned char WriteBits(HANDLE_BIT_BUF h + bitsToWrite = min(hBitBuf->wBitPos + 1, noBitsToWrite); + + +- tmp = (unsigned char) ( writeValue << (32 - noBitsToWrite) >> (32 - bitsToWrite) << (hBitBuf->wBitPos + 1 - bitsToWrite) ); ++ tmp = (unsigned char) ( writeValue << (LongSize - noBitsToWrite) >> (LongSize - bitsToWrite) << (hBitBuf->wBitPos + 1 - bitsToWrite) ); + + /* (hBitBuf->wBitPos + 1 - bitsToWrite) --> already calculated */ + msk = ~(((1 << bitsToWrite) - 1) << (hBitBuf->wBitPos + 1 - bitsToWrite)); diff --git a/patches/0006-add_bitrates.patch b/patches/0006-add_bitrates.patch new file mode 100644 index 0000000..9f4e7b8 --- /dev/null +++ b/patches/0006-add_bitrates.patch @@ -0,0 +1,21 @@ +diff -Nupr src.p5/sbr_main.c src.p6/sbr_main.c +--- src.p5/sbr_main.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p6/sbr_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -57,11 +57,17 @@ static const struct + { 28000, 36000, 22050, 2, 7, 8, 2, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 32 kbit/s */ + { 36000, 44000, 22050, 2, 10, 9, 2, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 40 kbit/s */ + { 44000, 52000, 22050, 2, 12, 9, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 48 kbit/s */ ++ { 52000, 60000, 22050, 2, 12, 9, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 56 kbit/s */ ++ { 60000, 68000, 22050, 2, 14, 10, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 64 kbit/s */ ++ { 68000, 72001, 22050, 2, 14, 10, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 72 kbit/s */ + + { 24000, 28000, 24000, 2, 5, 6, 1, 0, -3, SBR_SWITCH_LRC, 3 }, /* nominal: 24 kbit/s */ + { 28000, 36000, 24000, 2, 7, 8, 2, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 32 kbit/s */ + { 36000, 44000, 24000, 2, 10, 9, 2, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 40 kbit/s */ + { 44000, 52000, 24000, 2, 12, 9, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 48 kbit/s */ ++ { 52000, 60000, 24000, 2, 12, 9, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 56 kbit/s */ ++ { 60000, 68000, 24000, 2, 14, 10, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 64 kbit/s */ ++ { 68000, 72001, 24000, 2, 14, 10, 3, 0, -3, SBR_SWITCH_LRC, 2 }, /* nominal: 72 kbit/s */ + + }; + diff --git a/patches/0007-fix_si_bits_dup.patch b/patches/0007-fix_si_bits_dup.patch new file mode 100644 index 0000000..b50ece9 --- /dev/null +++ b/patches/0007-fix_si_bits_dup.patch @@ -0,0 +1,60 @@ +diff -Nupr src.p6/env_bit.h src.p7/env_bit.h +--- src.p6/env_bit.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p7/env_bit.h 2010-10-21 13:06:37.000000000 +0300 +@@ -22,12 +22,24 @@ + + + +-#define SI_ID_BITS_AAC 3 +-#define SI_FILL_COUNT_BITS 4 +-#define SI_FILL_ESC_COUNT_BITS 8 +-#define SI_FILL_EXTENTION_BITS 4 +-#define ID_FIL 6 +- ++//#define SI_ID_BITS_AAC 3 ++//#define SI_FILL_COUNT_BITS 4 ++//#define SI_FILL_ESC_COUNT_BITS 8 ++//#define SI_FILL_EXTENTION_BITS 4 ++//#define ID_FIL 6 ++typedef enum{ ++ SI_ID_BITS =(3), ++ SI_FILL_COUNT_BITS =(4), ++ SI_FILL_ESC_COUNT_BITS =(8), ++ SI_FILL_EXTENTION_BITS =(4), ++ SI_FILL_NIBBLE_BITS =(4), ++ SI_SCE_BITS =(4), ++ SI_CPE_BITS =(5), ++ SI_CPE_MS_MASK_BITS =(2) , ++ SI_ICS_INFO_BITS_LONG =(1+2+1+6+1), ++ SI_ICS_INFO_BITS_SHORT =(1+2+1+4+7), ++ SI_ICS_BITS =(8+1+1+1), ++}SI_BITS; + + + +diff -Nupr src.p6/stat_bits.c src.p7/stat_bits.c +--- src.p6/stat_bits.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p7/stat_bits.c 2010-10-21 13:06:37.000000000 +0300 +@@ -5,22 +5,6 @@ + + /* the 3GPP instrumenting tool */ + +-typedef enum{ +- SI_ID_BITS =(3), +- SI_FILL_COUNT_BITS =(4), +- SI_FILL_ESC_COUNT_BITS =(8), +- SI_FILL_EXTENTION_BITS =(4), +- SI_FILL_NIBBLE_BITS =(4), +- SI_SCE_BITS =(4), +- SI_CPE_BITS =(5), +- SI_CPE_MS_MASK_BITS =(2) , +- SI_ICS_INFO_BITS_LONG =(1+2+1+6+1), +- SI_ICS_INFO_BITS_SHORT =(1+2+1+4+7), +- SI_ICS_BITS =(8+1+1+1), +-}SI_BITS; +- +- +- + static int countMsMaskBits(int sfbCnt, + int sfbPerGroup, + int maxSfbPerGroup, diff --git a/patches/0008-enchance_config.patch b/patches/0008-enchance_config.patch new file mode 100644 index 0000000..ca1879b --- /dev/null +++ b/patches/0008-enchance_config.patch @@ -0,0 +1,255 @@ +diff -Nupr src.p7/aacenc.c src.p8/aacenc.c +--- src.p7/aacenc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p8/aacenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -52,22 +52,28 @@ static struct AAC_ENCODER aacEncoder; + returns: --- + + ------------------------------------------------------------------------------*/ +-void AacInitDefaultConfig(AACENC_CONFIG *config) ++void AacInitDefaultConfig(aacplusEncConfiguration *config) + { + + + /* make the pre initialization of the structs flexible */ + +- memset(config, 0, sizeof(AACENC_CONFIG)); ++ memset(config, 0, sizeof(aacplusEncConfiguration)); + + /* default configurations */ + + config->bitRate = 48000; + config->bandWidth = 0; ++ config->nSamplesPerFrame = AACENC_BLOCKSIZE; + + + } + ++ ++ ++ ++ ++ + /*--------------------------------------------------------------------------- + + functionname: AacEncOpen +@@ -77,38 +83,26 @@ void AacInitDefaultConfig(AACENC_CONFIG + ---------------------------------------------------------------------------*/ + + int +-AacEncOpen ( struct AAC_ENCODER** phAacEnc, /* pointer to an encoder handle, initialized on return */ +- const AACENC_CONFIG config /* pre-initialized config struct */ ++AacEncOpen ( struct AAC_ENCODER *hAacEnc, /* pointer to an encoder handle, initialized on return */ ++ aacplusEncConfiguration *config /* pre-initialized config struct */ + ) + { + int error = 0; + int profile = 1; + ELEMENT_INFO* elInfo = NULL; +- struct AAC_ENCODER *hAacEnc ; +- +- + + /* counting previous operations */ + + +- hAacEnc = &aacEncoder; +- +- +- if (phAacEnc==0) { +- +- error=1; +- } +- +- + if (!error) { + /* sanity checks on config structure */ + +- error = (&config == 0 || phAacEnc == 0 || +- config.nChannelsIn < 1 || config.nChannelsIn > MAX_CHANNELS || +- config.nChannelsOut < 1 || config.nChannelsOut > MAX_CHANNELS || +- config.nChannelsIn < config.nChannelsOut || +- (config.bitRate!=0 && (config.bitRate / config.nChannelsOut < 8000 || +- config.bitRate / config.nChannelsOut > 160000))); ++ error = (&config == 0 || hAacEnc == 0 || ++ config->nChannelsIn < 1 || config->nChannelsIn > MAX_CHANNELS || ++ config->nChannelsOut < 1 || config->nChannelsOut > MAX_CHANNELS || ++ config->nChannelsIn < config->nChannelsOut || ++ (config->bitRate!=0 && (config->bitRate / config->nChannelsOut < 8000 || ++ config->bitRate / config->nChannelsOut > 160000))); + } + + /* check sample rate */ +@@ -116,7 +110,7 @@ AacEncOpen ( struct AAC_ENCODER** ph + if (!error) { + + +- switch (config.sampleRate) { ++ switch (config->sampleRate) { + case 8000: case 11025: case 12000: + case 16000: case 22050: case 24000: + case 32000: case 44100: case 48000: +@@ -134,8 +128,8 @@ AacEncOpen ( struct AAC_ENCODER** ph + if (!error) { + + +- if (config.bitRate > ((float)(MAX_CHANNEL_BITS-744)/FRAME_LEN_LONG* +- config.sampleRate*config.nChannelsOut)) ++ if (config->bitRate > ((float)(MAX_CHANNEL_BITS-744)/FRAME_LEN_LONG* ++ config->sampleRate*config->nChannelsOut)) + { + + error=1; +@@ -153,7 +147,7 @@ AacEncOpen ( struct AAC_ENCODER** ph + + if (!error) { + +- error = InitElementInfo (config.nChannelsOut, ++ error = InitElementInfo (config->nChannelsOut, + &hAacEnc->elInfo); + } + +@@ -179,12 +173,12 @@ AacEncOpen ( struct AAC_ENCODER** ph + /* counting previous operation */ + + +- hAacEnc->bandwidth90dB = (int)hAacEnc->config.bandWidth; ++ hAacEnc->bandwidth90dB = (int)hAacEnc->config->bandWidth; + + + error = psyMainInit(&hAacEnc->psyKernel, +- config.sampleRate, +- config.bitRate, ++ config->sampleRate, ++ config->bitRate, + elInfo->nChannelsInEl, + tnsMask, + hAacEnc->bandwidth90dB); +@@ -220,20 +214,20 @@ AacEncOpen ( struct AAC_ENCODER** ph + qcInit.bitRes = qcInit.maxBits; + + +- qcInit.averageBits = (config.bitRate * FRAME_LEN_LONG) / config.sampleRate; ++ qcInit.averageBits = (config->bitRate * FRAME_LEN_LONG) / config->sampleRate; + + +- qcInit.padding.paddingRest = config.sampleRate; ++ qcInit.padding.paddingRest = config->sampleRate; + + +- qcInit.meanPe = 10.0f * FRAME_LEN_LONG * hAacEnc->bandwidth90dB/(config.sampleRate/2.0f); ++ qcInit.meanPe = 10.0f * FRAME_LEN_LONG * hAacEnc->bandwidth90dB/(config->sampleRate/2.0f); + + + qcInit.maxBitFac = (float)((MAX_CHANNEL_BITS-744)*elInfo->nChannelsInEl) / + (float)(qcInit.averageBits?qcInit.averageBits:1); + + +- qcInit.bitrate = config.bitRate; ++ qcInit.bitrate = config->bitRate; + + + error = QCInit(&hAacEnc->qcKernel, &qcInit); +@@ -245,8 +239,8 @@ AacEncOpen ( struct AAC_ENCODER** ph + + + hAacEnc->bseInit.nChannels = elInfo->nChannelsInEl; +- hAacEnc->bseInit.bitrate = config.bitRate; +- hAacEnc->bseInit.sampleRate = config.sampleRate; ++ hAacEnc->bseInit.bitrate = config->bitRate; ++ hAacEnc->bseInit.sampleRate = config->sampleRate; + hAacEnc->bseInit.profile = profile; + } + +@@ -256,10 +250,10 @@ AacEncOpen ( struct AAC_ENCODER** ph + if (!error) { + + +- hAacEnc->downmix = (config.nChannelsIn==2 && config.nChannelsOut==1); ++ hAacEnc->downmix = (config->nChannelsIn==2 && config->nChannelsOut==1); + + +- hAacEnc->downmixFac = (hAacEnc->downmix) ? config.nChannelsIn : 1; ++ hAacEnc->downmixFac = (hAacEnc->downmix) ? config->nChannelsIn : 1; + } + + +@@ -273,7 +267,7 @@ AacEncOpen ( struct AAC_ENCODER** ph + + + if ( elInfo->elType == ID_CPE && +- (config.sampleRate <= 24000 && (config.bitRate/elInfo->nChannelsInEl*2) < 60000) ) { ++ (config->sampleRate <= 24000 && (config->bitRate/elInfo->nChannelsInEl*2) < 60000) ) { + + float scfUsedRatio = (float) hAacEnc->psyKernel.psyConfLong.sfbActive / hAacEnc->psyKernel.psyConfLong.sfbCnt ; + +@@ -282,8 +276,8 @@ AacEncOpen ( struct AAC_ENCODER** ph + + error = InitStereoPreProcessing(&(hAacEnc->stereoPrePro), + elInfo->nChannelsInEl, +- config.bitRate, +- config.sampleRate, ++ config->bitRate, ++ config->sampleRate, + scfUsedRatio); + } + } +@@ -295,11 +289,9 @@ AacEncOpen ( struct AAC_ENCODER** ph + AacEncClose(hAacEnc); + + +- hAacEnc=0; + } + + +- *phAacEnc = hAacEnc; + + + +@@ -361,8 +353,8 @@ int AacEncEncode(struct AAC_ENCODER *aac + + + AdjustBitrate(&aacEnc->qcKernel, +- aacEnc->config.bitRate, +- aacEnc->config.sampleRate); ++ aacEnc->config->bitRate, ++ aacEnc->config->sampleRate); + + /* + aacEnc->qcKernel.elementBits +@@ -456,11 +448,10 @@ void AacEncClose (struct AAC_ENCODER* hA + + error = PsyOutDelete(&hAacEnc->psyOut); + +- +- DeleteBitBuffer(&hAacEnc->hBitStream); ++ if(hAacEnc->hBitStream) ++ DeleteBitBuffer(&hAacEnc->hBitStream); + + +- hAacEnc=0; + } + + +diff -Nupr src.p7/aacenc.h src.p8/aacenc.h +--- src.p7/aacenc.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p8/aacenc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -46,7 +46,7 @@ struct AAC_ENCODER; + returns: --- + + ------------------------------------------------------------------------------*/ +-void AacInitDefaultConfig(AACENC_CONFIG *config); ++void AacInitDefaultConfig(aacplusEncConfiguration *config); + + /*--------------------------------------------------------------------------- + +@@ -57,8 +57,8 @@ void AacInitDefaultConfig(AACENC_CONFIG + ---------------------------------------------------------------------------*/ + + int AacEncOpen +-( struct AAC_ENCODER** phAacEnc, /* pointer to an encoder handle, initialized on return */ +- const AACENC_CONFIG config /* pre-initialized config struct */ ++( struct AAC_ENCODER* hAacEnc, /* pointer to an encoder handle, initialized on return */ ++ aacplusEncConfiguration *config /* pre-initialized config struct */ + ); + + int AacEncEncode(struct AAC_ENCODER *hAacEnc, diff --git a/patches/0009-move_aac_sbr_enc_2_hdr.patch b/patches/0009-move_aac_sbr_enc_2_hdr.patch new file mode 100644 index 0000000..c7fc27d --- /dev/null +++ b/patches/0009-move_aac_sbr_enc_2_hdr.patch @@ -0,0 +1,190 @@ +diff -Nupr src.p8/aacenc.c src.p9/aacenc.c +--- src.p8/aacenc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p9/aacenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -10,39 +10,7 @@ + + /* the 3GPP instrumenting tool */ + +-struct AAC_ENCODER { + +- AACENC_CONFIG config; +- +- ELEMENT_INFO elInfo; +- +- QC_STATE qcKernel; +- QC_OUT qcOut; +- +- PSY_OUT psyOut; +- PSY_KERNEL psyKernel; +- +- struct BITSTREAMENCODER_INIT bseInit; +- +- struct STEREO_PREPRO stereoPrePro; +- +- struct BIT_BUF bitStream; +- HANDLE_BIT_BUF hBitStream; +- +- /* lifetime vars */ +- int downmix; +- int downmixFac; +- int dualMono; +- int bandwidth90dB; +-}; +- +- +-/* +- static AAC encoder instance for one encoder +- all other major static and dynamic memory areas are located +- in module aac_ram.c and aac_rom.c +-*/ +-static struct AAC_ENCODER aacEncoder; + + + /*----------------------------------------------------------------------------- +diff -Nupr src.p8/aacenc.h src.p9/aacenc.h +--- src.p8/aacenc.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p9/aacenc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -5,38 +5,36 @@ + #ifndef _aacenc_h_ + #define _aacenc_h_ + +-/* here we distinguish between stereo and the mono only encoder */ +-#ifdef MONO_ONLY +-#define MAX_CHANNELS 1 +-#else +-#define MAX_CHANNELS 2 +-#endif +- +-#define AACENC_BLOCKSIZE 1024 /*! encoder only takes BLOCKSIZE samples at a time */ +-#define AACENC_TRANS_FAC 8 /*! encoder short long ratio */ +-#define AACENC_PCM_LEVEL 1.0 /*! encoder pcm 0db refernence */ +- +- +-/*-------------------------- defines --------------------------------------*/ +- +-#define BUFFERSIZE 1024 /* anc data */ +- +-/*-------------------- structure definitions ------------------------------*/ +- +-typedef struct { +- int sampleRate; /* audio file sample rate */ +- int bitRate; /* encoder bit rate in bits/sec */ +- int nChannelsIn; /* number of channels on input (1,2) */ +- int nChannelsOut; /* number of channels on output (1,2) */ +- int bandWidth; /* core coder audio bandwidth in Hz */ +-} AACENC_CONFIG; +- +-struct AAC_ENCODER; +- +-/* +- * p u b l i c a n c i l l a r y +- * +- */ ++struct AAC_ENCODER { ++//#ifdef _FFTW3 ++ FFTWFContext_t *fftctx; ++//#endif ++ ++ aacplusEncConfiguration *config; ++ AACRam_t *aac_ram; ++ SBRRam_t *sbr_ram; ++ ++ ELEMENT_INFO elInfo; ++ ++ QC_STATE qcKernel; ++ QC_OUT qcOut; ++ ++ PSY_OUT psyOut; ++ PSY_KERNEL psyKernel; ++ ++ struct BITSTREAMENCODER_INIT bseInit; ++ ++ struct STEREO_PREPRO stereoPrePro; ++ ++ struct BIT_BUF bitStream; ++ HANDLE_BIT_BUF hBitStream; ++ ++ /* lifetime vars */ ++ int downmix; ++ int downmixFac; ++ int dualMono; ++ int bandwidth90dB; ++}; + + + /*----------------------------------------------------------------------------- +diff -Nupr src.p8/sbr_main.c src.p9/sbr_main.c +--- src.p8/sbr_main.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p9/sbr_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -72,28 +72,6 @@ static const struct + }; + + +-struct SBR_ENCODER +-{ +- +- struct SBR_CONFIG_DATA sbrConfigData; +- struct SBR_HEADER_DATA sbrHeaderData; +- struct SBR_BITSTREAM_DATA sbrBitstreamData; +- struct ENV_CHANNEL* hEnvChannel[MAX_CHANNELS]; +- struct COMMON_DATA CmonData; +- struct PS_ENC *hPsEnc; +- SBR_QMF_FILTER_BANK *hSynthesisQmfBank; +- unsigned int sbrPayloadPrevious[MAX_PAYLOAD_SIZE/(sizeof(int))]; +- unsigned int sbrPayload[MAX_PAYLOAD_SIZE/(sizeof(int))]; +- int sbrPayloadSize; +-} ; +- +- +-static struct ENV_CHANNEL EnvChannel[MAX_CHANNELS]; +-static struct SBR_ENCODER sbrEncoder; +-static SBR_QMF_FILTER_BANK SynthesisQmfBank; +-static struct PS_ENC psEncoder; +- +- + /***************************************************************************/ + /*! + +@@ -804,21 +782,18 @@ createEnvChannel (int chan, + + *****************************************************************************/ + int +-EnvOpen (HANDLE_SBR_ENCODER * hEnvEncoder, ++EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + float *pCoreBuffer, + sbrConfigurationPtr params, + int *coreBandWith) + { +- HANDLE_SBR_ENCODER hEnvEnc ; + int ch; + + + + +- *hEnvEncoder=0; + + +- hEnvEnc = &sbrEncoder; + + /* hEnvEnc->hEnvChannel[] + EnvChannel[] +@@ -1085,7 +1060,6 @@ EnvOpen (HANDLE_SBR_ENCODER * hEnvEncode + hEnvEnc->sbrPayloadSize = 0; + + +- *hEnvEncoder = hEnvEnc; + *coreBandWith = hEnvEnc->sbrConfigData.xOverFreq; + + +diff -Nupr src.p8/sbr_main.h src.p9/sbr_main.h +--- src.p8/sbr_main.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p9/sbr_main.h 2010-10-21 13:06:37.000000000 +0300 +@@ -102,7 +102,7 @@ typedef struct SBR_ENCODER *HANDLE_SBR_E + + + int +-EnvOpen (HANDLE_SBR_ENCODER* hEnvEncoder, ++EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + float *pCoreBuffer, + sbrConfigurationPtr params, + int *coreBandWith diff --git a/patches/0010-use_dynamic_alloc.patch b/patches/0010-use_dynamic_alloc.patch new file mode 100644 index 0000000..587c542 --- /dev/null +++ b/patches/0010-use_dynamic_alloc.patch @@ -0,0 +1,894 @@ +diff -Nupr src.p9/aacenc.c src.p10/aacenc.c +--- src.p9/aacenc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/aacenc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -130,7 +130,7 @@ AacEncOpen ( struct AAC_ENCODER *hA + if (!error) { + + +- error = (PsyNew(&hAacEnc->psyKernel, elInfo->nChannelsInEl) || ++ error = (PsyNew(hAacEnc->aac_ram, hAacEnc->sbr_ram, &hAacEnc->psyKernel, elInfo->nChannelsInEl) || + PsyOutNew(&hAacEnc->psyOut)); + } + +@@ -157,7 +157,7 @@ AacEncOpen ( struct AAC_ENCODER *hA + + if (!error) { + +- error = QCOutNew(&hAacEnc->qcOut, ++ error = QCOutNew(hAacEnc->aac_ram, &hAacEnc->qcOut, + elInfo->nChannelsInEl); + } + +@@ -198,7 +198,7 @@ AacEncOpen ( struct AAC_ENCODER *hA + qcInit.bitrate = config->bitRate; + + +- error = QCInit(&hAacEnc->qcKernel, &qcInit); ++ error = QCInit(hAacEnc->aac_ram, &hAacEnc->qcKernel, &qcInit); + } + + /* init bitstream encoder */ +@@ -307,7 +307,8 @@ int AacEncEncode(struct AAC_ENCODER *aac + } + + +- psyMain(timeInStride, ++ psyMain(aacEnc->fftctx, ++ timeInStride, + elInfo, + timeSignal, + &aacEnc->psyKernel.psyData[elInfo->ChannelIndex[0]], +@@ -332,7 +333,8 @@ int AacEncEncode(struct AAC_ENCODER *aac + */ + + /* min() */ +- QCMain( &aacEnc->qcKernel, ++ QCMain( aacEnc->aac_ram, ++ &aacEnc->qcKernel, + elInfo->nChannelsInEl, + &aacEnc->qcKernel.elementBits, + &aacEnc->qcKernel.adjThr.adjThrStateElem, +diff -Nupr src.p9/dyn_bits.c src.p10/dyn_bits.c +--- src.p9/dyn_bits.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/dyn_bits.c 2010-10-21 13:06:37.000000000 +0300 +@@ -417,7 +417,7 @@ gmStage2(SECTION_INFO * section, + count bits used by the noiseless coder + */ + static void +-noiselessCounter(SECTION_DATA * sectionData, ++noiselessCounter(AACRam_t *aacram, SECTION_DATA * sectionData, + int mergeGainLookUp[MAX_SFB_LONG], + int bitLookUp[MAX_SFB_LONG][CODE_BOOK_ESC_NDX + 1], + const short *quantSpectrum, +@@ -441,12 +441,12 @@ noiselessCounter(SECTION_DATA * sectionD + case STOP_WINDOW: + + +- sideInfoTab = sideInfoTabLong; ++ sideInfoTab = aacram->sideInfoTabLong; + break; + case SHORT_WINDOW: + + +- sideInfoTab = sideInfoTabShort; ++ sideInfoTab = aacram->sideInfoTabShort; + break; + } + +@@ -715,7 +715,8 @@ static void scfCount(const short *scalef + typedef int (*lookUpTable)[CODE_BOOK_ESC_NDX + 1]; + + int +-dynBitCount(const short *quantSpectrum, ++dynBitCount(AACRam_t *aacram, ++ const short *quantSpectrum, + const unsigned short *maxValueInSfb, + const signed short *scalefac, + const int blockType, +@@ -742,7 +743,7 @@ dynBitCount(const short *quantS + sectionData->maxSfbPerGroup = maxSfbPerGroup; + + +- noiselessCounter(sectionData, ++ noiselessCounter(aacram, sectionData, + mergeGainLookUp, + (lookUpTable)bitLookUp, + quantSpectrum, +@@ -766,7 +767,7 @@ dynBitCount(const short *quantS + + + int +-BCInit(void) ++BCInit(AACRam_t *aacram) + { + int i; + +@@ -777,14 +778,14 @@ BCInit(void) + for (i = 0; i <= MAX_SFB_LONG; i++) + { + +- sideInfoTabLong[i] = calcSideInfoBits(i, LONG_WINDOW); ++ aacram->sideInfoTabLong[i] = calcSideInfoBits(i, LONG_WINDOW); + } + + /* sideInfoTabShort[] */ + for (i = 0; i <= MAX_SFB_SHORT; i++) + { + +- sideInfoTabShort[i] = calcSideInfoBits(i, SHORT_WINDOW); ++ aacram->sideInfoTabShort[i] = calcSideInfoBits(i, SHORT_WINDOW); + } + + +diff -Nupr src.p9/dyn_bits.h src.p10/dyn_bits.h +--- src.p9/dyn_bits.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/dyn_bits.h 2010-10-21 13:06:37.000000000 +0300 +@@ -36,10 +36,10 @@ typedef struct + } + SECTION_DATA; + ++int BCInit(AACRam_t *aacram); + +-int BCInit(void); +- +-int dynBitCount(const short *quantSpectrum, ++int dynBitCount(AACRam_t *aacram, ++ const short *quantSpectrum, + const unsigned short *maxValueInSfb, + const signed short *scalefac, + const int blockType, +diff -Nupr src.p9/env_est.c src.p10/env_est.c +--- src.p9/env_est.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/env_est.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1675,7 +1675,7 @@ extractSbrEnvelope (FFTWFContext_t *fftc + + ****************************************************************************/ + int +-CreateExtractSbrEnvelope (int chan, ++CreateExtractSbrEnvelope (SBRRam_t *sbrram, int chan, + HANDLE_SBR_EXTRACT_ENVELOPE hSbrCut, + int start_index) + { +@@ -1723,7 +1723,7 @@ CreateExtractSbrEnvelope (int chan, + + for (i = 0; i < YBufferLength; i++) { + +- hSbrCut->YBuffer[i] = &sbr_envYBuffer[chan*YBufferLength*64 + i*QMF_CHANNELS]; ++ hSbrCut->YBuffer[i] = &sbrram->sbr_envYBuffer[chan*YBufferLength*64 + i*QMF_CHANNELS]; + } + + /* hSbrCut->rBuffer[] +@@ -1732,10 +1732,10 @@ CreateExtractSbrEnvelope (int chan, + + for (i = 0; i < rBufferLength; i++) { + +- hSbrCut->rBuffer[i] = &sbr_envRBuffer[chan*QMF_TIME_SLOTS*QMF_CHANNELS + i*QMF_CHANNELS]; ++ hSbrCut->rBuffer[i] = &sbrram->sbr_envRBuffer[chan*QMF_TIME_SLOTS*QMF_CHANNELS + i*QMF_CHANNELS]; + + +- hSbrCut->iBuffer[i] = &sbr_envIBuffer[chan*QMF_TIME_SLOTS*QMF_CHANNELS + i*QMF_CHANNELS]; ++ hSbrCut->iBuffer[i] = &sbrram->sbr_envIBuffer[chan*QMF_TIME_SLOTS*QMF_CHANNELS + i*QMF_CHANNELS]; + } + + +diff -Nupr src.p9/env_est.h src.p10/env_est.h +--- src.p9/env_est.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/env_est.h 2010-10-21 13:06:37.000000000 +0300 +@@ -29,7 +29,7 @@ typedef SBR_EXTRACT_ENVELOPE *HANDLE_SBR + /************ Function Declarations ***************/ + + int +-CreateExtractSbrEnvelope (int chan, ++CreateExtractSbrEnvelope (SBRRam_t *sbrram, int chan, + HANDLE_SBR_EXTRACT_ENVELOPE hSbr, + + +diff -Nupr src.p9/mh_det.c src.p10/mh_det.c +--- src.p9/mh_det.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/mh_det.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1264,7 +1264,8 @@ SbrMissingHarmonicsDetectorQmf(HANDLE_SB + */ + /**************************************************************************/ + int +-CreateSbrMissingHarmonicsDetector (int chan, ++CreateSbrMissingHarmonicsDetector (SBRRam_t *sbrram, ++ int chan, + HANDLE_SBR_MISSING_HARMONICS_DETECTOR hSbrMHDet, + int sampleFreq, + unsigned char* freqBandTable, +@@ -1305,7 +1306,7 @@ CreateSbrMissingHarmonicsDetector (int c + hs->noEstPerFrame = noEstPerFrame; + + +- ptr = &sbr_toncorrBuff[chan*5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; ++ ptr = &sbrram->sbr_toncorrBuff[chan*5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; + + /* hs->tonalityDiff[i] + hs->sfmOrig[i] +@@ -1347,13 +1348,13 @@ CreateSbrMissingHarmonicsDetector (int c + memset(hs->guideVectors[i].guideVectorOrig,0,sizeof(float)*MAX_FREQ_COEFFS); + + +- hs->detectionVectors[i] = &(sbr_detectionVectors[chan*NO_OF_ESTIMATES*MAX_FREQ_COEFFS + i*MAX_FREQ_COEFFS]); ++ hs->detectionVectors[i] = &(sbrram->sbr_detectionVectors[chan*NO_OF_ESTIMATES*MAX_FREQ_COEFFS + i*MAX_FREQ_COEFFS]); + + + memset(hs->detectionVectors[i],0,sizeof(unsigned char)*MAX_FREQ_COEFFS); + + +- hs->guideVectors[i].guideVectorDetected = &(sbr_guideVectorDetected[chan*NO_OF_ESTIMATES*MAX_FREQ_COEFFS + i*MAX_FREQ_COEFFS]); ++ hs->guideVectors[i].guideVectorDetected = &(sbrram->sbr_guideVectorDetected[chan*NO_OF_ESTIMATES*MAX_FREQ_COEFFS + i*MAX_FREQ_COEFFS]); + + + memset(hs->guideVectors[i].guideVectorDetected,0,sizeof(unsigned char)*MAX_FREQ_COEFFS); +@@ -1361,13 +1362,13 @@ CreateSbrMissingHarmonicsDetector (int c + } + + +- hs->prevEnvelopeCompensation = &(sbr_prevEnvelopeCompensation[chan*MAX_FREQ_COEFFS]); ++ hs->prevEnvelopeCompensation = &(sbrram->sbr_prevEnvelopeCompensation[chan*MAX_FREQ_COEFFS]); + + + memset( hs->prevEnvelopeCompensation,0, sizeof(char)*MAX_FREQ_COEFFS); + + +- hs->guideScfb = &(sbr_guideScfb[chan*MAX_FREQ_COEFFS]); ++ hs->guideScfb = &(sbrram->sbr_guideScfb[chan*MAX_FREQ_COEFFS]); + + + memset( hs->guideScfb,0, sizeof(unsigned char)*MAX_FREQ_COEFFS); +@@ -1377,7 +1378,7 @@ CreateSbrMissingHarmonicsDetector (int c + hs->previousTransientFrame = 0; + hs->previousTransientPos = 0; + +- assert (ptr-&sbr_toncorrBuff[0] <= 5*MAX_CHANNELS*NO_OF_ESTIMATES*MAX_FREQ_COEFFS); ++ assert (ptr-&sbrram->sbr_toncorrBuff[0] <= 5*MAX_CHANNELS*NO_OF_ESTIMATES*MAX_FREQ_COEFFS); + + + +diff -Nupr src.p9/mh_det.h src.p10/mh_det.h +--- src.p9/mh_det.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/mh_det.h 2010-10-21 13:06:37.000000000 +0300 +@@ -61,7 +61,8 @@ SbrMissingHarmonicsDetectorQmf(HANDLE_SB + + + int +-CreateSbrMissingHarmonicsDetector(int chan, ++CreateSbrMissingHarmonicsDetector(SBRRam_t *sbrram, ++ int chan, + HANDLE_SBR_MISSING_HARMONICS_DETECTOR h_sbrMissingHarmonicsDetector, + int sampleFreq, + unsigned char* freqBandTable, +diff -Nupr src.p9/ps_enc.c src.p10/ps_enc.c +--- src.p9/ps_enc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/ps_enc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -56,7 +56,8 @@ int GetPsMode(int bitRate) + } + + int +-CreatePsEnc(HANDLE_PS_ENC h_ps_e, ++CreatePsEnc(SBRRam_t *sbrram, ++ HANDLE_PS_ENC h_ps_e, + int psMode) + { + int i; +@@ -67,10 +68,10 @@ CreatePsEnc(HANDLE_PS_ENC h_ps_e, + + + +- ptr1 = &sbr_envYBuffer[QMF_TIME_SLOTS * QMF_CHANNELS]; +- ptr2 = &PsBuf2[0]; +- ptr3 = &PsBuf3[0]; +- ptr4 = &PsBuf4[0]; ++ ptr1 = &sbrram->sbr_envYBuffer[QMF_TIME_SLOTS * QMF_CHANNELS]; ++ ptr2 = &sbrram->PsBuf2[0]; ++ ptr3 = &sbrram->PsBuf3[0]; ++ ptr4 = &sbrram->PsBuf4[0]; + + + if (h_ps_e == NULL) +diff -Nupr src.p9/ps_enc.h src.p10/ps_enc.h +--- src.p9/ps_enc.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/ps_enc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -85,7 +85,8 @@ typedef struct PS_ENC *HANDLE_PS_ENC; + int GetPsMode(int bitRate); + + int +-CreatePsEnc(HANDLE_PS_ENC h_ps_enc, ++CreatePsEnc(SBRRam_t *sbrram, ++ HANDLE_PS_ENC h_ps_enc, + int psMode); + + void +diff -Nupr src.p9/psy_main.c src.p10/psy_main.c +--- src.p9/psy_main.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/psy_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -44,7 +44,7 @@ static int advancePsychShortMS (PSY_DATA + input: pointer to a psych handle + + *****************************************************************************/ +-int PsyNew(PSY_KERNEL *hPsy, int nChan) ++int PsyNew(AACRam_t *aacram, SBRRam_t *sbrram, PSY_KERNEL *hPsy, int nChan) + { + int i; + +@@ -60,7 +60,7 @@ int PsyNew(PSY_KERNEL *hPsy, int nChan) + reserve memory for mdct delay buffer + */ + +- hPsy->psyData[i].mdctDelayBuffer = &mdctDelayBuffer[i*BLOCK_SWITCHING_OFFSET]; ++ hPsy->psyData[i].mdctDelayBuffer = &aacram->mdctDelayBuffer[i*BLOCK_SWITCHING_OFFSET]; + + + /* +@@ -68,12 +68,12 @@ int PsyNew(PSY_KERNEL *hPsy, int nChan) + */ + + +- hPsy->psyData[i].mdctSpectrum = &sbr_envRBuffer[i*FRAME_LEN_LONG]; ++ hPsy->psyData[i].mdctSpectrum = &sbrram->sbr_envRBuffer[i*FRAME_LEN_LONG]; + + } + + +- hPsy->pScratchTns = sbr_envIBuffer; ++ hPsy->pScratchTns = sbrram->sbr_envIBuffer; + + + +diff -Nupr src.p9/psy_main.h src.p10/psy_main.h +--- src.p9/psy_main.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/psy_main.h 2010-10-21 13:06:37.000000000 +0300 +@@ -16,7 +16,7 @@ typedef struct { + }PSY_KERNEL; + + +-int PsyNew( PSY_KERNEL *hPsy, int nChan); ++int PsyNew( AACRam_t *aacram, SBRRam_t *sbrram, PSY_KERNEL *hPsy, int nChan); + int PsyDelete( PSY_KERNEL *hPsy); + + int PsyOutNew( PSY_OUT *hPsyOut); +diff -Nupr src.p9/qc_main.c src.p10/qc_main.c +--- src.p9/qc_main.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/qc_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -118,7 +118,7 @@ static int framePadding(int bitRate, + + **********************************************************************************/ + +-int QCOutNew(QC_OUT *hQC, int nChannels) ++int QCOutNew(AACRam_t *aacram, QC_OUT *hQC, int nChannels) + { + int error=0; + int i; +@@ -135,13 +135,13 @@ int QCOutNew(QC_OUT *hQC, int nChannels) + + for (i=0; iqcChannel[i].quantSpec = &quantSpec[i*FRAME_LEN_LONG]; ++ hQC->qcChannel[i].quantSpec = &aacram->quantSpec[i*FRAME_LEN_LONG]; + + +- hQC->qcChannel[i].maxValueInSfb = &maxValueInSfb[i*MAX_GROUPED_SFB]; ++ hQC->qcChannel[i].maxValueInSfb = &aacram->maxValueInSfb[i*MAX_GROUPED_SFB]; + + +- hQC->qcChannel[i].scf = &scf[i*MAX_GROUPED_SFB]; ++ hQC->qcChannel[i].scf = &aacram->scf[i*MAX_GROUPED_SFB]; + } + + +@@ -231,7 +231,7 @@ void QCDelete(QC_STATE *hQC) + return: + + **********************************************************************************/ +-int QCInit(QC_STATE *hQC, ++int QCInit(AACRam_t *aacram, QC_STATE *hQC, + struct QC_INIT *init) + { + +@@ -264,7 +264,7 @@ int QCInit(QC_STATE *hQC, + hQC->elementBits.chBitrate); + + +- BCInit(); ++ BCInit(aacram); + + + +@@ -279,7 +279,8 @@ int QCInit(QC_STATE *hQC, + return: + + **********************************************************************************/ +-int QCMain(QC_STATE* hQC, ++int QCMain(AACRam_t *aacram, ++ QC_STATE* hQC, + int nChannels, + ELEMENT_BITS* elBits, + ATS_ELEMENT* adjThrStateElement, +@@ -350,7 +351,8 @@ int QCMain(QC_STATE* hQC, + qcOutElement->staticBitsUsed+qcOutElement->ancBitsUsed); + + +- EstimateScaleFactors(psyOutChannel, ++ EstimateScaleFactors(aacram, ++ psyOutChannel, + qcOutChannel, + sfbFormFactor, + sfbNRelevantLines, +@@ -427,7 +429,8 @@ int QCMain(QC_STATE* hQC, + + + chDynBits = +- dynBitCount(qcOutChannel[ch].quantSpec, ++ dynBitCount(aacram, ++ qcOutChannel[ch].quantSpec, + qcOutChannel[ch].maxValueInSfb, + qcOutChannel[ch].scf, + psyOutChannel[ch].windowSequence, +diff -Nupr src.p9/qc_main.h src.p10/qc_main.h +--- src.p9/qc_main.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/qc_main.h 2010-10-21 13:06:37.000000000 +0300 +@@ -4,19 +4,18 @@ + #ifndef _QC_MAIN_H + #define _QC_MAIN_H + +- +- +-int QCOutNew(QC_OUT *hQC, int nChannels); ++int QCOutNew(AACRam_t *aacram, QC_OUT *hQC, int nChannels); + + void QCOutDelete(QC_OUT *hQC); + + int QCNew(QC_STATE *hQC); + +-int QCInit(QC_STATE *hQC, struct QC_INIT *init); ++int QCInit(AACRam_t *aacram, QC_STATE *hQC, struct QC_INIT *init); + void QCDelete(QC_STATE *hQC); + + +-int QCMain(QC_STATE *hQC, ++int QCMain(AACRam_t *aacram, ++ QC_STATE *hQC, + int nChannels, + ELEMENT_BITS* elBits, + ATS_ELEMENT* adjThrStateElement, +diff -Nupr src.p9/qmf_enc.c src.p10/qmf_enc.c +--- src.p9/qmf_enc.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/qmf_enc.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1094,7 +1094,8 @@ getEnergyFromCplxQmfData(float **energyV + */ + + int +-createQmfBank (int chan, ++createQmfBank (SBRRam_t *sbrram, ++ int chan, + HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf + + +@@ -1112,7 +1113,7 @@ createQmfBank (int chan, + h_sbrQmf->p_filter = sbr_qmf_64_640; + + +- h_sbrQmf->qmf_states_buffer = sbr_QmfStatesAnalysis + chan * 640; ++ h_sbrQmf->qmf_states_buffer = sbrram->sbr_QmfStatesAnalysis + chan * 640; + + + +@@ -1228,14 +1229,14 @@ SynthesisQmfFiltering (float **sbrReal, + + *******************************************************************************/ + int +-CreateSynthesisQmfBank (HANDLE_SBR_QMF_FILTER_BANK hs) ++CreateSynthesisQmfBank (SBRRam_t *sbrram,HANDLE_SBR_QMF_FILTER_BANK hs) + { + float *ptr; + + + + +- ptr = &PsBuf5[0]; ++ ptr = &sbrram->PsBuf5[0]; + + + memset (hs, 0, sizeof (SBR_QMF_FILTER_BANK)); +diff -Nupr src.p9/qmf_enc.h src.p10/qmf_enc.h +--- src.p9/qmf_enc.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/qmf_enc.h 2010-10-21 13:06:37.000000000 +0300 +@@ -31,7 +31,7 @@ void sbrAnalysisFiltering (const float * + HANDLE_SBR_QMF_FILTER_BANK qmfBank); + + +-int createQmfBank (int chan,HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); ++int createQmfBank (SBRRam_t *sbrram,int chan,HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); + + + void deleteQmfBank (HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); +@@ -52,7 +52,7 @@ SynthesisQmfFiltering (float **sbrReal, + + + int +-CreateSynthesisQmfBank (HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); ++CreateSynthesisQmfBank (SBRRam_t *sbrram,HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf); + + + +diff -Nupr src.p9/sbr_main.c src.p10/sbr_main.c +--- src.p9/sbr_main.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/sbr_main.c 2010-10-21 13:06:37.000000000 +0300 +@@ -377,7 +377,7 @@ EnvClose (HANDLE_SBR_ENCODER hEnvEnc) + + + deleteEnvChannel (hEnvEnc->hEnvChannel[i]); +- ++ free(hEnvEnc->hEnvChannel[i]); + + hEnvEnc->hEnvChannel[i] = NULL; + } +@@ -390,6 +390,7 @@ EnvClose (HANDLE_SBR_ENCODER hEnvEnc) + { + + DeleteSynthesisQmfBank ((HANDLE_SBR_QMF_FILTER_BANK*)&hEnvEnc->hSynthesisQmfBank); ++ free(hEnvEnc->hSynthesisQmfBank); + } + + +@@ -397,6 +398,7 @@ EnvClose (HANDLE_SBR_ENCODER hEnvEnc) + { + + DeletePsEnc(&hEnvEnc->hPsEnc); ++ free(hEnvEnc->hPsEnc); + } + #endif /* #ifndef MONO_ONLY */ + +@@ -535,7 +537,8 @@ EnvEncodeFrame (HANDLE_SBR_ENCODER hEnvE + + + +- extractSbrEnvelope(samples, ++ extractSbrEnvelope(hEnvEncoder->fftctx, ++ samples, + pCoreBuffer, + timeInStride, + &hEnvEncoder->sbrConfigData, +@@ -587,7 +590,8 @@ EnvEncodeFrame (HANDLE_SBR_ENCODER hEnvE + *****************************************************************************/ + + static int +-createEnvChannel (int chan, ++createEnvChannel (SBRRam_t *sbrram, ++ int chan, + HANDLE_SBR_CONFIG_DATA sbrConfigData, + HANDLE_SBR_HEADER_DATA sbrHeaderData, + HANDLE_ENV_CHANNEL hEnv, +@@ -616,7 +620,7 @@ createEnvChannel (int chan, + + + +- if(createQmfBank (chan, &hEnv->sbrQmf)){ ++ if(createQmfBank (sbrram, chan, &hEnv->sbrQmf)){ + + + return (1); /* initialisation failed */ +@@ -627,7 +631,8 @@ createEnvChannel (int chan, + + + +- if(CreateTonCorrParamExtr (chan, ++ if(CreateTonCorrParamExtr (sbrram, ++ chan, + &hEnv->TonCorr, + + +@@ -691,7 +696,8 @@ createEnvChannel (int chan, + + + +- if(CreateExtractSbrEnvelope (chan, ++ if(CreateExtractSbrEnvelope (sbrram, ++ chan, + &hEnv->sbrExtractEnvelope, + + startIndex +@@ -742,7 +748,8 @@ createEnvChannel (int chan, + hEnv->encEnvData.freq_res_fixfix); + + +- if(CreateSbrTransientDetector (chan, ++ if(CreateSbrTransientDetector (sbrram, ++ chan, + &hEnv->sbrTransientDetector, + + sbrConfigData->sampleFreq, +@@ -782,7 +789,8 @@ createEnvChannel (int chan, + + *****************************************************************************/ + int +-EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, ++EnvOpen (SBRRam_t *sbrram, ++ HANDLE_SBR_ENCODER hEnvEnc, + float *pCoreBuffer, + sbrConfigurationPtr params, + int *coreBandWith) +@@ -802,7 +810,7 @@ EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + for (ch=0; chhEnvChannel[ch] = &EnvChannel[ch]; ++ hEnvEnc->hEnvChannel[ch] = calloc(1, sizeof(struct ENV_CHANNEL)); + } + + +@@ -817,19 +825,19 @@ EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + + + +- hEnvEnc->sbrConfigData.freqBandTable[LO] = sbr_freqBandTableLO; ++ hEnvEnc->sbrConfigData.freqBandTable[LO] = sbrram->sbr_freqBandTableLO; + + + memset(hEnvEnc->sbrConfigData.freqBandTable[LO],0,sizeof(unsigned char)*MAX_FREQ_COEFFS/2+1); + + +- hEnvEnc->sbrConfigData.freqBandTable[HI] = sbr_freqBandTableHI; ++ hEnvEnc->sbrConfigData.freqBandTable[HI] = sbrram->sbr_freqBandTableHI; + + + memset(hEnvEnc->sbrConfigData.freqBandTable[HI],0,sizeof(unsigned char)*MAX_FREQ_COEFFS+1); + + +- hEnvEnc->sbrConfigData.v_k_master = sbr_v_k_master; ++ hEnvEnc->sbrConfigData.v_k_master = sbrram->sbr_v_k_master; + + + memset(hEnvEnc->sbrConfigData.v_k_master,0,sizeof(unsigned char)*MAX_FREQ_COEFFS+1); +@@ -986,7 +994,8 @@ EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + for ( ch = 0; ch < hEnvEnc->sbrConfigData.nChannels; ch++ ) { + + +- if(createEnvChannel(ch, ++ if(createEnvChannel(sbrram, ++ ch, + &hEnvEnc->sbrConfigData, + &hEnvEnc->sbrHeaderData, + hEnvEnc->hEnvChannel[ch], +@@ -1011,12 +1020,13 @@ EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + if (params->usePs) + { + +- if(createQmfBank (1, &hEnvEnc->hEnvChannel[1]->sbrQmf)){ ++ if(createQmfBank (sbrram, 1, &hEnvEnc->hEnvChannel[1]->sbrQmf)){ + + return (1); + } + +- if(CreateExtractSbrEnvelope (1, ++ if(CreateExtractSbrEnvelope (sbrram, ++ 1, + &hEnvEnc->hEnvChannel[1]->sbrExtractEnvelope, + 576 + )) { +@@ -1025,10 +1035,10 @@ EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + } + + +- hEnvEnc->hSynthesisQmfBank = &SynthesisQmfBank; ++ hEnvEnc->hSynthesisQmfBank = calloc(1, sizeof(SBR_QMF_FILTER_BANK)); + + +- if(CreateSynthesisQmfBank (hEnvEnc->hSynthesisQmfBank)){ ++ if(CreateSynthesisQmfBank (sbrram, hEnvEnc->hSynthesisQmfBank)){ + + + DeleteSynthesisQmfBank ((HANDLE_SBR_QMF_FILTER_BANK*)&hEnvEnc->hSynthesisQmfBank); +@@ -1038,10 +1048,11 @@ EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, + } + + +- hEnvEnc->hPsEnc = &psEncoder; ++ hEnvEnc->hPsEnc = calloc(1, sizeof(struct PS_ENC)); + + +- if(CreatePsEnc (hEnvEnc->hPsEnc, ++ if(CreatePsEnc (sbrram, ++ hEnvEnc->hPsEnc, + params->psMode)){ + + +diff -Nupr src.p9/sbr_main.h src.p10/sbr_main.h +--- src.p9/sbr_main.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/sbr_main.h 2010-10-21 13:06:37.000000000 +0300 +@@ -102,7 +102,8 @@ typedef struct SBR_ENCODER *HANDLE_SBR_E + + + int +-EnvOpen (HANDLE_SBR_ENCODER hEnvEnc, ++EnvOpen (SBRRam_t *sbrram, ++ HANDLE_SBR_ENCODER hEnvEnc, + float *pCoreBuffer, + sbrConfigurationPtr params, + int *coreBandWith +diff -Nupr src.p9/sf_estim.c src.p10/sf_estim.c +--- src.p9/sf_estim.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/sf_estim.c 2010-10-21 13:06:37.000000000 +0300 +@@ -1035,7 +1035,8 @@ static void assimilateMultipleScf(PSY_OU + + + static void +-estimateScaleFactorsChannel(PSY_OUT_CHANNEL *psyOutChan, ++estimateScaleFactorsChannel(AACRam_t *aacram, ++ PSY_OUT_CHANNEL *psyOutChan, + short *scf, + int *globalGain, + float *sfbFormFactor, +@@ -1062,7 +1063,7 @@ estimateScaleFactorsChannel(PSY_OUT_CHAN + for (i=0; iexpSpec[i] = 0.0f; + quantSpec[i] = 0; + } + +@@ -1124,15 +1125,15 @@ estimateScaleFactorsChannel(PSY_OUT_CHAN + + /* find better scalefactor with analysis by synthesis */ + +- calcExpSpec(expSpec+psyOutChan->sfbOffsets[i], ++ calcExpSpec(aacram->expSpec+psyOutChan->sfbOffsets[i], + psyOutChan->mdctSpectrum+psyOutChan->sfbOffsets[i], + psyOutChan->sfbOffsets[i+1]-psyOutChan->sfbOffsets[i]); + + + scfInt = improveScf(psyOutChan->mdctSpectrum+psyOutChan->sfbOffsets[i], +- expSpec+psyOutChan->sfbOffsets[i], ++ aacram->expSpec+psyOutChan->sfbOffsets[i], + quantSpec+psyOutChan->sfbOffsets[i], +- quantSpecTmp+psyOutChan->sfbOffsets[i], ++ aacram->quantSpecTmp+psyOutChan->sfbOffsets[i], + psyOutChan->sfbOffsets[i+1]-psyOutChan->sfbOffsets[i], + thresh, scfInt, minSfMaxQuant[i], + &sfbDist[i], &minScfCalculated[i]); +@@ -1155,12 +1156,12 @@ estimateScaleFactorsChannel(PSY_OUT_CHAN + } + + +- assimilateSingleScf(psyOutChan, expSpec, quantSpec, quantSpecTmp, scf, ++ assimilateSingleScf(psyOutChan, aacram->expSpec, quantSpec, aacram->quantSpecTmp, scf, + minSfMaxQuant, sfbDist, sfbConstPePart, + sfbFormFactor, sfbNRelevantLines, minScfCalculated, 1); + + +- assimilateMultipleScf(psyOutChan, expSpec, quantSpec, quantSpecTmp, scf, ++ assimilateMultipleScf(psyOutChan, aacram->expSpec, quantSpec, aacram->quantSpecTmp, scf, + minSfMaxQuant, sfbDist, sfbConstPePart, + sfbFormFactor, sfbNRelevantLines); + } +@@ -1204,7 +1205,7 @@ estimateScaleFactorsChannel(PSY_OUT_CHAN + /* ??? */ + sfbDist[i] = + calcSfbDist(psyOutChan->mdctSpectrum+psyOutChan->sfbOffsets[i], +- expSpec+psyOutChan->sfbOffsets[i], ++ aacram->expSpec+psyOutChan->sfbOffsets[i], + quantSpec+psyOutChan->sfbOffsets[i], + psyOutChan->sfbOffsets[i+1]-psyOutChan->sfbOffsets[i], + scf[i]); +@@ -1301,7 +1302,8 @@ CalcFormFactor(float sfbFormFactor[MAX_C + + + void +-EstimateScaleFactors(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], ++EstimateScaleFactors(AACRam_t *aacram, ++ PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS], + QC_OUT_CHANNEL qcOutChannel[MAX_CHANNELS], + float sfbFormFactor[MAX_CHANNELS][MAX_GROUPED_SFB], + float sfbNRelevantLines[MAX_CHANNELS][MAX_GROUPED_SFB], +@@ -1315,7 +1317,8 @@ EstimateScaleFactors(PSY_OUT_CHANNEL psy + for (j=0; jnumberOfEstimates;i++) { + +- hTonCorr->quotaMatrix[i] = &(sbr_quotaMatrix[chan* NO_OF_ESTIMATES*QMF_CHANNELS + i*noQmfChannels]); ++ hTonCorr->quotaMatrix[i] = &(sbrram->sbr_quotaMatrix[chan* NO_OF_ESTIMATES*QMF_CHANNELS + i*noQmfChannels]); + + + memset(hTonCorr->quotaMatrix[i] ,0, sizeof(float)*QMF_CHANNELS); +@@ -815,7 +816,8 @@ CreateTonCorrParamExtr (int chan, + + + +- if(CreateSbrMissingHarmonicsDetector (chan, ++ if(CreateSbrMissingHarmonicsDetector (sbrram, ++ chan, + &hTonCorr->sbrMissingHarmonicsDetector, + fs, + freqBandTable[HI], +diff -Nupr src.p9/ton_corr.h src.p10/ton_corr.h +--- src.p9/ton_corr.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/ton_corr.h 2010-10-21 13:06:37.000000000 +0300 +@@ -72,7 +72,8 @@ TonCorrParamExtr(HANDLE_SBR_TON_CORR_EST + + + int +-CreateTonCorrParamExtr (int chan, ++CreateTonCorrParamExtr (SBRRam_t *sbrram, ++ int chan, + HANDLE_SBR_TON_CORR_EST hTonCorr, + int fs, + int usb, +diff -Nupr src.p9/tran_det.c src.p10/tran_det.c +--- src.p9/tran_det.c 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/tran_det.c 2010-10-21 13:06:37.000000000 +0300 +@@ -489,7 +489,8 @@ transientDetect (float **Energies, + + + int +-CreateSbrTransientDetector (int chan, ++CreateSbrTransientDetector (SBRRam_t *sbrram, ++ int chan, + HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, + + int sampleFreq, +@@ -555,13 +556,13 @@ CreateSbrTransientDetector (int chan, + h_sbrTransientDetector->prevLowBandEnergy = 0; + + +- h_sbrTransientDetector->thresholds = &sbr_thresholds[chan*QMF_CHANNELS]; ++ h_sbrTransientDetector->thresholds = &sbrram->sbr_thresholds[chan*QMF_CHANNELS]; + + + memset(h_sbrTransientDetector->thresholds,0,sizeof(float)*QMF_CHANNELS); + + +- h_sbrTransientDetector->transients = &sbr_transients[chan*h_sbrTransientDetector->buffer_length]; ++ h_sbrTransientDetector->transients = &sbrram->sbr_transients[chan*h_sbrTransientDetector->buffer_length]; + + + memset(h_sbrTransientDetector->transients,0,sizeof(float)*h_sbrTransientDetector->buffer_length); +diff -Nupr src.p9/tran_det.h src.p10/tran_det.h +--- src.p9/tran_det.h 2010-10-21 13:06:37.000000000 +0300 ++++ src.p10/tran_det.h 2010-10-21 13:06:37.000000000 +0300 +@@ -36,7 +36,8 @@ void transientDetect (float **Energies, + ); + + int +-CreateSbrTransientDetector (int chan, ++CreateSbrTransientDetector (SBRRam_t *sbrram, ++ int chan, + HANDLE_SBR_TRANSIENT_DETECTOR h_sbrTransientDetector, + + int sampleFreq, diff --git a/patches/Makefile.am b/patches/Makefile.am new file mode 100644 index 0000000..89e3873 --- /dev/null +++ b/patches/Makefile.am @@ -0,0 +1,11 @@ +EXTRA_DIST = \ +0001-move_headers_at_one_place.patch \ +0002-cfftn-add-fftw3f.patch \ +0003-faac_compatible.patch \ +0004-const_where_possible.patch \ +0005-fix_bitbuff_64bit.patch \ +0006-add_bitrates.patch \ +0007-fix_si_bits_dup.patch \ +0008-enchance_config.patch \ +0009-move_aac_sbr_enc_2_hdr.patch \ +0010-use_dynamic_alloc.patch diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..eab109f --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,237 @@ + +DISTCLEANFILES = 26410-800.zip $(top_srcdir)/26410-800.doc 26410-800-ANSI-C_source_code.zip $(library_sources_used) $(library_headers_used) +EXTRA_DIST = libaacplus.sym +INCLUDES = @FFTW3_INCFLAGS@ -I$(top_srcdir)/include +LDADD = @FFTW3_LDFLAGS@ + +lib_LTLIBRARIES = \ + libaacplus.la + + + +library_sources_used = \ + aacenc.c \ + aac_rom.c \ + adj_thr.c \ + band_nrg.c \ + bitbuffer.c \ + bit_cnt.c \ + bitenc.c \ + bit_sbr.c \ + block_switch.c \ + cfftn.c \ + channel_map.c \ + code_env.c \ + dyn_bits.c \ + env_bit.c \ + env_est.c \ + fram_gen.c \ + freq_sca.c \ + grp_data.c \ + hybrid.c \ + interface.c \ + invf_est.c \ + line_pe.c \ + mh_det.c \ + ms_stereo.c \ + nf_est.c \ + pre_echo_control.c \ + ps_bitenc.c \ + ps_enc.c \ + psy_configuration.c \ + psy_main.c \ + qc_main.c \ + qmf_enc.c \ + quantize.c \ + resampler.c \ + sbr_main.c \ + sbr_misc.c \ + sbr_rom.c \ + sf_estim.c \ + spreading.c \ + stat_bits.c \ + stprepro.c \ + tns.c \ + tns_param.c \ + ton_corr.c \ + tran_det.c \ + transcendent.c \ + transform.c + +libaacplus_la_SOURCES = $(library_sources_used) aacplusenc.c adts.c + + +libaacplus_la_LDFLAGS = \ + -export-symbols libaacplus.sym -no-undefined -version-info 2:2:0 @FFTW3_LDFLAGS@ + +libaacplusdir = \ + $(includedir)/libaacplus + + +#counters.h +library_headers_used = \ + aacenc.h \ + aac_rom.h \ + adj_thr_data.h \ + adj_thr.h \ + band_nrg.h \ + bit_cnt.h \ + bitenc.h \ + bit_sbr.h \ + block_switch.h \ + cfftn.h \ + channel_map.h \ + cmondata.h \ + code_env.h \ + dyn_bits.h \ + env_bit.h \ + env_est.h \ + FFR_bitbuffer.h \ + FloatFR.h \ + fram_gen.h \ + freq_sca.h \ + grp_data.h \ + hybrid.h \ + interface.h \ + invf_est.h \ + line_pe.h \ + mh_det.h \ + minmax.h \ + ms_stereo.h \ + nf_est.h \ + pre_echo_control.h \ + ps_bitenc.h \ + ps_enc.h \ + psy_configuration.h \ + psy_const.h \ + psy_data.h \ + psy_main.h \ + qc_data.h \ + qc_main.h \ + qmf_enc.h \ + quantize.h \ + resampler.h \ + sbr_def.h \ + sbr.h \ + sbr_main.h \ + sbr_misc.h \ + sbr_rom.h \ + sf_estim.h \ + spreading.h \ + stat_bits.h \ + stprepro.h \ + tns_func.h \ + tns.h \ + tns_param.h \ + ton_corr.h \ + tran_det.h \ + transform.h + +noinst_HEADERS = $(library_headers_used) aacplusenc.h adts.h aac_ram.h sbr_ram.h + +sources_delete: + @echo echo "Deleting headers..." + for source in $(library_headers_used); \ + do \ + rm -f $$source; \ + done + @echo echo "Deleting sources..." + for source in $(library_sources_used); \ + do \ + rm -f $$source; \ + done + +sources_copy: + @echo echo "Copying headers..." + for source in $(library_headers_used); \ + do \ + find $(srcdir)/FloatFR_aacPlusenc -name $$source -type f -exec cp {} $(srcdir) \; ; \ + done + @echo echo "Copying sources..." + for source in $(library_sources_used); \ + do \ + find $(srcdir)/FloatFR_aacPlusenc -name $$source -type f -exec cp {} $(srcdir) \; ; \ + done + +patch_all: + @echo echo "Patching sources and headers..." + find $(top_srcdir)/patches -name *.patch -type f -print | sort | xargs cat | $(PATCH) + +remove_debugging_symbols: + @echo echo "Removeing debugging symbols..." + for source in $(library_sources_used); \ + do \ + sed -e 's/ADD\ *([\ 0-9\*]*)\ *;//g;' $$source | \ + sed -e 's/BRANCH\ *([\ 0-9]*)\ *;//g;' | \ + sed -e 's/DIV\ *([\ 0-9]*)\ *;//g;' | \ + sed -e 's/FUNC\ *([\ 0-9]*)\ *;//g;' | \ + sed -e 's/INDIRECT\ *([\ 0-9]*)\ *;//g;' | \ + sed -e 's/LOGIC\ *([0-9\ ]*)\ *;//g;' | \ + sed -e 's/LOOP\ *([0-9\ ]*)\ *;//g;' | \ + sed -e 's/MAC\ *([0-9\ ]*)\ *;//g;' | \ + sed -e 's/MOVE\ *([a-zA-Z_0-9\ \+\*]*)\ *;//g;' | \ + sed -e 's/MISC\ *([0-9\ ]*)\ *;//g;' | \ + sed -e 's/MULT\ *([0-9\ \*\+]*)\ *;//g;' | \ + sed -e 's/PTR_INIT\ *([0-9\ ]*)\ *;*//g;' | \ + sed -e 's/STORE.*[^;];//g;' | \ + sed -e 's/SHIFT\ *([a-zA-Z0-9\ \+]*)\ *;//g;' | \ + sed -e 's/SQRT\ *([0-9\ ]*)\ *;//g;' | \ + sed -e 's/TRANS\ *([0-9\ ]*)\ *;//g;' | \ + sed -e 's/COUNT_init\ *(.*)\ *;//g;' | \ + sed -e 's/COUNT_end\ *(.*)\ *;//g;' | \ + sed -e 's/COUNT_sub_start\ *(.*)\ *;//g;' | \ + sed -e 's/COUNT_sub_end\ *(.*)\ *;//g;' | \ + sed -e 's/COUNT_frame_update\ *(.*)\ *;//g;' | \ + sed -e 's/COUNT_ops\ *(.*)\ *;//g;' | \ + sed -e 's/COUNT_mem\ *(.*)\ *;//g;' | \ + sed -e 's/^#include\ *"counters.h"//g;' > $${source#*/}.new; \ + mv $${source#*/}.new $${source#*/}; \ + done + +unpack_3gp_sources: + if ! [ -e $(srcdir)/aacenc.c ]; \ + then \ + $(MAKE) $(srcdir)/26410-800-ANSI-C_source_code.zip; \ + $(MAKE) $(srcdir)/FloatFR_aacPlusenc; \ + rm -f $(srcdir)/26410-800-ANSI-C_source_code.zip; \ + $(MAKE) sources_delete; \ + $(MAKE) sources_copy; \ + rm -rf $(srcdir)/FloatFR_aacPlusenc; \ + chmod -x-x-x *.c *.h; \ + $(MAKE) remove_debugging_symbols; \ + $(MAKE) patch_all; \ + fi + +$(library_sources_used): + $(MAKE) unpack_3gp_sources + +$(srcdir)/FloatFR_aacPlusenc: + cd $(srcdir) && $(UNZIP) 26410-800-ANSI-C_source_code.zip + mv -f $(srcdir)/3GPP_enhanced_aacPlus_src_*/FloatFR_aacPlusenc $(srcdir) + rm -rf $(srcdir)/3GPP_enhanced_aacPlus_src_* + + +$(srcdir)/26410-800-ANSI-C_source_code.zip: $(srcdir)/26410-800.zip + rm -f $(srcdir)/26410-800-ANSI-C_source_code.zip $(srcdir)/26410-800.doc + cd $(srcdir) && $(UNZIP) 26410-800.zip + mv $(srcdir)/26410-800.doc $(top_srcdir)/26410-800.doc + chmod og-w $(top_srcdir)/26410-800.doc + +$(srcdir)/26410-800.zip: + cd $(srcdir) && $(DOWNLOADER_PROG) http://www.3gpp.org/ftp/Specs/archive/26_series/26.410/26410-800.zip + +extraclean: + rm -f $(distdir)/($(library_sources_used)) $(distdir)/($(library_headers_used)) $(distdir)/26410-800.zip $(distdir)/../26410-800.doc $(distdir)/26410-800_ANSI-C_source_code.zip + +# WARNING: These commands use internal automake command and may fail in future version. +extradist-gzip: distdir extraclean + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + $(am__remove_distdir) +extradist-bzip2: distdir extraclean + tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2 + $(am__remove_distdir) + +extradist extradist-all: distdir extraclean + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2 + $(am__remove_distdir) diff --git a/src/aac_ram.h b/src/aac_ram.h new file mode 100644 index 0000000..b0997bf --- /dev/null +++ b/src/aac_ram.h @@ -0,0 +1,33 @@ +/* + * aac_ram.h + * + * Created on: 7 окт. 2010 + * Author: tipok + */ + +#ifndef AAC_RAM_H_ +#define AAC_RAM_H_ + +#include + +typedef struct { + /* Static memory areas, must not be overwritten in other sections of the encoder */ + /* aac Encoder mdct delay buffer */ + float mdctDelayBuffer[MAX_CHANNELS*BLOCK_SWITCHING_OFFSET]; + /* these tables are initialized once at application start + and are not touched thereafter */ + int sideInfoTabLong[MAX_SFB_LONG + 1]; + int sideInfoTabShort[MAX_SFB_SHORT + 1]; + /* Dynamic memory areas, might be reused in other algorithm sections, */ + /* quantized spectrum */ + short *quantSpec; + /* scratch space for quantization */ + float *expSpec; /* FRAME_LEN_LONG values */ + short *quantSpecTmp; + /* scalefactors */ + short *scf; /*[MAX_CHANNELS*MAX_GROUPED_SFB];*/ + /* max spectral values pre sfb */ + unsigned short *maxValueInSfb; /* [MAX_CHANNELS*MAX_GROUPED_SFB]; */ +} AACRam_t; + +#endif /* AAC_RAM_H_ */ diff --git a/src/aacplusenc.c b/src/aacplusenc.c new file mode 100644 index 0000000..647eb3a --- /dev/null +++ b/src/aacplusenc.c @@ -0,0 +1,392 @@ +/* + * aacplusenc.c + * + * Created on: 6 окт. 2010 + * Author: tipok + */ + +#include +#include +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "aacplus.h" +#include "aacplusenc.h" + +const int mpeg4audio_sample_rates[16] = { + 96000, 88200, 64000, 48000, 44100, 32000, + 24000, 22050, 16000, 12000, 11025, 8000, 7350 +}; + +const uint8_t mpeg4audio_channels[8] = { + 0, 1, 2, 3, 4, 5, 6, 8 +}; + + +int aacplusEncInitSBRAACRam(struct AAC_ENCODER *aacenc) +{ + SBRRam_t *sbr = calloc(1, sizeof(SBRRam_t)); + AACRam_t *aac = calloc(1, sizeof(AACRam_t)); + if(!sbr || !aac) return -1; + + sbr->PsBuf2= &aac->mdctDelayBuffer[BLOCK_SWITCHING_OFFSET]; + /* Overlay PsBuf4 and PsBuf5 with sbr_toncorrBuff of 2nd channel, since SBR only works in mono */ + sbr->PsBuf4 = &sbr->sbr_toncorrBuff[5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; + sbr->PsBuf5 = &sbr->sbr_toncorrBuff[5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS + PS_BUF4_SIZE]; + aacenc->sbr_ram = sbr; + + /* aac_ram.c */ + aac->quantSpec = (short*) sbr->PsBuf3; + aac->expSpec = sbr->sbr_envIBuffer; /* FRAME_LEN_LONG values */ + aac->quantSpecTmp = (short*) &sbr->sbr_envIBuffer[FRAME_LEN_LONG]; + aac->scf= (short*) &sbr->sbr_envIBuffer[2*FRAME_LEN_LONG]; /*[MAX_CHANNELS*MAX_GROUPED_SFB];*/ + aac->maxValueInSfb = (unsigned short*) &sbr->sbr_envIBuffer[2*FRAME_LEN_LONG+MAX_CHANNELS*MAX_GROUPED_SFB]; /* [MAX_CHANNELS*MAX_GROUPED_SFB]; */ + + aacenc->aac_ram = aac; + return 1; +} + +int aacplusEncFreeSBRAACRam(struct AAC_ENCODER *aacenc) +{ + free(aacenc->sbr_ram); + free(aacenc->aac_ram); + return 1; +} + + +aacplusEncHandle aacplusEncOpen(unsigned long sampleRate, + unsigned int numChannels, + unsigned long *inputSamples, + unsigned long *maxOutputBytes) { + + AACPContext *aacp = NULL; + + assert(numChannels <= MAX_CHANNELS); + aacp = calloc(1, sizeof(AACPContext)); + if(!aacp) + return aacp; + + /* set up basic parameters for aacPlus codec */ + AacInitDefaultConfig(&aacp->config); + aacp->config.nChannelsIn = numChannels; + aacp->config.sampleRate = sampleRate; + aacp->writeOffset = INPUT_DELAY*MAX_CHANNELS; + aacplusEncInitSBRAACRam(&aacp->aacEnc); +//#ifdef _FFTW3 + init_plans(&aacp->fftctx); +//#endif + *inputSamples = AACENC_BLOCKSIZE*2 * numChannels; + *maxOutputBytes = (6144/8)*MAX_CHANNELS+ADTS_HEADER_SIZE; + return (aacplusEncHandle ) aacp; +} + + + + +aacplusEncConfiguration *aacplusEncGetCurrentConfiguration(aacplusEncHandle hEncoder) +{ + AACPContext *aacp = (AACPContext *) hEncoder; + if(!aacp) return NULL; + return &aacp->config; +} + + + + + +int aacplusEncSetConfiguration(aacplusEncHandle hEncoder, + aacplusEncConfiguration *cfg) { + AACPContext *aacp = (AACPContext *) hEncoder; + + assert(cfg); + if(cfg != &aacp->config) + memcpy(&aacp->config, cfg, sizeof(aacplusEncConfiguration)); + + int sampleRateAAC = aacp->config.sampleRate; + + if(!aacp->config.nChannelsOut) + aacp->config.nChannelsOut = aacp->config.nChannelsIn; + + if(!aacp->config.bitRate) + return 0; + + if(aacp->config.bandWidth > aacp->config.sampleRate/2) + return 0; + + /* set input samples for not only 1024 framesize */ + aacp->config.inputSamples = aacp->config.nSamplesPerFrame * 2 * aacp->config.nChannelsIn; + + if ( (aacp->config.nChannelsOut == 2) && (aacp->config.bitRate >= 16000) && (aacp->config.bitRate < 44001) ) { + aacp->config.nChannelsOut=1; + aacp->useParametricStereo=1; + + aacp->envReadOffset = (MAX_DS_FILTER_DELAY + INPUT_DELAY)*MAX_CHANNELS; + aacp->coreWriteOffset = CORE_INPUT_OFFSET_PS; + aacp->writeOffset = aacp->envReadOffset; + } else { + /* set up 2:1 downsampling */ + InitIIR21_Resampler(&aacp->IIR21_reSampler[0]); + InitIIR21_Resampler(&aacp->IIR21_reSampler[1]); + + assert(aacp->IIR21_reSampler[0].delay <= MAX_DS_FILTER_DELAY); + aacp->writeOffset += aacp->IIR21_reSampler[0].delay*MAX_CHANNELS; + } + + /* set up SBR configuration */ + if(!IsSbrSettingAvail(aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC, &sampleRateAAC)) { + fprintf(stderr, "libaacplus: bad aac setting: br:%d, AACch:%d, AACsr:%d\n", + aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC); + return 0; + } + + InitializeSbrDefaults (&aacp->sbrConfig); + aacp->sbrConfig.usePs = aacp->useParametricStereo; + + if(!AdjustSbrSettings( &aacp->sbrConfig, aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC, AACENC_TRANS_FAC, 24000)) { + fprintf(stderr, "libaacplus: bad sbr setting: br:%d, AACch:%d, AACsr:%d PS:%d\n", + aacp->config.bitRate, aacp->config.nChannelsOut, sampleRateAAC, aacp->sbrConfig.usePs); + return 0; + } + + if(EnvOpen(aacp->aacEnc.sbr_ram, + &aacp->hEnvEnc, + &aacp->inBuf[aacp->coreWriteOffset], + &aacp->sbrConfig, + &aacp->config.bandWidth) != 0){ + EnvClose (&aacp->hEnvEnc); + fprintf(stderr, "libaacplus: can't open sbr encoder\n"); + return 0; + } + +//#ifdef _FFTW3 + aacp->hEnvEnc.fftctx = &aacp->fftctx; +//#endif + /* set up AAC encoder, now that samling rate is known */ + aacp->config.sampleRate = sampleRateAAC; + if (AacEncOpen( &aacp->aacEnc, &aacp->config) != 0){ + AacEncClose(&aacp->aacEnc); + fprintf(stderr, "libaacplus: can't open aac encoder\n"); + return 0; + } +//#ifdef _FFTW3 + aacp->aacEnc.fftctx = &aacp->fftctx; +//#endif + /* create the ADTS header */ + if(cfg->outputFormat==1) { + aacp->adts = calloc(1, sizeof(ADTSContext_t)); + if(!aacp->adts) { + fprintf(stderr, "libaacplus: can't create adts context\n"); + return 0; + } + adts_hdr_init(aacp->adts, &aacp->config, &aacp->aacEnc.bitStream); + } + return 1; +} + + +int FindSRIndex(int sr) +{ + int i; + for (i = 0; i < 16; i++) { + if (sr == mpeg4audio_sample_rates[i]) + return i; + } + return 16 - 1; +} + +int FindCHIndex(int ch) +{ + int i; + for (i = 0; i < 16; i++) { + if (ch == mpeg4audio_channels[i]) + return i; + } + return 16 - 1; +} + + +/* + +object_type (AOT_AAC_LC) = || 0001 | 0 +sr_idx (6 = 24000) = 011 || 0 +chan_cfg (1 = 1) = 000 | 1 +(specific_config_bitindex = 27 bits) +blablabla = 000 +sync_extension = || 0101 | 0110 || 111 + +object_type (AOT_SBR) = 0 | 0101 +have_new_sr? = || 1 +sr_idx (3 = 48000) = 001 | 1 + +000 || + + + +/////////////////////////// +PS: +101 || 0100 1000 || x... .... || +7 +*/ + + +/* create extradata for aac+ */ +#define AACPLUS_AOT_AAC_LC 2 +#define AACPLUS_AOT_SBR 5 +#define AACPLUS_LOAS_SYNC 0x2b7 +#define AACPLUS_PS_EXT 0x548 + +int aacplusEncGetDecoderSpecificInfo(aacplusEncHandle hEncoder, unsigned char **ppBuffer, + unsigned long *pSizeOfDecoderSpecificInfo){ + AACPContext *aacp = (AACPContext *) hEncoder; + int srate_idx, ch_idx; + int window_size = 0; + int loas_sync = AACPLUS_LOAS_SYNC; + int ps_extension = 0; + uint8_t *extradata = calloc(1, MAX_EXTRADATA_SIZE); + if(!extradata) + return -3; + + if(aacp->useParametricStereo) + ps_extension = AACPLUS_PS_EXT; + + srate_idx = FindSRIndex(aacp->config.sampleRate); + ch_idx = FindCHIndex(aacp->config.nChannelsOut); + if(aacp->config.nSamplesPerFrame != AACENC_BLOCKSIZE) + window_size = 1; + extradata[0] = AACPLUS_AOT_AAC_LC << 3 | srate_idx >> 1; + extradata[1] = srate_idx << 7 | ch_idx << 3 | window_size << 2; + + srate_idx = FindSRIndex(aacp->config.sampleRate * 2); + + extradata[2] = loas_sync >> 3; //sync extension + extradata[3] = (loas_sync << 5) & 0xe0 | AACPLUS_AOT_SBR; //sync extension + sbr hdr + extradata[4] = 1 << 7 | srate_idx << 3 | ps_extension >> 8; + if(ps_extension) { + extradata[5] = ps_extension & 0xff; + extradata[6] = 1 << 7; + *pSizeOfDecoderSpecificInfo = 7; + } else { + *pSizeOfDecoderSpecificInfo = 5; + } + +// fprintf(stderr, "libaacplus: codec config(%d): %02x %02x %02x %02x %02x %02x %02x\n", *pSizeOfDecoderSpecificInfo, +// extradata[0], extradata[1], extradata[2], extradata[3], extradata[4], extradata[5], extradata[6]); + *ppBuffer = extradata; + return 1; +} + + +int aacplusEncEncode(aacplusEncHandle hEncoder, int32_t *inputBuffer, unsigned int samplesInput, + unsigned char *outputBuffer, + unsigned int bufferSize) { + AACPContext *aacp = (AACPContext *) hEncoder; + unsigned int i; + int ch, outSamples=0, numOutBytes = 0; + int adts_offset = 0; + + assert(outputBuffer); + + if(samplesInput > aacp->config.inputSamples) + return -1; + + switch (aacp->config.inputFormat){ + case AACPLUS_INPUT_16BIT: { + int16_t *inbuff = (int16_t *) inputBuffer; + for (i=0; iinBuf[(2/aacp->config.nChannelsIn)*i+aacp->writeOffset+aacp->writtenSamples] = (float) inbuff[i]; + break; + } + case AACPLUS_INPUT_FLOAT: { + float *inbuff = (float *) inputBuffer; + for (i=0; iinBuf[(2/aacp->config.nChannelsIn)*i+aacp->writeOffset+aacp->writtenSamples] = inbuff[i] * SHRT_MAX; + break; + } + default: + return -1; + break; + } + + /* Simple stereo to mono conversion: L = (L+R)/2 */ + if((aacp->config.nChannelsIn == 2) && + (aacp->config.nChannelsOut == 1) && !aacp->useParametricStereo) { + for (i=0; iinBuf[i+aacp->writeOffset+aacp->writtenSamples] = (aacp->inBuf[i+aacp->writeOffset+aacp->writtenSamples] + + aacp->inBuf[i+aacp->writeOffset+aacp->writtenSamples+1])*0.5f; + } + + aacp->writtenSamples+=samplesInput; + + if (aacp->writtenSamples < aacp->config.inputSamples) + return 0; + + if(aacp->adts) adts_offset=ADTS_HEADER_SIZE; + if (bufferSize < (6144/8)*MAX_CHANNELS+adts_offset) + return -1; + + /* encode one SBR frame */ + EnvEncodeFrame( &aacp->hEnvEnc, + &aacp->inBuf[aacp->envReadOffset], + &aacp->inBuf[aacp->coreWriteOffset], + MAX_CHANNELS, + &aacp->numAncDataBytes, + aacp->ancDataBytes); + + /* 2:1 downsampling for AAC core */ + if (!aacp->useParametricStereo) + for( ch=0; chconfig.nChannelsIn; ch++ ) + IIR21_Downsample( &aacp->IIR21_reSampler[ch], + &aacp->inBuf[aacp->writeOffset+ch], + aacp->config.nSamplesPerFrame * 2, //aacp->writtenSamples, + MAX_CHANNELS, + &aacp->inBuf[ch], + &outSamples, + MAX_CHANNELS); + + AacEncEncode( &aacp->aacEnc, + aacp->inBuf, + aacp->useParametricStereo ? 1 : MAX_CHANNELS, /* stride (step) */ + aacp->ancDataBytes, + &aacp->numAncDataBytes, + (unsigned *) (outputBuffer+adts_offset), + &numOutBytes); + if (aacp->useParametricStereo) { + memcpy( aacp->inBuf,&aacp->inBuf[aacp->config.nSamplesPerFrame],CORE_INPUT_OFFSET_PS*sizeof(float)); + } else { + memmove( aacp->inBuf,&aacp->inBuf[aacp->config.nSamplesPerFrame*2*MAX_CHANNELS], + aacp->writeOffset*sizeof(float)); + } + + /* Write one frame of encoded audio */ + if(numOutBytes > 0 && aacp->adts) { + adts_hdr_up(aacp->adts, outputBuffer, numOutBytes); + numOutBytes+=adts_offset; + } + + aacp->writtenSamples=0; + return numOutBytes; +} + + +int aacplusEncClose(aacplusEncHandle hEncoder) { + AACPContext *aacp = (AACPContext *) hEncoder; + + if(!aacp) return 0; + + AacEncClose(&aacp->aacEnc); + EnvClose(&aacp->hEnvEnc); + +//#ifdef _FFTW3 + destroy_plans(&aacp->fftctx); +//#endif + + aacplusEncFreeSBRAACRam(&aacp->aacEnc); + if(aacp->adts) + free(aacp->adts); + + free(aacp); + return 1; +} diff --git a/src/aacplusenc.h b/src/aacplusenc.h new file mode 100644 index 0000000..aeb80bb --- /dev/null +++ b/src/aacplusenc.h @@ -0,0 +1,166 @@ +/* + * aacplusenc.h + * + * Created on: 7 окт. 2010 + * Author: tipok + */ + +#ifndef AACPLUSENC_H_ +#define AACPLUSENC_H_ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +/*-------------------------- defines --------------------------------------*/ +/* here we distinguish between stereo and the mono only encoder */ +#ifdef MONO_ONLY +#define MAX_CHANNELS 1 +#else +#define MAX_CHANNELS 2 +#endif + +#define AACENC_BLOCKSIZE 1024 /*! encoder only takes BLOCKSIZE samples at a time */ +#define AACENC_TRANS_FAC 8 /*! encoder short long ratio */ +#define AACENC_PCM_LEVEL 1.0 /*! encoder pcm 0db refernence */ + +#define MAX_EXTRADATA_SIZE 7 /* LC + SBR + PS config */ +#define BUFFERSIZE 1024 /* anc data */ + +#include "aacplus.h" + +#include "minmax.h" +#include "sbr_def.h" + + +#include "psy_const.h" +#include "cfftn.h" +#include "hybrid.h" +#include "sbr_ram.h" + +#include "sbr_main.h" +#include "fram_gen.h" +#include "tran_det.h" +#include "code_env.h" + +#include "qmf_enc.h" +#include "env_est.h" +#include "mh_det.h" +#include "nf_est.h" +#include "invf_est.h" +#include "ton_corr.h" + + +#include "tns.h" +#include "sbr.h" + +#include "aac_ram.h" +#include "tns_param.h" +#include "aac_rom.h" + +#include "dyn_bits.h" +#include "adj_thr_data.h" +#include "qc_data.h" +#include "block_switch.h" +#include "psy_data.h" +#include "interface.h" +#include "psy_configuration.h" +#include "psy_main.h" +#include "FFR_bitbuffer.h" +#include "bitenc.h" +#include "stprepro.h" +#include "aacenc.h" + +#include "adj_thr.h" +#include "adts.h" +#include "band_nrg.h" +#include "bit_cnt.h" +#include "bit_sbr.h" +#include "channel_map.h" +#include "env_bit.h" +#include "FloatFR.h" +#include "freq_sca.h" +#include "grp_data.h" + +#include "line_pe.h" +#include "ms_stereo.h" +#include "pre_echo_control.h" +#include "ps_bitenc.h" +#include "ps_enc.h" +#include "cmondata.h" + +#include "qc_main.h" +#include "quantize.h" +#include "resampler.h" +#include "sbr_misc.h" +#include "sbr_rom.h" +#include "sf_estim.h" +#include "spreading.h" +#include "stat_bits.h" +#include "tns_func.h" +#include "transform.h" + + +struct SBR_ENCODER +{ + FFTWFContext_t *fftctx; + struct SBR_CONFIG_DATA sbrConfigData; + struct SBR_HEADER_DATA sbrHeaderData; + struct SBR_BITSTREAM_DATA sbrBitstreamData; + struct ENV_CHANNEL* hEnvChannel[MAX_CHANNELS]; + struct COMMON_DATA CmonData; + struct PS_ENC *hPsEnc; + SBR_QMF_FILTER_BANK *hSynthesisQmfBank; + unsigned int sbrPayloadPrevious[MAX_PAYLOAD_SIZE/(sizeof(int))]; + unsigned int sbrPayload[MAX_PAYLOAD_SIZE/(sizeof(int))]; + int sbrPayloadSize; +} ; + + +#define CORE_DELAY (1600) +/* (96-64) makes AAC still some 64 core samples too early wrt SBR ... maybe -32 would be even more correct, but 1024-32 would need additional SBR bitstream delay by one frame */ +#define CORE_INPUT_OFFSET_PS (0) +/* ((1600 (core codec)*2 (multi rate) + 6*64 (sbr dec delay) - 2048 (sbr enc delay) + magic*/ +#define INPUT_DELAY ((CORE_DELAY)*2 +6*64-(AACENC_BLOCKSIZE*2)+1) +/* the additional max resampler filter delay (source fs)*/ +#define MAX_DS_FILTER_DELAY 16 + +typedef struct { + /* adts stuff */ + ADTSContext_t *adts; + + /* AAC encoder instance for one encoder */ + aacplusEncConfiguration config; + struct AAC_ENCODER aacEnc; + + sbrConfiguration sbrConfig; + struct SBR_ENCODER hEnvEnc; + SBR_QMF_FILTER_BANK SynthesisQmfBank; + struct PS_ENC psEncoder; + + /* 2x => 1x samplerate converter instance */ + IIR21_RESAMPLER IIR21_reSampler[MAX_CHANNELS]; +//#ifdef _FFTW3 + FFTWFContext_t fftctx; +//#endif + float inBuf[(AACENC_BLOCKSIZE*2 + MAX_DS_FILTER_DELAY + INPUT_DELAY)*MAX_CHANNELS]; + //char outBuf[(6144/8)*MAX_CHANNELS+ADTS_HEADER_SIZE]; + + + unsigned int numAncDataBytes; + unsigned char ancDataBytes[MAX_PAYLOAD_SIZE]; + + + int useParametricStereo; + unsigned int inSamples; + unsigned int writtenSamples; + unsigned int writeOffset; + int envReadOffset; + int coreWriteOffset; + +} AACPContext; + +int FindSRIndex(int sr); + +#endif /* AACPLUSENC_H_ */ diff --git a/src/adts.c b/src/adts.c new file mode 100644 index 0000000..0785810 --- /dev/null +++ b/src/adts.c @@ -0,0 +1,70 @@ +/* + adts + + Original work by Matteo Croce + Small changes and fixes by Rafael Diniz + + Copyright (C) Matteo Croce and Rafael Diniz + */ +#include + +#include "aacplusenc.h" + +void adts_hdr_init(ADTSContext_t *ctx, aacplusEncConfiguration *config, HANDLE_BIT_BUF bitBuffer) +{ + ctx->adts_size = ADTS_HEADER_SIZE; + int mpeg_id = ADTS_MPEG_ID; + int profile = ADTS_MPEG_PROFILE; + int srate_idx = FindSRIndex(config->sampleRate); + + ctx->bitBuffer = bitBuffer; + /* adts use only 1024 samples window */ + assert(config->nSamplesPerFrame == AACENC_BLOCKSIZE); + + /* SOURCE: http://blog.olivierlanglois.net/index.php/2008/09/12/aac_adts_header_buffer_fullness_field */ + unsigned short min_dec_in_size = (6144*config->nChannelsOut); + ctx->mean_framelength = (unsigned short)((float) config->bitRate/config->sampleRate*1024); + ctx->max_bit_reservoir = min_dec_in_size - ctx->mean_framelength; + ctx->frl_divider = 32*config->nChannelsOut; + + memset(ctx->const_hdr, 0, 4); + ctx->const_hdr[0] = 0xFF; /* 8bits: syncword */ + ctx->const_hdr[1] = 0xF0; /* 4bits: syncword */ + ctx->const_hdr[1] |= mpeg_id << 3; /* 1bit: mpeg id = 0 */ + /* 2bits: layer = 00 */ + ctx->const_hdr[1] |= 1; /* 1bit: protection absent (1 - means "no protection")*/ + ctx->const_hdr[2] = ((profile << 6) & 0xC0); /* 2bits: profile */ + ctx->const_hdr[2] |= ((srate_idx << 2) & 0x3C); /* 4b: sampling_frequency_index */ + /* 1b: private = 0 */ + ctx->const_hdr[2] |= ((config->nChannelsOut >> 2) & 0x1); /* 1b: channel_configuration */ + ctx->const_hdr[3] = ((config->nChannelsOut << 6) & 0xC0); /* 2b: channel_configuration */ + +} + +void adts_hdr_up(ADTSContext_t *ctx, char *buff, int size) +{ + unsigned short len = size + ADTS_HEADER_SIZE; + unsigned short buffer_fullness = 0x07FF; + + memcpy(buff, ctx->const_hdr, 4); + +//#ifdef ENABLE_BIT_RESERVOIR + ctx->bit_reservoir_state += ctx->mean_framelength - GetBitsAvail(ctx->bitBuffer); + if (ctx->bit_reservoir_state < 0) { + ctx->bit_reservoir_state = 0; + } else if (ctx->bit_reservoir_state > ctx->max_bit_reservoir) { + ctx->bit_reservoir_state = ctx->max_bit_reservoir; + } + buffer_fullness = ctx->bit_reservoir_state/ctx->frl_divider; +//#endif + + /* frame length, 13 bits */ + buff[3] &= 0xFC; + buff[3] |= ((len >> 11) & 0x03); /* 2b: aac_frame_length */ + buff[4] = len >> 3; /* 8b: aac_frame_length */ + buff[5] = (len << 5) & 0xE0; /* 3b: aac_frame_length */ + /* buffer fullness, 11 bits */ + buff[5] |= ((buffer_fullness >> 6) & 0x1F); /* 5b: adts_buffer_fullness */ + buff[6] = (buffer_fullness << 2) & 0xFC; /* 6b: adts_buffer_fullness */ + /* 2b: num_raw_data_blocks */ +} diff --git a/src/adts.h b/src/adts.h new file mode 100644 index 0000000..5719028 --- /dev/null +++ b/src/adts.h @@ -0,0 +1,33 @@ +/* + adts + + Original work by Matteo Croce + Small changes and fixes by Rafael Diniz + + Copyright (C) Matteo Croce and Rafael Diniz + */ +#ifndef adts_h_ +#define adts_h_ + +#include +#include "aacplusenc.h" + +#define ADTS_HEADER_SIZE 7 +#define ADTS_MPEG_ID 1 /* 0: MPEG-4, 1: MPEG-2 */ +#define ADTS_MPEG_PROFILE 1 + +typedef struct { + HANDLE_BIT_BUF bitBuffer; + uint8_t const_hdr[4]; + int bit_reservoir_state; + unsigned short mean_framelength; + unsigned short frl_divider; + unsigned short max_bit_reservoir; + int adts_size; + int window_size; +} ADTSContext_t; + +void adts_hdr_init(ADTSContext_t *ctx, aacplusEncConfiguration *config, HANDLE_BIT_BUF bitBuffer); +void adts_hdr_up(ADTSContext_t *ctx, char *buff, int size); + +#endif diff --git a/src/libaacplus.sym b/src/libaacplus.sym new file mode 100644 index 0000000..176d7e5 --- /dev/null +++ b/src/libaacplus.sym @@ -0,0 +1,6 @@ +aacplusEncGetCurrentConfiguration +aacplusEncSetConfiguration +aacplusEncOpen +aacplusEncGetDecoderSpecificInfo +aacplusEncEncode +aacplusEncClose diff --git a/src/sbr_ram.h b/src/sbr_ram.h new file mode 100644 index 0000000..727f731 --- /dev/null +++ b/src/sbr_ram.h @@ -0,0 +1,123 @@ +/* + * sbr_ram.h + * + * Created on: 7 окт. 2010 + * Author: tipok + */ + +#ifndef SBR_RAM_H_ +#define SBR_RAM_H_ + +#include +#include + +#define PS_BUF4_SIZE (4*(QMF_TIME_SLOTS + QMF_BUFFER_MOVE) + 4*(NO_QMF_BANDS_IN_HYBRID + NO_QMF_BANDS_IN_HYBRID*QMF_BUFFER_MOVE)) +#define PS_BUF5_SIZE (QMF_FILTER_LENGTH/2 + QMF_CHANNELS) + +typedef struct { + /* sbr_ram.c */ + /* Overlay with mdctDelayBuffer of 2nd channel since AAC only works in mono */ + float *PsBuf2; + /* Overlay PsBuf4 and PsBuf5 with sbr_toncorrBuff of 2nd channel, since SBR only works in mono */ + float *PsBuf4; + float *PsBuf5; + float PsBuf3[MAX_CHANNELS*FRAME_LEN_LONG*sizeof(short)/sizeof(float)]; + /*! + \name StaticSbrData + + Static memory areas, must not be overwritten in other sections of the encoder + */ + /*! Filter states for QMF-analysis.
+ Dimension: #MAXNRSBRCHANNELS * #SBR_QMF_FILTER_LENGTH */ + float sbr_QmfStatesAnalysis[MAX_CHANNELS * QMF_FILTER_LENGTH]; + /*! Energy buffer for envelope extraction
+ Dimension #MAXNRSBRCHANNELS * +#SBR_QMF_SLOTS*2 * #SBR_QMF_CHANNELS + */ + float sbr_envYBuffer[MAX_CHANNELS * QMF_TIME_SLOTS * QMF_CHANNELS]; + /*! Matrix holding the quota values for all estimates, all channels + Dimension #MAXNRSBRCHANNELS * +#SBR_QMF_CHANNELS* #NO_OF_ESTIMATES + */ + float sbr_quotaMatrix[MAX_CHANNELS * NO_OF_ESTIMATES*QMF_CHANNELS]; + /*! Thresholds for transient detection
+ Dimension #MAXNRSBRCHANNELS * #SBR_QMF_CHANNELS + */ + float sbr_thresholds[MAX_CHANNELS *QMF_CHANNELS]; + /*! Frequency band table (low res)
+ Dimension #MAX_FREQ_COEFFS/2+1 + */ + unsigned char sbr_freqBandTableLO[MAX_FREQ_COEFFS/2+1]; + /*! Frequency band table (high res)
+ Dimension #MAX_FREQ_COEFFS +1 + */ + unsigned char sbr_freqBandTableHI[MAX_FREQ_COEFFS+1]; + /*! vk matser table
+ Dimension #MAX_FREQ_COEFFS +1 + */ + unsigned char sbr_v_k_master[MAX_FREQ_COEFFS +1]; + /* + Missing harmonics detection + */ + /*! sbr_detectionVectors
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + */ + unsigned char sbr_detectionVectors[MAX_CHANNELS*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; + /*! + The following tonality correclation buffers are allocated in + one non-reusable buffer + sbr_tonalityDiff
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + sbr_sfmOrig
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + sbr_sfmSbr
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + sbr_guideVectorDiff
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + sbr_guideVectorOrig
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + */ + /* To overlay 2nd half of sbr_toncorrBuff with PS-Buffers, the 2nd half + must not fall below a minium size */ + float sbr_toncorrBuff[max( /* two channels or... */ + (MAX_CHANNELS*5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS), + ( + /* 1st half */ + (5*NO_OF_ESTIMATES*MAX_FREQ_COEFFS)+ + PS_BUF4_SIZE + PS_BUF5_SIZE + ) + )]; + /*! sbr_prevCompVec[
+ Dimension #MAX_CHANNELS*#MAX_FREQ_COEFFS] + */ + char sbr_prevEnvelopeCompensation[MAX_CHANNELS*MAX_FREQ_COEFFS]; + /*! sbr_guideScfb[
+ Dimension #MAX_CHANNELS*#MAX_FREQ_COEFFS] + */ + unsigned char sbr_guideScfb[MAX_CHANNELS*MAX_FREQ_COEFFS]; + /*! sbr_guideVectorDiff
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + */ + /*! sbr_guideVectorDetected
+ Dimension #MAX_CHANNELS*#NO_OF_ESTIMATES*#MAX_FREQ_COEFFS] + */ + unsigned char sbr_guideVectorDetected[MAX_CHANNELS*NO_OF_ESTIMATES*MAX_FREQ_COEFFS]; + /*! + \name DynamicSbrData + + Dynamic memory areas, might be reused in other algorithm sections, + e.g. the core decoder + */ + /*! Real buffer for envelope extraction
+ Dimension #SBR_QMF_SLOTS * #SBR_QMF_CHANNELS + */ + float sbr_envRBuffer [MAX_CHANNELS * QMF_TIME_SLOTS * QMF_CHANNELS]; + /*! Imag buffer for envelope extraction
+ Dimension #SBR_QMF_SLOTS * #SBR_QMF_CHANNELS + */ + float sbr_envIBuffer [MAX_CHANNELS * QMF_TIME_SLOTS * QMF_CHANNELS]; + /*! Transients for transient detection
+ Dimension MAX_CHANNELS*3* #QMF_TIME_SLOTS + */ + float sbr_transients[MAX_CHANNELS*3*QMF_TIME_SLOTS]; +} SBRRam_t; + +#endif /* SBR_RAM_H_ */