From 4dc6556e8160772fa84fd4ff838753dbd048f370 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 21 May 2022 14:03:24 +0300
Subject: [PATCH] Rebase and update stb_vorbis.h to SDL_sound's version :
- Keeps the original stb_vorbis as intact as possible so
that future updates from mainstream would be painless.
- Reduces STB_VORBIS_MAX_CHANNELS from 16 to 6 (objections?)
- Adds several missing libm function overrides,
- SDL_mixer now requires SDL >= 2.0.9 because of SDL_exp()
- Fixes slow loads and leaks in start_decoder:
https://github.com/nothings/stb/pull/1174
- Fixes submap array out-of-bounds indexing bug:
https://github.com/nothings/stb/pull/1312
- Replace signed overflow clamps with unsigned overflow:
https://github.com/nothings/stb/issues/1168
- Replaces alloca() usage with setup_malloc() (from libxmp.)
- Fixes '-Wmaybe-uninitialized' warnings in get_seek_page_info:
https://github.com/nothings/stb/pull/1172
- A minor UBSan fix and suppression:
https://github.com/nothings/stb/issues/1168
- Fixes signature of dummy realloc() for STB_VORBIS_NO_CRT:
https://github.com/nothings/stb/pull/1198
- Renames BUFFER_SIZE macro to STB_BUFFER_SIZE:
https://github.com/nothings/stb/pull/1078
- Pulls in sample-accurate offset patch of Vitaly Novichkov:
(stb_vorbis_get_playback_sample_offset, because it's used
in OGG_Tell and OGG_GetSome):
https://github.com/nothings/stb/issues/1294
https://github.com/nothings/stb/pull/1295
- Fixes a few warnings here and there in some environments.
- Replaces two dummy '(void) 0' with 'do {} while(0)'
---
configure | 2 +-
configure.ac | 2 +-
src/codecs/music_ogg_stb.c | 42 +-
src/codecs/stb_vorbis/stb_vorbis.h | 2910 ++++++++++++++--------------
4 files changed, 1526 insertions(+), 1430 deletions(-)
diff --git a/configure b/configure
index e022ba7c..485f183c 100755
--- a/configure
+++ b/configure
@@ -15308,7 +15308,7 @@ find_lib()
done
}
-SDL_VERSION=2.0.7
+SDL_VERSION=2.0.9
# Check whether --with-sdl-prefix was given.
if test "${with_sdl_prefix+set}" = set; then :
diff --git a/configure.ac b/configure.ac
index d828bfd4..88987bdb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -251,7 +251,7 @@ find_lib()
}
dnl Check for SDL
-SDL_VERSION=2.0.7
+SDL_VERSION=2.0.9
AM_PATH_SDL2($SDL_VERSION,
:,
AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
diff --git a/src/codecs/music_ogg_stb.c b/src/codecs/music_ogg_stb.c
index 2ec97a69..9e06f3cb 100644
--- a/src/codecs/music_ogg_stb.c
+++ b/src/codecs/music_ogg_stb.c
@@ -25,10 +25,46 @@
#include "music_ogg.h"
#include "utils.h"
+#include "SDL_assert.h"
+
+#define STB_VORBIS_SDL 1 /* for SDL_mixer-specific stuff. */
+#define STB_VORBIS_NO_STDIO 1
+#define STB_VORBIS_NO_CRT 1
+#define STB_VORBIS_NO_PUSHDATA_API 1
+#define STB_VORBIS_MAX_CHANNELS 6
+#define STBV_CDECL
+#define STB_FORCEINLINE SDL_FORCE_INLINE
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define STB_VORBIS_BIG_ENDIAN 1
+#endif
+
+#ifdef assert
+#undef assert
+#endif
+#ifdef memset
+#undef memset
+#endif
+#ifdef memcpy
+#undef memcpy
+#endif
+#define assert SDL_assert
+#define memset SDL_memset
+#define memcmp SDL_memcmp
+#define memcpy SDL_memcpy
+#define qsort SDL_qsort
+#define malloc SDL_malloc
+#define realloc SDL_realloc
+#define free SDL_free
+
+#define pow SDL_pow
+#define floor SDL_floor
+#define ldexp(v, e) SDL_scalbn((v), (e))
+#define abs(x) SDL_abs(x)
+#define cos(x) SDL_cos(x)
+#define sin(x) SDL_sin(x)
+#define log(x) SDL_log(x)
+#define exp(x) SDL_exp(x)
-#define OV_EXCLUDE_STATIC_CALLBACKS
-#define STB_VORBIS_NO_STDIO
-#define STB_VORBIS_NO_CRT
#include "stb_vorbis/stb_vorbis.h"
typedef struct {
diff --git a/src/codecs/stb_vorbis/stb_vorbis.h b/src/codecs/stb_vorbis/stb_vorbis.h
index 94418e20..45c5b09f 100644
--- a/src/codecs/stb_vorbis/stb_vorbis.h
+++ b/src/codecs/stb_vorbis/stb_vorbis.h
@@ -1,83 +1,81 @@
-/* Ogg Vorbis audio decoder - v1.22 - public domain */
-/* http://nothings.org/stb_vorbis/ */
-/* */
-/* Original version written by Sean Barrett in 2007. */
-/* */
-/* Originally sponsored by RAD Game Tools. Seeking implementation */
-/* sponsored by Phillip Bennefall, Marc Andersen, Aaron Baker, */
-/* Elias Software, Aras Pranckevicius, and Sean Barrett. */
-/* */
-/* LICENSE */
-/* */
-/* See end of file for license information. */
-/* */
-/* Limitations: */
-/* */
-/* - floor 0 not supported (used in old ogg vorbis files pre-2004) */
-/* - lossless sample-truncation at beginning ignored */
-/* - cannot concatenate multiple vorbis streams */
-/* - sample positions are 32-bit, limiting seekable 192Khz */
-/* files to around 6 hours (Ogg supports 64-bit) */
-/* */
-/* Feature contributors: */
-/* Dougall Johnson (sample-exact seeking) */
-/* */
-/* Bugfix/warning contributors: */
-/* Terje Mathisen Niklas Frykholm Andy Hill */
-/* Casey Muratori John Bolton Gargaj */
-/* Laurent Gomila Marc LeBlanc Ronny Chevalier */
-/* Bernhard Wodo Evan Balster github:alxprd */
-/* Tom Beaumont Ingo Leitgeb Nicolas Guillemot */
-/* Phillip Bennefall Rohit Thiago Goulart */
-/* github:manxorist Saga Musix github:infatum */
-/* Timur Gagiev Maxwell Koo Peter Waller */
-/* github:audinowho Dougall Johnson David Reid */
-/* github:Clownacy Pedro J. Estebanez Remi Verschelde */
-/* AnthoFoxo github:morlat Gabriel Ravier */
-/* */
-/* Partial history: */
-/* 1.22 - 2021-07-11 - various small fixes */
-/* 1.21 - 2021-07-02 - fix bug for files with no comments */
-/* 1.20 - 2020-07-11 - several small fixes */
-/* 1.19 - 2020-02-05 - warnings */
-/* 1.18 - 2020-02-02 - fix seek bugs; parse header comments; misc warnings etc. */
-/* 1.17 - 2019-07-08 - fix CVE-2019-13217..CVE-2019-13223 (by ForAllSecure) */
-/* 1.16 - 2019-03-04 - fix warnings */
-/* 1.15 - 2019-02-07 - explicit failure if Ogg Skeleton data is found */
-/* 1.14 - 2018-02-11 - delete bogus dealloca usage */
-/* 1.13 - 2018-01-29 - fix truncation of last frame (hopefully) */
-/* 1.12 - 2017-11-21 - limit residue begin/end to blocksize/2 to avoid large temp allocs in bad/corrupt files */
-/* 1.11 - 2017-07-23 - fix MinGW compilation */
-/* 1.10 - 2017-03-03 - more robust seeking; fix negative ilog(); clear error in open_memory */
-/* 1.09 - 2016-04-04 - back out 'truncation of last frame' fix from previous version */
-/* 1.08 - 2016-04-02 - warnings; setup memory leaks; truncation of last frame */
-/* 1.07 - 2015-01-16 - fixes for crashes on invalid files; warning fixes; const */
-/* 1.06 - 2015-08-31 - full, correct support for seeking API (Dougall Johnson) */
-/* some crash fixes when out of memory or with corrupt files */
-/* fix some inappropriately signed shifts */
-/* 1.05 - 2015-04-19 - don't define __forceinline if it's redundant */
-/* 1.04 - 2014-08-27 - fix missing const-correct case in API */
-/* 1.03 - 2014-08-07 - warning fixes */
-/* 1.02 - 2014-07-09 - declare qsort comparison as explicitly _cdecl in Windows */
-/* 1.01 - 2014-06-18 - fix stb_vorbis_get_samples_float (interleaved was correct) */
-/* 1.0 - 2014-05-26 - fix memory leaks; fix warnings; fix bugs in >2-channel; */
-/* (API change) report sample rate for decode-full-file funcs */
-/* */
-/* See end of file for full version history. */
-
-
-/* //////////////////////////////////////////////////////////////////////////// */
-/* */
-/* HEADER BEGINS HERE */
-/* */
+// Ogg Vorbis audio decoder - v1.22 - public domain
+// http://nothings.org/stb_vorbis/
+//
+// Original version written by Sean Barrett in 2007.
+//
+// Originally sponsored by RAD Game Tools. Seeking implementation
+// sponsored by Phillip Bennefall, Marc Andersen, Aaron Baker,
+// Elias Software, Aras Pranckevicius, and Sean Barrett.
+//
+// LICENSE
+//
+// See end of file for license information.
+//
+// Limitations:
+//
+// - floor 0 not supported (used in old ogg vorbis files pre-2004)
+// - lossless sample-truncation at beginning ignored
+// - cannot concatenate multiple vorbis streams
+// - sample positions are 32-bit, limiting seekable 192Khz
+// files to around 6 hours (Ogg supports 64-bit)
+//
+// Feature contributors:
+// Dougall Johnson (sample-exact seeking)
+// Vitaly Novichkov (sample-accurate tell)
+//
+// Bugfix/warning contributors:
+// Terje Mathisen Niklas Frykholm Andy Hill
+// Casey Muratori John Bolton Gargaj
+// Laurent Gomila Marc LeBlanc Ronny Chevalier
+// Bernhard Wodo Evan Balster github:alxprd
+// Tom Beaumont Ingo Leitgeb Nicolas Guillemot
+// Phillip Bennefall Rohit Thiago Goulart
+// github:manxorist Saga Musix github:infatum
+// Timur Gagiev Maxwell Koo Peter Waller
+// github:audinowho Dougall Johnson David Reid
+// github:Clownacy Pedro J. Estebanez Remi Verschelde
+// AnthoFoxo github:morlat Gabriel Ravier
+// Alice Rowan
+//
+// Partial history:
+// 1.22 - 2021-07-11 - various small fixes
+// 1.21 - 2021-07-02 - fix bug for files with no comments
+// 1.20 - 2020-07-11 - several small fixes
+// 1.19 - 2020-02-05 - warnings
+// 1.18 - 2020-02-02 - fix seek bugs; parse header comments; misc warnings etc.
+// 1.17 - 2019-07-08 - fix CVE-2019-13217..CVE-2019-13223 (by ForAllSecure)
+// 1.16 - 2019-03-04 - fix warnings
+// 1.15 - 2019-02-07 - explicit failure if Ogg Skeleton data is found
+// 1.14 - 2018-02-11 - delete bogus dealloca usage
+// 1.13 - 2018-01-29 - fix truncation of last frame (hopefully)
+// 1.12 - 2017-11-21 - limit residue begin/end to blocksize/2 to avoid large temp allocs in bad/corrupt files
+// 1.11 - 2017-07-23 - fix MinGW compilation
+// 1.10 - 2017-03-03 - more robust seeking; fix negative ilog(); clear error in open_memory
+// 1.09 - 2016-04-04 - back out 'truncation of last frame' fix from previous version
+// 1.08 - 2016-04-02 - warnings; setup memory leaks; truncation of last frame
+// 1.07 - 2015-01-16 - fixes for crashes on invalid files; warning fixes; const
+// 1.06 - 2015-08-31 - full, correct support for seeking API (Dougall Johnson)
+// some crash fixes when out of memory or with corrupt files
+// fix some inappropriately signed shifts
+// 1.05 - 2015-04-19 - don't define __forceinline if it's redundant
+// 1.04 - 2014-08-27 - fix missing const-correct case in API
+// 1.03 - 2014-08-07 - warning fixes
+// 1.02 - 2014-07-09 - declare qsort comparison as explicitly _cdecl in Windows
+// 1.01 - 2014-06-18 - fix stb_vorbis_get_samples_float (interleaved was correct)
+// 1.0 - 2014-05-26 - fix memory leaks; fix warnings; fix bugs in >2-channel;
+// (API change) report sample rate for decode-full-file funcs
+//
+// See end of file for full version history.
+
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// HEADER BEGINS HERE
+//
#ifndef STB_VORBIS_INCLUDE_STB_VORBIS_H
#define STB_VORBIS_INCLUDE_STB_VORBIS_H
-#include "SDL_stdinc.h"
-#include "SDL_rwops.h"
-#include "SDL_assert.h"
-
#if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO)
#define STB_VORBIS_NO_STDIO 1
#endif
@@ -90,34 +88,34 @@
extern "C" {
#endif
-/* ///////// THREAD SAFETY */
-
-/* Individual stb_vorbis* handles are not thread-safe; you cannot decode from */
-/* them from multiple threads at the same time. However, you can have multiple */
-/* stb_vorbis* handles and decode from them independently in multiple thrads. */
-
-
-/* ///////// MEMORY ALLOCATION */
-
-/* normally stb_vorbis uses malloc() to allocate memory at startup, */
-/* and alloca() to allocate temporary memory during a frame on the */
-/* stack. (Memory consumption will depend on the amount of setup */
-/* data in the file and how you set the compile flags for speed */
-/* vs. size. In my test files the maximal-size usage is ~150KB.) */
-/* */
-/* You can modify the wrapper functions in the source (setup_malloc, */
-/* setup_temp_malloc, temp_malloc) to change this behavior, or you */
-/* can use a simpler allocation model: you pass in a buffer from */
-/* which stb_vorbis will allocate _all_ its memory (including the */
-/* temp memory). "open" may fail with a VORBIS_outofmem if you */
-/* do not pass in enough data; there is no way to determine how */
-/* much you do need except to succeed (at which point you can */
-/* query get_info to find the exact amount required. yes I know */
-/* this is lame). */
-/* */
-/* If you pass in a non-NULL buffer of the type below, allocation */
-/* will occur from it as described above. Otherwise just pass NULL */
-/* to use malloc()/alloca() */
+/////////// THREAD SAFETY
+
+// Individual stb_vorbis* handles are not thread-safe; you cannot decode from
+// them from multiple threads at the same time. However, you can have multiple
+// stb_vorbis* handles and decode from them independently in multiple thrads.
+
+
+/////////// MEMORY ALLOCATION
+
+// normally stb_vorbis uses malloc() to allocate memory at startup,
+// and alloca() to allocate temporary memory during a frame on the
+// stack. (Memory consumption will depend on the amount of setup
+// data in the file and how you set the compile flags for speed
+// vs. size. In my test files the maximal-size usage is ~150KB.)
+//
+// You can modify the wrapper functions in the source (setup_malloc,
+// setup_temp_malloc, temp_malloc) to change this behavior, or you
+// can use a simpler allocation model: you pass in a buffer from
+// which stb_vorbis will allocate _all_ its memory (including the
+// temp memory). "open" may fail with a VORBIS_outofmem if you
+// do not pass in enough data; there is no way to determine how
+// much you do need except to succeed (at which point you can
+// query get_info to find the exact amount required. yes I know
+// this is lame).
+//
+// If you pass in a non-NULL buffer of the type below, allocation
+// will occur from it as described above. Otherwise just pass NULL
+// to use malloc()/alloca()
typedef struct
{
@@ -126,7 +124,7 @@ typedef struct
} stb_vorbis_alloc;
-/* ///////// FUNCTIONS USEABLE WITH ALL INPUT MODES */
+/////////// FUNCTIONS USEABLE WITH ALL INPUT MODES
typedef struct stb_vorbis stb_vorbis;
@@ -150,119 +148,119 @@ typedef struct
char **comment_list;
} stb_vorbis_comment;
-/* get general information about the file */
+// get general information about the file
extern stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f);
-/* get ogg comments */
+// get ogg comments
extern stb_vorbis_comment stb_vorbis_get_comment(stb_vorbis *f);
-/* get the last error detected (clears it, too) */
+// get the last error detected (clears it, too)
extern int stb_vorbis_get_error(stb_vorbis *f);
-/* close an ogg vorbis file and free all memory in use */
+// close an ogg vorbis file and free all memory in use
extern void stb_vorbis_close(stb_vorbis *f);
-/* this function returns the offset (in samples) from the beginning of the */
-/* file that will be returned by the next decode, if it is known, or -1 */
-/* otherwise. after a flush_pushdata() call, this may take a while before */
-/* it becomes valid again. */
-/* NOT WORKING YET after a seek with PULLDATA API */
-extern Sint64 stb_vorbis_get_sample_offset(stb_vorbis *f);
-
-/* this function returns the count of returned samples from the beginning of the */
-/* file. Functions "stb_vorbis_get_samples_*", "stb_vorbis_seek_*()" will
- * affect the returned value. Use this call to get the accurate sample position
- * during playback. */
-extern Sint64 stb_vorbis_get_playback_sample_offset(stb_vorbis *f);
-
-/* returns the current seek point within the file, or offset from the beginning */
-/* of the memory buffer. In pushdata mode it returns 0. */
+// this function returns the offset (in samples) from the beginning of the
+// file that will be returned by the next decode, if it is known, or -1
+// otherwise. after a flush_pushdata() call, this may take a while before
+// it becomes valid again.
+// NOT WORKING YET after a seek with PULLDATA API
+extern int stb_vorbis_get_sample_offset(stb_vorbis *f);
+
+// this function returns the count of returned samples from the beginning of the
+// file. Functions "stb_vorbis_get_samples_*", "stb_vorbis_seek_*()" will
+// affect the returned value. Use this call to get the accurate sample position
+// during playback.
+extern int stb_vorbis_get_playback_sample_offset(stb_vorbis *f);
+
+// returns the current seek point within the file, or offset from the beginning
+// of the memory buffer. In pushdata mode it returns 0.
extern unsigned int stb_vorbis_get_file_offset(stb_vorbis *f);
-/* ///////// PUSHDATA API */
+/////////// PUSHDATA API
#ifndef STB_VORBIS_NO_PUSHDATA_API
-/* this API allows you to get blocks of data from any source and hand */
-/* them to stb_vorbis. you have to buffer them; stb_vorbis will tell */
-/* you how much it used, and you have to give it the rest next time; */
-/* and stb_vorbis may not have enough data to work with and you will */
-/* need to give it the same data again PLUS more. Note that the Vorbis */
-/* specification does not bound the size of an individual frame. */
+// this API allows you to get blocks of data from any source and hand
+// them to stb_vorbis. you have to buffer them; stb_vorbis will tell
+// you how much it used, and you have to give it the rest next time;
+// and stb_vorbis may not have enough data to work with and you will
+// need to give it the same data again PLUS more. Note that the Vorbis
+// specification does not bound the size of an individual frame.
extern 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);
-/* create a vorbis decoder by passing in the initial data block containing */
-/* the ogg&vorbis headers (you don't need to do parse them, just provide */
-/* the first N bytes of the file--you're told if it's not enough, see below) */
-/* on success, returns an stb_vorbis *, does not set error, returns the amount of */
-/* data parsed/consumed on this call in *datablock_memory_consumed_in_bytes; */
-/* on failure, returns NULL on error and sets *error, does not change *datablock_memory_consumed */
-/* if returns NULL and *error is VORBIS_need_more_data, then the input block was */
-/* incomplete and you need to pass in a larger block from the start of the file */
+// create a vorbis decoder by passing in the initial data block containing
+// the ogg&vorbis headers (you don't need to do parse them, just provide
+// the first N bytes of the file--you're told if it's not enough, see below)
+// on success, returns an stb_vorbis *, does not set error, returns the amount of
+// data parsed/consumed on this call in *datablock_memory_consumed_in_bytes;
+// on failure, returns NULL on error and sets *error, does not change *datablock_memory_consumed
+// if returns NULL and *error is VORBIS_need_more_data, then the input block was
+// incomplete and you need to pass in a larger block from the start of the file
extern int stb_vorbis_decode_frame_pushdata(
stb_vorbis *f,
const unsigned char *datablock, int datablock_length_in_bytes,
- int *channels, /* place to write number of float * buffers */
- float ***output, /* place to write float ** array of float * buffers */
- int *samples /* place to write number of output samples */
+ int *channels, // place to write number of float * buffers
+ float ***output, // place to write float ** array of float * buffers
+ int *samples // place to write number of output samples
);
-/* decode a frame of audio sample data if possible from the passed-in data block */
-/* */
-/* return value: number of bytes we used from datablock */
-/* */
-/* possible cases: */
-/* 0 bytes used, 0 samples output (need more data) */
-/* N bytes used, 0 samples output (resynching the stream, keep going) */
-/* N bytes used, M samples output (one frame of data) */
-/* note that after opening a file, you will ALWAYS get one N-bytes,0-sample */
-/* frame, because Vorbis always "discards" the first frame. */
-/* */
-/* Note that on resynch, stb_vorbis will rarely consume all of the buffer, */
-/* instead only datablock_length_in_bytes-3 or less. This is because it wants */
-/* to avoid missing parts of a page header if they cross a datablock boundary, */
-/* without writing state-machiney code to record a partial detection. */
-/* */
-/* The number of channels returned are stored in *channels (which can be */
-/* NULL--it is always the same as the number of channels reported by */
-/* get_info). *output will contain an array of float* buffers, one per */
-/* channel. In other words, (*output)[0][0] contains the first sample from */
-/* the first channel, and (*output)[1][0] contains the first sample from */
-/* the second channel. */
-/* */
-/* *output points into stb_vorbis's internal output buffer storage; these */
-/* buffers are owned by stb_vorbis and application code should not free */
-/* them or modify their contents. They are transient and will be overwritten */
-/* once you ask for more data to get decoded, so be sure to grab any data */
-/* you need before then. */
+// decode a frame of audio sample data if possible from the passed-in data block
+//
+// return value: number of bytes we used from datablock
+//
+// possible cases:
+// 0 bytes used, 0 samples output (need more data)
+// N bytes used, 0 samples output (resynching the stream, keep going)
+// N bytes used, M samples output (one frame of data)
+// note that after opening a file, you will ALWAYS get one N-bytes,0-sample
+// frame, because Vorbis always "discards" the first frame.
+//
+// Note that on resynch, stb_vorbis will rarely consume all of the buffer,
+// instead only datablock_length_in_bytes-3 or less. This is because it wants
+// to avoid missing parts of a page header if they cross a datablock boundary,
+// without writing state-machiney code to record a partial detection.
+//
+// The number of channels returned are stored in *channels (which can be
+// NULL--it is always the same as the number of channels reported by
+// get_info). *output will contain an array of float* buffers, one per
+// channel. In other words, (*output)[0][0] contains the first sample from
+// the first channel, and (*output)[1][0] contains the first sample from
+// the second channel.
+//
+// *output points into stb_vorbis's internal output buffer storage; these
+// buffers are owned by stb_vorbis and application code should not free
+// them or modify their contents. They are transient and will be overwritten
+// once you ask for more data to get decoded, so be sure to grab any data
+// you need before then.
extern void stb_vorbis_flush_pushdata(stb_vorbis *f);
-/* inform stb_vorbis that your next datablock will not be contiguous with */
-/* previous ones (e.g. you've seeked in the data); future attempts to decode */
-/* frames will cause stb_vorbis to resynchronize (as noted above), and */
-/* once it sees a valid Ogg page (typically 4-8KB, as large as 64KB), it */
-/* will begin decoding the _next_ frame. */
-/* */
-/* if you want to seek using pushdata, you need to seek in your file, then */
-/* call stb_vorbis_flush_pushdata(), then start calling decoding, then once */
-/* decoding is returning you data, call stb_vorbis_get_sample_offset, and */
-/* if you don't like the result, seek your file again and repeat. */
+// inform stb_vorbis that your next datablock will not be contiguous with
+// previous ones (e.g. you've seeked in the data); future attempts to decode
+// frames will cause stb_vorbis to resynchronize (as noted above), and
+// once it sees a valid Ogg page (typically 4-8KB, as large as 64KB), it
+// will begin decoding the _next_ frame.
+//
+// if you want to seek using pushdata, you need to seek in your file, then
+// call stb_vorbis_flush_pushdata(), then start calling decoding, then once
+// decoding is returning you data, call stb_vorbis_get_sample_offset, and
+// if you don't like the result, seek your file again and repeat.
#endif
-/* //////// PULLING INPUT API */
+////////// PULLING INPUT API
#ifndef STB_VORBIS_NO_PULLDATA_API
-/* This API assumes stb_vorbis is allowed to pull data from a source-- */
-/* either a block of memory containing the _entire_ vorbis stream, or a */
-/* FILE * that you or it create, or possibly some other reading mechanism */
-/* if you go modify the source to replace the FILE * case with some kind */
-/* of callback to your code. (But if you don't support seeking, you may */
-/* just want to go ahead and use pushdata.) */
+// This API assumes stb_vorbis is allowed to pull data from a source--
+// either a block of memory containing the _entire_ vorbis stream, or a
+// FILE * that you or it create, or possibly some other reading mechanism
+// if you go modify the source to replace the FILE * case with some kind
+// of callback to your code. (But if you don't support seeking, you may
+// just want to go ahead and use pushdata.)
#if !defined(STB_VORBIS_NO_STDIO) && !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
extern int stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_rate, short **output);
@@ -270,147 +268,146 @@ extern int stb_vorbis_decode_filename(const char *filename, int *channels, int *
#if !defined(STB_VORBIS_NO_INTEGER_CONVERSION)
extern int stb_vorbis_decode_memory(const unsigned char *mem, int len, int *channels, int *sample_rate, short **output);
#endif
-/* decode an entire file and output the data interleaved into a malloc()ed */
-/* buffer stored in *output. The return value is the number of samples */
-/* decoded, or -1 if the file could not be opened or was not an ogg vorbis file. */
-/* When you're done with it, just free() the pointer returned in *output. */
+// decode an entire file and output the data interleaved into a malloc()ed
+// buffer stored in *output. The return value is the number of samples
+// decoded, or -1 if the file could not be opened or was not an ogg vorbis file.
+// When you're done with it, just free() the pointer returned in *output.
extern stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len,
int *error, const stb_vorbis_alloc *alloc_buffer);
-/* create an ogg vorbis decoder from an ogg vorbis stream in memory (note */
-/* this must be the entire stream!). on failure, returns NULL and sets *error */
+// create an ogg vorbis decoder from an ogg vorbis stream in memory (note
+// this must be the entire stream!). on failure, returns NULL and sets *error
#ifndef STB_VORBIS_NO_STDIO
extern stb_vorbis * stb_vorbis_open_filename(const char *filename,
int *error, const stb_vorbis_alloc *alloc_buffer);
-/* create an ogg vorbis decoder from a filename via fopen(). on failure, */
-/* returns NULL and sets *error (possibly to VORBIS_file_open_failure). */
+// create an ogg vorbis decoder from a filename via fopen(). on failure,
+// returns NULL and sets *error (possibly to VORBIS_file_open_failure).
extern stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close,
int *error, const stb_vorbis_alloc *alloc_buffer);
-/* create an ogg vorbis decoder from an open FILE *, looking for a stream at */
-/* the _current_ seek point (ftell). on failure, returns NULL and sets *error. */
-/* note that stb_vorbis must "own" this stream; if you seek it in between */
-/* calls to stb_vorbis, it will become confused. Moreover, if you attempt to */
-/* perform stb_vorbis_seek_*() operations on this file, it will assume it */
-/* owns the _entire_ rest of the file after the start point. Use the next */
-/* function, stb_vorbis_open_file_section(), to limit it. */
+// create an ogg vorbis decoder from an open FILE *, looking for a stream at
+// the _current_ seek point (ftell). on failure, returns NULL and sets *error.
+// note that stb_vorbis must "own" this stream; if you seek it in between
+// calls to stb_vorbis, it will become confused. Moreover, if you attempt to
+// perform stb_vorbis_seek_*() operations on this file, it will assume it
+// owns the _entire_ rest of the file after the start point. Use the next
+// function, stb_vorbis_open_file_section(), to limit it.
extern 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);
-/* create an ogg vorbis decoder from an open FILE *, looking for a stream at */
-/* the _current_ seek point (ftell); the stream will be of length 'len' bytes. */
-/* on failure, returns NULL and sets *error. note that stb_vorbis must "own" */
-/* this stream; if you seek it in between calls to stb_vorbis, it will become */
-/* confused. */
+// create an ogg vorbis decoder from an open FILE *, looking for a stream at
+// the _current_ seek point (ftell); the stream will be of length 'len' bytes.
+// on failure, returns NULL and sets *error. note that stb_vorbis must "own"
+// this stream; if you seek it in between calls to stb_vorbis, it will become
+// confused.
#endif
-extern stb_vorbis * stb_vorbis_open_rwops(SDL_RWops *f, int close_handle_on_close,
- int *error, const stb_vorbis_alloc *alloc_buffer);
-
-extern stb_vorbis * stb_vorbis_open_rwops_section(SDL_RWops *file, int close_handle_on_close,
- int *error, const stb_vorbis_alloc *alloc_buffer, unsigned int len);
+#ifdef STB_VORBIS_SDL
+extern stb_vorbis * stb_vorbis_open_rwops_section(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length);
+extern stb_vorbis * stb_vorbis_open_rwops(SDL_RWops *rwops, int close_on_free, int *error, const stb_vorbis_alloc *alloc);
+#endif
extern int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number);
-extern int stb_vorbis_seek(stb_vorbis *f, Sint64 sample_number);
-/* these functions seek in the Vorbis file to (approximately) 'sample_number'. */
-/* after calling seek_frame(), the next call to get_frame_*() will include */
-/* the specified sample. after calling stb_vorbis_seek(), the next call to */
-/* stb_vorbis_get_samples_* will start with the specified sample. If you */
-/* do not need to seek to EXACTLY the target sample when using get_samples_*, */
-/* you can also use seek_frame(). */
+extern int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number);
+// these functions seek in the Vorbis file to (approximately) 'sample_number'.
+// after calling seek_frame(), the next call to g
(Patch may be truncated, please check the link at the top of this post.)