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,10 @@
1
+ /* You expect a license plate for _this_ file? */
2
+ #ifndef MPG123_ICY2UTF_H
3
+ #define MPG123_ICY2UTF_H
4
+
5
+ #ifndef NO_ICY
6
+ /* (string, force conversion) */
7
+ char *icy2utf8(const char *, int);
8
+ #endif
9
+
10
+ #endif
@@ -0,0 +1,999 @@
1
+ /*
2
+ id3: ID3v2.3 and ID3v2.4 parsing (a relevant subset)
3
+
4
+ copyright 2006-2008 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 Thomas Orgis
7
+ */
8
+
9
+ #include "mpg123lib_intern.h"
10
+ #include "id3.h"
11
+ #include "debug.h"
12
+
13
+ #ifndef NO_ID3V2 /* Only the main parsing routine will always be there. */
14
+
15
+ /* We know the usual text frames plus some specifics. */
16
+ #define KNOWN_FRAMES 4
17
+ static const char frame_type[KNOWN_FRAMES][5] = { "COMM", "TXXX", "RVA2", "USLT" };
18
+ enum frame_types { unknown = -2, text = -1, comment, extra, rva2, uslt };
19
+
20
+ /* UTF support definitions */
21
+
22
+ typedef void (*text_converter)(mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
23
+
24
+ static void convert_latin1 (mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
25
+ static void convert_utf16bom(mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
26
+ static void convert_utf8 (mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet);
27
+
28
+ static const text_converter text_converters[4] =
29
+ {
30
+ convert_latin1,
31
+ /* We always check for (multiple) BOM in 16bit unicode. Without BOM, UTF16 BE is the default.
32
+ Errors in encoding are detected anyway. */
33
+ convert_utf16bom,
34
+ convert_utf16bom,
35
+ convert_utf8
36
+ };
37
+
38
+ static const unsigned int encoding_widths[4] = { 1, 2, 2, 1 };
39
+
40
+ /* the code starts here... */
41
+
42
+ static void null_id3_links(mpg123_handle *fr)
43
+ {
44
+ fr->id3v2.title = NULL;
45
+ fr->id3v2.artist = NULL;
46
+ fr->id3v2.album = NULL;
47
+ fr->id3v2.year = NULL;
48
+ fr->id3v2.genre = NULL;
49
+ fr->id3v2.comment = NULL;
50
+ }
51
+
52
+ void init_id3(mpg123_handle *fr)
53
+ {
54
+ fr->id3v2.version = 0; /* nothing there */
55
+ null_id3_links(fr);
56
+ fr->id3v2.comments = 0;
57
+ fr->id3v2.comment_list = NULL;
58
+ fr->id3v2.texts = 0;
59
+ fr->id3v2.text = NULL;
60
+ fr->id3v2.extras = 0;
61
+ fr->id3v2.extra = NULL;
62
+ }
63
+
64
+ /* Managing of the text, comment and extra lists. */
65
+
66
+ /* Initialize one element. */
67
+ static void init_mpg123_text(mpg123_text *txt)
68
+ {
69
+ mpg123_init_string(&txt->text);
70
+ mpg123_init_string(&txt->description);
71
+ txt->id[0] = 0;
72
+ txt->id[1] = 0;
73
+ txt->id[2] = 0;
74
+ txt->id[3] = 0;
75
+ txt->lang[0] = 0;
76
+ txt->lang[1] = 0;
77
+ txt->lang[2] = 0;
78
+ }
79
+
80
+ /* Free memory of one element. */
81
+ static void free_mpg123_text(mpg123_text *txt)
82
+ {
83
+ mpg123_free_string(&txt->text);
84
+ mpg123_free_string(&txt->description);
85
+ }
86
+
87
+ /* Free memory of whole list. */
88
+ #define free_comment(mh) free_id3_text(&((mh)->id3v2.comment_list), &((mh)->id3v2.comments))
89
+ #define free_text(mh) free_id3_text(&((mh)->id3v2.text), &((mh)->id3v2.texts))
90
+ #define free_extra(mh) free_id3_text(&((mh)->id3v2.extra), &((mh)->id3v2.extras))
91
+ static void free_id3_text(mpg123_text **list, size_t *size)
92
+ {
93
+ size_t i;
94
+ for(i=0; i<*size; ++i) free_mpg123_text(&((*list)[i]));
95
+
96
+ free(*list);
97
+ *list = NULL;
98
+ *size = 0;
99
+ }
100
+
101
+ /* Add items to the list. */
102
+ #define add_comment(mh) add_id3_text(&((mh)->id3v2.comment_list), &((mh)->id3v2.comments))
103
+ #define add_text(mh) add_id3_text(&((mh)->id3v2.text), &((mh)->id3v2.texts))
104
+ #define add_extra(mh) add_id3_text(&((mh)->id3v2.extra), &((mh)->id3v2.extras))
105
+ static mpg123_text *add_id3_text(mpg123_text **list, size_t *size)
106
+ {
107
+ mpg123_text *x = safe_realloc(*list, sizeof(mpg123_text)*(*size+1));
108
+ if(x == NULL) return NULL; /* bad */
109
+
110
+ *list = x;
111
+ *size += 1;
112
+ init_mpg123_text(&((*list)[*size-1]));
113
+
114
+ return &((*list)[*size-1]); /* Return pointer to the added text. */
115
+ }
116
+
117
+ /* Remove the last item. */
118
+ #define pop_comment(mh) pop_id3_text(&((mh)->id3v2.comment_list), &((mh)->id3v2.comments))
119
+ #define pop_text(mh) pop_id3_text(&((mh)->id3v2.text), &((mh)->id3v2.texts))
120
+ #define pop_extra(mh) pop_id3_text(&((mh)->id3v2.extra), &((mh)->id3v2.extras))
121
+ static void pop_id3_text(mpg123_text **list, size_t *size)
122
+ {
123
+ mpg123_text *x;
124
+ if(*size < 1) return;
125
+
126
+ free_mpg123_text(&((*list)[*size-1]));
127
+ if(*size > 1)
128
+ {
129
+ x = safe_realloc(*list, sizeof(mpg123_text)*(*size-1));
130
+ if(x != NULL){ *list = x; *size -= 1; }
131
+ }
132
+ else
133
+ {
134
+ free(*list);
135
+ *list = NULL;
136
+ *size = 0;
137
+ }
138
+ }
139
+
140
+ /* OK, back t the higher level functions. */
141
+
142
+ void exit_id3(mpg123_handle *fr)
143
+ {
144
+ free_comment(fr);
145
+ free_extra(fr);
146
+ free_text(fr);
147
+ }
148
+
149
+ void reset_id3(mpg123_handle *fr)
150
+ {
151
+ exit_id3(fr);
152
+ init_id3(fr);
153
+ }
154
+
155
+ /* Set the id3v2.artist id3v2.title ... links to elements of the array. */
156
+ void id3_link(mpg123_handle *fr)
157
+ {
158
+ size_t i;
159
+ mpg123_id3v2 *v2 = &fr->id3v2;
160
+ debug("linking ID3v2");
161
+ null_id3_links(fr);
162
+ for(i=0; i<v2->texts; ++i)
163
+ {
164
+ mpg123_text *entry = &v2->text[i];
165
+ if (!strncmp("TIT2", entry->id, 4)) v2->title = &entry->text;
166
+ else if(!strncmp("TALB", entry->id, 4)) v2->album = &entry->text;
167
+ else if(!strncmp("TPE1", entry->id, 4)) v2->artist = &entry->text;
168
+ else if(!strncmp("TYER", entry->id, 4)) v2->year = &entry->text;
169
+ else if(!strncmp("TCON", entry->id, 4)) v2->genre = &entry->text;
170
+ }
171
+ for(i=0; i<v2->comments; ++i)
172
+ {
173
+ mpg123_text *entry = &v2->comment_list[i];
174
+ if(entry->description.fill == 0 || entry->description.p[0] == 0)
175
+ v2->comment = &entry->text;
176
+ }
177
+ /* When no generic comment found, use the last non-generic one. */
178
+ if(v2->comment == NULL && v2->comments > 0)
179
+ v2->comment = &v2->comment_list[v2->comments-1].text;
180
+ }
181
+
182
+ /*
183
+ Store ID3 text data in an mpg123_string; either verbatim copy or everything translated to UTF-8 encoding.
184
+ Preserve the zero string separator (I don't need strlen for the total size).
185
+
186
+ ID3v2 standard says that there should be one text frame of specific type per tag, and subsequent tags overwrite old values.
187
+ So, I always replace the text that may be stored already (perhaps with a list of zero-separated strings, though).
188
+ */
189
+ static void store_id3_text(mpg123_string *sb, char *source, size_t source_size, const int noquiet, const int notranslate)
190
+ {
191
+ if(!source_size)
192
+ {
193
+ debug("Empty id3 data!");
194
+ return;
195
+ }
196
+
197
+ /* We shall just copy the data. Client wants to decode itself. */
198
+ if(notranslate)
199
+ {
200
+ /* Future: Add a path for ID3 errors. */
201
+ if(!mpg123_resize_string(sb, source_size))
202
+ {
203
+ if(noquiet) error("Cannot resize target string, out of memory?");
204
+ return;
205
+ }
206
+ memcpy(sb->p, source, source_size);
207
+ sb->fill = source_size;
208
+ debug1("stored undecoded ID3 text of size %"SIZE_P, (size_p)source_size);
209
+ return;
210
+ }
211
+
212
+ id3_to_utf8(sb, ((unsigned char *)source)[0], (unsigned char*)source+1, source_size-1, noquiet);
213
+
214
+ if(sb->fill) debug1("UTF-8 string (the first one): %s", sb->p);
215
+ else if(noquiet) error("unable to convert string to UTF-8 (out of memory, junk input?)!");
216
+ }
217
+
218
+ /* On error, sb->size is 0. */
219
+ void id3_to_utf8(mpg123_string *sb, unsigned char encoding, const unsigned char *source, size_t source_size, int noquiet)
220
+ {
221
+ unsigned int bwidth;
222
+ debug1("encoding: %u", encoding);
223
+ /* A note: ID3v2.3 uses UCS-2 non-variable 16bit encoding, v2.4 uses UTF16.
224
+ UTF-16 uses a reserved/private range in UCS-2 to add the magic, so we just always treat it as UTF. */
225
+ if(encoding > mpg123_id3_enc_max)
226
+ {
227
+ if(noquiet) error1("Unknown text encoding %u, I take no chances, sorry!", encoding);
228
+
229
+ mpg123_free_string(sb);
230
+ return;
231
+ }
232
+ bwidth = encoding_widths[encoding];
233
+ /* Hack! I've seen a stray zero byte before BOM. Is that supposed to happen? */
234
+ if(encoding != mpg123_id3_utf16be) /* UTF16be _can_ beging with a null byte! */
235
+ while(source_size > bwidth && source[0] == 0)
236
+ {
237
+ --source_size;
238
+ ++source;
239
+ debug("skipped leading zero");
240
+ }
241
+ if(source_size % bwidth)
242
+ {
243
+ /* When we need two bytes for a character, it's strange to have an uneven bytestream length. */
244
+ if(noquiet) warning2("Weird tag size %d for encoding %u - I will probably trim too early or something but I think the MP3 is broken.", (int)source_size, encoding);
245
+ source_size -= source_size % bwidth;
246
+ }
247
+ text_converters[encoding](sb, source, source_size, noquiet);
248
+ }
249
+
250
+ static char *next_text(char* prev, int encoding, size_t limit)
251
+ {
252
+ char *text = prev;
253
+ size_t width = encoding_widths[encoding];
254
+
255
+ /* So I go lengths to find zero or double zero...
256
+ Remember bug 2834636: Only check for aligned NULLs! */
257
+ while(text-prev < (ssize_t)limit)
258
+ {
259
+ if(text[0] == 0)
260
+ {
261
+ if(width <= limit-(text-prev))
262
+ {
263
+ size_t i = 1;
264
+ for(; i<width; ++i) if(text[i] != 0) break;
265
+
266
+ if(i == width) /* found a null wide enough! */
267
+ {
268
+ text += width;
269
+ break;
270
+ }
271
+ }
272
+ else return NULL; /* No full character left? This text is broken */
273
+ }
274
+
275
+ text += width;
276
+ }
277
+ if((size_t)(text-prev) >= limit) text = NULL;
278
+
279
+ return text;
280
+ }
281
+
282
+ static const char *enc_name(int enc)
283
+ {
284
+ switch(enc)
285
+ {
286
+ case 0: return "Latin 1";
287
+ case 1: return "UTF-16 BOM";
288
+ case 2: return "UTF-16 BE";
289
+ case 3: return "UTF-8";
290
+ default: return "unknown!";
291
+ }
292
+ }
293
+
294
+ static void process_text(mpg123_handle *fr, char *realdata, size_t realsize, char *id)
295
+ {
296
+ /* Text encoding $xx */
297
+ /* The text (encoded) ... */
298
+ mpg123_text *t = add_text(fr);
299
+ if(VERBOSE4) fprintf(stderr, "Note: Storing text from %s encoding\n", enc_name(realdata[0]));
300
+ if(t == NULL)
301
+ {
302
+ if(NOQUIET) error("Unable to attach new text!");
303
+ return;
304
+ }
305
+ memcpy(t->id, id, 4);
306
+ store_id3_text(&t->text, realdata, realsize, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
307
+ if(VERBOSE4) fprintf(stderr, "Note: ID3v2 %c%c%c%c text frame: %s\n", id[0], id[1], id[2], id[3], t->text.p);
308
+ }
309
+
310
+ /* Store a new comment that perhaps is a RVA / RVA_ALBUM/AUDIOPHILE / RVA_MIX/RADIO one
311
+ Special gimmik: It also stores USLT to the texts. Stucture is the same as for comments. */
312
+ static void process_comment(mpg123_handle *fr, enum frame_types tt, char *realdata, size_t realsize, int rva_level, char *id)
313
+ {
314
+ /* Text encoding $xx */
315
+ /* Language $xx xx xx */
316
+ /* Short description (encoded!) <text> $00 (00) */
317
+ /* Then the comment text (encoded) ... */
318
+ char encoding = realdata[0];
319
+ char *lang = realdata+1; /* I'll only use the 3 bytes! */
320
+ char *descr = realdata+4;
321
+ char *text = NULL;
322
+ mpg123_text *xcom = NULL;
323
+ mpg123_text localcom; /* UTF-8 variant for local processing. */
324
+
325
+ if((int)realsize < descr-realdata)
326
+ {
327
+ if(NOQUIET) error1("Invalid frame size of %lu (too small for anything).", (unsigned long)realsize);
328
+ return;
329
+ }
330
+ xcom = (tt == uslt ? add_text(fr) : add_comment(fr));
331
+ if(VERBOSE4) fprintf(stderr, "Note: Storing comment from %s encoding\n", enc_name(realdata[0]));
332
+ if(xcom == NULL)
333
+ {
334
+ if(NOQUIET) error("Unable to attach new comment!");
335
+ return;
336
+ }
337
+ memcpy(xcom->lang, lang, 3);
338
+ memcpy(xcom->id, id, 4);
339
+ /* Now I can abuse a byte from lang for the encoding. */
340
+ descr[-1] = encoding;
341
+ /* Be careful with finding the end of description, I have to honor encoding here. */
342
+ text = next_text(descr, encoding, realsize-(descr-realdata));
343
+ if(text == NULL)
344
+ {
345
+ if(NOQUIET) error("No comment text / valid description?");
346
+ pop_comment(fr);
347
+ return;
348
+ }
349
+
350
+ init_mpg123_text(&localcom);
351
+ /* Store the text, without translation to UTF-8, but for comments always a local copy in UTF-8.
352
+ Reminder: No bailing out from here on without freeing the local comment data! */
353
+ store_id3_text(&xcom->description, descr-1, text-descr+1, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
354
+ if(tt == comment)
355
+ store_id3_text(&localcom.description, descr-1, text-descr+1, NOQUIET, 0);
356
+
357
+ text[-1] = encoding; /* Byte abusal for encoding... */
358
+ store_id3_text(&xcom->text, text-1, realsize+1-(text-realdata), NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
359
+ /* Remember: I will probably decode the above (again) for rva comment checking. So no messing around, please. */
360
+
361
+ if(VERBOSE4) /* Do _not_ print the verbatim text: The encoding might be funny! */
362
+ {
363
+ fprintf(stderr, "Note: ID3 comm/uslt desc of length %"SIZE_P".\n", (size_p)xcom->description.fill);
364
+ fprintf(stderr, "Note: ID3 comm/uslt text of length %"SIZE_P".\n", (size_p)xcom->text.fill);
365
+ }
366
+ /* Look out for RVA info only when we really deal with a straight comment. */
367
+ if(tt == comment && localcom.description.fill > 0)
368
+ {
369
+ int rva_mode = -1; /* mix / album */
370
+ if( !strcasecmp(localcom.description.p, "rva")
371
+ || !strcasecmp(localcom.description.p, "rva_mix")
372
+ || !strcasecmp(localcom.description.p, "rva_track")
373
+ || !strcasecmp(localcom.description.p, "rva_radio") )
374
+ rva_mode = 0;
375
+ else if( !strcasecmp(localcom.description.p, "rva_album")
376
+ || !strcasecmp(localcom.description.p, "rva_audiophile")
377
+ || !strcasecmp(localcom.description.p, "rva_user") )
378
+ rva_mode = 1;
379
+ if((rva_mode > -1) && (fr->rva.level[rva_mode] <= rva_level))
380
+ {
381
+ /* Only translate the contents in here where we really need them. */
382
+ store_id3_text(&localcom.text, text-1, realsize+1-(text-realdata), NOQUIET, 0);
383
+ if(localcom.text.fill > 0)
384
+ {
385
+ fr->rva.gain[rva_mode] = (float) atof(localcom.text.p);
386
+ if(VERBOSE3) fprintf(stderr, "Note: RVA value %fdB\n", fr->rva.gain[rva_mode]);
387
+ fr->rva.peak[rva_mode] = 0;
388
+ fr->rva.level[rva_mode] = rva_level;
389
+ }
390
+ }
391
+ }
392
+ /* Make sure to free the local memory... */
393
+ free_mpg123_text(&localcom);
394
+ }
395
+
396
+ static void process_extra(mpg123_handle *fr, char* realdata, size_t realsize, int rva_level, char *id)
397
+ {
398
+ /* Text encoding $xx */
399
+ /* Description ... $00 (00) */
400
+ /* Text ... */
401
+ char encoding = realdata[0];
402
+ char *descr = realdata+1; /* remember, the encoding is descr[-1] */
403
+ char *text;
404
+ mpg123_text *xex;
405
+ mpg123_text localex;
406
+
407
+ if((int)realsize < descr-realdata)
408
+ {
409
+ if(NOQUIET) error1("Invalid frame size of %lu (too small for anything).", (unsigned long)realsize);
410
+ return;
411
+ }
412
+ text = next_text(descr, encoding, realsize-(descr-realdata));
413
+ if(VERBOSE4) fprintf(stderr, "Note: Storing extra from %s encoding\n", enc_name(realdata[0]));
414
+ if(text == NULL)
415
+ {
416
+ if(NOQUIET) error("No extra frame text / valid description?");
417
+ return;
418
+ }
419
+ xex = add_extra(fr);
420
+ if(xex == NULL)
421
+ {
422
+ if(NOQUIET) error("Unable to attach new extra text!");
423
+ return;
424
+ }
425
+ memcpy(xex->id, id, 4);
426
+ init_mpg123_text(&localex); /* For our local copy. */
427
+
428
+ /* The outside storage gets reencoded to UTF-8 only if not requested otherwise.
429
+ Remember that we really need the -1 here to hand in the encoding byte!*/
430
+ store_id3_text(&xex->description, descr-1, text-descr+1, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
431
+ /* Our local copy is always stored in UTF-8! */
432
+ store_id3_text(&localex.description, descr-1, text-descr+1, NOQUIET, 0);
433
+ /* At first, only store the outside copy of the payload. We may not need the local copy. */
434
+ text[-1] = encoding;
435
+ store_id3_text(&xex->text, text-1, realsize-(text-realdata)+1, NOQUIET, fr->p.flags & MPG123_PLAIN_ID3TEXT);
436
+
437
+ /* Now check if we would like to interpret this extra info for RVA. */
438
+ if(localex.description.fill > 0)
439
+ {
440
+ int is_peak = 0;
441
+ int rva_mode = -1; /* mix / album */
442
+
443
+ if(!strncasecmp(localex.description.p, "replaygain_track_",17))
444
+ {
445
+ if(VERBOSE3) fprintf(stderr, "Note: RVA ReplayGain track gain/peak\n");
446
+
447
+ rva_mode = 0;
448
+ if(!strcasecmp(localex.description.p, "replaygain_track_peak")) is_peak = 1;
449
+ else if(strcasecmp(localex.description.p, "replaygain_track_gain")) rva_mode = -1;
450
+ }
451
+ else
452
+ if(!strncasecmp(localex.description.p, "replaygain_album_",17))
453
+ {
454
+ if(VERBOSE3) fprintf(stderr, "Note: RVA ReplayGain album gain/peak\n");
455
+
456
+ rva_mode = 1;
457
+ if(!strcasecmp(localex.description.p, "replaygain_album_peak")) is_peak = 1;
458
+ else if(strcasecmp(localex.description.p, "replaygain_album_gain")) rva_mode = -1;
459
+ }
460
+ if((rva_mode > -1) && (fr->rva.level[rva_mode] <= rva_level))
461
+ {
462
+ /* Now we need the translated copy of the data. */
463
+ store_id3_text(&localex.text, text-1, realsize-(text-realdata)+1, NOQUIET, 0);
464
+ if(localex.text.fill > 0)
465
+ {
466
+ if(is_peak)
467
+ {
468
+ fr->rva.peak[rva_mode] = (float) atof(localex.text.p);
469
+ if(VERBOSE3) fprintf(stderr, "Note: RVA peak %f\n", fr->rva.peak[rva_mode]);
470
+ }
471
+ else
472
+ {
473
+ fr->rva.gain[rva_mode] = (float) atof(localex.text.p);
474
+ if(VERBOSE3) fprintf(stderr, "Note: RVA gain %fdB\n", fr->rva.gain[rva_mode]);
475
+ }
476
+ fr->rva.level[rva_mode] = rva_level;
477
+ }
478
+ }
479
+ }
480
+
481
+ free_mpg123_text(&localex);
482
+ }
483
+
484
+ /* Make a ID3v2.3+ 4-byte ID from a ID3v2.2 3-byte ID
485
+ Note that not all frames survived to 2.4; the mapping goes to 2.3 .
486
+ A notable miss is the old RVA frame, which is very unspecific anyway.
487
+ This function returns -1 when a not known 3 char ID was encountered, 0 otherwise. */
488
+ static int promote_framename(mpg123_handle *fr, char *id) /* fr because of VERBOSE macros */
489
+ {
490
+ size_t i;
491
+ char *old[] =
492
+ {
493
+ "COM", "TAL", "TBP", "TCM", "TCO", "TCR", "TDA", "TDY", "TEN", "TFT",
494
+ "TIM", "TKE", "TLA", "TLE", "TMT", "TOA", "TOF", "TOL", "TOR", "TOT",
495
+ "TP1", "TP2", "TP3", "TP4", "TPA", "TPB", "TRC", "TDA", "TRK", "TSI",
496
+ "TSS", "TT1", "TT2", "TT3", "TXT", "TXX", "TYE"
497
+ };
498
+ char *new[] =
499
+ {
500
+ "COMM", "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDAT", "TDLY", "TENC", "TFLT",
501
+ "TIME", "TKEY", "TLAN", "TLEN", "TMED", "TOPE", "TOFN", "TOLY", "TORY", "TOAL",
502
+ "TPE1", "TPE2", "TPE3", "TPE4", "TPOS", "TPUB", "TSRC", "TRDA", "TRCK", "TSIZ",
503
+ "TSSE", "TIT1", "TIT2", "TIT3", "TEXT", "TXXX", "TYER"
504
+ };
505
+ for(i=0; i<sizeof(old)/sizeof(char*); ++i)
506
+ {
507
+ if(!strncmp(id, old[i], 3))
508
+ {
509
+ memcpy(id, new[i], 4);
510
+ if(VERBOSE3) fprintf(stderr, "Translated ID3v2.2 frame %s to %s\n", old[i], new[i]);
511
+ return 0;
512
+ }
513
+ }
514
+ if(VERBOSE3) fprintf(stderr, "Ignoring untranslated ID3v2.2 frame %c%c%c\n", id[0], id[1], id[2]);
515
+ return -1;
516
+ }
517
+
518
+ #endif /* NO_ID3V2 */
519
+
520
+ /*
521
+ trying to parse ID3v2.3 and ID3v2.4 tags...
522
+
523
+ returns: 0: bad or just unparseable tag
524
+ 1: good, (possibly) new tag info
525
+ <0: reader error (may need more data feed, try again)
526
+ */
527
+ int parse_new_id3(mpg123_handle *fr, unsigned long first4bytes)
528
+ {
529
+ #define UNSYNC_FLAG 128
530
+ #define EXTHEAD_FLAG 64
531
+ #define EXP_FLAG 32
532
+ #define FOOTER_FLAG 16
533
+ #define UNKNOWN_FLAGS 15 /* 00001111*/
534
+ unsigned char buf[6];
535
+ unsigned long length=0;
536
+ unsigned char flags = 0;
537
+ int ret = 1;
538
+ int ret2;
539
+ unsigned char major = first4bytes & 0xff;
540
+ debug1("ID3v2: major tag version: %i", major);
541
+ if(major == 0xff) return 0; /* Invalid... */
542
+ if((ret2 = fr->rd->read_frame_body(fr, buf, 6)) < 0) /* read more header information */
543
+ return ret2;
544
+
545
+ if(buf[0] == 0xff) return 0; /* Revision, will never be 0xff. */
546
+
547
+ /* second new byte are some nice flags, if these are invalid skip the whole thing */
548
+ flags = buf[1];
549
+ debug1("ID3v2: flags 0x%08x", flags);
550
+ /* use 4 bytes from buf to construct 28bit uint value and return 1; return 0 if bytes are not synchsafe */
551
+ #define synchsafe_to_long(buf,res) \
552
+ ( \
553
+ (((buf)[0]|(buf)[1]|(buf)[2]|(buf)[3]) & 0x80) ? 0 : \
554
+ (res = (((unsigned long) (buf)[0]) << 21) \
555
+ | (((unsigned long) (buf)[1]) << 14) \
556
+ | (((unsigned long) (buf)[2]) << 7) \
557
+ | ((unsigned long) (buf)[3]) \
558
+ ,1) \
559
+ )
560
+ /* id3v2.3 does not store synchsafe frame sizes, but synchsafe tag size - doh! */
561
+ #define bytes_to_long(buf,res) \
562
+ ( \
563
+ major == 3 ? \
564
+ (res = (((unsigned long) (buf)[0]) << 24) \
565
+ | (((unsigned long) (buf)[1]) << 16) \
566
+ | (((unsigned long) (buf)[2]) << 8) \
567
+ | ((unsigned long) (buf)[3]) \
568
+ ,1) : synchsafe_to_long(buf,res) \
569
+ )
570
+ /* for id3v2.2 only */
571
+ #define threebytes_to_long(buf,res) \
572
+ ( \
573
+ res = (((unsigned long) (buf)[0]) << 16) \
574
+ | (((unsigned long) (buf)[1]) << 8) \
575
+ | ((unsigned long) (buf)[2]) \
576
+ ,1 \
577
+ )
578
+
579
+ /* length-10 or length-20 (footer present); 4 synchsafe integers == 28 bit number */
580
+ /* we have already read 10 bytes, so left are length or length+10 bytes belonging to tag */
581
+ if(!synchsafe_to_long(buf+2,length))
582
+ {
583
+ if(NOQUIET) error4("Bad tag length (not synchsafe): 0x%02x%02x%02x%02x; You got a bad ID3 tag here.", buf[2],buf[3],buf[4],buf[5]);
584
+ return 0;
585
+ }
586
+ debug1("ID3v2: tag data length %lu", length);
587
+ #ifndef NO_ID3V2
588
+ if(VERBOSE2) fprintf(stderr,"Note: ID3v2.%i rev %i tag of %lu bytes\n", major, buf[0], length);
589
+ /* skip if unknown version/scary flags, parse otherwise */
590
+ if(fr->p.flags & MPG123_SKIP_ID3V2 || ((flags & UNKNOWN_FLAGS) || (major > 4) || (major < 2)))
591
+ {
592
+ if(NOQUIET)
593
+ {
594
+ if(fr->p.flags & MPG123_SKIP_ID3V2)
595
+ {
596
+ if(VERBOSE3) fprintf(stderr, "Note: Skipping ID3v2 tag per user request.\n");
597
+ }
598
+ else /* Must be because of scary Tag properties. */
599
+ warning2("ID3v2: Won't parse the ID3v2 tag with major version %u and flags 0x%xu - some extra code may be needed", major, flags);
600
+ }
601
+ #endif
602
+ if((ret2 = fr->rd->skip_bytes(fr,length)) < 0) /* will not store data in backbuff! */
603
+ ret = ret2;
604
+ #ifndef NO_ID3V2
605
+ }
606
+ else
607
+ {
608
+ unsigned char* tagdata = NULL;
609
+ fr->id3v2.version = major;
610
+ /* try to interpret that beast */
611
+ if((tagdata = (unsigned char*) malloc(length+1)) != NULL)
612
+ {
613
+ debug("ID3v2: analysing frames...");
614
+ if((ret2 = fr->rd->read_frame_body(fr,tagdata,length)) > 0)
615
+ {
616
+ unsigned long tagpos = 0;
617
+ debug1("ID3v2: have read at all %lu bytes for the tag now", (unsigned long)length+6);
618
+ /* going to apply strlen for strings inside frames, make sure that it doesn't overflow! */
619
+ tagdata[length] = 0;
620
+ if(flags & EXTHEAD_FLAG)
621
+ {
622
+ debug("ID3v2: skipping extended header");
623
+ if(!bytes_to_long(tagdata, tagpos))
624
+ {
625
+ ret = 0;
626
+ if(NOQUIET) error4("Bad (non-synchsafe) tag offset: 0x%02x%02x%02x%02x", tagdata[0], tagdata[1], tagdata[2], tagdata[3]);
627
+ }
628
+ }
629
+ if(ret > 0)
630
+ {
631
+ char id[5];
632
+ unsigned long framesize;
633
+ unsigned long fflags; /* need 16 bits, actually */
634
+ id[4] = 0;
635
+ /* pos now advanced after ext head, now a frame has to follow */
636
+ while(tagpos < length-10) /* I want to read at least a full header */
637
+ {
638
+ int i = 0;
639
+ unsigned long pos = tagpos;
640
+ int head_part = fr->id3v2.version == 2 ? 3 : 4; /* bytes of frame title and of framesize value */
641
+ /* level 1,2,3 - 0 is info from lame/info tag! */
642
+ /* rva tags with ascending significance, then general frames */
643
+ enum frame_types tt = unknown;
644
+ /* we may have entered the padding zone or any other strangeness: check if we have valid frame id characters */
645
+ for(i=0; i< head_part; ++i)
646
+ if( !( ((tagdata[tagpos+i] > 47) && (tagdata[tagpos+i] < 58))
647
+ || ((tagdata[tagpos+i] > 64) && (tagdata[tagpos+i] < 91)) ) )
648
+ {
649
+ debug5("ID3v2: real tag data apparently ended after %lu bytes with 0x%02x%02x%02x%02x", tagpos, tagdata[tagpos], tagdata[tagpos+1], tagdata[tagpos+2], tagdata[tagpos+3]);
650
+ /* This is no hard error... let's just hope that we got something meaningful already (ret==1 in that case). */
651
+ goto tagparse_cleanup; /* Need to escape two loops here. */
652
+ }
653
+ if(ret > 0)
654
+ {
655
+ /* 4 or 3 bytes id */
656
+ strncpy(id, (char*) tagdata+pos, head_part);
657
+ id[head_part] = 0; /* terminate for 3 or 4 bytes */
658
+ pos += head_part;
659
+ tagpos += head_part;
660
+ /* size as 32 bits or 28 bits */
661
+ if(fr->id3v2.version == 2) threebytes_to_long(tagdata+pos, framesize);
662
+ else
663
+ if(!bytes_to_long(tagdata+pos, framesize))
664
+ {
665
+ /* Just assume that up to now there was some good data. */
666
+ if(NOQUIET) error1("ID3v2: non-syncsafe size of %s frame, skipping the remainder of tag", id);
667
+ break;
668
+ }
669
+ if(VERBOSE3) fprintf(stderr, "Note: ID3v2 %s frame of size %lu\n", id, framesize);
670
+ tagpos += head_part + framesize; /* the important advancement in whole tag */
671
+ if(tagpos > length)
672
+ {
673
+ if(NOQUIET) error("Whoa! ID3v2 frame claims to be larger than the whole rest of the tag.");
674
+ break;
675
+ }
676
+ pos += head_part;
677
+ if(fr->id3v2.version > 2)
678
+ {
679
+ fflags = (((unsigned long) tagdata[pos]) << 8) | ((unsigned long) tagdata[pos+1]);
680
+ pos += 2;
681
+ tagpos += 2;
682
+ }
683
+ else fflags = 0;
684
+ /* for sanity, after full parsing tagpos should be == pos */
685
+ /* debug4("ID3v2: found %s frame, size %lu (as bytes: 0x%08lx), flags 0x%016lx", id, framesize, framesize, fflags); */
686
+ /* %0abc0000 %0h00kmnp */
687
+ #define BAD_FFLAGS (unsigned long) 36784
688
+ #define PRES_TAG_FFLAG 16384
689
+ #define PRES_FILE_FFLAG 8192
690
+ #define READ_ONLY_FFLAG 4096
691
+ #define GROUP_FFLAG 64
692
+ #define COMPR_FFLAG 8
693
+ #define ENCR_FFLAG 4
694
+ #define UNSYNC_FFLAG 2
695
+ #define DATLEN_FFLAG 1
696
+ if(head_part < 4 && promote_framename(fr, id) != 0) continue;
697
+
698
+ /* shall not or want not handle these */
699
+ if(fflags & (BAD_FFLAGS | COMPR_FFLAG | ENCR_FFLAG))
700
+ {
701
+ if(NOQUIET) warning("ID3v2: skipping invalid/unsupported frame");
702
+ continue;
703
+ }
704
+
705
+ for(i = 0; i < KNOWN_FRAMES; ++i)
706
+ if(!strncmp(frame_type[i], id, 4)){ tt = i; break; }
707
+
708
+ if(id[0] == 'T' && tt != extra) tt = text;
709
+
710
+ if(tt != unknown)
711
+ {
712
+ int rva_mode = -1; /* mix / album */
713
+ unsigned long realsize = framesize;
714
+ unsigned char* realdata = tagdata+pos;
715
+ if((flags & UNSYNC_FLAG) || (fflags & UNSYNC_FFLAG))
716
+ {
717
+ unsigned long ipos = 0;
718
+ unsigned long opos = 0;
719
+ debug("Id3v2: going to de-unsync the frame data");
720
+ /* de-unsync: FF00 -> FF; real FF00 is simply represented as FF0000 ... */
721
+ /* damn, that means I have to delete bytes from withing the data block... thus need temporal storage */
722
+ /* standard mandates that de-unsync should always be safe if flag is set */
723
+ realdata = (unsigned char*) malloc(framesize); /* will need <= bytes */
724
+ if(realdata == NULL)
725
+ {
726
+ if(NOQUIET) error("ID3v2: unable to allocate working buffer for de-unsync");
727
+ continue;
728
+ }
729
+ /* now going byte per byte through the data... */
730
+ realdata[0] = tagdata[pos];
731
+ opos = 1;
732
+ for(ipos = pos+1; ipos < pos+framesize; ++ipos)
733
+ {
734
+ if(!((tagdata[ipos] == 0) && (tagdata[ipos-1] == 0xff)))
735
+ {
736
+ realdata[opos++] = tagdata[ipos];
737
+ }
738
+ }
739
+ realsize = opos;
740
+ debug2("ID3v2: de-unsync made %lu out of %lu bytes", realsize, framesize);
741
+ }
742
+ pos = 0; /* now at the beginning again... */
743
+ switch(tt)
744
+ {
745
+ case comment:
746
+ case uslt:
747
+ process_comment(fr, tt, (char*)realdata, realsize, comment+1, id);
748
+ break;
749
+ case extra: /* perhaps foobar2000's work */
750
+ process_extra(fr, (char*)realdata, realsize, extra+1, id);
751
+ break;
752
+ case rva2: /* "the" RVA tag */
753
+ {
754
+ /* starts with null-terminated identification */
755
+ if(VERBOSE3) fprintf(stderr, "Note: RVA2 identification \"%s\"\n", realdata);
756
+ /* default: some individual value, mix mode */
757
+ rva_mode = 0;
758
+ if( !strncasecmp((char*)realdata, "album", 5)
759
+ || !strncasecmp((char*)realdata, "audiophile", 10)
760
+ || !strncasecmp((char*)realdata, "user", 4))
761
+ rva_mode = 1;
762
+ if(fr->rva.level[rva_mode] <= rva2+1)
763
+ {
764
+ pos += strlen((char*) realdata) + 1;
765
+ if(realdata[pos] == 1)
766
+ {
767
+ ++pos;
768
+ /* only handle master channel */
769
+ debug("ID3v2: it is for the master channel");
770
+ /* two bytes adjustment, one byte for bits representing peak - n bytes, eh bits, for peak */
771
+ /* 16 bit signed integer = dB * 512 ... the double cast is needed to preserve the sign of negative values! */
772
+ fr->rva.gain[rva_mode] = (float) ( (((short)((signed char)realdata[pos])) << 8) | realdata[pos+1] ) / 512;
773
+ pos += 2;
774
+ if(VERBOSE3) fprintf(stderr, "Note: RVA value %fdB\n", fr->rva.gain[rva_mode]);
775
+ /* heh, the peak value is represented by a number of bits - but in what manner? Skipping that part */
776
+ fr->rva.peak[rva_mode] = 0;
777
+ fr->rva.level[rva_mode] = rva2+1;
778
+ }
779
+ }
780
+ }
781
+ break;
782
+ /* non-rva metainfo, simply store... */
783
+ case text:
784
+ process_text(fr, (char*)realdata, realsize, id);
785
+ break;
786
+ default: if(NOQUIET) error1("ID3v2: unknown frame type %i", tt);
787
+ }
788
+ if((flags & UNSYNC_FLAG) || (fflags & UNSYNC_FFLAG)) free(realdata);
789
+ }
790
+ #undef BAD_FFLAGS
791
+ #undef PRES_TAG_FFLAG
792
+ #undef PRES_FILE_FFLAG
793
+ #undef READ_ONLY_FFLAG
794
+ #undef GROUP_FFLAG
795
+ #undef COMPR_FFLAG
796
+ #undef ENCR_FFLAG
797
+ #undef UNSYNC_FFLAG
798
+ #undef DATLEN_FFLAG
799
+ }
800
+ else break;
801
+ #undef KNOWN_FRAMES
802
+ }
803
+ }
804
+ }
805
+ else
806
+ {
807
+ /* There are tags with zero length. Strictly not an error, then. */
808
+ if(length > 0 && NOQUIET && ret2 != MPG123_NEED_MORE) error("ID3v2: Duh, not able to read ID3v2 tag data.");
809
+ ret = ret2;
810
+ }
811
+ tagparse_cleanup:
812
+ free(tagdata);
813
+ }
814
+ else
815
+ {
816
+ if(NOQUIET) error1("ID3v2: Arrg! Unable to allocate %lu bytes for interpreting ID3v2 data - trying to skip instead.", length);
817
+ if((ret2 = fr->rd->skip_bytes(fr,length)) < 0) ret = ret2; /* will not store data in backbuff! */
818
+ else ret = 0;
819
+ }
820
+ }
821
+ #endif /* NO_ID3V2 */
822
+ /* skip footer if present */
823
+ if((ret > 0) && (flags & FOOTER_FLAG) && ((ret2 = fr->rd->skip_bytes(fr,length)) < 0)) ret = ret2;
824
+
825
+ return ret;
826
+ #undef UNSYNC_FLAG
827
+ #undef EXTHEAD_FLAG
828
+ #undef EXP_FLAG
829
+ #undef FOOTER_FLAG
830
+ #undef UNKOWN_FLAGS
831
+ }
832
+
833
+ #ifndef NO_ID3V2 /* Disabling all the rest... */
834
+
835
+ static void convert_latin1(mpg123_string *sb, const unsigned char* s, size_t l, const int noquiet)
836
+ {
837
+ size_t length = l;
838
+ size_t i;
839
+ unsigned char *p;
840
+ /* determine real length, a latin1 character can at most take 2 in UTF8 */
841
+ for(i=0; i<l; ++i)
842
+ if(s[i] >= 0x80) ++length;
843
+
844
+ debug1("UTF-8 length: %lu", (unsigned long)length);
845
+ /* one extra zero byte for paranoia */
846
+ if(!mpg123_resize_string(sb, length+1)){ mpg123_free_string(sb); return ; }
847
+
848
+ p = (unsigned char*) sb->p; /* Signedness doesn't matter but it shows I thought about the non-issue */
849
+ for(i=0; i<l; ++i)
850
+ if(s[i] < 0x80){ *p = s[i]; ++p; }
851
+ else /* two-byte encoding */
852
+ {
853
+ *p = 0xc0 | (s[i]>>6);
854
+ *(p+1) = 0x80 | (s[i] & 0x3f);
855
+ p+=2;
856
+ }
857
+
858
+ sb->p[length] = 0;
859
+ sb->fill = length+1;
860
+ }
861
+
862
+ /*
863
+ Check if we have a byte oder mark(s) there, return:
864
+ -1: little endian
865
+ 0: no BOM
866
+ 1: big endian
867
+
868
+ This modifies source and len to indicate the data _after_ the BOM(s).
869
+ Note on nasty data: The last encountered BOM determines the endianness.
870
+ I have seen data with multiple BOMS, namely from "the" id3v2 program.
871
+ Not nice, but what should I do?
872
+ */
873
+ static int check_bom(const unsigned char** source, size_t *len)
874
+ {
875
+ int this_bom = 0;
876
+ int further_bom = 0;
877
+
878
+ if(*len < 2) return 0;
879
+
880
+ if((*source)[0] == 0xff && (*source)[1] == 0xfe)
881
+ this_bom = -1;
882
+
883
+ if((*source)[0] == 0xfe && (*source)[1] == 0xff)
884
+ this_bom = 1;
885
+
886
+ /* Skip the detected BOM. */
887
+ if(this_bom != 0)
888
+ {
889
+ *source += 2;
890
+ *len -= 2;
891
+ /* Check for following BOMs. The last one wins! */
892
+ further_bom = check_bom(source, len);
893
+ if(further_bom == 0) return this_bom; /* End of the recursion. */
894
+ else return further_bom;
895
+ }
896
+ else return 0;
897
+ }
898
+
899
+ #define FULLPOINT(f,s) ( (((f)&0x3ff)<<10) + ((s)&0x3ff) + 0x10000 )
900
+ /* Remember: There's a limit at 0x1ffff. */
901
+ #define UTF8LEN(x) ( (x)<0x80 ? 1 : ((x)<0x800 ? 2 : ((x)<0x10000 ? 3 : 4)))
902
+ static void convert_utf16bom(mpg123_string *sb, const unsigned char* s, size_t l, const int noquiet)
903
+ {
904
+ size_t i;
905
+ size_t n; /* number bytes that make up full pairs */
906
+ unsigned char *p;
907
+ size_t length = 0; /* the resulting UTF-8 length */
908
+ /* Determine real length... extreme case can be more than utf-16 length. */
909
+ size_t high = 0;
910
+ size_t low = 1;
911
+ int bom_endian;
912
+
913
+ debug1("convert_utf16 with length %lu", (unsigned long)l);
914
+
915
+ bom_endian = check_bom(&s, &l);
916
+ debug1("UTF16 endianness check: %i", bom_endian);
917
+
918
+ if(bom_endian == -1) /* little-endian */
919
+ {
920
+ high = 1; /* The second byte is the high byte. */
921
+ low = 0; /* The first byte is the low byte. */
922
+ }
923
+
924
+ n = (l/2)*2; /* number bytes that make up full pairs */
925
+
926
+ /* first: get length, check for errors -- stop at first one */
927
+ for(i=0; i < n; i+=2)
928
+ {
929
+ unsigned long point = ((unsigned long) s[i+high]<<8) + s[i+low];
930
+ if((point & 0xd800) == 0xd800) /* lead surrogate */
931
+ {
932
+ unsigned short second = (i+3 < l) ? (s[i+2+high]<<8) + s[i+2+low] : 0;
933
+ if((second & 0xdc00) == 0xdc00) /* good... */
934
+ {
935
+ point = FULLPOINT(point,second);
936
+ length += UTF8LEN(point); /* possibly 4 bytes */
937
+ i+=2; /* We overstepped one word. */
938
+ }
939
+ else /* if no valid pair, break here */
940
+ {
941
+ if(noquiet) error2("Invalid UTF16 surrogate pair at %li (0x%04lx).", (unsigned long)i, point);
942
+ n = i; /* Forget the half pair, END! */
943
+ break;
944
+ }
945
+ }
946
+ else length += UTF8LEN(point); /* 1,2 or 3 bytes */
947
+ }
948
+
949
+ if(!mpg123_resize_string(sb, length+1)){ mpg123_free_string(sb); return ; }
950
+
951
+ /* Now really convert, skip checks as these have been done just before. */
952
+ p = (unsigned char*) sb->p; /* Signedness doesn't matter but it shows I thought about the non-issue */
953
+ for(i=0; i < n; i+=2)
954
+ {
955
+ unsigned long codepoint = ((unsigned long) s[i+high]<<8) + s[i+low];
956
+ if((codepoint & 0xd800) == 0xd800) /* lead surrogate */
957
+ {
958
+ unsigned short second = (s[i+2+high]<<8) + s[i+2+low];
959
+ codepoint = FULLPOINT(codepoint,second);
960
+ i+=2; /* We overstepped one word. */
961
+ }
962
+ if(codepoint < 0x80) *p++ = (unsigned char) codepoint;
963
+ else if(codepoint < 0x800)
964
+ {
965
+ *p++ = (unsigned char) (0xc0 | (codepoint>>6));
966
+ *p++ = (unsigned char) (0x80 | (codepoint & 0x3f));
967
+ }
968
+ else if(codepoint < 0x10000)
969
+ {
970
+ *p++ = (unsigned char) (0xe0 | (codepoint>>12));
971
+ *p++ = 0x80 | ((codepoint>>6) & 0x3f);
972
+ *p++ = 0x80 | (codepoint & 0x3f);
973
+ }
974
+ else if (codepoint < 0x200000)
975
+ {
976
+ *p++ = (unsigned char) (0xf0 | codepoint>>18);
977
+ *p++ = (unsigned char) (0x80 | ((codepoint>>12) & 0x3f));
978
+ *p++ = (unsigned char) (0x80 | ((codepoint>>6) & 0x3f));
979
+ *p++ = (unsigned char) (0x80 | (codepoint & 0x3f));
980
+ } /* ignore bigger ones (that are not possible here anyway) */
981
+ }
982
+ sb->p[sb->size-1] = 0; /* paranoia... */
983
+ sb->fill = sb->size;
984
+ }
985
+ #undef UTF8LEN
986
+ #undef FULLPOINT
987
+
988
+ static void convert_utf8(mpg123_string *sb, const unsigned char* source, size_t len, const int noquiet)
989
+ {
990
+ if(mpg123_resize_string(sb, len+1))
991
+ {
992
+ memcpy(sb->p, source, len);
993
+ sb->p[len] = 0;
994
+ sb->fill = len+1;
995
+ }
996
+ else mpg123_free_string(sb);
997
+ }
998
+
999
+ #endif