Update C sources and examples
This commit is contained in:
parent
3b28d17b95
commit
8f1ad11c49
100 changed files with 2081 additions and 1686 deletions
126
raylib/external/stb_vorbis.c
vendored
126
raylib/external/stb_vorbis.c
vendored
|
@ -162,21 +162,23 @@
|
|||
#endif
|
||||
|
||||
#ifndef STB_VORBIS_NO_CRT
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#if !(defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh))
|
||||
#include <malloc.h>
|
||||
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__)
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
// find definition of alloca if it's not in stdlib.h:
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__)
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
#else // STB_VORBIS_NO_CRT
|
||||
#define NULL 0
|
||||
#define malloc(s) 0
|
||||
#define free(s) ((void) 0)
|
||||
#define realloc(s) 0
|
||||
#define NULL 0
|
||||
#define malloc(s) 0
|
||||
#define free(s) ((void) 0)
|
||||
#define realloc(s) 0
|
||||
#endif // STB_VORBIS_NO_CRT
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -597,17 +599,18 @@ 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 };
|
||||
|
||||
if (n < 0) return 0; // signed n returns 0
|
||||
|
||||
// 2 compares if n < 16, 3 compares otherwise (4 if signed or n > 1<<29)
|
||||
if (n < (1 << 14))
|
||||
if (n < (1 << 4)) return 0 + log2_4[n ];
|
||||
else if (n < (1 << 9)) return 5 + log2_4[n >> 5];
|
||||
if (n < (1 << 4)) return 0 + log2_4[n ];
|
||||
else if (n < (1 << 9)) return 5 + log2_4[n >> 5];
|
||||
else return 10 + log2_4[n >> 10];
|
||||
else if (n < (1 << 24))
|
||||
if (n < (1 << 19)) return 15 + log2_4[n >> 15];
|
||||
if (n < (1 << 19)) return 15 + log2_4[n >> 15];
|
||||
else return 20 + log2_4[n >> 20];
|
||||
else if (n < (1 << 29)) return 25 + log2_4[n >> 25];
|
||||
else if (n < (1 << 31)) return 30 + log2_4[n >> 30];
|
||||
else return 0; // signed n returns 0
|
||||
else if (n < (1 << 29)) return 25 + log2_4[n >> 25];
|
||||
else return 30 + log2_4[n >> 30];
|
||||
}
|
||||
|
||||
#ifndef M_PI
|
||||
|
@ -880,13 +883,13 @@ static void neighbors(uint16 *x, int n, int *plow, int *phigh)
|
|||
// this has been repurposed so y is now the original index instead of y
|
||||
typedef struct
|
||||
{
|
||||
uint16 x,y;
|
||||
} Point;
|
||||
uint16 x,id;
|
||||
} stbv__floor_ordering;
|
||||
|
||||
static int STBV_CDECL point_compare(const void *p, const void *q)
|
||||
{
|
||||
Point *a = (Point *) p;
|
||||
Point *b = (Point *) q;
|
||||
stbv__floor_ordering *a = (stbv__floor_ordering *) p;
|
||||
stbv__floor_ordering *b = (stbv__floor_ordering *) q;
|
||||
return a->x < b->x ? -1 : a->x > b->x;
|
||||
}
|
||||
|
||||
|
@ -3095,11 +3098,13 @@ static int vorbis_finish_frame(stb_vorbis *f, int len, int left, int right)
|
|||
return right - left;
|
||||
}
|
||||
|
||||
static void vorbis_pump_first_frame(stb_vorbis *f)
|
||||
static int vorbis_pump_first_frame(stb_vorbis *f)
|
||||
{
|
||||
int len, right, left;
|
||||
if (vorbis_decode_packet(f, &len, &left, &right))
|
||||
int len, right, left, res;
|
||||
res = vorbis_decode_packet(f, &len, &left, &right);
|
||||
if (res)
|
||||
vorbis_finish_frame(f, len, left, right);
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifndef STB_VORBIS_NO_PUSHDATA_API
|
||||
|
@ -3482,7 +3487,7 @@ static int start_decoder(vorb *f)
|
|||
g->book_list[j] = get_bits(f,8);
|
||||
return error(f, VORBIS_feature_not_supported);
|
||||
} else {
|
||||
Point p[31*8+2];
|
||||
stbv__floor_ordering p[31*8+2];
|
||||
Floor1 *g = &f->floor_config[i].floor1;
|
||||
int max_class = -1;
|
||||
g->partitions = get_bits(f, 5);
|
||||
|
@ -3518,11 +3523,11 @@ static int start_decoder(vorb *f)
|
|||
// precompute the sorting
|
||||
for (j=0; j < g->values; ++j) {
|
||||
p[j].x = g->Xlist[j];
|
||||
p[j].y = j;
|
||||
p[j].id = j;
|
||||
}
|
||||
qsort(p, g->values, sizeof(p[0]), point_compare);
|
||||
for (j=0; j < g->values; ++j)
|
||||
g->sorted_order[j] = (uint8) p[j].y;
|
||||
g->sorted_order[j] = (uint8) p[j].id;
|
||||
// precompute the neighbors
|
||||
for (j=2; j < g->values; ++j) {
|
||||
int low,hi;
|
||||
|
@ -4226,8 +4231,9 @@ static int seek_to_sample_coarse(stb_vorbis *f, uint32 sample_number)
|
|||
|
||||
// starting from the start is handled differently
|
||||
if (sample_number <= left.last_decoded_sample) {
|
||||
stb_vorbis_seek_start(f);
|
||||
return 1;
|
||||
if (stb_vorbis_seek_start(f))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (left.page_end != right.page_start) {
|
||||
|
@ -4328,7 +4334,10 @@ static int seek_to_sample_coarse(stb_vorbis *f, uint32 sample_number)
|
|||
skip(f, f->segments[i]);
|
||||
|
||||
// start decoding (optimizable - this frame is generally discarded)
|
||||
vorbis_pump_first_frame(f);
|
||||
if (!vorbis_pump_first_frame(f))
|
||||
return 0;
|
||||
if (f->current_loc > sample_number)
|
||||
return error(f, VORBIS_seek_failed);
|
||||
return 1;
|
||||
|
||||
error:
|
||||
|
@ -4419,14 +4428,14 @@ int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void stb_vorbis_seek_start(stb_vorbis *f)
|
||||
int stb_vorbis_seek_start(stb_vorbis *f)
|
||||
{
|
||||
if (IS_PUSH_MODE(f)) { error(f, VORBIS_invalid_api_mixing); return; }
|
||||
if (IS_PUSH_MODE(f)) { return error(f, VORBIS_invalid_api_mixing); }
|
||||
set_file_offset(f, f->first_audio_page_offset);
|
||||
f->previous_length = 0;
|
||||
f->first_decode = TRUE;
|
||||
f->next_seg = -1;
|
||||
vorbis_pump_first_frame(f);
|
||||
return vorbis_pump_first_frame(f);
|
||||
}
|
||||
|
||||
unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f)
|
||||
|
@ -4591,6 +4600,7 @@ stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *err
|
|||
if (f) {
|
||||
*f = p;
|
||||
vorbis_pump_first_frame(f);
|
||||
if (error) *error = VORBIS__no_error;
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
@ -4956,6 +4966,7 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in
|
|||
#endif // STB_VORBIS_NO_PULLDATA_API
|
||||
|
||||
/* Version history
|
||||
1.10 - 2017/03/03 - more robust seeking; fix negative ilog(); clear error in open_memory
|
||||
1.09 - 2016/04/04 - back out 'avoid discarding last frame' fix from previous version
|
||||
1.08 - 2016/04/02 - fixed multiple warnings; fix setup memory leaks;
|
||||
avoid discarding last frame of audio data
|
||||
|
@ -5008,3 +5019,46 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in
|
|||
*/
|
||||
|
||||
#endif // STB_VORBIS_HEADER_ONLY
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue