aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore29
-rw-r--r--ChangeLog48
-rw-r--r--Makefile.am296
-rw-r--r--Makefile.vc323
-rw-r--r--aac-enc.c237
-rwxr-xr-xautogen.sh2
-rw-r--r--configure.ac38
-rw-r--r--fdk-aac.pc.in11
-rw-r--r--fdk-aac.sym18
-rw-r--r--libAACdec/include/aacdecoder_lib.h5
-rw-r--r--libAACdec/src/aacdecoder_lib.cpp2
-rw-r--r--libAACdec/src/usacdec_acelp.cpp4
-rw-r--r--libAACdec/src/usacdec_rom.cpp2
-rw-r--r--libAACdec/src/usacdec_rom.h2
-rw-r--r--libAACenc/include/aacenc_lib.h4
-rw-r--r--libAACenc/src/aacenc.h5
-rw-r--r--libAACenc/src/aacenc_lib.cpp2
-rw-r--r--libAACenc/src/intensity.cpp4
-rw-r--r--libAACenc/src/metadata_main.cpp15
-rw-r--r--libFDK/include/FDK_archdef.h17
-rw-r--r--libFDK/include/clz.h3
-rw-r--r--libFDK/include/common_fix.h4
-rw-r--r--libFDK/include/fft.h4
-rw-r--r--libFDK/include/fixmul.h3
-rw-r--r--libFDK/include/mips/cplx_mul_mips.h47
-rw-r--r--libFDK/include/ppc/clz_ppc.h102
-rw-r--r--libFDK/include/ppc/fixmul_ppc.h115
-rw-r--r--libMpegTPDec/src/tpdec_adts.cpp3
-rw-r--r--libSBRdec/src/hbe.cpp6
-rw-r--r--libSBRdec/src/psdec.cpp26
-rw-r--r--libSYS/include/syslib_channelMapDescr.h6
-rw-r--r--libSYS/src/syslib_channelMapDescr.cpp31
-rw-r--r--m4/.gitkeep0
-rw-r--r--wavreader.c193
-rw-r--r--wavreader.h37
-rw-r--r--win32/getopt.h904
36 files changed, 2472 insertions, 76 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..263e5aa
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,29 @@
+*.o
+*.lo
+*.la
+.deps
+.libs
+.dirstamp
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache
+configure
+fdk-aac.pc
+config.guess
+config.log
+config.status
+config.sub
+depcomp
+install-sh
+libtool
+ltmain.sh
+m4/libtool.m4
+m4/ltoptions.m4
+m4/ltsugar.m4
+m4/ltversion.m4
+m4/lt~obsolete.m4
+missing
+stamp-h1
+aac-enc
+compile
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..2675878
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,48 @@
+2.0.0
+ - Major update in the upstream source base, with support for new
+ profiles and features, and numerous crash/fuzz fixes. The new
+ upstream version is referred to as FDKv2, thus skipping the
+ major version 1 and syncing the fdk-aac major version number to 2.
+
+0.1.6
+ - Lots of minor assorted crash/fuzz fixes, mostly for the decoder but
+ also some for the encoder
+
+0.1.5
+ - Updated upstream sources
+ - Fixed building with GCC 3.3 and 3.4
+ - Fixed building with GCC 6
+ - AArch64 optimizations
+ - Makefiles for building with MSVC
+ - Support building the code in C++11 mode
+
+0.1.4
+ - Updated upstream sources, with minor changes to the decoder API
+ breaking the ABI. (Calling code using AUDIO_CHANNEL_TYPE may need to
+ be updated. A new option AAC_PCM_LIMITER_ENABLE has been added, enabled
+ by default, which incurs extra decoding delay.)
+ - PowerPC optimizations, fixes for building on AIX
+ - Support for reading streamed wav files in the encoder example
+ - Fix VBR encoding of sample rates over 64 kHz
+
+0.1.3
+ - Updated upstream sources, with a number of crash fixes and new features
+ (including support for encoding 7.1)
+
+0.1.2
+ - Fix a few more crashes
+ - Include dependency libs (such as -lm) in the pkg-config file
+
+0.1.1
+ - Updated to a new upstream version from Android 4.2, fixing a lot of crashes
+ - Cleanup of autotools usage
+ - Make sure the shared library links to libm if necessary
+ - Performance improvements on x86
+ - Added support for WG4/DVD audio channel mappings
+ - Minimized the differences to upstream
+ - Added an example encoder tool
+
+0.1.0
+ - Initial release of fdk-aac
+ - autotools based build system
+ - Enable setting VBR bitrate modes
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..fe6b867
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,296 @@
+ACLOCAL_AMFLAGS = -I m4
+AUTOMAKE_OPTIONS = subdir-objects
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/libAACdec/include \
+ -I$(top_srcdir)/libAACenc/include \
+ -I$(top_srcdir)/libArithCoding/include \
+ -I$(top_srcdir)/libDRCdec/include \
+ -I$(top_srcdir)/libSACdec/include \
+ -I$(top_srcdir)/libSACenc/include \
+ -I$(top_srcdir)/libSBRdec/include \
+ -I$(top_srcdir)/libSBRenc/include \
+ -I$(top_srcdir)/libMpegTPDec/include \
+ -I$(top_srcdir)/libMpegTPEnc/include \
+ -I$(top_srcdir)/libSYS/include \
+ -I$(top_srcdir)/libFDK/include \
+ -I$(top_srcdir)/libPCMutils/include
+
+AM_CXXFLAGS = -fno-exceptions -fno-rtti
+libfdk_aac_la_LINK = $(LINK) $(libfdk_aac_la_LDFLAGS)
+# Mention a dummy pure C file to trigger generation of the $(LINK) variable
+nodist_EXTRA_libfdk_aac_la_SOURCES = dummy.c
+
+fdk_aacincludedir = $(includedir)/fdk-aac
+fdk_aacinclude_HEADERS = \
+ $(top_srcdir)/libSYS/include/machine_type.h \
+ $(top_srcdir)/libSYS/include/genericStds.h \
+ $(top_srcdir)/libSYS/include/FDK_audio.h \
+ $(top_srcdir)/libSYS/include/syslib_channelMapDescr.h \
+ $(top_srcdir)/libAACenc/include/aacenc_lib.h \
+ $(top_srcdir)/libAACdec/include/aacdecoder_lib.h
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = fdk-aac.pc
+
+lib_LTLIBRARIES = libfdk-aac.la
+
+libfdk_aac_la_LDFLAGS = -version-info @FDK_AAC_VERSION@ -no-undefined \
+ -export-symbols $(top_srcdir)/fdk-aac.sym
+
+if EXAMPLE
+bin_PROGRAMS = aac-enc$(EXEEXT)
+
+aac_enc_LDADD = libfdk-aac.la
+aac_enc_SOURCES = aac-enc.c wavreader.c
+
+noinst_HEADERS = wavreader.h
+endif
+
+AACDEC_SRC = \
+ libAACdec/src/FDK_delay.cpp \
+ libAACdec/src/aac_ram.cpp \
+ libAACdec/src/aac_rom.cpp \
+ libAACdec/src/aacdec_drc.cpp \
+ libAACdec/src/aacdec_hcr.cpp \
+ libAACdec/src/aacdec_hcr_bit.cpp \
+ libAACdec/src/aacdec_hcrs.cpp \
+ libAACdec/src/aacdec_pns.cpp \
+ libAACdec/src/aacdec_tns.cpp \
+ libAACdec/src/aacdecoder.cpp \
+ libAACdec/src/aacdecoder_lib.cpp \
+ libAACdec/src/block.cpp \
+ libAACdec/src/channel.cpp \
+ libAACdec/src/channelinfo.cpp \
+ libAACdec/src/conceal.cpp \
+ libAACdec/src/ldfiltbank.cpp \
+ libAACdec/src/pulsedata.cpp \
+ libAACdec/src/rvlc.cpp \
+ libAACdec/src/rvlcbit.cpp \
+ libAACdec/src/rvlcconceal.cpp \
+ libAACdec/src/stereo.cpp \
+ libAACdec/src/usacdec_ace_d4t64.cpp \
+ libAACdec/src/usacdec_ace_ltp.cpp \
+ libAACdec/src/usacdec_acelp.cpp \
+ libAACdec/src/usacdec_fac.cpp \
+ libAACdec/src/usacdec_lpc.cpp \
+ libAACdec/src/usacdec_lpd.cpp \
+ libAACdec/src/usacdec_rom.cpp
+
+AACENC_SRC = \
+ libAACenc/src/aacEnc_ram.cpp \
+ libAACenc/src/aacEnc_rom.cpp \
+ libAACenc/src/aacenc.cpp \
+ libAACenc/src/aacenc_lib.cpp \
+ libAACenc/src/aacenc_pns.cpp \
+ libAACenc/src/aacenc_tns.cpp \
+ libAACenc/src/adj_thr.cpp \
+ libAACenc/src/band_nrg.cpp \
+ libAACenc/src/bandwidth.cpp \
+ libAACenc/src/bit_cnt.cpp \
+ libAACenc/src/bitenc.cpp \
+ libAACenc/src/block_switch.cpp \
+ libAACenc/src/channel_map.cpp \
+ libAACenc/src/chaosmeasure.cpp \
+ libAACenc/src/dyn_bits.cpp \
+ libAACenc/src/grp_data.cpp \
+ libAACenc/src/intensity.cpp \
+ libAACenc/src/line_pe.cpp \
+ libAACenc/src/metadata_compressor.cpp \
+ libAACenc/src/metadata_main.cpp \
+ libAACenc/src/mps_main.cpp \
+ libAACenc/src/ms_stereo.cpp \
+ libAACenc/src/noisedet.cpp \
+ libAACenc/src/pnsparam.cpp \
+ libAACenc/src/pre_echo_control.cpp \
+ libAACenc/src/psy_configuration.cpp \
+ libAACenc/src/psy_main.cpp \
+ libAACenc/src/qc_main.cpp \
+ libAACenc/src/quantize.cpp \
+ libAACenc/src/sf_estim.cpp \
+ libAACenc/src/spreading.cpp \
+ libAACenc/src/tonality.cpp \
+ libAACenc/src/transform.cpp
+
+ARITHCODING_SRC = \
+ libArithCoding/src/ac_arith_coder.cpp
+
+DRCDEC_SRC = \
+ libDRCdec/src/FDK_drcDecLib.cpp \
+ libDRCdec/src/drcDec_gainDecoder.cpp \
+ libDRCdec/src/drcDec_reader.cpp \
+ libDRCdec/src/drcDec_rom.cpp \
+ libDRCdec/src/drcDec_selectionProcess.cpp \
+ libDRCdec/src/drcDec_tools.cpp \
+ libDRCdec/src/drcGainDec_init.cpp \
+ libDRCdec/src/drcGainDec_preprocess.cpp \
+ libDRCdec/src/drcGainDec_process.cpp
+
+FDK_SRC = \
+ libFDK/src/FDK_bitbuffer.cpp \
+ libFDK/src/FDK_core.cpp \
+ libFDK/src/FDK_crc.cpp \
+ libFDK/src/FDK_decorrelate.cpp \
+ libFDK/src/FDK_hybrid.cpp \
+ libFDK/src/FDK_lpc.cpp \
+ libFDK/src/FDK_matrixCalloc.cpp \
+ libFDK/src/FDK_qmf_domain.cpp \
+ libFDK/src/FDK_tools_rom.cpp \
+ libFDK/src/FDK_trigFcts.cpp \
+ libFDK/src/autocorr2nd.cpp \
+ libFDK/src/dct.cpp \
+ libFDK/src/fft.cpp \
+ libFDK/src/fft_rad2.cpp \
+ libFDK/src/fixpoint_math.cpp \
+ libFDK/src/huff_nodes.cpp \
+ libFDK/src/mdct.cpp \
+ libFDK/src/nlc_dec.cpp \
+ libFDK/src/qmf.cpp \
+ libFDK/src/scale.cpp
+
+MPEGTPDEC_SRC = \
+ libMpegTPDec/src/tpdec_adif.cpp \
+ libMpegTPDec/src/tpdec_adts.cpp \
+ libMpegTPDec/src/tpdec_asc.cpp \
+ libMpegTPDec/src/tpdec_drm.cpp \
+ libMpegTPDec/src/tpdec_latm.cpp \
+ libMpegTPDec/src/tpdec_lib.cpp
+
+MPEGTPENC_SRC = \
+ libMpegTPEnc/src/tpenc_adif.cpp \
+ libMpegTPEnc/src/tpenc_adts.cpp \
+ libMpegTPEnc/src/tpenc_asc.cpp \
+ libMpegTPEnc/src/tpenc_latm.cpp \
+ libMpegTPEnc/src/tpenc_lib.cpp
+
+PCMUTILS_SRC = \
+ libPCMutils/src/limiter.cpp \
+ libPCMutils/src/pcm_utils.cpp \
+ libPCMutils/src/pcmdmx_lib.cpp
+
+SACDEC_SRC = \
+ libSACdec/src/sac_bitdec.cpp \
+ libSACdec/src/sac_calcM1andM2.cpp \
+ libSACdec/src/sac_dec.cpp \
+ libSACdec/src/sac_dec_conceal.cpp \
+ libSACdec/src/sac_dec_lib.cpp \
+ libSACdec/src/sac_process.cpp \
+ libSACdec/src/sac_qmf.cpp \
+ libSACdec/src/sac_reshapeBBEnv.cpp \
+ libSACdec/src/sac_rom.cpp \
+ libSACdec/src/sac_smoothing.cpp \
+ libSACdec/src/sac_stp.cpp \
+ libSACdec/src/sac_tsd.cpp
+
+SACENC_SRC = \
+ libSACenc/src/sacenc_bitstream.cpp \
+ libSACenc/src/sacenc_delay.cpp \
+ libSACenc/src/sacenc_dmx_tdom_enh.cpp \
+ libSACenc/src/sacenc_filter.cpp \
+ libSACenc/src/sacenc_framewindowing.cpp \
+ libSACenc/src/sacenc_huff_tab.cpp \
+ libSACenc/src/sacenc_lib.cpp \
+ libSACenc/src/sacenc_nlc_enc.cpp \
+ libSACenc/src/sacenc_onsetdetect.cpp \
+ libSACenc/src/sacenc_paramextract.cpp \
+ libSACenc/src/sacenc_staticgain.cpp \
+ libSACenc/src/sacenc_tree.cpp \
+ libSACenc/src/sacenc_vectorfunctions.cpp
+
+SBRDEC_SRC = \
+ libSBRdec/src/HFgen_preFlat.cpp \
+ libSBRdec/src/env_calc.cpp \
+ libSBRdec/src/env_dec.cpp \
+ libSBRdec/src/env_extr.cpp \
+ libSBRdec/src/hbe.cpp \
+ libSBRdec/src/huff_dec.cpp \
+ libSBRdec/src/lpp_tran.cpp \
+ libSBRdec/src/psbitdec.cpp \
+ libSBRdec/src/psdec.cpp \
+ libSBRdec/src/psdec_drm.cpp \
+ libSBRdec/src/psdecrom_drm.cpp \
+ libSBRdec/src/pvc_dec.cpp \
+ libSBRdec/src/sbr_crc.cpp \
+ libSBRdec/src/sbr_deb.cpp \
+ libSBRdec/src/sbr_dec.cpp \
+ libSBRdec/src/sbr_ram.cpp \
+ libSBRdec/src/sbr_rom.cpp \
+ libSBRdec/src/sbrdec_drc.cpp \
+ libSBRdec/src/sbrdec_freq_sca.cpp \
+ libSBRdec/src/sbrdecoder.cpp
+
+SBRENC_SRC = \
+ libSBRenc/src/bit_sbr.cpp \
+ libSBRenc/src/code_env.cpp \
+ libSBRenc/src/env_bit.cpp \
+ libSBRenc/src/env_est.cpp \
+ libSBRenc/src/fram_gen.cpp \
+ libSBRenc/src/invf_est.cpp \
+ libSBRenc/src/mh_det.cpp \
+ libSBRenc/src/nf_est.cpp \
+ libSBRenc/src/ps_bitenc.cpp \
+ libSBRenc/src/ps_encode.cpp \
+ libSBRenc/src/ps_main.cpp \
+ libSBRenc/src/resampler.cpp \
+ libSBRenc/src/sbr_encoder.cpp \
+ libSBRenc/src/sbr_misc.cpp \
+ libSBRenc/src/sbrenc_freq_sca.cpp \
+ libSBRenc/src/sbrenc_ram.cpp \
+ libSBRenc/src/sbrenc_rom.cpp \
+ libSBRenc/src/ton_corr.cpp \
+ libSBRenc/src/tran_det.cpp
+
+SYS_SRC = \
+ libSYS/src/genericStds.cpp \
+ libSYS/src/syslib_channelMapDescr.cpp
+
+libfdk_aac_la_SOURCES = \
+ $(AACDEC_SRC) $(AACENC_SRC) \
+ $(ARITHCODING_SRC) \
+ $(DRCDEC_SRC) \
+ $(MPEGTPDEC_SRC) $(MPEGTPENC_SRC) \
+ $(SACDEC_SRC) $(SACENC_SRC) \
+ $(SBRDEC_SRC) $(SBRENC_SRC) \
+ $(PCMUTILS_SRC) $(FDK_SRC) $(SYS_SRC)
+
+EXTRA_DIST = \
+ $(top_srcdir)/.clang-format \
+ $(top_srcdir)/autogen.sh \
+ $(top_srcdir)/MODULE_LICENSE_FRAUNHOFER \
+ $(top_srcdir)/NOTICE \
+ $(top_srcdir)/OWNERS \
+ $(top_srcdir)/Android.bp \
+ $(top_srcdir)/fdk-aac.sym \
+ $(top_srcdir)/Makefile.vc \
+ $(top_srcdir)/documentation/*.pdf \
+ $(top_srcdir)/libAACdec/src/*.h \
+ $(top_srcdir)/libAACdec/src/arm/*.cpp \
+ $(top_srcdir)/libAACenc/src/*.h \
+ $(top_srcdir)/libArithCoding/include/*.h \
+ $(top_srcdir)/libDRCdec/include/*.h \
+ $(top_srcdir)/libDRCdec/src/*.h \
+ $(top_srcdir)/libSACdec/include/*.h \
+ $(top_srcdir)/libSACdec/src/*.h \
+ $(top_srcdir)/libSACenc/include/*.h \
+ $(top_srcdir)/libSACenc/src/*.h \
+ $(top_srcdir)/libSBRenc/src/*.h \
+ $(top_srcdir)/libSBRenc/include/*.h \
+ $(top_srcdir)/libSBRdec/src/*.h \
+ $(top_srcdir)/libSBRdec/src/arm/*.cpp \
+ $(top_srcdir)/libSBRdec/include/*.h \
+ $(top_srcdir)/libSYS/include/*.h \
+ $(top_srcdir)/libPCMutils/include/*.h \
+ $(top_srcdir)/libPCMutils/src/*.h \
+ $(top_srcdir)/libMpegTPEnc/include/*.h \
+ $(top_srcdir)/libMpegTPEnc/src/*.h \
+ $(top_srcdir)/libMpegTPDec/include/*.h \
+ $(top_srcdir)/libMpegTPDec/src/*.h \
+ $(top_srcdir)/libFDK/include/*.h \
+ $(top_srcdir)/libFDK/include/arm/*.h \
+ $(top_srcdir)/libFDK/include/mips/*.h \
+ $(top_srcdir)/libFDK/include/ppc/*.h \
+ $(top_srcdir)/libFDK/include/x86/*.h \
+ $(top_srcdir)/libFDK/src/arm/*.cpp \
+ $(top_srcdir)/libFDK/src/mips/*.cpp \
+ $(top_srcdir)/win32/*.h
+
diff --git a/Makefile.vc b/Makefile.vc
new file mode 100644
index 0000000..b37c483
--- /dev/null
+++ b/Makefile.vc
@@ -0,0 +1,323 @@
+#
+# Options:
+# prefix=\path\to\install
+#
+# Compiling: nmake -f Makefile.vc
+# Installing: nmake -f Makefile.vc prefix=\path\to\x install
+#
+
+VERSION=0.1.5
+
+# Linker and librarian commands
+LD = link
+AR = lib
+
+!IFDEF HOME
+# In case we are using a cross compiler shell.
+MKDIR_FLAGS = -p
+!ENDIF
+
+AM_CPPFLAGS = \
+ -Iwin32 \
+ -IlibAACdec/include \
+ -IlibAACenc/include \
+ -IlibArithCoding/include \
+ -IlibDRCdec/include \
+ -IlibSACdec/include \
+ -IlibSACenc/include \
+ -IlibSBRdec/include \
+ -IlibSBRenc/include \
+ -IlibMpegTPDec/include \
+ -IlibMpegTPEnc/include \
+ -IlibSYS/include \
+ -IlibFDK/include \
+ -IlibPCMutils/include
+
+AACDEC_SRC = \
+ libAACdec/src/FDK_delay.cpp \
+ libAACdec/src/aac_ram.cpp \
+ libAACdec/src/aac_rom.cpp \
+ libAACdec/src/aacdec_drc.cpp \
+ libAACdec/src/aacdec_hcr.cpp \
+ libAACdec/src/aacdec_hcr_bit.cpp \
+ libAACdec/src/aacdec_hcrs.cpp \
+ libAACdec/src/aacdec_pns.cpp \
+ libAACdec/src/aacdec_tns.cpp \
+ libAACdec/src/aacdecoder.cpp \
+ libAACdec/src/aacdecoder_lib.cpp \
+ libAACdec/src/block.cpp \
+ libAACdec/src/channel.cpp \
+ libAACdec/src/channelinfo.cpp \
+ libAACdec/src/conceal.cpp \
+ libAACdec/src/ldfiltbank.cpp \
+ libAACdec/src/pulsedata.cpp \
+ libAACdec/src/rvlc.cpp \
+ libAACdec/src/rvlcbit.cpp \
+ libAACdec/src/rvlcconceal.cpp \
+ libAACdec/src/stereo.cpp \
+ libAACdec/src/usacdec_ace_d4t64.cpp \
+ libAACdec/src/usacdec_ace_ltp.cpp \
+ libAACdec/src/usacdec_acelp.cpp \
+ libAACdec/src/usacdec_fac.cpp \
+ libAACdec/src/usacdec_lpc.cpp \
+ libAACdec/src/usacdec_lpd.cpp \
+ libAACdec/src/usacdec_rom.cpp
+
+AACENC_SRC = \
+ libAACenc/src/aacEnc_ram.cpp \
+ libAACenc/src/aacEnc_rom.cpp \
+ libAACenc/src/aacenc.cpp \
+ libAACenc/src/aacenc_lib.cpp \
+ libAACenc/src/aacenc_pns.cpp \
+ libAACenc/src/aacenc_tns.cpp \
+ libAACenc/src/adj_thr.cpp \
+ libAACenc/src/band_nrg.cpp \
+ libAACenc/src/bandwidth.cpp \
+ libAACenc/src/bit_cnt.cpp \
+ libAACenc/src/bitenc.cpp \
+ libAACenc/src/block_switch.cpp \
+ libAACenc/src/channel_map.cpp \
+ libAACenc/src/chaosmeasure.cpp \
+ libAACenc/src/dyn_bits.cpp \
+ libAACenc/src/grp_data.cpp \
+ libAACenc/src/intensity.cpp \
+ libAACenc/src/line_pe.cpp \
+ libAACenc/src/metadata_compressor.cpp \
+ libAACenc/src/metadata_main.cpp \
+ libAACenc/src/mps_main.cpp \
+ libAACenc/src/ms_stereo.cpp \
+ libAACenc/src/noisedet.cpp \
+ libAACenc/src/pnsparam.cpp \
+ libAACenc/src/pre_echo_control.cpp \
+ libAACenc/src/psy_configuration.cpp \
+ libAACenc/src/psy_main.cpp \
+ libAACenc/src/qc_main.cpp \
+ libAACenc/src/quantize.cpp \
+ libAACenc/src/sf_estim.cpp \
+ libAACenc/src/spreading.cpp \
+ libAACenc/src/tonality.cpp \
+ libAACenc/src/transform.cpp
+
+ARITHCODING_SRC = \
+ libArithCoding/src/ac_arith_coder.cpp
+
+DRCDEC_SRC = \
+ libDRCdec/src/FDK_drcDecLib.cpp \
+ libDRCdec/src/drcDec_gainDecoder.cpp \
+ libDRCdec/src/drcDec_reader.cpp \
+ libDRCdec/src/drcDec_rom.cpp \
+ libDRCdec/src/drcDec_selectionProcess.cpp \
+ libDRCdec/src/drcDec_tools.cpp \
+ libDRCdec/src/drcGainDec_init.cpp \
+ libDRCdec/src/drcGainDec_preprocess.cpp \
+ libDRCdec/src/drcGainDec_process.cpp
+
+FDK_SRC = \
+ libFDK/src/FDK_bitbuffer.cpp \
+ libFDK/src/FDK_core.cpp \
+ libFDK/src/FDK_crc.cpp \
+ libFDK/src/FDK_decorrelate.cpp \
+ libFDK/src/FDK_hybrid.cpp \
+ libFDK/src/FDK_lpc.cpp \
+ libFDK/src/FDK_matrixCalloc.cpp \
+ libFDK/src/FDK_qmf_domain.cpp \
+ libFDK/src/FDK_tools_rom.cpp \
+ libFDK/src/FDK_trigFcts.cpp \
+ libFDK/src/autocorr2nd.cpp \
+ libFDK/src/dct.cpp \
+ libFDK/src/fft.cpp \
+ libFDK/src/fft_rad2.cpp \
+ libFDK/src/fixpoint_math.cpp \
+ libFDK/src/huff_nodes.cpp \
+ libFDK/src/mdct.cpp \
+ libFDK/src/nlc_dec.cpp \
+ libFDK/src/qmf.cpp \
+ libFDK/src/scale.cpp
+
+MPEGTPDEC_SRC = \
+ libMpegTPDec/src/tpdec_adif.cpp \
+ libMpegTPDec/src/tpdec_adts.cpp \
+ libMpegTPDec/src/tpdec_asc.cpp \
+ libMpegTPDec/src/tpdec_drm.cpp \
+ libMpegTPDec/src/tpdec_latm.cpp \
+ libMpegTPDec/src/tpdec_lib.cpp
+
+MPEGTPENC_SRC = \
+ libMpegTPEnc/src/tpenc_adif.cpp \
+ libMpegTPEnc/src/tpenc_adts.cpp \
+ libMpegTPEnc/src/tpenc_asc.cpp \
+ libMpegTPEnc/src/tpenc_latm.cpp \
+ libMpegTPEnc/src/tpenc_lib.cpp
+
+PCMUTILS_SRC = \
+ libPCMutils/src/limiter.cpp \
+ libPCMutils/src/pcm_utils.cpp \
+ libPCMutils/src/pcmdmx_lib.cpp
+
+SACDEC_SRC = \
+ libSACdec/src/sac_bitdec.cpp \
+ libSACdec/src/sac_calcM1andM2.cpp \
+ libSACdec/src/sac_dec.cpp \
+ libSACdec/src/sac_dec_conceal.cpp \
+ libSACdec/src/sac_dec_lib.cpp \
+ libSACdec/src/sac_process.cpp \
+ libSACdec/src/sac_qmf.cpp \
+ libSACdec/src/sac_reshapeBBEnv.cpp \
+ libSACdec/src/sac_rom.cpp \
+ libSACdec/src/sac_smoothing.cpp \
+ libSACdec/src/sac_stp.cpp \
+ libSACdec/src/sac_tsd.cpp
+
+SACENC_SRC = \
+ libSACenc/src/sacenc_bitstream.cpp \
+ libSACenc/src/sacenc_delay.cpp \
+ libSACenc/src/sacenc_dmx_tdom_enh.cpp \
+ libSACenc/src/sacenc_filter.cpp \
+ libSACenc/src/sacenc_framewindowing.cpp \
+ libSACenc/src/sacenc_huff_tab.cpp \
+ libSACenc/src/sacenc_lib.cpp \
+ libSACenc/src/sacenc_nlc_enc.cpp \
+ libSACenc/src/sacenc_onsetdetect.cpp \
+ libSACenc/src/sacenc_paramextract.cpp \
+ libSACenc/src/sacenc_staticgain.cpp \
+ libSACenc/src/sacenc_tree.cpp \
+ libSACenc/src/sacenc_vectorfunctions.cpp
+
+SBRDEC_SRC = \
+ libSBRdec/src/HFgen_preFlat.cpp \
+ libSBRdec/src/env_calc.cpp \
+ libSBRdec/src/env_dec.cpp \
+ libSBRdec/src/env_extr.cpp \
+ libSBRdec/src/hbe.cpp \
+ libSBRdec/src/huff_dec.cpp \
+ libSBRdec/src/lpp_tran.cpp \
+ libSBRdec/src/psbitdec.cpp \
+ libSBRdec/src/psdec.cpp \
+ libSBRdec/src/psdec_drm.cpp \
+ libSBRdec/src/psdecrom_drm.cpp \
+ libSBRdec/src/pvc_dec.cpp \
+ libSBRdec/src/sbr_crc.cpp \
+ libSBRdec/src/sbr_deb.cpp \
+ libSBRdec/src/sbr_dec.cpp \
+ libSBRdec/src/sbr_ram.cpp \
+ libSBRdec/src/sbr_rom.cpp \
+ libSBRdec/src/sbrdec_drc.cpp \
+ libSBRdec/src/sbrdec_freq_sca.cpp \
+ libSBRdec/src/sbrdecoder.cpp
+
+SBRENC_SRC = \
+ libSBRenc/src/bit_sbr.cpp \
+ libSBRenc/src/code_env.cpp \
+ libSBRenc/src/env_bit.cpp \
+ libSBRenc/src/env_est.cpp \
+ libSBRenc/src/fram_gen.cpp \
+ libSBRenc/src/invf_est.cpp \
+ libSBRenc/src/mh_det.cpp \
+ libSBRenc/src/nf_est.cpp \
+ libSBRenc/src/ps_bitenc.cpp \
+ libSBRenc/src/ps_encode.cpp \
+ libSBRenc/src/ps_main.cpp \
+ libSBRenc/src/resampler.cpp \
+ libSBRenc/src/sbr_encoder.cpp \
+ libSBRenc/src/sbr_misc.cpp \
+ libSBRenc/src/sbrenc_freq_sca.cpp \
+ libSBRenc/src/sbrenc_ram.cpp \
+ libSBRenc/src/sbrenc_rom.cpp \
+ libSBRenc/src/ton_corr.cpp \
+ libSBRenc/src/tran_det.cpp
+
+SYS_SRC = \
+ libSYS/src/genericStds.cpp \
+ libSYS/src/syslib_channelMapDescr.cpp
+
+libfdk_aac_SOURCES = \
+ $(AACDEC_SRC) $(AACENC_SRC) \
+ $(ARITHCODING_SRC) \
+ $(DRCDEC_SRC) \
+ $(MPEGTPDEC_SRC) $(MPEGTPENC_SRC) \
+ $(SACDEC_SRC) $(SACENC_SRC) \
+ $(SBRDEC_SRC) $(SBRENC_SRC) \
+ $(PCMUTILS_SRC) $(FDK_SRC) $(SYS_SRC)
+
+
+aac_enc_SOURCES = aac-enc.c wavreader.c
+
+prefix = \usr\local
+prefix_win = $(prefix:/=\) # In case we are using MSYS or MinGW.
+
+CFLAGS = /nologo /W3 /Ox /MT /EHsc /Dinline=__inline $(TARGET_FLAGS) $(AM_CPPFLAGS) $(XCFLAGS)
+CXXFLAGS = $(CFLAGS)
+CPPFLAGS = $(CFLAGS)
+LDFLAGS = -nologo $(XLDFLAGS)
+ARFLAGS = -nologo
+
+incdir = $(prefix_win)\include\fdk-aac
+bindir = $(prefix_win)\bin
+libdir = $(prefix_win)\lib
+
+INST_DIRS = $(bindir) $(incdir) $(libdir)
+
+LIB_DEF = fdk-aac.def
+STATIC_LIB = fdk-aac.lib
+SHARED_LIB = fdk-aac-1.dll
+IMP_LIB = fdk-aac.dll.lib
+
+AAC_ENC_OBJS = $(aac_enc_SOURCES:.c=.obj)
+FDK_OBJS = $(libfdk_aac_SOURCES:.cpp=.obj)
+
+PROGS = aac-enc.exe
+
+
+
+all: $(LIB_DEF) $(STATIC_LIB) $(SHARED_LIB) $(IMP_LIB) $(PROGS)
+
+clean:
+ del /f $(LIB_DEF) $(STATIC_LIB) $(SHARED_LIB) $(IMP_LIB) $(PROGS) libfdk-aac.pc 2>NUL
+ del /f *.obj *.exp 2>NUL
+ del /f libAACdec\src\*.obj 2>NUL
+ del /f libAACenc\src\*.obj 2>NUL
+ del /f libArithCoding\src\*.obj 2>NUL
+ del /f libDRCdec\src\*.obj 2>NUL
+ del /f libFDK\src\*.obj 2>NUL
+ del /f libMpegTPDec\src\*.obj 2>NUL
+ del /f libMpegTPEnc\src\*.obj 2>NUL
+ del /f libPCMutils\src\*.obj 2>NUL
+ del /f libSACdec\src\*.obj 2>NUL
+ del /f libSACenc\src\*.obj 2>NUL
+ del /f libSBRdec\src\*.obj 2>NUL
+ del /f libSBRenc\src\*.obj 2>NUL
+ del /f libSYS\src\*.obj 2>NUL
+
+install: $(INST_DIRS)
+ copy libAACdec\include\aacdecoder_lib.h $(incdir)
+ copy libAACenc\include\aacenc_lib.h $(incdir)
+ copy libSYS\include\FDK_audio.h $(incdir)
+ copy libSYS\include\genericStds.h $(incdir)
+ copy libSYS\include\machine_type.h $(incdir)
+ copy libSYS\include\syslib_channelMapDescr.h $(incdir)
+ copy $(STATIC_LIB) $(libdir)
+ copy $(IMP_LIB) $(libdir)
+ copy $(SHARED_LIB) $(bindir)
+ copy $(PROGS) $(bindir)
+ copy $(LIB_DEF) $(libdir)
+
+$(INST_DIRS):
+ @mkdir $(MKDIR_FLAGS) $@
+
+$(STATIC_LIB): $(FDK_OBJS)
+ $(AR) $(ARFLAGS) -out:$@ $(FDK_OBJS)
+
+$(IMP_LIB): $(SHARED_LIB)
+
+$(SHARED_LIB): $(FDK_OBJS)
+ $(LD) $(LDFLAGS) -OUT:$@ -DEF:$(LIB_DEF) -implib:$(IMP_LIB) -DLL $(FDK_OBJS)
+
+$(PROGS): $(AAC_ENC_OBJS)
+ $(LD) $(LDFLAGS) -out:$@ $(AAC_ENC_OBJS) $(STATIC_LIB)
+
+.cpp.obj:
+ $(CXX) $(CXXFLAGS) -c -Fo$@ $<
+
+$(LIB_DEF):
+ @echo EXPORTS > $(LIB_DEF)
+ @type fdk-aac.sym >> $(LIB_DEF)
diff --git a/aac-enc.c b/aac-enc.c
new file mode 100644
index 0000000..c90ff12
--- /dev/null
+++ b/aac-enc.c
@@ -0,0 +1,237 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 2011 Martin Storsjo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+#if defined(_MSC_VER)
+#include <getopt.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <stdlib.h>
+#include "libAACenc/include/aacenc_lib.h"
+#include "wavreader.h"
+
+void usage(const char* name) {
+ fprintf(stderr, "%s [-r bitrate] [-t aot] [-a afterburner] [-s sbr] [-v vbr] in.wav out.aac\n", name);
+ fprintf(stderr, "Supported AOTs:\n");
+ fprintf(stderr, "\t2\tAAC-LC\n");
+ fprintf(stderr, "\t5\tHE-AAC\n");
+ fprintf(stderr, "\t29\tHE-AAC v2\n");
+ fprintf(stderr, "\t23\tAAC-LD\n");
+ fprintf(stderr, "\t39\tAAC-ELD\n");
+}
+
+int main(int argc, char *argv[]) {
+ int bitrate = 64000;
+ int ch;
+ const char *infile, *outfile;
+ FILE *out;
+ void *wav;
+ int format, sample_rate, channels, bits_per_sample;
+ int input_size;
+ uint8_t* input_buf;
+ int16_t* convert_buf;
+ int aot = 2;
+ int afterburner = 1;
+ int eld_sbr = 0;
+ int vbr = 0;
+ HANDLE_AACENCODER handle;
+ CHANNEL_MODE mode;
+ AACENC_InfoStruct info = { 0 };
+ while ((ch = getopt(argc, argv, "r:t:a:s:v:")) != -1) {
+ switch (ch) {
+ case 'r':
+ bitrate = atoi(optarg);
+ break;
+ case 't':
+ aot = atoi(optarg);
+ break;
+ case 'a':
+ afterburner = atoi(optarg);
+ break;
+ case 's':
+ eld_sbr = atoi(optarg);
+ break;
+ case 'v':
+ vbr = atoi(optarg);
+ break;
+ case '?':
+ default:
+ usage(argv[0]);
+ return 1;
+ }
+ }
+ if (argc - optind < 2) {
+ usage(argv[0]);
+ return 1;
+ }
+ infile = argv[optind];
+ outfile = argv[optind + 1];
+
+ wav = wav_read_open(infile);
+ if (!wav) {
+ fprintf(stderr, "Unable to open wav file %s\n", infile);
+ return 1;
+ }
+ if (!wav_get_header(wav, &format, &channels, &sample_rate, &bits_per_sample, NULL)) {
+ fprintf(stderr, "Bad wav file %s\n", infile);
+ return 1;
+ }
+ if (format != 1) {
+ fprintf(stderr, "Unsupported WAV format %d\n", format);
+ return 1;
+ }
+ if (bits_per_sample != 16) {
+ fprintf(stderr, "Unsupported WAV sample depth %d\n", bits_per_sample);
+ return 1;
+ }
+ switch (channels) {
+ case 1: mode = MODE_1; break;
+ case 2: mode = MODE_2; break;
+ case 3: mode = MODE_1_2; break;
+ case 4: mode = MODE_1_2_1; break;
+ case 5: mode = MODE_1_2_2; break;
+ case 6: mode = MODE_1_2_2_1; break;
+ default:
+ fprintf(stderr, "Unsupported WAV channels %d\n", channels);
+ return 1;
+ }
+ if (aacEncOpen(&handle, 0, channels) != AACENC_OK) {
+ fprintf(stderr, "Unable to open encoder\n");
+ return 1;
+ }
+ if (aacEncoder_SetParam(handle, AACENC_AOT, aot) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the AOT\n");
+ return 1;
+ }
+ if (aot == 39 && eld_sbr) {
+ if (aacEncoder_SetParam(handle, AACENC_SBR_MODE, 1) != AACENC_OK) {
+ fprintf(stderr, "Unable to set SBR mode for ELD\n");
+ return 1;
+ }
+ }
+ if (aacEncoder_SetParam(handle, AACENC_SAMPLERATE, sample_rate) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the AOT\n");
+ return 1;
+ }
+ if (aacEncoder_SetParam(handle, AACENC_CHANNELMODE, mode) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the channel mode\n");
+ return 1;
+ }
+ if (aacEncoder_SetParam(handle, AACENC_CHANNELORDER, 1) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the wav channel order\n");
+ return 1;
+ }
+ if (vbr) {
+ if (aacEncoder_SetParam(handle, AACENC_BITRATEMODE, vbr) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the VBR bitrate mode\n");
+ return 1;
+ }
+ } else {
+ if (aacEncoder_SetParam(handle, AACENC_BITRATE, bitrate) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the bitrate\n");
+ return 1;
+ }
+ }
+ if (aacEncoder_SetParam(handle, AACENC_TRANSMUX, TT_MP4_ADTS) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the ADTS transmux\n");
+ return 1;
+ }
+ if (aacEncoder_SetParam(handle, AACENC_AFTERBURNER, afterburner) != AACENC_OK) {
+ fprintf(stderr, "Unable to set the afterburner mode\n");
+ return 1;
+ }
+ if (aacEncEncode(handle, NULL, NULL, NULL, NULL) != AACENC_OK) {
+ fprintf(stderr, "Unable to initialize the encoder\n");
+ return 1;
+ }
+ if (aacEncInfo(handle, &info) != AACENC_OK) {
+ fprintf(stderr, "Unable to get the encoder info\n");
+ return 1;
+ }
+
+ out = fopen(outfile, "wb");
+ if (!out) {
+ perror(outfile);
+ return 1;
+ }
+
+ input_size = channels*2*info.frameLength;
+ input_buf = (uint8_t*) malloc(input_size);
+ convert_buf = (int16_t*) malloc(input_size);
+
+ while (1) {
+ AACENC_BufDesc in_buf = { 0 }, out_buf = { 0 };
+ AACENC_InArgs in_args = { 0 };
+ AACENC_OutArgs out_args = { 0 };
+ int in_identifier = IN_AUDIO_DATA;
+ int in_size, in_elem_size;
+ int out_identifier = OUT_BITSTREAM_DATA;
+ int out_size, out_elem_size;
+ int read, i;
+ void *in_ptr, *out_ptr;
+ uint8_t outbuf[20480];
+ AACENC_ERROR err;
+
+ read = wav_read_data(wav, input_buf, input_size);
+ for (i = 0; i < read/2; i++) {
+ const uint8_t* in = &input_buf[2*i];
+ convert_buf[i] = in[0] | (in[1] << 8);
+ }
+ in_ptr = convert_buf;
+ in_size = read;
+ in_elem_size = 2;
+
+ in_args.numInSamples = read <= 0 ? -1 : read/2;
+ in_buf.numBufs = 1;
+ in_buf.bufs = &in_ptr;
+ in_buf.bufferIdentifiers = &in_identifier;
+ in_buf.bufSizes = &in_size;
+ in_buf.bufElSizes = &in_elem_size;
+
+ out_ptr = outbuf;
+ out_size = sizeof(outbuf);
+ out_elem_size = 1;
+ out_buf.numBufs = 1;
+ out_buf.bufs = &out_ptr;
+ out_buf.bufferIdentifiers = &out_identifier;
+ out_buf.bufSizes = &out_size;
+ out_buf.bufElSizes = &out_elem_size;
+
+ if ((err = aacEncEncode(handle, &in_buf, &out_buf, &in_args, &out_args)) != AACENC_OK) {
+ if (err == AACENC_ENCODE_EOF)
+ break;
+ fprintf(stderr, "Encoding failed\n");
+ return 1;
+ }
+ if (out_args.numOutBytes == 0)
+ continue;
+ fwrite(outbuf, 1, out_args.numOutBytes, out);
+ }
+ free(input_buf);
+ free(convert_buf);
+ fclose(out);
+ wav_read_close(wav);
+ aacEncClose(&handle);
+
+ return 0;
+}
+
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..210ccb8
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+autoreconf -fiv
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..9c714d7
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,38 @@
+dnl -*- Autoconf -*-
+dnl Process this file with autoconf to produce a configure script.
+
+AC_INIT([fdk-aac], [2.0.0], [http://sourceforge.net/projects/opencore-amr/])
+AC_CONFIG_AUX_DIR(.)
+AC_CONFIG_MACRO_DIR([m4])
+AM_INIT_AUTOMAKE([tar-ustar foreign])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+
+dnl Various options for configure
+AC_ARG_ENABLE([example],
+ [AS_HELP_STRING([--enable-example],
+ [enable example encoding program (default is no)])],
+ [example=$enableval], [example=no])
+
+dnl Automake conditionals to set
+AM_CONDITIONAL(EXAMPLE, test x$example = xyes)
+
+dnl Checks for programs.
+AC_PROG_CC
+AC_PROG_CXX
+LT_INIT
+
+AC_SEARCH_LIBS([sin], [m])
+
+dnl soname version to use
+dnl goes by ‘current[:revision[:age]]’ with the soname ending up as
+dnl current.age.revision
+FDK_AAC_VERSION=2:0:0
+
+AS_IF([test x$enable_shared = xyes], [LIBS_PRIVATE=$LIBS], [LIBS_PUBLIC=$LIBS])
+AC_SUBST(FDK_AAC_VERSION)
+AC_SUBST(LIBS_PUBLIC)
+AC_SUBST(LIBS_PRIVATE)
+
+AC_CONFIG_FILES([Makefile
+ fdk-aac.pc])
+AC_OUTPUT
diff --git a/fdk-aac.pc.in b/fdk-aac.pc.in
new file mode 100644
index 0000000..2edac45
--- /dev/null
+++ b/fdk-aac.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Fraunhofer FDK AAC Codec Library
+Description: AAC codec library
+Version: @PACKAGE_VERSION@
+Libs: -L${libdir} -lfdk-aac @LIBS_PUBLIC@
+Libs.private: @LIBS_PRIVATE@
+Cflags: -I${includedir}
diff --git a/fdk-aac.sym b/fdk-aac.sym
new file mode 100644
index 0000000..2a06c41
--- /dev/null
+++ b/fdk-aac.sym
@@ -0,0 +1,18 @@
+aacDecoder_AncDataGet
+aacDecoder_AncDataInit
+aacDecoder_Close
+aacDecoder_ConfigRaw
+aacDecoder_DecodeFrame
+aacDecoder_Fill
+aacDecoder_GetFreeBytes
+aacDecoder_GetLibInfo
+aacDecoder_GetStreamInfo
+aacDecoder_Open
+aacDecoder_SetParam
+aacEncClose
+aacEncEncode
+aacEncGetLibInfo
+aacEncInfo
+aacEncOpen
+aacEncoder_GetParam
+aacEncoder_SetParam
diff --git a/libAACdec/include/aacdecoder_lib.h b/libAACdec/include/aacdecoder_lib.h
index 3a9b910..5f0dd02 100644
--- a/libAACdec/include/aacdecoder_lib.h
+++ b/libAACdec/include/aacdecoder_lib.h
@@ -457,6 +457,11 @@ Where N equals to CStreamInfo::frameSize .
#include "FDK_audio.h"
#include "genericStds.h"
+
+#define AACDECODER_LIB_VL0 3
+#define AACDECODER_LIB_VL1 0
+#define AACDECODER_LIB_VL2 0
+
/**
* \brief AAC decoder error codes.
*/
diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp
index ea52bb5..705f758 100644
--- a/libAACdec/src/aacdecoder_lib.cpp
+++ b/libAACdec/src/aacdecoder_lib.cpp
@@ -943,6 +943,8 @@ LINKSPEC_CPP HANDLE_AACDECODER aacDecoder_Open(TRANSPORT_TYPE transportFmt,
return NULL;
}
+ transportDec_SetParam(pIn, TPDEC_PARAM_IGNORE_BUFFERFULLNESS, 1);
+
/* Allocate AAC decoder core struct. */
aacDec = CAacDecoder_Open(transportFmt);
diff --git a/libAACdec/src/usacdec_acelp.cpp b/libAACdec/src/usacdec_acelp.cpp
index af1f488..ed775d2 100644
--- a/libAACdec/src/usacdec_acelp.cpp
+++ b/libAACdec/src/usacdec_acelp.cpp
@@ -267,9 +267,9 @@ static void D_gain2_plus(int index, FIXP_COD code[], FIXP_SGL *gain_pit,
gcode0_e = gcode0_e + SF_MEAN_ENER_LG10 - (ener_code_e >> 1) + 1;
i = index << 1;
- *gain_pit = t_qua_gain7b[i]; /* adaptive codebook gain */
+ *gain_pit = fdk_t_qua_gain7b[i]; /* adaptive codebook gain */
/* t_qua_gain[ind2p1] : fixed codebook gain correction factor */
- Ltmp = fMult(t_qua_gain7b[i + 1], gcode0);
+ Ltmp = fMult(fdk_t_qua_gain7b[i + 1], gcode0);
*gain_code = scaleValue(Ltmp, gcode0_e - SF_GAIN_C + SF_QUA_GAIN7B);
/* update bad frame handler */
diff --git a/libAACdec/src/usacdec_rom.cpp b/libAACdec/src/usacdec_rom.cpp
index 519e992..ca3009e 100644
--- a/libAACdec/src/usacdec_rom.cpp
+++ b/libAACdec/src/usacdec_rom.cpp
@@ -1249,7 +1249,7 @@ const FIXP_LPC fdk_dec_dico_lsf_abs_8b[] = {
adaptive codebook gain g_p (left column). Scaled by 2.0f.
innovative codebook gain g_c (right column). Scaled by 16.0f.
*/
-const FIXP_SGL t_qua_gain7b[128 * 2] = {
+const FIXP_SGL fdk_t_qua_gain7b[128 * 2] = {
204, 441, 464, 1977, 869, 1077, 1072, 3062, 1281, 4759, 1647,
1539, 1845, 7020, 1853, 634, 1995, 2336, 2351, 15400, 2661, 1165,
2702, 3900, 2710, 10133, 3195, 1752, 3498, 2624, 3663, 849, 3984,
diff --git a/libAACdec/src/usacdec_rom.h b/libAACdec/src/usacdec_rom.h
index 0ad4cb0..f969e90 100644
--- a/libAACdec/src/usacdec_rom.h
+++ b/libAACdec/src/usacdec_rom.h
@@ -132,7 +132,7 @@ extern const FIXP_LPC fdk_dec_dico_lsf_abs_8b[16 * 256];
/* ACELP tables */
#define SF_QUA_GAIN7B 4
-extern const FIXP_SGL t_qua_gain7b[128 * 2];
+extern const FIXP_SGL fdk_t_qua_gain7b[128 * 2];
extern const FIXP_SGL lsp_interpol_factor[2][NB_SUBFR];
/* For bass post filter */
diff --git a/libAACenc/include/aacenc_lib.h b/libAACenc/include/aacenc_lib.h
index 2e47571..fa41ee6 100644
--- a/libAACenc/include/aacenc_lib.h
+++ b/libAACenc/include/aacenc_lib.h
@@ -1025,6 +1025,10 @@ internally.
#include "machine_type.h"
#include "FDK_audio.h"
+#define AACENCODER_LIB_VL0 4
+#define AACENCODER_LIB_VL1 0
+#define AACENCODER_LIB_VL2 0
+
/**
* AAC encoder error codes.
*/
diff --git a/libAACenc/src/aacenc.h b/libAACenc/src/aacenc.h
index 0e0d8c1..291ea54 100644
--- a/libAACenc/src/aacenc.h
+++ b/libAACenc/src/aacenc.h
@@ -206,8 +206,9 @@ typedef enum {
CH_ORDER_MPEG =
0, /*!< MPEG channel ordering (e. g. 5.1: C, L, R, SL, SR, LFE) */
- CH_ORDER_WAV /*!< WAV fileformat channel ordering (e. g. 5.1: L, R, C, LFE,
- SL, SR) */
+ CH_ORDER_WAV, /*!< WAV fileformat channel ordering (e. g. 5.1: L, R, C, LFE,
+ SL, SR) */
+ CH_ORDER_WG4 /*!< WG4 fileformat channel ordering (e. g. 5.1: L, R, SL, SR, C, LFE) */
} CHANNEL_ORDER;
diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp
index 11db3da..2f34d4d 100644
--- a/libAACenc/src/aacenc_lib.cpp
+++ b/libAACenc/src/aacenc_lib.cpp
@@ -2191,7 +2191,7 @@ AACENC_ERROR aacEncoder_SetParam(const HANDLE_AACENCODER hAacEncoder,
break;
case AACENC_CHANNELORDER:
if (hAacEncoder->aacConfig.channelOrder != (CHANNEL_ORDER)value) {
- if (!((value == 0) || (value == 1))) {
+ if (!((value == 0) || (value == 1) || (value == 2))) {
err = AACENC_INVALID_CONFIG;
break;
}
diff --git a/libAACenc/src/intensity.cpp b/libAACenc/src/intensity.cpp
index a160a4f..8cb1b45 100644
--- a/libAACenc/src/intensity.cpp
+++ b/libAACenc/src/intensity.cpp
@@ -747,9 +747,9 @@ void FDKaacEnc_IntensityStereoProcessing(
j++) {
s = ((mdctSpectrumLeft[j] << s0) >> 1) +
((mdctSpectrumRight[j] << s0) >> 1);
- es += fMultDiv2(s, s) >>
+ es = fAddSaturate(es, fMultDiv2(s, s) >>
(MDCT_SPEC_SF -
- 1); // scaled 2*(mdctScale - s0 + 1) + MDCT_SPEC_SF
+ 1)); // scaled 2*(mdctScale - s0 + 1) + MDCT_SPEC_SF
}
msMask[sfb + sfboffs] = 0;
tmp = fDivNorm(sfbEnergyLeft[sfb + sfboffs], es, &s1);
diff --git a/libAACenc/src/metadata_main.cpp b/libAACenc/src/metadata_main.cpp
index edd3831..ada4502 100644
--- a/libAACenc/src/metadata_main.cpp
+++ b/libAACenc/src/metadata_main.cpp
@@ -491,10 +491,17 @@ FDK_METADATA_ERROR FDK_MetadataEnc_Init(
FDK_channelMapDescr mapDescrPrev, mapDescr;
int c, src[2] = {-1, -1}, dst[2] = {-1, -1};
- FDK_chMapDescr_init(&mapDescrPrev, NULL, 0,
- (channelOrder == CH_ORDER_MPEG) ? 1 : 0);
- FDK_chMapDescr_init(&mapDescr, NULL, 0,
- (channelOrder == CH_ORDER_MPEG) ? 1 : 0);
+ if (channelOrder == CH_ORDER_WG4) {
+ FDK_chMapDescr_init(&mapDescrPrev, FDK_mapInfoTabWg4,
+ FDK_mapInfoTabLenWg4, 0);
+ FDK_chMapDescr_init(&mapDescr, FDK_mapInfoTabWg4,
+ FDK_mapInfoTabLenWg4, 0);
+ } else {
+ FDK_chMapDescr_init(&mapDescrPrev, NULL, 0,
+ (channelOrder == CH_ORDER_MPEG) ? 1 : 0);
+ FDK_chMapDescr_init(&mapDescr, NULL, 0,
+ (channelOrder == CH_ORDER_MPEG) ? 1 : 0);
+ }
switch (channelMode) {
case MODE_1:
diff --git a/libFDK/include/FDK_archdef.h b/libFDK/include/FDK_archdef.h
index 95601bb..b4fef8a 100644
--- a/libFDK/include/FDK_archdef.h
+++ b/libFDK/include/FDK_archdef.h
@@ -114,10 +114,14 @@ amm-info@iis.fraunhofer.de
#define __x86__
#endif
-#if defined(_M_ARM) && !defined(__arm__) || defined(__aarch64__)
+#if defined(_M_ARM) && !defined(__arm__) || defined(__aarch64__) || defined(_M_ARM64)
#define __arm__
#endif
+#if defined(_ARCH_PPC) && !defined(__powerpc__)
+#define __powerpc__ 1
+#endif
+
#if (__TARGET_ARCH_ARM == 5) || defined(__TARGET_FEATURE_DSPMUL) || \
(_M_ARM == 5) || defined(__ARM_ARCH_5TEJ__) || defined(__ARM_ARCH_7EM__)
/* Define __ARM_ARCH_5TE__ if armv5te features are supported */
@@ -158,12 +162,11 @@ amm-info@iis.fraunhofer.de
#define __ARM_ARCH_7EM__
#endif
-#if defined(__aarch64__)
+#if defined(__aarch64__) || defined(_M_ARM64)
#define __ARM_ARCH_8__
#endif
#ifdef _M_ARM
-#include "cmnintrin.h"
#include "armintr.h"
#endif
@@ -219,6 +222,14 @@ amm-info@iis.fraunhofer.de
#define POW2COEFF_16BIT
#define LDCOEFF_16BIT
+#elif defined(__powerpc__)
+#define ARCH_PREFER_MULT_32x32
+#define ARCH_PREFER_MULT_32x16
+#define SINETABLE_16BIT
+#define POW2COEFF_16BIT
+#define LDCOEFF_16BIT
+#define WINDOWTABLE_16BIT
+
#else
#warning >>>> Please set architecture characterization defines for your platform (FDK_HIGH_PERFORMANCE)! <<<<
diff --git a/libFDK/include/clz.h b/libFDK/include/clz.h
index 6acdee6..df75618 100644
--- a/libFDK/include/clz.h
+++ b/libFDK/include/clz.h
@@ -115,6 +115,9 @@ amm-info@iis.fraunhofer.de
#elif defined(__x86__)
#include "x86/clz_x86.h"
+#elif defined(__powerpc__)
+#include "ppc/clz_ppc.h"
+
#endif /* all cores */
/*************************************************************************
diff --git a/libFDK/include/common_fix.h b/libFDK/include/common_fix.h
index 8d0dfde..7c08225 100644
--- a/libFDK/include/common_fix.h
+++ b/libFDK/include/common_fix.h
@@ -406,10 +406,6 @@ FDK_INLINE FIXP_SGL fMax(FIXP_SGL a, FIXP_SGL b) { return fixmax_S(a, b); }
#if !defined(__LP64__)
FDK_INLINE INT fMax(INT a, INT b) { return fixmax_I(a, b); }
FDK_INLINE INT fMin(INT a, INT b) { return fixmin_I(a, b); }
-#if !defined(_MSC_VER) && defined(__x86_64__)
-FDK_INLINE SHORT fMax(SHORT a, SHORT b) { return fixmax_S(a, b); }
-FDK_INLINE SHORT fMin(SHORT a, SHORT b) { return fixmin_S(a, b); }
-#endif
#endif
inline UINT fMax(UINT a, UINT b) { return fixmax_UI(a, b); }
diff --git a/libFDK/include/fft.h b/libFDK/include/fft.h
index 3576ed3..d394046 100644
--- a/libFDK/include/fft.h
+++ b/libFDK/include/fft.h
@@ -139,7 +139,7 @@ void ifft(int length, FIXP_DBL *pInput, INT *scalefactor);
* bit scale headroom. The values are interleaved, real/imag pairs.
*/
LNK_SECTION_CODE_L1
-static void FDK_FORCEINLINE fft_4(FIXP_DBL *x) {
+static FDK_FORCEINLINE void fft_4(FIXP_DBL *x) {
FIXP_DBL a00, a10, a20, a30, tmp0, tmp1;
a00 = (x[0] + x[4]) >> 1; /* Re A + Re B */
@@ -168,7 +168,7 @@ static void FDK_FORCEINLINE fft_4(FIXP_DBL *x) {
#ifndef FUNCTION_fft_8
LNK_SECTION_CODE_L1
-static void FDK_FORCEINLINE fft_8(FIXP_DBL *x) {
+static FDK_FORCEINLINE void fft_8(FIXP_DBL *x) {
FIXP_SPK w_PiFOURTH = {{FIXP_SGL(0x5A82), FIXP_SGL(0x5A82)}};
FIXP_DBL a00, a10, a20, a30;
diff --git a/libFDK/include/fixmul.h b/libFDK/include/fixmul.h
index a51ca0c..8eeb7ab 100644
--- a/libFDK/include/fixmul.h
+++ b/libFDK/include/fixmul.h
@@ -115,6 +115,9 @@ amm-info@iis.fraunhofer.de
#elif defined(__x86__)
#include "x86/fixmul_x86.h"
+#elif defined(__powerpc__)
+#include "ppc/fixmul_ppc.h"
+
#endif /* all cores */
/*************************************************************************
diff --git a/libFDK/include/mips/cplx_mul_mips.h b/libFDK/include/mips/cplx_mul_mips.h
index acae118..4ade3e5 100644
--- a/libFDK/include/mips/cplx_mul_mips.h
+++ b/libFDK/include/mips/cplx_mul_mips.h
@@ -103,7 +103,7 @@ amm-info@iis.fraunhofer.de
#if !defined(CPLX_MUL_MIPS_H)
#define CPLX_MUL_MIPS_H
-#if defined(__GNUC__) && defined(__mips__) && __mips_isa_rev < 6
+#if defined(__GNUC__) && defined(__mips__)
//#define FUNCTION_cplxMultDiv2_32x16
//#define FUNCTION_cplxMultDiv2_32x16X2
@@ -115,53 +115,16 @@ amm-info@iis.fraunhofer.de
#if defined(FUNCTION_cplxMultDiv2_32x32X2)
inline void cplxMultDiv2(FIXP_DBL *c_Re, FIXP_DBL *c_Im, FIXP_DBL a_Re,
FIXP_DBL a_Im, FIXP_DBL b_Re, FIXP_DBL b_Im) {
- INT result;
-
- __asm__(
- "mult %[a_Re], %[b_Re];\n"
- "msub %[a_Im], %[b_Im];\n"
- "mfhi %[result];\n"
- : [result] "=r"(result)
- : [a_Re] "d"(a_Re), [b_Re] "d"(b_Re), [a_Im] "d"(a_Im), [b_Im] "d"(b_Im)
- : "lo");
-
- *c_Re = result;
-
- __asm__(
- "mult %[a_Re], %[b_Im];\n"
- "madd %[a_Im], %[b_Re];\n"
- "mfhi %[result];\n"
- : [result] "=r"(result)
- : [a_Re] "r"(a_Re), [b_Im] "r"(b_Im), [a_Im] "r"(a_Im), [b_Re] "r"(b_Re)
- : "lo");
- *c_Im = result;
+ *c_Re = (((long long)a_Re * (long long)b_Re) - ((long long)a_Im * (long long)b_Im))>>32;
+ *c_Im = (((long long)a_Re * (long long)b_Im) + ((long long)a_Im * (long long)b_Re))>>32;
}
#endif
#if defined(FUNCTION_cplxMult_32x32X2)
inline void cplxMult(FIXP_DBL *c_Re, FIXP_DBL *c_Im, FIXP_DBL a_Re,
FIXP_DBL a_Im, FIXP_DBL b_Re, FIXP_DBL b_Im) {
- INT result;
-
- __asm__(
- "mult %[a_Re], %[b_Re];\n"
- "msub %[a_Im], %[b_Im];\n"
- "mfhi %[result];\n"
- //"extr_w %[result], 31;\n"
- : [result] "=r"(result)
- : [a_Re] "r"(a_Re), [b_Re] "r"(b_Re), [a_Im] "r"(a_Im), [b_Im] "r"(b_Im)
- : "lo");
- *c_Re = result << 1;
-
- __asm__(
- "mult %[a_Re], %[b_Im];\n"
- "madd %[a_Im], %[b_Re];\n"
- "mfhi %[result];\n"
- //"extr_w %[result], 31;\n"
- : [result] "=r"(result)
- : [a_Re] "r"(a_Re), [b_Im] "r"(b_Im), [a_Im] "r"(a_Im), [b_Re] "r"(b_Re)
- : "lo");
- *c_Im = result << 1;
+ *c_Re = ((((long long)a_Re * (long long)b_Re) - ((long long)a_Im * (long long)b_Im))>>32)<<1;
+ *c_Im = ((((long long)a_Re * (long long)b_Im) + ((long long)a_Im * (long long)b_Re))>>32)<<1;
}
#endif
diff --git a/libFDK/include/ppc/clz_ppc.h b/libFDK/include/ppc/clz_ppc.h
new file mode 100644
index 0000000..bfd23c6
--- /dev/null
+++ b/libFDK/include/ppc/clz_ppc.h
@@ -0,0 +1,102 @@
+
+/* -----------------------------------------------------------------------------------------------------------
+Software License for The Fraunhofer FDK AAC Codec Library for Android
+
+© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
+ All rights reserved.
+
+ 1. INTRODUCTION
+The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
+the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
+This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
+
+AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
+audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
+independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
+of the MPEG specifications.
+
+Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
+may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
+individually for the purpose of encoding or decoding bit streams in products that are compliant with
+the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
+these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
+software may already be covered under those patent licenses when it is used for those licensed purposes only.
+
+Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
+are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
+applications information and documentation.
+
+2. COPYRIGHT LICENSE
+
+Redistribution and use in source and binary forms, with or without modification, are permitted without
+payment of copyright license fees provided that you satisfy the following conditions:
+
+You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
+your modifications thereto in source code form.
+
+You must retain the complete text of this software license in the documentation and/or other materials
+provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
+You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
+modifications thereto to recipients of copies in binary form.
+
+The name of Fraunhofer may not be used to endorse or promote products derived from this library without
+prior written permission.
+
+You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
+software or your modifications thereto.
+
+Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
+and the date of any change. For modified versions of the FDK AAC Codec, the term
+"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
+"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
+
+3. NO PATENT LICENSE
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
+ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
+respect to this software.
+
+You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
+by appropriate patent licenses.
+
+4. DISCLAIMER
+
+This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
+"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
+of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
+including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
+or business interruption, however caused and on any theory of liability, whether in contract, strict
+liability, or tort (including negligence), arising in any way out of the use of this software, even if
+advised of the possibility of such damage.
+
+5. CONTACT INFORMATION
+
+Fraunhofer Institute for Integrated Circuits IIS
+Attention: Audio and Multimedia Departments - FDK AAC LL
+Am Wolfsmantel 33
+91058 Erlangen, Germany
+
+www.iis.fraunhofer.de/amm
+amm-info@iis.fraunhofer.de
+----------------------------------------------------------------------------------------------------------- */
+
+/*************************** Fraunhofer IIS FDK Tools **********************
+
+ Author(s):
+ Description: fixed point intrinsics
+
+******************************************************************************/
+
+#if defined(__powerpc__) && (defined(__GNUC__) || defined(__xlC__))
+
+#define FUNCTION_fixnormz_D
+
+inline INT fixnormz_D(LONG value)
+{
+ INT result;
+ __asm__ ("cntlzw %0, %1" : "=r" (result) : "r" (value));
+ return result;
+}
+
+#endif /* __powerpc__ && (__GNUC__ || __xlC__) */
diff --git a/libFDK/include/ppc/fixmul_ppc.h b/libFDK/include/ppc/fixmul_ppc.h
new file mode 100644
index 0000000..9e2745c
--- /dev/null
+++ b/libFDK/include/ppc/fixmul_ppc.h
@@ -0,0 +1,115 @@
+
+/* -----------------------------------------------------------------------------------------------------------
+Software License for The Fraunhofer FDK AAC Codec Library for Android
+
+© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
+ All rights reserved.
+
+ 1. INTRODUCTION
+The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
+the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
+This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
+
+AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
+audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
+independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
+of the MPEG specifications.
+
+Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
+may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
+individually for the purpose of encoding or decoding bit streams in products that are compliant with
+the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
+these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
+software may already be covered under those patent licenses when it is used for those licensed purposes only.
+
+Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
+are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
+applications information and documentation.
+
+2. COPYRIGHT LICENSE
+
+Redistribution and use in source and binary forms, with or without modification, are permitted without
+payment of copyright license fees provided that you satisfy the following conditions:
+
+You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
+your modifications thereto in source code form.
+
+You must retain the complete text of this software license in the documentation and/or other materials
+provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
+You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
+modifications thereto to recipients of copies in binary form.
+
+The name of Fraunhofer may not be used to endorse or promote products derived from this library without
+prior written permission.
+
+You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
+software or your modifications thereto.
+
+Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
+and the date of any change. For modified versions of the FDK AAC Codec, the term
+"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
+"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
+
+3. NO PATENT LICENSE
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
+ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
+respect to this software.
+
+You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
+by appropriate patent licenses.
+
+4. DISCLAIMER
+
+This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
+"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
+of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
+including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
+or business interruption, however caused and on any theory of liability, whether in contract, strict
+liability, or tort (including negligence), arising in any way out of the use of this software, even if
+advised of the possibility of such damage.
+
+5. CONTACT INFORMATION
+
+Fraunhofer Institute for Integrated Circuits IIS
+Attention: Audio and Multimedia Departments - FDK AAC LL
+Am Wolfsmantel 33
+91058 Erlangen, Germany
+
+www.iis.fraunhofer.de/amm
+amm-info@iis.fraunhofer.de
+----------------------------------------------------------------------------------------------------------- */
+
+/*************************** Fraunhofer IIS FDK Tools **********************
+
+ Author(s):
+ Description: fixed point intrinsics
+
+******************************************************************************/
+
+#if defined(__powerpc__) && (defined(__GNUC__) || defined(__xlC__))
+
+#define FUNCTION_fixmuldiv2_DD
+
+#define FUNCTION_fixmuldiv2BitExact_DD
+#define fixmuldiv2BitExact_DD(a,b) fixmuldiv2_DD(a,b)
+
+#define FUNCTION_fixmulBitExact_DD
+#define fixmulBitExact_DD(a,b) fixmul_DD(a,b)
+
+#define FUNCTION_fixmuldiv2BitExact_DS
+#define fixmuldiv2BitExact_DS(a,b) fixmuldiv2_DS(a,b)
+
+#define FUNCTION_fixmulBitExact_DS
+#define fixmulBitExact_DS(a,b) fixmul_DS(a,b)
+
+
+inline INT fixmuldiv2_DD (const INT a, const INT b)
+{
+ INT result;
+ __asm__ ("mulhw %0, %1, %2" : "=r" (result) : "r" (a), "r" (b));
+ return result;
+}
+
+#endif /* __powerpc__ && (__GNUC__ || __xlC__) */
diff --git a/libMpegTPDec/src/tpdec_adts.cpp b/libMpegTPDec/src/tpdec_adts.cpp
index 6dc0275..d6fac21 100644
--- a/libMpegTPDec/src/tpdec_adts.cpp
+++ b/libMpegTPDec/src/tpdec_adts.cpp
@@ -181,6 +181,9 @@ TRANSPORTDEC_ERROR adtsRead_DecodeHeader(HANDLE_ADTS pAdts,
FDKmemcpy(&oldPce, &pAsc->m_progrConfigElement, sizeof(CProgramConfig));
valBits = FDKgetValidBits(hBs);
+ if (valBits < ADTS_HEADERLENGTH) {
+ return TRANSPORTDEC_NOT_ENOUGH_BITS;
+ }
/* adts_fixed_header */
bs.mpeg_id = FDKreadBits(hBs, Adts_Length_Id);
diff --git a/libSBRdec/src/hbe.cpp b/libSBRdec/src/hbe.cpp
index 53b21c9..176815b 100644
--- a/libSBRdec/src/hbe.cpp
+++ b/libSBRdec/src/hbe.cpp
@@ -641,7 +641,7 @@ static const FIXP_DBL invCubeRootCorrection[3] = {0x40000000, 0x50A28BE6,
*/
static
#ifdef __arm__
- FIXP_DBL __attribute__((always_inline))
+ FIXP_DBL FDK_FORCEINLINE
invCubeRootNorm2(FIXP_DBL op_m, INT* op_e)
#else
FIXP_DBL
@@ -763,7 +763,7 @@ static const FIXP_DBL invFourthRootCorrection[4] = {0x40000000, 0x4C1BF829,
static
#ifdef __arm__
- FIXP_DBL __attribute__((always_inline))
+ FIXP_DBL FDK_FORCEINLINE
invFourthRootNorm2(FIXP_DBL op_m, INT* op_e)
#else
FIXP_DBL
@@ -879,7 +879,7 @@ static const FIXP_DBL inv3EigthRootCorrection[8] = {
static
#ifdef __arm__
- FIXP_DBL __attribute__((always_inline))
+ FIXP_DBL FDK_FORCEINLINE
inv3EigthRootNorm2(FIXP_DBL op_m, INT* op_e)
#else
FIXP_DBL
diff --git a/libSBRdec/src/psdec.cpp b/libSBRdec/src/psdec.cpp
index 13a21bf..b31b310 100644
--- a/libSBRdec/src/psdec.cpp
+++ b/libSBRdec/src/psdec.cpp
@@ -325,11 +325,11 @@ void initSlotBasedRotation(
int env, int usb) {
INT group = 0;
INT bin = 0;
- INT noIidSteps;
+ INT noIidSteps, noFactors;
FIXP_SGL invL;
FIXP_DBL ScaleL, ScaleR;
- FIXP_DBL Alpha, Beta;
+ FIXP_DBL Alpha, Beta, AlphasValue;
FIXP_DBL h11r, h12r, h21r, h22r;
const FIXP_DBL *PScaleFactors;
@@ -337,9 +337,11 @@ void initSlotBasedRotation(
if (h_ps_d->bsData[h_ps_d->processSlot].mpeg.bFineIidQ) {
PScaleFactors = ScaleFactorsFine; /* values are shiftet right by one */
noIidSteps = NO_IID_STEPS_FINE;
+ noFactors = NO_IID_LEVELS_FINE;
} else {
PScaleFactors = ScaleFactors; /* values are shiftet right by one */
noIidSteps = NO_IID_STEPS;
+ noFactors = NO_IID_LEVELS;
}
/* dequantize and decode */
@@ -358,17 +360,23 @@ void initSlotBasedRotation(
/* ScaleR and ScaleL are scaled by 1 shift right */
- ScaleR = PScaleFactors[noIidSteps + h_ps_d->specificTo.mpeg.pCoef
- ->aaIidIndexMapped[env][bin]];
- ScaleL = PScaleFactors[noIidSteps - h_ps_d->specificTo.mpeg.pCoef
- ->aaIidIndexMapped[env][bin]];
-
+ ScaleL = ScaleR = 0;
+ if (noIidSteps + h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] >= 0 && noIidSteps + h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] < noFactors)
+ ScaleR = PScaleFactors[noIidSteps + h_ps_d->specificTo.mpeg.pCoef
+ ->aaIidIndexMapped[env][bin]];
+ if (noIidSteps - h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] >= 0 && noIidSteps - h_ps_d->specificTo.mpeg.pCoef->aaIidIndexMapped[env][bin] < noFactors)
+ ScaleL = PScaleFactors[noIidSteps - h_ps_d->specificTo.mpeg.pCoef
+ ->aaIidIndexMapped[env][bin]];
+
+ AlphasValue = 0;
+ if (h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin] >= 0)
+ AlphasValue = Alphas[h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin]];
Beta = fMult(
- fMult(Alphas[h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin]],
+ fMult(AlphasValue,
(ScaleR - ScaleL)),
FIXP_SQRT05);
Alpha =
- Alphas[h_ps_d->specificTo.mpeg.pCoef->aaIccIndexMapped[env][bin]] >> 1;
+ AlphasValue >> 1;
/* Alpha and Beta are now both scaled by 2 shifts right */
diff --git a/libSYS/include/syslib_channelMapDescr.h b/libSYS/include/syslib_channelMapDescr.h
index 1c5737a..375a24d 100644
--- a/libSYS/include/syslib_channelMapDescr.h
+++ b/libSYS/include/syslib_channelMapDescr.h
@@ -189,6 +189,12 @@ UCHAR FDK_chMapDescr_getMapValue(const FDK_channelMapDescr* const pMapDescr,
*/
int FDK_chMapDescr_isValid(const FDK_channelMapDescr* const pMapDescr);
+/**
+ * Extra variables for setting up Wg4 channel mapping.
+ */
+extern const CHANNEL_MAP_INFO FDK_mapInfoTabWg4[];
+extern const UINT FDK_mapInfoTabLenWg4;
+
#ifdef __cplusplus
}
#endif
diff --git a/libSYS/src/syslib_channelMapDescr.cpp b/libSYS/src/syslib_channelMapDescr.cpp
index e011f25..d22a30d 100644
--- a/libSYS/src/syslib_channelMapDescr.cpp
+++ b/libSYS/src/syslib_channelMapDescr.cpp
@@ -155,6 +155,37 @@ static const CHANNEL_MAP_INFO mapInfoTabDflt[DFLT_CH_MAP_TAB_LEN] =
/* 13 */ {mapCfg13, 24},
/* 14 */ {mapCfg14, 8}};
+
+static const UCHAR mapWg4Cfg1[] = {0, 1};
+static const UCHAR mapWg4Cfg2[] = {0, 1};
+static const UCHAR mapWg4Cfg3[] = {2, 0, 1};
+static const UCHAR mapWg4Cfg4[] = {3, 0, 1, 2};
+static const UCHAR mapWg4Cfg5[] = {4, 0, 1, 2, 3};
+static const UCHAR mapWg4Cfg6[] = {4, 0, 1, 2, 3, 5};
+static const UCHAR mapWg4Cfg7[] = {6, 0, 1, 2, 3, 4, 5, 7};
+static const UCHAR mapWg4Cfg14[] = {6, 0, 1, 2, 3, 4, 5, 7};
+
+const CHANNEL_MAP_INFO FDK_mapInfoTabWg4[] =
+ {/* chCfg, map, numCh */
+ /* 0 */ {mapFallback, 24},
+ /* 1 */ {mapWg4Cfg1, 2},
+ /* 2 */ {mapWg4Cfg2, 2},
+ /* 3 */ {mapWg4Cfg3, 3},
+ /* 4 */ {mapWg4Cfg4, 4},
+ /* 5 */ {mapWg4Cfg5, 5},
+ /* 6 */ {mapWg4Cfg6, 6},
+ /* 7 */ {mapWg4Cfg7, 8},
+ /* 8 */ {mapFallback, 24},
+ /* 9 */ {mapFallback, 24},
+ /* 10 */ {mapFallback, 24},
+ /* 11 */ {mapFallback, 24}, // Unhandled for Wg4 yet
+ /* 12 */ {mapFallback, 24}, // Unhandled for Wg4 yet
+ /* 13 */ {mapFallback, 24}, // Unhandled for Wg4 yet
+ /* 14 */ {mapFallback, 24}}; // Unhandled for Wg4 yet
+
+const UINT FDK_mapInfoTabLenWg4 = sizeof(FDK_mapInfoTabWg4)/sizeof(FDK_mapInfoTabWg4[0]);
+
+
/**
* Get the mapping value for a specific channel and map index.
*/
diff --git a/m4/.gitkeep b/m4/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/m4/.gitkeep
diff --git a/wavreader.c b/wavreader.c
new file mode 100644
index 0000000..898eb9c
--- /dev/null
+++ b/wavreader.c
@@ -0,0 +1,193 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 2009 Martin Storsjo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#include "wavreader.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#define TAG(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
+
+struct wav_reader {
+ FILE *wav;
+ uint32_t data_length;
+
+ int format;
+ int sample_rate;
+ int bits_per_sample;
+ int channels;
+ int byte_rate;
+ int block_align;
+
+ int streamed;
+};
+
+static uint32_t read_tag(struct wav_reader* wr) {
+ uint32_t tag = 0;
+ tag = (tag << 8) | fgetc(wr->wav);
+ tag = (tag << 8) | fgetc(wr->wav);
+ tag = (tag << 8) | fgetc(wr->wav);
+ tag = (tag << 8) | fgetc(wr->wav);
+ return tag;
+}
+
+static uint32_t read_int32(struct wav_reader* wr) {
+ uint32_t value = 0;
+ value |= fgetc(wr->wav) << 0;
+ value |= fgetc(wr->wav) << 8;
+ value |= fgetc(wr->wav) << 16;
+ value |= fgetc(wr->wav) << 24;
+ return value;
+}
+
+static uint16_t read_int16(struct wav_reader* wr) {
+ uint16_t value = 0;
+ value |= fgetc(wr->wav) << 0;
+ value |= fgetc(wr->wav) << 8;
+ return value;
+}
+
+static void skip(FILE *f, int n) {
+ int i;
+ for (i = 0; i < n; i++)
+ fgetc(f);
+}
+
+void* wav_read_open(const char *filename) {
+ struct wav_reader* wr = (struct wav_reader*) malloc(sizeof(*wr));
+ long data_pos = 0;
+ memset(wr, 0, sizeof(*wr));
+
+ if (!strcmp(filename, "-"))
+ wr->wav = stdin;
+ else
+ wr->wav = fopen(filename, "rb");
+ if (wr->wav == NULL) {
+ free(wr);
+ return NULL;
+ }
+
+ while (1) {
+ uint32_t tag, tag2, length;
+ tag = read_tag(wr);
+ if (feof(wr->wav))
+ break;
+ length = read_int32(wr);
+ if (!length || length >= 0x7fff0000) {
+ wr->streamed = 1;
+ length = ~0;
+ }
+ if (tag != TAG('R', 'I', 'F', 'F') || length < 4) {
+ fseek(wr->wav, length, SEEK_CUR);
+ continue;
+ }
+ tag2 = read_tag(wr);
+ length -= 4;
+ if (tag2 != TAG('W', 'A', 'V', 'E')) {
+ fseek(wr->wav, length, SEEK_CUR);
+ continue;
+ }
+ // RIFF chunk found, iterate through it
+ while (length >= 8) {
+ uint32_t subtag, sublength;
+ subtag = read_tag(wr);
+ if (feof(wr->wav))
+ break;
+ sublength = read_int32(wr);
+ length -= 8;
+ if (length < sublength)
+ break;
+ if (subtag == TAG('f', 'm', 't', ' ')) {
+ if (sublength < 16) {
+ // Insufficient data for 'fmt '
+ break;
+ }
+ wr->format = read_int16(wr);
+ wr->channels = read_int16(wr);
+ wr->sample_rate = read_int32(wr);
+ wr->byte_rate = read_int32(wr);
+ wr->block_align = read_int16(wr);
+ wr->bits_per_sample = read_int16(wr);
+ if (wr->format == 0xfffe) {
+ if (sublength < 28) {
+ // Insufficient data for waveformatex
+ break;
+ }
+ skip(wr->wav, 8);
+ wr->format = read_int32(wr);
+ skip(wr->wav, sublength - 28);
+ } else {
+ skip(wr->wav, sublength - 16);
+ }
+ } else if (subtag == TAG('d', 'a', 't', 'a')) {
+ data_pos = ftell(wr->wav);
+ wr->data_length = sublength;
+ if (!wr->data_length || wr->streamed) {
+ wr->streamed = 1;
+ return wr;
+ }
+ fseek(wr->wav, sublength, SEEK_CUR);
+ } else {
+ skip(wr->wav, sublength);
+ }
+ length -= sublength;
+ }
+ if (length > 0) {
+ // Bad chunk?
+ fseek(wr->wav, length, SEEK_CUR);
+ }
+ }
+ fseek(wr->wav, data_pos, SEEK_SET);
+ return wr;
+}
+
+void wav_read_close(void* obj) {
+ struct wav_reader* wr = (struct wav_reader*) obj;
+ if (wr->wav != stdin)
+ fclose(wr->wav);
+ free(wr);
+}
+
+int wav_get_header(void* obj, int* format, int* channels, int* sample_rate, int* bits_per_sample, unsigned int* data_length) {
+ struct wav_reader* wr = (struct wav_reader*) obj;
+ if (format)
+ *format = wr->format;
+ if (channels)
+ *channels = wr->channels;
+ if (sample_rate)
+ *sample_rate = wr->sample_rate;
+ if (bits_per_sample)
+ *bits_per_sample = wr->bits_per_sample;
+ if (data_length)
+ *data_length = wr->data_length;
+ return wr->format && wr->sample_rate;
+}
+
+int wav_read_data(void* obj, unsigned char* data, unsigned int length) {
+ struct wav_reader* wr = (struct wav_reader*) obj;
+ int n;
+ if (wr->wav == NULL)
+ return -1;
+ if (length > wr->data_length && !wr->streamed)
+ length = wr->data_length;
+ n = fread(data, 1, length, wr->wav);
+ wr->data_length -= length;
+ return n;
+}
+
diff --git a/wavreader.h b/wavreader.h
new file mode 100644
index 0000000..57a13ff
--- /dev/null
+++ b/wavreader.h
@@ -0,0 +1,37 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 2009 Martin Storsjo
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#ifndef WAVREADER_H
+#define WAVREADER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void* wav_read_open(const char *filename);
+void wav_read_close(void* obj);
+
+int wav_get_header(void* obj, int* format, int* channels, int* sample_rate, int* bits_per_sample, unsigned int* data_length);
+int wav_read_data(void* obj, unsigned char* data, unsigned int length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/win32/getopt.h b/win32/getopt.h
new file mode 100644
index 0000000..7402521
--- /dev/null
+++ b/win32/getopt.h
@@ -0,0 +1,904 @@
+#ifndef __GETOPT_H__
+/**
+ * DISCLAIMER
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ *
+ * The mingw-w64 runtime package and its code is distributed in the hope that it
+ * will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
+ * IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
+ * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/*
+ * Implementation of the `getopt', `getopt_long' and `getopt_long_only'
+ * APIs, for inclusion in the MinGW runtime library.
+ *
+ * This file is part of the MinGW32 package set.
+ *
+ * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
+ * Copyright (C) 2008, 2009, 2011, 2012, MinGW.org Project.
+ *
+ * ---------------------------------------------------------------------------
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice, this permission notice, and the following
+ * disclaimer shall be included in all copies or substantial portions of
+ * the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * ---------------------------------------------------------------------------
+ *
+ */
+
+#define __GETOPT_H__
+
+/* All the headers include this file. */
+#include <crtdefs.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int optind; /* index of first non-option in argv */
+extern int optopt; /* single option character, as parsed */
+extern int opterr; /* flag to enable built-in diagnostics... */
+ /* (user may set to zero, to suppress) */
+
+extern char *optarg; /* pointer to argument of current option */
+
+/* Identify how to get the calling program name, for use in messages...
+ */
+#ifdef __CYGWIN__
+/*
+ * CYGWIN uses this DLL reference...
+ */
+# define PROGNAME __progname
+extern char __declspec(dllimport) *__progname;
+#else
+/*
+ * ...while elsewhere, we simply use the first argument passed.
+ */
+# define PROGNAME *argv
+#endif
+
+extern int getopt(int nargc, char * const *nargv, const char *options);
+
+#ifdef _BSD_SOURCE
+/*
+ * BSD adds the non-standard `optreset' feature, for reinitialisation
+ * of `getopt' parsing. We support this feature, for applications which
+ * proclaim their BSD heritage, before including this header; however,
+ * to maintain portability, developers are advised to avoid it.
+ */
+# define optreset __mingw_optreset
+extern int optreset;
+#endif
+#ifdef __cplusplus
+}
+#endif
+/*
+ * POSIX requires the `getopt' API to be specified in `unistd.h';
+ * thus, `unistd.h' includes this header. However, we do not want
+ * to expose the `getopt_long' or `getopt_long_only' APIs, when
+ * included in this manner. Thus, close the standard __GETOPT_H__
+ * declarations block, and open an additional __GETOPT_LONG_H__
+ * specific block, only when *not* __UNISTD_H_SOURCED__, in which
+ * to declare the extended API.
+ */
+#endif /* !defined(__GETOPT_H__) */
+
+#if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
+#define __GETOPT_LONG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct option /* specification for a long form option... */
+{
+ const char *name; /* option name, without leading hyphens */
+ int has_arg; /* does it take an argument? */
+ int *flag; /* where to save its status, or NULL */
+ int val; /* its associated status value */
+};
+
+enum /* permitted values for its `has_arg' field... */
+{
+ no_argument = 0, /* option never takes an argument */
+ required_argument, /* option always requires an argument */
+ optional_argument /* option may take an argument */
+};
+
+extern int getopt_long(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx);
+extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx);
+/*
+ * Previous MinGW implementation had...
+ */
+#ifndef HAVE_DECL_GETOPT
+/*
+ * ...for the long form API only; keep this for compatibility.
+ */
+# define HAVE_DECL_GETOPT 1
+#endif
+
+
+
+/* Identify how to get the calling program name, for use in messages...
+ */
+#ifdef __CYGWIN__
+/*
+ * CYGWIN uses this DLL reference...
+ */
+# define PROGNAME __progname
+extern char __declspec(dllimport) *__progname;
+#else
+/*
+ * ...while elsewhere, we simply use the first argument passed.
+ */
+# define PROGNAME *argv
+#endif
+
+/* Initialise the public variables. */
+
+int optind = 1; /* index for first non-option arg */
+int opterr = 1; /* enable built-in error messages */
+
+char *optarg = NULL; /* pointer to current option argument */
+
+#define CHAR char /* argument type selector */
+
+#define getopt_switchar '-' /* option prefix character in argv */
+#define getopt_pluschar '+' /* prefix for POSIX mode in optstring */
+#define getopt_takes_argument ':' /* marker for optarg in optstring */
+#define getopt_arg_assign '=' /* longopt argument field separator */
+#define getopt_unknown '?' /* return code for unmatched option */
+#define getopt_ordered 1 /* return code for ordered non-option */
+
+#define getopt_all_done -1 /* return code to indicate completion */
+
+enum
+{ /* All `getopt' API functions are implemented via calls to the
+ * common static function `getopt_parse()'; these `mode' selectors
+ * determine the behaviour of `getopt_parse()', to deliver the
+ * appropriate result in each case.
+ */
+ getopt_mode_standard = 0, /* getopt() */
+ getopt_mode_long, /* getopt_long() */
+ getopt_mode_long_only /* getopt_long_only() */
+};
+
+enum
+{ /* When attempting to match a command line argument to a long form option,
+ * these indicate the status of the match.
+ */
+ getopt_no_match = 0, /* no successful match */
+ getopt_abbreviated_match, /* argument is an abbreviation for an option */
+ getopt_exact_match /* argument matches the full option name */
+};
+
+int optopt = getopt_unknown; /* return value for option being evaluated */
+
+/* Some BSD applications expect to be able to reinitialise `getopt' parsing
+ * by setting a global variable called `optreset'. We provide an obfuscated
+ * API, which allows applications to emulate this brain damage; however, any
+ * use of this is non-portable, and is strongly discouraged.
+ */
+#define optreset __mingw_optreset
+int optreset = 0;
+
+static
+int getopt_missing_arg( const CHAR *optstring )
+{
+ /* Helper function to determine the appropriate return value,
+ * for the case where a required option argument is missing.
+ */
+ if( (*optstring == getopt_pluschar) || (*optstring == getopt_switchar) )
+ ++optstring;
+ return (*optstring == getopt_takes_argument)
+ ? getopt_takes_argument
+ : getopt_unknown;
+}
+
+/* `complain' macro facilitates the generation of simple built-in
+ * error messages, displayed on various fault conditions, provided
+ * `opterr' is non-zero.
+ */
+#define complain( MSG, ARG ) if( opterr ) \
+ fprintf( stderr, "%s: "MSG"\n", PROGNAME, ARG )
+
+static
+int getopt_argerror( int mode, char *fmt, CHAR *prog, struct option *opt, int retval )
+{
+ /* Helper function, to generate more complex built-in error
+ * messages, for invalid arguments to long form options ...
+ */
+ if( opterr )
+ {
+ /* ... but, displayed only if `opterr' is non-zero.
+ */
+ char flag[] = "--";
+ if( mode != getopt_mode_long )
+ /*
+ * only display one hyphen, for implicit long form options,
+ * improperly resolved by `getopt_long_only()'.
+ */
+ flag[1] = 0;
+ /*
+ * always preface the program name ...
+ */
+ fprintf( stderr, "%s: ", prog );
+ /*
+ * to the appropriate, option specific message.
+ */
+ fprintf( stderr, fmt, flag, opt->name );
+ }
+ /* Whether displaying the message, or not, always set `optopt'
+ * to identify the faulty option ...
+ */
+ optopt = opt->val;
+ /*
+ * and return the `invalid option' indicator.
+ */
+ return retval;
+}
+
+/* `getopt_conventions' establish behavioural options, to control
+ * the operation of `getopt_parse()', e.g. to select between POSIX
+ * and GNU style argument parsing behaviour.
+ */
+#define getopt_set_conventions 0x1000
+#define getopt_posixly_correct 0x0010
+
+static
+int getopt_conventions( int flags )
+{
+ static int conventions = 0;
+
+ if( (conventions == 0) && ((flags & getopt_set_conventions) == 0) )
+ {
+ /* default conventions have not yet been established;
+ * initialise them now!
+ */
+ conventions = getopt_set_conventions;
+ if( flags == getopt_pluschar )
+ conventions |= getopt_posixly_correct;
+ }
+
+ else if( flags & getopt_set_conventions )
+ /*
+ * default conventions may have already been established,
+ * but this is a specific request to augment them.
+ */
+ conventions |= flags;
+
+ /* in any event, return the currently established conventions.
+ */
+ return conventions;
+}
+
+static
+int is_switchar( CHAR flag )
+{
+ /* A simple helper function, used to identify the switch character
+ * introducing an optional command line argument.
+ */
+ return flag == getopt_switchar;
+}
+
+static
+const CHAR *getopt_match( CHAR lookup, const CHAR *opt_string )
+{
+ /* Helper function, used to identify short form options.
+ */
+ if( (*opt_string == getopt_pluschar) || (*opt_string == getopt_switchar) )
+ ++opt_string;
+ if( *opt_string == getopt_takes_argument )
+ ++opt_string;
+ do if( lookup == *opt_string ) return opt_string;
+ while( *++opt_string );
+ return NULL;
+}
+
+static
+int getopt_match_long( const CHAR *nextchar, const CHAR *optname )
+{
+ /* Helper function, used to identify potential matches for
+ * long form options.
+ */
+ CHAR matchchar;
+ while( (matchchar = *nextchar++) && (matchchar == *optname) )
+ /*
+ * skip over initial substring which DOES match.
+ */
+ ++optname;
+
+ if( matchchar )
+ {
+ /* did NOT match the entire argument to an initial substring
+ * of a defined option name ...
+ */
+ if( matchchar != getopt_arg_assign )
+ /*
+ * ... and didn't stop at an `=' internal field separator,
+ * so this is NOT a possible match.
+ */
+ return getopt_no_match;
+
+ /* DID stop at an `=' internal field separator,
+ * so this IS a possible match, and what follows is an
+ * argument to the possibly matched option.
+ */
+ optarg = (char *)(nextchar);
+ }
+ return *optname
+ /*
+ * if we DIDN'T match the ENTIRE text of the option name,
+ * then it's a possible abbreviated match ...
+ */
+ ? getopt_abbreviated_match
+ /*
+ * but if we DID match the entire option name,
+ * then it's a DEFINITE EXACT match.
+ */
+ : getopt_exact_match;
+}
+
+static
+int getopt_resolved( int mode, int argc, CHAR *const *argv, int *argind,
+struct option *opt, int index, int *retindex, const CHAR *optstring )
+{
+ /* Helper function to establish appropriate return conditions,
+ * on resolution of a long form option.
+ */
+ if( retindex != NULL )
+ *retindex = index;
+
+ /* On return, `optind' should normally refer to the argument, if any,
+ * which follows the current one; it is convenient to set this, before
+ * checking for the presence of any `optarg'.
+ */
+ optind = *argind + 1;
+
+ if( optarg && (opt[index].has_arg == no_argument) )
+ /*
+ * it is an error for the user to specify an option specific argument
+ * with an option which doesn't expect one!
+ */
+ return getopt_argerror( mode, "option `%s%s' doesn't accept an argument\n",
+ PROGNAME, opt + index, getopt_unknown );
+
+ else if( (optarg == NULL) && (opt[index].has_arg == required_argument) )
+ {
+ /* similarly, it is an error if no argument is specified
+ * with an option which requires one ...
+ */
+ if( optind < argc )
+ /*
+ * ... except that the requirement may be satisfied from
+ * the following command line argument, if any ...
+ */
+ optarg = argv[*argind = optind++];
+
+ else
+ /* so fail this case, only if no such argument exists!
+ */
+ return getopt_argerror( mode, "option `%s%s' requires an argument\n",
+ PROGNAME, opt + index, getopt_missing_arg( optstring ) );
+ }
+
+ /* when the caller has provided a return buffer ...
+ */
+ if( opt[index].flag != NULL )
+ {
+ /* ... then we place the proper return value there,
+ * and return a status code of zero ...
+ */
+ *(opt[index].flag) = opt[index].val;
+ return 0;
+ }
+ /* ... otherwise, the return value becomes the status code.
+ */
+ return opt[index].val;
+}
+
+static
+int getopt_verify( const CHAR *nextchar, const CHAR *optstring )
+{
+ /* Helper function, called by getopt_parse() when invoked
+ * by getopt_long_only(), to verify when an unmatched or an
+ * ambiguously matched long form option string is valid as
+ * a short form option specification.
+ */
+ if( ! (nextchar && *nextchar && optstring && *optstring) )
+ /*
+ * There are no characters to be matched, or there are no
+ * valid short form option characters to which they can be
+ * matched, so this can never be valid.
+ */
+ return 0;
+
+ while( *nextchar )
+ {
+ /* For each command line character in turn ...
+ */
+ const CHAR *test;
+ if( (test = getopt_match( *nextchar++, optstring )) == NULL )
+ /*
+ * ... there is no short form option to match the current
+ * candidate, so the entire argument fails.
+ */
+ return 0;
+
+ if( test[1] == getopt_takes_argument )
+ /*
+ * The current candidate is valid, and it matches an option
+ * which takes an argument, so this command line argument is
+ * a valid short form option specification; accept it.
+ */
+ return 1;
+ }
+ /* If we get to here, then every character in the command line
+ * argument was valid as a short form option; accept it.
+ */
+ return 1;
+}
+
+static
+#define getopt_std_args int argc, CHAR *const argv[], const CHAR *optstring
+int getopt_parse( int mode, getopt_std_args, ... )
+{
+ /* Common core implementation for ALL `getopt' functions.
+ */
+ static int argind = 0;
+ static int optbase = 0;
+ static const CHAR *nextchar = NULL;
+ static int optmark = 0;
+
+ if( (optreset |= (optind < 1)) || (optind < optbase) )
+ {
+ /* POSIX does not prescribe any definitive mechanism for restarting
+ * a `getopt' scan, but some applications may require such capability.
+ * We will support it, by allowing the caller to adjust the value of
+ * `optind' downwards, (nominally setting it to zero). Since POSIX
+ * wants `optind' to have an initial value of one, but we want all
+ * of our internal place holders to be initialised to zero, when we
+ * are called for the first time, we will handle such a reset by
+ * adjusting all of the internal place holders to one less than
+ * the adjusted `optind' value, (but never to less than zero).
+ */
+ if( optreset )
+ {
+ /* User has explicitly requested reinitialisation...
+ * We need to reset `optind' to it's normal initial value of 1,
+ * to avoid a potential infinitely recursive loop; by doing this
+ * up front, we also ensure that the remaining place holders
+ * will be correctly reinitialised to no less than zero.
+ */
+ optind = 1;
+
+ /* We also need to clear the `optreset' request...
+ */
+ optreset = 0;
+ }
+
+ /* Now, we may safely reinitialise the internal place holders, to
+ * one less than `optind', without fear of making them negative.
+ */
+ optmark = optbase = argind = optind - 1;
+ nextchar = NULL;
+ }
+
+ /* From a POSIX perspective, the following is `undefined behaviour';
+ * we implement it thus, for compatibility with GNU and BSD getopt.
+ */
+ else if( optind > (argind + 1) )
+ {
+ /* Some applications expect to be able to manipulate `optind',
+ * causing `getopt' to skip over one or more elements of `argv';
+ * POSIX doesn't require us to support this brain-damaged concept;
+ * (indeed, POSIX defines no particular behaviour, in the event of
+ * such usage, so it must be considered a bug for an application
+ * to rely on any particular outcome); nonetheless, Mac-OS-X and
+ * BSD actually provide *documented* support for this capability,
+ * so we ensure that our internal place holders keep track of
+ * external `optind' increments; (`argind' must lag by one).
+ */
+ argind = optind - 1;
+
+ /* When `optind' is misused, in this fashion, we also abandon any
+ * residual text in the argument we had been parsing; this is done
+ * without any further processing of such abandoned text, assuming
+ * that the caller is equipped to handle it appropriately.
+ */
+ nextchar = NULL;
+ }
+
+ if( nextchar && *nextchar )
+ {
+ /* we are parsing a standard, or short format, option argument ...
+ */
+ const CHAR *optchar;
+ if( (optchar = getopt_match( optopt = *nextchar++, optstring )) != NULL )
+ {
+ /* we have identified it as valid ...
+ */
+ if( optchar[1] == getopt_takes_argument )
+ {
+ /* and determined that it requires an associated argument ...
+ */
+ if( ! *(optarg = (char *)(nextchar)) )
+ {
+ /* the argument is NOT attached ...
+ */
+ if( optchar[2] == getopt_takes_argument )
+ /*
+ * but this GNU extension marks it as optional,
+ * so we don't provide one on this occasion.
+ */
+ optarg = NULL;
+
+ /* otherwise this option takes a mandatory argument,
+ * so, provided there is one available ...
+ */
+ else if( (argc - argind) > 1 )
+ /*
+ * we take the following command line argument,
+ * as the appropriate option argument.
+ */
+ optarg = argv[++argind];
+
+ /* but if no further argument is available,
+ * then there is nothing we can do, except for
+ * issuing the requisite diagnostic message.
+ */
+ else
+ {
+ complain( "option requires an argument -- %c", optopt );
+ return getopt_missing_arg( optstring );
+ }
+ }
+ optind = argind + 1;
+ nextchar = NULL;
+ }
+ else
+ optarg = NULL;
+ optind = (nextchar && *nextchar) ? argind : argind + 1;
+ return optopt;
+ }
+ /* if we didn't find a valid match for the specified option character,
+ * then we fall through to here, so take appropriate diagnostic action.
+ */
+ if( mode == getopt_mode_long_only )
+ {
+ complain( "unrecognised option `-%s'", --nextchar );
+ nextchar = NULL;
+ optopt = 0;
+ }
+ else
+ complain( "invalid option -- %c", optopt );
+ optind = (nextchar && *nextchar) ? argind : argind + 1;
+ return getopt_unknown;
+ }
+
+ if( optmark > optbase )
+ {
+ /* This can happen, in GNU parsing mode ONLY, when we have
+ * skipped over non-option arguments, and found a subsequent
+ * option argument; in this case we permute the arguments.
+ */
+ int index;
+ /*
+ * `optspan' specifies the number of contiguous arguments
+ * which are spanned by the current option, and so must be
+ * moved together during permutation.
+ */
+ const int optspan = argind - optmark + 1;
+ /*
+ * we use `this_arg' to store these temporarily.
+ */
+ CHAR **this_arg = malloc(sizeof(CHAR*) * optspan);
+ /*
+ * we cannot manipulate `argv' directly, since the `getopt'
+ * API prototypes it as `read-only'; this cast to `arglist'
+ * allows us to work around that restriction.
+ */
+ CHAR **arglist = (char **)(argv);
+
+ /* save temporary copies of the arguments which are associated
+ * with the current option ...
+ */
+ for( index = 0; index < optspan; ++index )
+ this_arg[index] = arglist[optmark + index];
+
+ /* move all preceding non-option arguments to the right,
+ * overwriting these saved arguments, while making space
+ * to replace them in their permuted location.
+ */
+ for( --optmark; optmark >= optbase; --optmark )
+ arglist[optmark + optspan] = arglist[optmark];
+
+ /* restore the temporarily saved option arguments to
+ * their permuted location.
+ */
+ for( index = 0; index < optspan; ++index )
+ arglist[optbase + index] = this_arg[index];
+
+ /* adjust `optbase', to account for the relocated option.
+ */
+ optbase += optspan;
+
+ free(this_arg);
+ }
+
+ else
+ /* no permutation occurred ...
+ * simply adjust `optbase' for all options parsed so far.
+ */
+ optbase = argind + 1;
+
+ /* enter main parsing loop ...
+ */
+ while( argc > ++argind )
+ {
+ /* inspect each argument in turn, identifying possible options ...
+ */
+ if( is_switchar( *(nextchar = argv[optmark = argind]) ) && *++nextchar )
+ {
+ /* we've found a candidate option argument ... */
+
+ if( is_switchar( *nextchar ) )
+ {
+ /* it's a double hyphen argument ... */
+
+ const CHAR *refchar = nextchar;
+ if( *++refchar )
+ {
+ /* and it looks like a long format option ...
+ * `getopt_long' mode must be active to accept it as such,
+ * `getopt_long_only' also qualifies, but we must downgrade
+ * it to force explicit handling as a long format option.
+ */
+ if( mode >= getopt_mode_long )
+ {
+ nextchar = refchar;
+ mode = getopt_mode_long;
+ }
+ }
+ else
+ {
+ /* this is an explicit `--' end of options marker, so wrap up now!
+ */
+ if( optmark > optbase )
+ {
+ /* permuting the argument list as necessary ...
+ * (note use of `this_arg' and `arglist', as above).
+ */
+ CHAR *this_arg = argv[optmark];
+ CHAR **arglist = (CHAR **)(argv);
+
+ /* move all preceding non-option arguments to the right ...
+ */
+ do arglist[optmark] = arglist[optmark - 1];
+ while( optmark-- > optbase );
+
+ /* reinstate the `--' marker, in its permuted location.
+ */
+ arglist[optbase] = this_arg;
+ }
+ /* ... before finally bumping `optbase' past the `--' marker,
+ * and returning the `all done' completion indicator.
+ */
+ optind = ++optbase;
+ return getopt_all_done;
+ }
+ }
+ else if( mode < getopt_mode_long_only )
+ {
+ /* it's not an explicit long option, and `getopt_long_only' isn't active,
+ * so we must explicitly try to match it as a short option.
+ */
+ mode = getopt_mode_standard;
+ }
+
+ if( mode >= getopt_mode_long )
+ {
+ /* the current argument is a long form option, (either explicitly,
+ * introduced by a double hyphen, or implicitly because we were called
+ * by `getopt_long_only'); this is where we parse it.
+ */
+ int lookup;
+ int matched = -1;
+
+ /* we need to fetch the `extra' function arguments, which are
+ * specified for the `getopt_long' APIs.
+ */
+ va_list refptr;
+ struct option *longopts;
+ int *optindex;
+ va_start( refptr, optstring );
+ longopts = va_arg( refptr, struct option * );
+ optindex = va_arg( refptr, int * );
+ va_end( refptr );
+
+ /* ensuring that `optarg' does not inherit any junk, from parsing
+ * preceding arguments ...
+ */
+ optarg = NULL;
+ for( lookup = 0; longopts && longopts[lookup].name; ++lookup )
+ {
+ /* scan the list of defined long form options ...
+ */
+ switch( getopt_match_long( nextchar, longopts[lookup].name ) )
+ {
+ /* looking for possible matches for the current argument.
+ */
+ case getopt_exact_match:
+ /*
+ * when an exact match is found,
+ * return it immediately, setting `nextchar' to NULL,
+ * to ensure we don't mistakenly try to match any
+ * subsequent characters as short form options.
+ */
+ nextchar = NULL;
+ return getopt_resolved( mode, argc, argv, &argind,
+ longopts, lookup, optindex, optstring );
+
+ case getopt_abbreviated_match:
+ /*
+ * but, for a partial (initial substring) match ...
+ */
+ if( matched >= 0 )
+ {
+ /* if this is not the first, then we have an ambiguity ...
+ */
+ if( (mode == getopt_mode_long_only)
+ /*
+ * However, in the case of getopt_long_only(), if
+ * the entire ambiguously matched string represents
+ * a valid short option specification, then we may
+ * proceed to interpret it as such.
+ */
+ && getopt_verify( nextchar, optstring ) )
+ return getopt_parse( mode, argc, argv, optstring );
+
+ /* If we get to here, then the ambiguously matched
+ * partial long option isn't valid for short option
+ * evaluation; reset parser context to resume with
+ * the following command line argument, diagnose
+ * ambiguity, and bail out.
+ */
+ optopt = 0;
+ nextchar = NULL;
+ optind = argind + 1;
+ complain( "option `%s' is ambiguous", argv[argind] );
+ return getopt_unknown;
+ }
+ /* otherwise just note that we've found a possible match ...
+ */
+ matched = lookup;
+ }
+ }
+ if( matched >= 0 )
+ {
+ /* if we get to here, then we found exactly one partial match,
+ * so return it, as for an exact match.
+ */
+ nextchar = NULL;
+ return getopt_resolved( mode, argc, argv, &argind,
+ longopts, matched, optindex, optstring );
+ }
+ /* if here, then we had what SHOULD have been a long form option,
+ * but it is unmatched ...
+ */
+ if( (mode < getopt_mode_long_only)
+ /*
+ * ... although paradoxically, `mode == getopt_mode_long_only'
+ * allows us to still try to match it as a short form option.
+ */
+ || (getopt_verify( nextchar, optstring ) == 0) )
+ {
+ /* When it cannot be matched, reset the parsing context to
+ * resume from the next argument, diagnose the failed match,
+ * and bail out.
+ */
+ optopt = 0;
+ nextchar = NULL;
+ optind = argind + 1;
+ complain( "unrecognised option `%s'", argv[argind] );
+ return getopt_unknown;
+ }
+ }
+ /* fall through to handle standard short form options...
+ * when the option argument format is neither explictly identified
+ * as long, nor implicitly matched as such, and the argument isn't
+ * just a bare hyphen, (which isn't an option), then we make one
+ * recursive call to explicitly interpret it as short format.
+ */
+ if( *nextchar )
+ return getopt_parse( mode, argc, argv, optstring );
+ }
+ /* if we get to here, then we've parsed a non-option argument ...
+ * in GNU compatibility mode, we step over it, so we can permute
+ * any subsequent option arguments, but ...
+ */
+ if( *optstring == getopt_switchar )
+ {
+ /* if `optstring' begins with a `-' character, this special
+ * GNU specific behaviour requires us to return the non-option
+ * arguments in strict order, as pseudo-arguments to a special
+ * option, with return value defined as `getopt_ordered'.
+ */
+ nextchar = NULL;
+ optind = argind + 1;
+ optarg = argv[argind];
+ return getopt_ordered;
+ }
+ if( getopt_conventions( *optstring ) & getopt_posixly_correct )
+ /*
+ * otherwise ...
+ * for POSIXLY_CORRECT behaviour, or if `optstring' begins with
+ * a `+' character, then we break out of the parsing loop, so that
+ * the scan ends at the current argument, with no permutation.
+ */
+ break;
+ }
+ /* fall through when all arguments have been evaluated,
+ */
+ optind = optbase;
+ return getopt_all_done;
+}
+
+/* All three public API entry points are trivially defined,
+ * in terms of the internal `getopt_parse' function.
+ */
+int getopt( getopt_std_args )
+{
+ return getopt_parse( getopt_mode_standard, argc, argv, optstring );
+}
+
+int getopt_long( getopt_std_args, const struct option *opts, int *index )
+{
+ return getopt_parse( getopt_mode_long, argc, argv, optstring, opts, index );
+}
+
+int getopt_long_only( getopt_std_args, const struct option *opts, int *index )
+{
+ return getopt_parse( getopt_mode_long_only, argc, argv, optstring, opts, index );
+}
+
+#ifdef __weak_alias
+/*
+ * These Microsnot style uglified aliases are provided for compatibility
+ * with the previous MinGW implementation of the getopt API.
+ */
+__weak_alias( getopt, _getopt )
+__weak_alias( getopt_long, _getopt_long )
+__weak_alias( getopt_long_only, _getopt_long_only )
+#endif
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */