vkQuake2 doxygen  1.0 dev
stb_vorbis.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <limits.h>

Go to the source code of this file.

Classes

struct  stb_vorbis_alloc
 
struct  stb_vorbis_info
 
struct  Codebook
 
struct  Floor0
 
struct  Floor1
 
union  Floor
 
struct  Residue
 
struct  MappingChannel
 
struct  Mapping
 
struct  Mode
 
struct  CRCscan
 
struct  ProbedPage
 
struct  stb_vorbis
 
struct  stbv__floor_ordering
 
union  float_conv
 

Macros

#define STB_VORBIS_INCLUDE_STB_VORBIS_H
 
#define STB_VORBIS_MAX_CHANNELS   16
 
#define STB_VORBIS_PUSHDATA_CRC_COUNT   4
 
#define STB_VORBIS_FAST_HUFFMAN_LENGTH   10
 
#define STB_VORBIS_FAST_HUFFMAN_SHORT
 
#define STB_VORBIS_ENDIAN   0
 
#define __forceinline
 
#define CHECK(f)   ((void) 0)
 
#define MAX_BLOCKSIZE_LOG   13
 
#define MAX_BLOCKSIZE   (1 << MAX_BLOCKSIZE_LOG)
 
#define TRUE   1
 
#define FALSE   0
 
#define FAST_HUFFMAN_TABLE_SIZE   (1 << STB_VORBIS_FAST_HUFFMAN_LENGTH)
 
#define FAST_HUFFMAN_TABLE_MASK   (FAST_HUFFMAN_TABLE_SIZE - 1)
 
#define IS_PUSH_MODE(f)   ((f)->push_mode)
 
#define array_size_required(count, size)   (count*(sizeof(void *)+(size)))
 
#define temp_alloc(f, size)   (f->alloc.alloc_buffer ? setup_temp_malloc(f,size) : alloca(size))
 
#define temp_free(f, p)   0
 
#define temp_alloc_save(f)   ((f)->temp_offset)
 
#define temp_alloc_restore(f, p)   ((f)->temp_offset = (p))
 
#define temp_block_array(f, count, size)   make_block_array(temp_alloc(f,array_size_required(count,size)), count, size)
 
#define CRC32_POLY   0x04c11db7
 
#define M_PI   3.14159265358979323846264f
 
#define NO_CODE   255
 
#define STBV_CDECL
 
#define USE_MEMORY(z)   ((z)->stream)
 
#define PAGEFLAG_continued_packet   1
 
#define PAGEFLAG_first_page   2
 
#define PAGEFLAG_last_page   4
 
#define EOP   (-1)
 
#define INVALID_BITS   (-1)
 
#define DECODE_RAW(var, f, c)
 
#define DECODE(var, f, c)
 
#define DECODE_VQ(var, f, c)   DECODE_RAW(var,f,c)
 
#define CODEBOOK_ELEMENT(c, off)   (c->multiplicands[off])
 
#define CODEBOOK_ELEMENT_FAST(c, off)   (c->multiplicands[off])
 
#define CODEBOOK_ELEMENT_BASE(c)   (0)
 
#define LINE_OP(a, b)   a *= b
 
#define LIBVORBIS_MDCT   0
 
#define SAMPLE_unknown   0xffffffff
 
#define PLAYBACK_MONO   1
 
#define PLAYBACK_LEFT   2
 
#define PLAYBACK_RIGHT   4
 
#define L   (PLAYBACK_LEFT | PLAYBACK_MONO)
 
#define C   (PLAYBACK_LEFT | PLAYBACK_RIGHT | PLAYBACK_MONO)
 
#define R   (PLAYBACK_RIGHT | PLAYBACK_MONO)
 
#define FASTDEF(x)   float_conv x
 
#define MAGIC(SHIFT)   (1.5f * (1 << (23-SHIFT)) + 0.5f/(1 << SHIFT))
 
#define ADDEND(SHIFT)   (((150-SHIFT) << 23) + (1 << 22))
 
#define FAST_SCALED_FLOAT_TO_INT(temp, x, s)   (temp.f = (x) + MAGIC(s), temp.i - ADDEND(s))
 
#define check_endianness()
 
#define BUFFER_SIZE   32
 
#define BUFFER_SIZE   32
 

Typedefs

typedef struct stb_vorbis stb_vorbis
 
typedef unsigned char uint8
 
typedef signed char int8
 
typedef unsigned short uint16
 
typedef signed short int16
 
typedef unsigned int uint32
 
typedef signed int int32
 
typedef float codetype
 
typedef struct stb_vorbis vorb
 
typedef int16 YTYPE
 
typedef char stb_vorbis_float_size_test[sizeof(float)==4 &&sizeof(int)==4]
 

Enumerations

enum  STBVorbisError {
  VORBIS__no_error, VORBIS_need_more_data =1, VORBIS_invalid_api_mixing, VORBIS_outofmem,
  VORBIS_feature_not_supported, VORBIS_too_many_channels, VORBIS_file_open_failure, VORBIS_seek_without_length,
  VORBIS_unexpected_eof =10, VORBIS_seek_invalid, VORBIS_invalid_setup =20, VORBIS_invalid_stream,
  VORBIS_missing_capture_pattern =30, VORBIS_invalid_stream_structure_version, VORBIS_continued_packet_flag_invalid, VORBIS_incorrect_stream_serial_number,
  VORBIS_invalid_first_page, VORBIS_bad_packet_type, VORBIS_cant_find_last_page, VORBIS_seek_failed
}
 
enum  { VORBIS_packet_id = 1, VORBIS_packet_comment = 3, VORBIS_packet_setup = 5 }
 

Functions

stb_vorbis_info stb_vorbis_get_info (stb_vorbis *f)
 
int stb_vorbis_get_error (stb_vorbis *f)
 
void stb_vorbis_close (stb_vorbis *f)
 
int stb_vorbis_get_sample_offset (stb_vorbis *f)
 
unsigned int stb_vorbis_get_file_offset (stb_vorbis *f)
 
stb_vorbisstb_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_decode_frame_pushdata (stb_vorbis *f, const unsigned char *datablock, int datablock_length_in_bytes, int *channels, float ***output, int *samples)
 
void stb_vorbis_flush_pushdata (stb_vorbis *f)
 
int stb_vorbis_decode_filename (const char *filename, int *channels, int *sample_rate, short **output)
 
int stb_vorbis_decode_memory (const unsigned char *mem, int len, int *channels, int *sample_rate, short **output)
 
stb_vorbisstb_vorbis_open_memory (const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc_buffer)
 
stb_vorbisstb_vorbis_open_filename (const char *filename, int *error, const stb_vorbis_alloc *alloc_buffer)
 
stb_vorbisstb_vorbis_open_file (FILE *f, int close_handle_on_close, int *error, const stb_vorbis_alloc *alloc_buffer)
 
stb_vorbisstb_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_seek_frame (stb_vorbis *f, unsigned int sample_number)
 
int stb_vorbis_seek (stb_vorbis *f, unsigned int sample_number)
 
int stb_vorbis_seek_start (stb_vorbis *f)
 
unsigned int stb_vorbis_stream_length_in_samples (stb_vorbis *f)
 
float stb_vorbis_stream_length_in_seconds (stb_vorbis *f)
 
int stb_vorbis_get_frame_float (stb_vorbis *f, int *channels, float ***output)
 
int stb_vorbis_get_frame_short_interleaved (stb_vorbis *f, int num_c, short *buffer, int num_shorts)
 
int stb_vorbis_get_frame_short (stb_vorbis *f, int num_c, short **buffer, int num_samples)
 
int stb_vorbis_get_samples_float_interleaved (stb_vorbis *f, int channels, float *buffer, int num_floats)
 
int stb_vorbis_get_samples_float (stb_vorbis *f, int channels, float **buffer, int num_samples)
 
int stb_vorbis_get_samples_short_interleaved (stb_vorbis *f, int channels, short *buffer, int num_shorts)
 
int stb_vorbis_get_samples_short (stb_vorbis *f, int channels, short **buffer, int num_samples)
 
static int error (vorb *f, enum STBVorbisError e)
 
static voidmake_block_array (void *mem, int count, int size)
 
static voidsetup_malloc (vorb *f, int sz)
 
static void setup_free (vorb *f, void *p)
 
static voidsetup_temp_malloc (vorb *f, int sz)
 
static void setup_temp_free (vorb *f, void *p, int sz)
 
static void crc32_init (void)
 
static __forceinline uint32 crc32_update (uint32 crc, uint8 byte)
 
static unsigned int bit_reverse (unsigned int n)
 
static float square (float x)
 
static int ilog (int32 n)
 
static float float32_unpack (uint32 x)
 
static void add_entry (Codebook *c, uint32 huff_code, int symbol, int count, int len, uint32 *values)
 
static int compute_codewords (Codebook *c, uint8 *len, int n, uint32 *values)
 
static void compute_accelerated_huffman (Codebook *c)
 
static int STBV_CDECL uint32_compare (const void *p, const void *q)
 
static int include_in_sort (Codebook *c, uint8 len)
 
static void compute_sorted_huffman (Codebook *c, uint8 *lengths, uint32 *values)
 
static int vorbis_validate (uint8 *data)
 
static int lookup1_values (int entries, int dim)
 
static void compute_twiddle_factors (int n, float *A, float *B, float *C)
 
static void compute_window (int n, float *window)
 
static void compute_bitreverse (int n, uint16 *rev)
 
static int init_blocksize (vorb *f, int b, int n)
 
static void neighbors (uint16 *x, int n, int *plow, int *phigh)
 
static int STBV_CDECL point_compare (const void *p, const void *q)
 
static uint8 get8 (vorb *z)
 
static uint32 get32 (vorb *f)
 
static int getn (vorb *z, uint8 *data, int n)
 
static void skip (vorb *z, int n)
 
static int set_file_offset (stb_vorbis *f, unsigned int loc)
 
static int capture_pattern (vorb *f)
 
static int start_page_no_capturepattern (vorb *f)
 
static int start_page (vorb *f)
 
static int start_packet (vorb *f)
 
static int maybe_start_packet (vorb *f)
 
static int next_segment (vorb *f)
 
static int get8_packet_raw (vorb *f)
 
static int get8_packet (vorb *f)
 
static void flush_packet (vorb *f)
 
static uint32 get_bits (vorb *f, int n)
 
static __forceinline void prep_huffman (vorb *f)
 
static int codebook_decode_scalar_raw (vorb *f, Codebook *c)
 
static int codebook_decode_start (vorb *f, Codebook *c)
 
static int codebook_decode (vorb *f, Codebook *c, float *output, int len)
 
static int codebook_decode_step (vorb *f, Codebook *c, float *output, int len, int step)
 
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)
 
static int predict_point (int x, int x0, int x1, int y0, int y1)
 
static __forceinline void draw_line (float *output, int x0, int y0, int x1, int y1, int n)
 
static int residue_decode (vorb *f, Codebook *book, float *target, int offset, int n, int rtype)
 
static void decode_residue (vorb *f, float *residue_buffers[], int ch, int n, int rn, uint8 *do_not_decode)
 
static void imdct_step3_iter0_loop (int n, float *e, int i_off, int k_off, float *A)
 
static void imdct_step3_inner_r_loop (int lim, float *e, int d0, int k_off, float *A, int k1)
 
static void imdct_step3_inner_s_loop (int n, float *e, int i_off, int k_off, float *A, int a_off, int k0)
 
static __forceinline void iter_54 (float *z)
 
static void imdct_step3_inner_s_loop_ld654 (int n, float *e, int i_off, float *A, int base_n)
 
static void inverse_mdct (float *buffer, int n, vorb *f, int blocktype)
 
static float * get_window (vorb *f, int len)
 
static int do_floor (vorb *f, Mapping *map, int i, int n, float *target, YTYPE *finalY, uint8 *step2_flag)
 
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)
 
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)
 
static int vorbis_decode_packet (vorb *f, int *len, int *p_left, int *p_right)
 
static int vorbis_finish_frame (stb_vorbis *f, int len, int left, int right)
 
static int vorbis_pump_first_frame (stb_vorbis *f)
 
static int is_whole_packet_present (stb_vorbis *f, int end_page)
 
static int start_decoder (vorb *f)
 
static void vorbis_deinit (stb_vorbis *p)
 
static void vorbis_init (stb_vorbis *p, const stb_vorbis_alloc *z)
 
static stb_vorbisvorbis_alloc (stb_vorbis *f)
 
static int vorbis_search_for_page_pushdata (vorb *f, uint8 *data, int data_len)
 
static uint32 vorbis_find_page (stb_vorbis *f, uint32 *end, uint32 *last)
 
static int get_seek_page_info (stb_vorbis *f, ProbedPage *z)
 
static int go_to_page_before (stb_vorbis *f, unsigned int limit_offset)
 
static int seek_to_sample_coarse (stb_vorbis *f, uint32 sample_number)
 
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)
 
static void copy_samples (short *dest, float *src, int len)
 
static void compute_samples (int mask, short *output, int num_c, float **data, int d_offset, int len)
 
static void compute_stereo_samples (short *output, int num_c, float **data, int d_offset, int len)
 
static void convert_samples_short (int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples)
 
static void convert_channels_short_interleaved (int buf_c, short *buffer, int data_c, float **data, int d_offset, int len)
 

Variables

static uint32 crc_table [256]
 
static uint8 ogg_page_header [4] = { 0x4f, 0x67, 0x67, 0x53 }
 
static float inverse_db_table [256]
 
static int8 channel_position [7][6]
 

Macro Definition Documentation

◆ __forceinline

#define __forceinline

Definition at line 585 of file stb_vorbis.c.

◆ ADDEND

#define ADDEND (   SHIFT)    (((150-SHIFT) << 23) + (1 << 22))

Definition at line 5027 of file stb_vorbis.c.

◆ array_size_required

#define array_size_required (   count,
  size 
)    (count*(sizeof(void *)+(size)))

Definition at line 880 of file stb_vorbis.c.

◆ BUFFER_SIZE [1/2]

#define BUFFER_SIZE   32

◆ BUFFER_SIZE [2/2]

#define BUFFER_SIZE   32

◆ C

Definition at line 5003 of file stb_vorbis.c.

◆ CHECK

#define CHECK (   f)    ((void) 0)

Definition at line 602 of file stb_vorbis.c.

◆ check_endianness

#define check_endianness ( )

Definition at line 5029 of file stb_vorbis.c.

◆ CODEBOOK_ELEMENT

#define CODEBOOK_ELEMENT (   c,
  off 
)    (c->multiplicands[off])

Definition at line 1714 of file stb_vorbis.c.

◆ CODEBOOK_ELEMENT_BASE

#define CODEBOOK_ELEMENT_BASE (   c)    (0)

Definition at line 1716 of file stb_vorbis.c.

◆ CODEBOOK_ELEMENT_FAST

#define CODEBOOK_ELEMENT_FAST (   c,
  off 
)    (c->multiplicands[off])

Definition at line 1715 of file stb_vorbis.c.

◆ CRC32_POLY

#define CRC32_POLY   0x04c11db7

Definition at line 945 of file stb_vorbis.c.

◆ DECODE

#define DECODE (   var,
  f,
 
)
Value:
DECODE_RAW(var,f,c) \
if (c->sparse) var = c->sorted_values[var];

Definition at line 1697 of file stb_vorbis.c.

◆ DECODE_RAW

#define DECODE_RAW (   var,
  f,
 
)
Value:
if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH) \
prep_huffman(f); \
var = f->acc & FAST_HUFFMAN_TABLE_MASK; \
var = c->fast_huffman[var]; \
if (var >= 0) { \
int n = c->codeword_lengths[var]; \
f->acc >>= n; \
f->valid_bits -= n; \
if (f->valid_bits < 0) { f->valid_bits = 0; var = -1; } \
} else { \
}

Definition at line 1660 of file stb_vorbis.c.

◆ DECODE_VQ

#define DECODE_VQ (   var,
  f,
 
)    DECODE_RAW(var,f,c)

Definition at line 1702 of file stb_vorbis.c.

◆ EOP

#define EOP   (-1)

Definition at line 1514 of file stb_vorbis.c.

◆ FALSE

#define FALSE   0

Definition at line 618 of file stb_vorbis.c.

◆ FAST_HUFFMAN_TABLE_MASK

#define FAST_HUFFMAN_TABLE_MASK   (FAST_HUFFMAN_TABLE_SIZE - 1)

Definition at line 637 of file stb_vorbis.c.

◆ FAST_HUFFMAN_TABLE_SIZE

#define FAST_HUFFMAN_TABLE_SIZE   (1 << STB_VORBIS_FAST_HUFFMAN_LENGTH)

Definition at line 636 of file stb_vorbis.c.

◆ FAST_SCALED_FLOAT_TO_INT

#define FAST_SCALED_FLOAT_TO_INT (   temp,
  x,
  s 
)    (temp.f = (x) + MAGIC(s), temp.i - ADDEND(s))

Definition at line 5028 of file stb_vorbis.c.

◆ FASTDEF

#define FASTDEF (   x)    float_conv x

Definition at line 5024 of file stb_vorbis.c.

◆ INVALID_BITS

#define INVALID_BITS   (-1)

Definition at line 1515 of file stb_vorbis.c.

◆ IS_PUSH_MODE

#define IS_PUSH_MODE (   f)    ((f)->push_mode)

Definition at line 860 of file stb_vorbis.c.

◆ L

#define L   (PLAYBACK_LEFT | PLAYBACK_MONO)

Definition at line 5002 of file stb_vorbis.c.

◆ LIBVORBIS_MDCT

#define LIBVORBIS_MDCT   0

Definition at line 2343 of file stb_vorbis.c.

◆ LINE_OP

#define LINE_OP (   a,
 
)    a *= b

Definition at line 1966 of file stb_vorbis.c.

◆ M_PI

#define M_PI   3.14159265358979323846264f

Definition at line 1002 of file stb_vorbis.c.

◆ MAGIC

#define MAGIC (   SHIFT)    (1.5f * (1 << (23-SHIFT)) + 0.5f/(1 << SHIFT))

Definition at line 5026 of file stb_vorbis.c.

◆ MAX_BLOCKSIZE

#define MAX_BLOCKSIZE   (1 << MAX_BLOCKSIZE_LOG)

Definition at line 606 of file stb_vorbis.c.

◆ MAX_BLOCKSIZE_LOG

#define MAX_BLOCKSIZE_LOG   13

Definition at line 605 of file stb_vorbis.c.

◆ NO_CODE

#define NO_CODE   255

Definition at line 1006 of file stb_vorbis.c.

◆ PAGEFLAG_continued_packet

#define PAGEFLAG_continued_packet   1

Definition at line 1394 of file stb_vorbis.c.

◆ PAGEFLAG_first_page

#define PAGEFLAG_first_page   2

Definition at line 1395 of file stb_vorbis.c.

◆ PAGEFLAG_last_page

#define PAGEFLAG_last_page   4

Definition at line 1396 of file stb_vorbis.c.

◆ PLAYBACK_LEFT

#define PLAYBACK_LEFT   2

Definition at line 4999 of file stb_vorbis.c.

◆ PLAYBACK_MONO

#define PLAYBACK_MONO   1

Definition at line 4998 of file stb_vorbis.c.

◆ PLAYBACK_RIGHT

#define PLAYBACK_RIGHT   4

Definition at line 5000 of file stb_vorbis.c.

◆ R

#define R   (PLAYBACK_RIGHT | PLAYBACK_MONO)

Definition at line 5004 of file stb_vorbis.c.

◆ SAMPLE_unknown

#define SAMPLE_unknown   0xffffffff

Definition at line 4517 of file stb_vorbis.c.

◆ STB_VORBIS_ENDIAN

#define STB_VORBIS_ENDIAN   0

Definition at line 535 of file stb_vorbis.c.

◆ STB_VORBIS_FAST_HUFFMAN_LENGTH

#define STB_VORBIS_FAST_HUFFMAN_LENGTH   10

Definition at line 453 of file stb_vorbis.c.

◆ STB_VORBIS_FAST_HUFFMAN_SHORT

#define STB_VORBIS_FAST_HUFFMAN_SHORT

Definition at line 467 of file stb_vorbis.c.

◆ STB_VORBIS_INCLUDE_STB_VORBIS_H

#define STB_VORBIS_INCLUDE_STB_VORBIS_H

Definition at line 60 of file stb_vorbis.c.

◆ STB_VORBIS_MAX_CHANNELS

#define STB_VORBIS_MAX_CHANNELS   16

Definition at line 428 of file stb_vorbis.c.

◆ STB_VORBIS_PUSHDATA_CRC_COUNT

#define STB_VORBIS_PUSHDATA_CRC_COUNT   4

Definition at line 444 of file stb_vorbis.c.

◆ STBV_CDECL

#define STBV_CDECL

Definition at line 1115 of file stb_vorbis.c.

◆ temp_alloc

#define temp_alloc (   f,
  size 
)    (f->alloc.alloc_buffer ? setup_temp_malloc(f,size) : alloca(size))

Definition at line 882 of file stb_vorbis.c.

◆ temp_alloc_restore

#define temp_alloc_restore (   f,
 
)    ((f)->temp_offset = (p))

Definition at line 889 of file stb_vorbis.c.

◆ temp_alloc_save

#define temp_alloc_save (   f)    ((f)->temp_offset)

Definition at line 888 of file stb_vorbis.c.

◆ temp_block_array

#define temp_block_array (   f,
  count,
  size 
)    make_block_array(temp_alloc(f,array_size_required(count,size)), count, size)

Definition at line 891 of file stb_vorbis.c.

◆ temp_free

#define temp_free (   f,
 
)    0

Definition at line 886 of file stb_vorbis.c.

◆ TRUE

#define TRUE   1

Definition at line 617 of file stb_vorbis.c.

◆ USE_MEMORY

#define USE_MEMORY (   z)    ((z)->stream)

Definition at line 1288 of file stb_vorbis.c.

Typedef Documentation

◆ codetype

typedef float codetype

Definition at line 621 of file stb_vorbis.c.

◆ int16

typedef signed short int16

Definition at line 612 of file stb_vorbis.c.

◆ int32

typedef signed int int32

Definition at line 614 of file stb_vorbis.c.

◆ int8

typedef signed char int8

Definition at line 610 of file stb_vorbis.c.

◆ stb_vorbis

typedef struct stb_vorbis stb_vorbis

Definition at line 112 of file stb_vorbis.c.

◆ stb_vorbis_float_size_test

typedef char stb_vorbis_float_size_test[sizeof(float)==4 &&sizeof(int)==4]

Definition at line 5023 of file stb_vorbis.c.

◆ uint16

typedef unsigned short uint16

Definition at line 611 of file stb_vorbis.c.

◆ uint32

typedef unsigned int uint32

Definition at line 613 of file stb_vorbis.c.

◆ uint8

typedef unsigned char uint8

Definition at line 609 of file stb_vorbis.c.

◆ vorb

typedef struct stb_vorbis vorb

Definition at line 863 of file stb_vorbis.c.

◆ YTYPE

typedef int16 YTYPE

Definition at line 3048 of file stb_vorbis.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
VORBIS_packet_id 
VORBIS_packet_comment 
VORBIS_packet_setup 

Definition at line 1592 of file stb_vorbis.c.

1593 {
1594  VORBIS_packet_id = 1,
1597 };

◆ STBVorbisError

Enumerator
VORBIS__no_error 
VORBIS_need_more_data 
VORBIS_invalid_api_mixing 
VORBIS_outofmem 
VORBIS_feature_not_supported 
VORBIS_too_many_channels 
VORBIS_file_open_failure 
VORBIS_seek_without_length 
VORBIS_unexpected_eof 
VORBIS_seek_invalid 
VORBIS_invalid_setup 
VORBIS_invalid_stream 
VORBIS_missing_capture_pattern 
VORBIS_invalid_stream_structure_version 
VORBIS_continued_packet_flag_invalid 
VORBIS_incorrect_stream_serial_number 
VORBIS_invalid_first_page 
VORBIS_bad_packet_type 
VORBIS_cant_find_last_page 
VORBIS_seek_failed 

Definition at line 342 of file stb_vorbis.c.

343 {
345 
346  VORBIS_need_more_data=1, // not a real error
347 
348  VORBIS_invalid_api_mixing, // can't mix API modes
349  VORBIS_outofmem, // not enough memory
350  VORBIS_feature_not_supported, // uses floor 0
351  VORBIS_too_many_channels, // STB_VORBIS_MAX_CHANNELS is too small
352  VORBIS_file_open_failure, // fopen() failed
353  VORBIS_seek_without_length, // can't seek in unknown-length file
354 
355  VORBIS_unexpected_eof=10, // file is truncated?
356  VORBIS_seek_invalid, // seek past EOF
357 
358  // decoding errors (corrupt/invalid stream) -- you probably
359  // don't care about the exact details of these
360 
361  // vorbis errors:
364 
365  // ogg errors:
374 };

Function Documentation

◆ add_entry()

static void add_entry ( Codebook c,
uint32  huff_code,
int  symbol,
int  count,
int  len,
uint32 values 
)
static

Definition at line 1031 of file stb_vorbis.c.

1032 {
1033  if (!c->sparse) {
1034  c->codewords [symbol] = huff_code;
1035  } else {
1036  c->codewords [count] = huff_code;
1037  c->codeword_lengths[count] = len;
1038  values [count] = symbol;
1039  }
1040 }

Referenced by compute_codewords().

◆ bit_reverse()

static unsigned int bit_reverse ( unsigned int  n)
static

Definition at line 966 of file stb_vorbis.c.

967 {
968  n = ((n & 0xAAAAAAAA) >> 1) | ((n & 0x55555555) << 1);
969  n = ((n & 0xCCCCCCCC) >> 2) | ((n & 0x33333333) << 2);
970  n = ((n & 0xF0F0F0F0) >> 4) | ((n & 0x0F0F0F0F) << 4);
971  n = ((n & 0xFF00FF00) >> 8) | ((n & 0x00FF00FF) << 8);
972  return (n >> 16) | (n << 16);
973 }

Referenced by codebook_decode_scalar_raw(), compute_accelerated_huffman(), compute_bitreverse(), compute_codewords(), and compute_sorted_huffman().

◆ capture_pattern()

static int capture_pattern ( vorb f)
static

Definition at line 1385 of file stb_vorbis.c.

1386 {
1387  if (0x4f != get8(f)) return FALSE;
1388  if (0x67 != get8(f)) return FALSE;
1389  if (0x67 != get8(f)) return FALSE;
1390  if (0x53 != get8(f)) return FALSE;
1391  return TRUE;
1392 }

Referenced by start_page().

◆ codebook_decode()

static int codebook_decode ( vorb f,
Codebook c,
float *  output,
int  len 
)
static

Definition at line 1738 of file stb_vorbis.c.

1739 {
1740  int i,z = codebook_decode_start(f,c);
1741  if (z < 0) return FALSE;
1742  if (len > c->dimensions) len = c->dimensions;
1743 
1744 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1745  if (c->lookup_type == 1) {
1746  float last = CODEBOOK_ELEMENT_BASE(c);
1747  int div = 1;
1748  for (i=0; i < len; ++i) {
1749  int off = (z / div) % c->lookup_values;
1750  float val = CODEBOOK_ELEMENT_FAST(c,off) + last;
1751  output[i] += val;
1752  if (c->sequence_p) last = val + c->minimum_value;
1753  div *= c->lookup_values;
1754  }
1755  return TRUE;
1756  }
1757 #endif
1758 
1759  z *= c->dimensions;
1760  if (c->sequence_p) {
1761  float last = CODEBOOK_ELEMENT_BASE(c);
1762  for (i=0; i < len; ++i) {
1763  float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
1764  output[i] += val;
1765  last = val + c->minimum_value;
1766  }
1767  } else {
1768  float last = CODEBOOK_ELEMENT_BASE(c);
1769  for (i=0; i < len; ++i) {
1770  output[i] += CODEBOOK_ELEMENT_FAST(c,z+i) + last;
1771  }
1772  }
1773 
1774  return TRUE;
1775 }

Referenced by residue_decode().

◆ codebook_decode_deinterleave_repeat()

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 
)
static

Definition at line 1808 of file stb_vorbis.c.

1809 {
1810  int c_inter = *c_inter_p;
1811  int p_inter = *p_inter_p;
1812  int i,z, effective = c->dimensions;
1813 
1814  // type 0 is only legal in a scalar context
1815  if (c->lookup_type == 0) return error(f, VORBIS_invalid_stream);
1816 
1817  while (total_decode > 0) {
1818  float last = CODEBOOK_ELEMENT_BASE(c);
1819  DECODE_VQ(z,f,c);
1820  #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
1821  assert(!c->sparse || z < c->sorted_entries);
1822  #endif
1823  if (z < 0) {
1824  if (!f->bytes_in_seg)
1825  if (f->last_seg) return FALSE;
1826  return error(f, VORBIS_invalid_stream);
1827  }
1828 
1829  // if this will take us off the end of the buffers, stop short!
1830  // we check by computing the length of the virtual interleaved
1831  // buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter),
1832  // and the length we'll be using (effective)
1833  if (c_inter + p_inter*ch + effective > len * ch) {
1834  effective = len*ch - (p_inter*ch - c_inter);
1835  }
1836 
1837  #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1838  if (c->lookup_type == 1) {
1839  int div = 1;
1840  for (i=0; i < effective; ++i) {
1841  int off = (z / div) % c->lookup_values;
1842  float val = CODEBOOK_ELEMENT_FAST(c,off) + last;
1843  if (outputs[c_inter])
1844  outputs[c_inter][p_inter] += val;
1845  if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1846  if (c->sequence_p) last = val;
1847  div *= c->lookup_values;
1848  }
1849  } else
1850  #endif
1851  {
1852  z *= c->dimensions;
1853  if (c->sequence_p) {
1854  for (i=0; i < effective; ++i) {
1855  float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
1856  if (outputs[c_inter])
1857  outputs[c_inter][p_inter] += val;
1858  if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1859  last = val;
1860  }
1861  } else {
1862  for (i=0; i < effective; ++i) {
1863  float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
1864  if (outputs[c_inter])
1865  outputs[c_inter][p_inter] += val;
1866  if (++c_inter == ch) { c_inter = 0; ++p_inter; }
1867  }
1868  }
1869  }
1870 
1871  total_decode -= effective;
1872  }
1873  *c_inter_p = c_inter;
1874  *p_inter_p = p_inter;
1875  return TRUE;
1876 }

Referenced by decode_residue().

◆ codebook_decode_scalar_raw()

static int codebook_decode_scalar_raw ( vorb f,
Codebook c 
)
static

Definition at line 1599 of file stb_vorbis.c.

1600 {
1601  int i;
1602  prep_huffman(f);
1603 
1604  if (c->codewords == NULL && c->sorted_codewords == NULL)
1605  return -1;
1606 
1607  // cases to use binary search: sorted_codewords && !c->codewords
1608  // sorted_codewords && c->entries > 8
1609  if (c->entries > 8 ? c->sorted_codewords!=NULL : !c->codewords) {
1610  // binary search
1611  uint32 code = bit_reverse(f->acc);
1612  int x=0, n=c->sorted_entries, len;
1613 
1614  while (n > 1) {
1615  // invariant: sc[x] <= code < sc[x+n]
1616  int m = x + (n >> 1);
1617  if (c->sorted_codewords[m] <= code) {
1618  x = m;
1619  n -= (n>>1);
1620  } else {
1621  n >>= 1;
1622  }
1623  }
1624  // x is now the sorted index
1625  if (!c->sparse) x = c->sorted_values[x];
1626  // x is now sorted index if sparse, or symbol otherwise
1627  len = c->codeword_lengths[x];
1628  if (f->valid_bits >= len) {
1629  f->acc >>= len;
1630  f->valid_bits -= len;
1631  return x;
1632  }
1633 
1634  f->valid_bits = 0;
1635  return -1;
1636  }
1637 
1638  // if small, linear search
1639  assert(!c->sparse);
1640  for (i=0; i < c->entries; ++i) {
1641  if (c->codeword_lengths[i] == NO_CODE) continue;
1642  if (c->codewords[i] == (f->acc & ((1 << c->codeword_lengths[i])-1))) {
1643  if (f->valid_bits >= c->codeword_lengths[i]) {
1644  f->acc >>= c->codeword_lengths[i];
1645  f->valid_bits -= c->codeword_lengths[i];
1646  return i;
1647  }
1648  f->valid_bits = 0;
1649  return -1;
1650  }
1651  }
1652 
1654  f->valid_bits = 0;
1655  return -1;
1656 }

◆ codebook_decode_start()

static int codebook_decode_start ( vorb f,
Codebook c 
)
static

Definition at line 1718 of file stb_vorbis.c.

1719 {
1720  int z = -1;
1721 
1722  // type 0 is only legal in a scalar context
1723  if (c->lookup_type == 0)
1725  else {
1726  DECODE_VQ(z,f,c);
1727  if (c->sparse) assert(z < c->sorted_entries);
1728  if (z < 0) { // check for EOP
1729  if (!f->bytes_in_seg)
1730  if (f->last_seg)
1731  return z;
1733  }
1734  }
1735  return z;
1736 }

Referenced by codebook_decode(), and codebook_decode_step().

◆ codebook_decode_step()

static int codebook_decode_step ( vorb f,
Codebook c,
float *  output,
int  len,
int  step 
)
static

Definition at line 1777 of file stb_vorbis.c.

1778 {
1779  int i,z = codebook_decode_start(f,c);
1780  float last = CODEBOOK_ELEMENT_BASE(c);
1781  if (z < 0) return FALSE;
1782  if (len > c->dimensions) len = c->dimensions;
1783 
1784 #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
1785  if (c->lookup_type == 1) {
1786  int div = 1;
1787  for (i=0; i < len; ++i) {
1788  int off = (z / div) % c->lookup_values;
1789  float val = CODEBOOK_ELEMENT_FAST(c,off) + last;
1790  output[i*step] += val;
1791  if (c->sequence_p) last = val;
1792  div *= c->lookup_values;
1793  }
1794  return TRUE;
1795  }
1796 #endif
1797 
1798  z *= c->dimensions;
1799  for (i=0; i < len; ++i) {
1800  float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last;
1801  output[i*step] += val;
1802  if (c->sequence_p) last = val;
1803  }
1804 
1805  return TRUE;
1806 }

Referenced by residue_decode().

◆ compute_accelerated_huffman()

static void compute_accelerated_huffman ( Codebook c)
static

Definition at line 1090 of file stb_vorbis.c.

1091 {
1092  int i, len;
1093  for (i=0; i < FAST_HUFFMAN_TABLE_SIZE; ++i)
1094  c->fast_huffman[i] = -1;
1095 
1096  len = c->sparse ? c->sorted_entries : c->entries;
1098  if (len > 32767) len = 32767; // largest possible value we can encode!
1099  #endif
1100  for (i=0; i < len; ++i) {
1102  uint32 z = c->sparse ? bit_reverse(c->sorted_codewords[i]) : c->codewords[i];
1103  // set table entries for all bit combinations in the higher bits
1104  while (z < FAST_HUFFMAN_TABLE_SIZE) {
1105  c->fast_huffman[z] = i;
1106  z += 1 << c->codeword_lengths[i];
1107  }
1108  }
1109  }
1110 }

Referenced by start_decoder().

◆ compute_bitreverse()

static void compute_bitreverse ( int  n,
uint16 rev 
)
static

Definition at line 1232 of file stb_vorbis.c.

1233 {
1234  int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
1235  int i, n8 = n >> 3;
1236  for (i=0; i < n8; ++i)
1237  rev[i] = (bit_reverse(i) >> (32-ld+3)) << 2;
1238 }

Referenced by init_blocksize().

◆ compute_codewords()

static int compute_codewords ( Codebook c,
uint8 len,
int  n,
uint32 values 
)
static

Definition at line 1042 of file stb_vorbis.c.

1043 {
1044  int i,k,m=0;
1045  uint32 available[32];
1046 
1047  memset(available, 0, sizeof(available));
1048  // find the first entry
1049  for (k=0; k < n; ++k) if (len[k] < NO_CODE) break;
1050  if (k == n) { assert(c->sorted_entries == 0); return TRUE; }
1051  // add to the list
1052  add_entry(c, 0, k, m++, len[k], values);
1053  // add all available leaves
1054  for (i=1; i <= len[k]; ++i)
1055  available[i] = 1U << (32-i);
1056  // note that the above code treats the first case specially,
1057  // but it's really the same as the following code, so they
1058  // could probably be combined (except the initial code is 0,
1059  // and I use 0 in available[] to mean 'empty')
1060  for (i=k+1; i < n; ++i) {
1061  uint32 res;
1062  int z = len[i], y;
1063  if (z == NO_CODE) continue;
1064  // find lowest available leaf (should always be earliest,
1065  // which is what the specification calls for)
1066  // note that this property, and the fact we can never have
1067  // more than one free leaf at a given level, isn't totally
1068  // trivial to prove, but it seems true and the assert never
1069  // fires, so!
1070  while (z > 0 && !available[z]) --z;
1071  if (z == 0) { return FALSE; }
1072  res = available[z];
1073  assert(z >= 0 && z < 32);
1074  available[z] = 0;
1075  add_entry(c, bit_reverse(res), i, m++, len[i], values);
1076  // propogate availability up the tree
1077  if (z != len[i]) {
1078  assert(len[i] >= 0 && len[i] < 32);
1079  for (y=len[i]; y > z; --y) {
1080  assert(available[y] == 0);
1081  available[y] = res + (1 << (32-y));
1082  }
1083  }
1084  }
1085  return TRUE;
1086 }

Referenced by start_decoder().

◆ compute_samples()

static void compute_samples ( int  mask,
short *  output,
int  num_c,
float **  data,
int  d_offset,
int  len 
)
static

Definition at line 5049 of file stb_vorbis.c.

5050 {
5051  #define BUFFER_SIZE 32
5052  float buffer[BUFFER_SIZE];
5053  int i,j,o,n = BUFFER_SIZE;
5054  check_endianness();
5055  for (o = 0; o < len; o += BUFFER_SIZE) {
5056  memset(buffer, 0, sizeof(buffer));
5057  if (o + n > len) n = len - o;
5058  for (j=0; j < num_c; ++j) {
5059  if (channel_position[num_c][j] & mask) {
5060  for (i=0; i < n; ++i)
5061  buffer[i] += data[j][d_offset+o+i];
5062  }
5063  }
5064  for (i=0; i < n; ++i) {
5065  FASTDEF(temp);
5066  int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15);
5067  if ((unsigned int) (v + 32768) > 65535)
5068  v = v < 0 ? -32768 : 32767;
5069  output[o+i] = v;
5070  }
5071  }
5072 }

Referenced by convert_samples_short().

◆ compute_sorted_huffman()

static void compute_sorted_huffman ( Codebook c,
uint8 lengths,
uint32 values 
)
static

Definition at line 1135 of file stb_vorbis.c.

1136 {
1137  int i, len;
1138  // build a list of all the entries
1139  // OPTIMIZATION: don't include the short ones, since they'll be caught by FAST_HUFFMAN.
1140  // this is kind of a frivolous optimization--I don't see any performance improvement,
1141  // but it's like 4 extra lines of code, so.
1142  if (!c->sparse) {
1143  int k = 0;
1144  for (i=0; i < c->entries; ++i)
1145  if (include_in_sort(c, lengths[i]))
1146  c->sorted_codewords[k++] = bit_reverse(c->codewords[i]);
1147  assert(k == c->sorted_entries);
1148  } else {
1149  for (i=0; i < c->sorted_entries; ++i)
1151  }
1152 
1153  qsort(c->sorted_codewords, c->sorted_entries, sizeof(c->sorted_codewords[0]), uint32_compare);
1154  c->sorted_codewords[c->sorted_entries] = 0xffffffff;
1155 
1156  len = c->sparse ? c->sorted_entries : c->entries;
1157  // now we need to indicate how they correspond; we could either
1158  // #1: sort a different data structure that says who they correspond to
1159  // #2: for each sorted entry, search the original list to find who corresponds
1160  // #3: for each original entry, find the sorted entry
1161  // #1 requires extra storage, #2 is slow, #3 can use binary search!
1162  for (i=0; i < len; ++i) {
1163  int huff_len = c->sparse ? lengths[values[i]] : lengths[i];
1164  if (include_in_sort(c,huff_len)) {
1165  uint32 code = bit_reverse(c->codewords[i]);
1166  int x=0, n=c->sorted_entries;
1167  while (n > 1) {
1168  // invariant: sc[x] <= code < sc[x+n]
1169  int m = x + (n >> 1);
1170  if (c->sorted_codewords[m] <= code) {
1171  x = m;
1172  n -= (n>>1);
1173  } else {
1174  n >>= 1;
1175  }
1176  }
1177  assert(c->sorted_codewords[x] == code);
1178  if (c->sparse) {
1179  c->sorted_values[x] = values[i];
1180  c->codeword_lengths[x] = huff_len;
1181  } else {
1182  c->sorted_values[x] = i;
1183  }
1184  }
1185  }
1186 }

Referenced by start_decoder().

◆ compute_stereo_samples()

static void compute_stereo_samples ( short *  output,
int  num_c,
float **  data,
int  d_offset,
int  len 
)
static

Definition at line 5074 of file stb_vorbis.c.

5075 {
5076  #define BUFFER_SIZE 32
5077  float buffer[BUFFER_SIZE];
5078  int i,j,o,n = BUFFER_SIZE >> 1;
5079  // o is the offset in the source data
5080  check_endianness();
5081  for (o = 0; o < len; o += BUFFER_SIZE >> 1) {
5082  // o2 is the offset in the output data
5083  int o2 = o << 1;
5084  memset(buffer, 0, sizeof(buffer));
5085  if (o + n > len) n = len - o;
5086  for (j=0; j < num_c; ++j) {
5087  int m = channel_position[num_c][j] & (PLAYBACK_LEFT | PLAYBACK_RIGHT);
5088  if (m == (PLAYBACK_LEFT | PLAYBACK_RIGHT)) {
5089  for (i=0; i < n; ++i) {
5090  buffer[i*2+0] += data[j][d_offset+o+i];
5091  buffer[i*2+1] += data[j][d_offset+o+i];
5092  }
5093  } else if (m == PLAYBACK_LEFT) {
5094  for (i=0; i < n; ++i) {
5095  buffer[i*2+0] += data[j][d_offset+o+i];
5096  }
5097  } else if (m == PLAYBACK_RIGHT) {
5098  for (i=0; i < n; ++i) {
5099  buffer[i*2+1] += data[j][d_offset+o+i];
5100  }
5101  }
5102  }
5103  for (i=0; i < (n<<1); ++i) {
5104  FASTDEF(temp);
5105  int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15);
5106  if ((unsigned int) (v + 32768) > 65535)
5107  v = v < 0 ? -32768 : 32767;
5108  output[o2+i] = v;
5109  }
5110  }
5111 }

Referenced by convert_channels_short_interleaved().

◆ compute_twiddle_factors()

static void compute_twiddle_factors ( int  n,
float *  A,
float *  B,
float *  C 
)
static

Definition at line 1208 of file stb_vorbis.c.

1209 {
1210  int n4 = n >> 2, n8 = n >> 3;
1211  int k,k2;
1212 
1213  for (k=k2=0; k < n4; ++k,k2+=2) {
1214  A[k2 ] = (float) cos(4*k*M_PI/n);
1215  A[k2+1] = (float) -sin(4*k*M_PI/n);
1216  B[k2 ] = (float) cos((k2+1)*M_PI/n/2) * 0.5f;
1217  B[k2+1] = (float) sin((k2+1)*M_PI/n/2) * 0.5f;
1218  }
1219  for (k=k2=0; k < n8; ++k,k2+=2) {
1220  C[k2 ] = (float) cos(2*(k2+1)*M_PI/n);
1221  C[k2+1] = (float) -sin(2*(k2+1)*M_PI/n);
1222  }
1223 }

Referenced by init_blocksize().

◆ compute_window()

static void compute_window ( int  n,
float *  window 
)
static

Definition at line 1225 of file stb_vorbis.c.

1226 {
1227  int n2 = n >> 1, i;
1228  for (i=0; i < n2; ++i)
1229  window[i] = (float) sin(0.5 * M_PI * square((float) sin((i - 0 + 0.5) / n2 * 0.5 * M_PI)));
1230 }

Referenced by init_blocksize().

◆ convert_channels_short_interleaved()

static void convert_channels_short_interleaved ( int  buf_c,
short *  buffer,
int  data_c,
float **  data,
int  d_offset,
int  len 
)
static

Definition at line 5139 of file stb_vorbis.c.

5140 {
5141  int i;
5142  check_endianness();
5143  if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
5144  assert(buf_c == 2);
5145  for (i=0; i < buf_c; ++i)
5146  compute_stereo_samples(buffer, data_c, data, d_offset, len);
5147  } else {
5148  int limit = buf_c < data_c ? buf_c : data_c;
5149  int j;
5150  for (j=0; j < len; ++j) {
5151  for (i=0; i < limit; ++i) {
5152  FASTDEF(temp);
5153  float f = data[i][d_offset+j];
5154  int v = FAST_SCALED_FLOAT_TO_INT(temp, f,15);//data[i][d_offset+j],15);
5155  if ((unsigned int) (v + 32768) > 65535)
5156  v = v < 0 ? -32768 : 32767;
5157  *buffer++ = v;
5158  }
5159  for ( ; i < buf_c; ++i)
5160  *buffer++ = 0;
5161  }
5162  }
5163 }

Referenced by stb_vorbis_get_frame_short_interleaved(), and stb_vorbis_get_samples_short_interleaved().

◆ convert_samples_short()

static void convert_samples_short ( int  buf_c,
short **  buffer,
int  b_offset,
int  data_c,
float **  data,
int  d_offset,
int  samples 
)
static

Definition at line 5113 of file stb_vorbis.c.

5114 {
5115  int i;
5116  if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
5117  static int channel_selector[3][2] = { {0}, {PLAYBACK_MONO}, {PLAYBACK_LEFT, PLAYBACK_RIGHT} };
5118  for (i=0; i < buf_c; ++i)
5119  compute_samples(channel_selector[buf_c][i], buffer[i]+b_offset, data_c, data, d_offset, samples);
5120  } else {
5121  int limit = buf_c < data_c ? buf_c : data_c;
5122  for (i=0; i < limit; ++i)
5123  copy_samples(buffer[i]+b_offset, data[i]+d_offset, samples);
5124  for ( ; i < buf_c; ++i)
5125  memset(buffer[i]+b_offset, 0, sizeof(short) * samples);
5126  }
5127 }

Referenced by stb_vorbis_get_frame_short(), and stb_vorbis_get_samples_short().

◆ copy_samples()

static void copy_samples ( short *  dest,
float *  src,
int  len 
)
static

Definition at line 5036 of file stb_vorbis.c.

5037 {
5038  int i;
5039  check_endianness();
5040  for (i=0; i < len; ++i) {
5041  FASTDEF(temp);
5042  int v = FAST_SCALED_FLOAT_TO_INT(temp, src[i],15);
5043  if ((unsigned int) (v + 32768) > 65535)
5044  v = v < 0 ? -32768 : 32767;
5045  dest[i] = v;
5046  }
5047 }

Referenced by convert_samples_short().

◆ crc32_init()

static void crc32_init ( void  )
static

Definition at line 948 of file stb_vorbis.c.

949 {
950  int i,j;
951  uint32 s;
952  for(i=0; i < 256; i++) {
953  for (s=(uint32) i << 24, j=0; j < 8; ++j)
954  s = (s << 1) ^ (s >= (1U<<31) ? CRC32_POLY : 0);
955  crc_table[i] = s;
956  }
957 }

Referenced by start_decoder().

◆ crc32_update()

static __forceinline uint32 crc32_update ( uint32  crc,
uint8  byte 
)
static

Definition at line 959 of file stb_vorbis.c.

960 {
961  return (crc << 8) ^ crc_table[byte ^ (crc >> 24)];
962 }

Referenced by vorbis_find_page(), and vorbis_search_for_page_pushdata().

◆ decode_residue()

static void decode_residue ( vorb f,
float *  residue_buffers[],
int  ch,
int  n,
int  rn,
uint8 do_not_decode 
)
static

Definition at line 2045 of file stb_vorbis.c.

2046 {
2047  int i,j,pass;
2048  Residue *r = f->residue_config + rn;
2049  int rtype = f->residue_types[rn];
2050  int c = r->classbook;
2051  int classwords = f->codebooks[c].dimensions;
2052  int n_read = r->end - r->begin;
2053  int part_read = n_read / r->part_size;
2054  int temp_alloc_point = temp_alloc_save(f);
2055  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2056  uint8 ***part_classdata = (uint8 ***) temp_block_array(f,f->channels, part_read * sizeof(**part_classdata));
2057  #else
2058  int **classifications = (int **) temp_block_array(f,f->channels, part_read * sizeof(**classifications));
2059  #endif
2060 
2061  CHECK(f);
2062 
2063  for (i=0; i < ch; ++i)
2064  if (!do_not_decode[i])
2065  memset(residue_buffers[i], 0, sizeof(float) * n);
2066 
2067  if (rtype == 2 && ch != 1) {
2068  for (j=0; j < ch; ++j)
2069  if (!do_not_decode[j])
2070  break;
2071  if (j == ch)
2072  goto done;
2073 
2074  for (pass=0; pass < 8; ++pass) {
2075  int pcount = 0, class_set = 0;
2076  if (ch == 2) {
2077  while (pcount < part_read) {
2078  int z = r->begin + pcount*r->part_size;
2079  int c_inter = (z & 1), p_inter = z>>1;
2080  if (pass == 0) {
2081  Codebook *c = f->codebooks+r->classbook;
2082  int q;
2083  DECODE(q,f,c);
2084  if (q == EOP) goto done;
2085  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2086  part_classdata[0][class_set] = r->classdata[q];
2087  #else
2088  for (i=classwords-1; i >= 0; --i) {
2089  classifications[0][i+pcount] = q % r->classifications;
2090  q /= r->classifications;
2091  }
2092  #endif
2093  }
2094  for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2095  int z = r->begin + pcount*r->part_size;
2096  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2097  int c = part_classdata[0][class_set][i];
2098  #else
2099  int c = classifications[0][pcount];
2100  #endif
2101  int b = r->residue_books[c][pass];
2102  if (b >= 0) {
2103  Codebook *book = f->codebooks + b;
2104  #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK
2105  if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
2106  goto done;
2107  #else
2108  // saves 1%
2109  if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
2110  goto done;
2111  #endif
2112  } else {
2113  z += r->part_size;
2114  c_inter = z & 1;
2115  p_inter = z >> 1;
2116  }
2117  }
2118  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2119  ++class_set;
2120  #endif
2121  }
2122  } else if (ch == 1) {
2123  while (pcount < part_read) {
2124  int z = r->begin + pcount*r->part_size;
2125  int c_inter = 0, p_inter = z;
2126  if (pass == 0) {
2127  Codebook *c = f->codebooks+r->classbook;
2128  int q;
2129  DECODE(q,f,c);
2130  if (q == EOP) goto done;
2131  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2132  part_classdata[0][class_set] = r->classdata[q];
2133  #else
2134  for (i=classwords-1; i >= 0; --i) {
2135  classifications[0][i+pcount] = q % r->classifications;
2136  q /= r->classifications;
2137  }
2138  #endif
2139  }
2140  for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2141  int z = r->begin + pcount*r->part_size;
2142  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2143  int c = part_classdata[0][class_set][i];
2144  #else
2145  int c = classifications[0][pcount];
2146  #endif
2147  int b = r->residue_books[c][pass];
2148  if (b >= 0) {
2149  Codebook *book = f->codebooks + b;
2150  if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
2151  goto done;
2152  } else {
2153  z += r->part_size;
2154  c_inter = 0;
2155  p_inter = z;
2156  }
2157  }
2158  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2159  ++class_set;
2160  #endif
2161  }
2162  } else {
2163  while (pcount < part_read) {
2164  int z = r->begin + pcount*r->part_size;
2165  int c_inter = z % ch, p_inter = z/ch;
2166  if (pass == 0) {
2167  Codebook *c = f->codebooks+r->classbook;
2168  int q;
2169  DECODE(q,f,c);
2170  if (q == EOP) goto done;
2171  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2172  part_classdata[0][class_set] = r->classdata[q];
2173  #else
2174  for (i=classwords-1; i >= 0; --i) {
2175  classifications[0][i+pcount] = q % r->classifications;
2176  q /= r->classifications;
2177  }
2178  #endif
2179  }
2180  for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2181  int z = r->begin + pcount*r->part_size;
2182  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2183  int c = part_classdata[0][class_set][i];
2184  #else
2185  int c = classifications[0][pcount];
2186  #endif
2187  int b = r->residue_books[c][pass];
2188  if (b >= 0) {
2189  Codebook *book = f->codebooks + b;
2190  if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size))
2191  goto done;
2192  } else {
2193  z += r->part_size;
2194  c_inter = z % ch;
2195  p_inter = z / ch;
2196  }
2197  }
2198  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2199  ++class_set;
2200  #endif
2201  }
2202  }
2203  }
2204  goto done;
2205  }
2206  CHECK(f);
2207 
2208  for (pass=0; pass < 8; ++pass) {
2209  int pcount = 0, class_set=0;
2210  while (pcount < part_read) {
2211  if (pass == 0) {
2212  for (j=0; j < ch; ++j) {
2213  if (!do_not_decode[j]) {
2214  Codebook *c = f->codebooks+r->classbook;
2215  int temp;
2216  DECODE(temp,f,c);
2217  if (temp == EOP) goto done;
2218  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2219  part_classdata[j][class_set] = r->classdata[temp];
2220  #else
2221  for (i=classwords-1; i >= 0; --i) {
2222  classifications[j][i+pcount] = temp % r->classifications;
2223  temp /= r->classifications;
2224  }
2225  #endif
2226  }
2227  }
2228  }
2229  for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) {
2230  for (j=0; j < ch; ++j) {
2231  if (!do_not_decode[j]) {
2232  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2233  int c = part_classdata[j][class_set][i];
2234  #else
2235  int c = classifications[j][pcount];
2236  #endif
2237  int b = r->residue_books[c][pass];
2238  if (b >= 0) {
2239  float *target = residue_buffers[j];
2240  int offset = r->begin + pcount * r->part_size;
2241  int n = r->part_size;
2242  Codebook *book = f->codebooks + b;
2243  if (!residue_decode(f, book, target, offset, n, rtype))
2244  goto done;
2245  }
2246  }
2247  }
2248  }
2249  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2250  ++class_set;
2251  #endif
2252  }
2253  }
2254  done:
2255  CHECK(f);
2256  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
2257  temp_free(f,part_classdata);
2258  #else
2259  temp_free(f,classifications);
2260  #endif
2261  temp_alloc_restore(f,temp_alloc_point);
2262 }

Referenced by vorbis_decode_packet_rest().

◆ do_floor()

static int do_floor ( vorb f,
Mapping map,
int  i,
int  n,
float *  target,
YTYPE finalY,
uint8 step2_flag 
)
static

Definition at line 3052 of file stb_vorbis.c.

3053 {
3054  int n2 = n >> 1;
3055  int s = map->chan[i].mux, floor;
3056  floor = map->submap_floor[s];
3057  if (f->floor_types[floor] == 0) {
3058  return error(f, VORBIS_invalid_stream);
3059  } else {
3060  Floor1 *g = &f->floor_config[floor].floor1;
3061  int j,q;
3062  int lx = 0, ly = finalY[0] * g->floor1_multiplier;
3063  for (q=1; q < g->values; ++q) {
3064  j = g->sorted_order[q];
3065  #ifndef STB_VORBIS_NO_DEFER_FLOOR
3066  if (finalY[j] >= 0)
3067  #else
3068  if (step2_flag[j])
3069  #endif
3070  {
3071  int hy = finalY[j] * g->floor1_multiplier;
3072  int hx = g->Xlist[j];
3073  if (lx != hx)
3074  draw_line(target, lx,ly, hx,hy, n2);
3075  CHECK(f);
3076  lx = hx, ly = hy;
3077  }
3078  }
3079  if (lx < n2) {
3080  // optimization of: draw_line(target, lx,ly, n,ly, n2);
3081  for (j=lx; j < n2; ++j)
3083  CHECK(f);
3084  }
3085  }
3086  return TRUE;
3087 }

Referenced by vorbis_decode_packet_rest().

◆ draw_line()

static __forceinline void draw_line ( float *  output,
int  x0,
int  y0,
int  x1,
int  y1,
int  n 
)
static

Definition at line 1977 of file stb_vorbis.c.

1978 {
1979  int dy = y1 - y0;
1980  int adx = x1 - x0;
1981  int ady = abs(dy);
1982  int base;
1983  int x=x0,y=y0;
1984  int err = 0;
1985  int sy;
1986 
1987 #ifdef STB_VORBIS_DIVIDE_TABLE
1988  if (adx < DIVTAB_DENOM && ady < DIVTAB_NUMER) {
1989  if (dy < 0) {
1990  base = -integer_divide_table[ady][adx];
1991  sy = base-1;
1992  } else {
1993  base = integer_divide_table[ady][adx];
1994  sy = base+1;
1995  }
1996  } else {
1997  base = dy / adx;
1998  if (dy < 0)
1999  sy = base - 1;
2000  else
2001  sy = base+1;
2002  }
2003 #else
2004  base = dy / adx;
2005  if (dy < 0)
2006  sy = base - 1;
2007  else
2008  sy = base+1;
2009 #endif
2010  ady -= abs(base) * adx;
2011  if (x1 > n) x1 = n;
2012  if (x < x1) {
2013  LINE_OP(output[x], inverse_db_table[y]);
2014  for (++x; x < x1; ++x) {
2015  err += ady;
2016  if (err >= adx) {
2017  err -= adx;
2018  y += sy;
2019  } else
2020  y += base;
2021  LINE_OP(output[x], inverse_db_table[y]);
2022  }
2023  }
2024 }

Referenced by do_floor().

◆ error()

◆ float32_unpack()

static float float32_unpack ( uint32  x)
static

Definition at line 1013 of file stb_vorbis.c.

1014 {
1015  // from the specification
1016  uint32 mantissa = x & 0x1fffff;
1017  uint32 sign = x & 0x80000000;
1018  uint32 exp = (x & 0x7fe00000) >> 21;
1019  double res = sign ? -(double)mantissa : (double)mantissa;
1020  return (float) ldexp((float)res, exp-788);
1021 }

Referenced by start_decoder().

◆ flush_packet()

static void flush_packet ( vorb f)
static

Definition at line 1536 of file stb_vorbis.c.

1537 {
1538  while (get8_packet_raw(f) != EOP);
1539 }

Referenced by start_decoder(), stb_vorbis_seek_frame(), and vorbis_decode_packet_rest().

◆ get32()

static uint32 get32 ( vorb f)
static

Definition at line 1307 of file stb_vorbis.c.

1308 {
1309  uint32 x;
1310  x = get8(f);
1311  x += get8(f) << 8;
1312  x += get8(f) << 16;
1313  x += (uint32) get8(f) << 24;
1314  return x;
1315 }

Referenced by start_decoder(), start_page_no_capturepattern(), and stb_vorbis_stream_length_in_samples().

◆ get8()

static uint8 get8 ( vorb z)
static

Definition at line 1291 of file stb_vorbis.c.

1292 {
1293  if (USE_MEMORY(z)) {
1294  if (z->stream >= z->stream_end) { z->eof = TRUE; return 0; }
1295  return *z->stream++;
1296  }
1297 
1298  #ifndef STB_VORBIS_NO_STDIO
1299  {
1300  int c = fgetc(z->f);
1301  if (c == EOF) { z->eof = TRUE; return 0; }
1302  return c;
1303  }
1304  #endif
1305 }

Referenced by capture_pattern(), get32(), get8_packet_raw(), maybe_start_packet(), start_decoder(), start_page_no_capturepattern(), and vorbis_find_page().

◆ get8_packet()

static int get8_packet ( vorb f)
static

Definition at line 1529 of file stb_vorbis.c.

1530 {
1531  int x = get8_packet_raw(f);
1532  f->valid_bits = 0;
1533  return x;
1534 }

Referenced by start_decoder(), stb_vorbis_decode_frame_pushdata(), and vorbis_decode_initial().

◆ get8_packet_raw()

static int get8_packet_raw ( vorb f)
static

Definition at line 1517 of file stb_vorbis.c.

1518 {
1519  if (!f->bytes_in_seg) { // CLANG!
1520  if (f->last_seg) return EOP;
1521  else if (!next_segment(f)) return EOP;
1522  }
1523  assert(f->bytes_in_seg > 0);
1524  --f->bytes_in_seg;
1525  ++f->packet_bytes;
1526  return get8(f);
1527 }

Referenced by flush_packet(), get8_packet(), get_bits(), and prep_huffman().

◆ get_bits()

static uint32 get_bits ( vorb f,
int  n 
)
static

Definition at line 1543 of file stb_vorbis.c.

1544 {
1545  uint32 z;
1546 
1547  if (f->valid_bits < 0) return 0;
1548  if (f->valid_bits < n) {
1549  if (n > 24) {
1550  // the accumulator technique below would not work correctly in this case
1551  z = get_bits(f, 24);
1552  z += get_bits(f, n-24) << 24;
1553  return z;
1554  }
1555  if (f->valid_bits == 0) f->acc = 0;
1556  while (f->valid_bits < n) {
1557  int z = get8_packet_raw(f);
1558  if (z == EOP) {
1559  f->valid_bits = INVALID_BITS;
1560  return 0;
1561  }
1562  f->acc += z << f->valid_bits;
1563  f->valid_bits += 8;
1564  }
1565  }
1566  if (f->valid_bits < 0) return 0;
1567  z = f->acc & ((1 << n)-1);
1568  f->acc >>= n;
1569  f->valid_bits -= n;
1570  return z;
1571 }

Referenced by start_decoder(), vorbis_decode_initial(), and vorbis_decode_packet_rest().

◆ get_seek_page_info()

static int get_seek_page_info ( stb_vorbis f,
ProbedPage z 
)
static

Definition at line 4528 of file stb_vorbis.c.

4529 {
4530  uint8 header[27], lacing[255];
4531  int i,len;
4532 
4533  // record where the page starts
4534  z->page_start = stb_vorbis_get_file_offset(f);
4535 
4536  // parse the header
4537  getn(f, header, 27);
4538  if (header[0] != 'O' || header[1] != 'g' || header[2] != 'g' || header[3] != 'S')
4539  return 0;
4540  getn(f, lacing, header[26]);
4541 
4542  // determine the length of the payload
4543  len = 0;
4544  for (i=0; i < header[26]; ++i)
4545  len += lacing[i];
4546 
4547  // this implies where the page ends
4548  z->page_end = z->page_start + 27 + header[26] + len;
4549 
4550  // read the last-decoded sample out of the data
4551  z->last_decoded_sample = header[6] + (header[7] << 8) + (header[8] << 16) + (header[9] << 24);
4552 
4553  // restore file state to where we were
4554  set_file_offset(f, z->page_start);
4555  return 1;
4556 }

Referenced by seek_to_sample_coarse().

◆ get_window()

static float* get_window ( vorb f,
int  len 
)
static

Definition at line 3038 of file stb_vorbis.c.

3039 {
3040  len <<= 1;
3041  if (len == f->blocksize_0) return f->window[0];
3042  if (len == f->blocksize_1) return f->window[1];
3043  assert(0);
3044  return NULL;
3045 }

Referenced by vorbis_finish_frame().

◆ getn()

static int getn ( vorb z,
uint8 data,
int  n 
)
static

Definition at line 1317 of file stb_vorbis.c.

1318 {
1319  if (USE_MEMORY(z)) {
1320  if (z->stream+n > z->stream_end) { z->eof = 1; return 0; }
1321  memcpy(data, z->stream, n);
1322  z->stream += n;
1323  return 1;
1324  }
1325 
1326  #ifndef STB_VORBIS_NO_STDIO
1327  if (fread(data, n, 1, z->f) == 1)
1328  return 1;
1329  else {
1330  z->eof = 1;
1331  return 0;
1332  }
1333  #endif
1334 }

Referenced by get_seek_page_info(), start_decoder(), start_page_no_capturepattern(), and stb_vorbis_stream_length_in_samples().

◆ go_to_page_before()

static int go_to_page_before ( stb_vorbis f,
unsigned int  limit_offset 
)
static

Definition at line 4560 of file stb_vorbis.c.

4561 {
4562  unsigned int previous_safe, end;
4563 
4564  // now we want to seek back 64K from the limit
4565  if (limit_offset >= 65536 && limit_offset-65536 >= f->first_audio_page_offset)
4566  previous_safe = limit_offset - 65536;
4567  else
4568  previous_safe = f->first_audio_page_offset;
4569 
4570  set_file_offset(f, previous_safe);
4571 
4572  while (vorbis_find_page(f, &end, NULL)) {
4573  if (end >= limit_offset && stb_vorbis_get_file_offset(f) < limit_offset)
4574  return 1;
4575  set_file_offset(f, end);
4576  }
4577 
4578  return 0;
4579 }

Referenced by seek_to_sample_coarse().

◆ ilog()

static int ilog ( int32  n)
static

Definition at line 983 of file stb_vorbis.c.

984 {
985  static signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 };
986 
987  if (n < 0) return 0; // signed n returns 0
988 
989  // 2 compares if n < 16, 3 compares otherwise (4 if signed or n > 1<<29)
990  if (n < (1 << 14))
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 return 30 + log2_4[n >> 30];
999 }

Referenced by compute_bitreverse(), inverse_mdct(), peek_decode_initial(), start_decoder(), vorbis_decode_initial(), and vorbis_decode_packet_rest().

◆ imdct_step3_inner_r_loop()

static void imdct_step3_inner_r_loop ( int  lim,
float *  e,
int  d0,
int  k_off,
float *  A,
int  k1 
)
static

Definition at line 2431 of file stb_vorbis.c.

2432 {
2433  int i;
2434  float k00_20, k01_21;
2435 
2436  float *e0 = e + d0;
2437  float *e2 = e0 + k_off;
2438 
2439  for (i=lim >> 2; i > 0; --i) {
2440  k00_20 = e0[-0] - e2[-0];
2441  k01_21 = e0[-1] - e2[-1];
2442  e0[-0] += e2[-0];//e0[-0] = e0[-0] + e2[-0];
2443  e0[-1] += e2[-1];//e0[-1] = e0[-1] + e2[-1];
2444  e2[-0] = (k00_20)*A[0] - (k01_21) * A[1];
2445  e2[-1] = (k01_21)*A[0] + (k00_20) * A[1];
2446 
2447  A += k1;
2448 
2449  k00_20 = e0[-2] - e2[-2];
2450  k01_21 = e0[-3] - e2[-3];
2451  e0[-2] += e2[-2];//e0[-2] = e0[-2] + e2[-2];
2452  e0[-3] += e2[-3];//e0[-3] = e0[-3] + e2[-3];
2453  e2[-2] = (k00_20)*A[0] - (k01_21) * A[1];
2454  e2[-3] = (k01_21)*A[0] + (k00_20) * A[1];
2455 
2456  A += k1;
2457 
2458  k00_20 = e0[-4] - e2[-4];
2459  k01_21 = e0[-5] - e2[-5];
2460  e0[-4] += e2[-4];//e0[-4] = e0[-4] + e2[-4];
2461  e0[-5] += e2[-5];//e0[-5] = e0[-5] + e2[-5];
2462  e2[-4] = (k00_20)*A[0] - (k01_21) * A[1];
2463  e2[-5] = (k01_21)*A[0] + (k00_20) * A[1];
2464 
2465  A += k1;
2466 
2467  k00_20 = e0[-6] - e2[-6];
2468  k01_21 = e0[-7] - e2[-7];
2469  e0[-6] += e2[-6];//e0[-6] = e0[-6] + e2[-6];
2470  e0[-7] += e2[-7];//e0[-7] = e0[-7] + e2[-7];
2471  e2[-6] = (k00_20)*A[0] - (k01_21) * A[1];
2472  e2[-7] = (k01_21)*A[0] + (k00_20) * A[1];
2473 
2474  e0 -= 8;
2475  e2 -= 8;
2476 
2477  A += k1;
2478  }
2479 }

Referenced by inverse_mdct().

◆ imdct_step3_inner_s_loop()

static void imdct_step3_inner_s_loop ( int  n,
float *  e,
int  i_off,
int  k_off,
float *  A,
int  a_off,
int  k0 
)
static

Definition at line 2481 of file stb_vorbis.c.

2482 {
2483  int i;
2484  float A0 = A[0];
2485  float A1 = A[0+1];
2486  float A2 = A[0+a_off];
2487  float A3 = A[0+a_off+1];
2488  float A4 = A[0+a_off*2+0];
2489  float A5 = A[0+a_off*2+1];
2490  float A6 = A[0+a_off*3+0];
2491  float A7 = A[0+a_off*3+1];
2492 
2493  float k00,k11;
2494 
2495  float *ee0 = e +i_off;
2496  float *ee2 = ee0+k_off;
2497 
2498  for (i=n; i > 0; --i) {
2499  k00 = ee0[ 0] - ee2[ 0];
2500  k11 = ee0[-1] - ee2[-1];
2501  ee0[ 0] = ee0[ 0] + ee2[ 0];
2502  ee0[-1] = ee0[-1] + ee2[-1];
2503  ee2[ 0] = (k00) * A0 - (k11) * A1;
2504  ee2[-1] = (k11) * A0 + (k00) * A1;
2505 
2506  k00 = ee0[-2] - ee2[-2];
2507  k11 = ee0[-3] - ee2[-3];
2508  ee0[-2] = ee0[-2] + ee2[-2];
2509  ee0[-3] = ee0[-3] + ee2[-3];
2510  ee2[-2] = (k00) * A2 - (k11) * A3;
2511  ee2[-3] = (k11) * A2 + (k00) * A3;
2512 
2513  k00 = ee0[-4] - ee2[-4];
2514  k11 = ee0[-5] - ee2[-5];
2515  ee0[-4] = ee0[-4] + ee2[-4];
2516  ee0[-5] = ee0[-5] + ee2[-5];
2517  ee2[-4] = (k00) * A4 - (k11) * A5;
2518  ee2[-5] = (k11) * A4 + (k00) * A5;
2519 
2520  k00 = ee0[-6] - ee2[-6];
2521  k11 = ee0[-7] - ee2[-7];
2522  ee0[-6] = ee0[-6] + ee2[-6];
2523  ee0[-7] = ee0[-7] + ee2[-7];
2524  ee2[-6] = (k00) * A6 - (k11) * A7;
2525  ee2[-7] = (k11) * A6 + (k00) * A7;
2526 
2527  ee0 -= k0;
2528  ee2 -= k0;
2529  }
2530 }

Referenced by inverse_mdct().

◆ imdct_step3_inner_s_loop_ld654()

static void imdct_step3_inner_s_loop_ld654 ( int  n,
float *  e,
int  i_off,
float *  A,
int  base_n 
)
static

Definition at line 2564 of file stb_vorbis.c.

2565 {
2566  int a_off = base_n >> 3;
2567  float A2 = A[0+a_off];
2568  float *z = e + i_off;
2569  float *base = z - 16 * n;
2570 
2571  while (z > base) {
2572  float k00,k11;
2573 
2574  k00 = z[-0] - z[-8];
2575  k11 = z[-1] - z[-9];
2576  z[-0] = z[-0] + z[-8];
2577  z[-1] = z[-1] + z[-9];
2578  z[-8] = k00;
2579  z[-9] = k11 ;
2580 
2581  k00 = z[ -2] - z[-10];
2582  k11 = z[ -3] - z[-11];
2583  z[ -2] = z[ -2] + z[-10];
2584  z[ -3] = z[ -3] + z[-11];
2585  z[-10] = (k00+k11) * A2;
2586  z[-11] = (k11-k00) * A2;
2587 
2588  k00 = z[-12] - z[ -4]; // reverse to avoid a unary negation
2589  k11 = z[ -5] - z[-13];
2590  z[ -4] = z[ -4] + z[-12];
2591  z[ -5] = z[ -5] + z[-13];
2592  z[-12] = k11;
2593  z[-13] = k00;
2594 
2595  k00 = z[-14] - z[ -6]; // reverse to avoid a unary negation
2596  k11 = z[ -7] - z[-15];
2597  z[ -6] = z[ -6] + z[-14];
2598  z[ -7] = z[ -7] + z[-15];
2599  z[-14] = (k00+k11) * A2;
2600  z[-15] = (k00-k11) * A2;
2601 
2602  iter_54(z);
2603  iter_54(z-8);
2604  z -= 16;
2605  }
2606 }

Referenced by inverse_mdct().

◆ imdct_step3_iter0_loop()

static void imdct_step3_iter0_loop ( int  n,
float *  e,
int  i_off,
int  k_off,
float *  A 
)
static

Definition at line 2386 of file stb_vorbis.c.

2387 {
2388  float *ee0 = e + i_off;
2389  float *ee2 = ee0 + k_off;
2390  int i;
2391 
2392  assert((n & 3) == 0);
2393  for (i=(n>>2); i > 0; --i) {
2394  float k00_20, k01_21;
2395  k00_20 = ee0[ 0] - ee2[ 0];
2396  k01_21 = ee0[-1] - ee2[-1];
2397  ee0[ 0] += ee2[ 0];//ee0[ 0] = ee0[ 0] + ee2[ 0];
2398  ee0[-1] += ee2[-1];//ee0[-1] = ee0[-1] + ee2[-1];
2399  ee2[ 0] = k00_20 * A[0] - k01_21 * A[1];
2400  ee2[-1] = k01_21 * A[0] + k00_20 * A[1];
2401  A += 8;
2402 
2403  k00_20 = ee0[-2] - ee2[-2];
2404  k01_21 = ee0[-3] - ee2[-3];
2405  ee0[-2] += ee2[-2];//ee0[-2] = ee0[-2] + ee2[-2];
2406  ee0[-3] += ee2[-3];//ee0[-3] = ee0[-3] + ee2[-3];
2407  ee2[-2] = k00_20 * A[0] - k01_21 * A[1];
2408  ee2[-3] = k01_21 * A[0] + k00_20 * A[1];
2409  A += 8;
2410 
2411  k00_20 = ee0[-4] - ee2[-4];
2412  k01_21 = ee0[-5] - ee2[-5];
2413  ee0[-4] += ee2[-4];//ee0[-4] = ee0[-4] + ee2[-4];
2414  ee0[-5] += ee2[-5];//ee0[-5] = ee0[-5] + ee2[-5];
2415  ee2[-4] = k00_20 * A[0] - k01_21 * A[1];
2416  ee2[-5] = k01_21 * A[0] + k00_20 * A[1];
2417  A += 8;
2418 
2419  k00_20 = ee0[-6] - ee2[-6];
2420  k01_21 = ee0[-7] - ee2[-7];
2421  ee0[-6] += ee2[-6];//ee0[-6] = ee0[-6] + ee2[-6];
2422  ee0[-7] += ee2[-7];//ee0[-7] = ee0[-7] + ee2[-7];
2423  ee2[-6] = k00_20 * A[0] - k01_21 * A[1];
2424  ee2[-7] = k01_21 * A[0] + k00_20 * A[1];
2425  A += 8;
2426  ee0 -= 8;
2427  ee2 -= 8;
2428  }
2429 }

Referenced by inverse_mdct().

◆ include_in_sort()

static int include_in_sort ( Codebook c,
uint8  len 
)
static

Definition at line 1125 of file stb_vorbis.c.

1126 {
1127  if (c->sparse) { assert(len != NO_CODE); return TRUE; }
1128  if (len == NO_CODE) return FALSE;
1129  if (len > STB_VORBIS_FAST_HUFFMAN_LENGTH) return TRUE;
1130  return FALSE;
1131 }

Referenced by compute_sorted_huffman().

◆ init_blocksize()

static int init_blocksize ( vorb f,
int  b,
int  n 
)
static

Definition at line 1240 of file stb_vorbis.c.

1241 {
1242  int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3;
1243  f->A[b] = (float *) setup_malloc(f, sizeof(float) * n2);
1244  f->B[b] = (float *) setup_malloc(f, sizeof(float) * n2);
1245  f->C[b] = (float *) setup_malloc(f, sizeof(float) * n4);
1246  if (!f->A[b] || !f->B[b] || !f->C[b]) return error(f, VORBIS_outofmem);
1247  compute_twiddle_factors(n, f->A[b], f->B[b], f->C[b]);
1248  f->window[b] = (float *) setup_malloc(f, sizeof(float) * n2);
1249  if (!f->window[b]) return error(f, VORBIS_outofmem);
1250  compute_window(n, f->window[b]);
1251  f->bit_reverse[b] = (uint16 *) setup_malloc(f, sizeof(uint16) * n8);
1252  if (!f->bit_reverse[b]) return error(f, VORBIS_outofmem);
1253  compute_bitreverse(n, f->bit_reverse[b]);
1254  return TRUE;
1255 }

Referenced by start_decoder().

◆ inverse_mdct()

static void inverse_mdct ( float *  buffer,
int  n,
vorb f,
int  blocktype 
)
static

Definition at line 2608 of file stb_vorbis.c.

2609 {
2610  int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l;
2611  int ld;
2612  // @OPTIMIZE: reduce register pressure by using fewer variables?
2613  int save_point = temp_alloc_save(f);
2614  float *buf2 = (float *) temp_alloc(f, n2 * sizeof(*buf2));
2615  float *u=NULL,*v=NULL;
2616  // twiddle factors
2617  float *A = f->A[blocktype];
2618 
2619  // IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio"
2620  // See notes about bugs in that paper in less-optimal implementation 'inverse_mdct_old' after this function.
2621 
2622  // kernel from paper
2623 
2624 
2625  // merged:
2626  // copy and reflect spectral data
2627  // step 0
2628 
2629  // note that it turns out that the items added together during
2630  // this step are, in fact, being added to themselves (as reflected
2631  // by step 0). inexplicable inefficiency! this became obvious
2632  // once I combined the passes.
2633 
2634  // so there's a missing 'times 2' here (for adding X to itself).
2635  // this propogates through linearly to the end, where the numbers
2636  // are 1/2 too small, and need to be compensated for.
2637 
2638  {
2639  float *d,*e, *AA, *e_stop;
2640  d = &buf2[n2-2];
2641  AA = A;
2642  e = &buffer[0];
2643  e_stop = &buffer[n2];
2644  while (e != e_stop) {
2645  d[1] = (e[0] * AA[0] - e[2]*AA[1]);
2646  d[0] = (e[0] * AA[1] + e[2]*AA[0]);
2647  d -= 2;
2648  AA += 2;
2649  e += 4;
2650  }
2651 
2652  e = &buffer[n2-3];
2653  while (d >= buf2) {
2654  d[1] = (-e[2] * AA[0] - -e[0]*AA[1]);
2655  d[0] = (-e[2] * AA[1] + -e[0]*AA[0]);
2656  d -= 2;
2657  AA += 2;
2658  e -= 4;
2659  }
2660  }
2661 
2662  // now we use symbolic names for these, so that we can
2663  // possibly swap their meaning as we change which operations
2664  // are in place
2665 
2666  u = buffer;
2667  v = buf2;
2668 
2669  // step 2 (paper output is w, now u)
2670  // this could be in place, but the data ends up in the wrong
2671  // place... _somebody_'s got to swap it, so this is nominated
2672  {
2673  float *AA = &A[n2-8];
2674  float *d0,*d1, *e0, *e1;
2675 
2676  e0 = &v[n4];
2677  e1 = &v[0];
2678 
2679  d0 = &u[n4];
2680  d1 = &u[0];
2681 
2682  while (AA >= A) {
2683  float v40_20, v41_21;
2684 
2685  v41_21 = e0[1] - e1[1];
2686  v40_20 = e0[0] - e1[0];
2687  d0[1] = e0[1] + e1[1];
2688  d0[0] = e0[0] + e1[0];
2689  d1[1] = v41_21*AA[4] - v40_20*AA[5];
2690  d1[0] = v40_20*AA[4] + v41_21*AA[5];
2691 
2692  v41_21 = e0[3] - e1[3];
2693  v40_20 = e0[2] - e1[2];
2694  d0[3] = e0[3] + e1[3];
2695  d0[2] = e0[2] + e1[2];
2696  d1[3] = v41_21*AA[0] - v40_20*AA[1];
2697  d1[2] = v40_20*AA[0] + v41_21*AA[1];
2698 
2699  AA -= 8;
2700 
2701  d0 += 4;
2702  d1 += 4;
2703  e0 += 4;
2704  e1 += 4;
2705  }
2706  }
2707 
2708  // step 3
2709  ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
2710 
2711  // optimized step 3:
2712 
2713  // the original step3 loop can be nested r inside s or s inside r;
2714  // it's written originally as s inside r, but this is dumb when r
2715  // iterates many times, and s few. So I have two copies of it and
2716  // switch between them halfway.
2717 
2718  // this is iteration 0 of step 3
2719  imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*0, -(n >> 3), A);
2720  imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*1, -(n >> 3), A);
2721 
2722  // this is iteration 1 of step 3
2723  imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*0, -(n >> 4), A, 16);
2724  imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*1, -(n >> 4), A, 16);
2725  imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*2, -(n >> 4), A, 16);
2726  imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*3, -(n >> 4), A, 16);
2727 
2728  l=2;
2729  for (; l < (ld-3)>>1; ++l) {
2730  int k0 = n >> (l+2), k0_2 = k0>>1;
2731  int lim = 1 << (l+1);
2732  int i;
2733  for (i=0; i < lim; ++i)
2734  imdct_step3_inner_r_loop(n >> (l+4), u, n2-1 - k0*i, -k0_2, A, 1 << (l+3));
2735  }
2736 
2737  for (; l < ld-6; ++l) {
2738  int k0 = n >> (l+2), k1 = 1 << (l+3), k0_2 = k0>>1;
2739  int rlim = n >> (l+6), r;
2740  int lim = 1 << (l+1);
2741  int i_off;
2742  float *A0 = A;
2743  i_off = n2-1;
2744  for (r=rlim; r > 0; --r) {
2745  imdct_step3_inner_s_loop(lim, u, i_off, -k0_2, A0, k1, k0);
2746  A0 += k1*4;
2747  i_off -= 8;
2748  }
2749  }
2750 
2751  // iterations with count:
2752  // ld-6,-5,-4 all interleaved together
2753  // the big win comes from getting rid of needless flops
2754  // due to the constants on pass 5 & 4 being all 1 and 0;
2755  // combining them to be simultaneous to improve cache made little difference
2756  imdct_step3_inner_s_loop_ld654(n >> 5, u, n2-1, A, n);
2757 
2758  // output is u
2759 
2760  // step 4, 5, and 6
2761  // cannot be in-place because of step 5
2762  {
2763  uint16 *bitrev = f->bit_reverse[blocktype];
2764  // weirdly, I'd have thought reading sequentially and writing
2765  // erratically would have been better than vice-versa, but in
2766  // fact that's not what my testing showed. (That is, with
2767  // j = bitreverse(i), do you read i and write j, or read j and write i.)
2768 
2769  float *d0 = &v[n4-4];
2770  float *d1 = &v[n2-4];
2771  while (d0 >= v) {
2772  int k4;
2773 
2774  k4 = bitrev[0];
2775  d1[3] = u[k4+0];
2776  d1[2] = u[k4+1];
2777  d0[3] = u[k4+2];
2778  d0[2] = u[k4+3];
2779 
2780  k4 = bitrev[1];
2781  d1[1] = u[k4+0];
2782  d1[0] = u[k4+1];
2783  d0[1] = u[k4+2];
2784  d0[0] = u[k4+3];
2785 
2786  d0 -= 4;
2787  d1 -= 4;
2788  bitrev += 2;
2789  }
2790  }
2791  // (paper output is u, now v)
2792 
2793 
2794  // data must be in buf2
2795  assert(v == buf2);
2796 
2797  // step 7 (paper output is v, now v)
2798  // this is now in place
2799  {
2800  float *C = f->C[blocktype];
2801  float *d, *e;
2802 
2803  d = v;
2804  e = v + n2 - 4;
2805 
2806  while (d < e) {
2807  float a02,a11,b0,b1,b2,b3;
2808 
2809  a02 = d[0] - e[2];
2810  a11 = d[1] + e[3];
2811 
2812  b0 = C[1]*a02 + C[0]*a11;
2813  b1 = C[1]*a11 - C[0]*a02;
2814 
2815  b2 = d[0] + e[ 2];
2816  b3 = d[1] - e[ 3];
2817 
2818  d[0] = b2 + b0;
2819  d[1] = b3 + b1;
2820  e[2] = b2 - b0;
2821  e[3] = b1 - b3;
2822 
2823  a02 = d[2] - e[0];
2824  a11 = d[3] + e[1];
2825 
2826  b0 = C[3]*a02 + C[2]*a11;
2827  b1 = C[3]*a11 - C[2]*a02;
2828 
2829  b2 = d[2] + e[ 0];
2830  b3 = d[3] - e[ 1];
2831 
2832  d[2] = b2 + b0;
2833  d[3] = b3 + b1;
2834  e[0] = b2 - b0;
2835  e[1] = b1 - b3;
2836 
2837  C += 4;
2838  d += 4;
2839  e -= 4;
2840  }
2841  }
2842 
2843  // data must be in buf2
2844 
2845 
2846  // step 8+decode (paper output is X, now buffer)
2847  // this generates pairs of data a la 8 and pushes them directly through
2848  // the decode kernel (pushing rather than pulling) to avoid having
2849  // to make another pass later
2850 
2851  // this cannot POSSIBLY be in place, so we refer to the buffers directly
2852 
2853  {
2854  float *d0,*d1,*d2,*d3;
2855 
2856  float *B = f->B[blocktype] + n2 - 8;
2857  float *e = buf2 + n2 - 8;
2858  d0 = &buffer[0];
2859  d1 = &buffer[n2-4];
2860  d2 = &buffer[n2];
2861  d3 = &buffer[n-4];
2862  while (e >= v) {
2863  float p0,p1,p2,p3;
2864 
2865  p3 = e[6]*B[7] - e[7]*B[6];
2866  p2 = -e[6]*B[6] - e[7]*B[7];
2867 
2868  d0[0] = p3;
2869  d1[3] = - p3;
2870  d2[0] = p2;
2871  d3[3] = p2;
2872 
2873  p1 = e[4]*B[5] - e[5]*B[4];
2874  p0 = -e[4]*B[4] - e[5]*B[5];
2875 
2876  d0[1] = p1;
2877  d1[2] = - p1;
2878  d2[1] = p0;
2879  d3[2] = p0;
2880 
2881  p3 = e[2]*B[3] - e[3]*B[2];
2882  p2 = -e[2]*B[2] - e[3]*B[3];
2883 
2884  d0[2] = p3;
2885  d1[1] = - p3;
2886  d2[2] = p2;
2887  d3[1] = p2;
2888 
2889  p1 = e[0]*B[1] - e[1]*B[0];
2890  p0 = -e[0]*B[0] - e[1]*B[1];
2891 
2892  d0[3] = p1;
2893  d1[0] = - p1;
2894  d2[3] = p0;
2895  d3[0] = p0;
2896 
2897  B -= 8;
2898  e -= 8;
2899  d0 += 4;
2900  d2 += 4;
2901  d1 -= 4;
2902  d3 -= 4;
2903  }
2904  }
2905 
2906  temp_free(f,buf2);
2907  temp_alloc_restore(f,save_point);
2908 }

Referenced by vorbis_decode_packet_rest().

◆ is_whole_packet_present()

static int is_whole_packet_present ( stb_vorbis f,
int  end_page 
)
static

Definition at line 3496 of file stb_vorbis.c.

3497 {
3498  // make sure that we have the packet available before continuing...
3499  // this requires a full ogg parse, but we know we can fetch from f->stream
3500 
3501  // instead of coding this out explicitly, we could save the current read state,
3502  // read the next packet with get8() until end-of-packet, check f->eof, then
3503  // reset the state? but that would be slower, esp. since we'd have over 256 bytes
3504  // of state to restore (primarily the page segment table)
3505 
3506  int s = f->next_seg, first = TRUE;
3507  uint8 *p = f->stream;
3508 
3509  if (s != -1) { // if we're not starting the packet with a 'continue on next page' flag
3510  for (; s < f->segment_count; ++s) {
3511  p += f->segments[s];
3512  if (f->segments[s] < 255) // stop at first short segment
3513  break;
3514  }
3515  // either this continues, or it ends it...
3516  if (end_page)
3517  if (s < f->segment_count-1) return error(f, VORBIS_invalid_stream);
3518  if (s == f->segment_count)
3519  s = -1; // set 'crosses page' flag
3520  if (p > f->stream_end) return error(f, VORBIS_need_more_data);
3521  first = FALSE;
3522  }
3523  for (; s == -1;) {
3524  uint8 *q;
3525  int n;
3526 
3527  // check that we have the page header ready
3528  if (p + 26 >= f->stream_end) return error(f, VORBIS_need_more_data);
3529  // validate the page
3530  if (memcmp(p, ogg_page_header, 4)) return error(f, VORBIS_invalid_stream);
3531  if (p[4] != 0) return error(f, VORBIS_invalid_stream);
3532  if (first) { // the first segment must NOT have 'continued_packet', later ones MUST
3533  if (f->previous_length)
3534  if ((p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream);
3535  // if no previous length, we're resynching, so we can come in on a continued-packet,
3536  // which we'll just drop
3537  } else {
3538  if (!(p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream);
3539  }
3540  n = p[26]; // segment counts
3541  q = p+27; // q points to segment table
3542  p = q + n; // advance past header
3543  // make sure we've read the segment table
3544  if (p > f->stream_end) return error(f, VORBIS_need_more_data);
3545  for (s=0; s < n; ++s) {
3546  p += q[s];
3547  if (q[s] < 255)
3548  break;
3549  }
3550  if (end_page)
3551  if (s < n-1) return error(f, VORBIS_invalid_stream);
3552  if (s == n)
3553  s = -1; // set 'crosses page' flag
3554  if (p > f->stream_end) return error(f, VORBIS_need_more_data);
3555  first = FALSE;
3556  }
3557  return TRUE;
3558 }

Referenced by start_decoder(), and stb_vorbis_decode_frame_pushdata().

◆ iter_54()

static __forceinline void iter_54 ( float *  z)
static

Definition at line 2532 of file stb_vorbis.c.

2533 {
2534  float k00,k11,k22,k33;
2535  float y0,y1,y2,y3;
2536 
2537  k00 = z[ 0] - z[-4];
2538  y0 = z[ 0] + z[-4];
2539  y2 = z[-2] + z[-6];
2540  k22 = z[-2] - z[-6];
2541 
2542  z[-0] = y0 + y2; // z0 + z4 + z2 + z6
2543  z[-2] = y0 - y2; // z0 + z4 - z2 - z6
2544 
2545  // done with y0,y2
2546 
2547  k33 = z[-3] - z[-7];
2548 
2549  z[-4] = k00 + k33; // z0 - z4 + z3 - z7
2550  z[-6] = k00 - k33; // z0 - z4 - z3 + z7
2551 
2552  // done with k33
2553 
2554  k11 = z[-1] - z[-5];
2555  y1 = z[-1] + z[-5];
2556  y3 = z[-3] + z[-7];
2557 
2558  z[-1] = y1 + y3; // z1 + z5 + z3 + z7
2559  z[-3] = y1 - y3; // z1 + z5 - z3 - z7
2560  z[-5] = k11 - k22; // z1 - z5 + z2 - z6
2561  z[-7] = k11 + k22; // z1 - z5 - z2 + z6
2562 }

Referenced by imdct_step3_inner_s_loop_ld654().

◆ lookup1_values()

static int lookup1_values ( int  entries,
int  dim 
)
static

Definition at line 1197 of file stb_vorbis.c.

1198 {
1199  int r = (int) floor(exp((float) log((float) entries) / dim));
1200  if ((int) floor(pow((float) r+1, dim)) <= entries) // (int) cast for MinGW warning;
1201  ++r; // floor() to avoid _ftol() when non-CRT
1202  assert(pow((float) r+1, dim) > entries);
1203  assert((int) floor(pow((float) r, dim)) <= entries); // (int),floor() as above
1204  return r;
1205 }

Referenced by start_decoder().

◆ make_block_array()

static void* make_block_array ( void mem,
int  count,
int  size 
)
static

Definition at line 894 of file stb_vorbis.c.

895 {
896  int i;
897  void ** p = (void **) mem;
898  char *q = (char *) (p + count);
899  for (i=0; i < count; ++i) {
900  p[i] = q;
901  q += size;
902  }
903  return p;
904 }

◆ maybe_start_packet()

static int maybe_start_packet ( vorb f)
static

Definition at line 1472 of file stb_vorbis.c.

1473 {
1474  if (f->next_seg == -1) {
1475  int x = get8(f);
1476  if (f->eof) return FALSE; // EOF at page boundary is not an error!
1477  if (0x4f != x ) return error(f, VORBIS_missing_capture_pattern);
1478  if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern);
1479  if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern);
1480  if (0x53 != get8(f)) return error(f, VORBIS_missing_capture_pattern);
1481  if (!start_page_no_capturepattern(f)) return FALSE;
1483  // set up enough state that we can read this packet if we want,
1484  // e.g. during recovery
1485  f->last_seg = FALSE;
1486  f->bytes_in_seg = 0;
1488  }
1489  }
1490  return start_packet(f);
1491 }

Referenced by stb_vorbis_seek_frame(), and vorbis_decode_initial().

◆ neighbors()

static void neighbors ( uint16 x,
int  n,
int plow,
int phigh 
)
static

Definition at line 1257 of file stb_vorbis.c.

1258 {
1259  int low = -1;
1260  int high = 65536;
1261  int i;
1262  for (i=0; i < n; ++i) {
1263  if (x[i] > low && x[i] < x[n]) { *plow = i; low = x[i]; }
1264  if (x[i] < high && x[i] > x[n]) { *phigh = i; high = x[i]; }
1265  }
1266 }

Referenced by start_decoder().

◆ next_segment()

static int next_segment ( vorb f)
static

Definition at line 1493 of file stb_vorbis.c.

1494 {
1495  int len;
1496  if (f->last_seg) return 0;
1497  if (f->next_seg == -1) {
1498  f->last_seg_which = f->segment_count-1; // in case start_page fails
1499  if (!start_page(f)) { f->last_seg = 1; return 0; }
1501  }
1502  len = f->segments[f->next_seg++];
1503  if (len < 255) {
1504  f->last_seg = TRUE;
1505  f->last_seg_which = f->next_seg-1;
1506  }
1507  if (f->next_seg >= f->segment_count)
1508  f->next_seg = -1;
1509  assert(f->bytes_in_seg == 0);
1510  f->bytes_in_seg = len;
1511  return len;
1512 }

Referenced by get8_packet_raw(), and start_decoder().

◆ peek_decode_initial()

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 
)
static

Definition at line 4735 of file stb_vorbis.c.

4736 {
4737  int bits_read, bytes_read;
4738 
4739  if (!vorbis_decode_initial(f, p_left_start, p_left_end, p_right_start, p_right_end, mode))
4740  return 0;
4741 
4742  // either 1 or 2 bytes were read, figure out which so we can rewind
4743  bits_read = 1 + ilog(f->mode_count-1);
4744  if (f->mode_config[*mode].blockflag)
4745  bits_read += 2;
4746  bytes_read = (bits_read + 7) / 8;
4747 
4748  f->bytes_in_seg += bytes_read;
4749  f->packet_bytes -= bytes_read;
4750  skip(f, -bytes_read);
4751  if (f->next_seg == -1)
4752  f->next_seg = f->segment_count - 1;
4753  else
4754  f->next_seg--;
4755  f->valid_bits = 0;
4756 
4757  return 1;
4758 }

Referenced by stb_vorbis_seek_frame().

◆ point_compare()

static int STBV_CDECL point_compare ( const void p,
const void q 
)
static

Definition at line 1274 of file stb_vorbis.c.

1275 {
1278  return a->x < b->x ? -1 : a->x > b->x;
1279 }

Referenced by start_decoder().

◆ predict_point()

static int predict_point ( int  x,
int  x0,
int  x1,
int  y0,
int  y1 
)
static

Definition at line 1878 of file stb_vorbis.c.

1879 {
1880  int dy = y1 - y0;
1881  int adx = x1 - x0;
1882  // @OPTIMIZE: force int division to round in the right direction... is this necessary on x86?
1883  int err = abs(dy) * (x - x0);
1884  int off = err / adx;
1885  return dy < 0 ? y0 - off : y0 + off;
1886 }

Referenced by vorbis_decode_packet_rest().

◆ prep_huffman()

static __forceinline void prep_huffman ( vorb f)
static

Definition at line 1577 of file stb_vorbis.c.

1578 {
1579  if (f->valid_bits <= 24) {
1580  if (f->valid_bits == 0) f->acc = 0;
1581  do {
1582  int z;
1583  if (f->last_seg && !f->bytes_in_seg) return;
1584  z = get8_packet_raw(f);
1585  if (z == EOP) return;
1586  f->acc += (unsigned) z << f->valid_bits;
1587  f->valid_bits += 8;
1588  } while (f->valid_bits <= 24);
1589  }
1590 }

Referenced by codebook_decode_scalar_raw().

◆ residue_decode()

static int residue_decode ( vorb f,
Codebook book,
float *  target,
int  offset,
int  n,
int  rtype 
)
static

Definition at line 2026 of file stb_vorbis.c.

2027 {
2028  int k;
2029  if (rtype == 0) {
2030  int step = n / book->dimensions;
2031  for (k=0; k < step; ++k)
2032  if (!codebook_decode_step(f, book, target+offset+k, n-offset-k, step))
2033  return FALSE;
2034  } else {
2035  for (k=0; k < n; ) {
2036  if (!codebook_decode(f, book, target+offset, n-k))
2037  return FALSE;
2038  k += book->dimensions;
2039  offset += book->dimensions;
2040  }
2041  }
2042  return TRUE;
2043 }

Referenced by decode_residue().

◆ seek_to_sample_coarse()

static int seek_to_sample_coarse ( stb_vorbis f,
uint32  sample_number 
)
static

Definition at line 4585 of file stb_vorbis.c.

4586 {
4587  ProbedPage left, right, mid;
4588  int i, start_seg_with_known_loc, end_pos, page_start;
4589  uint32 delta, stream_length, padding;
4590  double offset = 0, bytes_per_sample = 0;
4591  int probe = 0;
4592 
4593  // find the last page and validate the target sample
4594  stream_length = stb_vorbis_stream_length_in_samples(f);
4595  if (stream_length == 0) return error(f, VORBIS_seek_without_length);
4596  if (sample_number > stream_length) return error(f, VORBIS_seek_invalid);
4597 
4598  // this is the maximum difference between the window-center (which is the
4599  // actual granule position value), and the right-start (which the spec
4600  // indicates should be the granule position (give or take one)).
4601  padding = ((f->blocksize_1 - f->blocksize_0) >> 2);
4602  if (sample_number < padding)
4603  sample_number = 0;
4604  else
4605  sample_number -= padding;
4606 
4607  left = f->p_first;
4608  while (left.last_decoded_sample == ~0U) {
4609  // (untested) the first page does not have a 'last_decoded_sample'
4610  set_file_offset(f, left.page_end);
4611  if (!get_seek_page_info(f, &left)) goto error;
4612  }
4613 
4614  right = f->p_last;
4615  assert(right.last_decoded_sample != ~0U);
4616 
4617  // starting from the start is handled differently
4618  if (sample_number <= left.last_decoded_sample) {
4619  if (stb_vorbis_seek_start(f))
4620  return 1;
4621  return 0;
4622  }
4623 
4624  while (left.page_end != right.page_start) {
4625  assert(left.page_end < right.page_start);
4626  // search range in bytes
4627  delta = right.page_start - left.page_end;
4628  if (delta <= 65536) {
4629  // there's only 64K left to search - handle it linearly
4630  set_file_offset(f, left.page_end);
4631  } else {
4632  if (probe < 2) {
4633  if (probe == 0) {
4634  // first probe (interpolate)
4635  double data_bytes = right.page_end - left.page_start;
4636  bytes_per_sample = data_bytes / right.last_decoded_sample;
4637  offset = left.page_start + bytes_per_sample * (sample_number - left.last_decoded_sample);
4638  } else {
4639  // second probe (try to bound the other side)
4640  double error = ((double) sample_number - mid.last_decoded_sample) * bytes_per_sample;
4641  if (error >= 0 && error < 8000) error = 8000;
4642  if (error < 0 && error > -8000) error = -8000;
4643  offset += error * 2;
4644  }
4645 
4646  // ensure the offset is valid
4647  if (offset < left.page_end)
4648  offset = left.page_end;
4649  if (offset > right.page_start - 65536)
4650  offset = right.page_start - 65536;
4651 
4652  set_file_offset(f, (unsigned int) offset);
4653  } else {
4654  // binary search for large ranges (offset by 32K to ensure
4655  // we don't hit the right page)
4656  set_file_offset(f, left.page_end + (delta / 2) - 32768);
4657  }
4658 
4659  if (!vorbis_find_page(f, NULL, NULL)) goto error;
4660  }
4661 
4662  for (;;) {
4663  if (!get_seek_page_info(f, &mid)) goto error;
4664  if (mid.last_decoded_sample != ~0U) break;
4665  // (untested) no frames end on this page
4666  set_file_offset(f, mid.page_end);
4667  assert(mid.page_start < right.page_start);
4668  }
4669 
4670  // if we've just found the last page again then we're in a tricky file,
4671  // and we're close enough.
4672  if (mid.page_start == right.page_start)
4673  break;
4674 
4675  if (sample_number < mid.last_decoded_sample)
4676  right = mid;
4677  else
4678  left = mid;
4679 
4680  ++probe;
4681  }
4682 
4683  // seek back to start of the last packet
4684  page_start = left.page_start;
4685  set_file_offset(f, page_start);
4686  if (!start_page(f)) return error(f, VORBIS_seek_failed);
4687  end_pos = f->end_seg_with_known_loc;
4688  assert(end_pos >= 0);
4689 
4690  for (;;) {
4691  for (i = end_pos; i > 0; --i)
4692  if (f->segments[i-1] != 255)
4693  break;
4694 
4695  start_seg_with_known_loc = i;
4696 
4697  if (start_seg_with_known_loc > 0 || !(f->page_flag & PAGEFLAG_continued_packet))
4698  break;
4699 
4700  // (untested) the final packet begins on an earlier page
4701  if (!go_to_page_before(f, page_start))
4702  goto error;
4703 
4704  page_start = stb_vorbis_get_file_offset(f);
4705  if (!start_page(f)) goto error;
4706  end_pos = f->segment_count - 1;
4707  }
4708 
4709  // prepare to start decoding
4710  f->current_loc_valid = FALSE;
4711  f->last_seg = FALSE;
4712  f->valid_bits = 0;
4713  f->packet_bytes = 0;
4714  f->bytes_in_seg = 0;
4715  f->previous_length = 0;
4716  f->next_seg = start_seg_with_known_loc;
4717 
4718  for (i = 0; i < start_seg_with_known_loc; i++)
4719  skip(f, f->segments[i]);
4720 
4721  // start decoding (optimizable - this frame is generally discarded)
4722  if (!vorbis_pump_first_frame(f))
4723  return 0;
4724  if (f->current_loc > sample_number)
4725  return error(f, VORBIS_seek_failed);
4726  return 1;
4727 
4728 error:
4729  // try to restore the file to a valid state
4731  return error(f, VORBIS_seek_failed);
4732 }

Referenced by stb_vorbis_seek_frame().

◆ set_file_offset()

static int set_file_offset ( stb_vorbis f,
unsigned int  loc 
)
static

Definition at line 1351 of file stb_vorbis.c.

1352 {
1353  #ifndef STB_VORBIS_NO_PUSHDATA_API
1354  if (f->push_mode) return 0;
1355  #endif
1356  f->eof = 0;
1357  if (USE_MEMORY(f)) {
1358  if (f->stream_start + loc >= f->stream_end || f->stream_start + loc < f->stream_start) {
1359  f->stream = f->stream_end;
1360  f->eof = 1;
1361  return 0;
1362  } else {
1363  f->stream = f->stream_start + loc;
1364  return 1;
1365  }
1366  }
1367  #ifndef STB_VORBIS_NO_STDIO
1368  if (loc + f->f_start < loc || loc >= 0x80000000) {
1369  loc = 0x7fffffff;
1370  f->eof = 1;
1371  } else {
1372  loc += f->f_start;
1373  }
1374  if (!fseek(f->f, loc, SEEK_SET))
1375  return 1;
1376  f->eof = 1;
1377  fseek(f->f, f->f_start, SEEK_END);
1378  return 0;
1379  #endif
1380 }

Referenced by get_seek_page_info(), go_to_page_before(), seek_to_sample_coarse(), stb_vorbis_seek_start(), stb_vorbis_stream_length_in_samples(), and vorbis_find_page().

◆ setup_free()

static void setup_free ( vorb f,
void p 
)
static

Definition at line 919 of file stb_vorbis.c.

920 {
921  if (f->alloc.alloc_buffer) return; // do nothing; setup mem is a stack
922  free(p);
923 }

Referenced by stb_vorbis_close(), and vorbis_deinit().

◆ setup_malloc()

static void* setup_malloc ( vorb f,
int  sz 
)
static

Definition at line 906 of file stb_vorbis.c.

907 {
908  sz = (sz+3) & ~3;
909  f->setup_memory_required += sz;
910  if (f->alloc.alloc_buffer) {
911  void *p = (char *) f->alloc.alloc_buffer + f->setup_offset;
912  if (f->setup_offset + sz > f->temp_offset) return NULL;
913  f->setup_offset += sz;
914  return p;
915  }
916  return sz ? malloc(sz) : NULL;
917 }

Referenced by init_blocksize(), start_decoder(), and vorbis_alloc().

◆ setup_temp_free()

static void setup_temp_free ( vorb f,
void p,
int  sz 
)
static

Definition at line 936 of file stb_vorbis.c.

937 {
938  if (f->alloc.alloc_buffer) {
939  f->temp_offset += (sz+3)&~3;
940  return;
941  }
942  free(p);
943 }

Referenced by start_decoder().

◆ setup_temp_malloc()

static void* setup_temp_malloc ( vorb f,
int  sz 
)
static

Definition at line 925 of file stb_vorbis.c.

926 {
927  sz = (sz+3) & ~3;
928  if (f->alloc.alloc_buffer) {
929  if (f->temp_offset - sz < f->setup_offset) return NULL;
930  f->temp_offset -= sz;
931  return (char *) f->alloc.alloc_buffer + f->temp_offset;
932  }
933  return malloc(sz);
934 }

Referenced by start_decoder().

◆ skip()

static void skip ( vorb z,
int  n 
)
static

Definition at line 1336 of file stb_vorbis.c.

1337 {
1338  if (USE_MEMORY(z)) {
1339  z->stream += n;
1340  if (z->stream >= z->stream_end) z->eof = 1;
1341  return;
1342  }
1343  #ifndef STB_VORBIS_NO_STDIO
1344  {
1345  long x = ftell(z->f);
1346  fseek(z->f, x+n, SEEK_SET);
1347  }
1348  #endif
1349 }

Referenced by Con_DrawNotify(), Draw_Char(), Draw_StretchPicImplementation(), peek_decode_initial(), seek_to_sample_coarse(), and start_decoder().

◆ square()

static float square ( float  x)
static

Definition at line 975 of file stb_vorbis.c.

976 {
977  return x*x;
978 }

Referenced by compute_window().

◆ start_decoder()

static int start_decoder ( vorb f)
static

Definition at line 3561 of file stb_vorbis.c.

3562 {
3563  uint8 header[6], x,y;
3564  int len,i,j,k, max_submaps = 0;
3565  int longest_floorlist=0;
3566 
3567  // first page, first packet
3568 
3569  if (!start_page(f)) return FALSE;
3570  // validate page flag
3574  // check for expected packet length
3575  if (f->segment_count != 1) return error(f, VORBIS_invalid_first_page);
3576  if (f->segments[0] != 30) return error(f, VORBIS_invalid_first_page);
3577  // read packet
3578  // check packet header
3579  if (get8(f) != VORBIS_packet_id) return error(f, VORBIS_invalid_first_page);
3580  if (!getn(f, header, 6)) return error(f, VORBIS_unexpected_eof);
3581  if (!vorbis_validate(header)) return error(f, VORBIS_invalid_first_page);
3582  // vorbis_version
3583  if (get32(f) != 0) return error(f, VORBIS_invalid_first_page);
3584  f->channels = get8(f); if (!f->channels) return error(f, VORBIS_invalid_first_page);
3586  f->sample_rate = get32(f); if (!f->sample_rate) return error(f, VORBIS_invalid_first_page);
3587  get32(f); // bitrate_maximum
3588  get32(f); // bitrate_nominal
3589  get32(f); // bitrate_minimum
3590  x = get8(f);
3591  {
3592  int log0,log1;
3593  log0 = x & 15;
3594  log1 = x >> 4;
3595  f->blocksize_0 = 1 << log0;
3596  f->blocksize_1 = 1 << log1;
3597  if (log0 < 6 || log0 > 13) return error(f, VORBIS_invalid_setup);
3598  if (log1 < 6 || log1 > 13) return error(f, VORBIS_invalid_setup);
3599  if (log0 > log1) return error(f, VORBIS_invalid_setup);
3600  }
3601 
3602  // framing_flag
3603  x = get8(f);
3604  if (!(x & 1)) return error(f, VORBIS_invalid_first_page);
3605 
3606  // second packet!
3607  if (!start_page(f)) return FALSE;
3608 
3609  if (!start_packet(f)) return FALSE;
3610  do {
3611  len = next_segment(f);
3612  skip(f, len);
3613  f->bytes_in_seg = 0;
3614  } while (len);
3615 
3616  // third packet!
3617  if (!start_packet(f)) return FALSE;
3618 
3619  #ifndef STB_VORBIS_NO_PUSHDATA_API
3620  if (IS_PUSH_MODE(f)) {
3621  if (!is_whole_packet_present(f, TRUE)) {
3622  // convert error in ogg header to write type
3623  if (f->error == VORBIS_invalid_stream)
3625  return FALSE;
3626  }
3627  }
3628  #endif
3629 
3630  crc32_init(); // always init it, to avoid multithread race conditions
3631 
3633  for (i=0; i < 6; ++i) header[i] = get8_packet(f);
3634  if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup);
3635 
3636  // codebooks
3637 
3638  f->codebook_count = get_bits(f,8) + 1;
3639  f->codebooks = (Codebook *) setup_malloc(f, sizeof(*f->codebooks) * f->codebook_count);
3640  if (f->codebooks == NULL) return error(f, VORBIS_outofmem);
3641  memset(f->codebooks, 0, sizeof(*f->codebooks) * f->codebook_count);
3642  for (i=0; i < f->codebook_count; ++i) {
3643  uint32 *values;
3644  int ordered, sorted_count;
3645  int total=0;
3646  uint8 *lengths;
3647  Codebook *c = f->codebooks+i;
3648  CHECK(f);
3649  x = get_bits(f, 8); if (x != 0x42) return error(f, VORBIS_invalid_setup);
3650  x = get_bits(f, 8); if (x != 0x43) return error(f, VORBIS_invalid_setup);
3651  x = get_bits(f, 8); if (x != 0x56) return error(f, VORBIS_invalid_setup);
3652  x = get_bits(f, 8);
3653  c->dimensions = (get_bits(f, 8)<<8) + x;
3654  x = get_bits(f, 8);
3655  y = get_bits(f, 8);
3656  c->entries = (get_bits(f, 8)<<16) + (y<<8) + x;
3657  ordered = get_bits(f,1);
3658  c->sparse = ordered ? 0 : get_bits(f,1);
3659 
3660  if (c->dimensions == 0 && c->entries != 0) return error(f, VORBIS_invalid_setup);
3661 
3662  if (c->sparse)
3663  lengths = (uint8 *) setup_temp_malloc(f, c->entries);
3664  else
3665  lengths = c->codeword_lengths = (uint8 *) setup_malloc(f, c->entries);
3666 
3667  if (!lengths) return error(f, VORBIS_outofmem);
3668 
3669  if (ordered) {
3670  int current_entry = 0;
3671  int current_length = get_bits(f,5) + 1;
3672  while (current_entry < c->entries) {
3673  int limit = c->entries - current_entry;
3674  int n = get_bits(f, ilog(limit));
3675  if (current_entry + n > (int) c->entries) { return error(f, VORBIS_invalid_setup); }
3676  memset(lengths + current_entry, current_length, n);
3677  current_entry += n;
3678  ++current_length;
3679  }
3680  } else {
3681  for (j=0; j < c->entries; ++j) {
3682  int present = c->sparse ? get_bits(f,1) : 1;
3683  if (present) {
3684  lengths[j] = get_bits(f, 5) + 1;
3685  ++total;
3686  if (lengths[j] == 32)
3687  return error(f, VORBIS_invalid_setup);
3688  } else {
3689  lengths[j] = NO_CODE;
3690  }
3691  }
3692  }
3693 
3694  if (c->sparse && total >= c->entries >> 2) {
3695  // convert sparse items to non-sparse!
3696  if (c->entries > (int) f->setup_temp_memory_required)
3698 
3699  c->codeword_lengths = (uint8 *) setup_malloc(f, c->entries);
3700  if (c->codeword_lengths == NULL) return error(f, VORBIS_outofmem);
3701  memcpy(c->codeword_lengths, lengths, c->entries);
3702  setup_temp_free(f, lengths, c->entries); // note this is only safe if there have been no intervening temp mallocs!
3703  lengths = c->codeword_lengths;
3704  c->sparse = 0;
3705  }
3706 
3707  // compute the size of the sorted tables
3708  if (c->sparse) {
3709  sorted_count = total;
3710  } else {
3711  sorted_count = 0;
3712  #ifndef STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH
3713  for (j=0; j < c->entries; ++j)
3714  if (lengths[j] > STB_VORBIS_FAST_HUFFMAN_LENGTH && lengths[j] != NO_CODE)
3715  ++sorted_count;
3716  #endif
3717  }
3718 
3719  c->sorted_entries = sorted_count;
3720  values = NULL;
3721 
3722  CHECK(f);
3723  if (!c->sparse) {
3724  c->codewords = (uint32 *) setup_malloc(f, sizeof(c->codewords[0]) * c->entries);
3725  if (!c->codewords) return error(f, VORBIS_outofmem);
3726  } else {
3727  unsigned int size;
3728  if (c->sorted_entries) {
3730  if (!c->codeword_lengths) return error(f, VORBIS_outofmem);
3731  c->codewords = (uint32 *) setup_temp_malloc(f, sizeof(*c->codewords) * c->sorted_entries);
3732  if (!c->codewords) return error(f, VORBIS_outofmem);
3733  values = (uint32 *) setup_temp_malloc(f, sizeof(*values) * c->sorted_entries);
3734  if (!values) return error(f, VORBIS_outofmem);
3735  }
3736  size = c->entries + (sizeof(*c->codewords) + sizeof(*values)) * c->sorted_entries;
3739  }
3740 
3741  if (!compute_codewords(c, lengths, c->entries, values)) {
3742  if (c->sparse) setup_temp_free(f, values, 0);
3743  return error(f, VORBIS_invalid_setup);
3744  }
3745 
3746  if (c->sorted_entries) {
3747  // allocate an extra slot for sentinels
3748  c->sorted_codewords = (uint32 *) setup_malloc(f, sizeof(*c->sorted_codewords) * (c->sorted_entries+1));
3749  if (c->sorted_codewords == NULL) return error(f, VORBIS_outofmem);
3750  // allocate an extra slot at the front so that c->sorted_values[-1] is defined
3751  // so that we can catch that case without an extra if
3752  c->sorted_values = ( int *) setup_malloc(f, sizeof(*c->sorted_values ) * (c->sorted_entries+1));
3753  if (c->sorted_values == NULL) return error(f, VORBIS_outofmem);
3754  ++c->sorted_values;
3755  c->sorted_values[-1] = -1;
3756  compute_sorted_huffman(c, lengths, values);
3757  }
3758 
3759  if (c->sparse) {
3760  setup_temp_free(f, values, sizeof(*values)*c->sorted_entries);
3761  setup_temp_free(f, c->codewords, sizeof(*c->codewords)*c->sorted_entries);
3762  setup_temp_free(f, lengths, c->entries);
3763  c->codewords = NULL;
3764  }
3765 
3767 
3768  CHECK(f);
3769  c->lookup_type = get_bits(f, 4);
3770  if (c->lookup_type > 2) return error(f, VORBIS_invalid_setup);
3771  if (c->lookup_type > 0) {
3772  uint16 *mults;
3773  c->minimum_value = float32_unpack(get_bits(f, 32));
3774  c->delta_value = float32_unpack(get_bits(f, 32));
3775  c->value_bits = get_bits(f, 4)+1;
3776  c->sequence_p = get_bits(f,1);
3777  if (c->lookup_type == 1) {
3779  } else {
3780  c->lookup_values = c->entries * c->dimensions;
3781  }
3782  if (c->lookup_values == 0) return error(f, VORBIS_invalid_setup);
3783  mults = (uint16 *) setup_temp_malloc(f, sizeof(mults[0]) * c->lookup_values);
3784  if (mults == NULL) return error(f, VORBIS_outofmem);
3785  for (j=0; j < (int) c->lookup_values; ++j) {
3786  int q = get_bits(f, c->value_bits);
3787  if (q == EOP) { setup_temp_free(f,mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_invalid_setup); }
3788  mults[j] = q;
3789  }
3790 
3791 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
3792  if (c->lookup_type == 1) {
3793  int len, sparse = c->sparse;
3794  float last=0;
3795  // pre-expand the lookup1-style multiplicands, to avoid a divide in the inner loop
3796  if (sparse) {
3797  if (c->sorted_entries == 0) goto skip;
3798  c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->sorted_entries * c->dimensions);
3799  } else
3800  c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->entries * c->dimensions);
3801  if (c->multiplicands == NULL) { setup_temp_free(f,mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); }
3802  len = sparse ? c->sorted_entries : c->entries;
3803  for (j=0; j < len; ++j) {
3804  unsigned int z = sparse ? c->sorted_values[j] : j;
3805  unsigned int div=1;
3806  for (k=0; k < c->dimensions; ++k) {
3807  int off = (z / div) % c->lookup_values;
3808  float val = mults[off];
3809  val = mults[off]*c->delta_value + c->minimum_value + last;
3810  c->multiplicands[j*c->dimensions + k] = val;
3811  if (c->sequence_p)
3812  last = val;
3813  if (k+1 < c->dimensions) {
3814  if (div > UINT_MAX / (unsigned int) c->lookup_values) {
3815  setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values);
3816  return error(f, VORBIS_invalid_setup);
3817  }
3818  div *= c->lookup_values;
3819  }
3820  }
3821  }
3822  c->lookup_type = 2;
3823  }
3824  else
3825 #endif
3826  {
3827  float last=0;
3828  CHECK(f);
3829  c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->lookup_values);
3830  if (c->multiplicands == NULL) { setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); }
3831  for (j=0; j < (int) c->lookup_values; ++j) {
3832  float val = mults[j] * c->delta_value + c->minimum_value + last;
3833  c->multiplicands[j] = val;
3834  if (c->sequence_p)
3835  last = val;
3836  }
3837  }
3838 #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK
3839  skip:;
3840 #endif
3841  setup_temp_free(f, mults, sizeof(mults[0])*c->lookup_values);
3842 
3843  CHECK(f);
3844  }
3845  CHECK(f);
3846  }
3847 
3848  // time domain transfers (notused)
3849 
3850  x = get_bits(f, 6) + 1;
3851  for (i=0; i < x; ++i) {
3852  uint32 z = get_bits(f, 16);
3853  if (z != 0) return error(f, VORBIS_invalid_setup);
3854  }
3855 
3856  // Floors
3857  f->floor_count = get_bits(f, 6)+1;
3858  f->floor_config = (Floor *) setup_malloc(f, f->floor_count * sizeof(*f->floor_config));
3859  if (f->floor_config == NULL) return error(f, VORBIS_outofmem);
3860  for (i=0; i < f->floor_count; ++i) {
3861  f->floor_types[i] = get_bits(f, 16);
3862  if (f->floor_types[i] > 1) return error(f, VORBIS_invalid_setup);
3863  if (f->floor_types[i] == 0) {
3864  Floor0 *g = &f->floor_config[i].floor0;
3865  g->order = get_bits(f,8);
3866  g->rate = get_bits(f,16);
3867  g->bark_map_size = get_bits(f,16);
3868  g->amplitude_bits = get_bits(f,6);
3869  g->amplitude_offset = get_bits(f,8);
3870  g->number_of_books = get_bits(f,4) + 1;
3871  for (j=0; j < g->number_of_books; ++j)
3872  g->book_list[j] = get_bits(f,8);
3874  } else {
3875  stbv__floor_ordering p[31*8+2];
3876  Floor1 *g = &f->floor_config[i].floor1;
3877  int max_class = -1;
3878  g->partitions = get_bits(f, 5);
3879  for (j=0; j < g->partitions; ++j) {
3880  g->partition_class_list[j] = get_bits(f, 4);
3881  if (g->partition_class_list[j] > max_class)
3882  max_class = g->partition_class_list[j];
3883  }
3884  for (j=0; j <= max_class; ++j) {
3885  g->class_dimensions[j] = get_bits(f, 3)+1;
3886  g->class_subclasses[j] = get_bits(f, 2);
3887  if (g->class_subclasses[j]) {
3888  g->class_masterbooks[j] = get_bits(f, 8);
3889  if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
3890  }
3891  for (k=0; k < 1 << g->class_subclasses[j]; ++k) {
3892  g->subclass_books[j][k] = get_bits(f,8)-1;
3893  if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
3894  }
3895  }
3896  g->floor1_multiplier = get_bits(f,2)+1;
3897  g->rangebits = get_bits(f,4);
3898  g->Xlist[0] = 0;
3899  g->Xlist[1] = 1 << g->rangebits;
3900  g->values = 2;
3901  for (j=0; j < g->partitions; ++j) {
3902  int c = g->partition_class_list[j];
3903  for (k=0; k < g->class_dimensions[c]; ++k) {
3904  g->Xlist[g->values] = get_bits(f, g->rangebits);
3905  ++g->values;
3906  }
3907  }
3908  // precompute the sorting
3909  for (j=0; j < g->values; ++j) {
3910  p[j].x = g->Xlist[j];
3911  p[j].id = j;
3912  }
3913  qsort(p, g->values, sizeof(p[0]), point_compare);
3914  for (j=0; j < g->values; ++j)
3915  g->sorted_order[j] = (uint8) p[j].id;
3916  // precompute the neighbors
3917  for (j=2; j < g->values; ++j) {
3918  int low,hi;
3919  neighbors(g->Xlist, j, &low,&hi);
3920  g->neighbors[j][0] = low;
3921  g->neighbors[j][1] = hi;
3922  }
3923 
3924  if (g->values > longest_floorlist)
3925  longest_floorlist = g->values;
3926  }
3927  }
3928 
3929  // Residue
3930  f->residue_count = get_bits(f, 6)+1;
3931  f->residue_config = (Residue *) setup_malloc(f, f->residue_count * sizeof(f->residue_config[0]));
3932  if (f->residue_config == NULL) return error(f, VORBIS_outofmem);
3933  memset(f->residue_config, 0, f->residue_count * sizeof(f->residue_config[0]));
3934  for (i=0; i < f->residue_count; ++i) {
3935  uint8 residue_cascade[64];
3936  Residue *r = f->residue_config+i;
3937  f->residue_types[i] = get_bits(f, 16);
3938  if (f->residue_types[i] > 2) return error(f, VORBIS_invalid_setup);
3939  r->begin = get_bits(f, 24);
3940  r->end = get_bits(f, 24);
3941  if (r->end < r->begin) return error(f, VORBIS_invalid_setup);
3942  r->part_size = get_bits(f,24)+1;
3943  r->classifications = get_bits(f,6)+1;
3944  r->classbook = get_bits(f,8);
3945  if (r->classbook >= f->codebook_count) return error(f, VORBIS_invalid_setup);
3946  for (j=0; j < r->classifications; ++j) {
3947  uint8 high_bits=0;
3948  uint8 low_bits=get_bits(f,3);
3949  if (get_bits(f,1))
3950  high_bits = get_bits(f,5);
3951  residue_cascade[j] = high_bits*8 + low_bits;
3952  }
3953  r->residue_books = (short (*)[8]) setup_malloc(f, sizeof(r->residue_books[0]) * r->classifications);
3954  if (r->residue_books == NULL) return error(f, VORBIS_outofmem);
3955  for (j=0; j < r->classifications; ++j) {
3956  for (k=0; k < 8; ++k) {
3957  if (residue_cascade[j] & (1 << k)) {
3958  r->residue_books[j][k] = get_bits(f, 8);
3959  if (r->residue_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup);
3960  } else {
3961  r->residue_books[j][k] = -1;
3962  }
3963  }
3964  }
3965  // precompute the classifications[] array to avoid inner-loop mod/divide
3966  // call it 'classdata' since we already have r->classifications
3967  r->classdata = (uint8 **) setup_malloc(f, sizeof(*r->classdata) * f->codebooks[r->classbook].entries);
3968  if (!r->classdata) return error(f, VORBIS_outofmem);
3969  memset(r->classdata, 0, sizeof(*r->classdata) * f->codebooks[r->classbook].entries);
3970  for (j=0; j < f->codebooks[r->classbook].entries; ++j) {
3971  int classwords = f->codebooks[r->classbook].dimensions;
3972  int temp = j;
3973  r->classdata[j] = (uint8 *) setup_malloc(f, sizeof(r->classdata[j][0]) * classwords);
3974  if (r->classdata[j] == NULL) return error(f, VORBIS_outofmem);
3975  for (k=classwords-1; k >= 0; --k) {
3976  r->classdata[j][k] = temp % r->classifications;
3977  temp /= r->classifications;
3978  }
3979  }
3980  }
3981 
3982  f->mapping_count = get_bits(f,6)+1;
3983  f->mapping = (Mapping *) setup_malloc(f, f->mapping_count * sizeof(*f->mapping));
3984  if (f->mapping == NULL) return error(f, VORBIS_outofmem);
3985  memset(f->mapping, 0, f->mapping_count * sizeof(*f->mapping));
3986  for (i=0; i < f->mapping_count; ++i) {
3987  Mapping *m = f->mapping + i;
3988  int mapping_type = get_bits(f,16);
3989  if (mapping_type != 0) return error(f, VORBIS_invalid_setup);
3990  m->chan = (MappingChannel *) setup_malloc(f, f->channels * sizeof(*m->chan));
3991  if (m->chan == NULL) return error(f, VORBIS_outofmem);
3992  if (get_bits(f,1))
3993  m->submaps = get_bits(f,4)+1;
3994  else
3995  m->submaps = 1;
3996  if (m->submaps > max_submaps)
3997  max_submaps = m->submaps;
3998  if (get_bits(f,1)) {
3999  m->coupling_steps = get_bits(f,8)+1;
4000  for (k=0; k < m->coupling_steps; ++k) {
4001  m->chan[k].magnitude = get_bits(f, ilog(f->channels-1));
4002  m->chan[k].angle = get_bits(f, ilog(f->channels-1));
4003  if (m->chan[k].magnitude >= f->channels) return error(f, VORBIS_invalid_setup);
4004  if (m->chan[k].angle >= f->channels) return error(f, VORBIS_invalid_setup);
4005  if (m->chan[k].magnitude == m->chan[k].angle) return error(f, VORBIS_invalid_setup);
4006  }
4007  } else
4008  m->coupling_steps = 0;
4009 
4010  // reserved field
4011  if (get_bits(f,2)) return error(f, VORBIS_invalid_setup);
4012  if (m->submaps > 1) {
4013  for (j=0; j < f->channels; ++j) {
4014  m->chan[j].mux = get_bits(f, 4);
4015  if (m->chan[j].mux >= m->submaps) return error(f, VORBIS_invalid_setup);
4016  }
4017  } else
4018  // @SPECIFICATION: this case is missing from the spec
4019  for (j=0; j < f->channels; ++j)
4020  m->chan[j].mux = 0;
4021 
4022  for (j=0; j < m->submaps; ++j) {
4023  get_bits(f,8); // discard
4024  m->submap_floor[j] = get_bits(f,8);
4025  m->submap_residue[j] = get_bits(f,8);
4026  if (m->submap_floor[j] >= f->floor_count) return error(f, VORBIS_invalid_setup);
4027  if (m->submap_residue[j] >= f->residue_count) return error(f, VORBIS_invalid_setup);
4028  }
4029  }
4030 
4031  // Modes
4032  f->mode_count = get_bits(f, 6)+1;
4033  for (i=0; i < f->mode_count; ++i) {
4034  Mode *m = f->mode_config+i;
4035  m->blockflag = get_bits(f,1);
4036  m->windowtype = get_bits(f,16);
4037  m->transformtype = get_bits(f,16);
4038  m->mapping = get_bits(f,8);
4039  if (m->windowtype != 0) return error(f, VORBIS_invalid_setup);
4040  if (m->transformtype != 0) return error(f, VORBIS_invalid_setup);
4041  if (m->mapping >= f->mapping_count) return error(f, VORBIS_invalid_setup);
4042  }
4043 
4044  flush_packet(f);
4045 
4046  f->previous_length = 0;
4047 
4048  for (i=0; i < f->channels; ++i) {
4049  f->channel_buffers[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1);
4050  f->previous_window[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1/2);
4051  f->finalY[i] = (int16 *) setup_malloc(f, sizeof(int16) * longest_floorlist);
4052  if (f->channel_buffers[i] == NULL || f->previous_window[i] == NULL || f->finalY[i] == NULL) return error(f, VORBIS_outofmem);
4053  #ifdef STB_VORBIS_NO_DEFER_FLOOR
4054  f->floor_buffers[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1/2);
4055  if (f->floor_buffers[i] == NULL) return error(f, VORBIS_outofmem);
4056  #endif
4057  }
4058 
4059  if (!init_blocksize(f, 0, f->blocksize_0)) return FALSE;
4060  if (!init_blocksize(f, 1, f->blocksize_1)) return FALSE;
4061  f->blocksize[0] = f->blocksize_0;
4062  f->blocksize[1] = f->blocksize_1;
4063 
4064 #ifdef STB_VORBIS_DIVIDE_TABLE
4065  if (integer_divide_table[1][1]==0)
4066  for (i=0; i < DIVTAB_NUMER; ++i)
4067  for (j=1; j < DIVTAB_DENOM; ++j)
4068  integer_divide_table[i][j] = i / j;
4069 #endif
4070 
4071  // compute how much temporary memory is needed
4072 
4073  // 1.
4074  {
4075  uint32 imdct_mem = (f->blocksize_1 * sizeof(float) >> 1);
4076  uint32 classify_mem;
4077  int i,max_part_read=0;
4078  for (i=0; i < f->residue_count; ++i) {
4079  Residue *r = f->residue_config + i;
4080  int n_read = r->end - r->begin;
4081  int part_read = n_read / r->part_size;
4082  if (part_read > max_part_read)
4083  max_part_read = part_read;
4084  }
4085  #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE
4086  classify_mem = f->channels * (sizeof(void*) + max_part_read * sizeof(uint8 *));
4087  #else
4088  classify_mem = f->channels * (sizeof(void*) + max_part_read * sizeof(int *));
4089  #endif
4090 
4091  f->temp_memory_required = classify_mem;
4092  if (imdct_mem > f->temp_memory_required)
4093  f->temp_memory_required = imdct_mem;
4094  }
4095 
4096  f->first_decode = TRUE;
4097 
4098  if (f->alloc.alloc_buffer) {
4100  // check if there's enough temp memory so we don't error later
4101  if (f->setup_offset + sizeof(*f) + f->temp_memory_required > (unsigned) f->temp_offset)
4102  return error(f, VORBIS_outofmem);
4103  }
4104 
4106 
4107  return TRUE;
4108 }

Referenced by stb_vorbis_open_file_section(), stb_vorbis_open_memory(), and stb_vorbis_open_pushdata().

◆ start_packet()

static int start_packet ( vorb f)
static

Definition at line 1457 of file stb_vorbis.c.

1458 {
1459  while (f->next_seg == -1) {
1460  if (!start_page(f)) return FALSE;
1463  }
1464  f->last_seg = FALSE;
1465  f->valid_bits = 0;
1466  f->packet_bytes = 0;
1467  f->bytes_in_seg = 0;
1468  // f->next_seg is now valid
1469  return TRUE;
1470 }

Referenced by maybe_start_packet(), and start_decoder().

◆ start_page()

static int start_page ( vorb f)
static

Definition at line 1451 of file stb_vorbis.c.

1452 {
1454  return start_page_no_capturepattern(f);
1455 }

Referenced by next_segment(), seek_to_sample_coarse(), start_decoder(), and start_packet().

◆ start_page_no_capturepattern()

static int start_page_no_capturepattern ( vorb f)
static

Definition at line 1398 of file stb_vorbis.c.

1399 {
1400  uint32 loc0,loc1,n;
1401  // stream structure version
1402  if (0 != get8(f)) return error(f, VORBIS_invalid_stream_structure_version);
1403  // header flag
1404  f->page_flag = get8(f);
1405  // absolute granule position
1406  loc0 = get32(f);
1407  loc1 = get32(f);
1408  // @TODO: validate loc0,loc1 as valid positions?
1409  // stream serial number -- vorbis doesn't interleave, so discard
1410  get32(f);
1411  //if (f->serial != get32(f)) return error(f, VORBIS_incorrect_stream_serial_number);
1412  // page sequence number
1413  n = get32(f);
1414  f->last_page = n;
1415  // CRC32
1416  get32(f);
1417  // page_segments
1418  f->segment_count = get8(f);
1419  if (!getn(f, f->segments, f->segment_count))
1420  return error(f, VORBIS_unexpected_eof);
1421  // assume we _don't_ know any the sample position of any segments
1422  f->end_seg_with_known_loc = -2;
1423  if (loc0 != ~0U || loc1 != ~0U) {
1424  int i;
1425  // determine which packet is the last one that will complete
1426  for (i=f->segment_count-1; i >= 0; --i)
1427  if (f->segments[i] < 255)
1428  break;
1429  // 'i' is now the index of the _last_ segment of a packet that ends
1430  if (i >= 0) {
1432  f->known_loc_for_packet = loc0;
1433  }
1434  }
1435  if (f->first_decode) {
1436  int i,len;
1437  ProbedPage p;
1438  len = 0;
1439  for (i=0; i < f->segment_count; ++i)
1440  len += f->segments[i];
1441  len += 27 + f->segment_count;
1443  p.page_end = p.page_start + len;
1444  p.last_decoded_sample = loc0;
1445  f->p_first = p;
1446  }
1447  f->next_seg = 0;
1448  return TRUE;
1449 }

Referenced by maybe_start_packet(), and start_page().

◆ stb_vorbis_close()

void stb_vorbis_close ( stb_vorbis f)

Definition at line 4166 of file stb_vorbis.c.

4167 {
4168  if (p == NULL) return;
4169  vorbis_deinit(p);
4170  setup_free(p,p);
4171 }

Referenced by stb_vorbis_decode_filename(), and stb_vorbis_decode_memory().

◆ stb_vorbis_decode_filename()

int stb_vorbis_decode_filename ( const char *  filename,
int channels,
int sample_rate,
short **  output 
)

Definition at line 5219 of file stb_vorbis.c.

5220 {
5221  int data_len, offset, total, limit, error;
5222  short *data;
5224  if (v == NULL) return -1;
5225  limit = v->channels * 4096;
5226  *channels = v->channels;
5227  if (sample_rate)
5228  *sample_rate = v->sample_rate;
5229  offset = data_len = 0;
5230  total = limit;
5231  data = (short *) malloc(total * sizeof(*data));
5232  if (data == NULL) {
5234  return -2;
5235  }
5236  for (;;) {
5237  int n = stb_vorbis_get_frame_short_interleaved(v, v->channels, data+offset, total-offset);
5238  if (n == 0) break;
5239  data_len += n;
5240  offset += n * v->channels;
5241  if (offset + limit > total) {
5242  short *data2;
5243  total *= 2;
5244  data2 = (short *) realloc(data, total * sizeof(*data));
5245  if (data2 == NULL) {
5246  free(data);
5248  return -2;
5249  }
5250  data = data2;
5251  }
5252  }
5253  *output = data;
5255  return data_len;
5256 }

◆ stb_vorbis_decode_frame_pushdata()

int stb_vorbis_decode_frame_pushdata ( stb_vorbis f,
const unsigned char *  datablock,
int  datablock_length_in_bytes,
int channels,
float ***  output,
int samples 
)

Definition at line 4330 of file stb_vorbis.c.

4337 {
4338  int i;
4339  int len,right,left;
4340 
4341  if (!IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
4342 
4343  if (f->page_crc_tests >= 0) {
4344  *samples = 0;
4345  return vorbis_search_for_page_pushdata(f, (uint8 *) data, data_len);
4346  }
4347 
4348  f->stream = (uint8 *) data;
4349  f->stream_end = (uint8 *) data + data_len;
4350  f->error = VORBIS__no_error;
4351 
4352  // check that we have the entire packet in memory
4353  if (!is_whole_packet_present(f, FALSE)) {
4354  *samples = 0;
4355  return 0;
4356  }
4357 
4358  if (!vorbis_decode_packet(f, &len, &left, &right)) {
4359  // save the actual error we encountered
4360  enum STBVorbisError error = f->error;
4361  if (error == VORBIS_bad_packet_type) {
4362  // flush and resynch
4363  f->error = VORBIS__no_error;
4364  while (get8_packet(f) != EOP)
4365  if (f->eof) break;
4366  *samples = 0;
4367  return (int) (f->stream - data);
4368  }
4370  if (f->previous_length == 0) {
4371  // we may be resynching, in which case it's ok to hit one
4372  // of these; just discard the packet
4373  f->error = VORBIS__no_error;
4374  while (get8_packet(f) != EOP)
4375  if (f->eof) break;
4376  *samples = 0;
4377  return (int) (f->stream - data);
4378  }
4379  }
4380  // if we get an error while parsing, what to do?
4381  // well, it DEFINITELY won't work to continue from where we are!
4383  // restore the error that actually made us bail
4384  f->error = error;
4385  *samples = 0;
4386  return 1;
4387  }
4388 
4389  // success!
4390  len = vorbis_finish_frame(f, len, left, right);
4391  for (i=0; i < f->channels; ++i)
4392  f->outputs[i] = f->channel_buffers[i] + left;
4393 
4394  if (channels) *channels = f->channels;
4395  *samples = len;
4396  *output = f->outputs;
4397  return (int) (f->stream - data);
4398 }

◆ stb_vorbis_decode_memory()

int stb_vorbis_decode_memory ( const unsigned char *  mem,
int  len,
int channels,
int sample_rate,
short **  output 
)

Definition at line 5259 of file stb_vorbis.c.

5260 {
5261  int data_len, offset, total, limit, error;
5262  short *data;
5263  stb_vorbis *v = stb_vorbis_open_memory(mem, len, &error, NULL);
5264  if (v == NULL) return -1;
5265  limit = v->channels * 4096;
5266  *channels = v->channels;
5267  if (sample_rate)
5268  *sample_rate = v->sample_rate;
5269  offset = data_len = 0;
5270  total = limit;
5271  data = (short *) malloc(total * sizeof(*data));
5272  if (data == NULL) {
5274  return -2;
5275  }
5276  for (;;) {
5277  int n = stb_vorbis_get_frame_short_interleaved(v, v->channels, data+offset, total-offset);
5278  if (n == 0) break;
5279  data_len += n;
5280  offset += n * v->channels;
5281  if (offset + limit > total) {
5282  short *data2;
5283  total *= 2;
5284  data2 = (short *) realloc(data, total * sizeof(*data));
5285  if (data2 == NULL) {
5286  free(data);
5288  return -2;
5289  }
5290  data = data2;
5291  }
5292  }
5293  *output = data;
5295  return data_len;
5296 }

◆ stb_vorbis_flush_pushdata()

void stb_vorbis_flush_pushdata ( stb_vorbis f)

Definition at line 4227 of file stb_vorbis.c.

4228 {
4229  f->previous_length = 0;
4230  f->page_crc_tests = 0;
4231  f->discard_samples_deferred = 0;
4232  f->current_loc_valid = FALSE;
4233  f->first_decode = FALSE;
4234  f->samples_output = 0;
4235  f->channel_buffer_start = 0;
4236  f->channel_buffer_end = 0;
4237 }

Referenced by stb_vorbis_decode_frame_pushdata().

◆ stb_vorbis_get_error()

int stb_vorbis_get_error ( stb_vorbis f)

Definition at line 4212 of file stb_vorbis.c.

4213 {
4214  int e = f->error;
4215  f->error = VORBIS__no_error;
4216  return e;
4217 }

◆ stb_vorbis_get_file_offset()

unsigned int stb_vorbis_get_file_offset ( stb_vorbis f)

Definition at line 4430 of file stb_vorbis.c.

4431 {
4432  #ifndef STB_VORBIS_NO_PUSHDATA_API
4433  if (f->push_mode) return 0;
4434  #endif
4435  if (USE_MEMORY(f)) return (unsigned int) (f->stream - f->stream_start);
4436  #ifndef STB_VORBIS_NO_STDIO
4437  return (unsigned int) (ftell(f->f) - f->f_start);
4438  #endif
4439 }

Referenced by get_seek_page_info(), go_to_page_before(), seek_to_sample_coarse(), start_decoder(), stb_vorbis_stream_length_in_samples(), and vorbis_find_page().

◆ stb_vorbis_get_frame_float()

int stb_vorbis_get_frame_float ( stb_vorbis f,
int channels,
float ***  output 
)

Definition at line 4908 of file stb_vorbis.c.

4909 {
4910  int len, right,left,i;
4911  if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
4912 
4913  if (!vorbis_decode_packet(f, &len, &left, &right)) {
4915  return 0;
4916  }
4917 
4918  len = vorbis_finish_frame(f, len, left, right);
4919  for (i=0; i < f->channels; ++i)
4920  f->outputs[i] = f->channel_buffers[i] + left;
4921 
4922  f->channel_buffer_start = left;
4923  f->channel_buffer_end = left+len;
4924 
4925  if (channels) *channels = f->channels;
4926  if (output) *output = f->outputs;
4927  return len;
4928 }

Referenced by stb_vorbis_get_frame_short(), stb_vorbis_get_frame_short_interleaved(), stb_vorbis_get_samples_float(), stb_vorbis_get_samples_float_interleaved(), stb_vorbis_get_samples_short(), stb_vorbis_get_samples_short_interleaved(), and stb_vorbis_seek().

◆ stb_vorbis_get_frame_short()

int stb_vorbis_get_frame_short ( stb_vorbis f,
int  num_c,
short **  buffer,
int  num_samples 
)

Definition at line 5129 of file stb_vorbis.c.

5130 {
5131  float **output;
5132  int len = stb_vorbis_get_frame_float(f, NULL, &output);
5133  if (len > num_samples) len = num_samples;
5134  if (len)
5135  convert_samples_short(num_c, buffer, 0, f->channels, output, 0, len);
5136  return len;
5137 }

Referenced by stb_vorbis_get_frame_short_interleaved().

◆ stb_vorbis_get_frame_short_interleaved()

int stb_vorbis_get_frame_short_interleaved ( stb_vorbis f,
int  num_c,
short *  buffer,
int  num_shorts 
)

Definition at line 5165 of file stb_vorbis.c.

5166 {
5167  float **output;
5168  int len;
5169  if (num_c == 1) return stb_vorbis_get_frame_short(f,num_c,&buffer, num_shorts);
5170  len = stb_vorbis_get_frame_float(f, NULL, &output);
5171  if (len) {
5172  if (len*num_c > num_shorts) len = num_shorts / num_c;
5173  convert_channels_short_interleaved(num_c, buffer, f->channels, output, 0, len);
5174  }
5175  return len;
5176 }

Referenced by stb_vorbis_decode_filename(), and stb_vorbis_decode_memory().

◆ stb_vorbis_get_info()

stb_vorbis_info stb_vorbis_get_info ( stb_vorbis f)

Definition at line 4200 of file stb_vorbis.c.

4201 {
4202  stb_vorbis_info d;
4203  d.channels = f->channels;
4204  d.sample_rate = f->sample_rate;
4208  d.max_frame_size = f->blocksize_1 >> 1;
4209  return d;
4210 }

◆ stb_vorbis_get_sample_offset()

int stb_vorbis_get_sample_offset ( stb_vorbis f)

Definition at line 4192 of file stb_vorbis.c.

4193 {
4194  if (f->current_loc_valid)
4195  return f->current_loc;
4196  else
4197  return -1;
4198 }

◆ stb_vorbis_get_samples_float()

int stb_vorbis_get_samples_float ( stb_vorbis f,
int  channels,
float **  buffer,
int  num_samples 
)

Definition at line 5326 of file stb_vorbis.c.

5327 {
5328  float **outputs;
5329  int n=0;
5330  int z = f->channels;
5331  if (z > channels) z = channels;
5332  while (n < num_samples) {
5333  int i;
5334  int k = f->channel_buffer_end - f->channel_buffer_start;
5335  if (n+k >= num_samples) k = num_samples - n;
5336  if (k) {
5337  for (i=0; i < z; ++i)
5338  memcpy(buffer[i]+n, f->channel_buffers[i]+f->channel_buffer_start, sizeof(float)*k);
5339  for ( ; i < channels; ++i)
5340  memset(buffer[i]+n, 0, sizeof(float) * k);
5341  }
5342  n += k;
5343  f->channel_buffer_start += k;
5344  if (n == num_samples)
5345  break;
5346  if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
5347  break;
5348  }
5349  return n;
5350 }

◆ stb_vorbis_get_samples_float_interleaved()

int stb_vorbis_get_samples_float_interleaved ( stb_vorbis f,
int  channels,
float *  buffer,
int  num_floats 
)

Definition at line 5299 of file stb_vorbis.c.

5300 {
5301  float **outputs;
5302  int len = num_floats / channels;
5303  int n=0;
5304  int z = f->channels;
5305  if (z > channels) z = channels;
5306  while (n < len) {
5307  int i,j;
5308  int k = f->channel_buffer_end - f->channel_buffer_start;
5309  if (n+k >= len) k = len - n;
5310  for (j=0; j < k; ++j) {
5311  for (i=0; i < z; ++i)
5313  for ( ; i < channels; ++i)
5314  *buffer++ = 0;
5315  }
5316  n += k;
5317  f->channel_buffer_start += k;
5318  if (n == len)
5319  break;
5320  if (!stb_vorbis_get_frame_float(f, NULL, &outputs))
5321  break;
5322  }
5323  return n;
5324 }

◆ stb_vorbis_get_samples_short()

int stb_vorbis_get_samples_short ( stb_vorbis f,
int  channels,
short **  buffer,
int  num_samples 
)

Definition at line 5199 of file stb_vorbis.c.

5200 {
5201  float **outputs;
5202  int n=0;
5203  int z = f->channels;
5204  if (z > channels) z = channels;
5205  while (n < len) {
5206  int k = f->channel_buffer_end - f->channel_buffer_start;
5207  if (n+k >= len) k = len - n;
5208  if (k)
5210  n += k;
5211  f->channel_buffer_start += k;
5212  if (n == len) break;
5213  if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
5214  }
5215  return n;
5216 }

◆ stb_vorbis_get_samples_short_interleaved()

int stb_vorbis_get_samples_short_interleaved ( stb_vorbis f,
int  channels,
short *  buffer,
int  num_shorts 
)

Definition at line 5178 of file stb_vorbis.c.

5179 {
5180  float **outputs;
5181  int len = num_shorts / channels;
5182  int n=0;
5183  int z = f->channels;
5184  if (z > channels) z = channels;
5185  while (n < len) {
5186  int k = f->channel_buffer_end - f->channel_buffer_start;
5187  if (n+k >= len) k = len - n;
5188  if (k)
5190  buffer += k*channels;
5191  n += k;
5192  f->channel_buffer_start += k;
5193  if (n == len) break;
5194  if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break;
5195  }
5196  return n;
5197 }

◆ stb_vorbis_open_file()

stb_vorbis * stb_vorbis_open_file ( FILE *  f,
int  close_handle_on_close,
int error,
const stb_vorbis_alloc alloc_buffer 
)

Definition at line 4953 of file stb_vorbis.c.

4954 {
4955  unsigned int len, start;
4956  start = (unsigned int) ftell(file);
4957  fseek(file, 0, SEEK_END);
4958  len = (unsigned int) (ftell(file) - start);
4959  fseek(file, start, SEEK_SET);
4960  return stb_vorbis_open_file_section(file, close_on_free, error, alloc, len);
4961 }

Referenced by stb_vorbis_open_filename().

◆ stb_vorbis_open_file_section()

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 
)

Definition at line 4932 of file stb_vorbis.c.

4933 {
4934  stb_vorbis *f, p;
4935  vorbis_init(&p, alloc);
4936  p.f = file;
4937  p.f_start = (uint32) ftell(file);
4938  p.stream_len = length;
4939  p.close_on_free = close_on_free;
4940  if (start_decoder(&p)) {
4941  f = vorbis_alloc(&p);
4942  if (f) {
4943  *f = p;
4945  return f;
4946  }
4947  }
4948  if (error) *error = p.error;
4949  vorbis_deinit(&p);
4950  return NULL;
4951 }

Referenced by stb_vorbis_open_file().

◆ stb_vorbis_open_filename()

stb_vorbis * stb_vorbis_open_filename ( const char *  filename,
int error,
const stb_vorbis_alloc alloc_buffer 
)

Definition at line 4963 of file stb_vorbis.c.

4964 {
4965  FILE *f = fopen(filename, "rb");
4966  if (f)
4967  return stb_vorbis_open_file(f, TRUE, error, alloc);
4969  return NULL;
4970 }

Referenced by stb_vorbis_decode_filename().

◆ stb_vorbis_open_memory()

stb_vorbis * stb_vorbis_open_memory ( const unsigned char *  data,
int  len,
int error,
const stb_vorbis_alloc alloc_buffer 
)

Definition at line 4973 of file stb_vorbis.c.

4974 {
4975  stb_vorbis *f, p;
4976  if (data == NULL) return NULL;
4977  vorbis_init(&p, alloc);
4978  p.stream = (uint8 *) data;
4979  p.stream_end = (uint8 *) data + len;
4980  p.stream_start = (uint8 *) p.stream;
4981  p.stream_len = len;
4982  p.push_mode = FALSE;
4983  if (start_decoder(&p)) {
4984  f = vorbis_alloc(&p);
4985  if (f) {
4986  *f = p;
4988  if (error) *error = VORBIS__no_error;
4989  return f;
4990  }
4991  }
4992  if (error) *error = p.error;
4993  vorbis_deinit(&p);
4994  return NULL;
4995 }

Referenced by stb_vorbis_decode_memory().

◆ stb_vorbis_open_pushdata()

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 
)

Definition at line 4400 of file stb_vorbis.c.

4404 {
4405  stb_vorbis *f, p;
4406  vorbis_init(&p, alloc);
4407  p.stream = (uint8 *) data;
4408  p.stream_end = (uint8 *) data + data_len;
4409  p.push_mode = TRUE;
4410  if (!start_decoder(&p)) {
4411  if (p.eof)
4413  else
4414  *error = p.error;
4415  return NULL;
4416  }
4417  f = vorbis_alloc(&p);
4418  if (f) {
4419  *f = p;
4420  *data_used = (int) (f->stream - data);
4421  *error = 0;
4422  return f;
4423  } else {
4424  vorbis_deinit(&p);
4425  return NULL;
4426  }
4427 }

◆ stb_vorbis_seek()

int stb_vorbis_seek ( stb_vorbis f,
unsigned int  sample_number 
)

Definition at line 4799 of file stb_vorbis.c.

4800 {
4801  if (!stb_vorbis_seek_frame(f, sample_number))
4802  return 0;
4803 
4804  if (sample_number != f->current_loc) {
4805  int n;
4806  uint32 frame_start = f->current_loc;
4808  assert(sample_number > frame_start);
4809  assert(f->channel_buffer_start + (int) (sample_number-frame_start) <= f->channel_buffer_end);
4810  f->channel_buffer_start += (sample_number - frame_start);
4811  }
4812 
4813  return 1;
4814 }

◆ stb_vorbis_seek_frame()

int stb_vorbis_seek_frame ( stb_vorbis f,
unsigned int  sample_number 
)

Definition at line 4760 of file stb_vorbis.c.

4761 {
4762  uint32 max_frame_samples;
4763 
4764  if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
4765 
4766  // fast page-level search
4767  if (!seek_to_sample_coarse(f, sample_number))
4768  return 0;
4769 
4770  assert(f->current_loc_valid);
4771  assert(f->current_loc <= sample_number);
4772 
4773  // linear search for the relevant packet
4774  max_frame_samples = (f->blocksize_1*3 - f->blocksize_0) >> 2;
4775  while (f->current_loc < sample_number) {
4776  int left_start, left_end, right_start, right_end, mode, frame_samples;
4777  if (!peek_decode_initial(f, &left_start, &left_end, &right_start, &right_end, &mode))
4778  return error(f, VORBIS_seek_failed);
4779  // calculate the number of samples returned by the next frame
4780  frame_samples = right_start - left_start;
4781  if (f->current_loc + frame_samples > sample_number) {
4782  return 1; // the next frame will contain the sample
4783  } else if (f->current_loc + frame_samples + max_frame_samples > sample_number) {
4784  // there's a chance the frame after this could contain the sample
4786  } else {
4787  // this frame is too early to be relevant
4788  f->current_loc += frame_samples;
4789  f->previous_length = 0;
4790  maybe_start_packet(f);
4791  flush_packet(f);
4792  }
4793  }
4794  // the next frame will start with the sample
4795  assert(f->current_loc == sample_number);
4796  return 1;
4797 }

Referenced by stb_vorbis_seek().

◆ stb_vorbis_seek_start()

int stb_vorbis_seek_start ( stb_vorbis f)

Definition at line 4816 of file stb_vorbis.c.

4817 {
4818  if (IS_PUSH_MODE(f)) { return error(f, VORBIS_invalid_api_mixing); }
4820  f->previous_length = 0;
4821  f->first_decode = TRUE;
4822  f->next_seg = -1;
4823  return vorbis_pump_first_frame(f);
4824 }

Referenced by seek_to_sample_coarse().

◆ stb_vorbis_stream_length_in_samples()

unsigned int stb_vorbis_stream_length_in_samples ( stb_vorbis f)

Definition at line 4826 of file stb_vorbis.c.

4827 {
4828  unsigned int restore_offset, previous_safe;
4829  unsigned int end, last_page_loc;
4830 
4831  if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing);
4832  if (!f->total_samples) {
4833  unsigned int last;
4834  uint32 lo,hi;
4835  char header[6];
4836 
4837  // first, store the current decode position so we can restore it
4838  restore_offset = stb_vorbis_get_file_offset(f);
4839 
4840  // now we want to seek back 64K from the end (the last page must
4841  // be at most a little less than 64K, but let's allow a little slop)
4842  if (f->stream_len >= 65536 && f->stream_len-65536 >= f->first_audio_page_offset)
4843  previous_safe = f->stream_len - 65536;
4844  else
4845  previous_safe = f->first_audio_page_offset;
4846 
4847  set_file_offset(f, previous_safe);
4848  // previous_safe is now our candidate 'earliest known place that seeking
4849  // to will lead to the final page'
4850 
4851  if (!vorbis_find_page(f, &end, &last)) {
4852  // if we can't find a page, we're hosed!
4854  f->total_samples = 0xffffffff;
4855  goto done;
4856  }
4857 
4858  // check if there are more pages
4859  last_page_loc = stb_vorbis_get_file_offset(f);
4860 
4861  // stop when the last_page flag is set, not when we reach eof;
4862  // this allows us to stop short of a 'file_section' end without
4863  // explicitly checking the length of the section
4864  while (!last) {
4865  set_file_offset(f, end);
4866  if (!vorbis_find_page(f, &end, &last)) {
4867  // the last page we found didn't have the 'last page' flag
4868  // set. whoops!
4869  break;
4870  }
4871  previous_safe = last_page_loc+1;
4872  last_page_loc = stb_vorbis_get_file_offset(f);
4873  }
4874 
4875  set_file_offset(f, last_page_loc);
4876 
4877  // parse the header
4878  getn(f, (unsigned char *)header, 6);
4879  // extract the absolute granule position
4880  lo = get32(f);
4881  hi = get32(f);
4882  if (lo == 0xffffffff && hi == 0xffffffff) {
4885  goto done;
4886  }
4887  if (hi)
4888  lo = 0xfffffffe; // saturate
4889  f->total_samples = lo;
4890 
4891  f->p_last.page_start = last_page_loc;
4892  f->p_last.page_end = end;
4893  f->p_last.last_decoded_sample = lo;
4894 
4895  done:
4896  set_file_offset(f, restore_offset);
4897  }
4898  return f->total_samples == SAMPLE_unknown ? 0 : f->total_samples;
4899 }

Referenced by seek_to_sample_coarse(), and stb_vorbis_stream_length_in_seconds().

◆ stb_vorbis_stream_length_in_seconds()

float stb_vorbis_stream_length_in_seconds ( stb_vorbis f)

Definition at line 4901 of file stb_vorbis.c.

4902 {
4903  return stb_vorbis_stream_length_in_samples(f) / (float) f->sample_rate;
4904 }

◆ uint32_compare()

static int STBV_CDECL uint32_compare ( const void p,
const void q 
)
static

Definition at line 1118 of file stb_vorbis.c.

1119 {
1120  uint32 x = * (uint32 *) p;
1121  uint32 y = * (uint32 *) q;
1122  return x < y ? -1 : x > y;
1123 }

Referenced by compute_sorted_huffman().

◆ vorbis_alloc()

static stb_vorbis* vorbis_alloc ( stb_vorbis f)
static

Definition at line 4219 of file stb_vorbis.c.

4220 {
4221  stb_vorbis *p = (stb_vorbis *) setup_malloc(f, sizeof(*p));
4222  return p;
4223 }

Referenced by stb_vorbis_open_file_section(), stb_vorbis_open_memory(), and stb_vorbis_open_pushdata().

◆ vorbis_decode_initial()

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 
)
static

Definition at line 3103 of file stb_vorbis.c.

3104 {
3105  Mode *m;
3106  int i, n, prev, next, window_center;
3108 
3109  retry:
3110  if (f->eof) return FALSE;
3111  if (!maybe_start_packet(f))
3112  return FALSE;
3113  // check packet type
3114  if (get_bits(f,1) != 0) {
3115  if (IS_PUSH_MODE(f))
3116  return error(f,VORBIS_bad_packet_type);
3117  while (EOP != get8_packet(f));
3118  goto retry;
3119  }
3120 
3121  if (f->alloc.alloc_buffer)
3123 
3124  i = get_bits(f, ilog(f->mode_count-1));
3125  if (i == EOP) return FALSE;
3126  if (i >= f->mode_count) return FALSE;
3127  *mode = i;
3128  m = f->mode_config + i;
3129  if (m->blockflag) {
3130  n = f->blocksize_1;
3131  prev = get_bits(f,1);
3132  next = get_bits(f,1);
3133  } else {
3134  prev = next = 0;
3135  n = f->blocksize_0;
3136  }
3137 
3138 // WINDOWING
3139 
3140  window_center = n >> 1;
3141  if (m->blockflag && !prev) {
3142  *p_left_start = (n - f->blocksize_0) >> 2;
3143  *p_left_end = (n + f->blocksize_0) >> 2;
3144  } else {
3145  *p_left_start = 0;
3146  *p_left_end = window_center;
3147  }
3148  if (m->blockflag && !next) {
3149  *p_right_start = (n*3 - f->blocksize_0) >> 2;
3150  *p_right_end = (n*3 + f->blocksize_0) >> 2;
3151  } else {
3152  *p_right_start = window_center;
3153  *p_right_end = n;
3154  }
3155 
3156  return TRUE;
3157 }

Referenced by peek_decode_initial(), and vorbis_decode_packet().

◆ vorbis_decode_packet()

static int vorbis_decode_packet ( vorb f,
int len,
int p_left,
int p_right 
)
static

Definition at line 3427 of file stb_vorbis.c.

3428 {
3429  int mode, left_end, right_end;
3430  if (!vorbis_decode_initial(f, p_left, &left_end, p_right, &right_end, &mode)) return 0;
3431  return vorbis_decode_packet_rest(f, len, f->mode_config + mode, *p_left, left_end, *p_right, right_end, p_left);
3432 }

Referenced by stb_vorbis_decode_frame_pushdata(), stb_vorbis_get_frame_float(), and vorbis_pump_first_frame().

◆ vorbis_decode_packet_rest()

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 
)
static

Definition at line 3159 of file stb_vorbis.c.

3160 {
3161  Mapping *map;
3162  int i,j,k,n,n2;
3163  int zero_channel[256];
3164  int really_zero_channel[256];
3165 
3166 // WINDOWING
3167 
3168  n = f->blocksize[m->blockflag];
3169  map = &f->mapping[m->mapping];
3170 
3171 // FLOORS
3172  n2 = n >> 1;
3173 
3174  CHECK(f);
3175 
3176  for (i=0; i < f->channels; ++i) {
3177  int s = map->chan[i].mux, floor;
3178  zero_channel[i] = FALSE;
3179  floor = map->submap_floor[s];
3180  if (f->floor_types[floor] == 0) {
3181  return error(f, VORBIS_invalid_stream);
3182  } else {
3183  Floor1 *g = &f->floor_config[floor].floor1;
3184  if (get_bits(f, 1)) {
3185  short *finalY;
3186  uint8 step2_flag[256];
3187  static int range_list[4] = { 256, 128, 86, 64 };
3188  int range = range_list[g->floor1_multiplier-1];
3189  int offset = 2;
3190  finalY = f->finalY[i];
3191  finalY[0] = get_bits(f, ilog(range)-1);
3192  finalY[1] = get_bits(f, ilog(range)-1);
3193  for (j=0; j < g->partitions; ++j) {
3194  int pclass = g->partition_class_list[j];
3195  int cdim = g->class_dimensions[pclass];
3196  int cbits = g->class_subclasses[pclass];
3197  int csub = (1 << cbits)-1;
3198  int cval = 0;
3199  if (cbits) {
3200  Codebook *c = f->codebooks + g->class_masterbooks[pclass];
3201  DECODE(cval,f,c);
3202  }
3203  for (k=0; k < cdim; ++k) {
3204  int book = g->subclass_books[pclass][cval & csub];
3205  cval = cval >> cbits;
3206  if (book >= 0) {
3207  int temp;
3208  Codebook *c = f->codebooks + book;
3209  DECODE(temp,f,c);
3210  finalY[offset++] = temp;
3211  } else
3212  finalY[offset++] = 0;
3213  }
3214  }
3215  if (f->valid_bits == INVALID_BITS) goto error; // behavior according to spec
3216  step2_flag[0] = step2_flag[1] = 1;
3217  for (j=2; j < g->values; ++j) {
3218  int low, high, pred, highroom, lowroom, room, val;
3219  low = g->neighbors[j][0];
3220  high = g->neighbors[j][1];
3221  //neighbors(g->Xlist, j, &low, &high);
3222  pred = predict_point(g->Xlist[j], g->Xlist[low], g->Xlist[high], finalY[low], finalY[high]);
3223  val = finalY[j];
3224  highroom = range - pred;
3225  lowroom = pred;
3226  if (highroom < lowroom)
3227  room = highroom * 2;
3228  else
3229  room = lowroom * 2;
3230  if (val) {
3231  step2_flag[low] = step2_flag[high] = 1;
3232  step2_flag[j] = 1;
3233  if (val >= room)
3234  if (highroom > lowroom)
3235  finalY[j] = val - lowroom + pred;
3236  else
3237  finalY[j] = pred - val + highroom - 1;
3238  else
3239  if (val & 1)
3240  finalY[j] = pred - ((val+1)>>1);
3241  else
3242  finalY[j] = pred + (val>>1);
3243  } else {
3244  step2_flag[j] = 0;
3245  finalY[j] = pred;
3246  }
3247  }
3248 
3249 #ifdef STB_VORBIS_NO_DEFER_FLOOR
3250  do_floor(f, map, i, n, f->floor_buffers[i], finalY, step2_flag);
3251 #else
3252  // defer final floor computation until _after_ residue
3253  for (j=0; j < g->values; ++j) {
3254  if (!step2_flag[j])
3255  finalY[j] = -1;
3256  }
3257 #endif
3258  } else {
3259  error:
3260  zero_channel[i] = TRUE;
3261  }
3262  // So we just defer everything else to later
3263 
3264  // at this point we've decoded the floor into buffer
3265  }
3266  }
3267  CHECK(f);
3268  // at this point we've decoded all floors
3269 
3270  if (f->alloc.alloc_buffer)
3272 
3273  // re-enable coupled channels if necessary
3274  memcpy(really_zero_channel, zero_channel, sizeof(really_zero_channel[0]) * f->channels);
3275  for (i=0; i < map->coupling_steps; ++i)
3276  if (!zero_channel[map->chan[i].magnitude] || !zero_channel[map->chan[i].angle]) {
3277  zero_channel[map->chan[i].magnitude] = zero_channel[map->chan[i].angle] = FALSE;
3278  }
3279 
3280  CHECK(f);
3281 // RESIDUE DECODE
3282  for (i=0; i < map->submaps; ++i) {
3283  float *residue_buffers[STB_VORBIS_MAX_CHANNELS];
3284  int r;
3285  uint8 do_not_decode[256];
3286  int ch = 0;
3287  for (j=0; j < f->channels; ++j) {
3288  if (map->chan[j].mux == i) {
3289  if (zero_channel[j]) {
3290  do_not_decode[ch] = TRUE;
3291  residue_buffers[ch] = NULL;
3292  } else {
3293  do_not_decode[ch] = FALSE;
3294  residue_buffers[ch] = f->channel_buffers[j];
3295  }
3296  ++ch;
3297  }
3298  }
3299  r = map->submap_residue[i];
3300  decode_residue(f, residue_buffers, ch, n2, r, do_not_decode);
3301  }
3302 
3303  if (f->alloc.alloc_buffer)
3305  CHECK(f);
3306 
3307 // INVERSE COUPLING
3308  for (i = map->coupling_steps-1; i >= 0; --i) {
3309  int n2 = n >> 1;
3310  float *m = f->channel_buffers[map->chan[i].magnitude];
3311  float *a = f->channel_buffers[map->chan[i].angle ];
3312  for (j=0; j < n2; ++j) {
3313  float a2,m2;
3314  if (m[j] > 0)
3315  if (a[j] > 0)
3316  m2 = m[j], a2 = m[j] - a[j];
3317  else
3318  a2 = m[j], m2 = m[j] + a[j];
3319  else
3320  if (a[j] > 0)
3321  m2 = m[j], a2 = m[j] + a[j];
3322  else
3323  a2 = m[j], m2 = m[j] - a[j];
3324  m[j] = m2;
3325  a[j] = a2;
3326  }
3327  }
3328  CHECK(f);
3329 
3330  // finish decoding the floors
3331 #ifndef STB_VORBIS_NO_DEFER_FLOOR
3332  for (i=0; i < f->channels; ++i) {
3333  if (really_zero_channel[i]) {
3334  memset(f->channel_buffers[i], 0, sizeof(*f->channel_buffers[i]) * n2);
3335  } else {
3336  do_floor(f, map, i, n, f->channel_buffers[i], f->finalY[i], NULL);
3337  }
3338  }
3339 #else
3340  for (i=0; i < f->channels; ++i) {
3341  if (really_zero_channel[i]) {
3342  memset(f->channel_buffers[i], 0, sizeof(*f->channel_buffers[i]) * n2);
3343  } else {
3344  for (j=0; j < n2; ++j)
3345  f->channel_buffers[i][j] *= f->floor_buffers[i][j];
3346  }
3347  }
3348 #endif
3349 
3350 // INVERSE MDCT
3351  CHECK(f);
3352  for (i=0; i < f->channels; ++i)
3353  inverse_mdct(f->channel_buffers[i], n, f, m->blockflag);
3354  CHECK(f);
3355 
3356  // this shouldn't be necessary, unless we exited on an error
3357  // and want to flush to get to the next packet
3358  flush_packet(f);
3359 
3360  if (f->first_decode) {
3361  // assume we start so first non-discarded sample is sample 0
3362  // this isn't to spec, but spec would require us to read ahead
3363  // and decode the size of all current frames--could be done,
3364  // but presumably it's not a commonly used feature
3365  f->current_loc = -n2; // start of first frame is positioned for discard
3366  // we might have to discard samples "from" the next frame too,
3367  // if we're lapping a large block then a small at the start?
3368  f->discard_samples_deferred = n - right_end;
3369  f->current_loc_valid = TRUE;
3370  f->first_decode = FALSE;
3371  } else if (f->discard_samples_deferred) {
3372  if (f->discard_samples_deferred >= right_start - left_start) {
3373  f->discard_samples_deferred -= (right_start - left_start);
3374  left_start = right_start;
3375  *p_left = left_start;
3376  } else {
3377  left_start += f->discard_samples_deferred;
3378  *p_left = left_start;
3379  f->discard_samples_deferred = 0;
3380  }
3381  } else if (f->previous_length == 0 && f->current_loc_valid) {
3382  // we're recovering from a seek... that means we're going to discard
3383  // the samples from this packet even though we know our position from
3384  // the last page header, so we need to update the position based on
3385  // the discarded samples here
3386  // but wait, the code below is going to add this in itself even
3387  // on a discard, so we don't need to do it here...
3388  }
3389 
3390  // check if we have ogg information about the sample # for this packet
3391  if (f->last_seg_which == f->end_seg_with_known_loc) {
3392  // if we have a valid current loc, and this is final:
3393  if (f->current_loc_valid && (f->page_flag & PAGEFLAG_last_page)) {
3394  uint32 current_end = f->known_loc_for_packet - (n-right_end);
3395  // then let's infer the size of the (probably) short final frame
3396  if (current_end < f->current_loc + (right_end-left_start)) {
3397  if (current_end < f->current_loc) {
3398  // negative truncation, that's impossible!
3399  *len = 0;
3400  } else {
3401  *len = current_end - f->current_loc;
3402  }
3403  *len += left_start;
3404  if (*len > right_end) *len = right_end; // this should never happen
3405  f->current_loc += *len;
3406  return TRUE;
3407  }
3408  }
3409  // otherwise, just set our sample loc
3410  // guess that the ogg granule pos refers to the _middle_ of the
3411  // last frame?
3412  // set f->current_loc to the position of left_start
3413  f->current_loc = f->known_loc_for_packet - (n2-left_start);
3414  f->current_loc_valid = TRUE;
3415  }
3416  if (f->current_loc_valid)
3417  f->current_loc += (right_start - left_start);
3418 
3419  if (f->alloc.alloc_buffer)
3421  *len = right_end; // ignore samples after the window goes to 0
3422  CHECK(f);
3423 
3424  return TRUE;
3425 }

Referenced by vorbis_decode_packet().

◆ vorbis_deinit()

static void vorbis_deinit ( stb_vorbis p)
static

Definition at line 4110 of file stb_vorbis.c.

4111 {
4112  int i,j;
4113  if (p->residue_config) {
4114  for (i=0; i < p->residue_count; ++i) {
4115  Residue *r = p->residue_config+i;
4116  if (r->classdata) {
4117  for (j=0; j < p->codebooks[r->classbook].entries; ++j)
4118  setup_free(p, r->classdata[j]);
4119  setup_free(p, r->classdata);
4120  }
4121  setup_free(p, r->residue_books);
4122  }
4123  }
4124 
4125  if (p->codebooks) {
4126  CHECK(p);
4127  for (i=0; i < p->codebook_count; ++i) {
4128  Codebook *c = p->codebooks + i;
4130  setup_free(p, c->multiplicands);
4131  setup_free(p, c->codewords);
4133  // c->sorted_values[-1] is the first entry in the array
4134  setup_free(p, c->sorted_values ? c->sorted_values-1 : NULL);
4135  }
4136  setup_free(p, p->codebooks);
4137  }
4138  setup_free(p, p->floor_config);
4139  setup_free(p, p->residue_config);
4140  if (p->mapping) {
4141  for (i=0; i < p->mapping_count; ++i)
4142  setup_free(p, p->mapping[i].chan);
4143  setup_free(p, p->mapping);
4144  }
4145  CHECK(p);
4146  for (i=0; i < p->channels && i < STB_VORBIS_MAX_CHANNELS; ++i) {
4147  setup_free(p, p->channel_buffers[i]);
4148  setup_free(p, p->previous_window[i]);
4149  #ifdef STB_VORBIS_NO_DEFER_FLOOR
4150  setup_free(p, p->floor_buffers[i]);
4151  #endif
4152  setup_free(p, p->finalY[i]);
4153  }
4154  for (i=0; i < 2; ++i) {
4155  setup_free(p, p->A[i]);
4156  setup_free(p, p->B[i]);
4157  setup_free(p, p->C[i]);
4158  setup_free(p, p->window[i]);
4159  setup_free(p, p->bit_reverse[i]);
4160  }
4161  #ifndef STB_VORBIS_NO_STDIO
4162  if (p->close_on_free) fclose(p->f);
4163  #endif
4164 }

Referenced by stb_vorbis_close(), stb_vorbis_open_file_section(), stb_vorbis_open_memory(), and stb_vorbis_open_pushdata().

◆ vorbis_find_page()

static uint32 vorbis_find_page ( stb_vorbis f,
uint32 end,
uint32 last 
)
static

Definition at line 4446 of file stb_vorbis.c.

4447 {
4448  for(;;) {
4449  int n;
4450  if (f->eof) return 0;
4451  n = get8(f);
4452  if (n == 0x4f) { // page header candidate
4453  unsigned int retry_loc = stb_vorbis_get_file_offset(f);
4454  int i;
4455  // check if we're off the end of a file_section stream
4456  if (retry_loc - 25 > f->stream_len)
4457  return 0;
4458  // check the rest of the header
4459  for (i=1; i < 4; ++i)
4460  if (get8(f) != ogg_page_header[i])
4461  break;
4462  if (f->eof) return 0;
4463  if (i == 4) {
4464  uint8 header[27];
4465  uint32 i, crc, goal, len;
4466  for (i=0; i < 4; ++i)
4467  header[i] = ogg_page_header[i];
4468  for (; i < 27; ++i)
4469  header[i] = get8(f);
4470  if (f->eof) return 0;
4471  if (header[4] != 0) goto invalid;
4472  goal = header[22] + (header[23] << 8) + (header[24]<<16) + (header[25]<<24);
4473  for (i=22; i < 26; ++i)
4474  header[i] = 0;
4475  crc = 0;
4476  for (i=0; i < 27; ++i)
4477  crc = crc32_update(crc, header[i]);
4478  len = 0;
4479  for (i=0; i < header[26]; ++i) {
4480  int s = get8(f);
4481  crc = crc32_update(crc, s);
4482  len += s;
4483  }
4484  if (len && f->eof) return 0;
4485  for (i=0; i < len; ++i)
4486  crc = crc32_update(crc, get8(f));
4487  // finished parsing probable page
4488  if (crc == goal) {
4489  // we could now check that it's either got the last
4490  // page flag set, OR it's followed by the capture
4491  // pattern, but I guess TECHNICALLY you could have
4492  // a file with garbage between each ogg page and recover
4493  // from it automatically? So even though that paranoia
4494  // might decrease the chance of an invalid decode by
4495  // another 2^32, not worth it since it would hose those
4496  // invalid-but-useful files?
4497  if (end)
4498  *end = stb_vorbis_get_file_offset(f);
4499  if (last) {
4500  if (header[5] & 0x04)
4501  *last = 1;
4502  else
4503  *last = 0;
4504  }
4505  set_file_offset(f, retry_loc-1);
4506  return 1;
4507  }
4508  }
4509  invalid:
4510  // not a valid page, so rewind and look for next one
4511  set_file_offset(f, retry_loc);
4512  }
4513  }
4514 }

Referenced by go_to_page_before(), seek_to_sample_coarse(), and stb_vorbis_stream_length_in_samples().

◆ vorbis_finish_frame()

static int vorbis_finish_frame ( stb_vorbis f,
int  len,
int  left,
int  right 
)
static

Definition at line 3434 of file stb_vorbis.c.

3435 {
3436  int prev,i,j;
3437  // we use right&left (the start of the right- and left-window sin()-regions)
3438  // to determine how much to return, rather than inferring from the rules
3439  // (same result, clearer code); 'left' indicates where our sin() window
3440  // starts, therefore where the previous window's right edge starts, and
3441  // therefore where to start mixing from the previous buffer. 'right'
3442  // indicates where our sin() ending-window starts, therefore that's where
3443  // we start saving, and where our returned-data ends.
3444 
3445  // mixin from previous window
3446  if (f->previous_length) {
3447  int i,j, n = f->previous_length;
3448  float *w = get_window(f, n);
3449  for (i=0; i < f->channels; ++i) {
3450  for (j=0; j < n; ++j)
3451  f->channel_buffers[i][left+j] =
3452  f->channel_buffers[i][left+j]*w[ j] +
3453  f->previous_window[i][ j]*w[n-1-j];
3454  }
3455  }
3456 
3457  prev = f->previous_length;
3458 
3459  // last half of this data becomes previous window
3460  f->previous_length = len - right;
3461 
3462  // @OPTIMIZE: could avoid this copy by double-buffering the
3463  // output (flipping previous_window with channel_buffers), but
3464  // then previous_window would have to be 2x as large, and
3465  // channel_buffers couldn't be temp mem (although they're NOT
3466  // currently temp mem, they could be (unless we want to level
3467  // performance by spreading out the computation))
3468  for (i=0; i < f->channels; ++i)
3469  for (j=0; right+j < len; ++j)
3470  f->previous_window[i][j] = f->channel_buffers[i][right+j];
3471 
3472  if (!prev)
3473  // there was no previous packet, so this data isn't valid...
3474  // this isn't entirely true, only the would-have-overlapped data
3475  // isn't valid, but this seems to be what the spec requires
3476  return 0;
3477 
3478  // truncate a short frame
3479  if (len < right) right = len;
3480 
3481  f->samples_output += right-left;
3482 
3483  return right - left;
3484 }

Referenced by stb_vorbis_decode_frame_pushdata(), stb_vorbis_get_frame_float(), and vorbis_pump_first_frame().

◆ vorbis_init()

static void vorbis_init ( stb_vorbis p,
const stb_vorbis_alloc z 
)
static

Definition at line 4173 of file stb_vorbis.c.

4174 {
4175  memset(p, 0, sizeof(*p)); // NULL out all malloc'd pointers to start
4176  if (z) {
4177  p->alloc = *z;
4180  }
4181  p->eof = 0;
4182  p->error = VORBIS__no_error;
4183  p->stream = NULL;
4184  p->codebooks = NULL;
4185  p->page_crc_tests = -1;
4186  #ifndef STB_VORBIS_NO_STDIO
4187  p->close_on_free = FALSE;
4188  p->f = NULL;
4189  #endif
4190 }

Referenced by stb_vorbis_open_file_section(), stb_vorbis_open_memory(), and stb_vorbis_open_pushdata().

◆ vorbis_pump_first_frame()

static int vorbis_pump_first_frame ( stb_vorbis f)
static

Definition at line 3486 of file stb_vorbis.c.

3487 {
3488  int len, right, left, res;
3489  res = vorbis_decode_packet(f, &len, &left, &right);
3490  if (res)
3491  vorbis_finish_frame(f, len, left, right);
3492  return res;
3493 }

Referenced by seek_to_sample_coarse(), stb_vorbis_open_file_section(), stb_vorbis_open_memory(), stb_vorbis_seek_frame(), and stb_vorbis_seek_start().

◆ vorbis_search_for_page_pushdata()

static int vorbis_search_for_page_pushdata ( vorb f,
uint8 data,
int  data_len 
)
static

Definition at line 4239 of file stb_vorbis.c.

4240 {
4241  int i,n;
4242  for (i=0; i < f->page_crc_tests; ++i)
4243  f->scan[i].bytes_done = 0;
4244 
4245  // if we have room for more scans, search for them first, because
4246  // they may cause us to stop early if their header is incomplete
4248  if (data_len < 4) return 0;
4249  data_len -= 3; // need to look for 4-byte sequence, so don't miss
4250  // one that straddles a boundary
4251  for (i=0; i < data_len; ++i) {
4252  if (data[i] == 0x4f) {
4253  if (0==memcmp(data+i, ogg_page_header, 4)) {
4254  int j,len;
4255  uint32 crc;
4256  // make sure we have the whole page header
4257  if (i+26 >= data_len || i+27+data[i+26] >= data_len) {
4258  // only read up to this page start, so hopefully we'll
4259  // have the whole page header start next time
4260  data_len = i;
4261  break;
4262  }
4263  // ok, we have it all; compute the length of the page
4264  len = 27 + data[i+26];
4265  for (j=0; j < data[i+26]; ++j)
4266  len += data[i+27+j];
4267  // scan everything up to the embedded crc (which we must 0)
4268  crc = 0;
4269  for (j=0; j < 22; ++j)
4270  crc = crc32_update(crc, data[i+j]);
4271  // now process 4 0-bytes
4272  for ( ; j < 26; ++j)
4273  crc = crc32_update(crc, 0);
4274  // len is the total number of bytes we need to scan
4275  n = f->page_crc_tests++;
4276  f->scan[n].bytes_left = len-j;
4277  f->scan[n].crc_so_far = crc;
4278  f->scan[n].goal_crc = data[i+22] + (data[i+23] << 8) + (data[i+24]<<16) + (data[i+25]<<24);
4279  // if the last frame on a page is continued to the next, then
4280  // we can't recover the sample_loc immediately
4281  if (data[i+27+data[i+26]-1] == 255)
4282  f->scan[n].sample_loc = ~0;
4283  else
4284  f->scan[n].sample_loc = data[i+6] + (data[i+7] << 8) + (data[i+ 8]<<16) + (data[i+ 9]<<24);
4285  f->scan[n].bytes_done = i+j;
4287  break;
4288  // keep going if we still have room for more
4289  }
4290  }
4291  }
4292  }
4293 
4294  for (i=0; i < f->page_crc_tests;) {
4295  uint32 crc;
4296  int j;
4297  int n = f->scan[i].bytes_done;
4298  int m = f->scan[i].bytes_left;
4299  if (m > data_len - n) m = data_len - n;
4300  // m is the bytes to scan in the current chunk
4301  crc = f->scan[i].crc_so_far;
4302  for (j=0; j < m; ++j)
4303  crc = crc32_update(crc, data[n+j]);
4304  f->scan[i].bytes_left -= m;
4305  f->scan[i].crc_so_far = crc;
4306  if (f->scan[i].bytes_left == 0) {
4307  // does it match?
4308  if (f->scan[i].crc_so_far == f->scan[i].goal_crc) {
4309  // Houston, we have page
4310  data_len = n+m; // consumption amount is wherever that scan ended
4311  f->page_crc_tests = -1; // drop out of page scan mode
4312  f->previous_length = 0; // decode-but-don't-output one frame
4313  f->next_seg = -1; // start a new page
4314  f->current_loc = f->scan[i].sample_loc; // set the current sample location
4315  // to the amount we'd have decoded had we decoded this page
4316  f->current_loc_valid = f->current_loc != ~0U;
4317  return data_len;
4318  }
4319  // delete entry
4320  f->scan[i] = f->scan[--f->page_crc_tests];
4321  } else {
4322  ++i;
4323  }
4324  }
4325 
4326  return data_len;
4327 }

Referenced by stb_vorbis_decode_frame_pushdata().

◆ vorbis_validate()

static int vorbis_validate ( uint8 data)
static

Definition at line 1189 of file stb_vorbis.c.

1190 {
1191  static uint8 vorbis[6] = { 'v', 'o', 'r', 'b', 'i', 's' };
1192  return memcmp(data, vorbis, 6) == 0;
1193 }

Referenced by start_decoder().

Variable Documentation

◆ channel_position

int8 channel_position[7][6]
static
Initial value:
=
{
{ 0 },
{ C },
{ L, R },
{ L, C, R },
{ L, R, L, R },
{ L, C, R, L, R },
{ L, C, R, L, R, C },
}

Definition at line 5006 of file stb_vorbis.c.

Referenced by compute_samples(), and compute_stereo_samples().

◆ crc_table

uint32 crc_table[256]
static

Definition at line 947 of file stb_vorbis.c.

Referenced by crc32_init(), and crc32_update().

◆ inverse_db_table

float inverse_db_table[256]
static

Definition at line 1889 of file stb_vorbis.c.

Referenced by do_floor(), and draw_line().

◆ ogg_page_header

uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 }
static
PLAYBACK_LEFT
#define PLAYBACK_LEFT
Definition: stb_vorbis.c:4999
stb_vorbis::known_loc_for_packet
uint32 known_loc_for_packet
Definition: stb_vorbis.c:840
vorbis_decode_packet
static int vorbis_decode_packet(vorb *f, int *len, int *p_left, int *p_right)
Definition: stb_vorbis.c:3427
Codebook::sequence_p
uint8 sequence_p
Definition: stb_vorbis.c:647
L
#define L
Definition: stb_vorbis.c:5002
stb_vorbis::window
float * window[2]
Definition: stb_vorbis.c:822
y2
GLdouble GLdouble GLdouble y2
Definition: qgl_win.c:301
stb_vorbis_get_frame_short_interleaved
int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts)
Definition: stb_vorbis.c:5165
get8_packet
static int get8_packet(vorb *f)
Definition: stb_vorbis.c:1529
compute_sorted_huffman
static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values)
Definition: stb_vorbis.c:1135
stb_vorbis::residue_count
int residue_count
Definition: stb_vorbis.c:792
VORBIS_file_open_failure
@ VORBIS_file_open_failure
Definition: stb_vorbis.c:352
stb_vorbis_open_file_section
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)
Definition: stb_vorbis.c:4932
imdct_step3_inner_s_loop
static void imdct_step3_inner_s_loop(int n, float *e, int i_off, int k_off, float *A, int a_off, int k0)
Definition: stb_vorbis.c:2481
setup_temp_malloc
static void * setup_temp_malloc(vorb *f, int sz)
Definition: stb_vorbis.c:925
CRCscan::goal_crc
uint32 goal_crc
Definition: stb_vorbis.c:731
TRUE
#define TRUE
Definition: stb_vorbis.c:617
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
DECODE
#define DECODE(var, f, c)
Definition: stb_vorbis.c:1697
temp_free
#define temp_free(f, p)
Definition: stb_vorbis.c:886
stb_vorbis::setup_offset
int setup_offset
Definition: stb_vorbis.c:775
Floor0::bark_map_size
uint16 bark_map_size
Definition: stb_vorbis.c:666
Floor1::rangebits
uint8 rangebits
Definition: stb_vorbis.c:685
Codebook::multiplicands
codetype * multiplicands
Definition: stb_vorbis.c:650
codebook_decode_deinterleave_repeat
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)
Definition: stb_vorbis.c:1808
LINE_OP
#define LINE_OP(a, b)
Definition: stb_vorbis.c:1966
stb_vorbis::next_seg
int next_seg
Definition: stb_vorbis.c:833
first
GLint first
Definition: qgl_win.c:128
temp_alloc_save
#define temp_alloc_save(f)
Definition: stb_vorbis.c:888
int16
signed short int16
Definition: stb_vorbis.c:612
vorbis_search_for_page_pushdata
static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len)
Definition: stb_vorbis.c:4239
VORBIS_need_more_data
@ VORBIS_need_more_data
Definition: stb_vorbis.c:346
crc32_update
static __forceinline uint32 crc32_update(uint32 crc, uint8 byte)
Definition: stb_vorbis.c:959
compute_samples
static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len)
Definition: stb_vorbis.c:5049
Mode::mapping
uint8 mapping
Definition: stb_vorbis.c:724
stb_vorbis::p_first
ProbedPage p_first
Definition: stb_vorbis.c:771
stb_vorbis::samples_output
uint32 samples_output
Definition: stb_vorbis.c:842
codetype
float codetype
Definition: stb_vorbis.c:621
NO_CODE
#define NO_CODE
Definition: stb_vorbis.c:1006
CRC32_POLY
#define CRC32_POLY
Definition: stb_vorbis.c:945
Codebook::lookup_type
uint8 lookup_type
Definition: stb_vorbis.c:646
v
GLdouble v
Definition: qgl_win.c:143
start_decoder
static int start_decoder(vorb *f)
Definition: stb_vorbis.c:3561
U
#define U(a, b, c, d, k, s)
Definition: md4.c:27
Floor0::amplitude_bits
uint8 amplitude_bits
Definition: stb_vorbis.c:667
uint16
unsigned short uint16
Definition: stb_vorbis.c:611
vorbis_init
static void vorbis_init(stb_vorbis *p, const stb_vorbis_alloc *z)
Definition: stb_vorbis.c:4173
prep_huffman
static __forceinline void prep_huffman(vorb *f)
Definition: stb_vorbis.c:1577
STB_VORBIS_PUSHDATA_CRC_COUNT
#define STB_VORBIS_PUSHDATA_CRC_COUNT
Definition: stb_vorbis.c:444
Codebook::sparse
uint8 sparse
Definition: stb_vorbis.c:648
ProbedPage
Definition: stb_vorbis.c:738
MappingChannel::magnitude
uint8 magnitude
Definition: stb_vorbis.c:707
ProbedPage::last_decoded_sample
uint32 last_decoded_sample
Definition: stb_vorbis.c:741
stb_vorbis::close_on_free
int close_on_free
Definition: stb_vorbis.c:758
flush_packet
static void flush_packet(vorb *f)
Definition: stb_vorbis.c:1536
predict_point
static int predict_point(int x, int x0, int x1, int y0, int y1)
Definition: stb_vorbis.c:1878
draw_line
static __forceinline void draw_line(float *output, int x0, int y0, int x1, int y1, int n)
Definition: stb_vorbis.c:1977
ProbedPage::page_start
uint32 page_start
Definition: stb_vorbis.c:740
edict_s::map
char * map
Definition: g_local.h:1065
start_page
static int start_page(vorb *f)
Definition: stb_vorbis.c:1451
stb_vorbis_info
Definition: stb_vorbis.c:114
Codebook::sorted_entries
int sorted_entries
Definition: stb_vorbis.c:659
copy_samples
static void copy_samples(short *dest, float *src, int len)
Definition: stb_vorbis.c:5036
vorbis_deinit
static void vorbis_deinit(stb_vorbis *p)
Definition: stb_vorbis.c:4110
get_seek_page_info
static int get_seek_page_info(stb_vorbis *f, ProbedPage *z)
Definition: stb_vorbis.c:4528
stb_vorbis_seek_frame
int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number)
Definition: stb_vorbis.c:4760
x
GLint GLenum GLint x
Definition: qgl_win.c:116
Codebook::minimum_value
float minimum_value
Definition: stb_vorbis.c:643
IS_PUSH_MODE
#define IS_PUSH_MODE(f)
Definition: stb_vorbis.c:860
z
GLdouble GLdouble z
Definition: qgl_win.c:283
i
int i
Definition: q_shared.c:305
INVALID_BITS
#define INVALID_BITS
Definition: stb_vorbis.c:1515
Floor1
Definition: stb_vorbis.c:673
FAST_HUFFMAN_TABLE_SIZE
#define FAST_HUFFMAN_TABLE_SIZE
Definition: stb_vorbis.c:636
stb_vorbis::current_loc
uint32 current_loc
Definition: stb_vorbis.c:815
CODEBOOK_ELEMENT_FAST
#define CODEBOOK_ELEMENT_FAST(c, off)
Definition: stb_vorbis.c:1715
Codebook::lookup_values
uint32 lookup_values
Definition: stb_vorbis.c:649
stb_vorbis::bytes_in_seg
uint8 bytes_in_seg
Definition: stb_vorbis.c:831
DECODE_RAW
#define DECODE_RAW(var, f, c)
Definition: stb_vorbis.c:1660
q
GLdouble GLdouble GLdouble q
Definition: qgl_win.c:344
maybe_start_packet
static int maybe_start_packet(vorb *f)
Definition: stb_vorbis.c:1472
stb_vorbis::finalY
int16 * finalY[STB_VORBIS_MAX_CHANNELS]
Definition: stb_vorbis.c:810
Floor::floor1
Floor1 floor1
Definition: stb_vorbis.c:692
A
static uint32_t A
Definition: md4.c:34
codebook_decode
static int codebook_decode(vorb *f, Codebook *c, float *output, int len)
Definition: stb_vorbis.c:1738
buffer
GLenum GLfloat * buffer
Definition: qgl_win.c:151
Floor1::class_dimensions
uint8 class_dimensions[16]
Definition: stb_vorbis.c:677
stb_vorbis::end_seg_with_known_loc
int end_seg_with_known_loc
Definition: stb_vorbis.c:839
Floor0::rate
uint16 rate
Definition: stb_vorbis.c:665
imdct_step3_inner_s_loop_ld654
static void imdct_step3_inner_s_loop_ld654(int n, float *e, int i_off, float *A, int base_n)
Definition: stb_vorbis.c:2564
go_to_page_before
static int go_to_page_before(stb_vorbis *f, unsigned int limit_offset)
Definition: stb_vorbis.c:4560
Codebook::fast_huffman
int16 fast_huffman[FAST_HUFFMAN_TABLE_SIZE]
Definition: stb_vorbis.c:653
VORBIS_bad_packet_type
@ VORBIS_bad_packet_type
Definition: stb_vorbis.c:371
stb_vorbis::C
float * C[2]
Definition: stb_vorbis.c:821
iter_54
static __forceinline void iter_54(float *z)
Definition: stb_vorbis.c:2532
stb_vorbis::residue_config
Residue * residue_config
Definition: stb_vorbis.c:794
lookup1_values
static int lookup1_values(int entries, int dim)
Definition: stb_vorbis.c:1197
get8
static uint8 get8(vorb *z)
Definition: stb_vorbis.c:1291
Residue
Definition: stb_vorbis.c:695
range
GLsizei range
Definition: qgl_win.c:121
stb_vorbis::channel_buffers
float * channel_buffers[STB_VORBIS_MAX_CHANNELS]
Definition: stb_vorbis.c:803
PAGEFLAG_continued_packet
#define PAGEFLAG_continued_packet
Definition: stb_vorbis.c:1394
is_whole_packet_present
static int is_whole_packet_present(stb_vorbis *f, int end_page)
Definition: stb_vorbis.c:3496
VORBIS_incorrect_stream_serial_number
@ VORBIS_incorrect_stream_serial_number
Definition: stb_vorbis.c:369
PLAYBACK_MONO
#define PLAYBACK_MONO
Definition: stb_vorbis.c:4998
BUFFER_SIZE
#define BUFFER_SIZE
stb_vorbis::channel_buffer_end
int channel_buffer_end
Definition: stb_vorbis.c:852
skip
static void skip(vorb *z, int n)
Definition: stb_vorbis.c:1336
ogg_page_header
static uint8 ogg_page_header[4]
Definition: stb_vorbis.c:1383
neighbors
static void neighbors(uint16 *x, int n, int *plow, int *phigh)
Definition: stb_vorbis.c:1257
residue_decode
static int residue_decode(vorb *f, Codebook *book, float *target, int offset, int n, int rtype)
Definition: stb_vorbis.c:2026
do_floor
static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *finalY, uint8 *step2_flag)
Definition: stb_vorbis.c:3052
STB_VORBIS_MAX_CHANNELS
#define STB_VORBIS_MAX_CHANNELS
Definition: stb_vorbis.c:428
VORBIS_cant_find_last_page
@ VORBIS_cant_find_last_page
Definition: stb_vorbis.c:372
Floor1::values
int values
Definition: stb_vorbis.c:686
stb_vorbis_close
void stb_vorbis_close(stb_vorbis *f)
Definition: stb_vorbis.c:4166
CRCscan::bytes_done
int bytes_done
Definition: stb_vorbis.c:734
ProbedPage::page_end
uint32 page_end
Definition: stb_vorbis.c:740
VORBIS_packet_id
@ VORBIS_packet_id
Definition: stb_vorbis.c:1594
Floor::floor0
Floor0 floor0
Definition: stb_vorbis.c:691
compute_window
static void compute_window(int n, float *window)
Definition: stb_vorbis.c:1225
VORBIS_too_many_channels
@ VORBIS_too_many_channels
Definition: stb_vorbis.c:351
j
GLint j
Definition: qgl_win.c:150
stb_vorbis::residue_types
uint16 residue_types[64]
Definition: stb_vorbis.c:793
PAGEFLAG_last_page
#define PAGEFLAG_last_page
Definition: stb_vorbis.c:1396
VORBIS_continued_packet_flag_invalid
@ VORBIS_continued_packet_flag_invalid
Definition: stb_vorbis.c:368
stb_vorbis::first_audio_page_offset
uint32 first_audio_page_offset
Definition: stb_vorbis.c:769
USE_MEMORY
#define USE_MEMORY(z)
Definition: stb_vorbis.c:1288
vorbis_finish_frame
static int vorbis_finish_frame(stb_vorbis *f, int len, int left, int right)
Definition: stb_vorbis.c:3434
Codebook::entries
int entries
Definition: stb_vorbis.c:641
getn
static int getn(vorb *z, uint8 *data, int n)
Definition: stb_vorbis.c:1317
CHECK
#define CHECK(f)
Definition: stb_vorbis.c:602
stb_vorbis::last_page
int last_page
Definition: stb_vorbis.c:827
stb_vorbis::push_mode
uint8 push_mode
Definition: stb_vorbis.c:767
stb_vorbis_seek_start
int stb_vorbis_seek_start(stb_vorbis *f)
Definition: stb_vorbis.c:4816
stb_vorbis::last_seg_which
int last_seg_which
Definition: stb_vorbis.c:835
codebook_decode_start
static int codebook_decode_start(vorb *f, Codebook *c)
Definition: stb_vorbis.c:1718
stb_vorbis_alloc::alloc_buffer_length_in_bytes
int alloc_buffer_length_in_bytes
Definition: stb_vorbis.c:106
stb_vorbis::last_seg
int last_seg
Definition: stb_vorbis.c:834
Floor0::number_of_books
uint8 number_of_books
Definition: stb_vorbis.c:669
compute_stereo_samples
static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len)
Definition: stb_vorbis.c:5074
u
static int u
Definition: r_part.c:472
CRCscan::crc_so_far
uint32 crc_so_far
Definition: stb_vorbis.c:733
VORBIS_seek_invalid
@ VORBIS_seek_invalid
Definition: stb_vorbis.c:356
VORBIS_unexpected_eof
@ VORBIS_unexpected_eof
Definition: stb_vorbis.c:355
stb_vorbis::valid_bits
int valid_bits
Definition: stb_vorbis.c:837
convert_channels_short_interleaved
static void convert_channels_short_interleaved(int buf_c, short *buffer, int data_c, float **data, int d_offset, int len)
Definition: stb_vorbis.c:5139
stb_vorbis::discard_samples_deferred
int discard_samples_deferred
Definition: stb_vorbis.c:841
VORBIS_invalid_stream_structure_version
@ VORBIS_invalid_stream_structure_version
Definition: stb_vorbis.c:367
VORBIS__no_error
@ VORBIS__no_error
Definition: stb_vorbis.c:344
set_file_offset
static int set_file_offset(stb_vorbis *f, unsigned int loc)
Definition: stb_vorbis.c:1351
stb_vorbis::bit_reverse
uint16 * bit_reverse[2]
Definition: stb_vorbis.c:823
vorbis_decode_packet_rest
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)
Definition: stb_vorbis.c:3159
r
GLdouble GLdouble r
Definition: qgl_win.c:336
MappingChannel
Definition: stb_vorbis.c:705
Mode::windowtype
uint16 windowtype
Definition: stb_vorbis.c:725
get_window
static float * get_window(vorb *f, int len)
Definition: stb_vorbis.c:3038
imdct_step3_iter0_loop
static void imdct_step3_iter0_loop(int n, float *e, int i_off, int k_off, float *A)
Definition: stb_vorbis.c:2386
stb_vorbis::sample_rate
unsigned int sample_rate
Definition: stb_vorbis.c:747
VORBIS_seek_without_length
@ VORBIS_seek_without_length
Definition: stb_vorbis.c:353
stb_vorbis::p_last
ProbedPage p_last
Definition: stb_vorbis.c:771
stb_vorbis::floor_config
Floor * floor_config
Definition: stb_vorbis.c:791
CRCscan::sample_loc
uint32 sample_loc
Definition: stb_vorbis.c:735
Floor1::partitions
uint8 partitions
Definition: stb_vorbis.c:675
inverse_mdct
static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype)
Definition: stb_vorbis.c:2608
B
static uint32_t B
Definition: md4.c:35
crc32_init
static void crc32_init(void)
Definition: stb_vorbis.c:948
Floor0::amplitude_offset
uint8 amplitude_offset
Definition: stb_vorbis.c:668
compute_twiddle_factors
static void compute_twiddle_factors(int n, float *A, float *B, float *C)
Definition: stb_vorbis.c:1208
stb_vorbis::stream_end
uint8 * stream_end
Definition: stb_vorbis.c:763
Mapping::chan
MappingChannel * chan
Definition: stb_vorbis.c:715
stb_vorbis::channel_buffer_start
int channel_buffer_start
Definition: stb_vorbis.c:851
EOP
#define EOP
Definition: stb_vorbis.c:1514
temp_alloc_restore
#define temp_alloc_restore(f, p)
Definition: stb_vorbis.c:889
stbv__floor_ordering::x
uint16 x
Definition: stb_vorbis.c:1271
Floor1::partition_class_list
uint8 partition_class_list[32]
Definition: stb_vorbis.c:676
stb_vorbis::f
FILE * f
Definition: stb_vorbis.c:756
stb_vorbis::scan
CRCscan scan[STB_VORBIS_PUSHDATA_CRC_COUNT]
Definition: stb_vorbis.c:847
stb_vorbis::page_flag
uint8 page_flag
Definition: stb_vorbis.c:830
Floor1::floor1_multiplier
uint8 floor1_multiplier
Definition: stb_vorbis.c:684
Floor0::order
uint8 order
Definition: stb_vorbis.c:664
stb_vorbis_open_memory
stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc_buffer)
Definition: stb_vorbis.c:4973
uint8
unsigned char uint8
Definition: stb_vorbis.c:609
FAST_HUFFMAN_TABLE_MASK
#define FAST_HUFFMAN_TABLE_MASK
Definition: stb_vorbis.c:637
compute_accelerated_huffman
static void compute_accelerated_huffman(Codebook *c)
Definition: stb_vorbis.c:1090
VORBIS_missing_capture_pattern
@ VORBIS_missing_capture_pattern
Definition: stb_vorbis.c:366
VORBIS_packet_setup
@ VORBIS_packet_setup
Definition: stb_vorbis.c:1596
error
static int error(vorb *f, enum STBVorbisError e)
Definition: stb_vorbis.c:865
stb_vorbis::setup_memory_required
unsigned int setup_memory_required
Definition: stb_vorbis.c:750
FASTDEF
#define FASTDEF(x)
Definition: stb_vorbis.c:5024
stb_vorbis::segments
uint8 segments[255]
Definition: stb_vorbis.c:829
SAMPLE_unknown
#define SAMPLE_unknown
Definition: stb_vorbis.c:4517
VORBIS_feature_not_supported
@ VORBIS_feature_not_supported
Definition: stb_vorbis.c:350
NULL
#define NULL
Definition: q_shared.h:67
y1
GLdouble y1
Definition: qgl_win.c:301
STBVorbisError
STBVorbisError
Definition: stb_vorbis.c:342
Codebook
Definition: stb_vorbis.c:639
stb_vorbis_get_file_offset
unsigned int stb_vorbis_get_file_offset(stb_vorbis *f)
Definition: stb_vorbis.c:4430
stb_vorbis::acc
uint32 acc
Definition: stb_vorbis.c:836
add_entry
static void add_entry(Codebook *c, uint32 huff_code, int symbol, int count, int len, uint32 *values)
Definition: stb_vorbis.c:1031
channels
channel_t channels[MAX_CHANNELS]
Definition: snd_dma.c:42
Mapping
Definition: stb_vorbis.c:712
Mapping::coupling_steps
uint16 coupling_steps
Definition: stb_vorbis.c:714
Mapping::submap_floor
uint8 submap_floor[15]
Definition: stb_vorbis.c:717
start_packet
static int start_packet(vorb *f)
Definition: stb_vorbis.c:1457
Mode
Definition: stb_vorbis.c:721
stb_vorbis
Definition: stb_vorbis.c:744
VORBIS_seek_failed
@ VORBIS_seek_failed
Definition: stb_vorbis.c:373
setup_free
static void setup_free(vorb *f, void *p)
Definition: stb_vorbis.c:919
Codebook::delta_value
float delta_value
Definition: stb_vorbis.c:644
Codebook::codewords
uint32 * codewords
Definition: stb_vorbis.c:651
stb_vorbis_open_file
stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close, int *error, const stb_vorbis_alloc *alloc_buffer)
Definition: stb_vorbis.c:4953
CODEBOOK_ELEMENT_BASE
#define CODEBOOK_ELEMENT_BASE(c)
Definition: stb_vorbis.c:1716
stb_vorbis::eof
int eof
Definition: stb_vorbis.c:779
s
static fixed16_t s
Definition: r_scan.c:30
y
GLint y
Definition: qgl_win.c:115
VORBIS_packet_comment
@ VORBIS_packet_comment
Definition: stb_vorbis.c:1595
Mapping::submap_residue
uint8 submap_residue[15]
Definition: stb_vorbis.c:718
Floor1::sorted_order
uint8 sorted_order[31 *8+2]
Definition: stb_vorbis.c:682
stb_vorbis_info::setup_memory_required
unsigned int setup_memory_required
Definition: stb_vorbis.c:119
stb_vorbis_info::sample_rate
unsigned int sample_rate
Definition: stb_vorbis.c:116
stb_vorbis_alloc::alloc_buffer
char * alloc_buffer
Definition: stb_vorbis.c:105
setup_malloc
static void * setup_malloc(vorb *f, int sz)
Definition: stb_vorbis.c:906
Codebook::dimensions
int dimensions
Definition: stb_vorbis.c:641
convert_samples_short
static void convert_samples_short(int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples)
Definition: stb_vorbis.c:5113
uint32
unsigned int uint32
Definition: stb_vorbis.c:613
stb_vorbis::previous_window
float * previous_window[STB_VORBIS_MAX_CHANNELS]
Definition: stb_vorbis.c:806
stb_vorbis::channels
int channels
Definition: stb_vorbis.c:748
stb_vorbis::f_start
uint32 f_start
Definition: stb_vorbis.c:757
stb_vorbis_get_frame_float
int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output)
Definition: stb_vorbis.c:4908
stb_vorbis_stream_length_in_samples
unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
Definition: stb_vorbis.c:4826
PAGEFLAG_first_page
#define PAGEFLAG_first_page
Definition: stb_vorbis.c:1395
STB_VORBIS_FAST_HUFFMAN_LENGTH
#define STB_VORBIS_FAST_HUFFMAN_LENGTH
Definition: stb_vorbis.c:453
float32_unpack
static float float32_unpack(uint32 x)
Definition: stb_vorbis.c:1013
get32
static uint32 get32(vorb *f)
Definition: stb_vorbis.c:1307
stb_vorbis::mapping
Mapping * mapping
Definition: stb_vorbis.c:796
stb_vorbis::segment_count
int segment_count
Definition: stb_vorbis.c:828
stb_vorbis::temp_offset
int temp_offset
Definition: stb_vorbis.c:776
setup_temp_free
static void setup_temp_free(vorb *f, void *p, int sz)
Definition: stb_vorbis.c:936
stb_vorbis_info::setup_temp_memory_required
unsigned int setup_temp_memory_required
Definition: stb_vorbis.c:120
uint32_compare
static int STBV_CDECL uint32_compare(const void *p, const void *q)
Definition: stb_vorbis.c:1118
stb_vorbis_info::channels
int channels
Definition: stb_vorbis.c:117
CRCscan::bytes_left
int bytes_left
Definition: stb_vorbis.c:732
Codebook::codeword_lengths
uint8 * codeword_lengths
Definition: stb_vorbis.c:642
check_endianness
#define check_endianness()
Definition: stb_vorbis.c:5029
stb_vorbis::stream_len
uint32 stream_len
Definition: stb_vorbis.c:765
C
#define C
Definition: stb_vorbis.c:5003
VORBIS_invalid_setup
@ VORBIS_invalid_setup
Definition: stb_vorbis.c:362
start_page_no_capturepattern
static int start_page_no_capturepattern(vorb *f)
Definition: stb_vorbis.c:1398
stb_vorbis::first_decode
uint8 first_decode
Definition: stb_vorbis.c:832
Mapping::submaps
uint8 submaps
Definition: stb_vorbis.c:716
point_compare
static int STBV_CDECL point_compare(const void *p, const void *q)
Definition: stb_vorbis.c:1274
temp_block_array
#define temp_block_array(f, count, size)
Definition: stb_vorbis.c:891
Floor
Definition: stb_vorbis.c:689
FAST_SCALED_FLOAT_TO_INT
#define FAST_SCALED_FLOAT_TO_INT(temp, x, s)
Definition: stb_vorbis.c:5028
stb_vorbis::stream
uint8 * stream
Definition: stb_vorbis.c:761
stb_vorbis::error
enum STBVorbisError error
Definition: stb_vorbis.c:780
Floor1::class_masterbooks
uint8 class_masterbooks[16]
Definition: stb_vorbis.c:679
stb_vorbis::codebook_count
int codebook_count
Definition: stb_vorbis.c:787
stbv__floor_ordering
Definition: stb_vorbis.c:1269
stb_vorbis_get_frame_short
int stb_vorbis_get_frame_short(stb_vorbis *f, int num_c, short **buffer, int num_samples)
Definition: stb_vorbis.c:5129
stb_vorbis::outputs
float * outputs[STB_VORBIS_MAX_CHANNELS]
Definition: stb_vorbis.c:804
stb_vorbis::previous_length
int previous_length
Definition: stb_vorbis.c:807
include_in_sort
static int include_in_sort(Codebook *c, uint8 len)
Definition: stb_vorbis.c:1125
stb_vorbis::page_crc_tests
int page_crc_tests
Definition: stb_vorbis.c:845
imdct_step3_inner_r_loop
static void imdct_step3_inner_r_loop(int lim, float *e, int d0, int k_off, float *A, int k1)
Definition: stb_vorbis.c:2431
MappingChannel::angle
uint8 angle
Definition: stb_vorbis.c:708
stb_vorbis::current_loc_valid
int current_loc_valid
Definition: stb_vorbis.c:816
vorbis_decode_initial
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)
Definition: stb_vorbis.c:3103
stb_vorbis::blocksize_1
int blocksize_1
Definition: stb_vorbis.c:786
temp_alloc
#define temp_alloc(f, size)
Definition: stb_vorbis.c:882
stb_vorbis::setup_temp_memory_required
unsigned int setup_temp_memory_required
Definition: stb_vorbis.c:752
init_blocksize
static int init_blocksize(vorb *f, int b, int n)
Definition: stb_vorbis.c:1240
peek_decode_initial
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)
Definition: stb_vorbis.c:4735
compute_bitreverse
static void compute_bitreverse(int n, uint16 *rev)
Definition: stb_vorbis.c:1232
stb_vorbis::stream_start
uint8 * stream_start
Definition: stb_vorbis.c:762
codebook_decode_scalar_raw
static int codebook_decode_scalar_raw(vorb *f, Codebook *c)
Definition: stb_vorbis.c:1599
codebook_decode_step
static int codebook_decode_step(vorb *f, Codebook *c, float *output, int len, int step)
Definition: stb_vorbis.c:1777
w
GLdouble GLdouble GLdouble w
Definition: qgl_win.c:291
FALSE
#define FALSE
Definition: stb_vorbis.c:618
right
GLdouble right
Definition: qgl_win.c:159
Floor1::class_subclasses
uint8 class_subclasses[16]
Definition: stb_vorbis.c:678
values
GLfloat * values
Definition: qgl_win.c:175
stb_vorbis::packet_bytes
int packet_bytes
Definition: stb_vorbis.c:838
stb_vorbis::temp_memory_required
unsigned int temp_memory_required
Definition: stb_vorbis.c:751
Floor1::subclass_books
int16 subclass_books[16][8]
Definition: stb_vorbis.c:680
stb_vorbis::codebooks
Codebook * codebooks
Definition: stb_vorbis.c:788
PLAYBACK_RIGHT
#define PLAYBACK_RIGHT
Definition: stb_vorbis.c:5000
vorbis_find_page
static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last)
Definition: stb_vorbis.c:4446
Floor1::Xlist
uint16 Xlist[31 *8+2]
Definition: stb_vorbis.c:681
crc_table
static uint32 crc_table[256]
Definition: stb_vorbis.c:947
mode
GLenum mode
Definition: qgl_win.c:113
bit_reverse
static unsigned int bit_reverse(unsigned int n)
Definition: stb_vorbis.c:966
VORBIS_invalid_first_page
@ VORBIS_invalid_first_page
Definition: stb_vorbis.c:370
get8_packet_raw
static int get8_packet_raw(vorb *f)
Definition: stb_vorbis.c:1517
Codebook::value_bits
uint8 value_bits
Definition: stb_vorbis.c:645
mask
GLint GLuint mask
Definition: qgl_win.c:317
Codebook::sorted_codewords
uint32 * sorted_codewords
Definition: stb_vorbis.c:657
stb_vorbis::A
float * A[2]
Definition: stb_vorbis.c:821
square
static float square(float x)
Definition: stb_vorbis.c:975
VORBIS_outofmem
@ VORBIS_outofmem
Definition: stb_vorbis.c:349
ilog
static int ilog(int32 n)
Definition: stb_vorbis.c:983
Mode::blockflag
uint8 blockflag
Definition: stb_vorbis.c:723
edict_s::size
vec3_t size
Definition: g_local.h:991
vorbis_validate
static int vorbis_validate(uint8 *data)
Definition: stb_vorbis.c:1189
M_PI
#define M_PI
Definition: stb_vorbis.c:1002
stb_vorbis_flush_pushdata
void stb_vorbis_flush_pushdata(stb_vorbis *f)
Definition: stb_vorbis.c:4227
VORBIS_invalid_stream
@ VORBIS_invalid_stream
Definition: stb_vorbis.c:363
stb_vorbis::total_samples
uint32 total_samples
Definition: stb_vorbis.c:800
STB_VORBIS_FAST_HUFFMAN_SHORT
#define STB_VORBIS_FAST_HUFFMAN_SHORT
Definition: stb_vorbis.c:467
Floor0::book_list
uint8 book_list[16]
Definition: stb_vorbis.c:670
stb_vorbis_open_filename
stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const stb_vorbis_alloc *alloc_buffer)
Definition: stb_vorbis.c:4963
AA
static uint32_t AA
Definition: md4.c:34
stb_vorbis::B
float * B[2]
Definition: stb_vorbis.c:821
stb_vorbis::mapping_count
int mapping_count
Definition: stb_vorbis.c:795
Mode::transformtype
uint16 transformtype
Definition: stb_vorbis.c:726
Codebook::sorted_values
int * sorted_values
Definition: stb_vorbis.c:658
MappingChannel::mux
uint8 mux
Definition: stb_vorbis.c:709
stb_vorbis::mode_count
int mode_count
Definition: stb_vorbis.c:797
R
#define R
Definition: stb_vorbis.c:5004
stbv__floor_ordering::id
uint16 id
Definition: stb_vorbis.c:1271
compute_codewords
static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values)
Definition: stb_vorbis.c:1042
decode_residue
static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int rn, uint8 *do_not_decode)
Definition: stb_vorbis.c:2045
stb_vorbis::floor_types
uint16 floor_types[64]
Definition: stb_vorbis.c:790
next_segment
static int next_segment(vorb *f)
Definition: stb_vorbis.c:1493
edict_s::target
char * target
Definition: g_local.h:1017
channel_position
static int8 channel_position[7][6]
Definition: stb_vorbis.c:5006
stb_vorbis::mode_config
Mode mode_config[64]
Definition: stb_vorbis.c:798
stb_vorbis::floor_count
int floor_count
Definition: stb_vorbis.c:789
inverse_db_table
static float inverse_db_table[256]
Definition: stb_vorbis.c:1889
stb_vorbis::alloc
stb_vorbis_alloc alloc
Definition: stb_vorbis.c:774
count
GLint GLsizei count
Definition: qgl_win.c:128
get_bits
static uint32 get_bits(vorb *f, int n)
Definition: stb_vorbis.c:1543
stb_vorbis_info::temp_memory_required
unsigned int temp_memory_required
Definition: stb_vorbis.c:121
DECODE_VQ
#define DECODE_VQ(var, f, c)
Definition: stb_vorbis.c:1702
stb_vorbis_info::max_frame_size
int max_frame_size
Definition: stb_vorbis.c:123
seek_to_sample_coarse
static int seek_to_sample_coarse(stb_vorbis *f, uint32 sample_number)
Definition: stb_vorbis.c:4585
VORBIS_invalid_api_mixing
@ VORBIS_invalid_api_mixing
Definition: stb_vorbis.c:348
stb_vorbis::blocksize
int blocksize[2]
Definition: stb_vorbis.c:785
vorbis_alloc
static stb_vorbis * vorbis_alloc(stb_vorbis *f)
Definition: stb_vorbis.c:4219
Floor1::neighbors
uint8 neighbors[31 *8+2][2]
Definition: stb_vorbis.c:683
stb_vorbis::blocksize_0
int blocksize_0
Definition: stb_vorbis.c:786
vorbis_pump_first_frame
static int vorbis_pump_first_frame(stb_vorbis *f)
Definition: stb_vorbis.c:3486
Floor0
Definition: stb_vorbis.c:662
capture_pattern
static int capture_pattern(vorb *f)
Definition: stb_vorbis.c:1385