gosu 0.10.6 → 0.10.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +1 -1
- data/Gosu/Gosu.hpp +1 -1
- data/Gosu/Version.hpp +3 -3
- data/README.md +4 -0
- data/ext/gosu/extconf.rb +8 -8
- data/ext/gosu/gosu_wrap.cxx +12 -7
- data/src/AppleUtility.hpp +19 -62
- data/src/Audio/Audio.cpp +31 -23
- data/src/Audio/AudioToolboxFile.hpp +19 -18
- data/src/Bitmap/BitmapIO.cpp +32 -17
- data/src/DirectoriesApple.mm +36 -41
- data/src/Input/Input.cpp +22 -6
- data/src/Input/InputUIKit.mm +37 -29
- data/src/Text/Font.cpp +1 -1
- data/src/Text/TextApple.mm +50 -41
- data/src/UIKit/GosuAppDelegate.mm +1 -1
- data/src/UIKit/GosuGLView.mm +0 -2
- data/src/UIKit/GosuViewController.mm +7 -10
- data/src/UtilityApple.mm +26 -19
- data/src/WindowUIKit.mm +22 -12
- data/src/stb_image.h +499 -253
- data/src/stb_image_write.h +98 -43
- data/src/stb_vorbis.c +188 -232
- metadata +4 -4
data/src/stb_image_write.h
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* stb_image_write - v1.
|
1
|
+
/* stb_image_write - v1.02 - public domain - http://nothings.org/stb/stb_image_write.h
|
2
2
|
writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010-2015
|
3
3
|
no warranty implied; use at your own risk
|
4
4
|
|
@@ -34,7 +34,7 @@ USAGE:
|
|
34
34
|
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
35
35
|
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
36
36
|
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
37
|
-
int stbi_write_hdr(char const *filename, int w, int h, int comp, const
|
37
|
+
int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
38
38
|
|
39
39
|
There are also four equivalent functions that use an arbitrary write function. You are
|
40
40
|
expected to open/close your file-equivalent before and after calling these:
|
@@ -98,12 +98,17 @@ CREDITS:
|
|
98
98
|
github:Chribba
|
99
99
|
Guillaume Chereau
|
100
100
|
github:jry2
|
101
|
+
github:romigrou
|
102
|
+
Sergio Gonzalez
|
103
|
+
Jonas Karlsson
|
104
|
+
Filip Wasil
|
105
|
+
Thatcher Ulrich
|
101
106
|
|
102
107
|
LICENSE
|
103
108
|
|
104
|
-
This software is
|
105
|
-
|
106
|
-
|
109
|
+
This software is dual-licensed to the public domain and under the following
|
110
|
+
license: you are granted a perpetual, irrevocable license to copy, modify,
|
111
|
+
publish, and distribute this file as you see fit.
|
107
112
|
|
108
113
|
*/
|
109
114
|
|
@@ -144,8 +149,12 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w,
|
|
144
149
|
#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
|
145
150
|
|
146
151
|
#ifdef _WIN32
|
152
|
+
#ifndef _CRT_SECURE_NO_WARNINGS
|
147
153
|
#define _CRT_SECURE_NO_WARNINGS
|
154
|
+
#endif
|
155
|
+
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
148
156
|
#define _CRT_NONSTDC_NO_DEPRECATE
|
157
|
+
#endif
|
149
158
|
#endif
|
150
159
|
|
151
160
|
#ifndef STBI_WRITE_NO_STDIO
|
@@ -157,19 +166,25 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w,
|
|
157
166
|
#include <string.h>
|
158
167
|
#include <math.h>
|
159
168
|
|
160
|
-
#if defined(STBIW_MALLOC) && defined(STBIW_FREE) && defined(STBIW_REALLOC)
|
169
|
+
#if defined(STBIW_MALLOC) && defined(STBIW_FREE) && (defined(STBIW_REALLOC) || defined(STBIW_REALLOC_SIZED))
|
161
170
|
// ok
|
162
|
-
#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC)
|
171
|
+
#elif !defined(STBIW_MALLOC) && !defined(STBIW_FREE) && !defined(STBIW_REALLOC) && !defined(STBIW_REALLOC_SIZED)
|
163
172
|
// ok
|
164
173
|
#else
|
165
|
-
#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC."
|
174
|
+
#error "Must define all or none of STBIW_MALLOC, STBIW_FREE, and STBIW_REALLOC (or STBIW_REALLOC_SIZED)."
|
166
175
|
#endif
|
167
176
|
|
168
177
|
#ifndef STBIW_MALLOC
|
169
|
-
#define STBIW_MALLOC(sz)
|
170
|
-
#define STBIW_REALLOC(p,
|
171
|
-
#define STBIW_FREE(p)
|
178
|
+
#define STBIW_MALLOC(sz) malloc(sz)
|
179
|
+
#define STBIW_REALLOC(p,newsz) realloc(p,newsz)
|
180
|
+
#define STBIW_FREE(p) free(p)
|
172
181
|
#endif
|
182
|
+
|
183
|
+
#ifndef STBIW_REALLOC_SIZED
|
184
|
+
#define STBIW_REALLOC_SIZED(p,oldsz,newsz) STBIW_REALLOC(p,newsz)
|
185
|
+
#endif
|
186
|
+
|
187
|
+
|
173
188
|
#ifndef STBIW_MEMMOVE
|
174
189
|
#define STBIW_MEMMOVE(a,b,sz) memmove(a,b,sz)
|
175
190
|
#endif
|
@@ -180,6 +195,8 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w,
|
|
180
195
|
#define STBIW_ASSERT(x) assert(x)
|
181
196
|
#endif
|
182
197
|
|
198
|
+
#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff)
|
199
|
+
|
183
200
|
typedef struct
|
184
201
|
{
|
185
202
|
stbi_write_func *func;
|
@@ -228,21 +245,21 @@ static void stbiw__writefv(stbi__write_context *s, const char *fmt, va_list v)
|
|
228
245
|
while (*fmt) {
|
229
246
|
switch (*fmt++) {
|
230
247
|
case ' ': break;
|
231
|
-
case '1': { unsigned char x = (
|
248
|
+
case '1': { unsigned char x = STBIW_UCHAR(va_arg(v, int));
|
232
249
|
s->func(s->context,&x,1);
|
233
250
|
break; }
|
234
251
|
case '2': { int x = va_arg(v,int);
|
235
252
|
unsigned char b[2];
|
236
|
-
b[0] = (
|
237
|
-
b[1] = (
|
253
|
+
b[0] = STBIW_UCHAR(x);
|
254
|
+
b[1] = STBIW_UCHAR(x>>8);
|
238
255
|
s->func(s->context,b,2);
|
239
256
|
break; }
|
240
257
|
case '4': { stbiw_uint32 x = va_arg(v,int);
|
241
258
|
unsigned char b[4];
|
242
|
-
b[0]=(
|
243
|
-
b[1]=(
|
244
|
-
b[2]=(
|
245
|
-
b[3]=(
|
259
|
+
b[0]=STBIW_UCHAR(x);
|
260
|
+
b[1]=STBIW_UCHAR(x>>8);
|
261
|
+
b[2]=STBIW_UCHAR(x>>16);
|
262
|
+
b[3]=STBIW_UCHAR(x>>24);
|
246
263
|
s->func(s->context,b,4);
|
247
264
|
break; }
|
248
265
|
default:
|
@@ -419,13 +436,13 @@ static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, v
|
|
419
436
|
}
|
420
437
|
|
421
438
|
if (diff) {
|
422
|
-
unsigned char header = (
|
439
|
+
unsigned char header = STBIW_UCHAR(len - 1);
|
423
440
|
s->func(s->context, &header, 1);
|
424
441
|
for (k = 0; k < len; ++k) {
|
425
442
|
stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp);
|
426
443
|
}
|
427
444
|
} else {
|
428
|
-
unsigned char header = (
|
445
|
+
unsigned char header = STBIW_UCHAR(len - 129);
|
429
446
|
s->func(s->context, &header, 1);
|
430
447
|
stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin);
|
431
448
|
}
|
@@ -467,7 +484,7 @@ void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
|
467
484
|
int exponent;
|
468
485
|
float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2]));
|
469
486
|
|
470
|
-
if (maxcomp < 1e-
|
487
|
+
if (maxcomp < 1e-32f) {
|
471
488
|
rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0;
|
472
489
|
} else {
|
473
490
|
float normalize = (float) frexp(maxcomp, &exponent) * 256.0f/maxcomp;
|
@@ -481,7 +498,7 @@ void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
|
481
498
|
|
482
499
|
void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte)
|
483
500
|
{
|
484
|
-
unsigned char lengthbyte = (
|
501
|
+
unsigned char lengthbyte = STBIW_UCHAR(length+128);
|
485
502
|
STBIW_ASSERT(length+128 <= 255);
|
486
503
|
s->func(s->context, &lengthbyte, 1);
|
487
504
|
s->func(s->context, &databyte, 1);
|
@@ -489,7 +506,7 @@ void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char dat
|
|
489
506
|
|
490
507
|
void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data)
|
491
508
|
{
|
492
|
-
unsigned char lengthbyte = (
|
509
|
+
unsigned char lengthbyte = STBIW_UCHAR(length);
|
493
510
|
STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code
|
494
511
|
s->func(s->context, &lengthbyte, 1);
|
495
512
|
s->func(s->context, data, length);
|
@@ -647,7 +664,7 @@ int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *da
|
|
647
664
|
static void *stbiw__sbgrowf(void **arr, int increment, int itemsize)
|
648
665
|
{
|
649
666
|
int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1;
|
650
|
-
void *p =
|
667
|
+
void *p = STBIW_REALLOC_SIZED(*arr ? stbiw__sbraw(*arr) : 0, *arr ? (stbiw__sbm(*arr)*itemsize + sizeof(int)*2) : 0, itemsize * m + sizeof(int)*2);
|
651
668
|
STBIW_ASSERT(p);
|
652
669
|
if (p) {
|
653
670
|
if (!*arr) ((int *) p)[1] = 0;
|
@@ -660,7 +677,7 @@ static void *stbiw__sbgrowf(void **arr, int increment, int itemsize)
|
|
660
677
|
static unsigned char *stbiw__zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount)
|
661
678
|
{
|
662
679
|
while (*bitcount >= 8) {
|
663
|
-
stbiw__sbpush(data, (
|
680
|
+
stbiw__sbpush(data, STBIW_UCHAR(*bitbuffer));
|
664
681
|
*bitbuffer >>= 8;
|
665
682
|
*bitcount -= 8;
|
666
683
|
}
|
@@ -720,7 +737,7 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
|
720
737
|
unsigned int bitbuf=0;
|
721
738
|
int i,j, bitcount=0;
|
722
739
|
unsigned char *out = NULL;
|
723
|
-
unsigned char
|
740
|
+
unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(char**));
|
724
741
|
if (quality < 5) quality = 5;
|
725
742
|
|
726
743
|
stbiw__sbpush(out, 0x78); // DEFLATE 32K window
|
@@ -792,10 +809,11 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
|
792
809
|
|
793
810
|
for (i=0; i < stbiw__ZHASH; ++i)
|
794
811
|
(void) stbiw__sbfree(hash_table[i]);
|
812
|
+
STBIW_FREE(hash_table);
|
795
813
|
|
796
814
|
{
|
797
815
|
// compute adler32 on input
|
798
|
-
unsigned int
|
816
|
+
unsigned int s1=1, s2=0;
|
799
817
|
int blocklen = (int) (data_len % 5552);
|
800
818
|
j=0;
|
801
819
|
while (j < data_len) {
|
@@ -804,10 +822,10 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
|
804
822
|
j += blocklen;
|
805
823
|
blocklen = 5552;
|
806
824
|
}
|
807
|
-
stbiw__sbpush(out, (
|
808
|
-
stbiw__sbpush(out, (
|
809
|
-
stbiw__sbpush(out, (
|
810
|
-
stbiw__sbpush(out, (
|
825
|
+
stbiw__sbpush(out, STBIW_UCHAR(s2 >> 8));
|
826
|
+
stbiw__sbpush(out, STBIW_UCHAR(s2));
|
827
|
+
stbiw__sbpush(out, STBIW_UCHAR(s1 >> 8));
|
828
|
+
stbiw__sbpush(out, STBIW_UCHAR(s1));
|
811
829
|
}
|
812
830
|
*out_len = stbiw__sbn(out);
|
813
831
|
// make returned pointer freeable
|
@@ -815,21 +833,52 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
|
815
833
|
return (unsigned char *) stbiw__sbraw(out);
|
816
834
|
}
|
817
835
|
|
818
|
-
unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
836
|
+
static unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
819
837
|
{
|
820
|
-
static unsigned int crc_table[256]
|
838
|
+
static unsigned int crc_table[256] =
|
839
|
+
{
|
840
|
+
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
841
|
+
0x0eDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
842
|
+
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
843
|
+
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
|
844
|
+
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
|
845
|
+
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
|
846
|
+
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
|
847
|
+
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
|
848
|
+
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
|
849
|
+
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
|
850
|
+
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
|
851
|
+
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
|
852
|
+
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
|
853
|
+
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
854
|
+
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
|
855
|
+
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
856
|
+
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
|
857
|
+
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
|
858
|
+
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
|
859
|
+
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
|
860
|
+
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
861
|
+
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
|
862
|
+
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
|
863
|
+
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
864
|
+
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
|
865
|
+
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
|
866
|
+
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
867
|
+
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
868
|
+
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
|
869
|
+
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
870
|
+
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
|
871
|
+
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
|
872
|
+
};
|
873
|
+
|
821
874
|
unsigned int crc = ~0u;
|
822
|
-
int i
|
823
|
-
if (crc_table[1] == 0)
|
824
|
-
for(i=0; i < 256; i++)
|
825
|
-
for (crc_table[i]=i, j=0; j < 8; ++j)
|
826
|
-
crc_table[i] = (crc_table[i] >> 1) ^ (crc_table[i] & 1 ? 0xedb88320 : 0);
|
875
|
+
int i;
|
827
876
|
for (i=0; i < len; ++i)
|
828
877
|
crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
|
829
878
|
return ~crc;
|
830
879
|
}
|
831
880
|
|
832
|
-
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=(
|
881
|
+
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4)
|
833
882
|
#define stbiw__wp32(data,v) stbiw__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v));
|
834
883
|
#define stbiw__wptag(data,s) stbiw__wpng4(data, s[0],s[1],s[2],s[3])
|
835
884
|
|
@@ -842,9 +891,9 @@ static void stbiw__wpcrc(unsigned char **data, int len)
|
|
842
891
|
static unsigned char stbiw__paeth(int a, int b, int c)
|
843
892
|
{
|
844
893
|
int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c);
|
845
|
-
if (pa <= pb && pa <= pc) return (
|
846
|
-
if (pb <= pc) return (
|
847
|
-
return (
|
894
|
+
if (pa <= pb && pa <= pc) return STBIW_UCHAR(a);
|
895
|
+
if (pb <= pc) return STBIW_UCHAR(b);
|
896
|
+
return STBIW_UCHAR(c);
|
848
897
|
}
|
849
898
|
|
850
899
|
unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
@@ -917,7 +966,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
|
917
966
|
stbiw__wp32(o, x);
|
918
967
|
stbiw__wp32(o, y);
|
919
968
|
*o++ = 8;
|
920
|
-
*o++ = (
|
969
|
+
*o++ = STBIW_UCHAR(ctype[n]);
|
921
970
|
*o++ = 0;
|
922
971
|
*o++ = 0;
|
923
972
|
*o++ = 0;
|
@@ -968,6 +1017,12 @@ STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x,
|
|
968
1017
|
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
969
1018
|
|
970
1019
|
/* Revision history
|
1020
|
+
1.02 (2016-04-02)
|
1021
|
+
avoid allocating large structures on the stack
|
1022
|
+
1.01 (2016-01-16)
|
1023
|
+
STBIW_REALLOC_SIZED: support allocators with no realloc support
|
1024
|
+
avoid race-condition in crc initialization
|
1025
|
+
minor compile issues
|
971
1026
|
1.00 (2015-09-14)
|
972
1027
|
installable file IO function
|
973
1028
|
0.99 (2015-09-13)
|
data/src/stb_vorbis.c
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
// Ogg Vorbis audio decoder - v1.
|
1
|
+
// Ogg Vorbis audio decoder - v1.09 - public domain
|
2
2
|
// http://nothings.org/stb_vorbis/
|
3
3
|
//
|
4
|
-
//
|
5
|
-
//
|
4
|
+
// Original version written by Sean Barrett in 2007.
|
5
|
+
//
|
6
|
+
// Originally sponsored by RAD Game Tools. Seeking sponsored
|
7
|
+
// by Phillip Bennefall, Marc Andersen, Aaron Baker, Elias Software,
|
8
|
+
// Aras Pranckevicius, and Sean Barrett.
|
6
9
|
//
|
7
10
|
// LICENSE
|
8
11
|
//
|
9
|
-
// This software is
|
10
|
-
//
|
11
|
-
//
|
12
|
+
// This software is dual-licensed to the public domain and under the following
|
13
|
+
// license: you are granted a perpetual, irrevocable license to copy, modify,
|
14
|
+
// publish, and distribute this file as you see fit.
|
12
15
|
//
|
13
16
|
// No warranty for any purpose is expressed or implied by the author (nor
|
14
17
|
// by RAD Game Tools). Report bugs and send enhancements to the author.
|
@@ -28,13 +31,15 @@
|
|
28
31
|
// Terje Mathisen Niklas Frykholm Andy Hill
|
29
32
|
// Casey Muratori John Bolton Gargaj
|
30
33
|
// Laurent Gomila Marc LeBlanc Ronny Chevalier
|
31
|
-
// Bernhard Wodo Evan Balster
|
34
|
+
// Bernhard Wodo Evan Balster alxprd@github
|
32
35
|
// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
|
33
|
-
//
|
34
|
-
//
|
35
|
-
// list them all because I was lax about updating for a long time, sorry.)
|
36
|
+
// Phillip Bennefall Rohit Thiago Goulart
|
37
|
+
// manxorist@github saga musix
|
36
38
|
//
|
37
39
|
// Partial history:
|
40
|
+
// 1.09 - 2016/04/04 - back out 'truncation of last frame' fix from previous version
|
41
|
+
// 1.08 - 2016/04/02 - warnings; setup memory leaks; truncation of last frame
|
42
|
+
// 1.07 - 2015/01/16 - fixes for crashes on invalid files; warning fixes; const
|
38
43
|
// 1.06 - 2015/08/31 - full, correct support for seeking API (Dougall Johnson)
|
39
44
|
// some crash fixes when out of memory or with corrupt files
|
40
45
|
// fix some inappropriately signed shifts
|
@@ -45,8 +50,6 @@
|
|
45
50
|
// 1.01 - 2014/06/18 - fix stb_vorbis_get_samples_float (interleaved was correct)
|
46
51
|
// 1.0 - 2014/05/26 - fix memory leaks; fix warnings; fix bugs in >2-channel;
|
47
52
|
// (API change) report sample rate for decode-full-file funcs
|
48
|
-
// 0.99996 - - bracket #include <malloc.h> for macintosh compilation
|
49
|
-
// 0.99995 - - avoid alias-optimization issue in float-to-int conversion
|
50
53
|
//
|
51
54
|
// See end of file for full version history.
|
52
55
|
|
@@ -155,10 +158,10 @@ extern unsigned int stb_vorbis_get_file_offset(stb_vorbis *f);
|
|
155
158
|
// specification does not bound the size of an individual frame.
|
156
159
|
|
157
160
|
extern stb_vorbis *stb_vorbis_open_pushdata(
|
158
|
-
unsigned char *datablock, int datablock_length_in_bytes,
|
161
|
+
const unsigned char * datablock, int datablock_length_in_bytes,
|
159
162
|
int *datablock_memory_consumed_in_bytes,
|
160
163
|
int *error,
|
161
|
-
stb_vorbis_alloc *alloc_buffer);
|
164
|
+
const stb_vorbis_alloc *alloc_buffer);
|
162
165
|
// create a vorbis decoder by passing in the initial data block containing
|
163
166
|
// the ogg&vorbis headers (you don't need to do parse them, just provide
|
164
167
|
// the first N bytes of the file--you're told if it's not enough, see below)
|
@@ -169,7 +172,8 @@ extern stb_vorbis *stb_vorbis_open_pushdata(
|
|
169
172
|
// incomplete and you need to pass in a larger block from the start of the file
|
170
173
|
|
171
174
|
extern int stb_vorbis_decode_frame_pushdata(
|
172
|
-
stb_vorbis *f,
|
175
|
+
stb_vorbis *f,
|
176
|
+
const unsigned char *datablock, int datablock_length_in_bytes,
|
173
177
|
int *channels, // place to write number of float * buffers
|
174
178
|
float ***output, // place to write float ** array of float * buffers
|
175
179
|
int *samples // place to write number of output samples
|
@@ -233,18 +237,18 @@ extern int stb_vorbis_decode_memory(const unsigned char *mem, int len, int *chan
|
|
233
237
|
// When you're done with it, just free() the pointer returned in *output.
|
234
238
|
|
235
239
|
extern stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len,
|
236
|
-
int *error, stb_vorbis_alloc *alloc_buffer);
|
240
|
+
int *error, const stb_vorbis_alloc *alloc_buffer);
|
237
241
|
// create an ogg vorbis decoder from an ogg vorbis stream in memory (note
|
238
242
|
// this must be the entire stream!). on failure, returns NULL and sets *error
|
239
243
|
|
240
244
|
#ifndef STB_VORBIS_NO_STDIO
|
241
245
|
extern stb_vorbis * stb_vorbis_open_filename(const char *filename,
|
242
|
-
int *error, stb_vorbis_alloc *alloc_buffer);
|
246
|
+
int *error, const stb_vorbis_alloc *alloc_buffer);
|
243
247
|
// create an ogg vorbis decoder from a filename via fopen(). on failure,
|
244
248
|
// returns NULL and sets *error (possibly to VORBIS_file_open_failure).
|
245
249
|
|
246
250
|
extern stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close,
|
247
|
-
int *error, stb_vorbis_alloc *alloc_buffer);
|
251
|
+
int *error, const stb_vorbis_alloc *alloc_buffer);
|
248
252
|
// create an ogg vorbis decoder from an open FILE *, looking for a stream at
|
249
253
|
// the _current_ seek point (ftell). on failure, returns NULL and sets *error.
|
250
254
|
// note that stb_vorbis must "own" this stream; if you seek it in between
|
@@ -254,7 +258,7 @@ extern stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close,
|
|
254
258
|
// function, stb_vorbis_open_file_section(), to limit it.
|
255
259
|
|
256
260
|
extern stb_vorbis * stb_vorbis_open_file_section(FILE *f, int close_handle_on_close,
|
257
|
-
int *error, stb_vorbis_alloc *alloc_buffer, unsigned int len);
|
261
|
+
int *error, const stb_vorbis_alloc *alloc_buffer, unsigned int len);
|
258
262
|
// create an ogg vorbis decoder from an open FILE *, looking for a stream at
|
259
263
|
// the _current_ seek point (ftell); the stream will be of length 'len' bytes.
|
260
264
|
// on failure, returns NULL and sets *error. note that stb_vorbis must "own"
|
@@ -292,15 +296,17 @@ extern int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***out
|
|
292
296
|
extern int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts);
|
293
297
|
extern int stb_vorbis_get_frame_short (stb_vorbis *f, int num_c, short **buffer, int num_samples);
|
294
298
|
#endif
|
295
|
-
// decode the next frame and return the number of samples per channel.
|
296
|
-
// data
|
299
|
+
// decode the next frame and return the number of *samples* per channel.
|
300
|
+
// Note that for interleaved data, you pass in the number of shorts (the
|
301
|
+
// size of your array), but the return value is the number of samples per
|
302
|
+
// channel, not the total number of samples.
|
303
|
+
//
|
304
|
+
// The data is coerced to the number of channels you request according to the
|
297
305
|
// channel coercion rules (see below). You must pass in the size of your
|
298
306
|
// buffer(s) so that stb_vorbis will not overwrite the end of the buffer.
|
299
307
|
// The maximum buffer size needed can be gotten from get_info(); however,
|
300
308
|
// the Vorbis I specification implies an absolute maximum of 4096 samples
|
301
|
-
// per channel.
|
302
|
-
// shorts (the size of your array), but the return value is the number of
|
303
|
-
// samples per channel, not the total number of samples.
|
309
|
+
// per channel.
|
304
310
|
|
305
311
|
// Channel coercion rules:
|
306
312
|
// Let M be the number of channels requested, and N the number of channels present,
|
@@ -367,7 +373,7 @@ enum STBVorbisError
|
|
367
373
|
VORBIS_invalid_first_page,
|
368
374
|
VORBIS_bad_packet_type,
|
369
375
|
VORBIS_cant_find_last_page,
|
370
|
-
VORBIS_seek_failed
|
376
|
+
VORBIS_seek_failed
|
371
377
|
};
|
372
378
|
|
373
379
|
|
@@ -488,14 +494,8 @@ enum STBVorbisError
|
|
488
494
|
// trade off storage for speed.
|
489
495
|
//#define STB_VORBIS_DIVIDES_IN_CODEBOOK
|
490
496
|
|
491
|
-
|
492
|
-
|
493
|
-
// b are floating point per-codebook constants, and x is a 16-bit int.
|
494
|
-
// Normally, stb_vorbis decodes them to floats rather than leaving them
|
495
|
-
// as 16-bit ints and computing ax+b while decoding. This is a speed/space
|
496
|
-
// tradeoff; you can save space by defining this flag.
|
497
|
-
#ifndef STB_VORBIS_CODEBOOK_SHORTS
|
498
|
-
#define STB_VORBIS_CODEBOOK_FLOATS
|
497
|
+
#ifdef STB_VORBIS_CODEBOOK_SHORTS
|
498
|
+
#error "STB_VORBIS_CODEBOOK_SHORTS is no longer supported as it produced incorrect results for some input formats"
|
499
499
|
#endif
|
500
500
|
|
501
501
|
// STB_VORBIS_DIVIDE_TABLE
|
@@ -555,12 +555,30 @@ enum STBVorbisError
|
|
555
555
|
#include <math.h>
|
556
556
|
#if !(defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh))
|
557
557
|
#include <malloc.h>
|
558
|
+
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__)
|
559
|
+
#include <alloca.h>
|
558
560
|
#endif
|
559
|
-
#else
|
560
|
-
#define NULL 0
|
561
561
|
#endif
|
562
|
-
|
563
|
-
#
|
562
|
+
#else // STB_VORBIS_NO_CRT
|
563
|
+
#define NULL 0
|
564
|
+
#define malloc(s) 0
|
565
|
+
#define free(s) ((void) 0)
|
566
|
+
#define realloc(s) 0
|
567
|
+
#endif // STB_VORBIS_NO_CRT
|
568
|
+
|
569
|
+
#include <limits.h>
|
570
|
+
|
571
|
+
#ifdef __MINGW32__
|
572
|
+
// eff you mingw:
|
573
|
+
// "fixed":
|
574
|
+
// http://sourceforge.net/p/mingw-w64/mailman/message/32882927/
|
575
|
+
// "no that broke the build, reverted, who cares about C":
|
576
|
+
// http://sourceforge.net/p/mingw-w64/mailman/message/32890381/
|
577
|
+
#ifdef __forceinline
|
578
|
+
#undef __forceinline
|
579
|
+
#endif
|
580
|
+
#define __forceinline
|
581
|
+
#elif !defined(_MSC_VER)
|
564
582
|
#if __GNUC__
|
565
583
|
#define __forceinline inline
|
566
584
|
#else
|
@@ -577,6 +595,13 @@ enum STBVorbisError
|
|
577
595
|
#endif
|
578
596
|
|
579
597
|
|
598
|
+
#if 0
|
599
|
+
#include <crtdbg.h>
|
600
|
+
#define CHECK(f) _CrtIsValidHeapPointer(f->channel_buffers[1])
|
601
|
+
#else
|
602
|
+
#define CHECK(f) ((void) 0)
|
603
|
+
#endif
|
604
|
+
|
580
605
|
#define MAX_BLOCKSIZE_LOG 13 // from specification
|
581
606
|
#define MAX_BLOCKSIZE (1 << MAX_BLOCKSIZE_LOG)
|
582
607
|
|
@@ -593,11 +618,7 @@ typedef signed int int32;
|
|
593
618
|
#define FALSE 0
|
594
619
|
#endif
|
595
620
|
|
596
|
-
#ifdef STB_VORBIS_CODEBOOK_FLOATS
|
597
621
|
typedef float codetype;
|
598
|
-
#else
|
599
|
-
typedef uint16 codetype;
|
600
|
-
#endif
|
601
622
|
|
602
623
|
// @NOTE
|
603
624
|
//
|
@@ -831,13 +852,6 @@ struct stb_vorbis
|
|
831
852
|
int channel_buffer_end;
|
832
853
|
};
|
833
854
|
|
834
|
-
extern int my_prof(int slot);
|
835
|
-
//#define stb_prof my_prof
|
836
|
-
|
837
|
-
#ifndef stb_prof
|
838
|
-
#define stb_prof(x) ((void) 0)
|
839
|
-
#endif
|
840
|
-
|
841
855
|
#if defined(STB_VORBIS_NO_PUSHDATA_API)
|
842
856
|
#define IS_PUSH_MODE(f) FALSE
|
843
857
|
#elif defined(STB_VORBIS_NO_PULLDATA_API)
|
@@ -904,7 +918,7 @@ static void *setup_malloc(vorb *f, int sz)
|
|
904
918
|
|
905
919
|
static void setup_free(vorb *f, void *p)
|
906
920
|
{
|
907
|
-
if (f->alloc.alloc_buffer) return; // do nothing; setup mem is
|
921
|
+
if (f->alloc.alloc_buffer) return; // do nothing; setup mem is a stack
|
908
922
|
free(p);
|
909
923
|
}
|
910
924
|
|
@@ -1055,10 +1069,12 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
|
|
1055
1069
|
while (z > 0 && !available[z]) --z;
|
1056
1070
|
if (z == 0) { return FALSE; }
|
1057
1071
|
res = available[z];
|
1072
|
+
assert(z >= 0 && z < 32);
|
1058
1073
|
available[z] = 0;
|
1059
1074
|
add_entry(c, bit_reverse(res), i, m++, len[i], values);
|
1060
1075
|
// propogate availability up the tree
|
1061
1076
|
if (z != len[i]) {
|
1077
|
+
assert(len[i] >= 0 && len[i] < 32);
|
1062
1078
|
for (y=len[i]; y > z; --y) {
|
1063
1079
|
assert(available[y] == 0);
|
1064
1080
|
available[y] = res + (1 << (32-y));
|
@@ -1576,7 +1592,7 @@ enum
|
|
1576
1592
|
{
|
1577
1593
|
VORBIS_packet_id = 1,
|
1578
1594
|
VORBIS_packet_comment = 3,
|
1579
|
-
VORBIS_packet_setup = 5
|
1595
|
+
VORBIS_packet_setup = 5
|
1580
1596
|
};
|
1581
1597
|
|
1582
1598
|
static int codebook_decode_scalar_raw(vorb *f, Codebook *c)
|
@@ -1584,7 +1600,9 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c)
|
|
1584
1600
|
int i;
|
1585
1601
|
prep_huffman(f);
|
1586
1602
|
|
1587
|
-
|
1603
|
+
if (c->codewords == NULL && c->sorted_codewords == NULL)
|
1604
|
+
return -1;
|
1605
|
+
|
1588
1606
|
// cases to use binary search: sorted_codewords && !c->codewords
|
1589
1607
|
// sorted_codewords && c->entries > 8
|
1590
1608
|
if (c->entries > 8 ? c->sorted_codewords!=NULL : !c->codewords) {
|
@@ -1692,15 +1710,9 @@ static int codebook_decode_scalar(vorb *f, Codebook *c)
|
|
1692
1710
|
|
1693
1711
|
// CODEBOOK_ELEMENT_FAST is an optimization for the CODEBOOK_FLOATS case
|
1694
1712
|
// where we avoid one addition
|
1695
|
-
#
|
1696
|
-
|
1697
|
-
|
1698
|
-
#define CODEBOOK_ELEMENT_BASE(c) (c->minimum_value)
|
1699
|
-
#else
|
1700
|
-
#define CODEBOOK_ELEMENT(c,off) (c->multiplicands[off])
|
1701
|
-
#define CODEBOOK_ELEMENT_FAST(c,off) (c->multiplicands[off])
|
1702
|
-
#define CODEBOOK_ELEMENT_BASE(c) (0)
|
1703
|
-
#endif
|
1713
|
+
#define CODEBOOK_ELEMENT(c,off) (c->multiplicands[off])
|
1714
|
+
#define CODEBOOK_ELEMENT_FAST(c,off) (c->multiplicands[off])
|
1715
|
+
#define CODEBOOK_ELEMENT_BASE(c) (0)
|
1704
1716
|
|
1705
1717
|
static int codebook_decode_start(vorb *f, Codebook *c)
|
1706
1718
|
{
|
@@ -1862,86 +1874,6 @@ static int codebook_decode_deinterleave_repeat(vorb *f, Codebook *c, float **out
|
|
1862
1874
|
return TRUE;
|
1863
1875
|
}
|
1864
1876
|
|
1865
|
-
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
|
1866
|
-
static int codebook_decode_deinterleave_repeat_2(vorb *f, Codebook *c, float **outputs, int *c_inter_p, int *p_inter_p, int len, int total_decode)
|
1867
|
-
{
|
1868
|
-
int c_inter = *c_inter_p;
|
1869
|
-
int p_inter = *p_inter_p;
|
1870
|
-
int i,z, effective = c->dimensions;
|
1871
|
-
|
1872
|
-
// type 0 is only legal in a scalar context
|
1873
|
-
if (c->lookup_type == 0) return error(f, VORBIS_invalid_stream);
|
1874
|
-
|
1875
|
-
while (total_decode > 0) {
|
1876
|
-
float last = CODEBOOK_ELEMENT_BASE(c);
|
1877
|
-
DECODE_VQ(z,f,c);
|
1878
|
-
|
1879
|
-
if (z < 0) {
|
1880
|
-
if (!f->bytes_in_seg)
|
1881
|
-
if (f->last_seg) return FALSE;
|
1882
|
-
return error(f, VORBIS_invalid_stream);
|
1883
|
-
}
|
1884
|
-
|
1885
|
-
// if this will take us off the end of the buffers, stop short!
|
1886
|
-
// we check by computing the length of the virtual interleaved
|
1887
|
-
// buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter),
|
1888
|
-
// and the length we'll be using (effective)
|
1889
|
-
if (c_inter + p_inter*2 + effective > len * 2) {
|
1890
|
-
effective = len*2 - (p_inter*2 - c_inter);
|
1891
|
-
}
|
1892
|
-
|
1893
|
-
{
|
1894
|
-
z *= c->dimensions;
|
1895
|
-
stb_prof(11);
|
1896
|
-
if (c->sequence_p) {
|
1897
|
-
// haven't optimized this case because I don't have any examples
|
1898
|
-
for (i=0; i < effective; ++i) {
|
1899
|
-
float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
|
1900
|
-
if (outputs[c_inter])
|
1901
|
-
outputs[c_inter][p_inter] += val;
|
1902
|
-
if (++c_inter == 2) { c_inter = 0; ++p_inter; }
|
1903
|
-
last = val;
|
1904
|
-
}
|
1905
|
-
} else {
|
1906
|
-
i=0;
|
1907
|
-
if (c_inter == 1) {
|
1908
|
-
float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
|
1909
|
-
if (outputs[c_inter])
|
1910
|
-
outputs[c_inter][p_inter] += val;
|
1911
|
-
c_inter = 0; ++p_inter;
|
1912
|
-
++i;
|
1913
|
-
}
|
1914
|
-
{
|
1915
|
-
float *z0 = outputs[0];
|
1916
|
-
float *z1 = outputs[1];
|
1917
|
-
for (; i+1 < effective;) {
|
1918
|
-
float v0 = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
|
1919
|
-
float v1 = CODEBOOK_ELEMENT_FAST(c,z+i+1) + last;
|
1920
|
-
if (z0)
|
1921
|
-
z0[p_inter] += v0;
|
1922
|
-
if (z1)
|
1923
|
-
z1[p_inter] += v1;
|
1924
|
-
++p_inter;
|
1925
|
-
i += 2;
|
1926
|
-
}
|
1927
|
-
}
|
1928
|
-
if (i < effective) {
|
1929
|
-
float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
|
1930
|
-
if (outputs[c_inter])
|
1931
|
-
outputs[c_inter][p_inter] += val;
|
1932
|
-
if (++c_inter == 2) { c_inter = 0; ++p_inter; }
|
1933
|
-
}
|
1934
|
-
}
|
1935
|
-
}
|
1936
|
-
|
1937
|
-
total_decode -= effective;
|
1938
|
-
}
|
1939
|
-
*c_inter_p = c_inter;
|
1940
|
-
*p_inter_p = p_inter;
|
1941
|
-
return TRUE;
|
1942
|
-
}
|
1943
|
-
#endif
|
1944
|
-
|
1945
1877
|
static int predict_point(int x, int x0, int x1, int y0, int y1)
|
1946
1878
|
{
|
1947
1879
|
int dy = y1 - y0;
|
@@ -2076,15 +2008,17 @@ static __forceinline void draw_line(float *output, int x0, int y0, int x1, int y
|
|
2076
2008
|
#endif
|
2077
2009
|
ady -= abs(base) * adx;
|
2078
2010
|
if (x1 > n) x1 = n;
|
2079
|
-
|
2080
|
-
for (++x; x < x1; ++x) {
|
2081
|
-
err += ady;
|
2082
|
-
if (err >= adx) {
|
2083
|
-
err -= adx;
|
2084
|
-
y += sy;
|
2085
|
-
} else
|
2086
|
-
y += base;
|
2011
|
+
if (x < x1) {
|
2087
2012
|
LINE_OP(output[x], inverse_db_table[y]);
|
2013
|
+
for (++x; x < x1; ++x) {
|
2014
|
+
err += ady;
|
2015
|
+
if (err >= adx) {
|
2016
|
+
err -= adx;
|
2017
|
+
y += sy;
|
2018
|
+
} else
|
2019
|
+
y += base;
|
2020
|
+
LINE_OP(output[x], inverse_db_table[y]);
|
2021
|
+
}
|
2088
2022
|
}
|
2089
2023
|
}
|
2090
2024
|
|
@@ -2123,7 +2057,8 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2123
2057
|
int **classifications = (int **) temp_block_array(f,f->channels, part_read * sizeof(**classifications));
|
2124
2058
|
#endif
|
2125
2059
|
|
2126
|
-
|
2060
|
+
CHECK(f);
|
2061
|
+
|
2127
2062
|
for (i=0; i < ch; ++i)
|
2128
2063
|
if (!do_not_decode[i])
|
2129
2064
|
memset(residue_buffers[i], 0, sizeof(float) * n);
|
@@ -2135,11 +2070,9 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2135
2070
|
if (j == ch)
|
2136
2071
|
goto done;
|
2137
2072
|
|
2138
|
-
stb_prof(3);
|
2139
2073
|
for (pass=0; pass < 8; ++pass) {
|
2140
2074
|
int pcount = 0, class_set = 0;
|
2141
2075
|
if (ch == 2) {
|
2142
|
-
stb_prof(13);
|
2143
2076
|
while (pcount < part_read) {
|
2144
2077
|
int z = r->begin + pcount*r->part_size;
|
2145
2078
|
int c_inter = (z & 1), p_inter = z>>1;
|
@@ -2157,7 +2090,6 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2157
2090
|
}
|
2158
2091
|
#endif
|
2159
2092
|
}
|
2160
|
-
stb_prof(5);
|
2161
2093
|
for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
|
2162
2094
|
int z = r->begin + pcount*r->part_size;
|
2163
2095
|
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
|
@@ -2168,23 +2100,20 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2168
2100
|
int b = r->residue_books[c][pass];
|
2169
2101
|
if (b >= 0) {
|
2170
2102
|
Codebook *book = f->codebooks + b;
|
2171
|
-
stb_prof(20); // accounts for X time
|
2172
2103
|
#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
|
2173
2104
|
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
|
2174
2105
|
goto done;
|
2175
2106
|
#else
|
2176
2107
|
// saves 1%
|
2177
|
-
if (!
|
2108
|
+
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
|
2178
2109
|
goto done;
|
2179
2110
|
#endif
|
2180
|
-
stb_prof(7);
|
2181
2111
|
} else {
|
2182
2112
|
z += r->part_size;
|
2183
2113
|
c_inter = z & 1;
|
2184
2114
|
p_inter = z >> 1;
|
2185
2115
|
}
|
2186
2116
|
}
|
2187
|
-
stb_prof(8);
|
2188
2117
|
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
|
2189
2118
|
++class_set;
|
2190
2119
|
#endif
|
@@ -2217,10 +2146,8 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2217
2146
|
int b = r->residue_books[c][pass];
|
2218
2147
|
if (b >= 0) {
|
2219
2148
|
Codebook *book = f->codebooks + b;
|
2220
|
-
stb_prof(22);
|
2221
2149
|
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
|
2222
2150
|
goto done;
|
2223
|
-
stb_prof(3);
|
2224
2151
|
} else {
|
2225
2152
|
z += r->part_size;
|
2226
2153
|
c_inter = 0;
|
@@ -2259,10 +2186,8 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2259
2186
|
int b = r->residue_books[c][pass];
|
2260
2187
|
if (b >= 0) {
|
2261
2188
|
Codebook *book = f->codebooks + b;
|
2262
|
-
stb_prof(22);
|
2263
2189
|
if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
|
2264
2190
|
goto done;
|
2265
|
-
stb_prof(3);
|
2266
2191
|
} else {
|
2267
2192
|
z += r->part_size;
|
2268
2193
|
c_inter = z % ch;
|
@@ -2277,7 +2202,7 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2277
2202
|
}
|
2278
2203
|
goto done;
|
2279
2204
|
}
|
2280
|
-
|
2205
|
+
CHECK(f);
|
2281
2206
|
|
2282
2207
|
for (pass=0; pass < 8; ++pass) {
|
2283
2208
|
int pcount = 0, class_set=0;
|
@@ -2326,7 +2251,12 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int
|
|
2326
2251
|
}
|
2327
2252
|
}
|
2328
2253
|
done:
|
2329
|
-
|
2254
|
+
CHECK(f);
|
2255
|
+
#ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
|
2256
|
+
temp_free(f,part_classdata);
|
2257
|
+
#else
|
2258
|
+
temp_free(f,classifications);
|
2259
|
+
#endif
|
2330
2260
|
temp_alloc_restore(f,temp_alloc_point);
|
2331
2261
|
}
|
2332
2262
|
|
@@ -2972,6 +2902,7 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype)
|
|
2972
2902
|
}
|
2973
2903
|
}
|
2974
2904
|
|
2905
|
+
temp_free(f,buf2);
|
2975
2906
|
temp_alloc_restore(f,save_point);
|
2976
2907
|
}
|
2977
2908
|
|
@@ -3140,13 +3071,16 @@ static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *f
|
|
3140
3071
|
int hx = g->Xlist[j];
|
3141
3072
|
if (lx != hx)
|
3142
3073
|
draw_line(target, lx,ly, hx,hy, n2);
|
3074
|
+
CHECK(f);
|
3143
3075
|
lx = hx, ly = hy;
|
3144
3076
|
}
|
3145
3077
|
}
|
3146
|
-
if (lx < n2)
|
3078
|
+
if (lx < n2) {
|
3147
3079
|
// optimization of: draw_line(target, lx,ly, n,ly, n2);
|
3148
3080
|
for (j=lx; j < n2; ++j)
|
3149
3081
|
LINE_OP(target[j], inverse_db_table[ly]);
|
3082
|
+
CHECK(f);
|
3083
|
+
}
|
3150
3084
|
}
|
3151
3085
|
return TRUE;
|
3152
3086
|
}
|
@@ -3217,6 +3151,7 @@ static int vorbis_decode_initial(vorb *f, int *p_left_start, int *p_left_end, in
|
|
3217
3151
|
*p_right_start = window_center;
|
3218
3152
|
*p_right_end = n;
|
3219
3153
|
}
|
3154
|
+
|
3220
3155
|
return TRUE;
|
3221
3156
|
}
|
3222
3157
|
|
@@ -3235,7 +3170,8 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3235
3170
|
// FLOORS
|
3236
3171
|
n2 = n >> 1;
|
3237
3172
|
|
3238
|
-
|
3173
|
+
CHECK(f);
|
3174
|
+
|
3239
3175
|
for (i=0; i < f->channels; ++i) {
|
3240
3176
|
int s = map->chan[i].mux, floor;
|
3241
3177
|
zero_channel[i] = FALSE;
|
@@ -3327,7 +3263,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3327
3263
|
// at this point we've decoded the floor into buffer
|
3328
3264
|
}
|
3329
3265
|
}
|
3330
|
-
|
3266
|
+
CHECK(f);
|
3331
3267
|
// at this point we've decoded all floors
|
3332
3268
|
|
3333
3269
|
if (f->alloc.alloc_buffer)
|
@@ -3340,6 +3276,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3340
3276
|
zero_channel[map->chan[i].magnitude] = zero_channel[map->chan[i].angle] = FALSE;
|
3341
3277
|
}
|
3342
3278
|
|
3279
|
+
CHECK(f);
|
3343
3280
|
// RESIDUE DECODE
|
3344
3281
|
for (i=0; i < map->submaps; ++i) {
|
3345
3282
|
float *residue_buffers[STB_VORBIS_MAX_CHANNELS];
|
@@ -3364,9 +3301,9 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3364
3301
|
|
3365
3302
|
if (f->alloc.alloc_buffer)
|
3366
3303
|
assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset);
|
3304
|
+
CHECK(f);
|
3367
3305
|
|
3368
3306
|
// INVERSE COUPLING
|
3369
|
-
stb_prof(14);
|
3370
3307
|
for (i = map->coupling_steps-1; i >= 0; --i) {
|
3371
3308
|
int n2 = n >> 1;
|
3372
3309
|
float *m = f->channel_buffers[map->chan[i].magnitude];
|
@@ -3387,10 +3324,10 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3387
3324
|
a[j] = a2;
|
3388
3325
|
}
|
3389
3326
|
}
|
3327
|
+
CHECK(f);
|
3390
3328
|
|
3391
3329
|
// finish decoding the floors
|
3392
3330
|
#ifndef STB_VORBIS_NO_DEFER_FLOOR
|
3393
|
-
stb_prof(15);
|
3394
3331
|
for (i=0; i < f->channels; ++i) {
|
3395
3332
|
if (really_zero_channel[i]) {
|
3396
3333
|
memset(f->channel_buffers[i], 0, sizeof(*f->channel_buffers[i]) * n2);
|
@@ -3410,10 +3347,10 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3410
3347
|
#endif
|
3411
3348
|
|
3412
3349
|
// INVERSE MDCT
|
3413
|
-
|
3350
|
+
CHECK(f);
|
3414
3351
|
for (i=0; i < f->channels; ++i)
|
3415
3352
|
inverse_mdct(f->channel_buffers[i], n, f, m->blockflag);
|
3416
|
-
|
3353
|
+
CHECK(f);
|
3417
3354
|
|
3418
3355
|
// this shouldn't be necessary, unless we exited on an error
|
3419
3356
|
// and want to flush to get to the next packet
|
@@ -3455,7 +3392,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3455
3392
|
if (f->current_loc_valid && (f->page_flag & PAGEFLAG_last_page)) {
|
3456
3393
|
uint32 current_end = f->known_loc_for_packet - (n-right_end);
|
3457
3394
|
// then let's infer the size of the (probably) short final frame
|
3458
|
-
if (current_end < f->current_loc + right_end) {
|
3395
|
+
if (current_end < f->current_loc + (right_end-left_start)) {
|
3459
3396
|
if (current_end < f->current_loc) {
|
3460
3397
|
// negative truncation, that's impossible!
|
3461
3398
|
*len = 0;
|
@@ -3463,6 +3400,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3463
3400
|
*len = current_end - f->current_loc;
|
3464
3401
|
}
|
3465
3402
|
*len += left_start;
|
3403
|
+
if (*len > right_end) *len = right_end; // this should never happen
|
3466
3404
|
f->current_loc += *len;
|
3467
3405
|
return TRUE;
|
3468
3406
|
}
|
@@ -3480,6 +3418,8 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
|
|
3480
3418
|
if (f->alloc.alloc_buffer)
|
3481
3419
|
assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset);
|
3482
3420
|
*len = right_end; // ignore samples after the window goes to 0
|
3421
|
+
CHECK(f);
|
3422
|
+
|
3483
3423
|
return TRUE;
|
3484
3424
|
}
|
3485
3425
|
|
@@ -3645,14 +3585,15 @@ static int start_decoder(vorb *f)
|
|
3645
3585
|
get32(f); // bitrate_nominal
|
3646
3586
|
get32(f); // bitrate_minimum
|
3647
3587
|
x = get8(f);
|
3648
|
-
{
|
3649
|
-
|
3650
|
-
|
3651
|
-
|
3652
|
-
|
3653
|
-
|
3654
|
-
|
3655
|
-
|
3588
|
+
{
|
3589
|
+
int log0,log1;
|
3590
|
+
log0 = x & 15;
|
3591
|
+
log1 = x >> 4;
|
3592
|
+
f->blocksize_0 = 1 << log0;
|
3593
|
+
f->blocksize_1 = 1 << log1;
|
3594
|
+
if (log0 < 6 || log0 > 13) return error(f, VORBIS_invalid_setup);
|
3595
|
+
if (log1 < 6 || log1 > 13) return error(f, VORBIS_invalid_setup);
|
3596
|
+
if (log0 > log1) return error(f, VORBIS_invalid_setup);
|
3656
3597
|
}
|
3657
3598
|
|
3658
3599
|
// framing_flag
|
@@ -3701,6 +3642,7 @@ static int start_decoder(vorb *f)
|
|
3701
3642
|
int total=0;
|
3702
3643
|
uint8 *lengths;
|
3703
3644
|
Codebook *c = f->codebooks+i;
|
3645
|
+
CHECK(f);
|
3704
3646
|
x = get_bits(f, 8); if (x != 0x42) return error(f, VORBIS_invalid_setup);
|
3705
3647
|
x = get_bits(f, 8); if (x != 0x43) return error(f, VORBIS_invalid_setup);
|
3706
3648
|
x = get_bits(f, 8); if (x != 0x56) return error(f, VORBIS_invalid_setup);
|
@@ -3712,6 +3654,8 @@ static int start_decoder(vorb *f)
|
|
3712
3654
|
ordered = get_bits(f,1);
|
3713
3655
|
c->sparse = ordered ? 0 : get_bits(f,1);
|
3714
3656
|
|
3657
|
+
if (c->dimensions == 0 && c->entries != 0) return error(f, VORBIS_invalid_setup);
|
3658
|
+
|
3715
3659
|
if (c->sparse)
|
3716
3660
|
lengths = (uint8 *) setup_temp_malloc(f, c->entries);
|
3717
3661
|
else
|
@@ -3736,6 +3680,8 @@ static int start_decoder(vorb *f)
|
|
3736
3680
|
if (present) {
|
3737
3681
|
lengths[j] = get_bits(f, 5) + 1;
|
3738
3682
|
++total;
|
3683
|
+
if (lengths[j] == 32)
|
3684
|
+
return error(f, VORBIS_invalid_setup);
|
3739
3685
|
} else {
|
3740
3686
|
lengths[j] = NO_CODE;
|
3741
3687
|
}
|
@@ -3770,6 +3716,7 @@ static int start_decoder(vorb *f)
|
|
3770
3716
|
c->sorted_entries = sorted_count;
|
3771
3717
|
values = NULL;
|
3772
3718
|
|
3719
|
+
CHECK(f);
|
3773
3720
|
if (!c->sparse) {
|
3774
3721
|
c->codewords = (uint32 *) setup_malloc(f, sizeof(c->codewords[0]) * c->entries);
|
3775
3722
|
if (!c->codewords) return error(f, VORBIS_outofmem);
|
@@ -3815,6 +3762,7 @@ static int start_decoder(vorb *f)
|
|
3815
3762
|
|
3816
3763
|
compute_accelerated_huffman(c);
|
3817
3764
|
|
3765
|
+
CHECK(f);
|
3818
3766
|
c->lookup_type = get_bits(f, 4);
|
3819
3767
|
if (c->lookup_type > 2) return error(f, VORBIS_invalid_setup);
|
3820
3768
|
if (c->lookup_type > 0) {
|
@@ -3828,6 +3776,7 @@ static int start_decoder(vorb *f)
|
|
3828
3776
|
} else {
|
3829
3777
|
c->lookup_values = c->entries * c->dimensions;
|
3830
3778
|
}
|
3779
|
+
if (c->lookup_values == 0) return error(f, VORBIS_invalid_setup);
|
3831
3780
|
mults = (uint16 *) setup_temp_malloc(f, sizeof(mults[0]) * c->lookup_values);
|
3832
3781
|
if (mults == NULL) return error(f, VORBIS_outofmem);
|
3833
3782
|
for (j=0; j < (int) c->lookup_values; ++j) {
|
@@ -3839,6 +3788,7 @@ static int start_decoder(vorb *f)
|
|
3839
3788
|
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
|
3840
3789
|
if (c->lookup_type == 1) {
|
3841
3790
|
int len, sparse = c->sparse;
|
3791
|
+
float last=0;
|
3842
3792
|
// pre-expand the lookup1-style multiplicands, to avoid a divide in the inner loop
|
3843
3793
|
if (sparse) {
|
3844
3794
|
if (c->sorted_entries == 0) goto skip;
|
@@ -3848,51 +3798,48 @@ static int start_decoder(vorb *f)
|
|
3848
3798
|
if (c->multiplicands == NULL) { setup_temp_free(f,mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); }
|
3849
3799
|
len = sparse ? c->sorted_entries : c->entries;
|
3850
3800
|
for (j=0; j < len; ++j) {
|
3851
|
-
int z = sparse ? c->sorted_values[j] : j
|
3801
|
+
unsigned int z = sparse ? c->sorted_values[j] : j;
|
3802
|
+
unsigned int div=1;
|
3852
3803
|
for (k=0; k < c->dimensions; ++k) {
|
3853
3804
|
int off = (z / div) % c->lookup_values;
|
3854
|
-
|
3855
|
-
|
3856
|
-
|
3857
|
-
|
3858
|
-
|
3859
|
-
|
3860
|
-
|
3861
|
-
|
3862
|
-
|
3863
|
-
|
3864
|
-
|
3865
|
-
|
3805
|
+
float val = mults[off];
|
3806
|
+
val = mults[off]*c->delta_value + c->minimum_value + last;
|
3807
|
+
c->multiplicands[j*c->dimensions + k] = val;
|
3808
|
+
if (c->sequence_p)
|
3809
|
+
last = val;
|
3810
|
+
if (k+1 < c->dimensions) {
|
3811
|
+
if (div > UINT_MAX / (unsigned int) c->lookup_values) {
|
3812
|
+
setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values);
|
3813
|
+
return error(f, VORBIS_invalid_setup);
|
3814
|
+
}
|
3815
|
+
div *= c->lookup_values;
|
3816
|
+
}
|
3866
3817
|
}
|
3867
3818
|
}
|
3868
|
-
setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values);
|
3869
3819
|
c->lookup_type = 2;
|
3870
3820
|
}
|
3871
3821
|
else
|
3872
3822
|
#endif
|
3873
3823
|
{
|
3824
|
+
float last=0;
|
3825
|
+
CHECK(f);
|
3874
3826
|
c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->lookup_values);
|
3875
3827
|
if (c->multiplicands == NULL) { setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); }
|
3876
|
-
|
3877
|
-
|
3878
|
-
|
3879
|
-
|
3880
|
-
|
3881
|
-
|
3882
|
-
setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values);
|
3828
|
+
for (j=0; j < (int) c->lookup_values; ++j) {
|
3829
|
+
float val = mults[j] * c->delta_value + c->minimum_value + last;
|
3830
|
+
c->multiplicands[j] = val;
|
3831
|
+
if (c->sequence_p)
|
3832
|
+
last = val;
|
3833
|
+
}
|
3883
3834
|
}
|
3884
3835
|
#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
|
3885
3836
|
skip:;
|
3886
3837
|
#endif
|
3838
|
+
setup_temp_free(f, mults, sizeof(mults[0])*c->lookup_values);
|
3887
3839
|
|
3888
|
-
|
3889
|
-
if (c->lookup_type == 2 && c->sequence_p) {
|
3890
|
-
for (j=1; j < (int) c->lookup_values; ++j)
|
3891
|
-
c->multiplicands[j] = c->multiplicands[j-1];
|
3892
|
-
c->sequence_p = 0;
|
3893
|
-
}
|
3894
|
-
#endif
|
3840
|
+
CHECK(f);
|
3895
3841
|
}
|
3842
|
+
CHECK(f);
|
3896
3843
|
}
|
3897
3844
|
|
3898
3845
|
// time domain transfers (notused)
|
@@ -3988,9 +3935,11 @@ static int start_decoder(vorb *f)
|
|
3988
3935
|
if (f->residue_types[i] > 2) return error(f, VORBIS_invalid_setup);
|
3989
3936
|
r->begin = get_bits(f, 24);
|
3990
3937
|
r->end = get_bits(f, 24);
|
3938
|
+
if (r->end < r->begin) return error(f, VORBIS_invalid_setup);
|
3991
3939
|
r->part_size = get_bits(f,24)+1;
|
3992
3940
|
r->classifications = get_bits(f,6)+1;
|
3993
3941
|
r->classbook = get_bits(f,8);
|
3942
|
+
if (r->classbook >= f->codebook_count) return error(f, VORBIS_invalid_setup);
|
3994
3943
|
for (j=0; j < r->classifications; ++j) {
|
3995
3944
|
uint8 high_bits=0;
|
3996
3945
|
uint8 low_bits=get_bits(f,3);
|
@@ -4171,6 +4120,7 @@ static void vorbis_deinit(stb_vorbis *p)
|
|
4171
4120
|
}
|
4172
4121
|
|
4173
4122
|
if (p->codebooks) {
|
4123
|
+
CHECK(p);
|
4174
4124
|
for (i=0; i < p->codebook_count; ++i) {
|
4175
4125
|
Codebook *c = p->codebooks + i;
|
4176
4126
|
setup_free(p, c->codeword_lengths);
|
@@ -4189,6 +4139,7 @@ static void vorbis_deinit(stb_vorbis *p)
|
|
4189
4139
|
setup_free(p, p->mapping[i].chan);
|
4190
4140
|
setup_free(p, p->mapping);
|
4191
4141
|
}
|
4142
|
+
CHECK(p);
|
4192
4143
|
for (i=0; i < p->channels && i < STB_VORBIS_MAX_CHANNELS; ++i) {
|
4193
4144
|
setup_free(p, p->channel_buffers[i]);
|
4194
4145
|
setup_free(p, p->previous_window[i]);
|
@@ -4216,7 +4167,7 @@ void stb_vorbis_close(stb_vorbis *p)
|
|
4216
4167
|
setup_free(p,p);
|
4217
4168
|
}
|
4218
4169
|
|
4219
|
-
static void vorbis_init(stb_vorbis *p, stb_vorbis_alloc *z)
|
4170
|
+
static void vorbis_init(stb_vorbis *p, const stb_vorbis_alloc *z)
|
4220
4171
|
{
|
4221
4172
|
memset(p, 0, sizeof(*p)); // NULL out all malloc'd pointers to start
|
4222
4173
|
if (z) {
|
@@ -4374,11 +4325,11 @@ static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len)
|
|
4374
4325
|
|
4375
4326
|
// return value: number of bytes we used
|
4376
4327
|
int stb_vorbis_decode_frame_pushdata(
|
4377
|
-
stb_vorbis *f,
|
4378
|
-
uint8 *data, int data_len,
|
4379
|
-
int *channels,
|
4380
|
-
float ***output,
|
4381
|
-
int *samples
|
4328
|
+
stb_vorbis *f, // the file we're decoding
|
4329
|
+
const uint8 *data, int data_len, // the memory available for decoding
|
4330
|
+
int *channels, // place to write number of float * buffers
|
4331
|
+
float ***output, // place to write float ** array of float * buffers
|
4332
|
+
int *samples // place to write number of output samples
|
4382
4333
|
)
|
4383
4334
|
{
|
4384
4335
|
int i;
|
@@ -4388,11 +4339,11 @@ int stb_vorbis_decode_frame_pushdata(
|
|
4388
4339
|
|
4389
4340
|
if (f->page_crc_tests >= 0) {
|
4390
4341
|
*samples = 0;
|
4391
|
-
return vorbis_search_for_page_pushdata(f, data, data_len);
|
4342
|
+
return vorbis_search_for_page_pushdata(f, (uint8 *) data, data_len);
|
4392
4343
|
}
|
4393
4344
|
|
4394
|
-
f->stream = data;
|
4395
|
-
f->stream_end = data + data_len;
|
4345
|
+
f->stream = (uint8 *) data;
|
4346
|
+
f->stream_end = (uint8 *) data + data_len;
|
4396
4347
|
f->error = VORBIS__no_error;
|
4397
4348
|
|
4398
4349
|
// check that we have the entire packet in memory
|
@@ -4410,7 +4361,7 @@ int stb_vorbis_decode_frame_pushdata(
|
|
4410
4361
|
while (get8_packet(f) != EOP)
|
4411
4362
|
if (f->eof) break;
|
4412
4363
|
*samples = 0;
|
4413
|
-
return f->stream - data;
|
4364
|
+
return (int) (f->stream - data);
|
4414
4365
|
}
|
4415
4366
|
if (error == VORBIS_continued_packet_flag_invalid) {
|
4416
4367
|
if (f->previous_length == 0) {
|
@@ -4420,7 +4371,7 @@ int stb_vorbis_decode_frame_pushdata(
|
|
4420
4371
|
while (get8_packet(f) != EOP)
|
4421
4372
|
if (f->eof) break;
|
4422
4373
|
*samples = 0;
|
4423
|
-
return f->stream - data;
|
4374
|
+
return (int) (f->stream - data);
|
4424
4375
|
}
|
4425
4376
|
}
|
4426
4377
|
// if we get an error while parsing, what to do?
|
@@ -4440,18 +4391,18 @@ int stb_vorbis_decode_frame_pushdata(
|
|
4440
4391
|
if (channels) *channels = f->channels;
|
4441
4392
|
*samples = len;
|
4442
4393
|
*output = f->outputs;
|
4443
|
-
return f->stream - data;
|
4394
|
+
return (int) (f->stream - data);
|
4444
4395
|
}
|
4445
4396
|
|
4446
4397
|
stb_vorbis *stb_vorbis_open_pushdata(
|
4447
|
-
unsigned char *data, int data_len, // the memory available for decoding
|
4398
|
+
const unsigned char *data, int data_len, // the memory available for decoding
|
4448
4399
|
int *data_used, // only defined if result is not NULL
|
4449
|
-
int *error, stb_vorbis_alloc *alloc)
|
4400
|
+
int *error, const stb_vorbis_alloc *alloc)
|
4450
4401
|
{
|
4451
4402
|
stb_vorbis *f, p;
|
4452
4403
|
vorbis_init(&p, alloc);
|
4453
|
-
p.stream = data;
|
4454
|
-
p.stream_end = data + data_len;
|
4404
|
+
p.stream = (uint8 *) data;
|
4405
|
+
p.stream_end = (uint8 *) data + data_len;
|
4455
4406
|
p.push_mode = TRUE;
|
4456
4407
|
if (!start_decoder(&p)) {
|
4457
4408
|
if (p.eof)
|
@@ -4463,7 +4414,7 @@ stb_vorbis *stb_vorbis_open_pushdata(
|
|
4463
4414
|
f = vorbis_alloc(&p);
|
4464
4415
|
if (f) {
|
4465
4416
|
*f = p;
|
4466
|
-
*data_used = f->stream - data;
|
4417
|
+
*data_used = (int) (f->stream - data);
|
4467
4418
|
*error = 0;
|
4468
4419
|
return f;
|
4469
4420
|
} else {
|
@@ -4478,9 +4429,9 @@ unsigned int stb_vorbis_get_file_offset(stb_vorbis *f)
|
|
4478
4429
|
#ifndef STB_VORBIS_NO_PUSHDATA_API
|
4479
4430
|
if (f->push_mode) return 0;
|
4480
4431
|
#endif
|
4481
|
-
if (USE_MEMORY(f)) return f->stream - f->stream_start;
|
4432
|
+
if (USE_MEMORY(f)) return (unsigned int) (f->stream - f->stream_start);
|
4482
4433
|
#ifndef STB_VORBIS_NO_STDIO
|
4483
|
-
return ftell(f->f) - f->f_start;
|
4434
|
+
return (unsigned int) (ftell(f->f) - f->f_start);
|
4484
4435
|
#endif
|
4485
4436
|
}
|
4486
4437
|
|
@@ -4971,12 +4922,12 @@ int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output)
|
|
4971
4922
|
|
4972
4923
|
#ifndef STB_VORBIS_NO_STDIO
|
4973
4924
|
|
4974
|
-
stb_vorbis * stb_vorbis_open_file_section(FILE *file, int close_on_free, int *error, stb_vorbis_alloc *alloc, unsigned int length)
|
4925
|
+
stb_vorbis * stb_vorbis_open_file_section(FILE *file, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length)
|
4975
4926
|
{
|
4976
4927
|
stb_vorbis *f, p;
|
4977
4928
|
vorbis_init(&p, alloc);
|
4978
4929
|
p.f = file;
|
4979
|
-
p.f_start = ftell(file);
|
4930
|
+
p.f_start = (uint32) ftell(file);
|
4980
4931
|
p.stream_len = length;
|
4981
4932
|
p.close_on_free = close_on_free;
|
4982
4933
|
if (start_decoder(&p)) {
|
@@ -4992,17 +4943,17 @@ stb_vorbis * stb_vorbis_open_file_section(FILE *file, int close_on_free, int *er
|
|
4992
4943
|
return NULL;
|
4993
4944
|
}
|
4994
4945
|
|
4995
|
-
stb_vorbis * stb_vorbis_open_file(FILE *file, int close_on_free, int *error, stb_vorbis_alloc *alloc)
|
4946
|
+
stb_vorbis * stb_vorbis_open_file(FILE *file, int close_on_free, int *error, const stb_vorbis_alloc *alloc)
|
4996
4947
|
{
|
4997
4948
|
unsigned int len, start;
|
4998
|
-
start = ftell(file);
|
4949
|
+
start = (unsigned int) ftell(file);
|
4999
4950
|
fseek(file, 0, SEEK_END);
|
5000
|
-
len = ftell(file) - start;
|
4951
|
+
len = (unsigned int) (ftell(file) - start);
|
5001
4952
|
fseek(file, start, SEEK_SET);
|
5002
4953
|
return stb_vorbis_open_file_section(file, close_on_free, error, alloc, len);
|
5003
4954
|
}
|
5004
4955
|
|
5005
|
-
stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, stb_vorbis_alloc *alloc)
|
4956
|
+
stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const stb_vorbis_alloc *alloc)
|
5006
4957
|
{
|
5007
4958
|
FILE *f = fopen(filename, "rb");
|
5008
4959
|
if (f)
|
@@ -5012,7 +4963,7 @@ stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, stb_vorb
|
|
5012
4963
|
}
|
5013
4964
|
#endif // STB_VORBIS_NO_STDIO
|
5014
4965
|
|
5015
|
-
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, stb_vorbis_alloc *alloc)
|
4966
|
+
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc)
|
5016
4967
|
{
|
5017
4968
|
stb_vorbis *f, p;
|
5018
4969
|
if (data == NULL) return NULL;
|
@@ -5392,6 +5343,11 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in
|
|
5392
5343
|
#endif // STB_VORBIS_NO_PULLDATA_API
|
5393
5344
|
|
5394
5345
|
/* Version history
|
5346
|
+
1.09 - 2016/04/04 - back out 'avoid discarding last frame' fix from previous version
|
5347
|
+
1.08 - 2016/04/02 - fixed multiple warnings; fix setup memory leaks;
|
5348
|
+
avoid discarding last frame of audio data
|
5349
|
+
1.07 - 2015/01/16 - fixed some warnings, fix mingw, const-correct API
|
5350
|
+
some more crash fixes when out of memory or with corrupt files
|
5395
5351
|
1.06 - 2015/08/31 - full, correct support for seeking API (Dougall Johnson)
|
5396
5352
|
some crash fixes when out of memory or with corrupt files
|
5397
5353
|
1.05 - 2015/04/19 - don't define __forceinline if it's redundant
|