seal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (421) hide show
  1. data/.yardopts +1 -0
  2. data/LICENSE +13 -0
  3. data/README.md +265 -0
  4. data/ext/seal/extconf.rb +45 -0
  5. data/include/al/al.h +724 -0
  6. data/include/al/alc.h +277 -0
  7. data/include/al/efx-presets.h +402 -0
  8. data/include/al/efx.h +758 -0
  9. data/include/mpg123/mpg123.h +1034 -0
  10. data/include/ogg/config_types.h +25 -0
  11. data/include/ogg/ogg.h +210 -0
  12. data/include/ogg/os_types.h +147 -0
  13. data/include/seal.h +23 -0
  14. data/include/seal/buf.h +143 -0
  15. data/include/seal/core.h +95 -0
  16. data/include/seal/efs.h +112 -0
  17. data/include/seal/err.h +93 -0
  18. data/include/seal/fmt.h +58 -0
  19. data/include/seal/listener.h +103 -0
  20. data/include/seal/raw.h +86 -0
  21. data/include/seal/rvb.h +520 -0
  22. data/include/seal/src.h +413 -0
  23. data/include/seal/stream.h +81 -0
  24. data/include/vorbis/codec.h +243 -0
  25. data/include/vorbis/vorbisfile.h +206 -0
  26. data/mpg123/AUTHORS +150 -0
  27. data/mpg123/COPYING +773 -0
  28. data/mpg123/ChangeLog +3 -0
  29. data/mpg123/INSTALL +111 -0
  30. data/mpg123/Makefile.am +99 -0
  31. data/mpg123/Makefile.in +1043 -0
  32. data/mpg123/NEWS +1200 -0
  33. data/mpg123/NEWS.libmpg123 +133 -0
  34. data/mpg123/README +203 -0
  35. data/mpg123/TODO +38 -0
  36. data/mpg123/aclocal.m4 +1168 -0
  37. data/mpg123/build/config.guess +1530 -0
  38. data/mpg123/build/config.sub +1782 -0
  39. data/mpg123/build/depcomp +707 -0
  40. data/mpg123/build/install-sh +527 -0
  41. data/mpg123/build/ltmain.sh +9655 -0
  42. data/mpg123/build/missing +330 -0
  43. data/mpg123/configure +20267 -0
  44. data/mpg123/configure.ac +2178 -0
  45. data/mpg123/doc/ACCURACY +2 -0
  46. data/mpg123/doc/BENCHMARKING +110 -0
  47. data/mpg123/doc/BUGS +3 -0
  48. data/mpg123/doc/CONTACT +17 -0
  49. data/mpg123/doc/LICENSE +22 -0
  50. data/mpg123/doc/Makefile.am +32 -0
  51. data/mpg123/doc/Makefile.in +490 -0
  52. data/mpg123/doc/PATENTS +39 -0
  53. data/mpg123/doc/README.3DNOW +56 -0
  54. data/mpg123/doc/README.gain +171 -0
  55. data/mpg123/doc/README.remote +218 -0
  56. data/mpg123/doc/ROAD_TO_LGPL +270 -0
  57. data/mpg123/doc/THANKS +13 -0
  58. data/mpg123/doc/TODO +63 -0
  59. data/mpg123/doc/doxy_examples.c +21 -0
  60. data/mpg123/doc/doxygen.conf +41 -0
  61. data/mpg123/doc/doxyhead.xhtml +12 -0
  62. data/mpg123/doc/examples/dump_seekindex.c +41 -0
  63. data/mpg123/doc/examples/extract_frames.c +92 -0
  64. data/mpg123/doc/examples/feedseek.c +238 -0
  65. data/mpg123/doc/examples/id3dump.c +178 -0
  66. data/mpg123/doc/examples/mpg123_to_wav.c +118 -0
  67. data/mpg123/doc/examples/mpglib.c +92 -0
  68. data/mpg123/doc/examples/scan.c +47 -0
  69. data/mpg123/doc/libmpg123_speed.txt +84 -0
  70. data/mpg123/equalize.dat +37 -0
  71. data/mpg123/libmpg123.pc.in +11 -0
  72. data/mpg123/m4/addrconfig.m4 +34 -0
  73. data/mpg123/m4/libtool.m4 +7982 -0
  74. data/mpg123/m4/ltoptions.m4 +384 -0
  75. data/mpg123/m4/ltsugar.m4 +123 -0
  76. data/mpg123/m4/ltversion.m4 +23 -0
  77. data/mpg123/m4/lt~obsolete.m4 +98 -0
  78. data/mpg123/makedll.sh +19 -0
  79. data/mpg123/man1/mpg123.1 +512 -0
  80. data/mpg123/mpg123.spec +68 -0
  81. data/mpg123/mpg123.spec.in +68 -0
  82. data/mpg123/ports/MSVC++/2005/libmpg123/libmpg123.vcproj +741 -0
  83. data/mpg123/ports/MSVC++/2008/dump_seekindex/dump_seekindex.vcproj +194 -0
  84. data/mpg123/ports/MSVC++/2008/feedseek/feedseek.vcproj +195 -0
  85. data/mpg123/ports/MSVC++/2008/libmpg123/libmpg123.vcproj +1357 -0
  86. data/mpg123/ports/MSVC++/2008/mpg123.sln +44 -0
  87. data/mpg123/ports/MSVC++/2008/mpglib/mpglib.vcproj +191 -0
  88. data/mpg123/ports/MSVC++/2008/scan/scan.vcproj +195 -0
  89. data/mpg123/ports/MSVC++/2008clr/2008clr.sln +81 -0
  90. data/mpg123/ports/MSVC++/2008clr/examples/ReplaceReaderclr/Program.cs +435 -0
  91. data/mpg123/ports/MSVC++/2008clr/examples/ReplaceReaderclr/Properties/AssemblyInfo.cs +36 -0
  92. data/mpg123/ports/MSVC++/2008clr/examples/ReplaceReaderclr/ReplaceReaderclr.csproj +72 -0
  93. data/mpg123/ports/MSVC++/2008clr/examples/feedseekclr/Program.cs +331 -0
  94. data/mpg123/ports/MSVC++/2008clr/examples/feedseekclr/Properties/AssemblyInfo.cs +36 -0
  95. data/mpg123/ports/MSVC++/2008clr/examples/feedseekclr/feedseekclr.csproj +71 -0
  96. data/mpg123/ports/MSVC++/2008clr/examples/scanclr/Program.cs +79 -0
  97. data/mpg123/ports/MSVC++/2008clr/examples/scanclr/Properties/AssemblyInfo.cs +36 -0
  98. data/mpg123/ports/MSVC++/2008clr/examples/scanclr/scanclr.csproj +70 -0
  99. data/mpg123/ports/MSVC++/2008clr/mpg123clr/AssemblyInfo.cpp +76 -0
  100. data/mpg123/ports/MSVC++/2008clr/mpg123clr/ReadMe.txt +165 -0
  101. data/mpg123/ports/MSVC++/2008clr/mpg123clr/advanced.cpp +91 -0
  102. data/mpg123/ports/MSVC++/2008clr/mpg123clr/advanced.h +130 -0
  103. data/mpg123/ports/MSVC++/2008clr/mpg123clr/dllmain.cpp +19 -0
  104. data/mpg123/ports/MSVC++/2008clr/mpg123clr/enum.h +218 -0
  105. data/mpg123/ports/MSVC++/2008clr/mpg123clr/error.cpp +48 -0
  106. data/mpg123/ports/MSVC++/2008clr/mpg123clr/error.h +134 -0
  107. data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v1.cpp +92 -0
  108. data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v1.h +132 -0
  109. data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v2.cpp +138 -0
  110. data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v2.h +152 -0
  111. data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.cpp +896 -0
  112. data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.h +953 -0
  113. data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.rc +102 -0
  114. data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.vcproj +328 -0
  115. data/mpg123/ports/MSVC++/2008clr/mpg123clr/resource.h +14 -0
  116. data/mpg123/ports/MSVC++/2008clr/mpg123clr/stdafx.cpp +8 -0
  117. data/mpg123/ports/MSVC++/2008clr/mpg123clr/stdafx.h +38 -0
  118. data/mpg123/ports/MSVC++/2008clr/mpg123clr/string.cpp +166 -0
  119. data/mpg123/ports/MSVC++/2008clr/mpg123clr/string.h +265 -0
  120. data/mpg123/ports/MSVC++/2008clr/mpg123clr/targetver.h +24 -0
  121. data/mpg123/ports/MSVC++/2008clr/mpg123clr/text.cpp +67 -0
  122. data/mpg123/ports/MSVC++/2008clr/mpg123clr/text.h +111 -0
  123. data/mpg123/ports/MSVC++/2010/dump_seekindex/dump_seekindex.vcxproj +90 -0
  124. data/mpg123/ports/MSVC++/2010/dump_seekindex/dump_seekindex.vcxproj.filters +6 -0
  125. data/mpg123/ports/MSVC++/2010/feedseek/feedseek.vcxproj +95 -0
  126. data/mpg123/ports/MSVC++/2010/feedseek/feedseek.vcxproj.filters +6 -0
  127. data/mpg123/ports/MSVC++/2010/libmpg123/libmpg123.vcxproj +960 -0
  128. data/mpg123/ports/MSVC++/2010/libmpg123/libmpg123.vcxproj.user +3 -0
  129. data/mpg123/ports/MSVC++/2010/libmpg123/yasm.exe +0 -0
  130. data/mpg123/ports/MSVC++/2010/mpg123.sln +38 -0
  131. data/mpg123/ports/MSVC++/2010/scan/scan.vcxproj +93 -0
  132. data/mpg123/ports/MSVC++/2010/scan/scan.vcxproj.filters +6 -0
  133. data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/CORE/CORE_FileIn.H +15 -0
  134. data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/CORE/SourceFilter_MP3.H +139 -0
  135. data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/IIEP_Def.H +206 -0
  136. data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/IIEP_FileIn.H +167 -0
  137. data/mpg123/ports/MSVC++/CMP3Stream/README +4 -0
  138. data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/CORE_FileIn.CPP +462 -0
  139. data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/CORE_Log.CPP +122 -0
  140. data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/CORE_Mutex.CPP +35 -0
  141. data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/SourceFilter_MP3Stream.CPP +586 -0
  142. data/mpg123/ports/MSVC++/CMP3Stream/libMPG123/PLACE_LIBMPG123_SOURCES_HERE +0 -0
  143. data/mpg123/ports/MSVC++/CMP3Stream/libMPG123/libMPG123.vcproj +245 -0
  144. data/mpg123/ports/MSVC++/config.h +35 -0
  145. data/mpg123/ports/MSVC++/examples/feedseek.c +240 -0
  146. data/mpg123/ports/MSVC++/examples/scan.c +47 -0
  147. data/mpg123/ports/MSVC++/mpg123.h +46 -0
  148. data/mpg123/ports/MSVC++/msvc.c +59 -0
  149. data/mpg123/ports/README +26 -0
  150. data/mpg123/ports/Sony_PSP/Makefile.psp +38 -0
  151. data/mpg123/ports/Sony_PSP/README +11 -0
  152. data/mpg123/ports/Sony_PSP/config.h +368 -0
  153. data/mpg123/ports/Sony_PSP/readers.c.patch +2 -0
  154. data/mpg123/ports/Xcode/config.h +197 -0
  155. data/mpg123/ports/Xcode/mpg123.h +17 -0
  156. data/mpg123/ports/Xcode/mpg123.xcodeproj/project.pbxproj +670 -0
  157. data/mpg123/ports/mpg123_.pas +478 -0
  158. data/mpg123/scripts/benchmark-cpu.pl +56 -0
  159. data/mpg123/scripts/tag_lyrics.py +76 -0
  160. data/mpg123/src/Makefile.am +186 -0
  161. data/mpg123/src/Makefile.in +1097 -0
  162. data/mpg123/src/audio.c +725 -0
  163. data/mpg123/src/audio.h +106 -0
  164. data/mpg123/src/buffer.c +312 -0
  165. data/mpg123/src/buffer.h +45 -0
  166. data/mpg123/src/common.c +240 -0
  167. data/mpg123/src/common.h +29 -0
  168. data/mpg123/src/config.h.in +436 -0
  169. data/mpg123/src/control_generic.c +809 -0
  170. data/mpg123/src/equalizer.c +48 -0
  171. data/mpg123/src/genre.c +271 -0
  172. data/mpg123/src/genre.h +15 -0
  173. data/mpg123/src/getlopt.c +148 -0
  174. data/mpg123/src/getlopt.h +77 -0
  175. data/mpg123/src/httpget.c +700 -0
  176. data/mpg123/src/httpget.h +66 -0
  177. data/mpg123/src/legacy_module.c +74 -0
  178. data/mpg123/src/libmpg123/Makefile.am +141 -0
  179. data/mpg123/src/libmpg123/Makefile.in +919 -0
  180. data/mpg123/src/libmpg123/compat.c +138 -0
  181. data/mpg123/src/libmpg123/compat.h +178 -0
  182. data/mpg123/src/libmpg123/dct36_3dnow.S +505 -0
  183. data/mpg123/src/libmpg123/dct36_3dnowext.S +512 -0
  184. data/mpg123/src/libmpg123/dct64.c +174 -0
  185. data/mpg123/src/libmpg123/dct64_3dnow.S +712 -0
  186. data/mpg123/src/libmpg123/dct64_3dnowext.S +714 -0
  187. data/mpg123/src/libmpg123/dct64_altivec.c +315 -0
  188. data/mpg123/src/libmpg123/dct64_i386.c +336 -0
  189. data/mpg123/src/libmpg123/dct64_i486.c +342 -0
  190. data/mpg123/src/libmpg123/dct64_mmx.S +811 -0
  191. data/mpg123/src/libmpg123/dct64_neon.S +297 -0
  192. data/mpg123/src/libmpg123/dct64_neon_float.S +270 -0
  193. data/mpg123/src/libmpg123/dct64_sse.S +454 -0
  194. data/mpg123/src/libmpg123/dct64_sse_float.S +401 -0
  195. data/mpg123/src/libmpg123/dct64_x86_64.S +464 -0
  196. data/mpg123/src/libmpg123/dct64_x86_64_float.S +426 -0
  197. data/mpg123/src/libmpg123/debug.h +171 -0
  198. data/mpg123/src/libmpg123/decode.h +268 -0
  199. data/mpg123/src/libmpg123/dither.c +119 -0
  200. data/mpg123/src/libmpg123/dither.h +23 -0
  201. data/mpg123/src/libmpg123/equalizer.c +17 -0
  202. data/mpg123/src/libmpg123/equalizer_3dnow.S +70 -0
  203. data/mpg123/src/libmpg123/feature.c +106 -0
  204. data/mpg123/src/libmpg123/format.c +521 -0
  205. data/mpg123/src/libmpg123/frame.c +1046 -0
  206. data/mpg123/src/libmpg123/frame.h +410 -0
  207. data/mpg123/src/libmpg123/gapless.h +119 -0
  208. data/mpg123/src/libmpg123/getbits.h +100 -0
  209. data/mpg123/src/libmpg123/getcpuflags.S +91 -0
  210. data/mpg123/src/libmpg123/getcpuflags.h +47 -0
  211. data/mpg123/src/libmpg123/huffman.h +340 -0
  212. data/mpg123/src/libmpg123/icy.c +32 -0
  213. data/mpg123/src/libmpg123/icy.h +38 -0
  214. data/mpg123/src/libmpg123/icy2utf8.c +438 -0
  215. data/mpg123/src/libmpg123/icy2utf8.h +10 -0
  216. data/mpg123/src/libmpg123/id3.c +999 -0
  217. data/mpg123/src/libmpg123/id3.h +43 -0
  218. data/mpg123/src/libmpg123/index.c +134 -0
  219. data/mpg123/src/libmpg123/index.h +59 -0
  220. data/mpg123/src/libmpg123/intsym.h +256 -0
  221. data/mpg123/src/libmpg123/l12_integer_tables.h +278 -0
  222. data/mpg123/src/libmpg123/l2tables.h +164 -0
  223. data/mpg123/src/libmpg123/l3_integer_tables.h +1002 -0
  224. data/mpg123/src/libmpg123/layer1.c +155 -0
  225. data/mpg123/src/libmpg123/layer2.c +371 -0
  226. data/mpg123/src/libmpg123/layer3.c +2053 -0
  227. data/mpg123/src/libmpg123/lfs_alias.c +252 -0
  228. data/mpg123/src/libmpg123/lfs_wrap.c +751 -0
  229. data/mpg123/src/libmpg123/libmpg123.c +1607 -0
  230. data/mpg123/src/libmpg123/mangle.h +74 -0
  231. data/mpg123/src/libmpg123/mpeghead.h +87 -0
  232. data/mpg123/src/libmpg123/mpg123.h.in +1075 -0
  233. data/mpg123/src/libmpg123/mpg123lib_intern.h +338 -0
  234. data/mpg123/src/libmpg123/ntom.c +148 -0
  235. data/mpg123/src/libmpg123/optimize.c +964 -0
  236. data/mpg123/src/libmpg123/optimize.h +219 -0
  237. data/mpg123/src/libmpg123/parse.c +1179 -0
  238. data/mpg123/src/libmpg123/parse.h +25 -0
  239. data/mpg123/src/libmpg123/reader.h +137 -0
  240. data/mpg123/src/libmpg123/readers.c +1235 -0
  241. data/mpg123/src/libmpg123/sample.h +152 -0
  242. data/mpg123/src/libmpg123/stringbuf.c +163 -0
  243. data/mpg123/src/libmpg123/synth.c +816 -0
  244. data/mpg123/src/libmpg123/synth.h +196 -0
  245. data/mpg123/src/libmpg123/synth_3dnow.S +318 -0
  246. data/mpg123/src/libmpg123/synth_3dnowext.S +6 -0
  247. data/mpg123/src/libmpg123/synth_8bit.c +142 -0
  248. data/mpg123/src/libmpg123/synth_8bit.h +86 -0
  249. data/mpg123/src/libmpg123/synth_altivec.c +1057 -0
  250. data/mpg123/src/libmpg123/synth_arm.S +271 -0
  251. data/mpg123/src/libmpg123/synth_arm_accurate.S +287 -0
  252. data/mpg123/src/libmpg123/synth_i486.c +252 -0
  253. data/mpg123/src/libmpg123/synth_i586.S +336 -0
  254. data/mpg123/src/libmpg123/synth_i586_dither.S +375 -0
  255. data/mpg123/src/libmpg123/synth_mmx.S +125 -0
  256. data/mpg123/src/libmpg123/synth_mono.h +64 -0
  257. data/mpg123/src/libmpg123/synth_neon.S +123 -0
  258. data/mpg123/src/libmpg123/synth_neon_accurate.S +173 -0
  259. data/mpg123/src/libmpg123/synth_neon_float.S +149 -0
  260. data/mpg123/src/libmpg123/synth_neon_s32.S +168 -0
  261. data/mpg123/src/libmpg123/synth_ntom.h +213 -0
  262. data/mpg123/src/libmpg123/synth_real.c +404 -0
  263. data/mpg123/src/libmpg123/synth_s32.c +411 -0
  264. data/mpg123/src/libmpg123/synth_sse.S +6 -0
  265. data/mpg123/src/libmpg123/synth_sse3d.h +246 -0
  266. data/mpg123/src/libmpg123/synth_sse_accurate.S +294 -0
  267. data/mpg123/src/libmpg123/synth_sse_float.S +241 -0
  268. data/mpg123/src/libmpg123/synth_sse_s32.S +306 -0
  269. data/mpg123/src/libmpg123/synth_stereo_neon.S +175 -0
  270. data/mpg123/src/libmpg123/synth_stereo_neon_accurate.S +262 -0
  271. data/mpg123/src/libmpg123/synth_stereo_neon_float.S +220 -0
  272. data/mpg123/src/libmpg123/synth_stereo_neon_s32.S +247 -0
  273. data/mpg123/src/libmpg123/synth_stereo_sse_accurate.S +508 -0
  274. data/mpg123/src/libmpg123/synth_stereo_sse_float.S +416 -0
  275. data/mpg123/src/libmpg123/synth_stereo_sse_s32.S +540 -0
  276. data/mpg123/src/libmpg123/synth_stereo_x86_64.S +335 -0
  277. data/mpg123/src/libmpg123/synth_stereo_x86_64_accurate.S +454 -0
  278. data/mpg123/src/libmpg123/synth_stereo_x86_64_float.S +396 -0
  279. data/mpg123/src/libmpg123/synth_stereo_x86_64_s32.S +473 -0
  280. data/mpg123/src/libmpg123/synth_x86_64.S +244 -0
  281. data/mpg123/src/libmpg123/synth_x86_64_accurate.S +301 -0
  282. data/mpg123/src/libmpg123/synth_x86_64_float.S +259 -0
  283. data/mpg123/src/libmpg123/synth_x86_64_s32.S +312 -0
  284. data/mpg123/src/libmpg123/synths.h +52 -0
  285. data/mpg123/src/libmpg123/tabinit.c +294 -0
  286. data/mpg123/src/libmpg123/tabinit_mmx.S +210 -0
  287. data/mpg123/src/libmpg123/testcpu.c +35 -0
  288. data/mpg123/src/libmpg123/true.h +14 -0
  289. data/mpg123/src/local.c +63 -0
  290. data/mpg123/src/local.h +21 -0
  291. data/mpg123/src/metaprint.c +373 -0
  292. data/mpg123/src/metaprint.h +17 -0
  293. data/mpg123/src/module.c +306 -0
  294. data/mpg123/src/module.h +48 -0
  295. data/mpg123/src/mpg123.c +1405 -0
  296. data/mpg123/src/mpg123app.h +171 -0
  297. data/mpg123/src/output/Makefile.am +213 -0
  298. data/mpg123/src/output/Makefile.in +1238 -0
  299. data/mpg123/src/output/aix.c +300 -0
  300. data/mpg123/src/output/alib.c +209 -0
  301. data/mpg123/src/output/alsa.c +297 -0
  302. data/mpg123/src/output/arts.c +117 -0
  303. data/mpg123/src/output/coreaudio.c +370 -0
  304. data/mpg123/src/output/dummy.c +78 -0
  305. data/mpg123/src/output/esd.c +167 -0
  306. data/mpg123/src/output/hp.c +184 -0
  307. data/mpg123/src/output/jack.c +450 -0
  308. data/mpg123/src/output/mint.c +197 -0
  309. data/mpg123/src/output/nas.c +335 -0
  310. data/mpg123/src/output/openal.c +197 -0
  311. data/mpg123/src/output/os2.c +665 -0
  312. data/mpg123/src/output/oss.c +319 -0
  313. data/mpg123/src/output/portaudio.c +255 -0
  314. data/mpg123/src/output/pulse.c +164 -0
  315. data/mpg123/src/output/sdl.c +206 -0
  316. data/mpg123/src/output/sgi.c +213 -0
  317. data/mpg123/src/output/sndio.c +161 -0
  318. data/mpg123/src/output/sun.c +281 -0
  319. data/mpg123/src/output/win32.c +229 -0
  320. data/mpg123/src/playlist.c +596 -0
  321. data/mpg123/src/playlist.h +52 -0
  322. data/mpg123/src/resolver.c +319 -0
  323. data/mpg123/src/resolver.h +25 -0
  324. data/mpg123/src/sfifo.c +146 -0
  325. data/mpg123/src/sfifo.h +95 -0
  326. data/mpg123/src/streamdump.c +74 -0
  327. data/mpg123/src/streamdump.h +20 -0
  328. data/mpg123/src/term.c +479 -0
  329. data/mpg123/src/term.h +81 -0
  330. data/mpg123/src/tests/noise.c +52 -0
  331. data/mpg123/src/tests/plain_id3.c +109 -0
  332. data/mpg123/src/tests/seek_accuracy.c +261 -0
  333. data/mpg123/src/tests/seek_whence.c +56 -0
  334. data/mpg123/src/tests/testtext.h +34 -0
  335. data/mpg123/src/tests/text.c +80 -0
  336. data/mpg123/src/wav.c +464 -0
  337. data/mpg123/src/wavhead.h +68 -0
  338. data/mpg123/src/win32_net.c +599 -0
  339. data/mpg123/src/win32_support.c +191 -0
  340. data/mpg123/src/win32_support.h +152 -0
  341. data/mpg123/src/xfermem.c +321 -0
  342. data/mpg123/src/xfermem.h +74 -0
  343. data/mpg123/windows-builds.sh +137 -0
  344. data/msvc/lib/OpenAL32.lib +0 -0
  345. data/spec/fixtures/heal.ogg +0 -0
  346. data/spec/fixtures/tone_up.wav +0 -0
  347. data/spec/seal/buffer_spec.rb +37 -0
  348. data/spec/seal/core_spec.rb +29 -0
  349. data/spec/seal/effect_slot_spec.rb +38 -0
  350. data/spec/seal/listener_spec.rb +33 -0
  351. data/spec/seal/reverb_spec.rb +51 -0
  352. data/spec/seal/source_spec.rb +370 -0
  353. data/spec/seal/stream_spec.rb +38 -0
  354. data/spec/spec_helper.rb +45 -0
  355. data/spec/support/attribute_examples.rb +75 -0
  356. data/spec/support/audio_object_with_format.rb +27 -0
  357. data/spec/support/movable_object.rb +22 -0
  358. data/src/libogg/bitwise.c +857 -0
  359. data/src/libogg/framing.c +2093 -0
  360. data/src/libvorbis/backends.h +144 -0
  361. data/src/libvorbis/bitrate.c +253 -0
  362. data/src/libvorbis/bitrate.h +59 -0
  363. data/src/libvorbis/block.c +1046 -0
  364. data/src/libvorbis/codebook.c +484 -0
  365. data/src/libvorbis/codebook.h +119 -0
  366. data/src/libvorbis/codec_internal.h +167 -0
  367. data/src/libvorbis/envelope.c +375 -0
  368. data/src/libvorbis/envelope.h +80 -0
  369. data/src/libvorbis/floor0.c +221 -0
  370. data/src/libvorbis/floor1.c +1100 -0
  371. data/src/libvorbis/highlevel.h +58 -0
  372. data/src/libvorbis/info.c +668 -0
  373. data/src/libvorbis/lookup.c +94 -0
  374. data/src/libvorbis/lookup.h +32 -0
  375. data/src/libvorbis/lookup_data.h +192 -0
  376. data/src/libvorbis/lpc.c +160 -0
  377. data/src/libvorbis/lpc.h +29 -0
  378. data/src/libvorbis/lsp.c +456 -0
  379. data/src/libvorbis/lsp.h +28 -0
  380. data/src/libvorbis/mapping0.c +816 -0
  381. data/src/libvorbis/masking.h +785 -0
  382. data/src/libvorbis/mdct.c +563 -0
  383. data/src/libvorbis/mdct.h +71 -0
  384. data/src/libvorbis/misc.h +57 -0
  385. data/src/libvorbis/os.h +186 -0
  386. data/src/libvorbis/psy.c +1206 -0
  387. data/src/libvorbis/psy.h +154 -0
  388. data/src/libvorbis/registry.c +45 -0
  389. data/src/libvorbis/registry.h +32 -0
  390. data/src/libvorbis/res0.c +889 -0
  391. data/src/libvorbis/scales.h +90 -0
  392. data/src/libvorbis/sharedbook.c +579 -0
  393. data/src/libvorbis/smallft.c +1255 -0
  394. data/src/libvorbis/smallft.h +34 -0
  395. data/src/libvorbis/synthesis.c +184 -0
  396. data/src/libvorbis/vorbisfile.c +2337 -0
  397. data/src/libvorbis/window.c +2135 -0
  398. data/src/libvorbis/window.h +26 -0
  399. data/src/rubyext.c +2329 -0
  400. data/src/seal/buf.c +124 -0
  401. data/src/seal/core.c +283 -0
  402. data/src/seal/efs.c +74 -0
  403. data/src/seal/err.c +118 -0
  404. data/src/seal/fmt.c +86 -0
  405. data/src/seal/listener.c +111 -0
  406. data/src/seal/mpg.c +174 -0
  407. data/src/seal/mpg.h +24 -0
  408. data/src/seal/ov.c +180 -0
  409. data/src/seal/ov.h +22 -0
  410. data/src/seal/raw.c +59 -0
  411. data/src/seal/reader.c +102 -0
  412. data/src/seal/reader.h +59 -0
  413. data/src/seal/rvb.c +368 -0
  414. data/src/seal/src.c +654 -0
  415. data/src/seal/stream.c +109 -0
  416. data/src/seal/threading.c +66 -0
  417. data/src/seal/threading.h +20 -0
  418. data/src/seal/wav.c +297 -0
  419. data/src/seal/wav.h +23 -0
  420. data/src/win32api.rb +29 -0
  421. metadata +563 -0
@@ -0,0 +1,219 @@
1
+ #ifndef MPG123_H_OPTIMIZE
2
+ #define MPG123_H_OPTIMIZE
3
+ /*
4
+ optimize: get a grip on the different optimizations
5
+
6
+ copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
7
+ see COPYING and AUTHORS files in distribution or http://mpg123.org
8
+ initially written by Thomas Orgis, taking from mpg123.[hc]
9
+
10
+ for building mpg123 with one optimization only, you have to choose exclusively between
11
+ OPT_GENERIC (generic C code for everyone)
12
+ OPT_GENERIC_DITHER (same with dithering for 1to1)
13
+ OPT_I386 (Intel i386)
14
+ OPT_I486 (Somewhat special code for i486; does not work together with others.)
15
+ OPT_I586 (Intel Pentium)
16
+ OPT_I586_DITHER (Intel Pentium with dithering/noise shaping for enhanced quality)
17
+ OPT_MMX (Intel Pentium and compatibles with MMX, fast, but not the best accuracy)
18
+ OPT_3DNOW (AMD 3DNow!, K6-2/3, Athlon, compatibles...)
19
+ OPT_3DNOWEXT (AMD 3DNow! extended, generally Athlon, compatibles...)
20
+ OPT_ALTIVEC (Motorola/IBM PPC with AltiVec under MacOSX)
21
+ OPT_X86_64 (x86-64 / AMD64 / Intel 64)
22
+
23
+ or you define OPT_MULTI and give a combination which makes sense (do not include i486, do not mix altivec and x86).
24
+
25
+ I still have to examine the dynamics of this here together with REAL_IS_FIXED.
26
+ Basic point is: Don't use REAL_IS_FIXED with something else than generic or i386.
27
+
28
+ Also, one should minimize code size by really ensuring that only functions that are really needed are included.
29
+ Currently, all generic functions will be always there (to be safe for fallbacks for advanced decoders).
30
+ Strictly, at least the synth_1to1 should not be necessary for single-decoder mode.
31
+ */
32
+
33
+
34
+ /* Runtime optimization interface now here: */
35
+
36
+ enum optdec
37
+ { /* autodec needs to be =0 and the first, nodec needs to be the last -- for loops! */
38
+ autodec=0, generic, generic_dither, idrei,
39
+ ivier, ifuenf, ifuenf_dither, mmx,
40
+ dreidnow, dreidnowext, altivec, sse, x86_64, arm, neon,
41
+ nodec
42
+ };
43
+ enum optcla { nocla=0, normal, mmxsse };
44
+
45
+ /* - Set up the table of synth functions for current decoder choice. */
46
+ int frame_cpu_opt(mpg123_handle *fr, const char* cpu);
47
+ /* - Choose, from the synth table, the synth functions to use for current output format/rate. */
48
+ int set_synth_functions(mpg123_handle *fr);
49
+ /* - Parse decoder name and return numerical code. */
50
+ enum optdec dectype(const char* decoder);
51
+ /* - Return the default decoder type. */
52
+ enum optdec defdec(void);
53
+ /* - Return the class of a decoder type (mmxsse or normal). */
54
+ enum optcla decclass(const enum optdec);
55
+
56
+ /* Now comes a whole lot of definitions, for multi decoder mode and single decoder mode.
57
+ Because of the latter, it may look redundant at times. */
58
+
59
+ /* this is included in mpg123.h, which includes config.h */
60
+ #ifdef CCALIGN
61
+ #define ALIGNED(a) __attribute__((aligned(a)))
62
+ #else
63
+ #define ALIGNED(a)
64
+ #endif
65
+
66
+ /* Safety catch for invalid decoder choice. */
67
+ #ifdef REAL_IS_FIXED
68
+ #if (defined OPT_I486) || (defined OPT_I586) || (defined OPT_I586_DITHER) \
69
+ || (defined OPT_MMX) || (defined OPT_SSE) || (defined_OPT_ALTIVEC) \
70
+ || (defined OPT_3DNOW) || (defined OPT_3DNOWEXT) || (defined OPT_X86_64) \
71
+ || (defined OPT_NEON) || (defined OPT_GENERIC_DITHER)
72
+ #error "Bad decoder choice together with fixed point math!"
73
+ #endif
74
+ #endif
75
+
76
+ #if (defined NO_LAYER1 && defined NO_LAYER2)
77
+ #define NO_LAYER12
78
+ #endif
79
+
80
+ #ifdef OPT_GENERIC
81
+ #ifndef OPT_MULTI
82
+ # define defopt generic
83
+ #endif
84
+ #endif
85
+
86
+ #ifdef OPT_GENERIC_DITHER
87
+ #define OPT_DITHER
88
+ #ifndef OPT_MULTI
89
+ # define defopt generic_dither
90
+ #endif
91
+ #endif
92
+
93
+ /* i486 is special... always alone! */
94
+ #ifdef OPT_I486
95
+ #define OPT_X86
96
+ #define defopt ivier
97
+ #ifdef OPT_MULTI
98
+ #error "i486 can only work alone!"
99
+ #endif
100
+ #define FIR_BUFFER_SIZE 128
101
+ #define FIR_SIZE 16
102
+ #endif
103
+
104
+ #ifdef OPT_I386
105
+ #define OPT_X86
106
+ #ifndef OPT_MULTI
107
+ # define defopt idrei
108
+ #endif
109
+ #endif
110
+
111
+ #ifdef OPT_I586
112
+ #define OPT_X86
113
+ #ifndef OPT_MULTI
114
+ # define defopt ifuenf
115
+ #endif
116
+ #endif
117
+
118
+ #ifdef OPT_I586_DITHER
119
+ #define OPT_X86
120
+ #define OPT_DITHER
121
+ #ifndef OPT_MULTI
122
+ # define defopt ifuenf_dither
123
+ #endif
124
+ #endif
125
+
126
+ /* We still have some special code around MMX tables. */
127
+
128
+ #ifdef OPT_MMX
129
+ #define OPT_MMXORSSE
130
+ #define OPT_X86
131
+ #ifndef OPT_MULTI
132
+ # define defopt mmx
133
+ #endif
134
+ #endif
135
+
136
+ #ifdef OPT_SSE
137
+ #define OPT_MMXORSSE
138
+ #define OPT_MPLAYER
139
+ #define OPT_X86
140
+ #ifndef OPT_MULTI
141
+ # define defopt sse
142
+ #endif
143
+ #endif
144
+
145
+ #ifdef OPT_3DNOWEXT
146
+ #define OPT_MMXORSSE
147
+ #define OPT_MPLAYER
148
+ #define OPT_X86
149
+ #ifndef OPT_MULTI
150
+ # define defopt dreidnowext
151
+ # define opt_dct36(fr) dct36_3dnowext
152
+ #endif
153
+ #endif
154
+
155
+ #ifdef OPT_MPLAYER
156
+ extern const int costab_mmxsse[];
157
+ #endif
158
+
159
+ /* 3dnow used to use synth_1to1_i586 for mono / 8bit conversion - was that intentional? */
160
+ /* I'm trying to skip the pentium code here ... until I see that that is indeed a bad idea */
161
+ #ifdef OPT_3DNOW
162
+ #define OPT_X86
163
+ #ifndef OPT_MULTI
164
+ # define defopt dreidnow
165
+ # define opt_dct36(fr) dct36_3dnow
166
+ #endif
167
+ #endif
168
+
169
+ #ifdef OPT_ALTIVEC
170
+ #ifndef OPT_MULTI
171
+ # define defopt altivec
172
+ #endif
173
+ #endif
174
+
175
+ #ifdef OPT_X86_64
176
+ #define OPT_MMXORSSE
177
+ #ifndef OPT_MULTI
178
+ # define defopt x86_64
179
+ #endif
180
+ #endif
181
+
182
+ #ifdef OPT_ARM
183
+ #ifndef OPT_MULTI
184
+ # define defopt arm
185
+ #endif
186
+ #endif
187
+
188
+ #ifdef OPT_NEON
189
+ #define OPT_MMXORSSE
190
+ #ifndef OPT_MULTI
191
+ # define defopt neon
192
+ #endif
193
+ #endif
194
+
195
+ /* used for multi opt mode and the single 3dnow mode to have the old 3dnow test flag still working */
196
+ void check_decoders(void);
197
+
198
+ /*
199
+ Now come two blocks of standard definitions for multi-decoder mode and single-decoder mode.
200
+ Most stuff is so automatic that it's indeed generated by some inline shell script.
201
+ Remember to use these scripts when possible, instead of direct repetitive hacking.
202
+ */
203
+
204
+ #ifdef OPT_MULTI
205
+
206
+ # define defopt nodec
207
+
208
+ # if (defined OPT_3DNOW || defined OPT_3DNOWEXT)
209
+ # define opt_dct36(fr) ((fr)->cpu_opts.the_dct36)
210
+ # endif
211
+
212
+ #endif /* OPT_MULTI else */
213
+
214
+ # ifndef opt_dct36
215
+ # define opt_dct36(fr) dct36
216
+ # endif
217
+
218
+ #endif /* MPG123_H_OPTIMIZE */
219
+
@@ -0,0 +1,1179 @@
1
+ /*
2
+ parse: spawned from common; clustering around stream/frame parsing
3
+
4
+ copyright ?-2012 by the mpg123 project - free software under the terms of the LGPL 2.1
5
+ see COPYING and AUTHORS files in distribution or http://mpg123.org
6
+ initially written by Michael Hipp & Thomas Orgis
7
+ */
8
+
9
+ #include "mpg123lib_intern.h"
10
+
11
+ #include <sys/stat.h>
12
+ #include <fcntl.h>
13
+
14
+ #include "getbits.h"
15
+
16
+ #if defined (WANT_WIN32_SOCKETS)
17
+ #include <winsock2.h>
18
+ #include <ws2tcpip.h>
19
+ #endif
20
+
21
+ /* a limit for number of frames in a track; beyond that unsigned long may not be enough to hold byte addresses */
22
+ #ifdef HAVE_LIMITS_H
23
+ #include <limits.h>
24
+ #endif
25
+ #ifndef ULONG_MAX
26
+ /* hm, is this portable across preprocessors? */
27
+ #define ULONG_MAX ((unsigned long)-1)
28
+ #endif
29
+ #define TRACK_MAX_FRAMES ULONG_MAX/4/1152
30
+
31
+ #include "mpeghead.h"
32
+
33
+ #include "debug.h"
34
+
35
+ #define bsbufid(fr) (fr)->bsbuf==(fr)->bsspace[0] ? 0 : ((fr)->bsbuf==fr->bsspace[1] ? 1 : ( (fr)->bsbuf==(fr)->bsspace[0]+512 ? 2 : ((fr)->bsbuf==fr->bsspace[1]+512 ? 3 : -1) ) )
36
+
37
+ /* PARSE_GOOD and PARSE_BAD have to be 1 and 0 (TRUE and FALSE), others can vary. */
38
+ enum parse_codes
39
+ {
40
+ PARSE_MORE = MPG123_NEED_MORE
41
+ ,PARSE_ERR = MPG123_ERR
42
+ ,PARSE_END = 10 /* No more audio data to find. */
43
+ ,PARSE_GOOD = 1 /* Everything's fine. */
44
+ ,PARSE_BAD = 0 /* Not fine (invalid data). */
45
+ ,PARSE_RESYNC = 2 /* Header not good, go into resync. */
46
+ ,PARSE_AGAIN = 3 /* Really start over, throw away and read a new header, again. */
47
+ };
48
+
49
+ /* bitrates for [mpeg1/2][layer] */
50
+ static const int tabsel_123[2][3][16] =
51
+ {
52
+ {
53
+ {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
54
+ {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
55
+ {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,}
56
+ },
57
+ {
58
+ {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
59
+ {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
60
+ {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}
61
+ }
62
+ };
63
+
64
+ static const long freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 };
65
+
66
+ static int decode_header(mpg123_handle *fr,unsigned long newhead, int *freeformat_count);
67
+ static int skip_junk(mpg123_handle *fr, unsigned long *newheadp, long *headcount);
68
+ static int do_readahead(mpg123_handle *fr, unsigned long newhead);
69
+ static int wetwork(mpg123_handle *fr, unsigned long *newheadp);
70
+
71
+ /* These two are to be replaced by one function that gives all the frame parameters (for outsiders).*/
72
+ /* Those functions are unsafe regarding bad arguments (inside the mpg123_handle), but just returning anything would also be unsafe, the caller code has to be trusted. */
73
+
74
+ int frame_bitrate(mpg123_handle *fr)
75
+ {
76
+ return tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
77
+ }
78
+
79
+ long frame_freq(mpg123_handle *fr)
80
+ {
81
+ return freqs[fr->sampling_frequency];
82
+ }
83
+
84
+ /* compiler is smart enought to inline this one or should I really do it as macro...? */
85
+ static int head_check(unsigned long head)
86
+ {
87
+ if
88
+ (
89
+ ((head & HDR_SYNC) != HDR_SYNC)
90
+ ||
91
+ /* layer: 01,10,11 is 1,2,3; 00 is reserved */
92
+ (!(HDR_LAYER_VAL(head)))
93
+ ||
94
+ /* 1111 means bad bitrate */
95
+ (HDR_BITRATE_VAL(head) == 0xf)
96
+ ||
97
+ /* sampling freq: 11 is reserved */
98
+ (HDR_SAMPLERATE_VAL(head) == 0x3)
99
+ /* here used to be a mpeg 2.5 check... re-enabled 2.5 decoding due to lack of evidence that it is really not good */
100
+ )
101
+ {
102
+ return FALSE;
103
+ }
104
+ /* if no check failed, the header is valid (hopefully)*/
105
+ else
106
+ {
107
+ return TRUE;
108
+ }
109
+ }
110
+
111
+ static int check_lame_tag(mpg123_handle *fr)
112
+ {
113
+ /*
114
+ going to look for Xing or Info at some position after the header
115
+ MPEG 1 MPEG 2/2.5 (LSF)
116
+ Stereo, Joint Stereo, Dual Channel 32 17
117
+ Mono 17 9
118
+
119
+ Also, how to avoid false positives? I guess I should interpret more of the header to rule that out(?).
120
+ I hope that ensuring all zeros until tag start is enough.
121
+ */
122
+ int lame_offset = (fr->stereo == 2) ? (fr->lsf ? 17 : 32 ) : (fr->lsf ? 9 : 17);
123
+
124
+ if(fr->p.flags & MPG123_IGNORE_INFOFRAME) return 0;
125
+
126
+ /* Note: CRC or not, that does not matter here. */
127
+ if(fr->framesize >= 120+lame_offset) /* traditional Xing header is 120 bytes */
128
+ {
129
+ int i;
130
+ int lame_type = 0;
131
+ debug("do we have lame tag?");
132
+ /* only search for tag when all zero before it (apart from checksum) */
133
+ for(i=2; i < lame_offset; ++i) if(fr->bsbuf[i] != 0) break;
134
+ if(i == lame_offset)
135
+ {
136
+ debug("possibly...");
137
+ if
138
+ (
139
+ (fr->bsbuf[lame_offset] == 'I')
140
+ && (fr->bsbuf[lame_offset+1] == 'n')
141
+ && (fr->bsbuf[lame_offset+2] == 'f')
142
+ && (fr->bsbuf[lame_offset+3] == 'o')
143
+ )
144
+ {
145
+ lame_type = 1; /* We still have to see what there is */
146
+ }
147
+ else if
148
+ (
149
+ (fr->bsbuf[lame_offset] == 'X')
150
+ && (fr->bsbuf[lame_offset+1] == 'i')
151
+ && (fr->bsbuf[lame_offset+2] == 'n')
152
+ && (fr->bsbuf[lame_offset+3] == 'g')
153
+ )
154
+ {
155
+ lame_type = 2;
156
+ fr->vbr = MPG123_VBR; /* Xing header means always VBR */
157
+ }
158
+ if(lame_type)
159
+ {
160
+ unsigned long xing_flags;
161
+
162
+ /* we have one of these headers... */
163
+ if(VERBOSE2) fprintf(stderr, "Note: Xing/Lame/Info header detected\n");
164
+ /* now interpret the Xing part, I have 120 bytes total for sure */
165
+ /* there are 4 bytes for flags, but only the last byte contains known ones */
166
+ lame_offset += 4; /* now first byte after Xing/Name */
167
+ /* 4 bytes dword for flags */
168
+ #define make_long(a, o) ((((unsigned long) a[o]) << 24) | (((unsigned long) a[o+1]) << 16) | (((unsigned long) a[o+2]) << 8) | ((unsigned long) a[o+3]))
169
+ /* 16 bit */
170
+ #define make_short(a,o) ((((unsigned short) a[o]) << 8) | ((unsigned short) a[o+1]))
171
+ xing_flags = make_long(fr->bsbuf, lame_offset);
172
+ lame_offset += 4;
173
+ debug1("Xing: flags 0x%08lx", xing_flags);
174
+ if(xing_flags & 1) /* frames */
175
+ {
176
+ if(fr->p.flags & MPG123_IGNORE_STREAMLENGTH)
177
+ {
178
+ if(VERBOSE3)
179
+ fprintf(stderr, "Note: Ignoring Xing frames because of MPG123_IGNORE_STREAMLENGTH\n");
180
+ }
181
+ else
182
+ {
183
+ fr->track_frames = (off_t) make_long(fr->bsbuf, lame_offset);
184
+ if(fr->track_frames > TRACK_MAX_FRAMES) fr->track_frames = 0; /* endless stream? */
185
+ #ifdef GAPLESS
186
+ /* All or nothing: Only if encoder delay/padding is known we'll cut samples for gapless. */
187
+ if(fr->p.flags & MPG123_GAPLESS)
188
+ frame_gapless_init(fr, fr->track_frames, 0, 0);
189
+ #endif
190
+ if(VERBOSE3) fprintf(stderr, "Note: Xing: %lu frames\n", (long unsigned)fr->track_frames);
191
+ }
192
+
193
+ lame_offset += 4;
194
+ }
195
+ if(xing_flags & 0x2) /* bytes */
196
+ {
197
+ if(fr->p.flags & MPG123_IGNORE_STREAMLENGTH)
198
+ {
199
+ if(VERBOSE3)
200
+ fprintf(stderr, "Note: Ignoring Xing bytes because of MPG123_IGNORE_STREAMLENGTH\n");
201
+ }
202
+ else
203
+ {
204
+ unsigned long xing_bytes = make_long(fr->bsbuf, lame_offset); /* We assume that this is the _total_ size of the file, including Xing frame ... and ID3 frames...
205
+ It's not that clearly documented... */
206
+ if(fr->rdat.filelen < 1)
207
+ fr->rdat.filelen = (off_t) xing_bytes; /* One could start caring for overflow here. */
208
+ else
209
+ {
210
+ if((off_t) xing_bytes != fr->rdat.filelen && NOQUIET)
211
+ {
212
+ double diff = 1.0/fr->rdat.filelen * (fr->rdat.filelen - (off_t)xing_bytes);
213
+ if(diff < 0.) diff = -diff;
214
+
215
+ if(VERBOSE3)
216
+ fprintf(stderr, "Note: Xing stream size %lu differs by %f%% from determined/given file size!\n", xing_bytes, diff);
217
+
218
+ if(diff > 1.)
219
+ fprintf(stderr, "Warning: Xing stream size off by more than 1%%, fuzzy seeking may be even more fuzzy than by design!\n");
220
+ }
221
+ }
222
+
223
+ if(VERBOSE3)
224
+ fprintf(stderr, "Note: Xing: %lu bytes\n", (long unsigned)xing_bytes);
225
+ }
226
+
227
+ lame_offset += 4;
228
+ }
229
+ if(xing_flags & 0x4) /* TOC */
230
+ {
231
+ frame_fill_toc(fr, fr->bsbuf+lame_offset);
232
+ lame_offset += 100; /* just skip */
233
+ }
234
+ if(xing_flags & 0x8) /* VBR quality */
235
+ {
236
+ if(VERBOSE3)
237
+ {
238
+ unsigned long xing_quality = make_long(fr->bsbuf, lame_offset);
239
+ fprintf(stderr, "Note: Xing: quality = %lu\n", (long unsigned)xing_quality);
240
+ }
241
+ lame_offset += 4;
242
+ }
243
+ /* I guess that either 0 or LAME extra data follows */
244
+ if(fr->bsbuf[lame_offset] != 0)
245
+ {
246
+ unsigned char lame_vbr;
247
+ float replay_gain[2] = {0,0};
248
+ float peak = 0;
249
+ float gain_offset = 0; /* going to be +6 for old lame that used 83dB */
250
+ char nb[10];
251
+ memcpy(nb, fr->bsbuf+lame_offset, 9);
252
+ nb[9] = 0;
253
+ if(VERBOSE3) fprintf(stderr, "Note: Info: Encoder: %s\n", nb);
254
+ if(!strncmp("LAME", nb, 4))
255
+ {
256
+ /* Lame versions before 3.95.1 used 83 dB reference level, later versions 89 dB.
257
+ We stick with 89 dB as being "normal", adding 6 dB. */
258
+ unsigned int major, minor;
259
+ char rest[6];
260
+ rest[0] = 0;
261
+ if(sscanf(nb+4, "%u.%u%s", &major, &minor, rest) >= 2)
262
+ {
263
+ debug3("LAME: %u/%u/%s", major, minor, rest);
264
+ /* We cannot detect LAME 3.95 reliably (same version string as 3.95.1), so this is a blind spot.
265
+ Everything < 3.95 is safe, though. */
266
+ if(major < 3 || (major == 3 && minor < 95)) /* || (major == 3 && minor == 95 && rest[0] == 0)) */
267
+ {
268
+ gain_offset = 6;
269
+ if(VERBOSE3) fprintf(stderr, "Note: Info: Old LAME detected, using ReplayGain preamp of %f dB.\n", gain_offset);
270
+ }
271
+ }
272
+ else if(VERBOSE3) fprintf(stderr, "Note: Info: Cannot determine LAME version.\n");
273
+ }
274
+ lame_offset += 9;
275
+ /* the 4 big bits are tag revision, the small bits vbr method */
276
+ lame_vbr = fr->bsbuf[lame_offset] & 15;
277
+ if(VERBOSE3)
278
+ {
279
+ fprintf(stderr, "Note: Info: rev %u\n", fr->bsbuf[lame_offset] >> 4);
280
+ fprintf(stderr, "Note: Info: vbr mode %u\n", lame_vbr);
281
+ }
282
+ lame_offset += 1;
283
+ switch(lame_vbr)
284
+ {
285
+ /* from rev1 proposal... not sure if all good in practice */
286
+ case 1:
287
+ case 8: fr->vbr = MPG123_CBR; break;
288
+ case 2:
289
+ case 9: fr->vbr = MPG123_ABR; break;
290
+ default: fr->vbr = MPG123_VBR; /* 00==unknown is taken as VBR */
291
+ }
292
+ /* skipping: lowpass filter value */
293
+ lame_offset += 1;
294
+ /* replaygain */
295
+ /* 32bit float: peak amplitude -- why did I parse it as int before??*/
296
+ /* Ah, yes, lame seems to store it as int since some day in 2003; I've only seen zeros anyway until now, bah! */
297
+ if
298
+ (
299
+ (fr->bsbuf[lame_offset] != 0)
300
+ || (fr->bsbuf[lame_offset+1] != 0)
301
+ || (fr->bsbuf[lame_offset+2] != 0)
302
+ || (fr->bsbuf[lame_offset+3] != 0)
303
+ )
304
+ {
305
+ debug("Wow! Is there _really_ a non-zero peak value? Now is it stored as float or int - how should I know?");
306
+ /* byte*peak_bytes = (byte*) &peak;
307
+ ... endianess ... just copy bytes to avoid floating point operation on unaligned memory?
308
+ peak_bytes[0] = ...
309
+ peak = *(float*) (fr->bsbuf+lame_offset); */
310
+ }
311
+ if(VERBOSE3) fprintf(stderr, "Note: Info: peak = %f (I won't use this)\n", peak);
312
+ peak = 0; /* until better times arrived */
313
+ lame_offset += 4;
314
+ /*
315
+ ReplayGain values - lame only writes radio mode gain...
316
+ 16bit gain, 3 bits name, 3 bits originator, sign (1=-, 0=+), dB value*10 in 9 bits (fixed point)
317
+ ignore the setting if name or originator == 000!
318
+ radio 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1
319
+ audiophile 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0
320
+ */
321
+
322
+ for(i =0; i < 2; ++i)
323
+ {
324
+ unsigned char origin = (fr->bsbuf[lame_offset] >> 2) & 0x7; /* the 3 bits after that... */
325
+ if(origin != 0)
326
+ {
327
+ unsigned char gt = fr->bsbuf[lame_offset] >> 5; /* only first 3 bits */
328
+ if(gt == 1) gt = 0; /* radio */
329
+ else if(gt == 2) gt = 1; /* audiophile */
330
+ else continue;
331
+ /* get the 9 bits into a number, divide by 10, multiply sign... happy bit banging */
332
+ replay_gain[gt] = (float) ((fr->bsbuf[lame_offset] & 0x2) ? -0.1 : 0.1) * (make_short(fr->bsbuf, lame_offset) & 0x1ff);
333
+ /* If this is an automatic value from LAME (or whatever), the automatic gain offset applies.
334
+ If a user or whoever set the value, do not touch it! 011 is automatic origin. */
335
+ if(origin == 3) replay_gain[gt] += gain_offset;
336
+ }
337
+ lame_offset += 2;
338
+ }
339
+ if(VERBOSE3)
340
+ {
341
+ fprintf(stderr, "Note: Info: Radio Gain = %03.1fdB\n", replay_gain[0]);
342
+ fprintf(stderr, "Note: Info: Audiophile Gain = %03.1fdB\n", replay_gain[1]);
343
+ }
344
+ for(i=0; i < 2; ++i)
345
+ {
346
+ if(fr->rva.level[i] <= 0)
347
+ {
348
+ fr->rva.peak[i] = 0; /* at some time the parsed peak should be used */
349
+ fr->rva.gain[i] = replay_gain[i];
350
+ fr->rva.level[i] = 0;
351
+ }
352
+ }
353
+ lame_offset += 1; /* skipping encoding flags byte */
354
+ if(fr->vbr == MPG123_ABR)
355
+ {
356
+ fr->abr_rate = fr->bsbuf[lame_offset];
357
+ if(VERBOSE3) fprintf(stderr, "Note: Info: ABR rate = %u\n", fr->abr_rate);
358
+ }
359
+ lame_offset += 1;
360
+ /* encoder delay and padding, two 12 bit values... lame does write them from int ...*/
361
+ if(VERBOSE3)
362
+ fprintf(stderr, "Note: Encoder delay = %i; padding = %i\n",
363
+ ((((int) fr->bsbuf[lame_offset]) << 4) | (((int) fr->bsbuf[lame_offset+1]) >> 4)),
364
+ (((((int) fr->bsbuf[lame_offset+1]) << 8) | (((int) fr->bsbuf[lame_offset+2]))) & 0xfff) );
365
+ #ifdef GAPLESS
366
+ if(fr->p.flags & MPG123_GAPLESS)
367
+ {
368
+ off_t skipbegin = ((((int) fr->bsbuf[lame_offset]) << 4) | (((int) fr->bsbuf[lame_offset+1]) >> 4));
369
+ off_t skipend = (((((int) fr->bsbuf[lame_offset+1]) << 8) | (((int) fr->bsbuf[lame_offset+2]))) & 0xfff);
370
+ frame_gapless_init(fr, fr->track_frames, skipbegin, skipend);
371
+ }
372
+ #endif
373
+ }
374
+ /* switch buffer back ... */
375
+ fr->bsbuf = fr->bsspace[fr->bsnum]+512;
376
+ fr->bsnum = (fr->bsnum + 1) & 1;
377
+ return 1; /* got it! */
378
+ }
379
+ }
380
+ }
381
+ return 0; /* no lame tag */
382
+ }
383
+
384
+ /* Just tell if the header is some mono. */
385
+ static int header_mono(unsigned long newhead)
386
+ {
387
+ return HDR_CHANNEL_VAL(newhead) == MPG_MD_MONO ? TRUE : FALSE;
388
+ }
389
+
390
+ static void halfspeed_prepare(mpg123_handle *fr)
391
+ {
392
+ /* save for repetition */
393
+ if(fr->p.halfspeed && fr->lay == 3)
394
+ {
395
+ debug("halfspeed - reusing old bsbuf ");
396
+ memcpy (fr->ssave, fr->bsbuf, fr->ssize);
397
+ }
398
+ }
399
+
400
+ /* If this returns 1, the next frame is the repetition. */
401
+ static int halfspeed_do(mpg123_handle *fr)
402
+ {
403
+ /* Speed-down hack: Play it again, Sam (the frame, I mean). */
404
+ if (fr->p.halfspeed)
405
+ {
406
+ if(fr->halfphase) /* repeat last frame */
407
+ {
408
+ debug("repeat!");
409
+ fr->to_decode = fr->to_ignore = TRUE;
410
+ --fr->halfphase;
411
+ fr->bitindex = 0;
412
+ fr->wordpointer = (unsigned char *) fr->bsbuf;
413
+ if(fr->lay == 3) memcpy (fr->bsbuf, fr->ssave, fr->ssize);
414
+ if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
415
+ return 1;
416
+ }
417
+ else
418
+ {
419
+ fr->halfphase = fr->p.halfspeed - 1;
420
+ }
421
+ }
422
+ return 0;
423
+ }
424
+
425
+ /*
426
+ Temporary macro until we got this worked out.
427
+ Idea is to filter out special return values that shall trigger direct jumps to end / resync / read again.
428
+ Particularily, the generic ret==PARSE_BAD==0 and ret==PARSE_GOOD==1 are not affected.
429
+ */
430
+ #define JUMP_CONCLUSION(ret) \
431
+ { \
432
+ if(ret < 0){ debug1("%s", ret == MPG123_NEED_MORE ? "need more" : "read error"); goto read_frame_bad; } \
433
+ else if(ret == PARSE_AGAIN) goto read_again; \
434
+ else if(ret == PARSE_RESYNC) goto init_resync; \
435
+ else if(ret == PARSE_END) goto read_frame_bad; \
436
+ }
437
+
438
+ /*
439
+ That's a big one: read the next frame. 1 is success, <= 0 is some error
440
+ Special error READER_MORE means: Please feed more data and try again.
441
+ */
442
+ int read_frame(mpg123_handle *fr)
443
+ {
444
+ /* TODO: rework this thing */
445
+ int freeformat_count = 0;
446
+ unsigned long newhead;
447
+ off_t framepos;
448
+ int ret;
449
+ /* stuff that needs resetting if complete frame reading fails */
450
+ int oldsize = fr->framesize;
451
+ int oldphase = fr->halfphase;
452
+
453
+ /* The counter for the search-first-header loop.
454
+ It is persistent outside the loop to prevent seemingly endless loops
455
+ when repeatedly headers are found that do not have valid followup headers. */
456
+ long headcount = 0;
457
+
458
+ fr->fsizeold=fr->framesize; /* for Layer3 */
459
+
460
+ if(halfspeed_do(fr) == 1) return 1;
461
+
462
+ read_again:
463
+ /* In case we are looping to find a valid frame, discard any buffered data before the current position.
464
+ This is essential to prevent endless looping, always going back to the beginning when feeder buffer is exhausted. */
465
+ if(fr->rd->forget != NULL) fr->rd->forget(fr);
466
+
467
+ debug2("trying to get frame %"OFF_P" at %"OFF_P, (off_p)fr->num+1, (off_p)fr->rd->tell(fr));
468
+ if((ret = fr->rd->head_read(fr,&newhead)) <= 0){ debug1("need more? (%i)", ret); goto read_frame_bad;}
469
+
470
+ init_resync:
471
+
472
+ fr->header_change = 2; /* output format change is possible... */
473
+ if(fr->oldhead) /* check a following header for change */
474
+ {
475
+ if(fr->oldhead == newhead) fr->header_change = 0;
476
+ else
477
+ /* If they have the same sample rate. Note that only is _not_ the case for the first header, as we enforce sample rate match for following frames.
478
+ So, during one stream, only change of stereoness is possible and indicated by header_change == 2. */
479
+ if((fr->oldhead & HDR_SAMPMASK) == (newhead & HDR_SAMPMASK))
480
+ {
481
+ /* Now if both channel modes are mono or both stereo, it's no big deal. */
482
+ if( header_mono(fr->oldhead) == header_mono(newhead))
483
+ fr->header_change = 1;
484
+ }
485
+ }
486
+
487
+ #ifdef SKIP_JUNK
488
+ if(!fr->firsthead && !head_check(newhead))
489
+ {
490
+ ret = skip_junk(fr, &newhead, &headcount);
491
+ JUMP_CONCLUSION(ret);
492
+ }
493
+ #endif
494
+
495
+ ret = head_check(newhead);
496
+ if(ret) ret = decode_header(fr, newhead, &freeformat_count);
497
+
498
+ JUMP_CONCLUSION(ret); /* That only continues for ret == PARSE_BAD or PARSE_GOOD. */
499
+ if(ret == PARSE_BAD)
500
+ { /* Header was not good. */
501
+ ret = wetwork(fr, &newhead); /* Messy stuff, handle junk, resync ... */
502
+ JUMP_CONCLUSION(ret);
503
+ /* Normally, we jumped already. If for some reason everything's fine to continue, do continue. */
504
+ if(ret != PARSE_GOOD) goto read_frame_bad;
505
+ }
506
+
507
+ if(!fr->firsthead)
508
+ {
509
+ ret = do_readahead(fr, newhead);
510
+ /* readahead can fail mit NEED_MORE, in which case we must also make the just read header available again for next go */
511
+ if(ret < 0) fr->rd->back_bytes(fr, 4);
512
+ JUMP_CONCLUSION(ret);
513
+ }
514
+
515
+ /* Now we should have our valid header and proceed to reading the frame. */
516
+
517
+ /* if filepos is invalid, so is framepos */
518
+ framepos = fr->rd->tell(fr) - 4;
519
+ /* flip/init buffer for Layer 3 */
520
+ {
521
+ unsigned char *newbuf = fr->bsspace[fr->bsnum]+512;
522
+ /* read main data into memory */
523
+ if((ret=fr->rd->read_frame_body(fr,newbuf,fr->framesize))<0)
524
+ {
525
+ /* if failed: flip back */
526
+ debug("need more?");
527
+ goto read_frame_bad;
528
+ }
529
+ fr->bsbufold = fr->bsbuf;
530
+ fr->bsbuf = newbuf;
531
+ }
532
+ fr->bsnum = (fr->bsnum + 1) & 1;
533
+
534
+ if(!fr->firsthead)
535
+ {
536
+ fr->firsthead = newhead; /* _now_ it's time to store it... the first real header */
537
+ /* This is the first header of our current stream segment.
538
+ It is only the actual first header of the whole stream when fr->num is still below zero!
539
+ Think of resyncs where firsthead has been reset for format flexibility. */
540
+ if(fr->num < 0)
541
+ {
542
+ fr->audio_start = framepos;
543
+ /* Only check for LAME tag at beginning of whole stream
544
+ ... when there indeed is one in between, it's the user's problem. */
545
+ if(fr->lay == 3 && check_lame_tag(fr) == 1)
546
+ { /* ...in practice, Xing/LAME tags are layer 3 only. */
547
+ if(fr->rd->forget != NULL) fr->rd->forget(fr);
548
+
549
+ fr->oldhead = 0;
550
+ goto read_again;
551
+ }
552
+ /* now adjust volume */
553
+ do_rva(fr);
554
+ }
555
+
556
+ debug2("fr->firsthead: %08lx, audio_start: %li", fr->firsthead, (long int)fr->audio_start);
557
+ }
558
+
559
+ fr->bitindex = 0;
560
+ fr->wordpointer = (unsigned char *) fr->bsbuf;
561
+ /* Question: How bad does the floating point value get with repeated recomputation?
562
+ Also, considering that we can play the file or parts of many times. */
563
+ if(++fr->mean_frames != 0)
564
+ {
565
+ fr->mean_framesize = ((fr->mean_frames-1)*fr->mean_framesize+compute_bpf(fr)) / fr->mean_frames ;
566
+ }
567
+ ++fr->num; /* 0 for first frame! */
568
+ debug4("Frame %"OFF_P" %08lx %i, next filepos=%"OFF_P,
569
+ (off_p)fr->num, newhead, fr->framesize, (off_p)fr->rd->tell(fr));
570
+ if(!(fr->state_flags & FRAME_FRANKENSTEIN) && (
571
+ (fr->track_frames > 0 && fr->num >= fr->track_frames)
572
+ #ifdef GAPLESS
573
+ || (fr->gapless_frames > 0 && fr->num >= fr->gapless_frames)
574
+ #endif
575
+ ))
576
+ {
577
+ fr->state_flags |= FRAME_FRANKENSTEIN;
578
+ if(NOQUIET) fprintf(stderr, "\nWarning: Encountered more data after announced end of track (frame %"OFF_P"/%"OFF_P"). Frankenstein!\n", (off_p)fr->num,
579
+ #ifdef GAPLESS
580
+ fr->gapless_frames > 0 ? (off_p)fr->gapless_frames :
581
+ #endif
582
+ (off_p)fr->track_frames);
583
+ }
584
+
585
+ halfspeed_prepare(fr);
586
+
587
+ /* index the position */
588
+ fr->input_offset = framepos;
589
+ #ifdef FRAME_INDEX
590
+ /* Keep track of true frame positions in our frame index.
591
+ but only do so when we are sure that the frame number is accurate... */
592
+ if((fr->state_flags & FRAME_ACCURATE) && FI_NEXT(fr->index, fr->num))
593
+ fi_add(&fr->index, framepos);
594
+ #endif
595
+
596
+ if(fr->silent_resync > 0) --fr->silent_resync;
597
+
598
+ if(fr->rd->forget != NULL) fr->rd->forget(fr);
599
+
600
+ fr->to_decode = fr->to_ignore = TRUE;
601
+ if(fr->error_protection) fr->crc = getbits(fr, 16); /* skip crc */
602
+
603
+ fr->oldhead = newhead;
604
+
605
+ return 1;
606
+ read_frame_bad:
607
+ /* Also if we searched for valid data in vein, we can forget skipped data.
608
+ Otherwise, the feeder would hold every dead old byte in memory until the first valid frame! */
609
+ if(fr->rd->forget != NULL) fr->rd->forget(fr);
610
+
611
+ fr->silent_resync = 0;
612
+ if(fr->err == MPG123_OK) fr->err = MPG123_ERR_READER;
613
+ fr->framesize = oldsize;
614
+ fr->halfphase = oldphase;
615
+ /* That return code might be inherited from some feeder action, or reader error. */
616
+ return ret;
617
+ }
618
+
619
+
620
+ /*
621
+ * read ahead and find the next MPEG header, to guess framesize
622
+ * return value: success code
623
+ * PARSE_GOOD: found a valid frame size (stored in the handle).
624
+ * <0: error codes, possibly from feeder buffer (NEED_MORE)
625
+ * PARSE_BAD: cannot get the framesize for some reason and shall silentry try the next possible header (if this is no free format stream after all...)
626
+ */
627
+ static int guess_freeformat_framesize(mpg123_handle *fr)
628
+ {
629
+ long i;
630
+ int ret;
631
+ unsigned long head;
632
+ if(!(fr->rdat.flags & (READER_SEEKABLE|READER_BUFFERED)))
633
+ {
634
+ if(NOQUIET) error("Cannot look for freeformat frame size with non-seekable and non-buffered stream!");
635
+
636
+ return PARSE_BAD;
637
+ }
638
+ if((ret=fr->rd->head_read(fr,&head))<=0)
639
+ return ret;
640
+
641
+ /* We are already 4 bytes into it */
642
+ for(i=4;i<MAXFRAMESIZE+4;i++)
643
+ {
644
+ if((ret=fr->rd->head_shift(fr,&head))<=0) return ret;
645
+
646
+ /* No head_check needed, the mask contains all relevant bits. */
647
+ if((head & HDR_SAMEMASK) == (fr->oldhead & HDR_SAMEMASK))
648
+ {
649
+ fr->rd->back_bytes(fr,i+1);
650
+ fr->framesize = i-3;
651
+ return PARSE_GOOD; /* Success! */
652
+ }
653
+ }
654
+ fr->rd->back_bytes(fr,i);
655
+ return PARSE_BAD;
656
+ }
657
+
658
+
659
+ /*
660
+ * decode a header and write the information
661
+ * into the frame structure
662
+ * Return values are compatible with those of read_frame, namely:
663
+ * 1: success
664
+ * 0: no valid header
665
+ * <0: some error
666
+ * You are required to do a head_check() before calling!
667
+ */
668
+ static int decode_header(mpg123_handle *fr,unsigned long newhead, int *freeformat_count)
669
+ {
670
+ #ifdef DEBUG /* Do not waste cycles checking the header twice all the time. */
671
+ if(!head_check(newhead))
672
+ {
673
+ error1("trying to decode obviously invalid header 0x%08lx", newhead);
674
+ }
675
+ #endif
676
+ if(HDR_VERSION_VAL(newhead) & 0x2)
677
+ {
678
+ fr->lsf = (HDR_VERSION_VAL(newhead) & 0x1) ? 0 : 1;
679
+ fr->mpeg25 = 0;
680
+ }
681
+ else
682
+ {
683
+ fr->lsf = 1;
684
+ fr->mpeg25 = 1;
685
+ }
686
+
687
+ if( (fr->p.flags & MPG123_NO_RESYNC) || !fr->oldhead
688
+ || (HDR_VERSION_VAL(fr->oldhead) != HDR_VERSION_VAL(newhead)) )
689
+ {
690
+ /* If "tryresync" is false, assume that certain
691
+ parameters do not change within the stream!
692
+ Force an update if lsf or mpeg25 settings
693
+ have changed. */
694
+ fr->lay = 4 - HDR_LAYER_VAL(newhead);
695
+ if(fr->mpeg25)
696
+ fr->sampling_frequency = 6 + HDR_SAMPLERATE_VAL(newhead);
697
+ else
698
+ fr->sampling_frequency = HDR_SAMPLERATE_VAL(newhead) + (fr->lsf*3);
699
+ }
700
+
701
+ #ifdef DEBUG
702
+ /* seen a file where this varies (old lame tag without crc, track with crc) */
703
+ if((HDR_CRC_VAL(newhead)^0x1) != fr->error_protection) debug("changed crc bit!");
704
+ #endif
705
+ fr->error_protection = HDR_CRC_VAL(newhead)^0x1;
706
+ fr->bitrate_index = HDR_BITRATE_VAL(newhead);
707
+ fr->padding = HDR_PADDING_VAL(newhead);
708
+ fr->extension = HDR_PRIVATE_VAL(newhead);
709
+ fr->mode = HDR_CHANNEL_VAL(newhead);
710
+ fr->mode_ext = HDR_CHANEX_VAL(newhead);
711
+ fr->copyright = HDR_COPYRIGHT_VAL(newhead);
712
+ fr->original = HDR_ORIGINAL_VAL(newhead);
713
+ fr->emphasis = HDR_EMPHASIS_VAL(newhead);
714
+ fr->freeformat = !(newhead & HDR_BITRATE);
715
+
716
+ fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
717
+
718
+ /* we can't use tabsel_123 for freeformat, so trying to guess framesize... */
719
+ if(fr->freeformat)
720
+ {
721
+ /* when we first encounter the frame with freeformat, guess framesize */
722
+ if(fr->freeformat_framesize < 0)
723
+ {
724
+ int ret;
725
+ *freeformat_count += 1;
726
+ if(*freeformat_count > 5)
727
+ {
728
+ if(VERBOSE3) error("You fooled me too often. Refusing to guess free format frame size _again_.");
729
+ return PARSE_BAD;
730
+ }
731
+ ret = guess_freeformat_framesize(fr);
732
+ if(ret == PARSE_GOOD)
733
+ {
734
+ fr->freeformat_framesize = fr->framesize - fr->padding;
735
+ if(VERBOSE2)
736
+ fprintf(stderr, "Note: free format frame size %li\n", fr->freeformat_framesize);
737
+ }
738
+ else
739
+ {
740
+ if(ret == MPG123_NEED_MORE)
741
+ debug("Need more data to guess free format frame size.");
742
+ else if(VERBOSE3)
743
+ error("Encountered free format header, but failed to guess frame size.");
744
+
745
+ return ret;
746
+ }
747
+ }
748
+ /* freeformat should be CBR, so the same framesize can be used at the 2nd reading or later */
749
+ else
750
+ {
751
+ fr->framesize = fr->freeformat_framesize + fr->padding;
752
+ }
753
+ }
754
+
755
+ switch(fr->lay)
756
+ {
757
+ #ifndef NO_LAYER1
758
+ case 1:
759
+ fr->do_layer = do_layer1;
760
+ if(!fr->freeformat)
761
+ {
762
+ fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
763
+ fr->framesize /= freqs[fr->sampling_frequency];
764
+ fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
765
+ }
766
+ break;
767
+ #endif
768
+ #ifndef NO_LAYER2
769
+ case 2:
770
+ fr->do_layer = do_layer2;
771
+ if(!fr->freeformat)
772
+ {
773
+ debug2("bitrate index: %i (%i)", fr->bitrate_index, tabsel_123[fr->lsf][1][fr->bitrate_index] );
774
+ fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
775
+ fr->framesize /= freqs[fr->sampling_frequency];
776
+ fr->framesize += fr->padding - 4;
777
+ }
778
+ break;
779
+ #endif
780
+ #ifndef NO_LAYER3
781
+ case 3:
782
+ fr->do_layer = do_layer3;
783
+ if(fr->lsf)
784
+ fr->ssize = (fr->stereo == 1) ? 9 : 17;
785
+ else
786
+ fr->ssize = (fr->stereo == 1) ? 17 : 32;
787
+
788
+ if(fr->error_protection)
789
+ fr->ssize += 2;
790
+
791
+ if(!fr->freeformat)
792
+ {
793
+ fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
794
+ fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
795
+ fr->framesize = fr->framesize + fr->padding - 4;
796
+ }
797
+ break;
798
+ #endif
799
+ default:
800
+ if(NOQUIET) error1("Layer type %i not supported in this build!", fr->lay);
801
+
802
+ return PARSE_BAD;
803
+ }
804
+ if (fr->framesize > MAXFRAMESIZE)
805
+ {
806
+ if(NOQUIET) error1("Frame size too big: %d", fr->framesize+4-fr->padding);
807
+
808
+ return PARSE_BAD;
809
+ }
810
+ return PARSE_GOOD;
811
+ }
812
+
813
+ void set_pointer(mpg123_handle *fr, long backstep)
814
+ {
815
+ fr->wordpointer = fr->bsbuf + fr->ssize - backstep;
816
+ if (backstep)
817
+ memcpy(fr->wordpointer,fr->bsbufold+fr->fsizeold-backstep,backstep);
818
+
819
+ fr->bitindex = 0;
820
+ }
821
+
822
+ /********************************/
823
+
824
+ double compute_bpf(mpg123_handle *fr)
825
+ {
826
+ double bpf;
827
+
828
+ switch(fr->lay)
829
+ {
830
+ case 1:
831
+ bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
832
+ bpf *= 12000.0 * 4.0;
833
+ bpf /= freqs[fr->sampling_frequency] <<(fr->lsf);
834
+ break;
835
+ case 2:
836
+ case 3:
837
+ bpf = tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
838
+ bpf *= 144000;
839
+ bpf /= freqs[fr->sampling_frequency] << (fr->lsf);
840
+ break;
841
+ default:
842
+ bpf = 1.0;
843
+ }
844
+
845
+ return bpf;
846
+ }
847
+
848
+ int attribute_align_arg mpg123_spf(mpg123_handle *mh)
849
+ {
850
+ if(mh == NULL) return MPG123_ERR;
851
+
852
+ return spf(mh);
853
+ }
854
+
855
+ double attribute_align_arg mpg123_tpf(mpg123_handle *fr)
856
+ {
857
+ static int bs[4] = { 0,384,1152,1152 };
858
+ double tpf;
859
+ if(fr == NULL) return -1;
860
+
861
+ tpf = (double) bs[fr->lay];
862
+ tpf /= freqs[fr->sampling_frequency] << (fr->lsf);
863
+ return tpf;
864
+ }
865
+
866
+ int attribute_align_arg mpg123_position(mpg123_handle *fr, off_t no, off_t buffsize,
867
+ off_t *current_frame, off_t *frames_left,
868
+ double *current_seconds, double *seconds_left)
869
+ {
870
+ double tpf;
871
+ double dt = 0.0;
872
+ off_t cur, left;
873
+ double curs, lefts;
874
+
875
+ if(!fr || !fr->rd) /* Isn't this too paranoid? */
876
+ {
877
+ debug("reader troubles!");
878
+ return MPG123_ERR;
879
+ }
880
+
881
+ no += fr->num; /* no starts out as offset */
882
+ cur = no;
883
+ tpf = mpg123_tpf(fr);
884
+ if(buffsize > 0 && fr->af.rate > 0 && fr->af.channels > 0)
885
+ {
886
+ dt = (double) buffsize / fr->af.rate / fr->af.channels;
887
+ if(fr->af.encoding & MPG123_ENC_16) dt *= 0.5;
888
+ }
889
+
890
+ left = 0;
891
+
892
+ if((fr->track_frames != 0) && (fr->track_frames >= fr->num)) left = no < fr->track_frames ? fr->track_frames - no : 0;
893
+ else
894
+ if(fr->rdat.filelen >= 0)
895
+ {
896
+ double bpf;
897
+ off_t t = fr->rd->tell(fr);
898
+ bpf = fr->mean_framesize ? fr->mean_framesize : compute_bpf(fr);
899
+ left = (off_t)((double)(fr->rdat.filelen-t)/bpf);
900
+ /* no can be different for prophetic purposes, file pointer is always associated with fr->num! */
901
+ if(fr->num != no)
902
+ {
903
+ if(fr->num > no) left += fr->num - no;
904
+ else
905
+ {
906
+ if(left >= (no - fr->num)) left -= no - fr->num;
907
+ else left = 0; /* uh, oh! */
908
+ }
909
+ }
910
+ /* I totally don't understand why we should re-estimate the given correct(?) value */
911
+ /* fr->num = (unsigned long)((double)t/bpf); */
912
+ }
913
+
914
+ /* beginning with 0 or 1?*/
915
+ curs = (double) no*tpf-dt;
916
+ lefts = (double)left*tpf+dt;
917
+ #if 0
918
+ curs = curs < 0 ? 0.0 : curs;
919
+ #endif
920
+ if(left < 0 || lefts < 0)
921
+ { /* That is the case for non-seekable streams. */
922
+ left = 0;
923
+ lefts = 0.0;
924
+ }
925
+ if(current_frame != NULL) *current_frame = cur;
926
+ if(frames_left != NULL) *frames_left = left;
927
+ if(current_seconds != NULL) *current_seconds = curs;
928
+ if(seconds_left != NULL) *seconds_left = lefts;
929
+ return MPG123_OK;
930
+ }
931
+
932
+ int get_songlen(mpg123_handle *fr,int no)
933
+ {
934
+ double tpf;
935
+
936
+ if(!fr)
937
+ return 0;
938
+
939
+ if(no < 0) {
940
+ if(!fr->rd || fr->rdat.filelen < 0)
941
+ return 0;
942
+ no = (int) ((double) fr->rdat.filelen / compute_bpf(fr));
943
+ }
944
+
945
+ tpf = mpg123_tpf(fr);
946
+ return (int) (no*tpf);
947
+ }
948
+
949
+ /* first attempt of read ahead check to find the real first header; cannot believe what junk is out there! */
950
+ static int do_readahead(mpg123_handle *fr, unsigned long newhead)
951
+ {
952
+ unsigned long nexthead = 0;
953
+ int hd = 0;
954
+ off_t start, oret;
955
+ int ret;
956
+
957
+ if( ! (!fr->firsthead && fr->rdat.flags & (READER_SEEKABLE|READER_BUFFERED)) )
958
+ return PARSE_GOOD;
959
+
960
+ start = fr->rd->tell(fr);
961
+
962
+ debug2("doing ahead check with BPF %d at %"OFF_P, fr->framesize+4, (off_p)start);
963
+ /* step framesize bytes forward and read next possible header*/
964
+ if((oret=fr->rd->skip_bytes(fr, fr->framesize))<0)
965
+ {
966
+ if(oret==READER_ERROR && NOQUIET) error("cannot seek!");
967
+
968
+ return oret == MPG123_NEED_MORE ? PARSE_MORE : PARSE_ERR;
969
+ }
970
+
971
+ /* Read header, seek back. */
972
+ hd = fr->rd->head_read(fr,&nexthead);
973
+ if( fr->rd->back_bytes(fr, fr->rd->tell(fr)-start) < 0 )
974
+ {
975
+ if(NOQUIET) error("Cannot seek back!");
976
+
977
+ return PARSE_ERR;
978
+ }
979
+ if(hd == MPG123_NEED_MORE) return PARSE_MORE;
980
+
981
+ debug1("After fetching next header, at %"OFF_P, (off_p)fr->rd->tell(fr));
982
+ if(!hd)
983
+ {
984
+ if(NOQUIET) warning("Cannot read next header, a one-frame stream? Duh...");
985
+ return PARSE_END;
986
+ }
987
+
988
+ debug2("does next header 0x%08lx match first 0x%08lx?", nexthead, newhead);
989
+ if(!head_check(nexthead) || (nexthead & HDR_CMPMASK) != (newhead & HDR_CMPMASK))
990
+ {
991
+ debug("No, the header was not valid, start from beginning...");
992
+ fr->oldhead = 0; /* start over */
993
+ /* try next byte for valid header */
994
+ if((ret=fr->rd->back_bytes(fr, 3))<0)
995
+ {
996
+ if(NOQUIET) error("Cannot seek 3 bytes back!");
997
+
998
+ return PARSE_ERR;
999
+ }
1000
+ return PARSE_AGAIN;
1001
+ }
1002
+ else return PARSE_GOOD;
1003
+ }
1004
+
1005
+ static int handle_id3v2(mpg123_handle *fr, unsigned long newhead)
1006
+ {
1007
+ int ret;
1008
+ fr->oldhead = 0; /* Think about that. Used to be present only for skipping of junk, not resync-style wetwork. */
1009
+ ret = parse_new_id3(fr, newhead);
1010
+ if (ret < 0) return ret;
1011
+ #ifndef NO_ID3V2
1012
+ else if(ret > 0){ debug("got ID3v2"); fr->metaflags |= MPG123_NEW_ID3|MPG123_ID3; }
1013
+ else debug("no useful ID3v2");
1014
+ #endif
1015
+ return PARSE_AGAIN;
1016
+ }
1017
+
1018
+ /* watch out for junk/tags on beginning of stream by invalid header */
1019
+ static int skip_junk(mpg123_handle *fr, unsigned long *newheadp, long *headcount)
1020
+ {
1021
+ int ret;
1022
+ int freeformat_count = 0;
1023
+ long limit = 65536;
1024
+ unsigned long newhead = *newheadp;
1025
+ /* check for id3v2; first three bytes (of 4) are "ID3" */
1026
+ if((newhead & (unsigned long) 0xffffff00) == (unsigned long) 0x49443300)
1027
+ {
1028
+ return handle_id3v2(fr, newhead);
1029
+ }
1030
+ else if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr,"Note: Junk at the beginning (0x%08lx)\n",newhead);
1031
+
1032
+ /* I even saw RIFF headers at the beginning of MPEG streams ;( */
1033
+ if(newhead == ('R'<<24)+('I'<<16)+('F'<<8)+'F')
1034
+ {
1035
+ if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr, "Note: Looks like a RIFF header.\n");
1036
+
1037
+ if((ret=fr->rd->head_read(fr,&newhead))<=0) return ret;
1038
+
1039
+ while(newhead != ('d'<<24)+('a'<<16)+('t'<<8)+'a')
1040
+ {
1041
+ if((ret=fr->rd->head_shift(fr,&newhead))<=0) return ret;
1042
+ }
1043
+ if((ret=fr->rd->head_read(fr,&newhead))<=0) return ret;
1044
+
1045
+ if(VERBOSE2 && fr->silent_resync == 0) fprintf(stderr,"Note: Skipped RIFF header!\n");
1046
+
1047
+ fr->oldhead = 0;
1048
+ *newheadp = newhead;
1049
+ return PARSE_AGAIN;
1050
+ }
1051
+
1052
+ /*
1053
+ Unhandled junk... just continue search for a header, stepping in single bytes through next 64K.
1054
+ This is rather identical to the resync loop.
1055
+ */
1056
+ debug("searching for header...");
1057
+ *newheadp = 0; /* Invalidate the external value. */
1058
+ ret = 0; /* We will check the value after the loop. */
1059
+
1060
+ /* We prepare for at least the 64K bytes as usual, unless
1061
+ user explicitly wanted more (even infinity). Never less. */
1062
+ if(fr->p.resync_limit < 0 || fr->p.resync_limit > limit)
1063
+ limit = fr->p.resync_limit;
1064
+
1065
+ do
1066
+ {
1067
+ ++(*headcount);
1068
+ if(limit >= 0 && *headcount >= limit) break;
1069
+
1070
+ if((ret=fr->rd->head_shift(fr,&newhead))<=0) return ret;
1071
+
1072
+ if(head_check(newhead) && (ret=decode_header(fr, newhead, &freeformat_count))) break;
1073
+ } while(1);
1074
+ if(ret<0) return ret;
1075
+
1076
+ if(limit >= 0 && *headcount >= limit)
1077
+ {
1078
+ if(NOQUIET) error1("Giving up searching valid MPEG header after %li bytes of junk.", *headcount);
1079
+ return PARSE_END;
1080
+ }
1081
+ else debug1("hopefully found one at %"OFF_P, (off_p)fr->rd->tell(fr));
1082
+
1083
+ /* If the new header ist good, it is already decoded. */
1084
+ *newheadp = newhead;
1085
+ return PARSE_GOOD;
1086
+ }
1087
+
1088
+ /* The newhead is bad, so let's check if it is something special, otherwise just resync. */
1089
+ static int wetwork(mpg123_handle *fr, unsigned long *newheadp)
1090
+ {
1091
+ int ret = PARSE_ERR;
1092
+ unsigned long newhead = *newheadp;
1093
+ *newheadp = 0;
1094
+
1095
+ /* Classic ID3 tags. Read, then start parsing again. */
1096
+ if((newhead & 0xffffff00) == ('T'<<24)+('A'<<16)+('G'<<8))
1097
+ {
1098
+ fr->id3buf[0] = (unsigned char) ((newhead >> 24) & 0xff);
1099
+ fr->id3buf[1] = (unsigned char) ((newhead >> 16) & 0xff);
1100
+ fr->id3buf[2] = (unsigned char) ((newhead >> 8) & 0xff);
1101
+ fr->id3buf[3] = (unsigned char) ( newhead & 0xff);
1102
+
1103
+ if((ret=fr->rd->fullread(fr,fr->id3buf+4,124)) < 0) return ret;
1104
+
1105
+ fr->metaflags |= MPG123_NEW_ID3|MPG123_ID3;
1106
+ fr->rdat.flags |= READER_ID3TAG; /* that marks id3v1 */
1107
+ if(VERBOSE3) fprintf(stderr,"Note: Skipped ID3v1 tag.\n");
1108
+
1109
+ return PARSE_AGAIN;
1110
+ }
1111
+ /* This is similar to initial junk skipping code... */
1112
+ /* Check for id3v2; first three bytes (of 4) are "ID3" */
1113
+ if((newhead & (unsigned long) 0xffffff00) == (unsigned long) 0x49443300)
1114
+ {
1115
+ return handle_id3v2(fr, newhead);
1116
+ }
1117
+ else if(NOQUIET && fr->silent_resync == 0)
1118
+ {
1119
+ fprintf(stderr,"Note: Illegal Audio-MPEG-Header 0x%08lx at offset %"OFF_P".\n",
1120
+ newhead, (off_p)fr->rd->tell(fr)-4);
1121
+ }
1122
+
1123
+ /* Now we got something bad at hand, try to recover. */
1124
+
1125
+ if(NOQUIET && (newhead & 0xffffff00) == ('b'<<24)+('m'<<16)+('p'<<8)) fprintf(stderr,"Note: Could be a BMP album art.\n");
1126
+
1127
+ if( !(fr->p.flags & MPG123_NO_RESYNC) )
1128
+ {
1129
+ long try = 0;
1130
+ long limit = fr->p.resync_limit;
1131
+
1132
+ /* If a resync is needed the bitreservoir of previous frames is no longer valid */
1133
+ fr->bitreservoir = 0;
1134
+
1135
+ if(NOQUIET && fr->silent_resync == 0) fprintf(stderr, "Note: Trying to resync...\n");
1136
+
1137
+ do /* ... shift the header with additional single bytes until be found something that could be a header. */
1138
+ {
1139
+ ++try;
1140
+ if(limit >= 0 && try >= limit) break;
1141
+
1142
+ if((ret=fr->rd->head_shift(fr,&newhead)) <= 0)
1143
+ {
1144
+ *newheadp = newhead;
1145
+ if(NOQUIET) fprintf (stderr, "Note: Hit end of (available) data during resync.\n");
1146
+
1147
+ return ret ? ret : PARSE_END;
1148
+ }
1149
+ if(VERBOSE3) debug3("resync try %li at %"OFF_P", got newhead 0x%08lx", try, (off_p)fr->rd->tell(fr), newhead);
1150
+ } while(!head_check(newhead));
1151
+
1152
+ *newheadp = newhead;
1153
+ if(NOQUIET && fr->silent_resync == 0) fprintf (stderr, "Note: Skipped %li bytes in input.\n", try);
1154
+
1155
+ /* Now we either got something that could be a header, or we gave up. */
1156
+ if(limit >= 0 && try >= limit)
1157
+ {
1158
+ if(NOQUIET)
1159
+ error1("Giving up resync after %li bytes - your stream is not nice... (maybe increasing resync limit could help).", try);
1160
+
1161
+ fr->err = MPG123_RESYNC_FAIL;
1162
+ return PARSE_ERR;
1163
+ }
1164
+ else
1165
+ {
1166
+ debug1("Found possibly valid header 0x%lx... unsetting firsthead to reinit stream.", newhead);
1167
+ fr->firsthead = 0;
1168
+ return PARSE_RESYNC;
1169
+ }
1170
+ }
1171
+ else
1172
+ {
1173
+ if(NOQUIET) error("not attempting to resync...");
1174
+
1175
+ fr->err = MPG123_OUT_OF_SYNC;
1176
+ return PARSE_ERR;
1177
+ }
1178
+ /* Control never goes here... we return before that. */
1179
+ }