gosu 1.5.0 → 2.0.0.pre6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/dependencies/SDL/include/SDL.h +233 -0
- data/dependencies/SDL/include/SDL_assert.h +320 -0
- data/dependencies/SDL/include/SDL_atomic.h +414 -0
- data/dependencies/SDL/include/SDL_audio.h +1500 -0
- data/dependencies/SDL/include/{SDL3/SDL_bits.h → SDL_bits.h} +27 -47
- data/dependencies/SDL/include/{SDL3/SDL_blendmode.h → SDL_blendmode.h} +55 -59
- data/dependencies/SDL/include/SDL_clipboard.h +141 -0
- data/dependencies/SDL/include/SDL_config.h +331 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +594 -0
- data/dependencies/SDL/include/{SDL3/SDL_egl.h → SDL_egl.h} +8 -11
- data/dependencies/SDL/include/SDL_endian.h +348 -0
- data/dependencies/SDL/include/SDL_error.h +163 -0
- data/dependencies/SDL/include/SDL_events.h +1166 -0
- data/dependencies/SDL/include/SDL_filesystem.h +149 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +1074 -0
- data/dependencies/SDL/include/SDL_gesture.h +117 -0
- data/dependencies/SDL/include/SDL_guid.h +100 -0
- data/dependencies/SDL/include/SDL_haptic.h +1341 -0
- data/dependencies/SDL/include/SDL_hidapi.h +451 -0
- data/dependencies/SDL/include/SDL_hints.h +2613 -0
- data/dependencies/SDL/include/SDL_joystick.h +1069 -0
- data/dependencies/SDL/include/SDL_keyboard.h +353 -0
- data/dependencies/SDL/include/SDL_keycode.h +358 -0
- data/dependencies/SDL/include/SDL_loadso.h +115 -0
- data/dependencies/SDL/include/{SDL3/SDL_locale.h → SDL_locale.h} +24 -40
- data/dependencies/SDL/include/SDL_log.h +404 -0
- data/dependencies/SDL/include/SDL_main.h +282 -0
- data/dependencies/SDL/include/{SDL3/SDL_messagebox.h → SDL_messagebox.h} +48 -85
- data/dependencies/SDL/include/{SDL3/SDL_metal.h → SDL_metal.h} +29 -29
- data/dependencies/SDL/include/{SDL3/SDL_misc.h → SDL_misc.h} +12 -13
- data/dependencies/SDL/include/SDL_mouse.h +464 -0
- data/dependencies/SDL/include/SDL_mutex.h +545 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/{SDL3/SDL_opengl.h → SDL_opengl.h} +252 -1221
- data/dependencies/SDL/include/{SDL3/SDL_opengles.h → SDL_opengles.h} +7 -6
- data/dependencies/SDL/include/{SDL3/SDL_opengles2.h → SDL_opengles2.h} +11 -10
- data/dependencies/SDL/include/SDL_pixels.h +644 -0
- data/dependencies/SDL/include/SDL_platform.h +261 -0
- data/dependencies/SDL/include/{SDL3/SDL_power.h → SDL_power.h} +19 -40
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +376 -0
- data/dependencies/SDL/include/SDL_render.h +1924 -0
- data/dependencies/SDL/include/SDL_revision.h +7 -0
- data/dependencies/SDL/include/SDL_rwops.h +841 -0
- data/dependencies/SDL/include/{SDL3/SDL_scancode.h → SDL_scancode.h} +68 -60
- data/dependencies/SDL/include/SDL_sensor.h +322 -0
- data/dependencies/SDL/include/SDL_shape.h +155 -0
- data/dependencies/SDL/include/SDL_stdinc.h +838 -0
- data/dependencies/SDL/include/SDL_surface.h +997 -0
- data/dependencies/SDL/include/SDL_system.h +623 -0
- data/dependencies/SDL/include/SDL_syswm.h +386 -0
- data/dependencies/SDL/include/{SDL3/SDL_test.h → SDL_test.h} +22 -16
- data/dependencies/SDL/include/{SDL3/SDL_test_assert.h → SDL_test_assert.h} +34 -27
- data/dependencies/SDL/include/{SDL3/SDL_test_common.h → SDL_test_common.h} +52 -109
- data/dependencies/SDL/include/{SDL3/SDL_test_compare.h → SDL_test_compare.h} +14 -22
- data/dependencies/SDL/include/{SDL3/SDL_test_crc32.h → SDL_test_crc32.h} +30 -27
- data/dependencies/SDL/include/{SDL3/SDL_test_font.h → SDL_test_font.h} +49 -50
- data/dependencies/SDL/include/{SDL3/SDL_test_fuzzer.h → SDL_test_fuzzer.h} +79 -64
- data/dependencies/SDL/include/{SDL3/SDL_test_harness.h → SDL_test_harness.h} +30 -47
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/{SDL3/SDL_platform.h → SDL_test_log.h} +26 -25
- data/dependencies/SDL/include/{SDL3/SDL_test_md5.h → SDL_test_md5.h} +28 -21
- data/dependencies/SDL/include/{SDL3/SDL_test_memory.h → SDL_test_memory.h} +16 -19
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +464 -0
- data/dependencies/SDL/include/SDL_timer.h +222 -0
- data/dependencies/SDL/include/SDL_touch.h +150 -0
- data/dependencies/SDL/include/{SDL3/SDL_copying.h → SDL_types.h} +9 -2
- data/dependencies/SDL/include/SDL_version.h +204 -0
- data/dependencies/SDL/include/SDL_video.h +2178 -0
- data/dependencies/SDL/include/SDL_vulkan.h +215 -0
- data/dependencies/SDL/include/begin_code.h +187 -0
- data/dependencies/SDL/include/{SDL3/SDL_close_code.h → close_code.h} +6 -7
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +215 -136
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +54 -55
- data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +41 -24
- data/dependencies/SDL_sound/SDL_sound_flac.c +12 -32
- data/dependencies/SDL_sound/SDL_sound_internal.h +48 -33
- data/dependencies/SDL_sound/SDL_sound_modplug.c +29 -21
- data/dependencies/SDL_sound/SDL_sound_mp3.c +13 -35
- data/dependencies/SDL_sound/SDL_sound_raw.c +15 -14
- data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
- data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +25 -34
- data/dependencies/SDL_sound/SDL_sound_wav.c +82 -86
- data/dependencies/SDL_sound/dr_flac.h +1281 -1845
- data/dependencies/SDL_sound/dr_mp3.h +617 -1035
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +4 -5
- data/dependencies/SDL_sound/libmodplug/load_ams.c +3 -6
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +1 -2
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
- data/dependencies/SDL_sound/libmodplug/modplug.h +1 -2
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
- data/dependencies/SDL_sound/libmodplug/sndfile.c +0 -3
- data/dependencies/SDL_sound/libmodplug/sndmix.c +3 -7
- data/dependencies/SDL_sound/stb_vorbis.h +343 -397
- data/dependencies/mojoAL/AL/alc.h +2 -2
- data/dependencies/mojoAL/mojoal.c +1878 -2113
- data/dependencies/stb/stb_image.h +1381 -1192
- data/dependencies/stb/stb_image_write.h +129 -329
- data/dependencies/stb/stb_truetype.h +60 -304
- data/dependencies/utf8proc/utf8proc.c +75 -133
- data/dependencies/utf8proc/utf8proc.h +50 -131
- data/dependencies/utf8proc/utf8proc_data.h +15658 -16213
- data/ext/gosu-ffi/extconf.rb +28 -11
- data/ext/gosu-ffi/gosu-ffi.def +0 -3
- data/ffi/Gosu.cpp +29 -52
- data/ffi/Gosu.h +4 -4
- data/ffi/Gosu_Color.cpp +36 -80
- data/ffi/Gosu_FFI_internal.h +13 -12
- data/ffi/Gosu_Font.cpp +11 -16
- data/ffi/Gosu_Font.h +4 -4
- data/ffi/Gosu_Image.cpp +36 -69
- data/ffi/Gosu_Image.h +5 -16
- data/include/Gosu/Bitmap.hpp +1 -1
- data/include/Gosu/Color.hpp +4 -5
- data/include/Gosu/Graphics.hpp +0 -2
- data/include/Gosu/Image.hpp +1 -1
- data/include/Gosu/Math.hpp +5 -5
- data/include/Gosu/Utility.hpp +1 -27
- data/include/Gosu/Version.hpp +2 -2
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/channel.rb +0 -1
- data/lib/gosu/color.rb +13 -36
- data/lib/gosu/compat.rb +14 -106
- data/lib/gosu/constants.rb +24 -24
- data/lib/gosu/ffi.rb +13 -24
- data/lib/gosu/font.rb +13 -19
- data/lib/gosu/gosu.rb +61 -101
- data/lib/gosu/image.rb +34 -72
- data/lib/gosu/sample.rb +0 -1
- data/lib/gosu/song.rb +0 -1
- data/lib/gosu/text_input.rb +1 -15
- data/lib/gosu/window.rb +10 -31
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +0 -2
- data/src/Audio.cpp +16 -22
- data/src/AudioFileSDLSound.cpp +5 -5
- data/src/BinPacker.cpp +4 -5
- data/src/Bitmap.cpp +9 -16
- data/src/Buffer.cpp +14 -5
- data/src/ClipRectStack.hpp +83 -17
- data/src/Directories.cpp +1 -1
- data/src/DrawOp.hpp +17 -14
- data/src/DrawOpQueue.hpp +31 -25
- data/src/Font.cpp +1 -1
- data/src/GosuGLView.cpp +7 -1
- data/src/Graphics.cpp +25 -32
- data/src/GraphicsImpl.hpp +24 -0
- data/src/Image.cpp +2 -2
- data/src/Input.cpp +70 -66
- data/src/Macro.cpp +26 -43
- data/src/Macro.hpp +16 -22
- data/src/Math.cpp +7 -20
- data/src/OffScreenTarget.cpp +10 -3
- data/src/OpenGLContext.cpp +8 -7
- data/src/OpenGLContext.hpp +2 -2
- data/src/RenderState.hpp +54 -30
- data/src/Resolution.cpp +38 -48
- data/src/TexChunk.cpp +2 -2
- data/src/TextInput.cpp +9 -9
- data/src/Texture.cpp +1 -1
- data/src/TiledDrawable.cpp +7 -6
- data/src/TrueTypeFontUnix.cpp +9 -12
- data/src/Utility.cpp +26 -39
- data/src/UtilityWin.cpp +2 -6
- data/src/Window.cpp +34 -54
- metadata +93 -99
- data/dependencies/SDL/include/SDL3/SDL.h +0 -91
- data/dependencies/SDL/include/SDL3/SDL_assert.h +0 -710
- data/dependencies/SDL/include/SDL3/SDL_asyncio.h +0 -550
- data/dependencies/SDL/include/SDL3/SDL_atomic.h +0 -692
- data/dependencies/SDL/include/SDL3/SDL_audio.h +0 -2382
- data/dependencies/SDL/include/SDL3/SDL_begin_code.h +0 -553
- data/dependencies/SDL/include/SDL3/SDL_camera.h +0 -535
- data/dependencies/SDL/include/SDL3/SDL_clipboard.h +0 -331
- data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +0 -374
- data/dependencies/SDL/include/SDL3/SDL_dialog.h +0 -343
- data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +0 -234
- data/dependencies/SDL/include/SDL3/SDL_endian.h +0 -645
- data/dependencies/SDL/include/SDL3/SDL_error.h +0 -226
- data/dependencies/SDL/include/SDL3/SDL_events.h +0 -1651
- data/dependencies/SDL/include/SDL3/SDL_filesystem.h +0 -537
- data/dependencies/SDL/include/SDL3/SDL_gamepad.h +0 -1657
- data/dependencies/SDL/include/SDL3/SDL_gpu.h +0 -4637
- data/dependencies/SDL/include/SDL3/SDL_guid.h +0 -106
- data/dependencies/SDL/include/SDL3/SDL_haptic.h +0 -1461
- data/dependencies/SDL/include/SDL3/SDL_hidapi.h +0 -571
- data/dependencies/SDL/include/SDL3/SDL_hints.h +0 -5041
- data/dependencies/SDL/include/SDL3/SDL_init.h +0 -508
- data/dependencies/SDL/include/SDL3/SDL_intrin.h +0 -410
- data/dependencies/SDL/include/SDL3/SDL_iostream.h +0 -1379
- data/dependencies/SDL/include/SDL3/SDL_joystick.h +0 -1385
- data/dependencies/SDL/include/SDL3/SDL_keyboard.h +0 -615
- data/dependencies/SDL/include/SDL3/SDL_keycode.h +0 -348
- data/dependencies/SDL/include/SDL3/SDL_loadso.h +0 -145
- data/dependencies/SDL/include/SDL3/SDL_log.h +0 -541
- data/dependencies/SDL/include/SDL3/SDL_main.h +0 -704
- data/dependencies/SDL/include/SDL3/SDL_main_impl.h +0 -149
- data/dependencies/SDL/include/SDL3/SDL_mouse.h +0 -813
- data/dependencies/SDL/include/SDL3/SDL_mutex.h +0 -1117
- data/dependencies/SDL/include/SDL3/SDL_oldnames.h +0 -1339
- data/dependencies/SDL/include/SDL3/SDL_pen.h +0 -198
- data/dependencies/SDL/include/SDL3/SDL_pixels.h +0 -1441
- data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +0 -497
- data/dependencies/SDL/include/SDL3/SDL_process.h +0 -441
- data/dependencies/SDL/include/SDL3/SDL_properties.h +0 -572
- data/dependencies/SDL/include/SDL3/SDL_rect.h +0 -528
- data/dependencies/SDL/include/SDL3/SDL_render.h +0 -3034
- data/dependencies/SDL/include/SDL3/SDL_revision.h +0 -56
- data/dependencies/SDL/include/SDL3/SDL_sensor.h +0 -321
- data/dependencies/SDL/include/SDL3/SDL_stdinc.h +0 -6186
- data/dependencies/SDL/include/SDL3/SDL_storage.h +0 -686
- data/dependencies/SDL/include/SDL3/SDL_surface.h +0 -1769
- data/dependencies/SDL/include/SDL3/SDL_system.h +0 -840
- data/dependencies/SDL/include/SDL3/SDL_test_log.h +0 -83
- data/dependencies/SDL/include/SDL3/SDL_thread.h +0 -602
- data/dependencies/SDL/include/SDL3/SDL_time.h +0 -249
- data/dependencies/SDL/include/SDL3/SDL_timer.h +0 -454
- data/dependencies/SDL/include/SDL3/SDL_touch.h +0 -184
- data/dependencies/SDL/include/SDL3/SDL_tray.h +0 -544
- data/dependencies/SDL/include/SDL3/SDL_version.h +0 -198
- data/dependencies/SDL/include/SDL3/SDL_video.h +0 -3497
- data/dependencies/SDL/include/SDL3/SDL_vulkan.h +0 -287
- data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
- data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +0 -755
- data/lib/SDL3.dll +0 -0
- data/lib64/SDL3.dll +0 -0
- data/src/ClipRectStack.cpp +0 -38
- /data/dependencies/SDL/include/{SDL3/SDL_opengl_glext.h → SDL_opengl_glext.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2.h → SDL_opengles2_gl2.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2ext.h → SDL_opengles2_gl2ext.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2platform.h → SDL_opengles2_gl2platform.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_khrplatform.h → SDL_opengles2_khrplatform.h} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Ogg Vorbis audio decoder - v1.
|
|
1
|
+
// Ogg Vorbis audio decoder - v1.22 - public domain
|
|
2
2
|
// http://nothings.org/stb_vorbis/
|
|
3
3
|
//
|
|
4
4
|
// Original version written by Sean Barrett in 2007.
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
//
|
|
22
22
|
// Feature contributors:
|
|
23
23
|
// Dougall Johnson (sample-exact seeking)
|
|
24
|
-
// Vitaly Novichkov (sample-accurate tell)
|
|
25
24
|
//
|
|
26
25
|
// Bugfix/warning contributors:
|
|
27
26
|
// Terje Mathisen Niklas Frykholm Andy Hill
|
|
@@ -38,8 +37,6 @@
|
|
|
38
37
|
// Alice Rowan
|
|
39
38
|
//
|
|
40
39
|
// Partial history:
|
|
41
|
-
// 1.24 - 2026-11-12 - fixes
|
|
42
|
-
// 1.23 - 2026-11-08 - many fixes, support for 64-bit seek/offsets
|
|
43
40
|
// 1.22 - 2021-07-11 - various small fixes
|
|
44
41
|
// 1.21 - 2021-07-02 - fix bug for files with no comments
|
|
45
42
|
// 1.20 - 2020-07-11 - several small fixes
|
|
@@ -69,14 +66,6 @@
|
|
|
69
66
|
//
|
|
70
67
|
// See end of file for full version history.
|
|
71
68
|
|
|
72
|
-
#ifdef STB_VORBIS_NO_PULLDATA_API
|
|
73
|
-
#ifndef STB_VORBIS_NO_INTEGER_CONVERSION
|
|
74
|
-
#define STB_VORBIS_NO_INTEGER_CONVERSION
|
|
75
|
-
#endif
|
|
76
|
-
#ifndef STB_VORBIS_NO_STDIO
|
|
77
|
-
#define STB_VORBIS_NO_STDIO
|
|
78
|
-
#endif
|
|
79
|
-
#endif
|
|
80
69
|
|
|
81
70
|
//////////////////////////////////////////////////////////////////////////////
|
|
82
71
|
//
|
|
@@ -86,6 +75,10 @@
|
|
|
86
75
|
#ifndef STB_VORBIS_INCLUDE_STB_VORBIS_H
|
|
87
76
|
#define STB_VORBIS_INCLUDE_STB_VORBIS_H
|
|
88
77
|
|
|
78
|
+
#if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
|
|
79
|
+
#define STB_VORBIS_NO_STDIO 1
|
|
80
|
+
#endif
|
|
81
|
+
|
|
89
82
|
#ifndef STB_VORBIS_NO_STDIO
|
|
90
83
|
#include <stdio.h>
|
|
91
84
|
#endif
|
|
@@ -146,8 +139,6 @@ typedef struct
|
|
|
146
139
|
int max_frame_size;
|
|
147
140
|
} stb_vorbis_info;
|
|
148
141
|
|
|
149
|
-
#ifndef STB_VORBIS_NO_COMMENTS
|
|
150
|
-
|
|
151
142
|
typedef struct
|
|
152
143
|
{
|
|
153
144
|
char *vendor;
|
|
@@ -156,15 +147,11 @@ typedef struct
|
|
|
156
147
|
char **comment_list;
|
|
157
148
|
} stb_vorbis_comment;
|
|
158
149
|
|
|
159
|
-
#endif
|
|
160
|
-
|
|
161
150
|
// get general information about the file
|
|
162
151
|
extern stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f);
|
|
163
152
|
|
|
164
|
-
#ifndef STB_VORBIS_NO_COMMENTS
|
|
165
153
|
// get ogg comments
|
|
166
154
|
extern stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f);
|
|
167
|
-
#endif
|
|
168
155
|
|
|
169
156
|
// get the last error detected (clears it, too)
|
|
170
157
|
extern int stb_vorbis_get_error(stb_vorbis *f);
|
|
@@ -179,12 +166,6 @@ extern void stb_vorbis_close(stb_vorbis *f);
|
|
|
179
166
|
// NOT WORKING YET after a seek with PULLDATA API
|
|
180
167
|
extern int stb_vorbis_get_sample_offset(stb_vorbis *f);
|
|
181
168
|
|
|
182
|
-
// this function returns the count of returned samples from the beginning of the
|
|
183
|
-
// file. Functions "stb_vorbis_get_samples_*", "stb_vorbis_seek_*()" will
|
|
184
|
-
// affect the returned value. Use this call to get the accurate sample position
|
|
185
|
-
// during playback.
|
|
186
|
-
extern int stb_vorbis_get_playback_sample_offset(stb_vorbis *f);
|
|
187
|
-
|
|
188
169
|
// returns the current seek point within the file, or offset from the beginning
|
|
189
170
|
// of the memory buffer. In pushdata mode it returns 0.
|
|
190
171
|
extern unsigned int stb_vorbis_get_file_offset(stb_vorbis *f);
|
|
@@ -315,10 +296,9 @@ extern stb_vorbis * stb_vorbis_open_file_section(FILE *f, int close_handle_on_cl
|
|
|
315
296
|
// confused.
|
|
316
297
|
#endif
|
|
317
298
|
|
|
318
|
-
#ifdef
|
|
319
|
-
extern stb_vorbis *
|
|
320
|
-
extern stb_vorbis *
|
|
321
|
-
#define IO_BUFFER_SIZE 2048
|
|
299
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
300
|
+
extern stb_vorbis * stb_vorbis_open_rwops_section(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length);
|
|
301
|
+
extern stb_vorbis * stb_vorbis_open_rwops(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc);
|
|
322
302
|
#endif
|
|
323
303
|
|
|
324
304
|
extern int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number);
|
|
@@ -468,12 +448,12 @@ enum STBVorbisError
|
|
|
468
448
|
// does not compile the code for converting audio sample data from
|
|
469
449
|
// float to integer (implied by STB_VORBIS_NO_PULLDATA_API)
|
|
470
450
|
// #define STB_VORBIS_NO_INTEGER_CONVERSION
|
|
471
|
-
|
|
472
|
-
//
|
|
473
|
-
//
|
|
474
|
-
//
|
|
475
|
-
|
|
476
|
-
|
|
451
|
+
|
|
452
|
+
// STB_VORBIS_NO_FAST_SCALED_FLOAT
|
|
453
|
+
// does not use a fast float-to-int trick to accelerate float-to-int on
|
|
454
|
+
// most platforms which requires endianness be defined correctly.
|
|
455
|
+
//#define STB_VORBIS_NO_FAST_SCALED_FLOAT
|
|
456
|
+
|
|
477
457
|
|
|
478
458
|
// STB_VORBIS_MAX_CHANNELS [number]
|
|
479
459
|
// globally define this to the maximum number of channels you need.
|
|
@@ -570,26 +550,67 @@ enum STBVorbisError
|
|
|
570
550
|
// you'd ever want to do it except for debugging.
|
|
571
551
|
// #define STB_VORBIS_NO_DEFER_FLOOR
|
|
572
552
|
|
|
573
|
-
|
|
553
|
+
// STB_VORBIS_NO_COMMENTS
|
|
554
|
+
// disables reading and storing user comments
|
|
555
|
+
// #define STB_VORBIS_NO_COMMENTS
|
|
574
556
|
|
|
575
557
|
|
|
576
558
|
//////////////////////////////////////////////////////////////////////////////
|
|
577
559
|
|
|
560
|
+
#ifdef STB_VORBIS_NO_PULLDATA_API
|
|
561
|
+
#define STB_VORBIS_NO_INTEGER_CONVERSION
|
|
562
|
+
#define STB_VORBIS_NO_STDIO
|
|
563
|
+
#endif
|
|
564
|
+
|
|
565
|
+
#if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
|
|
566
|
+
#define STB_VORBIS_NO_STDIO 1
|
|
567
|
+
#endif
|
|
568
|
+
|
|
569
|
+
#ifndef STB_VORBIS_NO_INTEGER_CONVERSION
|
|
570
|
+
#ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
|
|
571
|
+
|
|
572
|
+
// only need endianness for fast-float-to-int, which we don't
|
|
573
|
+
// use for pushdata
|
|
574
|
+
|
|
575
|
+
#ifndef STB_VORBIS_BIG_ENDIAN
|
|
576
|
+
#define STB_VORBIS_ENDIAN 0
|
|
577
|
+
#else
|
|
578
|
+
#define STB_VORBIS_ENDIAN 1
|
|
579
|
+
#endif
|
|
580
|
+
|
|
581
|
+
#endif
|
|
582
|
+
#endif
|
|
583
|
+
|
|
584
|
+
|
|
578
585
|
#ifndef STB_VORBIS_NO_STDIO
|
|
579
586
|
#include <stdio.h>
|
|
580
587
|
#endif
|
|
581
588
|
|
|
582
|
-
#
|
|
583
|
-
#include <
|
|
584
|
-
#include <
|
|
585
|
-
#include <
|
|
589
|
+
#ifndef STB_VORBIS_NO_CRT
|
|
590
|
+
#include <stdlib.h>
|
|
591
|
+
#include <string.h>
|
|
592
|
+
#include <assert.h>
|
|
593
|
+
#include <math.h>
|
|
594
|
+
#else // STB_VORBIS_NO_CRT
|
|
595
|
+
#ifndef NULL
|
|
596
|
+
#define NULL 0
|
|
597
|
+
#endif
|
|
598
|
+
#ifndef malloc
|
|
599
|
+
#define malloc(s) 0
|
|
600
|
+
#endif
|
|
601
|
+
#ifndef free
|
|
602
|
+
#define free(p) ((void) 0)
|
|
603
|
+
#endif
|
|
604
|
+
#ifndef realloc
|
|
605
|
+
#define realloc(p, s) 0
|
|
606
|
+
#endif
|
|
607
|
+
#endif // STB_VORBIS_NO_CRT
|
|
608
|
+
|
|
586
609
|
#include <limits.h>
|
|
587
610
|
|
|
588
611
|
#ifndef STB_FORCEINLINE
|
|
589
|
-
#if defined(_MSC_VER)
|
|
612
|
+
#if defined(_MSC_VER)
|
|
590
613
|
#define STB_FORCEINLINE __forceinline
|
|
591
|
-
#elif defined(_MSC_VER)
|
|
592
|
-
#define STB_FORCEINLINE static __inline
|
|
593
614
|
#elif (defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2))) || defined(__clang__)
|
|
594
615
|
#define STB_FORCEINLINE static __inline __attribute__((always_inline))
|
|
595
616
|
#else
|
|
@@ -616,7 +637,7 @@ enum STBVorbisError
|
|
|
616
637
|
#define MAX_BLOCKSIZE_LOG 13 // from specification
|
|
617
638
|
#define MAX_BLOCKSIZE (1 << MAX_BLOCKSIZE_LOG)
|
|
618
639
|
|
|
619
|
-
#ifdef
|
|
640
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
620
641
|
typedef Uint8 uint8;
|
|
621
642
|
typedef Sint8 int8;
|
|
622
643
|
typedef Uint16 uint16;
|
|
@@ -624,22 +645,13 @@ typedef Sint16 int16;
|
|
|
624
645
|
typedef Uint32 uint32;
|
|
625
646
|
typedef Sint32 int32;
|
|
626
647
|
#else
|
|
627
|
-
|
|
628
|
-
#if defined B_BEOS_VERSION
|
|
629
|
-
#include <SupportDefs.h>
|
|
630
|
-
#elif defined __amigaos4__
|
|
631
|
-
#include <exec/types.h>
|
|
632
|
-
#elif defined _arch_dreamcast /* KallistiOS */
|
|
633
|
-
#include <arch/types.h>
|
|
634
|
-
#else
|
|
635
648
|
typedef unsigned char uint8;
|
|
636
649
|
typedef signed char int8;
|
|
637
650
|
typedef unsigned short uint16;
|
|
638
651
|
typedef signed short int16;
|
|
639
652
|
typedef unsigned int uint32;
|
|
640
653
|
typedef signed int int32;
|
|
641
|
-
#endif
|
|
642
|
-
#endif /* !STB_VORBIS_SDL */
|
|
654
|
+
#endif
|
|
643
655
|
|
|
644
656
|
#ifdef __has_feature
|
|
645
657
|
#if __has_feature(undefined_behavior_sanitizer)
|
|
@@ -661,8 +673,6 @@ typedef float codetype;
|
|
|
661
673
|
|
|
662
674
|
#ifdef _MSC_VER
|
|
663
675
|
#define STBV_NOTUSED(v) (void)(v)
|
|
664
|
-
#elif defined(__VBCC__)
|
|
665
|
-
#define STBV_NOTUSED(v)
|
|
666
676
|
#else
|
|
667
677
|
#define STBV_NOTUSED(v) (void)sizeof(v)
|
|
668
678
|
#endif
|
|
@@ -758,6 +768,7 @@ typedef struct
|
|
|
758
768
|
|
|
759
769
|
typedef struct
|
|
760
770
|
{
|
|
771
|
+
// https://github.com/nothings/stb/pull/1312
|
|
761
772
|
MappingChannel *chan;
|
|
762
773
|
uint16 coupling_steps;
|
|
763
774
|
uint8 submaps;
|
|
@@ -810,19 +821,15 @@ struct stb_vorbis
|
|
|
810
821
|
uint32 f_start;
|
|
811
822
|
int close_on_free;
|
|
812
823
|
#endif
|
|
813
|
-
#ifdef
|
|
814
|
-
|
|
815
|
-
uint32
|
|
816
|
-
uint32 io_virtual_pos;
|
|
817
|
-
uint32 io_buffer_pos;
|
|
818
|
-
uint32 io_buffer_fill;
|
|
819
|
-
uint8 io_buffer[IO_BUFFER_SIZE];
|
|
824
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
825
|
+
SDL_RWops *rwops;
|
|
826
|
+
uint32 rwops_start;
|
|
820
827
|
int close_on_free;
|
|
821
828
|
#endif
|
|
822
829
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
830
|
+
uint8 *stream;
|
|
831
|
+
uint8 *stream_start;
|
|
832
|
+
uint8 *stream_end;
|
|
826
833
|
|
|
827
834
|
uint32 stream_len;
|
|
828
835
|
|
|
@@ -880,9 +887,6 @@ struct stb_vorbis
|
|
|
880
887
|
uint32 current_loc; // sample location of next frame to decode
|
|
881
888
|
int current_loc_valid;
|
|
882
889
|
|
|
883
|
-
int32 current_playback_loc; // sample location of played samples
|
|
884
|
-
int current_playback_loc_valid;
|
|
885
|
-
|
|
886
890
|
// per-blocksize precomputed data
|
|
887
891
|
|
|
888
892
|
// twiddle factors
|
|
@@ -966,8 +970,6 @@ static int error(vorb *f, enum STBVorbisError e)
|
|
|
966
970
|
// given a sufficiently large block of memory, make an array of pointers to subblocks of it
|
|
967
971
|
static void *make_block_array(void *mem, int count, int size)
|
|
968
972
|
{
|
|
969
|
-
if (!mem) return NULL;
|
|
970
|
-
else {
|
|
971
973
|
int i;
|
|
972
974
|
void ** p = (void **) mem;
|
|
973
975
|
char *q = (char *) (p + count);
|
|
@@ -976,17 +978,15 @@ static void *make_block_array(void *mem, int count, int size)
|
|
|
976
978
|
q += size;
|
|
977
979
|
}
|
|
978
980
|
return p;
|
|
979
|
-
}
|
|
980
981
|
}
|
|
981
982
|
|
|
982
983
|
static void *setup_malloc(vorb *f, int sz)
|
|
983
984
|
{
|
|
984
|
-
if (sz <= 0 || INT_MAX - 7 < sz) return NULL;
|
|
985
985
|
sz = (sz+7) & ~7; // round up to nearest 8 for alignment of future allocs.
|
|
986
986
|
f->setup_memory_required += sz;
|
|
987
987
|
if (f->alloc.alloc_buffer) {
|
|
988
988
|
void *p = (char *) f->alloc.alloc_buffer + f->setup_offset;
|
|
989
|
-
if (f->
|
|
989
|
+
if (f->setup_offset + sz > f->temp_offset) return NULL;
|
|
990
990
|
f->setup_offset += sz;
|
|
991
991
|
return p;
|
|
992
992
|
}
|
|
@@ -1001,14 +1001,13 @@ static void setup_free(vorb *f, void *p)
|
|
|
1001
1001
|
|
|
1002
1002
|
static void *setup_temp_malloc(vorb *f, int sz)
|
|
1003
1003
|
{
|
|
1004
|
-
if (sz <= 0 || INT_MAX - 7 < sz) return NULL;
|
|
1005
1004
|
sz = (sz+7) & ~7; // round up to nearest 8 for alignment of future allocs.
|
|
1006
1005
|
if (f->alloc.alloc_buffer) {
|
|
1007
|
-
if (f->temp_offset
|
|
1006
|
+
if (f->temp_offset - sz < f->setup_offset) return NULL;
|
|
1008
1007
|
f->temp_offset -= sz;
|
|
1009
1008
|
return (char *) f->alloc.alloc_buffer + f->temp_offset;
|
|
1010
1009
|
}
|
|
1011
|
-
return
|
|
1010
|
+
return malloc(sz);
|
|
1012
1011
|
}
|
|
1013
1012
|
|
|
1014
1013
|
static void setup_temp_free(vorb *f, void **_p, int sz)
|
|
@@ -1062,7 +1061,7 @@ static float square(float x)
|
|
|
1062
1061
|
// @OPTIMIZE: called multiple times per-packet with "constants"; move to setup
|
|
1063
1062
|
static int ilog(int32 n)
|
|
1064
1063
|
{
|
|
1065
|
-
static
|
|
1064
|
+
static signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 };
|
|
1066
1065
|
|
|
1067
1066
|
if (n < 0) return 0; // signed n returns 0
|
|
1068
1067
|
|
|
@@ -1114,7 +1113,7 @@ static void add_entry(Codebook *c, uint32 huff_code, int symbol, int count, int
|
|
|
1114
1113
|
c->codewords [symbol] = huff_code;
|
|
1115
1114
|
} else {
|
|
1116
1115
|
c->codewords [count] = huff_code;
|
|
1117
|
-
c->codeword_lengths[count] =
|
|
1116
|
+
c->codeword_lengths[count] = len;
|
|
1118
1117
|
values [count] = symbol;
|
|
1119
1118
|
}
|
|
1120
1119
|
}
|
|
@@ -1182,7 +1181,7 @@ static void compute_accelerated_huffman(Codebook *c)
|
|
|
1182
1181
|
uint32 z = c->sparse ? bit_reverse(c->sorted_codewords[i]) : c->codewords[i];
|
|
1183
1182
|
// set table entries for all bit combinations in the higher bits
|
|
1184
1183
|
while (z < FAST_HUFFMAN_TABLE_SIZE) {
|
|
1185
|
-
c->fast_huffman[z] =
|
|
1184
|
+
c->fast_huffman[z] = i;
|
|
1186
1185
|
z += 1 << c->codeword_lengths[i];
|
|
1187
1186
|
}
|
|
1188
1187
|
}
|
|
@@ -1199,8 +1198,8 @@ static void compute_accelerated_huffman(Codebook *c)
|
|
|
1199
1198
|
|
|
1200
1199
|
static int STBV_CDECL uint32_compare(const void *p, const void *q)
|
|
1201
1200
|
{
|
|
1202
|
-
uint32 x = * (
|
|
1203
|
-
uint32 y = * (
|
|
1201
|
+
uint32 x = * (uint32 *) p;
|
|
1202
|
+
uint32 y = * (uint32 *) q;
|
|
1204
1203
|
return x < y ? -1 : x > y;
|
|
1205
1204
|
}
|
|
1206
1205
|
|
|
@@ -1242,7 +1241,7 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values)
|
|
|
1242
1241
|
// #3: for each original entry, find the sorted entry
|
|
1243
1242
|
// #1 requires extra storage, #2 is slow, #3 can use binary search!
|
|
1244
1243
|
for (i=0; i < len; ++i) {
|
|
1245
|
-
|
|
1244
|
+
int huff_len = c->sparse ? lengths[values[i]] : lengths[i];
|
|
1246
1245
|
if (include_in_sort(c,huff_len)) {
|
|
1247
1246
|
uint32 code = bit_reverse(c->codewords[i]);
|
|
1248
1247
|
int x=0, n=c->sorted_entries;
|
|
@@ -1270,7 +1269,7 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values)
|
|
|
1270
1269
|
// only run while parsing the header (3 times)
|
|
1271
1270
|
static int vorbis_validate(uint8 *data)
|
|
1272
1271
|
{
|
|
1273
|
-
static
|
|
1272
|
+
static uint8 vorbis[6] = { 'v', 'o', 'r', 'b', 'i', 's' };
|
|
1274
1273
|
return memcmp(data, vorbis, 6) == 0;
|
|
1275
1274
|
}
|
|
1276
1275
|
|
|
@@ -1282,14 +1281,12 @@ static int vorbis_validate(uint8 *data)
|
|
|
1282
1281
|
STB_NO_SANITIZE("float-cast-overflow")
|
|
1283
1282
|
static int lookup1_values(int entries, int dim)
|
|
1284
1283
|
{
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
if (
|
|
1289
|
-
++r;
|
|
1290
|
-
if (pow((double) r+1, dim) <= entriesd)
|
|
1284
|
+
int r = (int) floor(exp((float) log((float) entries) / dim));
|
|
1285
|
+
if ((int) floor(pow((float) r+1, dim)) <= entries) // (int) cast for MinGW warning;
|
|
1286
|
+
++r; // floor() to avoid _ftol() when non-CRT
|
|
1287
|
+
if (pow((float) r+1, dim) <= entries)
|
|
1291
1288
|
return -1;
|
|
1292
|
-
if (floor(pow((
|
|
1289
|
+
if ((int) floor(pow((float) r, dim)) > entries)
|
|
1293
1290
|
return -1;
|
|
1294
1291
|
return r;
|
|
1295
1292
|
}
|
|
@@ -1324,7 +1321,7 @@ static void compute_bitreverse(int n, uint16 *rev)
|
|
|
1324
1321
|
int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
|
|
1325
1322
|
int i, n8 = n >> 3;
|
|
1326
1323
|
for (i=0; i < n8; ++i)
|
|
1327
|
-
rev[i] = (
|
|
1324
|
+
rev[i] = (bit_reverse(i) >> (32-ld+3)) << 2;
|
|
1328
1325
|
}
|
|
1329
1326
|
|
|
1330
1327
|
static int init_blocksize(vorb *f, int b, int n)
|
|
@@ -1363,8 +1360,8 @@ typedef struct
|
|
|
1363
1360
|
|
|
1364
1361
|
static int STBV_CDECL point_compare(const void *p, const void *q)
|
|
1365
1362
|
{
|
|
1366
|
-
|
|
1367
|
-
|
|
1363
|
+
stbv__floor_ordering *a = (stbv__floor_ordering *) p;
|
|
1364
|
+
stbv__floor_ordering *b = (stbv__floor_ordering *) q;
|
|
1368
1365
|
return a->x < b->x ? -1 : a->x > b->x;
|
|
1369
1366
|
}
|
|
1370
1367
|
|
|
@@ -1372,7 +1369,7 @@ static int STBV_CDECL point_compare(const void *p, const void *q)
|
|
|
1372
1369
|
/////////////////////// END LEAF SETUP FUNCTIONS //////////////////////////
|
|
1373
1370
|
|
|
1374
1371
|
|
|
1375
|
-
#ifdef
|
|
1372
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
1376
1373
|
#define USE_MEMORY(z) FALSE
|
|
1377
1374
|
#elif defined(STB_VORBIS_NO_STDIO)
|
|
1378
1375
|
#define USE_MEMORY(z) TRUE
|
|
@@ -1382,30 +1379,25 @@ static int STBV_CDECL point_compare(const void *p, const void *q)
|
|
|
1382
1379
|
|
|
1383
1380
|
static uint8 get8(vorb *z)
|
|
1384
1381
|
{
|
|
1385
|
-
#ifdef
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if (z->io_buffer_fill == 0) { z->eof = TRUE; return 0; }
|
|
1390
|
-
}
|
|
1391
|
-
z->io_virtual_pos++;
|
|
1392
|
-
return z->io_buffer[z->io_buffer_pos++];
|
|
1382
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
1383
|
+
uint8 c;
|
|
1384
|
+
if (SDL_RWread(z->rwops, &c, 1, 1) != 1) { z->eof = TRUE; return 0; }
|
|
1385
|
+
return c;
|
|
1393
1386
|
|
|
1394
|
-
#else
|
|
1387
|
+
#else
|
|
1395
1388
|
if (USE_MEMORY(z)) {
|
|
1396
1389
|
if (z->stream >= z->stream_end) { z->eof = TRUE; return 0; }
|
|
1397
1390
|
return *z->stream++;
|
|
1398
1391
|
}
|
|
1392
|
+
#endif
|
|
1399
1393
|
|
|
1400
1394
|
#ifndef STB_VORBIS_NO_STDIO
|
|
1401
1395
|
{
|
|
1402
1396
|
int c = fgetc(z->f);
|
|
1403
1397
|
if (c == EOF) { z->eof = TRUE; return 0; }
|
|
1404
|
-
return
|
|
1398
|
+
return c;
|
|
1405
1399
|
}
|
|
1406
1400
|
#endif
|
|
1407
|
-
return 0; /* silence warnings */
|
|
1408
|
-
#endif /* !STB_VORBIS_SDL */
|
|
1409
1401
|
}
|
|
1410
1402
|
|
|
1411
1403
|
static uint32 get32(vorb *f)
|
|
@@ -1420,37 +1412,19 @@ static uint32 get32(vorb *f)
|
|
|
1420
1412
|
|
|
1421
1413
|
static int getn(vorb *z, uint8 *data, int n)
|
|
1422
1414
|
{
|
|
1423
|
-
#ifdef
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
if (z->io_buffer_pos >= z->io_buffer_fill) {
|
|
1428
|
-
z->io_buffer_fill = SDL_ReadIO(z->io, z->io_buffer, IO_BUFFER_SIZE);
|
|
1429
|
-
z->io_buffer_pos = 0;
|
|
1430
|
-
if (z->io_buffer_fill == 0) {
|
|
1431
|
-
z->eof = 1;
|
|
1432
|
-
return 0;
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
chunk = z->io_buffer_fill - z->io_buffer_pos;
|
|
1437
|
-
if (chunk > n) chunk = n;
|
|
1438
|
-
|
|
1439
|
-
memcpy(data, z->io_buffer + z->io_buffer_pos, chunk);
|
|
1440
|
-
z->io_buffer_pos += chunk;
|
|
1441
|
-
z->io_virtual_pos += chunk;
|
|
1442
|
-
data += chunk;
|
|
1443
|
-
n -= chunk;
|
|
1444
|
-
}
|
|
1445
|
-
return 1;
|
|
1415
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
1416
|
+
if (SDL_RWread(z->rwops, data, n, 1) == 1) return 1;
|
|
1417
|
+
z->eof = 1;
|
|
1418
|
+
return 0;
|
|
1446
1419
|
|
|
1447
|
-
#else
|
|
1420
|
+
#else
|
|
1448
1421
|
if (USE_MEMORY(z)) {
|
|
1449
1422
|
if (z->stream+n > z->stream_end) { z->eof = 1; return 0; }
|
|
1450
1423
|
memcpy(data, z->stream, n);
|
|
1451
1424
|
z->stream += n;
|
|
1452
1425
|
return 1;
|
|
1453
1426
|
}
|
|
1427
|
+
#endif
|
|
1454
1428
|
|
|
1455
1429
|
#ifndef STB_VORBIS_NO_STDIO
|
|
1456
1430
|
if (fread(data, n, 1, z->f) == 1)
|
|
@@ -1460,33 +1434,29 @@ static int getn(vorb *z, uint8 *data, int n)
|
|
|
1460
1434
|
return 0;
|
|
1461
1435
|
}
|
|
1462
1436
|
#endif
|
|
1463
|
-
return 0; /* silence warnings */
|
|
1464
|
-
#endif /* !STB_VORBIS_SDL */
|
|
1465
1437
|
}
|
|
1466
1438
|
|
|
1467
|
-
static int set_file_offset(stb_vorbis *f, unsigned int loc);
|
|
1468
|
-
|
|
1469
1439
|
static void skip(vorb *z, int n)
|
|
1470
1440
|
{
|
|
1471
|
-
#ifdef
|
|
1472
|
-
|
|
1473
|
-
|
|
1441
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
1442
|
+
SDL_RWseek(z->rwops, n, RW_SEEK_CUR);
|
|
1443
|
+
|
|
1444
|
+
#else
|
|
1474
1445
|
if (USE_MEMORY(z)) {
|
|
1475
1446
|
z->stream += n;
|
|
1476
1447
|
if (z->stream >= z->stream_end) z->eof = 1;
|
|
1477
1448
|
return;
|
|
1478
1449
|
}
|
|
1450
|
+
#endif
|
|
1451
|
+
|
|
1479
1452
|
#ifndef STB_VORBIS_NO_STDIO
|
|
1480
1453
|
{
|
|
1481
1454
|
long x = ftell(z->f);
|
|
1482
1455
|
fseek(z->f, x+n, SEEK_SET);
|
|
1483
1456
|
}
|
|
1484
1457
|
#endif
|
|
1485
|
-
#endif /* !STB_VORBIS_SDL */
|
|
1486
1458
|
}
|
|
1487
1459
|
|
|
1488
|
-
#ifndef STB_VORBIS_NO_PULLDATA_API
|
|
1489
|
-
|
|
1490
1460
|
static int set_file_offset(stb_vorbis *f, unsigned int loc)
|
|
1491
1461
|
{
|
|
1492
1462
|
#ifndef STB_VORBIS_NO_PUSHDATA_API
|
|
@@ -1494,36 +1464,22 @@ static int set_file_offset(stb_vorbis *f, unsigned int loc)
|
|
|
1494
1464
|
#endif
|
|
1495
1465
|
f->eof = 0;
|
|
1496
1466
|
|
|
1497
|
-
#ifdef
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
uint32 buffer_end = buffer_start + f->io_buffer_fill;
|
|
1501
|
-
f->io_virtual_pos = loc;
|
|
1502
|
-
|
|
1503
|
-
// Move within buffer if possible
|
|
1504
|
-
if (loc >= buffer_start && loc < buffer_end)
|
|
1505
|
-
{
|
|
1506
|
-
f->io_buffer_pos = loc - buffer_start;
|
|
1507
|
-
return 1;
|
|
1508
|
-
}
|
|
1509
|
-
|
|
1510
|
-
io_pos = loc + f->io_start;
|
|
1511
|
-
if (io_pos < loc || loc >= 0x80000000) {
|
|
1512
|
-
io_pos = 0x7fffffff;
|
|
1467
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
1468
|
+
if (loc + f->rwops_start < loc || loc >= 0x80000000) {
|
|
1469
|
+
loc = 0x7fffffff;
|
|
1513
1470
|
f->eof = 1;
|
|
1471
|
+
} else {
|
|
1472
|
+
loc += f->rwops_start;
|
|
1514
1473
|
}
|
|
1515
|
-
|
|
1516
|
-
f->io_buffer_pos = f->io_buffer_fill = 0; // Invalidate buffer
|
|
1517
|
-
if (SDL_SeekIO(f->io, io_pos, SDL_IO_SEEK_SET) != -1)
|
|
1474
|
+
if (SDL_RWseek(f->rwops, loc, RW_SEEK_SET) != -1)
|
|
1518
1475
|
return 1;
|
|
1519
1476
|
f->eof = 1;
|
|
1520
|
-
|
|
1477
|
+
SDL_RWseek(f->rwops, f->rwops_start, RW_SEEK_END);
|
|
1521
1478
|
return 0;
|
|
1522
|
-
}
|
|
1523
1479
|
|
|
1524
|
-
#else
|
|
1480
|
+
#else
|
|
1525
1481
|
if (USE_MEMORY(f)) {
|
|
1526
|
-
if (loc >= f->
|
|
1482
|
+
if (f->stream_start + loc >= f->stream_end || f->stream_start + loc < f->stream_start) {
|
|
1527
1483
|
f->stream = f->stream_end;
|
|
1528
1484
|
f->eof = 1;
|
|
1529
1485
|
return 0;
|
|
@@ -1532,8 +1488,10 @@ static int set_file_offset(stb_vorbis *f, unsigned int loc)
|
|
|
1532
1488
|
return 1;
|
|
1533
1489
|
}
|
|
1534
1490
|
}
|
|
1491
|
+
#endif
|
|
1492
|
+
|
|
1535
1493
|
#ifndef STB_VORBIS_NO_STDIO
|
|
1536
|
-
if (loc
|
|
1494
|
+
if (loc + f->f_start < loc || loc >= 0x80000000) {
|
|
1537
1495
|
loc = 0x7fffffff;
|
|
1538
1496
|
f->eof = 1;
|
|
1539
1497
|
} else {
|
|
@@ -1545,14 +1503,10 @@ static int set_file_offset(stb_vorbis *f, unsigned int loc)
|
|
|
1545
1503
|
fseek(f->f, f->f_start, SEEK_END);
|
|
1546
1504
|
return 0;
|
|
1547
1505
|
#endif
|
|
1548
|
-
return 0; /* silence warnings */
|
|
1549
|
-
#endif /* !STB_VORBIS_SDL */
|
|
1550
1506
|
}
|
|
1551
1507
|
|
|
1552
|
-
#endif // STBI_VORBIS_NO_PULLDATA_API
|
|
1553
1508
|
|
|
1554
|
-
|
|
1555
|
-
static const uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 };
|
|
1509
|
+
static uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 };
|
|
1556
1510
|
|
|
1557
1511
|
static int capture_pattern(vorb *f)
|
|
1558
1512
|
{
|
|
@@ -1664,7 +1618,7 @@ static int maybe_start_packet(vorb *f)
|
|
|
1664
1618
|
|
|
1665
1619
|
static int next_segment(vorb *f)
|
|
1666
1620
|
{
|
|
1667
|
-
|
|
1621
|
+
int len;
|
|
1668
1622
|
if (f->last_seg) return 0;
|
|
1669
1623
|
if (f->next_seg == -1) {
|
|
1670
1624
|
f->last_seg_which = f->segment_count-1; // in case start_page fails
|
|
@@ -1708,10 +1662,11 @@ static int get8_packet(vorb *f)
|
|
|
1708
1662
|
#ifndef STB_VORBIS_NO_COMMENTS
|
|
1709
1663
|
static int get32_packet(vorb *f)
|
|
1710
1664
|
{
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1665
|
+
uint32 x;
|
|
1666
|
+
x = get8_packet(f);
|
|
1667
|
+
x += get8_packet(f) << 8;
|
|
1668
|
+
x += get8_packet(f) << 16;
|
|
1669
|
+
x += (uint32) get8_packet(f) << 24;
|
|
1715
1670
|
return x;
|
|
1716
1671
|
}
|
|
1717
1672
|
#endif
|
|
@@ -1737,12 +1692,12 @@ static uint32 get_bits(vorb *f, int n)
|
|
|
1737
1692
|
}
|
|
1738
1693
|
if (f->valid_bits == 0) f->acc = 0;
|
|
1739
1694
|
while (f->valid_bits < n) {
|
|
1740
|
-
int
|
|
1741
|
-
if (
|
|
1695
|
+
int z = get8_packet_raw(f);
|
|
1696
|
+
if (z == EOP) {
|
|
1742
1697
|
f->valid_bits = INVALID_BITS;
|
|
1743
1698
|
return 0;
|
|
1744
1699
|
}
|
|
1745
|
-
f->acc +=
|
|
1700
|
+
f->acc += z << f->valid_bits;
|
|
1746
1701
|
f->valid_bits += 8;
|
|
1747
1702
|
}
|
|
1748
1703
|
}
|
|
@@ -1822,12 +1777,10 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c)
|
|
|
1822
1777
|
// if small, linear search
|
|
1823
1778
|
assert(!c->sparse);
|
|
1824
1779
|
for (i=0; i < c->entries; ++i) {
|
|
1825
|
-
uint32 mask;
|
|
1826
1780
|
if (c->codeword_lengths[i] == NO_CODE) continue;
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
if (c->codewords[i] == (f->acc & mask)) {
|
|
1781
|
+
/* unsigned left shift for 32-bit codewords.
|
|
1782
|
+
* https://github.com/nothings/stb/issues/1168 */
|
|
1783
|
+
if (c->codewords[i] == (f->acc & ((1U << c->codeword_lengths[i])-1))) {
|
|
1831
1784
|
if (f->valid_bits >= c->codeword_lengths[i]) {
|
|
1832
1785
|
f->acc >>= c->codeword_lengths[i];
|
|
1833
1786
|
f->valid_bits -= c->codeword_lengths[i];
|
|
@@ -1851,9 +1804,9 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c)
|
|
|
1851
1804
|
var = f->acc & FAST_HUFFMAN_TABLE_MASK; \
|
|
1852
1805
|
var = c->fast_huffman[var]; \
|
|
1853
1806
|
if (var >= 0) { \
|
|
1854
|
-
int
|
|
1855
|
-
f->acc >>=
|
|
1856
|
-
f->valid_bits -=
|
|
1807
|
+
int n = c->codeword_lengths[var]; \
|
|
1808
|
+
f->acc >>= n; \
|
|
1809
|
+
f->valid_bits -= n; \
|
|
1857
1810
|
if (f->valid_bits < 0) { f->valid_bits = 0; var = -1; } \
|
|
1858
1811
|
} else { \
|
|
1859
1812
|
var = codebook_decode_scalar_raw(f,c); \
|
|
@@ -1884,7 +1837,7 @@ static int codebook_decode_scalar(vorb *f, Codebook *c)
|
|
|
1884
1837
|
|
|
1885
1838
|
#define DECODE(var,f,c) \
|
|
1886
1839
|
DECODE_RAW(var,f,c) \
|
|
1887
|
-
if (c->sparse
|
|
1840
|
+
if (c->sparse) var = c->sorted_values[var];
|
|
1888
1841
|
|
|
1889
1842
|
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
|
|
1890
1843
|
#define DECODE_VQ(var,f,c) DECODE_RAW(var,f,c)
|
|
@@ -2019,7 +1972,7 @@ static int codebook_decode_deinterleave_repeat(vorb *f, Codebook *c, float **out
|
|
|
2019
1972
|
// buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter),
|
|
2020
1973
|
// and the length we'll be using (effective)
|
|
2021
1974
|
if (c_inter + p_inter*ch + effective > len * ch) {
|
|
2022
|
-
effective = len*ch - p_inter*ch
|
|
1975
|
+
effective = len*ch - (p_inter*ch + c_inter);
|
|
2023
1976
|
}
|
|
2024
1977
|
|
|
2025
1978
|
#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
|
|
@@ -2074,7 +2027,7 @@ static int predict_point(int x, int x0, int x1, int y0, int y1)
|
|
|
2074
2027
|
}
|
|
2075
2028
|
|
|
2076
2029
|
// the following table is block-copied from the specification
|
|
2077
|
-
static
|
|
2030
|
+
static float inverse_db_table[256] =
|
|
2078
2031
|
{
|
|
2079
2032
|
1.0649863e-07f, 1.1341951e-07f, 1.2079015e-07f, 1.2863978e-07f,
|
|
2080
2033
|
1.3699951e-07f, 1.4590251e-07f, 1.5538408e-07f, 1.6548181e-07f,
|
|
@@ -2198,7 +2151,7 @@ STB_FORCEINLINE void draw_line(float *output, int x0, int y0, int x1, int y1, in
|
|
|
2198
2151
|
ady -= abs(base) * adx;
|
|
2199
2152
|
if (x1 > n) x1 = n;
|
|
2200
2153
|
if (x < x1) {
|
|
2201
|
-
LINE_OP(output[x], inverse_db_table[
|
|
2154
|
+
LINE_OP(output[x], inverse_db_table[y&255]);
|
|
2202
2155
|
for (++x; x < x1; ++x) {
|
|
2203
2156
|
err += ady;
|
|
2204
2157
|
if (err >= adx) {
|
|
@@ -2206,7 +2159,7 @@ STB_FORCEINLINE void draw_line(float *output, int x0, int y0, int x1, int y1, in
|
|
|
2206
2159
|
y += sy;
|
|
2207
2160
|
} else
|
|
2208
2161
|
y += base;
|
|
2209
|
-
LINE_OP(output[x], inverse_db_table[
|
|
2162
|
+
LINE_OP(output[x], inverse_db_table[y&255]);
|
|
2210
2163
|
}
|
|
2211
2164
|
}
|
|
2212
2165
|
}
|
|
@@ -2237,8 +2190,9 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
|
2237
2190
|
int i,j,pass;
|
|
2238
2191
|
Residue *r = f->residue_config + rn;
|
|
2239
2192
|
int rtype = f->residue_types[rn];
|
|
2240
|
-
int
|
|
2241
|
-
|
|
2193
|
+
int c = r->classbook;
|
|
2194
|
+
int classwords = f->codebooks[c].dimensions;
|
|
2195
|
+
unsigned int actual_size = rtype == 2 ? n*2 : n;
|
|
2242
2196
|
unsigned int limit_r_begin = (r->begin < actual_size ? r->begin : actual_size);
|
|
2243
2197
|
unsigned int limit_r_end = (r->end < actual_size ? r->end : actual_size);
|
|
2244
2198
|
int n_read = limit_r_end - limit_r_begin;
|
|
@@ -2267,8 +2221,8 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
|
2267
2221
|
int pcount = 0, class_set = 0;
|
|
2268
2222
|
if (ch == 2) {
|
|
2269
2223
|
while (pcount < part_read) {
|
|
2270
|
-
int
|
|
2271
|
-
int c_inter = (
|
|
2224
|
+
int z = r->begin + pcount*r->part_size;
|
|
2225
|
+
int c_inter = (z & 1), p_inter = z>>1;
|
|
2272
2226
|
if (pass == 0) {
|
|
2273
2227
|
Codebook *c = f->codebooks+r->classbook;
|
|
2274
2228
|
int q;
|
|
@@ -2313,8 +2267,8 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
|
2313
2267
|
}
|
|
2314
2268
|
} else if (ch > 2) {
|
|
2315
2269
|
while (pcount < part_read) {
|
|
2316
|
-
int
|
|
2317
|
-
int c_inter =
|
|
2270
|
+
int z = r->begin + pcount*r->part_size;
|
|
2271
|
+
int c_inter = z % ch, p_inter = z/ch;
|
|
2318
2272
|
if (pass == 0) {
|
|
2319
2273
|
Codebook *c = f->codebooks+r->classbook;
|
|
2320
2274
|
int q;
|
|
@@ -2390,8 +2344,9 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
|
2390
2344
|
if (b >= 0) {
|
|
2391
2345
|
float *target = residue_buffers[j];
|
|
2392
2346
|
int offset = r->begin + pcount * r->part_size;
|
|
2347
|
+
int n = r->part_size;
|
|
2393
2348
|
Codebook *book = f->codebooks + b;
|
|
2394
|
-
if (!residue_decode(f, book, target, offset,
|
|
2349
|
+
if (!residue_decode(f, book, target, offset, n, rtype))
|
|
2395
2350
|
goto done;
|
|
2396
2351
|
}
|
|
2397
2352
|
}
|
|
@@ -3229,7 +3184,7 @@ static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *f
|
|
|
3229
3184
|
if (lx < n2) {
|
|
3230
3185
|
// optimization of: draw_line(target, lx,ly, n,ly, n2);
|
|
3231
3186
|
for (j=lx; j < n2; ++j)
|
|
3232
|
-
LINE_OP(target[j], inverse_db_table[ly
|
|
3187
|
+
LINE_OP(target[j], inverse_db_table[ly]);
|
|
3233
3188
|
CHECK(f);
|
|
3234
3189
|
}
|
|
3235
3190
|
}
|
|
@@ -3335,12 +3290,12 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
|
3335
3290
|
if (get_bits(f, 1)) {
|
|
3336
3291
|
short *finalY;
|
|
3337
3292
|
uint8 step2_flag[256];
|
|
3338
|
-
static
|
|
3293
|
+
static int range_list[4] = { 256, 128, 86, 64 };
|
|
3339
3294
|
int range = range_list[g->floor1_multiplier-1];
|
|
3340
3295
|
int offset = 2;
|
|
3341
3296
|
finalY = f->finalY[i];
|
|
3342
|
-
finalY[0] =
|
|
3343
|
-
finalY[1] =
|
|
3297
|
+
finalY[0] = get_bits(f, ilog(range)-1);
|
|
3298
|
+
finalY[1] = get_bits(f, ilog(range)-1);
|
|
3344
3299
|
for (j=0; j < g->partitions; ++j) {
|
|
3345
3300
|
int pclass = g->partition_class_list[j];
|
|
3346
3301
|
int cdim = g->class_dimensions[pclass];
|
|
@@ -3358,7 +3313,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
|
3358
3313
|
int temp;
|
|
3359
3314
|
Codebook *c = f->codebooks + book;
|
|
3360
3315
|
DECODE(temp,f,c);
|
|
3361
|
-
finalY[offset++] =
|
|
3316
|
+
finalY[offset++] = temp;
|
|
3362
3317
|
} else
|
|
3363
3318
|
finalY[offset++] = 0;
|
|
3364
3319
|
}
|
|
@@ -3383,17 +3338,17 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
|
3383
3338
|
step2_flag[j] = 1;
|
|
3384
3339
|
if (val >= room)
|
|
3385
3340
|
if (highroom > lowroom)
|
|
3386
|
-
finalY[j] =
|
|
3341
|
+
finalY[j] = val - lowroom + pred;
|
|
3387
3342
|
else
|
|
3388
|
-
finalY[j] =
|
|
3343
|
+
finalY[j] = pred - val + highroom - 1;
|
|
3389
3344
|
else
|
|
3390
3345
|
if (val & 1)
|
|
3391
|
-
finalY[j] =
|
|
3346
|
+
finalY[j] = pred - ((val+1)>>1);
|
|
3392
3347
|
else
|
|
3393
|
-
finalY[j] =
|
|
3348
|
+
finalY[j] = pred + (val>>1);
|
|
3394
3349
|
} else {
|
|
3395
3350
|
step2_flag[j] = 0;
|
|
3396
|
-
finalY[j] =
|
|
3351
|
+
finalY[j] = pred;
|
|
3397
3352
|
}
|
|
3398
3353
|
}
|
|
3399
3354
|
|
|
@@ -3457,22 +3412,23 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
|
3457
3412
|
|
|
3458
3413
|
// INVERSE COUPLING
|
|
3459
3414
|
for (i = map->coupling_steps-1; i >= 0; --i) {
|
|
3460
|
-
|
|
3461
|
-
float *
|
|
3415
|
+
int n2 = n >> 1;
|
|
3416
|
+
float *m = f->channel_buffers[map->chan[i].magnitude];
|
|
3417
|
+
float *a = f->channel_buffers[map->chan[i].angle ];
|
|
3462
3418
|
for (j=0; j < n2; ++j) {
|
|
3463
3419
|
float a2,m2;
|
|
3464
|
-
if (
|
|
3465
|
-
if (
|
|
3466
|
-
m2 =
|
|
3420
|
+
if (m[j] > 0)
|
|
3421
|
+
if (a[j] > 0)
|
|
3422
|
+
m2 = m[j], a2 = m[j] - a[j];
|
|
3467
3423
|
else
|
|
3468
|
-
a2 =
|
|
3424
|
+
a2 = m[j], m2 = m[j] + a[j];
|
|
3469
3425
|
else
|
|
3470
|
-
if (
|
|
3471
|
-
m2 =
|
|
3426
|
+
if (a[j] > 0)
|
|
3427
|
+
m2 = m[j], a2 = m[j] + a[j];
|
|
3472
3428
|
else
|
|
3473
|
-
a2 =
|
|
3474
|
-
|
|
3475
|
-
|
|
3429
|
+
a2 = m[j], m2 = m[j] - a[j];
|
|
3430
|
+
m[j] = m2;
|
|
3431
|
+
a[j] = a2;
|
|
3476
3432
|
}
|
|
3477
3433
|
}
|
|
3478
3434
|
CHECK(f);
|
|
@@ -3594,7 +3550,7 @@ static int vorbis_finish_frame(stb_vorbis *f, int len, int left, int right)
|
|
|
3594
3550
|
|
|
3595
3551
|
// mixin from previous window
|
|
3596
3552
|
if (f->previous_length) {
|
|
3597
|
-
int n = f->previous_length;
|
|
3553
|
+
int i,j, n = f->previous_length;
|
|
3598
3554
|
float *w = get_window(f, n);
|
|
3599
3555
|
if (w == NULL) return 0;
|
|
3600
3556
|
for (i=0; i < f->channels; ++i) {
|
|
@@ -3634,18 +3590,14 @@ static int vorbis_finish_frame(stb_vorbis *f, int len, int left, int right)
|
|
|
3634
3590
|
return right - left;
|
|
3635
3591
|
}
|
|
3636
3592
|
|
|
3637
|
-
#ifndef STB_VORBIS_NO_PULLDATA_API
|
|
3638
3593
|
static int vorbis_pump_first_frame(stb_vorbis *f)
|
|
3639
3594
|
{
|
|
3640
3595
|
int len, right, left, res;
|
|
3641
3596
|
res = vorbis_decode_packet(f, &len, &left, &right);
|
|
3642
3597
|
if (res)
|
|
3643
3598
|
vorbis_finish_frame(f, len, left, right);
|
|
3644
|
-
f->current_playback_loc = 0;
|
|
3645
|
-
f->current_playback_loc_valid = TRUE;
|
|
3646
3599
|
return res;
|
|
3647
3600
|
}
|
|
3648
|
-
#endif
|
|
3649
3601
|
|
|
3650
3602
|
#ifndef STB_VORBIS_NO_PUSHDATA_API
|
|
3651
3603
|
static int is_whole_packet_present(stb_vorbis *f)
|
|
@@ -3659,7 +3611,7 @@ static int is_whole_packet_present(stb_vorbis *f)
|
|
|
3659
3611
|
// of state to restore (primarily the page segment table)
|
|
3660
3612
|
|
|
3661
3613
|
int s = f->next_seg, first = TRUE;
|
|
3662
|
-
|
|
3614
|
+
uint8 *p = f->stream;
|
|
3663
3615
|
|
|
3664
3616
|
if (s != -1) { // if we're not starting the packet with a 'continue on next page' flag
|
|
3665
3617
|
for (; s < f->segment_count; ++s) {
|
|
@@ -3674,7 +3626,7 @@ static int is_whole_packet_present(stb_vorbis *f)
|
|
|
3674
3626
|
first = FALSE;
|
|
3675
3627
|
}
|
|
3676
3628
|
for (; s == -1;) {
|
|
3677
|
-
|
|
3629
|
+
uint8 *q;
|
|
3678
3630
|
int n;
|
|
3679
3631
|
|
|
3680
3632
|
// check that we have the page header ready
|
|
@@ -3709,8 +3661,6 @@ static int is_whole_packet_present(stb_vorbis *f)
|
|
|
3709
3661
|
}
|
|
3710
3662
|
#endif // !STB_VORBIS_NO_PUSHDATA_API
|
|
3711
3663
|
|
|
3712
|
-
#define CODEBOOK_LIMIT (1 << 18)
|
|
3713
|
-
|
|
3714
3664
|
static int start_decoder(vorb *f)
|
|
3715
3665
|
{
|
|
3716
3666
|
uint8 header[6], x,y;
|
|
@@ -3763,9 +3713,8 @@ static int start_decoder(vorb *f)
|
|
|
3763
3713
|
log1 = x >> 4;
|
|
3764
3714
|
f->blocksize_0 = 1 << log0;
|
|
3765
3715
|
f->blocksize_1 = 1 << log1;
|
|
3766
|
-
|
|
3767
|
-
if (
|
|
3768
|
-
if (log1 < 8 || log1 > 13) return error(f, VORBIS_invalid_setup);
|
|
3716
|
+
if (log0 < 6 || log0 > 13) return error(f, VORBIS_invalid_setup);
|
|
3717
|
+
if (log1 < 6 || log1 > 13) return error(f, VORBIS_invalid_setup);
|
|
3769
3718
|
if (log0 > log1) return error(f, VORBIS_invalid_setup);
|
|
3770
3719
|
}
|
|
3771
3720
|
|
|
@@ -3782,15 +3731,14 @@ static int start_decoder(vorb *f)
|
|
|
3782
3731
|
if (!next_segment(f)) return FALSE;
|
|
3783
3732
|
|
|
3784
3733
|
if (get8_packet(f) != VORBIS_packet_comment) return error(f, VORBIS_invalid_setup);
|
|
3785
|
-
for (i=0; i < 6; ++i) header[i] =
|
|
3734
|
+
for (i=0; i < 6; ++i) header[i] = get8_packet(f);
|
|
3786
3735
|
if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup);
|
|
3787
3736
|
//file vendor
|
|
3788
3737
|
len = get32_packet(f);
|
|
3789
|
-
if (len < 0 || len == INT_MAX) return error(f, VORBIS_invalid_setup);
|
|
3790
3738
|
f->vendor = (char*)setup_malloc(f, sizeof(char) * (len+1));
|
|
3791
3739
|
if (f->vendor == NULL) return error(f, VORBIS_outofmem);
|
|
3792
3740
|
for(i=0; i < len; ++i) {
|
|
3793
|
-
f->vendor[i] =
|
|
3741
|
+
f->vendor[i] = get8_packet(f);
|
|
3794
3742
|
}
|
|
3795
3743
|
f->vendor[len] = (char)'\0';
|
|
3796
3744
|
//user comments
|
|
@@ -3798,11 +3746,8 @@ static int start_decoder(vorb *f)
|
|
|
3798
3746
|
f->comment_list = NULL;
|
|
3799
3747
|
if (f->comment_list_length > 0)
|
|
3800
3748
|
{
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
f->comment_list = (char**) setup_malloc(f, len);
|
|
3804
|
-
if (f->comment_list == NULL) { f->comment_list_length = 0; return error(f, VORBIS_outofmem); }
|
|
3805
|
-
memset(f->comment_list, 0, len);
|
|
3749
|
+
f->comment_list = (char**) setup_malloc(f, sizeof(char*) * (f->comment_list_length));
|
|
3750
|
+
if (f->comment_list == NULL) return error(f, VORBIS_outofmem);
|
|
3806
3751
|
}
|
|
3807
3752
|
|
|
3808
3753
|
for(i=0; i < f->comment_list_length; ++i) {
|
|
@@ -3811,13 +3756,13 @@ static int start_decoder(vorb *f)
|
|
|
3811
3756
|
if (f->comment_list[i] == NULL) return error(f, VORBIS_outofmem);
|
|
3812
3757
|
|
|
3813
3758
|
for(j=0; j < len; ++j) {
|
|
3814
|
-
f->comment_list[i][j] =
|
|
3759
|
+
f->comment_list[i][j] = get8_packet(f);
|
|
3815
3760
|
}
|
|
3816
3761
|
f->comment_list[i][len] = (char)'\0';
|
|
3817
3762
|
}
|
|
3818
3763
|
|
|
3819
3764
|
// framing_flag
|
|
3820
|
-
x =
|
|
3765
|
+
x = get8_packet(f);
|
|
3821
3766
|
if (!(x & 1)) return error(f, VORBIS_invalid_setup);
|
|
3822
3767
|
|
|
3823
3768
|
|
|
@@ -3848,7 +3793,7 @@ static int start_decoder(vorb *f)
|
|
|
3848
3793
|
crc32_init(); // always init it, to avoid multithread race conditions
|
|
3849
3794
|
|
|
3850
3795
|
if (get8_packet(f) != VORBIS_packet_setup) return error(f, VORBIS_invalid_setup);
|
|
3851
|
-
for (i=0; i < 6; ++i) header[i] =
|
|
3796
|
+
for (i=0; i < 6; ++i) header[i] = get8_packet(f);
|
|
3852
3797
|
if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup);
|
|
3853
3798
|
|
|
3854
3799
|
// codebooks
|
|
@@ -3865,19 +3810,18 @@ static int start_decoder(vorb *f)
|
|
|
3865
3810
|
uint8 *lengths;
|
|
3866
3811
|
Codebook *c = f->codebooks+i;
|
|
3867
3812
|
CHECK(f);
|
|
3868
|
-
x =
|
|
3869
|
-
x =
|
|
3870
|
-
x =
|
|
3871
|
-
x =
|
|
3813
|
+
x = get_bits(f, 8); if (x != 0x42) return error(f, VORBIS_invalid_setup);
|
|
3814
|
+
x = get_bits(f, 8); if (x != 0x43) return error(f, VORBIS_invalid_setup);
|
|
3815
|
+
x = get_bits(f, 8); if (x != 0x56) return error(f, VORBIS_invalid_setup);
|
|
3816
|
+
x = get_bits(f, 8);
|
|
3872
3817
|
c->dimensions = (get_bits(f, 8)<<8) + x;
|
|
3873
|
-
x =
|
|
3874
|
-
y =
|
|
3818
|
+
x = get_bits(f, 8);
|
|
3819
|
+
y = get_bits(f, 8);
|
|
3875
3820
|
c->entries = (get_bits(f, 8)<<16) + (y<<8) + x;
|
|
3876
3821
|
ordered = get_bits(f,1);
|
|
3877
|
-
c->sparse = ordered ? 0 :
|
|
3822
|
+
c->sparse = ordered ? 0 : get_bits(f,1);
|
|
3878
3823
|
|
|
3879
3824
|
if (c->dimensions == 0 && c->entries != 0) return error(f, VORBIS_invalid_setup);
|
|
3880
|
-
if (c->entries && CODEBOOK_LIMIT / c->entries < c->dimensions) return error(f, VORBIS_invalid_setup);
|
|
3881
3825
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
3882
3826
|
|
|
3883
3827
|
if (c->sparse) {
|
|
@@ -3906,7 +3850,7 @@ static int start_decoder(vorb *f)
|
|
|
3906
3850
|
int present = c->sparse ? get_bits(f,1) : 1;
|
|
3907
3851
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
3908
3852
|
if (present) {
|
|
3909
|
-
lengths[j] =
|
|
3853
|
+
lengths[j] = get_bits(f, 5) + 1;
|
|
3910
3854
|
++total;
|
|
3911
3855
|
if (lengths[j] == 32) return error(f, VORBIS_invalid_setup);
|
|
3912
3856
|
} else {
|
|
@@ -3991,18 +3935,18 @@ static int start_decoder(vorb *f)
|
|
|
3991
3935
|
compute_accelerated_huffman(c);
|
|
3992
3936
|
|
|
3993
3937
|
CHECK(f);
|
|
3994
|
-
c->lookup_type =
|
|
3938
|
+
c->lookup_type = get_bits(f, 4);
|
|
3995
3939
|
if (c->lookup_type > 2) return error(f, VORBIS_invalid_setup);
|
|
3996
3940
|
if (c->lookup_type > 0) {
|
|
3997
3941
|
uint16 *mults;
|
|
3998
3942
|
c->minimum_value = float32_unpack(get_bits(f, 32));
|
|
3999
3943
|
c->delta_value = float32_unpack(get_bits(f, 32));
|
|
4000
|
-
c->value_bits =
|
|
4001
|
-
c->sequence_p =
|
|
3944
|
+
c->value_bits = get_bits(f, 4)+1;
|
|
3945
|
+
c->sequence_p = get_bits(f,1);
|
|
4002
3946
|
if (c->lookup_type == 1) {
|
|
4003
|
-
int
|
|
4004
|
-
if (
|
|
4005
|
-
c->lookup_values = (uint32)
|
|
3947
|
+
int values = lookup1_values(c->entries, c->dimensions);
|
|
3948
|
+
if (values < 0) return error(f, VORBIS_invalid_setup);
|
|
3949
|
+
c->lookup_values = (uint32) values;
|
|
4006
3950
|
} else {
|
|
4007
3951
|
/* unsigned multiply to suppress (legitimate) warning.
|
|
4008
3952
|
* https://github.com/nothings/stb/issues/1168 */
|
|
@@ -4015,12 +3959,12 @@ static int start_decoder(vorb *f)
|
|
|
4015
3959
|
for (j=0; j < (int) c->lookup_values; ++j) {
|
|
4016
3960
|
int q = get_bits(f, c->value_bits);
|
|
4017
3961
|
if (f->valid_bits < 0) return error(f, VORBIS_invalid_setup);
|
|
4018
|
-
mults[j] =
|
|
3962
|
+
mults[j] = q;
|
|
4019
3963
|
}
|
|
4020
3964
|
|
|
4021
3965
|
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
|
|
4022
3966
|
if (c->lookup_type == 1) {
|
|
4023
|
-
int
|
|
3967
|
+
int len, sparse = c->sparse;
|
|
4024
3968
|
float last=0;
|
|
4025
3969
|
// pre-expand the lookup1-style multiplicands, to avoid a divide in the inner loop
|
|
4026
3970
|
if (sparse) {
|
|
@@ -4029,8 +3973,8 @@ static int start_decoder(vorb *f)
|
|
|
4029
3973
|
} else
|
|
4030
3974
|
c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->entries * c->dimensions);
|
|
4031
3975
|
if (c->multiplicands == NULL) return error(f, VORBIS_outofmem);
|
|
4032
|
-
|
|
4033
|
-
for (j=0; j <
|
|
3976
|
+
len = sparse ? c->sorted_entries : c->entries;
|
|
3977
|
+
for (j=0; j < len; ++j) {
|
|
4034
3978
|
unsigned int z = sparse ? c->sorted_values[j] : j;
|
|
4035
3979
|
unsigned int div=1;
|
|
4036
3980
|
for (k=0; k < c->dimensions; ++k) {
|
|
@@ -4075,7 +4019,7 @@ static int start_decoder(vorb *f)
|
|
|
4075
4019
|
|
|
4076
4020
|
// time domain transfers (notused)
|
|
4077
4021
|
|
|
4078
|
-
x =
|
|
4022
|
+
x = get_bits(f, 6) + 1;
|
|
4079
4023
|
for (i=0; i < x; ++i) {
|
|
4080
4024
|
uint32 z = get_bits(f, 16);
|
|
4081
4025
|
if (z != 0) return error(f, VORBIS_invalid_setup);
|
|
@@ -4087,35 +4031,35 @@ static int start_decoder(vorb *f)
|
|
|
4087
4031
|
f->floor_config = (Floor *) setup_malloc(f, f->floor_count * sizeof(*f->floor_config));
|
|
4088
4032
|
if (f->floor_config == NULL) return error(f, VORBIS_outofmem);
|
|
4089
4033
|
for (i=0; i < f->floor_count; ++i) {
|
|
4090
|
-
f->floor_types[i] =
|
|
4034
|
+
f->floor_types[i] = get_bits(f, 16);
|
|
4091
4035
|
if (f->floor_types[i] > 1) return error(f, VORBIS_invalid_setup);
|
|
4092
4036
|
if (f->floor_types[i] == 0) {
|
|
4093
4037
|
Floor0 *g = &f->floor_config[i].floor0;
|
|
4094
|
-
g->order =
|
|
4095
|
-
g->rate =
|
|
4096
|
-
g->bark_map_size =
|
|
4097
|
-
g->amplitude_bits =
|
|
4098
|
-
g->amplitude_offset =
|
|
4099
|
-
g->number_of_books =
|
|
4038
|
+
g->order = get_bits(f,8);
|
|
4039
|
+
g->rate = get_bits(f,16);
|
|
4040
|
+
g->bark_map_size = get_bits(f,16);
|
|
4041
|
+
g->amplitude_bits = get_bits(f,6);
|
|
4042
|
+
g->amplitude_offset = get_bits(f,8);
|
|
4043
|
+
g->number_of_books = get_bits(f,4) + 1;
|
|
4100
4044
|
for (j=0; j < g->number_of_books; ++j)
|
|
4101
|
-
g->book_list[j] =
|
|
4045
|
+
g->book_list[j] = get_bits(f,8);
|
|
4102
4046
|
return error(f, VORBIS_feature_not_supported);
|
|
4103
4047
|
} else {
|
|
4104
4048
|
stbv__floor_ordering p[31*8+2];
|
|
4105
4049
|
Floor1 *g = &f->floor_config[i].floor1;
|
|
4106
4050
|
int max_class = -1;
|
|
4107
|
-
g->partitions =
|
|
4051
|
+
g->partitions = get_bits(f, 5);
|
|
4108
4052
|
for (j=0; j < g->partitions; ++j) {
|
|
4109
|
-
g->partition_class_list[j] =
|
|
4053
|
+
g->partition_class_list[j] = get_bits(f, 4);
|
|
4110
4054
|
if (g->partition_class_list[j] > max_class)
|
|
4111
4055
|
max_class = g->partition_class_list[j];
|
|
4112
4056
|
}
|
|
4113
4057
|
for (j=0; j <= max_class; ++j) {
|
|
4114
|
-
g->class_dimensions[j] =
|
|
4115
|
-
g->class_subclasses[j] =
|
|
4058
|
+
g->class_dimensions[j] = get_bits(f, 3)+1;
|
|
4059
|
+
g->class_subclasses[j] = get_bits(f, 2);
|
|
4116
4060
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
4117
4061
|
if (g->class_subclasses[j]) {
|
|
4118
|
-
g->class_masterbooks[j] =
|
|
4062
|
+
g->class_masterbooks[j] = get_bits(f, 8);
|
|
4119
4063
|
if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
|
4120
4064
|
}
|
|
4121
4065
|
for (k=0; k < 1 << g->class_subclasses[j]; ++k) {
|
|
@@ -4123,22 +4067,22 @@ static int start_decoder(vorb *f)
|
|
|
4123
4067
|
if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
|
4124
4068
|
}
|
|
4125
4069
|
}
|
|
4126
|
-
g->floor1_multiplier =
|
|
4127
|
-
g->rangebits =
|
|
4070
|
+
g->floor1_multiplier = get_bits(f,2)+1;
|
|
4071
|
+
g->rangebits = get_bits(f,4);
|
|
4128
4072
|
g->Xlist[0] = 0;
|
|
4129
4073
|
g->Xlist[1] = 1 << g->rangebits;
|
|
4130
4074
|
g->values = 2;
|
|
4131
4075
|
for (j=0; j < g->partitions; ++j) {
|
|
4132
4076
|
int c = g->partition_class_list[j];
|
|
4133
4077
|
for (k=0; k < g->class_dimensions[c]; ++k) {
|
|
4134
|
-
g->Xlist[g->values] =
|
|
4078
|
+
g->Xlist[g->values] = get_bits(f, g->rangebits);
|
|
4135
4079
|
++g->values;
|
|
4136
4080
|
}
|
|
4137
4081
|
}
|
|
4138
4082
|
// precompute the sorting
|
|
4139
4083
|
for (j=0; j < g->values; ++j) {
|
|
4140
4084
|
p[j].x = g->Xlist[j];
|
|
4141
|
-
p[j].id =
|
|
4085
|
+
p[j].id = j;
|
|
4142
4086
|
}
|
|
4143
4087
|
qsort(p, g->values, sizeof(p[0]), point_compare);
|
|
4144
4088
|
for (j=0; j < g->values-1; ++j)
|
|
@@ -4150,8 +4094,8 @@ static int start_decoder(vorb *f)
|
|
|
4150
4094
|
for (j=2; j < g->values; ++j) {
|
|
4151
4095
|
int low = 0,hi = 0;
|
|
4152
4096
|
neighbors(g->Xlist, j, &low,&hi);
|
|
4153
|
-
g->neighbors[j][0] =
|
|
4154
|
-
g->neighbors[j][1] =
|
|
4097
|
+
g->neighbors[j][0] = low;
|
|
4098
|
+
g->neighbors[j][1] = hi;
|
|
4155
4099
|
}
|
|
4156
4100
|
|
|
4157
4101
|
if (g->values > longest_floorlist)
|
|
@@ -4168,22 +4112,22 @@ static int start_decoder(vorb *f)
|
|
|
4168
4112
|
for (i=0; i < f->residue_count; ++i) {
|
|
4169
4113
|
uint8 residue_cascade[64];
|
|
4170
4114
|
Residue *r = f->residue_config+i;
|
|
4171
|
-
f->residue_types[i] =
|
|
4115
|
+
f->residue_types[i] = get_bits(f, 16);
|
|
4172
4116
|
if (f->residue_types[i] > 2) return error(f, VORBIS_invalid_setup);
|
|
4173
4117
|
r->begin = get_bits(f, 24);
|
|
4174
4118
|
r->end = get_bits(f, 24);
|
|
4175
4119
|
if (r->end < r->begin) return error(f, VORBIS_invalid_setup);
|
|
4176
4120
|
r->part_size = get_bits(f,24)+1;
|
|
4177
|
-
r->classifications =
|
|
4178
|
-
r->classbook =
|
|
4121
|
+
r->classifications = get_bits(f,6)+1;
|
|
4122
|
+
r->classbook = get_bits(f,8);
|
|
4179
4123
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
4180
4124
|
if (r->classbook >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
|
4181
4125
|
for (j=0; j < r->classifications; ++j) {
|
|
4182
4126
|
uint8 high_bits=0;
|
|
4183
|
-
uint8 low_bits=
|
|
4127
|
+
uint8 low_bits=get_bits(f,3);
|
|
4184
4128
|
if (get_bits(f,1))
|
|
4185
|
-
high_bits =
|
|
4186
|
-
residue_cascade[j] =
|
|
4129
|
+
high_bits = get_bits(f,5);
|
|
4130
|
+
residue_cascade[j] = high_bits*8 + low_bits;
|
|
4187
4131
|
}
|
|
4188
4132
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
4189
4133
|
r->residue_books = (short (*)[8]) setup_malloc(f, sizeof(r->residue_books[0]) * r->classifications);
|
|
@@ -4191,7 +4135,7 @@ static int start_decoder(vorb *f)
|
|
|
4191
4135
|
for (j=0; j < r->classifications; ++j) {
|
|
4192
4136
|
for (k=0; k < 8; ++k) {
|
|
4193
4137
|
if (residue_cascade[j] & (1 << k)) {
|
|
4194
|
-
r->residue_books[j][k] =
|
|
4138
|
+
r->residue_books[j][k] = get_bits(f, 8);
|
|
4195
4139
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
4196
4140
|
if (r->residue_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
|
4197
4141
|
} else {
|
|
@@ -4228,17 +4172,17 @@ static int start_decoder(vorb *f)
|
|
|
4228
4172
|
m->chan = (MappingChannel *) setup_malloc(f, f->channels * sizeof(*m->chan));
|
|
4229
4173
|
if (m->chan == NULL) return error(f, VORBIS_outofmem);
|
|
4230
4174
|
if (get_bits(f,1))
|
|
4231
|
-
m->submaps =
|
|
4175
|
+
m->submaps = get_bits(f,4)+1;
|
|
4232
4176
|
else
|
|
4233
4177
|
m->submaps = 1;
|
|
4234
4178
|
if (m->submaps > max_submaps)
|
|
4235
4179
|
max_submaps = m->submaps;
|
|
4236
4180
|
if (get_bits(f,1)) {
|
|
4237
|
-
m->coupling_steps =
|
|
4181
|
+
m->coupling_steps = get_bits(f,8)+1;
|
|
4238
4182
|
if (m->coupling_steps > f->channels) return error(f, VORBIS_invalid_setup);
|
|
4239
4183
|
for (k=0; k < m->coupling_steps; ++k) {
|
|
4240
|
-
m->chan[k].magnitude =
|
|
4241
|
-
m->chan[k].angle =
|
|
4184
|
+
m->chan[k].magnitude = get_bits(f, ilog(f->channels-1));
|
|
4185
|
+
m->chan[k].angle = get_bits(f, ilog(f->channels-1));
|
|
4242
4186
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
4243
4187
|
if (m->chan[k].magnitude >= f->channels) return error(f, VORBIS_invalid_setup);
|
|
4244
4188
|
if (m->chan[k].angle >= f->channels) return error(f, VORBIS_invalid_setup);
|
|
@@ -4251,7 +4195,7 @@ static int start_decoder(vorb *f)
|
|
|
4251
4195
|
if (get_bits(f,2)) return error(f, VORBIS_invalid_setup);
|
|
4252
4196
|
if (m->submaps > 1) {
|
|
4253
4197
|
for (j=0; j < f->channels; ++j) {
|
|
4254
|
-
m->chan[j].mux =
|
|
4198
|
+
m->chan[j].mux = get_bits(f, 4);
|
|
4255
4199
|
if (m->chan[j].mux >= m->submaps) return error(f, VORBIS_invalid_setup);
|
|
4256
4200
|
}
|
|
4257
4201
|
} else
|
|
@@ -4260,9 +4204,9 @@ static int start_decoder(vorb *f)
|
|
|
4260
4204
|
m->chan[j].mux = 0;
|
|
4261
4205
|
|
|
4262
4206
|
for (j=0; j < m->submaps; ++j) {
|
|
4263
|
-
|
|
4264
|
-
m->submap_floor[j] =
|
|
4265
|
-
m->submap_residue[j] =
|
|
4207
|
+
get_bits(f,8); // discard
|
|
4208
|
+
m->submap_floor[j] = get_bits(f,8);
|
|
4209
|
+
m->submap_residue[j] = get_bits(f,8);
|
|
4266
4210
|
if (m->submap_floor[j] >= f->floor_count) return error(f, VORBIS_invalid_setup);
|
|
4267
4211
|
if (m->submap_residue[j] >= f->residue_count) return error(f, VORBIS_invalid_setup);
|
|
4268
4212
|
}
|
|
@@ -4272,10 +4216,10 @@ static int start_decoder(vorb *f)
|
|
|
4272
4216
|
f->mode_count = get_bits(f, 6)+1;
|
|
4273
4217
|
for (i=0; i < f->mode_count; ++i) {
|
|
4274
4218
|
Mode *m = f->mode_config+i;
|
|
4275
|
-
m->blockflag =
|
|
4276
|
-
m->windowtype =
|
|
4277
|
-
m->transformtype =
|
|
4278
|
-
m->mapping =
|
|
4219
|
+
m->blockflag = get_bits(f,1);
|
|
4220
|
+
m->windowtype = get_bits(f,16);
|
|
4221
|
+
m->transformtype = get_bits(f,16);
|
|
4222
|
+
m->mapping = get_bits(f,8);
|
|
4279
4223
|
if (f->valid_bits < 0) return error(f, VORBIS_unexpected_eof);
|
|
4280
4224
|
if (m->windowtype != 0) return error(f, VORBIS_invalid_setup);
|
|
4281
4225
|
if (m->transformtype != 0) return error(f, VORBIS_invalid_setup);
|
|
@@ -4316,10 +4260,11 @@ static int start_decoder(vorb *f)
|
|
|
4316
4260
|
{
|
|
4317
4261
|
uint32 imdct_mem = (f->blocksize_1 * sizeof(float) >> 1);
|
|
4318
4262
|
uint32 classify_mem;
|
|
4319
|
-
int max_part_read=0;
|
|
4263
|
+
int i,max_part_read=0;
|
|
4320
4264
|
for (i=0; i < f->residue_count; ++i) {
|
|
4321
4265
|
Residue *r = f->residue_config + i;
|
|
4322
|
-
unsigned int
|
|
4266
|
+
unsigned int rtype = f->residue_types[i];
|
|
4267
|
+
unsigned int actual_size = rtype == 2 ? f->blocksize_1 : f->blocksize_1 / 2;
|
|
4323
4268
|
unsigned int limit_r_begin = r->begin < actual_size ? r->begin : actual_size;
|
|
4324
4269
|
unsigned int limit_r_end = r->end < actual_size ? r->end : actual_size;
|
|
4325
4270
|
int n_read = limit_r_end - limit_r_begin;
|
|
@@ -4434,8 +4379,8 @@ static void vorbis_deinit(stb_vorbis *p)
|
|
|
4434
4379
|
setup_temp_free(p, &p->temp_values, 0);
|
|
4435
4380
|
setup_temp_free(p, &p->temp_mults, 0);
|
|
4436
4381
|
}
|
|
4437
|
-
#ifdef
|
|
4438
|
-
if (p->close_on_free)
|
|
4382
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
4383
|
+
if (p->close_on_free) SDL_RWclose(p->rwops);
|
|
4439
4384
|
#endif
|
|
4440
4385
|
#ifndef STB_VORBIS_NO_STDIO
|
|
4441
4386
|
if (p->close_on_free) fclose(p->f);
|
|
@@ -4462,13 +4407,9 @@ static void vorbis_init(stb_vorbis *p, const stb_vorbis_alloc *z)
|
|
|
4462
4407
|
p->stream = NULL;
|
|
4463
4408
|
p->codebooks = NULL;
|
|
4464
4409
|
p->page_crc_tests = -1;
|
|
4465
|
-
#ifdef
|
|
4410
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
4466
4411
|
p->close_on_free = FALSE;
|
|
4467
|
-
p->
|
|
4468
|
-
p->io_start = 0;
|
|
4469
|
-
p->io_virtual_pos = 0;
|
|
4470
|
-
p->io_buffer_pos = 0;
|
|
4471
|
-
p->io_buffer_fill = 0;
|
|
4412
|
+
p->rwops = NULL;
|
|
4472
4413
|
#endif
|
|
4473
4414
|
#ifndef STB_VORBIS_NO_STDIO
|
|
4474
4415
|
p->close_on_free = FALSE;
|
|
@@ -4484,14 +4425,6 @@ int stb_vorbis_get_sample_offset(stb_vorbis *f)
|
|
|
4484
4425
|
return -1;
|
|
4485
4426
|
}
|
|
4486
4427
|
|
|
4487
|
-
int stb_vorbis_get_playback_sample_offset(stb_vorbis *f)
|
|
4488
|
-
{
|
|
4489
|
-
if (f->current_playback_loc_valid)
|
|
4490
|
-
return f->current_playback_loc;
|
|
4491
|
-
else
|
|
4492
|
-
return -1;
|
|
4493
|
-
}
|
|
4494
|
-
|
|
4495
4428
|
stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f)
|
|
4496
4429
|
{
|
|
4497
4430
|
stb_vorbis_info d;
|
|
@@ -4542,9 +4475,9 @@ void stb_vorbis_flush_pushdata(stb_vorbis *f)
|
|
|
4542
4475
|
f->channel_buffer_end = 0;
|
|
4543
4476
|
}
|
|
4544
4477
|
|
|
4545
|
-
static int vorbis_search_for_page_pushdata(vorb *f,
|
|
4478
|
+
static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len)
|
|
4546
4479
|
{
|
|
4547
|
-
int i;
|
|
4480
|
+
int i,n;
|
|
4548
4481
|
for (i=0; i < f->page_crc_tests; ++i)
|
|
4549
4482
|
f->scan[i].bytes_done = 0;
|
|
4550
4483
|
|
|
@@ -4557,7 +4490,7 @@ static int vorbis_search_for_page_pushdata(vorb *f, const uint8 *data, int data_
|
|
|
4557
4490
|
for (i=0; i < data_len; ++i) {
|
|
4558
4491
|
if (data[i] == 0x4f) {
|
|
4559
4492
|
if (0==memcmp(data+i, ogg_page_header, 4)) {
|
|
4560
|
-
int j,
|
|
4493
|
+
int j,len;
|
|
4561
4494
|
uint32 crc;
|
|
4562
4495
|
// make sure we have the whole page header
|
|
4563
4496
|
if (i+26 >= data_len || i+27+data[i+26] >= data_len) {
|
|
@@ -4585,7 +4518,7 @@ static int vorbis_search_for_page_pushdata(vorb *f, const uint8 *data, int data_
|
|
|
4585
4518
|
// if the last frame on a page is continued to the next, then
|
|
4586
4519
|
// we can't recover the sample_loc immediately
|
|
4587
4520
|
if (data[i+27+data[i+26]-1] == 255)
|
|
4588
|
-
f->scan[n].sample_loc = ~
|
|
4521
|
+
f->scan[n].sample_loc = ~0;
|
|
4589
4522
|
else
|
|
4590
4523
|
f->scan[n].sample_loc = data[i+6] + (data[i+7] << 8) + (data[i+ 8]<<16) + (data[i+ 9]<<24);
|
|
4591
4524
|
f->scan[n].bytes_done = i+j;
|
|
@@ -4648,11 +4581,11 @@ int stb_vorbis_decode_frame_pushdata(
|
|
|
4648
4581
|
|
|
4649
4582
|
if (f->page_crc_tests >= 0) {
|
|
4650
4583
|
*samples = 0;
|
|
4651
|
-
return vorbis_search_for_page_pushdata(f, data, data_len);
|
|
4584
|
+
return vorbis_search_for_page_pushdata(f, (uint8 *) data, data_len);
|
|
4652
4585
|
}
|
|
4653
4586
|
|
|
4654
|
-
f->stream = (
|
|
4655
|
-
f->stream_end = (
|
|
4587
|
+
f->stream = (uint8 *) data;
|
|
4588
|
+
f->stream_end = (uint8 *) data + data_len;
|
|
4656
4589
|
f->error = VORBIS__no_error;
|
|
4657
4590
|
|
|
4658
4591
|
// check that we have the entire packet in memory
|
|
@@ -4710,8 +4643,8 @@ stb_vorbis *stb_vorbis_open_pushdata(
|
|
|
4710
4643
|
{
|
|
4711
4644
|
stb_vorbis *f, p;
|
|
4712
4645
|
vorbis_init(&p, alloc);
|
|
4713
|
-
p.stream = (
|
|
4714
|
-
p.stream_end = (
|
|
4646
|
+
p.stream = (uint8 *) data;
|
|
4647
|
+
p.stream_end = (uint8 *) data + data_len;
|
|
4715
4648
|
p.push_mode = TRUE;
|
|
4716
4649
|
if (!start_decoder(&p)) {
|
|
4717
4650
|
if (p.eof)
|
|
@@ -4739,15 +4672,14 @@ unsigned int stb_vorbis_get_file_offset(stb_vorbis *f)
|
|
|
4739
4672
|
#ifndef STB_VORBIS_NO_PUSHDATA_API
|
|
4740
4673
|
if (f->push_mode) return 0;
|
|
4741
4674
|
#endif
|
|
4742
|
-
#ifdef
|
|
4743
|
-
return f->
|
|
4744
|
-
#else
|
|
4675
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
4676
|
+
return (unsigned int) (SDL_RWtell(f->rwops) - f->rwops_start);
|
|
4677
|
+
#else
|
|
4745
4678
|
if (USE_MEMORY(f)) return (unsigned int) (f->stream - f->stream_start);
|
|
4679
|
+
#endif
|
|
4746
4680
|
#ifndef STB_VORBIS_NO_STDIO
|
|
4747
4681
|
return (unsigned int) (ftell(f->f) - f->f_start);
|
|
4748
4682
|
#endif
|
|
4749
|
-
return 0; /* silence warnings */
|
|
4750
|
-
#endif /* !STB_VORBIS_SDL */
|
|
4751
4683
|
}
|
|
4752
4684
|
|
|
4753
4685
|
#ifndef STB_VORBIS_NO_PULLDATA_API
|
|
@@ -4763,7 +4695,7 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
|
|
|
4763
4695
|
n = get8(f);
|
|
4764
4696
|
if (n == 0x4f) { // page header candidate
|
|
4765
4697
|
unsigned int retry_loc = stb_vorbis_get_file_offset(f);
|
|
4766
|
-
|
|
4698
|
+
int i;
|
|
4767
4699
|
// check if we're off the end of a file_section stream
|
|
4768
4700
|
if (retry_loc - 25 > f->stream_len)
|
|
4769
4701
|
return 0;
|
|
@@ -4774,7 +4706,7 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
|
|
|
4774
4706
|
if (f->eof) return 0;
|
|
4775
4707
|
if (i == 4) {
|
|
4776
4708
|
uint8 header[27];
|
|
4777
|
-
uint32
|
|
4709
|
+
uint32 i, crc, goal, len;
|
|
4778
4710
|
for (i=0; i < 4; ++i)
|
|
4779
4711
|
header[i] = ogg_page_header[i];
|
|
4780
4712
|
for (; i < 27; ++i)
|
|
@@ -4789,7 +4721,7 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
|
|
|
4789
4721
|
crc = crc32_update(crc, header[i]);
|
|
4790
4722
|
len = 0;
|
|
4791
4723
|
for (i=0; i < header[26]; ++i) {
|
|
4792
|
-
|
|
4724
|
+
int s = get8(f);
|
|
4793
4725
|
crc = crc32_update(crc, s);
|
|
4794
4726
|
len += s;
|
|
4795
4727
|
}
|
|
@@ -4939,11 +4871,8 @@ static int seek_to_sample_coarse(stb_vorbis *f, uint32 sample_number)
|
|
|
4939
4871
|
return 0;
|
|
4940
4872
|
}
|
|
4941
4873
|
|
|
4942
|
-
mid = left; // just make sure it's initialized to quiet some warnings
|
|
4943
|
-
|
|
4944
4874
|
while (left.page_end != right.page_start) {
|
|
4945
|
-
|
|
4946
|
-
return error(f, VORBIS_seek_failed);
|
|
4875
|
+
assert(left.page_end < right.page_start);
|
|
4947
4876
|
// search range in bytes
|
|
4948
4877
|
delta = right.page_start - left.page_end;
|
|
4949
4878
|
if (delta <= 65536) {
|
|
@@ -5068,7 +4997,7 @@ static int peek_decode_initial(vorb *f, int *p_left_start, int *p_left_end, int
|
|
|
5068
4997
|
bits_read += 2;
|
|
5069
4998
|
bytes_read = (bits_read + 7) / 8;
|
|
5070
4999
|
|
|
5071
|
-
f->bytes_in_seg +=
|
|
5000
|
+
f->bytes_in_seg += bytes_read;
|
|
5072
5001
|
f->packet_bytes -= bytes_read;
|
|
5073
5002
|
skip(f, -bytes_read);
|
|
5074
5003
|
if (f->next_seg == -1)
|
|
@@ -5116,29 +5045,23 @@ int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number)
|
|
|
5116
5045
|
}
|
|
5117
5046
|
// the next frame should start with the sample
|
|
5118
5047
|
if (f->current_loc != sample_number) return error(f, VORBIS_seek_failed);
|
|
5119
|
-
f->current_playback_loc = sample_number;
|
|
5120
5048
|
return 1;
|
|
5121
5049
|
}
|
|
5122
5050
|
|
|
5123
5051
|
int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number)
|
|
5124
5052
|
{
|
|
5125
|
-
if (!stb_vorbis_seek_frame(f, sample_number))
|
|
5126
|
-
f->current_playback_loc_valid = FALSE;
|
|
5053
|
+
if (!stb_vorbis_seek_frame(f, sample_number))
|
|
5127
5054
|
return 0;
|
|
5128
|
-
}
|
|
5129
5055
|
|
|
5130
5056
|
if (sample_number != f->current_loc) {
|
|
5131
5057
|
int n;
|
|
5132
5058
|
uint32 frame_start = f->current_loc;
|
|
5133
|
-
|
|
5059
|
+
stb_vorbis_get_frame_float(f, &n, NULL);
|
|
5134
5060
|
assert(sample_number > frame_start);
|
|
5135
5061
|
assert(f->channel_buffer_start + (int) (sample_number-frame_start) <= f->channel_buffer_end);
|
|
5136
5062
|
f->channel_buffer_start += (sample_number - frame_start);
|
|
5137
5063
|
}
|
|
5138
5064
|
|
|
5139
|
-
f->current_playback_loc_valid = TRUE;
|
|
5140
|
-
f->current_playback_loc = sample_number;
|
|
5141
|
-
|
|
5142
5065
|
return 1;
|
|
5143
5066
|
}
|
|
5144
5067
|
|
|
@@ -5305,13 +5228,13 @@ stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const st
|
|
|
5305
5228
|
}
|
|
5306
5229
|
#endif // STB_VORBIS_NO_STDIO
|
|
5307
5230
|
|
|
5308
|
-
#ifdef
|
|
5309
|
-
stb_vorbis *
|
|
5231
|
+
#ifdef __SDL_SOUND_INTERNAL__
|
|
5232
|
+
stb_vorbis * stb_vorbis_open_rwops_section(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length)
|
|
5310
5233
|
{
|
|
5311
5234
|
stb_vorbis *f, p;
|
|
5312
5235
|
vorbis_init(&p, alloc);
|
|
5313
|
-
p.
|
|
5314
|
-
p.
|
|
5236
|
+
p.rwops = rwops;
|
|
5237
|
+
p.rwops_start = (uint32) SDL_RWtell(rwops);
|
|
5315
5238
|
p.stream_len = length;
|
|
5316
5239
|
p.close_on_free = close_on_free;
|
|
5317
5240
|
if (start_decoder(&p)) {
|
|
@@ -5327,13 +5250,13 @@ stb_vorbis * stb_vorbis_open_io_section(SDL_IOStream *io, int close_on_free, int
|
|
|
5327
5250
|
return NULL;
|
|
5328
5251
|
}
|
|
5329
5252
|
|
|
5330
|
-
stb_vorbis *
|
|
5253
|
+
stb_vorbis * stb_vorbis_open_rwops(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc)
|
|
5331
5254
|
{
|
|
5332
|
-
const unsigned int start = (unsigned int)
|
|
5333
|
-
const unsigned int len = (unsigned int) (
|
|
5334
|
-
return
|
|
5255
|
+
const unsigned int start = (unsigned int) SDL_RWtell(rwops);
|
|
5256
|
+
const unsigned int len = (unsigned int) (SDL_RWsize(rwops) - start);
|
|
5257
|
+
return stb_vorbis_open_rwops_section(rwops, close_on_free, error, alloc, len);
|
|
5335
5258
|
}
|
|
5336
|
-
#endif
|
|
5259
|
+
#endif
|
|
5337
5260
|
|
|
5338
5261
|
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc)
|
|
5339
5262
|
{
|
|
@@ -5343,9 +5266,9 @@ stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *err
|
|
|
5343
5266
|
return NULL;
|
|
5344
5267
|
}
|
|
5345
5268
|
vorbis_init(&p, alloc);
|
|
5346
|
-
p.stream = (
|
|
5347
|
-
p.stream_end = (
|
|
5348
|
-
p.stream_start = (
|
|
5269
|
+
p.stream = (uint8 *) data;
|
|
5270
|
+
p.stream_end = (uint8 *) data + len;
|
|
5271
|
+
p.stream_start = (uint8 *) p.stream;
|
|
5349
5272
|
p.stream_len = len;
|
|
5350
5273
|
p.push_mode = FALSE;
|
|
5351
5274
|
if (start_decoder(&p)) {
|
|
@@ -5362,21 +5285,6 @@ stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *err
|
|
|
5362
5285
|
return NULL;
|
|
5363
5286
|
}
|
|
5364
5287
|
|
|
5365
|
-
static int fixup_current_playback_loc(stb_vorbis *f, int n)
|
|
5366
|
-
{
|
|
5367
|
-
unsigned int lgs;
|
|
5368
|
-
|
|
5369
|
-
f->current_playback_loc += n;
|
|
5370
|
-
lgs = stb_vorbis_stream_length_in_samples(f);
|
|
5371
|
-
if (lgs != 0 && lgs != SAMPLE_unknown && f->current_playback_loc > (int)lgs) {
|
|
5372
|
-
int r = n - (f->current_playback_loc - (int)lgs);
|
|
5373
|
-
f->current_playback_loc = lgs;
|
|
5374
|
-
return r;
|
|
5375
|
-
}
|
|
5376
|
-
|
|
5377
|
-
return n;
|
|
5378
|
-
}
|
|
5379
|
-
|
|
5380
5288
|
#ifndef STB_VORBIS_NO_INTEGER_CONVERSION
|
|
5381
5289
|
#define PLAYBACK_MONO 1
|
|
5382
5290
|
#define PLAYBACK_LEFT 2
|
|
@@ -5386,7 +5294,7 @@ static int fixup_current_playback_loc(stb_vorbis *f, int n)
|
|
|
5386
5294
|
#define C (PLAYBACK_LEFT | PLAYBACK_RIGHT | PLAYBACK_MONO)
|
|
5387
5295
|
#define R (PLAYBACK_RIGHT | PLAYBACK_MONO)
|
|
5388
5296
|
|
|
5389
|
-
static
|
|
5297
|
+
static int8 channel_position[7][6] =
|
|
5390
5298
|
{
|
|
5391
5299
|
{ 0 },
|
|
5392
5300
|
{ C },
|
|
@@ -5397,20 +5305,38 @@ static const int8 channel_position[7][6] =
|
|
|
5397
5305
|
{ L, C, R, L, R, C },
|
|
5398
5306
|
};
|
|
5399
5307
|
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
}
|
|
5308
|
+
|
|
5309
|
+
#ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
|
|
5310
|
+
typedef union {
|
|
5311
|
+
float f;
|
|
5312
|
+
// changed this to unsigned to suppress an UBSan error.
|
|
5313
|
+
// upstream: https://github.com/nothings/stb/issues/1168.
|
|
5314
|
+
unsigned int i;
|
|
5315
|
+
} float_conv;
|
|
5316
|
+
typedef char stb_vorbis_float_size_test[sizeof(float)==4 && sizeof(int) == 4];
|
|
5317
|
+
#define FASTDEF(x) float_conv x
|
|
5318
|
+
// add (1<<23) to convert to int, then divide by 2^SHIFT, then add 0.5/2^SHIFT to round
|
|
5319
|
+
#define MAGIC(SHIFT) (1.5f * (1 << (23-SHIFT)) + 0.5f/(1 << SHIFT))
|
|
5320
|
+
#define ADDEND(SHIFT) (((150-SHIFT) << 23) + (1 << 22))
|
|
5321
|
+
#define FAST_SCALED_FLOAT_TO_INT(temp,x,s) (int)(temp.f = (x) + MAGIC(s), temp.i - ADDEND(s))
|
|
5322
|
+
#define check_endianness()
|
|
5323
|
+
#else
|
|
5324
|
+
#define FAST_SCALED_FLOAT_TO_INT(temp,x,s) ((int) ((x) * (1 << (s))))
|
|
5325
|
+
#define check_endianness()
|
|
5326
|
+
#define FASTDEF(x)
|
|
5327
|
+
#endif
|
|
5408
5328
|
|
|
5409
5329
|
static void copy_samples(short *dest, float *src, int len)
|
|
5410
5330
|
{
|
|
5411
5331
|
int i;
|
|
5412
|
-
|
|
5413
|
-
|
|
5332
|
+
check_endianness();
|
|
5333
|
+
for (i=0; i < len; ++i) {
|
|
5334
|
+
FASTDEF(temp);
|
|
5335
|
+
int v = FAST_SCALED_FLOAT_TO_INT(temp, src[i],15);
|
|
5336
|
+
if ((unsigned int)v + 32768 > 65535)
|
|
5337
|
+
v = v < 0 ? -32768 : 32767;
|
|
5338
|
+
dest[i] = v;
|
|
5339
|
+
}
|
|
5414
5340
|
}
|
|
5415
5341
|
|
|
5416
5342
|
static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len)
|
|
@@ -5418,6 +5344,7 @@ static void compute_samples(int mask, short *output, int num_c, float **data, in
|
|
|
5418
5344
|
#define STB_BUFFER_SIZE 32
|
|
5419
5345
|
float buffer[STB_BUFFER_SIZE];
|
|
5420
5346
|
int i,j,o,n = STB_BUFFER_SIZE;
|
|
5347
|
+
check_endianness();
|
|
5421
5348
|
for (o = 0; o < len; o += STB_BUFFER_SIZE) {
|
|
5422
5349
|
memset(buffer, 0, sizeof(buffer));
|
|
5423
5350
|
if (o + n > len) n = len - o;
|
|
@@ -5427,8 +5354,13 @@ static void compute_samples(int mask, short *output, int num_c, float **data, in
|
|
|
5427
5354
|
buffer[i] += data[j][d_offset+o+i];
|
|
5428
5355
|
}
|
|
5429
5356
|
}
|
|
5430
|
-
for (i=0; i < n; ++i)
|
|
5431
|
-
|
|
5357
|
+
for (i=0; i < n; ++i) {
|
|
5358
|
+
FASTDEF(temp);
|
|
5359
|
+
int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15);
|
|
5360
|
+
if ((unsigned int)v + 32768 > 65535)
|
|
5361
|
+
v = v < 0 ? -32768 : 32767;
|
|
5362
|
+
output[o+i] = v;
|
|
5363
|
+
}
|
|
5432
5364
|
}
|
|
5433
5365
|
#undef STB_BUFFER_SIZE
|
|
5434
5366
|
}
|
|
@@ -5439,6 +5371,7 @@ static void compute_stereo_samples(short *output, int num_c, float **data, int d
|
|
|
5439
5371
|
float buffer[STB_BUFFER_SIZE];
|
|
5440
5372
|
int i,j,o,n = STB_BUFFER_SIZE >> 1;
|
|
5441
5373
|
// o is the offset in the source data
|
|
5374
|
+
check_endianness();
|
|
5442
5375
|
for (o = 0; o < len; o += STB_BUFFER_SIZE >> 1) {
|
|
5443
5376
|
// o2 is the offset in the output data
|
|
5444
5377
|
int o2 = o << 1;
|
|
@@ -5461,8 +5394,13 @@ static void compute_stereo_samples(short *output, int num_c, float **data, int d
|
|
|
5461
5394
|
}
|
|
5462
5395
|
}
|
|
5463
5396
|
}
|
|
5464
|
-
for (i=0; i < (n<<1); ++i)
|
|
5465
|
-
|
|
5397
|
+
for (i=0; i < (n<<1); ++i) {
|
|
5398
|
+
FASTDEF(temp);
|
|
5399
|
+
int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15);
|
|
5400
|
+
if ((unsigned int)v + 32768 > 65535)
|
|
5401
|
+
v = v < 0 ? -32768 : 32767;
|
|
5402
|
+
output[o2+i] = v;
|
|
5403
|
+
}
|
|
5466
5404
|
}
|
|
5467
5405
|
#undef STB_BUFFER_SIZE
|
|
5468
5406
|
}
|
|
@@ -5471,7 +5409,7 @@ static void convert_samples_short(int buf_c, short **buffer, int b_offset, int d
|
|
|
5471
5409
|
{
|
|
5472
5410
|
int i;
|
|
5473
5411
|
if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
|
|
5474
|
-
static
|
|
5412
|
+
static int channel_selector[3][2] = { {0}, {PLAYBACK_MONO}, {PLAYBACK_LEFT, PLAYBACK_RIGHT} };
|
|
5475
5413
|
for (i=0; i < buf_c; ++i)
|
|
5476
5414
|
compute_samples(channel_selector[buf_c][i], buffer[i]+b_offset, data_c, data, d_offset, samples);
|
|
5477
5415
|
} else {
|
|
@@ -5496,15 +5434,23 @@ int stb_vorbis_get_frame_short(stb_vorbis *f, int num_c, short **buffer, int num
|
|
|
5496
5434
|
static void convert_channels_short_interleaved(int buf_c, short *buffer, int data_c, float **data, int d_offset, int len)
|
|
5497
5435
|
{
|
|
5498
5436
|
int i;
|
|
5499
|
-
|
|
5437
|
+
check_endianness();
|
|
5438
|
+
if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
|
|
5439
|
+
assert(buf_c == 2);
|
|
5500
5440
|
for (i=0; i < buf_c; ++i)
|
|
5501
5441
|
compute_stereo_samples(buffer, data_c, data, d_offset, len);
|
|
5502
5442
|
} else {
|
|
5503
5443
|
int limit = buf_c < data_c ? buf_c : data_c;
|
|
5504
5444
|
int j;
|
|
5505
5445
|
for (j=0; j < len; ++j) {
|
|
5506
|
-
for (i=0; i < limit; ++i)
|
|
5507
|
-
|
|
5446
|
+
for (i=0; i < limit; ++i) {
|
|
5447
|
+
FASTDEF(temp);
|
|
5448
|
+
float f = data[i][d_offset+j];
|
|
5449
|
+
int v = FAST_SCALED_FLOAT_TO_INT(temp, f,15);//data[i][d_offset+j],15);
|
|
5450
|
+
if ((unsigned int)v + 32768 > 65535)
|
|
5451
|
+
v = v < 0 ? -32768 : 32767;
|
|
5452
|
+
*buffer++ = v;
|
|
5453
|
+
}
|
|
5508
5454
|
for ( ; i < buf_c; ++i)
|
|
5509
5455
|
*buffer++ = 0;
|
|
5510
5456
|
}
|
|
@@ -5540,7 +5486,7 @@ int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short
|
|
|
5540
5486
|
if (n == len) break;
|
|
5541
5487
|
if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
|
|
5542
5488
|
}
|
|
5543
|
-
return
|
|
5489
|
+
return n;
|
|
5544
5490
|
}
|
|
5545
5491
|
|
|
5546
5492
|
int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int len)
|
|
@@ -5557,7 +5503,7 @@ int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, in
|
|
|
5557
5503
|
if (n == len) break;
|
|
5558
5504
|
if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
|
|
5559
5505
|
}
|
|
5560
|
-
return
|
|
5506
|
+
return n;
|
|
5561
5507
|
}
|
|
5562
5508
|
|
|
5563
5509
|
#ifndef STB_VORBIS_NO_STDIO
|
|
@@ -5665,7 +5611,7 @@ int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float
|
|
|
5665
5611
|
if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
|
|
5666
5612
|
break;
|
|
5667
5613
|
}
|
|
5668
|
-
return
|
|
5614
|
+
return n;
|
|
5669
5615
|
}
|
|
5670
5616
|
|
|
5671
5617
|
int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples)
|
|
@@ -5691,7 +5637,7 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in
|
|
|
5691
5637
|
if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
|
|
5692
5638
|
break;
|
|
5693
5639
|
}
|
|
5694
|
-
return
|
|
5640
|
+
return n;
|
|
5695
5641
|
}
|
|
5696
5642
|
#endif // STB_VORBIS_NO_PULLDATA_API
|
|
5697
5643
|
|