From de467b38d6976ea55c7d0b5ae5effe0a0d54d57d Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Thu, 10 Oct 2013 21:53:28 -0700 Subject: [PATCH] Added AC3 decoder to FFMPEG plugin --- .../FFMPEG/FFMPEG.xcodeproj/project.pbxproj | 100 ++ Frameworks/FFMPEG/ffmpeg-minimal/config.h | 16 +- .../libavcodec/aac_ac3_parser.c | 104 ++ .../libavcodec/aac_ac3_parser.h | 66 + .../FFMPEG/ffmpeg-minimal/libavcodec/ac3.c | 231 +++ .../FFMPEG/ffmpeg-minimal/libavcodec/ac3.h | 181 ++ .../ffmpeg-minimal/libavcodec/ac3_parser.c | 194 +++ .../ffmpeg-minimal/libavcodec/ac3_parser.h | 41 + .../FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.c | 1491 +++++++++++++++++ .../FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.h | 241 +++ .../ffmpeg-minimal/libavcodec/ac3dec_data.c | 60 + .../ffmpeg-minimal/libavcodec/ac3dec_data.h | 32 + .../FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.c | 263 +++ .../FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.h | 144 ++ .../FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.c | 314 ++++ .../FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.h | 73 + .../ffmpeg-minimal/libavcodec/eac3_data.c | 1134 +++++++++++++ .../ffmpeg-minimal/libavcodec/eac3_data.h | 36 + .../ffmpeg-minimal/libavcodec/eac3dec.c | 607 +++++++ .../FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.c | 47 + .../FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.h | 35 + .../libavcodec/x86/ac3dsp_init.c | 231 +++ .../ffmpeg-minimal/libavformat/ac3dec.c | 123 ++ .../FFMPEG/ffmpeg-minimal/libavutil/lfg.c | 102 ++ .../FFMPEG/ffmpeg-minimal/libavutil/lfg.h | 62 + .../FFMPEG/ffmpeg-minimal/libavutil/md5.c | 236 +++ .../FFMPEG/ffmpeg-minimal/libavutil/md5.h | 81 + Frameworks/TagLib/taglib/taglib/fileref.cpp | 3 +- Plugins/FFMPEG/FFMPEGDecoder.m | 4 +- Plugins/TagLib/TagLibMetadataReader.m | 4 +- 30 files changed, 6246 insertions(+), 10 deletions(-) create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3dec.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/x86/ac3dsp_init.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavformat/ac3dec.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.h create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.c create mode 100644 Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.h diff --git a/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj b/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj index e59f9093b..780291eab 100644 --- a/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj +++ b/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj @@ -306,6 +306,31 @@ 833C37D718032EA500CBA602 /* idct_xvid.h in Headers */ = {isa = PBXBuildFile; fileRef = 833C37D618032EA500CBA602 /* idct_xvid.h */; }; 8384904D1807898200E7332D /* apedec.c in Sources */ = {isa = PBXBuildFile; fileRef = 8384904C1807898200E7332D /* apedec.c */; }; 8384904F1807898A00E7332D /* ape.c in Sources */ = {isa = PBXBuildFile; fileRef = 8384904E1807898A00E7332D /* ape.c */; }; + 8384905C1807AF0100E7332D /* ac3_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490501807AF0100E7332D /* ac3_parser.c */; }; + 8384905D1807AF0100E7332D /* ac3_parser.h in Headers */ = {isa = PBXBuildFile; fileRef = 838490511807AF0100E7332D /* ac3_parser.h */; }; + 8384905E1807AF0100E7332D /* ac3.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490521807AF0100E7332D /* ac3.c */; }; + 8384905F1807AF0100E7332D /* ac3.h in Headers */ = {isa = PBXBuildFile; fileRef = 838490531807AF0100E7332D /* ac3.h */; }; + 838490601807AF0100E7332D /* ac3dec_data.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490541807AF0100E7332D /* ac3dec_data.c */; }; + 838490611807AF0100E7332D /* ac3dec_data.h in Headers */ = {isa = PBXBuildFile; fileRef = 838490551807AF0100E7332D /* ac3dec_data.h */; }; + 838490621807AF0100E7332D /* ac3dec.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490561807AF0100E7332D /* ac3dec.c */; }; + 838490631807AF0100E7332D /* ac3dec.h in Headers */ = {isa = PBXBuildFile; fileRef = 838490571807AF0100E7332D /* ac3dec.h */; }; + 838490641807AF0100E7332D /* ac3dsp.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490581807AF0100E7332D /* ac3dsp.c */; }; + 838490651807AF0100E7332D /* ac3dsp.h in Headers */ = {isa = PBXBuildFile; fileRef = 838490591807AF0100E7332D /* ac3dsp.h */; }; + 838490661807AF0100E7332D /* ac3tab.c in Sources */ = {isa = PBXBuildFile; fileRef = 8384905A1807AF0100E7332D /* ac3tab.c */; }; + 838490671807AF0100E7332D /* ac3tab.h in Headers */ = {isa = PBXBuildFile; fileRef = 8384905B1807AF0100E7332D /* ac3tab.h */; }; + 838490691807AF5800E7332D /* ac3dec.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490681807AF5800E7332D /* ac3dec.c */; }; + 8384906C1807AFB800E7332D /* aac_ac3_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = 8384906A1807AFB800E7332D /* aac_ac3_parser.c */; }; + 8384906D1807AFB800E7332D /* aac_ac3_parser.h in Headers */ = {isa = PBXBuildFile; fileRef = 8384906B1807AFB800E7332D /* aac_ac3_parser.h */; }; + 838490701807B04200E7332D /* lfg.c in Sources */ = {isa = PBXBuildFile; fileRef = 8384906E1807B04200E7332D /* lfg.c */; }; + 838490711807B04200E7332D /* lfg.h in Headers */ = {isa = PBXBuildFile; fileRef = 8384906F1807B04200E7332D /* lfg.h */; }; + 838490741807B07000E7332D /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490721807B07000E7332D /* md5.c */; }; + 838490751807B07000E7332D /* md5.h in Headers */ = {isa = PBXBuildFile; fileRef = 838490731807B07000E7332D /* md5.h */; }; + 838490781807B13000E7332D /* kbdwin.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490761807B13000E7332D /* kbdwin.c */; }; + 838490791807B13000E7332D /* kbdwin.h in Headers */ = {isa = PBXBuildFile; fileRef = 838490771807B13000E7332D /* kbdwin.h */; }; + 8384907F1807B17500E7332D /* eac3_data.c in Sources */ = {isa = PBXBuildFile; fileRef = 8384907A1807B17500E7332D /* eac3_data.c */; }; + 838490801807B17500E7332D /* eac3_data.h in Headers */ = {isa = PBXBuildFile; fileRef = 8384907B1807B17500E7332D /* eac3_data.h */; }; + 838490811807B17500E7332D /* eac3dec.c in Sources */ = {isa = PBXBuildFile; fileRef = 8384907C1807B17500E7332D /* eac3dec.c */; }; + 838490851807B17C00E7332D /* ac3dsp_init.c in Sources */ = {isa = PBXBuildFile; fileRef = 838490841807B17C00E7332D /* ac3dsp_init.c */; }; 8393B7E218052BB000913C76 /* mp3dec.c in Sources */ = {isa = PBXBuildFile; fileRef = 8393B7DF18052BB000913C76 /* mp3dec.c */; }; 8393B7E318052BB000913C76 /* mpeg.c in Sources */ = {isa = PBXBuildFile; fileRef = 8393B7E018052BB000913C76 /* mpeg.c */; }; 8393B7E418052BB000913C76 /* mpeg.h in Headers */ = {isa = PBXBuildFile; fileRef = 8393B7E118052BB000913C76 /* mpeg.h */; }; @@ -643,6 +668,31 @@ 833C37D618032EA500CBA602 /* idct_xvid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = idct_xvid.h; sourceTree = ""; }; 8384904C1807898200E7332D /* apedec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = apedec.c; sourceTree = ""; }; 8384904E1807898A00E7332D /* ape.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ape.c; sourceTree = ""; }; + 838490501807AF0100E7332D /* ac3_parser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3_parser.c; sourceTree = ""; }; + 838490511807AF0100E7332D /* ac3_parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ac3_parser.h; sourceTree = ""; }; + 838490521807AF0100E7332D /* ac3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3.c; sourceTree = ""; }; + 838490531807AF0100E7332D /* ac3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ac3.h; sourceTree = ""; }; + 838490541807AF0100E7332D /* ac3dec_data.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3dec_data.c; sourceTree = ""; }; + 838490551807AF0100E7332D /* ac3dec_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ac3dec_data.h; sourceTree = ""; }; + 838490561807AF0100E7332D /* ac3dec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3dec.c; sourceTree = ""; }; + 838490571807AF0100E7332D /* ac3dec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ac3dec.h; sourceTree = ""; }; + 838490581807AF0100E7332D /* ac3dsp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3dsp.c; sourceTree = ""; }; + 838490591807AF0100E7332D /* ac3dsp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ac3dsp.h; sourceTree = ""; }; + 8384905A1807AF0100E7332D /* ac3tab.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3tab.c; sourceTree = ""; }; + 8384905B1807AF0100E7332D /* ac3tab.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ac3tab.h; sourceTree = ""; }; + 838490681807AF5800E7332D /* ac3dec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3dec.c; sourceTree = ""; }; + 8384906A1807AFB800E7332D /* aac_ac3_parser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aac_ac3_parser.c; sourceTree = ""; }; + 8384906B1807AFB800E7332D /* aac_ac3_parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aac_ac3_parser.h; sourceTree = ""; }; + 8384906E1807B04200E7332D /* lfg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lfg.c; sourceTree = ""; }; + 8384906F1807B04200E7332D /* lfg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lfg.h; sourceTree = ""; }; + 838490721807B07000E7332D /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = ""; }; + 838490731807B07000E7332D /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; + 838490761807B13000E7332D /* kbdwin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = kbdwin.c; sourceTree = ""; }; + 838490771807B13000E7332D /* kbdwin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = kbdwin.h; sourceTree = ""; }; + 8384907A1807B17500E7332D /* eac3_data.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = eac3_data.c; sourceTree = ""; }; + 8384907B1807B17500E7332D /* eac3_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = eac3_data.h; sourceTree = ""; }; + 8384907C1807B17500E7332D /* eac3dec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = eac3dec.c; sourceTree = ""; }; + 838490841807B17C00E7332D /* ac3dsp_init.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ac3dsp_init.c; sourceTree = ""; }; 8393B7DF18052BB000913C76 /* mp3dec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mp3dec.c; sourceTree = ""; }; 8393B7E018052BB000913C76 /* mpeg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mpeg.c; sourceTree = ""; }; 8393B7E118052BB000913C76 /* mpeg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mpeg.h; sourceTree = ""; }; @@ -755,6 +805,25 @@ 830F0B8E17FC4FB900042E8F /* libavcodec */ = { isa = PBXGroup; children = ( + 8384907A1807B17500E7332D /* eac3_data.c */, + 8384907B1807B17500E7332D /* eac3_data.h */, + 8384907C1807B17500E7332D /* eac3dec.c */, + 838490761807B13000E7332D /* kbdwin.c */, + 838490771807B13000E7332D /* kbdwin.h */, + 8384906A1807AFB800E7332D /* aac_ac3_parser.c */, + 8384906B1807AFB800E7332D /* aac_ac3_parser.h */, + 838490501807AF0100E7332D /* ac3_parser.c */, + 838490511807AF0100E7332D /* ac3_parser.h */, + 838490521807AF0100E7332D /* ac3.c */, + 838490531807AF0100E7332D /* ac3.h */, + 838490541807AF0100E7332D /* ac3dec_data.c */, + 838490551807AF0100E7332D /* ac3dec_data.h */, + 838490561807AF0100E7332D /* ac3dec.c */, + 838490571807AF0100E7332D /* ac3dec.h */, + 838490581807AF0100E7332D /* ac3dsp.c */, + 838490591807AF0100E7332D /* ac3dsp.h */, + 8384905A1807AF0100E7332D /* ac3tab.c */, + 8384905B1807AF0100E7332D /* ac3tab.h */, 8384904C1807898200E7332D /* apedec.c */, 8393B81518052E9900913C76 /* mpegaudiodsp_fixed.c */, 8393B81318052E7400913C76 /* mpegaudiodsp.c */, @@ -929,6 +998,7 @@ 830F0BAD17FC4FB900042E8F /* libavformat */ = { isa = PBXGroup; children = ( + 838490681807AF5800E7332D /* ac3dec.c */, 8384904E1807898A00E7332D /* ape.c */, 8393B7DF18052BB000913C76 /* mp3dec.c */, 8393B7E018052BB000913C76 /* mpeg.c */, @@ -1001,6 +1071,10 @@ 830F0BBA17FC4FB900042E8F /* libavutil */ = { isa = PBXGroup; children = ( + 838490721807B07000E7332D /* md5.c */, + 838490731807B07000E7332D /* md5.h */, + 8384906E1807B04200E7332D /* lfg.c */, + 8384906F1807B04200E7332D /* lfg.h */, 83BCB8DF17FCA64400760340 /* avconfig.h */, 83BCB8E017FCA64400760340 /* timecode.c */, 83BCB8E117FCA64400760340 /* timecode.h */, @@ -1123,6 +1197,7 @@ 830F0D0717FC80B400042E8F /* x86 */ = { isa = PBXGroup; children = ( + 838490841807B17C00E7332D /* ac3dsp_init.c */, 8393B80D18052BD500913C76 /* mpegaudiodsp.c */, 833C37D618032EA500CBA602 /* idct_xvid.h */, 833C37D218032E4800CBA602 /* dsputil_init.c */, @@ -1198,6 +1273,7 @@ 8393B7FF18052BC200913C76 /* mpegaudiodata.h in Headers */, 830F0CD417FC7F1E00042E8F /* dct32.h in Headers */, 830F0CCF17FC7F1E00042E8F /* copy_block.h in Headers */, + 838490801807B17500E7332D /* eac3_data.h in Headers */, 830F0D9317FC8EAC00042E8F /* dvdata.h in Headers */, 830F0CEA17FC7F1E00042E8F /* imgconvert.h in Headers */, 8393B7FB18052BC200913C76 /* mpegaudio_tablegen.h in Headers */, @@ -1207,6 +1283,8 @@ 830F0D1417FC815000042E8F /* constants.h in Headers */, 830F0C7717FC7DCB00042E8F /* avstring.h in Headers */, 830F0BF917FC4FB900042E8F /* os_support.h in Headers */, + 8384906D1807AFB800E7332D /* aac_ac3_parser.h in Headers */, + 838490611807AF0100E7332D /* ac3dec_data.h in Headers */, 830F0D2217FC82AB00042E8F /* eval.h in Headers */, 830F0C2A17FC54F800042E8F /* rtpdec.h in Headers */, 830F0CFF17FC7F1E00042E8F /* wma.h in Headers */, @@ -1225,6 +1303,7 @@ 830F0C7217FC7DB100042E8F /* rc4.h in Headers */, 830F0C2517FC527400042E8F /* bswap.h in Headers */, 833C379F18032A2700CBA602 /* unary.h in Headers */, + 8384905F1807AF0100E7332D /* ac3.h in Headers */, 830F0CDD17FC7F1E00042E8F /* faandct.h in Headers */, 830F0D0B17FC80B400042E8F /* lsp_mips.h in Headers */, 830F0C2B17FC54F800042E8F /* srtp.h in Headers */, @@ -1235,7 +1314,9 @@ 830F0D3D17FC846C00042E8F /* random_seed.h in Headers */, 830F0CCA17FC7F1E00042E8F /* bytestream.h in Headers */, 830F0D0317FC7F4000042E8F /* sinewin_tablegen.h in Headers */, + 838490651807AF0100E7332D /* ac3dsp.h in Headers */, 833C37C518032CF600CBA602 /* dirac_dwt.h in Headers */, + 838490751807B07000E7332D /* md5.h in Headers */, 830F0CDF17FC7F1E00042E8F /* faanidct.h in Headers */, 830F0DD217FC934D00042E8F /* spdif.h in Headers */, 830F0BDE17FC4FB900042E8F /* parser.h in Headers */, @@ -1251,7 +1332,9 @@ 830F0CF517FC7F1E00042E8F /* rdft.h in Headers */, 830F0D1F17FC82AB00042E8F /* cpu_internal.h in Headers */, 830F0C1A17FC523000042E8F /* rtp.h in Headers */, + 838490711807B04200E7332D /* lfg.h in Headers */, 830F0D8817FC8E8B00042E8F /* aac_tablegen_decl.h in Headers */, + 838490671807AF0100E7332D /* ac3tab.h in Headers */, 830F0BE917FC4FB900042E8F /* wmaprodata.h in Headers */, 830F0C4917FC7CA300042E8F /* asf.h in Headers */, 830F0DCA17FC931700042E8F /* pcm.h in Headers */, @@ -1260,6 +1343,7 @@ 830F0BD717FC4FB900042E8F /* get_bits.h in Headers */, 830F0C2417FC527400042E8F /* atomic.h in Headers */, 830F0C5D17FC7CEA00042E8F /* id3v1.h in Headers */, + 838490631807AF0100E7332D /* ac3dec.h in Headers */, 830F0C6A17FC7DB100042E8F /* avassert.h in Headers */, 830F0D6D17FC8C0700042E8F /* aactab.h in Headers */, 830F0BEC17FC4FB900042E8F /* wmavoice_data.h in Headers */, @@ -1308,6 +1392,7 @@ 830F0D8A17FC8E8B00042E8F /* aacps.h in Headers */, 833C37C818032CF600CBA602 /* dirac.h in Headers */, 830F0BD617FC4FB900042E8F /* fft.h in Headers */, + 838490791807B13000E7332D /* kbdwin.h in Headers */, 830F0CE317FC7F1E00042E8F /* frame_thread_encoder.h in Headers */, 830F0BE617FC4FB900042E8F /* wmadata.h in Headers */, 830F0C5717FC7CC300042E8F /* avlanguage.h in Headers */, @@ -1322,6 +1407,7 @@ 830F0CC517FC7F1E00042E8F /* acelp_pitch_delay.h in Headers */, 830F0D8F17FC8E8B00042E8F /* sbrdsp.h in Headers */, 830F0CCE17FC7F1E00042E8F /* celp_math.h in Headers */, + 8384905D1807AF0100E7332D /* ac3_parser.h in Headers */, 833C37B718032AEF00CBA602 /* dsputil_x86.h in Headers */, 830F0CFA17FC7F1E00042E8F /* sinewin.h in Headers */, 830F0CC717FC7F1E00042E8F /* acelp_vectors.h in Headers */, @@ -1392,6 +1478,7 @@ buildActionMask = 2147483647; files = ( 833C37A918032AAD00CBA602 /* img2.c in Sources */, + 838490701807B04200E7332D /* lfg.c in Sources */, 830F0D6717FC8A3300042E8F /* options.c in Sources */, 830F0DAF17FC8FBD00042E8F /* fmtconvert_init.c in Sources */, 830F0DD617FC93E400042E8F /* xwma.c in Sources */, @@ -1406,6 +1493,7 @@ 830F0D5A17FC893E00042E8F /* rawdec.c in Sources */, 830F0DAE17FC8FBD00042E8F /* fft_init.c in Sources */, 830F0D2F17FC841B00042E8F /* error.c in Sources */, + 838490781807B13000E7332D /* kbdwin.c in Sources */, 830F0BDB17FC4FB900042E8F /* mdct.c in Sources */, 833C37A618032A5000CBA602 /* apetag.c in Sources */, 830F0D5817FC893E00042E8F /* bitstream.c in Sources */, @@ -1414,10 +1502,12 @@ 830F0DCD17FC933100042E8F /* w64.c in Sources */, 833C37D518032E7000CBA602 /* jrevdct.c in Sources */, 830F0BE217FC4FB900042E8F /* utils.c in Sources */, + 838490741807B07000E7332D /* md5.c in Sources */, 8393B80E18052BD500913C76 /* mpegaudiodsp.c in Sources */, 8393B81418052E7400913C76 /* mpegaudiodsp.c in Sources */, 830F0CF917FC7F1E00042E8F /* sinewin.c in Sources */, 833C37C418032CF600CBA602 /* dirac_dwt.c in Sources */, + 838490851807B17C00E7332D /* ac3dsp_init.c in Sources */, 830F0CE417FC7F1E00042E8F /* h264chroma_template.c in Sources */, 830F0BEF17FC4FB900042E8F /* asf.c in Sources */, 830F0BD517FC4FB900042E8F /* fft.c in Sources */, @@ -1431,6 +1521,7 @@ 830F0CE217FC7F1E00042E8F /* frame_thread_encoder.c in Sources */, 8393B80118052BC200913C76 /* mpegaudiodec.c in Sources */, 830F0C3817FC554D00042E8F /* buffer.c in Sources */, + 8384905C1807AF0100E7332D /* ac3_parser.c in Sources */, 830F0C6B17FC7DB100042E8F /* bprint.c in Sources */, 830F0BE017FC4FB900042E8F /* simple_idct.c in Sources */, 830F0D6917FC8A3D00042E8F /* avpicture.c in Sources */, @@ -1438,6 +1529,7 @@ 830F0CDA17FC7F1E00042E8F /* error_resilience.c in Sources */, 830F0D3317FC841B00042E8F /* opt.c in Sources */, 830F0D7317FC8C1300042E8F /* astdec.c in Sources */, + 8384905E1807AF0100E7332D /* ac3.c in Sources */, 830F0D5317FC891800042E8F /* file_open.c in Sources */, 833C379D180328B300CBA602 /* takdec.c in Sources */, 830F0D7B17FC8E2400042E8F /* avidec.c in Sources */, @@ -1455,6 +1547,8 @@ 830F0D1317FC815000042E8F /* constants.c in Sources */, 830F0BE417FC4FB900042E8F /* wma_common.c in Sources */, 8393B7FA18052BC200913C76 /* mpegaudio_tablegen.c in Sources */, + 838490601807AF0100E7332D /* ac3dec_data.c in Sources */, + 8384907F1807B17500E7332D /* eac3_data.c in Sources */, 830F0C5617FC7CC300042E8F /* avlanguage.c in Sources */, 830F0C5117FC7CA300042E8F /* riffdec.c in Sources */, 830F0D4617FC85ED00042E8F /* integer.c in Sources */, @@ -1476,10 +1570,12 @@ 830F0D2117FC82AB00042E8F /* eval.c in Sources */, 830F0C2317FC527400042E8F /* atomic.c in Sources */, 830F0D4D17FC862400042E8F /* time.c in Sources */, + 838490661807AF0100E7332D /* ac3tab.c in Sources */, 830F0C0817FC4FB900042E8F /* mem.c in Sources */, 830F0CDE17FC7F1E00042E8F /* faanidct.c in Sources */, 833C379B180328B300CBA602 /* tak.c in Sources */, 830F0CC917FC7F1E00042E8F /* bit_depth_template.c in Sources */, + 8384906C1807AFB800E7332D /* aac_ac3_parser.c in Sources */, 8393B7E318052BB000913C76 /* mpeg.c in Sources */, 830F0D4017FC848D00042E8F /* sha.c in Sources */, 830F0BF417FC4FB900042E8F /* aviobuf.c in Sources */, @@ -1487,6 +1583,7 @@ 830F0DC617FC92FA00042E8F /* wavdec.c in Sources */, 830F0BDA17FC4FB900042E8F /* mathtables.c in Sources */, 830F0C5917FC7CC300042E8F /* utils.c in Sources */, + 838490641807AF0100E7332D /* ac3dsp.c in Sources */, 830F0CDC17FC7F1E00042E8F /* faandct.c in Sources */, 830F0CE017FC7F1E00042E8F /* fmtconvert.c in Sources */, 830F0C6F17FC7DB100042E8F /* pixdesc.c in Sources */, @@ -1510,6 +1607,7 @@ 830F0CFC17FC7F1E00042E8F /* videodsp.c in Sources */, 830F0D8C17FC8E8B00042E8F /* dv_profile.c in Sources */, 833C37B118032AEF00CBA602 /* diracdsp.c in Sources */, + 838490691807AF5800E7332D /* ac3dec.c in Sources */, 830F0CD017FC7F1E00042E8F /* dct.c in Sources */, 833C3795180328A300CBA602 /* takdec.c in Sources */, 830F0DC217FC929E00042E8F /* mux.c in Sources */, @@ -1532,10 +1630,12 @@ 8393B7FC18052BC200913C76 /* mpegaudio.c in Sources */, 833C37C618032CF600CBA602 /* dirac_parser.c in Sources */, 830F0CED17FC7F1E00042E8F /* mpeg12data.c in Sources */, + 838490811807B17500E7332D /* eac3dec.c in Sources */, 833C37C718032CF600CBA602 /* dirac.c in Sources */, 830F0D7E17FC8E4800042E8F /* dv.c in Sources */, 830F0C7B17FC7E4E00042E8F /* crc.c in Sources */, 830F0BE817FC4FB900042E8F /* wmalosslessdec.c in Sources */, + 838490621807AF0100E7332D /* ac3dec.c in Sources */, 83BCB8E317FCA64400760340 /* timecode.c in Sources */, 8393B80B18052BC200913C76 /* mpegaudioenc.c in Sources */, 830F0D3517FC841B00042E8F /* samplefmt.c in Sources */, diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/config.h b/Frameworks/FFMPEG/ffmpeg-minimal/config.h index 5f1612d5b..19e7c33f6 100644 --- a/Frameworks/FFMPEG/ffmpeg-minimal/config.h +++ b/Frameworks/FFMPEG/ffmpeg-minimal/config.h @@ -8,6 +8,11 @@ #define ARCH_ALPHA 0 #define ARCH_BFIN 0 #define ARCH_SH4 0 +#define ARCH_MIPS 0 + +#define HAVE_BIGENDIAN 0 +#define HAVE_FAST_UNALIGNED 1 + #define HAVE_VIS 0 #define TUNECPU generic @@ -18,6 +23,7 @@ #define HAVE_SSSE3_EXTERNAL 0 #define HAVE_SSE4_EXTERNAL 0 #define emms_c() +#define HAVE_MMX_EXTERNAL 0 #define HAVE_MMX2 0 #define HAVE_MMXEXT 0 #define HAVE_MMXEXT_EXTERNAL 0 @@ -382,7 +388,7 @@ #define CONFIG_AAC_DECODER 0 #define CONFIG_AAC_LATM_DECODER 0 #define CONFIG_AC3_ENCODER 0 -#define CONFIG_AC3_DECODER 0 +#define CONFIG_AC3_DECODER 1 #define CONFIG_AC3_FIXED_ENCODER 0 #define CONFIG_ALAC_ENCODER 0 #define CONFIG_ALAC_DECODER 0 @@ -400,7 +406,7 @@ #define CONFIG_DCA_DECODER 0 #define CONFIG_DSICINAUDIO_DECODER 0 #define CONFIG_EAC3_ENCODER 0 -#define CONFIG_EAC3_DECODER 0 +#define CONFIG_EAC3_DECODER 1 #define CONFIG_EVRC_DECODER 0 #define CONFIG_FFWAVESYNTH_DECODER 0 #define CONFIG_FLAC_ENCODER 0 @@ -651,7 +657,7 @@ #define CONFIG_AAC_PARSER 0 #define CONFIG_AAC_LATM_PARSER 0 -#define CONFIG_AC3_PARSER 0 +#define CONFIG_AC3_PARSER 1 #define CONFIG_ADX_PARSER 0 #define CONFIG_BMP_PARSER 0 #define CONFIG_CAVSVIDEO_PARSER 0 @@ -700,7 +706,7 @@ #define CONFIG_A64_MUXER 0 #define CONFIG_AAC_DEMUXER 0 #define CONFIG_AC3_MUXER 0 -#define CONFIG_AC3_DEMUXER 0 +#define CONFIG_AC3_DEMUXER 1 #define CONFIG_ACT_DEMUXER 0 #define CONFIG_ADF_DEMUXER 0 #define CONFIG_ADP_DEMUXER 0 @@ -769,7 +775,7 @@ #define CONFIG_EA_DEMUXER 0 #define CONFIG_EA_CDATA_DEMUXER 0 #define CONFIG_EAC3_MUXER 0 -#define CONFIG_EAC3_DEMUXER 0 +#define CONFIG_EAC3_DEMUXER 1 #define CONFIG_EPAF_DEMUXER 0 #define CONFIG_F4V_MUXER 0 #define CONFIG_FFM_MUXER 0 diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.c new file mode 100644 index 000000000..6f1e188c2 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.c @@ -0,0 +1,104 @@ +/* + * Common AAC and AC-3 parser + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "parser.h" +#include "aac_ac3_parser.h" + +int ff_aac_ac3_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + AACAC3ParseContext *s = s1->priv_data; + ParseContext *pc = &s->pc; + int len, i; + int new_frame_start; + +get_next: + i=END_NOT_FOUND; + if(s->remaining_size <= buf_size){ + if(s->remaining_size && !s->need_next_header){ + i= s->remaining_size; + s->remaining_size = 0; + }else{ //we need a header first + len=0; + for(i=s->remaining_size; istate = (s->state<<8) + buf[i]; + if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start))) + break; + } + if(len<=0){ + i=END_NOT_FOUND; + }else{ + s->state=0; + i-= s->header_size -1; + s->remaining_size = len; + if(!new_frame_start || pc->index+i<=0){ + s->remaining_size += i; + goto get_next; + } + } + } + } + + if(ff_combine_frame(pc, i, &buf, &buf_size)<0){ + s->remaining_size -= FFMIN(s->remaining_size, buf_size); + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + + /* update codec info */ + if(s->codec_id) + avctx->codec_id = s->codec_id; + + /* Due to backwards compatible HE-AAC the sample rate, channel count, + and total number of samples found in an AAC ADTS header are not + reliable. Bit rate is still accurate because the total frame duration in + seconds is still correct (as is the number of bits in the frame). */ + if (avctx->codec_id != AV_CODEC_ID_AAC) { + avctx->sample_rate = s->sample_rate; + + /* allow downmixing to stereo (or mono for AC-3) */ + if(avctx->request_channels > 0 && + avctx->request_channels < s->channels && + (avctx->request_channels <= 2 || + (avctx->request_channels == 1 && + (avctx->codec_id == AV_CODEC_ID_AC3 || + avctx->codec_id == AV_CODEC_ID_EAC3)))) { + avctx->channels = avctx->request_channels; + } else { + avctx->channels = s->channels; + avctx->channel_layout = s->channel_layout; + } + s1->duration = s->samples; + avctx->audio_service_type = s->service_type; + } + + avctx->bit_rate = s->bit_rate; + + return i; +} diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.h new file mode 100644 index 000000000..c2506a5bf --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/aac_ac3_parser.h @@ -0,0 +1,66 @@ +/* + * Common AAC and AC-3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AAC_AC3_PARSER_H +#define AVCODEC_AAC_AC3_PARSER_H + +#include +#include "avcodec.h" +#include "parser.h" + +typedef enum { + AAC_AC3_PARSE_ERROR_SYNC = -0x1030c0a, + AAC_AC3_PARSE_ERROR_BSID = -0x2030c0a, + AAC_AC3_PARSE_ERROR_SAMPLE_RATE = -0x3030c0a, + AAC_AC3_PARSE_ERROR_FRAME_SIZE = -0x4030c0a, + AAC_AC3_PARSE_ERROR_FRAME_TYPE = -0x5030c0a, + AAC_AC3_PARSE_ERROR_CRC = -0x6030c0a, + AAC_AC3_PARSE_ERROR_CHANNEL_CFG = -0x7030c0a, +} AACAC3ParseError; + +typedef struct AACAC3ParseContext { + ParseContext pc; + int frame_size; + int header_size; + int (*sync)(uint64_t state, struct AACAC3ParseContext *hdr_info, + int *need_next_header, int *new_frame_start); + + int channels; + int sample_rate; + int bit_rate; + int samples; + uint64_t channel_layout; + int service_type; + + int remaining_size; + uint64_t state; + + int need_next_header; + enum AVCodecID codec_id; +} AACAC3ParseContext; + +int ff_aac_ac3_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size); + +#endif /* AVCODEC_AAC_AC3_PARSER_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.c new file mode 100644 index 000000000..29e132f5d --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.c @@ -0,0 +1,231 @@ +/* + * Common code between the AC-3 encoder and decoder + * Copyright (c) 2000 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Common code between the AC-3 encoder and decoder. + */ + +#include "avcodec.h" +#include "ac3.h" +#include "get_bits.h" + +/** + * Starting frequency coefficient bin for each critical band. + */ +const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 31, + 34, 37, 40, 43, 46, 49, 55, 61, 67, 73, + 79, 85, 97, 109, 121, 133, 157, 181, 205, 229, 253 +}; + +#if CONFIG_HARDCODED_TABLES + +/** + * Map each frequency coefficient bin to the critical band that contains it. + */ +const uint8_t ff_ac3_bin_to_band_tab[253] = { + 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30, + 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, + 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, + 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, + 39, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40, + 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 +}; + +#else /* CONFIG_HARDCODED_TABLES */ +uint8_t ff_ac3_bin_to_band_tab[253]; +#endif + +static inline int calc_lowcomp1(int a, int b0, int b1, int c) +{ + if ((b0 + 256) == b1) { + a = c; + } else if (b0 > b1) { + a = FFMAX(a - 64, 0); + } + return a; +} + +static inline int calc_lowcomp(int a, int b0, int b1, int bin) +{ + if (bin < 7) { + return calc_lowcomp1(a, b0, b1, 384); + } else if (bin < 20) { + return calc_lowcomp1(a, b0, b1, 320); + } else { + return FFMAX(a - 128, 0); + } +} + +void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, + int16_t *band_psd) +{ + int bin, band; + + /* exponent mapping to PSD */ + for (bin = start; bin < end; bin++) { + psd[bin]=(3072 - (exp[bin] << 7)); + } + + /* PSD integration */ + bin = start; + band = ff_ac3_bin_to_band_tab[start]; + do { + int v = psd[bin++]; + int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end); + for (; bin < band_end; bin++) { + int max = FFMAX(v, psd[bin]); + /* logadd */ + int adr = FFMIN(max - ((v + psd[bin] + 1) >> 1), 255); + v = max + ff_ac3_log_add_tab[adr]; + } + band_psd[band++] = v; + } while (end > ff_ac3_band_start_tab[band]); +} + +int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, + int start, int end, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, uint8_t *dba_offsets, + uint8_t *dba_lengths, uint8_t *dba_values, + int16_t *mask) +{ + int16_t excite[AC3_CRITICAL_BANDS]; /* excitation */ + int band; + int band_start, band_end, begin, end1; + int lowcomp, fastleak, slowleak; + + /* excitation function */ + band_start = ff_ac3_bin_to_band_tab[start]; + band_end = ff_ac3_bin_to_band_tab[end-1] + 1; + + if (band_start == 0) { + lowcomp = 0; + lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384); + excite[0] = band_psd[0] - fast_gain - lowcomp; + lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384); + excite[1] = band_psd[1] - fast_gain - lowcomp; + begin = 7; + for (band = 2; band < 7; band++) { + if (!(is_lfe && band == 6)) + lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384); + fastleak = band_psd[band] - fast_gain; + slowleak = band_psd[band] - s->slow_gain; + excite[band] = fastleak - lowcomp; + if (!(is_lfe && band == 6)) { + if (band_psd[band] <= band_psd[band+1]) { + begin = band + 1; + break; + } + } + } + + end1 = FFMIN(band_end, 22); + for (band = begin; band < end1; band++) { + if (!(is_lfe && band == 6)) + lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band); + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain); + excite[band] = FFMAX(fastleak - lowcomp, slowleak); + } + begin = 22; + } else { + /* coupling channel */ + begin = band_start; + fastleak = (s->cpl_fast_leak << 8) + 768; + slowleak = (s->cpl_slow_leak << 8) + 768; + } + + for (band = begin; band < band_end; band++) { + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain); + excite[band] = FFMAX(fastleak, slowleak); + } + + /* compute masking curve */ + + for (band = band_start; band < band_end; band++) { + int tmp = s->db_per_bit - band_psd[band]; + if (tmp > 0) { + excite[band] += tmp >> 2; + } + mask[band] = FFMAX(ff_ac3_hearing_threshold_tab[band >> s->sr_shift][s->sr_code], excite[band]); + } + + /* delta bit allocation */ + + if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) { + int i, seg, delta; + if (dba_nsegs > 8) + return -1; + band = band_start; + for (seg = 0; seg < dba_nsegs; seg++) { + band += dba_offsets[seg]; + if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band) + return -1; + if (dba_values[seg] >= 4) { + delta = (dba_values[seg] - 3) << 7; + } else { + delta = (dba_values[seg] - 4) << 7; + } + for (i = 0; i < dba_lengths[seg]; i++) { + mask[band++] += delta; + } + } + } + return 0; +} + +/** + * Initialize some tables. + * note: This function must remain thread safe because it is called by the + * AVParser init code. + */ +av_cold void ff_ac3_common_init(void) +{ +#if !CONFIG_HARDCODED_TABLES + /* compute ff_ac3_bin_to_band_tab from ff_ac3_band_start_tab */ + int bin = 0, band; + for (band = 0; band < AC3_CRITICAL_BANDS; band++) { + int band_end = ff_ac3_band_start_tab[band+1]; + while (bin < band_end) + ff_ac3_bin_to_band_tab[bin++] = band; + } +#endif /* !CONFIG_HARDCODED_TABLES */ +} diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.h new file mode 100644 index 000000000..e609bb51c --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3.h @@ -0,0 +1,181 @@ +/* + * Common code between the AC-3 encoder and decoder + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Common code between the AC-3 encoder and decoder. + */ + +#ifndef AVCODEC_AC3_H +#define AVCODEC_AC3_H + +#define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */ +#define AC3_MAX_CHANNELS 7 /**< maximum number of channels, including coupling channel */ +#define CPL_CH 0 /**< coupling channel index */ + +#define AC3_MAX_COEFS 256 +#define AC3_BLOCK_SIZE 256 +#define AC3_MAX_BLOCKS 6 +#define AC3_FRAME_SIZE (AC3_MAX_BLOCKS * 256) +#define AC3_WINDOW_SIZE (AC3_BLOCK_SIZE * 2) +#define AC3_CRITICAL_BANDS 50 +#define AC3_MAX_CPL_BANDS 18 + +#include "libavutil/opt.h" +#include "avcodec.h" +#include "ac3tab.h" + +/* exponent encoding strategy */ +#define EXP_REUSE 0 +#define EXP_NEW 1 + +#define EXP_D15 1 +#define EXP_D25 2 +#define EXP_D45 3 + +/* pre-defined gain values */ +#define LEVEL_PLUS_3DB 1.4142135623730950 +#define LEVEL_PLUS_1POINT5DB 1.1892071150027209 +#define LEVEL_MINUS_1POINT5DB 0.8408964152537145 +#define LEVEL_MINUS_3DB 0.7071067811865476 +#define LEVEL_MINUS_4POINT5DB 0.5946035575013605 +#define LEVEL_MINUS_6DB 0.5000000000000000 +#define LEVEL_MINUS_9DB 0.3535533905932738 +#define LEVEL_ZERO 0.0000000000000000 +#define LEVEL_ONE 1.0000000000000000 + +/** Delta bit allocation strategy */ +typedef enum { + DBA_REUSE = 0, + DBA_NEW, + DBA_NONE, + DBA_RESERVED +} AC3DeltaStrategy; + +/** Channel mode (audio coding mode) */ +typedef enum { + AC3_CHMODE_DUALMONO = 0, + AC3_CHMODE_MONO, + AC3_CHMODE_STEREO, + AC3_CHMODE_3F, + AC3_CHMODE_2F1R, + AC3_CHMODE_3F1R, + AC3_CHMODE_2F2R, + AC3_CHMODE_3F2R +} AC3ChannelMode; + +typedef struct AC3BitAllocParameters { + int sr_code; + int sr_shift; + int slow_gain, slow_decay, fast_decay, db_per_bit, floor; + int cpl_fast_leak, cpl_slow_leak; +} AC3BitAllocParameters; + +/** + * @struct AC3HeaderInfo + * Coded AC-3 header values up to the lfeon element, plus derived values. + */ +typedef struct AC3HeaderInfo { + /** @name Coded elements + * @{ + */ + uint16_t sync_word; + uint16_t crc1; + uint8_t sr_code; + uint8_t bitstream_id; + uint8_t bitstream_mode; + uint8_t channel_mode; + uint8_t lfe_on; + uint8_t frame_type; + int substreamid; ///< substream identification + int center_mix_level; ///< Center mix level index + int surround_mix_level; ///< Surround mix level index + uint16_t channel_map; + int num_blocks; ///< number of audio blocks + /** @} */ + + /** @name Derived values + * @{ + */ + uint8_t sr_shift; + uint16_t sample_rate; + uint32_t bit_rate; + uint8_t channels; + uint16_t frame_size; + uint64_t channel_layout; + /** @} */ +} AC3HeaderInfo; + +typedef enum { + EAC3_FRAME_TYPE_INDEPENDENT = 0, + EAC3_FRAME_TYPE_DEPENDENT, + EAC3_FRAME_TYPE_AC3_CONVERT, + EAC3_FRAME_TYPE_RESERVED +} EAC3FrameType; + +void ff_ac3_common_init(void); + +/** + * Calculate the log power-spectral density of the input signal. + * This gives a rough estimate of signal power in the frequency domain by using + * the spectral envelope (exponents). The psd is also separately grouped + * into critical bands for use in the calculating the masking curve. + * 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters + * determines the reference level. + * + * @param[in] exp frequency coefficient exponents + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[out] psd signal power for each frequency bin + * @param[out] band_psd signal power for each critical band + */ +void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, + int16_t *band_psd); + +/** + * Calculate the masking curve. + * First, the excitation is calculated using parameters in s and the signal + * power in each critical band. The excitation is compared with a predefined + * hearing threshold table to produce the masking curve. If delta bit + * allocation information is provided, it is used for adjusting the masking + * curve, usually to give a closer match to a better psychoacoustic model. + * + * @param[in] s adjustable bit allocation parameters + * @param[in] band_psd signal power for each critical band + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] fast_gain fast gain (estimated signal-to-mask ratio) + * @param[in] is_lfe whether or not the channel being processed is the LFE + * @param[in] dba_mode delta bit allocation mode (none, reuse, or new) + * @param[in] dba_nsegs number of delta segments + * @param[in] dba_offsets location offsets for each segment + * @param[in] dba_lengths length of each segment + * @param[in] dba_values delta bit allocation for each segment + * @param[out] mask calculated masking curve + * @return returns 0 for success, non-zero for error + */ +int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, + int start, int end, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, uint8_t *dba_offsets, + uint8_t *dba_lengths, uint8_t *dba_values, + int16_t *mask); + +#endif /* AVCODEC_AC3_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.c new file mode 100644 index 000000000..8dc4c0d48 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.c @@ -0,0 +1,194 @@ +/* + * AC-3 parser + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/channel_layout.h" +#include "parser.h" +#include "ac3_parser.h" +#include "aac_ac3_parser.h" +#include "get_bits.h" + + +#define AC3_HEADER_SIZE 7 + + +static const uint8_t eac3_blocks[4] = { + 1, 2, 3, 6 +}; + +/** + * Table for center mix levels + * reference: Section 5.4.2.4 cmixlev + */ +static const uint8_t center_levels[4] = { 4, 5, 6, 5 }; + +/** + * Table for surround mix levels + * reference: Section 5.4.2.5 surmixlev + */ +static const uint8_t surround_levels[4] = { 4, 6, 7, 6 }; + + +int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) +{ + int frame_size_code; + + memset(hdr, 0, sizeof(*hdr)); + + hdr->sync_word = get_bits(gbc, 16); + if(hdr->sync_word != 0x0B77) + return AAC_AC3_PARSE_ERROR_SYNC; + + /* read ahead to bsid to distinguish between AC-3 and E-AC-3 */ + hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F; + if(hdr->bitstream_id > 16) + return AAC_AC3_PARSE_ERROR_BSID; + + hdr->num_blocks = 6; + + /* set default mix levels */ + hdr->center_mix_level = 5; // -4.5dB + hdr->surround_mix_level = 6; // -6.0dB + + if(hdr->bitstream_id <= 10) { + /* Normal AC-3 */ + hdr->crc1 = get_bits(gbc, 16); + hdr->sr_code = get_bits(gbc, 2); + if(hdr->sr_code == 3) + return AAC_AC3_PARSE_ERROR_SAMPLE_RATE; + + frame_size_code = get_bits(gbc, 6); + if(frame_size_code > 37) + return AAC_AC3_PARSE_ERROR_FRAME_SIZE; + + skip_bits(gbc, 5); // skip bsid, already got it + + hdr->bitstream_mode = get_bits(gbc, 3); + hdr->channel_mode = get_bits(gbc, 3); + + if(hdr->channel_mode == AC3_CHMODE_STEREO) { + skip_bits(gbc, 2); // skip dsurmod + } else { + if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) + hdr-> center_mix_level = center_levels[get_bits(gbc, 2)]; + if(hdr->channel_mode & 4) + hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)]; + } + hdr->lfe_on = get_bits1(gbc); + + hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8; + hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift; + hdr->bit_rate = (ff_ac3_bitrate_tab[frame_size_code>>1] * 1000) >> hdr->sr_shift; + hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; + hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2; + hdr->frame_type = EAC3_FRAME_TYPE_AC3_CONVERT; //EAC3_FRAME_TYPE_INDEPENDENT; + hdr->substreamid = 0; + } else { + /* Enhanced AC-3 */ + hdr->crc1 = 0; + hdr->frame_type = get_bits(gbc, 2); + if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED) + return AAC_AC3_PARSE_ERROR_FRAME_TYPE; + + hdr->substreamid = get_bits(gbc, 3); + + hdr->frame_size = (get_bits(gbc, 11) + 1) << 1; + if(hdr->frame_size < AC3_HEADER_SIZE) + return AAC_AC3_PARSE_ERROR_FRAME_SIZE; + + hdr->sr_code = get_bits(gbc, 2); + if (hdr->sr_code == 3) { + int sr_code2 = get_bits(gbc, 2); + if(sr_code2 == 3) + return AAC_AC3_PARSE_ERROR_SAMPLE_RATE; + hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2; + hdr->sr_shift = 1; + } else { + hdr->num_blocks = eac3_blocks[get_bits(gbc, 2)]; + hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code]; + hdr->sr_shift = 0; + } + + hdr->channel_mode = get_bits(gbc, 3); + hdr->lfe_on = get_bits1(gbc); + + hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate / + (hdr->num_blocks * 256.0)); + hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; + } + hdr->channel_layout = avpriv_ac3_channel_layout_tab[hdr->channel_mode]; + if (hdr->lfe_on) + hdr->channel_layout |= AV_CH_LOW_FREQUENCY; + + return 0; +} + +static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info, + int *need_next_header, int *new_frame_start) +{ + int err; + union { + uint64_t u64; + uint8_t u8[8]; + } tmp = { av_be2ne64(state) }; + AC3HeaderInfo hdr; + GetBitContext gbc; + + init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54); + err = avpriv_ac3_parse_header(&gbc, &hdr); + + if(err < 0) + return 0; + + hdr_info->sample_rate = hdr.sample_rate; + hdr_info->bit_rate = hdr.bit_rate; + hdr_info->channels = hdr.channels; + hdr_info->channel_layout = hdr.channel_layout; + hdr_info->samples = hdr.num_blocks * 256; + hdr_info->service_type = hdr.bitstream_mode; + if (hdr.bitstream_mode == 0x7 && hdr.channels > 1) + hdr_info->service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE; + if(hdr.bitstream_id>10) + hdr_info->codec_id = AV_CODEC_ID_EAC3; + else if (hdr_info->codec_id == AV_CODEC_ID_NONE) + hdr_info->codec_id = AV_CODEC_ID_AC3; + + *need_next_header = (hdr.frame_type != EAC3_FRAME_TYPE_AC3_CONVERT); + *new_frame_start = (hdr.frame_type != EAC3_FRAME_TYPE_DEPENDENT); + return hdr.frame_size; +} + +static av_cold int ac3_parse_init(AVCodecParserContext *s1) +{ + AACAC3ParseContext *s = s1->priv_data; + s->header_size = AC3_HEADER_SIZE; + s->sync = ac3_sync; + return 0; +} + + +AVCodecParser ff_ac3_parser = { + .codec_ids = { AV_CODEC_ID_AC3, AV_CODEC_ID_EAC3 }, + .priv_data_size = sizeof(AACAC3ParseContext), + .parser_init = ac3_parse_init, + .parser_parse = ff_aac_ac3_parse, + .parser_close = ff_parse_close, +}; diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.h new file mode 100644 index 000000000..b5022de2d --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3_parser.h @@ -0,0 +1,41 @@ +/* + * AC-3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AC3_PARSER_H +#define AVCODEC_AC3_PARSER_H + +#include "ac3.h" +#include "get_bits.h" + +/** + * Parse AC-3 frame header. + * Parse the header up to the lfeon element, which is the first 52 or 54 bits + * depending on the audio coding mode. + * @param[in] gbc BitContext containing the first 54 bits of the frame. + * @param[out] hdr Pointer to struct where header info is written. + * @return Returns 0 on success, -1 if there is a sync word mismatch, + * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) + * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. + */ +int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); + +#endif /* AVCODEC_AC3_PARSER_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.c new file mode 100644 index 000000000..f91ded0fc --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.c @@ -0,0 +1,1491 @@ +/* + * AC-3 Audio Decoder + * This code was developed as part of Google Summer of Code 2006. + * E-AC-3 support was added as part of Google Summer of Code 2007. + * + * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com) + * Copyright (c) 2007-2008 Bartlomiej Wolowiec + * Copyright (c) 2007 Justin Ruggles + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "libavutil/crc.h" +#include "libavutil/opt.h" +#include "internal.h" +#include "aac_ac3_parser.h" +#include "ac3_parser.h" +#include "ac3dec.h" +#include "ac3dec_data.h" +#include "kbdwin.h" + +/** + * table for ungrouping 3 values in 7 bits. + * used for exponents and bap=2 mantissas + */ +static uint8_t ungroup_3_in_7_bits_tab[128][3]; + +/** tables for ungrouping mantissas */ +static int b1_mantissas[32][3]; +static int b2_mantissas[128][3]; +static int b3_mantissas[8]; +static int b4_mantissas[128][2]; +static int b5_mantissas[16]; + +/** + * Quantization table: levels for symmetric. bits for asymmetric. + * reference: Table 7.18 Mapping of bap to Quantizer + */ +static const uint8_t quantization_tab[16] = { + 0, 3, 5, 7, 11, 15, + 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 +}; + +/** dynamic range table. converts codes to scale factors. */ +static float dynamic_range_tab[256]; + +/** Adjustments in dB gain */ +static const float gain_levels[9] = { + LEVEL_PLUS_3DB, + LEVEL_PLUS_1POINT5DB, + LEVEL_ONE, + LEVEL_MINUS_1POINT5DB, + LEVEL_MINUS_3DB, + LEVEL_MINUS_4POINT5DB, + LEVEL_MINUS_6DB, + LEVEL_ZERO, + LEVEL_MINUS_9DB +}; + +/** + * Table for default stereo downmixing coefficients + * reference: Section 7.8.2 Downmixing Into Two Channels + */ +static const uint8_t ac3_default_coeffs[8][5][2] = { + { { 2, 7 }, { 7, 2 }, }, + { { 4, 4 }, }, + { { 2, 7 }, { 7, 2 }, }, + { { 2, 7 }, { 5, 5 }, { 7, 2 }, }, + { { 2, 7 }, { 7, 2 }, { 6, 6 }, }, + { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 }, }, + { { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, }, + { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, }, +}; + +/** + * Symmetrical Dequantization + * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization + * Tables 7.19 to 7.23 + */ +static inline int +symmetric_dequant(int code, int levels) +{ + return ((code - (levels >> 1)) << 24) / levels; +} + +/* + * Initialize tables at runtime. + */ +static av_cold void ac3_tables_init(void) +{ + int i; + + /* generate table for ungrouping 3 values in 7 bits + reference: Section 7.1.3 Exponent Decoding */ + for (i = 0; i < 128; i++) { + ungroup_3_in_7_bits_tab[i][0] = i / 25; + ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5; + ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5; + } + + /* generate grouped mantissa tables + reference: Section 7.3.5 Ungrouping of Mantissas */ + for (i = 0; i < 32; i++) { + /* bap=1 mantissas */ + b1_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][0], 3); + b1_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][1], 3); + b1_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][2], 3); + } + for (i = 0; i < 128; i++) { + /* bap=2 mantissas */ + b2_mantissas[i][0] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][0], 5); + b2_mantissas[i][1] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][1], 5); + b2_mantissas[i][2] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][2], 5); + + /* bap=4 mantissas */ + b4_mantissas[i][0] = symmetric_dequant(i / 11, 11); + b4_mantissas[i][1] = symmetric_dequant(i % 11, 11); + } + /* generate ungrouped mantissa tables + reference: Tables 7.21 and 7.23 */ + for (i = 0; i < 7; i++) { + /* bap=3 mantissas */ + b3_mantissas[i] = symmetric_dequant(i, 7); + } + for (i = 0; i < 15; i++) { + /* bap=5 mantissas */ + b5_mantissas[i] = symmetric_dequant(i, 15); + } + + /* generate dynamic range table + reference: Section 7.7.1 Dynamic Range Control */ + for (i = 0; i < 256; i++) { + int v = (i >> 5) - ((i >> 7) << 3) - 5; + dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); + } +} + +/** + * AVCodec initialization + */ +static av_cold int ac3_decode_init(AVCodecContext *avctx) +{ + AC3DecodeContext *s = avctx->priv_data; + int i; + + s->avctx = avctx; + + ff_ac3_common_init(); + ac3_tables_init(); + ff_mdct_init(&s->imdct_256, 8, 1, 1.0); + ff_mdct_init(&s->imdct_512, 9, 1, 1.0); + ff_kbd_window_init(s->window, 5.0, 256); + ff_dsputil_init(&s->dsp, avctx); + avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); + ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT); + ff_fmt_convert_init(&s->fmt_conv, avctx); + av_lfg_init(&s->dith_state, 0); + + avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; + + /* allow downmixing to stereo or mono */ + if (avctx->channels > 0 && avctx->request_channels > 0 && + avctx->request_channels < avctx->channels && + avctx->request_channels <= 2) { + avctx->channels = avctx->request_channels; + } + s->downmixed = 1; + + for (i = 0; i < AC3_MAX_CHANNELS; i++) { + s->xcfptr[i] = s->transform_coeffs[i]; + s->dlyptr[i] = s->delay[i]; + } + + return 0; +} + +/** + * Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream. + * GetBitContext within AC3DecodeContext must point to + * the start of the synchronized AC-3 bitstream. + */ +static int ac3_parse_header(AC3DecodeContext *s) +{ + GetBitContext *gbc = &s->gbc; + int i; + + /* read the rest of the bsi. read twice for dual mono mode. */ + i = !s->channel_mode; + do { + skip_bits(gbc, 5); // skip dialog normalization + if (get_bits1(gbc)) + skip_bits(gbc, 8); //skip compression + if (get_bits1(gbc)) + skip_bits(gbc, 8); //skip language code + if (get_bits1(gbc)) + skip_bits(gbc, 7); //skip audio production information + } while (i--); + + skip_bits(gbc, 2); //skip copyright bit and original bitstream bit + + /* skip the timecodes (or extra bitstream information for Alternate Syntax) + TODO: read & use the xbsi1 downmix levels */ + if (get_bits1(gbc)) + skip_bits(gbc, 14); //skip timecode1 / xbsi1 + if (get_bits1(gbc)) + skip_bits(gbc, 14); //skip timecode2 / xbsi2 + + /* skip additional bitstream info */ + if (get_bits1(gbc)) { + i = get_bits(gbc, 6); + do { + skip_bits(gbc, 8); + } while (i--); + } + + return 0; +} + +/** + * Common function to parse AC-3 or E-AC-3 frame header + */ +static int parse_frame_header(AC3DecodeContext *s) +{ + AC3HeaderInfo hdr; + int err; + + err = avpriv_ac3_parse_header(&s->gbc, &hdr); + if (err) + return err; + + /* get decoding parameters from header info */ + s->bit_alloc_params.sr_code = hdr.sr_code; + s->bitstream_mode = hdr.bitstream_mode; + s->channel_mode = hdr.channel_mode; + s->channel_layout = hdr.channel_layout; + s->lfe_on = hdr.lfe_on; + s->bit_alloc_params.sr_shift = hdr.sr_shift; + s->sample_rate = hdr.sample_rate; + s->bit_rate = hdr.bit_rate; + s->channels = hdr.channels; + s->fbw_channels = s->channels - s->lfe_on; + s->lfe_ch = s->fbw_channels + 1; + s->frame_size = hdr.frame_size; + s->center_mix_level = hdr.center_mix_level; + s->surround_mix_level = hdr.surround_mix_level; + s->num_blocks = hdr.num_blocks; + s->frame_type = hdr.frame_type; + s->substreamid = hdr.substreamid; + + if (s->lfe_on) { + s->start_freq[s->lfe_ch] = 0; + s->end_freq[s->lfe_ch] = 7; + s->num_exp_groups[s->lfe_ch] = 2; + s->channel_in_cpl[s->lfe_ch] = 0; + } + + if (hdr.bitstream_id <= 10) { + s->eac3 = 0; + s->snr_offset_strategy = 2; + s->block_switch_syntax = 1; + s->dither_flag_syntax = 1; + s->bit_allocation_syntax = 1; + s->fast_gain_syntax = 0; + s->first_cpl_leak = 0; + s->dba_syntax = 1; + s->skip_syntax = 1; + memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht)); + return ac3_parse_header(s); + } else if (CONFIG_EAC3_DECODER) { + s->eac3 = 1; + return ff_eac3_parse_header(s); + } else { + av_log(s->avctx, AV_LOG_ERROR, "E-AC-3 support not compiled in\n"); + return AVERROR(ENOSYS); + } +} + +/** + * Set stereo downmixing coefficients based on frame header info. + * reference: Section 7.8.2 Downmixing Into Two Channels + */ +static void set_downmix_coeffs(AC3DecodeContext *s) +{ + int i; + float cmix = gain_levels[s-> center_mix_level]; + float smix = gain_levels[s->surround_mix_level]; + float norm0, norm1; + + for (i = 0; i < s->fbw_channels; i++) { + s->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]]; + s->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]]; + } + if (s->channel_mode > 1 && s->channel_mode & 1) { + s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix; + } + if (s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { + int nf = s->channel_mode - 2; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB; + } + if (s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { + int nf = s->channel_mode - 4; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix; + } + + /* renormalize */ + norm0 = norm1 = 0.0; + for (i = 0; i < s->fbw_channels; i++) { + norm0 += s->downmix_coeffs[i][0]; + norm1 += s->downmix_coeffs[i][1]; + } + norm0 = 1.0f / norm0; + norm1 = 1.0f / norm1; + for (i = 0; i < s->fbw_channels; i++) { + s->downmix_coeffs[i][0] *= norm0; + s->downmix_coeffs[i][1] *= norm1; + } + + if (s->output_mode == AC3_CHMODE_MONO) { + for (i = 0; i < s->fbw_channels; i++) + s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + + s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB; + } +} + +/** + * Decode the grouped exponents according to exponent strategy. + * reference: Section 7.1.3 Exponent Decoding + */ +static int decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps, + uint8_t absexp, int8_t *dexps) +{ + int i, j, grp, group_size; + int dexp[256]; + int expacc, prevexp; + + /* unpack groups */ + group_size = exp_strategy + (exp_strategy == EXP_D45); + for (grp = 0, i = 0; grp < ngrps; grp++) { + expacc = get_bits(gbc, 7); + dexp[i++] = ungroup_3_in_7_bits_tab[expacc][0]; + dexp[i++] = ungroup_3_in_7_bits_tab[expacc][1]; + dexp[i++] = ungroup_3_in_7_bits_tab[expacc][2]; + } + + /* convert to absolute exps and expand groups */ + prevexp = absexp; + for (i = 0, j = 0; i < ngrps * 3; i++) { + prevexp += dexp[i] - 2; + if (prevexp > 24U) + return -1; + switch (group_size) { + case 4: dexps[j++] = prevexp; + dexps[j++] = prevexp; + case 2: dexps[j++] = prevexp; + case 1: dexps[j++] = prevexp; + } + } + return 0; +} + +/** + * Generate transform coefficients for each coupled channel in the coupling + * range using the coupling coefficients and coupling coordinates. + * reference: Section 7.4.3 Coupling Coordinate Format + */ +static void calc_transform_coeffs_cpl(AC3DecodeContext *s) +{ + int bin, band, ch; + + bin = s->start_freq[CPL_CH]; + for (band = 0; band < s->num_cpl_bands; band++) { + int band_start = bin; + int band_end = bin + s->cpl_band_sizes[band]; + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (s->channel_in_cpl[ch]) { + int cpl_coord = s->cpl_coords[ch][band] << 5; + for (bin = band_start; bin < band_end; bin++) { + s->fixed_coeffs[ch][bin] = + MULH(s->fixed_coeffs[CPL_CH][bin] << 4, cpl_coord); + } + if (ch == 2 && s->phase_flags[band]) { + for (bin = band_start; bin < band_end; bin++) + s->fixed_coeffs[2][bin] = -s->fixed_coeffs[2][bin]; + } + } + } + bin = band_end; + } +} + +/** + * Grouped mantissas for 3-level 5-level and 11-level quantization + */ +typedef struct { + int b1_mant[2]; + int b2_mant[2]; + int b4_mant; + int b1; + int b2; + int b4; +} mant_groups; + +/** + * Decode the transform coefficients for a particular channel + * reference: Section 7.3 Quantization and Decoding of Mantissas + */ +static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m) +{ + int start_freq = s->start_freq[ch_index]; + int end_freq = s->end_freq[ch_index]; + uint8_t *baps = s->bap[ch_index]; + int8_t *exps = s->dexps[ch_index]; + int32_t *coeffs = s->fixed_coeffs[ch_index]; + int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index]; + GetBitContext *gbc = &s->gbc; + int freq; + + for (freq = start_freq; freq < end_freq; freq++) { + int bap = baps[freq]; + int mantissa; + switch (bap) { + case 0: + /* random noise with approximate range of -0.707 to 0.707 */ + if (dither) + mantissa = (((av_lfg_get(&s->dith_state)>>8)*181)>>8) - 5931008; + else + mantissa = 0; + break; + case 1: + if (m->b1) { + m->b1--; + mantissa = m->b1_mant[m->b1]; + } else { + int bits = get_bits(gbc, 5); + mantissa = b1_mantissas[bits][0]; + m->b1_mant[1] = b1_mantissas[bits][1]; + m->b1_mant[0] = b1_mantissas[bits][2]; + m->b1 = 2; + } + break; + case 2: + if (m->b2) { + m->b2--; + mantissa = m->b2_mant[m->b2]; + } else { + int bits = get_bits(gbc, 7); + mantissa = b2_mantissas[bits][0]; + m->b2_mant[1] = b2_mantissas[bits][1]; + m->b2_mant[0] = b2_mantissas[bits][2]; + m->b2 = 2; + } + break; + case 3: + mantissa = b3_mantissas[get_bits(gbc, 3)]; + break; + case 4: + if (m->b4) { + m->b4 = 0; + mantissa = m->b4_mant; + } else { + int bits = get_bits(gbc, 7); + mantissa = b4_mantissas[bits][0]; + m->b4_mant = b4_mantissas[bits][1]; + m->b4 = 1; + } + break; + case 5: + mantissa = b5_mantissas[get_bits(gbc, 4)]; + break; + default: /* 6 to 15 */ + /* Shift mantissa and sign-extend it. */ + mantissa = get_sbits(gbc, quantization_tab[bap]); + mantissa <<= 24 - quantization_tab[bap]; + break; + } + coeffs[freq] = mantissa >> exps[freq]; + } +} + +/** + * Remove random dithering from coupling range coefficients with zero-bit + * mantissas for coupled channels which do not use dithering. + * reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0) + */ +static void remove_dithering(AC3DecodeContext *s) { + int ch, i; + + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (!s->dither_flag[ch] && s->channel_in_cpl[ch]) { + for (i = s->start_freq[CPL_CH]; i < s->end_freq[CPL_CH]; i++) { + if (!s->bap[CPL_CH][i]) + s->fixed_coeffs[ch][i] = 0; + } + } + } +} + +static void decode_transform_coeffs_ch(AC3DecodeContext *s, int blk, int ch, + mant_groups *m) +{ + if (!s->channel_uses_aht[ch]) { + ac3_decode_transform_coeffs_ch(s, ch, m); + } else { + /* if AHT is used, mantissas for all blocks are encoded in the first + block of the frame. */ + int bin; + if (!blk && CONFIG_EAC3_DECODER) + ff_eac3_decode_transform_coeffs_aht_ch(s, ch); + for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { + s->fixed_coeffs[ch][bin] = s->pre_mantissa[ch][bin][blk] >> s->dexps[ch][bin]; + } + } +} + +/** + * Decode the transform coefficients. + */ +static void decode_transform_coeffs(AC3DecodeContext *s, int blk) +{ + int ch, end; + int got_cplchan = 0; + mant_groups m; + + m.b1 = m.b2 = m.b4 = 0; + + for (ch = 1; ch <= s->channels; ch++) { + /* transform coefficients for full-bandwidth channel */ + decode_transform_coeffs_ch(s, blk, ch, &m); + /* transform coefficients for coupling channel come right after the + coefficients for the first coupled channel*/ + if (s->channel_in_cpl[ch]) { + if (!got_cplchan) { + decode_transform_coeffs_ch(s, blk, CPL_CH, &m); + calc_transform_coeffs_cpl(s); + got_cplchan = 1; + } + end = s->end_freq[CPL_CH]; + } else { + end = s->end_freq[ch]; + } + do + s->fixed_coeffs[ch][end] = 0; + while (++end < 256); + } + + /* zero the dithered coefficients for appropriate channels */ + remove_dithering(s); +} + +/** + * Stereo rematrixing. + * reference: Section 7.5.4 Rematrixing : Decoding Technique + */ +static void do_rematrixing(AC3DecodeContext *s) +{ + int bnd, i; + int end, bndend; + + end = FFMIN(s->end_freq[1], s->end_freq[2]); + + for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) { + if (s->rematrixing_flags[bnd]) { + bndend = FFMIN(end, ff_ac3_rematrix_band_tab[bnd + 1]); + for (i = ff_ac3_rematrix_band_tab[bnd]; i < bndend; i++) { + int tmp0 = s->fixed_coeffs[1][i]; + s->fixed_coeffs[1][i] += s->fixed_coeffs[2][i]; + s->fixed_coeffs[2][i] = tmp0 - s->fixed_coeffs[2][i]; + } + } + } +} + +/** + * Inverse MDCT Transform. + * Convert frequency domain coefficients to time-domain audio samples. + * reference: Section 7.9.4 Transformation Equations + */ +static inline void do_imdct(AC3DecodeContext *s, int channels) +{ + int ch; + + for (ch = 1; ch <= channels; ch++) { + if (s->block_switch[ch]) { + int i; + float *x = s->tmp_output + 128; + for (i = 0; i < 128; i++) + x[i] = s->transform_coeffs[ch][2 * i]; + s->imdct_256.imdct_half(&s->imdct_256, s->tmp_output, x); + s->fdsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], + s->tmp_output, s->window, 128); + for (i = 0; i < 128; i++) + x[i] = s->transform_coeffs[ch][2 * i + 1]; + s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch - 1], x); + } else { + s->imdct_512.imdct_half(&s->imdct_512, s->tmp_output, s->transform_coeffs[ch]); + s->fdsp.vector_fmul_window(s->outptr[ch - 1], s->delay[ch - 1], + s->tmp_output, s->window, 128); + memcpy(s->delay[ch - 1], s->tmp_output + 128, 128 * sizeof(float)); + } + } +} + +/** + * Upmix delay samples from stereo to original channel layout. + */ +static void ac3_upmix_delay(AC3DecodeContext *s) +{ + int channel_data_size = sizeof(s->delay[0]); + switch (s->channel_mode) { + case AC3_CHMODE_DUALMONO: + case AC3_CHMODE_STEREO: + /* upmix mono to stereo */ + memcpy(s->delay[1], s->delay[0], channel_data_size); + break; + case AC3_CHMODE_2F2R: + memset(s->delay[3], 0, channel_data_size); + case AC3_CHMODE_2F1R: + memset(s->delay[2], 0, channel_data_size); + break; + case AC3_CHMODE_3F2R: + memset(s->delay[4], 0, channel_data_size); + case AC3_CHMODE_3F1R: + memset(s->delay[3], 0, channel_data_size); + case AC3_CHMODE_3F: + memcpy(s->delay[2], s->delay[1], channel_data_size); + memset(s->delay[1], 0, channel_data_size); + break; + } +} + +/** + * Decode band structure for coupling, spectral extension, or enhanced coupling. + * The band structure defines how many subbands are in each band. For each + * subband in the range, 1 means it is combined with the previous band, and 0 + * means that it starts a new band. + * + * @param[in] gbc bit reader context + * @param[in] blk block number + * @param[in] eac3 flag to indicate E-AC-3 + * @param[in] ecpl flag to indicate enhanced coupling + * @param[in] start_subband subband number for start of range + * @param[in] end_subband subband number for end of range + * @param[in] default_band_struct default band structure table + * @param[out] num_bands number of bands (optionally NULL) + * @param[out] band_sizes array containing the number of bins in each band (optionally NULL) + */ +static void decode_band_structure(GetBitContext *gbc, int blk, int eac3, + int ecpl, int start_subband, int end_subband, + const uint8_t *default_band_struct, + int *num_bands, uint8_t *band_sizes) +{ + int subbnd, bnd, n_subbands, n_bands=0; + uint8_t bnd_sz[22]; + uint8_t coded_band_struct[22]; + const uint8_t *band_struct; + + n_subbands = end_subband - start_subband; + + /* decode band structure from bitstream or use default */ + if (!eac3 || get_bits1(gbc)) { + for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) { + coded_band_struct[subbnd] = get_bits1(gbc); + } + band_struct = coded_band_struct; + } else if (!blk) { + band_struct = &default_band_struct[start_subband+1]; + } else { + /* no change in band structure */ + return; + } + + /* calculate number of bands and band sizes based on band structure. + note that the first 4 subbands in enhanced coupling span only 6 bins + instead of 12. */ + if (num_bands || band_sizes ) { + n_bands = n_subbands; + bnd_sz[0] = ecpl ? 6 : 12; + for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) { + int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12; + if (band_struct[subbnd - 1]) { + n_bands--; + bnd_sz[bnd] += subbnd_size; + } else { + bnd_sz[++bnd] = subbnd_size; + } + } + } + + /* set optional output params */ + if (num_bands) + *num_bands = n_bands; + if (band_sizes) + memcpy(band_sizes, bnd_sz, n_bands); +} + +/** + * Decode a single audio block from the AC-3 bitstream. + */ +static int decode_audio_block(AC3DecodeContext *s, int blk) +{ + int fbw_channels = s->fbw_channels; + int channel_mode = s->channel_mode; + int i, bnd, seg, ch; + int different_transforms; + int downmix_output; + int cpl_in_use; + GetBitContext *gbc = &s->gbc; + uint8_t bit_alloc_stages[AC3_MAX_CHANNELS] = { 0 }; + + /* block switch flags */ + different_transforms = 0; + if (s->block_switch_syntax) { + for (ch = 1; ch <= fbw_channels; ch++) { + s->block_switch[ch] = get_bits1(gbc); + if (ch > 1 && s->block_switch[ch] != s->block_switch[1]) + different_transforms = 1; + } + } + + /* dithering flags */ + if (s->dither_flag_syntax) { + for (ch = 1; ch <= fbw_channels; ch++) { + s->dither_flag[ch] = get_bits1(gbc); + } + } + + /* dynamic range */ + i = !s->channel_mode; + do { + if (get_bits1(gbc)) { + s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)] - 1.0) * + s->drc_scale) + 1.0; + } else if (blk == 0) { + s->dynamic_range[i] = 1.0f; + } + } while (i--); + + /* spectral extension strategy */ + if (s->eac3 && (!blk || get_bits1(gbc))) { + s->spx_in_use = get_bits1(gbc); + if (s->spx_in_use) { + int dst_start_freq, dst_end_freq, src_start_freq, + start_subband, end_subband; + + /* determine which channels use spx */ + if (s->channel_mode == AC3_CHMODE_MONO) { + s->channel_uses_spx[1] = 1; + } else { + for (ch = 1; ch <= fbw_channels; ch++) + s->channel_uses_spx[ch] = get_bits1(gbc); + } + + /* get the frequency bins of the spx copy region and the spx start + and end subbands */ + dst_start_freq = get_bits(gbc, 2); + start_subband = get_bits(gbc, 3) + 2; + if (start_subband > 7) + start_subband += start_subband - 7; + end_subband = get_bits(gbc, 3) + 5; + if (end_subband > 7) + end_subband += end_subband - 7; + dst_start_freq = dst_start_freq * 12 + 25; + src_start_freq = start_subband * 12 + 25; + dst_end_freq = end_subband * 12 + 25; + + /* check validity of spx ranges */ + if (start_subband >= end_subband) { + av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension " + "range (%d >= %d)\n", start_subband, end_subband); + return AVERROR_INVALIDDATA; + } + if (dst_start_freq >= src_start_freq) { + av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension " + "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq); + return AVERROR_INVALIDDATA; + } + + s->spx_dst_start_freq = dst_start_freq; + s->spx_src_start_freq = src_start_freq; + s->spx_dst_end_freq = dst_end_freq; + + decode_band_structure(gbc, blk, s->eac3, 0, + start_subband, end_subband, + ff_eac3_default_spx_band_struct, + &s->num_spx_bands, + s->spx_band_sizes); + } else { + for (ch = 1; ch <= fbw_channels; ch++) { + s->channel_uses_spx[ch] = 0; + s->first_spx_coords[ch] = 1; + } + } + } + + /* spectral extension coordinates */ + if (s->spx_in_use) { + for (ch = 1; ch <= fbw_channels; ch++) { + if (s->channel_uses_spx[ch]) { + if (s->first_spx_coords[ch] || get_bits1(gbc)) { + float spx_blend; + int bin, master_spx_coord; + + s->first_spx_coords[ch] = 0; + spx_blend = get_bits(gbc, 5) * (1.0f/32); + master_spx_coord = get_bits(gbc, 2) * 3; + + bin = s->spx_src_start_freq; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + int bandsize; + int spx_coord_exp, spx_coord_mant; + float nratio, sblend, nblend, spx_coord; + + /* calculate blending factors */ + bandsize = s->spx_band_sizes[bnd]; + nratio = ((float)((bin + (bandsize >> 1))) / s->spx_dst_end_freq) - spx_blend; + nratio = av_clipf(nratio, 0.0f, 1.0f); + nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) + // to give unity variance + sblend = sqrtf(1.0f - nratio); + bin += bandsize; + + /* decode spx coordinates */ + spx_coord_exp = get_bits(gbc, 4); + spx_coord_mant = get_bits(gbc, 2); + if (spx_coord_exp == 15) spx_coord_mant <<= 1; + else spx_coord_mant += 4; + spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord); + spx_coord = spx_coord_mant * (1.0f / (1 << 23)); + + /* multiply noise and signal blending factors by spx coordinate */ + s->spx_noise_blend [ch][bnd] = nblend * spx_coord; + s->spx_signal_blend[ch][bnd] = sblend * spx_coord; + } + } + } else { + s->first_spx_coords[ch] = 1; + } + } + } + + /* coupling strategy */ + if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) { + memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); + if (!s->eac3) + s->cpl_in_use[blk] = get_bits1(gbc); + if (s->cpl_in_use[blk]) { + /* coupling in use */ + int cpl_start_subband, cpl_end_subband; + + if (channel_mode < AC3_CHMODE_STEREO) { + av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n"); + return AVERROR_INVALIDDATA; + } + + /* check for enhanced coupling */ + if (s->eac3 && get_bits1(gbc)) { + /* TODO: parse enhanced coupling strategy info */ + avpriv_request_sample(s->avctx, "Enhanced coupling"); + return AVERROR_PATCHWELCOME; + } + + /* determine which channels are coupled */ + if (s->eac3 && s->channel_mode == AC3_CHMODE_STEREO) { + s->channel_in_cpl[1] = 1; + s->channel_in_cpl[2] = 1; + } else { + for (ch = 1; ch <= fbw_channels; ch++) + s->channel_in_cpl[ch] = get_bits1(gbc); + } + + /* phase flags in use */ + if (channel_mode == AC3_CHMODE_STEREO) + s->phase_flags_in_use = get_bits1(gbc); + + /* coupling frequency range */ + cpl_start_subband = get_bits(gbc, 4); + cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 : + get_bits(gbc, 4) + 3; + if (cpl_start_subband >= cpl_end_subband) { + av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n", + cpl_start_subband, cpl_end_subband); + return AVERROR_INVALIDDATA; + } + s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37; + s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37; + + decode_band_structure(gbc, blk, s->eac3, 0, cpl_start_subband, + cpl_end_subband, + ff_eac3_default_cpl_band_struct, + &s->num_cpl_bands, s->cpl_band_sizes); + } else { + /* coupling not in use */ + for (ch = 1; ch <= fbw_channels; ch++) { + s->channel_in_cpl[ch] = 0; + s->first_cpl_coords[ch] = 1; + } + s->first_cpl_leak = s->eac3; + s->phase_flags_in_use = 0; + } + } else if (!s->eac3) { + if (!blk) { + av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must " + "be present in block 0\n"); + return AVERROR_INVALIDDATA; + } else { + s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; + } + } + cpl_in_use = s->cpl_in_use[blk]; + + /* coupling coordinates */ + if (cpl_in_use) { + int cpl_coords_exist = 0; + + for (ch = 1; ch <= fbw_channels; ch++) { + if (s->channel_in_cpl[ch]) { + if ((s->eac3 && s->first_cpl_coords[ch]) || get_bits1(gbc)) { + int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; + s->first_cpl_coords[ch] = 0; + cpl_coords_exist = 1; + master_cpl_coord = 3 * get_bits(gbc, 2); + for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { + cpl_coord_exp = get_bits(gbc, 4); + cpl_coord_mant = get_bits(gbc, 4); + if (cpl_coord_exp == 15) + s->cpl_coords[ch][bnd] = cpl_coord_mant << 22; + else + s->cpl_coords[ch][bnd] = (cpl_coord_mant + 16) << 21; + s->cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord); + } + } else if (!blk) { + av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must " + "be present in block 0\n"); + return AVERROR_INVALIDDATA; + } + } else { + /* channel not in coupling */ + s->first_cpl_coords[ch] = 1; + } + } + /* phase flags */ + if (channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) { + for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { + s->phase_flags[bnd] = s->phase_flags_in_use? get_bits1(gbc) : 0; + } + } + } + + /* stereo rematrixing strategy and band structure */ + if (channel_mode == AC3_CHMODE_STEREO) { + if ((s->eac3 && !blk) || get_bits1(gbc)) { + s->num_rematrixing_bands = 4; + if (cpl_in_use && s->start_freq[CPL_CH] <= 61) { + s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); + } else if (s->spx_in_use && s->spx_src_start_freq <= 61) { + s->num_rematrixing_bands--; + } + for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) + s->rematrixing_flags[bnd] = get_bits1(gbc); + } else if (!blk) { + av_log(s->avctx, AV_LOG_WARNING, "Warning: " + "new rematrixing strategy not present in block 0\n"); + s->num_rematrixing_bands = 0; + } + } + + /* exponent strategies for each channel */ + for (ch = !cpl_in_use; ch <= s->channels; ch++) { + if (!s->eac3) + s->exp_strategy[blk][ch] = get_bits(gbc, 2 - (ch == s->lfe_ch)); + if (s->exp_strategy[blk][ch] != EXP_REUSE) + bit_alloc_stages[ch] = 3; + } + + /* channel bandwidth */ + for (ch = 1; ch <= fbw_channels; ch++) { + s->start_freq[ch] = 0; + if (s->exp_strategy[blk][ch] != EXP_REUSE) { + int group_size; + int prev = s->end_freq[ch]; + if (s->channel_in_cpl[ch]) + s->end_freq[ch] = s->start_freq[CPL_CH]; + else if (s->channel_uses_spx[ch]) + s->end_freq[ch] = s->spx_src_start_freq; + else { + int bandwidth_code = get_bits(gbc, 6); + if (bandwidth_code > 60) { + av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60\n", bandwidth_code); + return AVERROR_INVALIDDATA; + } + s->end_freq[ch] = bandwidth_code * 3 + 73; + } + group_size = 3 << (s->exp_strategy[blk][ch] - 1); + s->num_exp_groups[ch] = (s->end_freq[ch] + group_size-4) / group_size; + if (blk > 0 && s->end_freq[ch] != prev) + memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); + } + } + if (cpl_in_use && s->exp_strategy[blk][CPL_CH] != EXP_REUSE) { + s->num_exp_groups[CPL_CH] = (s->end_freq[CPL_CH] - s->start_freq[CPL_CH]) / + (3 << (s->exp_strategy[blk][CPL_CH] - 1)); + } + + /* decode exponents for each channel */ + for (ch = !cpl_in_use; ch <= s->channels; ch++) { + if (s->exp_strategy[blk][ch] != EXP_REUSE) { + s->dexps[ch][0] = get_bits(gbc, 4) << !ch; + if (decode_exponents(gbc, s->exp_strategy[blk][ch], + s->num_exp_groups[ch], s->dexps[ch][0], + &s->dexps[ch][s->start_freq[ch]+!!ch])) { + av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n"); + return AVERROR_INVALIDDATA; + } + if (ch != CPL_CH && ch != s->lfe_ch) + skip_bits(gbc, 2); /* skip gainrng */ + } + } + + /* bit allocation information */ + if (s->bit_allocation_syntax) { + if (get_bits1(gbc)) { + s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; + s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; + s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; + s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; + s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; + for (ch = !cpl_in_use; ch <= s->channels; ch++) + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } else if (!blk) { + av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must " + "be present in block 0\n"); + return AVERROR_INVALIDDATA; + } + } + + /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ + if (!s->eac3 || !blk) { + if (s->snr_offset_strategy && get_bits1(gbc)) { + int snr = 0; + int csnr; + csnr = (get_bits(gbc, 6) - 15) << 4; + for (i = ch = !cpl_in_use; ch <= s->channels; ch++) { + /* snr offset */ + if (ch == i || s->snr_offset_strategy == 2) + snr = (csnr + get_bits(gbc, 4)) << 2; + /* run at least last bit allocation stage if snr offset changes */ + if (blk && s->snr_offset[ch] != snr) { + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 1); + } + s->snr_offset[ch] = snr; + + /* fast gain (normal AC-3 only) */ + if (!s->eac3) { + int prev = s->fast_gain[ch]; + s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; + /* run last 2 bit allocation stages if fast gain changes */ + if (blk && prev != s->fast_gain[ch]) + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + } + } else if (!s->eac3 && !blk) { + av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n"); + return AVERROR_INVALIDDATA; + } + } + + /* fast gain (E-AC-3 only) */ + if (s->fast_gain_syntax && get_bits1(gbc)) { + for (ch = !cpl_in_use; ch <= s->channels; ch++) { + int prev = s->fast_gain[ch]; + s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; + /* run last 2 bit allocation stages if fast gain changes */ + if (blk && prev != s->fast_gain[ch]) + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + } else if (s->eac3 && !blk) { + for (ch = !cpl_in_use; ch <= s->channels; ch++) + s->fast_gain[ch] = ff_ac3_fast_gain_tab[4]; + } + + /* E-AC-3 to AC-3 converter SNR offset */ + if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && get_bits1(gbc)) { + skip_bits(gbc, 10); // skip converter snr offset + } + + /* coupling leak information */ + if (cpl_in_use) { + if (s->first_cpl_leak || get_bits1(gbc)) { + int fl = get_bits(gbc, 3); + int sl = get_bits(gbc, 3); + /* run last 2 bit allocation stages for coupling channel if + coupling leak changes */ + if (blk && (fl != s->bit_alloc_params.cpl_fast_leak || + sl != s->bit_alloc_params.cpl_slow_leak)) { + bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); + } + s->bit_alloc_params.cpl_fast_leak = fl; + s->bit_alloc_params.cpl_slow_leak = sl; + } else if (!s->eac3 && !blk) { + av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must " + "be present in block 0\n"); + return AVERROR_INVALIDDATA; + } + s->first_cpl_leak = 0; + } + + /* delta bit allocation information */ + if (s->dba_syntax && get_bits1(gbc)) { + /* delta bit allocation exists (strategy) */ + for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { + s->dba_mode[ch] = get_bits(gbc, 2); + if (s->dba_mode[ch] == DBA_RESERVED) { + av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); + return AVERROR_INVALIDDATA; + } + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + /* channel delta offset, len and bit allocation */ + for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { + if (s->dba_mode[ch] == DBA_NEW) { + s->dba_nsegs[ch] = get_bits(gbc, 3) + 1; + for (seg = 0; seg < s->dba_nsegs[ch]; seg++) { + s->dba_offsets[ch][seg] = get_bits(gbc, 5); + s->dba_lengths[ch][seg] = get_bits(gbc, 4); + s->dba_values[ch][seg] = get_bits(gbc, 3); + } + /* run last 2 bit allocation stages if new dba values */ + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + } + } else if (blk == 0) { + for (ch = 0; ch <= s->channels; ch++) { + s->dba_mode[ch] = DBA_NONE; + } + } + + /* Bit allocation */ + for (ch = !cpl_in_use; ch <= s->channels; ch++) { + if (bit_alloc_stages[ch] > 2) { + /* Exponent mapping into PSD and PSD integration */ + ff_ac3_bit_alloc_calc_psd(s->dexps[ch], + s->start_freq[ch], s->end_freq[ch], + s->psd[ch], s->band_psd[ch]); + } + if (bit_alloc_stages[ch] > 1) { + /* Compute excitation function, Compute masking curve, and + Apply delta bit allocation */ + if (ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params, s->band_psd[ch], + s->start_freq[ch], s->end_freq[ch], + s->fast_gain[ch], (ch == s->lfe_ch), + s->dba_mode[ch], s->dba_nsegs[ch], + s->dba_offsets[ch], s->dba_lengths[ch], + s->dba_values[ch], s->mask[ch])) { + av_log(s->avctx, AV_LOG_ERROR, "error in bit allocation\n"); + return AVERROR_INVALIDDATA; + } + } + if (bit_alloc_stages[ch] > 0) { + /* Compute bit allocation */ + const uint8_t *bap_tab = s->channel_uses_aht[ch] ? + ff_eac3_hebap_tab : ff_ac3_bap_tab; + s->ac3dsp.bit_alloc_calc_bap(s->mask[ch], s->psd[ch], + s->start_freq[ch], s->end_freq[ch], + s->snr_offset[ch], + s->bit_alloc_params.floor, + bap_tab, s->bap[ch]); + } + } + + /* unused dummy data */ + if (s->skip_syntax && get_bits1(gbc)) { + int skipl = get_bits(gbc, 9); + while (skipl--) + skip_bits(gbc, 8); + } + + /* unpack the transform coefficients + this also uncouples channels if coupling is in use. */ + decode_transform_coeffs(s, blk); + + /* TODO: generate enhanced coupling coordinates and uncouple */ + + /* recover coefficients if rematrixing is in use */ + if (s->channel_mode == AC3_CHMODE_STEREO) + do_rematrixing(s); + + /* apply scaling to coefficients (headroom, dynrng) */ + for (ch = 1; ch <= s->channels; ch++) { + float gain = 1.0 / 4194304.0f; + if (s->channel_mode == AC3_CHMODE_DUALMONO) { + gain *= s->dynamic_range[2 - ch]; + } else { + gain *= s->dynamic_range[0]; + } + s->fmt_conv.int32_to_float_fmul_scalar(s->transform_coeffs[ch], + s->fixed_coeffs[ch], gain, 256); + } + + /* apply spectral extension to high frequency bins */ + if (s->spx_in_use && CONFIG_EAC3_DECODER) { + ff_eac3_apply_spectral_extension(s); + } + + /* downmix and MDCT. order depends on whether block switching is used for + any channel in this block. this is because coefficients for the long + and short transforms cannot be mixed. */ + downmix_output = s->channels != s->out_channels && + !((s->output_mode & AC3_OUTPUT_LFEON) && + s->fbw_channels == s->out_channels); + if (different_transforms) { + /* the delay samples have already been downmixed, so we upmix the delay + samples in order to reconstruct all channels before downmixing. */ + if (s->downmixed) { + s->downmixed = 0; + ac3_upmix_delay(s); + } + + do_imdct(s, s->channels); + + if (downmix_output) { + s->ac3dsp.downmix(s->outptr, s->downmix_coeffs, + s->out_channels, s->fbw_channels, 256); + } + } else { + if (downmix_output) { + s->ac3dsp.downmix(s->xcfptr + 1, s->downmix_coeffs, + s->out_channels, s->fbw_channels, 256); + } + + if (downmix_output && !s->downmixed) { + s->downmixed = 1; + s->ac3dsp.downmix(s->dlyptr, s->downmix_coeffs, s->out_channels, + s->fbw_channels, 128); + } + + do_imdct(s, s->out_channels); + } + + return 0; +} + +/** + * Decode a single AC-3 frame. + */ +static int ac3_decode_frame(AVCodecContext * avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) +{ + AVFrame *frame = data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AC3DecodeContext *s = avctx->priv_data; + int blk, ch, err, ret; + const uint8_t *channel_map; + const float *output[AC3_MAX_CHANNELS]; + + /* copy input buffer to decoder context to avoid reading past the end + of the buffer, which can be caused by a damaged input stream. */ + if (buf_size >= 2 && AV_RB16(buf) == 0x770B) { + // seems to be byte-swapped AC-3 + int cnt = FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE) >> 1; + s->dsp.bswap16_buf((uint16_t *)s->input_buffer, (const uint16_t *)buf, cnt); + } else + memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE)); + buf = s->input_buffer; + /* initialize the GetBitContext with the start of valid AC-3 Frame */ + init_get_bits(&s->gbc, buf, buf_size * 8); + + /* parse the syncinfo */ + err = parse_frame_header(s); + + if (err) { + switch (err) { + case AAC_AC3_PARSE_ERROR_SYNC: + av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); + return AVERROR_INVALIDDATA; + case AAC_AC3_PARSE_ERROR_BSID: + av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n"); + break; + case AAC_AC3_PARSE_ERROR_SAMPLE_RATE: + av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); + break; + case AAC_AC3_PARSE_ERROR_FRAME_SIZE: + av_log(avctx, AV_LOG_ERROR, "invalid frame size\n"); + break; + case AAC_AC3_PARSE_ERROR_FRAME_TYPE: + /* skip frame if CRC is ok. otherwise use error concealment. */ + /* TODO: add support for substreams and dependent frames */ + if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) { + av_log(avctx, AV_LOG_WARNING, "unsupported frame type : " + "skipping frame\n"); + *got_frame_ptr = 0; + return buf_size; + } else { + av_log(avctx, AV_LOG_ERROR, "invalid frame type\n"); + } + break; + case AAC_AC3_PARSE_ERROR_CRC: + case AAC_AC3_PARSE_ERROR_CHANNEL_CFG: + break; + default: // Normal AVERROR do not try to recover. + *got_frame_ptr = 0; + return err; + } + } else { + /* check that reported frame size fits in input buffer */ + if (s->frame_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); + err = AAC_AC3_PARSE_ERROR_FRAME_SIZE; + } else if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) { + /* check for crc mismatch */ + if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], + s->frame_size - 2)) { + av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); + err = AAC_AC3_PARSE_ERROR_CRC; + } + } + } + + /* if frame is ok, set audio parameters */ + if (!err) { + avctx->sample_rate = s->sample_rate; + avctx->bit_rate = s->bit_rate; + } + + /* channel config */ + if (!err || (s->channels && s->out_channels != s->channels)) { + s->out_channels = s->channels; + s->output_mode = s->channel_mode; + if (s->lfe_on) + s->output_mode |= AC3_OUTPUT_LFEON; + if (avctx->request_channels > 0 && avctx->request_channels <= 2 && + avctx->request_channels < s->channels) { + s->out_channels = avctx->request_channels; + s->output_mode = avctx->request_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO; + s->channel_layout = avpriv_ac3_channel_layout_tab[s->output_mode]; + } + avctx->channels = s->out_channels; + avctx->channel_layout = s->channel_layout; + + s->loro_center_mix_level = gain_levels[s-> center_mix_level]; + s->loro_surround_mix_level = gain_levels[s->surround_mix_level]; + s->ltrt_center_mix_level = LEVEL_MINUS_3DB; + s->ltrt_surround_mix_level = LEVEL_MINUS_3DB; + /* set downmixing coefficients if needed */ + if (s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && + s->fbw_channels == s->out_channels)) { + set_downmix_coeffs(s); + } + } else if (!s->channels) { + av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n"); + return AVERROR_INVALIDDATA; + } + avctx->channels = s->out_channels; + + /* set audio service type based on bitstream mode for AC-3 */ + avctx->audio_service_type = s->bitstream_mode; + if (s->bitstream_mode == 0x7 && s->channels > 1) + avctx->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE; + + /* get output buffer */ + frame->nb_samples = s->num_blocks * AC3_BLOCK_SIZE; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + return ret; + + /* decode the audio blocks */ + channel_map = ff_ac3_dec_channel_map[s->output_mode & ~AC3_OUTPUT_LFEON][s->lfe_on]; + for (ch = 0; ch < AC3_MAX_CHANNELS; ch++) { + output[ch] = s->output[ch]; + s->outptr[ch] = s->output[ch]; + } + for (ch = 0; ch < s->channels; ch++) { + if (ch < s->out_channels) + s->outptr[channel_map[ch]] = (float *)frame->data[ch]; + } + for (blk = 0; blk < s->num_blocks; blk++) { + if (!err && decode_audio_block(s, blk)) { + av_log(avctx, AV_LOG_ERROR, "error decoding the audio block\n"); + err = 1; + } + if (err) + for (ch = 0; ch < s->out_channels; ch++) + memcpy(((float*)frame->data[ch]) + AC3_BLOCK_SIZE*blk, output[ch], sizeof(**output) * AC3_BLOCK_SIZE); + for (ch = 0; ch < s->out_channels; ch++) + output[ch] = s->outptr[channel_map[ch]]; + for (ch = 0; ch < s->out_channels; ch++) { + if (!ch || channel_map[ch]) + s->outptr[channel_map[ch]] += AC3_BLOCK_SIZE; + } + } + + av_frame_set_decode_error_flags(frame, err ? FF_DECODE_ERROR_INVALID_BITSTREAM : 0); + + /* keep last block for error concealment in next frame */ + for (ch = 0; ch < s->out_channels; ch++) + memcpy(s->output[ch], output[ch], sizeof(**output) * AC3_BLOCK_SIZE); + + *got_frame_ptr = 1; + + return FFMIN(buf_size, s->frame_size); +} + +/** + * Uninitialize the AC-3 decoder. + */ +static av_cold int ac3_decode_end(AVCodecContext *avctx) +{ + AC3DecodeContext *s = avctx->priv_data; + ff_mdct_end(&s->imdct_512); + ff_mdct_end(&s->imdct_256); + + return 0; +} + +#define OFFSET(x) offsetof(AC3DecodeContext, x) +#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM) +static const AVOption options[] = { + { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 1.0, PAR }, + +{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0, "dmix_mode"}, +{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, +{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, +{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, +{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, + + { NULL}, +}; + +static const AVClass ac3_decoder_class = { + .class_name = "AC3 decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVCodec ff_ac3_decoder = { + .name = "ac3", + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_AC3, + .priv_data_size = sizeof (AC3DecodeContext), + .init = ac3_decode_init, + .close = ac3_decode_end, + .decode = ac3_decode_frame, + .capabilities = CODEC_CAP_DR1, + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, + AV_SAMPLE_FMT_NONE }, + .priv_class = &ac3_decoder_class, +}; + +#if CONFIG_EAC3_DECODER +static const AVClass eac3_decoder_class = { + .class_name = "E-AC3 decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVCodec ff_eac3_decoder = { + .name = "eac3", + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_EAC3, + .priv_data_size = sizeof (AC3DecodeContext), + .init = ac3_decode_init, + .close = ac3_decode_end, + .decode = ac3_decode_frame, + .capabilities = CODEC_CAP_DR1, + .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, + AV_SAMPLE_FMT_NONE }, + .priv_class = &eac3_decoder_class, +}; +#endif diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.h new file mode 100644 index 000000000..ae72d80c8 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec.h @@ -0,0 +1,241 @@ +/* + * Common code between the AC-3 and E-AC-3 decoders + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Common code between the AC-3 and E-AC-3 decoders. + * + * Summary of MDCT Coefficient Grouping: + * The individual MDCT coefficient indices are often referred to in the + * (E-)AC-3 specification as frequency bins. These bins are grouped together + * into subbands of 12 coefficients each. The subbands are grouped together + * into bands as defined in the bitstream by the band structures, which + * determine the number of bands and the size of each band. The full spectrum + * of 256 frequency bins is divided into 1 DC bin + 21 subbands = 253 bins. + * This system of grouping coefficients is used for channel bandwidth, stereo + * rematrixing, channel coupling, enhanced coupling, and spectral extension. + * + * +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+ + * |1| |12| | [12|12|12|12] | | | | | | | | | | | | |3| + * +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+ + * ~~~ ~~~~ ~~~~~~~~~~~~~ ~~~ + * | | | | + * | | | 3 unused frequency bins--+ + * | | | + * | | +--1 band containing 4 subbands + * | | + * | +--1 subband of 12 frequency bins + * | + * +--DC frequency bin + */ + +#ifndef AVCODEC_AC3DEC_H +#define AVCODEC_AC3DEC_H + +#include "libavutil/float_dsp.h" +#include "libavutil/lfg.h" +#include "ac3.h" +#include "ac3dsp.h" +#include "get_bits.h" +#include "dsputil.h" +#include "fft.h" +#include "fmtconvert.h" + +#define AC3_OUTPUT_LFEON 8 + +#define SPX_MAX_BANDS 17 + +/** Large enough for maximum possible frame size when the specification limit is ignored */ +#define AC3_FRAME_BUFFER_SIZE 32768 + +typedef struct AC3DecodeContext { + AVClass *class; ///< class for AVOptions + AVCodecContext *avctx; ///< parent context + GetBitContext gbc; ///< bitstream reader + +///@name Bit stream information +///@{ + int frame_type; ///< frame type (strmtyp) + int substreamid; ///< substream identification + int frame_size; ///< current frame size, in bytes + int bit_rate; ///< stream bit rate, in bits-per-second + int sample_rate; ///< sample frequency, in Hz + int num_blocks; ///< number of audio blocks + int bitstream_mode; ///< bitstream mode (bsmod) + int channel_mode; ///< channel mode (acmod) + int channel_layout; ///< channel layout + int lfe_on; ///< lfe channel in use + int channel_map; ///< custom channel map + int center_mix_level; ///< Center mix level index + int surround_mix_level; ///< Surround mix level index + int eac3; ///< indicates if current frame is E-AC-3 +///@} + + int preferred_stereo_downmix; + float ltrt_center_mix_level; + float ltrt_surround_mix_level; + float loro_center_mix_level; + float loro_surround_mix_level; + +///@name Frame syntax parameters + int snr_offset_strategy; ///< SNR offset strategy (snroffststr) + int block_switch_syntax; ///< block switch syntax enabled (blkswe) + int dither_flag_syntax; ///< dither flag syntax enabled (dithflage) + int bit_allocation_syntax; ///< bit allocation model syntax enabled (bamode) + int fast_gain_syntax; ///< fast gain codes enabled (frmfgaincode) + int dba_syntax; ///< delta bit allocation syntax enabled (dbaflde) + int skip_syntax; ///< skip field syntax enabled (skipflde) + ///@} + +///@name Standard coupling + int cpl_in_use[AC3_MAX_BLOCKS]; ///< coupling in use (cplinu) + int cpl_strategy_exists[AC3_MAX_BLOCKS];///< coupling strategy exists (cplstre) + int channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling (chincpl) + int phase_flags_in_use; ///< phase flags in use (phsflginu) + int phase_flags[AC3_MAX_CPL_BANDS]; ///< phase flags (phsflg) + int num_cpl_bands; ///< number of coupling bands (ncplbnd) + uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]; ///< number of coeffs in each coupling band + int firstchincpl; ///< first channel in coupling + int first_cpl_coords[AC3_MAX_CHANNELS]; ///< first coupling coordinates states (firstcplcos) + int cpl_coords[AC3_MAX_CHANNELS][AC3_MAX_CPL_BANDS]; ///< coupling coordinates (cplco) +///@} + +///@name Spectral extension +///@{ + int spx_in_use; ///< spectral extension in use (spxinu) + uint8_t channel_uses_spx[AC3_MAX_CHANNELS]; ///< channel uses spectral extension (chinspx) + int8_t spx_atten_code[AC3_MAX_CHANNELS]; ///< spx attenuation code (spxattencod) + int spx_src_start_freq; ///< spx start frequency bin + int spx_dst_end_freq; ///< spx end frequency bin + int spx_dst_start_freq; ///< spx starting frequency bin for copying (copystartmant) + ///< the copy region ends at the start of the spx region. + int num_spx_bands; ///< number of spx bands (nspxbnds) + uint8_t spx_band_sizes[SPX_MAX_BANDS]; ///< number of bins in each spx band + uint8_t first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos) + float spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact) + float spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact) +///@} + +///@name Adaptive hybrid transform + int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu) + int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][AC3_MAX_BLOCKS]; ///< pre-IDCT mantissas +///@} + +///@name Channel + int fbw_channels; ///< number of full-bandwidth channels + int channels; ///< number of total channels + int lfe_ch; ///< index of LFE channel + float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients + int downmixed; ///< indicates if coeffs are currently downmixed + int output_mode; ///< output channel configuration + int out_channels; ///< number of output channels +///@} + +///@name Dynamic range + float dynamic_range[2]; ///< dynamic range + float drc_scale; ///< percentage of dynamic range compression to be applied +///@} + +///@name Bandwidth + int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin (strtmant) + int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin (endmant) +///@} + +///@name Rematrixing + int num_rematrixing_bands; ///< number of rematrixing bands (nrematbnd) + int rematrixing_flags[4]; ///< rematrixing flags (rematflg) +///@} + +///@name Exponents + int num_exp_groups[AC3_MAX_CHANNELS]; ///< Number of exponent groups (nexpgrp) + int8_t dexps[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< decoded exponents + int exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]; ///< exponent strategies (expstr) +///@} + +///@name Bit allocation + AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters + int first_cpl_leak; ///< first coupling leak state (firstcplleak) + int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets (snroffst) + int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values/SMR's (fgain) + uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< bit allocation pointers + int16_t psd[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< scaled exponents + int16_t band_psd[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; ///< interpolated exponents + int16_t mask[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; ///< masking curve values + int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode + int dba_nsegs[AC3_MAX_CHANNELS]; ///< number of delta segments + uint8_t dba_offsets[AC3_MAX_CHANNELS][8]; ///< delta segment offsets + uint8_t dba_lengths[AC3_MAX_CHANNELS][8]; ///< delta segment lengths + uint8_t dba_values[AC3_MAX_CHANNELS][8]; ///< delta values for each segment +///@} + +///@name Zero-mantissa dithering + int dither_flag[AC3_MAX_CHANNELS]; ///< dither flags (dithflg) + AVLFG dith_state; ///< for dither generation +///@} + +///@name IMDCT + int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags (blksw) + FFTContext imdct_512; ///< for 512 sample IMDCT + FFTContext imdct_256; ///< for 256 sample IMDCT +///@} + +///@name Optimization + DSPContext dsp; ///< for optimization + AVFloatDSPContext fdsp; + AC3DSPContext ac3dsp; + FmtConvertContext fmt_conv; ///< optimized conversion functions +///@} + + float *outptr[AC3_MAX_CHANNELS]; + float *xcfptr[AC3_MAX_CHANNELS]; + float *dlyptr[AC3_MAX_CHANNELS]; + +///@name Aligned arrays + DECLARE_ALIGNED(16, int32_t, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< fixed-point transform coefficients + DECLARE_ALIGNED(32, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients + DECLARE_ALIGNED(32, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block + DECLARE_ALIGNED(32, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients + DECLARE_ALIGNED(32, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing + DECLARE_ALIGNED(32, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing + DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread +///@} +} AC3DecodeContext; + +/** + * Parse the E-AC-3 frame header. + * This parses both the bit stream info and audio frame header. + */ +int ff_eac3_parse_header(AC3DecodeContext *s); + +/** + * Decode mantissas in a single channel for the entire frame. + * This is used when AHT mode is enabled. + */ +void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch); + +/** + * Apply spectral extension to each channel by copying lower frequency + * coefficients to higher frequency bins and applying side information to + * approximate the original high frequency signal. + */ +void ff_eac3_apply_spectral_extension(AC3DecodeContext *s); + +#endif /* AVCODEC_AC3DEC_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.c new file mode 100644 index 000000000..d0a9b1ec4 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.c @@ -0,0 +1,60 @@ +/* + * AC-3 and E-AC-3 decoder tables + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Tables taken directly from the AC-3 spec. + */ + +#include "ac3dec_data.h" +#include "ac3.h" + +/** + * Table used to ungroup 3 values stored in 5 bits. + * Used by bap=1 mantissas and GAQ. + * ff_ac3_ungroup_3_in_5_bits_tab[i] = { i/9, (i%9)/3, (i%9)%3 } + */ +const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3] = { + { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, { 0, 1, 0 }, + { 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 }, { 0, 2, 1 }, + { 0, 2, 2 }, { 1, 0, 0 }, { 1, 0, 1 }, { 1, 0, 2 }, + { 1, 1, 0 }, { 1, 1, 1 }, { 1, 1, 2 }, { 1, 2, 0 }, + { 1, 2, 1 }, { 1, 2, 2 }, { 2, 0, 0 }, { 2, 0, 1 }, + { 2, 0, 2 }, { 2, 1, 0 }, { 2, 1, 1 }, { 2, 1, 2 }, + { 2, 2, 0 }, { 2, 2, 1 }, { 2, 2, 2 }, { 3, 0, 0 }, + { 3, 0, 1 }, { 3, 0, 2 }, { 3, 1, 0 }, { 3, 1, 1 } +}; + +const uint8_t ff_eac3_hebap_tab[64] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, + 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, + 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, + 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, + 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, + 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, + 19, 19, 19, 19, +}; + +/** + * Table E2.15 Default Spectral Extension Banding Structure + */ +const uint8_t ff_eac3_default_spx_band_struct[17] = +{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }; diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.h new file mode 100644 index 000000000..975b52ef2 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dec_data.h @@ -0,0 +1,32 @@ +/* + * AC-3 and E-AC-3 decoder tables + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AC3DEC_DATA_H +#define AVCODEC_AC3DEC_DATA_H + +#include + +extern const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]; + +extern const uint8_t ff_eac3_hebap_tab[64]; +extern const uint8_t ff_eac3_default_spx_band_struct[17]; + +#endif /* AVCODEC_AC3DEC_DATA_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.c new file mode 100644 index 000000000..6df3a68a4 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.c @@ -0,0 +1,263 @@ +/* + * AC-3 DSP utils + * Copyright (c) 2011 Justin Ruggles + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/avassert.h" +#include "avcodec.h" +#include "ac3.h" +#include "ac3dsp.h" +#include "mathops.h" + +static void ac3_exponent_min_c(uint8_t *exp, int num_reuse_blocks, int nb_coefs) +{ + int blk, i; + + if (!num_reuse_blocks) + return; + + for (i = 0; i < nb_coefs; i++) { + uint8_t min_exp = *exp; + uint8_t *exp1 = exp + 256; + for (blk = 0; blk < num_reuse_blocks; blk++) { + uint8_t next_exp = *exp1; + if (next_exp < min_exp) + min_exp = next_exp; + exp1 += 256; + } + *exp++ = min_exp; + } +} + +static int ac3_max_msb_abs_int16_c(const int16_t *src, int len) +{ + int i, v = 0; + for (i = 0; i < len; i++) + v |= abs(src[i]); + return v; +} + +static void ac3_lshift_int16_c(int16_t *src, unsigned int len, + unsigned int shift) +{ + uint32_t *src32 = (uint32_t *)src; + const uint32_t mask = ~(((1 << shift) - 1) << 16); + int i; + len >>= 1; + for (i = 0; i < len; i += 8) { + src32[i ] = (src32[i ] << shift) & mask; + src32[i+1] = (src32[i+1] << shift) & mask; + src32[i+2] = (src32[i+2] << shift) & mask; + src32[i+3] = (src32[i+3] << shift) & mask; + src32[i+4] = (src32[i+4] << shift) & mask; + src32[i+5] = (src32[i+5] << shift) & mask; + src32[i+6] = (src32[i+6] << shift) & mask; + src32[i+7] = (src32[i+7] << shift) & mask; + } +} + +static void ac3_rshift_int32_c(int32_t *src, unsigned int len, + unsigned int shift) +{ + do { + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + len -= 8; + } while (len > 0); +} + +static void float_to_fixed24_c(int32_t *dst, const float *src, unsigned int len) +{ + const float scale = 1 << 24; + do { + *dst++ = lrintf(*src++ * scale); + *dst++ = lrintf(*src++ * scale); + *dst++ = lrintf(*src++ * scale); + *dst++ = lrintf(*src++ * scale); + *dst++ = lrintf(*src++ * scale); + *dst++ = lrintf(*src++ * scale); + *dst++ = lrintf(*src++ * scale); + *dst++ = lrintf(*src++ * scale); + len -= 8; + } while (len > 0); +} + +static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd, + int start, int end, + int snr_offset, int floor, + const uint8_t *bap_tab, uint8_t *bap) +{ + int bin, band, band_end; + + /* special case, if snr offset is -960, set all bap's to zero */ + if (snr_offset == -960) { + memset(bap, 0, AC3_MAX_COEFS); + return; + } + + bin = start; + band = ff_ac3_bin_to_band_tab[start]; + do { + int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor; + band_end = ff_ac3_band_start_tab[++band]; + band_end = FFMIN(band_end, end); + + for (; bin < band_end; bin++) { + int address = av_clip((psd[bin] - m) >> 5, 0, 63); + bap[bin] = bap_tab[address]; + } + } while (end > band_end); +} + +static void ac3_update_bap_counts_c(uint16_t mant_cnt[16], uint8_t *bap, + int len) +{ + while (len-- > 0) + mant_cnt[bap[len]]++; +} + +DECLARE_ALIGNED(16, const uint16_t, ff_ac3_bap_bits)[16] = { + 0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 +}; + +static int ac3_compute_mantissa_size_c(uint16_t mant_cnt[6][16]) +{ + int blk, bap; + int bits = 0; + + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + // bap=1 : 3 mantissas in 5 bits + bits += (mant_cnt[blk][1] / 3) * 5; + // bap=2 : 3 mantissas in 7 bits + // bap=4 : 2 mantissas in 7 bits + bits += ((mant_cnt[blk][2] / 3) + (mant_cnt[blk][4] >> 1)) * 7; + // bap=3 : 1 mantissa in 3 bits + bits += mant_cnt[blk][3] * 3; + // bap=5 to 15 : get bits per mantissa from table + for (bap = 5; bap < 16; bap++) + bits += mant_cnt[blk][bap] * ff_ac3_bap_bits[bap]; + } + return bits; +} + +static void ac3_extract_exponents_c(uint8_t *exp, int32_t *coef, int nb_coefs) +{ + int i; + + for (i = 0; i < nb_coefs; i++) { + int v = abs(coef[i]); + exp[i] = v ? 23 - av_log2(v) : 24; + } +} + +static void ac3_sum_square_butterfly_int32_c(int64_t sum[4], + const int32_t *coef0, + const int32_t *coef1, + int len) +{ + int i; + + sum[0] = sum[1] = sum[2] = sum[3] = 0; + + for (i = 0; i < len; i++) { + int lt = coef0[i]; + int rt = coef1[i]; + int md = lt + rt; + int sd = lt - rt; + MAC64(sum[0], lt, lt); + MAC64(sum[1], rt, rt); + MAC64(sum[2], md, md); + MAC64(sum[3], sd, sd); + } +} + +static void ac3_sum_square_butterfly_float_c(float sum[4], + const float *coef0, + const float *coef1, + int len) +{ + int i; + + sum[0] = sum[1] = sum[2] = sum[3] = 0; + + for (i = 0; i < len; i++) { + float lt = coef0[i]; + float rt = coef1[i]; + float md = lt + rt; + float sd = lt - rt; + sum[0] += lt * lt; + sum[1] += rt * rt; + sum[2] += md * md; + sum[3] += sd * sd; + } +} + +static void ac3_downmix_c(float **samples, float (*matrix)[2], + int out_ch, int in_ch, int len) +{ + int i, j; + float v0, v1; + if (out_ch == 2) { + for (i = 0; i < len; i++) { + v0 = v1 = 0.0f; + for (j = 0; j < in_ch; j++) { + v0 += samples[j][i] * matrix[j][0]; + v1 += samples[j][i] * matrix[j][1]; + } + samples[0][i] = v0; + samples[1][i] = v1; + } + } else if (out_ch == 1) { + for (i = 0; i < len; i++) { + v0 = 0.0f; + for (j = 0; j < in_ch; j++) + v0 += samples[j][i] * matrix[j][0]; + samples[0][i] = v0; + } + } +} + +av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) +{ + c->ac3_exponent_min = ac3_exponent_min_c; + c->ac3_max_msb_abs_int16 = ac3_max_msb_abs_int16_c; + c->ac3_lshift_int16 = ac3_lshift_int16_c; + c->ac3_rshift_int32 = ac3_rshift_int32_c; + c->float_to_fixed24 = float_to_fixed24_c; + c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c; + c->update_bap_counts = ac3_update_bap_counts_c; + c->compute_mantissa_size = ac3_compute_mantissa_size_c; + c->extract_exponents = ac3_extract_exponents_c; + c->sum_square_butterfly_int32 = ac3_sum_square_butterfly_int32_c; + c->sum_square_butterfly_float = ac3_sum_square_butterfly_float_c; + c->downmix = ac3_downmix_c; + + if (ARCH_ARM) + ff_ac3dsp_init_arm(c, bit_exact); + if (ARCH_X86) + ff_ac3dsp_init_x86(c, bit_exact); + if (ARCH_MIPS) + ff_ac3dsp_init_mips(c, bit_exact); +} diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.h new file mode 100644 index 000000000..bafbc8995 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3dsp.h @@ -0,0 +1,144 @@ +/* + * AC-3 DSP utils + * Copyright (c) 2011 Justin Ruggles + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AC3DSP_H +#define AVCODEC_AC3DSP_H + +#include + +/** + * Number of mantissa bits written for each bap value. + * bap values with fractional bits are set to 0 and are calculated separately. + */ +extern const uint16_t ff_ac3_bap_bits[16]; + +typedef struct AC3DSPContext { + /** + * Set each encoded exponent in a block to the minimum of itself and the + * exponents in the same frequency bin of up to 5 following blocks. + * @param exp pointer to the start of the current block of exponents. + * constraints: align 16 + * @param num_reuse_blocks number of blocks that will reuse exponents from the current block. + * constraints: range 0 to 5 + * @param nb_coefs number of frequency coefficients. + */ + void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs); + + /** + * Calculate the maximum MSB of the absolute value of each element in an + * array of int16_t. + * @param src input array + * constraints: align 16. values must be in range [-32767,32767] + * @param len number of values in the array + * constraints: multiple of 16 greater than 0 + * @return a value with the same MSB as max(abs(src[])) + */ + int (*ac3_max_msb_abs_int16)(const int16_t *src, int len); + + /** + * Left-shift each value in an array of int16_t by a specified amount. + * @param src input array + * constraints: align 16 + * @param len number of values in the array + * constraints: multiple of 32 greater than 0 + * @param shift left shift amount + * constraints: range [0,15] + */ + void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift); + + /** + * Right-shift each value in an array of int32_t by a specified amount. + * @param src input array + * constraints: align 16 + * @param len number of values in the array + * constraints: multiple of 16 greater than 0 + * @param shift right shift amount + * constraints: range [0,31] + */ + void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift); + + /** + * Convert an array of float in range [-1.0,1.0] to int32_t with range + * [-(1<<24),(1<<24)] + * + * @param dst destination array of int32_t. + * constraints: 16-byte aligned + * @param src source array of float. + * constraints: 16-byte aligned + * @param len number of elements to convert. + * constraints: multiple of 32 greater than zero + */ + void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len); + + /** + * Calculate bit allocation pointers. + * The SNR is the difference between the masking curve and the signal. AC-3 + * uses this value for each frequency bin to allocate bits. The snroffset + * parameter is a global adjustment to the SNR for all bins. + * + * @param[in] mask masking curve + * @param[in] psd signal power for each frequency bin + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] snr_offset SNR adjustment + * @param[in] floor noise floor + * @param[in] bap_tab look-up table for bit allocation pointers + * @param[out] bap bit allocation pointers + */ + void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, + int snr_offset, int floor, + const uint8_t *bap_tab, uint8_t *bap); + + /** + * Update bap counts using the supplied array of bap. + * + * @param[out] mant_cnt bap counts for 1 block + * @param[in] bap array of bap, pointing to start coef bin + * @param[in] len number of elements to process + */ + void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len); + + /** + * Calculate the number of bits needed to encode a set of mantissas. + * + * @param[in] mant_cnt bap counts for all blocks + * @return mantissa bit count + */ + int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]); + + void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs); + + void (*sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0, + const int32_t *coef1, int len); + + void (*sum_square_butterfly_float)(float sum[4], const float *coef0, + const float *coef1, int len); + + void (*downmix)(float **samples, float (*matrix)[2], int out_ch, + int in_ch, int len); +} AC3DSPContext; + +void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); +void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact); +void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact); +void ff_ac3dsp_init_mips(AC3DSPContext *c, int bit_exact); + +#endif /* AVCODEC_AC3DSP_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.c new file mode 100644 index 000000000..1ae7ddf2a --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.c @@ -0,0 +1,314 @@ +/* + * AC-3 tables + * copyright (c) 2001 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * tables taken directly from the AC-3 spec. + */ + +#include "libavutil/channel_layout.h" +#include "avcodec.h" +#include "ac3tab.h" + +/** + * Possible frame sizes. + * from ATSC A/52 Table 5.18 Frame Size Code Table. + */ +const uint16_t ff_ac3_frame_size_tab[38][3] = { + { 64, 69, 96 }, + { 64, 70, 96 }, + { 80, 87, 120 }, + { 80, 88, 120 }, + { 96, 104, 144 }, + { 96, 105, 144 }, + { 112, 121, 168 }, + { 112, 122, 168 }, + { 128, 139, 192 }, + { 128, 140, 192 }, + { 160, 174, 240 }, + { 160, 175, 240 }, + { 192, 208, 288 }, + { 192, 209, 288 }, + { 224, 243, 336 }, + { 224, 244, 336 }, + { 256, 278, 384 }, + { 256, 279, 384 }, + { 320, 348, 480 }, + { 320, 349, 480 }, + { 384, 417, 576 }, + { 384, 418, 576 }, + { 448, 487, 672 }, + { 448, 488, 672 }, + { 512, 557, 768 }, + { 512, 558, 768 }, + { 640, 696, 960 }, + { 640, 697, 960 }, + { 768, 835, 1152 }, + { 768, 836, 1152 }, + { 896, 975, 1344 }, + { 896, 976, 1344 }, + { 1024, 1114, 1536 }, + { 1024, 1115, 1536 }, + { 1152, 1253, 1728 }, + { 1152, 1254, 1728 }, + { 1280, 1393, 1920 }, + { 1280, 1394, 1920 }, +}; + +/** + * Map audio coding mode (acmod) to number of full-bandwidth channels. + * from ATSC A/52 Table 5.8 Audio Coding Mode + */ +const uint8_t ff_ac3_channels_tab[8] = { + 2, 1, 2, 3, 3, 4, 4, 5 +}; + +/** + * Map audio coding mode (acmod) to channel layout mask. + */ +const uint16_t avpriv_ac3_channel_layout_tab[8] = { + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_SURROUND, + AV_CH_LAYOUT_2_1, + AV_CH_LAYOUT_4POINT0, + AV_CH_LAYOUT_2_2, + AV_CH_LAYOUT_5POINT0 +}; + +#define COMMON_CHANNEL_MAP \ + { { 0, 1, }, { 0, 1, 2, } },\ + { { 0, }, { 0, 1, } },\ + { { 0, 1, }, { 0, 1, 2, } },\ + { { 0, 2, 1, }, { 0, 2, 1, 3, } },\ + { { 0, 1, 2, }, { 0, 1, 3, 2, } },\ + { { 0, 2, 1, 3, }, { 0, 2, 1, 4, 3, } }, + +/** + * Table to remap channels from SMPTE order to AC-3 order. + * [channel_mode][lfe][ch] + */ +const uint8_t ff_ac3_enc_channel_map[8][2][6] = { + COMMON_CHANNEL_MAP + { { 0, 1, 2, 3, }, { 0, 1, 3, 4, 2, } }, + { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } }, +}; + +/** + * Table to remap channels from AC-3 order to SMPTE order. + * [channel_mode][lfe][ch] + */ +const uint8_t ff_ac3_dec_channel_map[8][2][6] = { + COMMON_CHANNEL_MAP + { { 0, 1, 2, 3, }, { 0, 1, 4, 2, 3, } }, + { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } }, +}; + +/* possible frequencies */ +const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 }; + +/* possible bitrates */ +const uint16_t ff_ac3_bitrate_tab[19] = { + 32, 40, 48, 56, 64, 80, 96, 112, 128, + 160, 192, 224, 256, 320, 384, 448, 512, 576, 640 +}; + +/** + * Table of bin locations for rematrixing bands + * reference: Section 7.5.2 Rematrixing : Frequency Band Definitions + */ +const uint8_t ff_ac3_rematrix_band_tab[5] = { 13, 25, 37, 61, 253 }; + +/** + * Table E2.16 Default Coupling Banding Structure + */ +const uint8_t ff_eac3_default_cpl_band_struct[18] = { + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 +}; + +/* AC-3 MDCT window */ + +/* MDCT window */ +DECLARE_ALIGNED(16, const int16_t, ff_ac3_window)[AC3_WINDOW_SIZE/2] = { + 4, 7, 12, 16, 21, 28, 34, 42, + 51, 61, 72, 84, 97, 111, 127, 145, + 164, 184, 207, 231, 257, 285, 315, 347, + 382, 419, 458, 500, 544, 591, 641, 694, + 750, 810, 872, 937, 1007, 1079, 1155, 1235, + 1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016, + 2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076, + 3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444, + 4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127, + 6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112, + 8380, 8652, 8927, 9207, 9491, 9778,10069,10363, +10660,10960,11264,11570,11879,12190,12504,12820, +13138,13458,13780,14103,14427,14753,15079,15407, +15735,16063,16392,16720,17049,17377,17705,18032, +18358,18683,19007,19330,19651,19970,20287,20602, +20914,21225,21532,21837,22139,22438,22733,23025, +23314,23599,23880,24157,24430,24699,24964,25225, +25481,25732,25979,26221,26459,26691,26919,27142, +27359,27572,27780,27983,28180,28373,28560,28742, +28919,29091,29258,29420,29577,29729,29876,30018, +30155,30288,30415,30538,30657,30771,30880,30985, +31086,31182,31274,31363,31447,31528,31605,31678, +31747,31814,31877,31936,31993,32046,32097,32145, +32190,32232,32272,32310,32345,32378,32409,32438, +32465,32490,32513,32535,32556,32574,32592,32608, +32623,32636,32649,32661,32671,32681,32690,32698, +32705,32712,32718,32724,32729,32733,32737,32741, +32744,32747,32750,32752,32754,32756,32757,32759, +32760,32761,32762,32763,32764,32764,32765,32765, +32766,32766,32766,32766,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767, +}; + +const uint8_t ff_ac3_log_add_tab[260]= { +0x40,0x3f,0x3e,0x3d,0x3c,0x3b,0x3a,0x39,0x38,0x37, +0x36,0x35,0x34,0x34,0x33,0x32,0x31,0x30,0x2f,0x2f, +0x2e,0x2d,0x2c,0x2c,0x2b,0x2a,0x29,0x29,0x28,0x27, +0x26,0x26,0x25,0x24,0x24,0x23,0x23,0x22,0x21,0x21, +0x20,0x20,0x1f,0x1e,0x1e,0x1d,0x1d,0x1c,0x1c,0x1b, +0x1b,0x1a,0x1a,0x19,0x19,0x18,0x18,0x17,0x17,0x16, +0x16,0x15,0x15,0x15,0x14,0x14,0x13,0x13,0x13,0x12, +0x12,0x12,0x11,0x11,0x11,0x10,0x10,0x10,0x0f,0x0f, +0x0f,0x0e,0x0e,0x0e,0x0d,0x0d,0x0d,0x0d,0x0c,0x0c, +0x0c,0x0c,0x0b,0x0b,0x0b,0x0b,0x0a,0x0a,0x0a,0x0a, +0x0a,0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x08,0x08, +0x08,0x08,0x07,0x07,0x07,0x07,0x07,0x07,0x06,0x06, +0x06,0x06,0x06,0x06,0x06,0x06,0x05,0x05,0x05,0x05, +0x05,0x05,0x05,0x05,0x04,0x04,0x04,0x04,0x04,0x04, +0x04,0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03, +0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x02, +0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, +0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01, +0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]= { +{ 0x04d0,0x04f0,0x0580 }, +{ 0x04d0,0x04f0,0x0580 }, +{ 0x0440,0x0460,0x04b0 }, +{ 0x0400,0x0410,0x0450 }, +{ 0x03e0,0x03e0,0x0420 }, +{ 0x03c0,0x03d0,0x03f0 }, +{ 0x03b0,0x03c0,0x03e0 }, +{ 0x03b0,0x03b0,0x03d0 }, +{ 0x03a0,0x03b0,0x03c0 }, +{ 0x03a0,0x03a0,0x03b0 }, +{ 0x03a0,0x03a0,0x03b0 }, +{ 0x03a0,0x03a0,0x03b0 }, +{ 0x03a0,0x03a0,0x03a0 }, +{ 0x0390,0x03a0,0x03a0 }, +{ 0x0390,0x0390,0x03a0 }, +{ 0x0390,0x0390,0x03a0 }, +{ 0x0380,0x0390,0x03a0 }, +{ 0x0380,0x0380,0x03a0 }, +{ 0x0370,0x0380,0x03a0 }, +{ 0x0370,0x0380,0x03a0 }, +{ 0x0360,0x0370,0x0390 }, +{ 0x0360,0x0370,0x0390 }, +{ 0x0350,0x0360,0x0390 }, +{ 0x0350,0x0360,0x0390 }, +{ 0x0340,0x0350,0x0380 }, +{ 0x0340,0x0350,0x0380 }, +{ 0x0330,0x0340,0x0380 }, +{ 0x0320,0x0340,0x0370 }, +{ 0x0310,0x0320,0x0360 }, +{ 0x0300,0x0310,0x0350 }, +{ 0x02f0,0x0300,0x0340 }, +{ 0x02f0,0x02f0,0x0330 }, +{ 0x02f0,0x02f0,0x0320 }, +{ 0x02f0,0x02f0,0x0310 }, +{ 0x0300,0x02f0,0x0300 }, +{ 0x0310,0x0300,0x02f0 }, +{ 0x0340,0x0320,0x02f0 }, +{ 0x0390,0x0350,0x02f0 }, +{ 0x03e0,0x0390,0x0300 }, +{ 0x0420,0x03e0,0x0310 }, +{ 0x0460,0x0420,0x0330 }, +{ 0x0490,0x0450,0x0350 }, +{ 0x04a0,0x04a0,0x03c0 }, +{ 0x0460,0x0490,0x0410 }, +{ 0x0440,0x0460,0x0470 }, +{ 0x0440,0x0440,0x04a0 }, +{ 0x0520,0x0480,0x0460 }, +{ 0x0800,0x0630,0x0440 }, +{ 0x0840,0x0840,0x0450 }, +{ 0x0840,0x0840,0x04e0 }, +}; + +const uint8_t ff_ac3_bap_tab[64]= { + 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, + 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, + 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, + 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, + 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, + 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, + 15, 15, 15, 15, +}; + +const uint8_t ff_ac3_slow_decay_tab[4]={ + 0x0f, 0x11, 0x13, 0x15, +}; + +const uint8_t ff_ac3_fast_decay_tab[4]={ + 0x3f, 0x53, 0x67, 0x7b, +}; + +const uint16_t ff_ac3_slow_gain_tab[4]= { + 0x540, 0x4d8, 0x478, 0x410, +}; + +const uint16_t ff_ac3_db_per_bit_tab[4]= { + 0x000, 0x700, 0x900, 0xb00, +}; + +const int16_t ff_ac3_floor_tab[8]= { + 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800, +}; + +const uint16_t ff_ac3_fast_gain_tab[8]= { + 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400, +}; + +/** + * Default channel map for a dependent substream defined by acmod + */ +const uint16_t ff_eac3_default_chmap[8] = { + AC3_CHMAP_L | AC3_CHMAP_R, // FIXME Ch1+Ch2 + AC3_CHMAP_C, + AC3_CHMAP_L | AC3_CHMAP_R, + AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R, + AC3_CHMAP_L | AC3_CHMAP_R | AC3_CHMAP_C_SUR, + AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_C_SUR, + AC3_CHMAP_L | AC3_CHMAP_R | AC3_CHMAP_L_SUR | AC3_CHMAP_R_SUR, + AC3_CHMAP_L | AC3_CHMAP_C | AC3_CHMAP_R | AC3_CHMAP_L_SUR | AC3_CHMAP_R_SUR +}; diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.h new file mode 100644 index 000000000..a71d093e7 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/ac3tab.h @@ -0,0 +1,73 @@ +/* + * AC-3 tables + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AC3TAB_H +#define AVCODEC_AC3TAB_H + +#include "config.h" +#include "libavutil/common.h" +#include "ac3.h" + +#if CONFIG_HARDCODED_TABLES +# define HCONST const +#else +# define HCONST +#endif + +extern const uint16_t ff_ac3_frame_size_tab[38][3]; +extern const uint8_t ff_ac3_channels_tab[8]; +extern av_export const uint16_t avpriv_ac3_channel_layout_tab[8]; +extern const uint8_t ff_ac3_enc_channel_map[8][2][6]; +extern const uint8_t ff_ac3_dec_channel_map[8][2][6]; +extern const uint16_t ff_ac3_sample_rate_tab[3]; +extern const uint16_t ff_ac3_bitrate_tab[19]; +extern const uint8_t ff_ac3_rematrix_band_tab[5]; +extern const uint8_t ff_eac3_default_cpl_band_struct[18]; +extern const int16_t ff_ac3_window[AC3_WINDOW_SIZE/2]; +extern const uint8_t ff_ac3_log_add_tab[260]; +extern const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]; +extern const uint8_t ff_ac3_bap_tab[64]; +extern const uint8_t ff_ac3_slow_decay_tab[4]; +extern const uint8_t ff_ac3_fast_decay_tab[4]; +extern const uint16_t ff_ac3_slow_gain_tab[4]; +extern const uint16_t ff_ac3_db_per_bit_tab[4]; +extern const int16_t ff_ac3_floor_tab[8]; +extern const uint16_t ff_ac3_fast_gain_tab[8]; +extern const uint16_t ff_eac3_default_chmap[8]; +extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1]; +extern HCONST uint8_t ff_ac3_bin_to_band_tab[253]; + +/** Custom channel map locations bitmask + * Other channels described in documentation: + * Lc/Rc pair, Lrs/Rrs pair, Ts, Lsd/Rsd pair, + * Lw/Rw pair, Lvh/Rvh pair, Cvh, Reserved, LFE2 + */ +enum CustomChannelMapLocation{ + AC3_CHMAP_L= 1<<(15-0), + AC3_CHMAP_C= 1<<(15-1), + AC3_CHMAP_R= 1<<(15-2), + AC3_CHMAP_L_SUR= 1<<(15-3), + AC3_CHMAP_R_SUR = 1<<(15-4), + AC3_CHMAP_C_SUR= 1<<(15-7), + AC3_CHMAP_LFE = 1<<(15-15) +}; + +#endif /* AVCODEC_AC3TAB_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.c new file mode 100644 index 000000000..b159e1682 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.c @@ -0,0 +1,1134 @@ +/* + * E-AC-3 tables + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Tables taken directly from the E-AC-3 spec. + */ + +#include "eac3_data.h" +#include "ac3.h" + +const uint8_t ff_eac3_bits_vs_hebap[20] = { + 0, 2, 3, 4, 5, 7, 8, 9, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, +}; + +/** + * Table E3.6, Gk=1 + * No gain (Gk=1) inverse quantization, remapping scale factors + * ff_eac3_gaq_remap[hebap+8] + */ +const int16_t ff_eac3_gaq_remap_1[12] = { + 4681, 2185, 1057, 520, 258, 129, 64, 32, 16, 8, 2, 0 +}; + +/** + * Table E3.6, Gk=2 & Gk=4, A + * Large mantissa inverse quantization, remapping scale factors + * ff_eac3_gaq_remap_2_4_a[hebap-8][Gk=2,4] + */ +const int16_t ff_eac3_gaq_remap_2_4_a[9][2] = { + { -10923, -4681 }, + { -14043, -6554 }, + { -15292, -7399 }, + { -15855, -7802 }, + { -16124, -7998 }, + { -16255, -8096 }, + { -16320, -8144 }, + { -16352, -8168 }, + { -16368, -8180 } +}; + +/** + * Table E3.6, Gk=2 & Gk=4, B + * Large mantissa inverse quantization, negative mantissa remapping offsets + * ff_eac3_gaq_remap_3_4_b[hebap-8][Gk=2,4] + */ +const int16_t ff_eac3_gaq_remap_2_4_b[9][2] = { + { -5461, -1170 }, + { -11703, -4915 }, + { -14199, -6606 }, + { -15327, -7412 }, + { -15864, -7805 }, + { -16126, -7999 }, + { -16255, -8096 }, + { -16320, -8144 }, + { -16352, -8168 } +}; + +static const int16_t vq_hebap1[4][6] = { +{ 7167, 4739, 1106, 4269, 10412, 4820}, +{ -5702, -3187, -14483, -1392, -2027, 849}, +{ 633, 6199, 7009, -12779, -2306, -2636}, +{ -1468, -7031, 7592, 10617, -5946, -3062}, +}; +static const int16_t vq_hebap2[8][6] = { +{ -12073, 608, -7019, 590, 4000, 869}, +{ 6692, 15689, -6178, -9239, -74, 133}, +{ 1855, -989, 20596, -2920, -4475, 225}, +{ -1194, -3901, -821, -6566, -875, -20298}, +{ -2762, -3181, -4094, -5623, -16945, 9765}, +{ 1547, 6839, 1980, 20233, -1071, -4986}, +{ 6221, -17915, -5516, 6266, 358, 1162}, +{ 3753, -1066, 4283, -3227, 15928, 10186}, +}; +static const int16_t vq_hebap3[16][6] = { +{ -10028, 20779, 10982, -4560, 798, -68}, +{ 11050, 20490, -6617, -5342, -1797, -1631}, +{ 3977, -542, 7118, -1166, 18844, 14678}, +{ -4320, -96, -7295, -492, -22050, -4277}, +{ 2692, 5856, 5530, 21862, -7212, -5325}, +{ -135, -23391, 962, 8115, -644, 382}, +{ -1563, 3400, -3299, 4693, -6892, 22398}, +{ 3535, 3030, 7296, 6214, 20476, -12099}, +{ 57, -6823, 1848, -22349, -5919, 6823}, +{ -821, -3655, -387, -6253, -1735, -22373}, +{ -6046, 1586, -18890, -14392, 9214, 705}, +{ -5716, 264, -17964, 14618, 7921, -337}, +{ -110, 108, 8, 74, -89, -50}, +{ 6612, -1517, 21687, -1658, -7949, -246}, +{ 21667, -6335, -8290, -101, -1349, -22}, +{ -22003, -6476, 7974, 648, 2054, -331}, +}; +static const int16_t vq_hebap4[32][6] = { +{ 6636, -4593, 14173, -17297, -16523, 864}, +{ 3658, 22540, 104, -1763, -84, 6}, +{ 21580, -17815, -7282, -1575, -2078, -320}, +{ -2233, 10017, -2728, 14938, -13640, -17659}, +{ -1564, -17738, -19161, 13735, 2757, 2951}, +{ 4520, 5510, 7393, 10799, 19231, -13770}, +{ 399, 2976, -1099, 5013, -1159, 22095}, +{ 3624, -2359, 4680, -2238, 22702, 3765}, +{ -4201, -8285, -6810, -12390, -18414, 15382}, +{ -5198, -6869, -10047, -8364, -16022, -20562}, +{ -142, -22671, -368, 4391, -464, -13}, +{ 814, -1118, -1089, -22019, 74, 1553}, +{ -1618, 19222, -17642, -13490, 842, -2309}, +{ 4689, 16490, 20813, -15387, -4164, -3968}, +{ -3308, 11214, -13542, 13599, -19473, 13770}, +{ 1817, 854, 21225, -966, -1643, -268}, +{ -2587, -107, -20154, 376, 1174, -304}, +{ -2919, 453, -5390, 750, -22034, -978}, +{ -19012, 16839, 10000, -3580, 2211, 1459}, +{ 1363, -2658, -33, -4067, 1165, -21985}, +{ -8592, -2760, -17520, -15985, 14897, 1323}, +{ 652, -9331, 3253, -14622, 12181, 19692}, +{ -6361, 5773, -15395, 17291, 16590, -2922}, +{ -661, -601, 1609, 22610, 992, -1045}, +{ 4961, 9107, 11225, 7829, 16320, 18627}, +{ -21872, -1433, 138, 1470, -1891, -196}, +{ -19499, -18203, 11056, -516, 2543, -2249}, +{ -1196, -17574, 20150, 11462, -401, 2619}, +{ 4638, -8154, 11891, -15759, 17615, -14955}, +{ -83, 278, 323, 55, -154, 232}, +{ 7788, 1462, 18395, 15296, -15763, -1131}, +}; +static const int16_t vq_hebap5[128][6] = { +{ -3394, -19730, 2963, 9590, 4660, 19673}, +{ -15665, -6405, 17671, 3860, -8232, -19429}, +{ 4467, 412, -17873, -8037, 691, -17307}, +{ 3580, 2363, 6886, 3763, 6379, -20522}, +{ -17230, -14133, -1396, -23939, 8373, -12537}, +{ -8073, -21469, -15638, 3214, 8105, -5965}, +{ 4343, 5169, 2683, -16822, -5146, -16558}, +{ 6348, -10668, 12995, -25500, -22090, 4091}, +{ -2880, -8366, -5968, -17158, -2638, 23132}, +{ -5095, -14281, -22371, 21741, 3689, 2961}, +{ -2443, -17739, 25155, 2707, 1594, 7}, +{ -18379, 9010, 4270, 731, -426, -640}, +{ -23695, 24732, 5642, 612, -308, -964}, +{ -767, 1268, 225, 1635, 173, 916}, +{ 5455, 6493, 4902, 10560, 23041, -17140}, +{ 17219, -21054, -18716, 4936, -3420, 3357}, +{ -1390, 15488, -21946, -14611, 1339, 542}, +{ -6866, -2254, -12070, -3075, -19981, -20622}, +{ -1803, 11775, 1343, 8917, 693, 24497}, +{ -21610, 9462, 4681, 9254, -7815, 15904}, +{ -5559, -3018, -9169, -1347, -22547, 12868}, +{ -366, 5076, -1727, 20427, -283, -2923}, +{ -1886, -6313, -939, -2081, -1399, 3513}, +{ -3161, -537, -5075, 11268, 19396, 989}, +{ 2345, 4153, 5769, -4273, 233, -399}, +{ -21894, -1138, -16474, 5902, 5488, -3211}, +{ 10007, -12530, 18829, 20932, -1158, 1790}, +{ -1165, 5014, -1199, 6415, -8418, -21038}, +{ 1892, -3534, 3815, -5846, 16427, 20288}, +{ -2664, -11627, -4147, -18311, -22710, 14848}, +{ 17256, 10419, 7764, 12040, 18956, 2525}, +{ -21419, -18685, -10897, 4368, -7051, 4539}, +{ -1574, 2050, 5760, 24756, 15983, 17678}, +{ -538, -22867, 11067, 10301, 385, 528}, +{ -8465, -3025, -16357, -23237, 16491, 3654}, +{ 5840, 575, 11890, 1947, 25157, 6653}, +{ 6625, -3516, -1964, 3850, -390, -116}, +{ 18005, 20900, 14323, -7621, -10922, 11802}, +{ -4857, -2932, -13334, -7815, 21622, 2267}, +{ -579, -9431, -748, -21321, 12367, 8265}, +{ -8317, 1375, -17847, 2921, 9062, 22046}, +{ 18398, 8635, -1503, -2418, -18295, -14734}, +{ -2987, 15129, -3331, 22300, 13878, -13639}, +{ 5874, -19026, 15587, 11350, -20738, 1971}, +{ 1581, -6955, -21440, 2455, 65, 414}, +{ 515, -4468, -665, -4672, 125, -19222}, +{ 21495, -20301, -1872, -1926, -211, -1022}, +{ 5189, -12250, -1775, -23550, -4546, 5813}, +{ 321, -6331, 14646, 6975, -1773, 867}, +{ -13814, 3180, 7927, 444, 19552, 3146}, +{ -6660, 12252, -1972, 17408, -24280, -12956}, +{ -745, 14356, -1107, 23742, -9631, -18344}, +{ 18284, -7909, -7531, 19118, 7721, -12659}, +{ 1926, 15101, -12848, 2153, 21631, 1864}, +{ -2130, 23416, 17056, -15597, -1544, 87}, +{ 8314, -11824, 14581, -20591, 7891, -2099}, +{ 19600, 22814, -17304, -2040, 285, -3863}, +{ -8214, -18322, 10724, -13744, -13469, -1666}, +{ 14351, 4880, -20034, 964, -4221, -180}, +{ -24598, -16635, 19724, 5925, 4777, 4414}, +{ -2495, 23493, -16141, 2918, -1038, -2010}, +{ 18974, -2540, 13343, 1405, -6194, -1136}, +{ 2489, 13670, 22638, -7311, -129, -2792}, +{ -13962, 16775, 23012, 728, 3397, 162}, +{ 3038, 993, 8774, -21969, -6609, 910}, +{ -12444, -22386, -2626, -5295, 19520, 9872}, +{ -1911, -18274, -18506, -14962, 4760, 7119}, +{ 8298, -2978, 25886, 7660, -7897, 1020}, +{ 6132, 15127, 18757, -24370, -6529, -6627}, +{ 7924, 12125, -9459, -23962, 5502, 937}, +{ -17056, -5373, 2522, 327, 1129, -390}, +{ 15774, 19955, -10380, 11172, -3107, 14853}, +{ -11904, -8091, -17928, -22287, -17237, -6803}, +{ -12862, -2172, -6509, 5927, 12458, -22355}, +{ -497, 322, 1038, -6643, -5404, 20311}, +{ 1083, -22984, -8494, 12130, -762, 2623}, +{ 5067, 19712, -1901, -30, -325, 85}, +{ 987, -5830, 4212, -9030, 9121, -25038}, +{ -7868, 7284, -12292, 12914, -21592, 20941}, +{ -1630, -7694, -2187, -8525, -5604, -25196}, +{ -6668, 388, -22535, 1526, 9082, 193}, +{ -7867, -22308, 5163, 362, 944, -259}, +{ 3824, -11850, 7591, -23176, 25342, 23771}, +{ -10504, 4123, -21111, 21173, 22439, -838}, +{ -4723, 21795, 6184, -122, 1642, -717}, +{ 24504, 19887, -2043, 986, 7, -55}, +{ -27313, -135, 2437, 259, 89, 307}, +{ 24446, -3873, -5391, -820, -2387, 361}, +{ 5529, 5784, 18682, 242, -21896, -4003}, +{ 22304, 4483, 722, -12242, 7570, 15448}, +{ 8673, 3009, 20437, 21108, -21100, -3080}, +{ -1132, 2705, -1825, 5420, -785, 18532}, +{ 16932, -13517, -16509, -14858, -20327, -14221}, +{ 2219, 1380, 21474, -1128, 327, 83}, +{ -2177, 21517, -3856, -14180, -204, -2191}, +{ 953, -9426, 15874, -10710, -3231, 21030}, +{ -421, -1377, 640, -8239, -20976, 2174}, +{ 4309, 18514, -9100, -18319, -15518, 3704}, +{ -5943, 449, -8387, 1075, -22210, -4992}, +{ 2953, 12788, 18285, 1430, 14937, 21731}, +{ -2913, 401, -4739, -20105, 1699, -1147}, +{ 3449, 5241, 8853, 22134, -7547, 1451}, +{ -2154, 8584, 18120, -15614, 19319, -5991}, +{ 3501, 2841, 5897, 6397, 8630, 23018}, +{ 2467, 2956, 379, 5703, -22047, -2189}, +{ -16963, -594, 18822, -5295, 1640, 774}, +{ 2896, -1424, 3586, -2292, 19910, -1822}, +{ -18575, 21219, -14001, -12573, 16466, 635}, +{ -1998, -19314, -16527, 12208, -16576, -7854}, +{ -9674, 1012, -21645, 2883, -12712, 2321}, +{ -1005, 471, -3629, 8045, -11087, 25533}, +{ 4141, -21472, -2673, 756, -663, -523}, +{ 6490, 8531, 19289, 18949, 6092, -9347}, +{ 16965, 24599, 14024, 10072, -536, -10438}, +{ -8147, 2145, -23028, -17073, 5451, -4401}, +{ -14873, 20520, -18303, -9717, -11885, -17831}, +{ -2290, -14120, 2070, 22467, 1671, 725}, +{ -8538, 14629, 3521, -20577, 6673, 8200}, +{ 20248, 4410, -1366, -585, 1229, -2449}, +{ 7467, -7148, 13667, -8246, 22392, -17320}, +{ -1932, 3875, -9064, -3812, 958, 265}, +{ -4399, 2959, -15911, 19598, 4954, -1105}, +{ 18009, -9923, -18137, -3862, 11178, 5821}, +{ -14596, -1227, 9660, 21619, 11228, -11721}, +{ -721, -1700, 109, -2142, 61, -6772}, +{ -24619, -22520, 5608, -1957, -1761, -1012}, +{ -23728, -4451, -2688, -14679, -4266, 9919}, +{ 8495, -894, 20438, -13820, -17267, 139}, +}; +static const int16_t vq_hebap6[256][6] = { +{ 10154, 7365, 16861, 18681, -22893, -3636}, +{ -2619, -3788, -5529, -5192, -9009, -20298}, +{ -5583, -22800, 21297, 7012, 745, 720}, +{ 428, -1459, 109, -3082, 361, -8403}, +{ 8161, 22401, 241, 1755, -874, -2824}, +{ 1140, 12643, 2306, 22263, -25146, -17557}, +{ -2609, 3379, 10337, -19730, -15468, -23944}, +{ -4040, -12796, -25772, 13096, 3905, 1315}, +{ 4624, -23799, 13608, 25317, -1175, 2173}, +{ -97, 13747, -5122, 23255, 4214, -22145}, +{ 6878, -322, 18264, -854, -11916, -733}, +{ 17280, -12669, -9693, 23563, -16240, -1309}, +{ 5802, -4968, 19526, -21194, -24622, -183}, +{ 5851, -16137, 15229, -9496, -1538, 377}, +{ 14096, 25057, 13419, 8290, 23320, 16818}, +{ -7261, 118, -15867, 19097, 9781, -277}, +{ -4288, 21589, -13288, -16259, 16633, -4862}, +{ 4909, -19217, 23411, 14705, -722, 125}, +{ 19462, -4732, -1928, -11527, 20770, 5425}, +{ -27562, -2881, -4331, 384, -2103, 1367}, +{ -266, -9175, 5441, 26333, -1924, 4221}, +{ -2970, -20170, -21816, 5450, -7426, 5344}, +{ -221, -6696, 603, -9140, 1308, -27506}, +{ 9621, -8380, -1967, 9403, -1651, 22817}, +{ 7566, -5250, -4165, 1385, -990, 560}, +{ -1262, 24738, -19057, 10741, 7585, -7098}, +{ 451, 20130, -9949, -6015, -2188, -1458}, +{ 22249, 9380, 9096, 10959, -2365, -3724}, +{ 18668, -650, -1234, 11092, 7678, 5969}, +{ 19207, -1485, -1076, -731, -684, 43}, +{ -4973, 13430, 20139, 60, 476, -935}, +{ -20029, 8710, 2499, 1016, -1158, 335}, +{ -26413, 18598, -2201, -669, 3409, 793}, +{ -4726, 8875, -24607, -9646, 3643, -283}, +{ 13303, -21404, -3691, -1184, -1970, 1612}, +{ 173, 60, 919, 1229, 6942, -665}, +{ 16377, 16991, 5341, -14015, -2304, -20390}, +{ 25334, -10609, 11947, -7653, -6363, 14058}, +{ 23929, -13259, -7226, -937, 234, -187}, +{ 6311, -1877, 12506, -1879, 18751, -23341}, +{ 621, 6445, 3354, -24274, 8406, 5315}, +{ -3297, -5034, -4704, -5080, -25730, 5347}, +{ -1275, -13295, -965, -23318, 1214, 26259}, +{ -6252, 10035, -20105, 15301, -16073, 5136}, +{ 9562, -3911, -19510, 4745, 22270, -4171}, +{ 7978, -19600, 14024, -5745, -20855, 8939}, +{ 7, -4039, 991, -6065, 52, -19423}, +{ 3485, 2969, 7732, 7786, 25312, 6206}, +{ -959, -12812, -1840, -22743, 7324, 10830}, +{ -4686, 1678, -10172, -5205, 4294, -1271}, +{ 3889, 1302, 7450, 638, 20374, -3133}, +{ -12496, -9123, 18463, -12343, -7238, 18552}, +{ -6185, 8649, -6903, -895, 17109, 16604}, +{ -9896, 28579, 2845, 1640, 2925, -298}, +{ 14968, -25988, 14878, -24012, 1815, -6474}, +{ 26107, 5166, 21225, 15873, 21617, 14825}, +{ -21684, 16438, 20504, -14346, -7114, -4162}, +{ 28647, 90, -1572, 789, -902, -75}, +{ -1479, 2471, -4061, 3612, -2240, 10914}, +{ 8616, 17491, 17255, -17456, 17022, -16357}, +{ -20722, -18597, 25274, 17720, -3573, 1695}, +{ -997, 6129, -6303, 11250, -11359, -19739}, +{ -74, -4001, -1584, 13384, 162, -144}, +{ -529, 21068, 7923, -11396, 422, -26}, +{ 7102, -13531, -20055, 2629, -178, -429}, +{ 9201, 1368, -22238, 2623, -20499, 24889}, +{ -432, 6675, -266, 8723, 80, 28024}, +{ 19493, -3108, -9261, 1910, -21777, 5345}, +{ 14079, -11489, 12604, 6079, 19877, 1315}, +{ 10947, 9837, -18612, 15742, 4792, 605}, +{ -1777, 3758, -4087, 21696, 6024, -576}, +{ 3567, -3578, 16379, 2680, -1752, 716}, +{ -5049, -1399, -4550, -652, -17721, -3366}, +{ -3635, -4372, -6522, -22152, 7382, 1458}, +{ 12242, 19190, 5646, -7815, -20289, 21344}, +{ -7508, 19952, 23542, -9753, 5669, -1990}, +{ -2275, 15438, 10907, -17879, 6497, 13582}, +{ -15894, -15646, -4716, 6019, 24250, -6179}, +{ -2049, -6856, -1208, 918, 17735, -69}, +{ -3721, 9099, -16065, -23621, 5981, -2344}, +{ 7862, -8918, 24033, 25508, -11033, -741}, +{ -12588, 19468, 14649, 15451, -21226, 1171}, +{ 2102, 1147, 2789, 4096, 2179, 8750}, +{ -18214, -17758, -10366, -5203, -1066, -3541}, +{ -2819, -19958, -11921, 6032, 8315, 10374}, +{ -9078, -2100, 19431, -17, 732, -689}, +{ -14512, -19224, -7095, 18727, 1870, 22906}, +{ 3912, 659, 25597, -4006, 9619, 877}, +{ 2616, 22695, -5770, 17920, 3812, 20220}, +{ 2561, 26847, -5245, -10908, 2256, -517}, +{ -4974, 198, -21983, -3608, 22174, -18924}, +{ 21308, -1211, 19144, 16691, -1588, 11390}, +{ -1790, 3959, -3488, 7003, -7107, 20877}, +{ -6108, -17955, -18722, 24763, 16508, 3211}, +{ 20462, -24987, -20361, 4484, -5111, -478}, +{ -6378, -1998, -10229, -561, -22039, -22339}, +{ 3047, -18850, 7586, 14743, -19862, 6351}, +{ -5047, 1405, -9672, 1055, -21881, 11170}, +{ 3481, -9699, 6526, -16655, 22813, 21907}, +{ -18570, 17501, 14664, 1291, 5026, 19676}, +{ 16134, -19810, -16956, -17939, -16933, 5800}, +{ -8224, 4908, 8935, 2272, -1140, -23217}, +{ 1572, 2753, -1598, 2143, -3346, -21926}, +{ -9832, -1060, -27818, 1214, 7289, 150}, +{ 98, 1538, 535, 17429, -23198, -901}, +{ 21340, -20146, 3297, -1744, -8207, -21462}, +{ -4166, -4633, -17902, 5478, 1285, 136}, +{ 18713, 21003, 24818, 11421, 1282, -4618}, +{ -3535, 7636, -265, 2141, -829, -2035}, +{ -3184, 19713, 2775, -2, 1090, 104}, +{ -6771, -20185, 2938, -2125, -36, 1268}, +{ 9560, 9430, 9586, 22100, 13827, 6296}, +{ -535, -20018, 4276, -1868, -448, -17183}, +{ -24352, 14244, -13647, -21040, 2271, 11555}, +{ -2646, 15437, -4589, 18638, -4299, -622}, +{ -20064, 4169, 18115, -1404, 13722, -1825}, +{ -16359, 9080, 744, 22021, 125, 10794}, +{ 9644, -14607, -18479, -14714, 11174, -20754}, +{ -326, -23762, 6144, 7909, 602, 1540}, +{ -6650, 6634, -12683, 21396, 20785, -6839}, +{ 4252, -21043, 5628, 18687, 23860, 8328}, +{ 17986, 5704, -5245, -18093, -555, 3219}, +{ 6091, 14232, -5117, -17456, -19452, -11649}, +{ -21586, 11302, 15434, 25590, 6777, -26683}, +{ 21355, -8244, 5877, -3540, 6079, -2567}, +{ 2603, -2455, 5421, -12286, -19100, 5574}, +{ -1721, -26393, -23664, 22904, -349, 3787}, +{ 2189, -1203, 5340, 3249, -22617, 104}, +{ -1664, -11020, -2857, -20723, -24049, 19900}, +{ 22873, -7345, -18481, -14616, -8400, -12965}, +{ 3777, 3958, 8239, 20494, -6991, -1201}, +{ -160, -1613, -793, -8681, 573, 776}, +{ 4297, -3786, 20373, 6082, -5321, -18400}, +{ 18745, 2463, 12546, -7749, -7734, -2183}, +{ 11074, -4720, 22119, 1825, -24351, 4080}, +{ 1503, -19178, -1569, 13, -313, 375}, +{ 318, -575, 2544, 178, 102, 40}, +{ -15996, -26897, 5008, 3320, 686, 1159}, +{ 25755, 26886, 574, -5930, -3916, 1407}, +{ -9148, -7665, -2875, -8384, -18663, 26400}, +{ -7445, -18040, -18396, 8802, -2252, -21886}, +{ 7851, 11773, 27485, -12847, -1410, 19590}, +{ 2240, 5947, 11247, 15980, -6499, 24280}, +{ 21673, -18515, 9771, 6550, -2730, 334}, +{ -4149, 1576, -11010, 89, -24429, -5710}, +{ 7720, 1478, 21412, -25025, -8385, 9}, +{ -2448, 10218, -12756, -16079, 1161, -21284}, +{ -8757, -14429, -22918, -14812, 2629, 13844}, +{ -7252, 2843, -9639, 2882, -14625, 24497}, +{ -674, -6530, 414, -23333, -21343, 454}, +{ 2104, -6312, 10887, 18087, -1199, 175}, +{ -493, -562, -2739, 118, -1074, 93}, +{ -10011, -4075, -28071, 22180, 15077, -636}, +{ -4637, -16408, -9003, -20418, -11608, -20932}, +{ 4815, 15892, 24238, -13634, -3074, -1059}, +{ -6724, 4610, -18772, -15283, -16685, 23988}, +{ 15349, -674, -3682, 21679, 4475, -12088}, +{ 4756, 2593, 5354, 6001, 15063, 26490}, +{ -23815, -17251, 6944, 378, 694, 670}, +{ 23392, -8839, -14713, 7544, -876, 11088}, +{ 3640, 3336, 22593, -3495, -2328, -113}, +{ 284, 6914, 3097, 10171, 6638, -18621}, +{ 2472, 5976, 11054, -11936, -603, -663}, +{ 16175, 16441, 13164, -4043, 4667, 7431}, +{ 19338, 15534, -6533, 1681, -4857, 17048}, +{ 17027, 532, -19064, -1441, -5130, 1085}, +{ -12617, -17609, 2062, -25332, 19009, -16121}, +{ 10056, -21000, -13634, -2949, 15367, 19934}, +{ -648, -1605, 10046, -1592, 13296, 19808}, +{ -1054, 10744, 538, 24938, 9630, -9052}, +{ -10099, 3042, -25076, -24052, 13971, 100}, +{ 6547, 6907, 7031, 10348, 23775, -17886}, +{ -22793, -1984, -1393, -3330, 9267, 14317}, +{ -14346, -3967, 3042, 16254, -17303, 9646}, +{ -21393, 23628, 16773, 716, 2663, 114}, +{ -19016, -3038, 1574, -245, 1463, -793}, +{ 22410, 23441, -14637, -530, 17310, 13617}, +{ -11582, 7935, -13954, 23465, -24628, 26550}, +{ -1045, 3679, -2218, 10572, 20999, -3702}, +{ -15513, 197, 16718, -24603, 4945, 5}, +{ 10781, 4335, 26790, -9059, -16152, -2840}, +{ 16075, -24100, -3933, -6833, 12645, -7029}, +{ 2096, -25572, -8370, 6814, 11, 1178}, +{ -11848, -583, -8889, -20543, -10471, -380}, +{ -2487, 24777, -21639, -19341, 1660, -732}, +{ 2313, 13679, 4085, 24549, 24691, -21179}, +{ -2366, -504, -4130, -10570, 23668, 1961}, +{ 20379, 17809, -9506, 3733, -18954, -6292}, +{ -3856, 16802, -929, -20310, -17739, 6797}, +{ 12431, 6078, -11272, -14450, 6913, 23476}, +{ 7636, -1655, 23017, 10719, -8292, 838}, +{ -8559, -1235, -18096, 3897, 16093, 1490}, +{ -3586, 8276, 15165, -3791, -21149, 1741}, +{ -4497, 21739, 2366, -278, -4792, 15549}, +{ -23122, -13708, 7668, 16232, 24120, 15025}, +{ -20043, 12821, -20160, 16691, -11655, -16081}, +{ -12601, 20239, 3496, -2549, -6745, -11850}, +{ 4441, 7812, 20783, 17080, 11523, -9643}, +{ 24766, 8494, -23298, -3262, 11101, -7120}, +{ -10107, -7623, -22152, -18303, 26645, 9550}, +{ -25549, 477, 7874, -1538, 1123, -168}, +{ 470, 9834, -347, 23945, -10381, -9467}, +{ -4096, -9702, -6856, -21544, 20845, 7174}, +{ 5370, 9748, -23765, -1190, 512, -1538}, +{ -1006, -10046, -12649, 19234, -1790, -890}, +{ 15108, 23620, -15646, -2522, -1203, -1325}, +{ -7406, -2605, 1095, -247, -473, 177}, +{ 8089, 4, 12424, -22284, 10405, -7728}, +{ 22196, 10775, -5043, 690, 534, -212}, +{ -3153, -1418, -16835, 18426, 15821, 22956}, +{ 5681, -2229, 3196, -3414, -21817, -14807}, +{ 19, 787, 1032, 170, -8295, -645}, +{ -882, -2319, -27105, 432, -4392, 1499}, +{ -1354, -11819, -76, -20380, -10293, 11328}, +{ 211, -4753, -4675, -6933, -13538, 14479}, +{ 6043, 5260, -459, -462, 143, -65}, +{ -2572, 7256, -3317, 9212, -23184, -9990}, +{ -24882, -9532, 18874, 6101, 2429, -14482}, +{ 8314, 2277, 14192, 3512, 25881, 22000}, +{ 208, 20218, -281, -24778, -63, -1183}, +{ 1095, -6034, 2706, -21935, -2655, 563}, +{ 23, -5930, 243, -8989, 5345, 20558}, +{ -15466, 12699, 4160, 11087, 20621, -10416}, +{ 20995, -85, -8468, 194, 1003, -9515}, +{ -19637, -3335, -14081, 3574, -23381, -667}, +{ -2076, 3489, -3192, -19367, 539, -1530}, +{ 7352, -15213, 22596, 19369, 1043, 16627}, +{ -1872, -413, 1235, -5276, -3550, 21903}, +{ 7931, -2008, 16968, -6799, 29393, -2475}, +{ -13589, 8389, -23636, -22091, -14178, -14297}, +{ -11575, -20090, 16056, -1848, 15721, 4500}, +{ 3849, -16581, 20161, -21155, 7778, 11864}, +{ -6547, -1273, -18837, -11218, 11636, 1044}, +{ 2528, -6691, -17917, -11362, -4894, -1008}, +{ 1241, 4260, 2319, 6111, 3485, 20209}, +{ 3014, -3048, 5316, -4539, 20831, 8702}, +{ -1790, -14683, 278, 13956, -10065, -10547}, +{ -22732, -7957, -1154, 13821, -1484, -1247}, +{ -7317, -615, 13094, 18927, 9897, 1452}, +{ 2552, -2338, 3424, -4630, 11124, -19584}, +{ -11125, -20553, -10855, -10783, -20767, 6833}, +{ 984, -15095, 5775, 25125, 5377, -19799}, +{ 517, 13272, -7458, -1711, 20612, -6013}, +{ -21417, 13251, -20795, 13449, 17281, 13104}, +{ -15811, -16248, 23093, -4037, -8195, 871}, +{ 582, 12571, -21129, -14766, -9187, 5685}, +{ 4318, -1776, 11425, -17763, -9921, 577}, +{ 6013, 16830, 17655, -25766, -4400, -3550}, +{ -13744, -16541, 3636, -3330, -21091, -15886}, +{ 6565, -11147, 8649, -13114, 23345, -13565}, +{ -2542, -9046, -7558, 29240, 3701, -383}, +{ -10612, 24995, 1893, -8210, 20920, -16210}, +{ 5276, 16726, 10659, 19940, -4799, -19324}, +{ -532, -9300, 27856, 4965, -241, 536}, +{ -765, -20706, -3412, 18870, 2765, 1420}, +{ -3059, 2708, -19022, -331, 3537, 116}, +}; +static const int16_t vq_hebap7[512][6] = { +{ -21173, 21893, 10390, 13646, 10718, -9177}, +{ -22519, -8193, 18328, -6629, 25518, -10848}, +{ 6800, -13758, -13278, 22418, 14667, -20938}, +{ 2347, 10516, 1125, -3455, 5569, 27136}, +{ -6617, 11851, -24524, 22937, 20362, -6019}, +{ -21768, 10681, -19615, -15021, -8478, -2081}, +{ -2745, 8684, -4895, 27739, 7554, -11961}, +{ -1020, 2460, -954, 4754, -627, -16368}, +{ -19702, 23097, 75, -13684, -2644, 2108}, +{ 4049, -2872, 5851, -4459, 22150, 12560}, +{ -21304, -17129, -730, 7419, -11658, -10523}, +{ 11332, 1792, 26666, 23518, -19561, -491}, +{ -17827, -16777, -13606, -14389, -22029, -2464}, +{ 1091, -5967, -7975, -16977, -20432, -21931}, +{ 18388, -1103, 1933, 13342, -17463, 18114}, +{ 22646, 17345, -9966, 17919, 18274, 698}, +{ 1484, 20297, -5754, -26515, 4941, -22263}, +{ -2603, 4587, -5842, 18464, 8767, -2568}, +{ -2797, -1602, 21713, 3099, -25683, 3224}, +{ -19027, 4693, -5007, 6060, 1972, -15095}, +{ -2189, 9516, -530, 20669, -4662, -8301}, +{ -22325, -8887, 2529, -11352, 5476, 998}, +{ 22100, -5052, 1651, -2657, 4615, 2319}, +{ 20855, -3078, -3330, 4105, 13470, 3069}, +{ 85, 17289, 10264, -14752, 214, 90}, +{ -26365, -18849, -19352, 19244, -10218, 9909}, +{ -9739, 20497, -6579, -6983, 2891, -738}, +{ 20575, -15860, -22913, 6870, 76, 327}, +{ 8744, -12877, -22945, -2372, -19424, -9771}, +{ -12886, 16183, 21084, 3821, 749, -13792}, +{ -15995, 18399, 2391, -17661, 19484, -6018}, +{ 1423, 11734, 4051, 19290, 6857, -19681}, +{ -5200, 9766, 18246, 2463, 18764, -4852}, +{ -597, 19498, 1323, -9096, -308, -1104}, +{ -3099, -25731, -15665, 25332, 4634, 2635}, +{ 19623, -2384, -7913, 11796, -9333, -14084}, +{ 2642, 26453, -21091, -10354, -1693, -1711}, +{ 22031, 21625, 11580, -22915, -4141, 129}, +{ -6122, 3542, 915, -261, -17, -383}, +{ 1696, 6704, -1425, 20838, 857, -4416}, +{ 1423, -15280, -8550, -9667, 5210, 5687}, +{ -4520, -613, -11683, 5618, 4230, 619}, +{ 937, -4963, -14102, -17104, -6906, -5952}, +{ -15068, -481, -7237, -14894, 18876, 21673}, +{ -25658, 2910, 1143, -327, -458, -995}, +{ -9656, -819, -24900, 2804, 20225, 1083}, +{ -1111, -3682, -1788, -19492, 966, 821}, +{ 7293, -21759, 10790, -7059, -23293, -1723}, +{ -282, -11093, 170, -20950, -28926, 12615}, +{ 17938, 3713, -1563, 885, 5, 564}, +{ 6116, 22696, 2242, -6951, 9975, -6132}, +{ 4338, 26808, -3705, 1976, -1079, -2570}, +{ -661, -7901, -2668, -15194, 17722, 4375}, +{ -4174, -11053, 717, -22506, 1562, 12252}, +{ -6405, 18334, 6103, 6983, 5956, 18195}, +{ 9851, 5370, 23604, -6861, -6569, -62}, +{ 21964, 13359, -683, 3785, 2168, 209}, +{ -3569, -1127, -19724, -1544, 1308, -803}, +{ -3083, 16049, -13791, -3077, 4294, 23713}, +{ -9999, 9943, -15872, 12934, -23631, 21699}, +{ 9722, 22837, 12192, 15091, 5533, 4837}, +{ 2243, 2099, 1243, 4089, 4748, 12956}, +{ 4007, -2468, 3353, -3092, 8843, 17024}, +{ 4330, 6127, 5549, 9249, 11226, 28592}, +{ -9586, -8825, 236, 1009, 455, -964}, +{ 6829, 19290, -1018, 200, 1821, 578}, +{ 5196, 957, 10372, 3330, -12800, -127}, +{ -3022, -8193, -14557, 22061, 5920, 1053}, +{ 10982, 25942, -24546, -23278, -11905, -6789}, +{ 22667, -11010, 5736, 2567, 23705, -10253}, +{ -3343, -4233, -5458, 20667, -10843, -3605}, +{ -4131, -3612, 4575, -829, -350, -847}, +{ -3303, 3451, -7398, -11604, 3023, 455}, +{ 3200, -9547, 3202, -22893, 11184, -26466}, +{ -14093, -4117, 15382, 14295, -10915, -20377}, +{ 3807, -11016, 22052, 14370, -15328, -7733}, +{ -6291, -17719, -1560, 12048, -19805, -443}, +{ -6147, -4234, -160, 8363, 22638, 11911}, +{ 19197, 1175, 7422, -9875, -4136, 4704}, +{ -72, -7652, -112, -11955, -3230, 27175}, +{ 3274, 5963, 7501, -17019, 866, -25452}, +{ 737, 1861, 1833, 2022, 2384, 4755}, +{ -5217, 7512, 3323, 2715, 3065, -1606}, +{ 4247, 565, 5629, 2497, 18019, -4920}, +{ -2833, -17920, -8062, 15738, -1018, 2136}, +{ 3050, -19483, 16930, 29835, -10222, 15153}, +{ -11346, 118, -25796, -13761, 15320, -468}, +{ -4824, 4960, -4263, 1575, -10593, 19561}, +{ -8203, -1409, -763, -1139, -607, 1408}, +{ -2203, -11415, 2021, -6388, -2600, 711}, +{ -413, -2511, -216, -3519, -28267, 1719}, +{ -14446, 17050, 13917, 13499, -25762, -16121}, +{ 19228, 7341, -12301, 682, -3791, -199}, +{ -4193, 20746, -15651, 11349, 5860, -824}, +{ -21490, -3546, -3, -1705, -3959, 9213}, +{ 15445, -1876, 2012, -19627, 16228, -4845}, +{ -2867, -3733, -7354, -175, -20119, 11174}, +{ -3571, -24587, 19700, 6654, 979, -654}, +{ 21820, -7430, -6639, -10767, -8362, 15543}, +{ 14827, 17977, -7204, -3409, 1906, -17288}, +{ 3525, -3947, -1415, -2798, 17648, 2082}, +{ -6580, -15255, -17913, 1337, 15338, 21158}, +{ 6210, 9698, 15155, -24666, -22507, -3999}, +{ -1740, -593, 1095, -7779, 25058, 5601}, +{ 21415, -432, -1658, -6898, -1438, -14454}, +{ -6943, 700, -12139, -745, -24187, 22466}, +{ 6287, 3283, 11006, 3844, 19184, 14781}, +{ -22502, 15274, 5443, -2808, -970, -3343}, +{ 3257, -3708, 4744, -8301, 22814, -10208}, +{ 24346, -20970, 19846, 987, -11958, -6277}, +{ 3906, -19701, 13060, -1609, 18641, 7466}, +{ -26409, -22549, 16305, 2014, 10975, 18032}, +{ -7039, 4655, -14818, 18739, 15789, 1296}, +{ 9310, -1681, 14667, -3326, 26535, -11853}, +{ 5728, 5917, 13400, 10020, -2236, -24704}, +{ 1741, -6727, 12695, -22009, 4080, 5450}, +{ -2621, 9393, 21143, -25938, -3162, -2529}, +{ 20672, 18894, -13939, 6990, -8260, 15811}, +{ -23818, 11183, -13639, 11868, 16045, 2630}, +{ 18361, -10220, 829, 856, -1010, 157}, +{ 14400, -4678, 5153, -13290, -27434, -11028}, +{ 21613, 11256, 17453, 7604, 13130, -484}, +{ 7, 1236, 573, 4214, 5576, -3081}, +{ 916, -9092, 1285, -8958, 1185, -28699}, +{ 21587, 23695, 19116, -2885, -14282, -8438}, +{ 23414, -6161, 12978, 3061, -9351, 2236}, +{ -3070, -7344, -20140, 5788, 582, -551}, +{ -3993, 315, -7773, 8224, -28082, -12465}, +{ 13766, -15357, 19205, -20624, 13043, -19247}, +{ 3777, -177, 8029, -1001, 17812, 5162}, +{ -7308, -4327, -18096, -620, -1350, 14932}, +{ 14756, -1221, -12819, -14922, -547, 27125}, +{ 2234, 1708, 2764, 5416, 7986, -25163}, +{ 2873, 3636, 3992, 5344, 10142, 21259}, +{ 1158, 5379, 508, -10514, 290, -1615}, +{ 1114, 24789, 16575, -25168, -298, -2832}, +{ -1107, -6144, -1918, -7791, -2971, -23276}, +{ 4016, 10793, 17317, -4342, -20982, -3383}, +{ -4494, -207, -9951, -3575, 7947, 1154}, +{ -7576, 8117, -14047, 16982, -26457, -27540}, +{ -15164, 16096, -16844, -8886, -23720, 15906}, +{ 24922, 5680, -1874, 420, 132, 117}, +{ -506, -19310, -198, 412, -311, 752}, +{ -1906, 3981, -7688, 16566, -19291, -14722}, +{ -399, -729, -3807, -4196, -12395, 7639}, +{ 3368, 2330, 9092, 23686, -10290, -1705}, +{ -3148, 2596, -7986, 14602, -4807, 16627}, +{ 8057, 1481, 49, 17205, 24869, 7474}, +{ -19304, -513, 11905, 2346, 5588, 3365}, +{ -5063, -21812, 11370, 10896, 4881, 261}, +{ 4794, 20577, 5109, -6025, -8049, -1521}, +{ 8125, -14756, 20639, -14918, 23941, -3650}, +{ 12451, 1381, 3613, 8687, -24002, 4848}, +{ 6726, 10643, 10086, 25217, -25159, -1065}, +{ 6561, 13977, 2911, 21737, 16465, -26050}, +{ -1776, 2575, -19606, -16800, 3032, 6679}, +{ 15012, -17910, -8438, -21554, -27111, 11808}, +{ 3448, -924, -15913, -1135, 5126, -20613}, +{ 7720, 2226, 17463, 5434, 28942, 17552}, +{ 1246, 15614, -11743, 24618, -17539, 3272}, +{ 3215, 17950, 2783, -722, -22672, 5979}, +{ -5678, -3184, -26087, 26034, 6583, 3302}, +{ 20310, -3555, -2715, -444, -1487, 1526}, +{ -20640, -21970, -12207, -25793, 8863, -1036}, +{ 17888, 570, -16102, 8329, -2553, 15275}, +{ -2677, 9950, -1879, 16477, -12762, -29007}, +{ -120, -2221, 219, 97, 365, 35}, +{ 1270, -718, 1480, -2689, 1930, -7527}, +{ 1896, 8750, 1906, 18235, -12692, -6174}, +{ -3733, 13713, -9882, -15960, -1376, -7146}, +{ -10600, 8496, 15967, -8792, 7532, 20439}, +{ 3041, -13457, 1032, -26952, 5787, 24984}, +{ -4590, -8220, -9322, -6112, -17243, 25745}, +{ -17808, 6970, 3752, 626, -114, 2178}, +{ 4449, -4862, 7054, -5404, 4738, -2827}, +{ 4922, -651, 18939, -9866, 848, 1886}, +{ -336, -5410, 7234, 20444, -9583, -600}, +{ 781, -19474, -12648, 6634, 1414, 450}, +{ -3399, -16770, 11107, 13200, -5498, 21663}, +{ -3265, 4859, -5961, 7530, -10837, 28086}, +{ 10350, -12901, 25699, 25640, -639, 351}, +{ 1163, 18763, -5466, -15087, -145, -1377}, +{ -14477, 27229, -31383, -32653, 21439, -2894}, +{ 15420, 18823, 22128, 19398, 22583, 13587}, +{ -10674, 10710, 5089, -4756, 909, -20760}, +{ -12948, -20660, 7410, 2722, 3427, 11585}, +{ -1105, 18374, 19731, -9650, 22442, 19634}, +{ -296, -6798, -14677, 21603, 19796, 21399}, +{ -19350, -7501, 25446, 13144, 8588, -25298}, +{ 3092, -10618, 20896, 9249, -3326, 1796}, +{ -811, 1449, 3106, 4748, 12073, -14262}, +{ -20720, 14275, -4332, -25838, -5781, -21149}, +{ -5132, 10554, -14020, -22150, 2840, -554}, +{ 25533, 17648, 14886, -21074, 2459, 25142}, +{ -9370, -1788, -12862, -5870, -25811, -11023}, +{ 6698, 819, 10313, 166, 27581, 523}, +{ 101, -19388, 3413, 9638, 64, 806}, +{ -2742, -17931, -2576, 22818, 8553, 1126}, +{ 2972, 15203, 1792, 25434, -5728, -17265}, +{ -1419, 1604, 4398, 11452, 1731, 23787}, +{ -5136, 4625, -10653, 27981, 9897, -2510}, +{ -10528, -28033, 2999, -1530, -832, -830}, +{ -11133, -12511, 22206, -7243, -23578, -21698}, +{ 16935, -21892, 1861, -9606, 9432, 19026}, +{ 10277, 9516, 26815, 2010, -4943, -9080}, +{ 5547, -2210, 14270, -15300, -19316, 1822}, +{ -4850, -783, -8959, -3076, -20056, -3197}, +{ 8232, -2794, -17752, 13308, 3229, -991}, +{ -12237, -6581, 10315, -9552, 2260, -20648}, +{ -7000, 5529, -7553, -7490, -10342, -10266}, +{ 3641, 19479, -5972, -19097, -18570, 12805}, +{ 1283, -4164, 4198, -28473, -2498, 1866}, +{ 16047, 26826, -13053, -6316, 985, -1597}, +{ -403, 13680, 6457, 25070, 27124, -20710}, +{ -18070, -1790, -24986, 5953, -954, 26600}, +{ -24224, -15383, 24788, 1953, -1136, 187}, +{ -2289, 12505, -20738, -904, 18324, 21258}, +{ 2658, -6140, 16179, 22276, -556, 2154}, +{ -6087, 13950, -25682, -27713, 4049, -4795}, +{ -21452, 26473, 19435, -9124, 895, 303}, +{ -22200, -26177, -6026, 24729, -22926, -9030}, +{ -14276, -15982, 23732, -22851, 9268, -3841}, +{ 29482, 21923, -6213, 1679, -2059, -1120}, +{ -435, 9802, -3891, 12359, -4288, -18971}, +{ 19768, -86, 2467, 1990, -1021, -5354}, +{ 20986, -8783, -5329, -23562, -4730, 2673}, +{ -5095, 5605, -4629, 19150, 26037, -12259}, +{ 972, 6858, 4551, 27949, -4025, -2272}, +{ 6075, -3260, -4989, -373, -1571, -3730}, +{ -7256, -12992, -8820, -5109, 23054, 5054}, +{ 920, 2615, 7912, -7353, -4905, 20186}, +{ -250, 5454, 3140, 6928, -18723, -2051}, +{ -10299, -4372, 19608, 4879, -661, -1885}, +{ 14816, -8603, -19815, 6135, -21210, 14108}, +{ -11945, -2223, 5018, 11892, 22741, 406}, +{ -13184, -2613, -13256, -22433, -12482, -8380}, +{ 17066, 25267, -2273, 5056, -342, 145}, +{ 8401, -17683, 19112, 10615, -19453, 17083}, +{ 20821, -5700, 12298, -25598, 10391, 7692}, +{ 4550, 15779, 17338, -19379, -4768, 1206}, +{ -7723, 10836, -27164, -11439, 6835, -1776}, +{ 2542, 3199, 4442, 17513, -3711, -914}, +{ 20960, -16774, -5814, 11087, -70, 22961}, +{ 3305, 2919, 6256, -4800, -20966, -3230}, +{ 5924, -16547, 2183, 2733, 3446, -23306}, +{ -6061, -194, -13852, -10971, 19488, 1029}, +{ 4467, -5964, -19004, 1519, -359, 855}, +{ -1581, -7607, 22070, -11580, -10032, 17102}, +{ -12412, 2553, 4324, 22500, 5751, 12170}, +{ -25127, 17996, -6384, 1180, 1182, 9622}, +{ 23462, -8471, -4392, -2669, 7638, -16835}, +{ -5511, -2887, -10757, -20883, 7246, 1053}, +{ 2703, -20602, -7554, 7516, -7740, 5868}, +{ 20670, 21901, 457, 14969, -17657, -11921}, +{ 3603, -1595, -2177, -157, -43, 605}, +{ 2513, 8954, 10527, 22559, -16100, -16041}, +{ 6002, 4951, 6795, -4862, -22400, 18849}, +{ 7590, -1693, -24688, -3404, 14169, 1214}, +{ -4398, -6663, -6870, -10083, -24596, 9253}, +{ 10468, 17751, -7748, 147, -6314, 4419}, +{ 16187, -16557, -4119, 4302, 7625, 5409}, +{ 3303, 2735, 7458, -19902, -2254, -3702}, +{ -2077, 21609, 14870, 12545, -6081, -1764}, +{ 4678, 11740, 2859, 6953, 1919, -3871}, +{ 3522, -21853, -2469, -10453, 18893, -10742}, +{ 3759, -10191, -4866, -2659, -17831, -1242}, +{ 14991, 9351, 11870, -1573, -4848, 22549}, +{ 9509, -27152, 10734, 20851, -26185, -17878}, +{ -7170, -1392, -19495, 12746, 8198, -1988}, +{ 1883, 28158, -846, -7235, 249, 233}, +{ -7200, 669, -371, -2948, 23234, -5635}, +{ 3141, 288, 3223, -1258, -98, -27607}, +{ 17373, -23235, 5110, -11199, -2574, -11487}, +{ -4928, 1518, -5456, 670, -18278, 1951}, +{ 10334, -19865, -4649, 361, -160, -923}, +{ 18732, 14264, -3155, -7485, -3328, 5959}, +{ -3614, 21077, 7276, 3536, 8121, -1528}, +{ -8422, 500, -19182, 18929, 26392, -1039}, +{ 15639, 25668, 8375, 1903, 1945, -11979}, +{ -2716, 3389, 26850, -4587, 1803, 22}, +{ 1177, -655, 1233, -2128, 7844, 1767}, +{ -761, 8209, -19290, -4593, 1923, -343}, +{ -689, -3530, -3267, -3804, -2753, 18566}, +{ -2110, 1962, -1353, 16643, 2765, -23102}, +{ -433, 4905, 302, 13016, 15933, -5905}, +{ 3203, 4126, 11181, -5496, -2529, -1160}, +{ -1091, -6469, -1415, 5682, -268, 583}, +{ -9405, -19572, 6216, 1658, 993, -75}, +{ -1695, -4504, -2289, -4088, -6556, -16577}, +{ 4760, -892, -10902, 6516, 24199, -6011}, +{ -253, 1000, 63, -81, -115, -382}, +{ -1333, 24224, -698, -4667, -2801, -19144}, +{ -876, -28866, -21873, 12677, -6344, 3235}, +{ 16847, 21145, -26172, -3183, -396, 230}, +{ 18296, -7790, -12857, -679, -1473, 5}, +{ -10488, 11429, 25805, -1122, 1401, -438}, +{ 3782, -7429, 26720, 17567, 19257, 12542}, +{ 6332, -746, 12789, 9316, -22542, -5354}, +{ 3418, -22728, 26978, 18303, 1076, 956}, +{ -27315, -2988, 920, 235, 2233, 81}, +{ 6199, 5296, 16093, 14768, -8429, -1112}, +{ -6432, 19244, 9921, -3253, 1278, -954}, +{ 24213, 2049, -22931, 2585, -2410, -4216}, +{ 9286, 14282, -19735, -3985, -2344, 1028}, +{ -20128, 17993, -9458, 23012, -16983, 8625}, +{ -6896, -20730, 3762, 17415, 22341, 19024}, +{ 842, 24181, 25062, -5839, -78, 937}, +{ -621, 19722, -24204, -1962, -14854, -56}, +{ 22766, -5119, 17365, 23868, -19480, -6558}, +{ -2158, 17490, -21435, 3340, -12819, -20295}, +{ -9621, 17325, 715, 2265, -4123, -492}, +{ 9156, 12947, 27303, -21175, -6072, -9457}, +{ -13164, -23269, -14006, -4184, 6978, 2}, +{ 938, -13381, 3520, -24297, 22902, 19589}, +{ -4911, -19774, 19764, -9310, -12650, 3819}, +{ -5462, -4249, -6987, -6260, -13943, -25150}, +{ 9341, 10369, -13862, -6704, 22556, -519}, +{ 6651, 18768, -4855, 12570, 14730, -10209}, +{ -823, 18119, 398, -1582, -116, -363}, +{ -6935, -12694, -28392, 8552, 6961, -239}, +{ -2602, -4704, -1021, 2015, 5129, 23670}, +{ -12559, -8190, -25028, 18544, 14179, 1663}, +{ 3813, 21036, -9620, -5051, -1800, -1087}, +{ -22057, 16675, 14960, 9459, 2786, 16991}, +{ -26040, -19318, -6414, 1104, 5798, -18039}, +{ -1737, 24825, 10417, -11087, 896, -5273}, +{ -1855, 11661, -2803, 24809, -21435, -19792}, +{ -23473, -16729, -5782, 5643, 2636, 4940}, +{ -1724, 4388, -26673, -13695, 10570, -25895}, +{ 15358, -19496, 26242, -18493, 1736, 8054}, +{ 5684, 20890, 4091, -19100, -14588, -10468}, +{ 17260, -16291, 14859, -17711, -19174, 12435}, +{ -27185, -12573, 6743, -562, 976, -257}, +{ 12395, -8618, -22248, -19843, 11013, 7762}, +{ 3799, 11853, -27622, -8473, 1089, -1495}, +{ 4141, -2182, -26720, -735, -774, 1469}, +{ 3125, 13762, 4606, 29257, 18771, -9958}, +{ -17465, -9445, -17562, -2530, -6435, -3726}, +{ -1742, 4351, -6841, -19773, 9627, -10654}, +{ 7251, 3525, 10835, 5601, 25198, -23348}, +{ -10300, -17830, 631, 11640, 2044, -20878}, +{ -873, -8502, -1063, -15674, -10693, 14934}, +{ -15957, 28137, 5268, 477, -1053, 1158}, +{ -1495, -8814, -5764, -24965, 25988, 7907}, +{ -1038, -114, -2308, -1319, -6480, 1472}, +{ 4895, -17897, -25850, 5301, -188, 1581}, +{ 3200, 17225, 4346, 22101, -18543, 22028}, +{ -10250, 545, -10932, 2276, -28070, 8118}, +{ 15343, 2329, 9316, 20537, 14908, 21021}, +{ 6329, 6130, -24508, 837, -8637, -5844}, +{ 7386, -501, 10503, 20131, 11435, -4755}, +{ -2745, 24174, -9274, 15273, -8389, -5835}, +{ 2992, -2864, 6048, -7473, 11687, -19996}, +{ -883, -11954, -9976, -21829, -4436, -27178}, +{ 3458, 19626, 1280, 2597, 19849, 5255}, +{ -5315, 19133, -14518, -8946, 13749, -1352}, +{ 18642, 17655, 11001, 6817, -18418, 6336}, +{ -1697, 2244, -4640, 3948, -12890, -5273}, +{ 20428, 10542, 4170, -1012, 19439, 21691}, +{ -2943, -19735, -4208, 1320, 909, -8897}, +{ 9351, -8066, -2618, -12933, 26582, 3507}, +{ 9705, -22628, 8311, 8167, -13293, 5608}, +{ 3222, 3749, -1508, 165, -52, -196}, +{ 102, -22744, -8832, 903, -11421, -14662}, +{ -120, 5998, 19765, 13401, 3628, 5197}, +{ 8528, 5827, -1066, 774, -39, -166}, +{ 9411, -9476, 9581, -13004, 24456, 24900}, +{ 17878, 2235, -21639, 20478, 4716, -7190}, +{ -2482, 9511, 1611, -21943, 14230, -1289}, +{ 9288, -2291, 23215, -3452, -10842, 11}, +{ 9496, 3041, 5130, -3890, -21219, -22589}, +{ 14262, -9838, 20195, 14019, 91, -17200}, +{ -18591, 980, 17, 821, 120, -574}, +{ 12285, -19269, 13742, 16373, -161, 6025}, +{ -3364, 1530, -4005, 2454, -10872, -23839}, +{ 105, 5085, -260, 5790, -588, 19170}, +{ 4121, 4169, 13439, 14644, 20899, 7434}, +{ -175, 13101, -3704, 23233, 3907, 10106}, +{ -6101, 23467, 5204, -1341, 1599, 13174}, +{ -3217, -3494, 15117, -8387, -11762, -4750}, +{ 1146, 4675, -19378, 14917, -5091, 249}, +{ -21506, 10136, -16473, -13305, 18382, -8601}, +{ 628, 2447, 3344, 3130, -5115, 119}, +{ 17900, -22422, -17633, 21967, -16293, -7676}, +{ 16863, 24214, 5612, -3858, -809, 3822}, +{ -2291, 10091, -2360, -25109, -1226, 312}, +{ 2957, 11256, 26745, -13266, -3455, -1128}, +{ -19762, -2708, 4604, 6355, 1638, 25501}, +{ -19593, -7753, 3159, -85, -489, -1855}, +{ 814, 12510, 19077, -4681, -2610, -1474}, +{ -23408, -19027, 8137, 19878, 7912, -282}, +{ 839, -19652, 11927, 27278, -3211, 2266}, +{ 4020, -1110, 8226, -1274, 20922, 25060}, +{ 26576, 325, -8693, -232, -2218, -699}, +{ -11293, -4200, 1805, -6673, -22940, -1339}, +{ -2005, -15886, -1047, -27687, -13235, 14370}, +{ -22073, 1949, 13175, -15656, -1846, 8055}, +{ 3039, 12025, 7132, -24632, 413, -2347}, +{ -24048, -206, 12459, -6654, -417, -10091}, +{ 18179, -23688, -20515, -16396, 7230, 763}, +{ 5659, -5085, 13878, -23729, -11077, -19587}, +{ 11340, 501, 25040, 7616, -19658, 1605}, +{ -26650, 8878, 10544, 417, 1299, 261}, +{ 14460, 11369, -3263, 9990, 8194, 18111}, +{ 1355, -20838, -9196, -16060, -8559, -730}, +{ -1918, -20937, -18293, -2461, -2651, 4316}, +{ -2810, 24521, -10996, -25721, 308, -1234}, +{ -9075, -17280, -1833, -29342, -24213, -16631}, +{ -2843, 10165, -5339, -2888, 21858, -21340}, +{ -15832, 14849, -23780, 5184, 10113, -20639}, +{ -19535, -11361, 8413, 1486, -23658, -5759}, +{ -7512, 1027, -20794, 13732, 19892, -21934}, +{ -12132, -7022, -19175, -8840, 22125, -16490}, +{ 1937, 5210, -6318, -23788, 13141, 11082}, +{ -205, 6036, -380, 8658, -233, 28020}, +{ -5523, 7477, 7635, 23595, 9763, -2590}, +{ 21658, -28313, -3086, -300, -1032, 1744}, +{ -22352, 16646, 208, 6665, -17400, -3028}, +{ 18482, 9336, -2737, -19372, 407, -4389}, +{ -4913, -17370, 18819, -17654, 13416, 15232}, +{ 7749, 6368, 23135, -18174, 7584, -4248}, +{ -1489, -6523, 586, -10157, 14964, 25568}, +{ 3844, -6156, 4897, -13045, -22526, 5647}, +{ -8491, -2105, -24774, 905, -9326, 1456}, +{ -3040, -1476, 1166, -4428, 11236, 9204}, +{ 3397, -1451, 13598, -15841, 24540, 5819}, +{ 8483, -2993, 21547, -16916, 7741, 24018}, +{ -14932, -23758, -5332, -6664, -4497, 13267}, +{ 19379, 12916, -2142, -737, 21100, -22101}, +{ 3393, -4629, 5735, -18913, -6969, 2687}, +{ 1148, -16147, -21433, -28095, -630, -14449}, +{ 7300, 672, 18530, -17452, -10149, 351}, +{ 11356, -10974, 17212, 4624, 145, 17791}, +{ -711, -3479, -2238, 15887, 2027, 0}, +{ -28048, 1794, -593, -2758, -21852, 11535}, +{ -19683, 4937, 22004, 21523, -3148, 1790}, +{ 813, 8231, 2633, 11981, -3043, 22201}, +{ 8952, -24760, -690, 14873, -2366, -5372}, +{ 8406, -5439, -274, -642, -145, 778}, +{ -6605, 7258, 20780, -23507, -18625, 22782}, +{ -22896, -25488, 10020, -1614, 1508, -1393}, +{ 7607, 407, -24678, -16385, -1804, -4699}, +{ -10592, -19139, 10462, -3747, 8721, -6919}, +{ 13010, 5292, -6230, -4884, -20904, -1797}, +{ 16891, -13770, -465, 19343, -10741, -12959}, +{ 25193, -14799, -5681, -521, -321, -1211}, +{ 6917, -3093, 20183, -26903, -12026, 1295}, +{ 305, 1992, 19457, -985, 25, -521}, +{ 6707, -3698, 8365, -8687, 21921, -27166}, +{ 4668, 5997, 7117, 11696, 24401, -10794}, +{ 744, -9416, 19893, 1963, 7922, -9824}, +{ 3430, 21282, -1736, 10844, 8821, 27015}, +{ -8813, 1521, -24038, 1651, 7838, -1208}, +{ 3911, -11221, 3273, -12541, 7168, 18402}, +{ 21642, 9117, -11536, -5256, 7077, 2382}, +{ 100, 3817, -6713, 1244, 1518, -321}, +{ 7946, -18670, 10667, -4866, 727, 776}, +{ -15883, -8150, -2087, 22739, 1567, -3482}, +{ 4380, -2735, 8469, -7025, -11424, 1317}, +{ 26970, 4393, 7665, 17561, -714, 650}, +{ -16191, -835, 8365, 1795, -14314, 16297}, +{ 4504, -10048, 7662, -26690, -17428, 2580}, +{ 48, -3984, 564, -5871, 2658, -18658}, +{ 12579, -26016, -15642, 2672, -1347, -887}, +{ -4950, 4208, -6811, 2569, -20621, -8658}, +{ -1836, -14818, -5571, -23322, -14800, 25867}, +{ 5434, -28139, -2357, -2883, -570, 2431}, +{ 13096, -2771, 24994, -12496, -24723, -1025}, +{ -5676, -4339, 1908, 18628, -21323, 17366}, +{ 27660, -27897, -15409, 1436, -7112, -2241}, +{ 8019, 3847, 24568, -469, 9674, 10683}, +{ -903, -10149, 1801, -21260, 4795, -8751}, +{ 1122, -9582, 2625, 22791, 956, 882}, +{ 7876, 19075, -9900, -24266, 7496, 9277}, +{ 980, -26764, -5386, 5396, 1086, 1648}, +{ 28838, -1270, -447, 5, -429, -20}, +{ -15283, 6132, 22812, 1252, -9963, 511}, +{ 851, 7925, -457, -12210, 4261, 7579}, +{ -4530, 8452, -1246, 14501, -24951, -5760}, +{ -17814, -10727, 9887, -23929, -13432, 1878}, +{ -15049, 10165, 16491, -14603, -11712, -21156}, +{ -3317, 840, -5683, 22413, 1994, 586}, +{ 23158, -5788, -15043, -10372, -9271, -13523}, +{ -773, -9509, -3993, -24264, 8463, 5804}, +{ -8545, -703, -12440, -3985, -25122, -28147}, +{ -16659, 16001, 2746, 1611, 5097, -1043}, +{ 41, -7181, 19903, 31555, -32237, 13927}, +{ -5658, 845, -12774, 5705, 16695, -86}, +{ 5282, 14875, 27026, 21124, 15776, -10477}, +{ 14712, 19648, -11487, -13361, -20196, -15229}, +{ 8597, -9138, -626, 10891, -6015, 6346}, +{ -1488, -1272, -1479, -1303, -3704, -5485}, +{ -3370, 17871, -6604, 24930, 25886, -3127}, +{ 8416, 27783, -1385, 5350, -4260, 19993}, +{ 5688, 362, 17246, 3809, -3246, 1088}, +{ -105, -29607, 2747, 15223, -167, 3722}, +{ 3502, -3195, 8602, 7772, -1566, -915}, +{ -491, 3257, -2423, 5522, 20606, -100}, +{ -13948, -11368, -15375, -21866, -8520, 12221}, +{ -616, 2424, -2023, 4398, -3805, 8108}, +{ -7204, 21043, 21211, -9395, -19391, 896}, +{ -5737, -15160, -21298, 17066, -1006, -366}, +{ 6261, 3240, -11937, -16213, -15820, 6581}, +{ -3155, 24796, 2733, -1257, -875, -1597}, +{ -20469, 11094, 24071, -8987, 14136, 2220}, +{ -14106, 11959, -22495, 4135, -1055, -5420}, +{ 801, -2655, 60, -5324, -790, 5937}, +{ -7372, -1764, -22433, -26060, 21707, 4178}, +{ -5715, -6648, -14908, 1325, -24044, 1493}, +{ -6024, -12488, 23930, 2950, 1601, 1173}, +{ 19067, 17630, 17929, -10654, 10928, -4958}, +{ 3231, -3284, 27336, 4174, -1683, 497}, +}; + +const int16_t (* const ff_eac3_mantissa_vq[8])[6] = { + NULL, + vq_hebap1, + vq_hebap2, + vq_hebap3, + vq_hebap4, + vq_hebap5, + vq_hebap6, + vq_hebap7, +}; + +/** + * Table E2.14 Frame Exponent Strategy Combinations + */ +const uint8_t ff_eac3_frm_expstr[32][6] = { +{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45}, +{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE}, +{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45}, +{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE}, +{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45}, +{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE}, +{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45}, +{ EXP_D25, EXP_REUSE, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45}, +{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE}, +{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45}, +{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE}, +{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45}, +{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, +{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, +{ EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +{ EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45}, +{ EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE}, +{ EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45}, +{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE}, +{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45}, +{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE}, +{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45}, +{ EXP_D45, EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45}, +{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE}, +{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45}, +{ EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE}, +{ EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45}, +{ EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, +{ EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, +}; + +/** + * Table E.25: Spectral Extension Attenuation Table + * ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0); + */ +const float ff_eac3_spx_atten_tab[32][3] = { + { 0.954841603910416503f, 0.911722488558216804f, 0.870550563296124125f }, + { 0.911722488558216804f, 0.831237896142787758f, 0.757858283255198995f }, + { 0.870550563296124125f, 0.757858283255198995f, 0.659753955386447100f }, + { 0.831237896142787758f, 0.690956439983888004f, 0.574349177498517438f }, + { 0.793700525984099792f, 0.629960524947436595f, 0.500000000000000000f }, + { 0.757858283255198995f, 0.574349177498517438f, 0.435275281648062062f }, + { 0.723634618720189082f, 0.523647061410313364f, 0.378929141627599553f }, + { 0.690956439983888004f, 0.477420801955208307f, 0.329876977693223550f }, + { 0.659753955386447100f, 0.435275281648062062f, 0.287174588749258719f }, + { 0.629960524947436595f, 0.396850262992049896f, 0.250000000000000000f }, + { 0.601512518041058319f, 0.361817309360094541f, 0.217637640824031003f }, + { 0.574349177498517438f, 0.329876977693223550f, 0.189464570813799776f }, + { 0.548412489847312945f, 0.300756259020529160f, 0.164938488846611775f }, + { 0.523647061410313364f, 0.274206244923656473f, 0.143587294374629387f }, + { 0.500000000000000000f, 0.250000000000000000f, 0.125000000000000000f }, + { 0.477420801955208307f, 0.227930622139554201f, 0.108818820412015502f }, + { 0.455861244279108402f, 0.207809474035696939f, 0.094732285406899888f }, + { 0.435275281648062062f, 0.189464570813799776f, 0.082469244423305887f }, + { 0.415618948071393879f, 0.172739109995972029f, 0.071793647187314694f }, + { 0.396850262992049896f, 0.157490131236859149f, 0.062500000000000000f }, + { 0.378929141627599553f, 0.143587294374629387f, 0.054409410206007751f }, + { 0.361817309360094541f, 0.130911765352578369f, 0.047366142703449930f }, + { 0.345478219991944002f, 0.119355200488802049f, 0.041234622211652958f }, + { 0.329876977693223550f, 0.108818820412015502f, 0.035896823593657347f }, + { 0.314980262473718298f, 0.099212565748012460f, 0.031250000000000000f }, + { 0.300756259020529160f, 0.090454327340023621f, 0.027204705103003875f }, + { 0.287174588749258719f, 0.082469244423305887f, 0.023683071351724965f }, + { 0.274206244923656473f, 0.075189064755132290f, 0.020617311105826479f }, + { 0.261823530705156682f, 0.068551561230914118f, 0.017948411796828673f }, + { 0.250000000000000000f, 0.062500000000000000f, 0.015625000000000000f }, + { 0.238710400977604098f, 0.056982655534888536f, 0.013602352551501938f }, + { 0.227930622139554201f, 0.051952368508924235f, 0.011841535675862483f } +}; diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.h new file mode 100644 index 000000000..10a67f16d --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3_data.h @@ -0,0 +1,36 @@ +/* + * E-AC-3 tables + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_EAC3_DATA_H +#define AVCODEC_EAC3_DATA_H + +#include + +extern const uint8_t ff_eac3_bits_vs_hebap[20]; +extern const int16_t ff_eac3_gaq_remap_1[12]; +extern const int16_t ff_eac3_gaq_remap_2_4_a[9][2]; +extern const int16_t ff_eac3_gaq_remap_2_4_b[9][2]; + +extern const int16_t (* const ff_eac3_mantissa_vq[8])[6]; +extern const uint8_t ff_eac3_frm_expstr[32][6]; +extern const float ff_eac3_spx_atten_tab[32][3]; + +#endif /* AVCODEC_EAC3_DATA_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3dec.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3dec.c new file mode 100644 index 000000000..b55ee2a34 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/eac3dec.c @@ -0,0 +1,607 @@ +/* + * E-AC-3 decoder + * Copyright (c) 2007 Bartlomiej Wolowiec + * Copyright (c) 2008 Justin Ruggles + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * There are several features of E-AC-3 that this decoder does not yet support. + * + * Enhanced Coupling + * No known samples exist. If any ever surface, this feature should not be + * too difficult to implement. + * + * Reduced Sample Rates + * No known samples exist. The spec also does not give clear information + * on how this is to be implemented. + * + * Dependent Streams + * Only the independent stream is currently decoded. Any dependent + * streams are skipped. We have only come across two examples of this, and + * they are both just test streams, one for HD-DVD and the other for + * Blu-ray. + * + * Transient Pre-noise Processing + * This is side information which a decoder should use to reduce artifacts + * caused by transients. There are samples which are known to have this + * information, but this decoder currently ignores it. + */ + + +#include "avcodec.h" +#include "internal.h" +#include "aac_ac3_parser.h" +#include "ac3.h" +#include "ac3_parser.h" +#include "ac3dec.h" +#include "ac3dec_data.h" +#include "eac3_data.h" + +/** gain adaptive quantization mode */ +typedef enum { + EAC3_GAQ_NO =0, + EAC3_GAQ_12, + EAC3_GAQ_14, + EAC3_GAQ_124 +} EAC3GaqMode; + +#define EAC3_SR_CODE_REDUCED 3 + +void ff_eac3_apply_spectral_extension(AC3DecodeContext *s) +{ + int bin, bnd, ch, i; + uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS]; + float rms_energy[SPX_MAX_BANDS]; + + /* Set copy index mapping table. Set wrap flags to apply a notch filter at + wrap points later on. */ + bin = s->spx_dst_start_freq; + num_copy_sections = 0; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + int copysize; + int bandsize = s->spx_band_sizes[bnd]; + if (bin + bandsize > s->spx_src_start_freq) { + copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; + bin = s->spx_dst_start_freq; + wrapflag[bnd] = 1; + } + for (i = 0; i < bandsize; i += copysize) { + if (bin == s->spx_src_start_freq) { + copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; + bin = s->spx_dst_start_freq; + } + copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin); + bin += copysize; + } + } + copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; + + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (!s->channel_uses_spx[ch]) + continue; + + /* Copy coeffs from normal bands to extension bands */ + bin = s->spx_src_start_freq; + for (i = 0; i < num_copy_sections; i++) { + memcpy(&s->transform_coeffs[ch][bin], + &s->transform_coeffs[ch][s->spx_dst_start_freq], + copy_sizes[i]*sizeof(float)); + bin += copy_sizes[i]; + } + + /* Calculate RMS energy for each SPX band. */ + bin = s->spx_src_start_freq; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + int bandsize = s->spx_band_sizes[bnd]; + float accum = 0.0f; + for (i = 0; i < bandsize; i++) { + float coeff = s->transform_coeffs[ch][bin++]; + accum += coeff * coeff; + } + rms_energy[bnd] = sqrtf(accum / bandsize); + } + + /* Apply a notch filter at transitions between normal and extension + bands and at all wrap points. */ + if (s->spx_atten_code[ch] >= 0) { + const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]]; + bin = s->spx_src_start_freq - 2; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + if (wrapflag[bnd]) { + float *coeffs = &s->transform_coeffs[ch][bin]; + coeffs[0] *= atten_tab[0]; + coeffs[1] *= atten_tab[1]; + coeffs[2] *= atten_tab[2]; + coeffs[3] *= atten_tab[1]; + coeffs[4] *= atten_tab[0]; + } + bin += s->spx_band_sizes[bnd]; + } + } + + /* Apply noise-blended coefficient scaling based on previously + calculated RMS energy, blending factors, and SPX coordinates for + each band. */ + bin = s->spx_src_start_freq; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN); + float sscale = s->spx_signal_blend[ch][bnd]; + for (i = 0; i < s->spx_band_sizes[bnd]; i++) { + float noise = nscale * (int32_t)av_lfg_get(&s->dith_state); + s->transform_coeffs[ch][bin] *= sscale; + s->transform_coeffs[ch][bin++] += noise; + } + } + } +} + + +/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */ +#define COEFF_0 10273905LL + +/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */ +#define COEFF_1 11863283LL + +/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */ +#define COEFF_2 3070444LL + +/** + * Calculate 6-point IDCT of the pre-mantissas. + * All calculations are 24-bit fixed-point. + */ +static void idct6(int pre_mant[6]) +{ + int tmp; + int even0, even1, even2, odd0, odd1, odd2; + + odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5]; + + even2 = ( pre_mant[2] * COEFF_0) >> 23; + tmp = ( pre_mant[4] * COEFF_1) >> 23; + odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23; + + even0 = pre_mant[0] + (tmp >> 1); + even1 = pre_mant[0] - tmp; + + tmp = even0; + even0 = tmp + even2; + even2 = tmp - even2; + + tmp = odd0; + odd0 = tmp + pre_mant[1] + pre_mant[3]; + odd2 = tmp + pre_mant[5] - pre_mant[3]; + + pre_mant[0] = even0 + odd0; + pre_mant[1] = even1 + odd1; + pre_mant[2] = even2 + odd2; + pre_mant[3] = even2 - odd2; + pre_mant[4] = even1 - odd1; + pre_mant[5] = even0 - odd0; +} + +void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch) +{ + int bin, blk, gs; + int end_bap, gaq_mode; + GetBitContext *gbc = &s->gbc; + int gaq_gain[AC3_MAX_COEFS]; + + gaq_mode = get_bits(gbc, 2); + end_bap = (gaq_mode < 2) ? 12 : 17; + + /* if GAQ gain is used, decode gain codes for bins with hebap between + 8 and end_bap */ + gs = 0; + if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) { + /* read 1-bit GAQ gain codes */ + for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { + if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap) + gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1); + } + } else if (gaq_mode == EAC3_GAQ_124) { + /* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */ + int gc = 2; + for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { + if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) { + if (gc++ == 2) { + int group_code = get_bits(gbc, 5); + if (group_code > 26) { + av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n"); + group_code = 26; + } + gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0]; + gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1]; + gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2]; + gc = 0; + } + } + } + } + + gs=0; + for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) { + int hebap = s->bap[ch][bin]; + int bits = ff_eac3_bits_vs_hebap[hebap]; + if (!hebap) { + /* zero-mantissa dithering */ + for (blk = 0; blk < 6; blk++) { + s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; + } + } else if (hebap < 8) { + /* Vector Quantization */ + int v = get_bits(gbc, bits); + for (blk = 0; blk < 6; blk++) { + s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8; + } + } else { + /* Gain Adaptive Quantization */ + int gbits, log_gain; + if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) { + log_gain = gaq_gain[gs++]; + } else { + log_gain = 0; + } + gbits = bits - log_gain; + + for (blk = 0; blk < 6; blk++) { + int mant = get_sbits(gbc, gbits); + if (log_gain && mant == -(1 << (gbits-1))) { + /* large mantissa */ + int b; + int mbits = bits - (2 - log_gain); + mant = get_sbits(gbc, mbits); + mant <<= (23 - (mbits - 1)); + /* remap mantissa value to correct for asymmetric quantization */ + if (mant >= 0) + b = 1 << (23 - log_gain); + else + b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8; + mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b; + } else { + /* small mantissa, no GAQ, or Gk=1 */ + mant <<= 24 - bits; + if (!log_gain) { + /* remap mantissa value for no GAQ or Gk=1 */ + mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15; + } + } + s->pre_mantissa[ch][bin][blk] = mant; + } + } + idct6(s->pre_mantissa[ch][bin]); + } +} + +int ff_eac3_parse_header(AC3DecodeContext *s) +{ + int i, blk, ch; + int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data; + int parse_transient_proc_info; + int num_cpl_blocks; + GetBitContext *gbc = &s->gbc; + + /* An E-AC-3 stream can have multiple independent streams which the + application can select from. each independent stream can also contain + dependent streams which are used to add or replace channels. */ + if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) { + avpriv_request_sample(s->avctx, "Dependent substream decoding"); + return AAC_AC3_PARSE_ERROR_FRAME_TYPE; + } else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) { + av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n"); + return AAC_AC3_PARSE_ERROR_FRAME_TYPE; + } + + /* The substream id indicates which substream this frame belongs to. each + independent stream has its own substream id, and the dependent streams + associated to an independent stream have matching substream id's. */ + if (s->substreamid) { + /* only decode substream with id=0. skip any additional substreams. */ + avpriv_request_sample(s->avctx, "Additional substreams"); + return AAC_AC3_PARSE_ERROR_FRAME_TYPE; + } + + if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) { + /* The E-AC-3 specification does not tell how to handle reduced sample + rates in bit allocation. The best assumption would be that it is + handled like AC-3 DolbyNet, but we cannot be sure until we have a + sample which utilizes this feature. */ + avpriv_request_sample(s->avctx, "Reduced sampling rate"); + return AVERROR_PATCHWELCOME; + } + skip_bits(gbc, 5); // skip bitstream id + + /* volume control params */ + for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { + skip_bits(gbc, 5); // skip dialog normalization + if (get_bits1(gbc)) { + skip_bits(gbc, 8); // skip compression gain word + } + } + + /* dependent stream channel map */ + if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) { + if (get_bits1(gbc)) { + skip_bits(gbc, 16); // skip custom channel map + } + } + + /* mixing metadata */ + if (get_bits1(gbc)) { + /* center and surround mix levels */ + if (s->channel_mode > AC3_CHMODE_STEREO) { + skip_bits(gbc, 2); // skip preferred stereo downmix mode + if (s->channel_mode & 1) { + /* if three front channels exist */ + skip_bits(gbc, 3); //skip Lt/Rt center mix level + s->center_mix_level = get_bits(gbc, 3); + } + if (s->channel_mode & 4) { + /* if a surround channel exists */ + skip_bits(gbc, 3); //skip Lt/Rt surround mix level + s->surround_mix_level = get_bits(gbc, 3); + } + } + + /* lfe mix level */ + if (s->lfe_on && get_bits1(gbc)) { + // TODO: use LFE mix level + skip_bits(gbc, 5); // skip LFE mix level code + } + + /* info for mixing with other streams and substreams */ + if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) { + for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { + // TODO: apply program scale factor + if (get_bits1(gbc)) { + skip_bits(gbc, 6); // skip program scale factor + } + } + if (get_bits1(gbc)) { + skip_bits(gbc, 6); // skip external program scale factor + } + /* skip mixing parameter data */ + switch(get_bits(gbc, 2)) { + case 1: skip_bits(gbc, 5); break; + case 2: skip_bits(gbc, 12); break; + case 3: { + int mix_data_size = (get_bits(gbc, 5) + 2) << 3; + skip_bits_long(gbc, mix_data_size); + break; + } + } + /* skip pan information for mono or dual mono source */ + if (s->channel_mode < AC3_CHMODE_STEREO) { + for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { + if (get_bits1(gbc)) { + /* note: this is not in the ATSC A/52B specification + reference: ETSI TS 102 366 V1.1.1 + section: E.1.3.1.25 */ + skip_bits(gbc, 8); // skip pan mean direction index + skip_bits(gbc, 6); // skip reserved paninfo bits + } + } + } + /* skip mixing configuration information */ + if (get_bits1(gbc)) { + for (blk = 0; blk < s->num_blocks; blk++) { + if (s->num_blocks == 1 || get_bits1(gbc)) { + skip_bits(gbc, 5); + } + } + } + } + } + + /* informational metadata */ + if (get_bits1(gbc)) { + s->bitstream_mode = get_bits(gbc, 3); + skip_bits(gbc, 2); // skip copyright bit and original bitstream bit + if (s->channel_mode == AC3_CHMODE_STEREO) { + skip_bits(gbc, 4); // skip Dolby surround and headphone mode + } + if (s->channel_mode >= AC3_CHMODE_2F2R) { + skip_bits(gbc, 2); // skip Dolby surround EX mode + } + for (i = 0; i < (s->channel_mode ? 1 : 2); i++) { + if (get_bits1(gbc)) { + skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type + } + } + if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) { + skip_bits1(gbc); // skip source sample rate code + } + } + + /* converter synchronization flag + If frames are less than six blocks, this bit should be turned on + once every 6 blocks to indicate the start of a frame set. + reference: RFC 4598, Section 2.1.3 Frame Sets */ + if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) { + skip_bits1(gbc); // skip converter synchronization flag + } + + /* original frame size code if this stream was converted from AC-3 */ + if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT && + (s->num_blocks == 6 || get_bits1(gbc))) { + skip_bits(gbc, 6); // skip frame size code + } + + /* additional bitstream info */ + if (get_bits1(gbc)) { + int addbsil = get_bits(gbc, 6); + for (i = 0; i < addbsil + 1; i++) { + skip_bits(gbc, 8); // skip additional bit stream info + } + } + + /* audio frame syntax flags, strategy data, and per-frame data */ + + if (s->num_blocks == 6) { + ac3_exponent_strategy = get_bits1(gbc); + parse_aht_info = get_bits1(gbc); + } else { + /* less than 6 blocks, so use AC-3-style exponent strategy syntax, and + do not use AHT */ + ac3_exponent_strategy = 1; + parse_aht_info = 0; + } + + s->snr_offset_strategy = get_bits(gbc, 2); + parse_transient_proc_info = get_bits1(gbc); + + s->block_switch_syntax = get_bits1(gbc); + if (!s->block_switch_syntax) + memset(s->block_switch, 0, sizeof(s->block_switch)); + + s->dither_flag_syntax = get_bits1(gbc); + if (!s->dither_flag_syntax) { + for (ch = 1; ch <= s->fbw_channels; ch++) + s->dither_flag[ch] = 1; + } + s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0; + + s->bit_allocation_syntax = get_bits1(gbc); + if (!s->bit_allocation_syntax) { + /* set default bit allocation parameters */ + s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2]; + s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1]; + s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab [1]; + s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2]; + s->bit_alloc_params.floor = ff_ac3_floor_tab [7]; + } + + s->fast_gain_syntax = get_bits1(gbc); + s->dba_syntax = get_bits1(gbc); + s->skip_syntax = get_bits1(gbc); + parse_spx_atten_data = get_bits1(gbc); + + /* coupling strategy occurrence and coupling use per block */ + num_cpl_blocks = 0; + if (s->channel_mode > 1) { + for (blk = 0; blk < s->num_blocks; blk++) { + s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc)); + if (s->cpl_strategy_exists[blk]) { + s->cpl_in_use[blk] = get_bits1(gbc); + } else { + s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; + } + num_cpl_blocks += s->cpl_in_use[blk]; + } + } else { + memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use)); + } + + /* exponent strategy data */ + if (ac3_exponent_strategy) { + /* AC-3-style exponent strategy syntax */ + for (blk = 0; blk < s->num_blocks; blk++) { + for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) { + s->exp_strategy[blk][ch] = get_bits(gbc, 2); + } + } + } else { + /* LUT-based exponent strategy syntax */ + for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) { + int frmchexpstr = get_bits(gbc, 5); + for (blk = 0; blk < 6; blk++) { + s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk]; + } + } + } + /* LFE exponent strategy */ + if (s->lfe_on) { + for (blk = 0; blk < s->num_blocks; blk++) { + s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc); + } + } + /* original exponent strategies if this stream was converted from AC-3 */ + if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && + (s->num_blocks == 6 || get_bits1(gbc))) { + skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy + } + + /* determine which channels use AHT */ + if (parse_aht_info) { + /* For AHT to be used, all non-zero blocks must reuse exponents from + the first block. Furthermore, for AHT to be used in the coupling + channel, all blocks must use coupling and use the same coupling + strategy. */ + s->channel_uses_aht[CPL_CH]=0; + for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) { + int use_aht = 1; + for (blk = 1; blk < 6; blk++) { + if ((s->exp_strategy[blk][ch] != EXP_REUSE) || + (!ch && s->cpl_strategy_exists[blk])) { + use_aht = 0; + break; + } + } + s->channel_uses_aht[ch] = use_aht && get_bits1(gbc); + } + } else { + memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht)); + } + + /* per-frame SNR offset */ + if (!s->snr_offset_strategy) { + int csnroffst = (get_bits(gbc, 6) - 15) << 4; + int snroffst = (csnroffst + get_bits(gbc, 4)) << 2; + for (ch = 0; ch <= s->channels; ch++) + s->snr_offset[ch] = snroffst; + } + + /* transient pre-noise processing data */ + if (parse_transient_proc_info) { + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (get_bits1(gbc)) { // channel in transient processing + skip_bits(gbc, 10); // skip transient processing location + skip_bits(gbc, 8); // skip transient processing length + } + } + } + + /* spectral extension attenuation data */ + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (parse_spx_atten_data && get_bits1(gbc)) { + s->spx_atten_code[ch] = get_bits(gbc, 5); + } else { + s->spx_atten_code[ch] = -1; + } + } + + /* block start information */ + if (s->num_blocks > 1 && get_bits1(gbc)) { + /* reference: Section E2.3.2.27 + nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame))) + The spec does not say what this data is or what it's used for. + It is likely the offset of each block within the frame. */ + int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2)); + skip_bits_long(gbc, block_start_bits); + avpriv_request_sample(s->avctx, "Block start info"); + } + + /* syntax state initialization */ + for (ch = 1; ch <= s->fbw_channels; ch++) { + s->first_spx_coords[ch] = 1; + s->first_cpl_coords[ch] = 1; + } + s->first_cpl_leak = 1; + + return 0; +} diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.c new file mode 100644 index 000000000..5a62e9da2 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.c @@ -0,0 +1,47 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/avassert.h" +#include "libavutil/mathematics.h" +#include "libavutil/attributes.h" +#include "kbdwin.h" + +#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation + +av_cold void ff_kbd_window_init(float *window, float alpha, int n) +{ + int i, j; + double sum = 0.0, bessel, tmp; + double local_window[FF_KBD_WINDOW_MAX]; + double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); + + av_assert0(n <= FF_KBD_WINDOW_MAX); + + for (i = 0; i < n; i++) { + tmp = i * (n - i) * alpha2; + bessel = 1.0; + for (j = BESSEL_I0_ITER; j > 0; j--) + bessel = bessel * tmp / (j * j) + 1; + sum += bessel; + local_window[i] = sum; + } + + sum++; + for (i = 0; i < n; i++) + window[i] = sqrt(local_window[i] / sum); +} diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.h new file mode 100644 index 000000000..4b939756c --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/kbdwin.h @@ -0,0 +1,35 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_KBDWIN_H +#define AVCODEC_KBDWIN_H + +/** + * Maximum window size for ff_kbd_window_init. + */ +#define FF_KBD_WINDOW_MAX 1024 + +/** + * Generate a Kaiser-Bessel Derived Window. + * @param window pointer to half window + * @param alpha determines window shape + * @param n size of half window, max FF_KBD_WINDOW_MAX + */ +void ff_kbd_window_init(float *window, float alpha, int n); + +#endif /* AVCODEC_KBDWIN_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/x86/ac3dsp_init.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/x86/ac3dsp_init.c new file mode 100644 index 000000000..8c94db0d8 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/x86/ac3dsp_init.c @@ -0,0 +1,231 @@ +/* + * x86-optimized AC-3 DSP utils + * Copyright (c) 2011 Justin Ruggles + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/mem.h" +#include "libavutil/x86/asm.h" +#include "libavutil/x86/cpu.h" +#include "dsputil_x86.h" +#include "libavcodec/ac3.h" +#include "libavcodec/ac3dsp.h" + +void ff_ac3_exponent_min_mmx (uint8_t *exp, int num_reuse_blocks, int nb_coefs); +void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs); +void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs); + +int ff_ac3_max_msb_abs_int16_mmx (const int16_t *src, int len); +int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len); +int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len); +int ff_ac3_max_msb_abs_int16_ssse3(const int16_t *src, int len); + +void ff_ac3_lshift_int16_mmx (int16_t *src, unsigned int len, unsigned int shift); +void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift); + +void ff_ac3_rshift_int32_mmx (int32_t *src, unsigned int len, unsigned int shift); +void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift); + +void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len); +void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len); +void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len); + +int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]); + +void ff_ac3_extract_exponents_3dnow(uint8_t *exp, int32_t *coef, int nb_coefs); +void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs); +void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs); + +#if ARCH_X86_32 && defined(__INTEL_COMPILER) +# undef HAVE_7REGS +# define HAVE_7REGS 0 +#endif + +#if HAVE_SSE_INLINE && HAVE_7REGS + +#define IF1(x) x +#define IF0(x) + +#define MIX5(mono, stereo) \ + __asm__ volatile ( \ + "movss 0(%1), %%xmm5 \n" \ + "movss 8(%1), %%xmm6 \n" \ + "movss 24(%1), %%xmm7 \n" \ + "shufps $0, %%xmm5, %%xmm5 \n" \ + "shufps $0, %%xmm6, %%xmm6 \n" \ + "shufps $0, %%xmm7, %%xmm7 \n" \ + "1: \n" \ + "movaps (%0, %2), %%xmm0 \n" \ + "movaps (%0, %3), %%xmm1 \n" \ + "movaps (%0, %4), %%xmm2 \n" \ + "movaps (%0, %5), %%xmm3 \n" \ + "movaps (%0, %6), %%xmm4 \n" \ + "mulps %%xmm5, %%xmm0 \n" \ + "mulps %%xmm6, %%xmm1 \n" \ + "mulps %%xmm5, %%xmm2 \n" \ + "mulps %%xmm7, %%xmm3 \n" \ + "mulps %%xmm7, %%xmm4 \n" \ + stereo("addps %%xmm1, %%xmm0 \n") \ + "addps %%xmm1, %%xmm2 \n" \ + "addps %%xmm3, %%xmm0 \n" \ + "addps %%xmm4, %%xmm2 \n" \ + mono("addps %%xmm2, %%xmm0 \n") \ + "movaps %%xmm0, (%0, %2) \n" \ + stereo("movaps %%xmm2, (%0, %3) \n") \ + "add $16, %0 \n" \ + "jl 1b \n" \ + : "+&r"(i) \ + : "r"(matrix), \ + "r"(samples[0] + len), \ + "r"(samples[1] + len), \ + "r"(samples[2] + len), \ + "r"(samples[3] + len), \ + "r"(samples[4] + len) \ + : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ + "%xmm4", "%xmm5", "%xmm6", "%xmm7",) \ + "memory" \ + ); + +#define MIX_MISC(stereo) \ + __asm__ volatile ( \ + "mov %5, %2 \n" \ + "1: \n" \ + "mov -%c7(%6, %2, %c8), %3 \n" \ + "movaps (%3, %0), %%xmm0 \n" \ + stereo("movaps %%xmm0, %%xmm1 \n") \ + "mulps %%xmm4, %%xmm0 \n" \ + stereo("mulps %%xmm5, %%xmm1 \n") \ + "2: \n" \ + "mov (%6, %2, %c8), %1 \n" \ + "movaps (%1, %0), %%xmm2 \n" \ + stereo("movaps %%xmm2, %%xmm3 \n") \ + "mulps (%4, %2, 8), %%xmm2 \n" \ + stereo("mulps 16(%4, %2, 8), %%xmm3 \n") \ + "addps %%xmm2, %%xmm0 \n" \ + stereo("addps %%xmm3, %%xmm1 \n") \ + "add $4, %2 \n" \ + "jl 2b \n" \ + "mov %5, %2 \n" \ + stereo("mov (%6, %2, %c8), %1 \n") \ + "movaps %%xmm0, (%3, %0) \n" \ + stereo("movaps %%xmm1, (%1, %0) \n") \ + "add $16, %0 \n" \ + "jl 1b \n" \ + : "+&r"(i), "=&r"(j), "=&r"(k), "=&r"(m) \ + : "r"(matrix_simd + in_ch), \ + "g"((intptr_t) - 4 * (in_ch - 1)), \ + "r"(samp + in_ch), \ + "i"(sizeof(float *)), "i"(sizeof(float *)/4) \ + : "memory" \ + ); + +static void ac3_downmix_sse(float **samples, float (*matrix)[2], + int out_ch, int in_ch, int len) +{ + int (*matrix_cmp)[2] = (int(*)[2])matrix; + intptr_t i, j, k, m; + + i = -len * sizeof(float); + if (in_ch == 5 && out_ch == 2 && + !(matrix_cmp[0][1] | matrix_cmp[2][0] | + matrix_cmp[3][1] | matrix_cmp[4][0] | + (matrix_cmp[1][0] ^ matrix_cmp[1][1]) | + (matrix_cmp[0][0] ^ matrix_cmp[2][1]))) { + MIX5(IF0, IF1); + } else if (in_ch == 5 && out_ch == 1 && + matrix_cmp[0][0] == matrix_cmp[2][0] && + matrix_cmp[3][0] == matrix_cmp[4][0]) { + MIX5(IF1, IF0); + } else { + DECLARE_ALIGNED(16, float, matrix_simd)[AC3_MAX_CHANNELS][2][4]; + float *samp[AC3_MAX_CHANNELS]; + + for (j = 0; j < in_ch; j++) + samp[j] = samples[j] + len; + + j = 2 * in_ch * sizeof(float); + __asm__ volatile ( + "1: \n" + "sub $8, %0 \n" + "movss (%2, %0), %%xmm4 \n" + "movss 4(%2, %0), %%xmm5 \n" + "shufps $0, %%xmm4, %%xmm4 \n" + "shufps $0, %%xmm5, %%xmm5 \n" + "movaps %%xmm4, (%1, %0, 4) \n" + "movaps %%xmm5, 16(%1, %0, 4) \n" + "jg 1b \n" + : "+&r"(j) + : "r"(matrix_simd), "r"(matrix) + : "memory" + ); + if (out_ch == 2) { + MIX_MISC(IF1); + } else { + MIX_MISC(IF0); + } + } +} + +#endif /* HAVE_SSE_INLINE && HAVE_7REGS */ + +av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact) +{ + int cpu_flags = av_get_cpu_flags(); + + if (EXTERNAL_MMX(cpu_flags)) { + c->ac3_exponent_min = ff_ac3_exponent_min_mmx; + c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx; + c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx; + c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx; + } + if (EXTERNAL_AMD3DNOW(cpu_flags)) { + if (!bit_exact) { + c->float_to_fixed24 = ff_float_to_fixed24_3dnow; + } + } + if (EXTERNAL_MMXEXT(cpu_flags)) { + c->ac3_exponent_min = ff_ac3_exponent_min_mmxext; + c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmxext; + } + if (EXTERNAL_SSE(cpu_flags)) { + c->float_to_fixed24 = ff_float_to_fixed24_sse; + } + if (EXTERNAL_SSE2(cpu_flags)) { + c->ac3_exponent_min = ff_ac3_exponent_min_sse2; + c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2; + c->float_to_fixed24 = ff_float_to_fixed24_sse2; + c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2; + c->extract_exponents = ff_ac3_extract_exponents_sse2; + if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) { + c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2; + c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2; + } + } + if (EXTERNAL_SSSE3(cpu_flags)) { + c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_ssse3; + if (!(cpu_flags & AV_CPU_FLAG_ATOM)) { + c->extract_exponents = ff_ac3_extract_exponents_ssse3; + } + } + +#if HAVE_SSE_INLINE && HAVE_7REGS + if (INLINE_SSE(cpu_flags)) { + c->downmix = ac3_downmix_sse; + } +#endif +} diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavformat/ac3dec.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavformat/ac3dec.c new file mode 100644 index 000000000..3db23397d --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavformat/ac3dec.c @@ -0,0 +1,123 @@ +/* + * RAW AC-3 and E-AC-3 demuxer + * Copyright (c) 2007 Justin Ruggles + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/crc.h" +#include "libavcodec/ac3_parser.h" +#include "avformat.h" +#include "rawdec.h" + +static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID expected_codec_id) +{ + int max_frames, first_frames = 0, frames; + const uint8_t *buf, *buf2, *end; + AC3HeaderInfo hdr; + GetBitContext gbc; + enum AVCodecID codec_id = AV_CODEC_ID_AC3; + + max_frames = 0; + buf = p->buf; + end = buf + p->buf_size; + + for(; buf < end; buf++) { + if(buf > p->buf && !(buf[0] == 0x0B && buf[1] == 0x77) + && !(buf[0] == 0x77 && buf[1] == 0x0B) ) + continue; + buf2 = buf; + + for(frames = 0; buf2 < end; frames++) { + uint8_t buf3[4096]; + int i; + if(!memcmp(buf2, "\x1\x10\0\0\0\0\0\0", 8)) + buf2+=16; + if (buf[0] == 0x77 && buf[1] == 0x0B) { + for(i=0; i<8; i+=2) { + buf3[i ] = buf[i+1]; + buf3[i+1] = buf[i ]; + } + init_get_bits(&gbc, buf3, 54); + }else + init_get_bits(&gbc, buf2, 54); + if(avpriv_ac3_parse_header(&gbc, &hdr) < 0) + break; + if(buf2 + hdr.frame_size > end) + break; + if (buf[0] == 0x77 && buf[1] == 0x0B) { + av_assert0(hdr.frame_size <= sizeof(buf3)); + for(i=8; i 10) + codec_id = AV_CODEC_ID_EAC3; + buf2 += hdr.frame_size; + } + max_frames = FFMAX(max_frames, frames); + if(buf == p->buf) + first_frames = frames; + } + if(codec_id != expected_codec_id) return 0; + // keep this in sync with mp3 probe, both need to avoid + // issues with MPEG-files! + if (first_frames>=4) return AVPROBE_SCORE_EXTENSION + 1; + else if(max_frames>200)return AVPROBE_SCORE_EXTENSION; + else if(max_frames>=4) return AVPROBE_SCORE_EXTENSION/2; + else if(max_frames>=1) return 1; + else return 0; +} + +#if CONFIG_AC3_DEMUXER +static int ac3_probe(AVProbeData *p) +{ + return ac3_eac3_probe(p, AV_CODEC_ID_AC3); +} + +AVInputFormat ff_ac3_demuxer = { + .name = "ac3", + .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"), + .read_probe = ac3_probe, + .read_header = ff_raw_audio_read_header, + .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "ac3", + .raw_codec_id = AV_CODEC_ID_AC3, +}; +#endif + +#if CONFIG_EAC3_DEMUXER +static int eac3_probe(AVProbeData *p) +{ + return ac3_eac3_probe(p, AV_CODEC_ID_EAC3); +} + +AVInputFormat ff_eac3_demuxer = { + .name = "eac3", + .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"), + .read_probe = eac3_probe, + .read_header = ff_raw_audio_read_header, + .read_packet = ff_raw_read_partial_packet, + .flags = AVFMT_GENERIC_INDEX, + .extensions = "eac3", + .raw_codec_id = AV_CODEC_ID_EAC3, +}; +#endif diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.c new file mode 100644 index 000000000..ffa2f1fd3 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.c @@ -0,0 +1,102 @@ +/* + * Lagged Fibonacci PRNG + * Copyright (c) 2008 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include "lfg.h" +#include "md5.h" +#include "intreadwrite.h" +#include "attributes.h" + +av_cold void av_lfg_init(AVLFG *c, unsigned int seed) +{ + uint8_t tmp[16] = { 0 }; + int i; + + for (i = 8; i < 64; i += 4) { + AV_WL32(tmp, seed); + tmp[4] = i; + av_md5_sum(tmp, tmp, 16); + c->state[i ] = AV_RL32(tmp); + c->state[i + 1] = AV_RL32(tmp + 4); + c->state[i + 2] = AV_RL32(tmp + 8); + c->state[i + 3] = AV_RL32(tmp + 12); + } + c->index = 0; +} + +void av_bmg_get(AVLFG *lfg, double out[2]) +{ + double x1, x2, w; + + do { + x1 = 2.0 / UINT_MAX * av_lfg_get(lfg) - 1.0; + x2 = 2.0 / UINT_MAX * av_lfg_get(lfg) - 1.0; + w = x1 * x1 + x2 * x2; + } while (w >= 1.0); + + w = sqrt((-2.0 * log(w)) / w); + out[0] = x1 * w; + out[1] = x2 * w; +} + +#ifdef TEST +#include "log.h" +#include "timer.h" + +int main(void) +{ + int x = 0; + int i, j; + AVLFG state; + + av_lfg_init(&state, 0xdeadbeef); + for (j = 0; j < 10000; j++) { + START_TIMER + for (i = 0; i < 624; i++) { + //av_log(NULL, AV_LOG_ERROR, "%X\n", av_lfg_get(&state)); + x += av_lfg_get(&state); + } + STOP_TIMER("624 calls of av_lfg_get"); + } + av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x); + + /* BMG usage example */ + { + double mean = 1000; + double stddev = 53; + + av_lfg_init(&state, 42); + + for (i = 0; i < 1000; i += 2) { + double bmg_out[2]; + av_bmg_get(&state, bmg_out); + av_log(NULL, AV_LOG_INFO, + "%f\n%f\n", + bmg_out[0] * stddev + mean, + bmg_out[1] * stddev + mean); + } + } + + return 0; +} +#endif diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.h new file mode 100644 index 000000000..ec90562cf --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/lfg.h @@ -0,0 +1,62 @@ +/* + * Lagged Fibonacci PRNG + * Copyright (c) 2008 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_LFG_H +#define AVUTIL_LFG_H + +typedef struct AVLFG { + unsigned int state[64]; + int index; +} AVLFG; + +void av_lfg_init(AVLFG *c, unsigned int seed); + +/** + * Get the next random unsigned 32-bit number using an ALFG. + * + * Please also consider a simple LCG like state= state*1664525+1013904223, + * it may be good enough and faster for your specific use case. + */ +static inline unsigned int av_lfg_get(AVLFG *c){ + c->state[c->index & 63] = c->state[(c->index-24) & 63] + c->state[(c->index-55) & 63]; + return c->state[c->index++ & 63]; +} + +/** + * Get the next random unsigned 32-bit number using a MLFG. + * + * Please also consider av_lfg_get() above, it is faster. + */ +static inline unsigned int av_mlfg_get(AVLFG *c){ + unsigned int a= c->state[(c->index-55) & 63]; + unsigned int b= c->state[(c->index-24) & 63]; + return c->state[c->index++ & 63] = 2*a*b+a+b; +} + +/** + * Get the next two numbers generated by a Box-Muller Gaussian + * generator using the random numbers issued by lfg. + * + * @param out array where the two generated numbers are placed + */ +void av_bmg_get(AVLFG *lfg, double out[2]); + +#endif /* AVUTIL_LFG_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.c new file mode 100644 index 000000000..683d2c892 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.c @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at) + * Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org) + * + * References: + * IETF RFC 1321: The MD5 Message-Digest Algorithm + * Ron Rivest. IETF, April, 1992 + * + * based on http://ubiqx.org/libcifs/source/Auth/MD5.c + * from Christopher R. Hertel (crh@ubiqx.mn.org) + * Simplified, cleaned and IMO redundant comments removed by michael. + * + * If you use gcc, then version 4.1 or later and -fomit-frame-pointer is + * strongly recommended. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include "config.h" +#include "bswap.h" +#include "intreadwrite.h" +#include "md5.h" +#include "mem.h" + +typedef struct AVMD5{ + uint64_t len; + uint8_t block[64]; + uint32_t ABCD[4]; +} AVMD5; + +const int av_md5_size = sizeof(AVMD5); + +struct AVMD5 *av_md5_alloc(void) +{ + return av_mallocz(sizeof(struct AVMD5)); +} + +static const uint8_t S[4][4] = { + { 7, 12, 17, 22 }, /* round 1 */ + { 5, 9, 14, 20 }, /* round 2 */ + { 4, 11, 16, 23 }, /* round 3 */ + { 6, 10, 15, 21 } /* round 4 */ +}; + +static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32) + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, /* round 1 */ + 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, + 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, + + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* round 2 */ + 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, + 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, + + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* round 3 */ + 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, + 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, + + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* round 4 */ + 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, +}; + +#define CORE(i, a, b, c, d) do { \ + t = S[i >> 4][i & 3]; \ + a += T[i]; \ + \ + if (i < 32) { \ + if (i < 16) a += (d ^ (b & (c ^ d))) + X[ i & 15]; \ + else a += ((d & b) | (~d & c)) + X[(1 + 5*i) & 15]; \ + } else { \ + if (i < 48) a += (b ^ c ^ d) + X[(5 + 3*i) & 15]; \ + else a += (c ^ (b | ~d)) + X[( 7*i) & 15]; \ + } \ + a = b + (a << t | a >> (32 - t)); \ + } while (0) + +static void body(uint32_t ABCD[4], uint32_t *src, int nblocks) +{ + int i av_unused; + int n; + uint32_t a, b, c, d, t, *X; + + for (n = 0; n < nblocks; n++) { + a = ABCD[3]; + b = ABCD[2]; + c = ABCD[1]; + d = ABCD[0]; + + X = src + n * 16; + +#if HAVE_BIGENDIAN + for (i = 0; i < 16; i++) + X[i] = av_bswap32(X[i]); +#endif + +#if CONFIG_SMALL + for (i = 0; i < 64; i++) { + CORE(i, a, b, c, d); + t = d; + d = c; + c = b; + b = a; + a = t; + } +#else +#define CORE2(i) \ + CORE( i, a,b,c,d); CORE((i+1),d,a,b,c); \ + CORE((i+2),c,d,a,b); CORE((i+3),b,c,d,a) +#define CORE4(i) CORE2(i); CORE2((i+4)); CORE2((i+8)); CORE2((i+12)) + CORE4(0); CORE4(16); CORE4(32); CORE4(48); +#endif + + ABCD[0] += d; + ABCD[1] += c; + ABCD[2] += b; + ABCD[3] += a; + } +} + +void av_md5_init(AVMD5 *ctx) +{ + ctx->len = 0; + + ctx->ABCD[0] = 0x10325476; + ctx->ABCD[1] = 0x98badcfe; + ctx->ABCD[2] = 0xefcdab89; + ctx->ABCD[3] = 0x67452301; +} + +void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len) +{ + const uint8_t *end; + int j; + + j = ctx->len & 63; + ctx->len += len; + + if (j) { + int cnt = FFMIN(len, 64 - j); + memcpy(ctx->block + j, src, cnt); + src += cnt; + len -= cnt; + if (j + cnt < 64) + return; + body(ctx->ABCD, (uint32_t *)ctx->block, 1); + } + + end = src + (len & ~63); + if (HAVE_BIGENDIAN || (!HAVE_FAST_UNALIGNED && ((intptr_t)src & 3))) { + while (src < end) { + memcpy(ctx->block, src, 64); + body(ctx->ABCD, (uint32_t *) ctx->block, 1); + src += 64; + } + } else { + int nblocks = len / 64; + body(ctx->ABCD, (uint32_t *)src, nblocks); + src = end; + } + len &= 63; + if (len > 0) + memcpy(ctx->block, src, len); +} + +void av_md5_final(AVMD5 *ctx, uint8_t *dst) +{ + int i; + uint64_t finalcount = av_le2ne64(ctx->len << 3); + + av_md5_update(ctx, (const unsigned char *) "\200", 1); + while ((ctx->len & 63) != 56) + av_md5_update(ctx, (const unsigned char *) "", 1); + + av_md5_update(ctx, (uint8_t *)&finalcount, 8); + + for (i = 0; i < 4; i++) + AV_WL32(dst + 4*i, ctx->ABCD[3 - i]); +} + +void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len) +{ + AVMD5 ctx; + + av_md5_init(&ctx); + av_md5_update(&ctx, src, len); + av_md5_final(&ctx, dst); +} + +#ifdef TEST +#include + +static void print_md5(uint8_t *md5) +{ + int i; + for (i = 0; i < 16; i++) + printf("%02x", md5[i]); + printf("\n"); +} + +int main(void){ + uint8_t md5val[16]; + int i; + uint8_t in[1000]; + + for (i = 0; i < 1000; i++) + in[i] = i * i; + av_md5_sum(md5val, in, 1000); print_md5(md5val); + av_md5_sum(md5val, in, 63); print_md5(md5val); + av_md5_sum(md5val, in, 64); print_md5(md5val); + av_md5_sum(md5val, in, 65); print_md5(md5val); + for (i = 0; i < 1000; i++) + in[i] = i % 127; + av_md5_sum(md5val, in, 999); print_md5(md5val); + + return 0; +} +#endif diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.h new file mode 100644 index 000000000..79702c88c --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavutil/md5.h @@ -0,0 +1,81 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_MD5_H +#define AVUTIL_MD5_H + +#include + +#include "attributes.h" +#include "version.h" + +/** + * @defgroup lavu_md5 MD5 + * @ingroup lavu_crypto + * @{ + */ + +extern const int av_md5_size; + +struct AVMD5; + +/** + * Allocate an AVMD5 context. + */ +struct AVMD5 *av_md5_alloc(void); + +/** + * Initialize MD5 hashing. + * + * @param ctx pointer to the function context (of size av_md5_size) + */ +void av_md5_init(struct AVMD5 *ctx); + +/** + * Update hash value. + * + * @param ctx hash function context + * @param src input data to update hash with + * @param len input data length + */ +void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len); + +/** + * Finish hashing and output digest value. + * + * @param ctx hash function context + * @param dst buffer where output digest value is stored + */ +void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); + +/** + * Hash an array of data. + * + * @param dst The output buffer to write the digest into + * @param src The data to hash + * @param len The length of the data, in bytes + */ +void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len); + +/** + * @} + */ + +#endif /* AVUTIL_MD5_H */ diff --git a/Frameworks/TagLib/taglib/taglib/fileref.cpp b/Frameworks/TagLib/taglib/taglib/fileref.cpp index 8c95fcd30..e25161d57 100644 --- a/Frameworks/TagLib/taglib/taglib/fileref.cpp +++ b/Frameworks/TagLib/taglib/taglib/fileref.cpp @@ -139,6 +139,7 @@ StringList FileRef::defaultFileExtensions() l.append("ape"); l.append("opus"); l.append("tak"); + l.append("ac3"); l.append("apl"); return l; @@ -235,7 +236,7 @@ File *FileRef::create(FileName fileName, bool readAudioProperties, return new ASF::File(fileName, readAudioProperties, audioPropertiesStyle); if(ext == "APE") return new APE::File(fileName, readAudioProperties, audioPropertiesStyle); - if(ext == "TAK" || ext == "APL") + if(ext == "TAK" || ext == "AC3" || ext == "APL") return new APE::File(fileName, false, audioPropertiesStyle); } diff --git a/Plugins/FFMPEG/FFMPEGDecoder.m b/Plugins/FFMPEG/FFMPEGDecoder.m index 3942706c7..24a0e75a9 100644 --- a/Plugins/FFMPEG/FFMPEGDecoder.m +++ b/Plugins/FFMPEG/FFMPEGDecoder.m @@ -310,12 +310,12 @@ int lockmgr_callback(void ** mutex, enum AVLockOp op) + (NSArray *)fileTypes { - return [NSArray arrayWithObjects:@"wma", @"asf", @"xwma", @"tak", @"mp3", @"mp2", @"m2a", @"mpa", @"ape", nil]; + return [NSArray arrayWithObjects:@"wma", @"asf", @"xwma", @"tak", @"mp3", @"mp2", @"m2a", @"mpa", @"ape", @"ac3", nil]; } + (NSArray *)mimeTypes { - return [NSArray arrayWithObjects:@"application/wma", @"application/x-wma", @"audio/x-wma", @"audio/x-ms-wma", @"audio/x-tak", @"audio/mpeg", @"audio/x-mp3", @"audio/x-mp2", @"audio/x-ape", nil]; + return [NSArray arrayWithObjects:@"application/wma", @"application/x-wma", @"audio/x-wma", @"audio/x-ms-wma", @"audio/x-tak", @"audio/mpeg", @"audio/x-mp3", @"audio/x-mp2", @"audio/x-ape", @"audio/x-ac3", nil]; } diff --git a/Plugins/TagLib/TagLibMetadataReader.m b/Plugins/TagLib/TagLibMetadataReader.m index 4f01a8f6e..d522ab54e 100644 --- a/Plugins/TagLib/TagLibMetadataReader.m +++ b/Plugins/TagLib/TagLibMetadataReader.m @@ -130,12 +130,12 @@ + (NSArray *)fileTypes { //May be a way to get a list of supported formats - return [NSArray arrayWithObjects:@"ape", @"asf", @"wma", @"ogg", @"opus", @"mpc", @"flac", @"m4a", @"mp3", @"tak", @"apl", nil]; + return [NSArray arrayWithObjects:@"ape", @"asf", @"wma", @"ogg", @"opus", @"mpc", @"flac", @"m4a", @"mp3", @"tak", @"ac3", @"apl", nil]; } + (NSArray *)mimeTypes { - return [NSArray arrayWithObjects:@"audio/x-ape", @"audio/x-ms-wma", @"application/ogg", @"application/x-ogg", @"audio/x-vorbis+ogg", @"audio/x-musepack", @"audio/x-flac", @"audio/x-m4a", @"audio/mpeg", @"audio/x-mp3", @"audio/x-tak", @"audio/x-apl", nil]; + return [NSArray arrayWithObjects:@"audio/x-ape", @"audio/x-ms-wma", @"application/ogg", @"application/x-ogg", @"audio/x-vorbis+ogg", @"audio/x-musepack", @"audio/x-flac", @"audio/x-m4a", @"audio/mpeg", @"audio/x-mp3", @"audio/x-tak", @"audio/x-ac3", @"audio/x-apl", nil]; } @end