Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more static arrays in stb_vorbis const #1660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions stb_vorbis.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,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 @@ -1026,7 +1026,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 @@ -1161,8 +1161,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 @@ -1232,7 +1232,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 @@ -1319,8 +1319,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 @@ -1426,7 +1426,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 @@ -1943,7 +1943,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 @@ -3206,7 +3206,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 @@ -3527,7 +3527,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 @@ -3542,7 +3542,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 @@ -4350,7 +4350,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 @@ -4456,11 +4456,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 @@ -4518,8 +4518,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 @@ -5104,9 +5104,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 @@ -5132,7 +5132,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 @@ -5245,7 +5245,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