diff --git a/Libraries/DecMPA/DecMPA.xcodeproj/project.pbxproj b/Libraries/DecMPA/DecMPA.xcodeproj/project.pbxproj new file mode 100644 index 000000000..87b7f26f2 --- /dev/null +++ b/Libraries/DecMPA/DecMPA.xcodeproj/project.pbxproj @@ -0,0 +1,522 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 42; + objects = { + +/* Begin PBXBuildFile section */ + 8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; }; + 8EBDF1A409F28836004F2528 /* decmpa.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1A309F28836004F2528 /* decmpa.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 8EBDF1FB09F2884B004F2528 /* DecMPA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1A509F2884A004F2528 /* DecMPA.cpp */; }; + 8EBDF1FC09F2884B004F2528 /* DecMPAFileAccess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1A609F2884A004F2528 /* DecMPAFileAccess.cpp */; }; + 8EBDF1FD09F2884B004F2528 /* DecMPAFileAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1A709F2884A004F2528 /* DecMPAFileAccess.h */; }; + 8EBDF1FE09F2884B004F2528 /* DecodeEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1A809F2884A004F2528 /* DecodeEngine.h */; }; + 8EBDF1FF09F2884B004F2528 /* DefInc.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1A909F2884A004F2528 /* DefInc.h */; }; + 8EBDF20009F2884B004F2528 /* audioFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1AB09F2884A004F2528 /* audioFrame.cpp */; }; + 8EBDF20109F2884B004F2528 /* audioFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1AC09F2884A004F2528 /* audioFrame.h */; }; + 8EBDF20209F2884B004F2528 /* floatFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1AD09F2884A004F2528 /* floatFrame.cpp */; }; + 8EBDF20309F2884B004F2528 /* floatFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1AE09F2884A004F2528 /* floatFrame.h */; }; + 8EBDF20409F2884B004F2528 /* frame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1AF09F2884A004F2528 /* frame.cpp */; }; + 8EBDF20509F2884B004F2528 /* frame.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1B009F2884A004F2528 /* frame.h */; }; + 8EBDF20609F2884B004F2528 /* pcmFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1B109F2884A004F2528 /* pcmFrame.cpp */; }; + 8EBDF20709F2884B004F2528 /* pcmFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1B209F2884A004F2528 /* pcmFrame.h */; }; + 8EBDF20809F2884B004F2528 /* rawDataBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1B309F2884A004F2528 /* rawDataBuffer.cpp */; }; + 8EBDF20909F2884B004F2528 /* rawDataBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1B409F2884A004F2528 /* rawDataBuffer.h */; }; + 8EBDF20A09F2884B004F2528 /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1B609F2884A004F2528 /* common.c */; }; + 8EBDF20B09F2884B004F2528 /* common.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1B709F2884A004F2528 /* common.h */; }; + 8EBDF20C09F2884B004F2528 /* dct64_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1B809F2884A004F2528 /* dct64_i386.c */; }; + 8EBDF20D09F2884B004F2528 /* dct64_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1B909F2884A004F2528 /* dct64_i386.h */; }; + 8EBDF20E09F2884B004F2528 /* decode_i386.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1BA09F2884A004F2528 /* decode_i386.c */; }; + 8EBDF20F09F2884B004F2528 /* decode_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1BB09F2884A004F2528 /* decode_i386.h */; }; + 8EBDF21009F2884B004F2528 /* DecodeEngine_Hip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1BC09F2884A004F2528 /* DecodeEngine_Hip.cpp */; }; + 8EBDF21109F2884B004F2528 /* HIPDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1BD09F2884A004F2528 /* HIPDefines.h */; }; + 8EBDF21209F2884B004F2528 /* huffman.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1BE09F2884A004F2528 /* huffman.h */; }; + 8EBDF21309F2884B004F2528 /* interface.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1BF09F2884A004F2528 /* interface.c */; }; + 8EBDF21409F2884B004F2528 /* interface.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1C009F2884A004F2528 /* interface.h */; }; + 8EBDF21509F2884B004F2528 /* l2tables.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1C109F2884A004F2528 /* l2tables.h */; }; + 8EBDF21609F2884B004F2528 /* layer1.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1C209F2884A004F2528 /* layer1.c */; }; + 8EBDF21709F2884B004F2528 /* layer1.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1C309F2884A004F2528 /* layer1.h */; }; + 8EBDF21809F2884B004F2528 /* layer2.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1C409F2884A004F2528 /* layer2.c */; }; + 8EBDF21909F2884B004F2528 /* layer2.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1C509F2884A004F2528 /* layer2.h */; }; + 8EBDF21A09F2884B004F2528 /* layer3.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1C609F2884A004F2528 /* layer3.c */; }; + 8EBDF21B09F2884B004F2528 /* layer3.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1C709F2884A004F2528 /* layer3.h */; }; + 8EBDF21C09F2884B004F2528 /* mpg123.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1C809F2884A004F2528 /* mpg123.h */; }; + 8EBDF21D09F2884B004F2528 /* mpglib.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1C909F2884A004F2528 /* mpglib.h */; }; + 8EBDF21E09F2884B004F2528 /* tabinit.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1CA09F2884A004F2528 /* tabinit.c */; }; + 8EBDF21F09F2884B004F2528 /* tabinit.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1CB09F2884A004F2528 /* tabinit.h */; }; + 8EBDF22009F2884B004F2528 /* VbrTag.c in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1CC09F2884A004F2528 /* VbrTag.c */; }; + 8EBDF22109F2884B004F2528 /* VbrTag.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1CD09F2884A004F2528 /* VbrTag.h */; }; + 8EBDF22209F2884B004F2528 /* IFileAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1CE09F2884B004F2528 /* IFileAccess.h */; }; + 8EBDF22309F2884B004F2528 /* MemBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1CF09F2884B004F2528 /* MemBuffer.h */; }; + 8EBDF22409F2884B004F2528 /* MPADecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1D009F2884B004F2528 /* MPADecoder.cpp */; }; + 8EBDF22509F2884B004F2528 /* MPADecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1D109F2884B004F2528 /* MPADecoder.h */; }; + 8EBDF22609F2884B004F2528 /* MPAFrameFinder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1D209F2884B004F2528 /* MPAFrameFinder.cpp */; }; + 8EBDF22709F2884B004F2528 /* MPAFrameFinder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1D309F2884B004F2528 /* MPAFrameFinder.h */; }; + 8EBDF22809F2884B004F2528 /* MPAInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1D409F2884B004F2528 /* MPAInfo.cpp */; }; + 8EBDF22909F2884B004F2528 /* MPAInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1D509F2884B004F2528 /* MPAInfo.h */; }; + 8EBDF22A09F2884B004F2528 /* dxHead.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1D709F2884B004F2528 /* dxHead.cpp */; }; + 8EBDF22B09F2884B004F2528 /* dxHead.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1D809F2884B004F2528 /* dxHead.h */; }; + 8EBDF22C09F2884B004F2528 /* mpegAudioHeader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8EBDF1D909F2884B004F2528 /* mpegAudioHeader.cpp */; }; + 8EBDF22D09F2884B004F2528 /* mpegAudioHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 8EBDF1DA09F2884B004F2528 /* mpegAudioHeader.h */; }; +/* End PBXBuildFile section */ + +/* Begin PBXBuildStyle section */ + 014CEA440018CDF011CA2923 /* Debug */ = { + isa = PBXBuildStyle; + buildSettings = { + }; + name = Debug; + }; + 014CEA450018CDF011CA2923 /* Release */ = { + isa = PBXBuildStyle; + buildSettings = { + }; + name = Release; + }; +/* End PBXBuildStyle section */ + +/* Begin PBXFileReference section */ + 089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; + 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 8DC2EF5B0486A6940098B216 /* DecMPA.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DecMPA.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 8EBDF1A309F28836004F2528 /* decmpa.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = decmpa.h; path = Files/include/decmpa.h; sourceTree = ""; }; + 8EBDF1A509F2884A004F2528 /* DecMPA.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = DecMPA.cpp; path = Files/src/DecMPA.cpp; sourceTree = ""; }; + 8EBDF1A609F2884A004F2528 /* DecMPAFileAccess.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = DecMPAFileAccess.cpp; path = Files/src/DecMPAFileAccess.cpp; sourceTree = ""; }; + 8EBDF1A709F2884A004F2528 /* DecMPAFileAccess.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DecMPAFileAccess.h; path = Files/src/DecMPAFileAccess.h; sourceTree = ""; }; + 8EBDF1A809F2884A004F2528 /* DecodeEngine.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DecodeEngine.h; path = Files/src/DecodeEngine.h; sourceTree = ""; }; + 8EBDF1A909F2884A004F2528 /* DefInc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DefInc.h; path = Files/src/DefInc.h; sourceTree = ""; }; + 8EBDF1AB09F2884A004F2528 /* audioFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = audioFrame.cpp; sourceTree = ""; }; + 8EBDF1AC09F2884A004F2528 /* audioFrame.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = audioFrame.h; sourceTree = ""; }; + 8EBDF1AD09F2884A004F2528 /* floatFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = floatFrame.cpp; sourceTree = ""; }; + 8EBDF1AE09F2884A004F2528 /* floatFrame.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = floatFrame.h; sourceTree = ""; }; + 8EBDF1AF09F2884A004F2528 /* frame.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = frame.cpp; sourceTree = ""; }; + 8EBDF1B009F2884A004F2528 /* frame.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = frame.h; sourceTree = ""; }; + 8EBDF1B109F2884A004F2528 /* pcmFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = pcmFrame.cpp; sourceTree = ""; }; + 8EBDF1B209F2884A004F2528 /* pcmFrame.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = pcmFrame.h; sourceTree = ""; }; + 8EBDF1B309F2884A004F2528 /* rawDataBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = rawDataBuffer.cpp; sourceTree = ""; }; + 8EBDF1B409F2884A004F2528 /* rawDataBuffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = rawDataBuffer.h; sourceTree = ""; }; + 8EBDF1B609F2884A004F2528 /* common.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = common.c; sourceTree = ""; }; + 8EBDF1B709F2884A004F2528 /* common.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = ""; }; + 8EBDF1B809F2884A004F2528 /* dct64_i386.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = dct64_i386.c; sourceTree = ""; }; + 8EBDF1B909F2884A004F2528 /* dct64_i386.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = dct64_i386.h; sourceTree = ""; }; + 8EBDF1BA09F2884A004F2528 /* decode_i386.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = decode_i386.c; sourceTree = ""; }; + 8EBDF1BB09F2884A004F2528 /* decode_i386.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = decode_i386.h; sourceTree = ""; }; + 8EBDF1BC09F2884A004F2528 /* DecodeEngine_Hip.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DecodeEngine_Hip.cpp; sourceTree = ""; }; + 8EBDF1BD09F2884A004F2528 /* HIPDefines.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HIPDefines.h; sourceTree = ""; }; + 8EBDF1BE09F2884A004F2528 /* huffman.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = huffman.h; sourceTree = ""; }; + 8EBDF1BF09F2884A004F2528 /* interface.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = interface.c; sourceTree = ""; }; + 8EBDF1C009F2884A004F2528 /* interface.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = interface.h; sourceTree = ""; }; + 8EBDF1C109F2884A004F2528 /* l2tables.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = l2tables.h; sourceTree = ""; }; + 8EBDF1C209F2884A004F2528 /* layer1.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = layer1.c; sourceTree = ""; }; + 8EBDF1C309F2884A004F2528 /* layer1.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = layer1.h; sourceTree = ""; }; + 8EBDF1C409F2884A004F2528 /* layer2.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = layer2.c; sourceTree = ""; }; + 8EBDF1C509F2884A004F2528 /* layer2.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = layer2.h; sourceTree = ""; }; + 8EBDF1C609F2884A004F2528 /* layer3.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = layer3.c; sourceTree = ""; }; + 8EBDF1C709F2884A004F2528 /* layer3.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = layer3.h; sourceTree = ""; }; + 8EBDF1C809F2884A004F2528 /* mpg123.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = mpg123.h; sourceTree = ""; }; + 8EBDF1C909F2884A004F2528 /* mpglib.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = mpglib.h; sourceTree = ""; }; + 8EBDF1CA09F2884A004F2528 /* tabinit.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = tabinit.c; sourceTree = ""; }; + 8EBDF1CB09F2884A004F2528 /* tabinit.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = tabinit.h; sourceTree = ""; }; + 8EBDF1CC09F2884A004F2528 /* VbrTag.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = VbrTag.c; sourceTree = ""; }; + 8EBDF1CD09F2884A004F2528 /* VbrTag.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = VbrTag.h; sourceTree = ""; }; + 8EBDF1CE09F2884B004F2528 /* IFileAccess.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = IFileAccess.h; path = Files/src/IFileAccess.h; sourceTree = ""; }; + 8EBDF1CF09F2884B004F2528 /* MemBuffer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = MemBuffer.h; path = Files/src/MemBuffer.h; sourceTree = ""; }; + 8EBDF1D009F2884B004F2528 /* MPADecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = MPADecoder.cpp; path = Files/src/MPADecoder.cpp; sourceTree = ""; }; + 8EBDF1D109F2884B004F2528 /* MPADecoder.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = MPADecoder.h; path = Files/src/MPADecoder.h; sourceTree = ""; }; + 8EBDF1D209F2884B004F2528 /* MPAFrameFinder.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = MPAFrameFinder.cpp; path = Files/src/MPAFrameFinder.cpp; sourceTree = ""; }; + 8EBDF1D309F2884B004F2528 /* MPAFrameFinder.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = MPAFrameFinder.h; path = Files/src/MPAFrameFinder.h; sourceTree = ""; }; + 8EBDF1D409F2884B004F2528 /* MPAInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = MPAInfo.cpp; path = Files/src/MPAInfo.cpp; sourceTree = ""; }; + 8EBDF1D509F2884B004F2528 /* MPAInfo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = MPAInfo.h; path = Files/src/MPAInfo.h; sourceTree = ""; }; + 8EBDF1D709F2884B004F2528 /* dxHead.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = dxHead.cpp; sourceTree = ""; }; + 8EBDF1D809F2884B004F2528 /* dxHead.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = dxHead.h; sourceTree = ""; }; + 8EBDF1D909F2884B004F2528 /* mpegAudioHeader.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = mpegAudioHeader.cpp; sourceTree = ""; }; + 8EBDF1DA09F2884B004F2528 /* mpegAudioHeader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = mpegAudioHeader.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8DC2EF560486A6940098B216 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 034768DFFF38A50411DB9C8B /* Products */ = { + isa = PBXGroup; + children = ( + 8DC2EF5B0486A6940098B216 /* DecMPA.framework */, + ); + name = Products; + sourceTree = ""; + }; + 0867D691FE84028FC02AAC07 /* DecMPA */ = { + isa = PBXGroup; + children = ( + 8EBDF1A109F2881A004F2528 /* Headers */, + 8EBDF1A209F2881F004F2528 /* Source */, + 089C1665FE841158C02AAC07 /* Resources */, + 0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */, + 034768DFFF38A50411DB9C8B /* Products */, + ); + name = DecMPA; + sourceTree = ""; + }; + 0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */ = { + isa = PBXGroup; + children = ( + 1058C7B0FEA5585E11CA2CBB /* Linked Frameworks */, + 1058C7B2FEA5585E11CA2CBB /* Other Frameworks */, + ); + name = "External Frameworks and Libraries"; + sourceTree = ""; + }; + 089C1665FE841158C02AAC07 /* Resources */ = { + isa = PBXGroup; + children = ( + 8DC2EF5A0486A6940098B216 /* Info.plist */, + 089C1666FE841158C02AAC07 /* InfoPlist.strings */, + ); + name = Resources; + sourceTree = ""; + }; + 1058C7B0FEA5585E11CA2CBB /* Linked Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = "Linked Frameworks"; + sourceTree = ""; + }; + 1058C7B2FEA5585E11CA2CBB /* Other Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = "Other Frameworks"; + sourceTree = ""; + }; + 8EBDF1A109F2881A004F2528 /* Headers */ = { + isa = PBXGroup; + children = ( + 8EBDF1A309F28836004F2528 /* decmpa.h */, + ); + name = Headers; + sourceTree = ""; + }; + 8EBDF1A209F2881F004F2528 /* Source */ = { + isa = PBXGroup; + children = ( + 8EBDF1A509F2884A004F2528 /* DecMPA.cpp */, + 8EBDF1A609F2884A004F2528 /* DecMPAFileAccess.cpp */, + 8EBDF1A709F2884A004F2528 /* DecMPAFileAccess.h */, + 8EBDF1A809F2884A004F2528 /* DecodeEngine.h */, + 8EBDF1A909F2884A004F2528 /* DefInc.h */, + 8EBDF1AA09F2884A004F2528 /* frame */, + 8EBDF1B509F2884A004F2528 /* hip */, + 8EBDF1CE09F2884B004F2528 /* IFileAccess.h */, + 8EBDF1CF09F2884B004F2528 /* MemBuffer.h */, + 8EBDF1D009F2884B004F2528 /* MPADecoder.cpp */, + 8EBDF1D109F2884B004F2528 /* MPADecoder.h */, + 8EBDF1D209F2884B004F2528 /* MPAFrameFinder.cpp */, + 8EBDF1D309F2884B004F2528 /* MPAFrameFinder.h */, + 8EBDF1D409F2884B004F2528 /* MPAInfo.cpp */, + 8EBDF1D509F2884B004F2528 /* MPAInfo.h */, + 8EBDF1D609F2884B004F2528 /* mpegAudioFrame */, + ); + name = Source; + sourceTree = ""; + }; + 8EBDF1AA09F2884A004F2528 /* frame */ = { + isa = PBXGroup; + children = ( + 8EBDF1AB09F2884A004F2528 /* audioFrame.cpp */, + 8EBDF1AC09F2884A004F2528 /* audioFrame.h */, + 8EBDF1AD09F2884A004F2528 /* floatFrame.cpp */, + 8EBDF1AE09F2884A004F2528 /* floatFrame.h */, + 8EBDF1AF09F2884A004F2528 /* frame.cpp */, + 8EBDF1B009F2884A004F2528 /* frame.h */, + 8EBDF1B109F2884A004F2528 /* pcmFrame.cpp */, + 8EBDF1B209F2884A004F2528 /* pcmFrame.h */, + 8EBDF1B309F2884A004F2528 /* rawDataBuffer.cpp */, + 8EBDF1B409F2884A004F2528 /* rawDataBuffer.h */, + ); + name = frame; + path = Files/src/frame; + sourceTree = ""; + }; + 8EBDF1B509F2884A004F2528 /* hip */ = { + isa = PBXGroup; + children = ( + 8EBDF1B609F2884A004F2528 /* common.c */, + 8EBDF1B709F2884A004F2528 /* common.h */, + 8EBDF1B809F2884A004F2528 /* dct64_i386.c */, + 8EBDF1B909F2884A004F2528 /* dct64_i386.h */, + 8EBDF1BA09F2884A004F2528 /* decode_i386.c */, + 8EBDF1BB09F2884A004F2528 /* decode_i386.h */, + 8EBDF1BC09F2884A004F2528 /* DecodeEngine_Hip.cpp */, + 8EBDF1BD09F2884A004F2528 /* HIPDefines.h */, + 8EBDF1BE09F2884A004F2528 /* huffman.h */, + 8EBDF1BF09F2884A004F2528 /* interface.c */, + 8EBDF1C009F2884A004F2528 /* interface.h */, + 8EBDF1C109F2884A004F2528 /* l2tables.h */, + 8EBDF1C209F2884A004F2528 /* layer1.c */, + 8EBDF1C309F2884A004F2528 /* layer1.h */, + 8EBDF1C409F2884A004F2528 /* layer2.c */, + 8EBDF1C509F2884A004F2528 /* layer2.h */, + 8EBDF1C609F2884A004F2528 /* layer3.c */, + 8EBDF1C709F2884A004F2528 /* layer3.h */, + 8EBDF1C809F2884A004F2528 /* mpg123.h */, + 8EBDF1C909F2884A004F2528 /* mpglib.h */, + 8EBDF1CA09F2884A004F2528 /* tabinit.c */, + 8EBDF1CB09F2884A004F2528 /* tabinit.h */, + 8EBDF1CC09F2884A004F2528 /* VbrTag.c */, + 8EBDF1CD09F2884A004F2528 /* VbrTag.h */, + ); + name = hip; + path = Files/src/hip; + sourceTree = ""; + }; + 8EBDF1D609F2884B004F2528 /* mpegAudioFrame */ = { + isa = PBXGroup; + children = ( + 8EBDF1D709F2884B004F2528 /* dxHead.cpp */, + 8EBDF1D809F2884B004F2528 /* dxHead.h */, + 8EBDF1D909F2884B004F2528 /* mpegAudioHeader.cpp */, + 8EBDF1DA09F2884B004F2528 /* mpegAudioHeader.h */, + ); + name = mpegAudioFrame; + path = Files/src/mpegAudioFrame; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 8DC2EF500486A6940098B216 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 8EBDF1A409F28836004F2528 /* decmpa.h in Headers */, + 8EBDF1FD09F2884B004F2528 /* DecMPAFileAccess.h in Headers */, + 8EBDF1FE09F2884B004F2528 /* DecodeEngine.h in Headers */, + 8EBDF1FF09F2884B004F2528 /* DefInc.h in Headers */, + 8EBDF20109F2884B004F2528 /* audioFrame.h in Headers */, + 8EBDF20309F2884B004F2528 /* floatFrame.h in Headers */, + 8EBDF20509F2884B004F2528 /* frame.h in Headers */, + 8EBDF20709F2884B004F2528 /* pcmFrame.h in Headers */, + 8EBDF20909F2884B004F2528 /* rawDataBuffer.h in Headers */, + 8EBDF20B09F2884B004F2528 /* common.h in Headers */, + 8EBDF20D09F2884B004F2528 /* dct64_i386.h in Headers */, + 8EBDF20F09F2884B004F2528 /* decode_i386.h in Headers */, + 8EBDF21109F2884B004F2528 /* HIPDefines.h in Headers */, + 8EBDF21209F2884B004F2528 /* huffman.h in Headers */, + 8EBDF21409F2884B004F2528 /* interface.h in Headers */, + 8EBDF21509F2884B004F2528 /* l2tables.h in Headers */, + 8EBDF21709F2884B004F2528 /* layer1.h in Headers */, + 8EBDF21909F2884B004F2528 /* layer2.h in Headers */, + 8EBDF21B09F2884B004F2528 /* layer3.h in Headers */, + 8EBDF21C09F2884B004F2528 /* mpg123.h in Headers */, + 8EBDF21D09F2884B004F2528 /* mpglib.h in Headers */, + 8EBDF21F09F2884B004F2528 /* tabinit.h in Headers */, + 8EBDF22109F2884B004F2528 /* VbrTag.h in Headers */, + 8EBDF22209F2884B004F2528 /* IFileAccess.h in Headers */, + 8EBDF22309F2884B004F2528 /* MemBuffer.h in Headers */, + 8EBDF22509F2884B004F2528 /* MPADecoder.h in Headers */, + 8EBDF22709F2884B004F2528 /* MPAFrameFinder.h in Headers */, + 8EBDF22909F2884B004F2528 /* MPAInfo.h in Headers */, + 8EBDF22B09F2884B004F2528 /* dxHead.h in Headers */, + 8EBDF22D09F2884B004F2528 /* mpegAudioHeader.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 8DC2EF4F0486A6940098B216 /* DecMPA */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "DecMPA" */; + buildPhases = ( + 8DC2EF500486A6940098B216 /* Headers */, + 8DC2EF520486A6940098B216 /* Resources */, + 8DC2EF540486A6940098B216 /* Sources */, + 8DC2EF560486A6940098B216 /* Frameworks */, + ); + buildRules = ( + ); + buildSettings = { + }; + dependencies = ( + ); + name = DecMPA; + productInstallPath = "$(HOME)/Library/Frameworks"; + productName = DecMPA; + productReference = 8DC2EF5B0486A6940098B216 /* DecMPA.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 0867D690FE84028FC02AAC07 /* Project object */ = { + isa = PBXProject; + buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "DecMPA" */; + buildSettings = { + }; + buildStyles = ( + 014CEA440018CDF011CA2923 /* Debug */, + 014CEA450018CDF011CA2923 /* Release */, + ); + hasScannedForEncodings = 1; + mainGroup = 0867D691FE84028FC02AAC07 /* DecMPA */; + productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; + projectDirPath = ""; + targets = ( + 8DC2EF4F0486A6940098B216 /* DecMPA */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8DC2EF520486A6940098B216 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8DC2EF540486A6940098B216 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8EBDF1FB09F2884B004F2528 /* DecMPA.cpp in Sources */, + 8EBDF1FC09F2884B004F2528 /* DecMPAFileAccess.cpp in Sources */, + 8EBDF20009F2884B004F2528 /* audioFrame.cpp in Sources */, + 8EBDF20209F2884B004F2528 /* floatFrame.cpp in Sources */, + 8EBDF20409F2884B004F2528 /* frame.cpp in Sources */, + 8EBDF20609F2884B004F2528 /* pcmFrame.cpp in Sources */, + 8EBDF20809F2884B004F2528 /* rawDataBuffer.cpp in Sources */, + 8EBDF20A09F2884B004F2528 /* common.c in Sources */, + 8EBDF20C09F2884B004F2528 /* dct64_i386.c in Sources */, + 8EBDF20E09F2884B004F2528 /* decode_i386.c in Sources */, + 8EBDF21009F2884B004F2528 /* DecodeEngine_Hip.cpp in Sources */, + 8EBDF21309F2884B004F2528 /* interface.c in Sources */, + 8EBDF21609F2884B004F2528 /* layer1.c in Sources */, + 8EBDF21809F2884B004F2528 /* layer2.c in Sources */, + 8EBDF21A09F2884B004F2528 /* layer3.c in Sources */, + 8EBDF21E09F2884B004F2528 /* tabinit.c in Sources */, + 8EBDF22009F2884B004F2528 /* VbrTag.c in Sources */, + 8EBDF22409F2884B004F2528 /* MPADecoder.cpp in Sources */, + 8EBDF22609F2884B004F2528 /* MPAFrameFinder.cpp in Sources */, + 8EBDF22809F2884B004F2528 /* MPAInfo.cpp in Sources */, + 8EBDF22A09F2884B004F2528 /* dxHead.cpp in Sources */, + 8EBDF22C09F2884B004F2528 /* mpegAudioHeader.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 089C1666FE841158C02AAC07 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 089C1667FE841158C02AAC07 /* English */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 1DEB91AE08733DA50010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = NO; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + FRAMEWORK_VERSION = A; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(HOME)/Library/Frameworks"; + PRODUCT_NAME = DecMPA; + WRAPPER_EXTENSION = framework; + ZERO_LINK = YES; + }; + name = Debug; + }; + 1DEB91AF08733DA50010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + ppc, + i386, + ); + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + FRAMEWORK_VERSION = A; + GCC_GENERATE_DEBUGGING_SYMBOLS = NO; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_PREFIX_HEADER = ""; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "@executable_path/../Frameworks"; + PRODUCT_NAME = DecMPA; + WRAPPER_EXTENSION = framework; + }; + name = Release; + }; + 1DEB91B208733DA50010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + PREBINDING = NO; + SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk; + }; + name = Debug; + }; + 1DEB91B308733DA50010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + PREBINDING = NO; + SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "DecMPA" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB91AE08733DA50010E9CD /* Debug */, + 1DEB91AF08733DA50010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "DecMPA" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB91B208733DA50010E9CD /* Debug */, + 1DEB91B308733DA50010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 0867D690FE84028FC02AAC07 /* Project object */; +} diff --git a/Libraries/DecMPA/English.lproj/InfoPlist.strings b/Libraries/DecMPA/English.lproj/InfoPlist.strings new file mode 100644 index 000000000..7080cf949 Binary files /dev/null and b/Libraries/DecMPA/English.lproj/InfoPlist.strings differ diff --git a/Libraries/DecMPA/Files/ChangeLog.txt b/Libraries/DecMPA/Files/ChangeLog.txt new file mode 100644 index 000000000..d231e1ea7 --- /dev/null +++ b/Libraries/DecMPA/Files/ChangeLog.txt @@ -0,0 +1,125 @@ +0.4.1 + +- improved detection of invalid frames and, therefore, of non-MPEG Audio files + +- worked through HIP code: + - removed printfs and exits + - activated layer 1 and 2 support + - changed some interface things to work better with DecMPA + +0.4.0 + +- reorganized API in a way that should allow it to remain downward + compatible in future releases + +- the decoder parameters are no longer passed directly to DecMPA_Create + but are now set using a new function, DecMPA_SetParam. + +- added API version checking to ensure that the DLL is compatible + +- added a new function DecMPA_DecodeNoData to the API. It can be used + to perform a quick scan through a file without actually decoding + any audio data + +- added an ease-of-use function (DecMPA_CreateForFile) for creating a + decoder object that reads its input data from a file + +- ID3v2 data can now be returned + +- more code clean-up + +- revamped seek code - seeks are now performed instantly when the + Seek function is called, instead of at the next decode + +- more accurate calculation of seek position for VBR streams + +- better calculation of decode-time + +- improved duration estimation + +- corrected some issues on big endian systems + +- fixed a few other bugs + + +0.3.0 + +- integrated new decoding routines (from Lame/HIP) in addition to the "old" + SPlay decoding + +- added a mechanism to choose between HIP and SPlay decoding routines at + compile time + +- wrote a new frame finder that adds quite a bit of robustness and also + allows DecMPA to detect if the data is not mpeg audio. The new finder + also greatly reduces the risk to detect frames wrong after seeking. + +- threw out more old unnecessary Mpeglib stuff and rewrote/simplified some + other parts. + + +0.2.2 + +- disabled "downsampling" again - it only reduced the frequency by half instead + of synthesizing with twice the frequency and THEN reducing it by half. + Thus the quality was definitely NOT improved. + +0.2.1 + +- added workaround for Visual C++ compiler bug that caused occasional + artifacts when decoding some MP3s + + +0.2 + +- MP3 synthesis is now performed with downsampling, resulting in improved + quality + +- leading ID3v2 tags are now automatically skipped over, fixing some + problems with corrupted tags that contain unescaped "sync" values. + This also improves length detection for files with big ID3 tags. + +- removed some more old MPEGLib code that is unnecessary for pure audio + decoding + + + +0.1.8 + +- added an example application "decodefile" + +- added makefile and project file for new example to the "build" directory + +- cleaned the code up a bit, removed some unnecessary includes + +- the source files in the tar.gz archive now have UNIX-style linebreaks. + this fixes some issues with compilers that weren't able to cope with the + Windows-style linebreaks + +- changed some code in the build-tools for potability. + +- added makefiles for Digital Unix and Cygwin GCC + + +0.1.5 + +- added ability to create documentation with makefiles + +- added readme files about makefile usage + +- changed the interface of DecMPA_Create - it now accepts a POINTER to + DecMPA_Callbacks rather than an object. + +- fixed some portability issues + +- fixed a nasty bug in decmpa.h: DecMPA_Create did not have the DECMPA_CC + calling convention (resulting in possible loss of binary interoperability + with dlls created by different compilers) + +- fixed gcc commandline when creating a DLL - the DLL is now relocatable + and binary compatible with the VC6 generated DLL + + +0.1 + +- initial release diff --git a/Libraries/DecMPA/Files/License.txt b/Libraries/DecMPA/Files/License.txt new file mode 100644 index 000000000..1af9fba69 --- /dev/null +++ b/Libraries/DecMPA/Files/License.txt @@ -0,0 +1,459 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/Libraries/DecMPA/Files/Readme.txt b/Libraries/DecMPA/Files/Readme.txt new file mode 100644 index 000000000..3c24e030a --- /dev/null +++ b/Libraries/DecMPA/Files/Readme.txt @@ -0,0 +1,131 @@ +*** DecMPA v0.4.1 - Simple MPEG Audio Decoder *** + +DecMPA is a small library for decoding MPEG Audio (layer 1,2 and 3). You may +use it under the terms of the GNU Lesser General Public License +(see License.txt). + +DecMPA uses some parts of project MPEGLib v0.4.1 by Martin Vogt +(see http://mpeglib.sourceforge.net/) which itself uses modified SPlay +decoding routines (see http://splay.sourceforge.net). +DecMPA v0.3.0 and higher also uses code from Lame's HIP decoding +engine (see http://lame.sourceforge.net/). + +Essentially DecMPA is a mixture of "raw" decoding routines from other projects +(with a few bug fixes and extensions), with a new interface coded on top of +it. The goal is to provide a powerful MPEG Audio decoding library that can +be easily integrated into applications. + +The project homepage can be found at +http://decmpa.sourceforge.net + + +************************************************************ +** IMPORTANT NOTE for users of versions older than v0.4.0 ** +************************************************************ + +In version 0.4.0 the API has changed a little, in particular the parameters +you pass to the DecMPA_CreateXXX functions. The output type is not passed +directly to Create anymore, but can now be set using DecMPA_SetParam. + +Also note that the structure DecMPA_Callbacks now contains an additional +pointer to a "GetPosition" function that HAS to be provided. Be sure to +initialize it! + +Please read the documentation for additional information. + +These changes allow a greater flexibility when adding new features and will +hopefully enable future releases to be fully downward compatible to earlier +versions. + + +** Documentation + +Documentation is available in the subdirectory 'doc'. + + +** Compiling + +If you want to compile DecMPA yourself, project files and make files for +some target systems and compilers are located in build/SYSTEM, where +SYSTEM is: + +vc6: Windows, Visual C++ 6.0 +gcc-mingw32: Windows, GCC Mingw32 +gcc-cygwin: Windows, GCC Cygwin +gcc-linux: Linux, GCC +gcc-digux: Digital Unix, GCC + +For gcc systems, just open a shell/command prompt, got to the appropriate +build/SYSTEM directory and run "make" (or possibly "gmake" if the default +make for your system is not GNU make). + +DecMPA can use two different decoding engines: HIP and SPlay. HIP is the +default, but if you want to use SPlay instead you can pass "ENGINE=splay" +as a parameter to you call to make. + +More information about the make files can be found in build/MakeGoals.txt + +Generated libraries, shared objects and import libraries are placed in +lib/SYSTEM. +Generated DLLs and example executables are placed in bin/SYSTEM. + + +** Usage + +Include include/decmpa.h in your code files and link with the +appropriate library or import library for your target system from lib/SYSTEM. + +All library files except those for Windows/Visual C++ have to be compiled +first (see Compiling). + +Note that the LGPL might require you to use the dll/shared object instead +of the static library if your application is not released under the GPL +(see License.txt). + + +** Examples + +Example applications are located in the "examples" subdirectory. +The makefiles and project files for the examples are found exactly where +the library make files are (see "Compiling"). + +For GNU make files, the example make files are integrated into the +normal make files. They can be executed by calling GNU Make with the goal +"example_NAME" where NAME is the directory name of the example. For example +"make example_decodefile" builds the decodefile example application. +More information about the make files can be found in build/MakeGoals.txt + + +** Portability + +DecMPA has been compiled under a few systems, including Windows and Linux +(see "Compiling"). It will probably compile well on other UNIXes with the +Linux or Digital Unix makefiles, but that has not been tested yet. + +If you successfully compiled DecMPA on other systems, I would appreciate if +you could drop me a note (and maybe contribute your makefiles or project files +- see below). + + + +** Suggestions, fixes, extensions, feedback + +If you have any suggestions, small extension or bug fixes that you would like to +be incorporated into this library, send them to hazard_hd@users.sourceforge.net + +If you send me any of your code, you must agree that it will be released under +LGPL. + +If you want to continuously help with the development, please send a short resume +describing your qualifications and experience to hazard_hd@users.sourceforge.net. +If I think you will "fit in" I'll add you to the developer list, thus allowing +you direct access to the project CVS. + +I would also like to hear from you if you find this library useful and decide +to use it in one of your projects. + + + +Copyright 2002 Hauke Duden +hazard_hd@users.sourceforge.net + diff --git a/Libraries/DecMPA/Files/Todo.txt b/Libraries/DecMPA/Files/Todo.txt new file mode 100644 index 000000000..4f337eb6f --- /dev/null +++ b/Libraries/DecMPA/Files/Todo.txt @@ -0,0 +1,3 @@ +- Test on other operating systems + +- clean the code up a little more diff --git a/Libraries/DecMPA/Files/include/decmpa.h b/Libraries/DecMPA/Files/include/decmpa.h new file mode 100644 index 000000000..7b594b147 --- /dev/null +++ b/Libraries/DecMPA/Files/include/decmpa.h @@ -0,0 +1,556 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + +#ifndef _DECMPA_H_ +#define _DECMPA_H_ + + +/**\file +Specifies the DecMPA API.*/ + + +#ifndef DECMPA_VERSION + + /**DecMPA API version number.*/ + #define DECMPA_VERSION 1 + +#endif + +#if defined(_WINDOWS) || defined(_WIN32) + + #ifndef CALLBACK + #include + #endif + #define DECMPA_CC CALLBACK + +#else + + #define DECMPA_CC + +#endif + +/**\def DECMPA_CC +Macro for the calling convention used by DecMPA functions.*/ + + +/**\defgroup GroupFunctions Functions*/ + +/**\defgroup GroupResults Result Codes +Description of the result codes that are returned by most DecMPA functions. + +Codes of the form DECMPA_ERROR_*** represent errors and are all negative. +The other result codes, all >=0, indicate different degrees of success.*/ + +/**\defgroup GroupParamIDs Configuations Parameters +Description of the possible parameters that can be defined using +#DecMPA_SetParam. +*/ + +/**\defgroup GroupParamValues Configuration Parameter Values +Description of the value constants that can be assigned to some configuration +parameters.*/ + +/**\defgroup GroupStructs Structures*/ + + +/**\addtogroup GroupStructs*/ +/*@{*/ + +/**This structure contains pointers to the functions that are used +to read the MP3 data during DecMPA_Decode.*/ +typedef struct +{ + /**Pointer to the function that is used to read data. If this pointer + is NULL, DecMPA will read from stdin and ignore the other callback + functions. + + @param pContext context pointer that was passed to + #DecMPA_CreateUsingCallbacks + @param pBuffer buffer that the data should be stored into + @param nBytes number of bytes to read + @return the number of bytes read or -1 if an error occurred. If + the returned value is less than nBytes it is assumed that the end + of the data stream was reached. + + \note the function that the pointer points to should have the calling + convention DECMPA_CC, i.e. it should be defined as: + \code + long DECMPA_CC MyReadFuncName(void* pContext,void* pBuffer,long nBytes); + \endcode*/ + long (DECMPA_CC* Read)(void* pContext,void* pBuffer,long nBytes); + + + + /**Pointer to function that seeks to the specified data stream position. + This function pointer should be set to NULL if seeking is not supported. + + @param pContext context pointer that was passed to + #DecMPA_CreateUsingCallbacks + @param DestPos destination position, in bytes. + @return nonzero if successful, 0 otherwise. + + \note the function that the pointer points to should have the calling + convention DECMPA_CC, i.e. it should be defined as: + \code + int DECMPA_CC MySeekFuncName(void* pContext,long DestPos); + \endcode*/ + int (DECMPA_CC* Seek)(void* pContext,long DestPos); + + + + /**Pointer to a function that returns the length of the data stream. + This function pointer can be set to NULL if the length cannot be + determined. Alternatively the function can return -1, + + @param pContext context pointer that was passed to + #DecMPA_CreateUsingCallbacks + @return the length, in bytes. -1 if unknown. + + \note the function that the pointer points to should have the calling + convention DECMPA_CC, i.e. it should be defined as: + \code + long DECMPA_CC MyGetLengthFuncName(void* pContext); + \endcode*/ + long (DECMPA_CC* GetLength)(void* pContext); + + + + /**Pointer to a function that returns the current position in the data + stream. This function pointer can only be NULL if Read is also NULL. + + @param pContext context pointer that was passed to + #DecMPA_CreateUsingCallbacks + @return the current position, in bytes or -1 if an error occurred. + + \note the function that the pointer points to should have the calling + convention DECMPA_CC, i.e. it should be defined as: + \code + long DECMPA_CC MyGetPositionFuncName(void* pContext); + \endcode*/ + long (DECMPA_CC* GetPosition)(void* pContext); + +} DecMPA_Callbacks; + + + +/**This structure provides information extracted from an MPEG Audio header.*/ +typedef struct +{ + /**The original header data.*/ + unsigned char aRawData[4]; + + /**Protection*/ + int bProtection; + /**Layer*/ + int nLayer; + /**Version*/ + int nVersion; + /**Padding*/ + int bPadding; + /**Frequency index*/ + int nFrequencyIndex; + /**Frequency in Hz*/ + int nFrequency; + /**Bitrate index*/ + int nBitRateIndex; + /**Extended mode*/ + int nExtendedMode; + /**Mode*/ + int nMode; + /**Input stereo*/ + int bInputStereo; + /**MPEG 2.5*/ + int bMPEG25; + + /**Frame size in bytes*/ + int nFrameSize; + /**Number of decoded samples per frame. If the data is stereo, a sample + consists of one value for the left channel and one for the right.*/ + int nDecodedSamplesPerFrame; + /**Bitrate in Kbps.*/ + int nBitRateKbps; + +} DecMPA_MPEGHeader; + + +/**DecMPA_OutputFormat objects are used to specify the format of the decoded +audio data that is returned by DecMPA_Decode.*/ +typedef struct +{ + /**Specifies the type of the data. Can be either DECMPA_OUTPUT_INT16 or + DECMPA_OUTPUT_FLOAT*/ + int nType; + + /**Specifies the frequency of the data.*/ + int nFrequency; + + /**Specifies the number of channels. Can be 1 for mono or 2 for stereo.*/ + int nChannels; + +} DecMPA_OutputFormat; + +/*@}*/ + + +/**\addtogroup GroupResults*/ +/*@{*/ + +/**The operation has been successfully completed.*/ +#define DECMPA_OK 0 + +/**The end of the stream was reached and there is no more data to decode.*/ +#define DECMPA_END 1 + +/**An invalid parameter was passed to a function.*/ +#define DECMPA_ERROR_PARAM (-1) + +/**The operation is not supported.*/ +#define DECMPA_ERROR_UNSUPPORTED (-2) + +/**There is not enough free memory.*/ +#define DECMPA_ERROR_MEMORY (-3) + +/**An internal error occurred in the decoding routines.*/ +#define DECMPA_ERROR_INTERNAL (-4) + +/**Indicates an error during decoding, which usually means that the input data +is invalid or corrupted.*/ +#define DECMPA_ERROR_DECODE (-5) + +/**An error occurred during the reading of new data.*/ +#define DECMPA_ERROR_READ (-6) + +/**An error occurred when it was tried to seek to a different position in +the data stream.*/ +#define DECMPA_ERROR_SEEK (-7) + +/**An error occurred when opening a file.*/ +#define DECMPA_ERROR_OPENFILE (-8) + +/**The decoder is in the wrong state to perform the specified +function.*/ +#define DECMPA_ERROR_WRONGSTATE (-9) + +/**The requested resource is not available*/ +#define DECMPA_ERROR_NOTAVAILABLE (-10) + +/**The version of the DecMPA library that is used is incompatible:*/ +#define DECMPA_ERROR_INCOMPATIBLEVERSION (-11) + + +/*@}*/ + + + + +/**\addtogroup GroupParamIDs*/ +/*@{*/ + +/**Specifies the format DecMPA will use to output the decoded audio samples. +Can be either #DECMPA_OUTPUT_INT16 or #DECMPA_OUTPUT_FLOAT. + +Default value: #DECMPA_OUTPUT_INT16.*/ +#define DECMPA_PARAM_OUTPUT 0 + +/**Specifies wether the decoder should load a leading ID3v2 tag and +make it available through #DecMPA_GetID3v2Data. Can be either +#DECMPA_YES or #DECMPA_NO. + +Default value: #DECMPA_NO.*/ +#define DECMPA_PARAM_PROVIDEID3V2 1 + +/*@}*/ + +/**Constant indicating the number of definable parameters.*/ +#define DECMPA_PARAMCOUNT 2 + + + +/**\addtogroup GroupParamValues*/ +/*@{*/ + +/**\defgroup GroupParamGeneric Generic values*/ +/*@{*/ + +/**Indicates that the specified function is activated.*/ +#define DECMPA_YES 1 + +/**Indicates that the specified function is not activated.*/ +#define DECMPA_NO 0 + +/*@}*/ + +/**\defgroup GroupParamOutput DECMPA_PARAM_OUTPUT values*/ +/*@{*/ + +/**Indicates that the audio samples are signed 16 bit integers (one per +channel). -32768 is the minimum and 32767 is the maximum value. + +\note As of version 0.3.0 DecMPA uses integers internally. That means that +#DECMPA_OUTPUT_INT16 is a little faster than #DECMPA_OUTPUT_FLOAT because the +latter requires an additional conversion.*/ +#define DECMPA_OUTPUT_INT16 0 + +/**Indicates that the audio samples are floats (one per channel). +-1.0 is the minimum and 1.0 is the maximum value. + +\note As of version 0.3.0 DecMPA uses integers internally. That means that +#DECMPA_OUTPUT_INT16 is a little faster than #DECMPA_OUTPUT_FLOAT because the +latter requires an additional conversion.*/ +#define DECMPA_OUTPUT_FLOAT 1 + +/*@}*/ + +/*@}*/ + + + + +/**\addtogroup GroupFunctions*/ +/*@{*/ + + +/**Creates a new decoder that obtains its input data from a file. + +If you want to provide the input data in some other customized way, use +#DecMPA_CreateUsingCallbacks instead. + +After the decoder is created, additional parameters can be configured with +#DecMPA_SetParam. + +@param ppDecoder pointer to a void* variable that receives the address of the + decoder object. +@param sFilePath path of the file to open +@param APIVersion version number of the DecMPA API. You should always + pass the constant #DECMPA_VERSION for this parameter. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_CreateUsingFile(void** ppDecoder,const char* sFilePath,int APIVersion); + + + +/**Creates a new decoder that obtains its input data using callback functions. + +After the decoder is created, additional parameters can be configured with +#DecMPA_SetParam. + +@param ppDecoder pointer to a void* variable that receives the address of the + decoder object. +@param pCallbacks structure containing pointers to the callback functions that + are used to retrieve the MPEG Audio data. +@param pCallbackContext a pointer that is simply passed to the callback + functions. It has no meaning to the decoder and is only meant to be used + to pass arbitrary data to the callback functions. +@param APIVersion version number of the DecMPA API. You should always + pass the constant #DECMPA_VERSION for this parameter. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_CreateUsingCallbacks(void** ppDecoder,const DecMPA_Callbacks* pCallbacks,void* pCallbackContext,int APIVersion); + + + +/**Sets additional DecMPA parameters. + +Calling this function is completely optional - if you don't call it +or only call it for some parameters, the remaining parameters will simply keep +their default values. + +This function should only be called directly after the decoder was created, +before calling any of the other functions. Otherwise DecMPA_SetParam may return +#DECMPA_ERROR_WRONGSTATE. + +@param pDecoder the decoder object +@param ID ID of the parameter to set. See \ref GroupParamIDs. +@param Value the new value for the specified parameter. Which values are possible + depends of the parameter. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_SetParam(void* pDecoder,int ID,long Value); + + + +/**Returns the current value of a DecMPA parameter. + +@param pDecoder the decoder object +@param ID ID of the parameter. See \ref GroupParamIDs. +@return the current value of the specified parameter. +@see #DecMPA_SetParam +*/ +long DECMPA_CC DecMPA_GetParam(void* pDecoder,int ID); + + + +/**Decodes some data and stores it in the supplied buffer. The buffer is not +necessarily completely filled. Always check the value stored in pBytesDecoded +to find out how much data has been decoded. + +The format of the data (frequency and number of channels) can be obtained by +calling #DecMPA_GetOutputFormat after DecMPA_Decode. The format may +change from one call of DecMPA_Decode to the next. Wether the format has +changed can be checked using #DecMPA_OutputFormatChanged. + +@param pDecoder the decoder object +@param pBuffer pointer to a buffer that receives the decoded data. +@param nBufferBytes size of the buffer, in bytes +@param pBytesDecoded pointer to a variable that receives the number of bytes + that were stored in the buffer. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_Decode(void* pDecoder,void* pBuffer,long nBufferBytes,long* pBytesDecoded); + + + +/**This is a special version of #DecMPA_Decode that does not actually decode +any MPEG Audio data, but only decodes the header information. + +This function is a lot faster than #DecMPA_Decode and can be used +to make a quick run through the file and obtain accurate information about +its properties, like the exact duration or decoded file size. + +The function behaves in all ways like #DecMPA_Decode, except that it does not +return any data. In particular, the output format and mpeg audio header +information returned by #DecMPA_GetOutputFormat and #DecMPA_GetMPEGHeader will +be properly updated, just as #DecMPA_Decode does. + +@param pDecoder the decoder object +@param pDecodedBytes pointer to a variable that receives the decoded size + (in bytes) of the current MPEG audio frame. If #DecMPA_Decode was called + before and some parts of the current frame have already been read, the + size of the remaining data is returned +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_DecodeNoData(void* pDecoder,long* pDecodedBytes); + + + +/**Changes the decoding position to the specified time, relative to the +beginning of the data stream. + +If #DecMPA_CreateUsingCallbacks was used to create the decoder and no +Seek callback function has been specified, seeking is not supported and +#DECMPA_ERROR_UNSUPPORTED is returned. + +@param pDecoder the decoder object +@param Millis the target time, in milliseconds +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_SeekToTime(void* pDecoder,long Millis); + + + +/**Retrieves the current decoding time. The decoding time corresponds to +the time that it takes to play the data that has been decoded up to now. + +@param pDecoder the decoder object +@param pTime pointer to a variable that receives the time, in milliseconds. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_GetTime(void* pDecoder,long* pTime); + + + +/**Retrieves the time that it takes to play back the whole data stream. +If the duration is not known -1 is returned. + +\note The duration is an estimation that can be slightly wrong for some files +but is pretty accurate for the wide majority of files. If you need a +100% accurate duration value, there is really no other way than to read through +the whole file with #DecMPA_Decode or #DecMPA_DecodeNoData and add up the +\c DecodedBytes values that are returned by those functions. Note that +if you only make this pass through the file to get the duration, i.e. you do +not need decoded audio data, you can use #DecMPA_DecodeNoData which is a lot +faster than #DecMPA_Decode. + +@param pDecoder the decoder object +@param pDuration pointer to a variable that receives the duration, in + milliseconds. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_GetDuration(void* pDecoder,long* pDuration); + + + +/**Retrieves the format of the data that was returned by the last call to +DecMPA_Decode. + +The nType member of DecMPA_OutputFormat never changes and its value is +defined by the #DECMPA_PARAM_OUTPUT parameter that can be set using +#DecMPA_SetParam. If the value has not been explicitly changed using +#DecMPA_SetParam it will be #DECMPA_OUTPUT_INT16, indicating 16 bit signed +samples. + +The remaining fields of the structure may change after calls to +#DecMPA_Decode or #DecMPA_DecodeNoData. + +@param pDecoder the decoder object +@param pFormat pointer to a DecMPA_OutputFormat object that is filled with + the format data +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_GetOutputFormat(void* pDecoder,DecMPA_OutputFormat* pFormat); + + + +/**Checks wether the output format has changed during the last call to +DecMPA_Decode. + +@return nonzero if the format has changed, zero otherwise.*/ +int DECMPA_CC DecMPA_OutputFormatChanged(void* pDecoder); + + + +/**Retrieve mpeg header of the data that was returned by the last call to +DecMPA_Decode. This function is only supplied for information purposes. + +@param pDecoder the decoder object +@param pHeader pointer to a DecMPA_MPEGHeader object that received the data. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_GetMPEGHeader(void* pDecoder,DecMPA_MPEGHeader* pHeader); + + + +/**Returns the file's ID3v2 tag, if it has one. If the file has no ID3v2 +tag, #DECMPA_ERROR_NOTAVAILABLE is returned. + +This function will always return #DECMPA_ERROR_NOTAVAILABLE if the decoder parameter +#DECMPA_PARAM_PROVIDEID3V2 has not been set to #DECMPA_YES with #DecMPA_SetParam. + +\note There are other libraries that can be used to parse the returned +data, one of them being id3lib. It can be found at +http://id3lib.sourceforge.net/ . + +@param pDecoder the decoder object +@param ppData pointer to a pointer variable that will receive the address + of the ID3v2 data. The memory that contains the data will remain valid + until the decoder is destroyed. +@param pDataSize pointer to a variable that will receive the size of the + ID3v2 data, in bytes. +@return a DecMPA result code (see \ref GroupResults).*/ +int DECMPA_CC DecMPA_GetID3v2Data(void* pDecoder,unsigned char** ppData,long* pDataSize); + + + +/**Destroys a decoder. + +@param pDecoder decoder object.*/ +void DECMPA_CC DecMPA_Destroy(void* pDecoder); + + +/**Returns the version number of the DecMPA API used by the library.*/ +int DECMPA_CC DecMPA_GetVersion(void); + +/*@}*/ + +#endif + + diff --git a/Libraries/DecMPA/Files/src/DecMPA.cpp b/Libraries/DecMPA/Files/src/DecMPA.cpp new file mode 100644 index 000000000..5c5bd3fbd --- /dev/null +++ b/Libraries/DecMPA/Files/src/DecMPA.cpp @@ -0,0 +1,262 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#include "DefInc.h" +#include "../include/decmpa.h" +#include "MPADecoder.h" + +#include + +#include + + +#if defined(__GNUC__) && (defined(_WINDOWS) || defined(_WIN32)) + #define DLLEXPORT __declspec(dllexport) +#else + #define DLLEXPORT +#endif + +long DECMPA_CC DecMPA_StdioRead(void* pContext,void* pBuffer,long nBytes) +{ + long nBytesRead; + + nBytesRead=fread(pBuffer,1,nBytes,(FILE*)pContext); + if(nBytesRead!=nBytes) + { + if(ferror((FILE*)pContext)) + return -1; + } + + return nBytesRead; +} + + +int DECMPA_CC DecMPA_StdioSeek(void* pContext,long DestPos) +{ + if(fseek((FILE*)pContext,DestPos,SEEK_SET)!=0) + return 0; //error + else + return 1; //no error +} + +long DECMPA_CC DecMPA_StdioGetLength(void* pContext) +{ + long nOldPos; + long nLength=-1; + + nOldPos=ftell((FILE*)pContext); + if(fseek((FILE*)pContext,0,SEEK_END)==0) + { + nLength=ftell((FILE*)pContext); + fseek((FILE*)pContext,nOldPos,SEEK_SET); + } + + return nLength; +} + +long DECMPA_CC DecMPA_StdioGetPosition(void* pContext) +{ + return ftell((FILE*)pContext); +} + +void DecMPA_StdioDestroyNotify(void* pContext) +{ + fclose((FILE*)pContext); +} + +DLLEXPORT int DECMPA_CC DecMPA_CreateUsingFile(void** ppDecoder,const char* sFilePath,int Version) +{ + FILE* pFile; + DecMPA_Callbacks Callbacks; + int nResult; + + if(Version>DECMPA_VERSION) + return DECMPA_ERROR_INCOMPATIBLEVERSION; + + pFile=fopen(sFilePath,"rb"); + if(pFile==NULL) + return DECMPA_ERROR_OPENFILE; + + Callbacks.Read=DecMPA_StdioRead; + Callbacks.Seek=DecMPA_StdioSeek; + Callbacks.GetLength=DecMPA_StdioGetLength; + Callbacks.GetPosition=DecMPA_StdioGetPosition; + + nResult=DecMPA_CreateUsingCallbacks(ppDecoder,&Callbacks,pFile,Version); + if(nResult!=DECMPA_OK) + fclose(pFile); + + ((CMPADecoder*)(*ppDecoder))->SetDestroyNotify(DecMPA_StdioDestroyNotify,pFile); + + return nResult; +} + + +DLLEXPORT int DECMPA_CC DecMPA_CreateUsingCallbacks(void** ppDecoder,const DecMPA_Callbacks* pCallbacks,void* pContext,int Version) +{ + DecMPA_Callbacks Callbacks=*pCallbacks; + + if(Callbacks.Read==NULL) + { + Callbacks.Read=DecMPA_StdioRead; + Callbacks.Seek=NULL; + Callbacks.GetLength=NULL; + Callbacks.GetPosition=DecMPA_StdioGetPosition; + + pContext=stdin; + } + + if(Version>DECMPA_VERSION) + return DECMPA_ERROR_INCOMPATIBLEVERSION; + + if(ppDecoder==NULL || Callbacks.GetPosition==NULL) + return DECMPA_ERROR_PARAM; + + try + { + *ppDecoder=new CMPADecoder(Callbacks,pContext); + + return DECMPA_OK; + } + catch(std::bad_alloc e) + { + return DECMPA_ERROR_MEMORY; + } + catch(std::exception e) + { + return DECMPA_ERROR_INTERNAL; + } +} + +DLLEXPORT int DECMPA_CC DecMPA_SetParam(void* pDecoder,int ID,long Value) +{ + if(pDecoder==NULL) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->SetParam(ID,Value); +} + +DLLEXPORT long DECMPA_CC DecMPA_GetParam(void* pDecoder,int ID) +{ + if(pDecoder==NULL) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->GetParam(ID); +} + +DLLEXPORT int DECMPA_CC DecMPA_Decode(void* pDecoder,void* pBuffer,long nBufferBytes,long* pBytesDecoded) +{ + if(pDecoder==NULL || pBytesDecoded==NULL || (pBuffer==NULL && nBufferBytes!=0)) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->Decode(pBuffer,nBufferBytes,*pBytesDecoded); +} + +DLLEXPORT int DECMPA_CC DecMPA_DecodeNoData(void* pDecoder,long* pDecodedBytes) +{ + if(pDecoder==NULL || pDecodedBytes==NULL) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->DecodeNoData(*pDecodedBytes); +} + +DLLEXPORT int DECMPA_CC DecMPA_SeekToTime(void* pDecoder,long Millis) +{ + if(pDecoder==NULL) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->SeekToTime(Millis); +} + +DLLEXPORT int DECMPA_CC DecMPA_GetTime(void* pDecoder,long* pTime) +{ + if(pDecoder==NULL || pTime==NULL) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->GetTime(*pTime); +} + +DLLEXPORT int DECMPA_CC DecMPA_GetDuration(void* pDecoder,long* pDuration) +{ + if(pDecoder==NULL || pDuration==NULL) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->GetDuration(*pDuration); +} + +DLLEXPORT int DECMPA_CC DecMPA_GetOutputFormat(void* pDecoder,DecMPA_OutputFormat* pFormat) +{ + if(pDecoder==NULL || pFormat==NULL) + return DECMPA_ERROR_PARAM; + + ((CMPADecoder*)pDecoder)->GetOutputFormat(*pFormat); + + return DECMPA_OK; +} + +DLLEXPORT int DECMPA_CC DecMPA_OutputFormatChanged(void* pDecoder) +{ + if(pDecoder==NULL) + return 0; + + return ((CMPADecoder*)pDecoder)->OutputFormatChanged() ? 1 : 0; +} + +DLLEXPORT int DECMPA_CC DecMPA_GetMPEGHeader(void* pDecoder,DecMPA_MPEGHeader* pHeader) +{ + if(pDecoder==NULL || pHeader==NULL) + return DECMPA_ERROR_PARAM; + + ((CMPADecoder*)pDecoder)->GetMPEGHeader(*pHeader); + + return DECMPA_OK; +} + +DLLEXPORT int DECMPA_CC DecMPA_GetID3v2Data(void* pDecoder,unsigned char** ppData,long* pDataSize) +{ + if(pDecoder==NULL || ppData==NULL || pDataSize==NULL) + return DECMPA_ERROR_PARAM; + + return ((CMPADecoder*)pDecoder)->GetID3v2Data(*ppData,*pDataSize); +} + +DLLEXPORT void DECMPA_CC DecMPA_Destroy(void* pDecoder) +{ + if(pDecoder!=NULL) + { + try + { + delete (CMPADecoder*)pDecoder; + } + catch(std::exception) + { + } + } +} + +DLLEXPORT int DECMPA_CC DecMPA_GetVersion(void) +{ + return DECMPA_VERSION; +} + + diff --git a/Libraries/DecMPA/Files/src/DecMPAFileAccess.cpp b/Libraries/DecMPA/Files/src/DecMPAFileAccess.cpp new file mode 100644 index 000000000..c8eb3c9f9 --- /dev/null +++ b/Libraries/DecMPA/Files/src/DecMPAFileAccess.cpp @@ -0,0 +1,326 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + +#include "DefInc.h" +#include "DecMPAFileAccess.h" + +#include + +CDecMPAFileAccess::CDecMPAFileAccess(const DecMPA_Callbacks& Callbacks,void* pContext) +{ + m_Callbacks=Callbacks; + m_pCallbackContext=pContext; + + m_nPosition=Callbacks.GetPosition(pContext); + if(m_nPosition<0) + m_nPosition=0; + + m_bEOF=false; + + m_pUndoBuffer=NULL; + m_nUndoBufferSize=0; + + m_nUndoBufferFilled=0; + m_nUndoBufferPos=0; + + m_nUndoRecordingCount=0; + + m_LastError=DECMPA_OK; + + m_pSkipBuffer=NULL; + m_nSkipBufferSize=0; +} + +CDecMPAFileAccess::~CDecMPAFileAccess() +{ + if(m_pUndoBuffer!=NULL) + delete[] m_pUndoBuffer; + + if(m_pSkipBuffer!=NULL) + delete[] m_pSkipBuffer; +} + +int CDecMPAFileAccess::Read(void* pDest,int nBytes) +{ + long nResult=0; + long nRedoBytes=0; + + nRedoBytes=m_nUndoBufferFilled-m_nUndoBufferPos; + if(nRedoBytes>0) + { + if(nRedoBytes>nBytes) + nRedoBytes=nBytes; + memcpy(pDest,m_pUndoBuffer+m_nUndoBufferPos,nRedoBytes); + m_nUndoBufferPos+=nRedoBytes; + nBytes-=nRedoBytes; + pDest=((char*)pDest)+nRedoBytes; + + m_nPosition+=nRedoBytes; + + if(m_nUndoBufferPos==m_nUndoBufferFilled && m_nUndoRecordingCount==0) + { + m_nUndoBufferFilled=0; + m_nUndoBufferPos=0; + } + + nResult+=nRedoBytes; + } + + if(nBytes>0) + { + long nRead; + + nRead=m_Callbacks.Read(m_pCallbackContext,pDest,nBytes); + if(nRead>=0) + { + if(nRead!=nBytes) + m_bEOF=true; + m_nPosition+=nRead; + + if(m_nUndoRecordingCount>0) + { + EnsureUndoBufferFree(nRead); + memcpy(m_pUndoBuffer+m_nUndoBufferPos,pDest,nRead); + m_nUndoBufferFilled+=nRead; + m_nUndoBufferPos+=nRead; + } + + nResult+=nRead; + } + else + { + m_LastError=DECMPA_ERROR_READ; + nResult=-1; + } + } + + return nResult; +} + +long CDecMPAFileAccess::Skip(long nBytes) +{ + long nResult=0; + long nRedoBytes=0; + bool bSeekFailed=false; + + nRedoBytes=m_nUndoBufferFilled-m_nUndoBufferPos; + if(nRedoBytes>0) + { + if(nRedoBytes>nBytes) + nRedoBytes=nBytes; + m_nUndoBufferPos+=nRedoBytes; + nBytes-=nRedoBytes; + + m_nPosition+=nRedoBytes; + + if(m_nUndoBufferPos==m_nUndoBufferFilled && m_nUndoRecordingCount==0) + { + m_nUndoBufferFilled=0; + m_nUndoBufferPos=0; + } + + nResult+=nRedoBytes; + } + + if(nBytes>0) + { + //first try to skip using seek + + if(nBytes>1024 && m_Callbacks.Seek!=NULL && m_nUndoRecordingCount==0) + { + long nLength=GetLength(); + + if(nLength!=-1) + { + long nToSkip=nBytes; + + if(m_nPosition+nToSkip>nLength) + nToSkip=nLength-m_nPosition; + + if(m_Callbacks.Seek(m_pCallbackContext,m_nPosition+nToSkip)!=0) + { + m_nPosition+=nToSkip; + nResult+=nToSkip; + nBytes-=nToSkip; + } + else + { + //seek failed - not critical, we can still try to skip + //using read. + bSeekFailed=true; + } + } + } + } + + if(nBytes>0) + { + int nToRead; + int nRead; + + if(m_pSkipBuffer==NULL) + { + m_nSkipBufferSize=8192; + m_pSkipBuffer=new unsigned char[m_nSkipBufferSize]; + } + + while(nBytes>0 && !m_bEOF) + { + nToRead=(nBytes<=m_nSkipBufferSize) ? nBytes : m_nSkipBufferSize; + + nRead=m_Callbacks.Read(m_pCallbackContext,m_pSkipBuffer,nToRead); + if(nRead>=0) + { + if(nRead!=nToRead) + m_bEOF=true; + m_nPosition+=nRead; + + if(m_nUndoRecordingCount>0) + { + EnsureUndoBufferFree(nRead); + memcpy(m_pUndoBuffer+m_nUndoBufferPos,m_pSkipBuffer,nRead); + m_nUndoBufferFilled+=nRead; + m_nUndoBufferPos+=nRead; + } + + nResult+=nRead; + nBytes-=nRead; + } + else + { + if(bSeekFailed) + { + //if seek also failed before we report a seek error + m_LastError=DECMPA_ERROR_SEEK; + } + else + m_LastError=DECMPA_ERROR_READ; + + nResult=-1; + break; + } + } + } + + return nResult; +} + +bool CDecMPAFileAccess::IsEndOfFile() +{ + return m_bEOF; +} + +bool CDecMPAFileAccess::Seek(long pos) +{ + bool bResult=false; + + if(pos==m_nPosition) + bResult=true; + else + { + if(m_nUndoRecordingCount==0) + { + if(m_Callbacks.Seek!=NULL) + { + if(m_Callbacks.Seek(m_pCallbackContext,pos)!=0) + { + m_nPosition=pos; + bResult=true; + } + else + m_LastError=DECMPA_ERROR_SEEK; + } + } + } + + return bResult; +} + +long CDecMPAFileAccess::GetPosition() +{ + return m_nPosition; +} + +long CDecMPAFileAccess::GetLength() +{ + long nLength=-1; + + if(m_Callbacks.GetLength!=NULL) + nLength=m_Callbacks.GetLength(m_pCallbackContext); + + return nLength; +} + +long CDecMPAFileAccess::StartUndoRecording() +{ + m_nUndoRecordingCount++; + + return m_nUndoBufferPos; +} + +void CDecMPAFileAccess::EndUndoRecording(long ID,bool bUndo) +{ + if(m_nUndoRecordingCount>0) + { + if(bUndo) + { + m_nPosition-=m_nUndoBufferPos-ID; + if(m_nUndoBufferPos!=ID) + m_bEOF=false; + + m_nUndoBufferPos=ID; + } + + m_nUndoRecordingCount--; + } +} + +void CDecMPAFileAccess::EnsureUndoBufferFree(long nBytes) +{ + if(m_nUndoBufferPos+nBytes>m_nUndoBufferSize) + { + unsigned char* pNew; + long nAdd=m_nUndoBufferPos+nBytes-m_nUndoBufferSize; + + if((nAdd & 8191)!=0) + nAdd+=8192-(nAdd & 8191); + + pNew=new unsigned char[m_nUndoBufferSize+nAdd]; + memcpy(pNew,m_pUndoBuffer,m_nUndoBufferFilled); + m_nUndoBufferSize+=nAdd; + + if(m_pUndoBuffer!=NULL) + delete[] m_pUndoBuffer; + m_pUndoBuffer=pNew; + } +} + +int CDecMPAFileAccess::GetLastError() +{ + return m_LastError; +} + +bool CDecMPAFileAccess::CanSeek() +{ + return (m_Callbacks.Seek!=NULL); +} + diff --git a/Libraries/DecMPA/Files/src/DecMPAFileAccess.h b/Libraries/DecMPA/Files/src/DecMPAFileAccess.h new file mode 100644 index 000000000..0437c46b2 --- /dev/null +++ b/Libraries/DecMPA/Files/src/DecMPAFileAccess.h @@ -0,0 +1,75 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + +#ifndef _DECMPAFILEACCESS_H_ +#define _DECMPAFILEACCESS_H_ + +#include "../include/decmpa.h" + +#include "IFileAccess.h" + +class CDecMPAFileAccess : public IFileAccess +{ +public: + CDecMPAFileAccess(const DecMPA_Callbacks& Callbacks,void* pContext); + ~CDecMPAFileAccess(); + + int Read(void* pDest,int nBytes); + long Skip(long nBytes); + + bool IsEndOfFile(); + + bool CanSeek(); + bool Seek(long pos); + + long GetPosition(); + long GetLength(); + + long StartUndoRecording(); + void EndUndoRecording(long ID,bool bUndo); + + int GetLastError(); + +protected: + void EnsureUndoBufferFree(long nBytes); + + DecMPA_Callbacks m_Callbacks; + void* m_pCallbackContext; + + long m_nPosition; + bool m_bEOF; + + unsigned char* m_pUndoBuffer; + long m_nUndoBufferSize; + long m_nUndoBufferFilled; + long m_nUndoBufferPos; + + int m_nUndoRecordingCount; + + unsigned char* m_pSkipBuffer; + long m_nSkipBufferSize; + + int m_LastError; +}; + +#endif + diff --git a/Libraries/DecMPA/Files/src/DecodeEngine.h b/Libraries/DecMPA/Files/src/DecodeEngine.h new file mode 100644 index 000000000..4ee440474 --- /dev/null +++ b/Libraries/DecMPA/Files/src/DecodeEngine.h @@ -0,0 +1,36 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#ifndef _DECODEENGINE_H_ +#define _DECODEENGINE_H_ + +#include "frame/audioFrame.h" + +void* DecodeEngine_Create(); + +bool DecodeEngine_Decode(void* pEngine,AudioFrame* pDest,void* pData,long nDataLength); +void DecodeEngine_Flush(void* pEngine); + +void DecodeEngine_Destroy(void* pEngine); + +#endif diff --git a/Libraries/DecMPA/Files/src/DefInc.h b/Libraries/DecMPA/Files/src/DefInc.h new file mode 100644 index 000000000..7c22a5fb0 --- /dev/null +++ b/Libraries/DecMPA/Files/src/DefInc.h @@ -0,0 +1,25 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#include + diff --git a/Libraries/DecMPA/Files/src/IFileAccess.h b/Libraries/DecMPA/Files/src/IFileAccess.h new file mode 100644 index 000000000..dcece68f6 --- /dev/null +++ b/Libraries/DecMPA/Files/src/IFileAccess.h @@ -0,0 +1,40 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + +#ifndef _IFILEACCESS_H_ +#define _IFILEACCESS_H_ + +class IFileAccess +{ +public: + virtual int Read(void* pDest,int nBytes)=0; + virtual long Skip(long nBytes)=0; + virtual bool IsEndOfFile()=0; + + virtual bool CanSeek()=0; + virtual bool Seek(long nPosition)=0; + + virtual long GetPosition()=0; + virtual long GetLength()=0; +}; + +#endif diff --git a/Libraries/DecMPA/Files/src/MPADecoder.cpp b/Libraries/DecMPA/Files/src/MPADecoder.cpp new file mode 100644 index 000000000..ab548d768 --- /dev/null +++ b/Libraries/DecMPA/Files/src/MPADecoder.cpp @@ -0,0 +1,638 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + +//This file is a heavily modified version of SPlayPlugin.cpp from the original +//mpeglib. See Readme.txt for details. + +#include "DefInc.h" +#include "MPADecoder.h" + +#include "DecodeEngine.h" + +#include +#include + +#include + + +CMPADecoder::CMPADecoder(const DecMPA_Callbacks& Callbacks,void* pCallbackContext) +{ + pow(6.0,3.0); // fixes bug in __math.h + + m_Callbacks=Callbacks; + m_pCallbackContext=pCallbackContext; + + m_pFileAccess=new CDecMPAFileAccess(Callbacks,pCallbackContext); + + m_nResyncCounter=0; + + m_nBufferBytes=0; + m_nUsedBufferBytes=0; + m_pBuffer=NULL; + + m_OutputFormat.nType=0; + m_OutputFormat.nFrequency=0; + m_OutputFormat.nChannels=0; + m_bOutputFormatChanged=false; + + memset(&m_MPEGHeader,0,sizeof(m_MPEGHeader)); + + m_bDoFloat=false; + m_pPCMFrame=new PCMFrame(MP3FRAMESIZE); + m_pFloatFrame=new FloatFrame(MP3FRAMESIZE); + m_pAudioFrame=NULL; + + m_pFormatFrame=new AudioFrame; + + m_nReadTime=0; + m_nBufferStartTime=0; + m_nDecodeTime=0; + + m_bPrepared=false; + m_bHasFrame=false; + + m_bFirstDecode=true; + + m_pDecodeEngine=DecodeEngine_Create(); + + m_bStoreID3v2=false; + m_pID3v2Data=(unsigned char*)0; + m_nID3v2DataSize=0; + + m_pDestroyNotify=(void (*)(void*))0; + m_pDestroyNotifyContext=(void*)0; + + m_aParams[DECMPA_PARAM_OUTPUT]=DECMPA_OUTPUT_INT16; + m_aParams[DECMPA_PARAM_PROVIDEID3V2]=DECMPA_NO; + + m_bNotMPEG=false; + + m_bDecoderNeedsFlush=false; +} + +CMPADecoder::~CMPADecoder() +{ + if(m_pDestroyNotify!=(void (*)(void*))0) + m_pDestroyNotify(m_pDestroyNotifyContext); + + delete m_pPCMFrame; + delete m_pFloatFrame; + + delete m_pFileAccess; + delete m_pFormatFrame; + + DecodeEngine_Destroy(m_pDecodeEngine); +} + +int CMPADecoder::DecodeNoData(long& nDecodedBytes) +{ + return Decode(NULL,-1,nDecodedBytes); +} + +int CMPADecoder::Decode(void* pBuffer,long nBufferBytes,long& nBytesDecoded) +{ + int Result=DECMPA_OK; + + if(pBuffer==NULL) + nBufferBytes=-1; + + nBytesDecoded=0; + m_bOutputFormatChanged=false; + + if((Result=EnsurePrepared())!=DECMPA_OK) + return Result; + + try + { + while(!ReadDecodedData(pBuffer,nBufferBytes,nBytesDecoded)) + { + Result=DecodeNextFrame(pBuffer==NULL); + if(Result!=DECMPA_OK) + break; + } + } + catch(std::bad_alloc) + { + return DECMPA_ERROR_MEMORY; + } + catch(std::exception) + { + return DECMPA_ERROR_INTERNAL; + } + + return Result; +} + +int CMPADecoder::DecodeNextFrame(bool bNoData) +{ + int Result=DECMPA_OK; + + //find and read the next frame + //we may still have one frame buffered that was read to find out + //the file information. In that case don't read another one + if(!m_bHasFrame) + m_bHasFrame=ReadNextFrame(); + if(m_bHasFrame) + { + bool bDecodeOK; + + //don't use this frame again + m_bHasFrame=false; + + //if bNoData==true we don't decode any audio data but only + //parse the frame headers + //this allows the user to do a quick pass over the file and + //get an accurate estimate of the files properties + //(actual duration, decoded size, etc...). + if(!bNoData) + { + if(m_bDecoderNeedsFlush) + { + DecodeEngine_Flush(m_pDecodeEngine); + m_bDecoderNeedsFlush=false; + } + + bDecodeOK=DecodeEngine_Decode(m_pDecodeEngine,m_pAudioFrame,m_FrameFinder.GetFrameData(),m_FrameFinder.GetFrameSize()); + } + else + { + MpegAudioHeader* pHeader=m_FrameFinder.GetFrameHeader(); + long nDecodedFrameSize; + + m_bDecoderNeedsFlush=true; + + nDecodedFrameSize=pHeader->getpcmperframe(); + if(pHeader->getInputstereo()==1) + nDecodedFrameSize*=2; + + //pretend that we have decoded something + m_pAudioFrame->setLen(nDecodedFrameSize); + m_pAudioFrame->setFrameFormat(pHeader->getInputstereo(),pHeader->getFrequencyHz()); + + //note that this "ghost data" will never be retrieved because the call + //to ReadDecodedData that follows will always remove all of it + //(see Decode) + + bDecodeOK=true; + } + + if(bDecodeOK) + { + //make the decoded data available to the "user" + HandleDecodedData(m_pAudioFrame); + } + //ignore if the decoding of the frame failed. Just continue with + //the next frame + } + else + { + if(m_FrameFinder.IsStreamInvalid()) + Result=DECMPA_ERROR_DECODE; + else + { + if(m_pFileAccess->IsEndOfFile()) + { + //end of file reached + if(!m_FrameFinder.KnowsCharacteristics()) + { + //the end was reached without being able to find out + //essential stream characteristics + //=> not an MPEG Audio file (or one that has less than 4 frames) + Result=DECMPA_ERROR_DECODE; + } + else + Result=DECMPA_END; + } + else + { + if(m_pFileAccess->GetLastError()!=DECMPA_OK) + Result=m_pFileAccess->GetLastError(); + else + { + //should never happen - an invalid stream, end of file + //or a read error are the only things that could cause + //ReadNextFrame to fail + Result=DECMPA_ERROR_INTERNAL; + } + } + } + } + + return Result; +} + +void CMPADecoder::Flush() +{ + m_FrameFinder.Flush(); + DecodeEngine_Flush(m_pDecodeEngine); + + m_nBufferBytes=0; + m_nUsedBufferBytes=0; +} + +bool CMPADecoder::ReadDecodedData(void* pDest,long nBytes,long& nRead) +{ + long nAvailBytes=m_nBufferBytes-m_nUsedBufferBytes; + + if(nAvailBytes>0) + { + if(nBytes>nAvailBytes || nBytes==-1) + nBytes=nAvailBytes; + nBytes&=~m_nOutputBlockSize; //only full samples + + if(pDest!=NULL) + memcpy(pDest,m_pBuffer+m_nUsedBufferBytes,nBytes); + m_nUsedBufferBytes+=nBytes; + + nRead=nBytes; + + m_nReadTime=m_nBufferStartTime+(((double)(m_nUsedBufferBytes/m_nOutputBlockSize))*1000)/m_pFormatFrame->getFrequenceHZ(); + + return true; + } + else + return false; +} + +long CMPADecoder::GetFilePositionFromTime(long Millis) +{ + int nResult; + + if((nResult=EnsurePrepared())!=DECMPA_OK) + return nResult; + + return m_Info.GetFilePositionFromTime(Millis); +} + +int CMPADecoder::SeekToTime(long Millis) +{ + int Result=DECMPA_OK; + + if(!m_pFileAccess->CanSeek()) + Result=DECMPA_ERROR_UNSUPPORTED; + else + { + long nFilePos; + + if((Result=EnsurePrepared())==DECMPA_OK) + { + nFilePos=m_Info.GetFilePositionFromTime(Millis); + if(nFilePos==-1) + Result=DECMPA_ERROR_UNSUPPORTED; + else + { + if(!m_pFileAccess->Seek(nFilePos)) + Result=DECMPA_ERROR_SEEK; + else + { + //throw away buffered data + Flush(); + + if(Millis!=0) + { + //initiate resync (skip next 5 frames until back + //references are ok again) + m_nResyncCounter=5; + } + + m_nDecodeTime=Millis; + m_nBufferStartTime=Millis; + m_nReadTime=Millis; + } + } + } + } + + return Result; +} + +int CMPADecoder::GetTime(long& Time) +{ + Time=(long)m_nReadTime; + + return DECMPA_OK; +} + +int CMPADecoder::GetDuration(long& Duration) +{ + int nResult; + + try + { + if((nResult=EnsurePrepared())!=DECMPA_OK) + return nResult; + + Duration=m_Info.GetDuration(); + + return DECMPA_OK; + } + catch(std::bad_alloc) + { + return DECMPA_ERROR_MEMORY; + } + catch(std::exception) + { + return DECMPA_ERROR_INTERNAL; + } +} + +bool CMPADecoder::ReadNextFrame() +{ + while(!m_FrameFinder.ReadNextFrame()) + { + if(m_FrameFinder.IsStreamInvalid()) + return false; + + if(!m_FrameFinder.ReadInput(m_pFileAccess)) + return false; + } + + return true; +} + +void CMPADecoder::SetOutputFormat(AudioFrame* pNewFormatFrame) +{ + pNewFormatFrame->copyFormat(m_pFormatFrame); + + m_OutputFormat.nFrequency=m_pFormatFrame->getFrequenceHZ(); + m_OutputFormat.nChannels=m_pFormatFrame->getStereo() ? 2 : 1; + + m_bOutputFormatChanged=true; + + m_nOutputBlockSize=m_pFormatFrame->getSampleSize()/8; + m_nOutputBlockSize*=m_OutputFormat.nChannels; +} + +void CMPADecoder::UpdateMPEGHeader(MpegAudioHeader* pHeader) +{ + memcpy(m_MPEGHeader.aRawData,pHeader->getHeader(),4); + m_MPEGHeader.bProtection=pHeader->getProtection()!=0; + + m_MPEGHeader.nLayer=pHeader->getLayer(); + m_MPEGHeader.nVersion=pHeader->getVersion(); + m_MPEGHeader.bPadding=pHeader->getPadding()!=0; + m_MPEGHeader.nFrequencyIndex=pHeader->getFrequency(); + m_MPEGHeader.nFrequency=pHeader->getFrequencyHz(); + m_MPEGHeader.nBitRateIndex=pHeader->getBitrateindex(); + m_MPEGHeader.nExtendedMode=pHeader->getExtendedmode(); + m_MPEGHeader.nMode=pHeader->getMode(); + m_MPEGHeader.bInputStereo=pHeader->getInputstereo()!=0; + m_MPEGHeader.bMPEG25=pHeader->getLayer25()!=0; + + m_MPEGHeader.nFrameSize=pHeader->getFramesize(); + m_MPEGHeader.nDecodedSamplesPerFrame=pHeader->getpcmperframe(); + m_MPEGHeader.nBitRateKbps=pHeader->GetBitRateKbps(); +} + +bool CMPADecoder::OutputFormatChanged() +{ + return m_bOutputFormatChanged; +} + +void CMPADecoder::GetOutputFormat(DecMPA_OutputFormat& Format) +{ + Format=m_OutputFormat; +} + +void CMPADecoder::GetMPEGHeader(DecMPA_MPEGHeader& Header) +{ + Header=m_MPEGHeader; +} + + +void CMPADecoder::HandleDecodedData(AudioFrame* pDecodedFrame) +{ + int nDecodedSamples; + + if(m_bFirstDecode) + { + SetOutputFormat(pDecodedFrame); + m_bFirstDecode=false; + } + + nDecodedSamples=pDecodedFrame->getLen(); + if(pDecodedFrame->getStereo()==1) + nDecodedSamples/=2; + + m_nBufferStartTime=m_nDecodeTime; + m_nDecodeTime+=(((double)nDecodedSamples)*1000)/pDecodedFrame->getFrequenceHZ(); + + if(m_nResyncCounter>0) + { + //we need to resync = read a few frames to make sure + //that the back references are ok again + //do not output any of the decoded data + m_nResyncCounter--; + } + else + { + if(!m_pFormatFrame->isFormatEqual(pDecodedFrame)) + SetOutputFormat(pDecodedFrame); + + UpdateMPEGHeader(m_FrameFinder.GetFrameHeader()); + + if(m_bDoFloat) + { + m_nBufferBytes=m_pFloatFrame->getLen()*sizeof(float); + m_pBuffer=(unsigned char*)m_pFloatFrame->getData(); + } + else + { + m_nBufferBytes=m_pPCMFrame->getLen()*sizeof(short); + m_pBuffer=(unsigned char*)m_pPCMFrame->getData(); + } + m_nUsedBufferBytes=0; + } + +} + +int CMPADecoder::EnsurePrepared() +{ + int Result=DECMPA_OK; + + if(!m_bPrepared) + { + if(m_bNotMPEG) + Result=DECMPA_ERROR_DECODE; + else + { + m_bStoreID3v2=(m_aParams[DECMPA_PARAM_PROVIDEID3V2]==DECMPA_YES); + + m_bDoFloat=(m_aParams[DECMPA_PARAM_OUTPUT]==DECMPA_OUTPUT_FLOAT); + m_nOutputBlockSize=1; + if(m_bDoFloat) + m_pAudioFrame=m_pFloatFrame; + else + m_pAudioFrame=m_pPCMFrame; + + m_OutputFormat.nType=m_aParams[DECMPA_PARAM_OUTPUT]; + + //Skip or store any leading ID3 tags - some tags are not + //correctly escaped and contain "sync" codes that can confuse + //the decoder + HandleID3Tag(); + + if(!m_Info.InitInfo(&m_FrameFinder,m_pFileAccess)) + { + m_bNotMPEG=true; + Result=DECMPA_ERROR_DECODE; + } + else + { + //info reads up to one frame. + //we can use this in decoding, we only have to remember not + //to read a fresh one in the first iteration of Decode + m_bHasFrame=m_FrameFinder.HasFrame(); + + m_bPrepared=true; + } + } + } + + return Result; +} + +void CMPADecoder::HandleID3Tag() +{ + unsigned char aHeaderData[10]; + struct ID3v2Header + { + char sID[3]; + unsigned char Version; + unsigned char Revision; + unsigned char Flags; + unsigned long Size; + } Header; + + int nBytesRead; + long UndoID; + + UndoID=m_pFileAccess->StartUndoRecording(); + + if((nBytesRead=m_pFileAccess->Read((char*)&aHeaderData,10))==10) + { + //we do not read directly into the header because the fields may + //have been padded by the compiler + memcpy(Header.sID,aHeaderData,3); + Header.Version=aHeaderData[3]; + Header.Revision=aHeaderData[4]; + Header.Flags=aHeaderData[5]; + Header.Size=aHeaderData[6]; + Header.Size<<=8; + Header.Size|=aHeaderData[7]; + Header.Size<<=8; + Header.Size|=aHeaderData[8]; + Header.Size<<=8; + Header.Size|=aHeaderData[9]; + + //make sure its an ID3 header + if(strncmp(Header.sID,"ID3",3)==0 && Header.Version!=0xff && Header.Revision!=0xff + && (Header.Size & 0x80808080)==0) + { + unsigned long TagSize=Header.Size; + + //ok, we have an ID3 tag - no need for undo + m_pFileAccess->EndUndoRecording(UndoID,false); + UndoID=-1; + + //correct "unsyncing" of tag size + TagSize=(TagSize & 0x7f) | ((TagSize & 0x7f00)>>1) + | ((TagSize & 0x7f0000)>>2) | ((TagSize & 0x7f000000)>>3); + + if(m_bStoreID3v2) + { + //read ID3 tag + + m_pID3v2Data=new unsigned char[10+TagSize]; + memcpy(m_pID3v2Data,aHeaderData,10); + + if(m_pFileAccess->Read(m_pID3v2Data+10,TagSize)==(long)TagSize) + m_nID3v2DataSize=TagSize+10; + else + { + delete[] m_pID3v2Data; + m_pID3v2Data=(unsigned char*)0; + } + } + else + { + //skip the ID3 tag + m_pFileAccess->Skip(TagSize); + } + } + } + + if(UndoID!=-1) + { + //no ID3 tag found + //=> undo read operations + m_pFileAccess->EndUndoRecording(UndoID,true); + } +} + +int CMPADecoder::GetID3v2Data(unsigned char*& pData,long& nDataSize) +{ + int nResult; + + if((nResult=EnsurePrepared())!=DECMPA_OK) + return nResult; + + if(m_pID3v2Data==(unsigned char*)0) + return DECMPA_ERROR_NOTAVAILABLE; + + pData=m_pID3v2Data; + nDataSize=m_nID3v2DataSize; + + return DECMPA_OK; +} + + +int CMPADecoder::SetParam(int ID,long Value) +{ + bool bOK=false; + + if(m_bPrepared) + return DECMPA_ERROR_WRONGSTATE; + + switch(ID) + { + case DECMPA_PARAM_OUTPUT: bOK=(Value==DECMPA_OUTPUT_INT16 || Value==DECMPA_OUTPUT_FLOAT); + break; + case DECMPA_PARAM_PROVIDEID3V2: bOK=(Value==DECMPA_YES || Value==DECMPA_NO); + break; + } + if(!bOK) + return DECMPA_ERROR_PARAM; + + m_aParams[ID]=Value; + + return DECMPA_OK; + +} + +long CMPADecoder::GetParam(int ID) +{ + if(ID<0 || ID>=DECMPA_PARAMCOUNT) + return 0; + + return m_aParams[ID]; +} diff --git a/Libraries/DecMPA/Files/src/MPADecoder.h b/Libraries/DecMPA/Files/src/MPADecoder.h new file mode 100644 index 000000000..975e6c56e --- /dev/null +++ b/Libraries/DecMPA/Files/src/MPADecoder.h @@ -0,0 +1,143 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + +//This file is a heavily modified version of SPlayPlugin.h from the original +//mpeglib. See Readme.txt for details. + + +#ifndef _MPADECODER_H_ +#define _MPADECODER_H_ + +#include "../include/decmpa.h" + +#include "DecMPAFileAccess.h" + +#include "frame/pcmFrame.h" +#include "frame/floatFrame.h" + +#include "MPAFrameFinder.h" +#include "MPAInfo.h" + +class CMPADecoder +{ +public: + CMPADecoder(const DecMPA_Callbacks& Callbacks,void* pCallbackContext); + ~CMPADecoder(); + + int Decode(void* pBuffer,long nBufferBytes,long& nBytesDecoded); + int DecodeNoData(long& nDecodedBytes); + + int SeekToTime(long Millis); + + int GetTime(long& Time); + int GetDuration(long& Duration); + + bool OutputFormatChanged(); + void GetOutputFormat(DecMPA_OutputFormat& Format); + + void GetMPEGHeader(DecMPA_MPEGHeader& Header); + + int GetID3v2Data(unsigned char*& pData,long& nDataSize); + + inline void SetDestroyNotify(void (*pNotify)(void*),void* pContext); + + long GetFilePositionFromTime(long Millis); + + int SetParam(int ID,long Value); + long GetParam(int ID); + +protected: + int DecodeNextFrame(bool bNoData); + bool ReadNextFrame(); + + void HandleDecodedData(AudioFrame* playFrame); + void SetOutputFormat(AudioFrame* pNewFormatFrame); + + bool ReadDecodedData(void* pDest,long nBytes,long& nRead); + + void Flush(); + + int EnsurePrepared(); + void HandleID3Tag(); + + void UpdateMPEGHeader(MpegAudioHeader* pHeader); + + DecMPA_Callbacks m_Callbacks; + void* m_pCallbackContext; + + bool m_bDoFloat; + + AudioFrame* m_pAudioFrame; + FloatFrame* m_pFloatFrame; + PCMFrame* m_pPCMFrame; + + AudioFrame* m_pFormatFrame; + int m_nOutputBlockSize; + + CDecMPAFileAccess* m_pFileAccess; + + long m_nBufferBytes; + long m_nUsedBufferBytes; + unsigned char* m_pBuffer; + + double m_nReadTime; + double m_nBufferStartTime; + double m_nDecodeTime; + + DecMPA_OutputFormat m_OutputFormat; + bool m_bOutputFormatChanged; + + DecMPA_MPEGHeader m_MPEGHeader; + + bool m_bFirstDecode; + bool m_bPrepared; + bool m_bHasFrame; + + int m_nResyncCounter; + + void* m_pDecodeEngine; + + CMPAFrameFinder m_FrameFinder; + CMPAInfo m_Info; + + bool m_bStoreID3v2; + unsigned char* m_pID3v2Data; + long m_nID3v2DataSize; + + void (*m_pDestroyNotify)(void*); + void* m_pDestroyNotifyContext; + + long m_aParams[DECMPA_PARAMCOUNT]; + + bool m_bNotMPEG; + + bool m_bDecoderNeedsFlush; +}; + +inline void CMPADecoder::SetDestroyNotify(void (*pNotify)(void*),void* pContext) +{ + m_pDestroyNotify=pNotify; + m_pDestroyNotifyContext=pContext; +} + +#endif + diff --git a/Libraries/DecMPA/Files/src/MPAFrameFinder.cpp b/Libraries/DecMPA/Files/src/MPAFrameFinder.cpp new file mode 100644 index 000000000..e6c47503d --- /dev/null +++ b/Libraries/DecMPA/Files/src/MPAFrameFinder.cpp @@ -0,0 +1,550 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#include "MPAFrameFinder.h" + +#include + +CMPAFrameFinder::CMPAFrameFinder() +{ + // max size of buffer is: + // header: 4 + // max bitrate: 448 + // min freq: 22050 + // padding: 1 + // ------------------ + // maxsize: 4+144000*max(bitrate)/min(freq)+1 ca: 2931 byte + // then we add a "sentinel" at the end these are 4 byte. + // so we should be ok, with a 4KB buffer. + m_OutBuffer.Alloc(4096); + m_OutBuffer.SetSize(4096); + + m_MyInBuffer.Alloc(65536); + + m_pFirstHeader=(HeaderRecord*)0; + m_pLastHeader=(HeaderRecord*)0; + m_pNewHeaderRecord=(HeaderRecord*)0; + + m_bStreamInvalid=false; + m_nLayer=-1; + + m_bAllowFrequencyChanges=false; + + m_nLookAheadFrames=3; //try to find 4 consistent frames by default + + m_nReadStartPosition=0; + + Restart(); +} + +CMPAFrameFinder::~CMPAFrameFinder() +{ + DeleteHeaderRecords(); +} + +bool CMPAFrameFinder::ReadNextFrame() +{ + bool bNeedMoreThanAvailable; + + if(m_State==STATE_HAVEFRAME) + ResetState(); + + while(true) + { + bNeedMoreThanAvailable=false; + while(m_State!=STATE_HAVEFRAME && m_pInBuffer->HasMoreData() && !bNeedMoreThanAvailable) + { + switch(m_State) + { + case STATE_FINDCHARACTERISTICS: if(!FindCharacteristics()) + { + //need more data, but we may still have + //up to 3 bytes buffered + //so, break manually here + bNeedMoreThanAvailable=true; + } + break; + case STATE_FINDSYNC: FindNextSync(); + break; + case STATE_READHEADER: ReadHeader(); + break; + case STATE_CHECKHEADER: CheckHeader(); + break; + case STATE_READFRAME: ReadFrame(); + break; + } + } + + if(m_State!=STATE_HAVEFRAME && m_State>=STATE_FINDSYNC && m_pInBuffer==&m_MyInBuffer) + { + //we need more data, but were still reading + //from our own preread data that was used to find out the + //stream characteristics + + //switch to user buffer (it may already contain some data) + m_pInBuffer=&m_UserInBuffer; + } + else + break; + } + + if(m_State==STATE_FINDCHARACTERISTICS && m_MyInBuffer.GetSize()==m_MyInBuffer.GetCapacity()) + { + //we have read the maximum of data and not found m_nLookAheadFrames+1 consistent + //frames + + //the stream does probably not contain valid MPEG Audio data + m_bStreamInvalid=true; + } + + return (m_State==STATE_HAVEFRAME); //otherwise we need more data +} + +bool CMPAFrameFinder::FindCharacteristics() +{ + unsigned char* pData; + + //we read up to 64k data and try to find at least + //m_nLookAheadFrames+1 frame headers that are consistent with one + //another + + while(m_MyInBuffer.GetBytesLeft()>=4) + { + pData=m_MyInBuffer.GetPosPtr(); + + if(pData[0]==0xff && (pData[1] & 0xe0)==0xe0) + { + //found sync + //parse the header + if(m_pNewHeaderRecord==(HeaderRecord*)0) + m_pNewHeaderRecord=new HeaderRecord; + + if(m_pNewHeaderRecord->Header.parseHeader(pData)) + { + if(IsValidHeader(&m_pNewHeaderRecord->Header)) + { + //seems to be a valid header. + //add the a header record to the list + + m_pNewHeaderRecord->nPosition=m_MyInBuffer.GetPos(); + m_pNewHeaderRecord->pNext=(HeaderRecord*)0; + + if(m_pLastHeader==(HeaderRecord*)0) + m_pFirstHeader=m_pLastHeader=m_pNewHeaderRecord; + else + { + m_pLastHeader->pNext=m_pNewHeaderRecord; + m_pLastHeader=m_pNewHeaderRecord; + } + m_pNewHeaderRecord=(HeaderRecord*)0; + + //check wether we have found m_nLookAheadFrames+1 consistent headers yet + if(FindConsistentHeaders()) + break; + } + } + } + + m_MyInBuffer.AddToPos(1); + } + + return (m_State>=STATE_FINDSYNC); +} + +bool CMPAFrameFinder::FindConsistentHeaders() +{ + HeaderRecord* pRecord; + + //ok, we have found some headers in the data stream + //now we try to find m_nLookAheadFrames+1 that are consistent + //and assume that they correspond to valid frames in the stream + + pRecord=m_pFirstHeader; + while(pRecord!=(HeaderRecord*)0) + { + //be prejudiced for early headers + if(!CanHaveConsistentHeaders(pRecord,m_nLookAheadFrames)) + { + //if we haven't yet read enough data to find + //consistent headers for the first headers, stop + //here + pRecord=(HeaderRecord*)0; + break; + } + + //find two headers that are consistent with this one + if(HasConsistentHeaders(pRecord,pRecord->pNext,m_nLookAheadFrames)) + break; + + pRecord=pRecord->pNext; + } + + if(pRecord!=(HeaderRecord*)0) + { + //yay! we found m_nLookAheadFrames+1 consistent headers. + //The first of them is pRecord + + //store stream characteristics + m_nLayer=pRecord->Header.getLayer(); + m_nInputStereo=pRecord->Header.getInputstereo(); + m_nFrequency=pRecord->Header.getFrequencyHz(); + m_nLayer25=pRecord->Header.getLayer25(); + m_nVersion=pRecord->Header.getVersion(); + + //set input buffer to start of first frame + m_MyInBuffer.SetPos(pRecord->nPosition); + + m_nFirstFramePosition=pRecord->nPosition+m_nReadStartPosition; + + //throw away the header records + DeleteHeaderRecords(); + + //got to next state (start extracting frame data) + m_State++; + + return true; + } + + return false; +} + +bool CMPAFrameFinder::CanHaveConsistentHeaders(CMPAFrameFinder::HeaderRecord* pRecord,int nHeaderCount) +{ + long nFirstFrameBegin; + int nFrameSize; + long nLastFrameHeaderEnd; + + nFirstFrameBegin=pRecord->nPosition; + nFrameSize=pRecord->Header.getFramesize(); + + //assume that the frames have a size difference of at most 512 bytes + //(or at most 512 bytes of data in between) + nLastFrameHeaderEnd=nFirstFrameBegin+((nFrameSize+512)*nHeaderCount)+4; + + if(m_MyInBuffer.GetPos()pNext; + } + + return false; +} + +bool CMPAFrameFinder::AreHeadersConsistent(HeaderRecord* pFirst,HeaderRecord* pSecond) +{ + //do the corresponding frames overlap? + if(pFirst->nPosition+pFirst->Header.getFramesize()>pSecond->nPosition) + return false; + + //different layers? + if(pFirst->Header.getLayer()!=pSecond->Header.getLayer()) + return false; + + //one stereo, the other not? + if(pFirst->Header.getInputstereo()!=pSecond->Header.getInputstereo()) + return false; + + //mpeg 2.5? + if(pFirst->Header.getLayer25()!=pSecond->Header.getLayer25()) + return false; + + //version? + if(pFirst->Header.getVersion()!=pSecond->Header.getVersion()) + return false; + + if(!m_bAllowFrequencyChanges) + { + if(pFirst->Header.getFrequencyHz()!=pSecond->Header.getFrequencyHz()) + return false; + } + + return true; +} + +bool CMPAFrameFinder::IsConformingHeader(MpegAudioHeader* pHeader) +{ + //check wether the header conforms with the detected stream characteristics + + if(pHeader->getInputstereo()==m_nInputStereo + && pHeader->getLayer()==m_nLayer + && pHeader->getLayer25()==m_nLayer25 + && pHeader->getVersion()==m_nVersion + && (pHeader->getFrequencyHz()==m_nFrequency || m_bAllowFrequencyChanges)) + { + return true; + } + + return false; +} + +void CMPAFrameFinder::FindNextSync() +{ + unsigned char* pOut=m_OutBuffer.GetPosPtr(); + + while(m_pInBuffer->HasMoreData()) + { + // shift + pOut[0]=pOut[1]; + pOut[1]=m_pInBuffer->ReadByte(); + + if (pOut[0] == 0xff) + { + // upper 4 bit are syncword, except bit one + // which is layer 2.5 indicator. + if ( (pOut[1] & 0xe0) == 0xe0) + { + m_OutBuffer.SetPos(2); + m_State++; + break; + } + } + } +} + +void CMPAFrameFinder::ReadHeader() +{ + while(m_pInBuffer->HasMoreData()) + { + if(m_OutBuffer.GetPos()>=4) + { + m_State++; + break; + } + + m_OutBuffer.WriteByte(m_pInBuffer->ReadByte()); + } +} + +void CMPAFrameFinder::CheckHeader() +{ + bool bHeaderOK=false; + + if(m_Header.parseHeader(m_OutBuffer.GetPtr())) + { + if(IsValidHeader(&m_Header)) + { + //make sure the header conforms to the established stream + //characteristics + if(IsConformingHeader(&m_Header)) + { + m_nFrameSize=m_Header.getFramesize(); + bHeaderOK=true; + } + } + } + + if(bHeaderOK) + m_State++; + else + ResetState(); +} + +void CMPAFrameFinder::ReadFrame() +{ + int nBytesNeeded; + int nBytesAvailable; + int nCopyBytes; + + do + { + nBytesNeeded=m_nFrameSize-m_OutBuffer.GetPos(); + nBytesAvailable=m_pInBuffer->GetSize()-m_pInBuffer->GetPos(); + + nCopyBytes=(nBytesAvailableGetPosPtr(),nCopyBytes); + m_OutBuffer.AddToPos(nCopyBytes); + m_pInBuffer->AddToPos(nCopyBytes); + + if(nBytesNeeded==nCopyBytes) + { + m_State++; + break; + } + } + while(m_pInBuffer->HasMoreData()); +} + +void CMPAFrameFinder::SetInput(void* pBuffer,int nBufferBytes,long nStreamPosition) +{ + if(m_State==STATE_FINDCHARACTERISTICS) + { + int nCopyBytes=m_MyInBuffer.GetCapacity()-m_MyInBuffer.GetSize(); + + //copy it in into our own buffer + if(nCopyBytes>nBufferBytes) + nCopyBytes=nBufferBytes; + + if(m_MyInBuffer.GetSize()==0) + m_nReadStartPosition=nStreamPosition; + + memcpy(m_MyInBuffer.GetPtr()+m_MyInBuffer.GetSize(),pBuffer,nCopyBytes); + m_MyInBuffer.SetSize(m_MyInBuffer.GetSize()+nCopyBytes); + + pBuffer=((unsigned char*)pBuffer)+nCopyBytes; + nBufferBytes-=nCopyBytes; + + //attach the rest to the user buffer + } + + m_UserInBuffer.Attach(pBuffer,nBufferBytes); +} + +bool CMPAFrameFinder::ReadInput(IFileAccess* pFileAccess) +{ + int nResult; + + if(m_State==STATE_FINDCHARACTERISTICS) + { + int nFree=m_MyInBuffer.GetCapacity()-m_MyInBuffer.GetSize(); + + //read data into our own buffer + if(nFree>0) + { + //read in small chunks + if(nFree>4096) + nFree=4096; + + if(m_MyInBuffer.GetSize()==0) //first input + m_nReadStartPosition=pFileAccess->GetPosition(); + + nResult=pFileAccess->Read((char*)m_MyInBuffer.GetPtr()+m_MyInBuffer.GetSize(),nFree); + if(nResult<=0) + return false; + + m_MyInBuffer.SetSize(m_MyInBuffer.GetSize()+nResult); + } + } + else + { + if(m_UserInBuffer.IsAttached()) + m_UserInBuffer.Alloc(4096); + + nResult=pFileAccess->Read((char*)m_UserInBuffer.GetPtr(),m_UserInBuffer.GetCapacity()); + if(nResult<=0) + return false; + + m_UserInBuffer.SetSize(nResult); + m_UserInBuffer.SetPos(0); + } + + return true; +} + +void CMPAFrameFinder::Flush() +{ + ResetState(); + + m_UserInBuffer.SetSize(0); + m_MyInBuffer.SetSize(0); + + DeleteHeaderRecords(); +} + +void CMPAFrameFinder::ResetState() +{ + m_OutBuffer.SetPos(0); + + //make sure that we do not accidentally treat + //"leftover" data in the buffer as a sync mark + m_OutBuffer.GetPtr()[0]=0; + m_OutBuffer.GetPtr()[1]=0; + + if(m_State>=STATE_FINDSYNC) + m_State=STATE_FINDSYNC; +} + +void CMPAFrameFinder::Restart() +{ + Flush(); + + m_State=STATE_FINDCHARACTERISTICS; + m_pInBuffer=&m_MyInBuffer; + + m_bStreamInvalid=false; + + m_nFirstFramePosition=0; +} + +void CMPAFrameFinder::DeleteHeaderRecords() +{ + HeaderRecord* pRecord; + + while(m_pFirstHeader!=(HeaderRecord*)0) + { + pRecord=m_pFirstHeader; + m_pFirstHeader=m_pFirstHeader->pNext; + + delete pRecord; + } + + m_pLastHeader=(HeaderRecord*)0; + + if(m_pNewHeaderRecord!=(HeaderRecord*)0) + { + delete m_pNewHeaderRecord; + m_pNewHeaderRecord=(HeaderRecord*)0; + } +} + +bool CMPAFrameFinder::IsValidHeader(MpegAudioHeader* pHeader) +{ + int nFrameSize; + + nFrameSize=pHeader->getFramesize(); + + // don't allow stupid framesizes: + // if framesize <4 or > max mepg framsize its an error + if(nFrameSize<4 || nFrameSize+4>4096) + return false; + + if(pHeader->GetBitRateKbps()==0) + { + //skip frames with bitrate 0 (empty) + return false; + } + + return true; +} + + + diff --git a/Libraries/DecMPA/Files/src/MPAFrameFinder.h b/Libraries/DecMPA/Files/src/MPAFrameFinder.h new file mode 100644 index 000000000..e68849279 --- /dev/null +++ b/Libraries/DecMPA/Files/src/MPAFrameFinder.h @@ -0,0 +1,201 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#ifndef _MPAFRAMEFINDER_H_ +#define _MPAFRAMEFINDER_H_ + +#include "IFileAccess.h" +#include "mpegAudioFrame/mpegAudioHeader.h" + +#include "MemBuffer.h" + +class CMPAFrameFinder +{ +public: + CMPAFrameFinder(); + ~CMPAFrameFinder(); + + inline void SetLookAheadFrames(int nFrames); + inline void SetAllowFrequencyChanges(bool bAllow); + + inline int GetLookAheadFrames(); + inline bool GetAllowFrequencyChanges(); + + //if false, the finder needs more input data or the stream + //invalid + bool ReadNextFrame(); + + inline bool IsStreamInvalid(); + inline bool KnowsCharacteristics(); + + inline bool HasFrame(); + inline void* GetFrameData(); + inline int GetFrameSize(); + inline double GetAvgFrameSize(); + inline MpegAudioHeader* GetFrameHeader(); + + void SetInput(void* pBuffer,int nBytes,long nStreamPosition); + bool ReadInput(IFileAccess* pAccess); + + //throw away buffered data and find next frame + void Flush(); + + //start with a completely blank slate for a new data stream + void Restart(); + + inline long GetFirstFramePosition(); + +protected: + struct HeaderRecord + { + MpegAudioHeader Header; + long nPosition; + + HeaderRecord* pNext; + }; + + bool FindCharacteristics(); + bool FindConsistentHeaders(); + bool CanHaveConsistentHeaders(HeaderRecord* pRecord,int nHeaderCount); + bool HasConsistentHeaders(HeaderRecord* pCheckRecord,HeaderRecord* pRecord,int nHeadersNeeded); + bool AreHeadersConsistent(HeaderRecord* pFirst,HeaderRecord* pSecond); + + bool IsConformingHeader(MpegAudioHeader* pHeader); + + void FindNextSync(); + void ReadHeader(); + void CheckHeader(); + void ReadFrame(); + + void ResetState(); + + void DeleteHeaderRecords(); + + static bool IsValidHeader(MpegAudioHeader* pHeader); + + CMemBuffer m_OutBuffer; + + CMemBuffer* m_pInBuffer; + CMemBuffer m_MyInBuffer; + CMemBuffer m_UserInBuffer; + + int m_State; + + int m_nLookAheadFrames; + bool m_bAllowFrequencyChanges; + + int m_nLayer; + int m_nInputStereo; + int m_nFrequency; + int m_nLayer25; + int m_nVersion; + + MpegAudioHeader m_Header; + int m_nFrameSize; + + long m_nReadStartPosition; + long m_nFirstFramePosition; + + enum + { + STATE_FINDCHARACTERISTICS=0, + STATE_FINDSYNC, + STATE_READHEADER, + STATE_CHECKHEADER, + STATE_READFRAME, + + STATE_HAVEFRAME + }; + + HeaderRecord* m_pFirstHeader; + HeaderRecord* m_pLastHeader; + + HeaderRecord* m_pNewHeaderRecord; + + bool m_bStreamInvalid; +}; + +inline void CMPAFrameFinder::SetLookAheadFrames(int nFrames) +{ + if(nFrames<0) + nFrames=0; + + m_nLookAheadFrames=nFrames; +} + +inline void CMPAFrameFinder::SetAllowFrequencyChanges(bool bAllow) +{ + m_bAllowFrequencyChanges=bAllow; +} + +inline int CMPAFrameFinder::GetLookAheadFrames() +{ + return m_nLookAheadFrames; +} + +inline bool CMPAFrameFinder::GetAllowFrequencyChanges() +{ + return m_bAllowFrequencyChanges; +} + +inline bool CMPAFrameFinder::HasFrame() +{ + return (m_State==STATE_HAVEFRAME); +} + +inline void* CMPAFrameFinder::GetFrameData() +{ + return m_OutBuffer.GetPtr(); +} + +inline int CMPAFrameFinder::GetFrameSize() +{ + return m_OutBuffer.GetPos(); +} + +inline double CMPAFrameFinder::GetAvgFrameSize() +{ + return m_Header.GetAvgFrameSize(); +} + +inline MpegAudioHeader* CMPAFrameFinder::GetFrameHeader() +{ + return &m_Header; +} + +inline bool CMPAFrameFinder::IsStreamInvalid() +{ + return m_bStreamInvalid; +} + +inline bool CMPAFrameFinder::KnowsCharacteristics() +{ + return (m_State>STATE_FINDCHARACTERISTICS); +} + +inline long CMPAFrameFinder::GetFirstFramePosition() +{ + return m_nFirstFramePosition; +} + +#endif diff --git a/Libraries/DecMPA/Files/src/MPAInfo.cpp b/Libraries/DecMPA/Files/src/MPAInfo.cpp new file mode 100644 index 000000000..804212826 --- /dev/null +++ b/Libraries/DecMPA/Files/src/MPAInfo.cpp @@ -0,0 +1,200 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#include "MPAInfo.h" + +CMPAInfo::CMPAInfo() +{ + m_nEncodedDataSize=-1; + m_nEncodedDataOffset=0; + m_nDuration=-1; + m_bXingVBR=false; + + m_XingHeader.toc=m_aXingTOC; +} + +CMPAInfo::~CMPAInfo() +{ +} + +bool CMPAInfo::InitInfo(CMPAFrameFinder* pFrameFinder,IFileAccess* pFileAccess) +{ + m_nEncodedDataSize=-1; + m_nEncodedDataOffset=0; + m_nDuration=-1; + m_bXingVBR=false; + + while(!pFrameFinder->ReadNextFrame()) + { + if(pFrameFinder->IsStreamInvalid()) + return false; + + if(!pFrameFinder->ReadInput(pFileAccess)) + return false; + } + + m_nEncodedDataOffset=pFrameFinder->GetFirstFramePosition(); + + m_nEncodedDataSize=pFileAccess->GetLength(); + if(m_nEncodedDataSize!=-1) + { + //ignore any leading non-MPEG-Audio data + m_nEncodedDataSize-=m_nEncodedDataOffset; + } + + Init(pFrameFinder); + + return true; +} + +void CMPAInfo::Init(CMPAFrameFinder* pFrameFinder) +{ + double nAvgFrameSize; + int nFrameSize; + long nFrameCount=-1; + + nAvgFrameSize=pFrameFinder->GetAvgFrameSize(); + nFrameSize=pFrameFinder->GetFrameSize(); + if(nAvgFrameSize>0) + { + if(ReadXingHeader(pFrameFinder->GetFrameData(),nFrameSize)) + { + m_bXingVBR=true; + nFrameCount=m_XingHeader.frames; + } + else + { + if(m_nEncodedDataSize>=0) + nFrameCount=(long)(m_nEncodedDataSize/nAvgFrameSize); + } + } + + if(nFrameCount!=-1) + { + MpegAudioHeader* pHeader=pFrameFinder->GetFrameHeader(); + int nDecodedSamplesPerFrame; + int nFrequency; + double nDecodedSamples; + + nDecodedSamplesPerFrame=pHeader->getpcmperframe(); + nFrequency=pHeader->getFrequencyHz(); + + nDecodedSamples=((double)nFrameCount)*nDecodedSamplesPerFrame; + + if(nFrequency!=0) + m_nDuration=(long)((nDecodedSamples*1000)/nFrequency); + } +} + +bool CMPAInfo::ReadXingHeader(void* pFrameData,int nFrameSize) +{ + if(nFrameSize<152) //cannot have xing header + return false; + + if(::GetXingHeader(&m_XingHeader,(unsigned char*)pFrameData)==0) + return false; + + //we use floats so that we won't loose precision + //with the un-compensation stuff below + for(int i=0;i<100;i++) + m_aTOC[i]=((float)m_XingHeader.toc[i])/256.0f; + m_aTOC[100]=1.0f; + + if(m_aTOC[0]!=0) + { + //the Xing table of contents compensates for some + //leading non-MP3 data (maybe an ID3 tag or something) + //Since that data may never have been passed to the library + //(or if it has been passed, it should have been skipped) + //we undo this compensation + float FullSizeValue; + + FullSizeValue=1.0f-m_aTOC[0]; + + for(int i=100;i>=0;i--) + m_aTOC[i]=(m_aTOC[i]-m_aTOC[0])/FullSizeValue; + } + + return true; +} + +long CMPAInfo::GetFilePositionFromTime(long Millis) +{ + long nPos=-1; + double nTimeFraction; + + if(m_nDuration>0 && m_nEncodedDataSize>=0) + { + nTimeFraction=((double)Millis)/m_nDuration; + + if(m_bXingVBR) + { + nPos=GetEncodedDataPositionFromTOC((float)nTimeFraction); + + if(nPos>=m_nEncodedDataSize) + nPos=m_nEncodedDataSize; + } + else + nPos=(long)(nTimeFraction*m_nEncodedDataSize); + } + + if(nPos==-1) + { + //ok, we couldn't find the correct position because + //we don't know enough about the stream + + //however, ONE position we know: the beginning + if(Millis==0) + nPos=0; + } + + nPos+=m_nEncodedDataOffset; + + return nPos; +} + +long CMPAInfo::GetEncodedDataPositionFromTOC(float TimeFract) +{ + // interpolate in TOC to get file seek point in bytes + int nTOCIndex; + float LowerPosFract; + float UpperPosFract; + float PosFract; + float Percent=TimeFract*100.0f; + + if(Percent<0.0f) + Percent=0.0f; + if(Percent>100.0f) + Percent=100.0f; + + nTOCIndex=(int)Percent; + if(nTOCIndex>99) + nTOCIndex=99; + LowerPosFract=m_aTOC[nTOCIndex]; + UpperPosFract=m_aTOC[nTOCIndex+1]; + + PosFract=LowerPosFract + ((UpperPosFract-LowerPosFract)*(Percent-nTOCIndex)); + + return (long)(PosFract*m_nEncodedDataSize); +} + diff --git a/Libraries/DecMPA/Files/src/MPAInfo.h b/Libraries/DecMPA/Files/src/MPAInfo.h new file mode 100644 index 000000000..39a065eb0 --- /dev/null +++ b/Libraries/DecMPA/Files/src/MPAInfo.h @@ -0,0 +1,81 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#ifndef _MPAINFO_H_ +#define _MPAINFO_H_ + +#include "IFileAccess.h" +#include "MPAFrameFinder.h" +#include "mpegAudioFrame/dxHead.h" + +class CMPAInfo +{ +public: + CMPAInfo(); + ~CMPAInfo(); + + bool InitInfo(CMPAFrameFinder* pFrameFinder,IFileAccess* pFileAccess); + + //-1 if unknown + inline long GetDuration(); + + //-1 if unknown + long GetFilePositionFromTime(long Millis); + + inline bool IsXingVBR(); + inline XHEADDATA* GetXingHeader(); + +protected: + void Init(CMPAFrameFinder* pFrameFinder); + bool ReadXingHeader(void* pFrameData,int nFrameSize); + long GetEncodedDataPositionFromTOC(float TimeFract); + + long m_nEncodedDataSize; + long m_nEncodedDataOffset; + + long m_nDuration; + + bool m_bXingVBR; + XHEADDATA m_XingHeader; + unsigned char m_aXingTOC[100]; + + float m_aTOC[101]; +}; + +inline long CMPAInfo::GetDuration() +{ + return m_nDuration; +} + +inline bool CMPAInfo::IsXingVBR() +{ + return m_bXingVBR; +} + +inline XHEADDATA* CMPAInfo::GetXingHeader() +{ + return &m_XingHeader; +} + + +#endif diff --git a/Libraries/DecMPA/Files/src/MemBuffer.h b/Libraries/DecMPA/Files/src/MemBuffer.h new file mode 100644 index 000000000..4c20165a4 --- /dev/null +++ b/Libraries/DecMPA/Files/src/MemBuffer.h @@ -0,0 +1,157 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#ifndef _MEMBUFFER_H_ +#define _MEMBUFFER_H_ + +class CMemBuffer +{ +public: + inline CMemBuffer() + { + m_pBuffer=(unsigned char*)0; + m_nSize=0; + m_nCapacity=0; + m_bAllocated=false; + m_nPos=0; + } + + inline ~CMemBuffer() + { + Free(); + } + + inline void Alloc(int nBytes) + { + Free(); + if(nBytes>0) + { + m_pBuffer=new unsigned char[nBytes]; + m_bAllocated=true; + } + m_nCapacity=nBytes; + } + + inline void Free() + { + if(m_bAllocated) + delete[] m_pBuffer; + Detach(); + } + + inline void Attach(void* pMem,int nBytes) + { + Free(); + m_pBuffer=(unsigned char*)pMem; + m_nSize=nBytes; + m_nCapacity=nBytes; + } + + inline void Detach() + { + m_pBuffer=(unsigned char*)0; + m_nSize=0; + m_nCapacity=0; + m_bAllocated=false; + m_nPos=0; + } + + inline int GetPos() + { + return m_nPos; + } + + inline void SetPos(int Pos) + { + m_nPos=Pos; + } + + inline void AddToPos(int Add) + { + m_nPos+=Add; + } + + inline unsigned char ReadByte() + { + return m_pBuffer[m_nPos++]; + } + + inline void WriteByte(unsigned char Value) + { + m_pBuffer[m_nPos++]=Value; + } + + inline int GetSize() + { + return m_nSize; + } + + inline int GetCapacity() + { + return m_nCapacity; + } + + inline int GetBytesLeft() + { + return m_nSize-m_nPos; + } + + inline void SetSize(int nSize) + { + if(nSize>m_nCapacity) + nSize=m_nCapacity; + m_nSize=nSize; + if(m_nPos>m_nSize) + m_nPos=m_nSize; + } + + inline unsigned char* GetPosPtr() + { + return &m_pBuffer[m_nPos]; + } + + inline unsigned char* GetPtr() + { + return m_pBuffer; + } + + inline bool IsAttached() + { + return !m_bAllocated; + } + + inline bool HasMoreData() + { + return m_nPosstereo=stereo; + this->frequencyHZ=freq; +} + + + +int AudioFrame::isFormatEqual(AudioFrame* compare) { + if(compare->getStereo() != stereo) { + return false; + } + if(compare->getSampleSize() != sampleSize) { + return false; + } + if(compare->getBigEndian() != lBigEndian) { + return false; + } + if(compare->getFrequenceHZ() != frequencyHZ) { + return false; + } + if(compare->getSigned() != lSigned) { + return false; + } + return true; +} + +void AudioFrame::print(const char* msg) { + /*cout << "PCMFrame::print:"<getFrameType() != _FRAME_AUDIO_BASE) { + // cout << "cannot copy frameFormat into frametype!= _FRAME_AUDIO_BASE"<setFrameFormat(getStereo(),getFrequenceHZ()); + dest->sampleSize=getSampleSize(); + dest->lBigEndian=getBigEndian(); + dest->lSigned=getSigned(); +} diff --git a/Libraries/DecMPA/Files/src/frame/audioFrame.h b/Libraries/DecMPA/Files/src/frame/audioFrame.h new file mode 100644 index 000000000..2a8aedf6b --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/audioFrame.h @@ -0,0 +1,85 @@ +/* + abstract definition of an audio frame + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + + + +#ifndef __AUDIOFRAME_H +#define __AUDIOFRAME_H + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef WORDS_BIGENDIAN +#define AUDIOFRAME_BIGENDIAN 1 +#else +#define AUDIOFRAME_BIGENDIAN 0 +#endif + +#include "frame.h" + +#define SCALFACTOR SHRT_MAX +#define MP3FRAMESIZE (2*2*2*32*18) + + +class AudioFrame : public Frame { + + int stereo; + int frequencyHZ; + + public: + AudioFrame(); + virtual ~AudioFrame(); + + // info about "import" data + void setFrameFormat(int stereo,int freq); + + inline int getStereo() { return stereo; } + inline int getFrequenceHZ() { return frequencyHZ; } + + // these return values depend on the implementation + // how the data is stored internally after "import" + inline int getSampleSize() { return sampleSize; } + inline int getBigEndian() { return lBigEndian; } + inline int getSigned() { return lSigned; } + + // info about output + virtual int getLen(); + virtual void setLen(int len); + virtual int getSize(); + virtual void clearrawdata(); + + // data import + virtual void putFloatData(float* data,int len); + virtual void putFloatData(float* left,float* right,int len); + + virtual void putInt16Data(short* pdata,int nLength); + + virtual void putSilence(int nLength); + + int isFormatEqual(AudioFrame* compare); + // Note: this can only be called with _real_ AudioFrame's as dest + void copyFormat(AudioFrame* dest); + + void print(const char* msg); + + protected: + int sampleSize; + int lBigEndian; + int lSigned; + +}; + + +#endif diff --git a/Libraries/DecMPA/Files/src/frame/floatFrame.cpp b/Libraries/DecMPA/Files/src/frame/floatFrame.cpp new file mode 100644 index 000000000..d94b57363 --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/floatFrame.cpp @@ -0,0 +1,71 @@ +/* + stores frames as floats. + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - removed cout and exit stuff +// - added #include to ensure that bad_alloc will be thrown on mem error + +#include "floatFrame.h" + +#include +#include + + +FloatFrame::FloatFrame(int size) { + data=new float[size]; + len=0; + this->size=size; + this->sampleSize=sizeof(float)*8; + this->lSigned=true; + this->lBigEndian=AUDIOFRAME_BIGENDIAN; + setFrameType(_FRAME_AUDIO_FLOAT); +} + + +FloatFrame::~FloatFrame() { + delete data; +} + + +void FloatFrame::putFloatData(float* in,int lenCopy) { + //if ((len+lenCopy) > size) { + // cout << "cannot copy putFloatData. Does not fit"<len=len; } + int getSize() { return size; } + float* getData() { return data; } + + void putFloatData(float* data,int len); + void putFloatData(float* left,float* right,int len); + + void putInt16Data(short* pdata,int nLength); + void putSilence(int nLength); + + void clearrawdata() { len=0; } + + + +}; +#endif diff --git a/Libraries/DecMPA/Files/src/frame/frame.cpp b/Libraries/DecMPA/Files/src/frame/frame.cpp new file mode 100644 index 000000000..a42c802f6 --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/frame.cpp @@ -0,0 +1,73 @@ +/* + base class for frames + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + + +#include "frame.h" + + +Frame::Frame() { + type=_FRAME_UNK; +} + + +Frame::~Frame() { +} + + +const char* Frame::getMajorFrameName(int type) { + int majorID=type >> 12; + switch(majorID) { + case _FRAME_UNK: + return "_FRAME_UNK"; + case _FRAME_RAW: + return "_FRAME_RAW"; + case _FRAME_AUDIO: + return "_FRAME_AUDIO"; + case _FRAME_VIDEO: + return "_FRAME_VIDEO"; + case _FRAME_PAKET: + return "_FRAME_PAKET"; + default: + return "unknown major frameType"; + } + return "never happens Frame::getMajorFrameName"; +} + + + +const char* Frame::getFrameName(int type) { + switch(type) { + // Raw + case _FRAME_RAW_BASE: + return "_FRAME_RAW_BASE"; + case _FRAME_RAW_OGG: + return "_FRAME_RAW_OGG"; + + + // Audio + case _FRAME_AUDIO_BASE: + return "_FRAME_AUDIO_BASE"; + case _FRAME_AUDIO_PCM: + return "_FRAME_AUDIO_PCM"; + case _FRAME_AUDIO_FLOAT: + return "_FRAME_AUDIO_FLOAT"; + + + + // Rest + default: + return "cannot find name"; + } + return "never happens Frame::getFrameName"; +} + diff --git a/Libraries/DecMPA/Files/src/frame/frame.h b/Libraries/DecMPA/Files/src/frame/frame.h new file mode 100644 index 000000000..426a27f94 --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/frame.h @@ -0,0 +1,103 @@ +/* + base class for frames + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/11/2002 (by Hauke Duden): +// - removed unnecessary includes + +#ifndef __FRAME_H +#define __FRAME_H + + +//#include +//#include +//#include +//#include +//#include + + + +/** + The base class for frames. Every derived class from this class + must belong to some "major" class type and it must have an unique + id for itsself. Even if it is a base class it must have a unique id. + + How does this work. We have an int for the Frame id. In the int + itsself we but the majorid as well. + The Start codes are all multiple of 2 so for example + 0..127 belongs to FRAME UNK + 128..255 belongs to FRAME RAW + + So we can with a simple shift operation find out the major class +*/ +#define _FRAME_SHIFT 7 +#define _FRAME_ID_MAX 128 //(2^_FRAME_SHIFT) + + +// Major Frame classes +#define _FRAME_UNK 0 +#define _FRAME_RAW 1 +#define _FRAME_AUDIO 2 +#define _FRAME_VIDEO 3 +#define _FRAME_PAKET 4 + +// start ids of minor classes + +#define _FRAME_UNK_START (0) +#define _FRAME_RAW_START (_FRAME_ID_MAX) +#define _FRAME_AUDIO_START (_FRAME_ID_MAX*2) +#define _FRAME_VIDEO_START (_FRAME_ID_MAX*2*2) +#define _FRAME_PAKET_START (_FRAME_ID_MAX*2*2*2) + +// Minor Frame type IDs + + +// Raw +#define _FRAME_RAW_BASE (_FRAME_RAW_START+1) +#define _FRAME_RAW_OGG (_FRAME_RAW_START+2) +#define _FRAME_RAW_MPEG_I_VIDEO (_FRAME_RAW_START+3) +#define _FRAME_RAW_MPEG_SYSTEM (_FRAME_RAW_START+4) + + +// Audio: +#define _FRAME_AUDIO_BASE (_FRAME_AUDIO_START+1) +#define _FRAME_AUDIO_PCM (_FRAME_AUDIO_START+2) +#define _FRAME_AUDIO_FLOAT (_FRAME_AUDIO_START+3) + +// Video: +#define _FRAME_VIDEO_BASE (_FRAME_VIDEO_START+1) +#define _FRAME_VIDEO_YUV (_FRAME_VIDEO_START+2) +#define _FRAME_VIDEO_RGB_8 (_FRAME_VIDEO_START+3) +#define _FRAME_VIDEO_RGB_16 (_FRAME_VIDEO_START+4) +#define _FRAME_VIDEO_RGB_32 (_FRAME_VIDEO_START+5) + +// Packet: +#define _FRAME_PACKET_SYNC (_FRAME_PAKET_START+1) +#define _FRAME_PACKET_PACKET_CONTAINER (_FRAME_PAKET_START+2) + + + + +class Frame { + int type; + + public: + Frame(); + ~Frame(); + inline int getMajorFrameType() { return (type>>_FRAME_SHIFT);} + inline int getFrameType() { return type; } + inline void setFrameType(int type) { this->type=type; } + + + static const char* getMajorFrameName(int type); + static const char* getFrameName(int type); +}; +#endif diff --git a/Libraries/DecMPA/Files/src/frame/pcmFrame.cpp b/Libraries/DecMPA/Files/src/frame/pcmFrame.cpp new file mode 100644 index 000000000..d0fec8e41 --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/pcmFrame.cpp @@ -0,0 +1,143 @@ +/* + pcm frame description. + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - removed cout and exit stuff +// - added #include to ensure that bad_alloc will be thrown on mem error + +#include "pcmFrame.h" +#include + +#include +#include + +#include + +//anscheinend ist die range der Werte -1,1 +/*#define convMacro(in,dtemp,tmp) \ + tmp=(int)(in[0]*32768*0.9f); \ + in++; \ + if(tmp>32767) \ + tmp=32767; \ + else if(tmp<-32768) \ + tmp=-32768;*/ + + +#define convMacro(in,dtemp,tmp) \ + in[0]*=SCALFACTOR; \ + dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0))+(in[0]); \ + tmp = ((*(int *)&dtemp) - 0x80000000); \ + in++; \ + if(tmp>32767) { \ + tmp=32767; \ + } else if (tmp<-32768) { \ + tmp =-0x8000; \ + } + + + +PCMFrame::PCMFrame(int size) { + data=new short int[size]; + len=0; + this->size=size; + // this format has a sampleSize of 16, signed, endian==machine + this->sampleSize=sizeof(short int)*8; + this->lSigned=true; + this->lBigEndian=AUDIOFRAME_BIGENDIAN; + setFrameType(_FRAME_AUDIO_PCM); +} + + +PCMFrame::~PCMFrame() { + delete data; +} + + +void PCMFrame::putFloatData(float* left,float* right,int copyLen) { + int destSize=0; + if (left != NULL) destSize++; + if (right != NULL) destSize++; + destSize*=copyLen; + /*if ((len+destSize) > size) { + cout << "cannot copy putFloatData L/R version . Does not fit"< 0) { + convMacro(left,dtemp,tmp); + data[len++]=(short int)tmp; + convMacro(right,dtemp,tmp); + data[len++]=(short int)tmp; + i--; + } + break; + case 0: + if (left != NULL) { + int i=copyLen; + while(i > 0) { + convMacro(left,dtemp,tmp); + data[len++]=(short int)tmp; + i--; + // right channel empty + len++; + } + } + if (right != NULL) { + int i=copyLen; + len=len-destSize; + while(i > 0) { + // select right channel + len++; + convMacro(right,dtemp,tmp); + data[len++]=(short int)tmp; + i--; + // left channel already copied + } + } + default: + /*cout << "unknown stereo value in pcmFrame"< size) { + cout << "cannot copy putFloatData. Does not fit"< 0) { + convMacro(in,dtemp,tmp); + data[len++]=(short int)tmp; + lenCopy--; + } + +} + +void PCMFrame::putInt16Data(short* pData,int nLength) +{ + memcpy(data,pData,nLength*sizeof(short)); + len=nLength; +} + +void PCMFrame::putSilence(int nLength) +{ + memset(data,0,nLength*sizeof(short)); + len=nLength; +} diff --git a/Libraries/DecMPA/Files/src/frame/pcmFrame.h b/Libraries/DecMPA/Files/src/frame/pcmFrame.h new file mode 100644 index 000000000..eb84a797e --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/pcmFrame.h @@ -0,0 +1,50 @@ +/* + pcm frame description. + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + + +#ifndef __PCMFRAME_H +#define __PCMFRAME_H + + +#include "audioFrame.h" + +// this format has a sampleSize of 16, signed, endian==machine + +class PCMFrame : public AudioFrame { + + short int* data; + int len; + int size; + + public: + PCMFrame(int size); + ~PCMFrame(); + + int getLen() { return len; } + void setLen(int len) { this->len=len; } + int getSize() { return size; } + short int* getData() { return data; } + + void putFloatData(float* data,int len); + void putFloatData(float* left,float* right,int len); + + void putInt16Data(short* pdata,int nLength); + + void putSilence(int nLength); + + + void clearrawdata() { len=0; } + + +}; +#endif diff --git a/Libraries/DecMPA/Files/src/frame/rawDataBuffer.cpp b/Libraries/DecMPA/Files/src/frame/rawDataBuffer.cpp new file mode 100644 index 000000000..b14247826 --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/rawDataBuffer.cpp @@ -0,0 +1,21 @@ +/* + stores simple buffer information. does not allocate anything + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + +#include "rawDataBuffer.h" + +// hm + +RawDataBuffer::~RawDataBuffer() { +} + + diff --git a/Libraries/DecMPA/Files/src/frame/rawDataBuffer.h b/Libraries/DecMPA/Files/src/frame/rawDataBuffer.h new file mode 100644 index 000000000..bcfbb7c13 --- /dev/null +++ b/Libraries/DecMPA/Files/src/frame/rawDataBuffer.h @@ -0,0 +1,48 @@ +/* + stores simple buffer information. does not allocate anything + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + + +#ifndef __RAWDATABUFFER_H +#define __RAWDATABUFFER_H + + +class RawDataBuffer { + + int _size; + unsigned char* _ptr; + int _pos; + + public: + RawDataBuffer(unsigned char* ptr,int size) { set(ptr,size,0); } + ~RawDataBuffer(); + + + + unsigned char* ptr() { return _ptr; } + unsigned char* current() { return _ptr+_pos; } + int size() { return _size; } + int pos() { return _pos; } + int untilend() { return _size-_pos; } + int eof() { return _pos>=_size; } + + void inc() { this->_pos++; } + void inc(int val) { this->_pos+=val; } + void setpos(int val) { this->_pos=val; } + void setptr(unsigned char* ptr) { this->_ptr=ptr; } + void setsize(int size) { this->_size=size; } + + void set(unsigned char* ptr, + int size,int pos) { setpos(pos);setptr(ptr);setsize(size);} + +}; +#endif diff --git a/Libraries/DecMPA/Files/src/hip/DecodeEngine_Hip.cpp b/Libraries/DecMPA/Files/src/hip/DecodeEngine_Hip.cpp new file mode 100644 index 000000000..fbe487cd6 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/DecodeEngine_Hip.cpp @@ -0,0 +1,135 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + + +#include +#include "interface.h" + +#include "../DecodeEngine.h" + +#include "../frame/pcmFrame.h" + +#include + +extern const long freqs[9]; + +struct DecodeEngine +{ + MPSTR Decoder; + short aTempBuffer[MP3FRAMESIZE*2]; +}; + +void* DecodeEngine_Create() +{ + DecodeEngine* pEngine=new DecodeEngine; + + if(!InitMP3(&pEngine->Decoder)) + { + delete pEngine; + pEngine=(DecodeEngine*)0; + } + + return pEngine; +} + +void DecodeEngine_Destroy(void* pEng) +{ + DecodeEngine* pEngine=(DecodeEngine*)pEng; + + ExitMP3(&pEngine->Decoder); + + delete pEngine; +} + +bool DecodeEngine_Decode(void* pEng,AudioFrame* pDest,void* pData,long nDataLength) +{ + DecodeEngine* pEngine=(DecodeEngine*)pEng; + int nDone; + int nResult; + char* pOut; + int nOutSize; + int nChannels; + + if(pDest->getFrameType()==_FRAME_AUDIO_PCM) + { + pOut=(char*)((PCMFrame*)pDest)->getData(); + nOutSize=pDest->getSize(); + } + else + { + pOut=(char*)pEngine->aTempBuffer; + nOutSize=sizeof(pEngine->aTempBuffer)/sizeof(short); + } + + nResult=decodeMP3(&pEngine->Decoder,(unsigned char*)pData,nDataLength,pOut,nOutSize,&nDone); + if(nResult==MP3_OK) + { + nDone/=sizeof(short); + nChannels=pEngine->Decoder.fr.stereo; + + if(pDest->getFrameType()!=_FRAME_AUDIO_PCM) + pDest->putInt16Data((short*)pOut,nDone); + else + pDest->setLen(nDone); + + pDest->setFrameFormat((nChannels==2) ? 1 : 0,freqs[pEngine->Decoder.fr.sampling_frequency]); + + return true; + } + else if(nResult==MP3_NEED_MORE) + { + //should never happen otherwise because only whole frames + //are passed to HIP and the modified version of HIP we use + //here does not buffer data from the beginning for later use + + //not critical, though + + pDest->setLen(0); + pDest->setFrameFormat(1,44100); + + return true; + } + else + { + //error + return false; + } +} + +void DecodeEngine_Flush(void* pEng) +{ + DecodeEngine* pEngine=(DecodeEngine*)pEng; + + //complete reinit + ExitMP3(&pEngine->Decoder); + InitMP3(&pEngine->Decoder); + + /*while(pEngine->Decoder.tail!=NULL) + remove_buf(&pEngine->Decoder); + pEngine->Decoder.bsize=0; + + pEngine->Decoder.header_parsed=0; + pEngine->Decoder.side_parsed=0; + pEngine->Decoder.data_parsed=0; + pEngine->Decoder.sync_bitstream=1;*/ +} diff --git a/Libraries/DecMPA/Files/src/hip/HIPDefines.h b/Libraries/DecMPA/Files/src/hip/HIPDefines.h new file mode 100644 index 000000000..2e33badfa --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/HIPDefines.h @@ -0,0 +1,10 @@ +#ifndef _HIPDEFINES_H_ +#define _HIPDEFINES_H_ + +#define NOANALYSIS +#define USE_LAYER_1 +#define USE_LAYER_2 + +#define MPEG1 + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/VbrTag.c b/Libraries/DecMPA/Files/src/hip/VbrTag.c new file mode 100644 index 000000000..070ed58d1 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/VbrTag.c @@ -0,0 +1,176 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +#include "VbrTag.h" +#include + +/* stuff from lame's tables.c */ +const int bitrate_table [3] [16] = { + { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1 }, + { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1 }, + { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1 }, +}; + +const int samplerate_table [3] [4] = { + { 22050, 24000, 16000, -1 }, /* MPEG 2 */ + { 44100, 48000, 32000, -1 }, /* MPEG 1 */ + { 11025, 12000, 8000, -1 }, /* MPEG 2.5 */ +}; +/* end stuff from lame's tables.c */ + + +/* stuff from VbrTag.c/.h */ +const static char VBRTag[]={"Xing"}; +const static char VBRTag2[]={"Info"}; + +/* from lame's VbrTag.c */ +static int +ExtractI4(unsigned char *buf) +{ + int x; + /* big endian extract */ + x = buf[0]; + x <<= 8; + x |= buf[1]; + x <<= 8; + x |= buf[2]; + x <<= 8; + x |= buf[3]; + return x; +} + +/* from lame's VbrTag.c */ +int +GetVbrTag(VBRTAGDATA *pTagData, unsigned char *buf) +{ + int i, head_flags; + int h_bitrate,h_id, h_mode, h_sr_index; + int enc_delay,enc_padding; + + /* get Vbr header data */ + pTagData->flags = 0; + + /* get selected MPEG header data */ + h_id = (buf[1] >> 3) & 1; + h_sr_index = (buf[2] >> 2) & 3; + h_mode = (buf[3] >> 6) & 3; + h_bitrate = ((buf[2]>>4)&0xf); + h_bitrate = bitrate_table[h_id][h_bitrate]; + + /* check for FFE syncword */ + if ((buf[1]>>4)==0xE) + pTagData->samprate = samplerate_table[2][h_sr_index]; + else + pTagData->samprate = samplerate_table[h_id][h_sr_index]; + // if( h_id == 0 ) + // pTagData->samprate >>= 1; + + /* determine offset of header */ + if( h_id ) + { + /* mpeg1 */ + if( h_mode != 3 ) buf+=(32+4); + else buf+=(17+4); + } + else + { + /* mpeg2 */ + if( h_mode != 3 ) buf+=(17+4); + else buf+=(9+4); + } + + if( buf[0] != VBRTag[0] && buf[0] != VBRTag2[0] ) return 0; /* fail */ + if( buf[1] != VBRTag[1] && buf[1] != VBRTag2[1]) return 0; /* header not found*/ + if( buf[2] != VBRTag[2] && buf[2] != VBRTag2[2]) return 0; + if( buf[3] != VBRTag[3] && buf[3] != VBRTag2[3]) return 0; + + buf+=4; + + pTagData->h_id = h_id; + + head_flags = pTagData->flags = ExtractI4(buf); buf+=4; /* get flags */ + + if( head_flags & FRAMES_FLAG ) + { + pTagData->frames = ExtractI4(buf); buf+=4; + } + + if( head_flags & BYTES_FLAG ) + { + pTagData->bytes = ExtractI4(buf); buf+=4; + } + + if( head_flags & TOC_FLAG ) + { + if( pTagData->toc != NULL ) + { + for(i=0;itoc[i] = buf[i]; + } + buf+=NUMTOCENTRIES; + } + + pTagData->vbr_scale = -1; + + if( head_flags & VBR_SCALE_FLAG ) + { + pTagData->vbr_scale = ExtractI4(buf); buf+=4; + } + + pTagData->headersize = + ((h_id+1)*72000*h_bitrate) / pTagData->samprate; + + buf+=21; + enc_delay = buf[0] << 4; + enc_delay += buf[1] >> 4; + enc_padding= (buf[1] & 0x0F)<<8; + enc_padding += buf[2]; + // check for reasonable values (this may be an old Xing header, + // not a INFO tag) + if (enc_delay<0 || enc_delay > 3000) enc_delay=-1; + if (enc_padding<0 || enc_padding > 3000) enc_padding=-1; + + pTagData->enc_delay=enc_delay; + pTagData->enc_padding=enc_padding; + +#ifdef HIP_DEBUG + fprintf(stderr,"exit GetVbrTag:\n"); + fprintf(stderr," tag = %s\n",VBRTag); + fprintf(stderr," head_flags = %d\n",head_flags); + fprintf(stderr," bytes = %d\n",pTagData->bytes); + fprintf(stderr," frames = %d\n",pTagData->frames); + fprintf(stderr," VBR Scale = %d\n",pTagData->vbr_scale); + fprintf(stderr," enc_delay = %i \n",enc_delay); + fprintf(stderr," enc_padding = %i \n",enc_padding); + fprintf(stderr," toc =\n"); + if( pTagData->toc != NULL ) + { + for(i=0;itoc[i])); + } + } + fprintf(stderr,"\n"); +#endif + return 1; /* success */ +} diff --git a/Libraries/DecMPA/Files/src/hip/VbrTag.h b/Libraries/DecMPA/Files/src/hip/VbrTag.h new file mode 100644 index 000000000..f56feb34c --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/VbrTag.h @@ -0,0 +1,82 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + * + * Xing VBR tagging for LAME. + * + * Copyright (c) 1999 A.L. Faber + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef LAME_VRBTAG_H +#define LAME_VRBTAG_H +/* ----------------------------------------------------------- + * A Vbr header may be present in the ancillary + * data field of the first frame of an mp3 bitstream + * The Vbr header (optionally) contains + * frames total number of audio frames in the bitstream + * bytes total number of bytes in the bitstream + * toc table of contents + + * toc (table of contents) gives seek points + * for random access + * the ith entry determines the seek point for + * i-percent duration + * seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes + * e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes + */ + + +#define FRAMES_FLAG 0x0001 +#define BYTES_FLAG 0x0002 +#define TOC_FLAG 0x0004 +#define VBR_SCALE_FLAG 0x0008 + +#define NUMTOCENTRIES 100 + +#define FRAMES_AND_BYTES (FRAMES_FLAG | BYTES_FLAG) + + + +/*structure to receive extracted header */ +/* toc may be NULL*/ +typedef struct +{ + int h_id; /* from MPEG header, 0=MPEG2, 1=MPEG1 */ + int samprate; /* determined from MPEG header */ + int flags; /* from Vbr header data */ + int frames; /* total bit stream frames from Vbr header data */ + int bytes; /* total bit stream bytes from Vbr header data*/ + int vbr_scale; /* encoded vbr scale from Vbr header data*/ + unsigned char toc[NUMTOCENTRIES]; /* may be NULL if toc not desired*/ + int headersize; /* size of VBR header, in bytes */ + int enc_delay; /* encoder delay */ + int enc_padding; /* encoder paddign added at end of stream */ +} VBRTAGDATA; + +int CheckVbrTag(unsigned char *buf); +int GetVbrTag(VBRTAGDATA *pTagData, unsigned char *buf); + +/* +int SeekPoint(unsigned char TOC[NUMTOCENTRIES], int file_bytes, float percent); +int InitVbrTag(lame_global_flags *gfp); +int PutVbrTag(lame_global_flags *gfp,FILE *fid,int nVbrScale); +int PutLameVBR(lame_global_flags *gfp, FILE *fpStream, uint8_t *pbtStreamBuffer, uint32_t id3v2size, uint16_t crc); +void AddVbrFrame(lame_global_flags *gfp); +void ReportLameTagProgress(lame_global_flags *gfp,int nStart); +void UpdateMusicCRC(uint16_t *crc,unsigned char *buffer, int size); +*/ + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/common.c b/Libraries/DecMPA/Files/src/hip/common.c new file mode 100644 index 000000000..f5df930fa --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/common.c @@ -0,0 +1,320 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#ifdef HAVE_FCNTL_H +#include +#endif + +#ifdef macintosh +#include +#include +#else +#include +#include +#endif + +#include "common.h" + +#ifdef WITH_DMALLOC +#include +#endif + +// In C++ the array first must be prototyped, why ? + +extern const int tabsel_123 [2] [3] [16]; + +const int tabsel_123 [2] [3] [16] = { + { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,}, + {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,}, + {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} }, + + { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} } +}; + +const long freqs[9] = { 44100, 48000, 32000, + 22050, 24000, 16000, + 11025, 12000, 8000 }; + +int bitindex; +unsigned char *wordpointer; +unsigned char *pcm_sample; +int pcm_point = 0; + + +#if defined( USE_LAYER_1 ) || defined ( USE_LAYER_2 ) + real muls[27][64]; +#endif + +#define HDRCMPMASK 0xfffffd00 + + +int head_check(unsigned long head,int check_layer) +{ + /* + look for a valid header. + if check_layer > 0, then require that + nLayer = check_layer. + */ + + /* bits 13-14 = layer 3 */ + int nLayer=4-((head>>17)&3); + + if( (head & 0xffe00000) != 0xffe00000) { + /* syncword */ + return FALSE; + } +#if 0 + if(!((head>>17)&3)) { + /* bits 13-14 = layer 3 */ + return FALSE; + } +#endif + + if (3 != nLayer) + { + #if defined (USE_LAYER_1) || defined (USE_LAYER_2) + if (4==nLayer) + return FALSE; + #else + return FALSE; + #endif + } + + if (check_layer>0) { + if (nLayer != check_layer) return FALSE; + } + + if( ((head>>12)&0xf) == 0xf) { + /* bits 16,17,18,19 = 1111 invalid bitrate */ + return FALSE; + } + if( ((head>>10)&0x3) == 0x3 ) { + /* bits 20,21 = 11 invalid sampling freq */ + return FALSE; + } + return TRUE; +} + + +/* + * the code a header and write the information + * into the frame structure + */ +int decode_header(struct frame *fr,unsigned long newhead) +{ + + + if( newhead & (1<<20) ) { + fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1; + fr->mpeg25 = 0; + } + else { + fr->lsf = 1; + fr->mpeg25 = 1; + } + + + fr->lay = 4-((newhead>>17)&3); + if( ((newhead>>10)&0x3) == 0x3) + { + //fprintf(stderr,"Stream error\n"); + //exit(1); + return 0; + } + if(fr->mpeg25) { + fr->sampling_frequency = 6 + ((newhead>>10)&0x3); + } + else + fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3); + + fr->error_protection = ((newhead>>16)&0x1)^0x1; + + if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */ + fr->bitrate_index = ((newhead>>12)&0xf); + + fr->bitrate_index = ((newhead>>12)&0xf); + fr->padding = ((newhead>>9)&0x1); + fr->extension = ((newhead>>8)&0x1); + fr->mode = ((newhead>>6)&0x3); + fr->mode_ext = ((newhead>>4)&0x3); + fr->copyright = ((newhead>>3)&0x1); + fr->original = ((newhead>>2)&0x1); + fr->emphasis = newhead & 0x3; + + fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2; + + switch(fr->lay) + { +#ifdef USE_LAYER_1 + case 1: + fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000; + fr->framesize /= freqs[fr->sampling_frequency]; + fr->framesize = ((fr->framesize+fr->padding)<<2)-4; + fr->down_sample=0; + fr->down_sample_sblimit = SBLIMIT>>(fr->down_sample); + break; +#endif +#ifdef USE_LAYER_2 + case 2: + fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000; + fr->framesize /= freqs[fr->sampling_frequency]; + fr->framesize += fr->padding - 4; + fr->down_sample=0; + fr->down_sample_sblimit = SBLIMIT>>(fr->down_sample); + break; +#endif + case 3: +#if 0 + fr->do_layer = do_layer3; + if(fr->lsf) + ssize = (fr->stereo == 1) ? 9 : 17; + else + ssize = (fr->stereo == 1) ? 17 : 32; +#endif + +#if 0 + if(fr->error_protection) + ssize += 2; +#endif + if (fr->bitrate_index==0) + fr->framesize=0; + else{ + fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000; + fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf); + fr->framesize = fr->framesize + fr->padding - 4; + } + break; + default: + //fprintf(stderr,"Sorry, layer %d not supported\n",fr->lay); + return (0); + } + /* print_header(fr); */ + + return 1; +} + + +/*#if 1 +void print_header(struct frame *fr) +{ + static const char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" }; + static const char *layers[4] = { "Unknown" , "I", "II", "III" }; + + fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n", + fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), + layers[fr->lay],freqs[fr->sampling_frequency], + modes[fr->mode],fr->mode_ext,fr->framesize+4); + fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n", + fr->stereo,fr->copyright?"Yes":"No", + fr->original?"Yes":"No",fr->error_protection?"Yes":"No", + fr->emphasis); + fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n", + tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension); +} + +void print_header_compact(struct frame *fr) +{ + static const char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" }; + static const char *layers[4] = { "Unknown" , "I", "II", "III" }; + + fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n", + fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"), + layers[fr->lay], + tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index], + freqs[fr->sampling_frequency], modes[fr->mode]); +} + +#endif*/ + +unsigned int getbits(int number_of_bits) +{ + unsigned long rval; + + if(!number_of_bits) + return 0; + + { + rval = wordpointer[0]; + rval <<= 8; + rval |= wordpointer[1]; + rval <<= 8; + rval |= wordpointer[2]; + rval <<= bitindex; + rval &= 0xffffff; + + bitindex += number_of_bits; + + rval >>= (24-number_of_bits); + + wordpointer += (bitindex>>3); + bitindex &= 7; + } + return rval; +} + +unsigned int getbits_fast(int number_of_bits) +{ + unsigned long rval; + + { + rval = wordpointer[0]; + rval <<= 8; + rval |= wordpointer[1]; + rval <<= bitindex; + rval &= 0xffff; + bitindex += number_of_bits; + + rval >>= (16-number_of_bits); + + wordpointer += (bitindex>>3); + bitindex &= 7; + } + return rval; +} + + +int set_pointer( PMPSTR mp, long backstep) +{ + unsigned char *bsbufold; + + if(mp->fsizeold < 0 && backstep > 0) { + //fprintf(stderr,"Can't step back %ld!\n",backstep); + return MP3_ERR; + } + bsbufold = mp->bsspace[1-mp->bsnum] + 512; + wordpointer -= backstep; + if (backstep) + memcpy(wordpointer,bsbufold+mp->fsizeold-backstep,(size_t)backstep); + bitindex = 0; + return MP3_OK; +} diff --git a/Libraries/DecMPA/Files/src/hip/common.h b/Libraries/DecMPA/Files/src/hip/common.h new file mode 100644 index 000000000..43fa85e58 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/common.h @@ -0,0 +1,54 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* +** Copyright (C) 2000 Albert L. Faber +**/ + + +#ifndef COMMON_H_INCLUDED +#define COMMON_H_INCLUDED + +#include "HIPDefines.h" + +#include "mpg123.h" +#include "mpglib.h" + +extern const int tabsel_123[2][3][16]; +extern const long freqs[9]; +extern unsigned char *wordpointer; +extern int bitindex; + + +#if defined( USE_LAYER_1 ) || defined ( USE_LAYER_2 ) + extern real muls[27][64]; +#endif + +int head_check(unsigned long head,int check_layer); +int decode_header(struct frame *fr,unsigned long newhead); +void print_header(struct frame *fr); +void print_header_compact(struct frame *fr); +unsigned int getbits(int number_of_bits); +unsigned int getbits_fast(int number_of_bits); +int set_pointer( PMPSTR mp, long backstep); + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/dct64_i386.c b/Libraries/DecMPA/Files/src/hip/dct64_i386.c new file mode 100644 index 000000000..c7ef00617 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/dct64_i386.c @@ -0,0 +1,348 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + + +/* + * Discrete Cosine Tansform (DCT) for subband synthesis + * optimized for machines with no auto-increment. + * The performance is highly compiler dependend. Maybe + * the dct64.c version for 'normal' processor may be faster + * even for Intel processors. + */ + +/* $Id: dct64_i386.c 3 2005-06-02 18:16:43Z vspader $ */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "dct64_i386.h" +#include "tabinit.h" + +#ifdef WITH_DMALLOC +#include +#endif + +static void dct64_1(real *out0,real *out1,real *b1,real *b2,real *samples) +{ + + { + register real *costab = pnts[0]; + + b1[0x00] = samples[0x00] + samples[0x1F]; + b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0]; + + b1[0x01] = samples[0x01] + samples[0x1E]; + b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1]; + + b1[0x02] = samples[0x02] + samples[0x1D]; + b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2]; + + b1[0x03] = samples[0x03] + samples[0x1C]; + b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3]; + + b1[0x04] = samples[0x04] + samples[0x1B]; + b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4]; + + b1[0x05] = samples[0x05] + samples[0x1A]; + b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5]; + + b1[0x06] = samples[0x06] + samples[0x19]; + b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6]; + + b1[0x07] = samples[0x07] + samples[0x18]; + b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7]; + + b1[0x08] = samples[0x08] + samples[0x17]; + b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8]; + + b1[0x09] = samples[0x09] + samples[0x16]; + b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9]; + + b1[0x0A] = samples[0x0A] + samples[0x15]; + b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA]; + + b1[0x0B] = samples[0x0B] + samples[0x14]; + b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB]; + + b1[0x0C] = samples[0x0C] + samples[0x13]; + b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC]; + + b1[0x0D] = samples[0x0D] + samples[0x12]; + b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD]; + + b1[0x0E] = samples[0x0E] + samples[0x11]; + b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE]; + + b1[0x0F] = samples[0x0F] + samples[0x10]; + b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF]; + } + + + { + register real *costab = pnts[1]; + + b2[0x00] = b1[0x00] + b1[0x0F]; + b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0]; + b2[0x01] = b1[0x01] + b1[0x0E]; + b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1]; + b2[0x02] = b1[0x02] + b1[0x0D]; + b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2]; + b2[0x03] = b1[0x03] + b1[0x0C]; + b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3]; + b2[0x04] = b1[0x04] + b1[0x0B]; + b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4]; + b2[0x05] = b1[0x05] + b1[0x0A]; + b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5]; + b2[0x06] = b1[0x06] + b1[0x09]; + b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6]; + b2[0x07] = b1[0x07] + b1[0x08]; + b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7]; + + b2[0x10] = b1[0x10] + b1[0x1F]; + b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0]; + b2[0x11] = b1[0x11] + b1[0x1E]; + b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1]; + b2[0x12] = b1[0x12] + b1[0x1D]; + b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2]; + b2[0x13] = b1[0x13] + b1[0x1C]; + b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3]; + b2[0x14] = b1[0x14] + b1[0x1B]; + b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4]; + b2[0x15] = b1[0x15] + b1[0x1A]; + b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5]; + b2[0x16] = b1[0x16] + b1[0x19]; + b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6]; + b2[0x17] = b1[0x17] + b1[0x18]; + b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7]; + } + + { + register real *costab = pnts[2]; + + b1[0x00] = b2[0x00] + b2[0x07]; + b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0]; + b1[0x01] = b2[0x01] + b2[0x06]; + b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1]; + b1[0x02] = b2[0x02] + b2[0x05]; + b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2]; + b1[0x03] = b2[0x03] + b2[0x04]; + b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3]; + + b1[0x08] = b2[0x08] + b2[0x0F]; + b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0]; + b1[0x09] = b2[0x09] + b2[0x0E]; + b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1]; + b1[0x0A] = b2[0x0A] + b2[0x0D]; + b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2]; + b1[0x0B] = b2[0x0B] + b2[0x0C]; + b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3]; + + b1[0x10] = b2[0x10] + b2[0x17]; + b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0]; + b1[0x11] = b2[0x11] + b2[0x16]; + b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1]; + b1[0x12] = b2[0x12] + b2[0x15]; + b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2]; + b1[0x13] = b2[0x13] + b2[0x14]; + b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3]; + + b1[0x18] = b2[0x18] + b2[0x1F]; + b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0]; + b1[0x19] = b2[0x19] + b2[0x1E]; + b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1]; + b1[0x1A] = b2[0x1A] + b2[0x1D]; + b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2]; + b1[0x1B] = b2[0x1B] + b2[0x1C]; + b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3]; + } + + { + register real const cos0 = pnts[3][0]; + register real const cos1 = pnts[3][1]; + + b2[0x00] = b1[0x00] + b1[0x03]; + b2[0x03] = (b1[0x00] - b1[0x03]) * cos0; + b2[0x01] = b1[0x01] + b1[0x02]; + b2[0x02] = (b1[0x01] - b1[0x02]) * cos1; + + b2[0x04] = b1[0x04] + b1[0x07]; + b2[0x07] = (b1[0x07] - b1[0x04]) * cos0; + b2[0x05] = b1[0x05] + b1[0x06]; + b2[0x06] = (b1[0x06] - b1[0x05]) * cos1; + + b2[0x08] = b1[0x08] + b1[0x0B]; + b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0; + b2[0x09] = b1[0x09] + b1[0x0A]; + b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1; + + b2[0x0C] = b1[0x0C] + b1[0x0F]; + b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0; + b2[0x0D] = b1[0x0D] + b1[0x0E]; + b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1; + + b2[0x10] = b1[0x10] + b1[0x13]; + b2[0x13] = (b1[0x10] - b1[0x13]) * cos0; + b2[0x11] = b1[0x11] + b1[0x12]; + b2[0x12] = (b1[0x11] - b1[0x12]) * cos1; + + b2[0x14] = b1[0x14] + b1[0x17]; + b2[0x17] = (b1[0x17] - b1[0x14]) * cos0; + b2[0x15] = b1[0x15] + b1[0x16]; + b2[0x16] = (b1[0x16] - b1[0x15]) * cos1; + + b2[0x18] = b1[0x18] + b1[0x1B]; + b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0; + b2[0x19] = b1[0x19] + b1[0x1A]; + b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1; + + b2[0x1C] = b1[0x1C] + b1[0x1F]; + b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0; + b2[0x1D] = b1[0x1D] + b1[0x1E]; + b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1; + } + + { + register real const cos0 = pnts[4][0]; + + b1[0x00] = b2[0x00] + b2[0x01]; + b1[0x01] = (b2[0x00] - b2[0x01]) * cos0; + b1[0x02] = b2[0x02] + b2[0x03]; + b1[0x03] = (b2[0x03] - b2[0x02]) * cos0; + b1[0x02] += b1[0x03]; + + b1[0x04] = b2[0x04] + b2[0x05]; + b1[0x05] = (b2[0x04] - b2[0x05]) * cos0; + b1[0x06] = b2[0x06] + b2[0x07]; + b1[0x07] = (b2[0x07] - b2[0x06]) * cos0; + b1[0x06] += b1[0x07]; + b1[0x04] += b1[0x06]; + b1[0x06] += b1[0x05]; + b1[0x05] += b1[0x07]; + + b1[0x08] = b2[0x08] + b2[0x09]; + b1[0x09] = (b2[0x08] - b2[0x09]) * cos0; + b1[0x0A] = b2[0x0A] + b2[0x0B]; + b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0; + b1[0x0A] += b1[0x0B]; + + b1[0x0C] = b2[0x0C] + b2[0x0D]; + b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0; + b1[0x0E] = b2[0x0E] + b2[0x0F]; + b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0; + b1[0x0E] += b1[0x0F]; + b1[0x0C] += b1[0x0E]; + b1[0x0E] += b1[0x0D]; + b1[0x0D] += b1[0x0F]; + + b1[0x10] = b2[0x10] + b2[0x11]; + b1[0x11] = (b2[0x10] - b2[0x11]) * cos0; + b1[0x12] = b2[0x12] + b2[0x13]; + b1[0x13] = (b2[0x13] - b2[0x12]) * cos0; + b1[0x12] += b1[0x13]; + + b1[0x14] = b2[0x14] + b2[0x15]; + b1[0x15] = (b2[0x14] - b2[0x15]) * cos0; + b1[0x16] = b2[0x16] + b2[0x17]; + b1[0x17] = (b2[0x17] - b2[0x16]) * cos0; + b1[0x16] += b1[0x17]; + b1[0x14] += b1[0x16]; + b1[0x16] += b1[0x15]; + b1[0x15] += b1[0x17]; + + b1[0x18] = b2[0x18] + b2[0x19]; + b1[0x19] = (b2[0x18] - b2[0x19]) * cos0; + b1[0x1A] = b2[0x1A] + b2[0x1B]; + b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0; + b1[0x1A] += b1[0x1B]; + + b1[0x1C] = b2[0x1C] + b2[0x1D]; + b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0; + b1[0x1E] = b2[0x1E] + b2[0x1F]; + b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0; + b1[0x1E] += b1[0x1F]; + b1[0x1C] += b1[0x1E]; + b1[0x1E] += b1[0x1D]; + b1[0x1D] += b1[0x1F]; + } + + out0[0x10*16] = b1[0x00]; + out0[0x10*12] = b1[0x04]; + out0[0x10* 8] = b1[0x02]; + out0[0x10* 4] = b1[0x06]; + out0[0x10* 0] = b1[0x01]; + out1[0x10* 0] = b1[0x01]; + out1[0x10* 4] = b1[0x05]; + out1[0x10* 8] = b1[0x03]; + out1[0x10*12] = b1[0x07]; + + b1[0x08] += b1[0x0C]; + out0[0x10*14] = b1[0x08]; + b1[0x0C] += b1[0x0a]; + out0[0x10*10] = b1[0x0C]; + b1[0x0A] += b1[0x0E]; + out0[0x10* 6] = b1[0x0A]; + b1[0x0E] += b1[0x09]; + out0[0x10* 2] = b1[0x0E]; + b1[0x09] += b1[0x0D]; + out1[0x10* 2] = b1[0x09]; + b1[0x0D] += b1[0x0B]; + out1[0x10* 6] = b1[0x0D]; + b1[0x0B] += b1[0x0F]; + out1[0x10*10] = b1[0x0B]; + out1[0x10*14] = b1[0x0F]; + + b1[0x18] += b1[0x1C]; + out0[0x10*15] = b1[0x10] + b1[0x18]; + out0[0x10*13] = b1[0x18] + b1[0x14]; + b1[0x1C] += b1[0x1a]; + out0[0x10*11] = b1[0x14] + b1[0x1C]; + out0[0x10* 9] = b1[0x1C] + b1[0x12]; + b1[0x1A] += b1[0x1E]; + out0[0x10* 7] = b1[0x12] + b1[0x1A]; + out0[0x10* 5] = b1[0x1A] + b1[0x16]; + b1[0x1E] += b1[0x19]; + out0[0x10* 3] = b1[0x16] + b1[0x1E]; + out0[0x10* 1] = b1[0x1E] + b1[0x11]; + b1[0x19] += b1[0x1D]; + out1[0x10* 1] = b1[0x11] + b1[0x19]; + out1[0x10* 3] = b1[0x19] + b1[0x15]; + b1[0x1D] += b1[0x1B]; + out1[0x10* 5] = b1[0x15] + b1[0x1D]; + out1[0x10* 7] = b1[0x1D] + b1[0x13]; + b1[0x1B] += b1[0x1F]; + out1[0x10* 9] = b1[0x13] + b1[0x1B]; + out1[0x10*11] = b1[0x1B] + b1[0x17]; + out1[0x10*13] = b1[0x17] + b1[0x1F]; + out1[0x10*15] = b1[0x1F]; +} + +/* + * the call via dct64 is a trick to force GCC to use + * (new) registers for the b1,b2 pointer to the bufs[xx] field + */ +void dct64( real *a,real *b,real *c) +{ + real bufs[0x40]; + dct64_1(a,b,bufs,bufs+0x20,c); +} + diff --git a/Libraries/DecMPA/Files/src/hip/dct64_i386.h b/Libraries/DecMPA/Files/src/hip/dct64_i386.h new file mode 100644 index 000000000..34dd18bbc --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/dct64_i386.h @@ -0,0 +1,36 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* +** Copyright (C) 2000 Albert L. Faber +**/ + + +#ifndef MPGLIB_DCT64_I386_H_INCLUDED +#define MPGLIB_DCT64_I386_H_INCLUDED + +#include "common.h" + +void dct64( real *a,real *b,real *c); + + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/decode_i386.c b/Libraries/DecMPA/Files/src/hip/decode_i386.c new file mode 100644 index 000000000..c5bcab67e --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/decode_i386.c @@ -0,0 +1,202 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + + +/* + * Mpeg Layer-1,2,3 audio decoder + * ------------------------------ + * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved. + * See also 'README' + * + * slighlty optimized for machines without autoincrement/decrement. + * The performance is highly compiler dependend. Maybe + * the decode.c version for 'normal' processor may be faster + * even for Intel processors. + */ + +/* $Id: decode_i386.c 3 2005-06-02 18:16:43Z vspader $ */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +//#ifdef STDC_HEADERS +# include +# include +//#else +/*# ifndef HAVE_STRCHR +# define strchr index +# define strrchr rindex +# endif +char *strchr (), *strrchr (); +/*# ifndef HAVE_MEMCPY +# define memcpy(d, s, n) bcopy ((s), (d), (n)) +# define memmove(d, s, n) bcopy ((s), (d), (n)) +# endif +#endif*/ + +#if defined(__riscos__) && defined(FPA10) +#include "ymath.h" +#else +#include +#endif + +#include "decode_i386.h" +#include "dct64_i386.h" +#include "tabinit.h" + +#ifdef WITH_DMALLOC +#include +#endif + + + /* old WRITE_SAMPLE */ +#define WRITE_SAMPLE(samples,sum,clip) \ + if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \ + else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \ + else { *(samples) = (short)( ((sum)>0 ? (sum)+0.5 : (sum)-0.5) ); } + +int synth_1to1_mono(PMPSTR mp, real *bandPtr,unsigned char *samples,int *pnt) +{ + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; + + ret = synth_1to1(mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; + + for(i=0;i<32;i++) { + *( (short *) samples) = *tmp1; + samples += 2; + tmp1 += 2; + } + *pnt += 64; + + return ret; +} + +int synth_1to1(PMPSTR mp, real *bandPtr,int channel,unsigned char *out,int *pnt) +{ + static const int step = 2; + int bo; + short *samples = (short *) (out + *pnt); + + real *b0,(*buf)[0x110]; + int clip = 0; + int bo1; + + bo = mp->synth_bo; + + if(!channel) { + bo--; + bo &= 0xf; + buf = mp->synth_buffs[0]; + } + else { + samples++; + buf = mp->synth_buffs[1]; + } + + if(bo & 0x1) { + b0 = buf[0]; + bo1 = bo; + dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); + } + else { + b0 = buf[1]; + bo1 = bo+1; + dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); + } + + mp->synth_bo = bo; + + { + register int j; + real *window = decwin + 16 - bo1; + + for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) + { + real sum; + sum = window[0x0] * b0[0x0]; + sum -= window[0x1] * b0[0x1]; + sum += window[0x2] * b0[0x2]; + sum -= window[0x3] * b0[0x3]; + sum += window[0x4] * b0[0x4]; + sum -= window[0x5] * b0[0x5]; + sum += window[0x6] * b0[0x6]; + sum -= window[0x7] * b0[0x7]; + sum += window[0x8] * b0[0x8]; + sum -= window[0x9] * b0[0x9]; + sum += window[0xA] * b0[0xA]; + sum -= window[0xB] * b0[0xB]; + sum += window[0xC] * b0[0xC]; + sum -= window[0xD] * b0[0xD]; + sum += window[0xE] * b0[0xE]; + sum -= window[0xF] * b0[0xF]; + + WRITE_SAMPLE(samples,sum,clip); + } + + { + real sum; + sum = window[0x0] * b0[0x0]; + sum += window[0x2] * b0[0x2]; + sum += window[0x4] * b0[0x4]; + sum += window[0x6] * b0[0x6]; + sum += window[0x8] * b0[0x8]; + sum += window[0xA] * b0[0xA]; + sum += window[0xC] * b0[0xC]; + sum += window[0xE] * b0[0xE]; + WRITE_SAMPLE(samples,sum,clip); + b0-=0x10,window-=0x20,samples+=step; + } + window += bo1<<1; + + for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) + { + real sum; + sum = -window[-0x1] * b0[0x0]; + sum -= window[-0x2] * b0[0x1]; + sum -= window[-0x3] * b0[0x2]; + sum -= window[-0x4] * b0[0x3]; + sum -= window[-0x5] * b0[0x4]; + sum -= window[-0x6] * b0[0x5]; + sum -= window[-0x7] * b0[0x6]; + sum -= window[-0x8] * b0[0x7]; + sum -= window[-0x9] * b0[0x8]; + sum -= window[-0xA] * b0[0x9]; + sum -= window[-0xB] * b0[0xA]; + sum -= window[-0xC] * b0[0xB]; + sum -= window[-0xD] * b0[0xC]; + sum -= window[-0xE] * b0[0xD]; + sum -= window[-0xF] * b0[0xE]; + sum -= window[-0x0] * b0[0xF]; + + WRITE_SAMPLE(samples,sum,clip); + } + } + *pnt += 128; + + return clip; +} + diff --git a/Libraries/DecMPA/Files/src/hip/decode_i386.h b/Libraries/DecMPA/Files/src/hip/decode_i386.h new file mode 100644 index 000000000..2442b134d --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/decode_i386.h @@ -0,0 +1,36 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* +** Copyright (C) 2000 Albert L. Faber +**/ + + +#ifndef DECODE_I386_H_INCLUDED +#define DECODE_I386_H_INCLUDED + +#include "common.h" + +int synth_1to1_mono(PMPSTR mp, real *bandPtr,unsigned char *samples,int *pnt); +int synth_1to1(PMPSTR mp, real *bandPtr,int channel,unsigned char *out,int *pnt); + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/huffman.h b/Libraries/DecMPA/Files/src/hip/huffman.h new file mode 100644 index 000000000..543f208ae --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/huffman.h @@ -0,0 +1,354 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* + * huffman tables ... recalcualted to work with my optimzed + * decoder scheme (MH) + * + * probably we could save a few bytes of memory, because the + * smaller tables are often the part of a bigger table + */ + +struct newhuff +{ + const unsigned int linbits; + const short * const table; +}; + +static const short tab0[] = +{ + 0 +}; + +static const short tab1[] = +{ + -5, -3, -1, 17, 1, 16, 0 +}; + +static const short tab2[] = +{ + -15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1, + 16, 0 +}; + +static const short tab3[] = +{ + -13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1, + 1, 0 +}; + +static const short tab5[] = +{ + -29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19, + 3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16, + 0 +}; + +static const short tab6[] = +{ + -25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19, + 49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16, + 0 +}; + +static const short tab7[] = +{ + -69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83, + -1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1, + 80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7, + -3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18, + -5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0 +}; + +static const short tab8[] = +{ + -65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83, + -3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52, + 67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4, + 64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1, + 2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0 +}; + +static const short tab9[] = +{ + -63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1, + 84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67, + -1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5, + -3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2, + 18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0 +}; + +static const short tab10[] = +{ +-125,-121,-111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118, + 87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3, + -1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1, + 100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23, + -17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81, + -1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7, + -3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1, + 50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1, + 2, 32, 17, -1, 1, 16, 0 +}; + +static const short tab11[] = +{ +-121,-113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117, + -3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55, + -1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114, + -1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96, + -1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38, + 6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1, + 36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50, + -1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2, + 32, 17, -3, -1, 1, 16, 0 +}; + +static const short tab12[] = +{ +-115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87, + 117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115, + 85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7, + 112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5, + -1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37, + 82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4, + 36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3, + -1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1, + 2, 32, 0, 17, -1, 1, 16 +}; + +static const short tab13[] = +{ +-509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13, -9, + -7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238, + 207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1, + 236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249, + 234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158, + -5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1, + 203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245, + 231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1, + 63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15, + -5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1, + 200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1, + 240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1, + 46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3, + -1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1, + 198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5, + -1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167, + 151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76, + 196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137, + 28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106, + -5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43, + -1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178, + -11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1, + 58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161, + -3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88, + -1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1, + 131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25, + 145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100, + 40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113, + -1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38, + -1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6, + 96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81, + -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11, + -5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3, + -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16, + 0 +}; + +static const short tab15[] = +{ +-495,-445,-355,-263,-183,-115, -77, -43, -27, -13, -7, -3, -1, 255, 239, + -1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237, + 191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3, + -1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219, + -3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173, + -3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246, + -3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9, + -3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243, + 216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1, + 31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1, + 125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3, + -1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5, + -1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124, + 199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1, + 198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183, + -5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76, + -1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1, + 122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15, + -7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106, + -5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5, + -1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74, + -1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1, + 42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134, + 73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29, + -13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7, + -3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7, + -3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86, + -3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100, + 23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69, + -1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9, + -5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1, + 5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20, + 4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48, + 34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16, + 0 +}; + +static const short tab16[] = +{ +-509,-503,-461,-323,-103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223, + 253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3, + -1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5, + -3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19, + -13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1, + 238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5, + -1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125, + 94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13, + -5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3, + -1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186, + -1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1, + 214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169, + -5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213, + -3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154, + 108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1, + 153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1, + 192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45, + -1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107, + -1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12, + -1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1, + 178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74, + 164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33, + -19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3, + -1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147, + -1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1, + 145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3, + -1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1, + 8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3, + -1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1, + 99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9, + -5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33, + -23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, + -5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1, + 3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16, + 0 +}; + +static const short tab24[] = +{ +-451,-117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1, + 207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9, + -5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79, + 244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31, + 240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1, + 236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3, + -1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3, + -1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255,-235, +-143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3, + -1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9, + -5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1, + 78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185, + 170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199, + 77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3, + -1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3, + -1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196, + -3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1, + 167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1, + 137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10, + 26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9, + 144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165, + 27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135, + -1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104, + -1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3, + -1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3, + -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7, + -3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86, + 101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15, + -7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84, + -7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1, + 83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5, + 80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5, + -1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1, + 3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16, + 0 +}; + +static const short tab_c0[] = +{ + -29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5, + 9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8, + 0 +}; + +static const short tab_c1[] = +{ + -15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9, + 8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1, + 0 +}; + + + +static const struct newhuff ht[] = +{ + { /* 0 */ 0 , tab0 } , + { /* 2 */ 0 , tab1 } , + { /* 3 */ 0 , tab2 } , + { /* 3 */ 0 , tab3 } , + { /* 0 */ 0 , tab0 } , + { /* 4 */ 0 , tab5 } , + { /* 4 */ 0 , tab6 } , + { /* 6 */ 0 , tab7 } , + { /* 6 */ 0 , tab8 } , + { /* 6 */ 0 , tab9 } , + { /* 8 */ 0 , tab10 } , + { /* 8 */ 0 , tab11 } , + { /* 8 */ 0 , tab12 } , + { /* 16 */ 0 , tab13 } , + { /* 0 */ 0 , tab0 } , + { /* 16 */ 0 , tab15 } , + + { /* 16 */ 1 , tab16 } , + { /* 16 */ 2 , tab16 } , + { /* 16 */ 3 , tab16 } , + { /* 16 */ 4 , tab16 } , + { /* 16 */ 6 , tab16 } , + { /* 16 */ 8 , tab16 } , + { /* 16 */ 10, tab16 } , + { /* 16 */ 13, tab16 } , + { /* 16 */ 4 , tab24 } , + { /* 16 */ 5 , tab24 } , + { /* 16 */ 6 , tab24 } , + { /* 16 */ 7 , tab24 } , + { /* 16 */ 8 , tab24 } , + { /* 16 */ 9 , tab24 } , + { /* 16 */ 11, tab24 } , + { /* 16 */ 13, tab24 } +}; + +static const struct newhuff htc[] = +{ + { /* 1 , 1 , */ 0 , tab_c0 } , + { /* 1 , 1 , */ 0 , tab_c1 } +}; + + diff --git a/Libraries/DecMPA/Files/src/hip/interface.c b/Libraries/DecMPA/Files/src/hip/interface.c new file mode 100644 index 000000000..0d6104d73 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/interface.c @@ -0,0 +1,666 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +//changes: 8/20/2002, Hauke Duden +// - fixed potential access violation in check_vbr_header and sync_buffer + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "common.h" +#include "interface.h" +#include "tabinit.h" +#include "layer3.h" +#include "VbrTag.h" + +#ifdef USE_LAYER_1 + #include "layer1.h" +#endif + +#ifdef USE_LAYER_2 + #include "layer2.h" +#endif + +#ifdef WITH_DMALLOC +#include +#endif + + +BOOL InitMP3( PMPSTR mp) +{ + memset(mp,0,sizeof(MPSTR)); + + mp->framesize = 0; + mp->num_frames = 0; + mp->enc_delay = -1; + mp->enc_padding = -1; + mp->vbr_header=0; + mp->header_parsed=0; + mp->side_parsed=0; + mp->data_parsed=0; + mp->free_format=0; + mp->old_free_format=0; + mp->ssize = 0; + mp->dsize=0; + mp->fsizeold = -1; + mp->bsize = 0; + mp->head = mp->tail = NULL; + mp->fr.single = -1; + mp->bsnum = 0; + wordpointer = mp->bsspace[mp->bsnum] + 512; + mp->synth_bo = 1; + mp->sync_bitstream = 1; + + make_decode_tables(32767); + + init_layer3(SBLIMIT); + +#ifdef USE_LAYER_2 + init_layer2(); +#endif + + return !0; +} + +void ExitMP3( PMPSTR mp) +{ + struct buf *b,*bn; + + b = mp->tail; + while(b) { + free(b->pnt); + bn = b->next; + free(b); + b = bn; + } +} + +static struct buf *addbuf( PMPSTR mp, unsigned char *buf,int size) +{ + struct buf *nbuf; + + nbuf = (struct buf*) malloc( sizeof(struct buf) ); + if(!nbuf) { + //fprintf(stderr,"Out of memory!\n"); + return NULL; + } + nbuf->pnt = (unsigned char*) malloc((size_t)size); + if(!nbuf->pnt) { + free(nbuf); + return NULL; + } + nbuf->size = size; + memcpy(nbuf->pnt,buf,(size_t)size); + nbuf->next = NULL; + nbuf->prev = mp->head; + nbuf->pos = 0; + + if(!mp->tail) { + mp->tail = nbuf; + } + else { + mp->head->next = nbuf; + } + + mp->head = nbuf; + mp->bsize += size; + + return nbuf; +} + +void remove_buf(PMPSTR mp) +{ + struct buf *buf = mp->tail; + + mp->tail = buf->next; + if(mp->tail) + mp->tail->prev = NULL; + else { + mp->tail = mp->head = NULL; + } + + free(buf->pnt); + free(buf); + +} + +static int read_buf_byte(PMPSTR mp) +{ + unsigned int b; + + int pos; + + + pos = mp->tail->pos; + while(pos >= mp->tail->size) { + remove_buf(mp); + //if(!mp->tail) { + //fprintf(stderr,"Fatal error! tried to read past mp buffer\n"); + //exit(1); + //} + pos = mp->tail->pos; + } + + b = mp->tail->pnt[pos]; + mp->bsize--; + mp->tail->pos++; + + + return b; +} + + + +static void read_head(PMPSTR mp) +{ + unsigned long head; + + head = read_buf_byte(mp); + head <<= 8; + head |= read_buf_byte(mp); + head <<= 8; + head |= read_buf_byte(mp); + head <<= 8; + head |= read_buf_byte(mp); + + mp->header = head; +} + + + + + + +void copy_mp(PMPSTR mp,int size,unsigned char *ptr) +{ + int len = 0; + + while(len < size) { + int nlen; + int blen = mp->tail->size - mp->tail->pos; + if( (size - len) <= blen) { + nlen = size-len; + } + else { + nlen = blen; + } + memcpy(ptr+len,mp->tail->pnt+mp->tail->pos,(size_t)nlen); + len += nlen; + mp->tail->pos += nlen; + mp->bsize -= nlen; + if(mp->tail->pos == mp->tail->size) { + remove_buf(mp); + } + } +} + +// number of bytes needed by GetVbrTag to parse header +#define XING_HEADER_SIZE 194 + +// traverse mp data structure without changing it +// (just like sync_buffer) +// pull out Xing bytes +// call vbr header check code from LAME +// if we find a header, parse it and also compute the VBR header size +// if no header, do nothing. +// +// bytes = number of bytes before MPEG header. skip this many bytes +// before starting to read +// return value: number of bytes in VBR header, including syncword +int check_vbr_header(PMPSTR mp,int bytes) +{ + int i,pos; + struct buf *buf=mp->tail; + unsigned char xing[XING_HEADER_SIZE]; + VBRTAGDATA pTagData; + + pos = buf->pos; + // skip to valid header + for (i=0; i= buf->size) { + buf = buf->next; + //fixed by Hauke Duden + //this has to be checked BEFORE accessing buf->pos + if(!buf) return -1; /* fatal error */ + pos = buf->pos; + } + ++pos; + } + // now read header + for (i=0; i= buf->size) + { + buf = buf->next; + + //fixed by Hauke Duden + //this has to be checked BEFORE accessing buf->pos + if(!buf) return -1; /* fatal error */ + + pos = buf->pos; + } + xing[i] = buf->pnt[pos]; + ++pos; + } + + /* check first bytes for Xing header */ + mp->vbr_header = GetVbrTag(&pTagData,xing); + if (mp->vbr_header) { + mp->num_frames=pTagData.frames; + mp->enc_delay=pTagData.enc_delay; + mp->enc_padding=pTagData.enc_padding; + + //fprintf(stderr,"\rmpglib: delays: %i %i \n",mp->enc_delay,mp->enc_padding); + // fprintf(stderr,"\rmpglib: Xing VBR header dectected. MP3 file has %i frames\n", pTagData.frames); + return pTagData.headersize; + } + return 0; +} + + + + + + + +int sync_buffer(PMPSTR mp,int free_match) +{ + /* traverse mp structure without modifing pointers, looking + * for a frame valid header. + * if free_format, valid header must also have the same + * samplerate. + * return number of bytes in mp, before the header + * return -1 if header is not found + */ + unsigned int b[4]={0,0,0,0}; + int i,h,pos; + struct buf *buf=mp->tail; + + pos = buf->pos; + for (i=0; ibsize; i++) + { + /* get 4 bytes */ + + b[0]=b[1]; b[1]=b[2]; b[2]=b[3]; + while(pos >= buf->size) + { + buf = buf->next; + //fixed by Hauke Duden + //this has to be checked BEFORE accessing buf->pos + if(!buf) + { + return -1; + /* not enough data to read 4 bytes */ + } + pos = buf->pos; + } + b[3] = buf->pnt[pos]; + ++pos; + + if (i>=3) + { + struct frame *fr = &mp->fr; + unsigned long head; + + head = b[0]; + head <<= 8; + head |= b[1]; + head <<= 8; + head |= b[2]; + head <<= 8; + head |= b[3]; + h = head_check(head,fr->lay); + + if (h && free_match) + { + /* just to be even more thorough, match the sample rate */ + int mode,stereo,sampling_frequency,mpeg25,lsf; + + if( head & (1<<20) ) + { + lsf = (head & (1<<19)) ? 0x0 : 0x1; + mpeg25 = 0; + } + else + { + lsf = 1; + mpeg25 = 1; + } + + mode = ((head>>6)&0x3); + stereo = (mode == MPG_MD_MONO) ? 1 : 2; + + if(mpeg25) + sampling_frequency = 6 + ((head>>10)&0x3); + else + sampling_frequency = ((head>>10)&0x3) + (lsf*3); + h = ((stereo==fr->stereo) && (lsf==fr->lsf) && (mpeg25==fr->mpeg25) && + (sampling_frequency == fr->sampling_frequency)); + } + + if (h) + return i-3; + } + } + + return -1; +} + + + + + +int decodeMP3( PMPSTR mp,unsigned char *in,int isize,char *out, + int osize,int *done) +{ + int i,iret,bits,bytes; + + if(osize < 4608) + { + //fprintf(stderr,"To less out space\n"); + return MP3_ERR; + } + + if(in!=NULL) + { + if(addbuf(mp,in,isize) == NULL) + return MP3_ERR; + } + + + /* First decode header */ + if(!mp->header_parsed) + { + if (mp->fsizeold==-1 || mp->sync_bitstream) + { + int vbrbytes; + + mp->sync_bitstream=0; + + /* This is the very first call. sync with anything */ + /* bytes= number of bytes before header */ + bytes=sync_buffer(mp,0); + + /* now look for Xing VBR header */ + if (mp->bsize >= bytes+XING_HEADER_SIZE ) + { + /* vbrbytes = number of bytes in entire vbr header */ + vbrbytes=check_vbr_header(mp,bytes); + } + else + { + /* not enough data to look for Xing header */ + + //changed for DecMPA + //since DecMPA only passes in full frames and there is + //not enough data for a xing header, there is no Xing header. + if(mp->bsize==0) + return MP3_NEED_MORE; //no data at all, need next frame + else + { + //frame too small for xing header => no xing header + mp->vbr_header=0; + vbrbytes=0; + } + //return MP3_NEED_MORE; + + } + + if (mp->vbr_header) + { + /* do we have enough data to parse entire Xing header? */ + if (bytes+vbrbytes > mp->bsize) + return MP3_NEED_MORE; + + /* read in Xing header. Buffer data in case it + * is used by a non zero main_data_begin for the next + * frame, but otherwise dont decode Xing header */ + /*fprintf(stderr,"found xing header, skipping %i bytes\n",vbrbytes+bytes);*/ + for (i=0; i0) + { + /* there were some extra bytes in front of header. + * bitstream problem, but we are now resynced + * should try to buffer previous data in case new + * frame has nonzero main_data_begin, but we need + * to make sure we do not overflow buffer + */ + int size; + + //fprintf(stderr,"bitstream problem: resyncing...\n"); + mp->old_free_format=0; + mp->sync_bitstream=1; + + /* skip some bytes, buffer the rest */ + size = (int) (wordpointer - (mp->bsspace[mp->bsnum]+512)); + + if (size > MAXFRAMESIZE) + { + /* wordpointer buffer is trashed. probably cant recover, but try anyway */ + //fprintf(stderr,"mpglib: wordpointer trashed. size=%i (%i) bytes=%i \n", + //size,MAXFRAMESIZE,bytes); + size=0; + wordpointer = mp->bsspace[mp->bsnum]+512; + } + + /* buffer contains 'size' data right now + we want to add 'bytes' worth of data, but do not + exceed MAXFRAMESIZE, so we through away 'i' bytes */ + i = (size+bytes)-MAXFRAMESIZE; + for (; i>0; --i) + { + --bytes; + read_buf_byte(mp); + } + + copy_mp(mp,bytes,wordpointer); + mp->fsizeold += bytes; + } + + read_head(mp); + decode_header(&mp->fr,mp->header); + mp->header_parsed=1; + mp->framesize = mp->fr.framesize; + mp->free_format = (mp->framesize==0); + + if(mp->fr.lsf) + mp->ssize = (mp->fr.stereo == 1) ? 9 : 17; + else + mp->ssize = (mp->fr.stereo == 1) ? 17 : 32; + if (mp->fr.error_protection) + mp->ssize += 2; + + mp->bsnum = 1-mp->bsnum; /* toggle buffer */ + wordpointer = mp->bsspace[mp->bsnum] + 512; + bitindex = 0; + + /* for very first header, never parse rest of data */ + //Hauke Duden: why? header_parsed is 1 so continuing here is the same + //as returning and then being called again with no new data (or not + //enough new data) + //=> removed + //if (mp->fsizeold==-1) + //return MP3_NEED_MORE; + + } + + /* now decode side information */ + if (!mp->side_parsed) + { + /* Layer 3 only */ + if (mp->fr.lay==3) + { + if (mp->bsize < mp->ssize) + return MP3_NEED_MORE; + + copy_mp(mp,mp->ssize,wordpointer); + + if(mp->fr.error_protection) + getbits(16); + bits=do_layer3_sideinfo(&mp->fr); + + /* bits = actual number of bits needed to parse this frame */ + /* can be negative, if all bits needed are in the reservoir */ + if (bits<0) + bits=0; + + /* read just as many bytes as necessary before decoding */ + mp->dsize = (bits+7)/8; + + /* this will force mpglib to read entire frame before decoding */ + /* mp->dsize= mp->framesize - mp->ssize;*/ + } + else + { + /* Layers 1 and 2 */ + + /* check if there is enough input data */ + if(mp->fr.framesize > mp->bsize) + return MP3_NEED_MORE; + + /* takes care that the right amount of data is copied into wordpointer */ + mp->dsize=mp->fr.framesize; + mp->ssize=0; + } + + mp->side_parsed=1; + } + + /* now decode main data */ + iret=MP3_NEED_MORE; + if (!mp->data_parsed ) + { + if(mp->dsize > mp->bsize) + return MP3_NEED_MORE; + + copy_mp(mp,mp->dsize,wordpointer); + + *done = 0; + + //do_layer3(&mp->fr,(unsigned char *) out,done); + switch (mp->fr.lay) + { +#ifdef USE_LAYER_1 + case 1: + if(mp->fr.error_protection) + getbits(16); + + do_layer1(mp,(unsigned char *) out,done); + break; +#endif +#ifdef USE_LAYER_2 + case 2: + if(mp->fr.error_protection) + getbits(16); + + do_layer2(mp,(unsigned char *) out,done); + break; +#endif + case 3: + do_layer3(mp,(unsigned char *) out,done); + break; + default: + //fprintf(stderr,"invalid layer %d\n",mp->fr.lay); + break; + } + + wordpointer = mp->bsspace[mp->bsnum] + 512 + mp->ssize + mp->dsize; + + mp->data_parsed=1; + iret=MP3_OK; + } + + + /* remaining bits are ancillary data, or reservoir for next frame + * If free format, scan stream looking for next frame to determine + * mp->framesize */ + if (mp->free_format) + { + if (mp->old_free_format) + { + /* free format. bitrate must not vary */ + mp->framesize=mp->fsizeold_nopadding + (mp->fr.padding); + } + else + { + bytes=sync_buffer(mp,1); + if (bytes<0) + return iret; + mp->framesize = bytes + mp->ssize+mp->dsize; + mp->fsizeold_nopadding= mp->framesize - mp->fr.padding; + /* + fprintf(stderr,"freeformat bitstream: estimated bitrate=%ikbs \n", + 8*(4+mp->framesize)*freqs[mp->fr.sampling_frequency]/ + (1000*576*(2-mp->fr.lsf))); + */ + } + } + + /* buffer the ancillary data and reservoir for next frame */ + bytes = mp->framesize-(mp->ssize+mp->dsize); + if (bytes > mp->bsize) + return iret; + + if (bytes>0) + { + int size; + copy_mp(mp,bytes,wordpointer); + wordpointer += bytes; + + size = (int) (wordpointer - (mp->bsspace[mp->bsnum]+512)); + if (size > MAXFRAMESIZE) + { + //fprintf(stderr,"fatal error. MAXFRAMESIZE not large enough.\n"); + } + } + + /* the above frame is completey parsed. start looking for next frame */ + mp->fsizeold = mp->framesize; + mp->old_free_format = mp->free_format; + mp->framesize =0; + mp->header_parsed=0; + mp->side_parsed=0; + mp->data_parsed=0; + + return iret; +} + + + diff --git a/Libraries/DecMPA/Files/src/hip/interface.h b/Libraries/DecMPA/Files/src/hip/interface.h new file mode 100644 index 000000000..dc815b9c5 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/interface.h @@ -0,0 +1,47 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* +** Copyright (C) 2000 Albert L. Faber +**/ + +#ifndef INTERFACE_H_INCLUDED +#define INTERFACE_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#include "common.h" + +BOOL InitMP3(PMPSTR mp); +int decodeMP3(PMPSTR mp,unsigned char *inmemory,int inmemsize,char *outmemory,int outmemsize,int *done); +void ExitMP3(PMPSTR mp); + +/* added remove_buf to support mpglib seeking */ +void remove_buf(PMPSTR mp); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/l2tables.h b/Libraries/DecMPA/Files/src/hip/l2tables.h new file mode 100644 index 000000000..8eef3661e --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/l2tables.h @@ -0,0 +1,177 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + + +/* + * Layer 2 Alloc tables .. + * most other tables are calculated on program start (which is (of course) + * not ISO-conform) .. + * Layer-3 huffman table is in huffman.h + */ + +const struct al_table2 alloc_0[] = { + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767} }; + +const struct al_table2 alloc_1[] = { + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767} }; + +const struct al_table2 alloc_2[] = { + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} }; + +const struct al_table2 alloc_3[] = { + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} }; + +const struct al_table2 alloc_4[] = { + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9} }; + diff --git a/Libraries/DecMPA/Files/src/hip/layer1.c b/Libraries/DecMPA/Files/src/hip/layer1.c new file mode 100644 index 000000000..68ac94355 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/layer1.c @@ -0,0 +1,194 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* + * Mpeg Layer-1 audio decoder + * -------------------------- + * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README' + * near unoptimzed ... + * + * may have a few bugs after last optimization ... + * + */ + +/* $Id: layer1.c 3 2005-06-02 18:16:43Z vspader $ */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "HIPDefines.h" + +#ifdef USE_LAYER_1 + +#include +#include "common.h" +#include "decode_i386.h" + +#ifdef WITH_DMALLOC +#include +#endif + +void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr) +{ + unsigned int *ba=balloc; + unsigned int *sca = (unsigned int *) scale_index; + + assert ( fr->stereo == 0 || fr->stereo == 1 ); + if(fr->stereo) { + int i; + int jsbound = fr->jsbound; + for (i=0;istereo == 0 || fr->stereo == 1 ); + if(fr->stereo) { + int jsbound = fr->jsbound; + register real *f0 = fraction[0]; + register real *f1 = fraction[1]; + ba = balloc; + for (sample=smpb,i=0;idown_sample_sblimit;i<32;i++) + fraction[0][i] = fraction[1][i] = 0.0; + } + else { + register real *f0 = fraction[0]; + ba = balloc; + for (sample=smpb,i=0;idown_sample_sblimit;i<32;i++) + fraction[0][i] = 0.0; + } +} + +//int do_layer1(struct frame *fr,int outmode,struct audio_info_struct *ai) +int do_layer1(PMPSTR mp, unsigned char *pcm_sample,int *pcm_point) +{ + int clip=0; + unsigned int balloc[2*SBLIMIT]; + unsigned int scale_index[2][SBLIMIT]; + real fraction[2][SBLIMIT]; + struct frame *fr=&(mp->fr); + int i,stereo = fr->stereo; + int single = fr->single; + + fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32; + + if(stereo == 1 || single == 3) + single = 0; + + I_step_one(balloc,scale_index,fr); + + for (i=0;i= 0) + { + clip += synth_1to1_mono( mp, (real *) fraction[single],pcm_sample,pcm_point); + } + else { + int p1 = *pcm_point; + clip += synth_1to1( mp, (real *) fraction[0],0,pcm_sample,&p1); + clip += synth_1to1( mp, (real *) fraction[1],1,pcm_sample,pcm_point); + } + } + + return clip; +} + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/layer1.h b/Libraries/DecMPA/Files/src/hip/layer1.h new file mode 100644 index 000000000..71a0a9a4d --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/layer1.h @@ -0,0 +1,33 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* +** Copyright (C) 2000 Albert L. Faber +**/ + + +#ifndef LAYER1_H_INCLUDED +#define LAYER1_H_INCLUDED + +int do_layer1(PMPSTR mp, unsigned char *pcm_sample,int *pcm_point); + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/layer2.c b/Libraries/DecMPA/Files/src/hip/layer2.c new file mode 100644 index 000000000..94393649a --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/layer2.c @@ -0,0 +1,333 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* + * Mpeg Layer-2 audio decoder + * -------------------------- + * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README' + * + */ + +/* $Id: layer2.c 3 2005-06-02 18:16:43Z vspader $ */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "HIPDefines.h" + +#ifdef USE_LAYER_2 + + +#include "common.h" +#include "layer2.h" +#include "l2tables.h" +#include "decode_i386.h" + +#ifdef WITH_DMALLOC +#include +#endif + +static int grp_3tab[32 * 3] = { 0, }; /* used: 27 */ +static int grp_5tab[128 * 3] = { 0, }; /* used: 125 */ +static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */ + +void init_layer2(void) +{ + static const double mulmul[27] = { + 0.0 , -2.0/3.0 , 2.0/3.0 , + 2.0/7.0 , 2.0/15.0 , 2.0/31.0, 2.0/63.0 , 2.0/127.0 , 2.0/255.0 , + 2.0/511.0 , 2.0/1023.0 , 2.0/2047.0 , 2.0/4095.0 , 2.0/8191.0 , + 2.0/16383.0 , 2.0/32767.0 , 2.0/65535.0 , + -4.0/5.0 , -2.0/5.0 , 2.0/5.0, 4.0/5.0 , + -8.0/9.0 , -4.0/9.0 , -2.0/9.0 , 2.0/9.0 , 4.0/9.0 , 8.0/9.0 }; + static const int base[3][9] = { + { 1 , 0, 2 , } , + { 17, 18, 0 , 19, 20 , } , + { 21, 1, 22, 23, 0, 24, 25, 2, 26 } }; + int i,j,k,l,len; + real *table; + static const int tablen[3] = { 3 , 5 , 9 }; + static int *itable,*tables[3] = { grp_3tab , grp_5tab , grp_9tab }; + + for(i=0;i<3;i++) + { + itable = tables[i]; + len = tablen[i]; + for(j=0;jstereo-1; + int sblimit = fr->II_sblimit; + int jsbound = fr->jsbound; + int sblimit2 = fr->II_sblimit<alloc; + int i; + static unsigned int scfsi_buf[64]; + unsigned int *scfsi,*bita; + int sc,step; + + bita = bit_alloc; + if(stereo) + { + for (i=jsbound;i;i--,alloc1+=(1<bits); + *bita++ = (char) getbits(step); + } + for (i=sblimit-jsbound;i;i--,alloc1+=(1<bits); + bita[1] = bita[0]; + bita+=2; + } + bita = bit_alloc; + scfsi=scfsi_buf; + for (i=sblimit2;i;i--) + if (*bita++) + *scfsi++ = (char) getbits_fast(2); + } + else /* mono */ + { + for (i=sblimit;i;i--,alloc1+=(1<bits); + bita = bit_alloc; + scfsi=scfsi_buf; + for (i=sblimit;i;i--) + if (*bita++) + *scfsi++ = (char) getbits_fast(2); + } + + bita = bit_alloc; + scfsi=scfsi_buf; + for (i=sblimit2;i;i--) + if (*bita++) + switch (*scfsi++) + { + case 0: + *scale++ = getbits_fast(6); + *scale++ = getbits_fast(6); + *scale++ = getbits_fast(6); + break; + case 1 : + *scale++ = sc = getbits_fast(6); + *scale++ = sc; + *scale++ = getbits_fast(6); + break; + case 2: + *scale++ = sc = getbits_fast(6); + *scale++ = sc; + *scale++ = sc; + break; + default: /* case 3 */ + *scale++ = getbits_fast(6); + *scale++ = sc = getbits_fast(6); + *scale++ = sc; + break; + } + +} + +void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1) +{ + int i,j,k,ba; + int stereo = fr->stereo; + int sblimit = fr->II_sblimit; + int jsbound = fr->jsbound; + struct al_table2 *alloc2,*alloc1 = fr->alloc; + unsigned int *bita=bit_alloc; + int d1,step; + + for (i=0;ibits; + for (j=0;jbits; + if( (d1=alloc2->d) < 0) + { + real cm=muls[k][scale[x1]]; + fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm; + fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm; + fraction[j][2][i] = ((real) ((int)getbits(k) + d1)) * cm; + } + else + { + static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab }; + unsigned int idx,*tab,m=scale[x1]; + idx = (unsigned int) getbits(k); + tab = (unsigned int *) (table[d1] + idx + idx + idx); + fraction[j][0][i] = muls[*tab++][m]; + fraction[j][1][i] = muls[*tab++][m]; + fraction[j][2][i] = muls[*tab][m]; + } + scale+=3; + } + else + fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; + } + } + + for (i=jsbound;ibits; + bita++; /* channel 1 and channel 2 bitalloc are the same */ + if ( (ba=*bita++) ) + { + k=(alloc2 = alloc1+ba)->bits; + if( (d1=alloc2->d) < 0) + { + real cm; + cm=muls[k][scale[x1+3]]; + fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)getbits(k) + d1) ) * cm; + fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)getbits(k) + d1) ) * cm; + fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)getbits(k) + d1) ) * cm; + cm=muls[k][scale[x1]]; + fraction[0][0][i] *= cm; fraction[0][1][i] *= cm; fraction[0][2][i] *= cm; + } + else + { + static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab }; + unsigned int idx,*tab,m1,m2; + m1 = scale[x1]; m2 = scale[x1+3]; + idx = (unsigned int) getbits(k); + tab = (unsigned int *) (table[d1] + idx + idx + idx); + fraction[0][0][i] = muls[*tab][m1]; fraction[1][0][i] = muls[*tab++][m2]; + fraction[0][1][i] = muls[*tab][m1]; fraction[1][1][i] = muls[*tab++][m2]; + fraction[0][2][i] = muls[*tab][m1]; fraction[1][2][i] = muls[*tab][m2]; + } + scale+=6; + } + else { + fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = + fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0; + } +/* + should we use individual scalefac for channel 2 or + is the current way the right one , where we just copy channel 1 to + channel 2 ?? + The current 'strange' thing is, that we throw away the scalefac + values for the second channel ...!! +-> changed .. now we use the scalefac values of channel one !! +*/ + } + +// if(sblimit > (fr->down_sample_sblimit) ) +// sblimit = fr->down_sample_sblimit; + + for(i=sblimit;ilsf) + table = 4; + else + table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index]; + sblim = sblims[table]; + + fr->alloc = (struct al_table2*)tables[table]; + fr->II_sblimit = sblim; +} + + +int do_layer2( PMPSTR mp,unsigned char *pcm_sample,int *pcm_point) +//int do_layer2(struct frame *fr,int outmode,struct audio_info_struct *ai) +{ + int clip=0; + int i,j; + real fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */ + unsigned int bit_alloc[64]; + int scale[192]; + struct frame *fr=&(mp->fr); + int stereo = fr->stereo; + int single = fr->single; + + II_select_table(fr); + fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? + (fr->mode_ext<<2)+4 : fr->II_sblimit; + + if(stereo == 1 || single == 3) + single = 0; + + II_step_one(bit_alloc, scale, fr); + + for (i=0;i>2); + for (j=0;j<3;j++) + { + if(single >= 0) + { + clip += synth_1to1_mono(mp, fraction[single][j],pcm_sample,pcm_point); + } + else { + int p1 = *pcm_point; + clip += synth_1to1(mp, fraction[0][j],0,pcm_sample,&p1); + clip += synth_1to1(mp, fraction[1][j],1,pcm_sample,pcm_point); + } + } + } + + return clip; +} + + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/layer2.h b/Libraries/DecMPA/Files/src/hip/layer2.h new file mode 100644 index 000000000..557a32573 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/layer2.h @@ -0,0 +1,49 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* +** Copyright (C) 2000 Albert L. Faber +**/ + +#ifdef USE_LAYER_2 + +#ifndef LAYER2_H_INCLUDED +#define LAYER2_H_INCLUDED + + +struct al_table2 +{ + short bits; + short d; +}; + + + +void init_layer2(void); +void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr); +void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1); +int do_layer2( PMPSTR mp,unsigned char *pcm_sample,int *pcm_point); + +#endif + +#endif + diff --git a/Libraries/DecMPA/Files/src/hip/layer3.c b/Libraries/DecMPA/Files/src/hip/layer3.c new file mode 100644 index 000000000..ae921b584 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/layer3.c @@ -0,0 +1,1827 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* + * Mpeg Layer-3 audio decoder + * -------------------------- + * copyright (c) 1995,1996,1997 by Michael Hipp. + * All rights reserved. See also 'README' + */ + +/* $Id: layer3.c 3 2005-06-02 18:16:43Z vspader $ */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include "common.h" +#include "huffman.h" +#include "decode_i386.h" + +#ifdef WITH_DMALLOC +#include +#endif + +#define MPEG1 + + +static real ispow[8207]; +static real aa_ca[8],aa_cs[8]; +static real COS1[12][6]; +static real win[4][36]; +static real win1[4][36]; +static real gainpow2[256+118+4]; +static real COS9[9]; +static real COS6_1,COS6_2; +static real tfcos36[9]; +static real tfcos12[3]; + +struct bandInfoStruct { + short longIdx[23]; + short longDiff[22]; + short shortIdx[14]; + short shortDiff[13]; +}; + +int longLimit[9][23]; +int shortLimit[9][14]; + +const struct bandInfoStruct bandInfo[9] = { + +/* MPEG 1.0 */ + { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576}, + {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158}, + {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3}, + {4,4,4,4,6,8,10,12,14,18,22,30,56} } , + + { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576}, + {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192}, + {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3}, + {4,4,4,4,6,6,10,12,14,16,20,26,66} } , + + { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} , + {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} , + {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} , + {4,4,4,4,6,8,12,16,20,26,34,42,12} } , + +/* MPEG 2.0 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } , + {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} , + {4,4,4,6,6,8,10,14,18,26,32,42,18 } } , + /* docs: 332. mpg123: 330 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576}, + {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36 } , + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} , + {4,4,4,6,8,10,12,14,18,24,32,44,12 } } , + + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 }, + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3}, + {4,4,4,6,8,10,12,14,18,24,30,40,18 } } , +/* MPEG 2.5 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}, + {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2}, + {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576}, + {8,8,8,12,16,20,24,28,36,2,2,2,26} } , +}; + +static int mapbuf0[9][152]; +static int mapbuf1[9][156]; +static int mapbuf2[9][44]; +static int *map[9][3]; +static int *mapend[9][3]; + +static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ +static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ + +static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16]; +static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16]; + +static unsigned int get1bit(void) +{ + unsigned char rval; + rval = *wordpointer << bitindex; + + bitindex++; + wordpointer += (bitindex>>3); + bitindex &= 7; + + return rval>>7; +} + + + + +/* + * init tables for layer-3 + */ +void init_layer3(int down_sample_sblimit) +{ + int i,j,k; + + for(i=-256;i<118+4;i++) + gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) ); + + for(i=0;i<8207;i++) + ispow[i] = pow((double)i,(double)4.0/3.0); + + for (i=0;i<8;i++) + { + static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037}; + double sq=sqrt(1.0+Ci[i]*Ci[i]); + aa_cs[i] = 1.0/sq; + aa_ca[i] = Ci[i]/sq; + } + + for(i=0;i<18;i++) + { + win[0][i] = win[1][i] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 ); + win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); + } + for(i=0;i<6;i++) + { + win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); + win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 ); + win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 ); + win[1][i+30] = win[3][i] = 0.0; + win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 ); + } + + for(i=0;i<9;i++) + COS9[i] = cos( M_PI / 18.0 * (double) i); + + for(i=0;i<9;i++) + tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 ); + for(i=0;i<3;i++) + tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 ); + + COS6_1 = cos( M_PI / 6.0 * (double) 1); + COS6_2 = cos( M_PI / 6.0 * (double) 2); + + for(i=0;i<12;i++) + { + win[2][i] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 ); + for(j=0;j<6;j++) + COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) ); + } + + for(j=0;j<4;j++) { + static int len[4] = { 36,36,12,36 }; + for(i=0;i 0) { + if( i & 1 ) + p1 = pow(base,(i+1.0)*0.5); + else + p2 = pow(base,i*0.5); + } + pow1_1[j][i] = p1; + pow2_1[j][i] = p2; + pow1_2[j][i] = M_SQRT2 * p1; + pow2_2[j][i] = M_SQRT2 * p2; + } + } + + for(j=0;j<9;j++) + { + struct bandInfoStruct *bi = (struct bandInfoStruct *)&bandInfo[j]; + int *mp; + int cb,lwin; + short *bdf; + + mp = map[j][0] = mapbuf0[j]; + bdf = bi->longDiff; + for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) { + *mp++ = (*bdf) >> 1; + *mp++ = i; + *mp++ = 3; + *mp++ = cb; + } + bdf = bi->shortDiff+3; + for(cb=3;cb<13;cb++) { + int l = (*bdf++) >> 1; + for(lwin=0;lwin<3;lwin++) { + *mp++ = l; + *mp++ = i + lwin; + *mp++ = lwin; + *mp++ = cb; + } + i += 6*l; + } + mapend[j][0] = mp; + + mp = map[j][1] = mapbuf1[j]; + bdf = bi->shortDiff+0; + for(i=0,cb=0;cb<13;cb++) { + int l = (*bdf++) >> 1; + for(lwin=0;lwin<3;lwin++) { + *mp++ = l; + *mp++ = i + lwin; + *mp++ = lwin; + *mp++ = cb; + } + i += 6*l; + } + mapend[j][1] = mp; + + mp = map[j][2] = mapbuf2[j]; + bdf = bi->longDiff; + for(cb = 0; cb < 22 ; cb++) { + *mp++ = (*bdf++) >> 1; + *mp++ = cb; + } + mapend[j][2] = mp; + + } + + for(j=0;j<9;j++) { + for(i=0;i<23;i++) { + longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1; + if(longLimit[j][i] > (down_sample_sblimit) ) + longLimit[j][i] = down_sample_sblimit; + } + for(i=0;i<14;i++) { + shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1; + if(shortLimit[j][i] > (down_sample_sblimit) ) + shortLimit[j][i] = down_sample_sblimit; + } + } + + for(i=0;i<5;i++) { + for(j=0;j<6;j++) { + for(k=0;k<6;k++) { + int n = k + j * 6 + i * 36; + i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12); + } + } + } + for(i=0;i<4;i++) { + for(j=0;j<4;j++) { + for(k=0;k<4;k++) { + int n = k + j * 4 + i * 16; + i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12); + } + } + } + for(i=0;i<4;i++) { + for(j=0;j<3;j++) { + int n = j + i * 3; + i_slen2[n+244] = i|(j<<3) | (5<<12); + n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15); + } + } + + for(i=0;i<5;i++) { + for(j=0;j<5;j++) { + for(k=0;k<4;k++) { + int l; + for(l=0;l<4;l++) { + int n = l + k * 4 + j * 16 + i * 80; + n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12); + } + } + } + } + for(i=0;i<5;i++) { + for(j=0;j<5;j++) { + for(k=0;k<4;k++) { + int n = k + j * 4 + i * 20; + n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12); + } + } + } +} + +/* + * read additional side information + */ +#ifdef MPEG1 +static void III_get_side_info_1(struct III_sideinfo *si,int stereo, + int ms_stereo,long sfreq,int single) +{ + int ch, gr; + int powdiff = (single == 3) ? 4 : 0; + + si->main_data_begin = getbits(9); + if (stereo == 1) + si->private_bits = getbits_fast(5); + else + si->private_bits = getbits_fast(3); + + for (ch=0; chch[ch].gr[0].scfsi = -1; + si->ch[ch].gr[1].scfsi = getbits_fast(4); + } + + for (gr=0; gr<2; gr++) + { + for (ch=0; chch[ch].gr[gr]); + + gr_infos->part2_3_length = getbits(12); + gr_infos->big_values = getbits_fast(9); + if(gr_infos->big_values > 288) { + //fprintf(stderr,"big_values too large! %i\n",gr_infos->big_values); + gr_infos->big_values = 288; + } + { + unsigned int qss = getbits_fast(8); + gr_infos->pow2gain = gainpow2+256 - qss + powdiff; +/* +#ifndef NOANALYSIS + if (mpg123_pinfo != NULL) { + mpg123_pinfo->qss[gr][ch]=qss; + } +#endif +*/ + } + if(ms_stereo) + gr_infos->pow2gain += 2; + gr_infos->scalefac_compress = getbits_fast(4); +/* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */ + if(get1bit()) + { + int i; + gr_infos->block_type = getbits_fast(2); + gr_infos->mixed_block_flag = get1bit(); + gr_infos->table_select[0] = getbits_fast(5); + gr_infos->table_select[1] = getbits_fast(5); + + + /* + * table_select[2] not needed, because there is no region2, + * but to satisfy some verifications tools we set it either. + */ + gr_infos->table_select[2] = 0; + for(i=0;i<3;i++) { + unsigned int sbg = (getbits_fast(3)<<3); + gr_infos->full_gain[i] = gr_infos->pow2gain + sbg; +/* +#ifndef NOANALYSIS + if (mpg123_pinfo != NULL) + mpg123_pinfo->sub_gain[gr][ch][i]=sbg/8; +#endif +*/ + } + + if(gr_infos->block_type == 0) { + //fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n"); + /* error seems to be very good recoverable, so don't exit */ + /* exit(1); */ + } + /* region_count/start parameters are implicit in this case. */ + gr_infos->region1start = 36>>1; + gr_infos->region2start = 576>>1; + } + else + { + int i,r0c,r1c; + for (i=0; i<3; i++) + gr_infos->table_select[i] = getbits_fast(5); + r0c = getbits_fast(4); + r1c = getbits_fast(3); + gr_infos->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; + gr_infos->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; + gr_infos->block_type = 0; + gr_infos->mixed_block_flag = 0; + } + gr_infos->preflag = get1bit(); + gr_infos->scalefac_scale = get1bit(); + gr_infos->count1table_select = get1bit(); + } + } +} +#endif + +/* + * Side Info for MPEG 2.0 / LSF + */ +static void III_get_side_info_2(struct III_sideinfo *si,int stereo, + int ms_stereo,long sfreq,int single) +{ + int ch; + int powdiff = (single == 3) ? 4 : 0; + + si->main_data_begin = getbits(8); + + if (stereo == 1) + si->private_bits = get1bit(); + else + si->private_bits = getbits_fast(2); + + for (ch=0; chch[ch].gr[0]); + unsigned int qss; + + gr_infos->part2_3_length = getbits(12); + gr_infos->big_values = getbits_fast(9); + if(gr_infos->big_values > 288) { + //fprintf(stderr,"big_values too large! %i\n",gr_infos->big_values); + gr_infos->big_values = 288; + } + qss=getbits_fast(8); + gr_infos->pow2gain = gainpow2+256 - qss + powdiff; +/* +#ifndef NOANALYSIS + if (mpg123_pinfo!=NULL) { + mpg123_pinfo->qss[0][ch]=qss; + } +#endif +*/ + + + if(ms_stereo) + gr_infos->pow2gain += 2; + gr_infos->scalefac_compress = getbits(9); +/* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */ + if(get1bit()) + { + int i; + gr_infos->block_type = getbits_fast(2); + gr_infos->mixed_block_flag = get1bit(); + gr_infos->table_select[0] = getbits_fast(5); + gr_infos->table_select[1] = getbits_fast(5); + /* + * table_select[2] not needed, because there is no region2, + * but to satisfy some verifications tools we set it either. + */ + gr_infos->table_select[2] = 0; + for(i=0;i<3;i++) { + unsigned int sbg = (getbits_fast(3)<<3); + gr_infos->full_gain[i] = gr_infos->pow2gain + sbg; +/* +#ifndef NOANALYSIS + if (mpg123_pinfo!=NULL) + mpg123_pinfo->sub_gain[0][ch][i]=sbg/8; +#endif +*/ + + } + + if(gr_infos->block_type == 0) { + //fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n"); + /* error seems to be very good recoverable, so don't exit */ + /* exit(1); */ + } + /* region_count/start parameters are implicit in this case. */ +/* check this again! */ + if(gr_infos->block_type == 2) + gr_infos->region1start = 36>>1; + else if(sfreq == 8) +/* check this for 2.5 and sfreq=8 */ + gr_infos->region1start = 108>>1; + else + gr_infos->region1start = 54>>1; + gr_infos->region2start = 576>>1; + } + else + { + int i,r0c,r1c; + for (i=0; i<3; i++) + gr_infos->table_select[i] = getbits_fast(5); + r0c = getbits_fast(4); + r1c = getbits_fast(3); + gr_infos->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; + gr_infos->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; + gr_infos->block_type = 0; + gr_infos->mixed_block_flag = 0; + } + gr_infos->scalefac_scale = get1bit(); + gr_infos->count1table_select = get1bit(); + } +} + +/* + * read scalefactors + */ +#ifdef MPEG1 +static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_infos) +{ + static const unsigned char slen[2][16] = { + {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, + {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3} + }; + int numbits; + int num0 = slen[0][gr_infos->scalefac_compress]; + int num1 = slen[1][gr_infos->scalefac_compress]; + + if (gr_infos->block_type == 2) + { + int i=18; + numbits = (num0 + num1) * 18; + + if (gr_infos->mixed_block_flag) { + for (i=8;i;i--) + *scf++ = getbits_fast(num0); + i = 9; + numbits -= num0; /* num0 * 17 + num1 * 18 */ + } + + for (;i;i--) + *scf++ = getbits_fast(num0); + for (i = 18; i; i--) + *scf++ = getbits_fast(num1); + *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */ + } + else + { + int i; + int scfsi = gr_infos->scfsi; + + if(scfsi < 0) { /* scfsi < 0 => granule == 0 */ + for(i=11;i;i--) + *scf++ = getbits_fast(num0); + for(i=10;i;i--) + *scf++ = getbits_fast(num1); + numbits = (num0 + num1) * 10 + num0; + } + else { + numbits = 0; + if(!(scfsi & 0x8)) { + for (i=6;i;i--) + *scf++ = getbits_fast(num0); + numbits += num0 * 6; + } + else { + scf += 6; + } + + if(!(scfsi & 0x4)) { + for (i=5;i;i--) + *scf++ = getbits_fast(num0); + numbits += num0 * 5; + } + else { + scf += 5; + } + + if(!(scfsi & 0x2)) { + for(i=5;i;i--) + *scf++ = getbits_fast(num1); + numbits += num1 * 5; + } + else { + scf += 5; + } + + if(!(scfsi & 0x1)) { + for (i=5;i;i--) + *scf++ = getbits_fast(num1); + numbits += num1 * 5; + } + else { + scf += 5; + } + } + + *scf++ = 0; /* no l[21] in original sources */ + } + return numbits; +} +#endif + +static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_infos,int i_stereo) +{ + unsigned char *pnt; + int i,j; + unsigned int slen; + int n = 0; + int numbits = 0; + + static const unsigned char stab[3][6][4] = { + { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} , + { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } , + { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} , + {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } , + { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} , + { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } }; + + if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */ + slen = i_slen2[gr_infos->scalefac_compress>>1]; + else + slen = n_slen2[gr_infos->scalefac_compress]; + + gr_infos->preflag = (slen>>15) & 0x1; + + n = 0; + if( gr_infos->block_type == 2 ) { + n++; + if(gr_infos->mixed_block_flag) + n++; + } + + pnt = (unsigned char *)stab[n][(slen>>12)&0x7]; + + for(i=0;i<4;i++) { + int num = slen & 0x7; + slen >>= 3; + if(num) { + for(j=0;j<(int)(pnt[i]);j++) + *scf++ = getbits_fast(num); + numbits += pnt[i] * num; + } + else { + for(j=0;j<(int)(pnt[i]);j++) + *scf++ = 0; + } + } + + n = (n << 1) + 1; + for(i=0;iscalefac_scale; + real *xrpnt = (real *) xr; + int l[3],l3; + int part2remain = gr_infos->part2_3_length - part2bits; + int *me; + + { + int i; + + for(i=(&xr[SBLIMIT][0]-xrpnt)>>1;i>0;i--) { + *xrpnt++ = 0.0; + *xrpnt++ = 0.0; + } + + xrpnt = (real *) xr; + } + + { + int bv = gr_infos->big_values; + int region1 = gr_infos->region1start; + int region2 = gr_infos->region2start; + + l3 = ((576>>1)-bv)>>1; +/* + * we may lose the 'odd' bit here !! + * check this later again + */ + if(bv <= region1) { + l[0] = bv; l[1] = 0; l[2] = 0; + } + else { + l[0] = region1; + if(bv <= region2) { + l[1] = bv - l[0]; l[2] = 0; + } + else { + l[1] = region2 - l[0]; l[2] = bv - region2; + } + } + } + + if(gr_infos->block_type == 2) { + /* + * decoding with short or mixed mode BandIndex table + */ + int i,max[4]; + int step=0,lwin=0,cb=0; + register real v = 0.0; + register int *m,mc; + + if(gr_infos->mixed_block_flag) { + max[3] = -1; + max[0] = max[1] = max[2] = 2; + m = map[sfreq][0]; + me = mapend[sfreq][0]; + } + else { + max[0] = max[1] = max[2] = max[3] = -1; + /* max[3] not really needed in this case */ + m = map[sfreq][1]; + me = mapend[sfreq][1]; + } + + mc = 0; + for(i=0;i<2;i++) { + int lp = l[i]; + struct newhuff *h = (struct newhuff *)(ht+gr_infos->table_select[i]); + for(;lp;lp--,mc--) { + register int x,y; + if( (!mc) ) { + mc = *m++; + xrpnt = ((real *) xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) { + v = gr_infos->pow2gain[(*scf++) << shift]; + step = 1; + } + else { + v = gr_infos->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + { + register short *val = (short *)h->table; + while((y=*val++)<0) { + if (get1bit()) + val -= y; + part2remain--; + } + x = y >> 4; + y &= 0xf; + } + if(x == 15) { + max[lwin] = cb; + part2remain -= h->linbits+1; + x += getbits((int)h->linbits); + if(get1bit()) + *xrpnt = -ispow[x] * v; + else + *xrpnt = ispow[x] * v; + } + else if(x) { + max[lwin] = cb; + if(get1bit()) + *xrpnt = -ispow[x] * v; + else + *xrpnt = ispow[x] * v; + part2remain--; + } + else + *xrpnt = 0.0; + xrpnt += step; + if(y == 15) { + max[lwin] = cb; + part2remain -= h->linbits+1; + y += getbits((int)h->linbits); + if(get1bit()) + *xrpnt = -ispow[y] * v; + else + *xrpnt = ispow[y] * v; + } + else if(y) { + max[lwin] = cb; + if(get1bit()) + *xrpnt = -ispow[y] * v; + else + *xrpnt = ispow[y] * v; + part2remain--; + } + else + *xrpnt = 0.0; + xrpnt += step; + } + } + for(;l3 && (part2remain > 0);l3--) { + struct newhuff *h = (struct newhuff *)(htc+gr_infos->count1table_select); + register short *val = (short *)h->table,a; + + while((a=*val++)<0) { + part2remain--; + if(part2remain < 0) { + part2remain++; + a = 0; + break; + } + if (get1bit()) + val -= a; + } + for(i=0;i<4;i++) { + if(!(i & 1)) { + if(!mc) { + mc = *m++; + xrpnt = ((real *) xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) { + v = gr_infos->pow2gain[(*scf++) << shift]; + step = 1; + } + else { + v = gr_infos->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + mc--; + } + if( (a & (0x8>>i)) ) { + max[lwin] = cb; + part2remain--; + if(part2remain < 0) { + part2remain++; + break; + } + if(get1bit()) + *xrpnt = -v; + else + *xrpnt = v; + } + else + *xrpnt = 0.0; + xrpnt += step; + } + } + + while( m < me ) { + if(!mc) { + mc = *m++; + xrpnt = ((real *) xr) + *m++; + if( (*m++) == 3) + step = 1; + else + step = 3; + m++; /* cb */ + } + mc--; + *xrpnt = 0.0; + xrpnt += step; + *xrpnt = 0.0; + xrpnt += step; +/* we could add a little opt. here: + * if we finished a band for window 3 or a long band + * further bands could copied in a simple loop without a + * special 'map' decoding + */ + } + + gr_infos->maxband[0] = max[0]+1; + gr_infos->maxband[1] = max[1]+1; + gr_infos->maxband[2] = max[2]+1; + gr_infos->maxbandl = max[3]+1; + + { + int rmax = max[0] > max[1] ? max[0] : max[1]; + rmax = (rmax > max[2] ? rmax : max[2]) + 1; + gr_infos->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1]; + } + + } + else { + /* + * decoding with 'long' BandIndex table (block_type != 2) + */ + int *pretab = (int *)(gr_infos->preflag ? pretab1 : pretab2); + int i,max = -1; + int cb = 0; + register int *m = map[sfreq][2]; + register real v = 0.0; + register int mc = 0; +#if 0 + me = mapend[sfreq][2]; +#endif + + /* + * long hash table values + */ + for(i=0;i<3;i++) { + int lp = l[i]; + struct newhuff *h = (struct newhuff *)(ht+gr_infos->table_select[i]); + + for(;lp;lp--,mc--) { + int x,y; + + if(!mc) { + mc = *m++; + v = gr_infos->pow2gain[((*scf++) + (*pretab++)) << shift]; + cb = *m++; + } + { + register short *val = (short *)h->table; + while((y=*val++)<0) { + if (get1bit()) + val -= y; + part2remain--; + } + x = y >> 4; + y &= 0xf; + } + if (x == 15) { + max = cb; + part2remain -= h->linbits+1; + x += getbits((int)h->linbits); + if(get1bit()) + *xrpnt++ = -ispow[x] * v; + else + *xrpnt++ = ispow[x] * v; + } + else if(x) { + max = cb; + if(get1bit()) + *xrpnt++ = -ispow[x] * v; + else + *xrpnt++ = ispow[x] * v; + part2remain--; + } + else + *xrpnt++ = 0.0; + + if (y == 15) { + max = cb; + part2remain -= h->linbits+1; + y += getbits((int)h->linbits); + if(get1bit()) + *xrpnt++ = -ispow[y] * v; + else + *xrpnt++ = ispow[y] * v; + } + else if(y) { + max = cb; + if(get1bit()) + *xrpnt++ = -ispow[y] * v; + else + *xrpnt++ = ispow[y] * v; + part2remain--; + } + else + *xrpnt++ = 0.0; + } + } + + /* + * short (count1table) values + */ + for(;l3 && (part2remain > 0);l3--) { + struct newhuff *h = (struct newhuff *)(htc+gr_infos->count1table_select); + register short *val = (short *)h->table,a; + + while((a=*val++)<0) { + part2remain--; + if(part2remain < 0) { + part2remain++; + a = 0; + break; + } + if (get1bit()) + val -= a; + } + for(i=0;i<4;i++) { + if(!(i & 1)) { + if(!mc) { + mc = *m++; + cb = *m++; + v = gr_infos->pow2gain[((*scf++) + (*pretab++)) << shift]; + } + mc--; + } + if ( (a & (0x8>>i)) ) { + max = cb; + part2remain--; + if(part2remain < 0) { + part2remain++; + break; + } + if(get1bit()) + *xrpnt++ = -v; + else + *xrpnt++ = v; + } + else + *xrpnt++ = 0.0; + } + } + + /* + * zero part + */ + for(i=(&xr[SBLIMIT][0]-xrpnt)>>1;i;i--) { + *xrpnt++ = 0.0; + *xrpnt++ = 0.0; + } + + gr_infos->maxbandl = max+1; + gr_infos->maxb = longLimit[sfreq][gr_infos->maxbandl]; + } + + while( part2remain > 16 ) { + getbits(16); /* Dismiss stuffing Bits */ + part2remain -= 16; + } + if(part2remain > 0) + getbits(part2remain); + else if(part2remain < 0) { + //fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain); + return 1; /* -> error */ + } + return 0; +} + + +/* + * III_stereo: calculate real channel values for Joint-I-Stereo-mode + */ +static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, + struct gr_info_s *gr_infos,int sfreq,int ms_stereo,int lsf) +{ + real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf; + struct bandInfoStruct *bi = (struct bandInfoStruct *)&bandInfo[sfreq]; + real *tabl1,*tabl2; + + if(lsf) { + int p = gr_infos->scalefac_compress & 0x1; + if(ms_stereo) { + tabl1 = pow1_2[p]; tabl2 = pow2_2[p]; + } + else { + tabl1 = pow1_1[p]; tabl2 = pow2_1[p]; + } + } + else { + if(ms_stereo) { + tabl1 = tan1_2; tabl2 = tan2_2; + } + else { + tabl1 = tan1_1; tabl2 = tan2_1; + } + } + + if (gr_infos->block_type == 2) + { + int lwin,do_l = 0; + if( gr_infos->mixed_block_flag ) + do_l = 1; + + for (lwin=0;lwin<3;lwin++) /* process each window */ + { + /* get first band with zero values */ + int is_p,sb,idx,sfb = gr_infos->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ + if(sfb > 3) + do_l = 0; + + for(;sfb<12;sfb++) + { + is_p = scalefac[sfb*3+lwin-gr_infos->mixed_block_flag]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + sb = bi->shortDiff[sfb]; + idx = bi->shortIdx[sfb] + lwin; + t1 = tabl1[is_p]; t2 = tabl2[is_p]; + for (; sb > 0; sb--,idx+=3) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } + +#if 1 +/* in the original: copy 10 to 11 , here: copy 11 to 12 +maybe still wrong??? (copy 12 to 13?) */ + is_p = scalefac[11*3+lwin-gr_infos->mixed_block_flag]; /* scale: 0-15 */ + sb = bi->shortDiff[12]; + idx = bi->shortIdx[12] + lwin; +#else + is_p = scalefac[10*3+lwin-gr_infos->mixed_block_flag]; /* scale: 0-15 */ + sb = bi->shortDiff[11]; + idx = bi->shortIdx[11] + lwin; +#endif + if(is_p != 7) + { + real t1,t2; + t1 = tabl1[is_p]; t2 = tabl2[is_p]; + for ( ; sb > 0; sb--,idx+=3 ) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } /* end for(lwin; .. ; . ) */ + + if (do_l) + { +/* also check l-part, if ALL bands in the three windows are 'empty' + * and mode = mixed_mode + */ + int sfb = gr_infos->maxbandl; + int idx = bi->longIdx[sfb]; + + for ( ; sfb<8; sfb++ ) + { + int sb = bi->longDiff[sfb]; + int is_p = scalefac[sfb]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + t1 = tabl1[is_p]; t2 = tabl2[is_p]; + for ( ; sb > 0; sb--,idx++) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + else + idx += sb; + } + } + } + else /* ((gr_infos->block_type != 2)) */ + { + int sfb = gr_infos->maxbandl; + int is_p,idx = bi->longIdx[sfb]; + for ( ; sfb<21; sfb++) + { + int sb = bi->longDiff[sfb]; + is_p = scalefac[sfb]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + t1 = tabl1[is_p]; t2 = tabl2[is_p]; + for ( ; sb > 0; sb--,idx++) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + else + idx += sb; + } + + is_p = scalefac[20]; /* copy l-band 20 to l-band 21 */ + if(is_p != 7) + { + int sb; + real t1 = tabl1[is_p],t2 = tabl2[is_p]; + + for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) + { + real v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } /* ... */ +} + +static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_infos) +{ + int sblim; + + if(gr_infos->block_type == 2) + { + if(!gr_infos->mixed_block_flag) + return; + sblim = 1; + } + else { + sblim = gr_infos->maxb-1; + } + + /* 31 alias-reduction operations between each pair of sub-bands */ + /* with 8 butterflies between each pair */ + + { + int sb; + real *xr1=(real *) xr[1]; + + for(sb=sblim;sb;sb--,xr1+=10) + { + int ss; + real *cs=aa_cs,*ca=aa_ca; + real *xr2 = xr1; + + for(ss=7;ss>=0;ss--) + { /* upper and lower butterfly inputs */ + register real bu = *--xr2,bd = *xr1; + *xr2 = (bu * (*cs) ) - (bd * (*ca) ); + *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) ); + } + } + } +} + +/* + DCT insipired by Jeff Tsay's DCT from the maplay package + this is an optimized version with manual unroll. + + References: + [1] S. Winograd: "On Computing the Discrete Fourier Transform", + Mathematics of Computation, Volume 32, Number 141, January 1978, + Pages 175-199 +*/ + +static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf) +{ + { + register real *in = inbuf; + + in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; + in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11]; + in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8]; + in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; + in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; + in[2] +=in[1]; in[1] +=in[0]; + + in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; + in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1]; + + + { + +#define MACRO0(v) { \ + real tmp; \ + out2[9+(v)] = (tmp = sum0 + sum1) * w[27+(v)]; \ + out2[8-(v)] = tmp * w[26-(v)]; } \ + sum0 -= sum1; \ + ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \ + ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; +#define MACRO1(v) { \ + real sum0,sum1; \ + sum0 = tmp1a + tmp2a; \ + sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \ + MACRO0(v); } +#define MACRO2(v) { \ + real sum0,sum1; \ + sum0 = tmp2a - tmp1a; \ + sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \ + MACRO0(v); } + + register const real *c = COS9; + register real *out2 = o2; + register real *w = wintab; + register real *out1 = o1; + register real *ts = tsbuf; + + real ta33,ta66,tb33,tb66; + + ta33 = in[2*3+0] * c[3]; + ta66 = in[2*6+0] * c[6]; + tb33 = in[2*3+1] * c[3]; + tb66 = in[2*6+1] * c[6]; + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7]; + tmp1b = in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7]; + tmp2a = in[2*0+0] + in[2*2+0] * c[2] + in[2*4+0] * c[4] + ta66 + in[2*8+0] * c[8]; + tmp2b = in[2*0+1] + in[2*2+1] * c[2] + in[2*4+1] * c[4] + tb66 + in[2*8+1] * c[8]; + + MACRO1(0); + MACRO2(8); + } + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = ( in[2*1+0] - in[2*5+0] - in[2*7+0] ) * c[3]; + tmp1b = ( in[2*1+1] - in[2*5+1] - in[2*7+1] ) * c[3]; + tmp2a = ( in[2*2+0] - in[2*4+0] - in[2*8+0] ) * c[6] - in[2*6+0] + in[2*0+0]; + tmp2b = ( in[2*2+1] - in[2*4+1] - in[2*8+1] ) * c[6] - in[2*6+1] + in[2*0+1]; + + MACRO1(1); + MACRO2(7); + } + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = in[2*1+0] * c[5] - ta33 - in[2*5+0] * c[7] + in[2*7+0] * c[1]; + tmp1b = in[2*1+1] * c[5] - tb33 - in[2*5+1] * c[7] + in[2*7+1] * c[1]; + tmp2a = in[2*0+0] - in[2*2+0] * c[8] - in[2*4+0] * c[2] + ta66 + in[2*8+0] * c[4]; + tmp2b = in[2*0+1] - in[2*2+1] * c[8] - in[2*4+1] * c[2] + tb66 + in[2*8+1] * c[4]; + + MACRO1(2); + MACRO2(6); + } + + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = in[2*1+0] * c[7] - ta33 + in[2*5+0] * c[1] - in[2*7+0] * c[5]; + tmp1b = in[2*1+1] * c[7] - tb33 + in[2*5+1] * c[1] - in[2*7+1] * c[5]; + tmp2a = in[2*0+0] - in[2*2+0] * c[4] + in[2*4+0] * c[8] + ta66 - in[2*8+0] * c[2]; + tmp2b = in[2*0+1] - in[2*2+1] * c[4] + in[2*4+1] * c[8] + tb66 - in[2*8+1] * c[2]; + + MACRO1(3); + MACRO2(5); + } + + { + real sum0,sum1; + sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0]; + sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4]; + MACRO0(4); + } + } + + } +} + +/* + * new DCT12 + */ +static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts) +{ +#define DCT12_PART1 \ + in5 = in[5*3]; \ + in5 += (in4 = in[4*3]); \ + in4 += (in3 = in[3*3]); \ + in3 += (in2 = in[2*3]); \ + in2 += (in1 = in[1*3]); \ + in1 += (in0 = in[0*3]); \ + \ + in5 += in3; in3 += in1; \ + \ + in2 *= COS6_1; \ + in3 *= COS6_1; \ + +#define DCT12_PART2 \ + in0 += in4 * COS6_2; \ + \ + in4 = in0 + in2; \ + in0 -= in2; \ + \ + in1 += in5 * COS6_2; \ + \ + in5 = (in1 + in3) * tfcos12[0]; \ + in1 = (in1 - in3) * tfcos12[2]; \ + \ + in3 = in4 + in5; \ + in4 -= in5; \ + \ + in2 = in0 + in1; \ + in0 -= in1; + + + { + real in0,in1,in2,in3,in4,in5; + register real *out1 = rawout1; + ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2]; + ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5]; + + DCT12_PART1 + + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = (in1 - in5) * tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1]; + ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1]; + ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1]; + ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1]; + } + + DCT12_PART2 + + ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0]; + ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0]; + ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2]; + ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2]; + + ts[(6+0)*SBLIMIT] = out1[6+0] + in0 * wi[0]; + ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0]; + ts[(6+2)*SBLIMIT] = out1[6+2] + in4 * wi[2]; + ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2]; + } + + in++; + + { + real in0,in1,in2,in3,in4,in5; + register real *out2 = rawout2; + + DCT12_PART1 + + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = (in1 - in5) * tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[5-1] = tmp0 * wi[11-1]; + out2[0+1] = tmp0 * wi[6+1]; + ts[(12+1)*SBLIMIT] += tmp1 * wi[1]; + ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1]; + } + + DCT12_PART2 + + out2[5-0] = in2 * wi[11-0]; + out2[0+0] = in2 * wi[6+0]; + out2[0+2] = in3 * wi[6+2]; + out2[5-2] = in3 * wi[11-2]; + + ts[(12+0)*SBLIMIT] += in0 * wi[0]; + ts[(17-0)*SBLIMIT] += in0 * wi[5-0]; + ts[(12+2)*SBLIMIT] += in4 * wi[2]; + ts[(17-2)*SBLIMIT] += in4 * wi[5-2]; + } + + in++; + + { + real in0,in1,in2,in3,in4,in5; + register real *out2 = rawout2; + out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0; + + DCT12_PART1 + + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = (in1 - in5) * tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[11-1] = tmp0 * wi[11-1]; + out2[6 +1] = tmp0 * wi[6+1]; + out2[0+1] += tmp1 * wi[1]; + out2[5-1] += tmp1 * wi[5-1]; + } + + DCT12_PART2 + + out2[11-0] = in2 * wi[11-0]; + out2[6 +0] = in2 * wi[6+0]; + out2[6 +2] = in3 * wi[6+2]; + out2[11-2] = in3 * wi[11-2]; + + out2[0+0] += in0 * wi[0]; + out2[5-0] += in0 * wi[5-0]; + out2[0+2] += in4 * wi[2]; + out2[5-2] += in4 * wi[5-2]; + } +} + +/* + * III_hybrid + */ +static void III_hybrid( PMPSTR mp, real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT], + int ch,struct gr_info_s *gr_infos) +{ + real *tspnt = (real *) tsOut; + real (*block)[2][SBLIMIT*SSLIMIT] = mp->hybrid_block; + int *blc = mp->hybrid_blc; + real *rawout1,*rawout2; + int bt; + int sb = 0; + + { + int b = blc[ch]; + rawout1=block[b][ch]; + b=-b+1; + rawout2=block[b][ch]; + blc[ch] = b; + } + + + if(gr_infos->mixed_block_flag) { + sb = 2; + dct36(fsIn[0],rawout1,rawout2,win[0],tspnt); + dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1); + rawout1 += 36; rawout2 += 36; tspnt += 2; + } + + bt = gr_infos->block_type; + if(bt == 2) { + for (; sb<(int)gr_infos->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { + dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt); + dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1); + } + } + else { + for (; sb<(int)gr_infos->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) { + dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt); + dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1); + } + } + + for(;sbstereo; + int single = fr->single; + int ms_stereo; + int sfreq = fr->sampling_frequency; + int granules; + int ch,gr,databits; + + if(stereo == 1) { /* stream is mono */ + single = 0; + } + + if(fr->mode == MPG_MD_JOINT_STEREO) { + ms_stereo = fr->mode_ext & 0x2; + } + else + ms_stereo = 0; + + + if(fr->lsf) { + granules = 1; + III_get_side_info_2(&sideinfo,stereo,ms_stereo,sfreq,single); + } + else { + granules = 2; +#ifdef MPEG1 + III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single); +#else + //fprintf(stderr,"Not supported\n"); +#endif + } + + databits=0; + for (gr=0 ; gr < granules ; ++gr) { + for (ch=0; ch < stereo ; ++ch) { + struct gr_info_s *gr_infos = &(sideinfo.ch[ch].gr[gr]); + databits += gr_infos->part2_3_length; + } + } + return databits-8*sideinfo.main_data_begin; +} + + + +int do_layer3( PMPSTR mp,unsigned char *pcm_sample,int *pcm_point) +{ + int gr, ch, ss,clip=0; + int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ + // struct III_sideinfo sideinfo; + struct frame *fr=&(mp->fr); + int stereo = fr->stereo; + int single = fr->single; + int ms_stereo,i_stereo; + int sfreq = fr->sampling_frequency; + int stereo1,granules; + + if(set_pointer(mp, (int)sideinfo.main_data_begin) == MP3_ERR) + return -1; + + if(stereo == 1) { /* stream is mono */ + stereo1 = 1; + single = 0; + } + else if(single >= 0) /* stream is stereo, but force to mono */ + stereo1 = 1; + else + stereo1 = 2; + + if(fr->mode == MPG_MD_JOINT_STEREO) { + ms_stereo = fr->mode_ext & 0x2; + i_stereo = fr->mode_ext & 0x1; + } + else + ms_stereo = i_stereo = 0; + + + if(fr->lsf) { + granules = 1; + } + else { + granules = 2; + } + + + for (gr=0;grlsf) + part2bits = III_get_scale_factors_2(scalefacs[0],gr_infos,0); + else { +#ifdef MPEG1 + part2bits = III_get_scale_factors_1(scalefacs[0],gr_infos); +#else + //fprintf(stderr,"Not supported\n"); +#endif + } + +/* +#ifndef NOANALYSIS + if (mpg123_pinfo!=NULL) { + int i; + mpg123_pinfo->sfbits[gr][0] = part2bits; + for (i=0; i<39; i++) + mpg123_pinfo->sfb_s[gr][0][i]=scalefacs[0][i]; + } +#endif +*/ + + if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_infos,sfreq,part2bits)) + return clip; + } + if(stereo == 2) { + struct gr_info_s *gr_infos = &(sideinfo.ch[1].gr[gr]); + long part2bits; + if(fr->lsf) + part2bits = III_get_scale_factors_2(scalefacs[1],gr_infos,i_stereo); + else { +#ifdef MPEG1 + part2bits = III_get_scale_factors_1(scalefacs[1],gr_infos); +#else + //fprintf(stderr,"Not supported\n"); +#endif + } +/* +#ifndef NOANALYSIS + if (mpg123_pinfo!=NULL) { + int i; + mpg123_pinfo->sfbits[gr][1] = part2bits; + for (i=0; i<39; i++) + mpg123_pinfo->sfb_s[gr][1][i]=scalefacs[1][i]; + } +#endif +*/ + + if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_infos,sfreq,part2bits)) + return clip; + + if(ms_stereo) { + int i; + for(i=0;ilsf); + + if(ms_stereo || i_stereo || (single == 3) ) { + if(gr_infos->maxb > sideinfo.ch[0].gr[gr].maxb) + sideinfo.ch[0].gr[gr].maxb = gr_infos->maxb; + else + gr_infos->maxb = sideinfo.ch[0].gr[gr].maxb; + } + + switch(single) { + case 3: + { + register int i; + register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; + for(i=0;i<(int)(SSLIMIT*gr_infos->maxb);i++,in0++) + *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ + } + break; + case 1: + { + register int i; + register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; + for(i=0;i<(int)(SSLIMIT*gr_infos->maxb);i++) + *in0++ = *in1++; + } + break; + } + } + +#ifndef NOANALYSIS + if (mpg123_pinfo!=NULL) { + int i,sb; + float ifqstep; + + mpg123_pinfo->bitrate = + tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index]; + mpg123_pinfo->sampfreq = freqs[sfreq]; + mpg123_pinfo->emph = fr->emphasis; + mpg123_pinfo->crc = fr->error_protection; + mpg123_pinfo->padding = fr->padding; + mpg123_pinfo->stereo = fr->stereo; + mpg123_pinfo->js = (fr->mode == MPG_MD_JOINT_STEREO); + mpg123_pinfo->ms_stereo = ms_stereo; + mpg123_pinfo->i_stereo = i_stereo; + mpg123_pinfo->maindata = sideinfo.main_data_begin; + + for(ch=0;chbig_values[gr][ch]=gr_infos->big_values; + mpg123_pinfo->scalefac_scale[gr][ch]=gr_infos->scalefac_scale; + mpg123_pinfo->mixed[gr][ch] = gr_infos->mixed_block_flag; + mpg123_pinfo->mpg123blocktype[gr][ch]=gr_infos->block_type; + mpg123_pinfo->mainbits[gr][ch] = gr_infos->part2_3_length; + mpg123_pinfo->preflag[gr][ch] = gr_infos->preflag; + if (gr==1) mpg123_pinfo->scfsi[ch] = gr_infos->scfsi; + } + + + for (ch=0;chscalefac_scale[gr][ch] == 0 ) ? .5 : 1.0; + if (2==gr_infos->block_type) { + for (i=0; i<3; i++) { + for (sb=0; sb<12; sb++) { + int j = 3*sb+i; + /* + is_p = scalefac[sfb*3+lwin-gr_infos->mixed_block_flag]; + */ + /* scalefac was copied into mpg123_pinfo->sfb_s[] above */ + mpg123_pinfo->sfb_s[gr][ch][j] = -ifqstep*mpg123_pinfo->sfb_s[gr][ch][j-gr_infos->mixed_block_flag]; + mpg123_pinfo->sfb_s[gr][ch][j] -= 2*(mpg123_pinfo->sub_gain[gr][ch][i]); + } + mpg123_pinfo->sfb_s[gr][ch][3*sb+i] = - 2*(mpg123_pinfo->sub_gain[gr][ch][i]); + } + }else{ + for (sb=0; sb<21; sb++) { + /* scalefac was copied into mpg123_pinfo->sfb[] above */ + mpg123_pinfo->sfb[gr][ch][sb] = mpg123_pinfo->sfb_s[gr][ch][sb]; + if (gr_infos->preflag) mpg123_pinfo->sfb[gr][ch][sb] += pretab1[sb]; + mpg123_pinfo->sfb[gr][ch][sb] *= -ifqstep; + } + mpg123_pinfo->sfb[gr][ch][21]=0; + } + } + + + + for(ch=0;chmpg123xr[gr][ch][j]=hybridIn[ch][sb][ss]; + } + } +#endif + + for(ch=0;ch= 0) { + clip += synth_1to1_mono(mp, hybridOut[0][ss],pcm_sample,pcm_point); + } + else { + int p1 = *pcm_point; + clip += synth_1to1(mp, hybridOut[0][ss],0,pcm_sample,&p1); + clip += synth_1to1(mp, hybridOut[1][ss],1,pcm_sample,pcm_point); + } + } + } + + return clip; +} + diff --git a/Libraries/DecMPA/Files/src/hip/layer3.h b/Libraries/DecMPA/Files/src/hip/layer3.h new file mode 100644 index 000000000..c28be4899 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/layer3.h @@ -0,0 +1,35 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +/* +** Copyright (C) 2000 Albert L. Faber +**/ + +#ifndef LAYER3_H_INCLUDED +#define LAYER3_H_INCLUDED + +void init_layer3(int); +int do_layer3_sideinfo(struct frame *fr); +int do_layer3( PMPSTR mp,unsigned char *pcm_sample,int *pcm_point); + +#endif + diff --git a/Libraries/DecMPA/Files/src/hip/mpg123.h b/Libraries/DecMPA/Files/src/hip/mpg123.h new file mode 100644 index 000000000..6bde9b044 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/mpg123.h @@ -0,0 +1,157 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + + +#ifndef MPG123_H_INCLUDED +#define MPG123_H_INCLUDED + +#include + +//#ifdef STDC_HEADERS +# include +//#else +/*# ifndef HAVE_STRCHR +# define strchr index +# define strrchr rindex +# endif +char *strchr (), *strrchr (); +# ifndef HAVE_MEMCPY +# define memcpy(d, s, n) bcopy ((s), (d), (n)) +# define memmove(d, s, n) bcopy ((s), (d), (n)) +# endif +#endif*/ + +#include + + +#if defined(__riscos__) && defined(FPA10) +#include "ymath.h" +#else +#include +#endif + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif + + +#ifdef REAL_IS_FLOAT +# define real float +#elif defined(REAL_IS_LONG_DOUBLE) +# define real long double +#else +# define real double +#endif + +#define FALSE 0 +#define TRUE 1 + +#define SBLIMIT 32 +#define SSLIMIT 18 + +#define MPG_MD_STEREO 0 +#define MPG_MD_JOINT_STEREO 1 +#define MPG_MD_DUAL_CHANNEL 2 +#define MPG_MD_MONO 3 + +#define MAXFRAMESIZE 1792 + +/* AF: ADDED FOR LAYER1/LAYER2 */ +#define SCALE_BLOCK 12 + + +/* Pre Shift fo 16 to 8 bit converter table */ +#define AUSHIFT (3) + +struct frame { + int stereo; + int jsbound; + int single; + int lsf; + int mpeg25; + int header_change; + int lay; + int error_protection; + int bitrate_index; + int sampling_frequency; + int padding; + int extension; + int mode; + int mode_ext; + int copyright; + int original; + int emphasis; + int framesize; /* computed framesize */ + + /* AF: ADDED FOR LAYER1/LAYER2 */ +#if defined(USE_LAYER_2) || defined(USE_LAYER_1) + int II_sblimit; + struct al_table2 *alloc; + int down_sample_sblimit; + int down_sample; + +#endif + +}; + +struct gr_info_s { + int scfsi; + unsigned part2_3_length; + unsigned big_values; + unsigned scalefac_compress; + unsigned block_type; + unsigned mixed_block_flag; + unsigned table_select[3]; + unsigned subblock_gain[3]; + unsigned maxband[3]; + unsigned maxbandl; + unsigned maxb; + unsigned region1start; + unsigned region2start; + unsigned preflag; + unsigned scalefac_scale; + unsigned count1table_select; + real *full_gain[3]; + real *pow2gain; +}; + +struct III_sideinfo +{ + unsigned main_data_begin; + unsigned private_bits; + struct { + struct gr_info_s gr[2]; + } ch[2]; +}; + + +#endif diff --git a/Libraries/DecMPA/Files/src/hip/mpglib.h b/Libraries/DecMPA/Files/src/hip/mpglib.h new file mode 100644 index 000000000..f9b9be263 --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/mpglib.h @@ -0,0 +1,90 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + + +#ifndef _MPGLIB_H_ +#define _MPGLIB_H_ + +/* +#ifndef NOANALYSIS +extern plotting_data *mpg123_pinfo; +#endif +*/ + +struct buf { + unsigned char *pnt; + long size; + long pos; + struct buf *next; + struct buf *prev; +}; + +struct framebuf { + struct buf *buf; + long pos; + struct frame *next; + struct frame *prev; +}; + +typedef struct mpstr_tag { + struct buf *head,*tail; + int vbr_header; /* 1 if valid Xing vbr header detected */ + int num_frames; /* set if vbr header present */ + int enc_delay; /* set if vbr header present */ + int enc_padding; /* set if vbr header present */ + int header_parsed; + int side_parsed; + int data_parsed; + int free_format; /* 1 = free format frame */ + int old_free_format; /* 1 = last frame was free format */ + int bsize; + int framesize; + int ssize; + int dsize; + int fsizeold; + int fsizeold_nopadding; + struct frame fr; + unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */ + real hybrid_block[2][2][SBLIMIT*SSLIMIT]; + int hybrid_blc[2]; + unsigned long header; + int bsnum; + real synth_buffs[2][2][0x110]; + int synth_bo; + int sync_bitstream; + +} MPSTR, *PMPSTR; + + +#if ( defined(_MSC_VER) || defined(__BORLANDC__) ) + typedef int BOOL; /* windef.h contains the same definition */ +#else + #define BOOL int +#endif + +#define MP3_ERR -1 +#define MP3_OK 0 +#define MP3_NEED_MORE 1 + + + +#endif /* _MPGLIB_H_ */ diff --git a/Libraries/DecMPA/Files/src/hip/tabinit.c b/Libraries/DecMPA/Files/src/hip/tabinit.c new file mode 100644 index 000000000..8602ce9bc --- /dev/null +++ b/Libraries/DecMPA/Files/src/hip/tabinit.c @@ -0,0 +1,143 @@ +/* DecMPA decoding routines from Lame/HIP (Myers W. Carpenter) + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + + email: hazard_hd@users.sourceforge.net +*/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include "tabinit.h" +#include "mpg123.h" + +#ifdef WITH_DMALLOC +#include +#endif + +real decwin[512+32]; +static real cos64[16],cos32[8],cos16[4],cos8[2],cos4[1]; +real *pnts[] = { cos64,cos32,cos16,cos8,cos4 }; + +const double dewin[512] = { + 0.000000000,-0.000015259,-0.000015259,-0.000015259, + -0.000015259,-0.000015259,-0.000015259,-0.000030518, + -0.000030518,-0.000030518,-0.000030518,-0.000045776, + -0.000045776,-0.000061035,-0.000061035,-0.000076294, + -0.000076294,-0.000091553,-0.000106812,-0.000106812, + -0.000122070,-0.000137329,-0.000152588,-0.000167847, + -0.000198364,-0.000213623,-0.000244141,-0.000259399, + -0.000289917,-0.000320435,-0.000366211,-0.000396729, + -0.000442505,-0.000473022,-0.000534058,-0.000579834, + -0.000625610,-0.000686646,-0.000747681,-0.000808716, + -0.000885010,-0.000961304,-0.001037598,-0.001113892, + -0.001205444,-0.001296997,-0.001388550,-0.001480103, + -0.001586914,-0.001693726,-0.001785278,-0.001907349, + -0.002014160,-0.002120972,-0.002243042,-0.002349854, + -0.002456665,-0.002578735,-0.002685547,-0.002792358, + -0.002899170,-0.002990723,-0.003082275,-0.003173828, + -0.003250122,-0.003326416,-0.003387451,-0.003433228, + -0.003463745,-0.003479004,-0.003479004,-0.003463745, + -0.003417969,-0.003372192,-0.003280640,-0.003173828, + -0.003051758,-0.002883911,-0.002700806,-0.002487183, + -0.002227783,-0.001937866,-0.001617432,-0.001266479, + -0.000869751,-0.000442505, 0.000030518, 0.000549316, + 0.001098633, 0.001693726, 0.002334595, 0.003005981, + 0.003723145, 0.004486084, 0.005294800, 0.006118774, + 0.007003784, 0.007919312, 0.008865356, 0.009841919, + 0.010848999, 0.011886597, 0.012939453, 0.014022827, + 0.015121460, 0.016235352, 0.017349243, 0.018463135, + 0.019577026, 0.020690918, 0.021789551, 0.022857666, + 0.023910522, 0.024932861, 0.025909424, 0.026840210, + 0.027725220, 0.028533936, 0.029281616, 0.029937744, + 0.030532837, 0.031005859, 0.031387329, 0.031661987, + 0.031814575, 0.031845093, 0.031738281, 0.031478882, + 0.031082153, 0.030517578, 0.029785156, 0.028884888, + 0.027801514, 0.026535034, 0.025085449, 0.023422241, + 0.021575928, 0.019531250, 0.017257690, 0.014801025, + 0.012115479, 0.009231567, 0.006134033, 0.002822876, + -0.000686646,-0.004394531,-0.008316040,-0.012420654, + -0.016708374,-0.021179199,-0.025817871,-0.030609131, + -0.035552979,-0.040634155,-0.045837402,-0.051132202, + -0.056533813,-0.061996460,-0.067520142,-0.073059082, + -0.078628540,-0.084182739,-0.089706421,-0.095169067, + -0.100540161,-0.105819702,-0.110946655,-0.115921021, + -0.120697021,-0.125259399,-0.129562378,-0.133590698, + -0.137298584,-0.140670776,-0.143676758,-0.146255493, + -0.148422241,-0.150115967,-0.151306152,-0.151962280, + -0.152069092,-0.151596069,-0.150497437,-0.148773193, + -0.146362305,-0.143264771,-0.139450073,-0.134887695, + -0.129577637,-0.123474121,-0.116577148,-0.108856201, + -0.100311279,-0.090927124,-0.080688477,-0.069595337, + -0.057617187,-0.044784546,-0.031082153,-0.016510010, + -0.001068115, 0.015228271, 0.032379150, 0.050354004, + 0.069168091, 0.088775635, 0.109161377, 0.130310059, + 0.152206421, 0.174789429, 0.198059082, 0.221984863, + 0.246505737, 0.271591187, 0.297210693, 0.323318481, + 0.349868774, 0.376800537, 0.404083252, 0.431655884, + 0.459472656, 0.487472534, 0.515609741, 0.543823242, + 0.572036743, 0.600219727, 0.628295898, 0.656219482, + 0.683914185, 0.711318970, 0.738372803, 0.765029907, + 0.791213989, 0.816864014, 0.841949463, 0.866363525, + 0.890090942, 0.913055420, 0.935195923, 0.956481934, + 0.976852417, 0.996246338, 1.014617920, 1.031936646, + 1.048156738, 1.063217163, 1.077117920, 1.089782715, + 1.101211548, 1.111373901, 1.120223999, 1.127746582, + 1.133926392, 1.138763428, 1.142211914, 1.144287109, + 1.144989014 +}; + +void make_decode_tables(long scaleval) +{ + int i,j,k,kr,divv; + real *table,*costab; + + + for(i=0;i<5;i++) + { + kr=0x10>>i; divv=0x40>>i; + costab = pnts[i]; + for(k=0;k +//#include +#include +#include +#include "dxHead.h" + +// 4 Xing +// 4 flags +// 4 frames +// 4 bytes +// 100 toc + +/*-------------------------------------------------------------*/ +static int ExtractI4(unsigned char *buf) +{ +int x; +// big endian extract + +x = buf[0]; +x <<= 8; +x |= buf[1]; +x <<= 8; +x |= buf[2]; +x <<= 8; +x |= buf[3]; + +return x; +} +/*-------------------------------------------------------------*/ +int GetXingHeader(XHEADDATA *X, unsigned char *buf) +{ +int i, head_flags; +int h_id, h_mode, h_sr_index; +static const int sr_table[4] = { 44100, 48000, 32000, 99999 }; + +// get Xing header data + + +X->flags = 0; // clear to null incase fail + + +// get selected MPEG header data +h_id = (buf[1] >> 3) & 1; +h_sr_index = (buf[2] >> 2) & 3; +h_mode = (buf[3] >> 6) & 3; + + +// determine offset of header +if( h_id ) { // mpeg1 + if( h_mode != 3 ) buf+=(32+4); + else buf+=(17+4); +} +else { // mpeg2 + if( h_mode != 3 ) buf+=(17+4); + else buf+=(9+4); +} + +if( buf[0] != 'X' ) return 0; // fail +if( buf[1] != 'i' ) return 0; // header not found +if( buf[2] != 'n' ) return 0; +if( buf[3] != 'g' ) return 0; +buf+=4; + +X->h_id = h_id; +X->samprate = sr_table[h_sr_index]; +if( h_id == 0 ) X->samprate >>= 1; + +head_flags = X->flags = ExtractI4(buf); buf+=4; // get flags + +if( head_flags & FRAMES_FLAG ) {X->frames = ExtractI4(buf); buf+=4;} +if( head_flags & BYTES_FLAG ) {X->bytes = ExtractI4(buf); buf+=4;} + +if( head_flags & TOC_FLAG ) { + if( X->toc != (unsigned char*)0 ) { + for(i=0;i<100;i++) X->toc[i] = buf[i]; + } + buf+=100; +} + +X->vbr_scale = -1; +if( head_flags & VBR_SCALE_FLAG ) {X->vbr_scale = ExtractI4(buf); buf+=4;} + +//if( X->toc != NULL ) { +//for(i=0;i<100;i++) { +// if( (i%10) == 0 ) printf("\n"); +// printf(" %3d", (int)(X->toc[i])); +//} +//} + +return 1; // success +} +/*-------------------------------------------------------------*/ +int SeekPoint(unsigned char TOC[100], int file_bytes, float percent) +{ + // interpolate in TOC to get file seek point in bytes + int a, seekpoint; + float fa, fb, fx; + + if( percent < 0.0f ) + percent = 0.0f; + if( percent > 100.0f ) + percent = 100.0f; + + a = (int)percent; + if( a > 99 ) + a = 99; + fa = TOC[a]; + if( a < 99 ) + { + fb = TOC[a+1]; + } + else + { + fb = 256.0f; + } + + fx = fa + (fb-fa)*(percent-a); + //printf("%f ....... %f ...... %f\n",fa,fb,fx); + + seekpoint = (int)((1.0f/256.0f)*fx*file_bytes); + + return seekpoint; +} +/*-------------------------------------------------------------*/ diff --git a/Libraries/DecMPA/Files/src/mpegAudioFrame/dxHead.h b/Libraries/DecMPA/Files/src/mpegAudioFrame/dxHead.h new file mode 100644 index 000000000..da0f2eff6 --- /dev/null +++ b/Libraries/DecMPA/Files/src/mpegAudioFrame/dxHead.h @@ -0,0 +1,66 @@ +/*---- DXhead.h ------------------------------------------- + + +decoder MPEG Layer III + +handle Xing header + + +Copyright 1998 Xing Technology Corp. +-----------------------------------------------------------*/ +// A Xing header may be present in the ancillary +// data field of the first frame of an mp3 bitstream +// The Xing header (optionally) contains +// frames total number of audio frames in the bitstream +// bytes total number of bytes in the bitstream +// toc table of contents + +// toc (table of contents^) gives seek points +// for random access +// the ith entry determines the seek point for +// i-percent duration +// seek point in bytes = (toc[i]/256.0) * total_bitstream_bytes +// e.g. half duration seek point = (toc[50]/256.0) * total_bitstream_bytes + +#ifndef __DXHEAD_H +#define __DXHEAD_H + +#define FRAMES_FLAG 0x0001 +#define BYTES_FLAG 0x0002 +#define TOC_FLAG 0x0004 +#define VBR_SCALE_FLAG 0x0008 + +#define FRAMES_AND_BYTES (FRAMES_FLAG | BYTES_FLAG) + +// structure to receive extracted header +// toc may be NULL + +typedef struct XHEADDATA_s { + int h_id; // from MPEG header, 0=MPEG2, 1=MPEG1 + int samprate; // determined from MPEG header + int flags; // from Xing header data + int frames; // total bit stream frames from Xing header data + int bytes; // total bit stream bytes from Xing header data + int vbr_scale; // encoded vbr scale from Xing header data + unsigned char *toc; // pointer to unsigned char toc_buffer[100] + // may be NULL if toc not desired +} XHEADDATA; + +int GetXingHeader(XHEADDATA *X, unsigned char *buf); + +// return 0=fail, 1=success +// X structure to receive header data (output) +// buf bitstream input + + +int SeekPoint(unsigned char TOC[100], int file_bytes, float percent); +// return seekpoint in bytes (may be at eof if percent=100.0) +// TOC = table of contents from Xing header +// file_bytes = number of bytes in mp3 file +// percent = play time percentage of total playtime. May be +// fractional (e.g. 87.245) + + +#endif + + diff --git a/Libraries/DecMPA/Files/src/mpegAudioFrame/mpegAudioHeader.cpp b/Libraries/DecMPA/Files/src/mpegAudioFrame/mpegAudioHeader.cpp new file mode 100644 index 000000000..cf64f1e6f --- /dev/null +++ b/Libraries/DecMPA/Files/src/mpegAudioFrame/mpegAudioHeader.cpp @@ -0,0 +1,281 @@ +/* + stores information after we found a header. + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - removed cout and exit stuff +// - added bitratekbps variable + +#include "mpegAudioHeader.h" + +#define DEBUG_HEADER(x) +//#define DEBUG_HEADER(x) x + + + +static const int frequencies[3][3]= { + {44100,48000,32000}, // MPEG 1 + {22050,24000,16000}, // MPEG 2 + {11025,12000,8000} // MPEG 2.5 +}; + +static int translate[3][2][16] = { { { 2,0,0,2,2,2,3,3,3,3,3,3,3,3,3,2 } , + { 2,0,0,0,0,0,0,2,2,2,3,3,3,3,3,2 } } , + { { 2,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2 } , + { 2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2 } } , + { { 2,1,1,2,2,2,3,3,3,3,3,3,3,3,3,2 } , + { 2,1,1,1,1,1,1,2,2,2,3,3,3,3,3,2 } } }; + + +static int sblims[5] = { 8 , 12 , 27, 30 , 30 }; + + +static const int bitrate[2][3][15]= { + // MPEG 1 + {{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448}, + {0,32,48,56,64,80,96,112,128,160,192,224,256,320,384}, + {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320}}, + + // MPEG 2 + {{0,32,48,56,64,80,96,112,128,144,160,176,192,224,256}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160}} +}; + + +MpegAudioHeader::MpegAudioHeader() { + +} + + +MpegAudioHeader::~MpegAudioHeader() { +} + + +int MpegAudioHeader::getChannelbitrate() { + //cout << "getChannelbitrate not implemented"<>1)&3); + // we catch the layer==4 error later, for now go on with parsing + version=(int)(((c>>3)&1)^1); + if ((version==0) && lmpeg25) { + //DEBUG_HEADER(cout << "wrong lsf/mpeg25 combination"<>1; + padding=(c&1); + c>>=1; + frequency=(int)(c&3); + c>>=2; + bitrateindex=(int)c; + if(bitrateindex>=15) { + //DEBUG_HEADER(cout << "bitrateindex error"<>4; + extendedmode=c&3; + mode=(int)(c>>2); + + + // Making information + inputstereo= (mode==_MODE_SINGLE)?0:1; + + // + // frequency can be 0,1 or 2 but the mask above allows 3 as well + // check now. + if (frequency > 2) { + //DEBUG_HEADER(cout << "frequency value out of range"<>1; + if(mode==_MODE_SINGLE)stereobound=0; + if(mode==_MODE_JOINT)stereobound=(extendedmode+1)<<2; + + break; + case 1: + subbandnumber=MAXSUBBAND; + stereobound=subbandnumber; + tableindex=0; + if(mode==_MODE_SINGLE)stereobound=0; + if(mode==_MODE_JOINT)stereobound=(extendedmode+1)<<2; + break; + default: + //DEBUG_HEADER(cout <<"unknown layer"<protection=protection; + dest->layer=layer; + dest->version=version; + dest->padding=padding; + dest->frequency=frequency; + dest->frequencyHz=frequencyHz; + dest->bitrateindex=bitrateindex; + dest->extendedmode=extendedmode; + dest->mode=mode; + dest->inputstereo=inputstereo; + dest->channelbitrate=channelbitrate; + dest->tableindex=tableindex; + dest->subbandnumber=subbandnumber; + dest->stereobound=stereobound; + dest->framesize=framesize; + dest->layer3slots=layer3slots; + dest->lmpeg25=lmpeg25; +} + + +void MpegAudioHeader::print(const char* name) { +/* cout << "MpegAudioHeader [START]:"< +//#include +//#include +//#include + +#define _FREQUENCY_44100 0 +#define _FREQUENCY_48000 1 +#define _FREQUENCY_32000 2 + +#define _MODE_FULLSTEREO 0 +#define _MODE_JOINT 1 +#define _MODE_DUAL 2 +#define _MODE_SINGLE 3 + +#define _VERSION_1 0 +#define _VERSION_2 1 + + +#define MAXSUBBAND 32 +#define SCALEBLOCK 12 + + + +class MpegAudioHeader { + + int protection; + int layer; + int version; + int padding; + int frequency; + int frequencyHz; + int bitrateindex; + int extendedmode; + int mode; + int inputstereo; + int channelbitrate; + int tableindex; + int subbandnumber; + int stereobound; + int framesize; + int layer3slots; + int lmpeg25; + unsigned char header[4]; + + int m_nBitRateKbps; + double m_AvgFrameSize; + + public: + MpegAudioHeader(); + ~MpegAudioHeader(); + + int parseHeader(unsigned char* buf); + + inline int getProtection() { return protection; } + inline int getLayer() { return layer; } + inline int getVersion() { return version; } + inline int getPadding() { return padding; } + inline int getFrequency() { return frequency; } + inline int getFrequencyHz() { return frequencyHz; } + inline int getBitrateindex() { return bitrateindex; } + inline int getExtendedmode() { return extendedmode; } + inline int getMode() { return mode; } + inline int getInputstereo() { return inputstereo; } + inline int getFramesize() { return framesize; } + inline int getLayer25() { return lmpeg25; } + + // MPEG layer 2 + inline int getTableindex() { return tableindex; } + // MPEG layer 1/2 + inline int getSubbandnumber() { return subbandnumber; } + inline int getStereobound() { return stereobound; } + // MPEG layer 3 + inline int getLayer3slots() { return layer3slots; } + + int getChannelbitrate(); + + + inline unsigned char* getHeader() { return header; } + int getpcmperframe(); + + + void copyTo(MpegAudioHeader* dest); + + void print(const char* name); + void printStates(const char* name); + + inline int GetBitRateKbps(){ return m_nBitRateKbps; } + inline double GetAvgFrameSize() { return m_AvgFrameSize; } +}; +#endif diff --git a/Libraries/DecMPA/Files/src/splay/DecodeEngine_SPlay.cpp b/Libraries/DecMPA/Files/src/splay/DecodeEngine_SPlay.cpp new file mode 100644 index 000000000..0ffc7ccdc --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/DecodeEngine_SPlay.cpp @@ -0,0 +1,49 @@ +/* DecMPA - simple MPEG Audio decoding library. + Copyright (C) 2002 Hauke Duden + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information look at the file License.txt in this package. + + email: hazard_hd@users.sourceforge.net +*/ + + +#include "splayDecoder.h" +#include "../DecodeEngine.h" + +#include + +void* DecodeEngine_Create() +{ + return new SplayDecoder(); +} + +void DecodeEngine_Destroy(void* pEng) +{ + delete (SplayDecoder*)pEng; +} + +bool DecodeEngine_Decode(void* pEng,AudioFrame* pDest,void* pData,long nDataLength) +{ + SplayDecoder* pDecoder=(SplayDecoder*)pEng; + + return pDecoder->decode((unsigned char*)pData,nDataLength,pDest)!=0; +} + +void DecodeEngine_Flush(void* pEngine) +{ + //splay doesn't store old data, so we don't have to do anything +} diff --git a/Libraries/DecMPA/Files/src/splay/attribute.h b/Libraries/DecMPA/Files/src/splay/attribute.h new file mode 100644 index 000000000..1306ede0d --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/attribute.h @@ -0,0 +1,33 @@ +/* + align attribut definition (g++) + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + +#ifndef __ATTRIBUTE_H +#define __ATTRIBUTE_H + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* use gcc attribs to align critical data structures */ + +#ifdef ATTRIBUTE_ALIGNED_MAX +#define ATTR_ALIGN(align) __attribute__ \ + ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX + +#define SSLIMIT 18 +#define SBLIMIT 32 + + +#define LS 0 +#define RS 1 + + +typedef float REAL; + +extern "C" { +// The inline code works on intel only with egcs >= 1.1 +#ifdef __GNUC__ +#if (__GNUC__ < 2 || ( __GNUC__ == 2 && __GNUC_MINOR__ < 91 ) ) +#ifndef _AIX +#warning "inline code disabled! (buggy egcs version)" +#undef __NO_MATH_INLINES +#define __NO_MATH_INLINES 1 +#endif +#endif +#endif +#ifndef WIN32 +#include +#endif +#include + +} +#if defined WIN32 + #include +#endif + +//#include + +#ifndef M_PI +#define MY_PI 3.14159265358979323846 +#else +#define MY_PI M_PI +#endif + +#ifdef PI +#undef PI +#endif +#define PI MY_PI +#define PI_12 (PI/12.0) +#define PI_18 (PI/18.0) +#define PI_24 (PI/24.0) +#define PI_36 (PI/36.0) +#define PI_72 (PI/72.0) + + +#endif diff --git a/Libraries/DecMPA/Files/src/splay/dct.h b/Libraries/DecMPA/Files/src/splay/dct.h new file mode 100644 index 000000000..e2ca59188 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/dct.h @@ -0,0 +1,33 @@ +/* + wrapper for dcts + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + +#ifndef __DCT_HEADER_H +#define __DCT_HEADER_H + +// one source: +extern void initialize_dct64(); + +extern void dct64(REAL* out1,REAL* out2,REAL *fraction); + +// one source: +extern void initialize_dct64_downsample(); +extern void dct64_downsample(REAL* out1,REAL* out2,REAL *fraction); + +// one source file: +extern void initialize_dct12_dct36(); + +extern void dct12(REAL *in,REAL *prevblk1,REAL *prevblk2,REAL *wi,REAL *out); +extern void dct36(REAL *inbuf,REAL *prevblk1,REAL *prevblk2,REAL *wi,REAL *out); + +extern void initialize_win(); +#endif diff --git a/Libraries/DecMPA/Files/src/splay/dct36_12.cpp b/Libraries/DecMPA/Files/src/splay/dct36_12.cpp new file mode 100644 index 000000000..942669cc2 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/dct36_12.cpp @@ -0,0 +1,290 @@ +/* + wrapper for dcts + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - added some explicit casts to remove compilation warnings + +#include "common.h" +#include "dct.h" + + +ATTR_ALIGN(64) static REAL hsec_12[3]; +ATTR_ALIGN(64) static REAL cos2_6=(REAL)cos(PI/6.0*2.0); +ATTR_ALIGN(64) static REAL cos1_6=(REAL)cos(PI/6.0*1.0); +ATTR_ALIGN(64) static REAL hsec_36[9]; +ATTR_ALIGN(64) static REAL cos_18[9]; + + +/** + This was some time ago a standalone dct class, + but to get more speed I made it an inline dct + int the filter classes +*/ + +static int dct36_12Init=false; + +void initialize_dct12_dct36() { + if (dct36_12Init) { + return; + } + dct36_12Init=true; + + + int i; + + for(i=0;i<3;i++) + hsec_12[i]=(REAL)(0.5/cos(double(i*2+1)* PI_12)); + + for(i=0;i<9;i++) + hsec_36[i]=(REAL)(0.5/cos(double(i*2+1)* PI_36)); + + for(i=0;i<9;i++) + cos_18[i]=(REAL)(cos(PI_18*double(i))); + +} + + +void dct36(REAL *inbuf,REAL *prevblk1, + REAL *prevblk2,REAL *wi,REAL *out){ + +#define MACRO0(v) { \ + REAL tmp; \ + out2[9+(v)]=(tmp=sum0+sum1)*wi[27+(v)]; \ + out2[8-(v)]=tmp * wi[26-(v)]; } \ + sum0-=sum1; \ + ts[SBLIMIT*(8-(v))]=out1[8-(v)]+sum0*wi[8-(v)]; \ + ts[SBLIMIT*(9+(v))]=out1[9+(v)]+sum0*wi[9+(v)]; +#define MACRO1(v) { \ + REAL sum0,sum1; \ + sum0=tmp1a+tmp2a; \ + sum1=(tmp1b+tmp2b)*hsec_36[(v)]; \ + MACRO0(v); } +#define MACRO2(v) { \ + REAL sum0,sum1; \ + sum0=tmp2a-tmp1a; \ + sum1=(tmp2b-tmp1b) * hsec_36[(v)]; \ + MACRO0(v); } + + { + REAL *in = inbuf; + + in[17]+=in[16];in[16]+=in[15];in[15]+=in[14];in[14]+=in[13]; + in[13]+=in[12];in[12]+=in[11];in[11]+=in[10];in[10]+=in[ 9]; + in[ 9]+=in[ 8];in[ 8]+=in[ 7];in[ 7]+=in[ 6];in[ 6]+=in[ 5]; + in[ 5]+=in[ 4];in[ 4]+=in[ 3];in[ 3]+=in[ 2];in[ 2]+=in[ 1]; + in[ 1]+=in[ 0]; + + + in[17]+=in[15];in[15]+=in[13];in[13]+=in[11];in[11]+=in[ 9]; + in[ 9]+=in[ 7];in[7] +=in[ 5];in[ 5]+=in[ 3];in[ 3]+=in[ 1]; + + { + REAL *c = cos_18; + REAL *out2 = prevblk2; + REAL *out1 = prevblk1; + REAL *ts = out; + + REAL ta33,ta66,tb33,tb66; + + ta33=in[2*3+0]*c[3]; + ta66=in[2*6+0]*c[6]; + tb33=in[2*3+1]*c[3]; + tb66=in[2*6+1]*c[6]; + + { + REAL tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a= in[2*1+0]*c[1]+ta33 +in[2*5+0]*c[5]+in[2*7+0]*c[7]; + tmp1b= in[2*1+1]*c[1]+tb33 +in[2*5+1]*c[5]+in[2*7+1]*c[7]; + tmp2a=in[2*0+0]+in[2*2+0]*c[2]+in[2*4+0]*c[4]+ta66 +in[2*8+0]*c[8]; + tmp2b=in[2*0+1]+in[2*2+1]*c[2]+in[2*4+1]*c[4]+tb66 +in[2*8+1]*c[8]; + MACRO1(0); + MACRO2(8); + } + + { + REAL tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a=(in[2*1+0]-in[2*5+0]-in[2*7+0])*c[3]; + tmp1b=(in[2*1+1]-in[2*5+1]-in[2*7+1])*c[3]; + tmp2a=(in[2*2+0]-in[2*4+0]-in[2*8+0])*c[6]-in[2*6+0]+in[2*0+0]; + tmp2b=(in[2*2+1]-in[2*4+1]-in[2*8+1])*c[6]-in[2*6+1]+in[2*0+1]; + MACRO1(1); + MACRO2(7); + } + + { + REAL tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a= in[2*1+0]*c[5]-ta33 -in[2*5+0]*c[7]+in[2*7+0]*c[1]; + tmp1b= in[2*1+1]*c[5]-tb33 -in[2*5+1]*c[7]+in[2*7+1]*c[1]; + tmp2a=in[2*0+0]-in[2*2+0]*c[8]-in[2*4+0]*c[2]+ta66 +in[2*8+0]*c[4]; + tmp2b=in[2*0+1]-in[2*2+1]*c[8]-in[2*4+1]*c[2]+tb66 +in[2*8+1]*c[4]; + MACRO1(2); + MACRO2(6); + } + + { + REAL tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a= in[2*1+0]*c[7]-ta33 +in[2*5+0]*c[1]-in[2*7+0]*c[5]; + tmp1b= in[2*1+1]*c[7]-tb33 +in[2*5+1]*c[1]-in[2*7+1]*c[5]; + tmp2a=in[2*0+0]-in[2*2+0]*c[4]+in[2*4+0]*c[8]+ta66 -in[2*8+0]*c[2]; + tmp2b=in[2*0+1]-in[2*2+1]*c[4]+in[2*4+1]*c[8]+tb66 -in[2*8+1]*c[2]; + MACRO1(3); + MACRO2(5); + } + + { + REAL sum0,sum1; + sum0= in[2*0+0]-in[2*2+0]+in[2*4+0]-in[2*6+0]+in[2*8+0]; + sum1=(in[2*0+1]-in[2*2+1]+in[2*4+1]-in[2*6+1]+in[2*8+1])*hsec_36[4]; + MACRO0(4); + } + } + } + + +} + + +void dct12(REAL *in,REAL *prevblk1,REAL *prevblk2,REAL *wi,REAL *out) { + +#define DCT12_PART1 \ + in5=in[5*3]; \ + in5+=(in4=in[4*3]); \ + in4+=(in3=in[3*3]); \ + in3+=(in2=in[2*3]); \ + in2+=(in1=in[1*3]); \ + in1+=(in0=in[0*3]); \ + \ + in5+=in3;in3+=in1; \ + \ + in2*=cos1_6; \ + in3*=cos1_6; + +#define DCT12_PART2 \ + in0+=in4*cos2_6; \ + \ + in4=in0+in2; \ + in0-=in2; \ + \ + in1+=in5*cos2_6; \ + \ + in5=(in1+in3)*hsec_12[0]; \ + in1=(in1-in3)*hsec_12[2]; \ + \ + in3=in4+in5; \ + in4-=in5; \ + \ + in2=in0+in1; \ + in0-=in1; + + { + REAL in0,in1,in2,in3,in4,in5; + register REAL *pb1=prevblk1; + out[SBLIMIT*0]=pb1[0];out[SBLIMIT*1]=pb1[1];out[SBLIMIT*2]=pb1[2]; + out[SBLIMIT*3]=pb1[3];out[SBLIMIT*4]=pb1[4];out[SBLIMIT*5]=pb1[5]; + + DCT12_PART1; + + { + REAL tmp0,tmp1=(in0-in4); + { + register REAL tmp2=(in1-in5)*hsec_12[1]; + tmp0=tmp1+tmp2; + tmp1-=tmp2; + } + out[(17-1)*SBLIMIT]=pb1[17-1]+tmp0*wi[11-1]; + out[(12+1)*SBLIMIT]=pb1[12+1]+tmp0*wi[ 6+1]; + out[(6 +1)*SBLIMIT]=pb1[6 +1]+tmp1*wi[ 1 ]; + out[(11-1)*SBLIMIT]=pb1[11-1]+tmp1*wi[ 5-1]; + } + + DCT12_PART2; + out[(17-0)*SBLIMIT]=pb1[17-0]+in2*wi[11-0]; + out[(12+0)*SBLIMIT]=pb1[12+0]+in2*wi[ 6+0]; + out[(12+2)*SBLIMIT]=pb1[12+2]+in3*wi[ 6+2]; + out[(17-2)*SBLIMIT]=pb1[17-2]+in3*wi[11-2]; + + out[( 6+0)*SBLIMIT]=pb1[ 6+0]+in0*wi[0]; + out[(11-0)*SBLIMIT]=pb1[11-0]+in0*wi[5-0]; + out[( 6+2)*SBLIMIT]=pb1[ 6+2]+in4*wi[2]; + out[(11-2)*SBLIMIT]=pb1[11-2]+in4*wi[5-2]; + } + + in++; + { + REAL in0,in1,in2,in3,in4,in5; + register REAL *pb2 = prevblk2; + + DCT12_PART1; + + { + REAL tmp0,tmp1=(in0-in4); + { + REAL tmp2=(in1-in5)*hsec_12[1]; + tmp0=tmp1+tmp2; + tmp1-=tmp2; + } + pb2[5-1]=tmp0*wi[11-1]; + pb2[0+1]=tmp0*wi[6+1]; + out[(12+1)*SBLIMIT]+=tmp1*wi[1]; + out[(17-1)*SBLIMIT]+=tmp1*wi[5-1]; + } + + DCT12_PART2; + + pb2[5-0]=in2*wi[11-0]; + pb2[0+0]=in2*wi[6+0]; + pb2[0+2]=in3*wi[6+2]; + pb2[5-2]=in3*wi[11-2]; + + out[(12+0)*SBLIMIT]+=in0*wi[0]; + out[(17-0)*SBLIMIT]+=in0*wi[5-0]; + out[(12+2)*SBLIMIT]+=in4*wi[2]; + out[(17-2)*SBLIMIT]+=in4*wi[5-2]; + } + + in++; + { + REAL in0,in1,in2,in3,in4,in5; + register REAL *pb2 = prevblk2; + pb2[12]=pb2[13]=pb2[14]=pb2[15]=pb2[16]=pb2[17]=0.0; + + DCT12_PART1; + + { + REAL tmp0,tmp1=(in0-in4); + { + REAL tmp2=(in1-in5)*hsec_12[1]; + tmp0=tmp1+tmp2; + tmp1-=tmp2; + } + pb2[11-1]=tmp0*wi[11-1]; + pb2[ 6+1]=tmp0*wi[6+1]; + pb2[ 0+1]+=tmp1*wi[1]; + pb2[ 5-1]+=tmp1*wi[5-1]; + } + + DCT12_PART2; + pb2[11-0]=in2*wi[11-0]; + pb2[ 6+0]=in2*wi[ 6+0]; + pb2[ 6+2]=in3*wi[ 6+2]; + pb2[11-2]=in3*wi[11-2]; + + pb2[ 0+0]+=in0*wi[0 ]; + pb2[ 5-0]+=in0*wi[5-0]; + pb2[ 0+2]+=in4*wi[2 ]; + pb2[ 5-2]+=in4*wi[5-2]; + } + + +} + + diff --git a/Libraries/DecMPA/Files/src/splay/dct64.cpp b/Libraries/DecMPA/Files/src/splay/dct64.cpp new file mode 100644 index 000000000..5a142f09e --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/dct64.cpp @@ -0,0 +1,205 @@ +/* + wrapper for dcts + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - added some explicit casts to remove compilation warnings + +#include "common.h" +#include "dct.h" + +ATTR_ALIGN(64) static REAL hcos_64[16]; +ATTR_ALIGN(64) static REAL hcos_32[8]; +ATTR_ALIGN(64) static REAL hcos_16[4]; +ATTR_ALIGN(64) static REAL hcos_8[2]; +ATTR_ALIGN(64) static REAL hcos_4; + +/** + This was some time ago a standalone dct class, + but to get more speed I made it an inline dct + int the filter classes +*/ + +static int dct64Init=false; + +void initialize_dct64() { + if (dct64Init) { + return; + } + dct64Init=true; + + int i; + + for(i=0;i<16;i++) { + hcos_64[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/64.0))); + } + for(i=0;i< 8;i++) { + hcos_32[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/32.0))); + } + for(i=0;i< 4;i++) { + hcos_16[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/16.0))); + } + for(i=0;i< 2;i++) { + hcos_8[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/ 8.0))); + } + hcos_4=(REAL)(1.0/(2.0*cos(MY_PI*1.0/4.0))); + +} + + + + +// +// splay dct64 , faster than mpeg123 dct. (from decode.c) +// +void dct64(REAL* out1,REAL* out2,REAL *fraction) { + ATTR_ALIGN(64) REAL p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,pa,pb,pc,pd,pe,pf; + ATTR_ALIGN(64) REAL q0,q1,q2,q3,q4,q5,q6,q7,q8,q9,qa,qb,qc,qd,qe,qf; + +#define OUT1(v,t) out1[(32-(v))*16] =(-(out1[(v)*16]=t)) +#define OUT2(v) out2[(96-(v)-32)*16]=out2[((v)-32)*16] + + // compute new values via a fast cosine transform: + { + // put to buffer 0..15 + register REAL* x=fraction; + + p0=x[ 0]+x[31];p1=x[ 1]+x[30];p2=x[ 2]+x[29];p3=x[ 3]+x[28]; + p4=x[ 4]+x[27];p5=x[ 5]+x[26];p6=x[ 6]+x[25];p7=x[ 7]+x[24]; + p8=x[ 8]+x[23];p9=x[ 9]+x[22];pa=x[10]+x[21];pb=x[11]+x[20]; + pc=x[12]+x[19];pd=x[13]+x[18];pe=x[14]+x[17];pf=x[15]+x[16]; + } + + // put to buffer 32..39 + q0=p0+pf;q1=p1+pe;q2=p2+pd;q3=p3+pc; + q4=p4+pb;q5=p5+pa;q6=p6+p9;q7=p7+p8; + // put to buffer 40..47 + q8=hcos_32[0]*(p0-pf);q9=hcos_32[1]*(p1-pe); + qa=hcos_32[2]*(p2-pd);qb=hcos_32[3]*(p3-pc); + qc=hcos_32[4]*(p4-pb);qd=hcos_32[5]*(p5-pa); + qe=hcos_32[6]*(p6-p9);qf=hcos_32[7]*(p7-p8); + + p0=q0+q7;p1=q1+q6;p2=q2+q5;p3=q3+q4; + p4=hcos_16[0]*(q0-q7);p5=hcos_16[1]*(q1-q6); + p6=hcos_16[2]*(q2-q5);p7=hcos_16[3]*(q3-q4); + p8=q8+qf;p9=q9+qe;pa=qa+qd;pb=qb+qc; + pc=hcos_16[0]*(q8-qf);pd=hcos_16[1]*(q9-qe); + pe=hcos_16[2]*(qa-qd);pf=hcos_16[3]*(qb-qc); + + q0=p0+p3;q1=p1+p2;q2=hcos_8[0]*(p0-p3);q3=hcos_8[1]*(p1-p2); + q4=p4+p7;q5=p5+p6;q6=hcos_8[0]*(p4-p7);q7=hcos_8[1]*(p5-p6); + q8=p8+pb;q9=p9+pa;qa=hcos_8[0]*(p8-pb);qb=hcos_8[1]*(p9-pa); + qc=pc+pf;qd=pd+pe;qe=hcos_8[0]*(pc-pf);qf=hcos_8[1]*(pd-pe); + + p0=q0+q1;p1=hcos_4*(q0-q1);p2=q2+q3;p3=hcos_4*(q2-q3); + p4=q4+q5;p5=hcos_4*(q4-q5);p6=q6+q7;p7=hcos_4*(q6-q7); + p8=q8+q9;p9=hcos_4*(q8-q9);pa=qa+qb;pb=hcos_4*(qa-qb); + pc=qc+qd;pd=hcos_4*(qc-qd);pe=qe+qf;pf=hcos_4*(qe-qf); + + { + register REAL tmp; + + tmp=p6+p7; + OUT2(36)=-(p5+tmp); + OUT2(44)=-(p4+tmp); + tmp=pb+pf; + OUT1(10,tmp); + OUT1(6,pd+tmp); + tmp=pe+pf; + OUT2(46)=-(p8+pc+tmp); + OUT2(34)=-(p9+pd+tmp); + tmp+=pa+pb; + OUT2(38)=-(pd+tmp); + OUT2(42)=-(pc+tmp); + OUT1(2,p9+pd+pf); + OUT1(4,p5+p7); + OUT2(48)=-p0; + out2[0]=-(out1[0]=p1); + OUT1( 8,p3); + OUT1(12,p7); + OUT1(14,pf); + OUT2(40)=-(p2+p3); + } + + { + // put to buffer 16..31 + register REAL *x=fraction; + + p0=hcos_64[ 0]*(x[ 0]-x[31]);p1=hcos_64[ 1]*(x[ 1]-x[30]); + p2=hcos_64[ 2]*(x[ 2]-x[29]);p3=hcos_64[ 3]*(x[ 3]-x[28]); + p4=hcos_64[ 4]*(x[ 4]-x[27]);p5=hcos_64[ 5]*(x[ 5]-x[26]); + p6=hcos_64[ 6]*(x[ 6]-x[25]);p7=hcos_64[ 7]*(x[ 7]-x[24]); + p8=hcos_64[ 8]*(x[ 8]-x[23]);p9=hcos_64[ 9]*(x[ 9]-x[22]); + pa=hcos_64[10]*(x[10]-x[21]);pb=hcos_64[11]*(x[11]-x[20]); + pc=hcos_64[12]*(x[12]-x[19]);pd=hcos_64[13]*(x[13]-x[18]); + pe=hcos_64[14]*(x[14]-x[17]);pf=hcos_64[15]*(x[15]-x[16]); + } + + // put to 48..63 + q0=p0+pf;q1=p1+pe;q2=p2+pd;q3=p3+pc; + q4=p4+pb;q5=p5+pa;q6=p6+p9;q7=p7+p8; + q8=hcos_32[0]*(p0-pf);q9=hcos_32[1]*(p1-pe); + qa=hcos_32[2]*(p2-pd);qb=hcos_32[3]*(p3-pc); + qc=hcos_32[4]*(p4-pb);qd=hcos_32[5]*(p5-pa); + qe=hcos_32[6]*(p6-p9);qf=hcos_32[7]*(p7-p8); + + p0=q0+q7;p1=q1+q6;p2=q2+q5;p3=q3+q4; + p4=hcos_16[0]*(q0-q7);p5=hcos_16[1]*(q1-q6); + p6=hcos_16[2]*(q2-q5);p7=hcos_16[3]*(q3-q4); + p8=q8+qf;p9=q9+qe;pa=qa+qd;pb=qb+qc; + pc=hcos_16[0]*(q8-qf);pd=hcos_16[1]*(q9-qe); + pe=hcos_16[2]*(qa-qd);pf=hcos_16[3]*(qb-qc); + + q0=p0+p3;q1=p1+p2;q2=hcos_8[0]*(p0-p3);q3=hcos_8[1]*(p1-p2); + q4=p4+p7;q5=p5+p6;q6=hcos_8[0]*(p4-p7);q7=hcos_8[1]*(p5-p6); + q8=p8+pb;q9=p9+pa;qa=hcos_8[0]*(p8-pb);qb=hcos_8[1]*(p9-pa); + qc=pc+pf;qd=pd+pe;qe=hcos_8[0]*(pc-pf);qf=hcos_8[1]*(pd-pe); + + p0=q0+q1;p1=hcos_4*(q0-q1); + p2=q2+q3;p3=hcos_4*(q2-q3); + p4=q4+q5;p5=hcos_4*(q4-q5); + p6=q6+q7;p7=hcos_4*(q6-q7); + p8=q8+q9;p9=hcos_4*(q8-q9); + pa=qa+qb;pb=hcos_4*(qa-qb); + pc=qc+qd;pd=hcos_4*(qc-qd); + pe=qe+qf;pf=hcos_4*(qe-qf); + + { + REAL tmp; + + tmp=pd+pf; + OUT1(5,p5+p7+pb+tmp); + tmp+=p9; + OUT1(1,p1+tmp); + OUT2(33)=-(p1+pe+tmp); + tmp+=p5+p7; + OUT1(3,tmp); + OUT2(35)=-(p6+pe+tmp); + tmp=pa+pb+pc+pd+pe+pf; + OUT2(39)=-(p2+p3+tmp-pc); + OUT2(43)=-(p4+p6+p7+tmp-pd); + OUT2(37)=-(p5+p6+p7+tmp-pc); + OUT2(41)=-(p2+p3+tmp-pd); + tmp=p8+pc+pe+pf; + OUT2(47)=-(p0+tmp); + OUT2(45)=-(p4+p6+p7+tmp); + tmp=pb+pf; + OUT1(11,p7+tmp); + tmp+=p3; + OUT1( 9,tmp); + OUT1( 7,pd+tmp); + OUT1(13,p7+pf); + OUT1(15,pf); + } + +} + + diff --git a/Libraries/DecMPA/Files/src/splay/dct64_down.cpp b/Libraries/DecMPA/Files/src/splay/dct64_down.cpp new file mode 100644 index 000000000..09d907eef --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/dct64_down.cpp @@ -0,0 +1,215 @@ +/* + wrapper for dcts + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - added some explicit casts to remove compilation warnings + +#include "common.h" +#include "dct.h" + + +ATTR_ALIGN(64) static REAL hcos_64_down[16]; +ATTR_ALIGN(64) static REAL hcos_32_down[8]; +ATTR_ALIGN(64) static REAL hcos_16_down[4]; +ATTR_ALIGN(64) static REAL hcos_8_down[2]; +ATTR_ALIGN(64) static REAL hcos_4_down; + +/** + This was some time ago a standalone dct class, + but to get more speed I made it an inline dct + int the filter classes +*/ + +static int dctInit=false; + +void initialize_dct64_downsample() { + if (dctInit) { + return; + } + dctInit=true; + + int i; + + for(i=0;i<16;i++) { + hcos_64_down[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/64.0))); + } + for(i=0;i< 8;i++) { + hcos_32_down[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/32.0))); + } + for(i=0;i< 4;i++) { + hcos_16_down[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/16.0))); + } + for(i=0;i< 2;i++) { + hcos_8_down[i]=(REAL)(1.0/(2.0*cos(MY_PI*double(i*2+1)/ 8.0))); + } + hcos_4_down=(REAL)(1.0/(2.0*cos(MY_PI*1.0/4.0))); + +} + +void dct64_downsample(REAL* out1,REAL* out2,REAL *fraction) { + REAL p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,pa,pb,pc,pd,pe,pf; + REAL q0,q1,q2,q3,q4,q5,q6,q7,q8,q9,qa,qb,qc,qd,qe,qf; + +#define OUT1(v,t) out1[(32-(v))*16] =(-(out1[(v)*16]=t)) +#define OUT2(v) out2[(96-(v)-32)*16]=out2[((v)-32)*16] + + // compute new values via a fast cosine transform: + /* { + register REAL *x=fraction; + + p0=x[ 0]+x[31];p1=x[ 1]+x[30];p2=x[ 2]+x[29];p3=x[ 3]+x[28]; + p4=x[ 4]+x[27];p5=x[ 5]+x[26];p6=x[ 6]+x[25];p7=x[ 7]+x[24]; + p8=x[ 8]+x[23];p9=x[ 9]+x[22];pa=x[10]+x[21];pb=x[11]+x[20]; + pc=x[12]+x[19];pd=x[13]+x[18];pe=x[14]+x[17];pf=x[15]+x[16]; + } + + q0=p0+pf;q1=p1+pe;q2=p2+pd;q3=p3+pc; + q4=p4+pb;q5=p5+pa;q6=p6+p9;q7=p7+p8; + q8=hcos_32_down[0]*(p0-pf);q9=hcos_32_down[1]*(p1-pe); + qa=hcos_32_down[2]*(p2-pd);qb=hcos_32_down[3]*(p3-pc); + qc=hcos_32_down[4]*(p4-pb);qd=hcos_32_down[5]*(p5-pa); + qe=hcos_32_down[6]*(p6-p9);qf=hcos_32_down[7]*(p7-p8); */ + + { + + register REAL *x=fraction; + + q0=x[ 0]+x[15];q1=x[ 1]+x[14];q2=x[ 2]+x[13];q3=x[ 3]+x[12]; + q4=x[ 4]+x[11];q5=x[ 5]+x[10];q6=x[ 6]+x[ 9];q7=x[ 7]+x[ 8]; + + q8=hcos_32_down[0]*(x[ 0]-x[15]);q9=hcos_32_down[1]*(x[ 1]-x[14]); + qa=hcos_32_down[2]*(x[ 2]-x[13]);qb=hcos_32_down[3]*(x[ 3]-x[12]); + qc=hcos_32_down[4]*(x[ 4]-x[11]);qd=hcos_32_down[5]*(x[ 5]-x[10]); + qe=hcos_32_down[6]*(x[ 6]-x[ 9]);qf=hcos_32_down[7]*(x[ 7]-x[ 8]); + } + + p0=q0+q7;p1=q1+q6;p2=q2+q5;p3=q3+q4; + p4=hcos_16_down[0]*(q0-q7);p5=hcos_16_down[1]*(q1-q6); + p6=hcos_16_down[2]*(q2-q5);p7=hcos_16_down[3]*(q3-q4); + p8=q8+qf;p9=q9+qe;pa=qa+qd;pb=qb+qc; + pc=hcos_16_down[0]*(q8-qf);pd=hcos_16_down[1]*(q9-qe); + pe=hcos_16_down[2]*(qa-qd);pf=hcos_16_down[3]*(qb-qc); + + q0=p0+p3;q1=p1+p2;q2=hcos_8_down[0]*(p0-p3);q3=hcos_8_down[1]*(p1-p2); + q4=p4+p7;q5=p5+p6;q6=hcos_8_down[0]*(p4-p7);q7=hcos_8_down[1]*(p5-p6); + q8=p8+pb;q9=p9+pa;qa=hcos_8_down[0]*(p8-pb);qb=hcos_8_down[1]*(p9-pa); + qc=pc+pf;qd=pd+pe;qe=hcos_8_down[0]*(pc-pf);qf=hcos_8_down[1]*(pd-pe); + + p0=q0+q1;p1=hcos_4_down*(q0-q1);p2=q2+q3;p3=hcos_4_down*(q2-q3); + p4=q4+q5;p5=hcos_4_down*(q4-q5);p6=q6+q7;p7=hcos_4_down*(q6-q7); + p8=q8+q9;p9=hcos_4_down*(q8-q9);pa=qa+qb;pb=hcos_4_down*(qa-qb); + pc=qc+qd;pd=hcos_4_down*(qc-qd);pe=qe+qf;pf=hcos_4_down*(qe-qf); + + { + register REAL tmp; + + tmp=p6+p7; + OUT2(36)=-(p5+tmp); + OUT2(44)=-(p4+tmp); + tmp=pb+pf; + OUT1(10,tmp); + OUT1(6,pd+tmp); + tmp=pe+pf; + OUT2(46)=-(p8+pc+tmp); + OUT2(34)=-(p9+pd+tmp); + tmp+=pa+pb; + OUT2(38)=-(pd+tmp); + OUT2(42)=-(pc+tmp); + OUT1(2,p9+pd+pf); + OUT1(4,p5+p7); + OUT2(48)=-p0; + out2[0]=-(out1[0]=p1); + OUT1( 8,p3); + OUT1(12,p7); + OUT1(14,pf); + OUT2(40)=-(p2+p3); + } + + { + register REAL *x=fraction; + + /* p0=hcos_64_down[ 0]*(x[ 0]-x[31]);p1=hcos_64_down[ 1]*(x[ 1]-x[30]); + p2=hcos_64_down[ 2]*(x[ 2]-x[29]);p3=hcos_64_down[ 3]*(x[ 3]-x[28]); + p4=hcos_64_down[ 4]*(x[ 4]-x[27]);p5=hcos_64_down[ 5]*(x[ 5]-x[26]); + p6=hcos_64_down[ 6]*(x[ 6]-x[25]);p7=hcos_64_down[ 7]*(x[ 7]-x[24]); + p8=hcos_64_down[ 8]*(x[ 8]-x[23]);p9=hcos_64_down[ 9]*(x[ 9]-x[22]); + pa=hcos_64_down[10]*(x[10]-x[21]);pb=hcos_64_down[11]*(x[11]-x[20]); + pc=hcos_64_down[12]*(x[12]-x[19]);pd=hcos_64_down[13]*(x[13]-x[18]); + pe=hcos_64_down[14]*(x[14]-x[17]);pf=hcos_64_down[15]*(x[15]-x[16]); */ + + p0=hcos_64_down[ 0]*x[ 0];p1=hcos_64_down[ 1]*x[ 1]; + p2=hcos_64_down[ 2]*x[ 2];p3=hcos_64_down[ 3]*x[ 3]; + p4=hcos_64_down[ 4]*x[ 4];p5=hcos_64_down[ 5]*x[ 5]; + p6=hcos_64_down[ 6]*x[ 6];p7=hcos_64_down[ 7]*x[ 7]; + p8=hcos_64_down[ 8]*x[ 8];p9=hcos_64_down[ 9]*x[ 9]; + pa=hcos_64_down[10]*x[10];pb=hcos_64_down[11]*x[11]; + pc=hcos_64_down[12]*x[12];pd=hcos_64_down[13]*x[13]; + pe=hcos_64_down[14]*x[14];pf=hcos_64_down[15]*x[15]; + } + + q0=p0+pf;q1=p1+pe;q2=p2+pd;q3=p3+pc; + q4=p4+pb;q5=p5+pa;q6=p6+p9;q7=p7+p8; + q8=hcos_32_down[0]*(p0-pf);q9=hcos_32_down[1]*(p1-pe); + qa=hcos_32_down[2]*(p2-pd);qb=hcos_32_down[3]*(p3-pc); + qc=hcos_32_down[4]*(p4-pb);qd=hcos_32_down[5]*(p5-pa); + qe=hcos_32_down[6]*(p6-p9);qf=hcos_32_down[7]*(p7-p8); + + p0=q0+q7;p1=q1+q6;p2=q2+q5;p3=q3+q4; + p4=hcos_16_down[0]*(q0-q7);p5=hcos_16_down[1]*(q1-q6); + p6=hcos_16_down[2]*(q2-q5);p7=hcos_16_down[3]*(q3-q4); + p8=q8+qf;p9=q9+qe;pa=qa+qd;pb=qb+qc; + pc=hcos_16_down[0]*(q8-qf);pd=hcos_16_down[1]*(q9-qe); + pe=hcos_16_down[2]*(qa-qd);pf=hcos_16_down[3]*(qb-qc); + + q0=p0+p3;q1=p1+p2;q2=hcos_8_down[0]*(p0-p3);q3=hcos_8_down[1]*(p1-p2); + q4=p4+p7;q5=p5+p6;q6=hcos_8_down[0]*(p4-p7);q7=hcos_8_down[1]*(p5-p6); + q8=p8+pb;q9=p9+pa;qa=hcos_8_down[0]*(p8-pb);qb=hcos_8_down[1]*(p9-pa); + qc=pc+pf;qd=pd+pe;qe=hcos_8_down[0]*(pc-pf);qf=hcos_8_down[1]*(pd-pe); + + p0=q0+q1;p1=hcos_4_down*(q0-q1); + p2=q2+q3;p3=hcos_4_down*(q2-q3); + p4=q4+q5;p5=hcos_4_down*(q4-q5); + p6=q6+q7;p7=hcos_4_down*(q6-q7); + p8=q8+q9;p9=hcos_4_down*(q8-q9); + pa=qa+qb;pb=hcos_4_down*(qa-qb); + pc=qc+qd;pd=hcos_4_down*(qc-qd); + pe=qe+qf;pf=hcos_4_down*(qe-qf); + + { + REAL tmp; + + tmp=pd+pf; + OUT1(5,p5+p7+pb+tmp); + tmp+=p9; + OUT1(1,p1+tmp); + OUT2(33)=-(p1+pe+tmp); + tmp+=p5+p7; + OUT1(3,tmp); + OUT2(35)=-(p6+pe+tmp); + tmp=pa+pb+pc+pd+pe+pf; + OUT2(39)=-(p2+p3+tmp-pc); + OUT2(43)=-(p4+p6+p7+tmp-pd); + OUT2(37)=-(p5+p6+p7+tmp-pc); + OUT2(41)=-(p2+p3+tmp-pd); + tmp=p8+pc+pe+pf; + OUT2(47)=-(p0+tmp); + OUT2(45)=-(p4+p6+p7+tmp); + tmp=pb+pf; + OUT1(11,p7+tmp); + tmp+=p3; + OUT1( 9,tmp); + OUT1( 7,pd+tmp); + OUT1(13,p7+pf); + OUT1(15,pf); + } +} + diff --git a/Libraries/DecMPA/Files/src/splay/huffmanlookup.cpp b/Libraries/DecMPA/Files/src/splay/huffmanlookup.cpp new file mode 100644 index 000000000..028adb727 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/huffmanlookup.cpp @@ -0,0 +1,124 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + */ + +//changes 8/11/2002 (by Hauke Duden): +// - removed unnecessary includes + +#include "huffmanlookup.h" + +//#include + + + + +struct HuffmanLookup::decodeData HuffmanLookup::qdecode[32][256]; +/* for initialization */ +static HuffmanLookup l; + +HuffmanLookup::HuffmanLookup() +{ + int table,p,x,y; + + for(table = 0; table < 32; table++) + { + // 8 bits pattern + for(p = 0; p < 256; p++) + { + bits = 24; + pattern = (p << 16); + + huffmandecoder_1(&Mpegtoraw::ht[table], &x,&y); + + int used = 24 - bits; + qdecode[table][p].skip = (used <= 8)?used:0; + qdecode[table][p].x = x; + qdecode[table][p].y = y; + } + } +} + +int HuffmanLookup::wgetbit() +{ + return (pattern >> --bits) & 1; +} + +int HuffmanLookup::wgetbits (int b) +{ + bits -= b; + return (pattern >> bits) & ((1 << b) - 1); +} + +void HuffmanLookup::huffmandecoder_1(const HUFFMANCODETABLE *h, int *x, int *y) +{ + typedef unsigned int HUFFBITS; + + HUFFBITS level=(1<<(sizeof(HUFFBITS)*8-1)); + int point=0; + /* Lookup in Huffman table. */ + for(;;) + { + if(h->val[point][0]==0) + { /*end of tree*/ + int xx,yy; + + xx=h->val[point][1]>>4; + yy=h->val[point][1]&0xf; + + if(h->linbits) + { + if((h->xlen)==(unsigned)xx)xx+=wgetbits(h->linbits); + if(xx)if(wgetbit())xx=-xx; + if((h->ylen)==(unsigned)yy)yy+=wgetbits(h->linbits); + if(yy)if(wgetbit())yy=-yy; + } + else + { + if(xx)if(wgetbit())xx=-xx; + if(yy)if(wgetbit())yy=-yy; + } + *x=xx;*y=yy; + break; + } + + point+=h->val[point][wgetbit()]; + + level>>=1; + if(!(level || ((unsigned)pointtreelen))) + { + register int xx,yy; + + xx=(h->xlen<<1);// set x and y to a medium value as a simple concealment + yy=(h->ylen<<1); + + // h->xlen and h->ylen can't be 1 under tablename 32 + // if(xx) + if(wgetbit())xx=-xx; + // if(yy) + if(wgetbit())yy=-yy; + + *x=xx;*y=yy; + break; + } + } +} + + diff --git a/Libraries/DecMPA/Files/src/splay/huffmanlookup.h b/Libraries/DecMPA/Files/src/splay/huffmanlookup.h new file mode 100644 index 000000000..a5bdb26c4 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/huffmanlookup.h @@ -0,0 +1,57 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + */ + +#ifndef __HUFFMANLOOKUP_H +#define __HUFFMANLOOKUP_H +#include "mpegsound.h" + +/* + * This class speeds up the huffman table decoding by largely replacing it + * by a table lookup. It uses the fact that the huffman tables don't change, + * and that given a byte of the bitstream, we can predict what the result + * will be (without reading it bit by bit). + */ + +class HuffmanLookup { +private: + long pattern, bits; + int wgetbit(); + int wgetbits (int b); + void huffmandecoder_1(const HUFFMANCODETABLE *h,int *x, int *y); + + ATTR_ALIGN(64) static struct decodeData { + int x : 8; + int y : 8; + int skip : 16; + } qdecode[32][256]; +public: + HuffmanLookup(); + + static int decode(int table, int pattern, int* x, int* y) + { + *x = qdecode[table][pattern].x; + *y = qdecode[table][pattern].y; + return qdecode[table][pattern].skip; + } +}; + +#endif diff --git a/Libraries/DecMPA/Files/src/splay/huffmantable.cpp b/Libraries/DecMPA/Files/src/splay/huffmantable.cpp new file mode 100644 index 000000000..df7e620b4 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/huffmantable.cpp @@ -0,0 +1,584 @@ +/* MPEG/WAVE Sound library + + (C) 1997 by Jung woo-jae */ + +// Huffmantable.cc +// It contains initialized huffman table for MPEG layer 3 + + +#include "mpegsound.h" + +static const unsigned int +htd01[ 7][2]={{ 2, 1},{ 0, 0},{ 2, 1},{ 0, 16},{ 2, 1},{ 0, 1}, + { 0, 17}}, + +htd02[ 17][2]={{ 2, 1},{ 0, 0},{ 4, 1},{ 2, 1},{ 0, 16},{ 0, 1}, + { 2, 1},{ 0, 17},{ 4, 1},{ 2, 1},{ 0, 32},{ 0, 33}, + { 2, 1},{ 0, 18},{ 2, 1},{ 0, 2},{ 0, 34}}, + +htd03[ 17][2]={{ 4, 1},{ 2, 1},{ 0, 0},{ 0, 1},{ 2, 1},{ 0, 17}, + { 2, 1},{ 0, 16},{ 4, 1},{ 2, 1},{ 0, 32},{ 0, 33}, + { 2, 1},{ 0, 18},{ 2, 1},{ 0, 2},{ 0, 34}}, + +htd05[ 31][2]={{ 2, 1},{ 0, 0},{ 4, 1},{ 2, 1},{ 0, 16},{ 0, 1}, + { 2, 1},{ 0, 17},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 32}, + { 0, 2},{ 2, 1},{ 0, 33},{ 0, 18},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0, 34},{ 0, 48},{ 2, 1},{ 0, 3},{ 0, 19}, + { 2, 1},{ 0, 49},{ 2, 1},{ 0, 50},{ 2, 1},{ 0, 35}, + { 0, 51}}, + +htd06[ 31][2]={{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 0},{ 0, 16},{ 0, 17}, + { 6, 1},{ 2, 1},{ 0, 1},{ 2, 1},{ 0, 32},{ 0, 33}, + { 6, 1},{ 2, 1},{ 0, 18},{ 2, 1},{ 0, 2},{ 0, 34}, + { 4, 1},{ 2, 1},{ 0, 49},{ 0, 19},{ 4, 1},{ 2, 1}, + { 0, 48},{ 0, 50},{ 2, 1},{ 0, 35},{ 2, 1},{ 0, 3}, + { 0, 51}}, + +htd07[ 71][2]={{ 2, 1},{ 0, 0},{ 4, 1},{ 2, 1},{ 0, 16},{ 0, 1}, + { 8, 1},{ 2, 1},{ 0, 17},{ 4, 1},{ 2, 1},{ 0, 32}, + { 0, 2},{ 0, 33},{ 18, 1},{ 6, 1},{ 2, 1},{ 0, 18}, + { 2, 1},{ 0, 34},{ 0, 48},{ 4, 1},{ 2, 1},{ 0, 49}, + { 0, 19},{ 4, 1},{ 2, 1},{ 0, 3},{ 0, 50},{ 2, 1}, + { 0, 35},{ 0, 4},{ 10, 1},{ 4, 1},{ 2, 1},{ 0, 64}, + { 0, 65},{ 2, 1},{ 0, 20},{ 2, 1},{ 0, 66},{ 0, 36}, + { 12, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 51},{ 0, 67}, + { 0, 80},{ 4, 1},{ 2, 1},{ 0, 52},{ 0, 5},{ 0, 81}, + { 6, 1},{ 2, 1},{ 0, 21},{ 2, 1},{ 0, 82},{ 0, 37}, + + { 4, 1},{ 2, 1},{ 0, 68},{ 0, 53},{ 4, 1},{ 2, 1}, + { 0, 83},{ 0, 84},{ 2, 1},{ 0, 69},{ 0, 85}}, + +htd08[ 71][2]={{ 6, 1},{ 2, 1},{ 0, 0},{ 2, 1},{ 0, 16},{ 0, 1}, + { 2, 1},{ 0, 17},{ 4, 1},{ 2, 1},{ 0, 33},{ 0, 18}, + { 14, 1},{ 4, 1},{ 2, 1},{ 0, 32},{ 0, 2},{ 2, 1}, + { 0, 34},{ 4, 1},{ 2, 1},{ 0, 48},{ 0, 3},{ 2, 1}, + { 0, 49},{ 0, 19},{ 14, 1},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0, 50},{ 0, 35},{ 2, 1},{ 0, 64},{ 0, 4},{ 2, 1}, + { 0, 65},{ 2, 1},{ 0, 20},{ 0, 66},{ 12, 1},{ 6, 1}, + { 2, 1},{ 0, 36},{ 2, 1},{ 0, 51},{ 0, 80},{ 4, 1}, + { 2, 1},{ 0, 67},{ 0, 52},{ 0, 81},{ 6, 1},{ 2, 1}, + { 0, 21},{ 2, 1},{ 0, 5},{ 0, 82},{ 6, 1},{ 2, 1}, + + { 0, 37},{ 2, 1},{ 0, 68},{ 0, 53},{ 2, 1},{ 0, 83}, + { 2, 1},{ 0, 69},{ 2, 1},{ 0, 84},{ 0, 85}}, + +htd09[ 71][2]={{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 0},{ 0, 16},{ 2, 1}, + { 0, 1},{ 0, 17},{ 10, 1},{ 4, 1},{ 2, 1},{ 0, 32}, + { 0, 33},{ 2, 1},{ 0, 18},{ 2, 1},{ 0, 2},{ 0, 34}, + { 12, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 48},{ 0, 3}, + { 0, 49},{ 2, 1},{ 0, 19},{ 2, 1},{ 0, 50},{ 0, 35}, + { 12, 1},{ 4, 1},{ 2, 1},{ 0, 65},{ 0, 20},{ 4, 1}, + { 2, 1},{ 0, 64},{ 0, 51},{ 2, 1},{ 0, 66},{ 0, 36}, + { 10, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 4},{ 0, 80}, + { 0, 67},{ 2, 1},{ 0, 52},{ 0, 81},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0, 21},{ 0, 82},{ 2, 1},{ 0, 37},{ 0, 68}, + + { 6, 1},{ 4, 1},{ 2, 1},{ 0, 5},{ 0, 84},{ 0, 83}, + { 2, 1},{ 0, 53},{ 2, 1},{ 0, 69},{ 0, 85}}, + +htd10[127][2]={{ 2, 1},{ 0, 0},{ 4, 1},{ 2, 1},{ 0, 16},{ 0, 1}, + { 10, 1},{ 2, 1},{ 0, 17},{ 4, 1},{ 2, 1},{ 0, 32}, + { 0, 2},{ 2, 1},{ 0, 33},{ 0, 18},{ 28, 1},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0, 34},{ 0, 48},{ 2, 1},{ 0, 49}, + { 0, 19},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 3},{ 0, 50}, + { 2, 1},{ 0, 35},{ 0, 64},{ 4, 1},{ 2, 1},{ 0, 65}, + { 0, 20},{ 4, 1},{ 2, 1},{ 0, 4},{ 0, 51},{ 2, 1}, + { 0, 66},{ 0, 36},{ 28, 1},{ 10, 1},{ 6, 1},{ 4, 1}, + { 2, 1},{ 0, 80},{ 0, 5},{ 0, 96},{ 2, 1},{ 0, 97}, + { 0, 22},{ 12, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 67}, + + { 0, 52},{ 0, 81},{ 2, 1},{ 0, 21},{ 2, 1},{ 0, 82}, + { 0, 37},{ 4, 1},{ 2, 1},{ 0, 38},{ 0, 54},{ 0,113}, + { 20, 1},{ 8, 1},{ 2, 1},{ 0, 23},{ 4, 1},{ 2, 1}, + { 0, 68},{ 0, 83},{ 0, 6},{ 6, 1},{ 4, 1},{ 2, 1}, + { 0, 53},{ 0, 69},{ 0, 98},{ 2, 1},{ 0,112},{ 2, 1}, + { 0, 7},{ 0,100},{ 14, 1},{ 4, 1},{ 2, 1},{ 0,114}, + { 0, 39},{ 6, 1},{ 2, 1},{ 0, 99},{ 2, 1},{ 0, 84}, + { 0, 85},{ 2, 1},{ 0, 70},{ 0,115},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0, 55},{ 0,101},{ 2, 1},{ 0, 86},{ 0,116}, + { 6, 1},{ 2, 1},{ 0, 71},{ 2, 1},{ 0,102},{ 0,117}, + + { 4, 1},{ 2, 1},{ 0, 87},{ 0,118},{ 2, 1},{ 0,103}, + { 0,119}}, + +htd11[127][2]={{ 6, 1},{ 2, 1},{ 0, 0},{ 2, 1},{ 0, 16},{ 0, 1}, + { 8, 1},{ 2, 1},{ 0, 17},{ 4, 1},{ 2, 1},{ 0, 32}, + { 0, 2},{ 0, 18},{ 24, 1},{ 8, 1},{ 2, 1},{ 0, 33}, + { 2, 1},{ 0, 34},{ 2, 1},{ 0, 48},{ 0, 3},{ 4, 1}, + { 2, 1},{ 0, 49},{ 0, 19},{ 4, 1},{ 2, 1},{ 0, 50}, + { 0, 35},{ 4, 1},{ 2, 1},{ 0, 64},{ 0, 4},{ 2, 1}, + { 0, 65},{ 0, 20},{ 30, 1},{ 16, 1},{ 10, 1},{ 4, 1}, + { 2, 1},{ 0, 66},{ 0, 36},{ 4, 1},{ 2, 1},{ 0, 51}, + { 0, 67},{ 0, 80},{ 4, 1},{ 2, 1},{ 0, 52},{ 0, 81}, + { 0, 97},{ 6, 1},{ 2, 1},{ 0, 22},{ 2, 1},{ 0, 6}, + + { 0, 38},{ 2, 1},{ 0, 98},{ 2, 1},{ 0, 21},{ 2, 1}, + { 0, 5},{ 0, 82},{ 16, 1},{ 10, 1},{ 6, 1},{ 4, 1}, + { 2, 1},{ 0, 37},{ 0, 68},{ 0, 96},{ 2, 1},{ 0, 99}, + { 0, 54},{ 4, 1},{ 2, 1},{ 0,112},{ 0, 23},{ 0,113}, + { 16, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 7},{ 0,100}, + { 0,114},{ 2, 1},{ 0, 39},{ 4, 1},{ 2, 1},{ 0, 83}, + { 0, 53},{ 2, 1},{ 0, 84},{ 0, 69},{ 10, 1},{ 4, 1}, + { 2, 1},{ 0, 70},{ 0,115},{ 2, 1},{ 0, 55},{ 2, 1}, + { 0,101},{ 0, 86},{ 10, 1},{ 6, 1},{ 4, 1},{ 2, 1}, + { 0, 85},{ 0, 87},{ 0,116},{ 2, 1},{ 0, 71},{ 0,102}, + + { 4, 1},{ 2, 1},{ 0,117},{ 0,118},{ 2, 1},{ 0,103}, + { 0,119}}, + +htd12[127][2]={{ 12, 1},{ 4, 1},{ 2, 1},{ 0, 16},{ 0, 1},{ 2, 1}, + { 0, 17},{ 2, 1},{ 0, 0},{ 2, 1},{ 0, 32},{ 0, 2}, + { 16, 1},{ 4, 1},{ 2, 1},{ 0, 33},{ 0, 18},{ 4, 1}, + { 2, 1},{ 0, 34},{ 0, 49},{ 2, 1},{ 0, 19},{ 2, 1}, + { 0, 48},{ 2, 1},{ 0, 3},{ 0, 64},{ 26, 1},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0, 50},{ 0, 35},{ 2, 1},{ 0, 65}, + { 0, 51},{ 10, 1},{ 4, 1},{ 2, 1},{ 0, 20},{ 0, 66}, + { 2, 1},{ 0, 36},{ 2, 1},{ 0, 4},{ 0, 80},{ 4, 1}, + { 2, 1},{ 0, 67},{ 0, 52},{ 2, 1},{ 0, 81},{ 0, 21}, + { 28, 1},{ 14, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 82}, + + { 0, 37},{ 2, 1},{ 0, 83},{ 0, 53},{ 4, 1},{ 2, 1}, + { 0, 96},{ 0, 22},{ 0, 97},{ 4, 1},{ 2, 1},{ 0, 98}, + { 0, 38},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 5},{ 0, 6}, + { 0, 68},{ 2, 1},{ 0, 84},{ 0, 69},{ 18, 1},{ 10, 1}, + { 4, 1},{ 2, 1},{ 0, 99},{ 0, 54},{ 4, 1},{ 2, 1}, + { 0,112},{ 0, 7},{ 0,113},{ 4, 1},{ 2, 1},{ 0, 23}, + { 0,100},{ 2, 1},{ 0, 70},{ 0,114},{ 10, 1},{ 6, 1}, + { 2, 1},{ 0, 39},{ 2, 1},{ 0, 85},{ 0,115},{ 2, 1}, + { 0, 55},{ 0, 86},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,101}, + { 0,116},{ 2, 1},{ 0, 71},{ 0,102},{ 4, 1},{ 2, 1}, + + { 0,117},{ 0, 87},{ 2, 1},{ 0,118},{ 2, 1},{ 0,103}, + { 0,119}}, + +htd13[511][2]={{ 2, 1},{ 0, 0},{ 6, 1},{ 2, 1},{ 0, 16},{ 2, 1}, + { 0, 1},{ 0, 17},{ 28, 1},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0, 32},{ 0, 2},{ 2, 1},{ 0, 33},{ 0, 18},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0, 34},{ 0, 48},{ 2, 1},{ 0, 3}, + { 0, 49},{ 6, 1},{ 2, 1},{ 0, 19},{ 2, 1},{ 0, 50}, + { 0, 35},{ 4, 1},{ 2, 1},{ 0, 64},{ 0, 4},{ 0, 65}, + { 70, 1},{ 28, 1},{ 14, 1},{ 6, 1},{ 2, 1},{ 0, 20}, + { 2, 1},{ 0, 51},{ 0, 66},{ 4, 1},{ 2, 1},{ 0, 36}, + { 0, 80},{ 2, 1},{ 0, 67},{ 0, 52},{ 4, 1},{ 2, 1}, + { 0, 81},{ 0, 21},{ 4, 1},{ 2, 1},{ 0, 5},{ 0, 82}, // 60 + + { 2, 1},{ 0, 37},{ 2, 1},{ 0, 68},{ 0, 83},{ 14, 1}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0, 96},{ 0, 6},{ 2, 1}, + { 0, 97},{ 0, 22},{ 4, 1},{ 2, 1},{ 0,128},{ 0, 8}, + { 0,129},{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 53}, + { 0, 98},{ 2, 1},{ 0, 38},{ 0, 84},{ 4, 1},{ 2, 1}, + { 0, 69},{ 0, 99},{ 2, 1},{ 0, 54},{ 0,112},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0, 7},{ 0, 85},{ 0,113},{ 2, 1}, + { 0, 23},{ 2, 1},{ 0, 39},{ 0, 55},{ 72, 1},{ 24, 1}, + { 12, 1},{ 4, 1},{ 2, 1},{ 0, 24},{ 0,130},{ 2, 1}, + { 0, 40},{ 4, 1},{ 2, 1},{ 0,100},{ 0, 70},{ 0,114}, // 120 + + { 8, 1},{ 4, 1},{ 2, 1},{ 0,132},{ 0, 72},{ 2, 1}, + { 0,144},{ 0, 9},{ 2, 1},{ 0,145},{ 0, 25},{ 24, 1}, + { 14, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,115},{ 0,101}, + { 2, 1},{ 0, 86},{ 0,116},{ 4, 1},{ 2, 1},{ 0, 71}, + { 0,102},{ 0,131},{ 6, 1},{ 2, 1},{ 0, 56},{ 2, 1}, + { 0,117},{ 0, 87},{ 2, 1},{ 0,146},{ 0, 41},{ 14, 1}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,103},{ 0,133},{ 2, 1}, + { 0, 88},{ 0, 57},{ 2, 1},{ 0,147},{ 2, 1},{ 0, 73}, + { 0,134},{ 6, 1},{ 2, 1},{ 0,160},{ 2, 1},{ 0,104}, + { 0, 10},{ 2, 1},{ 0,161},{ 0, 26},{ 68, 1},{ 24, 1}, // 180 + + { 12, 1},{ 4, 1},{ 2, 1},{ 0,162},{ 0, 42},{ 4, 1}, + { 2, 1},{ 0,149},{ 0, 89},{ 2, 1},{ 0,163},{ 0, 58}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0, 74},{ 0,150},{ 2, 1}, + { 0,176},{ 0, 11},{ 2, 1},{ 0,177},{ 0, 27},{ 20, 1}, + { 8, 1},{ 2, 1},{ 0,178},{ 4, 1},{ 2, 1},{ 0,118}, + { 0,119},{ 0,148},{ 6, 1},{ 4, 1},{ 2, 1},{ 0,135}, + { 0,120},{ 0,164},{ 4, 1},{ 2, 1},{ 0,105},{ 0,165}, + { 0, 43},{ 12, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 90}, + { 0,136},{ 0,179},{ 2, 1},{ 0, 59},{ 2, 1},{ 0,121}, + { 0,166},{ 6, 1},{ 4, 1},{ 2, 1},{ 0,106},{ 0,180}, // 240 + + { 0,192},{ 4, 1},{ 2, 1},{ 0, 12},{ 0,152},{ 0,193}, + { 60, 1},{ 22, 1},{ 10, 1},{ 6, 1},{ 2, 1},{ 0, 28}, + { 2, 1},{ 0,137},{ 0,181},{ 2, 1},{ 0, 91},{ 0,194}, + { 4, 1},{ 2, 1},{ 0, 44},{ 0, 60},{ 4, 1},{ 2, 1}, + { 0,182},{ 0,107},{ 2, 1},{ 0,196},{ 0, 76},{ 16, 1}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,168},{ 0,138},{ 2, 1}, + { 0,208},{ 0, 13},{ 2, 1},{ 0,209},{ 2, 1},{ 0, 75}, + { 2, 1},{ 0,151},{ 0,167},{ 12, 1},{ 6, 1},{ 2, 1}, + { 0,195},{ 2, 1},{ 0,122},{ 0,153},{ 4, 1},{ 2, 1}, + { 0,197},{ 0, 92},{ 0,183},{ 4, 1},{ 2, 1},{ 0, 29}, // 300 + + { 0,210},{ 2, 1},{ 0, 45},{ 2, 1},{ 0,123},{ 0,211}, + { 52, 1},{ 28, 1},{ 12, 1},{ 4, 1},{ 2, 1},{ 0, 61}, + { 0,198},{ 4, 1},{ 2, 1},{ 0,108},{ 0,169},{ 2, 1}, + { 0,154},{ 0,212},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,184}, + { 0,139},{ 2, 1},{ 0, 77},{ 0,199},{ 4, 1},{ 2, 1}, + { 0,124},{ 0,213},{ 2, 1},{ 0, 93},{ 0,224},{ 10, 1}, + { 4, 1},{ 2, 1},{ 0,225},{ 0, 30},{ 4, 1},{ 2, 1}, + { 0, 14},{ 0, 46},{ 0,226},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0,227},{ 0,109},{ 2, 1},{ 0,140},{ 0,228},{ 4, 1}, + { 2, 1},{ 0,229},{ 0,186},{ 0,240},{ 38, 1},{ 16, 1}, // 360 + + { 4, 1},{ 2, 1},{ 0,241},{ 0, 31},{ 6, 1},{ 4, 1}, + { 2, 1},{ 0,170},{ 0,155},{ 0,185},{ 2, 1},{ 0, 62}, + { 2, 1},{ 0,214},{ 0,200},{ 12, 1},{ 6, 1},{ 2, 1}, + { 0, 78},{ 2, 1},{ 0,215},{ 0,125},{ 2, 1},{ 0,171}, + { 2, 1},{ 0, 94},{ 0,201},{ 6, 1},{ 2, 1},{ 0, 15}, + { 2, 1},{ 0,156},{ 0,110},{ 2, 1},{ 0,242},{ 0, 47}, + { 32, 1},{ 16, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0,216}, + { 0,141},{ 0, 63},{ 6, 1},{ 2, 1},{ 0,243},{ 2, 1}, + { 0,230},{ 0,202},{ 2, 1},{ 0,244},{ 0, 79},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0,187},{ 0,172},{ 2, 1},{ 0,231}, // 420 + + { 0,245},{ 4, 1},{ 2, 1},{ 0,217},{ 0,157},{ 2, 1}, + { 0, 95},{ 0,232},{ 30, 1},{ 12, 1},{ 6, 1},{ 2, 1}, + { 0,111},{ 2, 1},{ 0,246},{ 0,203},{ 4, 1},{ 2, 1}, + { 0,188},{ 0,173},{ 0,218},{ 8, 1},{ 2, 1},{ 0,247}, + { 4, 1},{ 2, 1},{ 0,126},{ 0,127},{ 0,142},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0,158},{ 0,174},{ 0,204},{ 2, 1}, + { 0,248},{ 0,143},{ 18, 1},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0,219},{ 0,189},{ 2, 1},{ 0,234},{ 0,249},{ 4, 1}, + { 2, 1},{ 0,159},{ 0,235},{ 2, 1},{ 0,190},{ 2, 1}, + { 0,205},{ 0,250},{ 14, 1},{ 4, 1},{ 2, 1},{ 0,221}, // 480 + + { 0,236},{ 6, 1},{ 4, 1},{ 2, 1},{ 0,233},{ 0,175}, + { 0,220},{ 2, 1},{ 0,206},{ 0,251},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0,191},{ 0,222},{ 2, 1},{ 0,207},{ 0,238}, + { 4, 1},{ 2, 1},{ 0,223},{ 0,239},{ 2, 1},{ 0,255}, + { 2, 1},{ 0,237},{ 2, 1},{ 0,253},{ 2, 1},{ 0,252}, + { 0,254}}, + +htd15[511][2]={{ 16, 1},{ 6, 1},{ 2, 1},{ 0, 0},{ 2, 1},{ 0, 16}, + { 0, 1},{ 2, 1},{ 0, 17},{ 4, 1},{ 2, 1},{ 0, 32}, + { 0, 2},{ 2, 1},{ 0, 33},{ 0, 18},{ 50, 1},{ 16, 1}, + { 6, 1},{ 2, 1},{ 0, 34},{ 2, 1},{ 0, 48},{ 0, 49}, + { 6, 1},{ 2, 1},{ 0, 19},{ 2, 1},{ 0, 3},{ 0, 64}, + { 2, 1},{ 0, 50},{ 0, 35},{ 14, 1},{ 6, 1},{ 4, 1}, + { 2, 1},{ 0, 4},{ 0, 20},{ 0, 65},{ 4, 1},{ 2, 1}, + { 0, 51},{ 0, 66},{ 2, 1},{ 0, 36},{ 0, 67},{ 10, 1}, + { 6, 1},{ 2, 1},{ 0, 52},{ 2, 1},{ 0, 80},{ 0, 5}, + { 2, 1},{ 0, 81},{ 0, 21},{ 4, 1},{ 2, 1},{ 0, 82}, // 60 + + { 0, 37},{ 4, 1},{ 2, 1},{ 0, 68},{ 0, 83},{ 0, 97}, + { 90, 1},{ 36, 1},{ 18, 1},{ 10, 1},{ 6, 1},{ 2, 1}, + { 0, 53},{ 2, 1},{ 0, 96},{ 0, 6},{ 2, 1},{ 0, 22}, + { 0, 98},{ 4, 1},{ 2, 1},{ 0, 38},{ 0, 84},{ 2, 1}, + { 0, 69},{ 0, 99},{ 10, 1},{ 6, 1},{ 2, 1},{ 0, 54}, + { 2, 1},{ 0,112},{ 0, 7},{ 2, 1},{ 0,113},{ 0, 85}, + { 4, 1},{ 2, 1},{ 0, 23},{ 0,100},{ 2, 1},{ 0,114}, + { 0, 39},{ 24, 1},{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0, 70},{ 0,115},{ 2, 1},{ 0, 55},{ 0,101},{ 4, 1}, + { 2, 1},{ 0, 86},{ 0,128},{ 2, 1},{ 0, 8},{ 0,116}, // 120 + + { 4, 1},{ 2, 1},{ 0,129},{ 0, 24},{ 2, 1},{ 0,130}, + { 0, 40},{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 71}, + { 0,102},{ 2, 1},{ 0,131},{ 0, 56},{ 4, 1},{ 2, 1}, + { 0,117},{ 0, 87},{ 2, 1},{ 0,132},{ 0, 72},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0,144},{ 0, 25},{ 0,145},{ 4, 1}, + { 2, 1},{ 0,146},{ 0,118},{ 2, 1},{ 0,103},{ 0, 41}, + { 92, 1},{ 36, 1},{ 18, 1},{ 10, 1},{ 4, 1},{ 2, 1}, + { 0,133},{ 0, 88},{ 4, 1},{ 2, 1},{ 0, 9},{ 0,119}, + { 0,147},{ 4, 1},{ 2, 1},{ 0, 57},{ 0,148},{ 2, 1}, + { 0, 73},{ 0,134},{ 10, 1},{ 6, 1},{ 2, 1},{ 0,104}, // 180 + + { 2, 1},{ 0,160},{ 0, 10},{ 2, 1},{ 0,161},{ 0, 26}, + { 4, 1},{ 2, 1},{ 0,162},{ 0, 42},{ 2, 1},{ 0,149}, + { 0, 89},{ 26, 1},{ 14, 1},{ 6, 1},{ 2, 1},{ 0,163}, + { 2, 1},{ 0, 58},{ 0,135},{ 4, 1},{ 2, 1},{ 0,120}, + { 0,164},{ 2, 1},{ 0, 74},{ 0,150},{ 6, 1},{ 4, 1}, + { 2, 1},{ 0,105},{ 0,176},{ 0,177},{ 4, 1},{ 2, 1}, + { 0, 27},{ 0,165},{ 0,178},{ 14, 1},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0, 90},{ 0, 43},{ 2, 1},{ 0,136},{ 0,151}, + { 2, 1},{ 0,179},{ 2, 1},{ 0,121},{ 0, 59},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0,106},{ 0,180},{ 2, 1},{ 0, 75}, // 240 + + { 0,193},{ 4, 1},{ 2, 1},{ 0,152},{ 0,137},{ 2, 1}, + { 0, 28},{ 0,181},{ 80, 1},{ 34, 1},{ 16, 1},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0, 91},{ 0, 44},{ 0,194},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0, 11},{ 0,192},{ 0,166},{ 2, 1}, + { 0,167},{ 0,122},{ 10, 1},{ 4, 1},{ 2, 1},{ 0,195}, + { 0, 60},{ 4, 1},{ 2, 1},{ 0, 12},{ 0,153},{ 0,182}, + { 4, 1},{ 2, 1},{ 0,107},{ 0,196},{ 2, 1},{ 0, 76}, + { 0,168},{ 20, 1},{ 10, 1},{ 4, 1},{ 2, 1},{ 0,138}, + { 0,197},{ 4, 1},{ 2, 1},{ 0,208},{ 0, 92},{ 0,209}, + { 4, 1},{ 2, 1},{ 0,183},{ 0,123},{ 2, 1},{ 0, 29}, // 300 + + { 2, 1},{ 0, 13},{ 0, 45},{ 12, 1},{ 4, 1},{ 2, 1}, + { 0,210},{ 0,211},{ 4, 1},{ 2, 1},{ 0, 61},{ 0,198}, + { 2, 1},{ 0,108},{ 0,169},{ 6, 1},{ 4, 1},{ 2, 1}, + { 0,154},{ 0,184},{ 0,212},{ 4, 1},{ 2, 1},{ 0,139}, + { 0, 77},{ 2, 1},{ 0,199},{ 0,124},{ 68, 1},{ 34, 1}, + { 18, 1},{ 10, 1},{ 4, 1},{ 2, 1},{ 0,213},{ 0, 93}, + { 4, 1},{ 2, 1},{ 0,224},{ 0, 14},{ 0,225},{ 4, 1}, + { 2, 1},{ 0, 30},{ 0,226},{ 2, 1},{ 0,170},{ 0, 46}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,185},{ 0,155},{ 2, 1}, + { 0,227},{ 0,214},{ 4, 1},{ 2, 1},{ 0,109},{ 0, 62}, // 360 + + { 2, 1},{ 0,200},{ 0,140},{ 16, 1},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0,228},{ 0, 78},{ 2, 1},{ 0,215},{ 0,125}, + { 4, 1},{ 2, 1},{ 0,229},{ 0,186},{ 2, 1},{ 0,171}, + { 0, 94},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,201},{ 0,156}, + { 2, 1},{ 0,241},{ 0, 31},{ 6, 1},{ 4, 1},{ 2, 1}, + { 0,240},{ 0,110},{ 0,242},{ 2, 1},{ 0, 47},{ 0,230}, + { 38, 1},{ 18, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,216}, + { 0,243},{ 2, 1},{ 0, 63},{ 0,244},{ 6, 1},{ 2, 1}, + { 0, 79},{ 2, 1},{ 0,141},{ 0,217},{ 2, 1},{ 0,187}, + { 0,202},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,172},{ 0,231}, // 420 + + { 2, 1},{ 0,126},{ 0,245},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0,157},{ 0, 95},{ 2, 1},{ 0,232},{ 0,142},{ 2, 1}, + { 0,246},{ 0,203},{ 34, 1},{ 18, 1},{ 10, 1},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0, 15},{ 0,174},{ 0,111},{ 2, 1}, + { 0,188},{ 0,218},{ 4, 1},{ 2, 1},{ 0,173},{ 0,247}, + { 2, 1},{ 0,127},{ 0,233},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0,158},{ 0,204},{ 2, 1},{ 0,248},{ 0,143},{ 4, 1}, + { 2, 1},{ 0,219},{ 0,189},{ 2, 1},{ 0,234},{ 0,249}, + { 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,159},{ 0,220}, + { 2, 1},{ 0,205},{ 0,235},{ 4, 1},{ 2, 1},{ 0,190}, // 480 + + { 0,250},{ 2, 1},{ 0,175},{ 0,221},{ 14, 1},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0,236},{ 0,206},{ 0,251},{ 4, 1}, + { 2, 1},{ 0,191},{ 0,237},{ 2, 1},{ 0,222},{ 0,252}, + { 6, 1},{ 4, 1},{ 2, 1},{ 0,207},{ 0,253},{ 0,238}, + { 4, 1},{ 2, 1},{ 0,223},{ 0,254},{ 2, 1},{ 0,239}, + { 0,255}}, + +htd16[511][2]={{ 2, 1},{ 0, 0},{ 6, 1},{ 2, 1},{ 0, 16},{ 2, 1}, + { 0, 1},{ 0, 17},{ 42, 1},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0, 32},{ 0, 2},{ 2, 1},{ 0, 33},{ 0, 18},{ 10, 1}, + { 6, 1},{ 2, 1},{ 0, 34},{ 2, 1},{ 0, 48},{ 0, 3}, + { 2, 1},{ 0, 49},{ 0, 19},{ 10, 1},{ 4, 1},{ 2, 1}, + { 0, 50},{ 0, 35},{ 4, 1},{ 2, 1},{ 0, 64},{ 0, 4}, + { 0, 65},{ 6, 1},{ 2, 1},{ 0, 20},{ 2, 1},{ 0, 51}, + { 0, 66},{ 4, 1},{ 2, 1},{ 0, 36},{ 0, 80},{ 2, 1}, + { 0, 67},{ 0, 52},{138, 1},{ 40, 1},{ 16, 1},{ 6, 1}, + { 4, 1},{ 2, 1},{ 0, 5},{ 0, 21},{ 0, 81},{ 4, 1}, // 60 + + { 2, 1},{ 0, 82},{ 0, 37},{ 4, 1},{ 2, 1},{ 0, 68}, + { 0, 53},{ 0, 83},{ 10, 1},{ 6, 1},{ 4, 1},{ 2, 1}, + { 0, 96},{ 0, 6},{ 0, 97},{ 2, 1},{ 0, 22},{ 0, 98}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0, 38},{ 0, 84},{ 2, 1}, + { 0, 69},{ 0, 99},{ 4, 1},{ 2, 1},{ 0, 54},{ 0,112}, + { 0,113},{ 40, 1},{ 18, 1},{ 8, 1},{ 2, 1},{ 0, 23}, + { 2, 1},{ 0, 7},{ 2, 1},{ 0, 85},{ 0,100},{ 4, 1}, + { 2, 1},{ 0,114},{ 0, 39},{ 4, 1},{ 2, 1},{ 0, 70}, + { 0,101},{ 0,115},{ 10, 1},{ 6, 1},{ 2, 1},{ 0, 55}, + { 2, 1},{ 0, 86},{ 0, 8},{ 2, 1},{ 0,128},{ 0,129}, // 120 + + { 6, 1},{ 2, 1},{ 0, 24},{ 2, 1},{ 0,116},{ 0, 71}, + { 2, 1},{ 0,130},{ 2, 1},{ 0, 40},{ 0,102},{ 24, 1}, + { 14, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,131},{ 0, 56}, + { 2, 1},{ 0,117},{ 0,132},{ 4, 1},{ 2, 1},{ 0, 72}, + { 0,144},{ 0,145},{ 6, 1},{ 2, 1},{ 0, 25},{ 2, 1}, + { 0, 9},{ 0,118},{ 2, 1},{ 0,146},{ 0, 41},{ 14, 1}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,133},{ 0, 88},{ 2, 1}, + { 0,147},{ 0, 57},{ 4, 1},{ 2, 1},{ 0,160},{ 0, 10}, + { 0, 26},{ 8, 1},{ 2, 1},{ 0,162},{ 2, 1},{ 0,103}, + { 2, 1},{ 0, 87},{ 0, 73},{ 6, 1},{ 2, 1},{ 0,148}, // 180 + + { 2, 1},{ 0,119},{ 0,134},{ 2, 1},{ 0,161},{ 2, 1}, + { 0,104},{ 0,149},{220, 1},{126, 1},{ 50, 1},{ 26, 1}, + { 12, 1},{ 6, 1},{ 2, 1},{ 0, 42},{ 2, 1},{ 0, 89}, + { 0, 58},{ 2, 1},{ 0,163},{ 2, 1},{ 0,135},{ 0,120}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,164},{ 0, 74},{ 2, 1}, + { 0,150},{ 0,105},{ 4, 1},{ 2, 1},{ 0,176},{ 0, 11}, + { 0,177},{ 10, 1},{ 4, 1},{ 2, 1},{ 0, 27},{ 0,178}, + { 2, 1},{ 0, 43},{ 2, 1},{ 0,165},{ 0, 90},{ 6, 1}, + { 2, 1},{ 0,179},{ 2, 1},{ 0,166},{ 0,106},{ 4, 1}, + { 2, 1},{ 0,180},{ 0, 75},{ 2, 1},{ 0, 12},{ 0,193}, // 240 + + { 30, 1},{ 14, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0,181}, + { 0,194},{ 0, 44},{ 4, 1},{ 2, 1},{ 0,167},{ 0,195}, + { 2, 1},{ 0,107},{ 0,196},{ 8, 1},{ 2, 1},{ 0, 29}, + { 4, 1},{ 2, 1},{ 0,136},{ 0,151},{ 0, 59},{ 4, 1}, + { 2, 1},{ 0,209},{ 0,210},{ 2, 1},{ 0, 45},{ 0,211}, + { 18, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0, 30},{ 0, 46}, + { 0,226},{ 6, 1},{ 4, 1},{ 2, 1},{ 0,121},{ 0,152}, + { 0,192},{ 2, 1},{ 0, 28},{ 2, 1},{ 0,137},{ 0, 91}, + { 14, 1},{ 6, 1},{ 2, 1},{ 0, 60},{ 2, 1},{ 0,122}, + { 0,182},{ 4, 1},{ 2, 1},{ 0, 76},{ 0,153},{ 2, 1}, // 300 + + { 0,168},{ 0,138},{ 6, 1},{ 2, 1},{ 0, 13},{ 2, 1}, + { 0,197},{ 0, 92},{ 4, 1},{ 2, 1},{ 0, 61},{ 0,198}, + { 2, 1},{ 0,108},{ 0,154},{ 88, 1},{ 86, 1},{ 36, 1}, + { 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,139},{ 0, 77}, + { 2, 1},{ 0,199},{ 0,124},{ 4, 1},{ 2, 1},{ 0,213}, + { 0, 93},{ 2, 1},{ 0,224},{ 0, 14},{ 8, 1},{ 2, 1}, + { 0,227},{ 4, 1},{ 2, 1},{ 0,208},{ 0,183},{ 0,123}, + { 6, 1},{ 4, 1},{ 2, 1},{ 0,169},{ 0,184},{ 0,212}, + { 2, 1},{ 0,225},{ 2, 1},{ 0,170},{ 0,185},{ 24, 1}, + { 10, 1},{ 6, 1},{ 4, 1},{ 2, 1},{ 0,155},{ 0,214}, // 360 + + { 0,109},{ 2, 1},{ 0, 62},{ 0,200},{ 6, 1},{ 4, 1}, + { 2, 1},{ 0,140},{ 0,228},{ 0, 78},{ 4, 1},{ 2, 1}, + { 0,215},{ 0,229},{ 2, 1},{ 0,186},{ 0,171},{ 12, 1}, + { 4, 1},{ 2, 1},{ 0,156},{ 0,230},{ 4, 1},{ 2, 1}, + { 0,110},{ 0,216},{ 2, 1},{ 0,141},{ 0,187},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0,231},{ 0,157},{ 2, 1},{ 0,232}, + { 0,142},{ 4, 1},{ 2, 1},{ 0,203},{ 0,188},{ 0,158}, + { 0,241},{ 2, 1},{ 0, 31},{ 2, 1},{ 0, 15},{ 0, 47}, + { 66, 1},{ 56, 1},{ 2, 1},{ 0,242},{ 52, 1},{ 50, 1}, + { 20, 1},{ 8, 1},{ 2, 1},{ 0,189},{ 2, 1},{ 0, 94}, // 420 + + { 2, 1},{ 0,125},{ 0,201},{ 6, 1},{ 2, 1},{ 0,202}, + { 2, 1},{ 0,172},{ 0,126},{ 4, 1},{ 2, 1},{ 0,218}, + { 0,173},{ 0,204},{ 10, 1},{ 6, 1},{ 2, 1},{ 0,174}, + { 2, 1},{ 0,219},{ 0,220},{ 2, 1},{ 0,205},{ 0,190}, + { 6, 1},{ 4, 1},{ 2, 1},{ 0,235},{ 0,237},{ 0,238}, + { 6, 1},{ 4, 1},{ 2, 1},{ 0,217},{ 0,234},{ 0,233}, + { 2, 1},{ 0,222},{ 4, 1},{ 2, 1},{ 0,221},{ 0,236}, + { 0,206},{ 0, 63},{ 0,240},{ 4, 1},{ 2, 1},{ 0,243}, + { 0,244},{ 2, 1},{ 0, 79},{ 2, 1},{ 0,245},{ 0, 95}, + { 10, 1},{ 2, 1},{ 0,255},{ 4, 1},{ 2, 1},{ 0,246}, // 480 + + { 0,111},{ 2, 1},{ 0,247},{ 0,127},{ 12, 1},{ 6, 1}, + { 2, 1},{ 0,143},{ 2, 1},{ 0,248},{ 0,249},{ 4, 1}, + { 2, 1},{ 0,159},{ 0,250},{ 0,175},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0,251},{ 0,191},{ 2, 1},{ 0,252},{ 0,207}, + { 4, 1},{ 2, 1},{ 0,253},{ 0,223},{ 2, 1},{ 0,254}, + { 0,239}}, + +htd24[512][2]={{ 60, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 0},{ 0, 16}, + { 2, 1},{ 0, 1},{ 0, 17},{ 14, 1},{ 6, 1},{ 4, 1}, + { 2, 1},{ 0, 32},{ 0, 2},{ 0, 33},{ 2, 1},{ 0, 18}, + { 2, 1},{ 0, 34},{ 2, 1},{ 0, 48},{ 0, 3},{ 14, 1}, + { 4, 1},{ 2, 1},{ 0, 49},{ 0, 19},{ 4, 1},{ 2, 1}, + { 0, 50},{ 0, 35},{ 4, 1},{ 2, 1},{ 0, 64},{ 0, 4}, + { 0, 65},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 20},{ 0, 51}, + { 2, 1},{ 0, 66},{ 0, 36},{ 6, 1},{ 4, 1},{ 2, 1}, + { 0, 67},{ 0, 52},{ 0, 81},{ 6, 1},{ 4, 1},{ 2, 1}, + { 0, 80},{ 0, 5},{ 0, 21},{ 2, 1},{ 0, 82},{ 0, 37}, // 60 + + {250+85, 1},{ 98, 1},{ 34, 1},{ 18, 1},{ 10, 1},{ 4, 1}, + { 2, 1},{ 0, 68},{ 0, 83},{ 2, 1},{ 0, 53},{ 2, 1}, + { 0, 96},{ 0, 6},{ 4, 1},{ 2, 1},{ 0, 97},{ 0, 22}, + { 2, 1},{ 0, 98},{ 0, 38},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0, 84},{ 0, 69},{ 2, 1},{ 0, 99},{ 0, 54},{ 4, 1}, + { 2, 1},{ 0,113},{ 0, 85},{ 2, 1},{ 0,100},{ 0, 70}, + { 32, 1},{ 14, 1},{ 6, 1},{ 2, 1},{ 0,114},{ 2, 1}, + { 0, 39},{ 0, 55},{ 2, 1},{ 0,115},{ 4, 1},{ 2, 1}, + { 0,112},{ 0, 7},{ 0, 23},{ 10, 1},{ 4, 1},{ 2, 1}, + { 0,101},{ 0, 86},{ 4, 1},{ 2, 1},{ 0,128},{ 0, 8}, // 120 + + { 0,129},{ 4, 1},{ 2, 1},{ 0,116},{ 0, 71},{ 2, 1}, + { 0, 24},{ 0,130},{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1}, + { 0, 40},{ 0,102},{ 2, 1},{ 0,131},{ 0, 56},{ 4, 1}, + { 2, 1},{ 0,117},{ 0, 87},{ 2, 1},{ 0,132},{ 0, 72}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,145},{ 0, 25},{ 2, 1}, + { 0,146},{ 0,118},{ 4, 1},{ 2, 1},{ 0,103},{ 0, 41}, + { 2, 1},{ 0,133},{ 0, 88},{ 92, 1},{ 34, 1},{ 16, 1}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,147},{ 0, 57},{ 2, 1}, + { 0,148},{ 0, 73},{ 4, 1},{ 2, 1},{ 0,119},{ 0,134}, + { 2, 1},{ 0,104},{ 0,161},{ 8, 1},{ 4, 1},{ 2, 1}, // 180 + + { 0,162},{ 0, 42},{ 2, 1},{ 0,149},{ 0, 89},{ 4, 1}, + { 2, 1},{ 0,163},{ 0, 58},{ 2, 1},{ 0,135},{ 2, 1}, + { 0,120},{ 0, 74},{ 22, 1},{ 12, 1},{ 4, 1},{ 2, 1}, + { 0,164},{ 0,150},{ 4, 1},{ 2, 1},{ 0,105},{ 0,177}, + { 2, 1},{ 0, 27},{ 0,165},{ 6, 1},{ 2, 1},{ 0,178}, + { 2, 1},{ 0, 90},{ 0, 43},{ 2, 1},{ 0,136},{ 0,179}, + { 16, 1},{ 10, 1},{ 6, 1},{ 2, 1},{ 0,144},{ 2, 1}, + { 0, 9},{ 0,160},{ 2, 1},{ 0,151},{ 0,121},{ 4, 1}, + { 2, 1},{ 0,166},{ 0,106},{ 0,180},{ 12, 1},{ 6, 1}, + { 2, 1},{ 0, 26},{ 2, 1},{ 0, 10},{ 0,176},{ 2, 1}, // 240 + + { 0, 59},{ 2, 1},{ 0, 11},{ 0,192},{ 4, 1},{ 2, 1}, + { 0, 75},{ 0,193},{ 2, 1},{ 0,152},{ 0,137},{ 67, 1}, + { 34, 1},{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 28}, + { 0,181},{ 2, 1},{ 0, 91},{ 0,194},{ 4, 1},{ 2, 1}, + { 0, 44},{ 0,167},{ 2, 1},{ 0,122},{ 0,195},{ 10, 1}, + { 6, 1},{ 2, 1},{ 0, 60},{ 2, 1},{ 0, 12},{ 0,208}, + { 2, 1},{ 0,182},{ 0,107},{ 4, 1},{ 2, 1},{ 0,196}, + { 0, 76},{ 2, 1},{ 0,153},{ 0,168},{ 16, 1},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0,138},{ 0,197},{ 2, 1},{ 0, 92}, + { 0,209},{ 4, 1},{ 2, 1},{ 0,183},{ 0,123},{ 2, 1}, // 300 + + { 0, 29},{ 0,210},{ 9, 1},{ 4, 1},{ 2, 1},{ 0, 45}, + { 0,211},{ 2, 1},{ 0, 61},{ 0,198},{ 85,250},{ 4, 1}, // 306 - + { 2, 1},{ 0,108},{ 0,169},{ 2, 1},{ 0,154},{ 0,212}, + { 32, 1},{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,184}, + { 0,139},{ 2, 1},{ 0, 77},{ 0,199},{ 4, 1},{ 2, 1}, + { 0,124},{ 0,213},{ 2, 1},{ 0, 93},{ 0,225},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0, 30},{ 0,226},{ 2, 1},{ 0,170}, + { 0,185},{ 4, 1},{ 2, 1},{ 0,155},{ 0,227},{ 2, 1}, + { 0,214},{ 0,109},{ 20, 1},{ 10, 1},{ 6, 1},{ 2, 1}, + { 0, 62},{ 2, 1},{ 0, 46},{ 0, 78},{ 2, 1},{ 0,200}, // 360 + + { 0,140},{ 4, 1},{ 2, 1},{ 0,228},{ 0,215},{ 4, 1}, + { 2, 1},{ 0,125},{ 0,171},{ 0,229},{ 10, 1},{ 4, 1}, + { 2, 1},{ 0,186},{ 0, 94},{ 2, 1},{ 0,201},{ 2, 1}, + { 0,156},{ 0,110},{ 8, 1},{ 2, 1},{ 0,230},{ 2, 1}, + { 0, 13},{ 2, 1},{ 0,224},{ 0, 14},{ 4, 1},{ 2, 1}, + { 0,216},{ 0,141},{ 2, 1},{ 0,187},{ 0,202},{ 74, 1}, + { 2, 1},{ 0,255},{ 64, 1},{ 58, 1},{ 32, 1},{ 16, 1}, + { 8, 1},{ 4, 1},{ 2, 1},{ 0,172},{ 0,231},{ 2, 1}, + { 0,126},{ 0,217},{ 4, 1},{ 2, 1},{ 0,157},{ 0,232}, + { 2, 1},{ 0,142},{ 0,203},{ 8, 1},{ 4, 1},{ 2, 1}, // 420 + + { 0,188},{ 0,218},{ 2, 1},{ 0,173},{ 0,233},{ 4, 1}, + { 2, 1},{ 0,158},{ 0,204},{ 2, 1},{ 0,219},{ 0,189}, + { 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,234},{ 0,174}, + { 2, 1},{ 0,220},{ 0,205},{ 4, 1},{ 2, 1},{ 0,235}, + { 0,190},{ 2, 1},{ 0,221},{ 0,236},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0,206},{ 0,237},{ 2, 1},{ 0,222},{ 0,238}, + { 0, 15},{ 4, 1},{ 2, 1},{ 0,240},{ 0, 31},{ 0,241}, + { 4, 1},{ 2, 1},{ 0,242},{ 0, 47},{ 2, 1},{ 0,243}, + { 0, 63},{ 18, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0,244}, + { 0, 79},{ 2, 1},{ 0,245},{ 0, 95},{ 4, 1},{ 2, 1}, // 480 + + { 0,246},{ 0,111},{ 2, 1},{ 0,247},{ 2, 1},{ 0,127}, + { 0,143},{ 10, 1},{ 4, 1},{ 2, 1},{ 0,248},{ 0,249}, + { 4, 1},{ 2, 1},{ 0,159},{ 0,175},{ 0,250},{ 8, 1}, + { 4, 1},{ 2, 1},{ 0,251},{ 0,191},{ 2, 1},{ 0,252}, + { 0,207},{ 4, 1},{ 2, 1},{ 0,253},{ 0,223},{ 2, 1}, + { 0,254},{ 0,239}}, + +htd32[ 31][2]={{ 2, 1},{ 0, 0},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 8}, + { 0, 4},{ 2, 1},{ 0, 1},{ 0, 2},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0, 12},{ 0, 10},{ 2, 1},{ 0, 3},{ 0, 6}, + { 6, 1},{ 2, 1},{ 0, 9},{ 2, 1},{ 0, 5},{ 0, 7}, + { 4, 1},{ 2, 1},{ 0, 14},{ 0, 13},{ 2, 1},{ 0, 15}, + { 0, 11}}, + +htd33[ 31][2]={{ 16, 1},{ 8, 1},{ 4, 1},{ 2, 1},{ 0, 0},{ 0, 1}, + { 2, 1},{ 0, 2},{ 0, 3},{ 4, 1},{ 2, 1},{ 0, 4}, + { 0, 5},{ 2, 1},{ 0, 6},{ 0, 7},{ 8, 1},{ 4, 1}, + { 2, 1},{ 0, 8},{ 0, 9},{ 2, 1},{ 0, 10},{ 0, 11}, + { 4, 1},{ 2, 1},{ 0, 12},{ 0, 13},{ 2, 1},{ 0, 14}, + { 0, 15}}; + +const HUFFMANCODETABLE Mpegtoraw::ht[HTN]= +{ + { 0, 0-1, 0-1, 0, 0, htd33}, + { 1, 2-1, 2-1, 0, 7,htd01}, + { 2, 3-1, 3-1, 0, 17,htd02}, + { 3, 3-1, 3-1, 0, 17,htd03}, + { 4, 0-1, 0-1, 0, 0, htd33}, + { 5, 4-1, 4-1, 0, 31,htd05}, + { 6, 4-1, 4-1, 0, 31,htd06}, + { 7, 6-1, 6-1, 0, 71,htd07}, + { 8, 6-1, 6-1, 0, 71,htd08}, + { 9, 6-1, 6-1, 0, 71,htd09}, + {10, 8-1, 8-1, 0,127,htd10}, + {11, 8-1, 8-1, 0,127,htd11}, + {12, 8-1, 8-1, 0,127,htd12}, + {13,16-1,16-1, 0,511,htd13}, + {14, 0-1, 0-1, 0, 0, htd33}, + {15,16-1,16-1, 0,511,htd15}, + {16,16-1,16-1, 1,511,htd16}, + {17,16-1,16-1, 2,511,htd16}, + {18,16-1,16-1, 3,511,htd16}, + {19,16-1,16-1, 4,511,htd16}, + {20,16-1,16-1, 6,511,htd16}, + {21,16-1,16-1, 8,511,htd16}, + {22,16-1,16-1,10,511,htd16}, + {23,16-1,16-1,13,511,htd16}, + {24,16-1,16-1, 4,512,htd24}, + {25,16-1,16-1, 5,512,htd24}, + {26,16-1,16-1, 6,512,htd24}, + {27,16-1,16-1, 7,512,htd24}, + {28,16-1,16-1, 8,512,htd24}, + {29,16-1,16-1, 9,512,htd24}, + {30,16-1,16-1,11,512,htd24}, + {31,16-1,16-1,13,512,htd24}, + {32, 1-1,16-1, 0, 31,htd32}, + {33, 1-1,16-1, 0, 31,htd33} +}; diff --git a/Libraries/DecMPA/Files/src/splay/mpeg2tables.h b/Libraries/DecMPA/Files/src/splay/mpeg2tables.h new file mode 100644 index 000000000..25fca9d99 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpeg2tables.h @@ -0,0 +1,441 @@ + + +//changes 8/4/2002 (by Hauke Duden): +// - added VC6 pragma to prevent some warnings from being reported + +#ifndef __MPEG2TABLES_H +#define __MPEG2TABLES_H + +#ifdef _MSC_VER +#pragma warning(disable : 4305) +#endif + + +#define MAXTABLE 3 + + +// Tables for layer 2. + +// bitalloclengthtable :0,1 supported 2. 2 ot tested & disabled +// this table merges the subbands to the longer one. +// 8 < 12 , 27 < 30 but the "length" is the same + +static const int bitalloclengthtable[MAXTABLE][MAXSUBBAND]= +{ {4,4,3,3,3,3,3,3,3,3,3,3,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3, 3,3,3,3,3,3,3,2,2,2,2,2,2,2,0,0}, + {4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0} }; + + +/* +Orignal is: +{ {4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3, 3,3,3,3,3,3,3,2,2,2,2,0,0,0,0,0}, + {4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3, 3,3,3,3,3,3,3,2,2,2,2,2,2,2,0,0}, + {4,4,3,3,3,3,3,3,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {4,4,3,3,3,3,3,3,3,3,3,3,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0} }; + +*/ + + + + + +static const REAL group5bits[27*3]= +{ + -2.0/3.0, -2.0/3.0, -2.0/3.0, + 0.0, -2.0/3.0, -2.0/3.0, + 2.0/3.0, -2.0/3.0, -2.0/3.0, + -2.0/3.0, 0.0, -2.0/3.0, + 0.0, 0.0, -2.0/3.0, + 2.0/3.0, 0.0, -2.0/3.0, + -2.0/3.0, 2.0/3.0, -2.0/3.0, + 0.0, 2.0/3.0, -2.0/3.0, + 2.0/3.0, 2.0/3.0, -2.0/3.0, + -2.0/3.0, -2.0/3.0, 0.0, + 0.0, -2.0/3.0, 0.0, + 2.0/3.0, -2.0/3.0, 0.0, + -2.0/3.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 2.0/3.0, 0.0, 0.0, + -2.0/3.0, 2.0/3.0, 0.0, + 0.0, 2.0/3.0, 0.0, + 2.0/3.0, 2.0/3.0, 0.0, + -2.0/3.0, -2.0/3.0, 2.0/3.0, + 0.0, -2.0/3.0, 2.0/3.0, + 2.0/3.0, -2.0/3.0, 2.0/3.0, + -2.0/3.0, 0.0, 2.0/3.0, + 0.0, 0.0, 2.0/3.0, + 2.0/3.0, 0.0, 2.0/3.0, + -2.0/3.0, 2.0/3.0, 2.0/3.0, + 0.0, 2.0/3.0, 2.0/3.0, + 2.0/3.0, 2.0/3.0, 2.0/3.0 +}; + +static const REAL group7bits[125*3]= +{ + -0.8,-0.8,-0.8, -0.4,-0.8,-0.8, 0.0,-0.8,-0.8, 0.4,-0.8,-0.8, 0.8,-0.8,-0.8, + -0.8,-0.4,-0.8, -0.4,-0.4,-0.8, 0.0,-0.4,-0.8, 0.4,-0.4,-0.8, 0.8,-0.4,-0.8, + -0.8, 0.0,-0.8, -0.4, 0.0,-0.8, 0.0, 0.0,-0.8, 0.4, 0.0,-0.8, 0.8, 0.0,-0.8, + -0.8, 0.4,-0.8, -0.4, 0.4,-0.8, 0.0, 0.4,-0.8, 0.4, 0.4,-0.8, 0.8, 0.4,-0.8, + -0.8, 0.8,-0.8, -0.4, 0.8,-0.8, 0.0, 0.8,-0.8, 0.4, 0.8,-0.8, 0.8, 0.8,-0.8, + -0.8,-0.8,-0.4, -0.4,-0.8,-0.4, 0.0,-0.8,-0.4, 0.4,-0.8,-0.4, 0.8,-0.8,-0.4, + -0.8,-0.4,-0.4, -0.4,-0.4,-0.4, 0.0,-0.4,-0.4, 0.4,-0.4,-0.4, 0.8,-0.4,-0.4, + -0.8, 0.0,-0.4, -0.4, 0.0,-0.4, 0.0, 0.0,-0.4, 0.4, 0.0,-0.4, 0.8, 0.0,-0.4, + -0.8, 0.4,-0.4, -0.4, 0.4,-0.4, 0.0, 0.4,-0.4, 0.4, 0.4,-0.4, 0.8, 0.4,-0.4, + -0.8, 0.8,-0.4, -0.4, 0.8,-0.4, 0.0, 0.8,-0.4, 0.4, 0.8,-0.4, 0.8, 0.8,-0.4, + -0.8,-0.8, 0.0, -0.4,-0.8, 0.0, 0.0,-0.8, 0.0, 0.4,-0.8, 0.0, 0.8,-0.8, 0.0, + -0.8,-0.4, 0.0, -0.4,-0.4, 0.0, 0.0,-0.4, 0.0, 0.4,-0.4, 0.0, 0.8,-0.4, 0.0, + -0.8, 0.0, 0.0, -0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4, 0.0, 0.0, 0.8, 0.0, 0.0, + -0.8, 0.4, 0.0, -0.4, 0.4, 0.0, 0.0, 0.4, 0.0, 0.4, 0.4, 0.0, 0.8, 0.4, 0.0, + -0.8, 0.8, 0.0, -0.4, 0.8, 0.0, 0.0, 0.8, 0.0, 0.4, 0.8, 0.0, 0.8, 0.8, 0.0, + -0.8,-0.8, 0.4, -0.4,-0.8, 0.4, 0.0,-0.8, 0.4, 0.4,-0.8, 0.4, 0.8,-0.8, 0.4, + -0.8,-0.4, 0.4, -0.4,-0.4, 0.4, 0.0,-0.4, 0.4, 0.4,-0.4, 0.4, 0.8,-0.4, 0.4, + -0.8, 0.0, 0.4, -0.4, 0.0, 0.4, 0.0, 0.0, 0.4, 0.4, 0.0, 0.4, 0.8, 0.0, 0.4, + -0.8, 0.4, 0.4, -0.4, 0.4, 0.4, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.8, 0.4, 0.4, + -0.8, 0.8, 0.4, -0.4, 0.8, 0.4, 0.0, 0.8, 0.4, 0.4, 0.8, 0.4, 0.8, 0.8, 0.4, + -0.8,-0.8, 0.8, -0.4,-0.8, 0.8, 0.0,-0.8, 0.8, 0.4,-0.8, 0.8, 0.8,-0.8, 0.8, + -0.8,-0.4, 0.8, -0.4,-0.4, 0.8, 0.0,-0.4, 0.8, 0.4,-0.4, 0.8, 0.8,-0.4, 0.8, + -0.8, 0.0, 0.8, -0.4, 0.0, 0.8, 0.0, 0.0, 0.8, 0.4, 0.0, 0.8, 0.8, 0.0, 0.8, + -0.8, 0.4, 0.8, -0.4, 0.4, 0.8, 0.0, 0.4, 0.8, 0.4, 0.4, 0.8, 0.8, 0.4, 0.8, + -0.8, 0.8, 0.8, -0.4, 0.8, 0.8, 0.0, 0.8, 0.8, 0.4, 0.8, 0.8, 0.8, 0.8, 0.8 +}; + +static const REAL group10bits[729*3]= +{ + -8.0/9.0,-8.0/9.0,-8.0/9.0, -6.0/9.0,-8.0/9.0,-8.0/9.0, -4.0/9.0,-8.0/9.0,-8.0/9.0, + -2.0/9.0,-8.0/9.0,-8.0/9.0, 0.0,-8.0/9.0,-8.0/9.0, 2.0/9.0,-8.0/9.0,-8.0/9.0, + 4.0/9.0,-8.0/9.0,-8.0/9.0, 6.0/9.0,-8.0/9.0,-8.0/9.0, 8.0/9.0,-8.0/9.0,-8.0/9.0, + -8.0/9.0,-6.0/9.0,-8.0/9.0, -6.0/9.0,-6.0/9.0,-8.0/9.0, -4.0/9.0,-6.0/9.0,-8.0/9.0, + -2.0/9.0,-6.0/9.0,-8.0/9.0, 0.0,-6.0/9.0,-8.0/9.0, 2.0/9.0,-6.0/9.0,-8.0/9.0, + 4.0/9.0,-6.0/9.0,-8.0/9.0, 6.0/9.0,-6.0/9.0,-8.0/9.0, 8.0/9.0,-6.0/9.0,-8.0/9.0, + -8.0/9.0,-4.0/9.0,-8.0/9.0, -6.0/9.0,-4.0/9.0,-8.0/9.0, -4.0/9.0,-4.0/9.0,-8.0/9.0, + -2.0/9.0,-4.0/9.0,-8.0/9.0, 0.0,-4.0/9.0,-8.0/9.0, 2.0/9.0,-4.0/9.0,-8.0/9.0, + 4.0/9.0,-4.0/9.0,-8.0/9.0, 6.0/9.0,-4.0/9.0,-8.0/9.0, 8.0/9.0,-4.0/9.0,-8.0/9.0, + -8.0/9.0,-2.0/9.0,-8.0/9.0, -6.0/9.0,-2.0/9.0,-8.0/9.0, -4.0/9.0,-2.0/9.0,-8.0/9.0, + -2.0/9.0,-2.0/9.0,-8.0/9.0, 0.0,-2.0/9.0,-8.0/9.0, 2.0/9.0,-2.0/9.0,-8.0/9.0, + 4.0/9.0,-2.0/9.0,-8.0/9.0, 6.0/9.0,-2.0/9.0,-8.0/9.0, 8.0/9.0,-2.0/9.0,-8.0/9.0, + -8.0/9.0, 0.0,-8.0/9.0, -6.0/9.0, 0.0,-8.0/9.0, -4.0/9.0, 0.0,-8.0/9.0, + -2.0/9.0, 0.0,-8.0/9.0, 0.0, 0.0,-8.0/9.0, 2.0/9.0, 0.0,-8.0/9.0, + 4.0/9.0, 0.0,-8.0/9.0, 6.0/9.0, 0.0,-8.0/9.0, 8.0/9.0, 0.0,-8.0/9.0, + -8.0/9.0, 2.0/9.0,-8.0/9.0, -6.0/9.0, 2.0/9.0,-8.0/9.0, -4.0/9.0, 2.0/9.0,-8.0/9.0, + -2.0/9.0, 2.0/9.0,-8.0/9.0, 0.0, 2.0/9.0,-8.0/9.0, 2.0/9.0, 2.0/9.0,-8.0/9.0, + 4.0/9.0, 2.0/9.0,-8.0/9.0, 6.0/9.0, 2.0/9.0,-8.0/9.0, 8.0/9.0, 2.0/9.0,-8.0/9.0, + -8.0/9.0, 4.0/9.0,-8.0/9.0, -6.0/9.0, 4.0/9.0,-8.0/9.0, -4.0/9.0, 4.0/9.0,-8.0/9.0, + -2.0/9.0, 4.0/9.0,-8.0/9.0, 0.0, 4.0/9.0,-8.0/9.0, 2.0/9.0, 4.0/9.0,-8.0/9.0, + 4.0/9.0, 4.0/9.0,-8.0/9.0, 6.0/9.0, 4.0/9.0,-8.0/9.0, 8.0/9.0, 4.0/9.0,-8.0/9.0, + -8.0/9.0, 6.0/9.0,-8.0/9.0, -6.0/9.0, 6.0/9.0,-8.0/9.0, -4.0/9.0, 6.0/9.0,-8.0/9.0, + -2.0/9.0, 6.0/9.0,-8.0/9.0, 0.0, 6.0/9.0,-8.0/9.0, 2.0/9.0, 6.0/9.0,-8.0/9.0, + 4.0/9.0, 6.0/9.0,-8.0/9.0, 6.0/9.0, 6.0/9.0,-8.0/9.0, 8.0/9.0, 6.0/9.0,-8.0/9.0, + -8.0/9.0, 8.0/9.0,-8.0/9.0, -6.0/9.0, 8.0/9.0,-8.0/9.0, -4.0/9.0, 8.0/9.0,-8.0/9.0, + -2.0/9.0, 8.0/9.0,-8.0/9.0, 0.0, 8.0/9.0,-8.0/9.0, 2.0/9.0, 8.0/9.0,-8.0/9.0, + 4.0/9.0, 8.0/9.0,-8.0/9.0, 6.0/9.0, 8.0/9.0,-8.0/9.0, 8.0/9.0, 8.0/9.0,-8.0/9.0, + -8.0/9.0,-8.0/9.0,-6.0/9.0, -6.0/9.0,-8.0/9.0,-6.0/9.0, -4.0/9.0,-8.0/9.0,-6.0/9.0, + -2.0/9.0,-8.0/9.0,-6.0/9.0, 0.0,-8.0/9.0,-6.0/9.0, 2.0/9.0,-8.0/9.0,-6.0/9.0, + 4.0/9.0,-8.0/9.0,-6.0/9.0, 6.0/9.0,-8.0/9.0,-6.0/9.0, 8.0/9.0,-8.0/9.0,-6.0/9.0, + -8.0/9.0,-6.0/9.0,-6.0/9.0, -6.0/9.0,-6.0/9.0,-6.0/9.0, -4.0/9.0,-6.0/9.0,-6.0/9.0, + -2.0/9.0,-6.0/9.0,-6.0/9.0, 0.0,-6.0/9.0,-6.0/9.0, 2.0/9.0,-6.0/9.0,-6.0/9.0, + 4.0/9.0,-6.0/9.0,-6.0/9.0, 6.0/9.0,-6.0/9.0,-6.0/9.0, 8.0/9.0,-6.0/9.0,-6.0/9.0, + -8.0/9.0,-4.0/9.0,-6.0/9.0, -6.0/9.0,-4.0/9.0,-6.0/9.0, -4.0/9.0,-4.0/9.0,-6.0/9.0, + -2.0/9.0,-4.0/9.0,-6.0/9.0, 0.0,-4.0/9.0,-6.0/9.0, 2.0/9.0,-4.0/9.0,-6.0/9.0, + 4.0/9.0,-4.0/9.0,-6.0/9.0, 6.0/9.0,-4.0/9.0,-6.0/9.0, 8.0/9.0,-4.0/9.0,-6.0/9.0, + -8.0/9.0,-2.0/9.0,-6.0/9.0, -6.0/9.0,-2.0/9.0,-6.0/9.0, -4.0/9.0,-2.0/9.0,-6.0/9.0, + -2.0/9.0,-2.0/9.0,-6.0/9.0, 0.0,-2.0/9.0,-6.0/9.0, 2.0/9.0,-2.0/9.0,-6.0/9.0, + 4.0/9.0,-2.0/9.0,-6.0/9.0, 6.0/9.0,-2.0/9.0,-6.0/9.0, 8.0/9.0,-2.0/9.0,-6.0/9.0, + -8.0/9.0, 0.0,-6.0/9.0, -6.0/9.0, 0.0,-6.0/9.0, -4.0/9.0, 0.0,-6.0/9.0, + -2.0/9.0, 0.0,-6.0/9.0, 0.0, 0.0,-6.0/9.0, 2.0/9.0, 0.0,-6.0/9.0, + 4.0/9.0, 0.0,-6.0/9.0, 6.0/9.0, 0.0,-6.0/9.0, 8.0/9.0, 0.0,-6.0/9.0, + -8.0/9.0, 2.0/9.0,-6.0/9.0, -6.0/9.0, 2.0/9.0,-6.0/9.0, -4.0/9.0, 2.0/9.0,-6.0/9.0, + -2.0/9.0, 2.0/9.0,-6.0/9.0, 0.0, 2.0/9.0,-6.0/9.0, 2.0/9.0, 2.0/9.0,-6.0/9.0, + 4.0/9.0, 2.0/9.0,-6.0/9.0, 6.0/9.0, 2.0/9.0,-6.0/9.0, 8.0/9.0, 2.0/9.0,-6.0/9.0, + -8.0/9.0, 4.0/9.0,-6.0/9.0, -6.0/9.0, 4.0/9.0,-6.0/9.0, -4.0/9.0, 4.0/9.0,-6.0/9.0, + -2.0/9.0, 4.0/9.0,-6.0/9.0, 0.0, 4.0/9.0,-6.0/9.0, 2.0/9.0, 4.0/9.0,-6.0/9.0, + 4.0/9.0, 4.0/9.0,-6.0/9.0, 6.0/9.0, 4.0/9.0,-6.0/9.0, 8.0/9.0, 4.0/9.0,-6.0/9.0, + -8.0/9.0, 6.0/9.0,-6.0/9.0, -6.0/9.0, 6.0/9.0,-6.0/9.0, -4.0/9.0, 6.0/9.0,-6.0/9.0, + -2.0/9.0, 6.0/9.0,-6.0/9.0, 0.0, 6.0/9.0,-6.0/9.0, 2.0/9.0, 6.0/9.0,-6.0/9.0, + 4.0/9.0, 6.0/9.0,-6.0/9.0, 6.0/9.0, 6.0/9.0,-6.0/9.0, 8.0/9.0, 6.0/9.0,-6.0/9.0, + -8.0/9.0, 8.0/9.0,-6.0/9.0, -6.0/9.0, 8.0/9.0,-6.0/9.0, -4.0/9.0, 8.0/9.0,-6.0/9.0, + -2.0/9.0, 8.0/9.0,-6.0/9.0, 0.0, 8.0/9.0,-6.0/9.0, 2.0/9.0, 8.0/9.0,-6.0/9.0, + 4.0/9.0, 8.0/9.0,-6.0/9.0, 6.0/9.0, 8.0/9.0,-6.0/9.0, 8.0/9.0, 8.0/9.0,-6.0/9.0, + -8.0/9.0,-8.0/9.0,-4.0/9.0, -6.0/9.0,-8.0/9.0,-4.0/9.0, -4.0/9.0,-8.0/9.0,-4.0/9.0, + -2.0/9.0,-8.0/9.0,-4.0/9.0, 0.0,-8.0/9.0,-4.0/9.0, 2.0/9.0,-8.0/9.0,-4.0/9.0, + 4.0/9.0,-8.0/9.0,-4.0/9.0, 6.0/9.0,-8.0/9.0,-4.0/9.0, 8.0/9.0,-8.0/9.0,-4.0/9.0, + -8.0/9.0,-6.0/9.0,-4.0/9.0, -6.0/9.0,-6.0/9.0,-4.0/9.0, -4.0/9.0,-6.0/9.0,-4.0/9.0, + -2.0/9.0,-6.0/9.0,-4.0/9.0, 0.0,-6.0/9.0,-4.0/9.0, 2.0/9.0,-6.0/9.0,-4.0/9.0, + 4.0/9.0,-6.0/9.0,-4.0/9.0, 6.0/9.0,-6.0/9.0,-4.0/9.0, 8.0/9.0,-6.0/9.0,-4.0/9.0, + -8.0/9.0,-4.0/9.0,-4.0/9.0, -6.0/9.0,-4.0/9.0,-4.0/9.0, -4.0/9.0,-4.0/9.0,-4.0/9.0, + -2.0/9.0,-4.0/9.0,-4.0/9.0, 0.0,-4.0/9.0,-4.0/9.0, 2.0/9.0,-4.0/9.0,-4.0/9.0, + 4.0/9.0,-4.0/9.0,-4.0/9.0, 6.0/9.0,-4.0/9.0,-4.0/9.0, 8.0/9.0,-4.0/9.0,-4.0/9.0, + -8.0/9.0,-2.0/9.0,-4.0/9.0, -6.0/9.0,-2.0/9.0,-4.0/9.0, -4.0/9.0,-2.0/9.0,-4.0/9.0, + -2.0/9.0,-2.0/9.0,-4.0/9.0, 0.0,-2.0/9.0,-4.0/9.0, 2.0/9.0,-2.0/9.0,-4.0/9.0, + 4.0/9.0,-2.0/9.0,-4.0/9.0, 6.0/9.0,-2.0/9.0,-4.0/9.0, 8.0/9.0,-2.0/9.0,-4.0/9.0, + -8.0/9.0, 0.0,-4.0/9.0, -6.0/9.0, 0.0,-4.0/9.0, -4.0/9.0, 0.0,-4.0/9.0, + -2.0/9.0, 0.0,-4.0/9.0, 0.0, 0.0,-4.0/9.0, 2.0/9.0, 0.0,-4.0/9.0, + 4.0/9.0, 0.0,-4.0/9.0, 6.0/9.0, 0.0,-4.0/9.0, 8.0/9.0, 0.0,-4.0/9.0, + -8.0/9.0, 2.0/9.0,-4.0/9.0, -6.0/9.0, 2.0/9.0,-4.0/9.0, -4.0/9.0, 2.0/9.0,-4.0/9.0, + -2.0/9.0, 2.0/9.0,-4.0/9.0, 0.0, 2.0/9.0,-4.0/9.0, 2.0/9.0, 2.0/9.0,-4.0/9.0, + 4.0/9.0, 2.0/9.0,-4.0/9.0, 6.0/9.0, 2.0/9.0,-4.0/9.0, 8.0/9.0, 2.0/9.0,-4.0/9.0, + -8.0/9.0, 4.0/9.0,-4.0/9.0, -6.0/9.0, 4.0/9.0,-4.0/9.0, -4.0/9.0, 4.0/9.0,-4.0/9.0, + -2.0/9.0, 4.0/9.0,-4.0/9.0, 0.0, 4.0/9.0,-4.0/9.0, 2.0/9.0, 4.0/9.0,-4.0/9.0, + 4.0/9.0, 4.0/9.0,-4.0/9.0, 6.0/9.0, 4.0/9.0,-4.0/9.0, 8.0/9.0, 4.0/9.0,-4.0/9.0, + -8.0/9.0, 6.0/9.0,-4.0/9.0, -6.0/9.0, 6.0/9.0,-4.0/9.0, -4.0/9.0, 6.0/9.0,-4.0/9.0, + -2.0/9.0, 6.0/9.0,-4.0/9.0, 0.0, 6.0/9.0,-4.0/9.0, 2.0/9.0, 6.0/9.0,-4.0/9.0, + 4.0/9.0, 6.0/9.0,-4.0/9.0, 6.0/9.0, 6.0/9.0,-4.0/9.0, 8.0/9.0, 6.0/9.0,-4.0/9.0, + -8.0/9.0, 8.0/9.0,-4.0/9.0, -6.0/9.0, 8.0/9.0,-4.0/9.0, -4.0/9.0, 8.0/9.0,-4.0/9.0, + -2.0/9.0, 8.0/9.0,-4.0/9.0, 0.0, 8.0/9.0,-4.0/9.0, 2.0/9.0, 8.0/9.0,-4.0/9.0, + 4.0/9.0, 8.0/9.0,-4.0/9.0, 6.0/9.0, 8.0/9.0,-4.0/9.0, 8.0/9.0, 8.0/9.0,-4.0/9.0, + -8.0/9.0,-8.0/9.0,-2.0/9.0, -6.0/9.0,-8.0/9.0,-2.0/9.0, -4.0/9.0,-8.0/9.0,-2.0/9.0, + -2.0/9.0,-8.0/9.0,-2.0/9.0, 0.0,-8.0/9.0,-2.0/9.0, 2.0/9.0,-8.0/9.0,-2.0/9.0, + 4.0/9.0,-8.0/9.0,-2.0/9.0, 6.0/9.0,-8.0/9.0,-2.0/9.0, 8.0/9.0,-8.0/9.0,-2.0/9.0, + -8.0/9.0,-6.0/9.0,-2.0/9.0, -6.0/9.0,-6.0/9.0,-2.0/9.0, -4.0/9.0,-6.0/9.0,-2.0/9.0, + -2.0/9.0,-6.0/9.0,-2.0/9.0, 0.0,-6.0/9.0,-2.0/9.0, 2.0/9.0,-6.0/9.0,-2.0/9.0, + 4.0/9.0,-6.0/9.0,-2.0/9.0, 6.0/9.0,-6.0/9.0,-2.0/9.0, 8.0/9.0,-6.0/9.0,-2.0/9.0, + -8.0/9.0,-4.0/9.0,-2.0/9.0, -6.0/9.0,-4.0/9.0,-2.0/9.0, -4.0/9.0,-4.0/9.0,-2.0/9.0, + -2.0/9.0,-4.0/9.0,-2.0/9.0, 0.0,-4.0/9.0,-2.0/9.0, 2.0/9.0,-4.0/9.0,-2.0/9.0, + 4.0/9.0,-4.0/9.0,-2.0/9.0, 6.0/9.0,-4.0/9.0,-2.0/9.0, 8.0/9.0,-4.0/9.0,-2.0/9.0, + -8.0/9.0,-2.0/9.0,-2.0/9.0, -6.0/9.0,-2.0/9.0,-2.0/9.0, -4.0/9.0,-2.0/9.0,-2.0/9.0, + -2.0/9.0,-2.0/9.0,-2.0/9.0, 0.0,-2.0/9.0,-2.0/9.0, 2.0/9.0,-2.0/9.0,-2.0/9.0, + 4.0/9.0,-2.0/9.0,-2.0/9.0, 6.0/9.0,-2.0/9.0,-2.0/9.0, 8.0/9.0,-2.0/9.0,-2.0/9.0, + -8.0/9.0, 0.0,-2.0/9.0, -6.0/9.0, 0.0,-2.0/9.0, -4.0/9.0, 0.0,-2.0/9.0, + -2.0/9.0, 0.0,-2.0/9.0, 0.0, 0.0,-2.0/9.0, 2.0/9.0, 0.0,-2.0/9.0, + 4.0/9.0, 0.0,-2.0/9.0, 6.0/9.0, 0.0,-2.0/9.0, 8.0/9.0, 0.0,-2.0/9.0, + -8.0/9.0, 2.0/9.0,-2.0/9.0, -6.0/9.0, 2.0/9.0,-2.0/9.0, -4.0/9.0, 2.0/9.0,-2.0/9.0, + -2.0/9.0, 2.0/9.0,-2.0/9.0, 0.0, 2.0/9.0,-2.0/9.0, 2.0/9.0, 2.0/9.0,-2.0/9.0, + 4.0/9.0, 2.0/9.0,-2.0/9.0, 6.0/9.0, 2.0/9.0,-2.0/9.0, 8.0/9.0, 2.0/9.0,-2.0/9.0, + -8.0/9.0, 4.0/9.0,-2.0/9.0, -6.0/9.0, 4.0/9.0,-2.0/9.0, -4.0/9.0, 4.0/9.0,-2.0/9.0, + -2.0/9.0, 4.0/9.0,-2.0/9.0, 0.0, 4.0/9.0,-2.0/9.0, 2.0/9.0, 4.0/9.0,-2.0/9.0, + 4.0/9.0, 4.0/9.0,-2.0/9.0, 6.0/9.0, 4.0/9.0,-2.0/9.0, 8.0/9.0, 4.0/9.0,-2.0/9.0, + -8.0/9.0, 6.0/9.0,-2.0/9.0, -6.0/9.0, 6.0/9.0,-2.0/9.0, -4.0/9.0, 6.0/9.0,-2.0/9.0, + -2.0/9.0, 6.0/9.0,-2.0/9.0, 0.0, 6.0/9.0,-2.0/9.0, 2.0/9.0, 6.0/9.0,-2.0/9.0, + 4.0/9.0, 6.0/9.0,-2.0/9.0, 6.0/9.0, 6.0/9.0,-2.0/9.0, 8.0/9.0, 6.0/9.0,-2.0/9.0, + -8.0/9.0, 8.0/9.0,-2.0/9.0, -6.0/9.0, 8.0/9.0,-2.0/9.0, -4.0/9.0, 8.0/9.0,-2.0/9.0, + -2.0/9.0, 8.0/9.0,-2.0/9.0, 0.0, 8.0/9.0,-2.0/9.0, 2.0/9.0, 8.0/9.0,-2.0/9.0, + 4.0/9.0, 8.0/9.0,-2.0/9.0, 6.0/9.0, 8.0/9.0,-2.0/9.0, 8.0/9.0, 8.0/9.0,-2.0/9.0, + -8.0/9.0,-8.0/9.0, 0.0, -6.0/9.0,-8.0/9.0, 0.0, -4.0/9.0,-8.0/9.0, 0.0, + -2.0/9.0,-8.0/9.0, 0.0, 0.0,-8.0/9.0, 0.0, 2.0/9.0,-8.0/9.0, 0.0, + 4.0/9.0,-8.0/9.0, 0.0, 6.0/9.0,-8.0/9.0, 0.0, 8.0/9.0,-8.0/9.0, 0.0, + -8.0/9.0,-6.0/9.0, 0.0, -6.0/9.0,-6.0/9.0, 0.0, -4.0/9.0,-6.0/9.0, 0.0, + -2.0/9.0,-6.0/9.0, 0.0, 0.0,-6.0/9.0, 0.0, 2.0/9.0,-6.0/9.0, 0.0, + 4.0/9.0,-6.0/9.0, 0.0, 6.0/9.0,-6.0/9.0, 0.0, 8.0/9.0,-6.0/9.0, 0.0, + -8.0/9.0,-4.0/9.0, 0.0, -6.0/9.0,-4.0/9.0, 0.0, -4.0/9.0,-4.0/9.0, 0.0, + -2.0/9.0,-4.0/9.0, 0.0, 0.0,-4.0/9.0, 0.0, 2.0/9.0,-4.0/9.0, 0.0, + 4.0/9.0,-4.0/9.0, 0.0, 6.0/9.0,-4.0/9.0, 0.0, 8.0/9.0,-4.0/9.0, 0.0, + -8.0/9.0,-2.0/9.0, 0.0, -6.0/9.0,-2.0/9.0, 0.0, -4.0/9.0,-2.0/9.0, 0.0, + -2.0/9.0,-2.0/9.0, 0.0, 0.0,-2.0/9.0, 0.0, 2.0/9.0,-2.0/9.0, 0.0, + 4.0/9.0,-2.0/9.0, 0.0, 6.0/9.0,-2.0/9.0, 0.0, 8.0/9.0,-2.0/9.0, 0.0, + -8.0/9.0, 0.0, 0.0, -6.0/9.0, 0.0, 0.0, -4.0/9.0, 0.0, 0.0, + -2.0/9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0/9.0, 0.0, 0.0, + 4.0/9.0, 0.0, 0.0, 6.0/9.0, 0.0, 0.0, 8.0/9.0, 0.0, 0.0, + -8.0/9.0, 2.0/9.0, 0.0, -6.0/9.0, 2.0/9.0, 0.0, -4.0/9.0, 2.0/9.0, 0.0, + -2.0/9.0, 2.0/9.0, 0.0, 0.0, 2.0/9.0, 0.0, 2.0/9.0, 2.0/9.0, 0.0, + 4.0/9.0, 2.0/9.0, 0.0, 6.0/9.0, 2.0/9.0, 0.0, 8.0/9.0, 2.0/9.0, 0.0, + -8.0/9.0, 4.0/9.0, 0.0, -6.0/9.0, 4.0/9.0, 0.0, -4.0/9.0, 4.0/9.0, 0.0, + -2.0/9.0, 4.0/9.0, 0.0, 0.0, 4.0/9.0, 0.0, 2.0/9.0, 4.0/9.0, 0.0, + 4.0/9.0, 4.0/9.0, 0.0, 6.0/9.0, 4.0/9.0, 0.0, 8.0/9.0, 4.0/9.0, 0.0, + -8.0/9.0, 6.0/9.0, 0.0, -6.0/9.0, 6.0/9.0, 0.0, -4.0/9.0, 6.0/9.0, 0.0, + -2.0/9.0, 6.0/9.0, 0.0, 0.0, 6.0/9.0, 0.0, 2.0/9.0, 6.0/9.0, 0.0, + 4.0/9.0, 6.0/9.0, 0.0, 6.0/9.0, 6.0/9.0, 0.0, 8.0/9.0, 6.0/9.0, 0.0, + -8.0/9.0, 8.0/9.0, 0.0, -6.0/9.0, 8.0/9.0, 0.0, -4.0/9.0, 8.0/9.0, 0.0, + -2.0/9.0, 8.0/9.0, 0.0, 0.0, 8.0/9.0, 0.0, 2.0/9.0, 8.0/9.0, 0.0, + 4.0/9.0, 8.0/9.0, 0.0, 6.0/9.0, 8.0/9.0, 0.0, 8.0/9.0, 8.0/9.0, 0.0, + -8.0/9.0,-8.0/9.0, 2.0/9.0, -6.0/9.0,-8.0/9.0, 2.0/9.0, -4.0/9.0,-8.0/9.0, 2.0/9.0, + -2.0/9.0,-8.0/9.0, 2.0/9.0, 0.0,-8.0/9.0, 2.0/9.0, 2.0/9.0,-8.0/9.0, 2.0/9.0, + 4.0/9.0,-8.0/9.0, 2.0/9.0, 6.0/9.0,-8.0/9.0, 2.0/9.0, 8.0/9.0,-8.0/9.0, 2.0/9.0, + -8.0/9.0,-6.0/9.0, 2.0/9.0, -6.0/9.0,-6.0/9.0, 2.0/9.0, -4.0/9.0,-6.0/9.0, 2.0/9.0, + -2.0/9.0,-6.0/9.0, 2.0/9.0, 0.0,-6.0/9.0, 2.0/9.0, 2.0/9.0,-6.0/9.0, 2.0/9.0, + 4.0/9.0,-6.0/9.0, 2.0/9.0, 6.0/9.0,-6.0/9.0, 2.0/9.0, 8.0/9.0,-6.0/9.0, 2.0/9.0, + -8.0/9.0,-4.0/9.0, 2.0/9.0, -6.0/9.0,-4.0/9.0, 2.0/9.0, -4.0/9.0,-4.0/9.0, 2.0/9.0, + -2.0/9.0,-4.0/9.0, 2.0/9.0, 0.0,-4.0/9.0, 2.0/9.0, 2.0/9.0,-4.0/9.0, 2.0/9.0, + 4.0/9.0,-4.0/9.0, 2.0/9.0, 6.0/9.0,-4.0/9.0, 2.0/9.0, 8.0/9.0,-4.0/9.0, 2.0/9.0, + -8.0/9.0,-2.0/9.0, 2.0/9.0, -6.0/9.0,-2.0/9.0, 2.0/9.0, -4.0/9.0,-2.0/9.0, 2.0/9.0, + -2.0/9.0,-2.0/9.0, 2.0/9.0, 0.0,-2.0/9.0, 2.0/9.0, 2.0/9.0,-2.0/9.0, 2.0/9.0, + 4.0/9.0,-2.0/9.0, 2.0/9.0, 6.0/9.0,-2.0/9.0, 2.0/9.0, 8.0/9.0,-2.0/9.0, 2.0/9.0, + -8.0/9.0, 0.0, 2.0/9.0, -6.0/9.0, 0.0, 2.0/9.0, -4.0/9.0, 0.0, 2.0/9.0, + -2.0/9.0, 0.0, 2.0/9.0, 0.0, 0.0, 2.0/9.0, 2.0/9.0, 0.0, 2.0/9.0, + 4.0/9.0, 0.0, 2.0/9.0, 6.0/9.0, 0.0, 2.0/9.0, 8.0/9.0, 0.0, 2.0/9.0, + -8.0/9.0, 2.0/9.0, 2.0/9.0, -6.0/9.0, 2.0/9.0, 2.0/9.0, -4.0/9.0, 2.0/9.0, 2.0/9.0, + -2.0/9.0, 2.0/9.0, 2.0/9.0, 0.0, 2.0/9.0, 2.0/9.0, 2.0/9.0, 2.0/9.0, 2.0/9.0, + 4.0/9.0, 2.0/9.0, 2.0/9.0, 6.0/9.0, 2.0/9.0, 2.0/9.0, 8.0/9.0, 2.0/9.0, 2.0/9.0, + -8.0/9.0, 4.0/9.0, 2.0/9.0, -6.0/9.0, 4.0/9.0, 2.0/9.0, -4.0/9.0, 4.0/9.0, 2.0/9.0, + -2.0/9.0, 4.0/9.0, 2.0/9.0, 0.0, 4.0/9.0, 2.0/9.0, 2.0/9.0, 4.0/9.0, 2.0/9.0, + 4.0/9.0, 4.0/9.0, 2.0/9.0, 6.0/9.0, 4.0/9.0, 2.0/9.0, 8.0/9.0, 4.0/9.0, 2.0/9.0, + -8.0/9.0, 6.0/9.0, 2.0/9.0, -6.0/9.0, 6.0/9.0, 2.0/9.0, -4.0/9.0, 6.0/9.0, 2.0/9.0, + -2.0/9.0, 6.0/9.0, 2.0/9.0, 0.0, 6.0/9.0, 2.0/9.0, 2.0/9.0, 6.0/9.0, 2.0/9.0, + 4.0/9.0, 6.0/9.0, 2.0/9.0, 6.0/9.0, 6.0/9.0, 2.0/9.0, 8.0/9.0, 6.0/9.0, 2.0/9.0, + -8.0/9.0, 8.0/9.0, 2.0/9.0, -6.0/9.0, 8.0/9.0, 2.0/9.0, -4.0/9.0, 8.0/9.0, 2.0/9.0, + -2.0/9.0, 8.0/9.0, 2.0/9.0, 0.0, 8.0/9.0, 2.0/9.0, 2.0/9.0, 8.0/9.0, 2.0/9.0, + 4.0/9.0, 8.0/9.0, 2.0/9.0, 6.0/9.0, 8.0/9.0, 2.0/9.0, 8.0/9.0, 8.0/9.0, 2.0/9.0, + -8.0/9.0,-8.0/9.0, 4.0/9.0, -6.0/9.0,-8.0/9.0, 4.0/9.0, -4.0/9.0,-8.0/9.0, 4.0/9.0, + -2.0/9.0,-8.0/9.0, 4.0/9.0, 0.0,-8.0/9.0, 4.0/9.0, 2.0/9.0,-8.0/9.0, 4.0/9.0, + 4.0/9.0,-8.0/9.0, 4.0/9.0, 6.0/9.0,-8.0/9.0, 4.0/9.0, 8.0/9.0,-8.0/9.0, 4.0/9.0, + -8.0/9.0,-6.0/9.0, 4.0/9.0, -6.0/9.0,-6.0/9.0, 4.0/9.0, -4.0/9.0,-6.0/9.0, 4.0/9.0, + -2.0/9.0,-6.0/9.0, 4.0/9.0, 0.0,-6.0/9.0, 4.0/9.0, 2.0/9.0,-6.0/9.0, 4.0/9.0, + 4.0/9.0,-6.0/9.0, 4.0/9.0, 6.0/9.0,-6.0/9.0, 4.0/9.0, 8.0/9.0,-6.0/9.0, 4.0/9.0, + -8.0/9.0,-4.0/9.0, 4.0/9.0, -6.0/9.0,-4.0/9.0, 4.0/9.0, -4.0/9.0,-4.0/9.0, 4.0/9.0, + -2.0/9.0,-4.0/9.0, 4.0/9.0, 0.0,-4.0/9.0, 4.0/9.0, 2.0/9.0,-4.0/9.0, 4.0/9.0, + 4.0/9.0,-4.0/9.0, 4.0/9.0, 6.0/9.0,-4.0/9.0, 4.0/9.0, 8.0/9.0,-4.0/9.0, 4.0/9.0, + -8.0/9.0,-2.0/9.0, 4.0/9.0, -6.0/9.0,-2.0/9.0, 4.0/9.0, -4.0/9.0,-2.0/9.0, 4.0/9.0, + -2.0/9.0,-2.0/9.0, 4.0/9.0, 0.0,-2.0/9.0, 4.0/9.0, 2.0/9.0,-2.0/9.0, 4.0/9.0, + 4.0/9.0,-2.0/9.0, 4.0/9.0, 6.0/9.0,-2.0/9.0, 4.0/9.0, 8.0/9.0,-2.0/9.0, 4.0/9.0, + -8.0/9.0, 0.0, 4.0/9.0, -6.0/9.0, 0.0, 4.0/9.0, -4.0/9.0, 0.0, 4.0/9.0, + -2.0/9.0, 0.0, 4.0/9.0, 0.0, 0.0, 4.0/9.0, 2.0/9.0, 0.0, 4.0/9.0, + 4.0/9.0, 0.0, 4.0/9.0, 6.0/9.0, 0.0, 4.0/9.0, 8.0/9.0, 0.0, 4.0/9.0, + -8.0/9.0, 2.0/9.0, 4.0/9.0, -6.0/9.0, 2.0/9.0, 4.0/9.0, -4.0/9.0, 2.0/9.0, 4.0/9.0, + -2.0/9.0, 2.0/9.0, 4.0/9.0, 0.0, 2.0/9.0, 4.0/9.0, 2.0/9.0, 2.0/9.0, 4.0/9.0, + 4.0/9.0, 2.0/9.0, 4.0/9.0, 6.0/9.0, 2.0/9.0, 4.0/9.0, 8.0/9.0, 2.0/9.0, 4.0/9.0, + -8.0/9.0, 4.0/9.0, 4.0/9.0, -6.0/9.0, 4.0/9.0, 4.0/9.0, -4.0/9.0, 4.0/9.0, 4.0/9.0, + -2.0/9.0, 4.0/9.0, 4.0/9.0, 0.0, 4.0/9.0, 4.0/9.0, 2.0/9.0, 4.0/9.0, 4.0/9.0, + 4.0/9.0, 4.0/9.0, 4.0/9.0, 6.0/9.0, 4.0/9.0, 4.0/9.0, 8.0/9.0, 4.0/9.0, 4.0/9.0, + -8.0/9.0, 6.0/9.0, 4.0/9.0, -6.0/9.0, 6.0/9.0, 4.0/9.0, -4.0/9.0, 6.0/9.0, 4.0/9.0, + -2.0/9.0, 6.0/9.0, 4.0/9.0, 0.0, 6.0/9.0, 4.0/9.0, 2.0/9.0, 6.0/9.0, 4.0/9.0, + 4.0/9.0, 6.0/9.0, 4.0/9.0, 6.0/9.0, 6.0/9.0, 4.0/9.0, 8.0/9.0, 6.0/9.0, 4.0/9.0, + -8.0/9.0, 8.0/9.0, 4.0/9.0, -6.0/9.0, 8.0/9.0, 4.0/9.0, -4.0/9.0, 8.0/9.0, 4.0/9.0, + -2.0/9.0, 8.0/9.0, 4.0/9.0, 0.0, 8.0/9.0, 4.0/9.0, 2.0/9.0, 8.0/9.0, 4.0/9.0, + 4.0/9.0, 8.0/9.0, 4.0/9.0, 6.0/9.0, 8.0/9.0, 4.0/9.0, 8.0/9.0, 8.0/9.0, 4.0/9.0, + -8.0/9.0,-8.0/9.0, 6.0/9.0, -6.0/9.0,-8.0/9.0, 6.0/9.0, -4.0/9.0,-8.0/9.0, 6.0/9.0, + -2.0/9.0,-8.0/9.0, 6.0/9.0, 0.0,-8.0/9.0, 6.0/9.0, 2.0/9.0,-8.0/9.0, 6.0/9.0, + 4.0/9.0,-8.0/9.0, 6.0/9.0, 6.0/9.0,-8.0/9.0, 6.0/9.0, 8.0/9.0,-8.0/9.0, 6.0/9.0, + -8.0/9.0,-6.0/9.0, 6.0/9.0, -6.0/9.0,-6.0/9.0, 6.0/9.0, -4.0/9.0,-6.0/9.0, 6.0/9.0, + -2.0/9.0,-6.0/9.0, 6.0/9.0, 0.0,-6.0/9.0, 6.0/9.0, 2.0/9.0,-6.0/9.0, 6.0/9.0, + 4.0/9.0,-6.0/9.0, 6.0/9.0, 6.0/9.0,-6.0/9.0, 6.0/9.0, 8.0/9.0,-6.0/9.0, 6.0/9.0, + -8.0/9.0,-4.0/9.0, 6.0/9.0, -6.0/9.0,-4.0/9.0, 6.0/9.0, -4.0/9.0,-4.0/9.0, 6.0/9.0, + -2.0/9.0,-4.0/9.0, 6.0/9.0, 0.0,-4.0/9.0, 6.0/9.0, 2.0/9.0,-4.0/9.0, 6.0/9.0, + 4.0/9.0,-4.0/9.0, 6.0/9.0, 6.0/9.0,-4.0/9.0, 6.0/9.0, 8.0/9.0,-4.0/9.0, 6.0/9.0, + -8.0/9.0,-2.0/9.0, 6.0/9.0, -6.0/9.0,-2.0/9.0, 6.0/9.0, -4.0/9.0,-2.0/9.0, 6.0/9.0, + -2.0/9.0,-2.0/9.0, 6.0/9.0, 0.0,-2.0/9.0, 6.0/9.0, 2.0/9.0,-2.0/9.0, 6.0/9.0, + 4.0/9.0,-2.0/9.0, 6.0/9.0, 6.0/9.0,-2.0/9.0, 6.0/9.0, 8.0/9.0,-2.0/9.0, 6.0/9.0, + -8.0/9.0, 0.0, 6.0/9.0, -6.0/9.0, 0.0, 6.0/9.0, -4.0/9.0, 0.0, 6.0/9.0, + -2.0/9.0, 0.0, 6.0/9.0, 0.0, 0.0, 6.0/9.0, 2.0/9.0, 0.0, 6.0/9.0, + 4.0/9.0, 0.0, 6.0/9.0, 6.0/9.0, 0.0, 6.0/9.0, 8.0/9.0, 0.0, 6.0/9.0, + -8.0/9.0, 2.0/9.0, 6.0/9.0, -6.0/9.0, 2.0/9.0, 6.0/9.0, -4.0/9.0, 2.0/9.0, 6.0/9.0, + -2.0/9.0, 2.0/9.0, 6.0/9.0, 0.0, 2.0/9.0, 6.0/9.0, 2.0/9.0, 2.0/9.0, 6.0/9.0, + 4.0/9.0, 2.0/9.0, 6.0/9.0, 6.0/9.0, 2.0/9.0, 6.0/9.0, 8.0/9.0, 2.0/9.0, 6.0/9.0, + -8.0/9.0, 4.0/9.0, 6.0/9.0, -6.0/9.0, 4.0/9.0, 6.0/9.0, -4.0/9.0, 4.0/9.0, 6.0/9.0, + -2.0/9.0, 4.0/9.0, 6.0/9.0, 0.0, 4.0/9.0, 6.0/9.0, 2.0/9.0, 4.0/9.0, 6.0/9.0, + 4.0/9.0, 4.0/9.0, 6.0/9.0, 6.0/9.0, 4.0/9.0, 6.0/9.0, 8.0/9.0, 4.0/9.0, 6.0/9.0, + -8.0/9.0, 6.0/9.0, 6.0/9.0, -6.0/9.0, 6.0/9.0, 6.0/9.0, -4.0/9.0, 6.0/9.0, 6.0/9.0, + -2.0/9.0, 6.0/9.0, 6.0/9.0, 0.0, 6.0/9.0, 6.0/9.0, 2.0/9.0, 6.0/9.0, 6.0/9.0, + 4.0/9.0, 6.0/9.0, 6.0/9.0, 6.0/9.0, 6.0/9.0, 6.0/9.0, 8.0/9.0, 6.0/9.0, 6.0/9.0, + -8.0/9.0, 8.0/9.0, 6.0/9.0, -6.0/9.0, 8.0/9.0, 6.0/9.0, -4.0/9.0, 8.0/9.0, 6.0/9.0, + -2.0/9.0, 8.0/9.0, 6.0/9.0, 0.0, 8.0/9.0, 6.0/9.0, 2.0/9.0, 8.0/9.0, 6.0/9.0, + 4.0/9.0, 8.0/9.0, 6.0/9.0, 6.0/9.0, 8.0/9.0, 6.0/9.0, 8.0/9.0, 8.0/9.0, 6.0/9.0, + -8.0/9.0,-8.0/9.0, 8.0/9.0, -6.0/9.0,-8.0/9.0, 8.0/9.0, -4.0/9.0,-8.0/9.0, 8.0/9.0, + -2.0/9.0,-8.0/9.0, 8.0/9.0, 0.0,-8.0/9.0, 8.0/9.0, 2.0/9.0,-8.0/9.0, 8.0/9.0, + 4.0/9.0,-8.0/9.0, 8.0/9.0, 6.0/9.0,-8.0/9.0, 8.0/9.0, 8.0/9.0,-8.0/9.0, 8.0/9.0, + -8.0/9.0,-6.0/9.0, 8.0/9.0, -6.0/9.0,-6.0/9.0, 8.0/9.0, -4.0/9.0,-6.0/9.0, 8.0/9.0, + -2.0/9.0,-6.0/9.0, 8.0/9.0, 0.0,-6.0/9.0, 8.0/9.0, 2.0/9.0,-6.0/9.0, 8.0/9.0, + 4.0/9.0,-6.0/9.0, 8.0/9.0, 6.0/9.0,-6.0/9.0, 8.0/9.0, 8.0/9.0,-6.0/9.0, 8.0/9.0, + -8.0/9.0,-4.0/9.0, 8.0/9.0, -6.0/9.0,-4.0/9.0, 8.0/9.0, -4.0/9.0,-4.0/9.0, 8.0/9.0, + -2.0/9.0,-4.0/9.0, 8.0/9.0, 0.0,-4.0/9.0, 8.0/9.0, 2.0/9.0,-4.0/9.0, 8.0/9.0, + 4.0/9.0,-4.0/9.0, 8.0/9.0, 6.0/9.0,-4.0/9.0, 8.0/9.0, 8.0/9.0,-4.0/9.0, 8.0/9.0, + -8.0/9.0,-2.0/9.0, 8.0/9.0, -6.0/9.0,-2.0/9.0, 8.0/9.0, -4.0/9.0,-2.0/9.0, 8.0/9.0, + -2.0/9.0,-2.0/9.0, 8.0/9.0, 0.0,-2.0/9.0, 8.0/9.0, 2.0/9.0,-2.0/9.0, 8.0/9.0, + 4.0/9.0,-2.0/9.0, 8.0/9.0, 6.0/9.0,-2.0/9.0, 8.0/9.0, 8.0/9.0,-2.0/9.0, 8.0/9.0, + -8.0/9.0, 0.0, 8.0/9.0, -6.0/9.0, 0.0, 8.0/9.0, -4.0/9.0, 0.0, 8.0/9.0, + -2.0/9.0, 0.0, 8.0/9.0, 0.0, 0.0, 8.0/9.0, 2.0/9.0, 0.0, 8.0/9.0, + 4.0/9.0, 0.0, 8.0/9.0, 6.0/9.0, 0.0, 8.0/9.0, 8.0/9.0, 0.0, 8.0/9.0, + -8.0/9.0, 2.0/9.0, 8.0/9.0, -6.0/9.0, 2.0/9.0, 8.0/9.0, -4.0/9.0, 2.0/9.0, 8.0/9.0, + -2.0/9.0, 2.0/9.0, 8.0/9.0, 0.0, 2.0/9.0, 8.0/9.0, 2.0/9.0, 2.0/9.0, 8.0/9.0, + 4.0/9.0, 2.0/9.0, 8.0/9.0, 6.0/9.0, 2.0/9.0, 8.0/9.0, 8.0/9.0, 2.0/9.0, 8.0/9.0, + -8.0/9.0, 4.0/9.0, 8.0/9.0, -6.0/9.0, 4.0/9.0, 8.0/9.0, -4.0/9.0, 4.0/9.0, 8.0/9.0, + -2.0/9.0, 4.0/9.0, 8.0/9.0, 0.0, 4.0/9.0, 8.0/9.0, 2.0/9.0, 4.0/9.0, 8.0/9.0, + 4.0/9.0, 4.0/9.0, 8.0/9.0, 6.0/9.0, 4.0/9.0, 8.0/9.0, 8.0/9.0, 4.0/9.0, 8.0/9.0, + -8.0/9.0, 6.0/9.0, 8.0/9.0, -6.0/9.0, 6.0/9.0, 8.0/9.0, -4.0/9.0, 6.0/9.0, 8.0/9.0, + -2.0/9.0, 6.0/9.0, 8.0/9.0, 0.0, 6.0/9.0, 8.0/9.0, 2.0/9.0, 6.0/9.0, 8.0/9.0, + 4.0/9.0, 6.0/9.0, 8.0/9.0, 6.0/9.0, 6.0/9.0, 8.0/9.0, 8.0/9.0, 6.0/9.0, 8.0/9.0, + -8.0/9.0, 8.0/9.0, 8.0/9.0, -6.0/9.0, 8.0/9.0, 8.0/9.0, -4.0/9.0, 8.0/9.0, 8.0/9.0, + -2.0/9.0, 8.0/9.0, 8.0/9.0, 0.0, 8.0/9.0, 8.0/9.0, 2.0/9.0, 8.0/9.0, 8.0/9.0, + 4.0/9.0, 8.0/9.0, 8.0/9.0, 6.0/9.0, 8.0/9.0, 8.0/9.0, 8.0/9.0, 8.0/9.0, 8.0/9.0 +}; + + +static const REAL *grouptableA[16] = +{ 0,group5bits,group7bits,group10bits,0,0,0,0,0,0,0,0,0,0,0,0}; +static const REAL *grouptableB1[16] = +{ 0,group5bits,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; +static const REAL *grouptableB234[16] = +{ 0,group5bits,group7bits,0,group10bits,0,0,0,0,0,0,0,0,0,0,0}; + +static const int codelengthtableA[16] = +{ 0, 5, 7, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; +static const int codelengthtableB1[16] = +{ 0, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; +static const int codelengthtableB2[16] = +{ 0, 5, 7, 3, 10, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 }; +static const int codelengthtableB3[8] = { 0, 5, 7, 3, 10, 4, 5, 16 }; +static const int codelengthtableB4[4] = { 0, 5, 7, 16 }; + + +static const REAL factortableA[16] = +{ 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, + 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0, + 1.0/128.0, 1.0/256.0, 1.0/512.0, 1.0/1024.0, + 1.0/2048.0, 1.0/4096.0, 1.0/8192.0, 1.0/16384.0 }; +static const REAL factortableB1[16] = +{ 0.0, 1.0/2.0, 1.0/4.0, 1.0/8.0, + 1.0/16.0, 1.0/32.0, 1.0/64.0, 1.0/128.0, + 1.0/256.0, 1.0/512.0, 1.0/1024.0, 1.0/2048.0, + 1.0/4096.0, 1.0/8192.0, 1.0/16384.0, 1.0/32768.0 }; +static const REAL factortableB2[16] = +{ 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, + 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32.0, + 1.0/64.0, 1.0/128.0, 1.0/256.0, 1.0/512.0, + 1.0/1024.0, 1.0/2048.0, 1.0/4096.0, 1.0/32768.0 }; +static const REAL factortableB3[8] = +{ 0.0, 1.0/2.0, 1.0/4.0, 1.0/4.0, 1.0/8.0, 1.0/8.0, 1.0/16.0, 1.0/32768.0 }; +static const REAL factortableB4[4] = { 0.0, 1.0/2.0, 1.0/4.0, 1.0/32768.0 }; + + +static const REAL ctableA[16]= +{ 0.0, 1.33333333333, 1.60000000000, 1.77777777777, + 1.06666666666, 1.03225806452, 1.01587301587, 1.00787401575, + 1.00392156863, 1.00195694716, 1.00097751711, 1.00048851979, + 1.00024420024, 1.00012208522, 1.00006103888, 1.00003051851}; +static const REAL ctableB1[16]= +{ 0.0, 1.33333333333, 1.14285714286, 1.06666666666, + 1.03225806452, 1.01587301587, 1.00787401575, 1.00392156863, + 1.00195694716, 1.00097751711, 1.00048851979, 1.00024420024, + 1.00012208522, 1.00006103888, 1.00003051851, 1.00001525902}; +static const REAL ctableB2[16] = +{ 0.0, 1.33333333333, 1.60000000000, 1.14285714286, + 1.77777777777, 1.06666666666, 1.03225806452, 1.01587301587, + 1.00787401575, 1.00392156863, 1.00195694716, 1.00097751711, + 1.00048851979, 1.00024420024, 1.00012208522, 1.00001525902}; +static const REAL ctableB3[8] = +{ 0.0, 1.33333333333, 1.60000000000, 1.14285714286, + 1.77777777777, 1.06666666666, 1.03225806452, 1.00001525902 }; +static const REAL ctableB4[4] = +{ 0.0, 1.33333333333, 1.60000000000, 1.00001525902 }; + + +static const REAL dtableA[16]= +{ 0.0, 0.50000000000, 0.50000000000, 0.50000000000, + 0.12500000000, 0.06250000000, 0.03125000000, 0.01562500000, + 0.00781250000, 0.00390625000, 0.00195312500, 0.00097656250, + 0.00048828125, 0.00024414063, 0.00012207031, 0.00006103516}; + +static const REAL dtableB1[16]= +{ 0.0, 0.50000000000, 0.25000000000, 0.12500000000, + 0.06250000000, 0.03125000000, 0.01562500000, 0.00781250000, + 0.00390625000, 0.00195312500, 0.00097656250, 0.00048828125, + 0.00024414063, 0.00012207031, 0.00006103516, 0.00003051758}; + +static const REAL dtableB2[16]= +{ 0.0, 0.50000000000, 0.50000000000, 0.25000000000, + 0.50000000000, 0.12500000000, 0.06250000000, 0.03125000000, + 0.01562500000, 0.00781250000, 0.00390625000, 0.00195312500, + 0.00097656250, 0.00048828125, 0.00024414063, 0.00003051758}; + +static const REAL dtableB3[8]= +{ 0.0, 0.50000000000, 0.50000000000, 0.25000000000, + 0.50000000000, 0.12500000000, 0.06250000000, 0.00003051758}; + +static const REAL dtableB4[4]= +{0.0, 0.50000000000, 0.50000000000, 0.00003051758}; + + +#ifdef _MSC_VER +#pragma warning(default : 4305) +#endif + + +#endif diff --git a/Libraries/DecMPA/Files/src/splay/mpegAudioBitWindow.cpp b/Libraries/DecMPA/Files/src/splay/mpegAudioBitWindow.cpp new file mode 100644 index 000000000..0ac30ad87 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpegAudioBitWindow.cpp @@ -0,0 +1,44 @@ +/* + bitwindow class + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - removed cout and exit stuff + + +#include "mpegAudioBitWindow.h" + + + + + + +int MpegAudioBitWindow::getCanReadBits() { + int p=bitindex>>3; + int bytes=point - p; + int bits=bytes*8+(bitindex&7); + /*cout << "point:"<>3; + point&=(WINDOWSIZE-1); + + if(p>=point) { + for(register int i=4;i + +#ifndef WORDS_BIGENDIAN +#define _KEY 0 +#else +#define _KEY 3 +#endif + +#define WINDOWSIZE 4096 +#define BITWINDOWSIZE (WINDOWSIZE*8) + + +class MpegAudioBitWindow { + + int point,bitindex; + char buffer[2*WINDOWSIZE]; + + public: + MpegAudioBitWindow(){bitindex=point=0;} + + inline void initialize(void) {bitindex=point=0;} + inline int gettotalbit(void) const {return bitindex;} + + inline void putbyte(int c) {buffer[point&(WINDOWSIZE-1)]=c;point++;} + void wrap(void); + inline void rewind(int bits) {bitindex-=bits;} + inline void forward(int bits) {bitindex+=bits;} + + // returns number of bits which can safley read + int getCanReadBits(); + + + // + // Ugly bitgetting inline functions for higher speed + // + + + inline int getbits(int bits) { + union + { + char store[4]; + int current; + }u; + int bi; + + if(!bits)return 0; + + u.current=0; + bi=(bitindex&7); + u.store[_KEY]=buffer[(bitindex>>3)&(WINDOWSIZE-1)]<>3]<>3)&(WINDOWSIZE-1)]; + //u.store[_KEY]=buffer[bitindex>>3]; + bitindex+=8; + bi=8; + } + + if(bits>=bi) { + u.current<<=bi; + bits-=bi; + bi=0; + } + else { + u.current<<=bits; + bi-=bits; + bits=0; + } + } + bitindex-=bi; + + return (u.current>>8); + } + + + int getbit(void) { + register int r=(buffer[(bitindex>>3)&(WINDOWSIZE-1)]>>(7-(bitindex&7)))&1; + //register int r=(buffer[bitindex>>3]>>(7-(bitindex&7)))&1; + bitindex++; + return r; + } + + // no range check version + inline int getbits9_f(int bits) { + register unsigned short a; + { + int offset=bitindex>>3; + a=(((unsigned char)buffer[offset])<<8)|((unsigned char)buffer[offset+1]); + } + a<<=(bitindex&7); + bitindex+=bits; + return (int)((unsigned int)(a>>(16-bits))); + } + + // range check version + int getbits9(int bits) { + register unsigned short a; + { + int offset=(bitindex>>3)&(WINDOWSIZE-1); + a=(((unsigned char)buffer[offset])<<8)|((unsigned char)buffer[offset+1]); + } + + a<<=(bitindex&7); + bitindex+=bits; + return (int)((unsigned int)(a>>(16-bits))); + } + + int peek8() { + int offset = (bitindex>>3)&(WINDOWSIZE-1), a; + a=(((unsigned char)buffer[offset])<<8) | ((unsigned char)buffer[offset+1]); + return (a >> (8-(bitindex&7))) & 0xff; + } + + +}; +#endif diff --git a/Libraries/DecMPA/Files/src/splay/mpegAudioStream.cpp b/Libraries/DecMPA/Files/src/splay/mpegAudioStream.cpp new file mode 100644 index 000000000..bc082b6ef --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpegAudioStream.cpp @@ -0,0 +1,42 @@ +/* + initializer/resyncer/frame detection etc.. for mpeg audio + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + + +#include "mpegAudioStream.h" + + +MpegAudioStream::MpegAudioStream() { + buffer=(char*)0; +} + + +MpegAudioStream::~MpegAudioStream() { +} + + + +void MpegAudioStream::setFrame(unsigned char* ptr,int len) { + this->buffer=(char*)ptr; + this->len=len; + bitindex=0; +} + + + + + + + + + + diff --git a/Libraries/DecMPA/Files/src/splay/mpegAudioStream.h b/Libraries/DecMPA/Files/src/splay/mpegAudioStream.h new file mode 100644 index 000000000..0165a0eda --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpegAudioStream.h @@ -0,0 +1,146 @@ +/* + initializer/resyncer/frame detection etc.. for mpeg audio + Copyright (C) 2000 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + + +#ifndef __MPEGAUDIOSTREAM_H +#define __MPEGAUDIOSTREAM_H + +// we include this for the big_endian define +//#include "mpegAudioBitWindow.h" + +#ifndef WORDS_BIGENDIAN +#define _KEY 0 +#else +#define _KEY 3 +#endif + + + +#define _MAX_MPEG_BUFFERSIZE 4096 + + +/** + Here we go from the frame to the bitlevel. + + +*/ + +class MpegAudioStream { + + char* buffer; + int len; + int bitindex; + + public: + MpegAudioStream(); + ~MpegAudioStream(); + + void setFrame(unsigned char* prt,int len); + + // Bit functions + + inline char* getBuffer() { return buffer; } + inline int getBufferSize() { return _MAX_MPEG_BUFFERSIZE ;} + inline void sync() { bitindex=(bitindex+7)&0xFFFFFFF8; } + inline int issync() { return (bitindex&7);}; + + /** + Now follow ugly inline function. The performance gain is 1.5 % + on a 400 MHz AMD + */ + + inline int getbyte() { + int r=(unsigned char)buffer[bitindex>>3]; + bitindex+=8; + return r; + } + + inline int getbits9(int bits) { + register unsigned short a; + { + int offset=bitindex>>3; + + a=(((unsigned char)buffer[offset])<<8) | + ((unsigned char)buffer[offset+1]); + } + + a<<=(bitindex&7); + bitindex+=bits; + return (int)((unsigned int)(a>>(16-bits))); + } + + inline int getbits8() { + register unsigned short a; + + { + int offset=bitindex>>3; + + a=(((unsigned char)buffer[offset])<<8) | + ((unsigned char)buffer[offset+1]); + } + + a<<=(bitindex&7); + bitindex+=8; + return (int)((unsigned int)(a>>8)); + } + + inline int getbit() { + register int r=(buffer[bitindex>>3]>>(7-(bitindex&7)))&1; + + bitindex++; + return r; + } + + inline int getbits(int bits) { + union + { + char store[4]; + int current; + }u; + int bi; + + if(!bits)return 0; + + u.current=0; + bi=(bitindex&7); + u.store[_KEY]=buffer[bitindex>>3]<>3]; + bitindex+=8; + bi=8; + } + if(bits>=bi) { + u.current<<=bi; + bits-=bi; + bi=0; + } else { + u.current<<=bits; + bi-=bits; + bits=0; + } + } + bitindex-=bi; + return (u.current>>8); + } + + + + +}; + + +#endif diff --git a/Libraries/DecMPA/Files/src/splay/mpeglayer1.cpp b/Libraries/DecMPA/Files/src/splay/mpeglayer1.cpp new file mode 100644 index 000000000..05aa4e014 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpeglayer1.cpp @@ -0,0 +1,118 @@ +/* MPEG/WAVE Sound library + + (C) 1997 by Jung woo-jae */ + +// Mpeglayer1.cc +// It's for MPEG Layer 1 + +//changes 8/4/2002 (by Hauke Duden): +// - added VC6 pragma to prevent some warnings from being reported + +#include "mpegsound.h" +#include "synthesis.h" + +#ifdef _MSC_VER +#pragma warning(disable : 4305) +#endif + +// Tables for layer 1 +static const REAL factortable[15] = +{ + 0.0, + (1.0/2.0) * (4.0/3.0), (1.0/4.0) * (8.0/7.0), + (1.0/8.0) * (16.0/15.0), (1.0/16.0) * (32.0/31.0), + (1.0/32.0) * (64.0/63.0), (1.0/64.0) * (128.0/127.0), + (1.0/128.0) * (256.0/255.0), (1.0/256.0) * (512.0/511.0), + (1.0/512.0) * (1024.0/1023.0), (1.0/1024.0) * (2048.0/2047.0), + (1.0/2048.0) * (4096.0/4095.0), (1.0/4096.0) * (8192.0/8191.0), + (1.0/8192.0) * (16384.0/16383.0), (1.0/16384.0) * (32768.0/32767.0) +}; + +static const REAL offsettable[15] = +{ + 0.0, + ((1.0/2.0)-1.0) * (4.0/3.0), ((1.0/4.0)-1.0) * (8.0/7.0), + ((1.0/8.0)-1.0) * (16.0/15.0), ((1.0/16.0)-1.0) * (32.0/31.0), + ((1.0/32.0)-1.0) * (64.0/63.0), ((1.0/64.0)-1.0) * (128.0/127.0), + ((1.0/128.0)-1.0) * (256.0/255.0), ((1.0/256.0)-1.0) * (512.0/511.0), + ((1.0/512.0)-1.0) * (1024.0/1023.0), ((1.0/1024.0)-1.0) * (2048.0/2047.0), + ((1.0/2048.0)-1.0) * (4096.0/4095.0), ((1.0/4096.0)-1.0) * (8192.0/8191.0), + ((1.0/8192.0)-1.0) * (16384.0/16383.0), ((1.0/16384.0)-1.0) * (32768.0/32767.0) +}; + +#ifdef _MSC_VER +#pragma warning(default : 4305) +#endif + +// Mpeg layer 1 +void Mpegtoraw::extractlayer1(void) +{ + int inputstereo=mpegAudioHeader->getInputstereo(); + int stereobound=mpegAudioHeader->getStereobound(); + REAL fraction[MAXCHANNEL][MAXSUBBAND]; + REAL scalefactor[MAXCHANNEL][MAXSUBBAND]; + + int bitalloc[MAXCHANNEL][MAXSUBBAND], + sample[MAXCHANNEL][MAXSUBBAND]; + + register int i,j; + int s=stereobound,l; + + +// Bitalloc + for(i=0;idoSynth(lDownSample,lOutputStereo, + fraction[LS],fraction[RS]); + } +} diff --git a/Libraries/DecMPA/Files/src/splay/mpeglayer2.cpp b/Libraries/DecMPA/Files/src/splay/mpeglayer2.cpp new file mode 100644 index 000000000..881520612 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpeglayer2.cpp @@ -0,0 +1,449 @@ +/* MPEG/WAVE Sound library + + (C) 1997 by Jung woo-jae */ + +// Mpeglayer2.cc +// It's for MPEG Layer 2 + +//changes 8/4/2002 (by Hauke Duden): +// - added some explicit casts to remove compilation warnings +// - added VC6 pragma to prevent some warnings from being reported + +#include "mpegsound.h" +#include "synthesis.h" + + +#define BUGFIX +#include "mpeg2tables.h" + + +// workaround for buggy mpeg2 streams. +// tested with 12 monkey cdi, worgked fine. +// problem was: the stream produced ints +// with access out of the tables +// if we have such an access we set it to a zero entry +#ifdef BUGFIX +static int checkCodeRange(int code,const REAL* group) { + int back=0; + if (group == NULL) { + //cout << "group null"< 27*3) { + // redirect to zero value + back=3; + } + return back; + } + if (group == group7bits) { + if (back > 125*3) { + back=6; + } + return back; + } + if (group == group10bits) { + if (back > 729*3) { + back=12; + } + return back; + } + //DEBUG_LAYER(cout << "unknown group found!"<getInputstereo(); + int tableindex=mpegAudioHeader->getTableindex(); + int subbandnumber=mpegAudioHeader->getSubbandnumber(); + int stereobound=mpegAudioHeader->getStereobound(); + + REAL fraction[MAXCHANNEL][3][MAXSUBBAND]; + unsigned int bitalloc[MAXCHANNEL][MAXSUBBAND], + scaleselector[MAXCHANNEL][MAXSUBBAND]; + REAL scalefactor[2][3][MAXSUBBAND]; + + const REAL *group[MAXCHANNEL][MAXSUBBAND]; + unsigned int codelength[MAXCHANNEL][MAXSUBBAND]; + REAL factor[MAXCHANNEL][MAXSUBBAND]; + REAL c[MAXCHANNEL][MAXSUBBAND],d[MAXCHANNEL][MAXSUBBAND]; + + int s=stereobound,n=subbandnumber; + + + // Bitalloc + { + register int i; + register const int *t=bitalloclengthtable[tableindex]; + for(i=0;i>2][i]; + fraction[LS][0][i]*=t; + fraction[LS][1][i]*=t; + fraction[LS][2][i]*=t; + } + + if(bitalloc[RS][i]) + { + if(!group[RS][i]) + { + fraction[RS][0][i]=(fraction[RS][0][i]+d[RS][i])*c[LS][i]; + fraction[RS][1][i]=(fraction[RS][1][i]+d[RS][i])*c[LS][i]; + fraction[RS][2][i]=(fraction[RS][2][i]+d[RS][i])*c[LS][i]; + } + + register REAL t=scalefactor[RS][l>>2][i]; + fraction[RS][0][i]*=t; + fraction[RS][1][i]*=t; + fraction[RS][2][i]*=t; + } + } + else + for(i=0;i>2][i]; + fraction[LS][0][i]*=t; + fraction[LS][1][i]*=t; + fraction[LS][2][i]*=t; + } + + + for(;idoSynth(lDownSample,lOutputStereo, + fraction[LS][i],fraction[RS][i]); + } + + } + } +} diff --git a/Libraries/DecMPA/Files/src/splay/mpeglayer3.cpp b/Libraries/DecMPA/Files/src/splay/mpeglayer3.cpp new file mode 100644 index 000000000..a6982ae97 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpeglayer3.cpp @@ -0,0 +1,1798 @@ +/* MPEG/WAVE Sound library + + (C) 1997 by Jung woo-jae */ + +// Mpeglayer3.cc +// It's for MPEG Layer 3 +// I've made array of superior functions for speed. +// Extend TO_FOUR_THIRDS to negative. +// Bug fix : maplay 1.2+ have wrong TO_FOUR_THIRDS ranges. +// Force to mono!! +// MPEG-2 is implemented +// Speed up in fixstereo (maybe buggy) + + +//changes 8/4/2002 (by Hauke Duden): +// - added VC6 pragma to prevent some warnings from being reported +// - removed dump stuff + +//changes 8/15/2002 +// - added pragmas to disable Visual-C++ optimizations that were causing +// artifacts with some MP3s + +#include "mpegsound.h" +#include "huffmanlookup.h" +//#include "dump.h" +#include "synthesis.h" + +#include "window.h" + +inline int Mpegtoraw::wgetbit (void) {return bitwindow.getbit (); } +inline int Mpegtoraw::wgetbits9(int bits){return bitwindow.getbits9(bits);} +inline int Mpegtoraw::wgetbits (int bits){return bitwindow.getbits (bits);} +inline int Mpegtoraw::wgetCanReadBits () {return bitwindow.getCanReadBits();} + + +#define MUL3(a) (((a)<<1)+(a)) + +#define REAL0 0 + +// 576 +#define ARRAYSIZE (SBLIMIT*SSLIMIT) +#define REALSIZE (sizeof(REAL)) + + +#define MAPLAY_OPT 1 + + +#ifdef NATIVE_ASSEMBLY +inline void long_memset(void * s,unsigned int c,int count) +{ +__asm__ __volatile__( + "cld\n\t" + "rep ; stosl\n\t" + : /* no output */ + :"a" (c), "c" (count/4), "D" ((long) s) + :"cx","di","memory"); +} +#endif + +#define FOURTHIRDSTABLENUMBER (8250) +static int initializedlayer3=false; + +static REAL two_to_negative_half_pow[70]; +static REAL TO_FOUR_THIRDSTABLE[FOURTHIRDSTABLENUMBER*2]; +static REAL POW2[256]; +static REAL POW2_1[8][2][16]; +static REAL ca[8],cs[8]; + + + + +typedef struct +{ + REAL l,r; +}RATIOS; + +static RATIOS rat_1[16],rat_2[2][64]; + +#ifdef _MSC_VER +#pragma warning(disable: 4244) +#endif + +void Mpegtoraw::layer3initialize(void) +{ + + int i,j,k,l; + + //maplay opt. + nonzero[0] = nonzero[1] = nonzero[2]=ARRAYSIZE; + + layer3framestart=0; + currentprevblock=0; + + for(l=0;l<2;l++) + for(i=0;i<2;i++) + for(j=0;j0) { + if ( k & 1) { + val=pow(base,(k+1.0)*0.5); + } else { + val=pow(base,k*0.5); + } + } + + POW2_MV[i][j][k]=val; + } + } + + for(i=0;i<8;i++) + for(j=0;j<2;j++) + for(k=0;k<16;k++) { + REAL a=POW2_1[i][j][k]; + REAL b=POW2_MV[i][j][k]; + printf("i:%d j%d k%d",i,j,k); + if (a != b) { + cout << "a:"<getInputstereo(); + + + sideinfo.main_data_begin=getbits(9); + if(!inputstereo)sideinfo.private_bits=getbits(5); + else sideinfo.private_bits=getbits(3); + + sideinfo.ch[LS].scfsi[0]=getbit(); + sideinfo.ch[LS].scfsi[1]=getbit(); + sideinfo.ch[LS].scfsi[2]=getbit(); + sideinfo.ch[LS].scfsi[3]=getbit(); + if(inputstereo) { + sideinfo.ch[RS].scfsi[0]=getbit(); + sideinfo.ch[RS].scfsi[1]=getbit(); + sideinfo.ch[RS].scfsi[2]=getbit(); + sideinfo.ch[RS].scfsi[3]=getbit(); + } + + for(int gr=0,ch;gr<2;gr++) + for(ch=0;;ch++) { + layer3grinfo *gi=&(sideinfo.ch[ch].gr[gr]); + + gi->part2_3_length =getbits(12); + gi->big_values =getbits(9); + if(gi->big_values > 288) { + DEBUG_LAYER(fprintf(stderr,"big_values too large!\n");) + gi->big_values = 288; + return false; + } + + gi->global_gain =getbits(8); + gi->scalefac_compress =getbits(4); + gi->window_switching_flag=getbit(); + if(gi->window_switching_flag) { + gi->block_type =getbits(2); + gi->mixed_block_flag=getbit(); + + gi->table_select[0] =getbits(5); + gi->table_select[1] =getbits(5); + + gi->subblock_gain[0]=getbits(3); + gi->subblock_gain[1]=getbits(3); + gi->subblock_gain[2]=getbits(3); + + /* Set region_count parameters since they are implicit in this case. */ + if(gi->block_type==0) + { + DEBUG_LAYER(printf("Side info bad: block_type==0 split block.\n");) + return false; + } + else if (gi->block_type==2 && gi->mixed_block_flag==0) + gi->region0_count=8; /* MI 9; */ + else gi->region0_count=7; /* MI 8; */ + gi->region1_count=20-(gi->region0_count); + } + else + { + gi->table_select[0] =getbits(5); + gi->table_select[1] =getbits(5); + gi->table_select[2] =getbits(5); + gi->region0_count =getbits(4); + gi->region1_count =getbits(3); + gi->block_type =0; + } + gi->preflag =getbit(); + gi->scalefac_scale =getbit(); + gi->count1table_select=getbit(); + + gi->generalflag=gi->window_switching_flag && (gi->block_type==2); + + if(!inputstereo || ch)break; + } + + return true; +} + +bool Mpegtoraw::layer3getsideinfo_2(void) { + int inputstereo=mpegAudioHeader->getInputstereo(); + sideinfo.main_data_begin=getbits(8); + + if(!inputstereo)sideinfo.private_bits=getbit(); + else sideinfo.private_bits=getbits(2); + + for(int ch=0;;ch++) + { + layer3grinfo *gi=&(sideinfo.ch[ch].gr[0]); + + gi->part2_3_length =getbits(12); + gi->big_values =getbits(9); + if(gi->big_values > 288) { + DEBUG_LAYER(fprintf(stderr,"big_values too large!\n");) + gi->big_values = 288; + return false; + } + + gi->global_gain =getbits(8); + gi->scalefac_compress =getbits(9); + gi->window_switching_flag=getbit(); + if(gi->window_switching_flag) + { + gi->block_type =getbits(2); + gi->mixed_block_flag=getbit(); + + gi->table_select[0] =getbits(5); + gi->table_select[1] =getbits(5); + + gi->subblock_gain[0]=getbits(3); + gi->subblock_gain[1]=getbits(3); + gi->subblock_gain[2]=getbits(3); + + /* Set region_count parameters since they are implicit in this case. */ + if(gi->block_type==0) + { + DEBUG_LAYER(printf("Side info bad: block_type==0 split block.\n");) + return false; + } + else if (gi->block_type==2 && gi->mixed_block_flag==0) + gi->region0_count=8; /* MI 9; */ + else gi->region0_count=7; /* MI 8; */ + gi->region1_count=20-(gi->region0_count); + } + else + { + gi->table_select[0] =getbits(5); + gi->table_select[1] =getbits(5); + gi->table_select[2] =getbits(5); + gi->region0_count =getbits(4); + gi->region1_count =getbits(3); + gi->block_type =0; + } + gi->scalefac_scale =getbit(); + gi->count1table_select=getbit(); + + gi->generalflag=gi->window_switching_flag && (gi->block_type==2); + + if(!inputstereo || ch)break; + } + + return true; +} + +void Mpegtoraw::layer3getscalefactors(int ch,int gr) +{ + static int slen[2][16]={{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, + {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}}; + + layer3grinfo *gi=&(sideinfo.ch[ch].gr[gr]); + register layer3scalefactor *sf=(&scalefactors[ch]); + int l0,l1; + + { + int scale_comp=gi->scalefac_compress; + + l0=slen[0][scale_comp]; + l1=slen[1][scale_comp]; + } + /* + wgetCanReadBits(); + cout << "lo:"<generalflag) + { + if(gi->mixed_block_flag) + { /* MIXED */ /* NEW-ag 11/25 */ + sf->l[0]=wgetbits9(l0);sf->l[1]=wgetbits9(l0); + sf->l[2]=wgetbits9(l0);sf->l[3]=wgetbits9(l0); + sf->l[4]=wgetbits9(l0);sf->l[5]=wgetbits9(l0); + sf->l[6]=wgetbits9(l0);sf->l[7]=wgetbits9(l0); + + sf->s[0][ 3]=wgetbits9(l0);sf->s[1][ 3]=wgetbits9(l0); + sf->s[2][ 3]=wgetbits9(l0); + sf->s[0][ 4]=wgetbits9(l0);sf->s[1][ 4]=wgetbits9(l0); + sf->s[2][ 4]=wgetbits9(l0); + sf->s[0][ 5]=wgetbits9(l0);sf->s[1][ 5]=wgetbits9(l0); + sf->s[2][ 5]=wgetbits9(l0); + + sf->s[0][ 6]=wgetbits9(l1);sf->s[1][ 6]=wgetbits9(l1); + sf->s[2][ 6]=wgetbits9(l1); + sf->s[0][ 7]=wgetbits9(l1);sf->s[1][ 7]=wgetbits9(l1); + sf->s[2][ 7]=wgetbits9(l1); + sf->s[0][ 8]=wgetbits9(l1);sf->s[1][ 8]=wgetbits9(l1); + sf->s[2][ 8]=wgetbits9(l1); + sf->s[0][ 9]=wgetbits9(l1);sf->s[1][ 9]=wgetbits9(l1); + sf->s[2][ 9]=wgetbits9(l1); + sf->s[0][10]=wgetbits9(l1);sf->s[1][10]=wgetbits9(l1); + sf->s[2][10]=wgetbits9(l1); + sf->s[0][11]=wgetbits9(l1);sf->s[1][11]=wgetbits9(l1); + sf->s[2][11]=wgetbits9(l1); + + sf->s[0][12]=sf->s[1][12]=sf->s[2][12]=0; + } + else + { /* SHORT*/ + sf->s[0][ 0]=wgetbits9(l0);sf->s[1][ 0]=wgetbits9(l0); + sf->s[2][ 0]=wgetbits9(l0); + sf->s[0][ 1]=wgetbits9(l0);sf->s[1][ 1]=wgetbits9(l0); + sf->s[2][ 1]=wgetbits9(l0); + sf->s[0][ 2]=wgetbits9(l0);sf->s[1][ 2]=wgetbits9(l0); + sf->s[2][ 2]=wgetbits9(l0); + sf->s[0][ 3]=wgetbits9(l0);sf->s[1][ 3]=wgetbits9(l0); + sf->s[2][ 3]=wgetbits9(l0); + sf->s[0][ 4]=wgetbits9(l0);sf->s[1][ 4]=wgetbits9(l0); + sf->s[2][ 4]=wgetbits9(l0); + sf->s[0][ 5]=wgetbits9(l0);sf->s[1][ 5]=wgetbits9(l0); + sf->s[2][ 5]=wgetbits9(l0); + + sf->s[0][ 6]=wgetbits9(l1);sf->s[1][ 6]=wgetbits9(l1); + sf->s[2][ 6]=wgetbits9(l1); + sf->s[0][ 7]=wgetbits9(l1);sf->s[1][ 7]=wgetbits9(l1); + sf->s[2][ 7]=wgetbits9(l1); + sf->s[0][ 8]=wgetbits9(l1);sf->s[1][ 8]=wgetbits9(l1); + sf->s[2][ 8]=wgetbits9(l1); + sf->s[0][ 9]=wgetbits9(l1);sf->s[1][ 9]=wgetbits9(l1); + sf->s[2][ 9]=wgetbits9(l1); + sf->s[0][10]=wgetbits9(l1);sf->s[1][10]=wgetbits9(l1); + sf->s[2][10]=wgetbits9(l1); + sf->s[0][11]=wgetbits9(l1);sf->s[1][11]=wgetbits9(l1); + sf->s[2][11]=wgetbits9(l1); + + sf->s[0][12]=sf->s[1][12]=sf->s[2][12]=0; + } + } + else + { /* LONG types 0,1,3 */ + if(gr==0) + { + sf->l[ 0]=wgetbits9(l0);sf->l[ 1]=wgetbits9(l0); + sf->l[ 2]=wgetbits9(l0);sf->l[ 3]=wgetbits9(l0); + sf->l[ 4]=wgetbits9(l0);sf->l[ 5]=wgetbits9(l0); + sf->l[ 6]=wgetbits9(l0);sf->l[ 7]=wgetbits9(l0); + sf->l[ 8]=wgetbits9(l0);sf->l[ 9]=wgetbits9(l0); + sf->l[10]=wgetbits9(l0); + sf->l[11]=wgetbits9(l1);sf->l[12]=wgetbits9(l1); + sf->l[13]=wgetbits9(l1);sf->l[14]=wgetbits9(l1); + sf->l[15]=wgetbits9(l1); + sf->l[16]=wgetbits9(l1);sf->l[17]=wgetbits9(l1); + sf->l[18]=wgetbits9(l1);sf->l[19]=wgetbits9(l1); + sf->l[20]=wgetbits9(l1); + } + else + { + if(sideinfo.ch[ch].scfsi[0]==0) + { + sf->l[ 0]=wgetbits9(l0);sf->l[ 1]=wgetbits9(l0); + sf->l[ 2]=wgetbits9(l0);sf->l[ 3]=wgetbits9(l0); + sf->l[ 4]=wgetbits9(l0);sf->l[ 5]=wgetbits9(l0); + } + if(sideinfo.ch[ch].scfsi[1]==0) + { + sf->l[ 6]=wgetbits9(l0);sf->l[ 7]=wgetbits9(l0); + sf->l[ 8]=wgetbits9(l0);sf->l[ 9]=wgetbits9(l0); + sf->l[10]=wgetbits9(l0); + } + if(sideinfo.ch[ch].scfsi[2]==0) + { + sf->l[11]=wgetbits9(l1);sf->l[12]=wgetbits9(l1); + sf->l[13]=wgetbits9(l1);sf->l[14]=wgetbits9(l1); + sf->l[15]=wgetbits9(l1); + } + if(sideinfo.ch[ch].scfsi[3]==0) + { + sf->l[16]=wgetbits9(l1);sf->l[17]=wgetbits9(l1); + sf->l[18]=wgetbits9(l1);sf->l[19]=wgetbits9(l1); + sf->l[20]=wgetbits9(l1); + } + } + sf->l[21]=sf->l[22]=0; + } + /* + cout << "end parse:"<getExtendedmode(); + layer3grinfo *gi=&(sideinfo.ch[ch].gr[0]); + register layer3scalefactor *sf=(&scalefactors[ch]); + + { + int blocktypenumber,sc; + int blocknumber; + int slen[4]; + + if(gi->block_type==2)blocktypenumber=1+gi->mixed_block_flag; + else blocktypenumber=0; + + sc=gi->scalefac_compress; + if(!((extendedmode==1 || extendedmode==3) && (ch==1))) + { + if(sc<400) + { + slen[0]=(sc>>4)/5; + slen[1]=(sc>>4)%5; + slen[2]=(sc%16)>>2; + slen[3]=(sc%4); + gi->preflag=0; + blocknumber=0; + } + else if(sc<500) + { + sc-=400; + slen[0]=(sc>>2)/5; + slen[1]=(sc>>2)%5; + slen[2]=sc%4; + slen[3]=0; + gi->preflag=0; + blocknumber=1; + } + else // if(sc<512) + { + sc-=500; + slen[0]=sc/3; + slen[1]=sc%3; + slen[2]=0; + slen[3]=0; + gi->preflag=1; + blocknumber=2; + } + } + else + { + sc>>=1; + if(sc<180) + { + slen[0]=sc/36; + slen[1]=(sc%36)/6; + slen[2]=(sc%36)%6; + slen[3]=0; + gi->preflag=0; + blocknumber=3; + } + else if(sc<244) + { + sc-=180; + slen[0]=(sc%64)>>4; + slen[1]=(sc%16)>>2; + slen[2]=sc%4; + slen[3]=0; + gi->preflag=0; + blocknumber=4; + } + else // if(sc<255) + { + sc-=244; + slen[0]=sc/3; + slen[1]=sc%3; + slen[2]= + slen[3]=0; + gi->preflag=0; + blocknumber=5; + } + } + + { + int i,j,k,*si; + + si=sfbblockindex[blocknumber][blocktypenumber]; + for(i=0;i<45;i++)sb[i]=0; + + for(k=i=0;i<4;i++) + for(j=0;jwindow_switching_flag && (gi->block_type==2)) + { + if(gi->mixed_block_flag) + { + for(sfb=0;sfb<8;sfb++)sf->l[sfb]=sb[k++]; + sfb=3; + } + else sfb=0; + + for(;sfb<12;sfb++) + for(window=0;window<3;window++) + sf->s[window][sfb]=sb[k++]; + + sf->s[0][12]=sf->s[1][12]=sf->s[2][12]=0; + } + else + { + for(sfb=0;sfb<21;sfb++) + sf->l[sfb]=sb[k++]; + sf->l[21]=sf->l[22]=0; + } + } +} + + +typedef unsigned int HUFFBITS; +#define MXOFF 250 + +/* do the huffman-decoding */ +/* note! for counta,countb -the 4 bit value is returned in y, discard x */ +// Huffman decoder for tablename<32 +inline void Mpegtoraw::huffmandecoder_1(const HUFFMANCODETABLE *h,int *x,int *y) +{ + HUFFBITS level=(1<<(sizeof(HUFFBITS)*8-1)); + int point=0; + + /* Lookup in Huffman table. */ + for(;;) + { + if(h->val[point][0]==0) + { /*end of tree*/ + int xx,yy; + + xx=h->val[point][1]>>4; + yy=h->val[point][1]&0xf; + + if(h->linbits) + { + if((h->xlen)==(unsigned)xx)xx+=wgetbits(h->linbits); + if(xx)if(wgetbit())xx=-xx; + if((h->ylen)==(unsigned)yy)yy+=wgetbits(h->linbits); + if(yy)if(wgetbit())yy=-yy; + } + else + { + if(xx)if(wgetbit())xx=-xx; + if(yy)if(wgetbit())yy=-yy; + } + *x=xx;*y=yy; + break; + } + + point+=h->val[point][wgetbit()]; + + level>>=1; + if(!(level || ((unsigned)pointtreelen))) + { + register int xx,yy; + + xx=(h->xlen<<1);// set x and y to a medium value as a simple concealment + yy=(h->ylen<<1); + + // h->xlen and h->ylen can't be 1 under tablename 32 + // if(xx) + if(wgetbit())xx=-xx; + // if(yy) + if(wgetbit())yy=-yy; + + *x=xx;*y=yy; + break; + } + } +} + +// Huffman decoder tablenumber>=32 +inline void Mpegtoraw::huffmandecoder_2(const HUFFMANCODETABLE *h, + int *x,int *y,int *v,int *w) +{ + HUFFBITS level=(1<<(sizeof(HUFFBITS)*8-1)); + int point=0; + + /* Lookup in Huffman table. */ + for(;;) + { + if(h->val[point][0]==0) + { /*end of tree*/ + register int t=h->val[point][1]; + + if(t&8)*v=1-(wgetbit()<<1); else *v=0; + if(t&4)*w=1-(wgetbit()<<1); else *w=0; + if(t&2)*x=1-(wgetbit()<<1); else *x=0; + if(t&1)*y=1-(wgetbit()<<1); else *y=0; + break; + } + point+=h->val[point][wgetbit()]; + level>>=1; + if(!(level || ((unsigned)pointtreelen))) + { + *v=1-(wgetbit()<<1); + *w=1-(wgetbit()<<1); + *x=1-(wgetbit()<<1); + *y=1-(wgetbit()<<1); + break; + } + } +} + +typedef struct +{ + int l[23]; + int s[14]; +}SFBANDINDEX; + +static SFBANDINDEX sfBandIndextable[3][3]= +{ + // MPEG 1 + {{{0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576}, + {0,4,8,12,16,22,30,40,52,66,84,106,136,192}}, + {{0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576}, + {0,4,8,12,16,22,28,38,50,64,80,100,126,192}}, + {{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576}, + {0,4,8,12,16,22,30,42,58,78,104,138,180,192}}}, + + // MPEG 2 + {{{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {0,4,8,12,18,24,32,42,56,74,100,132,174,192}}, + {{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576}, + {0,4,8,12,18,26,36,48,62,80,104,136,180,192}}, + {{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {0,4,8,12,18,26,36,48,62,80,104,134,174,192}}}, + // MPEG 2.5 + {{{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {0,4,8,12,18,26,36,48,62,80,104,134,174,192}}, + {{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {0,4,8,12,18,26,36,48,62,80,104,134,174,192}}, + {{0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}, + {0,8,16,24,36,52,72,96,124,160,162,164,166,192}}} +}; + + +void Mpegtoraw::layer3huffmandecode(int ch,int gr,int out[SBLIMIT][SSLIMIT]) +{ + layer3grinfo *gi=&(sideinfo.ch[ch].gr[gr]); + int part2_3_end=layer3part2start+(gi->part2_3_length); + int region1Start,region2Start; + int i,e=gi->big_values<<1; + int version=mpegAudioHeader->getVersion(); + int frequency=mpegAudioHeader->getFrequency(); + int mpeg25=mpegAudioHeader->getLayer25(); + + /* Find region boundary for short block case. */ + if(gi->generalflag) { + /* Region2. */ + region1Start= + sfBandIndextable[mpeg25?2:version][frequency].s[3]*3; + /* MPEG1:sfb[9/3]*3=36 */ + region2Start=576;/* No Region2 for short block case. */ + } else { + /* Find region boundary for long block case. */ + region1Start= + sfBandIndextable[mpeg25?2:version][frequency].l[gi->region0_count+1]; + region2Start= + sfBandIndextable[mpeg25?2:version][frequency].l[gi->region0_count+ + gi->region1_count+2]; + } + + /* Read bigvalues area. */ + for(i=0;itable_select[0]]; + if(region1Start>e)end=e; else end=region1Start; + } + else if(itable_select[1]]; + if(region2Start>e)end=e; else end=region2Start; + } + else + { + h=&ht[gi->table_select[2]]; + end=e; + } + + if(h->treelen) { + while(itablename, bitwindow.peek8(), + &out[0][i], &out[0][i+1]); + + if(skip) + bitwindow.forward(skip); + else + huffmandecoder_1(h,&out[0][i],&out[0][i+1]); + i+=2; + } + } else { + for(;icount1table_select+32]; + while(bitwindow.gettotalbit()=ARRAYSIZE) + { + break; + } + } + + // nonzero is the _size_ of the array with the last nonzero value + if (i < ARRAYSIZE) { + nonzero[ch] = i; + } else { + // catch bugs + nonzero[ch] = ARRAYSIZE; + } + + // debug start +#ifndef MAPLAY_OPT + nonzero[ch]=ARRAYSIZE; + for(;igetVersion(); + int frequency=mpegAudioHeader->getFrequency(); + int mpeg25=mpegAudioHeader->getLayer25(); + layer3grinfo *gi=&(sideinfo.ch[ch].gr[gr]); + SFBANDINDEX *sfBandIndex=&(sfBandIndextable[mpeg25?2:version][frequency]); + REAL globalgain=POW2[gi->global_gain]; + REAL *TO_FOUR_THIRDS=TO_FOUR_THIRDSTABLE+FOURTHIRDSTABLENUMBER; + int arrayEnd=nonzero[ch]; + /* choose correct scalefactor band per block type, initalize boundary */ + /* and apply formula per block type */ + if(!gi->generalflag) { + /* LONG blocks: 0,1,3 */ + int next_cb_boundary; + int cb=-1,index=0; + REAL factor; + + + do + { + + next_cb_boundary=sfBandIndex->l[(++cb)+1]; + REAL val=layer3twopow2(gi->scalefac_scale,gi->preflag, + pretab[cb],scalefactors[ch].l[cb]); + factor=globalgain*val; + // maplay opt + if (arrayEnd < next_cb_boundary) { + next_cb_boundary=arrayEnd; + } + + for(;indexmixed_block_flag) { + int cb=0,index=0; + int cb_width; + do + { + cb_width=(sfBandIndex->s[cb+1]-sfBandIndex->s[cb])>>1; + + for(register int k=0;k<3;k++) + { + register REAL factor; + register int count=cb_width; + // maplay12 opt. + if(index+(count<<1) > arrayEnd) { + if (index >= arrayEnd) break; + count=(arrayEnd-index)>>1; + } + + factor=globalgain* + layer3twopow2_1(gi->subblock_gain[k],gi->scalefac_scale, + scalefactors[ch].s[k][cb]); + + + do{ + out[0][index]=factor*TO_FOUR_THIRDS[in[0][index++]]; + out[0][index]=factor*TO_FOUR_THIRDS[in[0][index++]]; + }while(--count); + } + cb++; + }while(indexl[1]; /* LONG blocks: 0,1,3 */ + int index; + // I do not have an mp3 with this format, + // so we restore the "make rest of array zero" + // in this case + // to use the maplay opt here, we must make sure, that + // arrayEnd==ArraySize. + for(int i=arrayEnd;il[8]) + { + next_cb_boundary=sfBandIndex->s[4]; + next_cb_boundary=MUL3(next_cb_boundary); + cb=3; + cb_width=sfBandIndex->s[4]-sfBandIndex->s[3]; + cb_begin=sfBandIndex->s[3]; + cb_begin=MUL3(cb_begin); + } + else if(indexl[8]) + next_cb_boundary=sfBandIndex->l[(++cb)+1]; + else + { + next_cb_boundary=sfBandIndex->s[(++cb)+1]; + next_cb_boundary=MUL3(next_cb_boundary); + cb_begin=sfBandIndex->s[cb]; + cb_width=sfBandIndex->s[cb+1]-cb_begin; + cb_begin=MUL3(cb_begin); + } + } + /* LONG block types 0,1,3 & 1st 2 subbands of switched blocks */ + out[0][index]*=layer3twopow2(gi->scalefac_scale,gi->preflag, + pretab[cb],scalefactors[ch].l[cb]); + + } + + for(;indexl[8]) { + next_cb_boundary=sfBandIndex->s[4]; + next_cb_boundary=MUL3(next_cb_boundary); + cb=3; + cb_width=sfBandIndex->s[4]-sfBandIndex->s[3]; + cb_begin=sfBandIndex->s[3]; + cb_begin=(cb_begin<<2)-cb_begin; + } else if(indexl[8]) + next_cb_boundary=sfBandIndex->l[(++cb)+1]; + else { + next_cb_boundary=sfBandIndex->s[(++cb)+1]; + next_cb_boundary=MUL3(next_cb_boundary); + cb_begin=sfBandIndex->s[cb]; + cb_width=sfBandIndex->s[cb+1]-cb_begin; + cb_begin=MUL3(cb_begin); + } + } + { + /** + Here we check if we do a division by zero + and if the resulting t_index points + outside the array. (Needed for better robustness + of the mp3 decoder) + */ + unsigned int t_index=0; + if (cb_width) { + t_index=(unsigned int)((index-cb_begin)/cb_width); + if (t_index > 2) { + t_index=0; + } + } + + out[0][index]*=layer3twopow2_1(gi->subblock_gain[t_index], + gi->scalefac_scale, + scalefactors[ch].s[t_index][cb]); + } + } + } + /* + int i; + for(i=arrayEnd;i nonzero[1]) { + in[RS][0][nonzero[1]]=(REAL) 0.0; + nonzero[1]++; + } + while(nonzero[1] > nonzero[0]) { + in[LS][0][nonzero[0]]=(REAL) 0.0; + nonzero[0]++; + } + // now they are the same + // put this into the "max" var. + nonzero[2]=nonzero[1]; + +} + +inline void Mpegtoraw::layer3fixtostereo(int gr,REAL in[2][SBLIMIT][SSLIMIT]) +{ + int version=mpegAudioHeader->getVersion(); + int frequency=mpegAudioHeader->getFrequency(); + int extendedmode=mpegAudioHeader->getExtendedmode(); + int mode=mpegAudioHeader->getMode(); + int inputstereo=mpegAudioHeader->getInputstereo(); + int mpeg25=mpegAudioHeader->getLayer25(); + layer3grinfo *gi=&(sideinfo.ch[0].gr[gr]); + SFBANDINDEX *sfBandIndex=&(sfBandIndextable[mpeg25?2:version][frequency]); + + int ms_stereo=(mode==_MODE_JOINT) && (extendedmode & 0x2); + int i_stereo =(mode==_MODE_JOINT) && (extendedmode & 0x1); + + + if(!inputstereo) + { /* mono , bypass xr[0][][] to lr[0][][]*/ + // memcpy(out[0][0],in[0][0],ARRAYSIZE*REALSIZE); + for(int i=nonzero[0];iscalefac_compress%2]; + else ratios=rat_1; + + /* initialization */ + for(i=0;igeneralflag) + { + if(gi->mixed_block_flag) // Part I + { + int max_sfb=0; + + for(int j=0;j<3;j++) + { + int sfb,sfbcnt=2; + + for(sfb=12;sfb>=3;sfb--) + { + int lines; + + i=sfBandIndex->s[sfb]; + lines=sfBandIndex->s[sfb+1]-i; + i=MUL3(i)+(j+1)*lines-1; + for(;lines>0;lines--,i--) + if(in[1][0][i]!=0.0f) + { + sfbcnt=sfb; + sfb=0;break; // quit loop + } + } + sfb=sfbcnt+1; + + if(sfb>max_sfb)max_sfb=sfb; + + for(;sfb<12;sfb++) + { + int k,t; + + t=sfBandIndex->s[sfb]; + k=sfBandIndex->s[sfb+1]-t; + i=MUL3(t)+j*k; + + t=scalefactors[1].s[j][sfb]; + if(t!=7) + { + RATIOS r=ratios[t]; + + for(;k>0;k--,i++){ + is_pos[i]=t;is_ratio[i]=r;} + } + else + for(;k>0;k--,i++)is_pos[i]=t; + } + sfb=sfBandIndex->s[10]; + sfb=MUL3(sfb)+j*(sfBandIndex->s[11]-sfb); + + { + int k,t; + + t=sfBandIndex->s[11]; + k=sfBandIndex->s[12]-t; + i=MUL3(t)+j*k; + + t=is_pos[sfb]; + if(t!=7) + { + RATIOS r=is_ratio[sfb]; + + for(;k>0;k--,i++){ + is_pos[i]=t;is_ratio[i]=r;} + } + else + for(;k>0;k--,i++)is_pos[i]=t; + } + } + + if(max_sfb<=3) + { + { + REAL temp; + int k; + + temp=in[1][0][0];in[1][0][0]=1.0; + for(k=3*SSLIMIT-1;in[1][0][k]==0.0;k--); + in[1][0][0]=temp; + for(i=0;sfBandIndex->l[i]<=k;i++); + } + { + int sfb=i; + + i=sfBandIndex->l[i]; + for(;sfb<8;sfb++) + { + int t=scalefactors[1].l[sfb]; + int k=sfBandIndex->l[sfb+1]-sfBandIndex->l[sfb]; + + if(t!=7) + { + RATIOS r=ratios[t]; + + for(;k>0;k--,i++){ + is_pos[i]=t;is_ratio[i]=r;} + } + else for(;k>0;k--,i++)is_pos[i]=t; + } + } + } + } + else // Part II + { + for(int j=0;j<3;j++) + { + int sfbcnt=-1; + int sfb; + for(sfb=12;sfb>=0;sfb--) + { + int lines; + + { + int t; + + t=sfBandIndex->s[sfb]; + lines=sfBandIndex->s[sfb+1]-t; + i=MUL3(t)+(j+1)*lines-1; + } + + for(;lines>0;lines--,i--) + if(in[1][0][i]!=0.0f) + { + sfbcnt=sfb; + sfb=0;break; // quit loop + } + } + + for(sfb=sfbcnt+1;sfb<12;sfb++) + { + int k,t; + + t=sfBandIndex->s[sfb]; + k=sfBandIndex->s[sfb+1]-t; + i=MUL3(t)+j*k; + + t=scalefactors[1].s[j][sfb]; + if(t!=7) + { + RATIOS r=ratios[t]; + + for(;k>0;k--,i++){ + is_pos[i]=t;is_ratio[i]=r;} + } + else for(;k>0;k--,i++)is_pos[i]=t; + } + + { + int t1=sfBandIndex->s[10], + t2=sfBandIndex->s[11]; + int k,tt; + + tt=MUL3(t1)+j*(t2-t1); + k =sfBandIndex->s[12]-t2; + if(is_pos[tt]!=7) + { + RATIOS r=is_ratio[tt]; + int t=is_pos[tt]; + + i =MUL3(t1)+j*k; + for(;k>0;k--,i++){ + is_pos[i]=t;is_ratio[i]=r;} + } + else + for(;k>0;k--,i++)is_pos[i]=7; + } + } + } + } + else // ms-stereo (Part III) + { + { + REAL temp; + int k; + + temp=in[1][0][0];in[1][0][0]=1.0; + for(k=ARRAYSIZE-1;in[1][0][k]==0.0;k--); + in[1][0][0]=temp; + for(i=0;sfBandIndex->l[i]<=k;i++); + } + + { + int sfb; + + sfb=i; + i=sfBandIndex->l[i]; + for(;sfb<21;sfb++) + { + int k,t; + + k=sfBandIndex->l[sfb+1]-sfBandIndex->l[sfb]; + t=scalefactors[1].l[sfb]; + if(t!=7) + { + RATIOS r=ratios[t]; + + for(;k>0;k--,i++){ + is_pos[i]=t;is_ratio[i]=r;} + } + else + for(;k>0;k--,i++)is_pos[i]=t; + } + } + + { + int k,t,tt; + + tt=sfBandIndex->l[20]; + k=576-sfBandIndex->l[21]; + t=is_pos[tt]; + if(t!=7) + { + RATIOS r=is_ratio[tt]; + + for(;k>0;k--,i++){ + is_pos[i]=t;is_ratio[i]=r;} + } + else + for(;k>0;k--,i++)is_pos[i]=t; + } + } + + if(ms_stereo) + { + i=ARRAYSIZE-1; + do{ + if(is_pos[i]==7) + { + register REAL t=in[LS][0][i]; + in[LS][0][i]=(t+in[RS][0][i])*0.7071068f; + in[RS][0][i]=(t-in[RS][0][i])*0.7071068f; + } + else + { + in[RS][0][i]=in[LS][0][i]*is_ratio[i].r; + in[LS][0][i]*=is_ratio[i].l; + } + }while(i--); + } + else + { + i=ARRAYSIZE-1; + do{ + if(is_pos[i]!=7) + { + in[RS][0][i]=in[LS][0][i]*is_ratio[i].r; + in[LS][0][i]*=is_ratio[i].l; + } + }while(i--); + } + } + else + { + + if(ms_stereo) + { + int i=maxArray-1; + do{ + register REAL t=in[LS][0][i]; + + in[LS][0][i]=(t+in[RS][0][i])*0.7071068f; + in[RS][0][i]=(t-in[RS][0][i])*0.7071068f; + }while(i--); + } + for(int i=maxArray;is[3], + sfb_lines=sfBandIndex->s[4]-sfb_start; + sfb<13; + sfb++,sfb_start=sfBandIndex->s[sfb], + (sfb_lines=sfBandIndex->s[sfb+1]-sfb_start)) + { + for(int freq=0;freqs[1]; + sfb<13; + sfb++,sfb_start=sfBandIndex->s[sfb], + (sfb_lines=sfBandIndex->s[sfb+1]-sfb_start)) + { + for(int freq=0;freqgetVersion(); + int frequency=mpegAudioHeader->getFrequency(); + int mpeg25=mpegAudioHeader->getLayer25(); + register layer3grinfo *gi=&(sideinfo.ch[ch].gr[gr]); + + if(gi->generalflag) { + if(gi->mixed_block_flag) { + layer3reorder_1 (mpeg25?2:version,frequency,in,out); // Not checked... + layer3antialias_1(out); + } + else { + layer3reorder_2(mpeg25?2:version,frequency,in,out); + } + } + else { + + layer3antialias_2(in,out); + + } +} + + +//#include "dct36_12.cpp" +//#include "window.cpp" + +void Mpegtoraw::layer3hybrid(int ch,int gr,REAL in[SBLIMIT][SSLIMIT], + REAL out[SSLIMIT][SBLIMIT]) +{ + layer3grinfo *gi=&(sideinfo.ch[ch].gr[gr]); + int bt1,bt2; + REAL *prev1,*prev2; + + prev1=prevblck[ch][currentprevblock][0]; + prev2=prevblck[ch][currentprevblock^1][0]; + + bt1 = gi->mixed_block_flag ? 0 : gi->block_type; + bt2 = gi->block_type; + + { + REAL *ci=(REAL *)in, + *co=(REAL *)out; + int i; + + if(lDownSample)i=(SBLIMIT/2)-2; + else i=SBLIMIT-2; + + + if(bt2==2) + { + if(!bt1) + { + dct36(ci,prev1,prev2,getSplayWindow(0),co); + ci+=SSLIMIT;prev1+=SSLIMIT;prev2+=SSLIMIT;co++; + dct36(ci,prev1,prev2,getSplayWindowINV(0),co); + } + else + { + dct12(ci,prev1,prev2,getSplayWindow(2),co); + ci+=SSLIMIT;prev1+=SSLIMIT;prev2+=SSLIMIT;co++; + dct12(ci,prev1,prev2,getSplayWindowINV(2),co); + } + + do{ + ci+=SSLIMIT;prev1+=SSLIMIT;prev2+=SSLIMIT;co++; + dct12(ci,prev1,prev2,getSplayWindow(2),co); + i--; + ci+=SSLIMIT;prev1+=SSLIMIT;prev2+=SSLIMIT;co++; + dct12(ci,prev1,prev2,getSplayWindowINV(2),co); + }while(--i); + } + else + { + dct36(ci,prev1,prev2,getSplayWindow(bt1),co); + ci+=SSLIMIT;prev1+=SSLIMIT;prev2+=SSLIMIT;co++; + dct36(ci,prev1,prev2,getSplayWindowINV(bt1),co); + + do + { + ci+=SSLIMIT;prev1+=SSLIMIT;prev2+=SSLIMIT;co++; + dct36(ci,prev1,prev2,getSplayWindow(bt2),co); + i--; + ci+=SSLIMIT;prev1+=SSLIMIT;prev2+=SSLIMIT;co++; + dct36(ci,prev1,prev2,getSplayWindowINV(bt2),co); + }while(--i); + } + } +} + +void Mpegtoraw::extractlayer3(void) { + int version=mpegAudioHeader->getVersion(); + int inputstereo=mpegAudioHeader->getInputstereo(); + int layer3slots=mpegAudioHeader->getLayer3slots(); + + if(version) { + extractlayer3_2(); + return; + } + + { + int main_data_end,flush_main; + int bytes_to_discard; + if (layer3getsideinfo() == false) { + return; + } + // read main data. + if(issync()) { + for(register int i=layer3slots;i>0;i--) { + bitwindow.putbyte(getbyte()); + } + } else { + // read main data. + for(register int i=layer3slots;i>0;i--) { + bitwindow.putbyte(getbits8()); + } + } + + main_data_end=bitwindow.gettotalbit()>>3;// of previous frame + if (main_data_end < 0) { + DEBUG_LAYER(printf("main_data_end < 0\n");) + return; + } + + if((flush_main=(bitwindow.gettotalbit() & 0x7))) { + bitwindow.forward(8-flush_main); + main_data_end++; + } + + bytes_to_discard=layer3framestart-(main_data_end+sideinfo.main_data_begin); + if(main_data_end>WINDOWSIZE) { + layer3framestart-=WINDOWSIZE; + bitwindow.rewind(WINDOWSIZE*8); + } + layer3framestart+=layer3slots; + bitwindow.wrap(); + if(bytes_to_discard<0) return; + bitwindow.forward(bytes_to_discard<<3); + } + for(int gr=0;gr<2;gr++) { + ATTR_ALIGN(64) union + { + int is [SBLIMIT][SSLIMIT]; + REAL hin [2][SBLIMIT][SSLIMIT]; + }b1; + ATTR_ALIGN(64) union + { + REAL ro [2][SBLIMIT][SSLIMIT]; + REAL lr [2][SBLIMIT][SSLIMIT]; + REAL hout [2][SSLIMIT][SBLIMIT]; + }b2; + + layer3part2start=bitwindow.gettotalbit(); + layer3getscalefactors (LS,gr); + + layer3huffmandecode (LS,gr ,b1.is); + layer3dequantizesample(LS,gr,b1.is,b2.ro[LS]); + //dump->dump(b2.ro[LS]); + + if(inputstereo) { + layer3part2start=bitwindow.gettotalbit(); + layer3getscalefactors (RS,gr); + layer3huffmandecode (RS,gr ,b1.is); + layer3dequantizesample(RS,gr,b1.is,b2.ro[RS]); + } + layer3fixtostereo(gr,b2.ro); // b2.ro -> b2.lr + currentprevblock^=1; + + + layer3reorderandantialias(LS,gr,b2.lr[LS],b1.hin[LS]); + //dump->dump(b1.hin[LS]); + layer3hybrid (LS,gr,b1.hin[LS],b2.hout[LS]); + //dump->dump(b2.hout[LS]); + + + + + if(lOutputStereo) { + layer3reorderandantialias(RS,gr,b2.lr[RS],b1.hin[RS]); + layer3hybrid (RS,gr,b1.hin[RS],b2.hout[RS]); + + } + synthesis->doMP3Synth(lDownSample,lOutputStereo,b2.hout); + } +} + +void Mpegtoraw::extractlayer3_2(void) { + int inputstereo=mpegAudioHeader->getInputstereo(); + int layer3slots=mpegAudioHeader->getLayer3slots(); + + { + int main_data_end,flush_main; + int bytes_to_discard; + if (layer3getsideinfo_2() == false) { + return; + } + // read main data. + if(issync()) { + for(register int i=layer3slots;i>0;i--) { + bitwindow.putbyte(getbyte()); + } + } + else { + // read main data. + for(register int i=layer3slots;i>0;i--) { + bitwindow.putbyte(getbits8()); + } + } + + //bitwindow.wrap(); + + main_data_end=bitwindow.gettotalbit()>>3;// of previous frame + if (main_data_end < 0) { + DEBUG_LAYER(printf("main_data_end < 0\n");) + return; + } + + if((flush_main=(bitwindow.gettotalbit() & 0x7))) { + bitwindow.forward(8-flush_main); + main_data_end++; + } + + bytes_to_discard=layer3framestart-(main_data_end+sideinfo.main_data_begin); + if(main_data_end>WINDOWSIZE) { + layer3framestart-=WINDOWSIZE; + bitwindow.rewind(WINDOWSIZE*8); + } + layer3framestart+=layer3slots; + + bitwindow.wrap(); + if(bytes_to_discard<0)return; + bitwindow.forward(bytes_to_discard<<3); + } + + //for(int gr=0;gr<2;gr++) { + ATTR_ALIGN(64) union + { + int is [SBLIMIT][SSLIMIT]; + REAL hin [2][SBLIMIT][SSLIMIT]; + }b1; + ATTR_ALIGN(64) union + { + REAL ro [2][SBLIMIT][SSLIMIT]; + REAL lr [2][SBLIMIT][SSLIMIT]; + REAL hout [2][SSLIMIT][SBLIMIT]; + }b2; + + + layer3part2start=bitwindow.gettotalbit(); + layer3getscalefactors_2(LS); + //dump->dump(&scalefactors[LS]); + + layer3huffmandecode (LS,0 ,b1.is); + //dump->dump(b1.is); + layer3dequantizesample (LS,0,b1.is,b2.ro[LS]); + + if(inputstereo) { + layer3part2start=bitwindow.gettotalbit(); + layer3getscalefactors_2(RS); + layer3huffmandecode (RS,0 ,b1.is); + layer3dequantizesample (RS,0,b1.is,b2.ro[RS]); + } + + layer3fixtostereo(0,b2.ro); // b2.ro -> b2.lr + currentprevblock^=1; + + layer3reorderandantialias(LS,0,b2.lr[LS],b1.hin[LS]); + layer3hybrid (LS,0,b1.hin[LS],b2.hout[LS]); + if(lOutputStereo) { + layer3reorderandantialias(RS,0,b2.lr[RS],b1.hin[RS]); + layer3hybrid (RS,0,b1.hin[RS],b2.hout[RS]); + } + synthesis->doMP3Synth(lDownSample,lOutputStereo,b2.hout); + + +} + + diff --git a/Libraries/DecMPA/Files/src/splay/mpegsound.h b/Libraries/DecMPA/Files/src/splay/mpegsound.h new file mode 100644 index 000000000..5a0118405 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpegsound.h @@ -0,0 +1,252 @@ +// MPEG/WAVE Sound library + +// (C) 1997 by Woo-jae Jung + +// Mpegsound.h +// This is typeset for functions in MPEG/WAVE Sound library. +// Now, it's for only linux-pc-?86 + +//changes 8/4/2002 (by Hauke Duden): +// - removed dump stuff + + +/************************************/ +/* Include default library packages */ +/************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + + +#include "mpegAudioStream.h" +#include "common.h" + +class Synthesis; +class AudioFrame; + + +#ifndef _L__SOUND__ +#define _L__SOUND__ + +#include "../mpegAudioFrame/mpegAudioHeader.h" +#include "mpegAudioBitWindow.h" + + +//#define DEBUG_LAYER(x) x +#define DEBUG_LAYER(x) + + +/**************************/ +/* Define values for MPEG */ +/**************************/ +#define SCALEBLOCK 12 +#define MAXSUBBAND 32 +#define MAXCHANNEL 2 +#define RAWDATASIZE (2*2*2*32*SSLIMIT) + + + +// Huffmancode +#define HTN 34 + + + +#define MODE_MONO 0 +#define MODE_STEREO 1 + +/********************/ +/* Type definitions */ +/********************/ + +typedef struct { + bool generalflag; + unsigned int part2_3_length; + unsigned int big_values; + unsigned int global_gain; + unsigned int scalefac_compress; + unsigned int window_switching_flag; + unsigned int block_type; + unsigned int mixed_block_flag; + unsigned int table_select[3]; + unsigned int subblock_gain[3]; + unsigned int region0_count; + unsigned int region1_count; + unsigned int preflag; + unsigned int scalefac_scale; + unsigned int count1table_select; +}layer3grinfo; + +typedef struct { + unsigned main_data_begin; + unsigned private_bits; + struct { + unsigned scfsi[4]; + layer3grinfo gr[2]; + }ch[2]; +}layer3sideinfo; + +typedef struct { + int l[23]; /* [cb] */ + int s[3][13]; /* [window][cb] */ +}layer3scalefactor; /* [ch] */ + +typedef struct { + int tablename; + unsigned int xlen,ylen; + unsigned int linbits; + unsigned int treelen; + const unsigned int (*val)[2]; +}HUFFMANCODETABLE; + + + + + + + +class DCT; +//class Dump; + +// Class for converting mpeg format to raw format +class Mpegtoraw { + /*****************************/ + /* Constant tables for layer */ + /*****************************/ +private: + static const int bitrate[2][3][15]; + static const int frequencies[2][3]; + static const REAL scalefactorstable[64]; + ATTR_ALIGN(64) static const HUFFMANCODETABLE ht[HTN]; + + + friend class HuffmanLookup; + + /*************************/ + /* MPEG header variables */ + /*************************/ + + // comes from constructor, decoder works on them + MpegAudioStream* mpegAudioStream; + MpegAudioHeader* mpegAudioHeader; + AudioFrame* audioFrame; + //Dump* dump; + Synthesis* synthesis; + + /***************************************/ + /* Interface for setting music quality */ + /***************************************/ + + int lWantStereo; + int lOutputStereo; + int lDownSample; + +public: + Mpegtoraw(MpegAudioStream* mpegAudioStream, + MpegAudioHeader* mpegAudioHeader); + + + ~Mpegtoraw(); + int decode(AudioFrame* audioFrame); + + + void setStereo(int lStereo); + int getStereo(); + + void setDownSample(int lDownSample); + int getDownSample(); + + + +private: + void initialize(); + + + + /*****************************/ + /* Loading MPEG-Audio stream */ + /*****************************/ + + union + { + unsigned char store[4]; + unsigned int current; + }u; + + + int getbyte() { return mpegAudioStream->getbyte(); } + int getbits(int bits) { return mpegAudioStream->getbits(bits); } + int getbits9(int bits) { return mpegAudioStream->getbits9(bits); } + int getbits8() { return mpegAudioStream->getbits8(); } + int getbit() { return mpegAudioStream->getbit(); } + + + void sync() { mpegAudioStream->sync(); } + bool issync() { return mpegAudioStream->issync()!=0; } + + + /********************/ + /* Global variables */ + /********************/ + + // optimisation from maplay12+ + // 0/1: nonzero for channel 0/1 2: max position for both + int nonzero[3]; + + // for Layer3 + + int layer3framestart; + int layer3part2start; + + ATTR_ALIGN(64) REAL prevblck[2][2][SBLIMIT][SSLIMIT]; + int currentprevblock; + ATTR_ALIGN(64) layer3sideinfo sideinfo; + ATTR_ALIGN(64) layer3scalefactor scalefactors[2]; + + ATTR_ALIGN(64) MpegAudioBitWindow bitwindow; + MpegAudioBitWindow lastValidBitwindow; + + int wgetbit(void); + int wgetbits9(int bits); + int wgetbits(int bits); + int wgetCanReadBits(); + + /*************************************/ + /* Decoding functions for each layer */ + /*************************************/ + + // Extractor + void extractlayer1(void); // MPEG-1 + void extractlayer2(void); + void extractlayer3(void); + void extractlayer3_2(void); // MPEG-2 + + + // Functions for layer 3 + void layer3initialize(void); + bool layer3getsideinfo(void); + bool layer3getsideinfo_2(void); + void layer3getscalefactors(int ch,int gr); + void layer3getscalefactors_2(int ch); + void layer3huffmandecode(int ch,int gr,int out[SBLIMIT][SSLIMIT]); + REAL layer3twopow2(int scale,int preflag,int pretab_offset,int l); + REAL layer3twopow2_1(int a,int b,int c); + void layer3dequantizesample(int ch,int gr,int in[SBLIMIT][SSLIMIT], + REAL out[SBLIMIT][SSLIMIT]); + void adjustNonZero(REAL in[2][SBLIMIT][SSLIMIT]); + void layer3fixtostereo(int gr,REAL in[2][SBLIMIT][SSLIMIT]); + void layer3reorderandantialias(int ch,int gr,REAL in[SBLIMIT][SSLIMIT], + REAL out[SBLIMIT][SSLIMIT]); + + void layer3hybrid(int ch,int gr,REAL in[SBLIMIT][SSLIMIT], + REAL out[SSLIMIT][SBLIMIT]); + + void huffmandecoder_1(const HUFFMANCODETABLE *h,int *x,int *y); + void huffmandecoder_2(const HUFFMANCODETABLE *h,int *x,int *y,int *v,int *w); + +}; + + + +#endif diff --git a/Libraries/DecMPA/Files/src/splay/mpegtable.cpp b/Libraries/DecMPA/Files/src/splay/mpegtable.cpp new file mode 100644 index 000000000..5695ac4fa --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpegtable.cpp @@ -0,0 +1,43 @@ +/* MPEG/WAVE Sound library + + (C) 1997 by Jung woo-jae */ + +// Mpegtable.cc +// It has tables for MPEG layer 1, 2 and a part of layer 3 + +//changes 8/4/2002 (by Hauke Duden): +// - added VC6 pragma to prevent some warnings from being reported + + +#include "mpegsound.h" + +#ifdef _MSC_VER +#pragma warning(disable : 4305) +#endif + + +// Mpeg general table +const REAL Mpegtoraw::scalefactorstable[64] = +{ + 2.00000000000000, 1.58740105196820, 1.25992104989487, 1.00000000000000, + 0.79370052598410, 0.62996052494744, 0.50000000000000, 0.39685026299205, + 0.31498026247372, 0.25000000000000, 0.19842513149602, 0.15749013123686, + 0.12500000000000, 0.09921256574801, 0.07874506561843, 0.06250000000000, + 0.04960628287401, 0.03937253280921, 0.03125000000000, 0.02480314143700, + 0.01968626640461, 0.01562500000000, 0.01240157071850, 0.00984313320230, + 0.00781250000000, 0.00620078535925, 0.00492156660115, 0.00390625000000, + 0.00310039267963, 0.00246078330058, 0.00195312500000, 0.00155019633981, + 0.00123039165029, 0.00097656250000, 0.00077509816991, 0.00061519582514, + 0.00048828125000, 0.00038754908495, 0.00030759791257, 0.00024414062500, + 0.00019377454248, 0.00015379895629, 0.00012207031250, 0.00009688727124, + 0.00007689947814, 0.00006103515625, 0.00004844363562, 0.00003844973907, + 0.00003051757813, 0.00002422181781, 0.00001922486954, 0.00001525878906, + 0.00001211090890, 0.00000961243477, 0.00000762939453, 0.00000605545445, + 0.00000480621738, 0.00000381469727, 0.00000302772723, 0.00000240310869, + 0.00000190734863, 0.00000151386361, 0.00000120155435, 0.00000000000000 +}; + +#ifdef _MSC_VER +#pragma warning(default : 4305) +#endif + diff --git a/Libraries/DecMPA/Files/src/splay/mpegtoraw.cpp b/Libraries/DecMPA/Files/src/splay/mpegtoraw.cpp new file mode 100644 index 000000000..db65b1fde --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/mpegtoraw.cpp @@ -0,0 +1,137 @@ +/* MPEG/WAVE Sound library + + (C) 1997 by Jung woo-jae */ + +// Mpegtoraw.cc +// Server which get mpeg format and put raw format. + +//changes 8/4/2002 (by Hauke Duden): +// - added #include to ensure that bad_alloc will be thrown on mem error +// - removed dump stuff + +//changes 8/15/2002 (by Hauke Duden): +// - set downsample to true, by default + +//changes 8/17/2002 (by Hauke Duden): +// - set downsample to false again - it only reduced the frequency by half instead +// of synthesizing with twice the frequency and THEN reducing it by half + + +#include "mpegsound.h" +#include "synthesis.h" +//#include "dump.h" +#include "../frame/audioFrame.h" + +#include + + +Mpegtoraw::Mpegtoraw(MpegAudioStream* mpegAudioStream, + MpegAudioHeader* mpegAudioHeader) { + + this->mpegAudioStream=mpegAudioStream; + this->mpegAudioHeader=mpegAudioHeader; + + this->lOutputStereo=true; + setStereo(true); + setDownSample(false); + + //dump=new Dump(); + synthesis=new Synthesis(); + initialize(); + +} + +Mpegtoraw::~Mpegtoraw() { + + delete synthesis; + //delete dump; +} + + + + + + + +void Mpegtoraw::setStereo(int flag) { + lWantStereo=flag; +} + +void Mpegtoraw::setDownSample(int flag) { + lDownSample=flag; +} + +int Mpegtoraw::getStereo() { + return lWantStereo; +} + +int Mpegtoraw::getDownSample() { + return lDownSample; +} + + + + + + + +// Convert mpeg to raw +// Mpeg headder class +void Mpegtoraw::initialize() { + + + + layer3initialize(); + + +}; + + + + + +// Convert mpeg to raw +int Mpegtoraw::decode(AudioFrame* audioFrame) { + int back=true; + + this->audioFrame=audioFrame; + /*if (audioFrame->getSize() < RAWDATASIZE) { + cout << "audioFrame needs at least:"<clearrawdata(); + synthesis->clearrawdata(); + + int layer=mpegAudioHeader->getLayer(); + this->lOutputStereo=lWantStereo & mpegAudioHeader->getInputstereo(); + + if (mpegAudioHeader->getProtection()==false) { + mpegAudioStream->getbyte(); + mpegAudioStream->getbyte(); + } + switch(layer) { + case 3: + extractlayer3(); + break; + case 2: + extractlayer2(); + break; + case 1: + extractlayer1(); + break; + default: + //cout << "unknown layer:"<setFrameFormat(lOutputStereo, + mpegAudioHeader->getFrequencyHz()>>lDownSample); + + audioFrame->putFloatData(synthesis->getOutputData(),synthesis->getLen()); + return back; + +} diff --git a/Libraries/DecMPA/Files/src/splay/op.h b/Libraries/DecMPA/Files/src/splay/op.h new file mode 100644 index 000000000..77ace9f39 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/op.h @@ -0,0 +1,96 @@ +/* + unrolled operations, for better Pentium FPU scheduling + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + + + +#ifndef __OP_H +#define __OP_H + +/** + The Pentium has two pipelined FPUs which makes it possible + to do two operations in one cycle. + (If you are lucky) + +*/ + +#define PTR_DIST (1024) + +#define OS r1=vp1[0] * dp[0]; \ + r2=vp1[PTR_DIST-0] * dp[0]; \ + dp++; + +#define XX1 vp1+=15;dp++; + +#define XX2 r1+=vp1[0] * dp[-1]; \ + r2+=vp1[PTR_DIST-0] * dp[-1]; + +#define OP_END(val) vp1-=val;dp+=val; + +#define OP_END_1(vVal,dVal) vp1+=(vVal-dVal),dp+=dVal + + +// this is OP_END(x);XX1; together: +#define OP_END_2(vVal) vp1+=(15-vVal),dp+=vVal+1 + + +// check this to test pipelining + +#define SCHEDULE1(op,r1,r2) r1;op;r2; +#define SCHEDULE2(op,r1,r2) op;r1;r2; + +#define SCHEDULE(a,b,c) SCHEDULE2(a,b,c); + + +#define OP r1+=vp1[-1] * dp[0]; \ + r2+=vp1[PTR_DIST-1] * dp[0]; + + + +#define OP2 SCHEDULE(OP ,r1+=vp1[-2] * dp[1] ,r2+=vp1[PTR_DIST-2] *dp[1]); +#define OP3 SCHEDULE(OP2 ,r1+=vp1[-3] * dp[2] ,r2+=vp1[PTR_DIST-3] *dp[2]); +#define OP4 SCHEDULE(OP3 ,r1+=vp1[-4] * dp[3] ,r2+=vp1[PTR_DIST-4] *dp[3]); +#define OP5 SCHEDULE(OP4 ,r1+=vp1[-5] * dp[4] ,r2+=vp1[PTR_DIST-5] *dp[4]); +#define OP6 SCHEDULE(OP5 ,r1+=vp1[-6] * dp[5] ,r2+=vp1[PTR_DIST-6] *dp[5]); +#define OP7 SCHEDULE(OP6 ,r1+=vp1[-7] * dp[6] ,r2+=vp1[PTR_DIST-7] *dp[6]); +#define OP8 SCHEDULE(OP7 ,r1+=vp1[-8] * dp[7] ,r2+=vp1[PTR_DIST-8] *dp[7]); +#define OP9 SCHEDULE(OP8 ,r1+=vp1[-9] * dp[8] ,r2+=vp1[PTR_DIST-9] *dp[8]); +#define OP10 SCHEDULE(OP9 ,r1+=vp1[-10] * dp[9] ,r2+=vp1[PTR_DIST-10] *dp[9]); +#define OP11 SCHEDULE(OP10,r1+=vp1[-11] * dp[10],r2+=vp1[PTR_DIST-11] *dp[10]); +#define OP12 SCHEDULE(OP11,r1+=vp1[-12] * dp[11],r2+=vp1[PTR_DIST-12] *dp[11]); +#define OP13 SCHEDULE(OP12,r1+=vp1[-13] * dp[12],r2+=vp1[PTR_DIST-13] *dp[12]); +#define OP14 SCHEDULE(OP13,r1+=vp1[-14] * dp[13],r2+=vp1[PTR_DIST-14] *dp[13]); +#define OP15 SCHEDULE(OP14,r1+=vp1[-15] * dp[14],r2+=vp1[PTR_DIST-15] *dp[14]); + + +/* +#define OP r1+=vp1[-1] * dp[0]; \ + r2+=vp2[-1] * dp[0]; + + + +#define OP2 SCHEDULE(OP ,r1+=vp1[-2] * dp[1] ,r2+=vp2[-2] * dp[1]); +#define OP3 SCHEDULE(OP2 ,r1+=vp1[-3] * dp[2] ,r2+=vp2[-3] * dp[2]); +#define OP4 SCHEDULE(OP3 ,r1+=vp1[-4] * dp[3] ,r2+=vp2[-4] * dp[3]); +#define OP5 SCHEDULE(OP4 ,r1+=vp1[-5] * dp[4] ,r2+=vp2[-5] * dp[4]); +#define OP6 SCHEDULE(OP5 ,r1+=vp1[-6] * dp[5] ,r2+=vp2[-6] * dp[5]); +#define OP7 SCHEDULE(OP6 ,r1+=vp1[-7] * dp[6] ,r2+=vp2[-7] * dp[6]); +#define OP8 SCHEDULE(OP7 ,r1+=vp1[-8] * dp[7] ,r2+=vp2[-8] * dp[7]); +#define OP9 SCHEDULE(OP8 ,r1+=vp1[-9] * dp[8] ,r2+=vp2[-9] * dp[8]); +#define OP10 SCHEDULE(OP9 ,r1+=vp1[-10] * dp[9] ,r2+=vp2[-10] * dp[9]); +#define OP11 SCHEDULE(OP10,r1+=vp1[-11] * dp[10],r2+=vp2[-11] * dp[10]); +#define OP12 SCHEDULE(OP11,r1+=vp1[-12] * dp[11],r2+=vp2[-12] * dp[11]); +#define OP13 SCHEDULE(OP12,r1+=vp1[-13] * dp[12],r2+=vp2[-13] * dp[12]); +#define OP14 SCHEDULE(OP13,r1+=vp1[-14] * dp[13],r2+=vp2[-14] * dp[13]); +#define OP15 SCHEDULE(OP14,r1+=vp1[-15] * dp[14],r2+=vp2[-15] * dp[14]); +*/ + +#endif diff --git a/Libraries/DecMPA/Files/src/splay/splayDecoder.cpp b/Libraries/DecMPA/Files/src/splay/splayDecoder.cpp new file mode 100644 index 000000000..b80e31c28 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/splayDecoder.cpp @@ -0,0 +1,85 @@ +/* + decoder interface for the splay mp3 decoder. + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - added #include to ensure that bad_alloc will be thrown on mem error +// - removed dump stuff +// - added function to access header from outside + +#define _FROM_SOURCE +#include "../mpegAudioFrame/dxHead.h" +#include "splayDecoder.h" +#include "mpegsound.h" + +#include +#include + + +SplayDecoder::SplayDecoder() { + header = new MpegAudioHeader(); + stream = new MpegAudioStream(); + server = new Mpegtoraw(stream,header); + + xHeadData=new XHEADDATA(); + xHeadData->toc=new unsigned char[101]; + //dump=new Dump(); +} + + +SplayDecoder::~SplayDecoder() { + delete (xHeadData->toc); + delete xHeadData; + + delete server; + delete header; + delete stream; + //delete dump; +} + + + +int SplayDecoder::decode(unsigned char* ptr, int len,AudioFrame* dest) { + int back; + // fist setup the stream and the 4 bytes header info; + //dump->dump((char*)ptr,len); + if (header->parseHeader(ptr) == false) { + return false; + } + // maybe a Xing Header? + if (len >= 152+4) { + int lXing=GetXingHeader(xHeadData,(unsigned char*)ptr); + if (lXing) { + return false; + } + } + stream->setFrame(ptr+4,len-4); + back=server->decode(dest); + + return back; + +} + + +void SplayDecoder::config(const char* key,const char* val,void* ) { + if (strcmp(key,"2")==0) { + server->setDownSample(atoi(val)); + } + if (strcmp(key,"m")==0) { + server->setStereo(atoi(val)); + } +} + +MpegAudioHeader* SplayDecoder::GetMPEGAudioHeader() +{ + return header; +} + diff --git a/Libraries/DecMPA/Files/src/splay/splayDecoder.h b/Libraries/DecMPA/Files/src/splay/splayDecoder.h new file mode 100644 index 000000000..be797d4a4 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/splayDecoder.h @@ -0,0 +1,75 @@ +/* + decoder interface for the splay mp3 decoder. + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - removed dump stuff +// - added function to access header from outside + +//changes 8/11/2002 (by Hauke Duden): +// - removed unnecessary includes + +#ifndef __SPLAYDECODER_H +#define __SPLAYDECODER_H + +// state definitions for splay decoder + +#define _SPLAY_RESET 0 +#define _SPLAY_EOF 1 +#define _SPLAY_FIRSTINIT 2 +#define _SPLAY_REINIT 3 +#define _SPLAY_DECODE 4 +#define _SPLAY_FRAME 5 + + +#include "../frame/audioFrame.h" +//#include "dump.h" +//#include + +class Mpegtoraw; +class MpegAudioStream; +class MpegAudioHeader; + + +/** + The decoder interface. + The decoder expects an mpeg audio frame. + The call to decode is "atomic", after that you have + a PCMFrame to play. + +*/ + + + +class SplayDecoder { + + MpegAudioStream* stream; + MpegAudioHeader* header; + Mpegtoraw* server; + //Dump* dump; +#ifdef _FROM_SOURCE + XHEADDATA* xHeadData; +#else + void* xHeadData; +#endif + + + public: + SplayDecoder(); + ~SplayDecoder(); + + int decode(unsigned char* ptr, int len,AudioFrame* dest); + void config(const char* key,const char* val,void* ret); + + MpegAudioHeader* GetMPEGAudioHeader(); + +}; +#endif diff --git a/Libraries/DecMPA/Files/src/splay/synth_Down.cpp b/Libraries/DecMPA/Files/src/splay/synth_Down.cpp new file mode 100644 index 000000000..7fef84ff5 --- /dev/null +++ b/Libraries/DecMPA/Files/src/splay/synth_Down.cpp @@ -0,0 +1,231 @@ +/* + downsample implementation + Copyright (C) 2001 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file License.txt in this package + + */ + +//changes 8/4/2002 (by Hauke Duden): +// - removed cout and exit stuff + +#include "synthesis.h" +#include "dct.h" + +void Synthesis::computebuffer_Down(REAL *fraction, + REAL buffer[2][CALCBUFFERSIZE]){ + REAL *out1,*out2; + + out1=buffer[currentcalcbuffer]+calcbufferoffset; + out2=buffer[currentcalcbuffer^1]+calcbufferoffset; + dct64_downsample(out1,out2,fraction); +} + + + +#define SAVE putraw(r); \ + dp+=16;vp+=15+(15-14) +#define OS r=*vp * *dp++ +#define XX vp+=15;r+=*vp * *dp++ +#define OP r+=*--vp * *dp++ + +inline void Synthesis::generatesingle_Down(void) +{ + int i; + register REAL r, *vp; + register const REAL *dp; + + i=32/2; + dp=filter; + vp=calcbuffer[LS][currentcalcbuffer]+calcbufferoffset; +// actual_v+actual_write_pos; + + switch (calcbufferoffset) + { + case 0:for(;i;i--,vp+=15){ + OS;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 1:for(;i;i--,vp+=15){ + OS;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 2:for(;i;i--,vp+=15){ + OS;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 3:for(;i;i--,vp+=15){ + OS;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 4:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 5:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 6:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 7:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 8:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 9:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP; + SAVE;}break; + case 10:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP; + SAVE;}break; + case 11:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP; + SAVE;}break; + case 12:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP; + SAVE;}break; + case 13:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP; + SAVE;}break; + case 14:for(;i;i--,vp+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX; + SAVE;}break; + case 15:for(;i;i--,vp+=31){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + } +} + +#undef OS +#undef XX +#undef OP +#undef SAVE + +#define SAVE \ + putraw(r1); \ + putraw(r2); \ + dp+=16;vp1+=15+(15-14);vp2+=15+(15-14) +#define OS r1=*vp1 * *dp; \ + r2=*vp2 * *dp++ +#define XX vp1+=15;r1+=*vp1 * *dp; \ + vp2+=15;r2+=*vp2 * *dp++ +#define OP r1+=*--vp1 * *dp; \ + r2+=*--vp2 * *dp++ + + +inline void Synthesis::generate_Down(void) +{ + int i; + REAL r1,r2; + register REAL *vp1,*vp2; + register const REAL *dp; + + dp=filter; + vp1=calcbuffer[LS][currentcalcbuffer]+calcbufferoffset; + vp2=calcbuffer[RS][currentcalcbuffer]+calcbufferoffset; +// actual_v+actual_write_pos; + + i=32/2; + switch (calcbufferoffset) + { + case 0:for(;i;i--,vp1+=15,vp2+=15){ + OS;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 1:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 2:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 3:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 4:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 5:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 6:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 7:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 8:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP;OP; + SAVE;}break; + case 9:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP;OP; + SAVE;}break; + case 10:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP;OP; + SAVE;}break; + case 11:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP;OP; + SAVE;}break; + case 12:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP;OP; + SAVE;}break; + case 13:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX;OP; + SAVE;}break; + case 14:for(;i;i--,vp1+=15,vp2+=15){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;XX; + SAVE;}break; + case 15:for(;i;i--,vp1+=31,vp2+=31){ + OS;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP;OP; + SAVE;}break; + } +} + + + +void Synthesis::synth_Down(int lOutputStereo,REAL *fractionL,REAL *fractionR) { + switch(lOutputStereo) { + case true: + computebuffer_Down(fractionL,calcbuffer[LS]); + computebuffer_Down(fractionR,calcbuffer[RS]); + generate_Down(); + nextOffset(); + break; + case false: + computebuffer_Down(fractionL,calcbuffer[LS]); + generatesingle_Down(); + nextOffset(); + break; + default: + /*cout << "unknown lOutputStereo in Synthesis::synth_Std"<=0;i--) + calcbuffer[LS][0][i]=calcbuffer[LS][1][i]= + calcbuffer[RS][0][i]=calcbuffer[RS][1][i]=0.0; + + initialize_dct64(); + initialize_dct64_downsample(); +} + + +Synthesis::~Synthesis() { +} + + +void Synthesis::doSynth(int lDownSample,int lOutputStereo, + REAL *fractionL,REAL *fractionR) { + switch(lDownSample) { + case false: + synth_Std(lOutputStereo,fractionL,fractionR); + break; + case true: + synth_Down(lOutputStereo,fractionL,fractionR); + break; + default: + /*cout << "unknown downsample parameter"< + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleName + ${PRODUCT_NAME} + CFBundleIconFile + + CFBundleIdentifier + com.yourcompany.yourcocoaframework + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleSignature + ???? + CFBundleVersion + 1.0 + NSPrincipalClass + + +