Skip to content

Commit

Permalink
stb_vorbis: Make static arrays const.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 authored and sezero committed Feb 22, 2025
1 parent 2880444 commit 5effa72
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/stb_vorbis.h
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ struct stb_vorbis
int close_on_free;
#endif

uint8 *stream;
uint8 *stream_start;
uint8 *stream_end;
const uint8 *stream;
const uint8 *stream_start;
const uint8 *stream_end;

uint32 stream_len;

Expand Down Expand Up @@ -1081,7 +1081,7 @@ static float square(float x)
// @OPTIMIZE: called multiple times per-packet with "constants"; move to setup
static int ilog(int32 n)
{
static signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 };
static const signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 };

if (n < 0) return 0; // signed n returns 0

Expand Down Expand Up @@ -1218,8 +1218,8 @@ static void compute_accelerated_huffman(Codebook *c)

static int STBV_CDECL uint32_compare(const void *p, const void *q)
{
uint32 x = * (uint32 *) p;
uint32 y = * (uint32 *) q;
uint32 x = * (const uint32 *) p;
uint32 y = * (const uint32 *) q;
return x < y ? -1 : x > y;
}

Expand Down Expand Up @@ -1289,7 +1289,7 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values)
// only run while parsing the header (3 times)
static int vorbis_validate(uint8 *data)
{
static uint8 vorbis[6] = { 'v', 'o', 'r', 'b', 'i', 's' };
static const uint8 vorbis[6] = { 'v', 'o', 'r', 'b', 'i', 's' };
return memcmp(data, vorbis, 6) == 0;
}

Expand Down Expand Up @@ -1380,8 +1380,8 @@ typedef struct

static int STBV_CDECL point_compare(const void *p, const void *q)
{
stbv__floor_ordering *a = (stbv__floor_ordering *) p;
stbv__floor_ordering *b = (stbv__floor_ordering *) q;
const stbv__floor_ordering *a = (const stbv__floor_ordering *) p;
const stbv__floor_ordering *b = (const stbv__floor_ordering *) q;
return a->x < b->x ? -1 : a->x > b->x;
}

Expand Down Expand Up @@ -1526,7 +1526,7 @@ static int set_file_offset(stb_vorbis *f, unsigned int loc)
}


static uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 };
static const uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 };

static int capture_pattern(vorb *f)
{
Expand Down Expand Up @@ -2047,7 +2047,7 @@ static int predict_point(int x, int x0, int x1, int y0, int y1)
}

// the following table is block-copied from the specification
static float inverse_db_table[256] =
static const float inverse_db_table[256] =
{
1.0649863e-07f, 1.1341951e-07f, 1.2079015e-07f, 1.2863978e-07f,
1.3699951e-07f, 1.4590251e-07f, 1.5538408e-07f, 1.6548181e-07f,
Expand Down Expand Up @@ -3310,7 +3310,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start,
if (get_bits(f, 1)) {
short *finalY;
uint8 step2_flag[256];
static int range_list[4] = { 256, 128, 86, 64 };
static const int range_list[4] = { 256, 128, 86, 64 };
int range = range_list[g->floor1_multiplier-1];
int offset = 2;
finalY = f->finalY[i];
Expand Down Expand Up @@ -3633,7 +3633,7 @@ static int is_whole_packet_present(stb_vorbis *f)
// of state to restore (primarily the page segment table)

int s = f->next_seg, first = TRUE;
uint8 *p = f->stream;
const uint8 *p = f->stream;

if (s != -1) { // if we're not starting the packet with a 'continue on next page' flag
for (; s < f->segment_count; ++s) {
Expand All @@ -3648,7 +3648,7 @@ static int is_whole_packet_present(stb_vorbis *f)
first = FALSE;
}
for (; s == -1;) {
uint8 *q;
const uint8 *q;
int n;

// check that we have the page header ready
Expand Down Expand Up @@ -4513,7 +4513,7 @@ void stb_vorbis_flush_pushdata(stb_vorbis *f)
f->channel_buffer_end = 0;
}

static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len)
static int vorbis_search_for_page_pushdata(vorb *f, const uint8 *data, int data_len)
{
int i,n;
for (i=0; i < f->page_crc_tests; ++i)
Expand Down Expand Up @@ -4619,11 +4619,11 @@ int stb_vorbis_decode_frame_pushdata(

if (f->page_crc_tests >= 0) {
*samples = 0;
return vorbis_search_for_page_pushdata(f, (uint8 *) data, data_len);
return vorbis_search_for_page_pushdata(f, data, data_len);
}

f->stream = (uint8 *) data;
f->stream_end = (uint8 *) data + data_len;
f->stream = (const uint8 *) data;
f->stream_end = (const uint8 *) data + data_len;
f->error = VORBIS__no_error;

// check that we have the entire packet in memory
Expand Down Expand Up @@ -4681,8 +4681,8 @@ stb_vorbis *stb_vorbis_open_pushdata(
{
stb_vorbis *f, p;
vorbis_init(&p, alloc);
p.stream = (uint8 *) data;
p.stream_end = (uint8 *) data + data_len;
p.stream = (const uint8 *) data;
p.stream_end = (const uint8 *) data + data_len;
p.push_mode = TRUE;
if (!start_decoder(&p)) {
if (p.eof)
Expand Down Expand Up @@ -5310,9 +5310,9 @@ stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *err
return NULL;
}
vorbis_init(&p, alloc);
p.stream = (uint8 *) data;
p.stream_end = (uint8 *) data + len;
p.stream_start = (uint8 *) p.stream;
p.stream = (const uint8 *) data;
p.stream_end = (const uint8 *) data + len;
p.stream_start = (const uint8 *) p.stream;
p.stream_len = len;
p.push_mode = FALSE;
if (start_decoder(&p)) {
Expand All @@ -5338,7 +5338,7 @@ stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *err
#define C (PLAYBACK_LEFT | PLAYBACK_RIGHT | PLAYBACK_MONO)
#define R (PLAYBACK_RIGHT | PLAYBACK_MONO)

static int8 channel_position[7][6] =
static const int8 channel_position[7][6] =
{
{ 0 },
{ C },
Expand Down Expand Up @@ -5453,7 +5453,7 @@ static void convert_samples_short(int buf_c, short **buffer, int b_offset, int d
{
int i;
if (buf_c != data_c && buf_c <= 2 && data_c <= 6) {
static int channel_selector[3][2] = { {0}, {PLAYBACK_MONO}, {PLAYBACK_LEFT, PLAYBACK_RIGHT} };
static const int channel_selector[3][2] = { {0}, {PLAYBACK_MONO}, {PLAYBACK_LEFT, PLAYBACK_RIGHT} };
for (i=0; i < buf_c; ++i)
compute_samples(channel_selector[buf_c][i], buffer[i]+b_offset, data_c, data, d_offset, samples);
} else {
Expand Down

0 comments on commit 5effa72

Please sign in to comment.