Browse Source

Updated VGMStream to r1050-2895-g772fe03e

master
Christopher Snowhill 4 months ago
parent
commit
38b5dd6e3f
64 changed files with 14448 additions and 3123 deletions
  1. +64
    -12
      Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj
  2. +5
    -0
      Frameworks/vgmstream/vgmstream/src/coding/asf_decoder.c
  3. +109
    -29
      Frameworks/vgmstream/vgmstream/src/coding/circus_decoder.c
  4. +492
    -0
      Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.c
  5. +16
    -0
      Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.h
  6. +347
    -0
      Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib_data.h
  7. +297
    -0
      Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lzxpcm.h
  8. +7657
    -0
      Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_miniz.c
  9. +1346
    -0
      Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_miniz.h
  10. +9
    -2
      Frameworks/vgmstream/vgmstream/src/coding/coding.h
  11. +8
    -3
      Frameworks/vgmstream/vgmstream/src/coding/ima_decoder.c
  12. +10
    -10
      Frameworks/vgmstream/vgmstream/src/coding/psv_decoder.c
  13. +15
    -18
      Frameworks/vgmstream/vgmstream/src/coding/psx_decoder.c
  14. +152
    -145
      Frameworks/vgmstream/vgmstream/src/coding/vorbis_custom_utils_vid1.c
  15. +16
    -3
      Frameworks/vgmstream/vgmstream/src/formats.c
  16. +6
    -0
      Frameworks/vgmstream/vgmstream/src/layout/blocked.c
  17. +57
    -0
      Frameworks/vgmstream/vgmstream/src/layout/blocked_ubi_sce.c
  18. +61
    -0
      Frameworks/vgmstream/vgmstream/src/layout/blocked_vid1.c
  19. +2
    -0
      Frameworks/vgmstream/vgmstream/src/layout/layout.h
  20. +75
    -265
      Frameworks/vgmstream/vgmstream/src/meta/Cstr.c
  21. +4
    -1
      Frameworks/vgmstream/vgmstream/src/meta/adx_keys.h
  22. +18
    -13
      Frameworks/vgmstream/vgmstream/src/meta/awc.c
  23. +114
    -245
      Frameworks/vgmstream/vgmstream/src/meta/awc_xma_streamfile.h
  24. +126
    -0
      Frameworks/vgmstream/vgmstream/src/meta/bkhd.c
  25. +119
    -74
      Frameworks/vgmstream/vgmstream/src/meta/bnk_sony.c
  26. +5
    -1
      Frameworks/vgmstream/vgmstream/src/meta/bnsf.c
  27. +3
    -2
      Frameworks/vgmstream/vgmstream/src/meta/deblock_streamfile.c
  28. +3
    -1
      Frameworks/vgmstream/vgmstream/src/meta/ea_eaac.c
  29. +86
    -0
      Frameworks/vgmstream/vgmstream/src/meta/encrypted.c
  30. +629
    -629
      Frameworks/vgmstream/vgmstream/src/meta/fsb5.c
  31. +0
    -201
      Frameworks/vgmstream/vgmstream/src/meta/fsb5_interleave_streamfile.h
  32. +21
    -0
      Frameworks/vgmstream/vgmstream/src/meta/fsb5_streamfile.h
  33. +1
    -0
      Frameworks/vgmstream/vgmstream/src/meta/hca_keys.h
  34. +88
    -30
      Frameworks/vgmstream/vgmstream/src/meta/isb.c
  35. +6
    -1
      Frameworks/vgmstream/vgmstream/src/meta/meta.h
  36. +0
    -2
      Frameworks/vgmstream/vgmstream/src/meta/mp4.c
  37. +269
    -164
      Frameworks/vgmstream/vgmstream/src/meta/mul.c
  38. +65
    -0
      Frameworks/vgmstream/vgmstream/src/meta/mul_streamfile.h
  39. +0
    -75
      Frameworks/vgmstream/vgmstream/src/meta/ngc_vid1.c
  40. +32
    -20
      Frameworks/vgmstream/vgmstream/src/meta/nps.c
  41. +4
    -1
      Frameworks/vgmstream/vgmstream/src/meta/ogg_opus.c
  42. +5
    -5
      Frameworks/vgmstream/vgmstream/src/meta/opus.c
  43. +47
    -136
      Frameworks/vgmstream/vgmstream/src/meta/opus_interleave_streamfile.h
  44. +7
    -6
      Frameworks/vgmstream/vgmstream/src/meta/riff.c
  45. +576
    -346
      Frameworks/vgmstream/vgmstream/src/meta/sqex_sead.c
  46. +67
    -86
      Frameworks/vgmstream/vgmstream/src/meta/sqex_sead_streamfile.h
  47. +37
    -16
      Frameworks/vgmstream/vgmstream/src/meta/txth.c
  48. +141
    -32
      Frameworks/vgmstream/vgmstream/src/meta/ubi_ckd.c
  49. +16
    -39
      Frameworks/vgmstream/vgmstream/src/meta/ubi_lyn.c
  50. +0
    -92
      Frameworks/vgmstream/vgmstream/src/meta/ubi_lyn_ogg_streamfile.h
  51. +23
    -0
      Frameworks/vgmstream/vgmstream/src/meta/ubi_lyn_streamfile.h
  52. +35
    -7
      Frameworks/vgmstream/vgmstream/src/meta/ubi_sb.c
  53. +135
    -0
      Frameworks/vgmstream/vgmstream/src/meta/vid1.c
  54. +6
    -4
      Frameworks/vgmstream/vgmstream/src/meta/vpk.c
  55. +11
    -2
      Frameworks/vgmstream/vgmstream/src/meta/wwise.c
  56. +246
    -187
      Frameworks/vgmstream/vgmstream/src/meta/xnb.c
  57. +266
    -0
      Frameworks/vgmstream/vgmstream/src/meta/xnb_lz4mg.h
  58. +300
    -0
      Frameworks/vgmstream/vgmstream/src/meta/xnb_streamfile.h
  59. +82
    -69
      Frameworks/vgmstream/vgmstream/src/meta/xpcm.c
  60. +26
    -125
      Frameworks/vgmstream/vgmstream/src/meta/xwma_konami_streamfile.h
  61. +44
    -16
      Frameworks/vgmstream/vgmstream/src/streamfile.c
  62. +9
    -2
      Frameworks/vgmstream/vgmstream/src/streamfile.h
  63. +27
    -4
      Frameworks/vgmstream/vgmstream/src/vgmstream.c
  64. +5
    -2
      Frameworks/vgmstream/vgmstream/src/vgmstream.h

+ 64
- 12
Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj View File

@@ -11,6 +11,22 @@
8301659A1F256BD000CA0941 /* txth.c in Sources */ = {isa = PBXBuildFile; fileRef = 830165971F256BD000CA0941 /* txth.c */; };
8301659B1F256BD000CA0941 /* ea_schl_fixed.c in Sources */ = {isa = PBXBuildFile; fileRef = 830165981F256BD000CA0941 /* ea_schl_fixed.c */; };
8301659C1F256BD000CA0941 /* nds_strm_ffta2.c in Sources */ = {isa = PBXBuildFile; fileRef = 830165991F256BD000CA0941 /* nds_strm_ffta2.c */; };
83031EC4243C50A800C3F3E0 /* circus_decoder_miniz.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031EBE243C50A700C3F3E0 /* circus_decoder_miniz.h */; };
83031EC5243C50A800C3F3E0 /* circus_decoder_lib_data.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031EBF243C50A800C3F3E0 /* circus_decoder_lib_data.h */; };
83031EC6243C50A800C3F3E0 /* circus_decoder_miniz.c in Sources */ = {isa = PBXBuildFile; fileRef = 83031EC0243C50A800C3F3E0 /* circus_decoder_miniz.c */; };
83031EC7243C50A800C3F3E0 /* circus_decoder_lib.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031EC1243C50A800C3F3E0 /* circus_decoder_lib.h */; };
83031EC8243C50A800C3F3E0 /* circus_decoder_lib.c in Sources */ = {isa = PBXBuildFile; fileRef = 83031EC2243C50A800C3F3E0 /* circus_decoder_lib.c */; };
83031EC9243C50A800C3F3E0 /* circus_decoder_lzxpcm.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031EC3243C50A800C3F3E0 /* circus_decoder_lzxpcm.h */; };
83031ECC243C50CC00C3F3E0 /* blocked_ubi_sce.c in Sources */ = {isa = PBXBuildFile; fileRef = 83031ECA243C50CB00C3F3E0 /* blocked_ubi_sce.c */; };
83031ECD243C50CC00C3F3E0 /* blocked_vid1.c in Sources */ = {isa = PBXBuildFile; fileRef = 83031ECB243C50CB00C3F3E0 /* blocked_vid1.c */; };
83031ED1243C50DF00C3F3E0 /* encrypted.c in Sources */ = {isa = PBXBuildFile; fileRef = 83031ECE243C50DE00C3F3E0 /* encrypted.c */; };
83031ED2243C50DF00C3F3E0 /* bkhd.c in Sources */ = {isa = PBXBuildFile; fileRef = 83031ECF243C50DE00C3F3E0 /* bkhd.c */; };
83031ED3243C50DF00C3F3E0 /* fsb5_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031ED0243C50DF00C3F3E0 /* fsb5_streamfile.h */; };
83031ED9243C510500C3F3E0 /* ubi_lyn_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031ED4243C510400C3F3E0 /* ubi_lyn_streamfile.h */; };
83031EDA243C510500C3F3E0 /* mul_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031ED5243C510400C3F3E0 /* mul_streamfile.h */; };
83031EDB243C510500C3F3E0 /* xnb_lz4mg.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031ED6243C510400C3F3E0 /* xnb_lz4mg.h */; };
83031EDC243C510500C3F3E0 /* vid1.c in Sources */ = {isa = PBXBuildFile; fileRef = 83031ED7243C510400C3F3E0 /* vid1.c */; };
83031EDD243C510500C3F3E0 /* xnb_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 83031ED8243C510500C3F3E0 /* xnb_streamfile.h */; };
8306B08420984518000302D4 /* at3plus_decoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 8306B08120984517000302D4 /* at3plus_decoder.c */; };
8306B08520984518000302D4 /* yamaha_decoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 8306B08220984517000302D4 /* yamaha_decoder.c */; };
8306B08620984518000302D4 /* fadpcm_decoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 8306B08320984517000302D4 /* fadpcm_decoder.c */; };
@@ -48,7 +64,6 @@
8306B0DE20984590000302D4 /* awc_xma_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 8306B0C32098458C000302D4 /* awc_xma_streamfile.h */; };
8306B0DF20984590000302D4 /* ea_wve_ad10.c in Sources */ = {isa = PBXBuildFile; fileRef = 8306B0C42098458D000302D4 /* ea_wve_ad10.c */; };
8306B0E020984590000302D4 /* ppst_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 8306B0C52098458D000302D4 /* ppst_streamfile.h */; };
8306B0E120984590000302D4 /* ubi_lyn_ogg_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 8306B0C62098458D000302D4 /* ubi_lyn_ogg_streamfile.h */; };
8306B0E220984590000302D4 /* smv.c in Sources */ = {isa = PBXBuildFile; fileRef = 8306B0C72098458D000302D4 /* smv.c */; };
8306B0E420984590000302D4 /* wave.c in Sources */ = {isa = PBXBuildFile; fileRef = 8306B0C92098458E000302D4 /* wave.c */; };
8306B0E520984590000302D4 /* ubi_lyn.c in Sources */ = {isa = PBXBuildFile; fileRef = 8306B0CA2098458E000302D4 /* ubi_lyn.c */; };
@@ -140,7 +155,6 @@
8349A9101FE6258200E26435 /* ea_eaac.c in Sources */ = {isa = PBXBuildFile; fileRef = 8349A8F71FE6257E00E26435 /* ea_eaac.c */; };
8349A9111FE6258200E26435 /* bar_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 8349A8F81FE6257E00E26435 /* bar_streamfile.h */; };
8349A9121FE6258200E26435 /* vsf_tta.c in Sources */ = {isa = PBXBuildFile; fileRef = 8349A8F91FE6257E00E26435 /* vsf_tta.c */; };
8349A9131FE6258200E26435 /* ngc_vid1.c in Sources */ = {isa = PBXBuildFile; fileRef = 8349A8FA1FE6257E00E26435 /* ngc_vid1.c */; };
8349A9141FE6258200E26435 /* omu.c in Sources */ = {isa = PBXBuildFile; fileRef = 8349A8FB1FE6257F00E26435 /* omu.c */; };
8349A9151FE6258200E26435 /* ps2_xa2_rrp.c in Sources */ = {isa = PBXBuildFile; fileRef = 8349A8FC1FE6257F00E26435 /* ps2_xa2_rrp.c */; };
8349A9161FE6258200E26435 /* flx.c in Sources */ = {isa = PBXBuildFile; fileRef = 8349A8FD1FE6257F00E26435 /* flx.c */; };
@@ -197,7 +211,6 @@
834FE107215C79ED000A5D3D /* mib_mih.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0DE215C79EB000A5D3D /* mib_mih.c */; };
834FE108215C79ED000A5D3D /* hd3_bd3.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0DF215C79EB000A5D3D /* hd3_bd3.c */; };
834FE109215C79ED000A5D3D /* idsp_ie.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0E0215C79EB000A5D3D /* idsp_ie.c */; };
834FE10C215C79ED000A5D3D /* fsb5_interleave_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 834FE0E3215C79EC000A5D3D /* fsb5_interleave_streamfile.h */; };
834FE10D215C79ED000A5D3D /* vag.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0E4215C79EC000A5D3D /* vag.c */; };
834FE10E215C79ED000A5D3D /* ahv.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0E5215C79EC000A5D3D /* ahv.c */; };
834FE10F215C79ED000A5D3D /* sdf.c in Sources */ = {isa = PBXBuildFile; fileRef = 834FE0E6215C79EC000A5D3D /* sdf.c */; };
@@ -702,6 +715,22 @@
830165971F256BD000CA0941 /* txth.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = txth.c; sourceTree = "<group>"; };
830165981F256BD000CA0941 /* ea_schl_fixed.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ea_schl_fixed.c; sourceTree = "<group>"; };
830165991F256BD000CA0941 /* nds_strm_ffta2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nds_strm_ffta2.c; sourceTree = "<group>"; };
83031EBE243C50A700C3F3E0 /* circus_decoder_miniz.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = circus_decoder_miniz.h; sourceTree = "<group>"; };
83031EBF243C50A800C3F3E0 /* circus_decoder_lib_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = circus_decoder_lib_data.h; sourceTree = "<group>"; };
83031EC0243C50A800C3F3E0 /* circus_decoder_miniz.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = circus_decoder_miniz.c; sourceTree = "<group>"; };
83031EC1243C50A800C3F3E0 /* circus_decoder_lib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = circus_decoder_lib.h; sourceTree = "<group>"; };
83031EC2243C50A800C3F3E0 /* circus_decoder_lib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = circus_decoder_lib.c; sourceTree = "<group>"; };
83031EC3243C50A800C3F3E0 /* circus_decoder_lzxpcm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = circus_decoder_lzxpcm.h; sourceTree = "<group>"; };
83031ECA243C50CB00C3F3E0 /* blocked_ubi_sce.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = blocked_ubi_sce.c; sourceTree = "<group>"; };
83031ECB243C50CB00C3F3E0 /* blocked_vid1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = blocked_vid1.c; sourceTree = "<group>"; };
83031ECE243C50DE00C3F3E0 /* encrypted.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = encrypted.c; sourceTree = "<group>"; };
83031ECF243C50DE00C3F3E0 /* bkhd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bkhd.c; sourceTree = "<group>"; };
83031ED0243C50DF00C3F3E0 /* fsb5_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fsb5_streamfile.h; sourceTree = "<group>"; };
83031ED4243C510400C3F3E0 /* ubi_lyn_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ubi_lyn_streamfile.h; sourceTree = "<group>"; };
83031ED5243C510400C3F3E0 /* mul_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mul_streamfile.h; sourceTree = "<group>"; };
83031ED6243C510400C3F3E0 /* xnb_lz4mg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xnb_lz4mg.h; sourceTree = "<group>"; };
83031ED7243C510400C3F3E0 /* vid1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vid1.c; sourceTree = "<group>"; };
83031ED8243C510500C3F3E0 /* xnb_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xnb_streamfile.h; sourceTree = "<group>"; };
8306B08120984517000302D4 /* at3plus_decoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = at3plus_decoder.c; sourceTree = "<group>"; };
8306B08220984517000302D4 /* yamaha_decoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = yamaha_decoder.c; sourceTree = "<group>"; };
8306B08320984517000302D4 /* fadpcm_decoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fadpcm_decoder.c; sourceTree = "<group>"; };
@@ -739,7 +768,6 @@
8306B0C32098458C000302D4 /* awc_xma_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = awc_xma_streamfile.h; sourceTree = "<group>"; };
8306B0C42098458D000302D4 /* ea_wve_ad10.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ea_wve_ad10.c; sourceTree = "<group>"; };
8306B0C52098458D000302D4 /* ppst_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ppst_streamfile.h; sourceTree = "<group>"; };
8306B0C62098458D000302D4 /* ubi_lyn_ogg_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ubi_lyn_ogg_streamfile.h; sourceTree = "<group>"; };
8306B0C72098458D000302D4 /* smv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = smv.c; sourceTree = "<group>"; };
8306B0C92098458E000302D4 /* wave.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = wave.c; sourceTree = "<group>"; };
8306B0CA2098458E000302D4 /* ubi_lyn.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ubi_lyn.c; sourceTree = "<group>"; };
@@ -830,7 +858,6 @@
8349A8F71FE6257E00E26435 /* ea_eaac.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ea_eaac.c; sourceTree = "<group>"; };
8349A8F81FE6257E00E26435 /* bar_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bar_streamfile.h; sourceTree = "<group>"; };
8349A8F91FE6257E00E26435 /* vsf_tta.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vsf_tta.c; sourceTree = "<group>"; };
8349A8FA1FE6257E00E26435 /* ngc_vid1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ngc_vid1.c; sourceTree = "<group>"; };
8349A8FB1FE6257F00E26435 /* omu.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = omu.c; sourceTree = "<group>"; };
8349A8FC1FE6257F00E26435 /* ps2_xa2_rrp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ps2_xa2_rrp.c; sourceTree = "<group>"; };
8349A8FD1FE6257F00E26435 /* flx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = flx.c; sourceTree = "<group>"; };
@@ -886,7 +913,6 @@
834FE0DE215C79EB000A5D3D /* mib_mih.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mib_mih.c; sourceTree = "<group>"; };
834FE0DF215C79EB000A5D3D /* hd3_bd3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hd3_bd3.c; sourceTree = "<group>"; };
834FE0E0215C79EB000A5D3D /* idsp_ie.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = idsp_ie.c; sourceTree = "<group>"; };
834FE0E3215C79EC000A5D3D /* fsb5_interleave_streamfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fsb5_interleave_streamfile.h; sourceTree = "<group>"; };
834FE0E4215C79EC000A5D3D /* vag.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vag.c; sourceTree = "<group>"; };
834FE0E5215C79EC000A5D3D /* ahv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ahv.c; sourceTree = "<group>"; };
834FE0E6215C79EC000A5D3D /* sdf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sdf.c; sourceTree = "<group>"; };
@@ -1437,6 +1463,12 @@
8306B08120984517000302D4 /* at3plus_decoder.c */,
830EBE0F2004655D0023AA10 /* atrac9_decoder.c */,
834FE0B2215C798C000A5D3D /* celt_fsb_decoder.c */,
83031EBF243C50A800C3F3E0 /* circus_decoder_lib_data.h */,
83031EC2243C50A800C3F3E0 /* circus_decoder_lib.c */,
83031EC1243C50A800C3F3E0 /* circus_decoder_lib.h */,
83031EC3243C50A800C3F3E0 /* circus_decoder_lzxpcm.h */,
83031EC0243C50A800C3F3E0 /* circus_decoder_miniz.c */,
83031EBE243C50A700C3F3E0 /* circus_decoder_miniz.h */,
832BF7FC21E050B6006F50F1 /* circus_decoder.c */,
831BA6221EAC61CB00CF89B0 /* coding_utils.c */,
836F6DE518BDC2180095E648 /* coding.h */,
@@ -1540,8 +1572,10 @@
8306B09C20984550000302D4 /* blocked_str_snds.c */,
8306B09820984550000302D4 /* blocked_thp.c */,
8306B09920984550000302D4 /* blocked_tra.c */,
83031ECA243C50CB00C3F3E0 /* blocked_ubi_sce.c */,
8349A8E61FE6253900E26435 /* blocked_vawx.c */,
83AA5D1A1F6E2F7F0020821C /* blocked_vgs.c */,
83031ECB243C50CB00C3F3E0 /* blocked_vid1.c */,
832BF80321E050DC006F50F1 /* blocked_vs_square.c */,
832BF80421E050DC006F50F1 /* blocked_vs_str.c */,
8306B0A120984551000302D4 /* blocked_vs.c */,
@@ -1605,6 +1639,7 @@
837CEAD723487E8300E62A4A /* bgw_streamfile.h */,
836F6E3818BDC2180095E648 /* bgw.c */,
83299FCE1E7660C7003A3242 /* bik.c */,
83031ECF243C50DE00C3F3E0 /* bkhd.c */,
837CEAD423487E8300E62A4A /* bmp_konami.c */,
834FE0CA215C79E7000A5D3D /* bnk_sony.c */,
8373342523F60CDC00DE14DC /* bnsf_keys.h */,
@@ -1643,6 +1678,7 @@
83EED5D1203A8BC7008BEB45 /* ea_swvr.c */,
8306B0C42098458D000302D4 /* ea_wve_ad10.c */,
8306B0BF2098458C000302D4 /* ea_wve_au00.c */,
83031ECE243C50DE00C3F3E0 /* encrypted.c */,
836F6E4918BDC2180095E648 /* exakt_sc.c */,
836F6E4A18BDC2180095E648 /* excitebots.c */,
8349A8EF1FE6257C00E26435 /* ezw.c */,
@@ -1657,7 +1693,7 @@
83A21F7E201D8980000F04B9 /* fsb_keys.h */,
836F6E4C18BDC2180095E648 /* fsb.c */,
83C7280522BC893B00678B4A /* fsb5_fev.c */,
834FE0E3215C79EC000A5D3D /* fsb5_interleave_streamfile.h */,
83031ED0243C50DF00C3F3E0 /* fsb5_streamfile.h */,
83F5F8821908D0A400C8E65F /* fsb5.c */,
8373342323F60CDB00DE14DC /* fwse.c */,
834D3A6D19F47C98001C54F6 /* g1l.c */,
@@ -1714,6 +1750,7 @@
83C7280E22BC893D00678B4A /* mta2_streamfile.h */,
83C727FF22BC893900678B4A /* mta2.c */,
83C7280322BC893A00678B4A /* mtaf.c */,
83031ED5243C510400C3F3E0 /* mul_streamfile.h */,
832BF81221E05149006F50F1 /* mul.c */,
836F6E6218BDC2180095E648 /* mus_acm.c */,
83C7280622BC893B00678B4A /* mus_vc.c */,
@@ -1747,7 +1784,6 @@
8306B0BE2098458C000302D4 /* ngc_str_cauldron.c */,
836F6E7C18BDC2180095E648 /* ngc_tydsp.c */,
831BD11F1EEE1CF200198540 /* ngc_ulw.c */,
8349A8FA1FE6257E00E26435 /* ngc_vid1.c */,
836F6E7E18BDC2180095E648 /* ngc_ymf.c */,
836F6E7F18BDC2180095E648 /* ngca.c */,
83C727FC22BC893900678B4A /* nps.c */,
@@ -1906,7 +1942,7 @@
836F6EFC18BDC2190095E648 /* ubi_ckd.c */,
837CEAE023487F2A00E62A4A /* ubi_hx.c */,
8306B0D720984590000302D4 /* ubi_jade.c */,
8306B0C62098458D000302D4 /* ubi_lyn_ogg_streamfile.h */,
83031ED4243C510400C3F3E0 /* ubi_lyn_streamfile.h */,
8306B0CA2098458E000302D4 /* ubi_lyn.c */,
831BA6131EAC61A500CF89B0 /* ubi_raki.c */,
8375737521F950EC00F01AF5 /* ubi_sb_streamfile.h */,
@@ -1917,6 +1953,7 @@
834FE0D3215C79E9000A5D3D /* vai.c */,
831BA6141EAC61A500CF89B0 /* vawx.c */,
836F6EFD18BDC2190095E648 /* vgs.c */,
83031ED7243C510400C3F3E0 /* vid1.c */,
834FE0CE215C79E8000A5D3D /* vis.c */,
834FE0D4215C79E9000A5D3D /* vpk.c */,
832BF81821E0514A006F50F1 /* vs_square.c */,
@@ -1960,6 +1997,8 @@
834FE0DC215C79EA000A5D3D /* xmd.c */,
837CEAEC23487F2C00E62A4A /* xmu.c */,
837CEAE323487F2A00E62A4A /* xmv_valve.c */,
83031ED6243C510400C3F3E0 /* xnb_lz4mg.h */,
83031ED8243C510500C3F3E0 /* xnb_streamfile.h */,
830EBE112004656E0023AA10 /* xnb.c */,
832BF81921E0514A006F50F1 /* xopus.c */,
832BF80A21E05148006F50F1 /* xpcm.c */,
@@ -2012,6 +2051,7 @@
files = (
836F705518BDC2190095E648 /* streamtypes.h in Headers */,
836F6F3518BDC2190095E648 /* nwa_decoder.h in Headers */,
83031EC9243C50A800C3F3E0 /* circus_decoder_lzxpcm.h in Headers */,
83C7282222BC893D00678B4A /* mta2_streamfile.h in Headers */,
83A21F87201D8981000F04B9 /* fsb_keys.h in Headers */,
834FE0EC215C79ED000A5D3D /* kma9_streamfile.h in Headers */,
@@ -2031,6 +2071,7 @@
832BF82021E0514B006F50F1 /* zsnd_streamfile.h in Headers */,
8375737721F950ED00F01AF5 /* ubi_sb_streamfile.h in Headers */,
839E21E01F2EDAF100EE54D7 /* vorbis_custom_data_fsb.h in Headers */,
83031EDB243C510500C3F3E0 /* xnb_lz4mg.h in Headers */,
836F705418BDC2190095E648 /* streamfile.h in Headers */,
83A3F0761E3AD8B900D6A794 /* stack_alloc.h in Headers */,
8373342723F60CDC00DE14DC /* lrmd_streamfile.h in Headers */,
@@ -2039,15 +2080,14 @@
83C7280F22BC893D00678B4A /* xwb_xsb.h in Headers */,
83C7281622BC893D00678B4A /* xwma_konami_streamfile.h in Headers */,
839E21E81F2EDAF100EE54D7 /* mpeg_decoder.h in Headers */,
834FE10C215C79ED000A5D3D /* fsb5_interleave_streamfile.h in Headers */,
839E21E51F2EDAF100EE54D7 /* vorbis_custom_decoder.h in Headers */,
837CEADB23487E8300E62A4A /* bgw_streamfile.h in Headers */,
837CEB0323487F2C00E62A4A /* xavs_streamfile.h in Headers */,
8306B0E120984590000302D4 /* ubi_lyn_ogg_streamfile.h in Headers */,
836F705918BDC2190095E648 /* vgmstream.h in Headers */,
8373342623F60CDC00DE14DC /* deblock_streamfile.h in Headers */,
83C7281522BC893D00678B4A /* txth_streamfile.h in Headers */,
8306B0DE20984590000302D4 /* awc_xma_streamfile.h in Headers */,
83031EC5243C50A800C3F3E0 /* circus_decoder_lib_data.h in Headers */,
834FE0B5215C798C000A5D3D /* acm_decoder_libacm.h in Headers */,
839E21E61F2EDAF100EE54D7 /* vorbis_custom_data_wwise.h in Headers */,
8373342D23F60CDC00DE14DC /* bnsf_keys.h in Headers */,
@@ -2059,19 +2099,25 @@
836F6F9A18BDC2190095E648 /* meta.h in Headers */,
8306B0D820984590000302D4 /* ea_eaac_streamfile.h in Headers */,
837CEB0523487F2C00E62A4A /* sqex_sead_streamfile.h in Headers */,
83031ED9243C510500C3F3E0 /* ubi_lyn_streamfile.h in Headers */,
8373341D23F60C7B00DE14DC /* g7221_decoder_lib.h in Headers */,
8306B0E820984590000302D4 /* opus_interleave_streamfile.h in Headers */,
83031EDD243C510500C3F3E0 /* xnb_streamfile.h in Headers */,
8373341623F60C7B00DE14DC /* g7221_decoder_aes.h in Headers */,
8373341923F60C7B00DE14DC /* g7221_decoder_lib_data.h in Headers */,
83AFABBD23795202002F3947 /* ea_eaac_opus_streamfile.h in Headers */,
83031EDA243C510500C3F3E0 /* mul_streamfile.h in Headers */,
83C7281822BC893D00678B4A /* sfh_streamfile.h in Headers */,
834FE0EF215C79ED000A5D3D /* xvag_streamfile.h in Headers */,
8349A90C1FE6258200E26435 /* sqex_scd_streamfile.h in Headers */,
837CEAF323487F2C00E62A4A /* mzrt_streamfile.h in Headers */,
83031EC4243C50A800C3F3E0 /* circus_decoder_miniz.h in Headers */,
8349A91B1FE6258200E26435 /* adx_keys.h in Headers */,
836F6F4D18BDC2190095E648 /* layout.h in Headers */,
83269DD22399F5DE00F49FE3 /* nus3bank_streamfile.h in Headers */,
83AA5D251F6E2F9C0020821C /* hca_keys.h in Headers */,
83031EC7243C50A800C3F3E0 /* circus_decoder_lib.h in Headers */,
83031ED3243C50DF00C3F3E0 /* fsb5_streamfile.h in Headers */,
836F6F2318BDC2190095E648 /* coding.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -2435,7 +2481,6 @@
83299FD11E7660C7003A3242 /* dsp_adx.c in Sources */,
836F704018BDC2190095E648 /* wii_sng.c in Sources */,
834FE10D215C79ED000A5D3D /* vag.c in Sources */,
8349A9131FE6258200E26435 /* ngc_vid1.c in Sources */,
8350C0551E071881009E0A93 /* xma.c in Sources */,
837CEAF523487F2C00E62A4A /* ubi_hx.c in Sources */,
836F6F3218BDC2190095E648 /* ngc_dsp_decoder.c in Sources */,
@@ -2479,6 +2524,7 @@
8306B0BA20984552000302D4 /* blocked_wsi.c in Sources */,
83BAFB6C19F45EB3005DAB60 /* bfstm.c in Sources */,
836F704418BDC2190095E648 /* ws_aud.c in Sources */,
83031ED2243C50DF00C3F3E0 /* bkhd.c in Sources */,
8373342F23F60D4100DE14DC /* tgc.c in Sources */,
83709E081ECBC1A4005C03D3 /* ps2_rxws.c in Sources */,
8373342823F60CDC00DE14DC /* fda.c in Sources */,
@@ -2513,6 +2559,7 @@
836F6FE618BDC2190095E648 /* ps2_mcg.c in Sources */,
83AA5D241F6E2F9C0020821C /* awc.c in Sources */,
8349A8E91FE6253900E26435 /* blocked_ea_1snh.c in Sources */,
83031EC6243C50A800C3F3E0 /* circus_decoder_miniz.c in Sources */,
8306B0E620984590000302D4 /* msb_msh.c in Sources */,
836F702918BDC2190095E648 /* sat_sap.c in Sources */,
8351F3292212B53400A606E4 /* dsa_decoder.c in Sources */,
@@ -2521,6 +2568,7 @@
831BA6281EAC61CB00CF89B0 /* coding_utils.c in Sources */,
8373342B23F60CDC00DE14DC /* fwse.c in Sources */,
837CEAFF23487F2C00E62A4A /* raw_snds.c in Sources */,
83031EDC243C510500C3F3E0 /* vid1.c in Sources */,
836F700218BDC2190095E648 /* ps2_tk5.c in Sources */,
83AA5D271F6E2F9C0020821C /* stm.c in Sources */,
831BA61D1EAC61A500CF89B0 /* ubi_raki.c in Sources */,
@@ -2563,6 +2611,7 @@
834FE0F5215C79ED000A5D3D /* wv2.c in Sources */,
836F703D18BDC2190095E648 /* wii_mus.c in Sources */,
836F700D18BDC2190095E648 /* ps2_wmus.c in Sources */,
83031EC8243C50A800C3F3E0 /* circus_decoder_lib.c in Sources */,
831BA61C1EAC61A500CF89B0 /* sxd.c in Sources */,
836F6F8018BDC2190095E648 /* dsp_bdsp.c in Sources */,
836F6F9618BDC2190095E648 /* lsf.c in Sources */,
@@ -2576,14 +2625,17 @@
8306B0B120984552000302D4 /* blocked_halpst.c in Sources */,
836F6FD018BDC2190095E648 /* ps2_b1s.c in Sources */,
83AA5D181F6E2F600020821C /* mpeg_custom_utils_awc.c in Sources */,
83031ED1243C50DF00C3F3E0 /* encrypted.c in Sources */,
834FE0FE215C79ED000A5D3D /* ps_headerless.c in Sources */,
8306B0BB20984552000302D4 /* blocked_gsb.c in Sources */,
83031ECC243C50CC00C3F3E0 /* blocked_ubi_sce.c in Sources */,
836F6F7718BDC2190095E648 /* capdsp.c in Sources */,
836F6FB018BDC2190095E648 /* ngc_dsp_ygo.c in Sources */,
836F703318BDC2190095E648 /* str_snds.c in Sources */,
832BF82221E0514B006F50F1 /* vs_str.c in Sources */,
8349A9191FE6258200E26435 /* afc.c in Sources */,
836F703718BDC2190095E648 /* tun.c in Sources */,
83031ECD243C50CC00C3F3E0 /* blocked_vid1.c in Sources */,
836F700B18BDC2190095E648 /* ps2_wad.c in Sources */,
8349A9161FE6258200E26435 /* flx.c in Sources */,
832BF82921E0514B006F50F1 /* msf_banpresto.c in Sources */,


+ 5
- 0
Frameworks/vgmstream/vgmstream/src/coding/asf_decoder.c View File

@@ -54,3 +54,8 @@ void decode_asf(VGMSTREAMCHANNEL *stream, sample_t *outbuf, int channelspacing,
stream->adpcm_history1_32 = hist1;
stream->adpcm_history2_32 = hist2;
}

int32_t asf_bytes_to_samples(size_t bytes, int channels) {
if (channels <= 0) return 0;
return bytes / channels / 0x11 * 32;
}

+ 109
- 29
Frameworks/vgmstream/vgmstream/src/coding/circus_decoder.c View File

@@ -1,29 +1,109 @@
#include "coding.h"
/* Circus XPCM mode 2 decoding, verified vs EF.exe (info from foo_adpcm/libpcm and https://github.com/lioncash/ExtractData) */
void decode_circus_adpcm(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
int i, sample_pos = 0;
int32_t hist = stream->adpcm_history1_32;
int scale = stream->adpcm_scale;
off_t frame_offset = stream->offset; /* frame size is 1 */
for (i = first_sample; i < first_sample + samples_to_do; i++) {
int8_t code = read_8bit(frame_offset+i,stream->streamfile);
hist += code << scale;
if (code == 0) {
if (scale > 0)
scale--;
}
else if (code == 127 || code == -128) {
if (scale < 8)
scale++;
}
outbuf[sample_pos] = hist;
}
stream->adpcm_history1_32 = hist;
stream->adpcm_scale = scale;
}
#include "coding.h"
#include "circus_decoder_lib.h"



struct circus_codec_data {
STREAMFILE* sf;
int16_t* buf;
int buf_samples_all;
circus_handle_t* handle;
};


circus_codec_data* init_circus_vq(STREAMFILE* sf, off_t start, uint8_t codec, uint8_t flags) {
circus_codec_data* data = NULL;

data = calloc(1, sizeof(circus_codec_data));
if (!data) goto fail;

data->sf = reopen_streamfile(sf, 0);
data->handle = circus_init(start, codec, flags);
if (!data->handle) goto fail;

return data;
fail:
free_circus_vq(data);
return NULL;
}

void decode_circus_vq(circus_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels) {
int ok, i, samples_to_get;

while (samples_to_do > 0) {
if (data->buf_samples_all == 0) {
ok = circus_decode_frame(data->handle, data->sf, &data->buf, &data->buf_samples_all);
if (!ok) goto decode_fail;
}

samples_to_get = data->buf_samples_all / channels;
if (samples_to_get > samples_to_do)
samples_to_get = samples_to_do;

for (i = 0; i < samples_to_get * channels; i++) {
outbuf[i] = data->buf[i];
}

data->buf += samples_to_get * channels;
data->buf_samples_all -= samples_to_get * channels;
outbuf += samples_to_get * channels;
samples_to_do -= samples_to_get;
}

return;
decode_fail:
VGM_LOG("CIRCUS: decode error\n");
memset(outbuf, 0, samples_to_do * channels * sizeof(sample_t));
}

void reset_circus_vq(circus_codec_data* data) {
if (!data) return;

circus_reset(data->handle);
data->buf_samples_all = 0;
}

void seek_circus_vq(circus_codec_data* data, int32_t num_sample) {
if (!data) return;

reset_circus_vq(data);
//data->samples_discard = num_sample; //todo (xpcm don't have loop points tho)
}

void free_circus_vq(circus_codec_data* data) {
if (!data) return;

close_streamfile(data->sf);
circus_free(data->handle);
free(data);
}

/* ************************************************************************* */

/* Circus XPCM mode 2 decoding, verified vs EF.exe (info from foo_adpcm/libpcm and https://github.com/lioncash/ExtractData) */
void decode_circus_adpcm(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
int i, sample_pos = 0;
int32_t hist = stream->adpcm_history1_32;
int scale = stream->adpcm_scale;
off_t frame_offset = stream->offset; /* frame size is 1 */


for (i = first_sample; i < first_sample + samples_to_do; i++) {
int8_t code = read_8bit(frame_offset+i,stream->streamfile);

hist += code << scale;
if (code == 0) {
if (scale > 0)
scale--;
}
else if (code == 127 || code == -128) {
if (scale < 8)
scale++;
}
outbuf[sample_pos] = hist;
}

stream->adpcm_history1_32 = hist;
stream->adpcm_scale = scale;
}

+ 492
- 0
Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.c View File

@@ -0,0 +1,492 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

/* Decodes Circus's audio codec, reverse engineered from various .exe.
*
* Some sources identify this codec as VQ (vector quantization), though vector(?)
* data isn't actually bitpacked and just compressed using custom LZ or standard zlib.
* Channels aren't divided either so decoding results in N-ch interleaved PCM.
* It does seem to be using LPC/speech stuff from VQ codecs though.
*
* Some info from Japanese libpcm.c found in foo_adpcm
* https://bitbucket.org/losnoco/foo_adpcm/src/master/foo_oki/source/libpcm/libpcm.cpp
*/

#include "circus_decoder_lib.h"
#include "circus_decoder_lib_data.h"

#include "circus_decoder_lzxpcm.h"

/* use miniz (API-compatible) to avoid adding external zlib just for this codec
* - https://github.com/richgel999/miniz */
#include "circus_decoder_miniz.h"
//#include "zlib.h"


//#define XPCM_CODEC_PCM 0
#define XPCM_CODEC_VQ_LZXPCM 1
//#define XPCM_CODEC_ADPCM 2
#define XPCM_CODEC_VQ_DEFLATE 3

/* frame encodes 4096 PCM samples (all channels) = 4096*2 = 0x2000 bytes, re-interleaved then compressed */
#define XPCM_FRAME_SIZE (4096 * 2)
#define XPCM_FRAME_CODES 4096
#define XPCM_FRAME_SAMPLES_ALL 4064
#define XPCM_FRAME_OVERLAP_ALL 32
#define XPCM_INPUT_SIZE 0x8000

/* ************************************************************************* */
/* DECODE */
/* ************************************************************************* */

struct circus_handle_t {
/* config */
off_t start;
uint8_t codec;
uint8_t flags;
const int* scales;

/* temp buffers */
uint8_t srcbuf[XPCM_INPUT_SIZE]; /* compressed input data (arbitrary size) */
uint8_t decbuf[XPCM_FRAME_SIZE]; /* single decompressed frame */
uint8_t intbuf[XPCM_FRAME_SIZE]; /* re-interleaved frame */
int32_t invbuf[XPCM_FRAME_CODES]; /* main LPC data (may need less) */
int32_t tmpbuf[XPCM_FRAME_CODES]; /* temp LPC data (may need less) */

/* output samples (original code reuses decbuf though) */
int16_t pcmbuf[XPCM_FRAME_SAMPLES_ALL + XPCM_FRAME_OVERLAP_ALL]; /* final output samples and extra overlap samples */

/* sample filter state */
int hist1;
int hist2;
int frame;

/* lz/deflate decompression state */
lzxpcm_stream_t lstrm;
z_stream dstrm;
off_t offset;
};


static void convert(uint8_t flags, int32_t* invbuf, int16_t* pcmbuf, int* p_hist1, int* p_hist2, int frame) {
int i;
int sample, hist1, hist2;

hist1 = *p_hist1;
hist2 = *p_hist2;

/* some ops below would use SHRs (>>), but there is some rounding in the original
* ASM that decompiles and I think corresponds do DIVs (right shift and divs of
* negative values isn't equivalent). Similarly the filters seem to use CDQ tricks
* to simulate s64 ops, but I'm not sure casting is 100% equivalent (sounds ok tho). */

/* do final filtering and conversion to PCM */
for (i = 0; i < XPCM_FRAME_SAMPLES_ALL + XPCM_FRAME_OVERLAP_ALL; i++) {
sample = *invbuf++;
if (flags & 0x10)
sample = (3 * (int64_t)sample / 2) / 1024; //>> 10;
else
sample = sample / 1024; //>> 10;

sample = ((27 * (int64_t)sample + 4 * hist1 + hist2) << 11) / 65536; //>> 16

hist2 = hist1;
hist1 = sample;

/* last 32 decoded samples aren't output, but are used next frame to overlap
* with beginning samples (filters(?) windowing, not too noticeable though) */
if (i < XPCM_FRAME_OVERLAP_ALL && frame > 0) {
sample = ((i * (int64_t)sample) + ((XPCM_FRAME_OVERLAP_ALL - i) * pcmbuf[XPCM_FRAME_SAMPLES_ALL + i])) / 32; //>> 5
}

if (sample > 32767)
sample = 32767;
else if (sample < -32768)
sample = -32768;

pcmbuf[i] = sample;
}

*p_hist1 = hist1;
*p_hist2 = hist2;
}

static void transform(int32_t* invbuf, int32_t* tmpbuf) {
int lpc1, lpc2, lpc3, lpc4;
int step1, step2, step3;
int sc1, sc2;

/* bits were originally configurable (passed arg), but actually called with const 12,
* and removed in later games along with superfluous ifs (coefs > 0, bits >= 3, etc) */
//const int frame_bits = 12;

step1 = 4096; /* 1 << 12 */
step2 = step1 >> 1;
step3 = step2 >> 1;
sc1 = 1;

/* inverse transform of LPC(?) coefs */
for (lpc1 = 0; lpc1 < 12 - 2; lpc1++) {
int sub1, sub2;
int i1, i2, i3, i4;
int64_t cos1, sin1, cos2, sin2; /* needs i64 to force 64b ops (avoid overflows) */

cos1 = (int64_t)sincos_table[sc1 + 1024];
sin1 = (int64_t)sincos_table[sc1 + 0];

i1 = 0;
i2 = step2;
i3 = step3;
i4 = step2 + step3;

for (lpc2 = 0; lpc2 < 4096; lpc2 += step1) {
sub1 = invbuf[i1 + 0] - invbuf[i2 + 0];
sub2 = tmpbuf[i1 + 0] - tmpbuf[i2 + 0];
invbuf[i1 + 0] += invbuf[i2 + 0];
tmpbuf[i1 + 0] += tmpbuf[i2 + 0];
invbuf[i2 + 0] = sub1;
tmpbuf[i2 + 0] = sub2;

sub1 = invbuf[i1 + 1] - invbuf[i2 + 1];
sub2 = tmpbuf[i1 + 1] - tmpbuf[i2 + 1];
invbuf[i1 + 1] += invbuf[i2 + 1];
tmpbuf[i1 + 1] += tmpbuf[i2 + 1];
invbuf[i2 + 1] = ((sub1 * cos1) >> 12) + ((sub2 * sin1) >> 12);
tmpbuf[i2 + 1] = ((sub2 * cos1) >> 12) - ((sub1 * sin1) >> 12);

sub1 = invbuf[i3 + 0] - invbuf[i4 + 0];
sub2 = tmpbuf[i3 + 0] - tmpbuf[i4 + 0];
invbuf[i3 + 0] += invbuf[i4 + 0];
tmpbuf[i3 + 0] += tmpbuf[i4 + 0];
invbuf[i4 + 0] = sub2;
tmpbuf[i4 + 0] = -sub1;

sub1 = invbuf[i3 + 1] - invbuf[i4 + 1];
sub2 = tmpbuf[i3 + 1] - tmpbuf[i4 + 1];
invbuf[i3 + 1] += invbuf[i4 + 1];
tmpbuf[i3 + 1] += tmpbuf[i4 + 1];
invbuf[i4 + 1] = ((sub2 * cos1) >> 12) - ((sub1 * sin1) >> 12);
tmpbuf[i4 + 1] = -(((sub1 * cos1) >> 12) + ((sub2 * sin1) >> 12));

i1 += step1;
i2 += step1;
i3 += step1;
i4 += step1;
}

if (step3 > 2) {
sc2 = sc1 * 2;

for (lpc3 = 2; lpc3 < step3; lpc3++) {
cos2 = (int64_t)sincos_table[sc2 + 1024];
sin2 = (int64_t)sincos_table[sc2 + 0];
sc2 += sc1;

i1 = 0 + lpc3;
i2 = step2 + lpc3;
i3 = step3 + lpc3;
i4 = step2 + step3 + lpc3;

for (lpc4 = 0; lpc4 < 4096; lpc4 += step1) {
sub1 = invbuf[i1] - invbuf[i2];
sub2 = tmpbuf[i1] - tmpbuf[i2];
invbuf[i1] += invbuf[i2];
tmpbuf[i1] += tmpbuf[i2];
invbuf[i2] = ((sub1 * cos2) >> 12) + ((sub2 * sin2) >> 12);
tmpbuf[i2] = ((sub2 * cos2) >> 12) - ((sub1 * sin2) >> 12);

sub1 = invbuf[i3] - invbuf[i4];
sub2 = tmpbuf[i3] - tmpbuf[i4];
invbuf[i3] += invbuf[i4];
tmpbuf[i3] += tmpbuf[i4];
invbuf[i4] = ((sub2 * cos2) >> 12) - ((sub1 * sin2) >> 12);
tmpbuf[i4] = -(((sub1 * cos2) >> 12) + ((sub2 * sin2) >> 12));

i1 += step1;
i2 += step1;
i3 += step1;
i4 += step1;
}
}
}

step1 = step2; // step1 >>= 1;
step2 = step3; // step2 >>= 1;
step3 >>= 1;
sc1 *= 2;
}

{
int i, j;
int sub1, sub2, pow;

for (i = 0; i < 4096; i += 4) {
sub1 = invbuf[i + 0] - invbuf[i + 2];
invbuf[i + 0] += invbuf[i + 2];
invbuf[i + 2] = sub1;

sub2 = tmpbuf[i + 0] - tmpbuf[i + 2];
tmpbuf[i + 0] += tmpbuf[i + 2];
tmpbuf[i + 2] = sub2;

sub1 = invbuf[i + 3] - invbuf[i + 1];
sub2 = tmpbuf[i + 1] - tmpbuf[i + 3];
invbuf[i + 1] += invbuf[i + 3];
invbuf[i + 3] = sub2;
tmpbuf[i + 1] += tmpbuf[i + 3];
tmpbuf[i + 3] = sub1;
}

for (i = 0; i < 4096; i += 2) {
sub1 = invbuf[i + 0] - invbuf[i + 1];
invbuf[i + 0] += invbuf[i + 1];
invbuf[i + 1] = sub1;

sub2 = tmpbuf[i + 0] - tmpbuf[i + 1];
tmpbuf[i + 0] += tmpbuf[i + 1];
tmpbuf[i + 1] = sub2;
}

for (i = 1, j = 0; i < 4096 - 1; i++) {
for (pow = 4096 / 2; pow <= j; pow /= 2) {
j -= pow;
}
j += pow;

if (i < j) {
sub1 = invbuf[j];
invbuf[j] = invbuf[i];
invbuf[i] = sub1;

sub2 = tmpbuf[j];
tmpbuf[j] = tmpbuf[i];
tmpbuf[i] = sub2;
}
}
}
}

static void scale(const uint8_t* intbuf, const int* scales, int32_t* invbuf, int32_t* tmpbuf) {
int i, j;

/* reinterleave and scale intbuf into invbuf and tmpbuf */
for (i = 0, j = 0; i < 4096 / 2; i++, j += 16) {
int scale, qv1, qv2;

scale = scales[j / 4096];

qv1 = (intbuf[i*4 + 0] << 0) | (intbuf[i*4 + 1] << 8); /* get_u16le */
qv2 = (intbuf[i*4 + 2] << 0) | (intbuf[i*4 + 3] << 8); /* get_u16le */

/* lowest bit is short of "positive" flag, or rather: even=0..-32767, odd=1..32768
* (originally done through a LUT init at runtime with all 65536 indexes) */
qv1 = (qv1 & 1) ? (qv1 >> 1) + 1 : -(qv1 >> 1);
qv2 = (qv2 & 1) ? (qv2 >> 1) + 1 : -(qv2 >> 1);

invbuf[i] = scale * qv1;
tmpbuf[i] = scale * qv2;
}

/* reset rest of invbuf/tmpbuf */
for (i = 4096 / 2; i < 4096; i++) {
invbuf[i] = 0;
tmpbuf[i] = 0;
}
}

static void interleave(const uint8_t* decbuf, uint8_t* intbuf) {
int i, j;

/* reorder odd decbuf bytes into intbuf */
for (i = 0, j = 1; i < 0x1000; i++, j += 2) {
intbuf[j] = decbuf[i];
}

/* reorder even decbuf bytes into intbuf */
for (i = 0x1000, j = 0; i < 0x1800; i++, j += 4) {
uint8_t lo = decbuf[i + 0x800];
uint8_t hi = decbuf[i];

intbuf[j + 0] = (hi & 0xF0) | (lo >> 4);
intbuf[j + 2] = (hi << 4) | (lo & 0x0F);
}
}

/* ************************************************************ */
/* API */
/* ************************************************************ */

circus_handle_t* circus_init(off_t start, uint8_t codec, uint8_t flags) {
circus_handle_t* handle = NULL;
int scale_index, err;

handle = malloc(sizeof(circus_handle_t));
if (!handle) goto fail;

handle->start = start;
handle->codec = codec; //(config >> 0) & 0xFF;
handle->flags = flags; //(config >> 8) & 0xFF;

scale_index = (handle->flags & 0xF);
if (scale_index > 5) goto fail;
handle->scales = scale_table[scale_index];

if (handle->codec == XPCM_CODEC_VQ_DEFLATE) {
memset(&handle->dstrm, 0, sizeof(z_stream));
err = inflateInit(&handle->dstrm);
if (err < 0) goto fail;
}

circus_reset(handle);

return handle;
fail:
circus_free(handle);
return NULL;
}

void circus_free(circus_handle_t* handle) {
if (!handle)
return;

if (handle->codec == XPCM_CODEC_VQ_DEFLATE) {
inflateEnd(&handle->dstrm);
}

free(handle);
}

void circus_reset(circus_handle_t* handle) {
if (!handle)
return;
handle->hist1 = 0;
handle->hist2 = 0;
handle->frame = 0;

if (handle->codec == XPCM_CODEC_VQ_LZXPCM) {
lzxpcm_reset(&handle->lstrm);
} else if (handle->codec == XPCM_CODEC_VQ_DEFLATE) {
inflateReset(&handle->dstrm);
}
handle->offset = handle->start;
}

static int decompress_frame_lzxpcm(circus_handle_t* handle, STREAMFILE* sf) {
int res;

handle->lstrm.next_out = handle->decbuf;
handle->lstrm.avail_out = sizeof(handle->decbuf);
handle->lstrm.total_out = 0;
do {
if (handle->lstrm.avail_in == 0) {
handle->lstrm.next_in = handle->srcbuf;
handle->lstrm.avail_in = read_streamfile(handle->srcbuf, handle->offset, sizeof(handle->srcbuf), sf);
handle->offset += handle->lstrm.avail_in;

/* EOF (game reserves some extra buf so memset'ing is probably equivalent) */
if (handle->lstrm.avail_in == 0) {
memset(handle->decbuf + handle->lstrm.total_out, 0, sizeof(handle->decbuf) - handle->dstrm.total_out);
break;
}
}

res = lzxpcm_decompress(&handle->lstrm);
if (res != LZXPCM_OK)
goto fail;
}
while(handle->lstrm.avail_out != 0);

return 1;
fail:
return 0;
}

static int decompress_frame_deflate(circus_handle_t* handle, STREAMFILE* sf) {
int res;

handle->dstrm.next_out = handle->decbuf;
handle->dstrm.avail_out = sizeof(handle->decbuf);
handle->dstrm.total_out = 0;
do {
if (handle->dstrm.avail_in == 0) {
handle->dstrm.next_in = handle->srcbuf;
handle->dstrm.avail_in = read_streamfile(handle->srcbuf, handle->offset, sizeof(handle->srcbuf), sf);
handle->offset += handle->dstrm.avail_in;

/* EOF (game reserves some extra buf so memset'ing is probably equivalent) */
if (handle->dstrm.avail_in == 0) {
memset(handle->decbuf + handle->dstrm.total_out, 0, sizeof(handle->decbuf) - handle->dstrm.total_out);
break;
}
}

res = inflate(&handle->dstrm, Z_NO_FLUSH);
if (res != Z_OK && res != Z_STREAM_END)
goto fail;
}
while(handle->dstrm.avail_out != 0);

return 1;
fail:
return 0;
}

#ifdef XPCM_ALT
/* original code uses zlib 1.2.1 to decompress the full stream into memory */
static int deflate_decompress_full(uint8_t* dst, size_t dst_size, const uint8_t* src, size_t src_size) {
int err;
z_stream strm = {0};
strm.next_in = src;
strm.avail_in = src_size;
strm.next_out = dst;
strm.avail_out = dst_size;

err = inflateInit(&strm);
if (err < 0) {
//printf("inflateInit error: %i\n", err);
return 0;
}

err = inflate(&strm, Z_FINISH);
if (err < 0) {
//printf("inflate error: %i\n", err);
//return 0;
}

err = inflateEnd(&strm);
if (err < 0) {
//printf("inflateEnd error: %i\n", err);
return 0;
}

return 0;
}
#endif

int circus_decode_frame(circus_handle_t* handle, STREAMFILE* sf, int16_t** p_buf, int* p_buf_samples_all) {
int ok;

if (handle->codec == XPCM_CODEC_VQ_LZXPCM) {
ok = decompress_frame_lzxpcm(handle, sf);
} else if (handle->codec == XPCM_CODEC_VQ_DEFLATE) {
ok = decompress_frame_deflate(handle, sf);
} else {
ok = 0;
}
if (!ok)
goto fail;

interleave(handle->decbuf, handle->intbuf);
scale(handle->intbuf, handle->scales, handle->invbuf, handle->tmpbuf);
transform(handle->invbuf, handle->tmpbuf);
convert(handle->flags, handle->invbuf, handle->pcmbuf, &handle->hist1, &handle->hist2, handle->frame);
handle->frame++;

*p_buf = handle->pcmbuf;
*p_buf_samples_all = XPCM_FRAME_SAMPLES_ALL;
return 1;
fail:
return 0;
}

+ 16
- 0
Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib.h View File

@@ -0,0 +1,16 @@
#ifndef _CIRCUS_DECODER_LIB_H_
#define _CIRCUS_DECODER_LIB_H_

#include "../streamfile.h"

typedef struct circus_handle_t circus_handle_t;

circus_handle_t* circus_init(off_t start, uint8_t codec, uint8_t flags);

void circus_free(circus_handle_t* handle);

void circus_reset(circus_handle_t* handle);

int circus_decode_frame(circus_handle_t* handle, STREAMFILE* sf, int16_t** p_buf, int* p_buf_samples_all);

#endif

+ 347
- 0
Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lib_data.h View File

@@ -0,0 +1,347 @@
#ifndef _CIRCUS_DECODER_LIB_DATA_H_
#define _CIRCUS_DECODER_LIB_DATA_H_

#include <stdint.h>


/* sin-cosine LUT, seems generated with: */
/* table[i] = round( sin(2.0 * PI * i / 1024.0) * 1000.0 ) */
static const int sincos_table[1024*5 + 1] = {
0, 6, 12, 18, 25, 31, 37, 43, 50, 56, 62, 69, 75, 81, 87, 94,
100, 106, 113, 119, 125, 131, 138, 144, 150, 157, 163, 169, 175, 182, 188, 194,
200, 207, 213, 219, 226, 232, 238, 244, 251, 257, 263, 269, 276, 282, 288, 295,
301, 307, 313, 320, 326, 332, 338, 345, 351, 357, 363, 370, 376, 382, 388, 395,
401, 407, 413, 420, 426, 432, 438, 445, 451, 457, 463, 470, 476, 482, 488, 495,
501, 507, 513, 520, 526, 532, 538, 545, 551, 557, 563, 569, 576, 582, 588, 594,
601, 607, 613, 619, 625, 632, 638, 644, 650, 656, 663, 669, 675, 681, 687, 694,
700, 706, 712, 718, 725, 731, 737, 743, 749, 755, 762, 768, 774, 780, 786, 792,
799, 805, 811, 817, 823, 829, 836, 842, 848, 854, 860, 866, 872, 879, 885, 891,
897, 903, 909, 915, 921, 928, 934, 940, 946, 952, 958, 964, 970, 976, 983, 989,
995, 1001, 1007, 1013, 1019, 1025, 1031, 1037, 1043, 1050, 1056, 1062, 1068, 1074, 1080, 1086,
1092, 1098, 1104, 1110, 1116, 1122, 1128, 1134, 1140, 1146, 1152, 1158, 1164, 1170, 1176, 1182,
1189, 1195, 1201, 1207, 1213, 1219, 1225, 1231, 1237, 1243, 1248, 1254, 1260, 1266, 1272, 1278,
1284, 1290, 1296, 1302, 1308, 1314, 1320, 1326, 1332, 1338, 1344, 1350, 1356, 1362, 1368, 1373,
1379, 1385, 1391, 1397, 1403, 1409, 1415, 1421, 1427, 1433, 1438, 1444, 1450, 1456, 1462, 1468,
1474, 1479, 1485, 1491, 1497, 1503, 1509, 1515, 1520, 1526, 1532, 1538, 1544, 1550, 1555, 1561,
1567, 1573, 1579, 1584, 1590, 1596, 1602, 1608, 1613, 1619, 1625, 1631, 1636, 1642, 1648, 1654,
1659, 1665, 1671, 1677, 1682, 1688, 1694, 1699, 1705, 1711, 1717, 1722, 1728, 1734, 1739, 1745,
1751, 1756, 1762, 1768, 1773, 1779, 1785, 1790, 1796, 1802, 1807, 1813, 1819, 1824, 1830, 1835,
1841, 1847, 1852, 1858, 1864, 1869, 1875, 1880, 1886, 1891, 1897, 1903, 1908, 1914, 1919, 1925,
1930, 1936, 1941, 1947, 1952, 1958, 1964, 1969, 1975, 1980, 1986, 1991, 1997, 2002, 2007, 2013,
2018, 2024, 2029, 2035, 2040, 2046, 2051, 2057, 2062, 2067, 2073, 2078, 2084, 2089, 2094, 2100,
2105, 2111, 2116, 2121, 2127, 2132, 2138, 2143, 2148, 2154, 2159, 2164, 2170, 2175, 2180, 2186,
2191, 2196, 2201, 2207, 2212, 2217, 2223, 2228, 2233, 2238, 2244, 2249, 2254, 2259, 2265, 2270,
2275, 2280, 2286, 2291, 2296, 2301, 2306, 2312, 2317, 2322, 2327, 2332, 2337, 2343, 2348, 2353,
2358, 2363, 2368, 2373, 2379, 2384, 2389, 2394, 2399, 2404, 2409, 2414, 2419, 2424, 2429, 2434,
2439, 2445, 2450, 2455, 2460, 2465, 2470, 2475, 2480, 2485, 2490, 2495, 2500, 2505, 2510, 2515,
2519, 2524, 2529, 2534, 2539, 2544, 2549, 2554, 2559, 2564, 2569, 2574, 2578, 2583, 2588, 2593,
2598, 2603, 2608, 2613, 2617, 2622, 2627, 2632, 2637, 2641, 2646, 2651, 2656, 2661, 2665, 2670,
2675, 2680, 2684, 2689, 2694, 2699, 2703, 2708, 2713, 2717, 2722, 2727, 2732, 2736, 2741, 2746,
2750, 2755, 2760, 2764, 2769, 2773, 2778, 2783, 2787, 2792, 2796, 2801, 2806, 2810, 2815, 2819,
2824, 2828, 2833, 2837, 2842, 2847, 2851, 2856, 2860, 2865, 2869, 2874, 2878, 2882, 2887, 2891,
2896, 2900, 2905, 2909, 2914, 2918, 2922, 2927, 2931, 2936, 2940, 2944, 2949, 2953, 2957, 2962,
2966, 2970, 2975, 2979, 2983, 2988, 2992, 2996, 3000, 3005, 3009, 3013, 3018, 3022, 3026, 3030,
3034, 3039, 3043, 3047, 3051, 3055, 3060, 3064, 3068, 3072, 3076, 3080, 3085, 3089, 3093, 3097,
3101, 3105, 3109, 3113, 3117, 3121, 3126, 3130, 3134, 3138, 3142, 3146, 3150, 3154, 3158, 3162,
3166, 3170, 3174, 3178, 3182, 3186, 3190, 3193, 3197, 3201, 3205, 3209, 3213, 3217, 3221, 3225,
3229, 3232, 3236, 3240, 3244, 3248, 3252, 3255, 3259, 3263, 3267, 3271, 3274, 3278, 3282, 3286,
3289, 3293, 3297, 3301, 3304, 3308, 3312, 3315, 3319, 3323, 3326, 3330, 3334, 3337, 3341, 3345,
3348, 3352, 3356, 3359, 3363, 3366, 3370, 3373, 3377, 3381, 3384, 3388, 3391, 3395, 3398, 3402,
3405, 3409, 3412, 3416, 3419, 3423, 3426, 3429, 3433, 3436, 3440, 3443, 3447, 3450, 3453, 3457,
3460, 3463, 3467, 3470, 3473, 3477, 3480, 3483, 3487, 3490, 3493, 3497, 3500, 3503, 3506, 3510,
3513, 3516, 3519, 3522, 3526, 3529, 3532, 3535, 3538, 3541, 3545, 3548, 3551, 3554, 3557, 3560,
3563, 3566, 3570, 3573, 3576, 3579, 3582, 3585, 3588, 3591, 3594, 3597, 3600, 3603, 3606, 3609,
3612, 3615, 3618, 3621, 3624, 3627, 3629, 3632, 3635, 3638, 3641, 3644, 3647, 3650, 3652, 3655,
3658, 3661, 3664, 3667, 3669, 3672, 3675, 3678, 3680, 3683, 3686, 3689, 3691, 3694, 3697, 3700,
3702, 3705, 3708, 3710, 3713, 3716, 3718, 3721, 3723, 3726, 3729, 3731, 3734, 3736, 3739, 3742,
3744, 3747, 3749, 3752, 3754, 3757, 3759, 3762, 3764, 3767, 3769, 3772, 3774, 3776, 3779, 3781,
3784, 3786, 3789, 3791, 3793, 3796, 3798, 3800, 3803, 3805, 3807, 3810, 3812, 3814, 3816, 3819,
3821, 3823, 3826, 3828, 3830, 3832, 3834, 3837, 3839, 3841, 3843, 3845, 3848, 3850, 3852, 3854,
3856, 3858, 3860, 3862, 3864, 3867, 3869, 3871, 3873, 3875, 3877, 3879, 3881, 3883, 3885, 3887,
3889, 3891, 3893, 3895, 3897, 3899, 3900, 3902, 3904, 3906, 3908, 3910, 3912, 3914, 3915, 3917,
3919, 3921, 3923, 3925, 3926, 3928, 3930, 3932, 3933, 3935, 3937, 3939, 3940, 3942, 3944, 3945,
3947, 3949, 3950, 3952, 3954, 3955, 3957, 3959, 3960, 3962, 3963, 3965, 3967, 3968, 3970, 3971,
3973, 3974, 3976, 3977, 3979, 3980, 3982, 3983, 3985, 3986, 3988, 3989, 3990, 3992, 3993, 3995,
3996, 3997, 3999, 4000, 4001, 4003, 4004, 4005, 4007, 4008, 4009, 4011, 4012, 4013, 4014, 4016,
4017, 4018, 4019, 4020, 4022, 4023, 4024, 4025, 4026, 4027, 4029, 4030, 4031, 4032, 4033, 4034,
4035, 4036, 4037, 4038, 4039, 4040, 4041, 4042, 4043, 4044, 4045, 4046, 4047, 4048, 4049, 4050,
4051, 4052, 4053, 4054, 4055, 4056, 4057, 4057, 4058, 4059, 4060, 4061, 4062, 4062, 4063, 4064,
4065, 4065, 4066, 4067, 4068, 4068, 4069, 4070, 4071, 4071, 4072, 4073, 4073, 4074, 4075, 4075,
4076, 4076, 4077, 4078, 4078, 4079, 4079, 4080, 4080, 4081, 4081, 4082, 4082, 4083, 4083, 4084,
4084, 4085, 4085, 4086, 4086, 4087, 4087, 4087, 4088, 4088, 4089, 4089, 4089, 4090, 4090, 4090,
4091, 4091, 4091, 4091, 4092, 4092, 4092, 4092, 4093, 4093, 4093, 4093, 4094, 4094, 4094, 4094,
4094, 4094, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095,

4096, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4094,
4094, 4094, 4094, 4094, 4094, 4093, 4093, 4093, 4093, 4092, 4092, 4092, 4092, 4091, 4091, 4091,
4091, 4090, 4090, 4090, 4089, 4089, 4089, 4088, 4088, 4087, 4087, 4087, 4086, 4086, 4085, 4085,
4084, 4084, 4083, 4083, 4082, 4082, 4081, 4081, 4080, 4080, 4079, 4079, 4078, 4078, 4077, 4076,
4076, 4075, 4075, 4074, 4073, 4073, 4072, 4071, 4071, 4070, 4069, 4068, 4068, 4067, 4066, 4065,
4065, 4064, 4063, 4062, 4062, 4061, 4060, 4059, 4058, 4057, 4057, 4056, 4055, 4054, 4053, 4052,
4051, 4050, 4049, 4048, 4047, 4046, 4045, 4044, 4043, 4042, 4041, 4040, 4039, 4038, 4037, 4036,
4035, 4034, 4033, 4032, 4031, 4030, 4029, 4027, 4026, 4025, 4024, 4023, 4022, 4020, 4019, 4018,
4017, 4016, 4014, 4013, 4012, 4011, 4009, 4008, 4007, 4005, 4004, 4003, 4001, 4000, 3999, 3997,
3996, 3995, 3993, 3992, 3990, 3989, 3988, 3986, 3985, 3983, 3982, 3980, 3979, 3977, 3976, 3974,
3973, 3971, 3970, 3968, 3967, 3965, 3963, 3962, 3960, 3959, 3957, 3955, 3954, 3952, 3950, 3949,
3947, 3945, 3944, 3942, 3940, 3939, 3937, 3935, 3933, 3932, 3930, 3928, 3926, 3925, 3923, 3921,
3919, 3917, 3915, 3914, 3912, 3910, 3908, 3906, 3904, 3902, 3900, 3899, 3897, 3895, 3893, 3891,
3889, 3887, 3885, 3883, 3881, 3879, 3877, 3875, 3873, 3871, 3869, 3867, 3864, 3862, 3860, 3858,
3856, 3854, 3852, 3850, 3848, 3845, 3843, 3841, 3839, 3837, 3834, 3832, 3830, 3828, 3826, 3823,
3821, 3819, 3816, 3814, 3812, 3810, 3807, 3805, 3803, 3800, 3798, 3796, 3793, 3791, 3789, 3786,
3784, 3781, 3779, 3776, 3774, 3772, 3769, 3767, 3764, 3762, 3759, 3757, 3754, 3752, 3749, 3747,
3744, 3742, 3739, 3736, 3734, 3731, 3729, 3726, 3723, 3721, 3718, 3716, 3713, 3710, 3708, 3705,
3702, 3700, 3697, 3694, 3691, 3689, 3686, 3683, 3680, 3678, 3675, 3672, 3669, 3667, 3664, 3661,
3658, 3655, 3652, 3650, 3647, 3644, 3641, 3638, 3635, 3632, 3629, 3627, 3624, 3621, 3618, 3615,
3612, 3609, 3606, 3603, 3600, 3597, 3594, 3591, 3588, 3585, 3582, 3579, 3576, 3573, 3570, 3566,
3563, 3560, 3557, 3554, 3551, 3548, 3545, 3541, 3538, 3535, 3532, 3529, 3526, 3522, 3519, 3516,
3513, 3510, 3506, 3503, 3500, 3497, 3493, 3490, 3487, 3483, 3480, 3477, 3473, 3470, 3467, 3463,
3460, 3457, 3453, 3450, 3447, 3443, 3440, 3436, 3433, 3429, 3426, 3423, 3419, 3416, 3412, 3409,
3405, 3402, 3398, 3395, 3391, 3388, 3384, 3381, 3377, 3373, 3370, 3366, 3363, 3359, 3356, 3352,
3348, 3345, 3341, 3337, 3334, 3330, 3326, 3323, 3319, 3315, 3312, 3308, 3304, 3301, 3297, 3293,
3289, 3286, 3282, 3278, 3274, 3271, 3267, 3263, 3259, 3255, 3252, 3248, 3244, 3240, 3236, 3232,
3229, 3225, 3221, 3217, 3213, 3209, 3205, 3201, 3197, 3193, 3190, 3186, 3182, 3178, 3174, 3170,
3166, 3162, 3158, 3154, 3150, 3146, 3142, 3138, 3134, 3130, 3126, 3121, 3117, 3113, 3109, 3105,
3101, 3097, 3093, 3089, 3085, 3080, 3076, 3072, 3068, 3064, 3060, 3055, 3051, 3047, 3043, 3039,
3034, 3030, 3026, 3022, 3018, 3013, 3009, 3005, 3000, 2996, 2992, 2988, 2983, 2979, 2975, 2970,
2966, 2962, 2957, 2953, 2949, 2944, 2940, 2936, 2931, 2927, 2922, 2918, 2914, 2909, 2905, 2900,
2896, 2891, 2887, 2882, 2878, 2874, 2869, 2865, 2860, 2856, 2851, 2847, 2842, 2837, 2833, 2828,
2824, 2819, 2815, 2810, 2806, 2801, 2796, 2792, 2787, 2783, 2778, 2773, 2769, 2764, 2760, 2755,
2750, 2746, 2741, 2736, 2732, 2727, 2722, 2717, 2713, 2708, 2703, 2699, 2694, 2689, 2684, 2680,
2675, 2670, 2665, 2661, 2656, 2651, 2646, 2641, 2637, 2632, 2627, 2622, 2617, 2613, 2608, 2603,
2598, 2593, 2588, 2583, 2578, 2574, 2569, 2564, 2559, 2554, 2549, 2544, 2539, 2534, 2529, 2524,
2519, 2515, 2510, 2505, 2500, 2495, 2490, 2485, 2480, 2475, 2470, 2465, 2460, 2455, 2450, 2445,
2439, 2434, 2429, 2424, 2419, 2414, 2409, 2404, 2399, 2394, 2389, 2384, 2379, 2373, 2368, 2363,
2358, 2353, 2348, 2343, 2337, 2332, 2327, 2322, 2317, 2312, 2306, 2301, 2296, 2291, 2286, 2280,
2275, 2270, 2265, 2259, 2254, 2249, 2244, 2238, 2233, 2228, 2223, 2217, 2212, 2207, 2201, 2196,
2191, 2186, 2180, 2175, 2170, 2164, 2159, 2154, 2148, 2143, 2138, 2132, 2127, 2121, 2116, 2111,
2105, 2100, 2094, 2089, 2084, 2078, 2073, 2067, 2062, 2057, 2051, 2046, 2040, 2035, 2029, 2024,
2018, 2013, 2007, 2002, 1997, 1991, 1986, 1980, 1975, 1969, 1964, 1958, 1952, 1947, 1941, 1936,
1930, 1925, 1919, 1914, 1908, 1903, 1897, 1891, 1886, 1880, 1875, 1869, 1864, 1858, 1852, 1847,
1841, 1835, 1830, 1824, 1819, 1813, 1807, 1802, 1796, 1790, 1785, 1779, 1773, 1768, 1762, 1756,
1751, 1745, 1739, 1734, 1728, 1722, 1717, 1711, 1705, 1699, 1694, 1688, 1682, 1677, 1671, 1665,
1659, 1654, 1648, 1642, 1636, 1631, 1625, 1619, 1613, 1608, 1602, 1596, 1590, 1584, 1579, 1573,
1567, 1561, 1555, 1550, 1544, 1538, 1532, 1526, 1520, 1515, 1509, 1503, 1497, 1491, 1485, 1479,
1474, 1468, 1462, 1456, 1450, 1444, 1438, 1433, 1427, 1421, 1415, 1409, 1403, 1397, 1391, 1385,
1379, 1373, 1368, 1362, 1356, 1350, 1344, 1338, 1332, 1326, 1320, 1314, 1308, 1302, 1296, 1290,
1284, 1278, 1272, 1266, 1260, 1254, 1248, 1243, 1237, 1231, 1225, 1219, 1213, 1207, 1201, 1195,
1189, 1182, 1176, 1170, 1164, 1158, 1152, 1146, 1140, 1134, 1128, 1122, 1116, 1110, 1104, 1098,
1092, 1086, 1080, 1074, 1068, 1062, 1056, 1050, 1043, 1037, 1031, 1025, 1019, 1013, 1007, 1001,
995, 989, 983, 976, 970, 964, 958, 952, 946, 940, 934, 928, 921, 915, 909, 903,
897, 891, 885, 879, 872, 866, 860, 854, 848, 842, 836, 829, 823, 817, 811, 805,
799, 792, 786, 780, 774, 768, 762, 755, 749, 743, 737, 731, 725, 718, 712, 706,
700, 694, 687, 681, 675, 669, 663, 656, 650, 644, 638, 632, 625, 619, 613, 607,
601, 594, 588, 582, 576, 569, 563, 557, 551, 545, 538, 532, 526, 520, 513, 507,
501, 495, 488, 482, 476, 470, 463, 457, 451, 445, 438, 432, 426, 420, 413, 407,
401, 395, 388, 382, 376, 370, 363, 357, 351, 345, 338, 332, 326, 320, 313, 307,
301, 295, 288, 282, 276, 269, 263, 257, 251, 244, 238, 232, 226, 219, 213, 207,
200, 194, 188, 182, 175, 169, 163, 157, 150, 144, 138, 131, 125, 119, 113, 106,
100, 94, 87, 81, 75, 69, 62, 56, 50, 43, 37, 31, 25, 18, 12, 6,

0, -6, -12, -18, -25, -31, -37, -43, -50, -56, -62, -69, -75, -81, -87, -94,
-100, -106, -113, -119, -125, -131, -138, -144, -150, -157, -163, -169, -175, -182, -188, -194,
-200, -207, -213, -219, -226, -232, -238, -244, -251, -257, -263, -269, -276, -282, -288, -295,
-301, -307, -313, -320, -326, -332, -338, -345, -351, -357, -363, -370, -376, -382, -388, -395,
-401, -407, -413, -420, -426, -432, -438, -445, -451, -457, -463, -470, -476, -482, -488, -495,
-501, -507, -513, -520, -526, -532, -538, -545, -551, -557, -563, -569, -576, -582, -588, -594,
-601, -607, -613, -619, -625, -632, -638, -644, -650, -656, -663, -669, -675, -681, -687, -694,
-700, -706, -712, -718, -725, -731, -737, -743, -749, -755, -762, -768, -774, -780, -786, -792,
-799, -805, -811, -817, -823, -829, -836, -842, -848, -854, -860, -866, -872, -879, -885, -891,
-897, -903, -909, -915, -921, -928, -934, -940, -946, -952, -958, -964, -970, -976, -983, -989,
-995,-1001,-1007,-1013,-1019,-1025,-1031,-1037,-1043,-1050,-1056,-1062,-1068,-1074,-1080,-1086,
-1092,-1098,-1104,-1110,-1116,-1122,-1128,-1134,-1140,-1146,-1152,-1158,-1164,-1170,-1176,-1182,
-1189,-1195,-1201,-1207,-1213,-1219,-1225,-1231,-1237,-1243,-1248,-1254,-1260,-1266,-1272,-1278,
-1284,-1290,-1296,-1302,-1308,-1314,-1320,-1326,-1332,-1338,-1344,-1350,-1356,-1362,-1368,-1373,
-1379,-1385,-1391,-1397,-1403,-1409,-1415,-1421,-1427,-1433,-1438,-1444,-1450,-1456,-1462,-1468,
-1474,-1479,-1485,-1491,-1497,-1503,-1509,-1515,-1520,-1526,-1532,-1538,-1544,-1550,-1555,-1561,
-1567,-1573,-1579,-1584,-1590,-1596,-1602,-1608,-1613,-1619,-1625,-1631,-1636,-1642,-1648,-1654,
-1659,-1665,-1671,-1677,-1682,-1688,-1694,-1699,-1705,-1711,-1717,-1722,-1728,-1734,-1739,-1745,
-1751,-1756,-1762,-1768,-1773,-1779,-1785,-1790,-1796,-1802,-1807,-1813,-1819,-1824,-1830,-1835,
-1841,-1847,-1852,-1858,-1864,-1869,-1875,-1880,-1886,-1891,-1897,-1903,-1908,-1914,-1919,-1925,
-1930,-1936,-1941,-1947,-1952,-1958,-1964,-1969,-1975,-1980,-1986,-1991,-1997,-2002,-2007,-2013,
-2018,-2024,-2029,-2035,-2040,-2046,-2051,-2057,-2062,-2067,-2073,-2078,-2084,-2089,-2094,-2100,
-2105,-2111,-2116,-2121,-2127,-2132,-2138,-2143,-2148,-2154,-2159,-2164,-2170,-2175,-2180,-2186,
-2191,-2196,-2201,-2207,-2212,-2217,-2223,-2228,-2233,-2238,-2244,-2249,-2254,-2259,-2265,-2270,
-2275,-2280,-2286,-2291,-2296,-2301,-2306,-2312,-2317,-2322,-2327,-2332,-2337,-2343,-2348,-2353,
-2358,-2363,-2368,-2373,-2379,-2384,-2389,-2394,-2399,-2404,-2409,-2414,-2419,-2424,-2429,-2434,
-2439,-2445,-2450,-2455,-2460,-2465,-2470,-2475,-2480,-2485,-2490,-2495,-2500,-2505,-2510,-2515,
-2519,-2524,-2529,-2534,-2539,-2544,-2549,-2554,-2559,-2564,-2569,-2574,-2578,-2583,-2588,-2593,
-2598,-2603,-2608,-2613,-2617,-2622,-2627,-2632,-2637,-2641,-2646,-2651,-2656,-2661,-2665,-2670,
-2675,-2680,-2684,-2689,-2694,-2699,-2703,-2708,-2713,-2717,-2722,-2727,-2732,-2736,-2741,-2746,
-2750,-2755,-2760,-2764,-2769,-2773,-2778,-2783,-2787,-2792,-2796,-2801,-2806,-2810,-2815,-2819,
-2824,-2828,-2833,-2837,-2842,-2847,-2851,-2856,-2860,-2865,-2869,-2874,-2878,-2882,-2887,-2891,
-2896,-2900,-2905,-2909,-2914,-2918,-2922,-2927,-2931,-2936,-2940,-2944,-2949,-2953,-2957,-2962,
-2966,-2970,-2975,-2979,-2983,-2988,-2992,-2996,-3000,-3005,-3009,-3013,-3018,-3022,-3026,-3030,
-3034,-3039,-3043,-3047,-3051,-3055,-3060,-3064,-3068,-3072,-3076,-3080,-3085,-3089,-3093,-3097,
-3101,-3105,-3109,-3113,-3117,-3121,-3126,-3130,-3134,-3138,-3142,-3146,-3150,-3154,-3158,-3162,
-3166,-3170,-3174,-3178,-3182,-3186,-3190,-3193,-3197,-3201,-3205,-3209,-3213,-3217,-3221,-3225,
-3229,-3232,-3236,-3240,-3244,-3248,-3252,-3255,-3259,-3263,-3267,-3271,-3274,-3278,-3282,-3286,
-3289,-3293,-3297,-3301,-3304,-3308,-3312,-3315,-3319,-3323,-3326,-3330,-3334,-3337,-3341,-3345,
-3348,-3352,-3356,-3359,-3363,-3366,-3370,-3373,-3377,-3381,-3384,-3388,-3391,-3395,-3398,-3402,
-3405,-3409,-3412,-3416,-3419,-3423,-3426,-3429,-3433,-3436,-3440,-3443,-3447,-3450,-3453,-3457,
-3460,-3463,-3467,-3470,-3473,-3477,-3480,-3483,-3487,-3490,-3493,-3497,-3500,-3503,-3506,-3510,
-3513,-3516,-3519,-3522,-3526,-3529,-3532,-3535,-3538,-3541,-3545,-3548,-3551,-3554,-3557,-3560,
-3563,-3566,-3570,-3573,-3576,-3579,-3582,-3585,-3588,-3591,-3594,-3597,-3600,-3603,-3606,-3609,
-3612,-3615,-3618,-3621,-3624,-3627,-3629,-3632,-3635,-3638,-3641,-3644,-3647,-3650,-3652,-3655,
-3658,-3661,-3664,-3667,-3669,-3672,-3675,-3678,-3680,-3683,-3686,-3689,-3691,-3694,-3697,-3700,
-3702,-3705,-3708,-3710,-3713,-3716,-3718,-3721,-3723,-3726,-3729,-3731,-3734,-3736,-3739,-3742,
-3744,-3747,-3749,-3752,-3754,-3757,-3759,-3762,-3764,-3767,-3769,-3772,-3774,-3776,-3779,-3781,
-3784,-3786,-3789,-3791,-3793,-3796,-3798,-3800,-3803,-3805,-3807,-3810,-3812,-3814,-3816,-3819,
-3821,-3823,-3826,-3828,-3830,-3832,-3834,-3837,-3839,-3841,-3843,-3845,-3848,-3850,-3852,-3854,
-3856,-3858,-3860,-3862,-3864,-3867,-3869,-3871,-3873,-3875,-3877,-3879,-3881,-3883,-3885,-3887,
-3889,-3891,-3893,-3895,-3897,-3899,-3900,-3902,-3904,-3906,-3908,-3910,-3912,-3914,-3915,-3917,
-3919,-3921,-3923,-3925,-3926,-3928,-3930,-3932,-3933,-3935,-3937,-3939,-3940,-3942,-3944,-3945,
-3947,-3949,-3950,-3952,-3954,-3955,-3957,-3959,-3960,-3962,-3963,-3965,-3967,-3968,-3970,-3971,
-3973,-3974,-3976,-3977,-3979,-3980,-3982,-3983,-3985,-3986,-3988,-3989,-3990,-3992,-3993,-3995,
-3996,-3997,-3999,-4000,-4001,-4003,-4004,-4005,-4007,-4008,-4009,-4011,-4012,-4013,-4014,-4016,
-4017,-4018,-4019,-4020,-4022,-4023,-4024,-4025,-4026,-4027,-4029,-4030,-4031,-4032,-4033,-4034,
-4035,-4036,-4037,-4038,-4039,-4040,-4041,-4042,-4043,-4044,-4045,-4046,-4047,-4048,-4049,-4050,
-4051,-4052,-4053,-4054,-4055,-4056,-4057,-4057,-4058,-4059,-4060,-4061,-4062,-4062,-4063,-4064,
-4065,-4065,-4066,-4067,-4068,-4068,-4069,-4070,-4071,-4071,-4072,-4073,-4073,-4074,-4075,-4075,
-4076,-4076,-4077,-4078,-4078,-4079,-4079,-4080,-4080,-4081,-4081,-4082,-4082,-4083,-4083,-4084,
-4084,-4085,-4085,-4086,-4086,-4087,-4087,-4087,-4088,-4088,-4089,-4089,-4089,-4090,-4090,-4090,
-4091,-4091,-4091,-4091,-4092,-4092,-4092,-4092,-4093,-4093,-4093,-4093,-4094,-4094,-4094,-4094,
-4094,-4094,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,

-4096,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4095,-4094,
-4094,-4094,-4094,-4094,-4094,-4093,-4093,-4093,-4093,-4092,-4092,-4092,-4092,-4091,-4091,-4091,
-4091,-4090,-4090,-4090,-4089,-4089,-4089,-4088,-4088,-4087,-4087,-4087,-4086,-4086,-4085,-4085,
-4084,-4084,-4083,-4083,-4082,-4082,-4081,-4081,-4080,-4080,-4079,-4079,-4078,-4078,-4077,-4076,
-4076,-4075,-4075,-4074,-4073,-4073,-4072,-4071,-4071,-4070,-4069,-4068,-4068,-4067,-4066,-4065,
-4065,-4064,-4063,-4062,-4062,-4061,-4060,-4059,-4058,-4057,-4057,-4056,-4055,-4054,-4053,-4052,
-4051,-4050,-4049,-4048,-4047,-4046,-4045,-4044,-4043,-4042,-4041,-4040,-4039,-4038,-4037,-4036,
-4035,-4034,-4033,-4032,-4031,-4030,-4029,-4027,-4026,-4025,-4024,-4023,-4022,-4020,-4019,-4018,
-4017,-4016,-4014,-4013,-4012,-4011,-4009,-4008,-4007,-4005,-4004,-4003,-4001,-4000,-3999,-3997,
-3996,-3995,-3993,-3992,-3990,-3989,-3988,-3986,-3985,-3983,-3982,-3980,-3979,-3977,-3976,-3974,
-3973,-3971,-3970,-3968,-3967,-3965,-3963,-3962,-3960,-3959,-3957,-3955,-3954,-3952,-3950,-3949,
-3947,-3945,-3944,-3942,-3940,-3939,-3937,-3935,-3933,-3932,-3930,-3928,-3926,-3925,-3923,-3921,
-3919,-3917,-3915,-3914,-3912,-3910,-3908,-3906,-3904,-3902,-3900,-3899,-3897,-3895,-3893,-3891,
-3889,-3887,-3885,-3883,-3881,-3879,-3877,-3875,-3873,-3871,-3869,-3867,-3864,-3862,-3860,-3858,
-3856,-3854,-3852,-3850,-3848,-3845,-3843,-3841,-3839,-3837,-3834,-3832,-3830,-3828,-3826,-3823,
-3821,-3819,-3816,-3814,-3812,-3810,-3807,-3805,-3803,-3800,-3798,-3796,-3793,-3791,-3789,-3786,
-3784,-3781,-3779,-3776,-3774,-3772,-3769,-3767,-3764,-3762,-3759,-3757,-3754,-3752,-3749,-3747,
-3744,-3742,-3739,-3736,-3734,-3731,-3729,-3726,-3723,-3721,-3718,-3716,-3713,-3710,-3708,-3705,
-3702,-3700,-3697,-3694,-3691,-3689,-3686,-3683,-3680,-3678,-3675,-3672,-3669,-3667,-3664,-3661,
-3658,-3655,-3652,-3650,-3647,-3644,-3641,-3638,-3635,-3632,-3629,-3627,-3624,-3621,-3618,-3615,
-3612,-3609,-3606,-3603,-3600,-3597,-3594,-3591,-3588,-3585,-3582,-3579,-3576,-3573,-3570,-3566,
-3563,-3560,-3557,-3554,-3551,-3548,-3545,-3541,-3538,-3535,-3532,-3529,-3526,-3522,-3519,-3516,
-3513,-3510,-3506,-3503,-3500,-3497,-3493,-3490,-3487,-3483,-3480,-3477,-3473,-3470,-3467,-3463,
-3460,-3457,-3453,-3450,-3447,-3443,-3440,-3436,-3433,-3429,-3426,-3423,-3419,-3416,-3412,-3409,
-3405,-3402,-3398,-3395,-3391,-3388,-3384,-3381,-3377,-3373,-3370,-3366,-3363,-3359,-3356,-3352,
-3348,-3345,-3341,-3337,-3334,-3330,-3326,-3323,-3319,-3315,-3312,-3308,-3304,-3301,-3297,-3293,
-3289,-3286,-3282,-3278,-3274,-3271,-3267,-3263,-3259,-3255,-3252,-3248,-3244,-3240,-3236,-3232,
-3229,-3225,-3221,-3217,-3213,-3209,-3205,-3201,-3197,-3193,-3190,-3186,-3182,-3178,-3174,-3170,
-3166,-3162,-3158,-3154,-3150,-3146,-3142,-3138,-3134,-3130,-3126,-3121,-3117,-3113,-3109,-3105,
-3101,-3097,-3093,-3089,-3085,-3080,-3076,-3072,-3068,-3064,-3060,-3055,-3051,-3047,-3043,-3039,
-3034,-3030,-3026,-3022,-3018,-3013,-3009,-3005,-3000,-2996,-2992,-2988,-2983,-2979,-2975,-2970,
-2966,-2962,-2957,-2953,-2949,-2944,-2940,-2936,-2931,-2927,-2922,-2918,-2914,-2909,-2905,-2900,
-2896,-2891,-2887,-2882,-2878,-2874,-2869,-2865,-2860,-2856,-2851,-2847,-2842,-2837,-2833,-2828,
-2824,-2819,-2815,-2810,-2806,-2801,-2796,-2792,-2787,-2783,-2778,-2773,-2769,-2764,-2760,-2755,
-2750,-2746,-2741,-2736,-2732,-2727,-2722,-2717,-2713,-2708,-2703,-2699,-2694,-2689,-2684,-2680,
-2675,-2670,-2665,-2661,-2656,-2651,-2646,-2641,-2637,-2632,-2627,-2622,-2617,-2613,-2608,-2603,
-2598,-2593,-2588,-2583,-2578,-2574,-2569,-2564,-2559,-2554,-2549,-2544,-2539,-2534,-2529,-2524,
-2519,-2515,-2510,-2505,-2500,-2495,-2490,-2485,-2480,-2475,-2470,-2465,-2460,-2455,-2450,-2445,
-2439,-2434,-2429,-2424,-2419,-2414,-2409,-2404,-2399,-2394,-2389,-2384,-2379,-2373,-2368,-2363,
-2358,-2353,-2348,-2343,-2337,-2332,-2327,-2322,-2317,-2312,-2306,-2301,-2296,-2291,-2286,-2280,
-2275,-2270,-2265,-2259,-2254,-2249,-2244,-2238,-2233,-2228,-2223,-2217,-2212,-2207,-2201,-2196,
-2191,-2186,-2180,-2175,-2170,-2164,-2159,-2154,-2148,-2143,-2138,-2132,-2127,-2121,-2116,-2111,
-2105,-2100,-2094,-2089,-2084,-2078,-2073,-2067,-2062,-2057,-2051,-2046,-2040,-2035,-2029,-2024,
-2018,-2013,-2007,-2002,-1997,-1991,-1986,-1980,-1975,-1969,-1964,-1958,-1952,-1947,-1941,-1936,
-1930,-1925,-1919,-1914,-1908,-1903,-1897,-1891,-1886,-1880,-1875,-1869,-1864,-1858,-1852,-1847,
-1841,-1835,-1830,-1824,-1819,-1813,-1807,-1802,-1796,-1790,-1785,-1779,-1773,-1768,-1762,-1756,
-1751,-1745,-1739,-1734,-1728,-1722,-1717,-1711,-1705,-1699,-1694,-1688,-1682,-1677,-1671,-1665,
-1659,-1654,-1648,-1642,-1636,-1631,-1625,-1619,-1613,-1608,-1602,-1596,-1590,-1584,-1579,-1573,
-1567,-1561,-1555,-1550,-1544,-1538,-1532,-1526,-1520,-1515,-1509,-1503,-1497,-1491,-1485,-1479,
-1474,-1468,-1462,-1456,-1450,-1444,-1438,-1433,-1427,-1421,-1415,-1409,-1403,-1397,-1391,-1385,
-1379,-1373,-1368,-1362,-1356,-1350,-1344,-1338,-1332,-1326,-1320,-1314,-1308,-1302,-1296,-1290,
-1284,-1278,-1272,-1266,-1260,-1254,-1248,-1243,-1237,-1231,-1225,-1219,-1213,-1207,-1201,-1195,
-1189,-1182,-1176,-1170,-1164,-1158,-1152,-1146,-1140,-1134,-1128,-1122,-1116,-1110,-1104,-1098,
-1092,-1086,-1080,-1074,-1068,-1062,-1056,-1050,-1043,-1037,-1031,-1025,-1019,-1013,-1007,-1001,
-995, -989, -983, -976, -970, -964, -958, -952, -946, -940, -934, -928, -921, -915, -909, -903,
-897, -891, -885, -879, -872, -866, -860, -854, -848, -842, -836, -829, -823, -817, -811, -805,
-799, -792, -786, -780, -774, -768, -762, -755, -749, -743, -737, -731, -725, -718, -712, -706,
-700, -694, -687, -681, -675, -669, -663, -656, -650, -644, -638, -632, -625, -619, -613, -607,
-601, -594, -588, -582, -576, -569, -563, -557, -551, -545, -538, -532, -526, -520, -513, -507,
-501, -495, -488, -482, -476, -470, -463, -457, -451, -445, -438, -432, -426, -420, -413, -407,
-401, -395, -388, -382, -376, -370, -363, -357, -351, -345, -338, -332, -326, -320, -313, -307,
-301, -295, -288, -282, -276, -269, -263, -257, -251, -244, -238, -232, -226, -219, -213, -207,
-200, -194, -188, -182, -175, -169, -163, -157, -150, -144, -138, -131, -125, -119, -113, -106,
-100, -94, -87, -81, -75, -69, -62, -56, -50, -43, -37, -31, -25, -18, -12, -6,

0, 6, 12, 18, 25, 31, 37, 43, 50, 56, 62, 69, 75, 81, 87, 94,
100, 106, 113, 119, 125, 131, 138, 144, 150, 157, 163, 169, 175, 182, 188, 194,
200, 207, 213, 219, 226, 232, 238, 244, 251, 257, 263, 269, 276, 282, 288, 295,
301, 307, 313, 320, 326, 332, 338, 345, 351, 357, 363, 370, 376, 382, 388, 395,
401, 407, 413, 420, 426, 432, 438, 445, 451, 457, 463, 470, 476, 482, 488, 495,
501, 507, 513, 520, 526, 532, 538, 545, 551, 557, 563, 569, 576, 582, 588, 594,
601, 607, 613, 619, 625, 632, 638, 644, 650, 656, 663, 669, 675, 681, 687, 694,
700, 706, 712, 718, 725, 731, 737, 743, 749, 755, 762, 768, 774, 780, 786, 792,
799, 805, 811, 817, 823, 829, 836, 842, 848, 854, 860, 866, 872, 879, 885, 891,
897, 903, 909, 915, 921, 928, 934, 940, 946, 952, 958, 964, 970, 976, 983, 989,
995, 1001, 1007, 1013, 1019, 1025, 1031, 1037, 1043, 1050, 1056, 1062, 1068, 1074, 1080, 1086,
1092, 1098, 1104, 1110, 1116, 1122, 1128, 1134, 1140, 1146, 1152, 1158, 1164, 1170, 1176, 1182,
1189, 1195, 1201, 1207, 1213, 1219, 1225, 1231, 1237, 1243, 1248, 1254, 1260, 1266, 1272, 1278,
1284, 1290, 1296, 1302, 1308, 1314, 1320, 1326, 1332, 1338, 1344, 1350, 1356, 1362, 1368, 1373,
1379, 1385, 1391, 1397, 1403, 1409, 1415, 1421, 1427, 1433, 1438, 1444, 1450, 1456, 1462, 1468,
1474, 1479, 1485, 1491, 1497, 1503, 1509, 1515, 1520, 1526, 1532, 1538, 1544, 1550, 1555, 1561,
1567, 1573, 1579, 1584, 1590, 1596, 1602, 1608, 1613, 1619, 1625, 1631, 1636, 1642, 1648, 1654,
1659, 1665, 1671, 1677, 1682, 1688, 1694, 1699, 1705, 1711, 1717, 1722, 1728, 1734, 1739, 1745,
1751, 1756, 1762, 1768, 1773, 1779, 1785, 1790, 1796, 1802, 1807, 1813, 1819, 1824, 1830, 1835,
1841, 1847, 1852, 1858, 1864, 1869, 1875, 1880, 1886, 1891, 1897, 1903, 1908, 1914, 1919, 1925,
1930, 1936, 1941, 1947, 1952, 1958, 1964, 1969, 1975, 1980, 1986, 1991, 1997, 2002, 2007, 2013,
2018, 2024, 2029, 2035, 2040, 2046, 2051, 2057, 2062, 2067, 2073, 2078, 2084, 2089, 2094, 2100,
2105, 2111, 2116, 2121, 2127, 2132, 2138, 2143, 2148, 2154, 2159, 2164, 2170, 2175, 2180, 2186,
2191, 2196, 2201, 2207, 2212, 2217, 2223, 2228, 2233, 2238, 2244, 2249, 2254, 2259, 2265, 2270,
2275, 2280, 2286, 2291, 2296, 2301, 2306, 2312, 2317, 2322, 2327, 2332, 2337, 2343, 2348, 2353,
2358, 2363, 2368, 2373, 2379, 2384, 2389, 2394, 2399, 2404, 2409, 2414, 2419, 2424, 2429, 2434,
2439, 2445, 2450, 2455, 2460, 2465, 2470, 2475, 2480, 2485, 2490, 2495, 2500, 2505, 2510, 2515,
2519, 2524, 2529, 2534, 2539, 2544, 2549, 2554, 2559, 2564, 2569, 2574, 2578, 2583, 2588, 2593,
2598, 2603, 2608, 2613, 2617, 2622, 2627, 2632, 2637, 2641, 2646, 2651, 2656, 2661, 2665, 2670,
2675, 2680, 2684, 2689, 2694, 2699, 2703, 2708, 2713, 2717, 2722, 2727, 2732, 2736, 2741, 2746,
2750, 2755, 2760, 2764, 2769, 2773, 2778, 2783, 2787, 2792, 2796, 2801, 2806, 2810, 2815, 2819,
2824, 2828, 2833, 2837, 2842, 2847, 2851, 2856, 2860, 2865, 2869, 2874, 2878, 2882, 2887, 2891,
2896, 2900, 2905, 2909, 2914, 2918, 2922, 2927, 2931, 2936, 2940, 2944, 2949, 2953, 2957, 2962,
2966, 2970, 2975, 2979, 2983, 2988, 2992, 2996, 3000, 3005, 3009, 3013, 3018, 3022, 3026, 3030,
3034, 3039, 3043, 3047, 3051, 3055, 3060, 3064, 3068, 3072, 3076, 3080, 3085, 3089, 3093, 3097,
3101, 3105, 3109, 3113, 3117, 3121, 3126, 3130, 3134, 3138, 3142, 3146, 3150, 3154, 3158, 3162,
3166, 3170, 3174, 3178, 3182, 3186, 3190, 3193, 3197, 3201, 3205, 3209, 3213, 3217, 3221, 3225,
3229, 3232, 3236, 3240, 3244, 3248, 3252, 3255, 3259, 3263, 3267, 3271, 3274, 3278, 3282, 3286,
3289, 3293, 3297, 3301, 3304, 3308, 3312, 3315, 3319, 3323, 3326, 3330, 3334, 3337, 3341, 3345,
3348, 3352, 3356, 3359, 3363, 3366, 3370, 3373, 3377, 3381, 3384, 3388, 3391, 3395, 3398, 3402,
3405, 3409, 3412, 3416, 3419, 3423, 3426, 3429, 3433, 3436, 3440, 3443, 3447, 3450, 3453, 3457,
3460, 3463, 3467, 3470, 3473, 3477, 3480, 3483, 3487, 3490, 3493, 3497, 3500, 3503, 3506, 3510,
3513, 3516, 3519, 3522, 3526, 3529, 3532, 3535, 3538, 3541, 3545, 3548, 3551, 3554, 3557, 3560,
3563, 3566, 3570, 3573, 3576, 3579, 3582, 3585, 3588, 3591, 3594, 3597, 3600, 3603, 3606, 3609,
3612, 3615, 3618, 3621, 3624, 3627, 3629, 3632, 3635, 3638, 3641, 3644, 3647, 3650, 3652, 3655,
3658, 3661, 3664, 3667, 3669, 3672, 3675, 3678, 3680, 3683, 3686, 3689, 3691, 3694, 3697, 3700,
3702, 3705, 3708, 3710, 3713, 3716, 3718, 3721, 3723, 3726, 3729, 3731, 3734, 3736, 3739, 3742,
3744, 3747, 3749, 3752, 3754, 3757, 3759, 3762, 3764, 3767, 3769, 3772, 3774, 3776, 3779, 3781,
3784, 3786, 3789, 3791, 3793, 3796, 3798, 3800, 3803, 3805, 3807, 3810, 3812, 3814, 3816, 3819,
3821, 3823, 3826, 3828, 3830, 3832, 3834, 3837, 3839, 3841, 3843, 3845, 3848, 3850, 3852, 3854,
3856, 3858, 3860, 3862, 3864, 3867, 3869, 3871, 3873, 3875, 3877, 3879, 3881, 3883, 3885, 3887,
3889, 3891, 3893, 3895, 3897, 3899, 3900, 3902, 3904, 3906, 3908, 3910, 3912, 3914, 3915, 3917,
3919, 3921, 3923, 3925, 3926, 3928, 3930, 3932, 3933, 3935, 3937, 3939, 3940, 3942, 3944, 3945,
3947, 3949, 3950, 3952, 3954, 3955, 3957, 3959, 3960, 3962, 3963, 3965, 3967, 3968, 3970, 3971,
3973, 3974, 3976, 3977, 3979, 3980, 3982, 3983, 3985, 3986, 3988, 3989, 3990, 3992, 3993, 3995,
3996, 3997, 3999, 4000, 4001, 4003, 4004, 4005, 4007, 4008, 4009, 4011, 4012, 4013, 4014, 4016,
4017, 4018, 4019, 4020, 4022, 4023, 4024, 4025, 4026, 4027, 4029, 4030, 4031, 4032, 4033, 4034,
4035, 4036, 4037, 4038, 4039, 4040, 4041, 4042, 4043, 4044, 4045, 4046, 4047, 4048, 4049, 4050,
4051, 4052, 4053, 4054, 4055, 4056, 4057, 4057, 4058, 4059, 4060, 4061, 4062, 4062, 4063, 4064,
4065, 4065, 4066, 4067, 4068, 4068, 4069, 4070, 4071, 4071, 4072, 4073, 4073, 4074, 4075, 4075,
4076, 4076, 4077, 4078, 4078, 4079, 4079, 4080, 4080, 4081, 4081, 4082, 4082, 4083, 4083, 4084,
4084, 4085, 4085, 4086, 4086, 4087, 4087, 4087, 4088, 4088, 4089, 4089, 4089, 4090, 4090, 4090,
4091, 4091, 4091, 4091, 4092, 4092, 4092, 4092, 4093, 4093, 4093, 4093, 4094, 4094, 4094, 4094,
4094, 4094, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095,

4096,
};

/* code can't actually access 2nd index >8 though */
static const int scale_table[5][8*2] = {
{ 2048, 2048, 4096, 4096, 8192, 8192,16384,16384, 1, 1, 1, 1, 1, 1, 1, 1, },
{ 2048, 2048, 2048, 4096, 4096, 4096, 8192,16384, 1, 1, 1, 1, 1, 1, 1, 1, },
{ 2048, 2048, 2048, 2048, 2048, 4096, 4096, 8192, 1, 1, 1, 1, 1, 1, 1, 1, },
{ 1024, 1024, 1024, 2048, 2048, 2048, 2048, 2048, 1, 1, 1, 1, 1, 1, 1, 1, },
{ 1365, 1365, 2048, 2730, 2730, 4096, 4096, 4096, 1, 1, 1, 1, 1, 1, 1, 1, },
};

#endif

+ 297
- 0
Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_lzxpcm.h View File

@@ -0,0 +1,297 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

/* Decompresses Circus's custom LZ used in XPCM as a machine state for streaming,
* that may break during any step. Original code decompress at once the full thing
* into memory so it's simpler. */

#define LZXPCM_OK 0
#define LZXPCM_ERROR -1
#define LZXPCM_WINDOW_SIZE (1 << 16)


typedef enum {
READ_FLAGS,
COPY_LITERAL,
READ_TOKEN,
PARSE_TOKEN,
SET_MATCH,
COPY_MATCH
} lzxpcm_state_t;

typedef struct {
lzxpcm_state_t state;

uint32_t flags;
uint8_t token;
int values_pos;
int offset_pos;
int match_len;
int match_pos;

int window_pos;
uint8_t window[LZXPCM_WINDOW_SIZE];
} lzxpcm_context_t;

typedef struct {
lzxpcm_context_t ctx;

uint8_t *next_out; /* next bytes to write (reassign when avail is 0) */
int avail_out; /* bytes available at next_out */
int total_out; /* written bytes, for reference (set to 0 per call if needed) */

const uint8_t *next_in; /* next bytes to read (reassign when avail is 0) */
int avail_in; /* bytes available at next_in */
int total_in; /* read bytes, for reference (set to 0 per call if needed) */
} lzxpcm_stream_t;


static void lzxpcm_reset(lzxpcm_stream_t* strm) {
memset(strm, 0, sizeof(lzxpcm_stream_t));
}

/* Decompress src into dst, returning a code and number of bytes used. Caller must handle
* stop (when no more input data or all data has been decompressed) as LZXPCM has no end marker. */
static int lzxpcm_decompress(lzxpcm_stream_t* strm) {
lzxpcm_context_t* ctx = &strm->ctx;
uint8_t* dst = strm->next_out;
const uint8_t* src = strm->next_in;
int dst_size = strm->avail_out;
int src_size = strm->avail_in;
int dst_pos = 0;
int src_pos = 0;
uint8_t next_val;


while (1) {
/* mostly linear state machine, but it may break anytime when reaching dst or src
* end, and resume from same state in next call */
switch(ctx->state) {

case READ_FLAGS:
if (src_pos >= src_size)
goto buffer_end;

ctx->flags >>= 1;

if ((ctx->flags & 0x0100) == 0) {
ctx->flags = 0xFF00 | src[src_pos++];
}

if (ctx->flags & 1)
ctx->state = COPY_LITERAL;
else
ctx->state = READ_TOKEN;
break;

case COPY_LITERAL:
if (src_pos >= src_size || dst_pos >= dst_size)
goto buffer_end;
next_val = src[src_pos++];

dst[dst_pos++] = next_val;

ctx->window[ctx->window_pos++] = next_val;
if (ctx->window_pos == LZXPCM_WINDOW_SIZE)
ctx->window_pos = 0;

ctx->state = READ_FLAGS;
break;

case READ_TOKEN:
if (src_pos >= src_size)
goto buffer_end;
ctx->token = src[src_pos++];

ctx->values_pos = 0;

ctx->state = PARSE_TOKEN;
break;

case PARSE_TOKEN:
if (ctx->token >= 0xC0) {
ctx->match_len = ((ctx->token >> 2) & 0x0F) + 4; /* 6b */

if (src_pos >= src_size)
goto buffer_end;
ctx->offset_pos = src[src_pos++]; /* upper 2b + lower 8b */
ctx->offset_pos |= ((ctx->token & 3) << 8);

}
else if (ctx->token >= 0x80) {
ctx->match_len = ((ctx->token >> 5) & 3) + 2; /* 2b */

ctx->offset_pos = ctx->token & 0x1F; /* 5b */
if (ctx->offset_pos == 0) {
if (src_pos >= src_size)
goto buffer_end;
ctx->offset_pos = src[src_pos++];
}
}
else if (ctx->token == 0x7F) {
if (ctx->values_pos == 0) {
if (src_pos >= src_size)
goto buffer_end;
ctx->match_len = (src[src_pos++] << 0u);
ctx->values_pos++;
}

if (ctx->values_pos == 1) {
if (src_pos >= src_size)
goto buffer_end;
ctx->match_len |= (src[src_pos++] << 8u);
ctx->match_len += 2;
ctx->values_pos++;
}
if (ctx->values_pos == 2) {
if (src_pos >= src_size)
goto buffer_end;
ctx->offset_pos = (src[src_pos++] << 0u);
ctx->values_pos++;
}

if (ctx->values_pos == 3) {
if (src_pos >= src_size)
goto buffer_end;
ctx->offset_pos |= (src[src_pos++] << 8u);
ctx->values_pos++;
}
}
else {
ctx->match_len = ctx->token + 4;

if (ctx->values_pos == 0) {
if (src_pos >= src_size)
goto buffer_end;
ctx->offset_pos = (src[src_pos++] << 0u);
ctx->values_pos++;
}

if (ctx->values_pos == 1) {
if (src_pos >= src_size)
goto buffer_end;
ctx->offset_pos |= (src[src_pos++] << 8u);
ctx->values_pos++;
}
}

ctx->state = SET_MATCH;
break;

case SET_MATCH:
ctx->match_pos = ctx->window_pos - ctx->offset_pos;
if (ctx->match_pos < 0) /* circular buffer so negative is from window end */
ctx->match_pos = LZXPCM_WINDOW_SIZE + ctx->match_pos;

ctx->state = COPY_MATCH;
break;

case COPY_MATCH:
while (ctx->match_len > 0) {
if (dst_pos >= dst_size)
goto buffer_end;

next_val = ctx->window[ctx->match_pos++];
if (ctx->match_pos == LZXPCM_WINDOW_SIZE)
ctx->match_pos = 0;

dst[dst_pos++] = next_val;

ctx->window[ctx->window_pos++] = next_val;
if (ctx->window_pos == LZXPCM_WINDOW_SIZE)
ctx->window_pos = 0;

ctx->match_len--;
};

ctx->state = READ_FLAGS;
break;

default:
goto fail;
}
}

buffer_end:
strm->next_out += dst_pos;
strm->next_in += src_pos;
strm->avail_out -= dst_pos;
strm->avail_in -= src_pos;
strm->total_out += dst_pos;
strm->total_in += src_pos;

return LZXPCM_OK;
fail:
return LZXPCM_ERROR;
}


#if 0
/* non-streamed form that XPCM originally uses, assumes buffers are big enough */
static int lzxpcm_decompress_full(uint8_t* dst, size_t dst_size, const uint8_t* src, size_t src_size) {
int src_pos = 0;
int dst_pos = 0;
uint32_t flags = 0;


while (src_pos < src_size && dst_pos < dst_size) {
flags >>= 1;

if ((flags & 0x0100) == 0) {
flags = 0xFF00 | src[src_pos++];
}
if (flags & 1) {
/* uncompressed byte per bit */
dst[dst_pos++] = src[src_pos++];
}
else {
/* compressed data */
uint32_t length;
uint32_t offset;
const uint32_t token = src[src_pos++];

if (token >= 0xC0) {
length = ((token >> 2) & 0x0F) + 4; /* 6b */

offset = ((token & 3) << 8) | src[src_pos++]; /* upper 2b + lower 8b */
}
else if (token >= 0x80) {
length = ((token >> 5) & 3) + 2; /* 2b */

offset = token & 0x1F; /* 5b */
if (offset == 0) {
offset = src[src_pos++];
}
}
else if (token == 0x7F) {
length = (uint16_t)(src[src_pos] | src[src_pos+1] << 8u) + 2;
src_pos += 2;

offset = (uint16_t)(src[src_pos] | src[src_pos+1] << 8u);
src_pos += 2;
}
else {
length = token + 4;

offset = (uint16_t)(src[src_pos] | src[src_pos+1] << 8u);
src_pos += 2;
}

if (dst_pos + length > dst_size) {
length = dst_size - dst_pos;
}

for (int i = 0; i < length; i++) {
dst[dst_pos] = dst[dst_pos - offset];
dst_pos++;
}
}
}

return 0;
}
#endif

+ 7657
- 0
Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_miniz.c
File diff suppressed because it is too large
View File


+ 1346
- 0
Frameworks/vgmstream/vgmstream/src/coding/circus_decoder_miniz.h
File diff suppressed because it is too large
View File


+ 9
- 2
Frameworks/vgmstream/vgmstream/src/coding/coding.h View File

@@ -35,7 +35,7 @@ void decode_apple_ima4(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channel
void decode_fsb_ima(VGMSTREAM * vgmstream, VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
void decode_wwise_ima(VGMSTREAM * vgmstream, VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
void decode_awc_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_ubi_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
void decode_ubi_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int codec_config);
void decode_h4m_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, uint16_t frame_format);
size_t ima_bytes_to_samples(size_t bytes, int channels);
size_t ms_ima_bytes_to_samples(size_t bytes, int block_align, int channels);
@@ -167,6 +167,7 @@ void decode_fadpcm(VGMSTREAMCHANNEL *stream, sample_t *outbuf, int channelspacin

/* asf_decoder */
void decode_asf(VGMSTREAMCHANNEL *stream, sample_t *outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
int32_t asf_bytes_to_samples(size_t bytes, int channels);

/* dsa_decoder */
void decode_dsa(VGMSTREAMCHANNEL *stream, sample_t *outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
@@ -178,7 +179,13 @@ void decode_xmd(VGMSTREAMCHANNEL *stream, sample_t *outbuf, int channelspacing,
void decode_derf(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);

/* circus_decoder */
void decode_circus_adpcm(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
typedef struct circus_codec_data circus_codec_data;
circus_codec_data* init_circus_vq(STREAMFILE* sf, off_t start, uint8_t codec, uint8_t flags);
void decode_circus_vq(circus_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels);
void reset_circus_vq(circus_codec_data* data);
void seek_circus_vq(circus_codec_data* data, int32_t num_sample);
void free_circus_vq(circus_codec_data* data);
void decode_circus_adpcm(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);

/* oki_decoder */
void decode_pcfx(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int mode);


+ 8
- 3
Frameworks/vgmstream/vgmstream/src/coding/ima_decoder.c View File

@@ -1009,8 +1009,9 @@ void decode_awc_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa


/* DVI stereo/mono with some mini header and sample output */
void decode_ubi_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel) {
void decode_ubi_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int codec_config) {
int i, sample_count = 0;
int has_header = (codec_config & 0x80) == 0;

int32_t hist1 = stream->adpcm_history1_32;
int step_index = stream->adpcm_step_index;
@@ -1018,7 +1019,7 @@ void decode_ubi_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa
//internal interleave

//header in the beginning of the stream
if (stream->channel_start_offset == stream->offset) {
if (has_header && stream->channel_start_offset == stream->offset) {
int version, big_endian, header_samples, max_samples_to_do;
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
off_t offset = stream->offset;
@@ -1051,8 +1052,12 @@ void decode_ubi_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa
}
}

if (has_header) {
first_sample -= 10; //todo fix hack (needed to adjust nibble offset below)
}

first_sample -= 10; //todo fix hack (needed to adjust nibble offset below)
if (step_index < 0) step_index=0;
if (step_index > 88) step_index=88;

for (i = first_sample; i < first_sample + samples_to_do; i++, sample_count += channelspacing) {
off_t byte_offset = channelspacing == 1 ?


+ 10
- 10
Frameworks/vgmstream/vgmstream/src/coding/psv_decoder.c View File

@@ -173,25 +173,25 @@ void decode_hevag(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspaci
if (shift_factor > 12)
shift_factor = 9; /* ? */
shift_factor = 20 - shift_factor;
/* decode nibbles */
for (i = first_sample; i < first_sample + samples_to_do; i++) {
int32_t sample = 0, scale = 0;
int32_t sample = 0;
if (flag < 0x07) { /* with flag 0x07 decoded sample must be 0 */
uint8_t nibbles = frame[0x02 + i/2];
scale = i&1 ? /* low nibble first */
sample = (i&1 ? /* low nibble first */
get_high_nibble_signed(nibbles):
get_low_nibble_signed(nibbles);
sample = (hist1 * hevag_coefs[coef_index][0] +
hist2 * hevag_coefs[coef_index][1] +
hist3 * hevag_coefs[coef_index][2] +
hist4 * hevag_coefs[coef_index][3] ) / 32;
sample = (sample + (scale << (20 - shift_factor)) + 128) >> 8;
sample = clamp16(sample);
get_low_nibble_signed(nibbles)) << shift_factor; /*scale*/
sample = ((hist1 * hevag_coefs[coef_index][0] +
hist2 * hevag_coefs[coef_index][1] +
hist3 * hevag_coefs[coef_index][2] +
hist4 * hevag_coefs[coef_index][3]) >> 5) + sample;
sample >>= 8;
}
outbuf[sample_count] = sample;
outbuf[sample_count] = clamp16(sample); /*clamping*/
sample_count += channelspacing;
hist4 = hist3;


+ 15
- 18
Frameworks/vgmstream/vgmstream/src/coding/psx_decoder.c View File

@@ -93,22 +93,22 @@ void decode_psx(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing,
VGM_ASSERT_ONCE(flag > 7,"PS-ADPCM: unknown flag at %x\n", (uint32_t)frame_offset); /* meta should use PSX-badflags */


shift_factor = 20 - shift_factor;
/* decode nibbles */
for (i = first_sample; i < first_sample + samples_to_do; i++) {
int32_t sample = 0;

if (flag < 0x07) { /* with flag 0x07 decoded sample must be 0 */
uint8_t nibbles = frame[0x02 + i/2];

sample = i&1 ? /* low nibble first */
(nibbles >> 4) & 0x0f :
(nibbles >> 0) & 0x0f;
sample = (int16_t)((sample << 12) & 0xf000) >> shift_factor; /* 16b sign extend + scale */
sample = (int32_t)(sample + ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2);
sample = clamp16(sample);
sample = (i&1 ? /* low nibble first */
get_high_nibble_signed(nibbles):
get_low_nibble_signed(nibbles)) << shift_factor; /*scale*/
sample = sample + (int32_t)((ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2) * 256.0f);
sample >>= 8;
}

outbuf[sample_count] = sample;
outbuf[sample_count] = clamp16(sample); /*clamping*/
sample_count += channelspacing;

hist2 = hist1;
@@ -192,7 +192,6 @@ void decode_psx_pivotal(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channe
uint8_t coef_index, shift_factor;
int32_t hist1 = stream->adpcm_history1_32;
int32_t hist2 = stream->adpcm_history2_32;
float scale;


/* external interleave (variable size), mono */
@@ -213,21 +212,19 @@ void decode_psx_pivotal(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channe
if (shift_factor > 12) /* same */
shift_factor = 12;

scale = (float)(1.0 / (double)(1 << shift_factor));


shift_factor = 20 - shift_factor;
/* decode nibbles */
for (i = first_sample; i < first_sample + samples_to_do; i++) {
int32_t sample = 0;
uint8_t nibbles = frame[0x01 + i/2];

sample = !(i&1) ? /* low nibble first */
(nibbles >> 0) & 0x0f :
(nibbles >> 4) & 0x0f;
sample = (int16_t)((sample << 12) & 0xf000); /* 16b sign extend + default scale */
sample = sample*scale + ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2; /* actually substracts negative coefs but whatevs */
sample = (i&1 ? /* low nibble first */
get_high_nibble_signed(nibbles):
get_low_nibble_signed(nibbles)) << shift_factor; /*scale*/
sample = sample + (int32_t)((ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2) * 256.0f); /* actually substracts negative coefs but whatevs */
sample >>= 8;

outbuf[sample_count] = clamp16(sample);
outbuf[sample_count] = clamp16(sample); /*clamping*/
sample_count += channelspacing;

hist2 = hist1;


+ 152
- 145
Frameworks/vgmstream/vgmstream/src/coding/vorbis_custom_utils_vid1.c View File

@@ -1,145 +1,152 @@
#include "vorbis_custom_decoder.h"
#ifdef VGM_USE_VORBIS
#include <vorbis/codec.h>
/* **************************************************************************** */
/* DEFS */
/* **************************************************************************** */
static int get_packet_header(STREAMFILE *streamFile, off_t *offset, size_t *size);
static int build_header_comment(uint8_t * buf, size_t bufsize);
/* **************************************************************************** */
/* EXTERNAL API */
/* **************************************************************************** */
/**
* VID1 removes the Ogg layer and uses a block layout with custom packet headers.
*
* Info from hcs's vid1_2ogg: https://github.com/hcs64/vgm_ripping/tree/master/demux/vid1_2ogg
*/
int vorbis_custom_setup_init_vid1(STREAMFILE *streamFile, off_t start_offset, vorbis_custom_codec_data *data) {
off_t offset = start_offset;
size_t packet_size = 0;
/* read header packets (id/setup), each with an VID1 header */
/* normal identificacion packet */
get_packet_header(streamFile, &offset, &packet_size);
if (packet_size > data->buffer_size) goto fail;
data->op.bytes = read_streamfile(data->buffer,offset,packet_size, streamFile);
if (vorbis_synthesis_headerin(&data->vi, &data->vc, &data->op) != 0) goto fail; /* parse identification header */
offset += packet_size;
/* generate comment packet */
data->op.bytes = build_header_comment(data->buffer, data->buffer_size);
if (!data->op.bytes) goto fail;
if (vorbis_synthesis_headerin(&data->vi, &data->vc, &data->op) !=0 ) goto fail; /* parse comment header */
/* normal setup packet */
get_packet_header(streamFile, &offset, &packet_size);
if (packet_size > data->buffer_size) goto fail;
data->op.bytes = read_streamfile(data->buffer,offset,packet_size, streamFile);
if (vorbis_synthesis_headerin(&data->vi, &data->vc, &data->op) != 0) goto fail; /* parse setup header */
offset += packet_size;
return 1;
fail:
return 0;
}
int vorbis_custom_parse_packet_vid1(VGMSTREAMCHANNEL *stream, vorbis_custom_codec_data *data) {
size_t bytes;
/* test block start */
if (read_32bitBE(stream->offset + 0x00,stream->streamfile) == 0x4652414D && /* "FRAM" */
read_32bitBE(stream->offset + 0x20,stream->streamfile) == 0x41554444) { /* "AUDD" */
data->block_offset = stream->offset;
data->block_size = read_32bitBE(stream->offset + 0x2c,stream->streamfile);
stream->offset += 0x34; /* actual start, rest is chunk sizes and maybe granule info */
}
/* get packet info the VID1 header */
get_packet_header(stream->streamfile, &stream->offset, (uint32_t*)&data->op.bytes);
if (data->op.bytes == 0 || data->op.bytes > data->buffer_size) goto fail; /* EOF or end padding */
/* read raw block */
bytes = read_streamfile(data->buffer,stream->offset, data->op.bytes,stream->streamfile);
stream->offset += data->op.bytes;
if (bytes != data->op.bytes) goto fail; /* wrong packet? */
//todo: sometimes there are short packets like 01be590000 and Vorbis complains and skips, no idea
/* test block end (weird size calc but seems ok) */
if ((stream->offset - (data->block_offset + 0x34)) >= (data->block_size - 0x06)) {
stream->offset = data->block_offset + read_32bitBE(data->block_offset + 0x04,stream->streamfile);
}
return 1;
fail:
return 0;
}
/* **************************************************************************** */
/* INTERNAL HELPERS */
/* **************************************************************************** */
static int build_header_comment(uint8_t * buf, size_t bufsize) {
int bytes = 0x19;
if (bytes > bufsize) return 0;
put_8bit (buf+0x00, 0x03); /* packet_type (comments) */
memcpy (buf+0x01, "vorbis", 6); /* id */
put_32bitLE(buf+0x07, 0x09); /* vendor_length */
memcpy (buf+0x0b, "vgmstream", 9); /* vendor_string */
put_32bitLE(buf+0x14, 0x00); /* user_comment_list_length */
put_8bit (buf+0x18, 0x01); /* framing_flag (fixed) */
return bytes;
}
/* read header in Vorbis bitpacking format */
static int get_packet_header(STREAMFILE *streamFile, off_t *offset, size_t *size) {
uint8_t ibuf[0x04]; /* header buffer */
size_t ibufsize = 0x04; /* header ~max */
vgm_bitstream ib = {0};
uint32_t size_bits;
if (read_streamfile(ibuf,(*offset),ibufsize, streamFile) != ibufsize)
goto fail;
ib.buf = ibuf;
ib.bufsize = ibufsize;
ib.b_off = 0;
ib.mode = BITSTREAM_VORBIS;
/* read using Vorbis weird LSF */
r_bits(&ib, 4,&size_bits);
r_bits(&ib, (size_bits+1),(uint32_t*)size);
/* special meaning, seen in silent frames */
if (size_bits == 0 && *size == 0 && (uint8_t)read_8bit(*offset, streamFile)==0x80) {
*size = 0x01;
}
/* pad and convert to byte offset */
if (ib.b_off % 8)
ib.b_off += 8 - (ib.b_off % 8);
*offset += (ib.b_off/8);
return 1;
fail:
return 0;
}
#endif
#include "vorbis_custom_decoder.h"

#ifdef VGM_USE_VORBIS
#include <vorbis/codec.h>