62 #ifndef STB_VORBIS_INCLUDE_STB_VORBIS_H
63 #define STB_VORBIS_INCLUDE_STB_VORBIS_H
65 #if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
66 #define STB_VORBIS_NO_STDIO 1
69 #ifndef STB_VORBIS_NO_STDIO
151 #ifndef STB_VORBIS_NO_PUSHDATA_API
161 const unsigned char * datablock,
int datablock_length_in_bytes,
162 int *datablock_memory_consumed_in_bytes,
176 const unsigned char *datablock,
int datablock_length_in_bytes,
220 #ifndef STB_VORBIS_NO_PULLDATA_API
228 #if !defined(STB_VORBIS_NO_STDIO) && !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
231 #if !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
244 #ifndef STB_VORBIS_NO_STDIO
295 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
331 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
384 #endif // STB_VORBIS_INCLUDE_STB_VORBIS_H
390 #ifndef STB_VORBIS_HEADER_ONLY
430 #ifndef STB_VORBIS_MAX_CHANNELS
431 #define STB_VORBIS_MAX_CHANNELS 16 // enough for anyone?
446 #ifndef STB_VORBIS_PUSHDATA_CRC_COUNT
447 #define STB_VORBIS_PUSHDATA_CRC_COUNT 4
455 #ifndef STB_VORBIS_FAST_HUFFMAN_LENGTH
456 #define STB_VORBIS_FAST_HUFFMAN_LENGTH 10
469 #ifndef STB_VORBIS_FAST_HUFFMAN_INT
470 #define STB_VORBIS_FAST_HUFFMAN_SHORT
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"
522 #ifdef STB_VORBIS_NO_PULLDATA_API
523 #define STB_VORBIS_NO_INTEGER_CONVERSION
524 #define STB_VORBIS_NO_STDIO
527 #if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
528 #define STB_VORBIS_NO_STDIO 1
531 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
532 #ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
537 #ifndef STB_VORBIS_BIG_ENDIAN
538 #define STB_VORBIS_ENDIAN 0
540 #define STB_VORBIS_ENDIAN 1
547 #ifndef STB_VORBIS_NO_STDIO
551 #ifndef STB_VORBIS_NO_CRT
561 #if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__)
564 #else // STB_VORBIS_NO_CRT
567 #define free(s) ((void) 0)
569 #endif // STB_VORBIS_NO_CRT
582 #define __forceinline
583 #elif !defined(_MSC_VER)
585 #define __forceinline inline
587 #define __forceinline
591 #if STB_VORBIS_MAX_CHANNELS > 256
592 #error "Value of STB_VORBIS_MAX_CHANNELS outside of allowed range"
595 #if STB_VORBIS_FAST_HUFFMAN_LENGTH > 24
596 #error "Value of STB_VORBIS_FAST_HUFFMAN_LENGTH outside of allowed range"
602 #define CHECK(f) _CrtIsValidHeapPointer(f->channel_buffers[1])
604 #define CHECK(f) ((void) 0)
607 #define MAX_BLOCKSIZE_LOG 13 // from specification
608 #define MAX_BLOCKSIZE (1 << MAX_BLOCKSIZE_LOG)
638 #define FAST_HUFFMAN_TABLE_SIZE (1 << STB_VORBIS_FAST_HUFFMAN_LENGTH)
639 #define FAST_HUFFMAN_TABLE_MASK (FAST_HUFFMAN_TABLE_SIZE - 1)
654 #ifdef STB_VORBIS_FAST_HUFFMAN_SHORT
757 #ifndef STB_VORBIS_NO_STDIO
811 #ifndef STB_VORBIS_NO_DEFER_FLOOR
848 #ifndef STB_VORBIS_NO_PUSHDATA_API
857 #if defined(STB_VORBIS_NO_PUSHDATA_API)
858 #define IS_PUSH_MODE(f) FALSE
859 #elif defined(STB_VORBIS_NO_PULLDATA_API)
860 #define IS_PUSH_MODE(f) TRUE
862 #define IS_PUSH_MODE(f) ((f)->push_mode)
882 #define array_size_required(count,size) (count*(sizeof(void *)+(size)))
884 #define temp_alloc(f,size) (f->alloc.alloc_buffer ? setup_temp_malloc(f,size) : alloca(size))
886 #define temp_free(f,p) (f->alloc.alloc_buffer ? 0 : dealloca(size))
888 #define temp_free(f,p) 0
890 #define temp_alloc_save(f) ((f)->temp_offset)
891 #define temp_alloc_restore(f,p) ((f)->temp_offset = (p))
893 #define temp_block_array(f,count,size) make_block_array(temp_alloc(f,array_size_required(count,size)), count, size)
899 void ** p = (
void **) mem;
900 char *q = (
char *) (p + count);
901 for (i=0; i < count; ++i) {
918 return sz ? malloc(sz) : NULL;
947 #define CRC32_POLY 0x04c11db7 // from spec
954 for(i=0; i < 256; i++) {
955 for (s=(
uint32) i << 24, j=0; j < 8; ++j)
956 s = (s << 1) ^ (s >= (1U<<31) ?
CRC32_POLY : 0);
963 return (crc << 8) ^
crc_table[byte ^ (crc >> 24)];
970 n = ((n & 0xAAAAAAAA) >> 1) | ((n & 0x55555555) << 1);
971 n = ((n & 0xCCCCCCCC) >> 2) | ((n & 0x33333333) << 2);
972 n = ((n & 0xF0F0F0F0) >> 4) | ((n & 0x0F0F0F0F) << 4);
973 n = ((n & 0xFF00FF00) >> 8) | ((n & 0x00FF00FF) << 8);
974 return (n >> 16) | (n << 16);
987 static signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 };
991 if (n < (1 << 4))
return 0 + log2_4[n ];
992 else if (n < (1 << 9))
return 5 + log2_4[n >> 5];
993 else return 10 + log2_4[n >> 10];
994 else if (n < (1 << 24))
995 if (n < (1 << 19))
return 15 + log2_4[n >> 15];
996 else return 20 + log2_4[n >> 20];
997 else if (n < (1 << 29))
return 25 + log2_4[n >> 25];
998 else if (n < (1 << 31))
return 30 + log2_4[n >> 30];
1003 #define M_PI 3.14159265358979323846264f // from CRC
1017 uint32 mantissa = x & 0x1fffff;
1019 uint32 exp = (x & 0x7fe00000) >> 21;
1020 double res = sign ? -(double)mantissa : (
double)mantissa;
1021 return (
float) ldexp((
float)res, exp-788);
1039 values [count] = symbol;
1048 memset(available, 0,
sizeof(available));
1050 for (k=0; k < n; ++k)
if (len[k] <
NO_CODE)
break;
1053 add_entry(c, 0, k, m++, len[k], values);
1055 for (i=1; i <= len[k]; ++i)
1056 available[i] = 1U << (32-i);
1061 for (i=k+1; i < n; ++i) {
1071 while (z > 0 && !available[z]) --z;
1072 if (z == 0) {
return FALSE; }
1074 assert(z >= 0 && z < 32);
1079 assert(len[i] >= 0 && len[i] < 32);
1080 for (y=len[i]; y > z; --y) {
1081 assert(available[y] == 0);
1082 available[y] = res + (1 << (32-y));
1099 if (len > 32767) len = 32767;
1101 for (i=0; i < len; ++i) {
1105 while (z < FAST_HUFFMAN_TABLE_SIZE) {
1114 #define STBV_CDECL __cdecl
1123 return x < y ? -1 : x > y;
1145 for (i=0; i < c->
entries; ++i)
1163 for (i=0; i < len; ++i) {
1164 int huff_len = c->
sparse ? lengths[values[i]] : lengths[i];
1170 int m = x + (n >> 1);
1192 static uint8 vorbis[6] = {
'v',
'o',
'r',
'b',
'i',
's' };
1193 return memcmp(data, vorbis, 6) == 0;
1200 int r = (int) floor(exp((
float) log((
float) entries) / dim));
1201 if ((
int) floor(pow((
float) r+1, dim)) <= entries)
1203 assert(pow((
float) r+1, dim) > entries);
1204 assert((
int) floor(pow((
float) r, dim)) <= entries);
1211 int n4 = n >> 2, n8 = n >> 3;
1214 for (k=k2=0; k < n4; ++k,k2+=2) {
1215 A[k2 ] = (float) cos(4*k*
M_PI/n);
1216 A[k2+1] = (float) -sin(4*k*
M_PI/n);
1217 B[k2 ] = (float) cos((k2+1)*
M_PI/n/2) * 0.5
f;
1218 B[k2+1] = (float) sin((k2+1)*
M_PI/n/2) * 0.5
f;
1220 for (k=k2=0; k < n8; ++k,k2+=2) {
1221 C[k2 ] = (float) cos(2*(k2+1)*
M_PI/n);
1222 C[k2+1] = (float) -sin(2*(k2+1)*
M_PI/n);
1229 for (i=0; i < n2; ++i)
1230 window[i] = (
float) sin(0.5 *
M_PI *
square((
float) sin((i - 0 + 0.5) / n2 * 0.5 *
M_PI)));
1235 int ld =
ilog(n) - 1;
1237 for (i=0; i < n8; ++i)
1243 int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3;
1263 for (i=0; i < n; ++i) {
1264 if (x[i] > low && x[i] < x[n]) { *plow = i; low = x[i]; }
1265 if (x[i] < high && x[i] > x[n]) { *phigh = i; high = x[i]; }
1279 return a->
x < b->
x ? -1 : a->
x > b->
x;
1286 #if defined(STB_VORBIS_NO_STDIO)
1287 #define USE_MEMORY(z) TRUE
1289 #define USE_MEMORY(z) ((z)->stream)
1299 #ifndef STB_VORBIS_NO_STDIO
1301 int c = fgetc(z->
f);
1302 if (c == EOF) { z->
eof =
TRUE;
return 0; }
1322 memcpy(data, z->
stream, n);
1327 #ifndef STB_VORBIS_NO_STDIO
1328 if (fread(data, n, 1, z->
f) == 1)
1344 #ifndef STB_VORBIS_NO_STDIO
1346 long x = ftell(z->
f);
1347 fseek(z->
f, x+n, SEEK_SET);
1354 #ifndef STB_VORBIS_NO_PUSHDATA_API
1368 #ifndef STB_VORBIS_NO_STDIO
1369 if (loc + f->
f_start < loc || loc >= 0x80000000) {
1375 if (!fseek(f->
f, loc, SEEK_SET))
1395 #define PAGEFLAG_continued_packet 1
1396 #define PAGEFLAG_first_page 2
1397 #define PAGEFLAG_last_page 4
1424 if (loc0 != ~0U || loc1 != ~0U) {
1516 #define INVALID_BITS (-1)
1568 z = f->
acc & ((1 << n)-1);
1586 if (z ==
EOP)
return;
1617 int m = x + (n >> 1);
1641 for (i=0; i < c->
entries; ++i) {
1659 #ifndef STB_VORBIS_NO_INLINE_DECODE
1661 #define DECODE_RAW(var, f,c) \
1662 if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH) \
1664 var = f->acc & FAST_HUFFMAN_TABLE_MASK; \
1665 var = c->fast_huffman[var]; \
1667 int n = c->codeword_lengths[var]; \
1669 f->valid_bits -= n; \
1670 if (f->valid_bits < 0) { f->valid_bits = 0; var = -1; } \
1672 var = codebook_decode_scalar_raw(f,c); \
1694 #define DECODE_RAW(var,f,c) var = codebook_decode_scalar(f,c);
1698 #define DECODE(var,f,c) \
1699 DECODE_RAW(var,f,c) \
1700 if (c->sparse) var = c->sorted_values[var];
1702 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
1703 #define DECODE_VQ(var,f,c) DECODE_RAW(var,f,c)
1705 #define DECODE_VQ(var,f,c) DECODE(var,f,c)
1715 #define CODEBOOK_ELEMENT(c,off) (c->multiplicands[off])
1716 #define CODEBOOK_ELEMENT_FAST(c,off) (c->multiplicands[off])
1717 #define CODEBOOK_ELEMENT_BASE(c) (0)
1728 if (c->
sparse) assert(z < c->sorted_entries);
1742 if (z < 0)
return FALSE;
1745 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1749 for (i=0; i < len; ++i) {
1763 for (i=0; i < len; ++i) {
1770 for (i=0; i < len; ++i) {
1782 if (z < 0)
return FALSE;
1785 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1788 for (i=0; i < len; ++i) {
1791 output[i*step] += val;
1800 for (i=0; i < len; ++i) {
1802 output[i*step] += val;
1811 int c_inter = *c_inter_p;
1812 int p_inter = *p_inter_p;
1818 while (total_decode > 0) {
1821 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
1822 assert(!c->
sparse || z < c->sorted_entries);
1834 if (c_inter + p_inter*ch + effective > len * ch) {
1835 effective = len*ch - (p_inter*ch - c_inter);
1838 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1841 for (i=0; i < effective; ++i) {
1844 if (outputs[c_inter])
1845 outputs[c_inter][p_inter] += val;
1846 if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1855 for (i=0; i < effective; ++i) {
1857 if (outputs[c_inter])
1858 outputs[c_inter][p_inter] += val;
1859 if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1863 for (i=0; i < effective; ++i) {
1865 if (outputs[c_inter])
1866 outputs[c_inter][p_inter] += val;
1867 if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1872 total_decode -= effective;
1874 *c_inter_p = c_inter;
1875 *p_inter_p = p_inter;
1884 int err = abs(dy) * (x - x0);
1885 int off = err / adx;
1886 return dy < 0 ? y0 - off : y0 + off;
1892 1.0649863e-07
f, 1.1341951e-07
f, 1.2079015e-07
f, 1.2863978e-07
f,
1893 1.3699951e-07
f, 1.4590251e-07
f, 1.5538408e-07
f, 1.6548181e-07
f,
1894 1.7623575e-07
f, 1.8768855e-07
f, 1.9988561e-07
f, 2.1287530e-07
f,
1895 2.2670913e-07
f, 2.4144197e-07
f, 2.5713223e-07
f, 2.7384213e-07
f,
1896 2.9163793e-07
f, 3.1059021e-07
f, 3.3077411e-07
f, 3.5226968e-07
f,
1897 3.7516214e-07
f, 3.9954229e-07
f, 4.2550680e-07
f, 4.5315863e-07
f,
1898 4.8260743e-07
f, 5.1396998e-07
f, 5.4737065e-07
f, 5.8294187e-07
f,
1899 6.2082472e-07
f, 6.6116941e-07
f, 7.0413592e-07
f, 7.4989464e-07
f,
1900 7.9862701e-07
f, 8.5052630e-07
f, 9.0579828e-07
f, 9.6466216e-07
f,
1901 1.0273513e-06
f, 1.0941144e-06
f, 1.1652161e-06
f, 1.2409384e-06
f,
1902 1.3215816e-06
f, 1.4074654e-06
f, 1.4989305e-06
f, 1.5963394e-06
f,
1903 1.7000785e-06
f, 1.8105592e-06
f, 1.9282195e-06
f, 2.0535261e-06
f,
1904 2.1869758e-06
f, 2.3290978e-06
f, 2.4804557e-06
f, 2.6416497e-06
f,
1905 2.8133190e-06
f, 2.9961443e-06
f, 3.1908506e-06
f, 3.3982101e-06
f,
1906 3.6190449e-06
f, 3.8542308e-06
f, 4.1047004e-06
f, 4.3714470e-06
f,
1907 4.6555282e-06
f, 4.9580707e-06
f, 5.2802740e-06
f, 5.6234160e-06
f,
1908 5.9888572e-06
f, 6.3780469e-06
f, 6.7925283e-06
f, 7.2339451e-06
f,
1909 7.7040476e-06
f, 8.2047000e-06
f, 8.7378876e-06
f, 9.3057248e-06
f,
1910 9.9104632e-06
f, 1.0554501e-05
f, 1.1240392e-05
f, 1.1970856e-05
f,
1911 1.2748789e-05
f, 1.3577278e-05
f, 1.4459606e-05
f, 1.5399272e-05
f,
1912 1.6400004e-05
f, 1.7465768e-05
f, 1.8600792e-05
f, 1.9809576e-05
f,
1913 2.1096914e-05
f, 2.2467911e-05
f, 2.3928002e-05
f, 2.5482978e-05
f,
1914 2.7139006e-05
f, 2.8902651e-05
f, 3.0780908e-05
f, 3.2781225e-05
f,
1915 3.4911534e-05
f, 3.7180282e-05
f, 3.9596466e-05
f, 4.2169667e-05
f,
1916 4.4910090e-05
f, 4.7828601e-05
f, 5.0936773e-05
f, 5.4246931e-05
f,
1917 5.7772202e-05
f, 6.1526565e-05
f, 6.5524908e-05
f, 6.9783085e-05
f,
1918 7.4317983e-05
f, 7.9147585e-05
f, 8.4291040e-05
f, 8.9768747e-05
f,
1919 9.5602426e-05
f, 0.00010181521f, 0.00010843174f, 0.00011547824f,
1920 0.00012298267f, 0.00013097477f, 0.00013948625f, 0.00014855085f,
1921 0.00015820453f, 0.00016848555f, 0.00017943469f, 0.00019109536f,
1922 0.00020351382f, 0.00021673929f, 0.00023082423f, 0.00024582449f,
1923 0.00026179955f, 0.00027881276f, 0.00029693158f, 0.00031622787f,
1924 0.00033677814f, 0.00035866388f, 0.00038197188f, 0.00040679456f,
1925 0.00043323036f, 0.00046138411f, 0.00049136745f, 0.00052329927f,
1926 0.00055730621f, 0.00059352311f, 0.00063209358f, 0.00067317058f,
1927 0.00071691700f, 0.00076350630f, 0.00081312324f, 0.00086596457f,
1928 0.00092223983f, 0.00098217216f, 0.0010459992f, 0.0011139742f,
1929 0.0011863665f, 0.0012634633f, 0.0013455702f, 0.0014330129f,
1930 0.0015261382f, 0.0016253153f, 0.0017309374f, 0.0018434235f,
1931 0.0019632195f, 0.0020908006f, 0.0022266726f, 0.0023713743f,
1932 0.0025254795f, 0.0026895994f, 0.0028643847f, 0.0030505286f,
1933 0.0032487691f, 0.0034598925f, 0.0036847358f, 0.0039241906f,
1934 0.0041792066f, 0.0044507950f, 0.0047400328f, 0.0050480668f,
1935 0.0053761186f, 0.0057254891f, 0.0060975636f, 0.0064938176f,
1936 0.0069158225f, 0.0073652516f, 0.0078438871f, 0.0083536271f,
1937 0.0088964928f, 0.009474637f, 0.010090352f, 0.010746080f,
1938 0.011444421f, 0.012188144f, 0.012980198f, 0.013823725f,
1939 0.014722068f, 0.015678791f, 0.016697687f, 0.017782797f,
1940 0.018938423f, 0.020169149f, 0.021479854f, 0.022875735f,
1941 0.024362330f, 0.025945531f, 0.027631618f, 0.029427276f,
1942 0.031339626f, 0.033376252f, 0.035545228f, 0.037855157f,
1943 0.040315199f, 0.042935108f, 0.045725273f, 0.048696758f,
1944 0.051861348f, 0.055231591f, 0.058820850f, 0.062643361f,
1945 0.066714279f, 0.071049749f, 0.075666962f, 0.080584227f,
1946 0.085821044f, 0.091398179f, 0.097337747f, 0.10366330f,
1947 0.11039993f, 0.11757434f, 0.12521498f, 0.13335215f,
1948 0.14201813f, 0.15124727f, 0.16107617f, 0.17154380f,
1949 0.18269168f, 0.19456402f, 0.20720788f, 0.22067342f,
1950 0.23501402f, 0.25028656f, 0.26655159f, 0.28387361f,
1951 0.30232132f, 0.32196786f, 0.34289114f, 0.36517414f,
1952 0.38890521f, 0.41417847f, 0.44109412f, 0.46975890f,
1953 0.50028648f, 0.53279791f, 0.56742212f, 0.60429640f,
1954 0.64356699f, 0.68538959f, 0.72993007f, 0.77736504f,
1955 0.82788260f, 0.88168307f, 0.9389798f, 1.0f
1966 #ifndef STB_VORBIS_NO_DEFER_FLOOR
1967 #define LINE_OP(a,b) a *= b
1969 #define LINE_OP(a,b) a = b
1972 #ifdef STB_VORBIS_DIVIDE_TABLE
1973 #define DIVTAB_NUMER 32
1974 #define DIVTAB_DENOM 64
1975 int8 integer_divide_table[DIVTAB_NUMER][DIVTAB_DENOM];
1988 #ifdef STB_VORBIS_DIVIDE_TABLE
1989 if (adx < DIVTAB_DENOM && ady < DIVTAB_NUMER) {
1991 base = -integer_divide_table[ady][adx];
1994 base = integer_divide_table[ady][adx];
2011 ady -= abs(base) * adx;
2015 for (++x; x < x1; ++x) {
2032 for (k=0; k < step; ++k)
2036 for (k=0; k < n; ) {
2056 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2064 for (i=0; i < ch; ++i)
2065 if (!do_not_decode[i])
2066 memset(residue_buffers[i], 0,
sizeof(
float) * n);
2068 if (rtype == 2 && ch != 1) {
2069 for (j=0; j < ch; ++j)
2070 if (!do_not_decode[j])
2075 for (pass=0; pass < 8; ++pass) {
2076 int pcount = 0, class_set = 0;
2078 while (pcount < part_read) {
2080 int c_inter = (z & 1), p_inter = z>>1;
2085 if (q ==
EOP)
goto done;
2086 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2087 part_classdata[0][class_set] = r->
classdata[q];
2089 for (i=classwords-1; i >= 0; --i) {
2095 for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2097 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2098 int c = part_classdata[0][class_set][i];
2100 int c = classifications[0][pcount];
2105 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
2119 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2123 }
else if (ch == 1) {
2124 while (pcount < part_read) {
2126 int c_inter = 0, p_inter = z;
2131 if (q ==
EOP)
goto done;
2132 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2133 part_classdata[0][class_set] = r->
classdata[q];
2135 for (i=classwords-1; i >= 0; --i) {
2141 for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2143 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2144 int c = part_classdata[0][class_set][i];
2146 int c = classifications[0][pcount];
2159 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2164 while (pcount < part_read) {
2166 int c_inter = z % ch, p_inter = z/ch;
2171 if (q ==
EOP)
goto done;
2172 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2173 part_classdata[0][class_set] = r->
classdata[q];
2175 for (i=classwords-1; i >= 0; --i) {
2181 for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2183 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2184 int c = part_classdata[0][class_set][i];
2186 int c = classifications[0][pcount];
2199 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2209 for (pass=0; pass < 8; ++pass) {
2210 int pcount = 0, class_set=0;
2211 while (pcount < part_read) {
2213 for (j=0; j < ch; ++j) {
2214 if (!do_not_decode[j]) {
2218 if (temp ==
EOP)
goto done;
2219 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2220 part_classdata[j][class_set] = r->
classdata[temp];
2222 for (i=classwords-1; i >= 0; --i) {
2230 for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2231 for (j=0; j < ch; ++j) {
2232 if (!do_not_decode[j]) {
2233 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2234 int c = part_classdata[j][class_set][i];
2236 int c = classifications[j][pcount];
2240 float *target = residue_buffers[j];
2250 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2257 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2268 void inverse_mdct_slow(
float *buffer,
int n)
2272 float *x = (
float *) malloc(
sizeof(*x) * n2);
2273 memcpy(x, buffer,
sizeof(*x) * n2);
2274 for (i=0; i < n; ++i) {
2276 for (j=0; j < n2; ++j)
2284 acc += x[j] * (
float) cos(
M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1));
2291 void inverse_mdct_slow(
float *buffer,
int n,
vorb *
f,
int blocktype)
2295 int n2 = n >> 1, nmask = (n << 2) -1;
2296 float *x = (
float *) malloc(
sizeof(*x) * n2);
2297 memcpy(x, buffer,
sizeof(*x) * n2);
2298 for (i=0; i < 4*n; ++i)
2299 mcos[i] = (
float) cos(
M_PI / 2 * i / n);
2301 for (i=0; i < n; ++i) {
2303 for (j=0; j < n2; ++j)
2304 acc += x[j] * mcos[(2 * i + 1 + n2)*(2*j+1) & nmask];
2312 void dct_iv_slow(
float *buffer,
int n)
2317 int n2 = n >> 1, nmask = (n << 3) - 1;
2318 memcpy(x, buffer,
sizeof(*x) * n);
2319 for (i=0; i < 8*n; ++i)
2320 mcos[i] = (
float) cos(
M_PI / 4 * i / n);
2321 for (i=0; i < n; ++i) {
2323 for (j=0; j < n; ++j)
2324 acc += x[j] * mcos[((2 * i + 1)*(2*j+1)) & nmask];
2329 void inverse_mdct_slow(
float *buffer,
int n,
vorb *f,
int blocktype)
2331 int i, n4 = n >> 2, n2 = n >> 1, n3_4 = n - n4;
2334 memcpy(temp, buffer, n2 *
sizeof(
float));
2335 dct_iv_slow(temp, n2);
2337 for (i=0; i < n4 ; ++i) buffer[i] = temp[i+n4];
2338 for ( ; i < n3_4; ++i) buffer[i] = -temp[n3_4 - i - 1];
2339 for ( ; i < n ; ++i) buffer[i] = -temp[i - n3_4];
2343 #ifndef LIBVORBIS_MDCT
2344 #define LIBVORBIS_MDCT 0
2361 extern void mdct_init(mdct_lookup *lookup,
int n);
2362 extern void mdct_clear(mdct_lookup *l);
2363 extern void mdct_backward(mdct_lookup *init,
float *in,
float *out);
2370 if (M1.n == n) M = &M1;
2371 else if (M2.n == n) M = &M2;
2372 else if (M1.n == 0) { mdct_init(&M1, n); M = &M1; }
2374 if (M2.n) __asm
int 3;
2379 mdct_backward(M, buffer, buffer);
2389 float *ee0 = e + i_off;
2390 float *ee2 = ee0 + k_off;
2393 assert((n & 3) == 0);
2394 for (i=(n>>2); i > 0; --i) {
2395 float k00_20, k01_21;
2396 k00_20 = ee0[ 0] - ee2[ 0];
2397 k01_21 = ee0[-1] - ee2[-1];
2400 ee2[ 0] = k00_20 * A[0] - k01_21 * A[1];
2401 ee2[-1] = k01_21 * A[0] + k00_20 * A[1];
2404 k00_20 = ee0[-2] - ee2[-2];
2405 k01_21 = ee0[-3] - ee2[-3];
2408 ee2[-2] = k00_20 * A[0] - k01_21 * A[1];
2409 ee2[-3] = k01_21 * A[0] + k00_20 * A[1];
2412 k00_20 = ee0[-4] - ee2[-4];
2413 k01_21 = ee0[-5] - ee2[-5];
2416 ee2[-4] = k00_20 * A[0] - k01_21 * A[1];
2417 ee2[-5] = k01_21 * A[0] + k00_20 * A[1];
2420 k00_20 = ee0[-6] - ee2[-6];
2421 k01_21 = ee0[-7] - ee2[-7];
2424 ee2[-6] = k00_20 * A[0] - k01_21 * A[1];
2425 ee2[-7] = k01_21 * A[0] + k00_20 * A[1];
2435 float k00_20, k01_21;
2438 float *e2 = e0 + k_off;
2440 for (i=lim >> 2; i > 0; --i) {
2441 k00_20 = e0[-0] - e2[-0];
2442 k01_21 = e0[-1] - e2[-1];
2445 e2[-0] = (k00_20)*A[0] - (k01_21) * A[1];
2446 e2[-1] = (k01_21)*A[0] + (k00_20) * A[1];
2450 k00_20 = e0[-2] - e2[-2];
2451 k01_21 = e0[-3] - e2[-3];
2454 e2[-2] = (k00_20)*A[0] - (k01_21) * A[1];
2455 e2[-3] = (k01_21)*A[0] + (k00_20) * A[1];
2459 k00_20 = e0[-4] - e2[-4];
2460 k01_21 = e0[-5] - e2[-5];
2463 e2[-4] = (k00_20)*A[0] - (k01_21) * A[1];
2464 e2[-5] = (k01_21)*A[0] + (k00_20) * A[1];
2468 k00_20 = e0[-6] - e2[-6];
2469 k01_21 = e0[-7] - e2[-7];
2472 e2[-6] = (k00_20)*A[0] - (k01_21) * A[1];
2473 e2[-7] = (k01_21)*A[0] + (k00_20) * A[1];
2487 float A2 = A[0+a_off];
2488 float A3 = A[0+a_off+1];
2489 float A4 = A[0+a_off*2+0];
2490 float A5 = A[0+a_off*2+1];
2491 float A6 = A[0+a_off*3+0];
2492 float A7 = A[0+a_off*3+1];
2496 float *ee0 = e +i_off;
2497 float *ee2 = ee0+k_off;
2499 for (i=n; i > 0; --i) {
2500 k00 = ee0[ 0] - ee2[ 0];
2501 k11 = ee0[-1] - ee2[-1];
2502 ee0[ 0] = ee0[ 0] + ee2[ 0];
2503 ee0[-1] = ee0[-1] + ee2[-1];
2504 ee2[ 0] = (k00) * A0 - (k11) * A1;
2505 ee2[-1] = (k11) * A0 + (k00) * A1;
2507 k00 = ee0[-2] - ee2[-2];
2508 k11 = ee0[-3] - ee2[-3];
2509 ee0[-2] = ee0[-2] + ee2[-2];
2510 ee0[-3] = ee0[-3] + ee2[-3];
2511 ee2[-2] = (k00) * A2 - (k11) * A3;
2512 ee2[-3] = (k11) * A2 + (k00) * A3;
2514 k00 = ee0[-4] - ee2[-4];
2515 k11 = ee0[-5] - ee2[-5];
2516 ee0[-4] = ee0[-4] + ee2[-4];
2517 ee0[-5] = ee0[-5] + ee2[-5];
2518 ee2[-4] = (k00) * A4 - (k11) * A5;
2519 ee2[-5] = (k11) * A4 + (k00) * A5;
2521 k00 = ee0[-6] - ee2[-6];
2522 k11 = ee0[-7] - ee2[-7];
2523 ee0[-6] = ee0[-6] + ee2[-6];
2524 ee0[-7] = ee0[-7] + ee2[-7];
2525 ee2[-6] = (k00) * A6 - (k11) * A7;
2526 ee2[-7] = (k11) * A6 + (k00) * A7;
2535 float k00,k11,k22,k33;
2538 k00 = z[ 0] - z[-4];
2541 k22 = z[-2] - z[-6];
2548 k33 = z[-3] - z[-7];
2555 k11 = z[-1] - z[-5];
2567 int a_off = base_n >> 3;
2568 float A2 = A[0+a_off];
2569 float *z = e + i_off;
2570 float *base = z - 16 * n;
2575 k00 = z[-0] - z[-8];
2576 k11 = z[-1] - z[-9];
2577 z[-0] = z[-0] + z[-8];
2578 z[-1] = z[-1] + z[-9];
2582 k00 = z[ -2] - z[-10];
2583 k11 = z[ -3] - z[-11];
2584 z[ -2] = z[ -2] + z[-10];
2585 z[ -3] = z[ -3] + z[-11];
2586 z[-10] = (k00+k11) * A2;
2587 z[-11] = (k11-k00) * A2;
2589 k00 = z[-12] - z[ -4];
2590 k11 = z[ -5] - z[-13];
2591 z[ -4] = z[ -4] + z[-12];
2592 z[ -5] = z[ -5] + z[-13];
2596 k00 = z[-14] - z[ -6];
2597 k11 = z[ -7] - z[-15];
2598 z[ -6] = z[ -6] + z[-14];
2599 z[ -7] = z[ -7] + z[-15];
2600 z[-14] = (k00+k11) * A2;
2601 z[-15] = (k00-k11) * A2;
2611 int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l;
2615 float *buf2 = (
float *)
temp_alloc(f, n2 *
sizeof(*buf2));
2616 float *u=NULL,*v=NULL;
2618 float *A = f->
A[blocktype];
2640 float *d,*e, *AA, *e_stop;
2644 e_stop = &buffer[n2];
2645 while (e != e_stop) {
2646 d[1] = (e[0] * AA[0] - e[2]*AA[1]);
2647 d[0] = (e[0] * AA[1] + e[2]*AA[0]);
2655 d[1] = (-e[2] * AA[0] - -e[0]*AA[1]);
2656 d[0] = (-e[2] * AA[1] + -e[0]*AA[0]);
2674 float *AA = &A[n2-8];
2675 float *d0,*d1, *e0, *e1;
2684 float v40_20, v41_21;
2686 v41_21 = e0[1] - e1[1];
2687 v40_20 = e0[0] - e1[0];
2688 d0[1] = e0[1] + e1[1];
2689 d0[0] = e0[0] + e1[0];
2690 d1[1] = v41_21*AA[4] - v40_20*AA[5];
2691 d1[0] = v40_20*AA[4] + v41_21*AA[5];
2693 v41_21 = e0[3] - e1[3];
2694 v40_20 = e0[2] - e1[2];
2695 d0[3] = e0[3] + e1[3];
2696 d0[2] = e0[2] + e1[2];
2697 d1[3] = v41_21*AA[0] - v40_20*AA[1];
2698 d1[2] = v40_20*AA[0] + v41_21*AA[1];
2730 for (; l < (ld-3)>>1; ++l) {
2731 int k0 = n >> (l+2), k0_2 = k0>>1;
2732 int lim = 1 << (l+1);
2734 for (i=0; i < lim; ++i)
2738 for (; l < ld-6; ++l) {
2739 int k0 = n >> (l+2), k1 = 1 << (l+3), k0_2 = k0>>1;
2740 int rlim = n >> (l+6), r;
2741 int lim = 1 << (l+1);
2745 for (r=rlim; r > 0; --r) {
2770 float *d0 = &v[n4-4];
2771 float *d1 = &v[n2-4];
2801 float *
C = f->
C[blocktype];
2808 float a02,a11,b0,b1,b2,b3;
2813 b0 = C[1]*a02 + C[0]*a11;
2814 b1 = C[1]*a11 - C[0]*a02;
2827 b0 = C[3]*a02 + C[2]*a11;
2828 b1 = C[3]*a11 - C[2]*a02;
2855 float *d0,*d1,*d2,*d3;
2857 float *B = f->
B[blocktype] + n2 - 8;
2858 float *e = buf2 + n2 - 8;
2866 p3 = e[6]*B[7] - e[7]*B[6];
2867 p2 = -e[6]*B[6] - e[7]*B[7];
2874 p1 = e[4]*B[5] - e[5]*B[4];
2875 p0 = -e[4]*B[4] - e[5]*B[5];
2882 p3 = e[2]*B[3] - e[3]*B[2];
2883 p2 = -e[2]*B[2] - e[3]*B[3];
2890 p1 = e[0]*B[1] - e[1]*B[0];
2891 p0 = -e[0]*B[0] - e[1]*B[1];
2913 void inverse_mdct_naive(
float *buffer,
int n)
2916 float A[1 << 12], B[1 << 12],
C[1 << 11];
2917 int i,k,k2,k4, n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l;
2918 int n3_4 = n - n4, ld;
2921 float u[1 << 13],
X[1 << 13], v[1 << 13], w[1 << 13];
2924 for (k=k2=0; k < n4; ++k,k2+=2) {
2925 A[k2 ] = (float) cos(4*k*
M_PI/n);
2926 A[k2+1] = (float) -sin(4*k*
M_PI/n);
2927 B[k2 ] = (float) cos((k2+1)*
M_PI/n/2);
2928 B[k2+1] = (float) sin((k2+1)*
M_PI/n/2);
2930 for (k=k2=0; k < n8; ++k,k2+=2) {
2931 C[k2 ] = (float) cos(2*(k2+1)*
M_PI/n);
2932 C[k2+1] = (float) -sin(2*(k2+1)*
M_PI/n);
2943 for (k=0; k < n2; ++k) u[k] = buffer[k];
2944 for ( ; k < n ; ++k) u[k] = -buffer[n - k - 1];
2947 for (k=k2=k4=0; k < n4; k+=1, k2+=2, k4+=4) {
2948 v[n-k4-1] = (u[k4] - u[n-k4-1]) * A[k2] - (u[k4+2] - u[n-k4-3])*A[k2+1];
2949 v[n-k4-3] = (u[k4] - u[n-k4-1]) * A[k2+1] + (u[k4+2] - u[n-k4-3])*A[k2];
2952 for (k=k4=0; k < n8; k+=1, k4+=4) {
2953 w[n2+3+k4] = v[n2+3+k4] + v[k4+3];
2954 w[n2+1+k4] = v[n2+1+k4] + v[k4+1];
2955 w[k4+3] = (v[n2+3+k4] - v[k4+3])*A[n2-4-k4] - (v[n2+1+k4]-v[k4+1])*A[n2-3-k4];
2956 w[k4+1] = (v[n2+1+k4] - v[k4+1])*A[n2-4-k4] + (v[n2+3+k4]-v[k4+3])*A[n2-3-k4];
2960 for (l=0; l < ld-3; ++l) {
2961 int k0 = n >> (l+2), k1 = 1 << (l+3);
2962 int rlim = n >> (l+4), r4, r;
2963 int s2lim = 1 << (l+2), s2;
2964 for (r=r4=0; r < rlim; r4+=4,++r) {
2965 for (s2=0; s2 < s2lim; s2+=2) {
2966 u[n-1-k0*s2-r4] = w[n-1-k0*s2-r4] + w[n-1-k0*(s2+1)-r4];
2967 u[n-3-k0*s2-r4] = w[n-3-k0*s2-r4] + w[n-3-k0*(s2+1)-r4];
2968 u[n-1-k0*(s2+1)-r4] = (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1]
2969 - (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1+1];
2970 u[n-3-k0*(s2+1)-r4] = (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1]
2971 + (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1+1];
2976 memcpy(w, u,
sizeof(u));
2981 for (i=0; i < n8; ++i) {
2993 int i8 = i << 3, j8 = j << 3;
2994 v[j8+1] = u[i8+1], v[i8+1] = u[j8 + 1];
2995 v[j8+3] = u[i8+3], v[i8+3] = u[j8 + 3];
2996 v[j8+5] = u[i8+5], v[i8+5] = u[j8 + 5];
2997 v[j8+7] = u[i8+7], v[i8+7] = u[j8 + 7];
3001 for (k=0; k < n2; ++k) {
3005 for (k=k2=k4=0; k < n8; ++k, k2 += 2, k4 += 4) {
3007 u[n-2-k2] = w[k4+1];
3008 u[n3_4 - 1 - k2] = w[k4+2];
3009 u[n3_4 - 2 - k2] = w[k4+3];
3012 for (k=k2=0; k < n8; ++k, k2 += 2) {
3013 v[n2 + k2 ] = ( u[n2 + k2] + u[n-2-k2] + C[k2+1]*(u[n2+k2]-u[n-2-k2]) + C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2;
3014 v[n-2 - k2] = ( u[n2 + k2] + u[n-2-k2] - C[k2+1]*(u[n2+k2]-u[n-2-k2]) - C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2;
3015 v[n2+1+ k2] = ( u[n2+1+k2] - u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2;
3016 v[n-1 - k2] = (-u[n2+1+k2] + u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2;
3019 for (k=k2=0; k < n4; ++k,k2 += 2) {
3020 X[k] = v[k2+n2]*B[k2 ] + v[k2+1+n2]*B[k2+1];
3021 X[n2-1-k] = v[k2+n2]*B[k2+1] - v[k2+1+n2]*B[k2 ];
3033 for (i=0; i < n4 ; ++i) buffer[i] = s * X[i+n4];
3034 for ( ; i < n3_4; ++i) buffer[i] = -s * X[n3_4 - i - 1];
3035 for ( ; i < n ; ++i) buffer[i] = -s * X[i - n3_4];
3048 #ifndef STB_VORBIS_NO_DEFER_FLOOR
3056 int s = map->
chan[i].
mux, floor;
3064 for (q=1; q < g->
values; ++q) {
3066 #ifndef STB_VORBIS_NO_DEFER_FLOOR
3073 int hx = g->
Xlist[j];
3082 for (j=lx; j < n2; ++j)
3107 int i, n, prev, next, window_center;
3141 window_center = n >> 1;
3147 *p_left_end = window_center;
3153 *p_right_start = window_center;
3164 int zero_channel[256];
3165 int really_zero_channel[256];
3178 int s = map->
chan[i].
mux, floor;
3179 zero_channel[i] =
FALSE;
3187 uint8 step2_flag[256];
3188 static int range_list[4] = { 256, 128, 86, 64 };
3198 int csub = (1 << cbits)-1;
3204 for (k=0; k < cdim; ++k) {
3206 cval = cval >> cbits;
3211 finalY[offset++] = temp;
3213 finalY[offset++] = 0;
3217 step2_flag[0] = step2_flag[1] = 1;
3218 for (j=2; j < g->
values; ++j) {
3219 int low, high, pred, highroom, lowroom, room, val;
3225 highroom = range - pred;
3227 if (highroom < lowroom)
3228 room = highroom * 2;
3232 step2_flag[low] = step2_flag[high] = 1;
3235 if (highroom > lowroom)
3236 finalY[j] = val - lowroom + pred;
3238 finalY[j] = pred - val + highroom - 1;
3241 finalY[j] = pred - ((val+1)>>1);
3243 finalY[j] = pred + (val>>1);
3250 #ifdef STB_VORBIS_NO_DEFER_FLOOR
3251 do_floor(f, map, i, n, f->floor_buffers[i], finalY, step2_flag);
3254 for (j=0; j < g->
values; ++j) {
3261 zero_channel[i] =
TRUE;
3275 memcpy(really_zero_channel, zero_channel,
sizeof(really_zero_channel[0]) * f->
channels);
3283 for (i=0; i < map->
submaps; ++i) {
3286 uint8 do_not_decode[256];
3290 if (zero_channel[j]) {
3291 do_not_decode[ch] =
TRUE;
3292 residue_buffers[ch] = NULL;
3294 do_not_decode[ch] =
FALSE;
3313 for (j=0; j < n2; ++j) {
3317 m2 = m[j], a2 = m[j] - a[j];
3319 a2 = m[j], m2 = m[j] + a[j];
3322 m2 = m[j], a2 = m[j] + a[j];
3324 a2 = m[j], m2 = m[j] - a[j];
3332 #ifndef STB_VORBIS_NO_DEFER_FLOOR
3334 if (really_zero_channel[i]) {
3342 if (really_zero_channel[i]) {
3345 for (j=0; j < n2; ++j)
3375 left_start = right_start;
3376 *p_left = left_start;
3379 *p_left = left_start;
3397 if (current_end < f->current_loc + (right_end-left_start)) {
3398 if (current_end < f->current_loc) {
3405 if (*len > right_end) *len = right_end;
3430 int mode, left_end, right_end;
3451 for (j=0; j < n; ++j)
3470 for (j=0; right+j < len; ++j)
3480 if (len < right) right = len;
3484 return right - left;
3489 int len, right, left;
3494 #ifndef STB_VORBIS_NO_PUSHDATA_API
3544 for (s=0; s < n; ++s) {
3558 #endif // !STB_VORBIS_NO_PUSHDATA_API
3562 uint8 header[6], x,y;
3563 int len,i,j,k, max_submaps = 0;
3564 int longest_floorlist=0;
3618 #ifndef STB_VORBIS_NO_PUSHDATA_API
3643 int ordered, sorted_count;
3669 int current_entry = 0;
3670 int current_length =
get_bits(f,5) + 1;
3671 while (current_entry < c->entries) {
3672 int limit = c->
entries - current_entry;
3675 memset(lengths + current_entry, current_length, n);
3680 for (j=0; j < c->
entries; ++j) {
3685 if (lengths[j] == 32)
3708 sorted_count = total;
3711 #ifndef STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH
3712 for (j=0; j < c->
entries; ++j)
3790 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
3792 int len, sparse = c->
sparse;
3802 for (j=0; j < len; ++j) {
3807 float val = mults[off];
3837 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
3850 for (i=0; i < x; ++i) {
3883 for (j=0; j <= max_class; ++j) {
3908 for (j=0; j < g->
values; ++j) {
3913 for (j=0; j < g->
values; ++j)
3916 for (j=2; j < g->
values; ++j) {
3923 if (g->
values > longest_floorlist)
3924 longest_floorlist = g->
values;
3934 uint8 residue_cascade[64];
3950 residue_cascade[j] = high_bits*8 + low_bits;
3955 for (k=0; k < 8; ++k) {
3956 if (residue_cascade[j] & (1 << k)) {
3974 for (k=classwords-1; k >= 0; --k) {
4021 for (j=0; j < m->
submaps; ++j) {
4052 #ifdef STB_VORBIS_NO_DEFER_FLOOR
4063 #ifdef STB_VORBIS_DIVIDE_TABLE
4064 if (integer_divide_table[1][1]==0)
4065 for (i=0; i < DIVTAB_NUMER; ++i)
4066 for (j=1; j < DIVTAB_DENOM; ++j)
4067 integer_divide_table[i][j] = i / j;
4076 int i,max_part_read=0;
4081 if (part_read > max_part_read)
4082 max_part_read = part_read;
4084 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
4085 classify_mem = f->
channels * (
sizeof(
void*) + max_part_read *
sizeof(
uint8 *));
4087 classify_mem = f->
channels * (
sizeof(
void*) + max_part_read *
sizeof(
int *));
4148 #ifdef STB_VORBIS_NO_DEFER_FLOOR
4153 for (i=0; i < 2; ++i) {
4160 #ifndef STB_VORBIS_NO_STDIO
4167 if (p == NULL)
return;
4174 memset(p, 0,
sizeof(*p));
4185 #ifndef STB_VORBIS_NO_STDIO
4224 #ifndef STB_VORBIS_NO_PUSHDATA_API
4247 if (data_len < 4)
return 0;
4250 for (i=0; i < data_len; ++i) {
4251 if (data[i] == 0x4f) {
4256 if (i+26 >= data_len || i+27+data[i+26] >= data_len) {
4263 len = 27 + data[i+26];
4264 for (j=0; j < data[i+26]; ++j)
4265 len += data[i+27+j];
4268 for (j=0; j < 22; ++j)
4271 for ( ; j < 26; ++j)
4277 f->
scan[n].
goal_crc = data[i+22] + (data[i+23] << 8) + (data[i+24]<<16) + (data[i+25]<<24);
4280 if (data[i+27+data[i+26]-1] == 255)
4283 f->
scan[n].
sample_loc = data[i+6] + (data[i+7] << 8) + (data[i+ 8]<<16) + (data[i+ 9]<<24);
4298 if (m > data_len - n) m = data_len - n;
4301 for (j=0; j < m; ++j)
4331 const uint8 *data,
int data_len,
4366 return (
int) (f->
stream - data);
4376 return (
int) (f->
stream - data);
4393 if (channels) *channels = f->
channels;
4396 return (
int) (f->
stream - data);
4400 const unsigned char *data,
int data_len,
4419 *data_used = (int) (f->
stream - data);
4427 #endif // STB_VORBIS_NO_PUSHDATA_API
4431 #ifndef STB_VORBIS_NO_PUSHDATA_API
4435 #ifndef STB_VORBIS_NO_STDIO
4436 return (
unsigned int) (ftell(f->
f) - f->
f_start);
4440 #ifndef STB_VORBIS_NO_PULLDATA_API
4449 if (f->
eof)
return 0;
4458 for (i=1; i < 4; ++i)
4461 if (f->
eof)
return 0;
4464 uint32 i, crc, goal, len;
4465 for (i=0; i < 4; ++i)
4468 header[i] =
get8(f);
4469 if (f->
eof)
return 0;
4470 if (header[4] != 0)
goto invalid;
4471 goal = header[22] + (header[23] << 8) + (header[24]<<16) + (header[25]<<24);
4472 for (i=22; i < 26; ++i)
4475 for (i=0; i < 27; ++i)
4478 for (i=0; i < header[26]; ++i) {
4483 if (len && f->
eof)
return 0;
4484 for (i=0; i < len; ++i)
4499 if (header[5] & 0x04)
4516 #define SAMPLE_unknown 0xffffffff
4529 uint8 header[27], lacing[255];
4536 getn(f, header, 27);
4537 if (header[0] !=
'O' || header[1] !=
'g' || header[2] !=
'g' || header[3] !=
'S')
4539 getn(f, lacing, header[26]);
4543 for (i=0; i < header[26]; ++i)
4550 z->
last_decoded_sample = header[6] + (header[7] << 8) + (header[8] << 16) + (header[9] << 24);
4561 unsigned int previous_safe, end;
4565 previous_safe = limit_offset - 65536;
4587 int i, start_seg_with_known_loc, end_pos, page_start;
4588 uint32 delta, stream_length, padding;
4589 double offset = 0, bytes_per_sample = 0;
4601 if (sample_number < padding)
4604 sample_number -= padding;
4626 if (delta <= 65536) {
4639 if (error >= 0 && error < 8000) error = 8000;
4640 if (error < 0 && error > -8000) error = -8000;
4641 offset += error * 2;
4686 assert(end_pos >= 0);
4689 for (i = end_pos; i > 0; --i)
4693 start_seg_with_known_loc = i;
4714 f->
next_seg = start_seg_with_known_loc;
4716 for (i = 0; i < start_seg_with_known_loc; i++)
4732 int bits_read, bytes_read;
4741 bytes_read = (bits_read + 7) / 8;
4745 skip(f, -bytes_read);
4757 uint32 max_frame_samples;
4771 int left_start, left_end, right_start, right_end, mode, frame_samples;
4775 frame_samples = right_start - left_start;
4776 if (f->
current_loc + frame_samples > sample_number) {
4778 }
else if (f->
current_loc + frame_samples + max_frame_samples > sample_number) {
4803 assert(sample_number > frame_start);
4823 unsigned int restore_offset, previous_safe;
4824 unsigned int end, last_page_loc;
4866 previous_safe = last_page_loc+1;
4873 getn(f, (
unsigned char *)header, 6);
4877 if (lo == 0xffffffff && hi == 0xffffffff) {
4905 int len, right,left,i;
4920 if (channels) *channels = f->
channels;
4921 if (output) *output = f->
outputs;
4925 #ifndef STB_VORBIS_NO_STDIO
4943 if (error) *error = p.
error;
4950 unsigned int len, start;
4951 start = (
unsigned int) ftell(file);
4952 fseek(file, 0, SEEK_END);
4953 len = (
unsigned int) (ftell(file) - start);
4954 fseek(file, start, SEEK_SET);
4960 FILE *f = fopen(filename,
"rb");
4966 #endif // STB_VORBIS_NO_STDIO
4971 if (data == NULL)
return NULL;
4986 if (error) *error = p.
error;
4991 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
4992 #define PLAYBACK_MONO 1
4993 #define PLAYBACK_LEFT 2
4994 #define PLAYBACK_RIGHT 4
4996 #define L (PLAYBACK_LEFT | PLAYBACK_MONO)
4997 #define C (PLAYBACK_LEFT | PLAYBACK_RIGHT | PLAYBACK_MONO)
4998 #define R (PLAYBACK_RIGHT | PLAYBACK_MONO)
5008 {
L,
C,
R,
L,
R, C },
5012 #ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
5018 #define FASTDEF(x) float_conv x
5020 #define MAGIC(SHIFT) (1.5f * (1 << (23-SHIFT)) + 0.5f/(1 << SHIFT))
5021 #define ADDEND(SHIFT) (((150-SHIFT) << 23) + (1 << 22))
5022 #define FAST_SCALED_FLOAT_TO_INT(temp,x,s) (temp.f = (x) + MAGIC(s), temp.i - ADDEND(s))
5023 #define check_endianness()
5025 #define FAST_SCALED_FLOAT_TO_INT(temp,x,s) ((int) ((x) * (1 << (s))))
5026 #define check_endianness()
5034 for (i=0; i < len; ++i) {
5037 if ((
unsigned int) (v + 32768) > 65535)
5038 v = v < 0 ? -32768 : 32767;
5043 static void compute_samples(
int mask,
short *output,
int num_c,
float **data,
int d_offset,
int len)
5045 #define BUFFER_SIZE 32
5050 memset(buffer, 0,
sizeof(buffer));
5051 if (o + n > len) n = len - o;
5052 for (j=0; j < num_c; ++j) {
5053 if (channel_position[num_c][j] & mask) {
5054 for (i=0; i < n; ++i)
5055 buffer[i] += data[j][d_offset+o+i];
5058 for (i=0; i < n; ++i) {
5061 if ((
unsigned int) (v + 32768) > 65535)
5062 v = v < 0 ? -32768 : 32767;
5070 #define BUFFER_SIZE 32
5075 for (o = 0; o < len; o += BUFFER_SIZE >> 1) {
5078 memset(buffer, 0,
sizeof(buffer));
5079 if (o + n > len) n = len - o;
5080 for (j=0; j < num_c; ++j) {
5083 for (i=0; i < n; ++i) {
5084 buffer[i*2+0] += data[j][d_offset+o+i];
5085 buffer[i*2+1] += data[j][d_offset+o+i];
5088 for (i=0; i < n; ++i) {
5089 buffer[i*2+0] += data[j][d_offset+o+i];
5092 for (i=0; i < n; ++i) {
5093 buffer[i*2+1] += data[j][d_offset+o+i];
5097 for (i=0; i < (n<<1); ++i) {
5100 if ((
unsigned int) (v + 32768) > 65535)
5101 v = v < 0 ? -32768 : 32767;
5107 static void convert_samples_short(
int buf_c,
short **buffer,
int b_offset,
int data_c,
float **data,
int d_offset,
int samples)
5110 if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
5112 for (i=0; i < buf_c; ++i)
5113 compute_samples(channel_selector[buf_c][i], buffer[i]+b_offset, data_c, data, d_offset, samples);
5115 int limit = buf_c < data_c ? buf_c : data_c;
5116 for (i=0; i < limit; ++i)
5117 copy_samples(buffer[i]+b_offset, data[i]+d_offset, samples);
5118 for ( ; i < buf_c; ++i)
5119 memset(buffer[i]+b_offset, 0,
sizeof(
short) * samples);
5125 float **output = NULL;
5127 if (len > num_samples) len = num_samples;
5137 if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
5139 for (i=0; i < buf_c; ++i)
5142 int limit = buf_c < data_c ? buf_c : data_c;
5144 for (j=0; j < len; ++j) {
5145 for (i=0; i < limit; ++i) {
5147 float f = data[i][d_offset+j];
5149 if ((
unsigned int) (v + 32768) > 65535)
5150 v = v < 0 ? -32768 : 32767;
5153 for ( ; i < buf_c; ++i)
5166 if (len*num_c > num_shorts) len = num_shorts / num_c;
5175 int len = num_shorts / channels;
5178 if (z > channels) z = channels;
5181 if (n+k >= len) k = len - n;
5184 buffer += k*channels;
5187 if (n == len)
break;
5198 if (z > channels) z = channels;
5201 if (n+k >= len) k = len - n;
5206 if (n == len)
break;
5212 #ifndef STB_VORBIS_NO_STDIO
5215 int data_len, offset, total, limit,
error;
5218 if (v == NULL)
return -1;
5223 offset = data_len = 0;
5225 data = (
short *) malloc(total *
sizeof(*data));
5235 if (offset + limit > total) {
5238 data2 = (
short *) realloc(data, total *
sizeof(*data));
5239 if (data2 == NULL) {
5255 int data_len, offset, total, limit,
error;
5258 if (v == NULL)
return -1;
5263 offset = data_len = 0;
5265 data = (
short *) malloc(total *
sizeof(*data));
5275 if (offset + limit > total) {
5278 data2 = (
short *) realloc(data, total *
sizeof(*data));
5279 if (data2 == NULL) {
5291 #endif // STB_VORBIS_NO_INTEGER_CONVERSION
5296 int len = num_floats / channels;
5299 if (z > channels) z = channels;
5303 if (n+k >= len) k = len - n;
5304 for (j=0; j < k; ++j) {
5305 for (i=0; i < z; ++i)
5307 for ( ; i < channels; ++i)
5325 if (z > channels) z = channels;
5326 while (n < num_samples) {
5329 if (n+k >= num_samples) k = num_samples - n;
5331 for (i=0; i < z; ++i)
5333 for ( ; i < channels; ++i)
5334 memset(buffer[i]+n, 0,
sizeof(
float) * k);
5338 if (n == num_samples)
5345 #endif // STB_VORBIS_NO_PULLDATA_API
5399 #endif // STB_VORBIS_HEADER_ONLY