74 #ifndef STB_VORBIS_INCLUDE_STB_VORBIS_H
75 #define STB_VORBIS_INCLUDE_STB_VORBIS_H
77 #if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
78 #define STB_VORBIS_NO_STDIO 1
81 #ifndef STB_VORBIS_NO_STDIO
174 #ifndef STB_VORBIS_NO_PUSHDATA_API
184 const unsigned char * datablock,
int datablock_length_in_bytes,
185 int *datablock_memory_consumed_in_bytes,
199 const unsigned char *datablock,
int datablock_length_in_bytes,
249 #ifndef STB_VORBIS_NO_PULLDATA_API
257 #if !defined(STB_VORBIS_NO_STDIO) && !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
260 #if !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
273 #ifndef STB_VORBIS_NO_STDIO
324 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
360 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
420 #ifndef STB_VORBIS_HEADER_ONLY
460 #ifndef STB_VORBIS_MAX_CHANNELS
461 #define STB_VORBIS_MAX_CHANNELS 16
476 #ifndef STB_VORBIS_PUSHDATA_CRC_COUNT
477 #define STB_VORBIS_PUSHDATA_CRC_COUNT 4
485 #ifndef STB_VORBIS_FAST_HUFFMAN_LENGTH
486 #define STB_VORBIS_FAST_HUFFMAN_LENGTH 10
499 #ifndef STB_VORBIS_FAST_HUFFMAN_INT
500 #define STB_VORBIS_FAST_HUFFMAN_SHORT
527 #ifdef STB_VORBIS_CODEBOOK_SHORTS
528 #error "STB_VORBIS_CODEBOOK_SHORTS is no longer supported as it produced incorrect results for some input formats"
552 #ifdef STB_VORBIS_NO_PULLDATA_API
553 #define STB_VORBIS_NO_INTEGER_CONVERSION
554 #define STB_VORBIS_NO_STDIO
557 #if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
558 #define STB_VORBIS_NO_STDIO 1
561 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
562 #ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
567 #ifndef STB_VORBIS_BIG_ENDIAN
568 #define STB_VORBIS_ENDIAN 0
570 #define STB_VORBIS_ENDIAN 1
577 #ifndef STB_VORBIS_NO_STDIO
581 #ifndef STB_VORBIS_NO_CRT
588 #if defined(_MSC_VER) || defined(__MINGW32__)
591 #if defined(__linux__) || defined(__linux) || defined(__sun__) || defined(__EMSCRIPTEN__) || defined(__NEWLIB__)
597 #define free(s) ((void) 0)
612 #define __forceinline
614 #define alloca __builtin_alloca
616 #elif !defined(_MSC_VER)
618 #define __forceinline inline
620 #define __forceinline
624 #if STB_VORBIS_MAX_CHANNELS > 256
625 #error "Value of STB_VORBIS_MAX_CHANNELS outside of allowed range"
628 #if STB_VORBIS_FAST_HUFFMAN_LENGTH > 24
629 #error "Value of STB_VORBIS_FAST_HUFFMAN_LENGTH outside of allowed range"
635 #define CHECK(f) _CrtIsValidHeapPointer(f->channel_buffers[1])
637 #define CHECK(f) ((void) 0)
640 #define MAX_BLOCKSIZE_LOG 13
641 #define MAX_BLOCKSIZE (1 << MAX_BLOCKSIZE_LOG)
659 #define STBV_NOTUSED(v) (void)(v)
661 #define STBV_NOTUSED(v) (void)sizeof(v)
677 #define FAST_HUFFMAN_TABLE_SIZE (1 << STB_VORBIS_FAST_HUFFMAN_LENGTH)
678 #define FAST_HUFFMAN_TABLE_MASK (FAST_HUFFMAN_TABLE_SIZE - 1)
693 #ifdef STB_VORBIS_FAST_HUFFMAN_SHORT
800 #ifndef STB_VORBIS_NO_STDIO
857 #ifndef STB_VORBIS_NO_DEFER_FLOOR
894 #ifndef STB_VORBIS_NO_PUSHDATA_API
903 #if defined(STB_VORBIS_NO_PUSHDATA_API)
904 #define IS_PUSH_MODE(f) FALSE
905 #elif defined(STB_VORBIS_NO_PULLDATA_API)
906 #define IS_PUSH_MODE(f) TRUE
908 #define IS_PUSH_MODE(f) ((f)->push_mode)
928 #define array_size_required(count,size) (count*(sizeof(void *)+(size)))
930 #define temp_alloc(f,size) (f->alloc.alloc_buffer ? setup_temp_malloc(f,size) : alloca(size))
931 #define temp_free(f,p) (void)0
932 #define temp_alloc_save(f) ((f)->temp_offset)
933 #define temp_alloc_restore(f,p) ((f)->temp_offset = (p))
935 #define temp_block_array(f,count,size) make_block_array(temp_alloc(f,array_size_required(count,size)), count, size)
938 static void *make_block_array(
void *mem,
int count,
int size)
941 void ** p = (
void **) mem;
942 char *q = (
char *) (p + count);
943 for (i=0; i < count; ++i) {
950 static void *setup_malloc(
vorb *
f,
int sz)
953 f->setup_memory_required += sz;
954 if (
f->alloc.alloc_buffer) {
955 void *p = (
char *)
f->alloc.alloc_buffer +
f->setup_offset;
956 if (
f->setup_offset + sz >
f->temp_offset)
return NULL;
957 f->setup_offset += sz;
960 return sz ? malloc(sz) : NULL;
963 static void setup_free(
vorb *
f,
void *p)
965 if (
f->alloc.alloc_buffer)
return;
969 static void *setup_temp_malloc(
vorb *
f,
int sz)
972 if (
f->alloc.alloc_buffer) {
974 f->temp_offset -= sz;
975 return (
char *)
f->alloc.alloc_buffer +
f->temp_offset;
980 static void setup_temp_free(
vorb *
f,
void *p,
int sz)
982 if (
f->alloc.alloc_buffer) {
983 f->temp_offset += (sz+7)&~7;
989 #define CRC32_POLY 0x04c11db7
991 static uint32 crc_table[256];
992 static void crc32_init(
void)
996 for(i=0; i < 256; i++) {
997 for (s=(
uint32) i << 24, j=0; j < 8; ++j)
998 s = (s << 1) ^ (s >= (1U<<31) ?
CRC32_POLY : 0);
1005 return (crc << 8) ^ crc_table[
byte ^ (crc >> 24)];
1012 n = ((n & 0xAAAAAAAA) >> 1) | ((n & 0x55555555) << 1);
1013 n = ((n & 0xCCCCCCCC) >> 2) | ((n & 0x33333333) << 2);
1014 n = ((n & 0xF0F0F0F0) >> 4) | ((n & 0x0F0F0F0F) << 4);
1015 n = ((n & 0xFF00FF00) >> 8) | ((n & 0x00FF00FF) << 8);
1016 return (n >> 16) | (n << 16);
1019 static float square(
float x)
1027 static int ilog(
int32 n)
1029 static signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 };
1031 if (n < 0)
return 0;
1035 if (n < (1 << 4))
return 0 + log2_4[n ];
1036 else if (n < (1 << 9))
return 5 + log2_4[n >> 5];
1037 else return 10 + log2_4[n >> 10];
1038 else if (n < (1 << 24))
1039 if (n < (1 << 19))
return 15 + log2_4[n >> 15];
1040 else return 20 + log2_4[n >> 20];
1041 else if (n < (1 << 29))
return 25 + log2_4[n >> 25];
1042 else return 30 + log2_4[n >> 30];
1046 #define M_PI 3.14159265358979323846264f
1057 static float float32_unpack(
uint32 x)
1060 uint32 mantissa = x & 0x1fffff;
1061 uint32 sign = x & 0x80000000;
1062 uint32 exp = (x & 0x7fe00000) >> 21;
1063 double res = sign ? -(double)mantissa : (
double)mantissa;
1064 return (
float) ldexp((
float)res, (
int)exp-788);
1075 static void add_entry(
Codebook *c,
uint32 huff_code,
int symbol,
int count,
int len,
uint32 *values)
1082 values [count] = symbol;
1091 memset(available, 0,
sizeof(available));
1093 for (k=0; k < n; ++k)
if (len[k] <
NO_CODE)
break;
1095 assert(len[k] < 32);
1097 add_entry(c, 0, k, m++, len[k], values);
1099 for (i=1; i <= len[k]; ++i)
1100 available[i] = 1U << (32-i);
1105 for (i=k+1; i < n; ++i) {
1116 while (z > 0 && !available[z]) --z;
1117 if (z == 0) {
return FALSE; }
1120 add_entry(c,
bit_reverse(res), i, m++, len[i], values);
1123 for (y=len[i]; y > z; --y) {
1124 assert(available[y] == 0);
1125 available[y] = res + (1 << (32-y));
1134 static void compute_accelerated_huffman(
Codebook *c)
1142 if (len > 32767) len = 32767;
1144 for (i=0; i < len; ++i) {
1157 #define STBV_CDECL __cdecl
1162 static int STBV_CDECL uint32_compare(
const void *p,
const void *q)
1166 return x < y ? -1 : x > y;
1188 for (i=0; i < c->
entries; ++i)
1189 if (include_in_sort(c, lengths[i]))
1206 for (i=0; i < len; ++i) {
1207 int huff_len = c->
sparse ? lengths[values[i]] : lengths[i];
1208 if (include_in_sort(c,huff_len)) {
1213 int m = x + (n >> 1);
1233 static int vorbis_validate(
uint8 *data)
1235 static uint8 vorbis[6] = {
'v',
'o',
'r',
'b',
'i',
's' };
1236 return memcmp(data, vorbis, 6) == 0;
1241 static int lookup1_values(
int entries,
int dim)
1243 int r = (int) floor(exp((
float)
log((
float) entries) / dim));
1244 if ((
int) floor(pow((
float) r+1, dim)) <= entries)
1246 if (pow((
float) r+1, dim) <= entries)
1248 if ((
int) floor(pow((
float) r, dim)) > entries)
1254 static void compute_twiddle_factors(
int n,
float *
A,
float *
B,
float *
C)
1256 int n4 = n >> 2, n8 = n >> 3;
1259 for (k=k2=0; k < n4; ++k,k2+=2) {
1260 A[k2 ] = (float) cos(4*k*
M_PI/n);
1261 A[k2+1] = (float) -sin(4*k*
M_PI/n);
1262 B[k2 ] = (float) cos((k2+1)*
M_PI/n/2) * 0.5f;
1263 B[k2+1] = (float) sin((k2+1)*
M_PI/n/2) * 0.5f;
1265 for (k=k2=0; k < n8; ++k,k2+=2) {
1266 C[k2 ] = (float) cos(2*(k2+1)*
M_PI/n);
1267 C[k2+1] = (float) -sin(2*(k2+1)*
M_PI/n);
1271 static void compute_window(
int n,
float *
window)
1274 for (i=0; i < n2; ++i)
1275 window[i] = (
float) sin(0.5 *
M_PI * square((
float) sin((i - 0 + 0.5) / n2 * 0.5 *
M_PI)));
1278 static void compute_bitreverse(
int n,
uint16 *rev)
1280 int ld = ilog(n) - 1;
1282 for (i=0; i < n8; ++i)
1286 static int init_blocksize(
vorb *
f,
int b,
int n)
1288 int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3;
1289 f->A[b] = (
float *) setup_malloc(
f,
sizeof(
float) * n2);
1290 f->B[b] = (
float *) setup_malloc(
f,
sizeof(
float) * n2);
1291 f->C[b] = (
float *) setup_malloc(
f,
sizeof(
float) * n4);
1293 compute_twiddle_factors(n,
f->A[b],
f->B[b],
f->C[b]);
1294 f->window[b] = (
float *) setup_malloc(
f,
sizeof(
float) * n2);
1296 compute_window(n,
f->window[b]);
1297 f->bit_reverse[b] = (
uint16 *) setup_malloc(
f,
sizeof(
uint16) * n8);
1299 compute_bitreverse(n,
f->bit_reverse[b]);
1303 static void neighbors(
uint16 *x,
int n,
int *plow,
int *phigh)
1308 for (i=0; i < n; ++i) {
1309 if (x[i] > low && x[i] < x[n]) { *plow = i; low = x[i]; }
1310 if (x[i] < high && x[i] > x[n]) { *phigh = i; high = x[i]; }
1320 static int STBV_CDECL point_compare(
const void *p,
const void *q)
1324 return a->
x < b->
x ? -1 : a->
x > b->
x;
1331 #if defined(STB_VORBIS_NO_STDIO)
1332 #define USE_MEMORY(z) TRUE
1334 #define USE_MEMORY(z) ((z)->stream)
1344 #ifndef STB_VORBIS_NO_STDIO
1346 int c = fgetc(z->
f);
1347 if (c == EOF) { z->
eof =
TRUE;
return 0; }
1363 static int getn(
vorb *z,
uint8 *data,
int n)
1367 memcpy(data, z->
stream, n);
1372 #ifndef STB_VORBIS_NO_STDIO
1373 if (fread(data, n, 1, z->
f) == 1)
1382 static void skip(
vorb *z,
int n)
1389 #ifndef STB_VORBIS_NO_STDIO
1391 long x = ftell(z->
f);
1392 fseek(z->
f, x+n, SEEK_SET);
1397 static int set_file_offset(
stb_vorbis *
f,
unsigned int loc)
1399 #ifndef STB_VORBIS_NO_PUSHDATA_API
1400 if (
f->push_mode)
return 0;
1404 if (
f->stream_start + loc >=
f->stream_end ||
f->stream_start + loc < f->
stream_start) {
1405 f->stream =
f->stream_end;
1409 f->stream =
f->stream_start + loc;
1413 #ifndef STB_VORBIS_NO_STDIO
1414 if (loc +
f->f_start < loc || loc >= 0x80000000) {
1420 if (!fseek(
f->f, loc, SEEK_SET))
1423 fseek(
f->f,
f->f_start, SEEK_END);
1429 static uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 };
1431 static int capture_pattern(
vorb *
f)
1433 if (0x4f != get8(
f))
return FALSE;
1434 if (0x67 != get8(
f))
return FALSE;
1435 if (0x67 != get8(
f))
return FALSE;
1436 if (0x53 != get8(
f))
return FALSE;
1440 #define PAGEFLAG_continued_packet 1
1441 #define PAGEFLAG_first_page 2
1442 #define PAGEFLAG_last_page 4
1444 static int start_page_no_capturepattern(
vorb *
f)
1453 f->page_flag = get8(
f);
1467 f->segment_count = get8(
f);
1468 if (!getn(
f,
f->segments,
f->segment_count))
1471 f->end_seg_with_known_loc = -2;
1472 if (loc0 != ~0U || loc1 != ~0U) {
1475 for (i=
f->segment_count-1; i >= 0; --i)
1476 if (
f->segments[i] < 255)
1480 f->end_seg_with_known_loc = i;
1481 f->known_loc_for_packet = loc0;
1484 if (
f->first_decode) {
1487 for (i=0; i <
f->segment_count; ++i)
1488 len +=
f->segments[i];
1489 len += 27 +
f->segment_count;
1490 f->p_first.page_end =
f->p_first.page_start + len;
1491 f->p_first.last_decoded_sample = loc0;
1497 static int start_page(
vorb *
f)
1500 return start_page_no_capturepattern(
f);
1503 static int start_packet(
vorb *
f)
1505 while (
f->next_seg == -1) {
1506 if (!start_page(
f))
return FALSE;
1512 f->packet_bytes = 0;
1513 f->bytes_in_seg = 0;
1518 static int maybe_start_packet(
vorb *
f)
1520 if (
f->next_seg == -1) {
1522 if (
f->eof)
return FALSE;
1527 if (!start_page_no_capturepattern(
f))
return FALSE;
1532 f->bytes_in_seg = 0;
1536 return start_packet(
f);
1539 static int next_segment(
vorb *
f)
1542 if (
f->last_seg)
return 0;
1543 if (
f->next_seg == -1) {
1544 f->last_seg_which =
f->segment_count-1;
1545 if (!start_page(
f)) {
f->last_seg = 1;
return 0; }
1548 len =
f->segments[
f->next_seg++];
1551 f->last_seg_which =
f->next_seg-1;
1553 if (
f->next_seg >=
f->segment_count)
1555 assert(
f->bytes_in_seg == 0);
1556 f->bytes_in_seg = len;
1561 #define INVALID_BITS (-1)
1563 static int get8_packet_raw(
vorb *
f)
1565 if (!
f->bytes_in_seg) {
1566 if (
f->last_seg)
return EOP;
1567 else if (!next_segment(
f))
return EOP;
1569 assert(
f->bytes_in_seg > 0);
1575 static int get8_packet(
vorb *
f)
1577 int x = get8_packet_raw(
f);
1582 static int get32_packet(
vorb *
f)
1586 x += get8_packet(
f) << 8;
1587 x += get8_packet(
f) << 16;
1588 x += (
uint32) get8_packet(
f) << 24;
1592 static void flush_packet(
vorb *
f)
1594 while (get8_packet_raw(
f) !=
EOP);
1603 if (
f->valid_bits < 0)
return 0;
1604 if (
f->valid_bits < n) {
1607 z = get_bits(
f, 24);
1608 z += get_bits(
f, n-24) << 24;
1611 if (
f->valid_bits == 0)
f->acc = 0;
1612 while (
f->valid_bits < n) {
1613 int z = get8_packet_raw(
f);
1618 f->acc += z <<
f->valid_bits;
1623 assert(
f->valid_bits >= n);
1624 z =
f->acc & ((1 << n)-1);
1636 if (
f->valid_bits <= 24) {
1637 if (
f->valid_bits == 0)
f->acc = 0;
1640 if (
f->last_seg && !
f->bytes_in_seg)
return;
1641 z = get8_packet_raw(
f);
1642 if (z ==
EOP)
return;
1643 f->acc += (unsigned) z <<
f->valid_bits;
1645 }
while (
f->valid_bits <= 24);
1673 int m = x + (n >> 1);
1685 if (
f->valid_bits >= len) {
1687 f->valid_bits -= len;
1697 for (i=0; i < c->
entries; ++i) {
1715 #ifndef STB_VORBIS_NO_INLINE_DECODE
1717 #define DECODE_RAW(var, f,c) \
1718 if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH) \
1720 var = f->acc & FAST_HUFFMAN_TABLE_MASK; \
1721 var = c->fast_huffman[var]; \
1723 int n = c->codeword_lengths[var]; \
1725 f->valid_bits -= n; \
1726 if (f->valid_bits < 0) { f->valid_bits = 0; var = -1; } \
1728 var = codebook_decode_scalar_raw(f,c); \
1744 if (
f->valid_bits < 0) {
f->valid_bits = 0;
return -1; }
1747 return codebook_decode_scalar_raw(
f,c);
1750 #define DECODE_RAW(var,f,c) var = codebook_decode_scalar(f,c);
1754 #define DECODE(var,f,c) \
1755 DECODE_RAW(var,f,c) \
1756 if (c->sparse) var = c->sorted_values[var];
1758 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
1759 #define DECODE_VQ(var,f,c) DECODE_RAW(var,f,c)
1761 #define DECODE_VQ(var,f,c) DECODE(var,f,c)
1771 #define CODEBOOK_ELEMENT(c,off) (c->multiplicands[off])
1772 #define CODEBOOK_ELEMENT_FAST(c,off) (c->multiplicands[off])
1773 #define CODEBOOK_ELEMENT_BASE(c) (0)
1784 if (c->
sparse) assert(z < c->sorted_entries);
1786 if (!
f->bytes_in_seg)
1795 static int codebook_decode(
vorb *
f,
Codebook *c,
float *output,
int len)
1797 int i,z = codebook_decode_start(
f,c);
1798 if (z < 0)
return FALSE;
1801 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1805 for (i=0; i < len; ++i) {
1819 for (i=0; i < len; ++i) {
1826 for (i=0; i < len; ++i) {
1834 static int codebook_decode_step(
vorb *
f,
Codebook *c,
float *output,
int len,
int step)
1836 int i,z = codebook_decode_start(
f,c);
1838 if (z < 0)
return FALSE;
1841 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1844 for (i=0; i < len; ++i) {
1847 output[i*step] += val;
1856 for (i=0; i < len; ++i) {
1858 output[i*step] += val;
1865 static int codebook_decode_deinterleave_repeat(
vorb *
f,
Codebook *c,
float **
outputs,
int ch,
int *c_inter_p,
int *p_inter_p,
int len,
int total_decode)
1867 int c_inter = *c_inter_p;
1868 int p_inter = *p_inter_p;
1874 while (total_decode > 0) {
1877 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
1878 assert(!c->
sparse || z < c->sorted_entries);
1881 if (!
f->bytes_in_seg)
1882 if (
f->last_seg)
return FALSE;
1890 if (c_inter + p_inter*ch + effective > len * ch) {
1891 effective = len*ch - (p_inter*ch - c_inter);
1894 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1897 for (i=0; i < effective; ++i) {
1901 outputs[c_inter][p_inter] += val;
1902 if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1911 for (i=0; i < effective; ++i) {
1914 outputs[c_inter][p_inter] += val;
1915 if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1919 for (i=0; i < effective; ++i) {
1922 outputs[c_inter][p_inter] += val;
1923 if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1928 total_decode -= effective;
1930 *c_inter_p = c_inter;
1931 *p_inter_p = p_inter;
1935 static int predict_point(
int x,
int x0,
int x1,
int y0,
int y1)
1940 int err = abs(dy) * (x - x0);
1941 int off = err / adx;
1942 return dy < 0 ? y0 - off : y0 + off;
1946 static float inverse_db_table[256] =
1948 1.0649863e-07f, 1.1341951e-07f, 1.2079015e-07f, 1.2863978e-07f,
1949 1.3699951e-07f, 1.4590251e-07f, 1.5538408e-07f, 1.6548181e-07f,
1950 1.7623575e-07f, 1.8768855e-07f, 1.9988561e-07f, 2.1287530e-07f,
1951 2.2670913e-07f, 2.4144197e-07f, 2.5713223e-07f, 2.7384213e-07f,
1952 2.9163793e-07f, 3.1059021e-07f, 3.3077411e-07f, 3.5226968e-07f,
1953 3.7516214e-07f, 3.9954229e-07f, 4.2550680e-07f, 4.5315863e-07f,
1954 4.8260743e-07f, 5.1396998e-07f, 5.4737065e-07f, 5.8294187e-07f,
1955 6.2082472e-07f, 6.6116941e-07f, 7.0413592e-07f, 7.4989464e-07f,
1956 7.9862701e-07f, 8.5052630e-07f, 9.0579828e-07f, 9.6466216e-07f,
1957 1.0273513e-06f, 1.0941144e-06f, 1.1652161e-06f, 1.2409384e-06f,
1958 1.3215816e-06f, 1.4074654e-06f, 1.4989305e-06f, 1.5963394e-06f,
1959 1.7000785e-06f, 1.8105592e-06f, 1.9282195e-06f, 2.0535261e-06f,
1960 2.1869758e-06f, 2.3290978e-06f, 2.4804557e-06f, 2.6416497e-06f,
1961 2.8133190e-06f, 2.9961443e-06f, 3.1908506e-06f, 3.3982101e-06f,
1962 3.6190449e-06f, 3.8542308e-06f, 4.1047004e-06f, 4.3714470e-06f,
1963 4.6555282e-06f, 4.9580707e-06f, 5.2802740e-06f, 5.6234160e-06f,
1964 5.9888572e-06f, 6.3780469e-06f, 6.7925283e-06f, 7.2339451e-06f,
1965 7.7040476e-06f, 8.2047000e-06f, 8.7378876e-06f, 9.3057248e-06f,
1966 9.9104632e-06f, 1.0554501e-05f, 1.1240392e-05f, 1.1970856e-05f,
1967 1.2748789e-05f, 1.3577278e-05f, 1.4459606e-05f, 1.5399272e-05f,
1968 1.6400004e-05f, 1.7465768e-05f, 1.8600792e-05f, 1.9809576e-05f,
1969 2.1096914e-05f, 2.2467911e-05f, 2.3928002e-05f, 2.5482978e-05f,
1970 2.7139006e-05f, 2.8902651e-05f, 3.0780908e-05f, 3.2781225e-05f,
1971 3.4911534e-05f, 3.7180282e-05f, 3.9596466e-05f, 4.2169667e-05f,
1972 4.4910090e-05f, 4.7828601e-05f, 5.0936773e-05f, 5.4246931e-05f,
1973 5.7772202e-05f, 6.1526565e-05f, 6.5524908e-05f, 6.9783085e-05f,
1974 7.4317983e-05f, 7.9147585e-05f, 8.4291040e-05f, 8.9768747e-05f,
1975 9.5602426e-05f, 0.00010181521f, 0.00010843174f, 0.00011547824f,
1976 0.00012298267f, 0.00013097477f, 0.00013948625f, 0.00014855085f,
1977 0.00015820453f, 0.00016848555f, 0.00017943469f, 0.00019109536f,
1978 0.00020351382f, 0.00021673929f, 0.00023082423f, 0.00024582449f,
1979 0.00026179955f, 0.00027881276f, 0.00029693158f, 0.00031622787f,
1980 0.00033677814f, 0.00035866388f, 0.00038197188f, 0.00040679456f,
1981 0.00043323036f, 0.00046138411f, 0.00049136745f, 0.00052329927f,
1982 0.00055730621f, 0.00059352311f, 0.00063209358f, 0.00067317058f,
1983 0.00071691700f, 0.00076350630f, 0.00081312324f, 0.00086596457f,
1984 0.00092223983f, 0.00098217216f, 0.0010459992f, 0.0011139742f,
1985 0.0011863665f, 0.0012634633f, 0.0013455702f, 0.0014330129f,
1986 0.0015261382f, 0.0016253153f, 0.0017309374f, 0.0018434235f,
1987 0.0019632195f, 0.0020908006f, 0.0022266726f, 0.0023713743f,
1988 0.0025254795f, 0.0026895994f, 0.0028643847f, 0.0030505286f,
1989 0.0032487691f, 0.0034598925f, 0.0036847358f, 0.0039241906f,
1990 0.0041792066f, 0.0044507950f, 0.0047400328f, 0.0050480668f,
1991 0.0053761186f, 0.0057254891f, 0.0060975636f, 0.0064938176f,
1992 0.0069158225f, 0.0073652516f, 0.0078438871f, 0.0083536271f,
1993 0.0088964928f, 0.009474637f, 0.010090352f, 0.010746080f,
1994 0.011444421f, 0.012188144f, 0.012980198f, 0.013823725f,
1995 0.014722068f, 0.015678791f, 0.016697687f, 0.017782797f,
1996 0.018938423f, 0.020169149f, 0.021479854f, 0.022875735f,
1997 0.024362330f, 0.025945531f, 0.027631618f, 0.029427276f,
1998 0.031339626f, 0.033376252f, 0.035545228f, 0.037855157f,
1999 0.040315199f, 0.042935108f, 0.045725273f, 0.048696758f,
2000 0.051861348f, 0.055231591f, 0.058820850f, 0.062643361f,
2001 0.066714279f, 0.071049749f, 0.075666962f, 0.080584227f,
2002 0.085821044f, 0.091398179f, 0.097337747f, 0.10366330f,
2003 0.11039993f, 0.11757434f, 0.12521498f, 0.13335215f,
2004 0.14201813f, 0.15124727f, 0.16107617f, 0.17154380f,
2005 0.18269168f, 0.19456402f, 0.20720788f, 0.22067342f,
2006 0.23501402f, 0.25028656f, 0.26655159f, 0.28387361f,
2007 0.30232132f, 0.32196786f, 0.34289114f, 0.36517414f,
2008 0.38890521f, 0.41417847f, 0.44109412f, 0.46975890f,
2009 0.50028648f, 0.53279791f, 0.56742212f, 0.60429640f,
2010 0.64356699f, 0.68538959f, 0.72993007f, 0.77736504f,
2011 0.82788260f, 0.88168307f, 0.9389798f, 1.0f
2022 #ifndef STB_VORBIS_NO_DEFER_FLOOR
2023 #define LINE_OP(a,b) a *= b
2025 #define LINE_OP(a,b) a = b
2028 #ifdef STB_VORBIS_DIVIDE_TABLE
2029 #define DIVTAB_NUMER 32
2030 #define DIVTAB_DENOM 64
2031 int8 integer_divide_table[DIVTAB_NUMER][DIVTAB_DENOM];
2034 static __forceinline void draw_line(
float *output,
int x0,
int y0,
int x1,
int y1,
int n)
2044 #ifdef STB_VORBIS_DIVIDE_TABLE
2045 if (adx < DIVTAB_DENOM && ady < DIVTAB_NUMER) {
2047 base = -integer_divide_table[ady][adx];
2050 base = integer_divide_table[ady][adx];
2067 ady -= abs(base) * adx;
2070 LINE_OP(output[x], inverse_db_table[y&255]);
2071 for (++x; x < x1; ++x) {
2078 LINE_OP(output[x], inverse_db_table[y&255]);
2083 static int residue_decode(
vorb *
f,
Codebook *book,
float *target,
int offset,
int n,
int rtype)
2088 for (k=0; k < step; ++k)
2089 if (!codebook_decode_step(
f, book, target+offset+k, n-offset-k, step))
2092 for (k=0; k < n; ) {
2093 if (!codebook_decode(
f, book, target+offset, n-k))
2104 static void decode_residue(
vorb *
f,
float *residue_buffers[],
int ch,
int n,
int rn,
uint8 *do_not_decode)
2107 Residue *r =
f->residue_config + rn;
2108 int rtype =
f->residue_types[rn];
2110 int classwords =
f->codebooks[c].dimensions;
2111 unsigned int actual_size = rtype == 2 ? n*2 : n;
2112 unsigned int limit_r_begin = (r->
begin < actual_size ? r->
begin : actual_size);
2113 unsigned int limit_r_end = (r->
end < actual_size ? r->
end : actual_size);
2114 int n_read = limit_r_end - limit_r_begin;
2117 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2120 int **classifications = (
int **)
temp_block_array(
f,
f->channels, part_read *
sizeof(**classifications));
2125 for (i=0; i < ch; ++i)
2126 if (!do_not_decode[i])
2127 memset(residue_buffers[i], 0,
sizeof(
float) * n);
2129 if (rtype == 2 && ch != 1) {
2130 for (j=0; j < ch; ++j)
2131 if (!do_not_decode[j])
2136 for (pass=0; pass < 8; ++pass) {
2137 int pcount = 0, class_set = 0;
2139 while (pcount < part_read) {
2141 int c_inter = (z & 1), p_inter = z>>1;
2146 if (q ==
EOP)
goto done;
2147 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2148 part_classdata[0][class_set] = r->
classdata[q];
2150 for (i=classwords-1; i >= 0; --i) {
2156 for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2158 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2159 int c = part_classdata[0][class_set][i];
2161 int c = classifications[0][pcount];
2166 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
2167 if (!codebook_decode_deinterleave_repeat(
f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->
part_size))
2171 if (!codebook_decode_deinterleave_repeat(
f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->
part_size))
2180 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2184 }
else if (ch > 2) {
2185 while (pcount < part_read) {
2187 int c_inter = z % ch, p_inter = z/ch;
2192 if (q ==
EOP)
goto done;
2193 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2194 part_classdata[0][class_set] = r->
classdata[q];
2196 for (i=classwords-1; i >= 0; --i) {
2202 for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2204 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2205 int c = part_classdata[0][class_set][i];
2207 int c = classifications[0][pcount];
2212 if (!codebook_decode_deinterleave_repeat(
f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->
part_size))
2220 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2230 for (pass=0; pass < 8; ++pass) {
2231 int pcount = 0, class_set=0;
2232 while (pcount < part_read) {
2234 for (j=0; j < ch; ++j) {
2235 if (!do_not_decode[j]) {
2239 if (temp ==
EOP)
goto done;
2240 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2241 part_classdata[j][class_set] = r->
classdata[temp];
2243 for (i=classwords-1; i >= 0; --i) {
2251 for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2252 for (j=0; j < ch; ++j) {
2253 if (!do_not_decode[j]) {
2254 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2255 int c = part_classdata[j][class_set][i];
2257 int c = classifications[j][pcount];
2261 float *target = residue_buffers[j];
2265 if (!residue_decode(
f, book, target, offset, n, rtype))
2271 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2278 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2289 void inverse_mdct_slow(
float *buffer,
int n)
2293 float *x = (
float *) malloc(
sizeof(*x) * n2);
2294 memcpy(x, buffer,
sizeof(*x) * n2);
2295 for (i=0; i < n; ++i) {
2297 for (j=0; j < n2; ++j)
2305 acc += x[j] * (
float) cos(
M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1));
2312 void inverse_mdct_slow(
float *buffer,
int n,
vorb *
f,
int blocktype)
2316 int n2 = n >> 1, nmask = (n << 2) -1;
2317 float *x = (
float *) malloc(
sizeof(*x) * n2);
2318 memcpy(x, buffer,
sizeof(*x) * n2);
2319 for (i=0; i < 4*n; ++i)
2320 mcos[i] = (
float) cos(
M_PI / 2 * i / n);
2322 for (i=0; i < n; ++i) {
2324 for (j=0; j < n2; ++j)
2325 acc += x[j] * mcos[(2 * i + 1 + n2)*(2*j+1) & nmask];
2333 void dct_iv_slow(
float *buffer,
int n)
2338 int n2 = n >> 1, nmask = (n << 3) - 1;
2339 memcpy(x, buffer,
sizeof(*x) * n);
2340 for (i=0; i < 8*n; ++i)
2341 mcos[i] = (
float) cos(
M_PI / 4 * i / n);
2342 for (i=0; i < n; ++i) {
2344 for (j=0; j < n; ++j)
2345 acc += x[j] * mcos[((2 * i + 1)*(2*j+1)) & nmask];
2350 void inverse_mdct_slow(
float *buffer,
int n,
vorb *
f,
int blocktype)
2352 int i, n4 = n >> 2, n2 = n >> 1, n3_4 = n - n4;
2355 memcpy(temp, buffer, n2 *
sizeof(
float));
2356 dct_iv_slow(temp, n2);
2358 for (i=0; i < n4 ; ++i) buffer[i] = temp[i+n4];
2359 for ( ; i < n3_4; ++i) buffer[i] = -temp[n3_4 - i - 1];
2360 for ( ; i < n ; ++i) buffer[i] = -temp[i - n3_4];
2364 #ifndef LIBVORBIS_MDCT
2365 #define LIBVORBIS_MDCT 0
2382 extern void mdct_init(mdct_lookup *lookup,
int n);
2383 extern void mdct_clear(mdct_lookup *l);
2384 extern void mdct_backward(mdct_lookup *
init,
float *in,
float *out);
2388 void inverse_mdct(
float *buffer,
int n,
vorb *
f,
int blocktype)
2391 if (M1.n == n) M = &M1;
2392 else if (M2.n == n) M = &M2;
2393 else if (M1.n == 0) { mdct_init(&M1, n); M = &M1; }
2395 if (M2.n) __asm
int 3;
2400 mdct_backward(M, buffer, buffer);
2408 static void imdct_step3_iter0_loop(
int n,
float *e,
int i_off,
int k_off,
float *
A)
2410 float *ee0 = e + i_off;
2411 float *ee2 = ee0 + k_off;
2414 assert((n & 3) == 0);
2415 for (i=(n>>2); i > 0; --i) {
2416 float k00_20, k01_21;
2417 k00_20 = ee0[ 0] - ee2[ 0];
2418 k01_21 = ee0[-1] - ee2[-1];
2421 ee2[ 0] = k00_20 *
A[0] - k01_21 *
A[1];
2422 ee2[-1] = k01_21 *
A[0] + k00_20 *
A[1];
2425 k00_20 = ee0[-2] - ee2[-2];
2426 k01_21 = ee0[-3] - ee2[-3];
2429 ee2[-2] = k00_20 *
A[0] - k01_21 *
A[1];
2430 ee2[-3] = k01_21 *
A[0] + k00_20 *
A[1];
2433 k00_20 = ee0[-4] - ee2[-4];
2434 k01_21 = ee0[-5] - ee2[-5];
2437 ee2[-4] = k00_20 *
A[0] - k01_21 *
A[1];
2438 ee2[-5] = k01_21 *
A[0] + k00_20 *
A[1];
2441 k00_20 = ee0[-6] - ee2[-6];
2442 k01_21 = ee0[-7] - ee2[-7];
2445 ee2[-6] = k00_20 *
A[0] - k01_21 *
A[1];
2446 ee2[-7] = k01_21 *
A[0] + k00_20 *
A[1];
2453 static void imdct_step3_inner_r_loop(
int lim,
float *e,
int d0,
int k_off,
float *
A,
int k1)
2456 float k00_20, k01_21;
2459 float *e2 = e0 + k_off;
2461 for (i=lim >> 2; i > 0; --i) {
2462 k00_20 = e0[-0] - e2[-0];
2463 k01_21 = e0[-1] - e2[-1];
2466 e2[-0] = (k00_20)*
A[0] - (k01_21) *
A[1];
2467 e2[-1] = (k01_21)*
A[0] + (k00_20) *
A[1];
2471 k00_20 = e0[-2] - e2[-2];
2472 k01_21 = e0[-3] - e2[-3];
2475 e2[-2] = (k00_20)*
A[0] - (k01_21) *
A[1];
2476 e2[-3] = (k01_21)*
A[0] + (k00_20) *
A[1];
2480 k00_20 = e0[-4] - e2[-4];
2481 k01_21 = e0[-5] - e2[-5];
2484 e2[-4] = (k00_20)*
A[0] - (k01_21) *
A[1];
2485 e2[-5] = (k01_21)*
A[0] + (k00_20) *
A[1];
2489 k00_20 = e0[-6] - e2[-6];
2490 k01_21 = e0[-7] - e2[-7];
2493 e2[-6] = (k00_20)*
A[0] - (k01_21) *
A[1];
2494 e2[-7] = (k01_21)*
A[0] + (k00_20) *
A[1];
2503 static void imdct_step3_inner_s_loop(
int n,
float *e,
int i_off,
int k_off,
float *
A,
int a_off,
int k0)
2508 float A2 =
A[0+a_off];
2509 float A3 =
A[0+a_off+1];
2510 float A4 =
A[0+a_off*2+0];
2511 float A5 =
A[0+a_off*2+1];
2512 float A6 =
A[0+a_off*3+0];
2513 float A7 =
A[0+a_off*3+1];
2517 float *ee0 = e +i_off;
2518 float *ee2 = ee0+k_off;
2520 for (i=n; i > 0; --i) {
2521 k00 = ee0[ 0] - ee2[ 0];
2522 k11 = ee0[-1] - ee2[-1];
2523 ee0[ 0] = ee0[ 0] + ee2[ 0];
2524 ee0[-1] = ee0[-1] + ee2[-1];
2525 ee2[ 0] = (k00) * A0 - (k11) * A1;
2526 ee2[-1] = (k11) * A0 + (k00) * A1;
2528 k00 = ee0[-2] - ee2[-2];
2529 k11 = ee0[-3] - ee2[-3];
2530 ee0[-2] = ee0[-2] + ee2[-2];
2531 ee0[-3] = ee0[-3] + ee2[-3];
2532 ee2[-2] = (k00) * A2 - (k11) * A3;
2533 ee2[-3] = (k11) * A2 + (k00) * A3;
2535 k00 = ee0[-4] - ee2[-4];
2536 k11 = ee0[-5] - ee2[-5];
2537 ee0[-4] = ee0[-4] + ee2[-4];
2538 ee0[-5] = ee0[-5] + ee2[-5];
2539 ee2[-4] = (k00) * A4 - (k11) * A5;
2540 ee2[-5] = (k11) * A4 + (k00) * A5;
2542 k00 = ee0[-6] - ee2[-6];
2543 k11 = ee0[-7] - ee2[-7];
2544 ee0[-6] = ee0[-6] + ee2[-6];
2545 ee0[-7] = ee0[-7] + ee2[-7];
2546 ee2[-6] = (k00) * A6 - (k11) * A7;
2547 ee2[-7] = (k11) * A6 + (k00) * A7;
2556 float k00,k11,k22,k33;
2559 k00 = z[ 0] - z[-4];
2562 k22 = z[-2] - z[-6];
2569 k33 = z[-3] - z[-7];
2576 k11 = z[-1] - z[-5];
2586 static void imdct_step3_inner_s_loop_ld654(
int n,
float *e,
int i_off,
float *
A,
int base_n)
2588 int a_off = base_n >> 3;
2589 float A2 =
A[0+a_off];
2590 float *z = e + i_off;
2591 float *base = z - 16 * n;
2597 k00 = z[-0] - z[ -8];
2598 k11 = z[-1] - z[ -9];
2599 l00 = z[-2] - z[-10];
2600 l11 = z[-3] - z[-11];
2601 z[ -0] = z[-0] + z[ -8];
2602 z[ -1] = z[-1] + z[ -9];
2603 z[ -2] = z[-2] + z[-10];
2604 z[ -3] = z[-3] + z[-11];
2607 z[-10] = (l00+l11) * A2;
2608 z[-11] = (l11-l00) * A2;
2610 k00 = z[ -4] - z[-12];
2611 k11 = z[ -5] - z[-13];
2612 l00 = z[ -6] - z[-14];
2613 l11 = z[ -7] - z[-15];
2614 z[ -4] = z[ -4] + z[-12];
2615 z[ -5] = z[ -5] + z[-13];
2616 z[ -6] = z[ -6] + z[-14];
2617 z[ -7] = z[ -7] + z[-15];
2620 z[-14] = (l11-l00) * A2;
2621 z[-15] = (l00+l11) * -A2;
2629 static void inverse_mdct(
float *buffer,
int n,
vorb *
f,
int blocktype)
2631 int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l;
2635 float *buf2 = (
float *)
temp_alloc(
f, n2 *
sizeof(*buf2));
2636 float *u=NULL,*v=NULL;
2638 float *
A =
f->A[blocktype];
2660 float *d,*e, *AA, *e_stop;
2664 e_stop = &buffer[n2];
2665 while (e != e_stop) {
2666 d[1] = (e[0] * AA[0] - e[2]*AA[1]);
2667 d[0] = (e[0] * AA[1] + e[2]*AA[0]);
2675 d[1] = (-e[2] * AA[0] - -e[0]*AA[1]);
2676 d[0] = (-e[2] * AA[1] + -e[0]*AA[0]);
2694 float *AA = &
A[n2-8];
2695 float *d0,*d1, *e0, *e1;
2704 float v40_20, v41_21;
2706 v41_21 = e0[1] - e1[1];
2707 v40_20 = e0[0] - e1[0];
2708 d0[1] = e0[1] + e1[1];
2709 d0[0] = e0[0] + e1[0];
2710 d1[1] = v41_21*AA[4] - v40_20*AA[5];
2711 d1[0] = v40_20*AA[4] + v41_21*AA[5];
2713 v41_21 = e0[3] - e1[3];
2714 v40_20 = e0[2] - e1[2];
2715 d0[3] = e0[3] + e1[3];
2716 d0[2] = e0[2] + e1[2];
2717 d1[3] = v41_21*AA[0] - v40_20*AA[1];
2718 d1[2] = v40_20*AA[0] + v41_21*AA[1];
2740 imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*0, -(n >> 3),
A);
2741 imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*1, -(n >> 3),
A);
2744 imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*0, -(n >> 4),
A, 16);
2745 imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*1, -(n >> 4),
A, 16);
2746 imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*2, -(n >> 4),
A, 16);
2747 imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*3, -(n >> 4),
A, 16);
2750 for (; l < (ld-3)>>1; ++l) {
2751 int k0 = n >> (l+2), k0_2 = k0>>1;
2752 int lim = 1 << (l+1);
2754 for (i=0; i < lim; ++i)
2755 imdct_step3_inner_r_loop(n >> (l+4), u, n2-1 - k0*i, -k0_2,
A, 1 << (l+3));
2758 for (; l < ld-6; ++l) {
2759 int k0 = n >> (l+2), k1 = 1 << (l+3), k0_2 = k0>>1;
2760 int rlim = n >> (l+6), r;
2761 int lim = 1 << (l+1);
2765 for (r=rlim; r > 0; --r) {
2766 imdct_step3_inner_s_loop(lim, u, i_off, -k0_2, A0, k1, k0);
2777 imdct_step3_inner_s_loop_ld654(n >> 5, u, n2-1,
A, n);
2784 uint16 *bitrev =
f->bit_reverse[blocktype];
2790 float *d0 = &v[n4-4];
2791 float *d1 = &v[n2-4];
2821 float *
C =
f->C[blocktype];
2828 float a02,a11,b0,b1,b2,b3;
2833 b0 =
C[1]*a02 +
C[0]*a11;
2834 b1 =
C[1]*a11 -
C[0]*a02;
2847 b0 =
C[3]*a02 +
C[2]*a11;
2848 b1 =
C[3]*a11 -
C[2]*a02;
2875 float *d0,*d1,*d2,*d3;
2877 float *
B =
f->B[blocktype] + n2 - 8;
2878 float *e = buf2 + n2 - 8;
2886 p3 = e[6]*
B[7] - e[7]*
B[6];
2887 p2 = -e[6]*
B[6] - e[7]*
B[7];
2894 p1 = e[4]*
B[5] - e[5]*
B[4];
2895 p0 = -e[4]*
B[4] - e[5]*
B[5];
2902 p3 = e[2]*
B[3] - e[3]*
B[2];
2903 p2 = -e[2]*
B[2] - e[3]*
B[3];
2910 p1 = e[0]*
B[1] - e[1]*
B[0];
2911 p0 = -e[0]*
B[0] - e[1]*
B[1];
2933 void inverse_mdct_naive(
float *buffer,
int n)
2936 float A[1 << 12],
B[1 << 12],
C[1 << 11];
2937 int i,k,k2,k4, n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l;
2938 int n3_4 = n - n4, ld;
2941 float u[1 << 13], X[1 << 13], v[1 << 13], w[1 << 13];
2944 for (k=k2=0; k < n4; ++k,k2+=2) {
2945 A[k2 ] = (float) cos(4*k*
M_PI/n);
2946 A[k2+1] = (float) -sin(4*k*
M_PI/n);
2947 B[k2 ] = (float) cos((k2+1)*
M_PI/n/2);
2948 B[k2+1] = (float) sin((k2+1)*
M_PI/n/2);
2950 for (k=k2=0; k < n8; ++k,k2+=2) {
2951 C[k2 ] = (float) cos(2*(k2+1)*
M_PI/n);
2952 C[k2+1] = (float) -sin(2*(k2+1)*
M_PI/n);
2963 for (k=0; k < n2; ++k) u[k] = buffer[k];
2964 for ( ; k < n ; ++k) u[k] = -buffer[n - k - 1];
2967 for (k=k2=k4=0; k < n4; k+=1, k2+=2, k4+=4) {
2968 v[n-k4-1] = (u[k4] - u[n-k4-1]) *
A[k2] - (u[k4+2] - u[n-k4-3])*
A[k2+1];
2969 v[n-k4-3] = (u[k4] - u[n-k4-1]) *
A[k2+1] + (u[k4+2] - u[n-k4-3])*
A[k2];
2972 for (k=k4=0; k < n8; k+=1, k4+=4) {
2973 w[n2+3+k4] = v[n2+3+k4] + v[k4+3];
2974 w[n2+1+k4] = v[n2+1+k4] + v[k4+1];
2975 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];
2976 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];
2980 for (l=0; l < ld-3; ++l) {
2981 int k0 = n >> (l+2), k1 = 1 << (l+3);
2982 int rlim = n >> (l+4), r4, r;
2983 int s2lim = 1 << (l+2), s2;
2984 for (r=r4=0; r < rlim; r4+=4,++r) {
2985 for (s2=0; s2 < s2lim; s2+=2) {
2986 u[n-1-k0*s2-r4] = w[n-1-k0*s2-r4] + w[n-1-k0*(s2+1)-r4];
2987 u[n-3-k0*s2-r4] = w[n-3-k0*s2-r4] + w[n-3-k0*(s2+1)-r4];
2988 u[n-1-k0*(s2+1)-r4] = (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) *
A[r*k1]
2989 - (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) *
A[r*k1+1];
2990 u[n-3-k0*(s2+1)-r4] = (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) *
A[r*k1]
2991 + (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) *
A[r*k1+1];
2996 memcpy(w, u,
sizeof(u));
3001 for (i=0; i < n8; ++i) {
3013 int i8 = i << 3, j8 = j << 3;
3014 v[j8+1] = u[i8+1], v[i8+1] = u[j8 + 1];
3015 v[j8+3] = u[i8+3], v[i8+3] = u[j8 + 3];
3016 v[j8+5] = u[i8+5], v[i8+5] = u[j8 + 5];
3017 v[j8+7] = u[i8+7], v[i8+7] = u[j8 + 7];
3021 for (k=0; k < n2; ++k) {
3025 for (k=k2=k4=0; k < n8; ++k, k2 += 2, k4 += 4) {
3027 u[n-2-k2] = w[k4+1];
3028 u[n3_4 - 1 - k2] = w[k4+2];
3029 u[n3_4 - 2 - k2] = w[k4+3];
3032 for (k=k2=0; k < n8; ++k, k2 += 2) {
3033 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;
3034 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;
3035 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;
3036 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;
3039 for (k=k2=0; k < n4; ++k,k2 += 2) {
3040 X[k] = v[k2+n2]*
B[k2 ] + v[k2+1+n2]*
B[k2+1];
3041 X[n2-1-k] = v[k2+n2]*
B[k2+1] - v[k2+1+n2]*
B[k2 ];
3053 for (i=0; i < n4 ; ++i) buffer[i] = s * X[i+n4];
3054 for ( ; i < n3_4; ++i) buffer[i] = -s * X[n3_4 - i - 1];
3055 for ( ; i < n ; ++i) buffer[i] = -s * X[i - n3_4];
3059 static float *get_window(
vorb *
f,
int len)
3062 if (len ==
f->blocksize_0)
return f->window[0];
3063 if (len ==
f->blocksize_1)
return f->window[1];
3067 #ifndef STB_VORBIS_NO_DEFER_FLOOR
3075 int s = map->
chan[i].
mux, floor;
3077 if (
f->floor_types[floor] == 0) {
3080 Floor1 *g = &
f->floor_config[floor].floor1;
3083 for (q=1; q < g->
values; ++q) {
3085 #ifndef STB_VORBIS_NO_DEFER_FLOOR
3093 int hx = g->
Xlist[j];
3095 draw_line(target, lx,ly, hx,hy, n2);
3102 for (j=lx; j < n2; ++j)
3103 LINE_OP(target[j], inverse_db_table[ly]);
3124 static int vorbis_decode_initial(
vorb *
f,
int *p_left_start,
int *p_left_end,
int *p_right_start,
int *p_right_end,
int *mode)
3127 int i, n, prev, next, window_center;
3128 f->channel_buffer_start =
f->channel_buffer_end = 0;
3131 if (
f->eof)
return FALSE;
3132 if (!maybe_start_packet(
f))
3135 if (get_bits(
f,1) != 0) {
3138 while (
EOP != get8_packet(
f));
3142 if (
f->alloc.alloc_buffer)
3143 assert(
f->alloc.alloc_buffer_length_in_bytes ==
f->temp_offset);
3145 i = get_bits(
f, ilog(
f->mode_count-1));
3147 if (i >=
f->mode_count)
return FALSE;
3149 m =
f->mode_config + i;
3152 prev = get_bits(
f,1);
3153 next = get_bits(
f,1);
3161 window_center = n >> 1;
3163 *p_left_start = (n -
f->blocksize_0) >> 2;
3164 *p_left_end = (n +
f->blocksize_0) >> 2;
3167 *p_left_end = window_center;
3170 *p_right_start = (n*3 -
f->blocksize_0) >> 2;
3171 *p_right_end = (n*3 +
f->blocksize_0) >> 2;
3173 *p_right_start = window_center;
3180 static int vorbis_decode_packet_rest(
vorb *
f,
int *len,
Mode *m,
int left_start,
int left_end,
int right_start,
int right_end,
int *p_left)
3184 int zero_channel[256];
3185 int really_zero_channel[256];
3198 for (i=0; i <
f->channels; ++i) {
3199 int s = map->
chan[i].
mux, floor;
3200 zero_channel[i] =
FALSE;
3202 if (
f->floor_types[floor] == 0) {
3205 Floor1 *g = &
f->floor_config[floor].floor1;
3206 if (get_bits(
f, 1)) {
3208 uint8 step2_flag[256];
3209 static int range_list[4] = { 256, 128, 86, 64 };
3213 finalY[0] = get_bits(
f, ilog(range)-1);
3214 finalY[1] = get_bits(
f, ilog(range)-1);
3219 int csub = (1 << cbits)-1;
3225 for (k=0; k < cdim; ++k) {
3227 cval = cval >> cbits;
3238 step2_flag[0] = step2_flag[1] = 1;
3239 for (j=2; j < g->
values; ++j) {
3240 int low, high, pred, highroom, lowroom, room, val;
3246 highroom = range - pred;
3248 if (highroom < lowroom)
3249 room = highroom * 2;
3253 step2_flag[low] = step2_flag[high] = 1;
3256 if (highroom > lowroom)
3257 finalY[j] = val - lowroom + pred;
3259 finalY[j] = pred - val + highroom - 1;
3262 finalY[j] = pred - ((val+1)>>1);
3264 finalY[j] = pred + (val>>1);
3271 #ifdef STB_VORBIS_NO_DEFER_FLOOR
3272 do_floor(
f, map, i, n,
f->floor_buffers[i],
finalY, step2_flag);
3275 for (j=0; j < g->
values; ++j) {
3282 zero_channel[i] =
TRUE;
3292 if (
f->alloc.alloc_buffer)
3293 assert(
f->alloc.alloc_buffer_length_in_bytes ==
f->temp_offset);
3296 memcpy(really_zero_channel, zero_channel,
sizeof(really_zero_channel[0]) *
f->channels);
3304 for (i=0; i < map->
submaps; ++i) {
3307 uint8 do_not_decode[256];
3309 for (j=0; j <
f->channels; ++j) {
3311 if (zero_channel[j]) {
3312 do_not_decode[ch] =
TRUE;
3313 residue_buffers[ch] = NULL;
3315 do_not_decode[ch] =
FALSE;
3316 residue_buffers[ch] =
f->channel_buffers[j];
3322 decode_residue(
f, residue_buffers, ch, n2, r, do_not_decode);
3325 if (
f->alloc.alloc_buffer)
3326 assert(
f->alloc.alloc_buffer_length_in_bytes ==
f->temp_offset);
3333 float *a =
f->channel_buffers[map->
chan[i].
angle ];
3334 for (j=0; j < n2; ++j) {
3338 m2 = m[j], a2 = m[j] - a[j];
3340 a2 = m[j], m2 = m[j] + a[j];
3343 m2 = m[j], a2 = m[j] + a[j];
3345 a2 = m[j], m2 = m[j] - a[j];
3353 #ifndef STB_VORBIS_NO_DEFER_FLOOR
3354 for (i=0; i <
f->channels; ++i) {
3355 if (really_zero_channel[i]) {
3356 memset(
f->channel_buffers[i], 0,
sizeof(*
f->channel_buffers[i]) * n2);
3358 do_floor(
f, map, i, n,
f->channel_buffers[i],
f->finalY[i], NULL);
3362 for (i=0; i <
f->channels; ++i) {
3363 if (really_zero_channel[i]) {
3364 memset(
f->channel_buffers[i], 0,
sizeof(*
f->channel_buffers[i]) * n2);
3366 for (j=0; j < n2; ++j)
3367 f->channel_buffers[i][j] *=
f->floor_buffers[i][j];
3374 for (i=0; i <
f->channels; ++i)
3375 inverse_mdct(
f->channel_buffers[i], n,
f, m->blockflag);
3382 if (
f->first_decode) {
3387 f->current_loc = 0u - n2;
3390 f->discard_samples_deferred = n - right_end;
3391 f->current_loc_valid =
TRUE;
3393 }
else if (
f->discard_samples_deferred) {
3394 if (
f->discard_samples_deferred >= right_start - left_start) {
3395 f->discard_samples_deferred -= (right_start - left_start);
3396 left_start = right_start;
3397 *p_left = left_start;
3399 left_start +=
f->discard_samples_deferred;
3400 *p_left = left_start;
3401 f->discard_samples_deferred = 0;
3403 }
else if (
f->previous_length == 0 &&
f->current_loc_valid) {
3413 if (
f->last_seg_which ==
f->end_seg_with_known_loc) {
3416 uint32 current_end =
f->known_loc_for_packet;
3418 if (current_end < f->
current_loc + (right_end-left_start)) {
3423 *len = current_end -
f->current_loc;
3426 if (*len > right_end) *len = right_end;
3427 f->current_loc += *len;
3435 f->current_loc =
f->known_loc_for_packet - (n2-left_start);
3436 f->current_loc_valid =
TRUE;
3438 if (
f->current_loc_valid)
3439 f->current_loc += (right_start - left_start);
3441 if (
f->alloc.alloc_buffer)
3442 assert(
f->alloc.alloc_buffer_length_in_bytes ==
f->temp_offset);
3449 static int vorbis_decode_packet(
vorb *
f,
int *len,
int *p_left,
int *p_right)
3451 int mode, left_end, right_end;
3452 if (!vorbis_decode_initial(
f, p_left, &left_end, p_right, &right_end, &mode))
return 0;
3453 return vorbis_decode_packet_rest(
f, len,
f->mode_config + mode, *p_left, left_end, *p_right, right_end, p_left);
3456 static int vorbis_finish_frame(
stb_vorbis *
f,
int len,
int left,
int right)
3468 if (
f->previous_length) {
3469 int i,j, n =
f->previous_length;
3470 float *w = get_window(
f, n);
3471 if (w == NULL)
return 0;
3472 for (i=0; i <
f->channels; ++i) {
3473 for (j=0; j < n; ++j)
3474 f->channel_buffers[i][left+j] =
3475 f->channel_buffers[i][left+j]*w[ j] +
3476 f->previous_window[i][ j]*w[n-1-j];
3480 prev =
f->previous_length;
3483 f->previous_length = len - right;
3491 for (i=0; i <
f->channels; ++i)
3492 for (j=0; right+j < len; ++j)
3493 f->previous_window[i][j] =
f->channel_buffers[i][right+j];
3502 if (len < right) right = len;
3504 f->samples_output += right-left;
3506 return right - left;
3511 int len, right, left, res;
3512 res = vorbis_decode_packet(
f, &len, &left, &right);
3514 vorbis_finish_frame(
f, len, left, right);
3518 #ifndef STB_VORBIS_NO_PUSHDATA_API
3529 int s =
f->next_seg, first =
TRUE;
3533 for (; s <
f->segment_count; ++s) {
3534 p +=
f->segments[s];
3535 if (
f->segments[s] < 255)
3539 if (s ==
f->segment_count)
3554 if (
f->previous_length)
3566 for (s=0; s < n; ++s) {
3580 static int start_decoder(
vorb *
f)
3582 uint8 header[6], x,y;
3583 int len,i,j,k, max_submaps = 0;
3584 int longest_floorlist=0;
3587 f->first_decode =
TRUE;
3589 if (!start_page(
f))
return FALSE;
3596 if (
f->segments[0] != 30) {
3598 if (
f->segments[0] == 64 &&
3599 getn(
f, header, 6) &&
3630 f->blocksize_0 = 1 << log0;
3631 f->blocksize_1 = 1 << log1;
3642 if (!start_page(
f))
return FALSE;
3644 if (!start_packet(
f))
return FALSE;
3646 if (!next_segment(
f))
return FALSE;
3649 for (i=0; i < 6; ++i) header[i] = get8_packet(
f);
3652 len = get32_packet(
f);
3653 f->vendor = (
char*)setup_malloc(
f,
sizeof(
char) * (len+1));
3655 for(i=0; i < len; ++i) {
3656 f->vendor[i] = get8_packet(
f);
3658 f->vendor[len] = (char)
'\0';
3660 f->comment_list_length = get32_packet(
f);
3661 f->comment_list = NULL;
3662 if (
f->comment_list_length > 0)
3664 f->comment_list = (
char**) setup_malloc(
f,
sizeof(
char*) * (
f->comment_list_length));
3668 for(i=0; i <
f->comment_list_length; ++i) {
3669 len = get32_packet(
f);
3670 f->comment_list[i] = (
char*)setup_malloc(
f,
sizeof(
char) * (len+1));
3673 for(j=0; j < len; ++j) {
3674 f->comment_list[i][j] = get8_packet(
f);
3676 f->comment_list[i][len] = (char)
'\0';
3684 skip(
f,
f->bytes_in_seg);
3685 f->bytes_in_seg = 0;
3688 len = next_segment(
f);
3690 f->bytes_in_seg = 0;
3694 if (!start_packet(
f))
return FALSE;
3696 #ifndef STB_VORBIS_NO_PUSHDATA_API
3698 if (!is_whole_packet_present(
f)) {
3710 for (i=0; i < 6; ++i) header[i] = get8_packet(
f);
3715 f->codebook_count = get_bits(
f,8) + 1;
3716 f->codebooks = (
Codebook *) setup_malloc(
f,
sizeof(*
f->codebooks) *
f->codebook_count);
3718 memset(
f->codebooks, 0,
sizeof(*
f->codebooks) *
f->codebook_count);
3719 for (i=0; i <
f->codebook_count; ++i) {
3721 int ordered, sorted_count;
3733 c->
entries = (get_bits(
f, 8)<<16) + (y<<8) + x;
3734 ordered = get_bits(
f,1);
3735 c->
sparse = ordered ? 0 : get_bits(
f,1);
3747 int current_entry = 0;
3748 int current_length = get_bits(
f,5) + 1;
3749 while (current_entry < c->entries) {
3750 int limit = c->
entries - current_entry;
3751 int n = get_bits(
f, ilog(limit));
3754 memset(lengths + current_entry, current_length, n);
3759 for (j=0; j < c->
entries; ++j) {
3760 int present = c->
sparse ? get_bits(
f,1) : 1;
3762 lengths[j] = get_bits(
f, 5) + 1;
3764 if (lengths[j] == 32)
3774 if (c->
entries > (
int)
f->setup_temp_memory_required)
3775 f->setup_temp_memory_required = c->
entries;
3780 setup_temp_free(
f, lengths, c->
entries);
3787 sorted_count = total;
3790 #ifndef STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH
3791 for (j=0; j < c->
entries; ++j)
3815 if (size >
f->setup_temp_memory_required)
3816 f->setup_temp_memory_required = size;
3819 if (!compute_codewords(c, lengths, c->
entries, values)) {
3820 if (c->
sparse) setup_temp_free(
f, values, 0);
3834 compute_sorted_huffman(c, lengths, values);
3840 setup_temp_free(
f, lengths, c->
entries);
3844 compute_accelerated_huffman(c);
3871 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
3873 int len, sparse = c->
sparse;
3883 for (j=0; j < len; ++j) {
3917 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
3929 x = get_bits(
f, 6) + 1;
3930 for (i=0; i < x; ++i) {
3936 f->floor_count = get_bits(
f, 6)+1;
3937 f->floor_config = (
Floor *) setup_malloc(
f,
f->floor_count *
sizeof(*
f->floor_config));
3939 for (i=0; i <
f->floor_count; ++i) {
3940 f->floor_types[i] = get_bits(
f, 16);
3942 if (
f->floor_types[i] == 0) {
3943 Floor0 *g = &
f->floor_config[i].floor0;
3944 g->
order = get_bits(
f,8);
3945 g->
rate = get_bits(
f,16);
3955 Floor1 *g = &
f->floor_config[i].floor1;
3963 for (j=0; j <= max_class; ++j) {
3988 for (j=0; j < g->
values; ++j) {
3992 qsort(p, g->
values,
sizeof(p[0]), point_compare);
3993 for (j=0; j < g->
values-1; ++j)
3994 if (p[j].x == p[j+1].x)
3996 for (j=0; j < g->
values; ++j)
3999 for (j=2; j < g->
values; ++j) {
4001 neighbors(g->
Xlist, j, &low,&hi);
4006 if (g->
values > longest_floorlist)
4007 longest_floorlist = g->
values;
4012 f->residue_count = get_bits(
f, 6)+1;
4013 f->residue_config = (
Residue *) setup_malloc(
f,
f->residue_count *
sizeof(
f->residue_config[0]));
4015 memset(
f->residue_config, 0,
f->residue_count *
sizeof(
f->residue_config[0]));
4016 for (i=0; i <
f->residue_count; ++i) {
4017 uint8 residue_cascade[64];
4019 f->residue_types[i] = get_bits(
f, 16);
4021 r->
begin = get_bits(
f, 24);
4022 r->
end = get_bits(
f, 24);
4030 uint8 low_bits=get_bits(
f,3);
4032 high_bits = get_bits(
f,5);
4033 residue_cascade[j] = high_bits*8 + low_bits;
4038 for (k=0; k < 8; ++k) {
4039 if (residue_cascade[j] & (1 << k)) {
4052 for (j=0; j <
f->codebooks[r->
classbook].entries; ++j) {
4053 int classwords =
f->codebooks[r->
classbook].dimensions;
4057 for (k=classwords-1; k >= 0; --k) {
4064 f->mapping_count = get_bits(
f,6)+1;
4065 f->mapping = (
Mapping *) setup_malloc(
f,
f->mapping_count *
sizeof(*
f->mapping));
4067 memset(
f->mapping, 0,
f->mapping_count *
sizeof(*
f->mapping));
4068 for (i=0; i <
f->mapping_count; ++i) {
4070 int mapping_type = get_bits(
f,16);
4080 if (get_bits(
f,1)) {
4085 m->
chan[k].
angle = get_bits(
f, ilog(
f->channels-1));
4096 for (j=0; j <
f->channels; ++j) {
4102 for (j=0; j <
f->channels; ++j)
4105 for (j=0; j < m->
submaps; ++j) {
4115 f->mode_count = get_bits(
f, 6)+1;
4116 for (i=0; i <
f->mode_count; ++i) {
4117 Mode *m =
f->mode_config+i;
4129 f->previous_length = 0;
4131 for (i=0; i <
f->channels; ++i) {
4132 f->channel_buffers[i] = (
float *) setup_malloc(
f,
sizeof(
float) *
f->blocksize_1);
4133 f->previous_window[i] = (
float *) setup_malloc(
f,
sizeof(
float) *
f->blocksize_1/2);
4134 f->finalY[i] = (
int16 *) setup_malloc(
f,
sizeof(
int16) * longest_floorlist);
4135 if (
f->channel_buffers[i] == NULL ||
f->previous_window[i] == NULL ||
f->finalY[i] == NULL)
return error(
f,
VORBIS_outofmem);
4136 memset(
f->channel_buffers[i], 0,
sizeof(
float) *
f->blocksize_1);
4137 #ifdef STB_VORBIS_NO_DEFER_FLOOR
4138 f->floor_buffers[i] = (
float *) setup_malloc(
f,
sizeof(
float) *
f->blocksize_1/2);
4143 if (!init_blocksize(
f, 0,
f->blocksize_0))
return FALSE;
4144 if (!init_blocksize(
f, 1,
f->blocksize_1))
return FALSE;
4145 f->blocksize[0] =
f->blocksize_0;
4146 f->blocksize[1] =
f->blocksize_1;
4148 #ifdef STB_VORBIS_DIVIDE_TABLE
4149 if (integer_divide_table[1][1]==0)
4150 for (i=0; i < DIVTAB_NUMER; ++i)
4151 for (j=1; j < DIVTAB_DENOM; ++j)
4152 integer_divide_table[i][j] = i / j;
4159 uint32 imdct_mem = (
f->blocksize_1 *
sizeof(float) >> 1);
4161 int i,max_part_read=0;
4162 for (i=0; i <
f->residue_count; ++i) {
4163 Residue *r =
f->residue_config + i;
4164 unsigned int actual_size =
f->blocksize_1 / 2;
4165 unsigned int limit_r_begin = r->
begin < actual_size ? r->
begin : actual_size;
4166 unsigned int limit_r_end = r->
end < actual_size ? r->
end : actual_size;
4167 int n_read = limit_r_end - limit_r_begin;
4169 if (part_read > max_part_read)
4170 max_part_read = part_read;
4172 #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
4173 classify_mem =
f->channels * (
sizeof(
void*) + max_part_read *
sizeof(
uint8 *));
4175 classify_mem =
f->channels * (
sizeof(
void*) + max_part_read *
sizeof(
int *));
4180 f->temp_memory_required = classify_mem;
4181 if (imdct_mem >
f->temp_memory_required)
4182 f->temp_memory_required = imdct_mem;
4186 if (
f->alloc.alloc_buffer) {
4187 assert(
f->temp_offset ==
f->alloc.alloc_buffer_length_in_bytes);
4189 if (
f->setup_offset +
sizeof(*
f) +
f->temp_memory_required > (
unsigned)
f->temp_offset)
4199 if (
f->next_seg == -1) {
4202 f->first_audio_page_offset = 0;
4212 setup_free(p, p->
vendor);
4254 #ifdef STB_VORBIS_NO_DEFER_FLOOR
4255 setup_free(p, p->floor_buffers[i]);
4257 setup_free(p, p->
finalY[i]);
4259 for (i=0; i < 2; ++i) {
4260 setup_free(p, p->
A[i]);
4261 setup_free(p, p->
B[i]);
4262 setup_free(p, p->
C[i]);
4263 setup_free(p, p->
window[i]);
4266 #ifndef STB_VORBIS_NO_STDIO
4273 if (p == NULL)
return;
4280 memset(p, 0,
sizeof(*p));
4291 #ifndef STB_VORBIS_NO_STDIO
4299 if (
f->current_loc_valid)
4300 return f->current_loc;
4339 #ifndef STB_VORBIS_NO_PUSHDATA_API
4343 f->previous_length = 0;
4344 f->page_crc_tests = 0;
4345 f->discard_samples_deferred = 0;
4346 f->current_loc_valid =
FALSE;
4348 f->samples_output = 0;
4349 f->channel_buffer_start = 0;
4350 f->channel_buffer_end = 0;
4353 static int vorbis_search_for_page_pushdata(
vorb *
f,
uint8 *data,
int data_len)
4356 for (i=0; i <
f->page_crc_tests; ++i)
4357 f->scan[i].bytes_done = 0;
4362 if (data_len < 4)
return 0;
4365 for (i=0; i < data_len; ++i) {
4366 if (data[i] == 0x4f) {
4367 if (0==memcmp(data+i, ogg_page_header, 4)) {
4371 if (i+26 >= data_len || i+27+data[i+26] >= data_len) {
4378 len = 27 + data[i+26];
4379 for (j=0; j < data[i+26]; ++j)
4380 len += data[i+27+j];
4383 for (j=0; j < 22; ++j)
4384 crc = crc32_update(crc, data[i+j]);
4386 for ( ; j < 26; ++j)
4387 crc = crc32_update(crc, 0);
4389 n =
f->page_crc_tests++;
4390 f->scan[n].bytes_left = len-j;
4391 f->scan[n].crc_so_far = crc;
4392 f->scan[n].goal_crc = data[i+22] + (data[i+23] << 8) + (data[i+24]<<16) + (data[i+25]<<24);
4395 if (data[i+27+data[i+26]-1] == 255)
4396 f->scan[n].sample_loc = ~0;
4398 f->scan[n].sample_loc = data[i+6] + (data[i+7] << 8) + (data[i+ 8]<<16) + (data[i+ 9]<<24);
4399 f->scan[n].bytes_done = i+j;
4408 for (i=0; i <
f->page_crc_tests;) {
4411 int n =
f->scan[i].bytes_done;
4412 int m =
f->scan[i].bytes_left;
4413 if (m > data_len - n) m = data_len - n;
4415 crc =
f->scan[i].crc_so_far;
4416 for (j=0; j < m; ++j)
4417 crc = crc32_update(crc, data[n+j]);
4418 f->scan[i].bytes_left -= m;
4419 f->scan[i].crc_so_far = crc;
4420 if (
f->scan[i].bytes_left == 0) {
4422 if (
f->scan[i].crc_so_far ==
f->scan[i].goal_crc) {
4425 f->page_crc_tests = -1;
4426 f->previous_length = 0;
4428 f->current_loc =
f->scan[i].sample_loc;
4430 f->current_loc_valid =
f->current_loc != ~0U;
4434 f->scan[i] =
f->scan[--
f->page_crc_tests];
4446 const uint8 *data,
int data_len,
4457 if (
f->page_crc_tests >= 0) {
4459 return vorbis_search_for_page_pushdata(
f, (
uint8 *) data, data_len);
4462 f->stream = (
uint8 *) data;
4463 f->stream_end = (
uint8 *) data + data_len;
4467 if (!is_whole_packet_present(
f)) {
4472 if (!vorbis_decode_packet(
f, &len, &left, &right)) {
4478 while (get8_packet(
f) !=
EOP)
4481 return (
int) (
f->stream - data);
4484 if (
f->previous_length == 0) {
4488 while (get8_packet(
f) !=
EOP)
4491 return (
int) (
f->stream - data);
4504 len = vorbis_finish_frame(
f, len, left, right);
4505 for (i=0; i <
f->channels; ++i)
4506 f->outputs[i] =
f->channel_buffers[i] + left;
4510 *output =
f->outputs;
4511 return (
int) (
f->stream - data);
4515 const unsigned char *data,
int data_len,
4520 vorbis_init(&p,
alloc);
4524 if (!start_decoder(&p)) {
4532 f = vorbis_alloc(&p);
4535 *data_used = (int) (
f->stream - data);
4547 #ifndef STB_VORBIS_NO_PUSHDATA_API
4548 if (
f->push_mode)
return 0;
4550 if (
USE_MEMORY(
f))
return (
unsigned int) (
f->stream -
f->stream_start);
4551 #ifndef STB_VORBIS_NO_STDIO
4552 return (
unsigned int) (ftell(
f->f) -
f->f_start);
4556 #ifndef STB_VORBIS_NO_PULLDATA_API
4565 if (
f->eof)
return 0;
4571 if (retry_loc - 25 >
f->stream_len)
4574 for (i=1; i < 4; ++i)
4575 if (get8(
f) != ogg_page_header[i])
4577 if (
f->eof)
return 0;
4580 uint32 i, crc, goal, len;
4581 for (i=0; i < 4; ++i)
4582 header[i] = ogg_page_header[i];
4584 header[i] = get8(
f);
4585 if (
f->eof)
return 0;
4586 if (header[4] != 0)
goto invalid;
4587 goal = header[22] + (header[23] << 8) + (header[24]<<16) + ((
uint32)header[25]<<24);
4588 for (i=22; i < 26; ++i)
4591 for (i=0; i < 27; ++i)
4592 crc = crc32_update(crc, header[i]);
4594 for (i=0; i < header[26]; ++i) {
4596 crc = crc32_update(crc, s);
4599 if (len &&
f->eof)
return 0;
4600 for (i=0; i < len; ++i)
4601 crc = crc32_update(crc, get8(
f));
4615 if (header[5] & 0x04)
4620 set_file_offset(
f, retry_loc-1);
4626 set_file_offset(
f, retry_loc);
4632 #define SAMPLE_unknown 0xffffffff
4645 uint8 header[27], lacing[255];
4652 getn(
f, header, 27);
4653 if (header[0] !=
'O' || header[1] !=
'g' || header[2] !=
'g' || header[3] !=
'S')
4655 getn(
f, lacing, header[26]);
4659 for (i=0; i < header[26]; ++i)
4666 z->
last_decoded_sample = header[6] + (header[7] << 8) + (header[8] << 16) + (header[9] << 24);
4675 static int go_to_page_before(
stb_vorbis *
f,
unsigned int limit_offset)
4677 unsigned int previous_safe, end;
4680 if (limit_offset >= 65536 && limit_offset-65536 >=
f->first_audio_page_offset)
4681 previous_safe = limit_offset - 65536;
4683 previous_safe =
f->first_audio_page_offset;
4685 set_file_offset(
f, previous_safe);
4687 while (vorbis_find_page(
f, &end, NULL)) {
4690 set_file_offset(
f, end);
4703 int i, start_seg_with_known_loc, end_pos, page_start;
4704 uint32 delta, stream_length, padding, last_sample_limit;
4705 double offset = 0.0, bytes_per_sample = 0.0;
4716 padding = ((
f->blocksize_1 -
f->blocksize_0) >> 2);
4717 if (sample_number < padding)
4718 last_sample_limit = 0;
4720 last_sample_limit = sample_number - padding;
4726 if (!get_seek_page_info(
f, &left))
goto error;
4735 if (
f->current_loc > sample_number)
4746 if (delta <= 65536) {
4760 if (error < 0 && error > -8000)
error = -8000;
4761 offset +=
error * 2;
4770 set_file_offset(
f, (
unsigned int) offset);
4774 set_file_offset(
f, left.
page_end + (delta / 2) - 32768);
4777 if (!vorbis_find_page(
f, NULL, NULL))
goto error;
4781 if (!get_seek_page_info(
f, &mid))
goto error;
4791 if (probe >= 2 || delta <= 65536)
4805 set_file_offset(
f, page_start);
4807 end_pos =
f->end_seg_with_known_loc;
4808 assert(end_pos >= 0);
4811 for (i = end_pos; i > 0; --i)
4812 if (
f->segments[i-1] != 255)
4815 start_seg_with_known_loc = i;
4821 if (!go_to_page_before(
f, page_start))
4825 if (!start_page(
f))
goto error;
4826 end_pos =
f->segment_count - 1;
4830 f->current_loc_valid =
FALSE;
4833 f->packet_bytes = 0;
4834 f->bytes_in_seg = 0;
4835 f->previous_length = 0;
4836 f->next_seg = start_seg_with_known_loc;
4838 for (i = 0; i < start_seg_with_known_loc; i++)
4839 skip(
f,
f->segments[i]);
4842 if (!vorbis_pump_first_frame(
f))
4844 if (
f->current_loc > sample_number)
4855 static int peek_decode_initial(
vorb *
f,
int *p_left_start,
int *p_left_end,
int *p_right_start,
int *p_right_end,
int *mode)
4857 int bits_read, bytes_read;
4859 if (!vorbis_decode_initial(
f, p_left_start, p_left_end, p_right_start, p_right_end, mode))
4863 bits_read = 1 + ilog(
f->mode_count-1);
4864 if (
f->mode_config[*mode].blockflag)
4866 bytes_read = (bits_read + 7) / 8;
4868 f->bytes_in_seg += bytes_read;
4869 f->packet_bytes -= bytes_read;
4870 skip(
f, -bytes_read);
4871 if (
f->next_seg == -1)
4872 f->next_seg =
f->segment_count - 1;
4882 uint32 max_frame_samples;
4887 if (!seek_to_sample_coarse(
f, sample_number))
4890 assert(
f->current_loc_valid);
4891 assert(
f->current_loc <= sample_number);
4894 max_frame_samples = (
f->blocksize_1*3 -
f->blocksize_0) >> 2;
4895 while (
f->current_loc < sample_number) {
4896 int left_start, left_end, right_start, right_end, mode, frame_samples;
4897 if (!peek_decode_initial(
f, &left_start, &left_end, &right_start, &right_end, &mode))
4900 frame_samples = right_start - left_start;
4901 if (
f->current_loc + frame_samples > sample_number) {
4903 }
else if (
f->current_loc + frame_samples + max_frame_samples > sample_number) {
4905 vorbis_pump_first_frame(
f);
4908 f->current_loc += frame_samples;
4909 f->previous_length = 0;
4910 maybe_start_packet(
f);
4924 if (sample_number !=
f->current_loc) {
4926 uint32 frame_start =
f->current_loc;
4928 assert(sample_number > frame_start);
4929 assert(
f->channel_buffer_start + (
int) (sample_number-frame_start) <=
f->channel_buffer_end);
4930 f->channel_buffer_start += (sample_number - frame_start);
4939 set_file_offset(
f,
f->first_audio_page_offset);
4940 f->previous_length = 0;
4941 f->first_decode =
TRUE;
4943 return vorbis_pump_first_frame(
f);
4948 unsigned int restore_offset, previous_safe;
4949 unsigned int end, last_page_loc;
4952 if (!
f->total_samples) {
4962 if (
f->stream_len >= 65536 &&
f->stream_len-65536 >=
f->first_audio_page_offset)
4963 previous_safe =
f->stream_len - 65536;
4965 previous_safe =
f->first_audio_page_offset;
4967 set_file_offset(
f, previous_safe);
4971 if (!vorbis_find_page(
f, &end, &last)) {
4974 f->total_samples = 0xffffffff;
4985 set_file_offset(
f, end);
4986 if (!vorbis_find_page(
f, &end, &last)) {
4995 set_file_offset(
f, last_page_loc);
4998 getn(
f, (
unsigned char *)header, 6);
5002 if (lo == 0xffffffff && hi == 0xffffffff) {
5009 f->total_samples = lo;
5011 f->p_last.page_start = last_page_loc;
5012 f->p_last.page_end = end;
5013 f->p_last.last_decoded_sample = lo;
5016 set_file_offset(
f, restore_offset);
5030 int len, right,left,i;
5033 if (!vorbis_decode_packet(
f, &len, &left, &right)) {
5034 f->channel_buffer_start =
f->channel_buffer_end = 0;
5038 len = vorbis_finish_frame(
f, len, left, right);
5039 for (i=0; i <
f->channels; ++i)
5040 f->outputs[i] =
f->channel_buffers[i] + left;
5042 f->channel_buffer_start = left;
5043 f->channel_buffer_end = left+len;
5046 if (output) *output =
f->outputs;
5050 #ifndef STB_VORBIS_NO_STDIO
5055 vorbis_init(&p,
alloc);
5060 if (start_decoder(&p)) {
5061 f = vorbis_alloc(&p);
5064 vorbis_pump_first_frame(
f);
5075 unsigned int len, start;
5076 start = (
unsigned int) ftell(file);
5077 fseek(file, 0, SEEK_END);
5078 len = (
unsigned int) (ftell(file) - start);
5079 fseek(file, start, SEEK_SET);
5086 #if defined(_WIN32) && defined(__STDC_WANT_SECURE_LIB__)
5087 if (0 != fopen_s(&
f, filename,
"rb"))
5090 f = fopen(filename,
"rb");
5106 vorbis_init(&p,
alloc);
5112 if (start_decoder(&p)) {
5113 f = vorbis_alloc(&p);
5116 vorbis_pump_first_frame(
f);
5126 #ifndef STB_VORBIS_NO_INTEGER_CONVERSION
5127 #define PLAYBACK_MONO 1
5128 #define PLAYBACK_LEFT 2
5129 #define PLAYBACK_RIGHT 4
5131 #define L (PLAYBACK_LEFT | PLAYBACK_MONO)
5132 #define C (PLAYBACK_LEFT | PLAYBACK_RIGHT | PLAYBACK_MONO)
5133 #define R (PLAYBACK_RIGHT | PLAYBACK_MONO)
5135 static int8 channel_position[7][6] =
5147 #ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT
5153 #define FASTDEF(x) float_conv x
5155 #define MAGIC(SHIFT) (1.5f * (1 << (23-SHIFT)) + 0.5f/(1 << SHIFT))
5156 #define ADDEND(SHIFT) (((150-SHIFT) << 23) + (1 << 22))
5157 #define FAST_SCALED_FLOAT_TO_INT(temp,x,s) (temp.f = (x) + MAGIC(s), temp.i - ADDEND(s))
5158 #define check_endianness()
5160 #define FAST_SCALED_FLOAT_TO_INT(temp,x,s) ((int) ((x) * (1 << (s))))
5161 #define check_endianness()
5165 static void copy_samples(
short *dest,
float *src,
int len)
5169 for (i=0; i < len; ++i) {
5172 if ((
unsigned int) (v + 32768) > 65535)
5173 v = v < 0 ? -32768 : 32767;
5178 static void compute_samples(
int mask,
short *output,
int num_c,
float **data,
int d_offset,
int len)
5180 #define STB_BUFFER_SIZE 32
5185 memset(buffer, 0,
sizeof(buffer));
5186 if (o + n > len) n = len - o;
5187 for (j=0; j < num_c; ++j) {
5188 if (channel_position[num_c][j] & mask) {
5189 for (i=0; i < n; ++i)
5190 buffer[i] += data[j][d_offset+o+i];
5193 for (i=0; i < n; ++i) {
5196 if ((
unsigned int) (v + 32768) > 65535)
5197 v = v < 0 ? -32768 : 32767;
5201 #undef STB_BUFFER_SIZE
5204 static void compute_stereo_samples(
short *output,
int num_c,
float **data,
int d_offset,
int len)
5206 #define STB_BUFFER_SIZE 32
5211 for (o = 0; o < len; o += STB_BUFFER_SIZE >> 1) {
5214 memset(buffer, 0,
sizeof(buffer));
5215 if (o + n > len) n = len - o;
5216 for (j=0; j < num_c; ++j) {
5219 for (i=0; i < n; ++i) {
5220 buffer[i*2+0] += data[j][d_offset+o+i];
5221 buffer[i*2+1] += data[j][d_offset+o+i];
5224 for (i=0; i < n; ++i) {
5225 buffer[i*2+0] += data[j][d_offset+o+i];
5228 for (i=0; i < n; ++i) {
5229 buffer[i*2+1] += data[j][d_offset+o+i];
5233 for (i=0; i < (n<<1); ++i) {
5236 if ((
unsigned int) (v + 32768) > 65535)
5237 v = v < 0 ? -32768 : 32767;
5241 #undef STB_BUFFER_SIZE
5244 static void convert_samples_short(
int buf_c,
short **buffer,
int b_offset,
int data_c,
float **data,
int d_offset,
int samples)
5247 if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
5249 for (i=0; i < buf_c; ++i)
5250 compute_samples(channel_selector[buf_c][i], buffer[i]+b_offset, data_c, data, d_offset, samples);
5252 int limit = buf_c < data_c ? buf_c : data_c;
5253 for (i=0; i < limit; ++i)
5254 copy_samples(buffer[i]+b_offset, data[i]+d_offset, samples);
5255 for ( ; i < buf_c; ++i)
5256 memset(buffer[i]+b_offset, 0,
sizeof(
short) * samples);
5262 float **output = NULL;
5264 if (len > num_samples) len = num_samples;
5266 convert_samples_short(num_c, buffer, 0, f->
channels, output, 0, len);
5270 static void convert_channels_short_interleaved(
int buf_c,
short *buffer,
int data_c,
float **data,
int d_offset,
int len)
5274 if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
5276 for (i=0; i < buf_c; ++i)
5277 compute_stereo_samples(buffer, data_c, data, d_offset, len);
5279 int limit = buf_c < data_c ? buf_c : data_c;
5281 for (j=0; j < len; ++j) {
5282 for (i=0; i < limit; ++i) {
5284 float f = data[i][d_offset+j];
5286 if ((
unsigned int) (v + 32768) > 65535)
5287 v = v < 0 ? -32768 : 32767;
5290 for ( ; i < buf_c; ++i)
5303 if (len*num_c > num_shorts) len = num_shorts / num_c;
5304 convert_channels_short_interleaved(num_c, buffer, f->
channels, output, 0, len);
5312 int len = num_shorts / channels;
5316 if (n+k >= len) k = len - n;
5319 buffer += k*channels;
5322 if (n == len)
break;
5334 if (n+k >= len) k = len - n;
5339 if (n == len)
break;
5345 #ifndef STB_VORBIS_NO_STDIO
5348 int data_len, offset, total, limit, error;
5351 if (v == NULL)
return -1;
5356 offset = data_len = 0;
5358 data = (
short *) malloc(total *
sizeof(*data));
5368 if (offset + limit > total) {
5371 data2 = (
short *) realloc(data, total *
sizeof(*data));
5372 if (data2 == NULL) {
5388 int data_len, offset, total, limit, error;
5391 if (v == NULL)
return -1;
5396 offset = data_len = 0;
5398 data = (
short *) malloc(total *
sizeof(*data));
5408 if (offset + limit > total) {
5411 data2 = (
short *) realloc(data, total *
sizeof(*data));
5412 if (data2 == NULL) {
5429 int len = num_floats / channels;
5432 if (z > channels) z = channels;
5436 if (n+k >= len) k = len - n;
5437 for (j=0; j < k; ++j) {
5438 for (i=0; i < z; ++i)
5440 for ( ; i < channels; ++i)
5458 if (z > channels) z = channels;
5459 while (n < num_samples) {
5462 if (n+k >= num_samples) k = num_samples - n;
5464 for (i=0; i < z; ++i)
5466 for ( ; i < channels; ++i)
5467 memset(buffer[i]+n, 0,
sizeof(
float) * k);
5471 if (n == num_samples)
void log(const std::string_view severity, const std::string_view category, const std::string_view msg)
Logs data to a file or console.
#define temp_alloc_save(f)
float stb_vorbis_stream_length_in_seconds(stb_vorbis *f)
#define temp_alloc(f, size)
@ VORBIS_seek_without_length
@ VORBIS_invalid_first_page
@ VORBIS_incorrect_stream_serial_number
@ VORBIS_missing_capture_pattern
@ VORBIS_continued_packet_flag_invalid
@ VORBIS_cant_find_last_page
@ VORBIS_too_many_channels
@ VORBIS_feature_not_supported
@ VORBIS_invalid_api_mixing
@ VORBIS_file_open_failure
@ VORBIS_ogg_skeleton_not_supported
@ VORBIS_invalid_stream_structure_version
int stb_vorbis_get_frame_short(stb_vorbis *f, int num_c, short **buffer, int num_samples)
#define FAST_HUFFMAN_TABLE_SIZE
int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number)
stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f)
void stb_vorbis_flush_pushdata(stb_vorbis *f)
#define temp_alloc_restore(f, p)
#define FAST_HUFFMAN_TABLE_MASK
int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples)
stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f)
int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output)
#define PAGEFLAG_last_page
#define STB_VORBIS_FAST_HUFFMAN_LENGTH
int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number)
int stb_vorbis_seek_start(stb_vorbis *f)
int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float *buffer, int num_floats)
stb_vorbis * stb_vorbis_open_file_section(FILE *f, int close_handle_on_close, int *error, const stb_vorbis_alloc *alloc_buffer, unsigned int len)
int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts)
char stb_vorbis_float_size_test[sizeof(float)==4 &&sizeof(int)==4]
int stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_rate, short **output)
#define PAGEFLAG_continued_packet
int stb_vorbis_decode_frame_pushdata(stb_vorbis *f, const unsigned char *datablock, int datablock_length_in_bytes, int *channels, float ***output, int *samples)
#define PAGEFLAG_first_page
stb_vorbis * stb_vorbis_open_pushdata(const unsigned char *datablock, int datablock_length_in_bytes, int *datablock_memory_consumed_in_bytes, int *error, const stb_vorbis_alloc *alloc_buffer)
int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int num_samples)
#define STB_VORBIS_PUSHDATA_CRC_COUNT
#define temp_block_array(f, count, size)
unsigned int stb_vorbis_get_file_offset(stb_vorbis *f)
stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close, int *error, const stb_vorbis_alloc *alloc_buffer)
#define check_endianness()
int stb_vorbis_get_sample_offset(stb_vorbis *f)
#define CODEBOOK_ELEMENT_BASE(c)
#define CODEBOOK_ELEMENT_FAST(c, off)
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc_buffer)
#define STB_VORBIS_FAST_HUFFMAN_SHORT
int stb_vorbis_get_error(stb_vorbis *f)
int stb_vorbis_decode_memory(const unsigned char *mem, int len, int *channels, int *sample_rate, short **output)
void stb_vorbis_close(stb_vorbis *f)
#define FAST_SCALED_FLOAT_TO_INT(temp, x, s)
#define STB_VORBIS_MAX_CHANNELS
#define DECODE(var, f, c)
unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts)
stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const stb_vorbis_alloc *alloc_buffer)
#define DECODE_VQ(var, f, c)
uint32 * sorted_codewords
int16 fast_huffman[FAST_HUFFMAN_TABLE_SIZE]
uint8 neighbors[31 *8+2][2]
uint8 sorted_order[31 *8+2]
uint8 class_dimensions[16]
uint8 class_masterbooks[16]
uint8 class_subclasses[16]
int16 subclass_books[16][8]
uint8 partition_class_list[32]
uint32 last_decoded_sample
int16(* residue_books)[8]
int alloc_buffer_length_in_bytes
unsigned int temp_memory_required
unsigned int setup_memory_required
unsigned int setup_temp_memory_required
float * previous_window[STB_VORBIS_MAX_CHANNELS]
unsigned int setup_temp_memory_required
float * channel_buffers[STB_VORBIS_MAX_CHANNELS]
int16 * finalY[STB_VORBIS_MAX_CHANNELS]
uint32 first_audio_page_offset
unsigned int temp_memory_required
uint32 known_loc_for_packet
int end_seg_with_known_loc
CRCscan scan[STB_VORBIS_PUSHDATA_CRC_COUNT]
float * outputs[STB_VORBIS_MAX_CHANNELS]
int discard_samples_deferred
unsigned int setup_memory_required
enum STBVorbisError error