seal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/LICENSE +13 -0
- data/README.md +265 -0
- data/ext/seal/extconf.rb +45 -0
- data/include/al/al.h +724 -0
- data/include/al/alc.h +277 -0
- data/include/al/efx-presets.h +402 -0
- data/include/al/efx.h +758 -0
- data/include/mpg123/mpg123.h +1034 -0
- data/include/ogg/config_types.h +25 -0
- data/include/ogg/ogg.h +210 -0
- data/include/ogg/os_types.h +147 -0
- data/include/seal.h +23 -0
- data/include/seal/buf.h +143 -0
- data/include/seal/core.h +95 -0
- data/include/seal/efs.h +112 -0
- data/include/seal/err.h +93 -0
- data/include/seal/fmt.h +58 -0
- data/include/seal/listener.h +103 -0
- data/include/seal/raw.h +86 -0
- data/include/seal/rvb.h +520 -0
- data/include/seal/src.h +413 -0
- data/include/seal/stream.h +81 -0
- data/include/vorbis/codec.h +243 -0
- data/include/vorbis/vorbisfile.h +206 -0
- data/mpg123/AUTHORS +150 -0
- data/mpg123/COPYING +773 -0
- data/mpg123/ChangeLog +3 -0
- data/mpg123/INSTALL +111 -0
- data/mpg123/Makefile.am +99 -0
- data/mpg123/Makefile.in +1043 -0
- data/mpg123/NEWS +1200 -0
- data/mpg123/NEWS.libmpg123 +133 -0
- data/mpg123/README +203 -0
- data/mpg123/TODO +38 -0
- data/mpg123/aclocal.m4 +1168 -0
- data/mpg123/build/config.guess +1530 -0
- data/mpg123/build/config.sub +1782 -0
- data/mpg123/build/depcomp +707 -0
- data/mpg123/build/install-sh +527 -0
- data/mpg123/build/ltmain.sh +9655 -0
- data/mpg123/build/missing +330 -0
- data/mpg123/configure +20267 -0
- data/mpg123/configure.ac +2178 -0
- data/mpg123/doc/ACCURACY +2 -0
- data/mpg123/doc/BENCHMARKING +110 -0
- data/mpg123/doc/BUGS +3 -0
- data/mpg123/doc/CONTACT +17 -0
- data/mpg123/doc/LICENSE +22 -0
- data/mpg123/doc/Makefile.am +32 -0
- data/mpg123/doc/Makefile.in +490 -0
- data/mpg123/doc/PATENTS +39 -0
- data/mpg123/doc/README.3DNOW +56 -0
- data/mpg123/doc/README.gain +171 -0
- data/mpg123/doc/README.remote +218 -0
- data/mpg123/doc/ROAD_TO_LGPL +270 -0
- data/mpg123/doc/THANKS +13 -0
- data/mpg123/doc/TODO +63 -0
- data/mpg123/doc/doxy_examples.c +21 -0
- data/mpg123/doc/doxygen.conf +41 -0
- data/mpg123/doc/doxyhead.xhtml +12 -0
- data/mpg123/doc/examples/dump_seekindex.c +41 -0
- data/mpg123/doc/examples/extract_frames.c +92 -0
- data/mpg123/doc/examples/feedseek.c +238 -0
- data/mpg123/doc/examples/id3dump.c +178 -0
- data/mpg123/doc/examples/mpg123_to_wav.c +118 -0
- data/mpg123/doc/examples/mpglib.c +92 -0
- data/mpg123/doc/examples/scan.c +47 -0
- data/mpg123/doc/libmpg123_speed.txt +84 -0
- data/mpg123/equalize.dat +37 -0
- data/mpg123/libmpg123.pc.in +11 -0
- data/mpg123/m4/addrconfig.m4 +34 -0
- data/mpg123/m4/libtool.m4 +7982 -0
- data/mpg123/m4/ltoptions.m4 +384 -0
- data/mpg123/m4/ltsugar.m4 +123 -0
- data/mpg123/m4/ltversion.m4 +23 -0
- data/mpg123/m4/lt~obsolete.m4 +98 -0
- data/mpg123/makedll.sh +19 -0
- data/mpg123/man1/mpg123.1 +512 -0
- data/mpg123/mpg123.spec +68 -0
- data/mpg123/mpg123.spec.in +68 -0
- data/mpg123/ports/MSVC++/2005/libmpg123/libmpg123.vcproj +741 -0
- data/mpg123/ports/MSVC++/2008/dump_seekindex/dump_seekindex.vcproj +194 -0
- data/mpg123/ports/MSVC++/2008/feedseek/feedseek.vcproj +195 -0
- data/mpg123/ports/MSVC++/2008/libmpg123/libmpg123.vcproj +1357 -0
- data/mpg123/ports/MSVC++/2008/mpg123.sln +44 -0
- data/mpg123/ports/MSVC++/2008/mpglib/mpglib.vcproj +191 -0
- data/mpg123/ports/MSVC++/2008/scan/scan.vcproj +195 -0
- data/mpg123/ports/MSVC++/2008clr/2008clr.sln +81 -0
- data/mpg123/ports/MSVC++/2008clr/examples/ReplaceReaderclr/Program.cs +435 -0
- data/mpg123/ports/MSVC++/2008clr/examples/ReplaceReaderclr/Properties/AssemblyInfo.cs +36 -0
- data/mpg123/ports/MSVC++/2008clr/examples/ReplaceReaderclr/ReplaceReaderclr.csproj +72 -0
- data/mpg123/ports/MSVC++/2008clr/examples/feedseekclr/Program.cs +331 -0
- data/mpg123/ports/MSVC++/2008clr/examples/feedseekclr/Properties/AssemblyInfo.cs +36 -0
- data/mpg123/ports/MSVC++/2008clr/examples/feedseekclr/feedseekclr.csproj +71 -0
- data/mpg123/ports/MSVC++/2008clr/examples/scanclr/Program.cs +79 -0
- data/mpg123/ports/MSVC++/2008clr/examples/scanclr/Properties/AssemblyInfo.cs +36 -0
- data/mpg123/ports/MSVC++/2008clr/examples/scanclr/scanclr.csproj +70 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/AssemblyInfo.cpp +76 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/ReadMe.txt +165 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/advanced.cpp +91 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/advanced.h +130 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/dllmain.cpp +19 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/enum.h +218 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/error.cpp +48 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/error.h +134 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v1.cpp +92 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v1.h +132 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v2.cpp +138 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/id3v2.h +152 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.cpp +896 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.h +953 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.rc +102 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/mpg123clr.vcproj +328 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/resource.h +14 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/stdafx.cpp +8 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/stdafx.h +38 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/string.cpp +166 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/string.h +265 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/targetver.h +24 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/text.cpp +67 -0
- data/mpg123/ports/MSVC++/2008clr/mpg123clr/text.h +111 -0
- data/mpg123/ports/MSVC++/2010/dump_seekindex/dump_seekindex.vcxproj +90 -0
- data/mpg123/ports/MSVC++/2010/dump_seekindex/dump_seekindex.vcxproj.filters +6 -0
- data/mpg123/ports/MSVC++/2010/feedseek/feedseek.vcxproj +95 -0
- data/mpg123/ports/MSVC++/2010/feedseek/feedseek.vcxproj.filters +6 -0
- data/mpg123/ports/MSVC++/2010/libmpg123/libmpg123.vcxproj +960 -0
- data/mpg123/ports/MSVC++/2010/libmpg123/libmpg123.vcxproj.user +3 -0
- data/mpg123/ports/MSVC++/2010/libmpg123/yasm.exe +0 -0
- data/mpg123/ports/MSVC++/2010/mpg123.sln +38 -0
- data/mpg123/ports/MSVC++/2010/scan/scan.vcxproj +93 -0
- data/mpg123/ports/MSVC++/2010/scan/scan.vcxproj.filters +6 -0
- data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/CORE/CORE_FileIn.H +15 -0
- data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/CORE/SourceFilter_MP3.H +139 -0
- data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/IIEP_Def.H +206 -0
- data/mpg123/ports/MSVC++/CMP3Stream/INCLUDE/IIEP_FileIn.H +167 -0
- data/mpg123/ports/MSVC++/CMP3Stream/README +4 -0
- data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/CORE_FileIn.CPP +462 -0
- data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/CORE_Log.CPP +122 -0
- data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/CORE_Mutex.CPP +35 -0
- data/mpg123/ports/MSVC++/CMP3Stream/SOURCE/SourceFilter_MP3Stream.CPP +586 -0
- data/mpg123/ports/MSVC++/CMP3Stream/libMPG123/PLACE_LIBMPG123_SOURCES_HERE +0 -0
- data/mpg123/ports/MSVC++/CMP3Stream/libMPG123/libMPG123.vcproj +245 -0
- data/mpg123/ports/MSVC++/config.h +35 -0
- data/mpg123/ports/MSVC++/examples/feedseek.c +240 -0
- data/mpg123/ports/MSVC++/examples/scan.c +47 -0
- data/mpg123/ports/MSVC++/mpg123.h +46 -0
- data/mpg123/ports/MSVC++/msvc.c +59 -0
- data/mpg123/ports/README +26 -0
- data/mpg123/ports/Sony_PSP/Makefile.psp +38 -0
- data/mpg123/ports/Sony_PSP/README +11 -0
- data/mpg123/ports/Sony_PSP/config.h +368 -0
- data/mpg123/ports/Sony_PSP/readers.c.patch +2 -0
- data/mpg123/ports/Xcode/config.h +197 -0
- data/mpg123/ports/Xcode/mpg123.h +17 -0
- data/mpg123/ports/Xcode/mpg123.xcodeproj/project.pbxproj +670 -0
- data/mpg123/ports/mpg123_.pas +478 -0
- data/mpg123/scripts/benchmark-cpu.pl +56 -0
- data/mpg123/scripts/tag_lyrics.py +76 -0
- data/mpg123/src/Makefile.am +186 -0
- data/mpg123/src/Makefile.in +1097 -0
- data/mpg123/src/audio.c +725 -0
- data/mpg123/src/audio.h +106 -0
- data/mpg123/src/buffer.c +312 -0
- data/mpg123/src/buffer.h +45 -0
- data/mpg123/src/common.c +240 -0
- data/mpg123/src/common.h +29 -0
- data/mpg123/src/config.h.in +436 -0
- data/mpg123/src/control_generic.c +809 -0
- data/mpg123/src/equalizer.c +48 -0
- data/mpg123/src/genre.c +271 -0
- data/mpg123/src/genre.h +15 -0
- data/mpg123/src/getlopt.c +148 -0
- data/mpg123/src/getlopt.h +77 -0
- data/mpg123/src/httpget.c +700 -0
- data/mpg123/src/httpget.h +66 -0
- data/mpg123/src/legacy_module.c +74 -0
- data/mpg123/src/libmpg123/Makefile.am +141 -0
- data/mpg123/src/libmpg123/Makefile.in +919 -0
- data/mpg123/src/libmpg123/compat.c +138 -0
- data/mpg123/src/libmpg123/compat.h +178 -0
- data/mpg123/src/libmpg123/dct36_3dnow.S +505 -0
- data/mpg123/src/libmpg123/dct36_3dnowext.S +512 -0
- data/mpg123/src/libmpg123/dct64.c +174 -0
- data/mpg123/src/libmpg123/dct64_3dnow.S +712 -0
- data/mpg123/src/libmpg123/dct64_3dnowext.S +714 -0
- data/mpg123/src/libmpg123/dct64_altivec.c +315 -0
- data/mpg123/src/libmpg123/dct64_i386.c +336 -0
- data/mpg123/src/libmpg123/dct64_i486.c +342 -0
- data/mpg123/src/libmpg123/dct64_mmx.S +811 -0
- data/mpg123/src/libmpg123/dct64_neon.S +297 -0
- data/mpg123/src/libmpg123/dct64_neon_float.S +270 -0
- data/mpg123/src/libmpg123/dct64_sse.S +454 -0
- data/mpg123/src/libmpg123/dct64_sse_float.S +401 -0
- data/mpg123/src/libmpg123/dct64_x86_64.S +464 -0
- data/mpg123/src/libmpg123/dct64_x86_64_float.S +426 -0
- data/mpg123/src/libmpg123/debug.h +171 -0
- data/mpg123/src/libmpg123/decode.h +268 -0
- data/mpg123/src/libmpg123/dither.c +119 -0
- data/mpg123/src/libmpg123/dither.h +23 -0
- data/mpg123/src/libmpg123/equalizer.c +17 -0
- data/mpg123/src/libmpg123/equalizer_3dnow.S +70 -0
- data/mpg123/src/libmpg123/feature.c +106 -0
- data/mpg123/src/libmpg123/format.c +521 -0
- data/mpg123/src/libmpg123/frame.c +1046 -0
- data/mpg123/src/libmpg123/frame.h +410 -0
- data/mpg123/src/libmpg123/gapless.h +119 -0
- data/mpg123/src/libmpg123/getbits.h +100 -0
- data/mpg123/src/libmpg123/getcpuflags.S +91 -0
- data/mpg123/src/libmpg123/getcpuflags.h +47 -0
- data/mpg123/src/libmpg123/huffman.h +340 -0
- data/mpg123/src/libmpg123/icy.c +32 -0
- data/mpg123/src/libmpg123/icy.h +38 -0
- data/mpg123/src/libmpg123/icy2utf8.c +438 -0
- data/mpg123/src/libmpg123/icy2utf8.h +10 -0
- data/mpg123/src/libmpg123/id3.c +999 -0
- data/mpg123/src/libmpg123/id3.h +43 -0
- data/mpg123/src/libmpg123/index.c +134 -0
- data/mpg123/src/libmpg123/index.h +59 -0
- data/mpg123/src/libmpg123/intsym.h +256 -0
- data/mpg123/src/libmpg123/l12_integer_tables.h +278 -0
- data/mpg123/src/libmpg123/l2tables.h +164 -0
- data/mpg123/src/libmpg123/l3_integer_tables.h +1002 -0
- data/mpg123/src/libmpg123/layer1.c +155 -0
- data/mpg123/src/libmpg123/layer2.c +371 -0
- data/mpg123/src/libmpg123/layer3.c +2053 -0
- data/mpg123/src/libmpg123/lfs_alias.c +252 -0
- data/mpg123/src/libmpg123/lfs_wrap.c +751 -0
- data/mpg123/src/libmpg123/libmpg123.c +1607 -0
- data/mpg123/src/libmpg123/mangle.h +74 -0
- data/mpg123/src/libmpg123/mpeghead.h +87 -0
- data/mpg123/src/libmpg123/mpg123.h.in +1075 -0
- data/mpg123/src/libmpg123/mpg123lib_intern.h +338 -0
- data/mpg123/src/libmpg123/ntom.c +148 -0
- data/mpg123/src/libmpg123/optimize.c +964 -0
- data/mpg123/src/libmpg123/optimize.h +219 -0
- data/mpg123/src/libmpg123/parse.c +1179 -0
- data/mpg123/src/libmpg123/parse.h +25 -0
- data/mpg123/src/libmpg123/reader.h +137 -0
- data/mpg123/src/libmpg123/readers.c +1235 -0
- data/mpg123/src/libmpg123/sample.h +152 -0
- data/mpg123/src/libmpg123/stringbuf.c +163 -0
- data/mpg123/src/libmpg123/synth.c +816 -0
- data/mpg123/src/libmpg123/synth.h +196 -0
- data/mpg123/src/libmpg123/synth_3dnow.S +318 -0
- data/mpg123/src/libmpg123/synth_3dnowext.S +6 -0
- data/mpg123/src/libmpg123/synth_8bit.c +142 -0
- data/mpg123/src/libmpg123/synth_8bit.h +86 -0
- data/mpg123/src/libmpg123/synth_altivec.c +1057 -0
- data/mpg123/src/libmpg123/synth_arm.S +271 -0
- data/mpg123/src/libmpg123/synth_arm_accurate.S +287 -0
- data/mpg123/src/libmpg123/synth_i486.c +252 -0
- data/mpg123/src/libmpg123/synth_i586.S +336 -0
- data/mpg123/src/libmpg123/synth_i586_dither.S +375 -0
- data/mpg123/src/libmpg123/synth_mmx.S +125 -0
- data/mpg123/src/libmpg123/synth_mono.h +64 -0
- data/mpg123/src/libmpg123/synth_neon.S +123 -0
- data/mpg123/src/libmpg123/synth_neon_accurate.S +173 -0
- data/mpg123/src/libmpg123/synth_neon_float.S +149 -0
- data/mpg123/src/libmpg123/synth_neon_s32.S +168 -0
- data/mpg123/src/libmpg123/synth_ntom.h +213 -0
- data/mpg123/src/libmpg123/synth_real.c +404 -0
- data/mpg123/src/libmpg123/synth_s32.c +411 -0
- data/mpg123/src/libmpg123/synth_sse.S +6 -0
- data/mpg123/src/libmpg123/synth_sse3d.h +246 -0
- data/mpg123/src/libmpg123/synth_sse_accurate.S +294 -0
- data/mpg123/src/libmpg123/synth_sse_float.S +241 -0
- data/mpg123/src/libmpg123/synth_sse_s32.S +306 -0
- data/mpg123/src/libmpg123/synth_stereo_neon.S +175 -0
- data/mpg123/src/libmpg123/synth_stereo_neon_accurate.S +262 -0
- data/mpg123/src/libmpg123/synth_stereo_neon_float.S +220 -0
- data/mpg123/src/libmpg123/synth_stereo_neon_s32.S +247 -0
- data/mpg123/src/libmpg123/synth_stereo_sse_accurate.S +508 -0
- data/mpg123/src/libmpg123/synth_stereo_sse_float.S +416 -0
- data/mpg123/src/libmpg123/synth_stereo_sse_s32.S +540 -0
- data/mpg123/src/libmpg123/synth_stereo_x86_64.S +335 -0
- data/mpg123/src/libmpg123/synth_stereo_x86_64_accurate.S +454 -0
- data/mpg123/src/libmpg123/synth_stereo_x86_64_float.S +396 -0
- data/mpg123/src/libmpg123/synth_stereo_x86_64_s32.S +473 -0
- data/mpg123/src/libmpg123/synth_x86_64.S +244 -0
- data/mpg123/src/libmpg123/synth_x86_64_accurate.S +301 -0
- data/mpg123/src/libmpg123/synth_x86_64_float.S +259 -0
- data/mpg123/src/libmpg123/synth_x86_64_s32.S +312 -0
- data/mpg123/src/libmpg123/synths.h +52 -0
- data/mpg123/src/libmpg123/tabinit.c +294 -0
- data/mpg123/src/libmpg123/tabinit_mmx.S +210 -0
- data/mpg123/src/libmpg123/testcpu.c +35 -0
- data/mpg123/src/libmpg123/true.h +14 -0
- data/mpg123/src/local.c +63 -0
- data/mpg123/src/local.h +21 -0
- data/mpg123/src/metaprint.c +373 -0
- data/mpg123/src/metaprint.h +17 -0
- data/mpg123/src/module.c +306 -0
- data/mpg123/src/module.h +48 -0
- data/mpg123/src/mpg123.c +1405 -0
- data/mpg123/src/mpg123app.h +171 -0
- data/mpg123/src/output/Makefile.am +213 -0
- data/mpg123/src/output/Makefile.in +1238 -0
- data/mpg123/src/output/aix.c +300 -0
- data/mpg123/src/output/alib.c +209 -0
- data/mpg123/src/output/alsa.c +297 -0
- data/mpg123/src/output/arts.c +117 -0
- data/mpg123/src/output/coreaudio.c +370 -0
- data/mpg123/src/output/dummy.c +78 -0
- data/mpg123/src/output/esd.c +167 -0
- data/mpg123/src/output/hp.c +184 -0
- data/mpg123/src/output/jack.c +450 -0
- data/mpg123/src/output/mint.c +197 -0
- data/mpg123/src/output/nas.c +335 -0
- data/mpg123/src/output/openal.c +197 -0
- data/mpg123/src/output/os2.c +665 -0
- data/mpg123/src/output/oss.c +319 -0
- data/mpg123/src/output/portaudio.c +255 -0
- data/mpg123/src/output/pulse.c +164 -0
- data/mpg123/src/output/sdl.c +206 -0
- data/mpg123/src/output/sgi.c +213 -0
- data/mpg123/src/output/sndio.c +161 -0
- data/mpg123/src/output/sun.c +281 -0
- data/mpg123/src/output/win32.c +229 -0
- data/mpg123/src/playlist.c +596 -0
- data/mpg123/src/playlist.h +52 -0
- data/mpg123/src/resolver.c +319 -0
- data/mpg123/src/resolver.h +25 -0
- data/mpg123/src/sfifo.c +146 -0
- data/mpg123/src/sfifo.h +95 -0
- data/mpg123/src/streamdump.c +74 -0
- data/mpg123/src/streamdump.h +20 -0
- data/mpg123/src/term.c +479 -0
- data/mpg123/src/term.h +81 -0
- data/mpg123/src/tests/noise.c +52 -0
- data/mpg123/src/tests/plain_id3.c +109 -0
- data/mpg123/src/tests/seek_accuracy.c +261 -0
- data/mpg123/src/tests/seek_whence.c +56 -0
- data/mpg123/src/tests/testtext.h +34 -0
- data/mpg123/src/tests/text.c +80 -0
- data/mpg123/src/wav.c +464 -0
- data/mpg123/src/wavhead.h +68 -0
- data/mpg123/src/win32_net.c +599 -0
- data/mpg123/src/win32_support.c +191 -0
- data/mpg123/src/win32_support.h +152 -0
- data/mpg123/src/xfermem.c +321 -0
- data/mpg123/src/xfermem.h +74 -0
- data/mpg123/windows-builds.sh +137 -0
- data/msvc/lib/OpenAL32.lib +0 -0
- data/spec/fixtures/heal.ogg +0 -0
- data/spec/fixtures/tone_up.wav +0 -0
- data/spec/seal/buffer_spec.rb +37 -0
- data/spec/seal/core_spec.rb +29 -0
- data/spec/seal/effect_slot_spec.rb +38 -0
- data/spec/seal/listener_spec.rb +33 -0
- data/spec/seal/reverb_spec.rb +51 -0
- data/spec/seal/source_spec.rb +370 -0
- data/spec/seal/stream_spec.rb +38 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/support/attribute_examples.rb +75 -0
- data/spec/support/audio_object_with_format.rb +27 -0
- data/spec/support/movable_object.rb +22 -0
- data/src/libogg/bitwise.c +857 -0
- data/src/libogg/framing.c +2093 -0
- data/src/libvorbis/backends.h +144 -0
- data/src/libvorbis/bitrate.c +253 -0
- data/src/libvorbis/bitrate.h +59 -0
- data/src/libvorbis/block.c +1046 -0
- data/src/libvorbis/codebook.c +484 -0
- data/src/libvorbis/codebook.h +119 -0
- data/src/libvorbis/codec_internal.h +167 -0
- data/src/libvorbis/envelope.c +375 -0
- data/src/libvorbis/envelope.h +80 -0
- data/src/libvorbis/floor0.c +221 -0
- data/src/libvorbis/floor1.c +1100 -0
- data/src/libvorbis/highlevel.h +58 -0
- data/src/libvorbis/info.c +668 -0
- data/src/libvorbis/lookup.c +94 -0
- data/src/libvorbis/lookup.h +32 -0
- data/src/libvorbis/lookup_data.h +192 -0
- data/src/libvorbis/lpc.c +160 -0
- data/src/libvorbis/lpc.h +29 -0
- data/src/libvorbis/lsp.c +456 -0
- data/src/libvorbis/lsp.h +28 -0
- data/src/libvorbis/mapping0.c +816 -0
- data/src/libvorbis/masking.h +785 -0
- data/src/libvorbis/mdct.c +563 -0
- data/src/libvorbis/mdct.h +71 -0
- data/src/libvorbis/misc.h +57 -0
- data/src/libvorbis/os.h +186 -0
- data/src/libvorbis/psy.c +1206 -0
- data/src/libvorbis/psy.h +154 -0
- data/src/libvorbis/registry.c +45 -0
- data/src/libvorbis/registry.h +32 -0
- data/src/libvorbis/res0.c +889 -0
- data/src/libvorbis/scales.h +90 -0
- data/src/libvorbis/sharedbook.c +579 -0
- data/src/libvorbis/smallft.c +1255 -0
- data/src/libvorbis/smallft.h +34 -0
- data/src/libvorbis/synthesis.c +184 -0
- data/src/libvorbis/vorbisfile.c +2337 -0
- data/src/libvorbis/window.c +2135 -0
- data/src/libvorbis/window.h +26 -0
- data/src/rubyext.c +2329 -0
- data/src/seal/buf.c +124 -0
- data/src/seal/core.c +283 -0
- data/src/seal/efs.c +74 -0
- data/src/seal/err.c +118 -0
- data/src/seal/fmt.c +86 -0
- data/src/seal/listener.c +111 -0
- data/src/seal/mpg.c +174 -0
- data/src/seal/mpg.h +24 -0
- data/src/seal/ov.c +180 -0
- data/src/seal/ov.h +22 -0
- data/src/seal/raw.c +59 -0
- data/src/seal/reader.c +102 -0
- data/src/seal/reader.h +59 -0
- data/src/seal/rvb.c +368 -0
- data/src/seal/src.c +654 -0
- data/src/seal/stream.c +109 -0
- data/src/seal/threading.c +66 -0
- data/src/seal/threading.h +20 -0
- data/src/seal/wav.c +297 -0
- data/src/seal/wav.h +23 -0
- data/src/win32api.rb +29 -0
- metadata +563 -0
@@ -0,0 +1,1607 @@
|
|
1
|
+
/*
|
2
|
+
libmpg123: MPEG Audio Decoder library
|
3
|
+
|
4
|
+
copyright 1995-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
|
+
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include "mpg123lib_intern.h"
|
10
|
+
#include "icy2utf8.h"
|
11
|
+
#include "debug.h"
|
12
|
+
|
13
|
+
#include "gapless.h"
|
14
|
+
|
15
|
+
#define SEEKFRAME(mh) ((mh)->ignoreframe < 0 ? 0 : (mh)->ignoreframe)
|
16
|
+
|
17
|
+
static int initialized = 0;
|
18
|
+
|
19
|
+
int attribute_align_arg mpg123_init(void)
|
20
|
+
{
|
21
|
+
if((sizeof(short) != 2) || (sizeof(long) < 4)) return MPG123_BAD_TYPES;
|
22
|
+
|
23
|
+
if(initialized) return MPG123_OK; /* no need to initialize twice */
|
24
|
+
|
25
|
+
#ifndef NO_LAYER12
|
26
|
+
init_layer12(); /* inits also shared tables with layer1 */
|
27
|
+
#endif
|
28
|
+
#ifndef NO_LAYER3
|
29
|
+
init_layer3();
|
30
|
+
#endif
|
31
|
+
prepare_decode_tables();
|
32
|
+
check_decoders();
|
33
|
+
initialized = 1;
|
34
|
+
return MPG123_OK;
|
35
|
+
}
|
36
|
+
|
37
|
+
void attribute_align_arg mpg123_exit(void)
|
38
|
+
{
|
39
|
+
/* nothing yet, but something later perhaps */
|
40
|
+
}
|
41
|
+
|
42
|
+
/* create a new handle with specified decoder, decoder can be "", "auto" or NULL for auto-detection */
|
43
|
+
mpg123_handle attribute_align_arg *mpg123_new(const char* decoder, int *error)
|
44
|
+
{
|
45
|
+
return mpg123_parnew(NULL, decoder, error);
|
46
|
+
}
|
47
|
+
|
48
|
+
/* ...the full routine with optional initial parameters to override defaults. */
|
49
|
+
mpg123_handle attribute_align_arg *mpg123_parnew(mpg123_pars *mp, const char* decoder, int *error)
|
50
|
+
{
|
51
|
+
mpg123_handle *fr = NULL;
|
52
|
+
int err = MPG123_OK;
|
53
|
+
|
54
|
+
if(initialized) fr = (mpg123_handle*) malloc(sizeof(mpg123_handle));
|
55
|
+
else err = MPG123_NOT_INITIALIZED;
|
56
|
+
if(fr != NULL)
|
57
|
+
{
|
58
|
+
frame_init_par(fr, mp);
|
59
|
+
debug("cpu opt setting");
|
60
|
+
if(frame_cpu_opt(fr, decoder) != 1)
|
61
|
+
{
|
62
|
+
err = MPG123_BAD_DECODER;
|
63
|
+
frame_exit(fr);
|
64
|
+
free(fr);
|
65
|
+
fr = NULL;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
if(fr != NULL)
|
69
|
+
{
|
70
|
+
fr->decoder_change = 1;
|
71
|
+
}
|
72
|
+
else if(err == MPG123_OK) err = MPG123_OUT_OF_MEM;
|
73
|
+
|
74
|
+
if(error != NULL) *error = err;
|
75
|
+
return fr;
|
76
|
+
}
|
77
|
+
|
78
|
+
int attribute_align_arg mpg123_decoder(mpg123_handle *mh, const char* decoder)
|
79
|
+
{
|
80
|
+
enum optdec dt = dectype(decoder);
|
81
|
+
|
82
|
+
if(mh == NULL) return MPG123_ERR;
|
83
|
+
|
84
|
+
if(dt == nodec)
|
85
|
+
{
|
86
|
+
mh->err = MPG123_BAD_DECODER;
|
87
|
+
return MPG123_ERR;
|
88
|
+
}
|
89
|
+
if(dt == mh->cpu_opts.type) return MPG123_OK;
|
90
|
+
|
91
|
+
/* Now really change. */
|
92
|
+
/* frame_exit(mh);
|
93
|
+
frame_init(mh); */
|
94
|
+
debug("cpu opt setting");
|
95
|
+
if(frame_cpu_opt(mh, decoder) != 1)
|
96
|
+
{
|
97
|
+
mh->err = MPG123_BAD_DECODER;
|
98
|
+
frame_exit(mh);
|
99
|
+
return MPG123_ERR;
|
100
|
+
}
|
101
|
+
/* New buffers for decoder are created in frame_buffers() */
|
102
|
+
if((frame_outbuffer(mh) != 0))
|
103
|
+
{
|
104
|
+
mh->err = MPG123_NO_BUFFERS;
|
105
|
+
frame_exit(mh);
|
106
|
+
return MPG123_ERR;
|
107
|
+
}
|
108
|
+
/* Do _not_ call decode_update here! That is only allowed after a first MPEG frame has been met. */
|
109
|
+
mh->decoder_change = 1;
|
110
|
+
return MPG123_OK;
|
111
|
+
}
|
112
|
+
|
113
|
+
int attribute_align_arg mpg123_param(mpg123_handle *mh, enum mpg123_parms key, long val, double fval)
|
114
|
+
{
|
115
|
+
int r;
|
116
|
+
|
117
|
+
if(mh == NULL) return MPG123_ERR;
|
118
|
+
r = mpg123_par(&mh->p, key, val, fval);
|
119
|
+
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
|
120
|
+
else
|
121
|
+
{ /* Special treatment for some settings. */
|
122
|
+
#ifdef FRAME_INDEX
|
123
|
+
if(key == MPG123_INDEX_SIZE)
|
124
|
+
{ /* Apply frame index size and grow property on the fly. */
|
125
|
+
r = frame_index_setup(mh);
|
126
|
+
if(r != MPG123_OK) mh->err = MPG123_INDEX_FAIL;
|
127
|
+
}
|
128
|
+
#endif
|
129
|
+
#ifndef NO_FEEDER
|
130
|
+
/* Feeder pool size is applied right away, reader will react to that. */
|
131
|
+
if(key == MPG123_FEEDPOOL || key == MPG123_FEEDBUFFER)
|
132
|
+
bc_poolsize(&mh->rdat.buffer, mh->p.feedpool, mh->p.feedbuffer);
|
133
|
+
#endif
|
134
|
+
}
|
135
|
+
return r;
|
136
|
+
}
|
137
|
+
|
138
|
+
int attribute_align_arg mpg123_par(mpg123_pars *mp, enum mpg123_parms key, long val, double fval)
|
139
|
+
{
|
140
|
+
int ret = MPG123_OK;
|
141
|
+
|
142
|
+
if(mp == NULL) return MPG123_BAD_PARS;
|
143
|
+
switch(key)
|
144
|
+
{
|
145
|
+
case MPG123_VERBOSE:
|
146
|
+
mp->verbose = val;
|
147
|
+
break;
|
148
|
+
case MPG123_FLAGS:
|
149
|
+
#ifndef GAPLESS
|
150
|
+
if(val & MPG123_GAPLESS) ret = MPG123_NO_GAPLESS;
|
151
|
+
#endif
|
152
|
+
if(ret == MPG123_OK) mp->flags = val;
|
153
|
+
debug1("set flags to 0x%lx", (unsigned long) mp->flags);
|
154
|
+
break;
|
155
|
+
case MPG123_ADD_FLAGS:
|
156
|
+
#ifndef GAPLESS
|
157
|
+
/* Enabling of gapless mode doesn't work when it's not there, but disabling (below) is no problem. */
|
158
|
+
if(val & MPG123_GAPLESS) ret = MPG123_NO_GAPLESS;
|
159
|
+
else
|
160
|
+
#endif
|
161
|
+
mp->flags |= val;
|
162
|
+
debug1("set flags to 0x%lx", (unsigned long) mp->flags);
|
163
|
+
break;
|
164
|
+
case MPG123_REMOVE_FLAGS:
|
165
|
+
mp->flags &= ~val;
|
166
|
+
debug1("set flags to 0x%lx", (unsigned long) mp->flags);
|
167
|
+
break;
|
168
|
+
case MPG123_FORCE_RATE: /* should this trigger something? */
|
169
|
+
#ifdef NO_NTOM
|
170
|
+
if(val > 0)
|
171
|
+
ret = MPG123_BAD_RATE;
|
172
|
+
#else
|
173
|
+
if(val > 96000) ret = MPG123_BAD_RATE;
|
174
|
+
else mp->force_rate = val < 0 ? 0 : val; /* >0 means enable, 0 disable */
|
175
|
+
#endif
|
176
|
+
break;
|
177
|
+
case MPG123_DOWN_SAMPLE:
|
178
|
+
#ifdef NO_DOWNSAMPLE
|
179
|
+
if(val != 0) ret = MPG123_BAD_RATE;
|
180
|
+
#else
|
181
|
+
if(val < 0 || val > 2) ret = MPG123_BAD_RATE;
|
182
|
+
else mp->down_sample = (int)val;
|
183
|
+
#endif
|
184
|
+
break;
|
185
|
+
case MPG123_RVA:
|
186
|
+
if(val < 0 || val > MPG123_RVA_MAX) ret = MPG123_BAD_RVA;
|
187
|
+
else mp->rva = (int)val;
|
188
|
+
break;
|
189
|
+
case MPG123_DOWNSPEED:
|
190
|
+
mp->halfspeed = val < 0 ? 0 : val;
|
191
|
+
break;
|
192
|
+
case MPG123_UPSPEED:
|
193
|
+
mp->doublespeed = val < 0 ? 0 : val;
|
194
|
+
break;
|
195
|
+
case MPG123_ICY_INTERVAL:
|
196
|
+
#ifndef NO_ICY
|
197
|
+
mp->icy_interval = val > 0 ? val : 0;
|
198
|
+
#else
|
199
|
+
if(val > 0) ret = MPG123_BAD_PARAM;
|
200
|
+
#endif
|
201
|
+
break;
|
202
|
+
case MPG123_OUTSCALE:
|
203
|
+
/* Choose the value that is non-zero, if any.
|
204
|
+
Downscaling integers to 1.0 . */
|
205
|
+
mp->outscale = val == 0 ? fval : (double)val/SHORT_SCALE;
|
206
|
+
break;
|
207
|
+
case MPG123_TIMEOUT:
|
208
|
+
#ifdef TIMEOUT_READ
|
209
|
+
mp->timeout = val >= 0 ? val : 0;
|
210
|
+
#else
|
211
|
+
if(val > 0) ret = MPG123_NO_TIMEOUT;
|
212
|
+
#endif
|
213
|
+
break;
|
214
|
+
case MPG123_RESYNC_LIMIT:
|
215
|
+
mp->resync_limit = val;
|
216
|
+
break;
|
217
|
+
case MPG123_INDEX_SIZE:
|
218
|
+
#ifdef FRAME_INDEX
|
219
|
+
mp->index_size = val;
|
220
|
+
#else
|
221
|
+
ret = MPG123_NO_INDEX;
|
222
|
+
#endif
|
223
|
+
break;
|
224
|
+
case MPG123_PREFRAMES:
|
225
|
+
if(val >= 0) mp->preframes = val;
|
226
|
+
else ret = MPG123_BAD_VALUE;
|
227
|
+
break;
|
228
|
+
case MPG123_FEEDPOOL:
|
229
|
+
#ifndef NO_FEEDER
|
230
|
+
if(val >= 0) mp->feedpool = val;
|
231
|
+
else ret = MPG123_BAD_VALUE;
|
232
|
+
#else
|
233
|
+
ret = MPG123_MISSING_FEATURE;
|
234
|
+
#endif
|
235
|
+
break;
|
236
|
+
case MPG123_FEEDBUFFER:
|
237
|
+
#ifndef NO_FEEDER
|
238
|
+
if(val > 0) mp->feedbuffer = val;
|
239
|
+
else ret = MPG123_BAD_VALUE;
|
240
|
+
#else
|
241
|
+
ret = MPG123_MISSING_FEATURE;
|
242
|
+
#endif
|
243
|
+
break;
|
244
|
+
default:
|
245
|
+
ret = MPG123_BAD_PARAM;
|
246
|
+
}
|
247
|
+
return ret;
|
248
|
+
}
|
249
|
+
|
250
|
+
int attribute_align_arg mpg123_getparam(mpg123_handle *mh, enum mpg123_parms key, long *val, double *fval)
|
251
|
+
{
|
252
|
+
int r;
|
253
|
+
|
254
|
+
if(mh == NULL) return MPG123_ERR;
|
255
|
+
r = mpg123_getpar(&mh->p, key, val, fval);
|
256
|
+
if(r != MPG123_OK){ mh->err = r; r = MPG123_ERR; }
|
257
|
+
return r;
|
258
|
+
}
|
259
|
+
|
260
|
+
int attribute_align_arg mpg123_getpar(mpg123_pars *mp, enum mpg123_parms key, long *val, double *fval)
|
261
|
+
{
|
262
|
+
int ret = 0;
|
263
|
+
|
264
|
+
if(mp == NULL) return MPG123_BAD_PARS;
|
265
|
+
switch(key)
|
266
|
+
{
|
267
|
+
case MPG123_VERBOSE:
|
268
|
+
if(val) *val = mp->verbose;
|
269
|
+
break;
|
270
|
+
case MPG123_FLAGS:
|
271
|
+
case MPG123_ADD_FLAGS:
|
272
|
+
if(val) *val = mp->flags;
|
273
|
+
break;
|
274
|
+
case MPG123_FORCE_RATE:
|
275
|
+
if(val)
|
276
|
+
#ifdef NO_NTOM
|
277
|
+
*val = 0;
|
278
|
+
#else
|
279
|
+
*val = mp->force_rate;
|
280
|
+
#endif
|
281
|
+
break;
|
282
|
+
case MPG123_DOWN_SAMPLE:
|
283
|
+
if(val) *val = mp->down_sample;
|
284
|
+
break;
|
285
|
+
case MPG123_RVA:
|
286
|
+
if(val) *val = mp->rva;
|
287
|
+
break;
|
288
|
+
case MPG123_DOWNSPEED:
|
289
|
+
if(val) *val = mp->halfspeed;
|
290
|
+
break;
|
291
|
+
case MPG123_UPSPEED:
|
292
|
+
if(val) *val = mp->doublespeed;
|
293
|
+
break;
|
294
|
+
case MPG123_ICY_INTERVAL:
|
295
|
+
#ifndef NO_ICY
|
296
|
+
if(val) *val = (long)mp->icy_interval;
|
297
|
+
#else
|
298
|
+
if(val) *val = 0;
|
299
|
+
#endif
|
300
|
+
break;
|
301
|
+
case MPG123_OUTSCALE:
|
302
|
+
if(fval) *fval = mp->outscale;
|
303
|
+
if(val) *val = (long)(mp->outscale*SHORT_SCALE);
|
304
|
+
break;
|
305
|
+
case MPG123_RESYNC_LIMIT:
|
306
|
+
if(val) *val = mp->resync_limit;
|
307
|
+
break;
|
308
|
+
case MPG123_INDEX_SIZE:
|
309
|
+
if(val)
|
310
|
+
#ifdef FRAME_INDEX
|
311
|
+
*val = mp->index_size;
|
312
|
+
#else
|
313
|
+
*val = 0; /* graceful fallback: no index is index of zero size */
|
314
|
+
#endif
|
315
|
+
break;
|
316
|
+
case MPG123_PREFRAMES:
|
317
|
+
*val = mp->preframes;
|
318
|
+
break;
|
319
|
+
case MPG123_FEEDPOOL:
|
320
|
+
#ifndef NO_FEEDER
|
321
|
+
*val = mp->feedpool;
|
322
|
+
#else
|
323
|
+
ret = MPG123_MISSING_FEATURE;
|
324
|
+
#endif
|
325
|
+
break;
|
326
|
+
case MPG123_FEEDBUFFER:
|
327
|
+
#ifndef NO_FEEDER
|
328
|
+
*val = mp->feedbuffer;
|
329
|
+
#else
|
330
|
+
ret = MPG123_MISSING_FEATURE;
|
331
|
+
#endif
|
332
|
+
break;
|
333
|
+
default:
|
334
|
+
ret = MPG123_BAD_PARAM;
|
335
|
+
}
|
336
|
+
return ret;
|
337
|
+
}
|
338
|
+
|
339
|
+
int attribute_align_arg mpg123_getstate(mpg123_handle *mh, enum mpg123_state key, long *val, double *fval)
|
340
|
+
{
|
341
|
+
int ret = MPG123_OK;
|
342
|
+
long theval = 0;
|
343
|
+
double thefval = 0.;
|
344
|
+
|
345
|
+
if(mh == NULL) return MPG123_ERR;
|
346
|
+
|
347
|
+
switch(key)
|
348
|
+
{
|
349
|
+
case MPG123_ACCURATE:
|
350
|
+
theval = mh->state_flags & FRAME_ACCURATE;
|
351
|
+
break;
|
352
|
+
case MPG123_FRANKENSTEIN:
|
353
|
+
theval = mh->state_flags & FRAME_FRANKENSTEIN;
|
354
|
+
break;
|
355
|
+
case MPG123_BUFFERFILL:
|
356
|
+
#ifndef NO_FEEDER
|
357
|
+
{
|
358
|
+
size_t sval = bc_fill(&mh->rdat.buffer);
|
359
|
+
theval = (long)sval;
|
360
|
+
if((size_t)theval != sval)
|
361
|
+
{
|
362
|
+
mh->err = MPG123_INT_OVERFLOW;
|
363
|
+
ret = MPG123_ERR;
|
364
|
+
}
|
365
|
+
}
|
366
|
+
#else
|
367
|
+
mh->err = MPG123_MISSING_FEATURE;
|
368
|
+
ret = MPG123_ERR;
|
369
|
+
#endif
|
370
|
+
break;
|
371
|
+
default:
|
372
|
+
mh->err = MPG123_BAD_KEY;
|
373
|
+
ret = MPG123_ERR;
|
374
|
+
}
|
375
|
+
|
376
|
+
if(val != NULL) *val = theval;
|
377
|
+
if(fval != NULL) *fval = thefval;
|
378
|
+
|
379
|
+
return ret;
|
380
|
+
}
|
381
|
+
|
382
|
+
int attribute_align_arg mpg123_eq(mpg123_handle *mh, enum mpg123_channels channel, int band, double val)
|
383
|
+
{
|
384
|
+
if(mh == NULL) return MPG123_ERR;
|
385
|
+
if(band < 0 || band > 31){ mh->err = MPG123_BAD_BAND; return MPG123_ERR; }
|
386
|
+
switch(channel)
|
387
|
+
{
|
388
|
+
case MPG123_LEFT|MPG123_RIGHT:
|
389
|
+
mh->equalizer[0][band] = mh->equalizer[1][band] = DOUBLE_TO_REAL(val);
|
390
|
+
break;
|
391
|
+
case MPG123_LEFT: mh->equalizer[0][band] = DOUBLE_TO_REAL(val); break;
|
392
|
+
case MPG123_RIGHT: mh->equalizer[1][band] = DOUBLE_TO_REAL(val); break;
|
393
|
+
default:
|
394
|
+
mh->err=MPG123_BAD_CHANNEL;
|
395
|
+
return MPG123_ERR;
|
396
|
+
}
|
397
|
+
mh->have_eq_settings = TRUE;
|
398
|
+
return MPG123_OK;
|
399
|
+
}
|
400
|
+
|
401
|
+
double attribute_align_arg mpg123_geteq(mpg123_handle *mh, enum mpg123_channels channel, int band)
|
402
|
+
{
|
403
|
+
double ret = 0.;
|
404
|
+
|
405
|
+
if(mh == NULL) return MPG123_ERR;
|
406
|
+
|
407
|
+
/* Handle this gracefully. When there is no band, it has no volume. */
|
408
|
+
if(band > -1 && band < 32)
|
409
|
+
switch(channel)
|
410
|
+
{
|
411
|
+
case MPG123_LEFT|MPG123_RIGHT:
|
412
|
+
ret = 0.5*(REAL_TO_DOUBLE(mh->equalizer[0][band])+REAL_TO_DOUBLE(mh->equalizer[1][band]));
|
413
|
+
break;
|
414
|
+
case MPG123_LEFT: ret = REAL_TO_DOUBLE(mh->equalizer[0][band]); break;
|
415
|
+
case MPG123_RIGHT: ret = REAL_TO_DOUBLE(mh->equalizer[1][band]); break;
|
416
|
+
/* Default case is already handled: ret = 0 */
|
417
|
+
}
|
418
|
+
|
419
|
+
return ret;
|
420
|
+
}
|
421
|
+
|
422
|
+
|
423
|
+
/* plain file access, no http! */
|
424
|
+
int attribute_align_arg mpg123_open(mpg123_handle *mh, const char *path)
|
425
|
+
{
|
426
|
+
if(mh == NULL) return MPG123_ERR;
|
427
|
+
|
428
|
+
mpg123_close(mh);
|
429
|
+
return open_stream(mh, path, -1);
|
430
|
+
}
|
431
|
+
|
432
|
+
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
|
433
|
+
{
|
434
|
+
if(mh == NULL) return MPG123_ERR;
|
435
|
+
|
436
|
+
mpg123_close(mh);
|
437
|
+
return open_stream(mh, NULL, fd);
|
438
|
+
}
|
439
|
+
|
440
|
+
int attribute_align_arg mpg123_open_handle(mpg123_handle *mh, void *iohandle)
|
441
|
+
{
|
442
|
+
if(mh == NULL) return MPG123_ERR;
|
443
|
+
|
444
|
+
mpg123_close(mh);
|
445
|
+
if(mh->rdat.r_read_handle == NULL)
|
446
|
+
{
|
447
|
+
mh->err = MPG123_BAD_CUSTOM_IO;
|
448
|
+
return MPG123_ERR;
|
449
|
+
}
|
450
|
+
return open_stream_handle(mh, iohandle);
|
451
|
+
}
|
452
|
+
|
453
|
+
int attribute_align_arg mpg123_open_feed(mpg123_handle *mh)
|
454
|
+
{
|
455
|
+
if(mh == NULL) return MPG123_ERR;
|
456
|
+
|
457
|
+
mpg123_close(mh);
|
458
|
+
return open_feed(mh);
|
459
|
+
}
|
460
|
+
|
461
|
+
int attribute_align_arg mpg123_replace_reader( mpg123_handle *mh,
|
462
|
+
ssize_t (*r_read) (int, void *, size_t),
|
463
|
+
off_t (*r_lseek)(int, off_t, int) )
|
464
|
+
{
|
465
|
+
if(mh == NULL) return MPG123_ERR;
|
466
|
+
|
467
|
+
mpg123_close(mh);
|
468
|
+
mh->rdat.r_read = r_read;
|
469
|
+
mh->rdat.r_lseek = r_lseek;
|
470
|
+
return MPG123_OK;
|
471
|
+
}
|
472
|
+
|
473
|
+
int attribute_align_arg mpg123_replace_reader_handle( mpg123_handle *mh,
|
474
|
+
ssize_t (*r_read) (void*, void *, size_t),
|
475
|
+
off_t (*r_lseek)(void*, off_t, int),
|
476
|
+
void (*cleanup)(void*) )
|
477
|
+
{
|
478
|
+
if(mh == NULL) return MPG123_ERR;
|
479
|
+
|
480
|
+
mpg123_close(mh);
|
481
|
+
mh->rdat.r_read_handle = r_read;
|
482
|
+
mh->rdat.r_lseek_handle = r_lseek;
|
483
|
+
mh->rdat.cleanup_handle = cleanup;
|
484
|
+
return MPG123_OK;
|
485
|
+
}
|
486
|
+
|
487
|
+
/* Update decoding engine for
|
488
|
+
a) a new choice of decoder
|
489
|
+
b) a changed native format of the MPEG stream
|
490
|
+
... calls are only valid after parsing some MPEG frame! */
|
491
|
+
int decode_update(mpg123_handle *mh)
|
492
|
+
{
|
493
|
+
long native_rate;
|
494
|
+
int b;
|
495
|
+
|
496
|
+
if(mh->num < 0)
|
497
|
+
{
|
498
|
+
if(!(mh->p.flags & MPG123_QUIET)) error("decode_update() has been called before reading the first MPEG frame! Internal programming error.");
|
499
|
+
|
500
|
+
mh->err = MPG123_BAD_DECODER_SETUP;
|
501
|
+
return MPG123_ERR;
|
502
|
+
}
|
503
|
+
|
504
|
+
native_rate = frame_freq(mh);
|
505
|
+
|
506
|
+
b = frame_output_format(mh); /* Select the new output format based on given constraints. */
|
507
|
+
if(b < 0) return MPG123_ERR;
|
508
|
+
|
509
|
+
if(b == 1) mh->new_format = 1; /* Store for later... */
|
510
|
+
|
511
|
+
debug3("updating decoder structure with native rate %li and af.rate %li (new format: %i)", native_rate, mh->af.rate, mh->new_format);
|
512
|
+
if(mh->af.rate == native_rate) mh->down_sample = 0;
|
513
|
+
else if(mh->af.rate == native_rate>>1) mh->down_sample = 1;
|
514
|
+
else if(mh->af.rate == native_rate>>2) mh->down_sample = 2;
|
515
|
+
else mh->down_sample = 3; /* flexible (fixed) rate */
|
516
|
+
switch(mh->down_sample)
|
517
|
+
{
|
518
|
+
case 0:
|
519
|
+
case 1:
|
520
|
+
case 2:
|
521
|
+
mh->down_sample_sblimit = SBLIMIT>>(mh->down_sample);
|
522
|
+
/* With downsampling I get less samples per frame */
|
523
|
+
mh->outblock = samples_to_storage(mh, (spf(mh)>>mh->down_sample));
|
524
|
+
break;
|
525
|
+
#ifndef NO_NTOM
|
526
|
+
case 3:
|
527
|
+
{
|
528
|
+
if(synth_ntom_set_step(mh) != 0) return -1;
|
529
|
+
if(frame_freq(mh) > mh->af.rate)
|
530
|
+
{
|
531
|
+
mh->down_sample_sblimit = SBLIMIT * mh->af.rate;
|
532
|
+
mh->down_sample_sblimit /= frame_freq(mh);
|
533
|
+
}
|
534
|
+
else mh->down_sample_sblimit = SBLIMIT;
|
535
|
+
mh->outblock = samples_to_storage(mh,
|
536
|
+
( ( NTOM_MUL-1+spf(mh)
|
537
|
+
* (((size_t)NTOM_MUL*mh->af.rate)/frame_freq(mh))
|
538
|
+
)/NTOM_MUL ));
|
539
|
+
}
|
540
|
+
break;
|
541
|
+
#endif
|
542
|
+
}
|
543
|
+
|
544
|
+
if(!(mh->p.flags & MPG123_FORCE_MONO))
|
545
|
+
{
|
546
|
+
if(mh->af.channels == 1) mh->single = SINGLE_MIX;
|
547
|
+
else mh->single = SINGLE_STEREO;
|
548
|
+
}
|
549
|
+
else mh->single = (mh->p.flags & MPG123_FORCE_MONO)-1;
|
550
|
+
if(set_synth_functions(mh) != 0) return -1;;
|
551
|
+
|
552
|
+
/* The needed size of output buffer may have changed. */
|
553
|
+
if(frame_outbuffer(mh) != MPG123_OK) return -1;
|
554
|
+
|
555
|
+
do_rva(mh);
|
556
|
+
debug3("done updating decoder structure with native rate %li and af.rate %li and down_sample %i", frame_freq(mh), mh->af.rate, mh->down_sample);
|
557
|
+
|
558
|
+
return 0;
|
559
|
+
}
|
560
|
+
|
561
|
+
size_t attribute_align_arg mpg123_safe_buffer(void)
|
562
|
+
{
|
563
|
+
/* real is the largest possible output (it's 32bit float, 32bit int or 64bit double). */
|
564
|
+
return sizeof(real)*2*1152*NTOM_MAX;
|
565
|
+
}
|
566
|
+
|
567
|
+
size_t attribute_align_arg mpg123_outblock(mpg123_handle *mh)
|
568
|
+
{
|
569
|
+
/* Try to be helpful and never return zero output block size. */
|
570
|
+
if(mh != NULL && mh->outblock > 0) return mh->outblock;
|
571
|
+
else return mpg123_safe_buffer();
|
572
|
+
}
|
573
|
+
|
574
|
+
/* Read in the next frame we actually want for decoding.
|
575
|
+
This includes skipping/ignoring frames, in additon to skipping junk in the parser. */
|
576
|
+
static int get_next_frame(mpg123_handle *mh)
|
577
|
+
{
|
578
|
+
/* We have some decoder ready, if the desired decoder has changed,
|
579
|
+
it is OK to use the old one for ignoring frames and activating
|
580
|
+
the new one for real (decode_update()) after getting the frame. */
|
581
|
+
int change = mh->decoder_change;
|
582
|
+
do
|
583
|
+
{
|
584
|
+
int b;
|
585
|
+
/* Decode & discard some frame(s) before beginning. */
|
586
|
+
if(mh->to_ignore && mh->num < mh->firstframe && mh->num >= mh->ignoreframe)
|
587
|
+
{
|
588
|
+
debug1("ignoring frame %li", (long)mh->num);
|
589
|
+
/* Decoder structure must be current! decode_update has been called before... */
|
590
|
+
(mh->do_layer)(mh); mh->buffer.fill = 0;
|
591
|
+
#ifndef NO_NTOM
|
592
|
+
/* The ignored decoding may have failed. Make sure ntom stays consistent. */
|
593
|
+
if(mh->down_sample == 3) ntom_set_ntom(mh, mh->num+1);
|
594
|
+
#endif
|
595
|
+
mh->to_ignore = mh->to_decode = FALSE;
|
596
|
+
}
|
597
|
+
/* Read new frame data; possibly breaking out here for MPG123_NEED_MORE. */
|
598
|
+
debug("read frame");
|
599
|
+
mh->to_decode = FALSE;
|
600
|
+
b = read_frame(mh); /* That sets to_decode only if a full frame was read. */
|
601
|
+
debug4("read of frame %li returned %i (to_decode=%i) at sample %li", (long)mh->num, b, mh->to_decode, (long)mpg123_tell(mh));
|
602
|
+
if(b == MPG123_NEED_MORE) return MPG123_NEED_MORE; /* need another call with data */
|
603
|
+
else if(b <= 0)
|
604
|
+
{
|
605
|
+
/* More sophisticated error control? */
|
606
|
+
if(b==0 || (mh->rdat.filelen >= 0 && mh->rdat.filepos == mh->rdat.filelen))
|
607
|
+
{ /* We simply reached the end. */
|
608
|
+
mh->track_frames = mh->num + 1;
|
609
|
+
debug("What about updating/checking gapless sample count here?");
|
610
|
+
return MPG123_DONE;
|
611
|
+
}
|
612
|
+
else return MPG123_ERR; /* Some real error. */
|
613
|
+
}
|
614
|
+
/* Now, there should be new data to decode ... and also possibly new stream properties */
|
615
|
+
if(mh->header_change > 1)
|
616
|
+
{
|
617
|
+
debug("big header change");
|
618
|
+
change = 1;
|
619
|
+
}
|
620
|
+
/* Now some accounting: Look at the numbers and decide if we want this frame. */
|
621
|
+
++mh->playnum;
|
622
|
+
/* Plain skipping without decoding, only when frame is not ignored on next cycle. */
|
623
|
+
if(mh->num < mh->firstframe || (mh->p.doublespeed && (mh->playnum % mh->p.doublespeed)))
|
624
|
+
{
|
625
|
+
if(!(mh->to_ignore && mh->num < mh->firstframe && mh->num >= mh->ignoreframe))
|
626
|
+
{
|
627
|
+
frame_skip(mh);
|
628
|
+
/* Should one fix NtoM here or not?
|
629
|
+
It is not work the trouble for doublespeed, but what with leading frames? */
|
630
|
+
}
|
631
|
+
}
|
632
|
+
/* Or, we are finally done and have a new frame. */
|
633
|
+
else break;
|
634
|
+
} while(1);
|
635
|
+
|
636
|
+
/* If we reach this point, we got a new frame ready to be decoded.
|
637
|
+
All other situations resulted in returns from the loop. */
|
638
|
+
if(change)
|
639
|
+
{
|
640
|
+
if(decode_update(mh) < 0) /* dito... */
|
641
|
+
return MPG123_ERR;
|
642
|
+
|
643
|
+
debug1("new format: %i", mh->new_format);
|
644
|
+
|
645
|
+
mh->decoder_change = 0;
|
646
|
+
if(mh->fresh)
|
647
|
+
{
|
648
|
+
#ifdef GAPLESS
|
649
|
+
int b=0;
|
650
|
+
/* Prepare offsets for gapless decoding. */
|
651
|
+
debug1("preparing gapless stuff with native rate %li", frame_freq(mh));
|
652
|
+
frame_gapless_realinit(mh);
|
653
|
+
frame_set_frameseek(mh, mh->num);
|
654
|
+
#endif
|
655
|
+
mh->fresh = 0;
|
656
|
+
#ifdef GAPLESS
|
657
|
+
/* Could this possibly happen? With a real big gapless offset... */
|
658
|
+
if(mh->num < mh->firstframe) b = get_next_frame(mh);
|
659
|
+
if(b < 0) return b; /* Could be error, need for more, new format... */
|
660
|
+
#endif
|
661
|
+
}
|
662
|
+
}
|
663
|
+
return MPG123_OK;
|
664
|
+
}
|
665
|
+
|
666
|
+
/* Assumption: A buffer full of zero samples can be constructed by repetition of this byte.
|
667
|
+
Oh, and it handles some format conversion.
|
668
|
+
Only to be used by decode_the_frame() ... */
|
669
|
+
static int zero_byte(mpg123_handle *fr)
|
670
|
+
{
|
671
|
+
#ifndef NO_8BIT
|
672
|
+
return fr->af.encoding & MPG123_ENC_8 ? fr->conv16to8[0] : 0;
|
673
|
+
#else
|
674
|
+
return 0; /* All normal signed formats have the zero here (even in byte form -- that may be an assumption for your funny machine...). */
|
675
|
+
#endif
|
676
|
+
}
|
677
|
+
|
678
|
+
/*
|
679
|
+
Not part of the api. This just decodes the frame and fills missing bits with zeroes.
|
680
|
+
There can be frames that are broken and thus make do_layer() fail.
|
681
|
+
*/
|
682
|
+
static void decode_the_frame(mpg123_handle *fr)
|
683
|
+
{
|
684
|
+
size_t needed_bytes = samples_to_storage(fr, frame_expect_outsamples(fr));
|
685
|
+
fr->clip += (fr->do_layer)(fr);
|
686
|
+
/*fprintf(stderr, "frame %"OFF_P": got %"SIZE_P" / %"SIZE_P"\n", fr->num,(size_p)fr->buffer.fill, (size_p)needed_bytes);*/
|
687
|
+
/* There could be less data than promised.
|
688
|
+
Also, then debugging, we look out for coding errors that could result in _more_ data than expected. */
|
689
|
+
#ifdef DEBUG
|
690
|
+
if(fr->buffer.fill != needed_bytes)
|
691
|
+
{
|
692
|
+
#endif
|
693
|
+
if(fr->buffer.fill < needed_bytes)
|
694
|
+
{
|
695
|
+
if(VERBOSE2)
|
696
|
+
fprintf(stderr, "Note: broken frame %li, filling up with %"SIZE_P" zeroes, from %"SIZE_P"\n", (long)fr->num, (size_p)(needed_bytes-fr->buffer.fill), (size_p)fr->buffer.fill);
|
697
|
+
|
698
|
+
/*
|
699
|
+
One could do a loop with individual samples instead... but zero is zero
|
700
|
+
Actually, that is wrong: zero is mostly a series of null bytes,
|
701
|
+
but we have funny 8bit formats that have a different opinion on zero...
|
702
|
+
Unsigned 16 or 32 bit formats are handled later.
|
703
|
+
*/
|
704
|
+
memset( fr->buffer.data + fr->buffer.fill, zero_byte(fr), needed_bytes - fr->buffer.fill );
|
705
|
+
|
706
|
+
fr->buffer.fill = needed_bytes;
|
707
|
+
#ifndef NO_NTOM
|
708
|
+
/* ntom_val will be wrong when the decoding wasn't carried out completely */
|
709
|
+
ntom_set_ntom(fr, fr->num+1);
|
710
|
+
#endif
|
711
|
+
}
|
712
|
+
#ifdef DEBUG
|
713
|
+
else
|
714
|
+
{
|
715
|
+
if(NOQUIET)
|
716
|
+
error2("I got _more_ bytes than expected (%"SIZE_P" / %"SIZE_P"), that should not be possible!", (size_p)fr->buffer.fill, (size_p)needed_bytes);
|
717
|
+
}
|
718
|
+
}
|
719
|
+
#endif
|
720
|
+
postprocess_buffer(fr);
|
721
|
+
}
|
722
|
+
|
723
|
+
/*
|
724
|
+
Decode the current frame into the frame structure's buffer, accessible at the location stored in <audio>, with <bytes> bytes available.
|
725
|
+
<num> will contain the last decoded frame number. This function should be called after mpg123_framebyframe_next positioned the stream at a
|
726
|
+
valid mp3 frame. The buffer contents will get lost on the next call to mpg123_framebyframe_next or mpg123_framebyframe_decode.
|
727
|
+
returns
|
728
|
+
MPG123_OK -- successfully decoded or ignored the frame, you get your output data or in case of ignored frames 0 bytes
|
729
|
+
MPG123_DONE -- decoding finished, should not happen
|
730
|
+
MPG123_ERR -- some error occured.
|
731
|
+
MPG123_ERR_NULL -- audio or bytes are not pointing to valid storage addresses
|
732
|
+
MPG123_BAD_HANDLE -- mh has not been initialized
|
733
|
+
MPG123_NO_SPACE -- not enough space in buffer for safe decoding, should not happen
|
734
|
+
*/
|
735
|
+
int attribute_align_arg mpg123_framebyframe_decode(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes)
|
736
|
+
{
|
737
|
+
if(bytes == NULL) return MPG123_ERR_NULL;
|
738
|
+
if(audio == NULL) return MPG123_ERR_NULL;
|
739
|
+
if(mh == NULL) return MPG123_BAD_HANDLE;
|
740
|
+
if(mh->buffer.size < mh->outblock) return MPG123_NO_SPACE;
|
741
|
+
|
742
|
+
*bytes = 0;
|
743
|
+
mh->buffer.fill = 0; /* always start fresh */
|
744
|
+
if(!mh->to_decode) return MPG123_OK;
|
745
|
+
|
746
|
+
if(num != NULL) *num = mh->num;
|
747
|
+
debug("decoding");
|
748
|
+
decode_the_frame(mh);
|
749
|
+
mh->to_decode = mh->to_ignore = FALSE;
|
750
|
+
mh->buffer.p = mh->buffer.data;
|
751
|
+
FRAME_BUFFERCHECK(mh);
|
752
|
+
*audio = mh->buffer.p;
|
753
|
+
*bytes = mh->buffer.fill;
|
754
|
+
return MPG123_OK;
|
755
|
+
}
|
756
|
+
|
757
|
+
/*
|
758
|
+
Find, read and parse the next mp3 frame while skipping junk and parsing id3 tags, lame headers, etc.
|
759
|
+
Prepares everything for decoding using mpg123_framebyframe_decode.
|
760
|
+
returns
|
761
|
+
MPG123_OK -- new frame was read and parsed, call mpg123_framebyframe_decode to actually decode
|
762
|
+
MPG123_NEW_FORMAT -- new frame was read, it results in changed output format, call mpg123_framebyframe_decode to actually decode
|
763
|
+
MPG123_BAD_HANDLE -- mh has not been initialized
|
764
|
+
MPG123_NEED_MORE -- more input data is needed to advance to the next frame. supply more input data using mpg123_feed
|
765
|
+
*/
|
766
|
+
int attribute_align_arg mpg123_framebyframe_next(mpg123_handle *mh)
|
767
|
+
{
|
768
|
+
int b;
|
769
|
+
if(mh == NULL) return MPG123_BAD_HANDLE;
|
770
|
+
|
771
|
+
mh->to_decode = mh->to_ignore = FALSE;
|
772
|
+
mh->buffer.fill = 0;
|
773
|
+
|
774
|
+
b = get_next_frame(mh);
|
775
|
+
if(b < 0) return b;
|
776
|
+
debug1("got next frame, %i", mh->to_decode);
|
777
|
+
|
778
|
+
/* mpg123_framebyframe_decode will return MPG123_OK with 0 bytes decoded if mh->to_decode is 0 */
|
779
|
+
if(!mh->to_decode)
|
780
|
+
return MPG123_OK;
|
781
|
+
|
782
|
+
if(mh->new_format)
|
783
|
+
{
|
784
|
+
debug("notifiying new format");
|
785
|
+
mh->new_format = 0;
|
786
|
+
return MPG123_NEW_FORMAT;
|
787
|
+
}
|
788
|
+
|
789
|
+
return MPG123_OK;
|
790
|
+
}
|
791
|
+
|
792
|
+
/*
|
793
|
+
Put _one_ decoded frame into the frame structure's buffer, accessible at the location stored in <audio>, with <bytes> bytes available.
|
794
|
+
The buffer contents will be lost on next call to mpg123_decode_frame.
|
795
|
+
MPG123_OK -- successfully decoded the frame, you get your output data
|
796
|
+
MPg123_DONE -- This is it. End.
|
797
|
+
MPG123_ERR -- some error occured...
|
798
|
+
MPG123_NEW_FORMAT -- new frame was read, it results in changed output format -> will be decoded on next call
|
799
|
+
MPG123_NEED_MORE -- that should not happen as this function is intended for in-library stream reader but if you force it...
|
800
|
+
MPG123_NO_SPACE -- not enough space in buffer for safe decoding, also should not happen
|
801
|
+
|
802
|
+
num will be updated to the last decoded frame number (may possibly _not_ increase, p.ex. when format changed).
|
803
|
+
*/
|
804
|
+
int attribute_align_arg mpg123_decode_frame(mpg123_handle *mh, off_t *num, unsigned char **audio, size_t *bytes)
|
805
|
+
{
|
806
|
+
if(bytes != NULL) *bytes = 0;
|
807
|
+
if(mh == NULL) return MPG123_ERR;
|
808
|
+
if(mh->buffer.size < mh->outblock) return MPG123_NO_SPACE;
|
809
|
+
mh->buffer.fill = 0; /* always start fresh */
|
810
|
+
while(TRUE)
|
811
|
+
{
|
812
|
+
/* decode if possible */
|
813
|
+
if(mh->to_decode)
|
814
|
+
{
|
815
|
+
if(mh->new_format)
|
816
|
+
{
|
817
|
+
debug("notifiying new format");
|
818
|
+
mh->new_format = 0;
|
819
|
+
return MPG123_NEW_FORMAT;
|
820
|
+
}
|
821
|
+
if(num != NULL) *num = mh->num;
|
822
|
+
debug("decoding");
|
823
|
+
|
824
|
+
decode_the_frame(mh);
|
825
|
+
|
826
|
+
mh->to_decode = mh->to_ignore = FALSE;
|
827
|
+
mh->buffer.p = mh->buffer.data;
|
828
|
+
FRAME_BUFFERCHECK(mh);
|
829
|
+
if(audio != NULL) *audio = mh->buffer.p;
|
830
|
+
if(bytes != NULL) *bytes = mh->buffer.fill;
|
831
|
+
|
832
|
+
return MPG123_OK;
|
833
|
+
}
|
834
|
+
else
|
835
|
+
{
|
836
|
+
int b = get_next_frame(mh);
|
837
|
+
if(b < 0) return b;
|
838
|
+
debug1("got next frame, %i", mh->to_decode);
|
839
|
+
}
|
840
|
+
}
|
841
|
+
}
|
842
|
+
|
843
|
+
int attribute_align_arg mpg123_read(mpg123_handle *mh, unsigned char *out, size_t size, size_t *done)
|
844
|
+
{
|
845
|
+
return mpg123_decode(mh, NULL, 0, out, size, done);
|
846
|
+
}
|
847
|
+
|
848
|
+
int attribute_align_arg mpg123_feed(mpg123_handle *mh, const unsigned char *in, size_t size)
|
849
|
+
{
|
850
|
+
if(mh == NULL) return MPG123_ERR;
|
851
|
+
#ifndef NO_FEEDER
|
852
|
+
if(size > 0)
|
853
|
+
{
|
854
|
+
if(in != NULL)
|
855
|
+
{
|
856
|
+
if(feed_more(mh, in, size) != 0) return MPG123_ERR;
|
857
|
+
else
|
858
|
+
{
|
859
|
+
/* The need for more data might have triggered an error.
|
860
|
+
This one is outdated now with the new data. */
|
861
|
+
if(mh->err == MPG123_ERR_READER) mh->err = MPG123_OK;
|
862
|
+
|
863
|
+
return MPG123_OK;
|
864
|
+
}
|
865
|
+
}
|
866
|
+
else
|
867
|
+
{
|
868
|
+
mh->err = MPG123_NULL_BUFFER;
|
869
|
+
return MPG123_ERR;
|
870
|
+
}
|
871
|
+
}
|
872
|
+
return MPG123_OK;
|
873
|
+
#else
|
874
|
+
mh->err = MPG123_MISSING_FEATURE;
|
875
|
+
return MPG123_ERR;
|
876
|
+
#endif
|
877
|
+
}
|
878
|
+
|
879
|
+
/*
|
880
|
+
The old picture:
|
881
|
+
while(1) {
|
882
|
+
len = read(0,buf,16384);
|
883
|
+
if(len <= 0)
|
884
|
+
break;
|
885
|
+
ret = decodeMP3(&mp,buf,len,out,8192,&size);
|
886
|
+
while(ret == MP3_OK) {
|
887
|
+
write(1,out,size);
|
888
|
+
ret = decodeMP3(&mp,NULL,0,out,8192,&size);
|
889
|
+
}
|
890
|
+
}
|
891
|
+
*/
|
892
|
+
|
893
|
+
int attribute_align_arg mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize, unsigned char *outmemory, size_t outmemsize, size_t *done)
|
894
|
+
{
|
895
|
+
int ret = MPG123_OK;
|
896
|
+
size_t mdone = 0;
|
897
|
+
|
898
|
+
if(done != NULL) *done = 0;
|
899
|
+
if(mh == NULL) return MPG123_ERR;
|
900
|
+
#ifndef NO_FEEDER
|
901
|
+
if(inmemsize > 0 && mpg123_feed(mh, inmemory, inmemsize) != MPG123_OK)
|
902
|
+
{
|
903
|
+
ret = MPG123_ERR;
|
904
|
+
goto decodeend;
|
905
|
+
}
|
906
|
+
if(outmemory == NULL) outmemsize = 0; /* Not just give error, give chance to get a status message. */
|
907
|
+
|
908
|
+
while(ret == MPG123_OK)
|
909
|
+
{
|
910
|
+
debug4("decode loop, fill %i (%li vs. %li); to_decode: %i", (int)mh->buffer.fill, (long)mh->num, (long)mh->firstframe, mh->to_decode);
|
911
|
+
/* Decode a frame that has been read before.
|
912
|
+
This only happens when buffer is empty! */
|
913
|
+
if(mh->to_decode)
|
914
|
+
{
|
915
|
+
if(mh->new_format)
|
916
|
+
{
|
917
|
+
debug("notifiying new format");
|
918
|
+
mh->new_format = 0;
|
919
|
+
ret = MPG123_NEW_FORMAT;
|
920
|
+
goto decodeend;
|
921
|
+
}
|
922
|
+
if(mh->buffer.size - mh->buffer.fill < mh->outblock)
|
923
|
+
{
|
924
|
+
ret = MPG123_NO_SPACE;
|
925
|
+
goto decodeend;
|
926
|
+
}
|
927
|
+
decode_the_frame(mh);
|
928
|
+
mh->to_decode = mh->to_ignore = FALSE;
|
929
|
+
mh->buffer.p = mh->buffer.data;
|
930
|
+
debug2("decoded frame %li, got %li samples in buffer", (long)mh->num, (long)(mh->buffer.fill / (samples_to_bytes(mh, 1))));
|
931
|
+
FRAME_BUFFERCHECK(mh);
|
932
|
+
}
|
933
|
+
if(mh->buffer.fill) /* Copy (part of) the decoded data to the caller's buffer. */
|
934
|
+
{
|
935
|
+
/* get what is needed - or just what is there */
|
936
|
+
int a = mh->buffer.fill > (outmemsize - mdone) ? outmemsize - mdone : mh->buffer.fill;
|
937
|
+
debug4("buffer fill: %i; copying %i (%i - %li)", (int)mh->buffer.fill, a, (int)outmemsize, (long)mdone);
|
938
|
+
memcpy(outmemory, mh->buffer.p, a);
|
939
|
+
/* less data in frame buffer, less needed, output pointer increase, more data given... */
|
940
|
+
mh->buffer.fill -= a;
|
941
|
+
outmemory += a;
|
942
|
+
mdone += a;
|
943
|
+
mh->buffer.p += a;
|
944
|
+
if(!(outmemsize > mdone)) goto decodeend;
|
945
|
+
}
|
946
|
+
else /* If we didn't have data, get a new frame. */
|
947
|
+
{
|
948
|
+
int b = get_next_frame(mh);
|
949
|
+
if(b < 0){ ret = b; goto decodeend; }
|
950
|
+
}
|
951
|
+
}
|
952
|
+
decodeend:
|
953
|
+
if(done != NULL) *done = mdone;
|
954
|
+
return ret;
|
955
|
+
#else
|
956
|
+
mh->err = MPG123_MISSING_FEATURE;
|
957
|
+
return MPG123_ERR;
|
958
|
+
#endif
|
959
|
+
}
|
960
|
+
|
961
|
+
long attribute_align_arg mpg123_clip(mpg123_handle *mh)
|
962
|
+
{
|
963
|
+
long ret = 0;
|
964
|
+
|
965
|
+
if(mh != NULL)
|
966
|
+
{
|
967
|
+
ret = mh->clip;
|
968
|
+
mh->clip = 0;
|
969
|
+
}
|
970
|
+
return ret;
|
971
|
+
}
|
972
|
+
|
973
|
+
/* Simples: Track needs initializtion if no initial frame has been read yet. */
|
974
|
+
#define track_need_init(mh) ((mh)->num < 0)
|
975
|
+
|
976
|
+
static int init_track(mpg123_handle *mh)
|
977
|
+
{
|
978
|
+
if(track_need_init(mh))
|
979
|
+
{
|
980
|
+
/* Fresh track, need first frame for basic info. */
|
981
|
+
int b = get_next_frame(mh);
|
982
|
+
if(b < 0) return b;
|
983
|
+
}
|
984
|
+
return 0;
|
985
|
+
}
|
986
|
+
|
987
|
+
int attribute_align_arg mpg123_getformat(mpg123_handle *mh, long *rate, int *channels, int *encoding)
|
988
|
+
{
|
989
|
+
int b;
|
990
|
+
|
991
|
+
if(mh == NULL) return MPG123_ERR;
|
992
|
+
b = init_track(mh);
|
993
|
+
if(b < 0) return b;
|
994
|
+
|
995
|
+
if(rate != NULL) *rate = mh->af.rate;
|
996
|
+
if(channels != NULL) *channels = mh->af.channels;
|
997
|
+
if(encoding != NULL) *encoding = mh->af.encoding;
|
998
|
+
mh->new_format = 0;
|
999
|
+
return MPG123_OK;
|
1000
|
+
}
|
1001
|
+
|
1002
|
+
off_t attribute_align_arg mpg123_timeframe(mpg123_handle *mh, double seconds)
|
1003
|
+
{
|
1004
|
+
off_t b;
|
1005
|
+
|
1006
|
+
if(mh == NULL) return MPG123_ERR;
|
1007
|
+
b = init_track(mh);
|
1008
|
+
if(b<0) return b;
|
1009
|
+
return (off_t)(seconds/mpg123_tpf(mh));
|
1010
|
+
}
|
1011
|
+
|
1012
|
+
/*
|
1013
|
+
Now, where are we? We need to know the last decoded frame... and what's left of it in buffer.
|
1014
|
+
The current frame number can mean the last decoded frame or the to-be-decoded frame.
|
1015
|
+
If mh->to_decode, then mh->num frames have been decoded, the frame mh->num now coming next.
|
1016
|
+
If not, we have the possibility of mh->num+1 frames being decoded or nothing at all.
|
1017
|
+
Then, there is firstframe...when we didn't reach it yet, then the next data will come from there.
|
1018
|
+
mh->num starts with -1
|
1019
|
+
*/
|
1020
|
+
off_t attribute_align_arg mpg123_tell(mpg123_handle *mh)
|
1021
|
+
{
|
1022
|
+
if(mh == NULL) return MPG123_ERR;
|
1023
|
+
if(track_need_init(mh)) return 0;
|
1024
|
+
/* Now we have all the info at hand. */
|
1025
|
+
debug5("tell: %li/%i first %li buffer %lu; frame_outs=%li", (long)mh->num, mh->to_decode, (long)mh->firstframe, (unsigned long)mh->buffer.fill, (long)frame_outs(mh, mh->num));
|
1026
|
+
|
1027
|
+
{ /* Funny block to keep C89 happy. */
|
1028
|
+
off_t pos = 0;
|
1029
|
+
if((mh->num < mh->firstframe) || (mh->num == mh->firstframe && mh->to_decode))
|
1030
|
+
{ /* We are at the beginning, expect output from firstframe on. */
|
1031
|
+
pos = frame_outs(mh, mh->firstframe);
|
1032
|
+
#ifdef GAPLESS
|
1033
|
+
pos += mh->firstoff;
|
1034
|
+
#endif
|
1035
|
+
}
|
1036
|
+
else if(mh->to_decode)
|
1037
|
+
{ /* We start fresh with this frame. Buffer should be empty, but we make sure to count it in. */
|
1038
|
+
pos = frame_outs(mh, mh->num) - bytes_to_samples(mh, mh->buffer.fill);
|
1039
|
+
}
|
1040
|
+
else
|
1041
|
+
{ /* We serve what we have in buffer and then the beginning of next frame... */
|
1042
|
+
pos = frame_outs(mh, mh->num+1) - bytes_to_samples(mh, mh->buffer.fill);
|
1043
|
+
}
|
1044
|
+
/* Substract padding and delay from the beginning. */
|
1045
|
+
pos = SAMPLE_ADJUST(mh,pos);
|
1046
|
+
/* Negative sample offsets are not right, less than nothing is still nothing. */
|
1047
|
+
return pos>0 ? pos : 0;
|
1048
|
+
}
|
1049
|
+
}
|
1050
|
+
|
1051
|
+
off_t attribute_align_arg mpg123_tellframe(mpg123_handle *mh)
|
1052
|
+
{
|
1053
|
+
if(mh == NULL) return MPG123_ERR;
|
1054
|
+
if(mh->num < mh->firstframe) return mh->firstframe;
|
1055
|
+
if(mh->to_decode) return mh->num;
|
1056
|
+
/* Consider firstoff? */
|
1057
|
+
return mh->buffer.fill ? mh->num : mh->num + 1;
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
off_t attribute_align_arg mpg123_tell_stream(mpg123_handle *mh)
|
1061
|
+
{
|
1062
|
+
if(mh == NULL) return MPG123_ERR;
|
1063
|
+
/* mh->rd is at least a bad_reader, so no worry. */
|
1064
|
+
return mh->rd->tell(mh);
|
1065
|
+
}
|
1066
|
+
|
1067
|
+
static int do_the_seek(mpg123_handle *mh)
|
1068
|
+
{
|
1069
|
+
int b;
|
1070
|
+
off_t fnum = SEEKFRAME(mh);
|
1071
|
+
mh->buffer.fill = 0;
|
1072
|
+
|
1073
|
+
/* If we are inside the ignoreframe - firstframe window, we may get away without actual seeking. */
|
1074
|
+
if(mh->num < mh->firstframe)
|
1075
|
+
{
|
1076
|
+
mh->to_decode = FALSE; /* In any case, don't decode the current frame, perhaps ignore instead. */
|
1077
|
+
if(mh->num > fnum) return MPG123_OK;
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
/* If we are already there, we are fine either for decoding or for ignoring. */
|
1081
|
+
if(mh->num == fnum && (mh->to_decode || fnum < mh->firstframe)) return MPG123_OK;
|
1082
|
+
/* We have the frame before... just go ahead as normal. */
|
1083
|
+
if(mh->num == fnum-1)
|
1084
|
+
{
|
1085
|
+
mh->to_decode = FALSE;
|
1086
|
+
return MPG123_OK;
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
/* OK, real seeking follows... clear buffers and go for it. */
|
1090
|
+
frame_buffers_reset(mh);
|
1091
|
+
#ifndef NO_NTOM
|
1092
|
+
if(mh->down_sample == 3)
|
1093
|
+
{
|
1094
|
+
ntom_set_ntom(mh, fnum);
|
1095
|
+
debug3("fixed ntom for frame %"OFF_P" to %lu, num=%"OFF_P, (off_p)fnum, mh->ntom_val[0], (off_p)mh->num);
|
1096
|
+
}
|
1097
|
+
#endif
|
1098
|
+
b = mh->rd->seek_frame(mh, fnum);
|
1099
|
+
debug1("seek_frame returned: %i", b);
|
1100
|
+
if(b<0) return b;
|
1101
|
+
/* Only mh->to_ignore is TRUE. */
|
1102
|
+
if(mh->num < mh->firstframe) mh->to_decode = FALSE;
|
1103
|
+
|
1104
|
+
mh->playnum = mh->num;
|
1105
|
+
return 0;
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
off_t attribute_align_arg mpg123_seek(mpg123_handle *mh, off_t sampleoff, int whence)
|
1109
|
+
{
|
1110
|
+
int b;
|
1111
|
+
off_t pos;
|
1112
|
+
|
1113
|
+
pos = mpg123_tell(mh); /* adjusted samples */
|
1114
|
+
/* pos < 0 also can mean that simply a former seek failed at the lower levels.
|
1115
|
+
In that case, we only allow absolute seeks. */
|
1116
|
+
if(pos < 0 && whence != SEEK_SET)
|
1117
|
+
{ /* Unless we got the obvious error of NULL handle, this is a special seek failure. */
|
1118
|
+
if(mh != NULL) mh->err = MPG123_NO_RELSEEK;
|
1119
|
+
return MPG123_ERR;
|
1120
|
+
}
|
1121
|
+
if((b=init_track(mh)) < 0) return b;
|
1122
|
+
switch(whence)
|
1123
|
+
{
|
1124
|
+
case SEEK_CUR: pos += sampleoff; break;
|
1125
|
+
case SEEK_SET: pos = sampleoff; break;
|
1126
|
+
case SEEK_END:
|
1127
|
+
/* When we do not know the end already, we can try to find it. */
|
1128
|
+
if(mh->track_frames < 1 && (mh->rdat.flags & READER_SEEKABLE))
|
1129
|
+
mpg123_scan(mh);
|
1130
|
+
if(mh->track_frames > 0) pos = SAMPLE_ADJUST(mh,frame_outs(mh, mh->track_frames)) - sampleoff;
|
1131
|
+
#ifdef GAPLESS
|
1132
|
+
else if(mh->end_os > 0) pos = SAMPLE_ADJUST(mh,mh->end_os) - sampleoff;
|
1133
|
+
#endif
|
1134
|
+
else
|
1135
|
+
{
|
1136
|
+
mh->err = MPG123_NO_SEEK_FROM_END;
|
1137
|
+
return MPG123_ERR;
|
1138
|
+
}
|
1139
|
+
break;
|
1140
|
+
default: mh->err = MPG123_BAD_WHENCE; return MPG123_ERR;
|
1141
|
+
}
|
1142
|
+
if(pos < 0) pos = 0;
|
1143
|
+
/* pos now holds the wanted sample offset in adjusted samples */
|
1144
|
+
frame_set_seek(mh, SAMPLE_UNADJUST(mh,pos));
|
1145
|
+
pos = do_the_seek(mh);
|
1146
|
+
if(pos < 0) return pos;
|
1147
|
+
|
1148
|
+
return mpg123_tell(mh);
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
/*
|
1152
|
+
A bit more tricky... libmpg123 does not do the seeking itself.
|
1153
|
+
All it can do is to ignore frames until the wanted one is there.
|
1154
|
+
The caller doesn't know where a specific frame starts and mpg123 also only knows the general region after it scanned the file.
|
1155
|
+
Well, it is tricky...
|
1156
|
+
*/
|
1157
|
+
off_t attribute_align_arg mpg123_feedseek(mpg123_handle *mh, off_t sampleoff, int whence, off_t *input_offset)
|
1158
|
+
{
|
1159
|
+
int b;
|
1160
|
+
off_t pos;
|
1161
|
+
|
1162
|
+
pos = mpg123_tell(mh); /* adjusted samples */
|
1163
|
+
debug3("seek from %li to %li (whence=%i)", (long)pos, (long)sampleoff, whence);
|
1164
|
+
/* The special seek error handling does not apply here... there is no lowlevel I/O. */
|
1165
|
+
if(pos < 0) return pos; /* mh == NULL is covered in mpg123_tell() */
|
1166
|
+
#ifndef NO_FEEDER
|
1167
|
+
if(input_offset == NULL)
|
1168
|
+
{
|
1169
|
+
mh->err = MPG123_NULL_POINTER;
|
1170
|
+
return MPG123_ERR;
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
if((b=init_track(mh)) < 0) return b; /* May need more to do anything at all. */
|
1174
|
+
|
1175
|
+
switch(whence)
|
1176
|
+
{
|
1177
|
+
case SEEK_CUR: pos += sampleoff; break;
|
1178
|
+
case SEEK_SET: pos = sampleoff; break;
|
1179
|
+
case SEEK_END:
|
1180
|
+
if(mh->track_frames > 0) pos = SAMPLE_ADJUST(mh,frame_outs(mh, mh->track_frames)) - sampleoff;
|
1181
|
+
#ifdef GAPLESS
|
1182
|
+
else if(mh->end_os >= 0) pos = SAMPLE_ADJUST(mh,mh->end_os) - sampleoff;
|
1183
|
+
#endif
|
1184
|
+
else
|
1185
|
+
{
|
1186
|
+
mh->err = MPG123_NO_SEEK_FROM_END;
|
1187
|
+
return MPG123_ERR;
|
1188
|
+
}
|
1189
|
+
break;
|
1190
|
+
default: mh->err = MPG123_BAD_WHENCE; return MPG123_ERR;
|
1191
|
+
}
|
1192
|
+
if(pos < 0) pos = 0;
|
1193
|
+
frame_set_seek(mh, SAMPLE_UNADJUST(mh,pos));
|
1194
|
+
pos = SEEKFRAME(mh);
|
1195
|
+
mh->buffer.fill = 0;
|
1196
|
+
|
1197
|
+
/* Shortcuts without modifying input stream. */
|
1198
|
+
*input_offset = mh->rdat.buffer.fileoff + mh->rdat.buffer.size;
|
1199
|
+
if(mh->num < mh->firstframe) mh->to_decode = FALSE;
|
1200
|
+
if(mh->num == pos && mh->to_decode) goto feedseekend;
|
1201
|
+
if(mh->num == pos-1) goto feedseekend;
|
1202
|
+
/* Whole way. */
|
1203
|
+
*input_offset = feed_set_pos(mh, frame_index_find(mh, SEEKFRAME(mh), &pos));
|
1204
|
+
mh->num = pos-1; /* The next read frame will have num = pos. */
|
1205
|
+
if(*input_offset < 0) return MPG123_ERR;
|
1206
|
+
|
1207
|
+
feedseekend:
|
1208
|
+
return mpg123_tell(mh);
|
1209
|
+
#else
|
1210
|
+
mh->err = MPG123_MISSING_FEATURE;
|
1211
|
+
return MPG123_ERR;
|
1212
|
+
#endif
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
off_t attribute_align_arg mpg123_seek_frame(mpg123_handle *mh, off_t offset, int whence)
|
1216
|
+
{
|
1217
|
+
int b;
|
1218
|
+
off_t pos = 0;
|
1219
|
+
|
1220
|
+
if(mh == NULL) return MPG123_ERR;
|
1221
|
+
if((b=init_track(mh)) < 0) return b;
|
1222
|
+
|
1223
|
+
/* Could play games here with to_decode... */
|
1224
|
+
pos = mh->num;
|
1225
|
+
switch(whence)
|
1226
|
+
{
|
1227
|
+
case SEEK_CUR: pos += offset; break;
|
1228
|
+
case SEEK_SET: pos = offset; break;
|
1229
|
+
case SEEK_END:
|
1230
|
+
if(mh->track_frames > 0) pos = mh->track_frames - offset;
|
1231
|
+
else
|
1232
|
+
{
|
1233
|
+
mh->err = MPG123_NO_SEEK_FROM_END;
|
1234
|
+
return MPG123_ERR;
|
1235
|
+
}
|
1236
|
+
break;
|
1237
|
+
default:
|
1238
|
+
mh->err = MPG123_BAD_WHENCE;
|
1239
|
+
return MPG123_ERR;
|
1240
|
+
}
|
1241
|
+
if(pos < 0) pos = 0;
|
1242
|
+
/* Not limiting the possible position on end for the chance that there might be more to the stream than announced via track_frames. */
|
1243
|
+
|
1244
|
+
frame_set_frameseek(mh, pos);
|
1245
|
+
pos = do_the_seek(mh);
|
1246
|
+
if(pos < 0) return pos;
|
1247
|
+
|
1248
|
+
return mpg123_tellframe(mh);
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
int attribute_align_arg mpg123_set_filesize(mpg123_handle *mh, off_t size)
|
1252
|
+
{
|
1253
|
+
if(mh == NULL) return MPG123_ERR;
|
1254
|
+
|
1255
|
+
mh->rdat.filelen = size;
|
1256
|
+
return MPG123_OK;
|
1257
|
+
}
|
1258
|
+
|
1259
|
+
off_t attribute_align_arg mpg123_length(mpg123_handle *mh)
|
1260
|
+
{
|
1261
|
+
int b;
|
1262
|
+
off_t length;
|
1263
|
+
|
1264
|
+
if(mh == NULL) return MPG123_ERR;
|
1265
|
+
b = init_track(mh);
|
1266
|
+
if(b<0) return b;
|
1267
|
+
if(mh->track_samples > -1) length = mh->track_samples;
|
1268
|
+
else if(mh->track_frames > 0) length = mh->track_frames*spf(mh);
|
1269
|
+
else if(mh->rdat.filelen > 0) /* Let the case of 0 length just fall through. */
|
1270
|
+
{
|
1271
|
+
/* A bad estimate. Ignoring tags 'n stuff. */
|
1272
|
+
double bpf = mh->mean_framesize ? mh->mean_framesize : compute_bpf(mh);
|
1273
|
+
length = (off_t)((double)(mh->rdat.filelen)/bpf*spf(mh));
|
1274
|
+
}
|
1275
|
+
else if(mh->rdat.filelen == 0) return mpg123_tell(mh); /* we could be in feeder mode */
|
1276
|
+
else return MPG123_ERR; /* No length info there! */
|
1277
|
+
|
1278
|
+
debug1("mpg123_length: internal sample length: %"OFF_P, (off_p)length);
|
1279
|
+
|
1280
|
+
length = frame_ins2outs(mh, length);
|
1281
|
+
debug1("mpg123_length: external sample length: %"OFF_P, (off_p)length);
|
1282
|
+
length = SAMPLE_ADJUST(mh,length);
|
1283
|
+
return length;
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
int attribute_align_arg mpg123_scan(mpg123_handle *mh)
|
1287
|
+
{
|
1288
|
+
int b;
|
1289
|
+
off_t backframe;
|
1290
|
+
int to_decode, to_ignore;
|
1291
|
+
|
1292
|
+
if(mh == NULL) return MPG123_ERR;
|
1293
|
+
if(!(mh->rdat.flags & READER_SEEKABLE)){ mh->err = MPG123_NO_SEEK; return MPG123_ERR; }
|
1294
|
+
/* Scan through the _whole_ file, since the current position is no count but computed assuming constant samples per frame. */
|
1295
|
+
/* Also, we can just keep the current buffer and seek settings. Just operate on input frames here. */
|
1296
|
+
debug("issuing scan");
|
1297
|
+
b = init_track(mh); /* mh->num >= 0 !! */
|
1298
|
+
if(b<0)
|
1299
|
+
{
|
1300
|
+
if(b == MPG123_DONE) return MPG123_OK;
|
1301
|
+
else return MPG123_ERR; /* Must be error here, NEED_MORE is not for seekable streams. */
|
1302
|
+
}
|
1303
|
+
backframe = mh->num;
|
1304
|
+
to_decode = mh->to_decode;
|
1305
|
+
to_ignore = mh->to_ignore;
|
1306
|
+
b = mh->rd->seek_frame(mh, 0);
|
1307
|
+
if(b<0 || mh->num != 0) return MPG123_ERR;
|
1308
|
+
/* One frame must be there now. */
|
1309
|
+
mh->track_frames = 1;
|
1310
|
+
mh->track_samples = spf(mh); /* Internal samples. */
|
1311
|
+
debug("TODO: We should disable gapless code when encountering inconsistent spf(mh)!");
|
1312
|
+
while(read_frame(mh) == 1)
|
1313
|
+
{
|
1314
|
+
++mh->track_frames;
|
1315
|
+
mh->track_samples += spf(mh);
|
1316
|
+
}
|
1317
|
+
debug2("Scanning yielded %"OFF_P" track samples, %"OFF_P" frames.", (off_p)mh->track_samples, (off_p)mh->track_frames);
|
1318
|
+
#ifdef GAPLESS
|
1319
|
+
/* Also, think about usefulness of that extra value track_samples ... it could be used for consistency checking. */
|
1320
|
+
frame_gapless_update(mh, mh->track_samples);
|
1321
|
+
#endif
|
1322
|
+
b = mh->rd->seek_frame(mh, backframe);
|
1323
|
+
if(b<0 || mh->num != backframe) return MPG123_ERR;
|
1324
|
+
mh->to_decode = to_decode;
|
1325
|
+
mh->to_ignore = to_ignore;
|
1326
|
+
return MPG123_OK;
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
int attribute_align_arg mpg123_meta_check(mpg123_handle *mh)
|
1330
|
+
{
|
1331
|
+
if(mh != NULL) return mh->metaflags;
|
1332
|
+
else return 0;
|
1333
|
+
}
|
1334
|
+
|
1335
|
+
void attribute_align_arg mpg123_meta_free(mpg123_handle *mh)
|
1336
|
+
{
|
1337
|
+
if(mh == NULL) return;
|
1338
|
+
|
1339
|
+
reset_id3(mh);
|
1340
|
+
reset_icy(&mh->icy);
|
1341
|
+
}
|
1342
|
+
|
1343
|
+
int attribute_align_arg mpg123_id3(mpg123_handle *mh, mpg123_id3v1 **v1, mpg123_id3v2 **v2)
|
1344
|
+
{
|
1345
|
+
if(v1 != NULL) *v1 = NULL;
|
1346
|
+
if(v2 != NULL) *v2 = NULL;
|
1347
|
+
if(mh == NULL) return MPG123_ERR;
|
1348
|
+
|
1349
|
+
if(mh->metaflags & MPG123_ID3)
|
1350
|
+
{
|
1351
|
+
id3_link(mh);
|
1352
|
+
if(v1 != NULL && mh->rdat.flags & READER_ID3TAG) *v1 = (mpg123_id3v1*) mh->id3buf;
|
1353
|
+
if(v2 != NULL)
|
1354
|
+
#ifdef NO_ID3V2
|
1355
|
+
*v2 = NULL;
|
1356
|
+
#else
|
1357
|
+
*v2 = &mh->id3v2;
|
1358
|
+
#endif
|
1359
|
+
|
1360
|
+
mh->metaflags |= MPG123_ID3;
|
1361
|
+
mh->metaflags &= ~MPG123_NEW_ID3;
|
1362
|
+
}
|
1363
|
+
return MPG123_OK;
|
1364
|
+
}
|
1365
|
+
|
1366
|
+
int attribute_align_arg mpg123_icy(mpg123_handle *mh, char **icy_meta)
|
1367
|
+
{
|
1368
|
+
if(mh == NULL) return MPG123_ERR;
|
1369
|
+
#ifndef NO_ICY
|
1370
|
+
if(icy_meta == NULL)
|
1371
|
+
{
|
1372
|
+
mh->err = MPG123_NULL_POINTER;
|
1373
|
+
return MPG123_ERR;
|
1374
|
+
}
|
1375
|
+
*icy_meta = NULL;
|
1376
|
+
|
1377
|
+
if(mh->metaflags & MPG123_ICY)
|
1378
|
+
{
|
1379
|
+
*icy_meta = mh->icy.data;
|
1380
|
+
mh->metaflags |= MPG123_ICY;
|
1381
|
+
mh->metaflags &= ~MPG123_NEW_ICY;
|
1382
|
+
}
|
1383
|
+
return MPG123_OK;
|
1384
|
+
#else
|
1385
|
+
mh->err = MPG123_MISSING_FEATURE;
|
1386
|
+
return MPG123_ERR;
|
1387
|
+
#endif
|
1388
|
+
}
|
1389
|
+
|
1390
|
+
char* attribute_align_arg mpg123_icy2utf8(const char* icy_text)
|
1391
|
+
{
|
1392
|
+
#ifndef NO_ICY
|
1393
|
+
return icy2utf8(icy_text, 0);
|
1394
|
+
#else
|
1395
|
+
return NULL;
|
1396
|
+
#endif
|
1397
|
+
}
|
1398
|
+
|
1399
|
+
/* That one is always defined... it's not worth it to remove it for NO_ID3V2. */
|
1400
|
+
enum mpg123_text_encoding attribute_align_arg mpg123_enc_from_id3(unsigned char id3_enc_byte)
|
1401
|
+
{
|
1402
|
+
switch(id3_enc_byte)
|
1403
|
+
{
|
1404
|
+
case mpg123_id3_latin1: return mpg123_text_latin1;
|
1405
|
+
case mpg123_id3_utf16bom: return mpg123_text_utf16bom; /* ID3v2.3 has UCS-2 with BOM here. */
|
1406
|
+
case mpg123_id3_utf16be: return mpg123_text_utf16be;
|
1407
|
+
case mpg123_id3_utf8: return mpg123_text_utf8;
|
1408
|
+
default: return mpg123_text_unknown;
|
1409
|
+
}
|
1410
|
+
}
|
1411
|
+
|
1412
|
+
#ifndef NO_STRING
|
1413
|
+
int mpg123_store_utf8(mpg123_string *sb, enum mpg123_text_encoding enc, const unsigned char *source, size_t source_size)
|
1414
|
+
{
|
1415
|
+
switch(enc)
|
1416
|
+
{
|
1417
|
+
#ifndef NO_ID3V2
|
1418
|
+
/* The encodings we get from ID3v2 tags. */
|
1419
|
+
case mpg123_text_utf8:
|
1420
|
+
id3_to_utf8(sb, mpg123_id3_utf8, source, source_size, 0);
|
1421
|
+
break;
|
1422
|
+
case mpg123_text_latin1:
|
1423
|
+
id3_to_utf8(sb, mpg123_id3_latin1, source, source_size, 0);
|
1424
|
+
break;
|
1425
|
+
case mpg123_text_utf16bom:
|
1426
|
+
case mpg123_text_utf16:
|
1427
|
+
id3_to_utf8(sb, mpg123_id3_utf16bom, source, source_size, 0);
|
1428
|
+
break;
|
1429
|
+
/* Special because one cannot skip zero bytes here. */
|
1430
|
+
case mpg123_text_utf16be:
|
1431
|
+
id3_to_utf8(sb, mpg123_id3_utf16be, source, source_size, 0);
|
1432
|
+
break;
|
1433
|
+
#endif
|
1434
|
+
#ifndef NO_ICY
|
1435
|
+
/* ICY encoding... */
|
1436
|
+
case mpg123_text_icy:
|
1437
|
+
case mpg123_text_cp1252:
|
1438
|
+
{
|
1439
|
+
mpg123_free_string(sb);
|
1440
|
+
/* Paranoia: Make sure that the string ends inside the buffer... */
|
1441
|
+
if(source[source_size-1] == 0)
|
1442
|
+
{
|
1443
|
+
/* Convert from ICY encoding... with force applied or not. */
|
1444
|
+
char *tmpstring = icy2utf8((const char*)source, enc == mpg123_text_cp1252 ? 1 : 0);
|
1445
|
+
if(tmpstring != NULL)
|
1446
|
+
{
|
1447
|
+
mpg123_set_string(sb, tmpstring);
|
1448
|
+
free(tmpstring);
|
1449
|
+
}
|
1450
|
+
}
|
1451
|
+
}
|
1452
|
+
break;
|
1453
|
+
#endif
|
1454
|
+
default:
|
1455
|
+
mpg123_free_string(sb);
|
1456
|
+
}
|
1457
|
+
/* At least a trailing null of some form should be there... */
|
1458
|
+
return (sb->fill > 0) ? 1 : 0;
|
1459
|
+
}
|
1460
|
+
#endif
|
1461
|
+
|
1462
|
+
int attribute_align_arg mpg123_index(mpg123_handle *mh, off_t **offsets, off_t *step, size_t *fill)
|
1463
|
+
{
|
1464
|
+
if(mh == NULL) return MPG123_ERR;
|
1465
|
+
if(offsets == NULL || step == NULL || fill == NULL)
|
1466
|
+
{
|
1467
|
+
mh->err = MPG123_BAD_INDEX_PAR;
|
1468
|
+
return MPG123_ERR;
|
1469
|
+
}
|
1470
|
+
#ifdef FRAME_INDEX
|
1471
|
+
*offsets = mh->index.data;
|
1472
|
+
*step = mh->index.step;
|
1473
|
+
*fill = mh->index.fill;
|
1474
|
+
#else
|
1475
|
+
*offsets = NULL;
|
1476
|
+
*step = 0;
|
1477
|
+
*fill = 0;
|
1478
|
+
#endif
|
1479
|
+
return MPG123_OK;
|
1480
|
+
}
|
1481
|
+
|
1482
|
+
int attribute_align_arg mpg123_set_index(mpg123_handle *mh, off_t *offsets, off_t step, size_t fill)
|
1483
|
+
{
|
1484
|
+
if(mh == NULL) return MPG123_ERR;
|
1485
|
+
#ifdef FRAME_INDEX
|
1486
|
+
if(step == 0)
|
1487
|
+
{
|
1488
|
+
mh->err = MPG123_BAD_INDEX_PAR;
|
1489
|
+
return MPG123_ERR;
|
1490
|
+
}
|
1491
|
+
if(fi_set(&mh->index, offsets, step, fill) == -1)
|
1492
|
+
{
|
1493
|
+
mh->err = MPG123_OUT_OF_MEM;
|
1494
|
+
return MPG123_ERR;
|
1495
|
+
}
|
1496
|
+
return MPG123_OK;
|
1497
|
+
#else
|
1498
|
+
mh->err = MPG123_MISSING_FEATURE;
|
1499
|
+
return MPG123_ERR;
|
1500
|
+
#endif
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
int attribute_align_arg mpg123_close(mpg123_handle *mh)
|
1504
|
+
{
|
1505
|
+
if(mh == NULL) return MPG123_ERR;
|
1506
|
+
|
1507
|
+
/* mh->rd is never NULL! */
|
1508
|
+
if(mh->rd->close != NULL) mh->rd->close(mh);
|
1509
|
+
|
1510
|
+
if(mh->new_format)
|
1511
|
+
{
|
1512
|
+
debug("Hey, we are closing a track before the new format has been queried...");
|
1513
|
+
invalidate_format(&mh->af);
|
1514
|
+
mh->new_format = 0;
|
1515
|
+
}
|
1516
|
+
/* Always reset the frame buffers on close, so we cannot forget it in funky opening routines (wrappers, even). */
|
1517
|
+
frame_reset(mh);
|
1518
|
+
return MPG123_OK;
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
void attribute_align_arg mpg123_delete(mpg123_handle *mh)
|
1522
|
+
{
|
1523
|
+
if(mh != NULL)
|
1524
|
+
{
|
1525
|
+
mpg123_close(mh);
|
1526
|
+
frame_exit(mh); /* free buffers in frame */
|
1527
|
+
free(mh); /* free struct; cast? */
|
1528
|
+
}
|
1529
|
+
}
|
1530
|
+
|
1531
|
+
static const char *mpg123_error[] =
|
1532
|
+
{
|
1533
|
+
"No error... (code 0)",
|
1534
|
+
"Unable to set up output format! (code 1)",
|
1535
|
+
"Invalid channel number specified. (code 2)",
|
1536
|
+
"Invalid sample rate specified. (code 3)",
|
1537
|
+
"Unable to allocate memory for 16 to 8 converter table! (code 4)",
|
1538
|
+
"Bad parameter id! (code 5)",
|
1539
|
+
"Bad buffer given -- invalid pointer or too small size. (code 6)",
|
1540
|
+
"Out of memory -- some malloc() failed. (code 7)",
|
1541
|
+
"You didn't initialize the library! (code 8)",
|
1542
|
+
"Invalid decoder choice. (code 9)",
|
1543
|
+
"Invalid mpg123 handle. (code 10)",
|
1544
|
+
"Unable to initialize frame buffers (out of memory?)! (code 11)",
|
1545
|
+
"Invalid RVA mode. (code 12)",
|
1546
|
+
"This build doesn't support gapless decoding. (code 13)",
|
1547
|
+
"Not enough buffer space. (code 14)",
|
1548
|
+
"Incompatible numeric data types. (code 15)",
|
1549
|
+
"Bad equalizer band. (code 16)",
|
1550
|
+
"Null pointer given where valid storage address needed. (code 17)",
|
1551
|
+
"Error reading the stream. (code 18)",
|
1552
|
+
"Cannot seek from end (end is not known). (code 19)",
|
1553
|
+
"Invalid 'whence' for seek function. (code 20)",
|
1554
|
+
"Build does not support stream timeouts. (code 21)",
|
1555
|
+
"File access error. (code 22)",
|
1556
|
+
"Seek not supported by stream. (code 23)",
|
1557
|
+
"No stream opened. (code 24)",
|
1558
|
+
"Bad parameter handle. (code 25)",
|
1559
|
+
"Invalid parameter addresses for index retrieval. (code 26)",
|
1560
|
+
"Lost track in the bytestream and did not attempt resync. (code 27)",
|
1561
|
+
"Failed to find valid MPEG data within limit on resync. (code 28)",
|
1562
|
+
"No 8bit encoding possible. (code 29)",
|
1563
|
+
"Stack alignment is not good. (code 30)",
|
1564
|
+
"You gave me a NULL buffer? (code 31)",
|
1565
|
+
"File position is screwed up, please do an absolute seek (code 32)",
|
1566
|
+
"Inappropriate NULL-pointer provided.",
|
1567
|
+
"Bad key value given.",
|
1568
|
+
"There is no frame index (disabled in this build).",
|
1569
|
+
"Frame index operation failed.",
|
1570
|
+
"Decoder setup failed (invalid combination of settings?)",
|
1571
|
+
"Feature not in this build."
|
1572
|
+
,"Some bad value has been provided."
|
1573
|
+
,"Low-level seeking has failed (call to lseek(), usually)."
|
1574
|
+
,"Custom I/O obviously not prepared."
|
1575
|
+
,"Overflow in LFS (large file support) conversion."
|
1576
|
+
,"Overflow in integer conversion."
|
1577
|
+
};
|
1578
|
+
|
1579
|
+
const char* attribute_align_arg mpg123_plain_strerror(int errcode)
|
1580
|
+
{
|
1581
|
+
if(errcode >= 0 && errcode < sizeof(mpg123_error)/sizeof(char*))
|
1582
|
+
return mpg123_error[errcode];
|
1583
|
+
else switch(errcode)
|
1584
|
+
{
|
1585
|
+
case MPG123_ERR:
|
1586
|
+
return "A generic mpg123 error.";
|
1587
|
+
case MPG123_DONE:
|
1588
|
+
return "Message: I am done with this track.";
|
1589
|
+
case MPG123_NEED_MORE:
|
1590
|
+
return "Message: Feed me more input data!";
|
1591
|
+
case MPG123_NEW_FORMAT:
|
1592
|
+
return "Message: Prepare for a changed audio format (query the new one)!";
|
1593
|
+
default:
|
1594
|
+
return "I have no idea - an unknown error code!";
|
1595
|
+
}
|
1596
|
+
}
|
1597
|
+
|
1598
|
+
int attribute_align_arg mpg123_errcode(mpg123_handle *mh)
|
1599
|
+
{
|
1600
|
+
if(mh != NULL) return mh->err;
|
1601
|
+
return MPG123_BAD_HANDLE;
|
1602
|
+
}
|
1603
|
+
|
1604
|
+
const char* attribute_align_arg mpg123_strerror(mpg123_handle *mh)
|
1605
|
+
{
|
1606
|
+
return mpg123_plain_strerror(mpg123_errcode(mh));
|
1607
|
+
}
|