diff --git a/audio/audio_mixer.c b/audio/audio_mixer.c index 38af301f9b..6926408e1b 100644 --- a/audio/audio_mixer.c +++ b/audio/audio_mixer.c @@ -32,11 +32,6 @@ #undef NULL -#ifdef __MINGW32__ -#undef __forceinline -#define __forceinline __inline__ __attribute__((__always_inline__,__gnu_inline__)) -#endif - #include "../deps/stb/stb_vorbis.h" /*---------------------------------------------------------------------------*/ @@ -527,7 +522,8 @@ again: } else { - for ( int i = buf_free; i != 0; --i ) + int i; + for (i = buf_free; i != 0; --i ) *buffer++ += *pcm++ * volume; voice->types.ogg.position += buf_free; diff --git a/deps/stb/stb_vorbis.h b/deps/stb/stb_vorbis.h index 90b9b066af..2c7681557f 100644 --- a/deps/stb/stb_vorbis.h +++ b/deps/stb/stb_vorbis.h @@ -1,52 +1,47 @@ -// Ogg Vorbis audio decoder - v1.05 - public domain -// http://nothings.org/stb_vorbis/ -// -// Written by Sean Barrett in 2007, last updated in 2014 -// Sponsored by RAD Game Tools. -// -// Placed in the public domain April 2007 by the author: no copyright -// is claimed, and you may use it for any purpose you like. -// -// No warranty for any purpose is expressed or implied by the author (nor -// by RAD Game Tools). Report bugs and send enhancements to the author. -// -// Limitations: -// -// - seeking not supported except manually via PUSHDATA api -// - 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) -// -// Bugfix/warning contributors: -// Terje Mathisen Niklas Frykholm Andy Hill -// Casey Muratori John Bolton Gargaj -// Laurent Gomila Marc LeBlanc Ronny Chevalier -// Bernhard Wodo Evan Balster "alxprd"@github -// Tom Beaumont Ingo Leitgeb Nicolas Guillemot -// (If you reported a bug but do not appear in this list, it is because -// someone else reported the bug before you. There were too many of you to -// list them all because I was lax about updating for a long time, sorry.) -// -// Partial history: -// 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 -// 0.99996 - - bracket #include for macintosh compilation -// 0.99995 - - avoid alias-optimization issue in float-to-int conversion -// -// See end of file for full version history. - - -////////////////////////////////////////////////////////////////////////////// -// -// HEADER BEGINS HERE -// +/* Ogg Vorbis audio decoder - v1.05 - public domain + * http://nothings.org/stb_vorbis/ + * + * Written by Sean Barrett in 2007, last updated in 2014 + * Sponsored by RAD Game Tools. + * + * Placed in the public domain April 2007 by the author: no copyright + * is claimed, and you may use it for any purpose you like. + * + * No warranty for any purpose is expressed or implied by the author (nor + * by RAD Game Tools). Report bugs and send enhancements to the author. + * + * Limitations: + * + * - seeking not supported except manually via PUSHDATA api + * - 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) + * + * Bugfix/warning contributors: + * Terje Mathisen Niklas Frykholm Andy Hill + * Casey Muratori John Bolton Gargaj + * Laurent Gomila Marc LeBlanc Ronny Chevalier + * Bernhard Wodo Evan Balster "alxprd"@github + * Tom Beaumont Ingo Leitgeb Nicolas Guillemot + * (If you reported a bug but do not appear in this list, it is because + * someone else reported the bug before you. There were too many of you to + * list them all because I was lax about updating for a long time, sorry.) + * + * Partial history: + * 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 + * 0.99996 - - bracket #include for macintosh compilation + * 0.99995 - - avoid alias-optimization issue in float-to-int conversion + * + * See end of file for full version history. + */ #ifndef STB_VORBIS_INCLUDE_STB_VORBIS_H #define STB_VORBIS_INCLUDE_STB_VORBIS_H @@ -65,34 +60,36 @@ extern "C" { #endif -/////////// THREAD SAFETY +/* 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. +/* 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 +/* 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() +/* 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 { @@ -101,7 +98,7 @@ typedef struct } stb_vorbis_alloc; -/////////// FUNCTIONS USEABLE WITH ALL INPUT MODES +/* FUNCTIONS USEABLE WITH ALL INPUT MODES */ typedef struct stb_vorbis stb_vorbis; @@ -117,103 +114,109 @@ typedef struct int max_frame_size; } stb_vorbis_info; -// get general information about the file +/* get general information about the file */ extern stb_vorbis_info stb_vorbis_get_info(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 +/* 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); -// returns the current seek point within the file, or offset from the beginning -// of the memory buffer. In pushdata mode it returns 0. +/* 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( unsigned char *datablock, int datablock_length_in_bytes, int *datablock_memory_consumed_in_bytes, int *error, 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, 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. + +/* 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. + */ 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); @@ -221,141 +224,145 @@ 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, 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, 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, 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. Morever, 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. Morever, 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, 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 int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number); extern int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number); -// NOT WORKING YET -// 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(). +/* NOT WORKING YET + * 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 void stb_vorbis_seek_start(stb_vorbis *f); -// this function is equivalent to stb_vorbis_seek(f,0), but it -// actually works +/* this function is equivalent to stb_vorbis_seek(f,0), but it + * actually works */ extern unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f); extern float stb_vorbis_stream_length_in_seconds(stb_vorbis *f); -// these functions return the total length of the vorbis stream +/* these functions return the total length of the vorbis stream */ extern int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output); -// decode the next frame and return the number of samples. 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. These outputs will -// be overwritten on the next call to stb_vorbis_get_frame_*. -// -// You generally should not intermix calls to stb_vorbis_get_frame_*() -// and stb_vorbis_get_samples_*(), since the latter calls the former. +/* decode the next frame and return the number of samples. 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. These outputs will + * be overwritten on the next call to stb_vorbis_get_frame_*. + * + * You generally should not intermix calls to stb_vorbis_get_frame_*() + * and stb_vorbis_get_samples_*(), since the latter calls the former. + */ #ifndef STB_VORBIS_NO_INTEGER_CONVERSION extern int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts); extern int stb_vorbis_get_frame_short (stb_vorbis *f, int num_c, short **buffer, int num_samples); #endif -// decode the next frame and return the number of samples per channel. the -// data is coerced to the number of channels you request according to the -// channel coercion rules (see below). You must pass in the size of your -// buffer(s) so that stb_vorbis will not overwrite the end of the buffer. -// The maximum buffer size needed can be gotten from get_info(); however, -// the Vorbis I specification implies an absolute maximum of 4096 samples -// per channel. Note that for interleaved data, you pass in the number of -// shorts (the size of your array), but the return value is the number of -// samples per channel, not the total number of samples. +/* decode the next frame and return the number of samples per channel. the + * data is coerced to the number of channels you request according to the + * channel coercion rules (see below). You must pass in the size of your + * buffer(s) so that stb_vorbis will not overwrite the end of the buffer. + * The maximum buffer size needed can be gotten from get_info(); however, + * the Vorbis I specification implies an absolute maximum of 4096 samples + * per channel. Note that for interleaved data, you pass in the number of + * shorts (the size of your array), but the return value is the number of + * samples per channel, not the total number of samples. -// Channel coercion rules: -// Let M be the number of channels requested, and N the number of channels present, -// and Cn be the nth channel; let stereo L be the sum of all L and center channels, -// and stereo R be the sum of all R and center channels (channel assignment from the -// vorbis spec). -// M N output -// 1 k sum(Ck) for all k -// 2 * stereo L, stereo R -// k l k > l, the first l channels, then 0s -// k l k <= l, the first k channels -// Note that this is not _good_ surround etc. mixing at all! It's just so -// you get something useful. + * Channel coercion rules: + * Let M be the number of channels requested, and N the number of channels present, + * and Cn be the nth channel; let stereo L be the sum of all L and center channels, + * and stereo R be the sum of all R and center channels (channel assignment from the + * vorbis spec). + * M N output + * 1 k sum(Ck) for all k + * 2 * stereo L, stereo R + * k l k > l, the first l channels, then 0s + * k l k <= l, the first k channels + * Note that this is not _good_ surround etc. mixing at all! It's just so + * you get something useful. + */ extern int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float *buffer, int num_floats); extern int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples); -// gets num_samples samples, not necessarily on a frame boundary--this requires -// buffering so you have to supply the buffers. DOES NOT APPLY THE COERCION RULES. -// Returns the number of samples stored per channel; it may be less than requested -// at the end of the file. If there are no more samples in the file, returns 0. +/* gets num_samples samples, not necessarily on a frame boundary--this requires + * buffering so you have to supply the buffers. DOES NOT APPLY THE COERCION RULES. + * Returns the number of samples stored per channel; it may be less than requested + * at the end of the file. If there are no more samples in the file, returns 0. + */ #ifndef STB_VORBIS_NO_INTEGER_CONVERSION extern int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts); extern int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int num_samples); #endif -// gets num_samples samples, not necessarily on a frame boundary--this requires -// buffering so you have to supply the buffers. Applies the coercion rules above -// to produce 'channels' channels. Returns the number of samples stored per channel; -// it may be less than requested at the end of the file. If there are no more -// samples in the file, returns 0. +/* gets num_samples samples, not necessarily on a frame boundary--this requires + * buffering so you have to supply the buffers. Applies the coercion rules above + * to produce 'channels' channels. Returns the number of samples stored per channel; + * it may be less than requested at the end of the file. If there are no more + * samples in the file, returns 0. */ #endif -//////// ERROR CODES +/* ERROR CODES */ enum STBVorbisError { VORBIS__no_error, - VORBIS_need_more_data=1, // not a real error + VORBIS_need_more_data=1, /* not a real error */ - VORBIS_invalid_api_mixing, // can't mix API modes - VORBIS_outofmem, // not enough memory - VORBIS_feature_not_supported, // uses floor 0 - VORBIS_too_many_channels, // STB_VORBIS_MAX_CHANNELS is too small - VORBIS_file_open_failure, // fopen() failed - VORBIS_seek_without_length, // can't seek in unknown-length file + VORBIS_invalid_api_mixing, /* can't mix API modes */ + VORBIS_outofmem, /* not enough memory */ + VORBIS_feature_not_supported, /* uses floor 0 */ + VORBIS_too_many_channels, /* STB_VORBIS_MAX_CHANNELS is too small */ + VORBIS_file_open_failure, /* fopen() failed */ + VORBIS_seek_without_length, /* can't seek in unknown-length file */ - VORBIS_unexpected_eof=10, // file is truncated? - VORBIS_seek_invalid, // seek past EOF + VORBIS_unexpected_eof=10, /* file is truncated? */ + VORBIS_seek_invalid, /* seek past EOF */ - // decoding errors (corrupt/invalid stream) -- you probably - // don't care about the exact details of these + /* decoding errors (corrupt/invalid stream) -- you probably + * don't care about the exact details of these */ - // vorbis errors: + /* vorbis errors: */ VORBIS_invalid_setup=20, VORBIS_invalid_stream, - // ogg errors: + /* ogg errors: */ VORBIS_missing_capture_pattern=30, VORBIS_invalid_stream_structure_version, VORBIS_continued_packet_flag_invalid, @@ -363,7 +370,7 @@ enum STBVorbisError VORBIS_invalid_first_page, VORBIS_bad_packet_type, VORBIS_cant_find_last_page, - VORBIS_seek_failed, + VORBIS_seek_failed }; @@ -371,150 +378,179 @@ enum STBVorbisError } #endif -#endif // STB_VORBIS_INCLUDE_STB_VORBIS_H -// -// HEADER ENDS HERE -// -////////////////////////////////////////////////////////////////////////////// +#endif /* STB_VORBIS_INCLUDE_STB_VORBIS_H */ #ifndef STB_VORBIS_HEADER_ONLY -// global configuration settings (e.g. set these in the project/makefile), -// or just set them in this file at the top (although ideally the first few -// should be visible when the header file is compiled too, although it's not -// crucial) +/* global configuration settings (e.g. set these in the project/makefile), + * or just set them in this file at the top (although ideally the first few + * should be visible when the header file is compiled too, although it's not + * crucial) + */ -// STB_VORBIS_NO_PUSHDATA_API -// does not compile the code for the various stb_vorbis_*_pushdata() -// functions -// #define STB_VORBIS_NO_PUSHDATA_API - -// STB_VORBIS_NO_PULLDATA_API -// does not compile the code for the non-pushdata APIs -// #define STB_VORBIS_NO_PULLDATA_API - -// STB_VORBIS_NO_STDIO -// does not compile the code for the APIs that use FILE *s internally -// or externally (implied by STB_VORBIS_NO_PULLDATA_API) -// #define STB_VORBIS_NO_STDIO - -// STB_VORBIS_NO_INTEGER_CONVERSION -// does not compile the code for converting audio sample data from -// float to integer (implied by STB_VORBIS_NO_PULLDATA_API) -// #define STB_VORBIS_NO_INTEGER_CONVERSION - -// STB_VORBIS_NO_FAST_SCALED_FLOAT -// does not use a fast float-to-int trick to accelerate float-to-int on -// most platforms which requires endianness be defined correctly. -//#define STB_VORBIS_NO_FAST_SCALED_FLOAT - - -// STB_VORBIS_MAX_CHANNELS [number] -// globally define this to the maximum number of channels you need. -// The spec does not put a restriction on channels except that -// the count is stored in a byte, so 255 is the hard limit. -// Reducing this saves about 16 bytes per value, so using 16 saves -// (255-16)*16 or around 4KB. Plus anything other memory usage -// I forgot to account for. Can probably go as low as 8 (7.1 audio), -// 6 (5.1 audio), or 2 (stereo only). -#ifndef STB_VORBIS_MAX_CHANNELS -#define STB_VORBIS_MAX_CHANNELS 16 // enough for anyone? +/* STB_VORBIS_NO_PUSHDATA_API + * does not compile the code for the various stb_vorbis_*_pushdata() + * functions + */ +#if 0 +#define STB_VORBIS_NO_PUSHDATA_API #endif -// STB_VORBIS_PUSHDATA_CRC_COUNT [number] -// after a flush_pushdata(), stb_vorbis begins scanning for the -// next valid page, without backtracking. when it finds something -// that looks like a page, it streams through it and verifies its -// CRC32. Should that validation fail, it keeps scanning. But it's -// possible that _while_ streaming through to check the CRC32 of -// one candidate page, it sees another candidate page. This #define -// determines how many "overlapping" candidate pages it can search -// at once. Note that "real" pages are typically ~4KB to ~8KB, whereas -// garbage pages could be as big as 64KB, but probably average ~16KB. -// So don't hose ourselves by scanning an apparent 64KB page and -// missing a ton of real ones in the interim; so minimum of 2 +/* STB_VORBIS_NO_PULLDATA_API + * does not compile the code for the non-pushdata APIs + */ +#if 0 +#define STB_VORBIS_NO_PULLDATA_API +#endif + +/* STB_VORBIS_NO_STDIO + * does not compile the code for the APIs that use FILE *s internally + * or externally (implied by STB_VORBIS_NO_PULLDATA_API) + */ +#if 0 +#define STB_VORBIS_NO_STDIO +#endif + +/* STB_VORBIS_NO_INTEGER_CONVERSION + * does not compile the code for converting audio sample data from + * float to integer (implied by STB_VORBIS_NO_PULLDATA_API) + */ +#if 0 +#define STB_VORBIS_NO_INTEGER_CONVERSION +#endif + +/* STB_VORBIS_NO_FAST_SCALED_FLOAT + * does not use a fast float-to-int trick to accelerate float-to-int on + * most platforms which requires endianness be defined correctly. + */ +#if 0 +#define STB_VORBIS_NO_FAST_SCALED_FLOAT +#endif + + +/* STB_VORBIS_MAX_CHANNELS [number] + * globally define this to the maximum number of channels you need. + * The spec does not put a restriction on channels except that + * the count is stored in a byte, so 255 is the hard limit. + * Reducing this saves about 16 bytes per value, so using 16 saves + * (255-16)*16 or around 4KB. Plus anything other memory usage + * I forgot to account for. Can probably go as low as 8 (7.1 audio), + * 6 (5.1 audio), or 2 (stereo only). + */ +#ifndef STB_VORBIS_MAX_CHANNELS +#define STB_VORBIS_MAX_CHANNELS 16 /* enough for anyone? */ +#endif + +/* STB_VORBIS_PUSHDATA_CRC_COUNT [number] + * after a flush_pushdata(), stb_vorbis begins scanning for the + * next valid page, without backtracking. when it finds something + * that looks like a page, it streams through it and verifies its + * CRC32. Should that validation fail, it keeps scanning. But it's + * possible that _while_ streaming through to check the CRC32 of + * one candidate page, it sees another candidate page. This #define + * determines how many "overlapping" candidate pages it can search + * at once. Note that "real" pages are typically ~4KB to ~8KB, whereas + * garbage pages could be as big as 64KB, but probably average ~16KB. + * So don't hose ourselves by scanning an apparent 64KB page and + * missing a ton of real ones in the interim; so minimum of 2 + */ #ifndef STB_VORBIS_PUSHDATA_CRC_COUNT #define STB_VORBIS_PUSHDATA_CRC_COUNT 4 #endif -// STB_VORBIS_FAST_HUFFMAN_LENGTH [number] -// sets the log size of the huffman-acceleration table. Maximum -// supported value is 24. with larger numbers, more decodings are O(1), -// but the table size is larger so worse cache missing, so you'll have -// to probe (and try multiple ogg vorbis files) to find the sweet spot. +/* STB_VORBIS_FAST_HUFFMAN_LENGTH [number] + * sets the log size of the huffman-acceleration table. Maximum + * supported value is 24. with larger numbers, more decodings are O(1), + * but the table size is larger so worse cache missing, so you'll have + * to probe (and try multiple ogg vorbis files) to find the sweet spot. + */ #ifndef STB_VORBIS_FAST_HUFFMAN_LENGTH #define STB_VORBIS_FAST_HUFFMAN_LENGTH 10 #endif -// STB_VORBIS_FAST_BINARY_LENGTH [number] -// sets the log size of the binary-search acceleration table. this -// is used in similar fashion to the fast-huffman size to set initial -// parameters for the binary search +/* STB_VORBIS_FAST_BINARY_LENGTH [number] + * sets the log size of the binary-search acceleration table. this + * is used in similar fashion to the fast-huffman size to set initial + * parameters for the binary search -// STB_VORBIS_FAST_HUFFMAN_INT -// The fast huffman tables are much more efficient if they can be -// stored as 16-bit results instead of 32-bit results. This restricts -// the codebooks to having only 65535 possible outcomes, though. -// (At least, accelerated by the huffman table.) + * STB_VORBIS_FAST_HUFFMAN_INT + * The fast huffman tables are much more efficient if they can be + * stored as 16-bit results instead of 32-bit results. This restricts + * the codebooks to having only 65535 possible outcomes, though. + * (At least, accelerated by the huffman table.) + */ #ifndef STB_VORBIS_FAST_HUFFMAN_INT #define STB_VORBIS_FAST_HUFFMAN_SHORT #endif -// STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH -// If the 'fast huffman' search doesn't succeed, then stb_vorbis falls -// back on binary searching for the correct one. This requires storing -// extra tables with the huffman codes in sorted order. Defining this -// symbol trades off space for speed by forcing a linear search in the -// non-fast case, except for "sparse" codebooks. -// #define STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH +/* STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH + * If the 'fast huffman' search doesn't succeed, then stb_vorbis falls + * back on binary searching for the correct one. This requires storing + * extra tables with the huffman codes in sorted order. Defining this + * symbol trades off space for speed by forcing a linear search in the + * non-fast case, except for "sparse" codebooks. + */ +#if 0 +#define STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH +#endif -// STB_VORBIS_DIVIDES_IN_RESIDUE -// stb_vorbis precomputes the result of the scalar residue decoding -// that would otherwise require a divide per chunk. you can trade off -// space for time by defining this symbol. -// #define STB_VORBIS_DIVIDES_IN_RESIDUE +/* STB_VORBIS_DIVIDES_IN_RESIDUE + * stb_vorbis precomputes the result of the scalar residue decoding + * that would otherwise require a divide per chunk. you can trade off + * space for time by defining this symbol. + */ +#if 0 +#define STB_VORBIS_DIVIDES_IN_RESIDUE +#endif -// STB_VORBIS_DIVIDES_IN_CODEBOOK -// vorbis VQ codebooks can be encoded two ways: with every case explicitly -// stored, or with all elements being chosen from a small range of values, -// and all values possible in all elements. By default, stb_vorbis expands -// this latter kind out to look like the former kind for ease of decoding, -// because otherwise an integer divide-per-vector-element is required to -// unpack the index. If you define STB_VORBIS_DIVIDES_IN_CODEBOOK, you can -// trade off storage for speed. -//#define STB_VORBIS_DIVIDES_IN_CODEBOOK +/* STB_VORBIS_DIVIDES_IN_CODEBOOK + * vorbis VQ codebooks can be encoded two ways: with every case explicitly + * stored, or with all elements being chosen from a small range of values, + * and all values possible in all elements. By default, stb_vorbis expands + * this latter kind out to look like the former kind for ease of decoding, + * because otherwise an integer divide-per-vector-element is required to + * unpack the index. If you define STB_VORBIS_DIVIDES_IN_CODEBOOK, you can + * trade off storage for speed. + */ +#if 0 +#define STB_VORBIS_DIVIDES_IN_CODEBOOK +#endif -// STB_VORBIS_CODEBOOK_SHORTS -// The vorbis file format encodes VQ codebook floats as ax+b where a and -// b are floating point per-codebook constants, and x is a 16-bit int. -// Normally, stb_vorbis decodes them to floats rather than leaving them -// as 16-bit ints and computing ax+b while decoding. This is a speed/space -// tradeoff; you can save space by defining this flag. +/* STB_VORBIS_CODEBOOK_SHORTS + * The vorbis file format encodes VQ codebook floats as ax+b where a and + * b are floating point per-codebook constants, and x is a 16-bit int. + * Normally, stb_vorbis decodes them to floats rather than leaving them + * as 16-bit ints and computing ax+b while decoding. This is a speed/space + * tradeoff; you can save space by defining this flag. + */ #ifndef STB_VORBIS_CODEBOOK_SHORTS #define STB_VORBIS_CODEBOOK_FLOATS #endif -// STB_VORBIS_DIVIDE_TABLE -// this replaces small integer divides in the floor decode loop with -// table lookups. made less than 1% difference, so disabled by default. +/* STB_VORBIS_DIVIDE_TABLE + * this replaces small integer divides in the floor decode loop with + * table lookups. made less than 1% difference, so disabled by default. + */ -// STB_VORBIS_NO_INLINE_DECODE -// disables the inlining of the scalar codebook fast-huffman decode. -// might save a little codespace; useful for debugging -// #define STB_VORBIS_NO_INLINE_DECODE +/* STB_VORBIS_NO_INLINE_DECODE + * disables the inlining of the scalar codebook fast-huffman decode. + * might save a little codespace; useful for debugging + */ +#if 0 +#define STB_VORBIS_NO_INLINE_DECODE +#endif -// STB_VORBIS_NO_DEFER_FLOOR -// Normally we only decode the floor without synthesizing the actual -// full curve. We can instead synthesize the curve immediately. This -// requires more memory and is very likely slower, so I don't think -// you'd ever want to do it except for debugging. -// #define STB_VORBIS_NO_DEFER_FLOOR +/* STB_VORBIS_NO_DEFER_FLOOR + * Normally we only decode the floor without synthesizing the actual + * full curve. We can instead synthesize the curve immediately. This + * requires more memory and is very likely slower, so I don't think + * you'd ever want to do it except for debugging. + */ +#if 0 +#define STB_VORBIS_NO_DEFER_FLOOR +#endif - - -////////////////////////////////////////////////////////////////////////////// - #ifdef STB_VORBIS_NO_PULLDATA_API #define STB_VORBIS_NO_INTEGER_CONVERSION #define STB_VORBIS_NO_STDIO @@ -527,8 +563,8 @@ enum STBVorbisError #ifndef STB_VORBIS_NO_INTEGER_CONVERSION #ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT - // only need endianness for fast-float-to-int, which we don't - // use for pushdata + /* only need endianness for fast-float-to-int, which we don't + * use for pushdata */ #ifndef STB_VORBIS_BIG_ENDIAN #define STB_VORBIS_ENDIAN 0 @@ -556,13 +592,7 @@ enum STBVorbisError #define NULL 0 #endif -#if !defined(_MSC_VER) && !(defined(__MINGW32__) && defined(__forceinline)) - #if __GNUC__ - #define __forceinline inline - #else - #define __forceinline - #endif -#endif +#include #if STB_VORBIS_MAX_CHANNELS > 256 #error "Value of STB_VORBIS_MAX_CHANNELS outside of allowed range" @@ -573,7 +603,7 @@ enum STBVorbisError #endif -#define MAX_BLOCKSIZE_LOG 13 // from specification +#define MAX_BLOCKSIZE_LOG 13 /* from specification */ #define MAX_BLOCKSIZE (1 << MAX_BLOCKSIZE_LOG) @@ -595,18 +625,19 @@ typedef float stb_vorbis_codetype; typedef uint16 stb_vorbis_codetype; #endif -// @NOTE -// -// Some arrays below are tagged "//varies", which means it's actually -// a variable-sized piece of data, but rather than malloc I assume it's -// small enough it's better to just allocate it all together with the -// main thing -// -// Most of the variables are specified with the smallest size I could pack -// them into. It might give better performance to make them all full-sized -// integers. It should be safe to freely rearrange the structures or change -// the sizes larger--nothing relies on silently truncating etc., nor the -// order of variables. +/* @NOTE + * + * Some arrays below are tagged "//varies", which means it's actually + * a variable-sized piece of data, but rather than malloc I assume it's + * small enough it's better to just allocate it all together with the + * main thing + * + * Most of the variables are specified with the smallest size I could pack + * them into. It might give better performance to make them all full-sized + * integers. It should be safe to freely rearrange the structures or change + * the sizes larger--nothing relies on silently truncating etc., nor the + * order of variables. + */ #define FAST_HUFFMAN_TABLE_SIZE (1 << STB_VORBIS_FAST_HUFFMAN_LENGTH) #define FAST_HUFFMAN_TABLE_MASK (FAST_HUFFMAN_TABLE_SIZE - 1) @@ -642,18 +673,18 @@ typedef struct uint8 amplitude_bits; uint8 amplitude_offset; uint8 number_of_books; - uint8 book_list[16]; // varies + uint8 book_list[16]; /* varies */ } Floor0; typedef struct { uint8 partitions; - uint8 partition_class_list[32]; // varies - uint8 class_dimensions[16]; // varies - uint8 class_subclasses[16]; // varies - uint8 class_masterbooks[16]; // varies - int16 subclass_books[16][8]; // varies - uint16 Xlist[31*8+2]; // varies + uint8 partition_class_list[32]; /* varies */ + uint8 class_dimensions[16]; /* varies */ + uint8 class_subclasses[16]; /* varies */ + uint8 class_masterbooks[16]; /* varies */ + int16 subclass_books[16][8]; /* varies */ + uint16 Xlist[31*8+2]; /* varies */ uint8 sorted_order[31*8+2]; uint8 neighbors[31*8+2][2]; uint8 floor1_multiplier; @@ -689,8 +720,8 @@ typedef struct uint16 coupling_steps; MappingChannel *chan; uint8 submaps; - uint8 submap_floor[15]; // varies - uint8 submap_residue[15]; // varies + uint8 submap_floor[15]; /* varies */ + uint8 submap_residue[15]; /* varies */ } Mapping; typedef struct @@ -703,11 +734,11 @@ typedef struct typedef struct { - uint32 goal_crc; // expected crc if match - int bytes_left; // bytes left in packet - uint32 crc_so_far; // running crc - int bytes_done; // bytes processed in _current_ chunk - uint32 sample_loc; // granule pos encoded in page + uint32 goal_crc; /* expected crc if match */ + int bytes_left; /* bytes left in packet */ + uint32 crc_so_far; /* running crc */ + int bytes_done; /* bytes processed in _current_ chunk */ + uint32 sample_loc; /* granule pos encoded in page */ } CRCscan; typedef struct @@ -720,7 +751,7 @@ typedef struct struct stb_vorbis { - // user-accessible info + /* user-accessible info */ unsigned int sample_rate; int channels; @@ -728,7 +759,7 @@ struct stb_vorbis unsigned int temp_memory_required; unsigned int setup_temp_memory_required; - // input config + /* input config */ #ifndef STB_VORBIS_NO_STDIO FILE *f; uint32 f_start; @@ -747,36 +778,36 @@ struct stb_vorbis ProbedPage p_first, p_last; - // memory management + /* memory management */ stb_vorbis_alloc alloc; int setup_offset; int temp_offset; - // run-time results + /* run-time results */ int eof; enum STBVorbisError error; - // user-useful data + /* user-useful data */ - // header info + /* header info */ int blocksize[2]; int blocksize_0, blocksize_1; int codebook_count; Codebook *codebooks; int floor_count; - uint16 floor_types[64]; // varies + uint16 floor_types[64]; /* varies */ Floor *floor_config; int residue_count; - uint16 residue_types[64]; // varies + uint16 residue_types[64]; /* varies */ Residue *residue_config; int mapping_count; Mapping *mapping; int mode_count; - Mode mode_config[64]; // varies + Mode mode_config[64]; /* varies */ uint32 total_samples; - // decode buffer + /* decode buffer */ float *channel_buffers[STB_VORBIS_MAX_CHANNELS]; float *outputs [STB_VORBIS_MAX_CHANNELS]; @@ -789,18 +820,18 @@ struct stb_vorbis float *floor_buffers[STB_VORBIS_MAX_CHANNELS]; #endif - uint32 current_loc; // sample location of next frame to decode + uint32 current_loc; /* sample location of next frame to decode */ int current_loc_valid; - // per-blocksize precomputed data + /* per-blocksize precomputed data */ - // twiddle factors + /* twiddle factors */ float *A[2],*B[2],*C[2]; float *window[2]; uint16 *bit_reverse[2]; - // current page/packet/segment streaming info - uint32 serial; // stream serial number for verification + /* current page/packet/segment streaming info */ + uint32 serial; /* stream serial number for verification */ int last_page; int segment_count; uint8 segments[255]; @@ -808,8 +839,8 @@ struct stb_vorbis uint8 bytes_in_seg; uint8 first_decode; int next_seg; - int last_seg; // flag that we're on the last segment - int last_seg_which; // what was the segment number of the last seg? + int last_seg; /* flag that we're on the last segment */ + int last_seg_which; /* what was the segment number of the last seg? */ uint32 acc; int valid_bits; int packet_bytes; @@ -818,19 +849,22 @@ struct stb_vorbis int discard_samples_deferred; uint32 samples_output; - // push mode scanning - int page_crc_tests; // only in push_mode: number of tests active; -1 if not searching + /* push mode scanning */ + int page_crc_tests; /* only in push_mode: number of tests active; -1 if not searching */ #ifndef STB_VORBIS_NO_PUSHDATA_API CRCscan scan[STB_VORBIS_PUSHDATA_CRC_COUNT]; #endif - // sample-access + /* sample-access */ int channel_buffer_start; int channel_buffer_end; }; extern int my_prof(int slot); -//#define stb_prof my_prof + +#if 0 +#define stb_prof my_prof +#endif #ifndef stb_prof #define stb_prof(x) ((void) 0) @@ -850,16 +884,17 @@ static int error(vorb *f, enum STBVorbisError e) { f->error = e; if (!f->eof && e != VORBIS_need_more_data) { - f->error=e; // breakpoint for debugging + f->error=e; /* breakpoint for debugging */ } return 0; } -// these functions are used for allocating temporary memory -// while decoding. if you can afford the stack space, use -// alloca(); otherwise, provide a temp buffer and it will -// allocate out of those. +/* these functions are used for allocating temporary memory + * while decoding. if you can afford the stack space, use + * alloca(); otherwise, provide a temp buffer and it will + * allocate out of those. + */ #define array_size_required(count,size) (count*(sizeof(void *)+(size))) @@ -874,7 +909,7 @@ static int error(vorb *f, enum STBVorbisError e) #define temp_block_array(f,count,size) make_block_array(temp_alloc(f,array_size_required(count,size)), count, size) -// given a sufficiently large block of memory, make an array of pointers to subblocks of it +/* given a sufficiently large block of memory, make an array of pointers to subblocks of it */ static void *make_block_array(void *mem, int count, int size) { int i; @@ -902,7 +937,7 @@ static void *setup_malloc(vorb *f, int sz) static void setup_free(vorb *f, void *p) { - if (f->alloc.alloc_buffer) return; // do nothing; setup mem is not a stack + if (f->alloc.alloc_buffer) return; /* do nothing; setup mem is not a stack */ free(p); } @@ -926,7 +961,7 @@ static void setup_temp_free(vorb *f, void *p, int sz) free(p); } -#define CRC32_POLY 0x04c11db7 // from spec +#define CRC32_POLY 0x04c11db7 /* from spec */ static uint32 stb_vorbis_crc_table[256]; static void crc32_init(void) @@ -940,13 +975,13 @@ static void crc32_init(void) } } -static __forceinline uint32 crc32_update(uint32 crc, uint8 byte) +static INLINE uint32 crc32_update(uint32 crc, uint8 byte) { return (crc << 8) ^ stb_vorbis_crc_table[byte ^ (crc >> 24)]; } -// used in setup, and for huffman that doesn't go fast path +/* used in setup, and for huffman that doesn't go fast path */ static unsigned int bit_reverse(unsigned int n) { n = ((n & 0xAAAAAAAA) >> 1) | ((n & 0x55555555) << 1); @@ -961,14 +996,15 @@ static float square(float x) return x*x; } -// this is a weird definition of log2() for which log2(1) = 1, log2(2) = 2, log2(4) = 3 -// as required by the specification. fast(?) implementation from stb.h -// @OPTIMIZE: called multiple times per-packet with "constants"; move to setup +/* this is a weird definition of log2() for which log2(1) = 1, log2(2) = 2, log2(4) = 3 + * as required by the specification. fast(?) implementation from stb.h + * @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 }; - // 2 compares if n < 16, 3 compares otherwise (4 if signed or n > 1<<29) + /* 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]; @@ -978,24 +1014,24 @@ static int ilog(int32 n) 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 return 0; /* signed n returns 0 */ } #ifndef M_PI - #define M_PI 3.14159265358979323846264f // from CRC + #define M_PI 3.14159265358979323846264f /* from CRC */ #endif -// code length assigned to a value with no huffman encoding +/* code length assigned to a value with no huffman encoding */ #define NO_CODE 255 -/////////////////////// LEAF SETUP FUNCTIONS ////////////////////////// -// -// these functions are only called at setup, and only a few times -// per file +/* LEAF SETUP FUNCTIONS */ + +/* these functions are only called at setup, and only a few times + * per file */ static float float32_unpack(uint32 x) { - // from the specification + /* from the specification */ uint32 mantissa = x & 0x1fffff; uint32 sign = x & 0x80000000; uint32 exp = (x & 0x7fe00000) >> 21; @@ -1004,13 +1040,14 @@ static float float32_unpack(uint32 x) } -// zlib & jpeg huffman tables assume that the output symbols -// can either be arbitrarily arranged, or have monotonically -// increasing frequencies--they rely on the lengths being sorted; -// this makes for a very simple generation algorithm. -// vorbis allows a huffman table with non-sorted lengths. This -// requires a more sophisticated construction, since symbols in -// order do not map to huffman codes "in order". +/* zlib & jpeg huffman tables assume that the output symbols + * can either be arbitrarily arranged, or have monotonically + * increasing frequencies--they rely on the lengths being sorted; + * this makes for a very simple generation algorithm. + * vorbis allows a huffman table with non-sorted lengths. This + * requires a more sophisticated construction, since symbols in + * order do not map to huffman codes "in order". + */ static void add_entry(Codebook *c, uint32 huff_code, int symbol, int count, int len, uint32 *values) { if (!c->sparse) { @@ -1028,34 +1065,34 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) uint32 available[32]; memset(available, 0, sizeof(available)); - // find the first entry + /* find the first entry */ for (k=0; k < n; ++k) if (len[k] < NO_CODE) break; if (k == n) { assert(c->sorted_entries == 0); return TRUE; } - // add to the list + /* add to the list */ add_entry(c, 0, k, m++, len[k], values); - // add all available leaves + /* add all available leaves */ for (i=1; i <= len[k]; ++i) available[i] = 1 << (32-i); - // note that the above code treats the first case specially, - // but it's really the same as the following code, so they - // could probably be combined (except the initial code is 0, - // and I use 0 in available[] to mean 'empty') + /* note that the above code treats the first case specially, + * but it's really the same as the following code, so they + * could probably be combined (except the initial code is 0, + * and I use 0 in available[] to mean 'empty') */ for (i=k+1; i < n; ++i) { uint32 res; int z = len[i], y; if (z == NO_CODE) continue; - // find lowest available leaf (should always be earliest, - // which is what the specification calls for) - // note that this property, and the fact we can never have - // more than one free leaf at a given level, isn't totally - // trivial to prove, but it seems true and the assert never - // fires, so! + /* find lowest available leaf (should always be earliest, + * which is what the specification calls for) + * note that this property, and the fact we can never have + * more than one free leaf at a given level, isn't totally + * trivial to prove, but it seems true and the assert never + * fires, so! */ while (z > 0 && !available[z]) --z; if (z == 0) { assert(0); return FALSE; } res = available[z]; available[z] = 0; add_entry(c, bit_reverse(res), i, m++, len[i], values); - // propogate availability up the tree + /* propogate availability up the tree */ if (z != len[i]) { for (y=len[i]; y > z; --y) { assert(available[y] == 0); @@ -1066,8 +1103,8 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) return TRUE; } -// accelerated huffman table allows fast O(1) match of all symbols -// of length <= STB_VORBIS_FAST_HUFFMAN_LENGTH +/* accelerated huffman table allows fast O(1) match of all symbols + * of length <= STB_VORBIS_FAST_HUFFMAN_LENGTH */ static void compute_accelerated_huffman(Codebook *c) { int i, len; @@ -1076,12 +1113,12 @@ static void compute_accelerated_huffman(Codebook *c) len = c->sparse ? c->sorted_entries : c->entries; #ifdef STB_VORBIS_FAST_HUFFMAN_SHORT - if (len > 32767) len = 32767; // largest possible value we can encode! + if (len > 32767) len = 32767; /* largest possible value we can encode! */ #endif for (i=0; i < len; ++i) { if (c->codeword_lengths[i] <= STB_VORBIS_FAST_HUFFMAN_LENGTH) { uint32 z = c->sparse ? bit_reverse(c->sorted_codewords[i]) : c->codewords[i]; - // set table entries for all bit combinations in the higher bits + /* set table entries for all bit combinations in the higher bits */ while (z < FAST_HUFFMAN_TABLE_SIZE) { c->fast_huffman[z] = i; z += 1 << c->codeword_lengths[i]; @@ -1111,15 +1148,15 @@ static int include_in_sort(Codebook *c, uint8 len) return FALSE; } -// if the fast table above doesn't work, we want to binary -// search them... need to reverse the bits +/* if the fast table above doesn't work, we want to binary + * search them... need to reverse the bits */ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values) { int i, len; - // build a list of all the entries - // OPTIMIZATION: don't include the short ones, since they'll be caught by FAST_HUFFMAN. - // this is kind of a frivolous optimization--I don't see any performance improvement, - // but it's like 4 extra lines of code, so. + /* build a list of all the entries + * OPTIMIZATION: don't include the short ones, since they'll be caught by FAST_HUFFMAN. + * this is kind of a frivolous optimization--I don't see any performance improvement, + * but it's like 4 extra lines of code, so. */ if (!c->sparse) { int k = 0; for (i=0; i < c->entries; ++i) @@ -1135,18 +1172,18 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values) c->sorted_codewords[c->sorted_entries] = 0xffffffff; len = c->sparse ? c->sorted_entries : c->entries; - // now we need to indicate how they correspond; we could either - // #1: sort a different data structure that says who they correspond to - // #2: for each sorted entry, search the original list to find who corresponds - // #3: for each original entry, find the sorted entry - // #1 requires extra storage, #2 is slow, #3 can use binary search! + /* now we need to indicate how they correspond; we could either + * #1: sort a different data structure that says who they correspond to + * #2: for each sorted entry, search the original list to find who corresponds + * #3: for each original entry, find the sorted entry + * #1 requires extra storage, #2 is slow, #3 can use binary search! */ for (i=0; i < len; ++i) { int huff_len = c->sparse ? lengths[values[i]] : lengths[i]; if (include_in_sort(c,huff_len)) { uint32 code = bit_reverse(c->codewords[i]); int x=0, n=c->sorted_entries; while (n > 1) { - // invariant: sc[x] <= code < sc[x+n] + /* invariant: sc[x] <= code < sc[x+n] */ int m = x + (n >> 1); if (c->sorted_codewords[m] <= code) { x = m; @@ -1166,26 +1203,26 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values) } } -// only run while parsing the header (3 times) +/* only run while parsing the header (3 times) */ static int vorbis_validate(uint8 *data) { static uint8 vorbis[6] = { 'v', 'o', 'r', 'b', 'i', 's' }; return memcmp(data, vorbis, 6) == 0; } -// called from setup only, once per code book -// (formula implied by specification) +/* called from setup only, once per code book + * (formula implied by specification) */ static int lookup1_values(int entries, int dim) { int r = (int) floor(exp((float) log((float) entries) / dim)); - if ((int) floor(pow((float) r+1, dim)) <= entries) // (int) cast for MinGW warning; - ++r; // floor() to avoid _ftol() when non-CRT + if ((int) floor(pow((float) r+1, dim)) <= entries) /* (int) cast for MinGW warning; */ + ++r; /* floor() to avoid _ftol() when non-CRT */ assert(pow((float) r+1, dim) > entries); - assert((int) floor(pow((float) r, dim)) <= entries); // (int),floor() as above + assert((int) floor(pow((float) r, dim)) <= entries); /* (int),floor() as above */ return r; } -// called twice per file +/* called twice per file */ static void compute_twiddle_factors(int n, float *A, float *B, float *C) { int n4 = n >> 2, n8 = n >> 3; @@ -1212,7 +1249,7 @@ static void compute_window(int n, float *window) static void compute_bitreverse(int n, uint16 *rev) { - int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions + int ld = ilog(n) - 1; /* ilog is off-by-one from normal definitions */ int i, n8 = n >> 3; for (i=0; i < n8; ++i) rev[i] = (bit_reverse(i) >> (32-ld+3)) << 2; @@ -1246,7 +1283,7 @@ 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 +/* this has been repurposed so y is now the original index instead of y */ typedef struct { uint16 x,y; @@ -1259,8 +1296,7 @@ static int STBV_CDECL point_compare(const void *p, const void *q) return a->x < b->x ? -1 : a->x > b->x; } -// -/////////////////////// END LEAF SETUP FUNCTIONS ////////////////////////// +/* END LEAF SETUP FUNCTIONS */ #if defined(STB_VORBIS_NO_STDIO) @@ -1379,35 +1415,35 @@ static int capture_pattern(vorb *f) static int start_page_no_capturepattern(vorb *f) { uint32 loc0,loc1,n; - // stream structure version + /* stream structure version */ if (0 != get8(f)) return error(f, VORBIS_invalid_stream_structure_version); - // header flag + /* header flag */ f->page_flag = get8(f); - // absolute granule position + /* absolute granule position */ loc0 = get32(f); loc1 = get32(f); - // @TODO: validate loc0,loc1 as valid positions? - // stream serial number -- vorbis doesn't interleave, so discard + /* @TODO: validate loc0,loc1 as valid positions? + * stream serial number -- vorbis doesn't interleave, so discard */ get32(f); - //if (f->serial != get32(f)) return error(f, VORBIS_incorrect_stream_serial_number); - // page sequence number + /*if (f->serial != get32(f)) return error(f, VORBIS_incorrect_stream_serial_number); + * page sequence number */ n = get32(f); f->last_page = n; - // CRC32 + /* CRC32 */ get32(f); - // page_segments + /* page_segments */ f->segment_count = get8(f); if (!getn(f, f->segments, f->segment_count)) return error(f, VORBIS_unexpected_eof); - // assume we _don't_ know any the sample position of any segments + /* assume we _don't_ know any the sample position of any segments */ f->end_seg_with_known_loc = -2; if (loc0 != ~0U || loc1 != ~0U) { int i; - // determine which packet is the last one that will complete + /* determine which packet is the last one that will complete */ for (i=f->segment_count-1; i >= 0; --i) if (f->segments[i] < 255) break; - // 'i' is now the index of the _last_ segment of a packet that ends + /* 'i' is now the index of the _last_ segment of a packet that ends */ if (i >= 0) { f->end_seg_with_known_loc = i; f->known_loc_for_packet = loc0; @@ -1448,7 +1484,7 @@ static int start_packet(vorb *f) f->valid_bits = 0; f->packet_bytes = 0; f->bytes_in_seg = 0; - // f->next_seg is now valid + /* f->next_seg is now valid */ return TRUE; } @@ -1456,15 +1492,15 @@ static int maybe_start_packet(vorb *f) { if (f->next_seg == -1) { int x = get8(f); - if (f->eof) return FALSE; // EOF at page boundary is not an error! + if (f->eof) return FALSE; /* EOF at page boundary is not an error! */ if (0x4f != x ) return error(f, VORBIS_missing_capture_pattern); if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern); if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern); if (0x53 != get8(f)) return error(f, VORBIS_missing_capture_pattern); if (!start_page_no_capturepattern(f)) return FALSE; if (f->page_flag & PAGEFLAG_continued_packet) { - // set up enough state that we can read this packet if we want, - // e.g. during recovery + /* set up enough state that we can read this packet if we want, + * e.g. during recovery */ f->last_seg = FALSE; f->bytes_in_seg = 0; return error(f, VORBIS_continued_packet_flag_invalid); @@ -1478,7 +1514,7 @@ static int next_segment(vorb *f) int len; if (f->last_seg) return 0; if (f->next_seg == -1) { - f->last_seg_which = f->segment_count-1; // in case start_page fails + f->last_seg_which = f->segment_count-1; /* in case start_page fails */ if (!start_page(f)) { f->last_seg = 1; return 0; } if (!(f->page_flag & PAGEFLAG_continued_packet)) return error(f, VORBIS_continued_packet_flag_invalid); } @@ -1499,7 +1535,7 @@ static int next_segment(vorb *f) static int get8_packet_raw(vorb *f) { - if (!f->bytes_in_seg) { // CLANG! + if (!f->bytes_in_seg) { /* CLANG! */ if (f->last_seg) return EOP; else if (!next_segment(f)) return EOP; } @@ -1521,8 +1557,8 @@ static void flush_packet(vorb *f) while (get8_packet_raw(f) != EOP); } -// @OPTIMIZE: this is the secondary bit decoder, so it's probably not as important -// as the huffman decoder? +/* @OPTIMIZE: this is the secondary bit decoder, so it's probably not as important + * as the huffman decoder? */ static uint32 get_bits(vorb *f, int n) { uint32 z; @@ -1530,7 +1566,7 @@ static uint32 get_bits(vorb *f, int n) if (f->valid_bits < 0) return 0; if (f->valid_bits < n) { if (n > 24) { - // the accumulator technique below would not work correctly in this case + /* the accumulator technique below would not work correctly in this case */ z = get_bits(f, 24); z += get_bits(f, n-24) << 24; return z; @@ -1553,11 +1589,11 @@ static uint32 get_bits(vorb *f, int n) return z; } -// @OPTIMIZE: primary accumulator for huffman -// expand the buffer to as many bits as possible without reading off end of packet -// it might be nice to allow f->valid_bits and f->acc to be stored in registers, -// e.g. cache them locally and decode locally -static __forceinline void prep_huffman(vorb *f) +/* @OPTIMIZE: primary accumulator for huffman + * expand the buffer to as many bits as possible without reading off end of packet + * it might be nice to allow f->valid_bits and f->acc to be stored in registers, + * e.g. cache them locally and decode locally */ +static INLINE void prep_huffman(vorb *f) { if (f->valid_bits <= 24) { if (f->valid_bits == 0) f->acc = 0; @@ -1576,7 +1612,7 @@ enum { VORBIS_packet_id = 1, VORBIS_packet_comment = 3, - VORBIS_packet_setup = 5, + VORBIS_packet_setup = 5 }; static int codebook_decode_scalar_raw(vorb *f, Codebook *c) @@ -1585,15 +1621,15 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c) prep_huffman(f); assert(c->sorted_codewords || c->codewords); - // cases to use binary search: sorted_codewords && !c->codewords - // sorted_codewords && c->entries > 8 + /* cases to use binary search: sorted_codewords && !c->codewords + * sorted_codewords && c->entries > 8 */ if (c->entries > 8 ? c->sorted_codewords!=NULL : !c->codewords) { - // binary search + /* binary search */ uint32 code = bit_reverse(f->acc); int x=0, n=c->sorted_entries, len; while (n > 1) { - // invariant: sc[x] <= code < sc[x+n] + /* invariant: sc[x] <= code < sc[x+n] */ int m = x + (n >> 1); if (c->sorted_codewords[m] <= code) { x = m; @@ -1602,9 +1638,9 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c) n >>= 1; } } - // x is now the sorted index + /* x is now the sorted index */ if (!c->sparse) x = c->sorted_values[x]; - // x is now sorted index if sparse, or symbol otherwise + /* x is now sorted index if sparse, or symbol otherwise */ len = c->codeword_lengths[x]; if (f->valid_bits >= len) { f->acc >>= len; @@ -1616,7 +1652,7 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c) return -1; } - // if small, linear search + /* if small, linear search */ assert(!c->sparse); for (i=0; i < c->entries; ++i) { if (c->codeword_lengths[i] == NO_CODE) continue; @@ -1659,7 +1695,7 @@ static int codebook_decode_scalar(vorb *f, Codebook *c) int i; if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH) prep_huffman(f); - // fast huffman table lookup + /* fast huffman table lookup */ i = f->acc & FAST_HUFFMAN_TABLE_MASK; i = c->fast_huffman[i]; if (i >= 0) { @@ -1690,8 +1726,8 @@ static int codebook_decode_scalar(vorb *f, Codebook *c) -// CODEBOOK_ELEMENT_FAST is an optimization for the CODEBOOK_FLOATS case -// where we avoid one addition +/* CODEBOOK_ELEMENT_FAST is an optimization for the CODEBOOK_FLOATS case + * where we avoid one addition */ #ifndef STB_VORBIS_CODEBOOK_FLOATS #define CODEBOOK_ELEMENT(c,off) (c->multiplicands[off] * c->delta_value + c->minimum_value) #define CODEBOOK_ELEMENT_FAST(c,off) (c->multiplicands[off] * c->delta_value) @@ -1706,13 +1742,13 @@ static int codebook_decode_start(vorb *f, Codebook *c) { int z = -1; - // type 0 is only legal in a scalar context + /* type 0 is only legal in a scalar context */ if (c->lookup_type == 0) error(f, VORBIS_invalid_stream); else { DECODE_VQ(z,f,c); if (c->sparse) assert(z < c->sorted_entries); - if (z < 0) { // check for EOP + if (z < 0) { /* check for EOP */ if (!f->bytes_in_seg) if (f->last_seg) return z; @@ -1798,7 +1834,7 @@ static int codebook_decode_deinterleave_repeat(vorb *f, Codebook *c, float **out int p_inter = *p_inter_p; int i,z, effective = c->dimensions; - // type 0 is only legal in a scalar context + /* type 0 is only legal in a scalar context */ if (c->lookup_type == 0) return error(f, VORBIS_invalid_stream); while (total_decode > 0) { @@ -1813,10 +1849,10 @@ static int codebook_decode_deinterleave_repeat(vorb *f, Codebook *c, float **out return error(f, VORBIS_invalid_stream); } - // if this will take us off the end of the buffers, stop short! - // we check by computing the length of the virtual interleaved - // buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter), - // and the length we'll be using (effective) + /* if this will take us off the end of the buffers, stop short! + * we check by computing the length of the virtual interleaved + * buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter), + * and the length we'll be using (effective) */ if (c_inter + p_inter*ch + effective > len * ch) { effective = len*ch - (p_inter*ch - c_inter); } @@ -1869,7 +1905,7 @@ static int codebook_decode_deinterleave_repeat_2(vorb *f, Codebook *c, float **o int p_inter = *p_inter_p; int i,z, effective = c->dimensions; - // type 0 is only legal in a scalar context + /* type 0 is only legal in a scalar context */ if (c->lookup_type == 0) return error(f, VORBIS_invalid_stream); while (total_decode > 0) { @@ -1882,10 +1918,11 @@ static int codebook_decode_deinterleave_repeat_2(vorb *f, Codebook *c, float **o return error(f, VORBIS_invalid_stream); } - // if this will take us off the end of the buffers, stop short! - // we check by computing the length of the virtual interleaved - // buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter), - // and the length we'll be using (effective) + /* if this will take us off the end of the buffers, stop short! + * we check by computing the length of the virtual interleaved + * buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter), + * and the length we'll be using (effective) + */ if (c_inter + p_inter*2 + effective > len * 2) { effective = len*2 - (p_inter*2 - c_inter); } @@ -1894,7 +1931,7 @@ static int codebook_decode_deinterleave_repeat_2(vorb *f, Codebook *c, float **o z *= c->dimensions; stb_prof(11); if (c->sequence_p) { - // haven't optimized this case because I don't have any examples + /* haven't optimized this case because I don't have any examples */ for (i=0; i < effective; ++i) { float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last; if (outputs[c_inter]) @@ -1946,13 +1983,13 @@ static int predict_point(int x, int x0, int x1, int y0, int y1) { int dy = y1 - y0; int adx = x1 - x0; - // @OPTIMIZE: force int division to round in the right direction... is this necessary on x86? + /* @OPTIMIZE: force int division to round in the right direction... is this necessary on x86? */ int err = abs(dy) * (x - x0); int off = err / adx; return dy < 0 ? y0 - off : y0 + off; } -// the following table is block-copied from the specification +/* the following table is block-copied from the specification */ static float inverse_db_table[256] = { 1.0649863e-07f, 1.1341951e-07f, 1.2079015e-07f, 1.2863978e-07f, @@ -2022,13 +2059,14 @@ static float inverse_db_table[256] = }; -// @OPTIMIZE: if you want to replace this bresenham line-drawing routine, -// note that you must produce bit-identical output to decode correctly; -// this specific sequence of operations is specified in the spec (it's -// drawing integer-quantized frequency-space lines that the encoder -// expects to be exactly the same) -// ... also, isn't the whole point of Bresenham's algorithm to NOT -// have to divide in the setup? sigh. +/* @OPTIMIZE: if you want to replace this bresenham line-drawing routine, + * note that you must produce bit-identical output to decode correctly; + * this specific sequence of operations is specified in the spec (it's + * drawing integer-quantized frequency-space lines that the encoder + * expects to be exactly the same) + * ... also, isn't the whole point of Bresenham's algorithm to NOT + * have to divide in the setup? sigh. + */ #ifndef STB_VORBIS_NO_DEFER_FLOOR #define LINE_OP(a,b) a *= b #else @@ -2038,10 +2076,10 @@ static float inverse_db_table[256] = #ifdef STB_VORBIS_DIVIDE_TABLE #define DIVTAB_NUMER 32 #define DIVTAB_DENOM 64 -int8 integer_divide_table[DIVTAB_NUMER][DIVTAB_DENOM]; // 2KB +int8 integer_divide_table[DIVTAB_NUMER][DIVTAB_DENOM]; /* 2KB */ #endif -static __forceinline void draw_line(float *output, int x0, int y0, int x1, int y1, int n) +static INLINE void draw_line(float *output, int x0, int y0, int x1, int y1, int n) { int dy = y1 - y0; int adx = x1 - x0; @@ -2168,12 +2206,12 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int int b = r->residue_books[c][pass]; if (b >= 0) { Codebook *book = f->codebooks + b; - stb_prof(20); // accounts for X time + stb_prof(20); /* accounts for X time */ #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size)) goto done; #else - // saves 1% + /* saves 1% */ if (!codebook_decode_deinterleave_repeat_2(f, book, residue_buffers, &c_inter, &p_inter, n, r->part_size)) goto done; #endif @@ -2331,90 +2369,13 @@ static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int } -#if 0 -// slow way for debugging -void inverse_mdct_slow(float *buffer, int n) -{ - int i,j; - int n2 = n >> 1; - float *x = (float *) malloc(sizeof(*x) * n2); - memcpy(x, buffer, sizeof(*x) * n2); - for (i=0; i < n; ++i) { - float acc = 0; - for (j=0; j < n2; ++j) - // formula from paper: - //acc += n/4.0f * x[j] * (float) cos(M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1)); - // formula from wikipedia - //acc += 2.0f / n2 * x[j] * (float) cos(M_PI/n2 * (i + 0.5 + n2/2)*(j + 0.5)); - // these are equivalent, except the formula from the paper inverts the multiplier! - // however, what actually works is NO MULTIPLIER!?! - //acc += 64 * 2.0f / n2 * x[j] * (float) cos(M_PI/n2 * (i + 0.5 + n2/2)*(j + 0.5)); - acc += x[j] * (float) cos(M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1)); - buffer[i] = acc; - } - free(x); -} -#elif 0 -// same as above, but just barely able to run in real time on modern machines -void inverse_mdct_slow(float *buffer, int n, vorb *f, int blocktype) -{ - float mcos[16384]; - int i,j; - int n2 = n >> 1, nmask = (n << 2) -1; - float *x = (float *) malloc(sizeof(*x) * n2); - memcpy(x, buffer, sizeof(*x) * n2); - for (i=0; i < 4*n; ++i) - mcos[i] = (float) cos(M_PI / 2 * i / n); - - for (i=0; i < n; ++i) { - float acc = 0; - for (j=0; j < n2; ++j) - acc += x[j] * mcos[(2 * i + 1 + n2)*(2*j+1) & nmask]; - buffer[i] = acc; - } - free(x); -} -#elif 0 -// transform to use a slow dct-iv; this is STILL basically trivial, -// but only requires half as many ops -void dct_iv_slow(float *buffer, int n) -{ - float mcos[16384]; - float x[2048]; - int i,j; - int n2 = n >> 1, nmask = (n << 3) - 1; - memcpy(x, buffer, sizeof(*x) * n); - for (i=0; i < 8*n; ++i) - mcos[i] = (float) cos(M_PI / 4 * i / n); - for (i=0; i < n; ++i) { - float acc = 0; - for (j=0; j < n; ++j) - acc += x[j] * mcos[((2 * i + 1)*(2*j+1)) & nmask]; - buffer[i] = acc; - } -} - -void inverse_mdct_slow(float *buffer, int n, vorb *f, int blocktype) -{ - int i, n4 = n >> 2, n2 = n >> 1, n3_4 = n - n4; - float temp[4096]; - - memcpy(temp, buffer, n2 * sizeof(float)); - dct_iv_slow(temp, n2); // returns -c'-d, a-b' - - for (i=0; i < n4 ; ++i) buffer[i] = temp[i+n4]; // a-b' - for ( ; i < n3_4; ++i) buffer[i] = -temp[n3_4 - i - 1]; // b-a', c+d' - for ( ; i < n ; ++i) buffer[i] = -temp[i - n3_4]; // c'+d -} -#endif - #ifndef LIBVORBIS_MDCT #define LIBVORBIS_MDCT 0 #endif #if LIBVORBIS_MDCT -// directly call the vorbis MDCT using an interface documented -// by Jeff Roberts... useful for performance comparison +/* directly call the vorbis MDCT using an interface documented + * by Jeff Roberts... useful for performance comparison */ typedef struct { int n; @@ -2449,9 +2410,9 @@ void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) #endif -// the following were split out into separate functions while optimizing; -// they could be pushed back up but eh. __forceinline showed no change; -// they're probably already being inlined. +/* the following were split out into separate functions while optimizing; + * they could be pushed back up but eh. __forceinline showed no change; + * they're probably already being inlined. */ static void imdct_step3_iter0_loop(int n, float *e, int i_off, int k_off, float *A) { float *ee0 = e + i_off; @@ -2463,32 +2424,32 @@ static void imdct_step3_iter0_loop(int n, float *e, int i_off, int k_off, float float k00_20, k01_21; k00_20 = ee0[ 0] - ee2[ 0]; k01_21 = ee0[-1] - ee2[-1]; - ee0[ 0] += ee2[ 0];//ee0[ 0] = ee0[ 0] + ee2[ 0]; - ee0[-1] += ee2[-1];//ee0[-1] = ee0[-1] + ee2[-1]; + ee0[ 0] += ee2[ 0];/*ee0[ 0] = ee0[ 0] + ee2[ 0]; */ + ee0[-1] += ee2[-1];/*ee0[-1] = ee0[-1] + ee2[-1]; */ ee2[ 0] = k00_20 * A[0] - k01_21 * A[1]; ee2[-1] = k01_21 * A[0] + k00_20 * A[1]; A += 8; k00_20 = ee0[-2] - ee2[-2]; k01_21 = ee0[-3] - ee2[-3]; - ee0[-2] += ee2[-2];//ee0[-2] = ee0[-2] + ee2[-2]; - ee0[-3] += ee2[-3];//ee0[-3] = ee0[-3] + ee2[-3]; + ee0[-2] += ee2[-2];/*ee0[-2] = ee0[-2] + ee2[-2]; */ + ee0[-3] += ee2[-3];/*ee0[-3] = ee0[-3] + ee2[-3]; */ ee2[-2] = k00_20 * A[0] - k01_21 * A[1]; ee2[-3] = k01_21 * A[0] + k00_20 * A[1]; A += 8; k00_20 = ee0[-4] - ee2[-4]; k01_21 = ee0[-5] - ee2[-5]; - ee0[-4] += ee2[-4];//ee0[-4] = ee0[-4] + ee2[-4]; - ee0[-5] += ee2[-5];//ee0[-5] = ee0[-5] + ee2[-5]; + ee0[-4] += ee2[-4];/*ee0[-4] = ee0[-4] + ee2[-4]; */ + ee0[-5] += ee2[-5];/*ee0[-5] = ee0[-5] + ee2[-5]; */ ee2[-4] = k00_20 * A[0] - k01_21 * A[1]; ee2[-5] = k01_21 * A[0] + k00_20 * A[1]; A += 8; k00_20 = ee0[-6] - ee2[-6]; k01_21 = ee0[-7] - ee2[-7]; - ee0[-6] += ee2[-6];//ee0[-6] = ee0[-6] + ee2[-6]; - ee0[-7] += ee2[-7];//ee0[-7] = ee0[-7] + ee2[-7]; + ee0[-6] += ee2[-6];/*ee0[-6] = ee0[-6] + ee2[-6]; */ + ee0[-7] += ee2[-7];/*ee0[-7] = ee0[-7] + ee2[-7]; */ ee2[-6] = k00_20 * A[0] - k01_21 * A[1]; ee2[-7] = k01_21 * A[0] + k00_20 * A[1]; A += 8; @@ -2508,8 +2469,8 @@ static void imdct_step3_inner_r_loop(int lim, float *e, int d0, int k_off, float for (i=lim >> 2; i > 0; --i) { k00_20 = e0[-0] - e2[-0]; k01_21 = e0[-1] - e2[-1]; - e0[-0] += e2[-0];//e0[-0] = e0[-0] + e2[-0]; - e0[-1] += e2[-1];//e0[-1] = e0[-1] + e2[-1]; + e0[-0] += e2[-0];/*e0[-0] = e0[-0] + e2[-0]; */ + e0[-1] += e2[-1];/*e0[-1] = e0[-1] + e2[-1]; */ e2[-0] = (k00_20)*A[0] - (k01_21) * A[1]; e2[-1] = (k01_21)*A[0] + (k00_20) * A[1]; @@ -2517,8 +2478,8 @@ static void imdct_step3_inner_r_loop(int lim, float *e, int d0, int k_off, float k00_20 = e0[-2] - e2[-2]; k01_21 = e0[-3] - e2[-3]; - e0[-2] += e2[-2];//e0[-2] = e0[-2] + e2[-2]; - e0[-3] += e2[-3];//e0[-3] = e0[-3] + e2[-3]; + e0[-2] += e2[-2];/*e0[-2] = e0[-2] + e2[-2]; */ + e0[-3] += e2[-3];/*e0[-3] = e0[-3] + e2[-3]; */ e2[-2] = (k00_20)*A[0] - (k01_21) * A[1]; e2[-3] = (k01_21)*A[0] + (k00_20) * A[1]; @@ -2526,8 +2487,8 @@ static void imdct_step3_inner_r_loop(int lim, float *e, int d0, int k_off, float k00_20 = e0[-4] - e2[-4]; k01_21 = e0[-5] - e2[-5]; - e0[-4] += e2[-4];//e0[-4] = e0[-4] + e2[-4]; - e0[-5] += e2[-5];//e0[-5] = e0[-5] + e2[-5]; + e0[-4] += e2[-4];/*e0[-4] = e0[-4] + e2[-4]; */ + e0[-5] += e2[-5];/*e0[-5] = e0[-5] + e2[-5]; */ e2[-4] = (k00_20)*A[0] - (k01_21) * A[1]; e2[-5] = (k01_21)*A[0] + (k00_20) * A[1]; @@ -2535,8 +2496,8 @@ static void imdct_step3_inner_r_loop(int lim, float *e, int d0, int k_off, float k00_20 = e0[-6] - e2[-6]; k01_21 = e0[-7] - e2[-7]; - e0[-6] += e2[-6];//e0[-6] = e0[-6] + e2[-6]; - e0[-7] += e2[-7];//e0[-7] = e0[-7] + e2[-7]; + e0[-6] += e2[-6];/*e0[-6] = e0[-6] + e2[-6]; */ + e0[-7] += e2[-7];/*e0[-7] = e0[-7] + e2[-7]; */ e2[-6] = (k00_20)*A[0] - (k01_21) * A[1]; e2[-7] = (k01_21)*A[0] + (k00_20) * A[1]; @@ -2598,7 +2559,7 @@ static void imdct_step3_inner_s_loop(int n, float *e, int i_off, int k_off, floa } } -static __forceinline void iter_54(float *z) +static INLINE void iter_54(float *z) { float k00,k11,k22,k33; float y0,y1,y2,y3; @@ -2608,26 +2569,26 @@ static __forceinline void iter_54(float *z) y2 = z[-2] + z[-6]; k22 = z[-2] - z[-6]; - z[-0] = y0 + y2; // z0 + z4 + z2 + z6 - z[-2] = y0 - y2; // z0 + z4 - z2 - z6 + z[-0] = y0 + y2; /* z0 + z4 + z2 + z6 */ + z[-2] = y0 - y2; /* z0 + z4 - z2 - z6 */ - // done with y0,y2 + /* done with y0,y2 */ k33 = z[-3] - z[-7]; - z[-4] = k00 + k33; // z0 - z4 + z3 - z7 - z[-6] = k00 - k33; // z0 - z4 - z3 + z7 + z[-4] = k00 + k33; /* z0 - z4 + z3 - z7 */ + z[-6] = k00 - k33; /* z0 - z4 - z3 + z7 */ - // done with k33 + /* done with k33 */ k11 = z[-1] - z[-5]; y1 = z[-1] + z[-5]; y3 = z[-3] + z[-7]; - z[-1] = y1 + y3; // z1 + z5 + z3 + z7 - z[-3] = y1 - y3; // z1 + z5 - z3 - z7 - z[-5] = k11 - k22; // z1 - z5 + z2 - z6 - z[-7] = k11 + k22; // z1 - z5 - z2 + z6 + z[-1] = y1 + y3; /* z1 + z5 + z3 + z7 */ + z[-3] = y1 - y3; /* z1 + z5 - z3 - z7 */ + z[-5] = k11 - k22; /* z1 - z5 + z2 - z6 */ + z[-7] = k11 + k22; /* z1 - z5 - z2 + z6 */ } static void imdct_step3_inner_s_loop_ld654(int n, float *e, int i_off, float *A, int base_n) @@ -2654,14 +2615,14 @@ static void imdct_step3_inner_s_loop_ld654(int n, float *e, int i_off, float *A, z[-10] = (k00+k11) * A2; z[-11] = (k11-k00) * A2; - k00 = z[-12] - z[ -4]; // reverse to avoid a unary negation + k00 = z[-12] - z[ -4]; /* reverse to avoid a unary negation */ k11 = z[ -5] - z[-13]; z[ -4] = z[ -4] + z[-12]; z[ -5] = z[ -5] + z[-13]; z[-12] = k11; z[-13] = k00; - k00 = z[-14] - z[ -6]; // reverse to avoid a unary negation + k00 = z[-14] - z[ -6]; /* reverse to avoid a unary negation */ k11 = z[ -7] - z[-15]; z[ -6] = z[ -6] + z[-14]; z[ -7] = z[ -7] + z[-15]; @@ -2678,31 +2639,32 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) { int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l; int ld; - // @OPTIMIZE: reduce register pressure by using fewer variables? + /* @OPTIMIZE: reduce register pressure by using fewer variables? */ int save_point = temp_alloc_save(f); float *buf2 = (float *) temp_alloc(f, n2 * sizeof(*buf2)); float *u=NULL,*v=NULL; - // twiddle factors + /* twiddle factors */ float *A = f->A[blocktype]; - // IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio" - // See notes about bugs in that paper in less-optimal implementation 'inverse_mdct_old' after this function. + /* IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio" + * See notes about bugs in that paper in less-optimal implementation 'inverse_mdct_old' after this function. - // kernel from paper + * kernel from paper - // merged: - // copy and reflect spectral data - // step 0 + * merged: + * copy and reflect spectral data + * step 0 - // note that it turns out that the items added together during - // this step are, in fact, being added to themselves (as reflected - // by step 0). inexplicable inefficiency! this became obvious - // once I combined the passes. + * note that it turns out that the items added together during + * this step are, in fact, being added to themselves (as reflected + * by step 0). inexplicable inefficiency! this became obvious + * once I combined the passes. - // so there's a missing 'times 2' here (for adding X to itself). - // this propogates through linearly to the end, where the numbers - // are 1/2 too small, and need to be compensated for. + * so there's a missing 'times 2' here (for adding X to itself). + * this propogates through linearly to the end, where the numbers + * are 1/2 too small, and need to be compensated for. + */ { float *d,*e, *AA, *e_stop; @@ -2728,16 +2690,16 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) } } - // now we use symbolic names for these, so that we can - // possibly swap their meaning as we change which operations - // are in place + /* now we use symbolic names for these, so that we can + * possibly swap their meaning as we change which operations + * are in place */ u = buffer; v = buf2; - // step 2 (paper output is w, now u) - // this could be in place, but the data ends up in the wrong - // place... _somebody_'s got to swap it, so this is nominated + /* step 2 (paper output is w, now u) + * this could be in place, but the data ends up in the wrong + * place... _somebody_'s got to swap it, so this is nominated */ { float *AA = &A[n2-8]; float *d0,*d1, *e0, *e1; @@ -2774,21 +2736,21 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) } } - // step 3 - ld = ilog(n) - 1; // ilog is off-by-one from normal definitions + /* step 3 */ + ld = ilog(n) - 1; /* ilog is off-by-one from normal definitions */ - // optimized step 3: + /* optimized step 3: - // the original step3 loop can be nested r inside s or s inside r; - // it's written originally as s inside r, but this is dumb when r - // iterates many times, and s few. So I have two copies of it and - // switch between them halfway. + * the original step3 loop can be nested r inside s or s inside r; + * it's written originally as s inside r, but this is dumb when r + * iterates many times, and s few. So I have two copies of it and + * switch between them halfway. - // this is iteration 0 of step 3 + * this is iteration 0 of step 3 */ imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*0, -(n >> 3), A); imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*1, -(n >> 3), A); - // this is iteration 1 of step 3 + /* this is iteration 1 of step 3 */ imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*0, -(n >> 4), A, 16); imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*1, -(n >> 4), A, 16); imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*2, -(n >> 4), A, 16); @@ -2817,23 +2779,24 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) } } - // iterations with count: - // ld-6,-5,-4 all interleaved together - // the big win comes from getting rid of needless flops - // due to the constants on pass 5 & 4 being all 1 and 0; - // combining them to be simultaneous to improve cache made little difference + /* iterations with count: + * ld-6,-5,-4 all interleaved together + * the big win comes from getting rid of needless flops + * due to the constants on pass 5 & 4 being all 1 and 0; + * combining them to be simultaneous to improve cache made little difference + */ imdct_step3_inner_s_loop_ld654(n >> 5, u, n2-1, A, n); - // output is u + /* output is u - // step 4, 5, and 6 - // cannot be in-place because of step 5 + * step 4, 5, and 6 + * cannot be in-place because of step 5 */ { uint16 *bitrev = f->bit_reverse[blocktype]; - // weirdly, I'd have thought reading sequentially and writing - // erratically would have been better than vice-versa, but in - // fact that's not what my testing showed. (That is, with - // j = bitreverse(i), do you read i and write j, or read j and write i.) + /* weirdly, I'd have thought reading sequentially and writing + * erratically would have been better than vice-versa, but in + * fact that's not what my testing showed. (That is, with + * j = bitreverse(i), do you read i and write j, or read j and write i.) */ float *d0 = &v[n4-4]; float *d1 = &v[n2-4]; @@ -2857,14 +2820,14 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) bitrev += 2; } } - // (paper output is u, now v) + /* (paper output is u, now v) */ - // data must be in buf2 + /* data must be in buf2 */ assert(v == buf2); - // step 7 (paper output is v, now v) - // this is now in place + /* step 7 (paper output is v, now v) + * this is now in place */ { float *C = f->C[blocktype]; float *d, *e; @@ -2909,15 +2872,16 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) } } - // data must be in buf2 + /* data must be in buf2 - // step 8+decode (paper output is X, now buffer) - // this generates pairs of data a la 8 and pushes them directly through - // the decode kernel (pushing rather than pulling) to avoid having - // to make another pass later + * step 8+decode (paper output is X, now buffer) + * this generates pairs of data a la 8 and pushes them directly through + * the decode kernel (pushing rather than pulling) to avoid having + * to make another pass later - // this cannot POSSIBLY be in place, so we refer to the buffers directly + * this cannot POSSIBLY be in place, so we refer to the buffers directly + */ { float *d0,*d1,*d2,*d3; @@ -2975,134 +2939,6 @@ static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) temp_alloc_restore(f,save_point); } -#if 0 -// this is the original version of the above code, if you want to optimize it from scratch -void inverse_mdct_naive(float *buffer, int n) -{ - float s; - float A[1 << 12], B[1 << 12], C[1 << 11]; - int i,k,k2,k4, n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l; - int n3_4 = n - n4, ld; - // how can they claim this only uses N words?! - // oh, because they're only used sparsely, whoops - float u[1 << 13], X[1 << 13], v[1 << 13], w[1 << 13]; - // set up twiddle factors - - for (k=k2=0; k < n4; ++k,k2+=2) { - A[k2 ] = (float) cos(4*k*M_PI/n); - A[k2+1] = (float) -sin(4*k*M_PI/n); - B[k2 ] = (float) cos((k2+1)*M_PI/n/2); - B[k2+1] = (float) sin((k2+1)*M_PI/n/2); - } - for (k=k2=0; k < n8; ++k,k2+=2) { - C[k2 ] = (float) cos(2*(k2+1)*M_PI/n); - C[k2+1] = (float) -sin(2*(k2+1)*M_PI/n); - } - - // IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio" - // Note there are bugs in that pseudocode, presumably due to them attempting - // to rename the arrays nicely rather than representing the way their actual - // implementation bounces buffers back and forth. As a result, even in the - // "some formulars corrected" version, a direct implementation fails. These - // are noted below as "paper bug". - - // copy and reflect spectral data - for (k=0; k < n2; ++k) u[k] = buffer[k]; - for ( ; k < n ; ++k) u[k] = -buffer[n - k - 1]; - // kernel from paper - // step 1 - for (k=k2=k4=0; k < n4; k+=1, k2+=2, k4+=4) { - v[n-k4-1] = (u[k4] - u[n-k4-1]) * A[k2] - (u[k4+2] - u[n-k4-3])*A[k2+1]; - v[n-k4-3] = (u[k4] - u[n-k4-1]) * A[k2+1] + (u[k4+2] - u[n-k4-3])*A[k2]; - } - // step 2 - for (k=k4=0; k < n8; k+=1, k4+=4) { - w[n2+3+k4] = v[n2+3+k4] + v[k4+3]; - w[n2+1+k4] = v[n2+1+k4] + v[k4+1]; - w[k4+3] = (v[n2+3+k4] - v[k4+3])*A[n2-4-k4] - (v[n2+1+k4]-v[k4+1])*A[n2-3-k4]; - w[k4+1] = (v[n2+1+k4] - v[k4+1])*A[n2-4-k4] + (v[n2+3+k4]-v[k4+3])*A[n2-3-k4]; - } - // step 3 - ld = ilog(n) - 1; // ilog is off-by-one from normal definitions - for (l=0; l < ld-3; ++l) { - int k0 = n >> (l+2), k1 = 1 << (l+3); - int rlim = n >> (l+4), r4, r; - int s2lim = 1 << (l+2), s2; - for (r=r4=0; r < rlim; r4+=4,++r) { - for (s2=0; s2 < s2lim; s2+=2) { - u[n-1-k0*s2-r4] = w[n-1-k0*s2-r4] + w[n-1-k0*(s2+1)-r4]; - u[n-3-k0*s2-r4] = w[n-3-k0*s2-r4] + w[n-3-k0*(s2+1)-r4]; - u[n-1-k0*(s2+1)-r4] = (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1] - - (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1+1]; - u[n-3-k0*(s2+1)-r4] = (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1] - + (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1+1]; - } - } - if (l+1 < ld-3) { - // paper bug: ping-ponging of u&w here is omitted - memcpy(w, u, sizeof(u)); - } - } - - // step 4 - for (i=0; i < n8; ++i) { - int j = bit_reverse(i) >> (32-ld+3); - assert(j < n8); - if (i == j) { - // paper bug: original code probably swapped in place; if copying, - // need to directly copy in this case - int i8 = i << 3; - v[i8+1] = u[i8+1]; - v[i8+3] = u[i8+3]; - v[i8+5] = u[i8+5]; - v[i8+7] = u[i8+7]; - } else if (i < j) { - int i8 = i << 3, j8 = j << 3; - v[j8+1] = u[i8+1], v[i8+1] = u[j8 + 1]; - v[j8+3] = u[i8+3], v[i8+3] = u[j8 + 3]; - v[j8+5] = u[i8+5], v[i8+5] = u[j8 + 5]; - v[j8+7] = u[i8+7], v[i8+7] = u[j8 + 7]; - } - } - // step 5 - for (k=0; k < n2; ++k) { - w[k] = v[k*2+1]; - } - // step 6 - for (k=k2=k4=0; k < n8; ++k, k2 += 2, k4 += 4) { - u[n-1-k2] = w[k4]; - u[n-2-k2] = w[k4+1]; - u[n3_4 - 1 - k2] = w[k4+2]; - u[n3_4 - 2 - k2] = w[k4+3]; - } - // step 7 - for (k=k2=0; k < n8; ++k, k2 += 2) { - v[n2 + k2 ] = ( u[n2 + k2] + u[n-2-k2] + C[k2+1]*(u[n2+k2]-u[n-2-k2]) + C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2; - v[n-2 - k2] = ( u[n2 + k2] + u[n-2-k2] - C[k2+1]*(u[n2+k2]-u[n-2-k2]) - C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2; - v[n2+1+ k2] = ( u[n2+1+k2] - u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2; - v[n-1 - k2] = (-u[n2+1+k2] + u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2; - } - // step 8 - for (k=k2=0; k < n4; ++k,k2 += 2) { - X[k] = v[k2+n2]*B[k2 ] + v[k2+1+n2]*B[k2+1]; - X[n2-1-k] = v[k2+n2]*B[k2+1] - v[k2+1+n2]*B[k2 ]; - } - - // decode kernel to output - // determined the following value experimentally - // (by first figuring out what made inverse_mdct_slow work); then matching that here - // (probably vorbis encoder premultiplies by n or n/2, to save it on the decoder?) - s = 0.5; // theoretically would be n4 - - // [[[ note! the s value of 0.5 is compensated for by the B[] in the current code, - // so it needs to use the "old" B values to behave correctly, or else - // set s to 1.0 ]]] - for (i=0; i < n4 ; ++i) buffer[i] = s * X[i+n4]; - for ( ; i < n3_4; ++i) buffer[i] = -s * X[n3_4 - i - 1]; - for ( ; i < n ; ++i) buffer[i] = -s * X[i - n3_4]; -} -#endif - static float *get_window(vorb *f, int len) { len <<= 1; @@ -3143,7 +2979,7 @@ static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *f } } if (lx < n2) - // optimization of: draw_line(target, lx,ly, n,ly, n2); + /* optimization of: draw_line(target, lx,ly, n,ly, n2); */ for (j=lx; j < n2; ++j) LINE_OP(target[j], inverse_db_table[ly]); } @@ -3160,7 +2996,7 @@ static int vorbis_decode_initial(vorb *f, int *p_left_start, int *p_left_end, in if (f->eof) return FALSE; if (!maybe_start_packet(f)) return FALSE; - // check packet type + /* check packet type */ if (get_bits(f,1) != 0) { if (IS_PUSH_MODE(f)) return error(f,VORBIS_bad_packet_type); @@ -3185,7 +3021,7 @@ static int vorbis_decode_initial(vorb *f, int *p_left_start, int *p_left_end, in n = f->blocksize_0; } -// WINDOWING +/* WINDOWING */ window_center = n >> 1; if (m->blockflag && !prev) { @@ -3212,12 +3048,12 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, int zero_channel[256]; int really_zero_channel[256]; -// WINDOWING +/* WINDOWING */ n = f->blocksize[m->blockflag]; map = &f->mapping[m->mapping]; -// FLOORS +/* FLOORS */ n2 = n >> 1; stb_prof(1); @@ -3260,13 +3096,15 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, finalY[offset++] = 0; } } - if (f->valid_bits == INVALID_BITS) goto error; // behavior according to spec + if (f->valid_bits == INVALID_BITS) goto error; /* behavior according to spec */ step2_flag[0] = step2_flag[1] = 1; for (j=2; j < g->values; ++j) { int low, high, pred, highroom, lowroom, room, val; low = g->neighbors[j][0]; high = g->neighbors[j][1]; - //neighbors(g->Xlist, j, &low, &high); +#if 0 + neighbors(g->Xlist, j, &low, &high); +#endif pred = predict_point(g->Xlist[j], g->Xlist[low], g->Xlist[high], finalY[low], finalY[high]); val = finalY[j]; highroom = range - pred; @@ -3297,7 +3135,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, #ifdef STB_VORBIS_NO_DEFER_FLOOR do_floor(f, map, i, n, f->floor_buffers[i], finalY, step2_flag); #else - // defer final floor computation until _after_ residue + /* defer final floor computation until _after_ residue */ for (j=0; j < g->values; ++j) { if (!step2_flag[j]) finalY[j] = -1; @@ -3307,25 +3145,25 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, error: zero_channel[i] = TRUE; } - // So we just defer everything else to later + /* So we just defer everything else to later */ - // at this point we've decoded the floor into buffer + /* at this point we've decoded the floor into buffer */ } } stb_prof(0); - // at this point we've decoded all floors + /* at this point we've decoded all floors */ if (f->alloc.alloc_buffer) assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset); - // re-enable coupled channels if necessary + /* re-enable coupled channels if necessary */ memcpy(really_zero_channel, zero_channel, sizeof(really_zero_channel[0]) * f->channels); for (i=0; i < map->coupling_steps; ++i) if (!zero_channel[map->chan[i].magnitude] || !zero_channel[map->chan[i].angle]) { zero_channel[map->chan[i].magnitude] = zero_channel[map->chan[i].angle] = FALSE; } -// RESIDUE DECODE +/* RESIDUE DECODE */ for (i=0; i < map->submaps; ++i) { float *residue_buffers[STB_VORBIS_MAX_CHANNELS]; int r; @@ -3350,7 +3188,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, if (f->alloc.alloc_buffer) assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset); -// INVERSE COUPLING +/* INVERSE COUPLING */ stb_prof(14); for (i = map->coupling_steps-1; i >= 0; --i) { int n2 = n >> 1; @@ -3373,7 +3211,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, } } - // finish decoding the floors + /* finish decoding the floors */ #ifndef STB_VORBIS_NO_DEFER_FLOOR stb_prof(15); for (i=0; i < f->channels; ++i) { @@ -3394,24 +3232,24 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, } #endif -// INVERSE MDCT +/* INVERSE MDCT */ stb_prof(16); for (i=0; i < f->channels; ++i) inverse_mdct(f->channel_buffers[i], n, f, m->blockflag); stb_prof(0); - // this shouldn't be necessary, unless we exited on an error - // and want to flush to get to the next packet + /* this shouldn't be necessary, unless we exited on an error + * and want to flush to get to the next packet */ flush_packet(f); if (f->first_decode) { - // assume we start so first non-discarded sample is sample 0 - // this isn't to spec, but spec would require us to read ahead - // and decode the size of all current frames--could be done, - // but presumably it's not a commonly used feature - f->current_loc = -n2; // start of first frame is positioned for discard - // we might have to discard samples "from" the next frame too, - // if we're lapping a large block then a small at the start? + /* assume we start so first non-discarded sample is sample 0 + * this isn't to spec, but spec would require us to read ahead + * and decode the size of all current frames--could be done, + * but presumably it's not a commonly used feature */ + f->current_loc = -n2; /* start of first frame is positioned for discard */ + /* we might have to discard samples "from" the next frame too, + * if we're lapping a large block then a small at the start? */ f->discard_samples_deferred = n - right_end; f->current_loc_valid = TRUE; f->first_decode = FALSE; @@ -3420,23 +3258,23 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, *p_left = left_start; f->discard_samples_deferred = 0; } else if (f->previous_length == 0 && f->current_loc_valid) { - // we're recovering from a seek... that means we're going to discard - // the samples from this packet even though we know our position from - // the last page header, so we need to update the position based on - // the discarded samples here - // but wait, the code below is going to add this in itself even - // on a discard, so we don't need to do it here... + /* we're recovering from a seek... that means we're going to discard + * the samples from this packet even though we know our position from + * the last page header, so we need to update the position based on + * the discarded samples here + * but wait, the code below is going to add this in itself even + * on a discard, so we don't need to do it here... */ } - // check if we have ogg information about the sample # for this packet + /* check if we have ogg information about the sample # for this packet */ if (f->last_seg_which == f->end_seg_with_known_loc) { - // if we have a valid current loc, and this is final: + /* if we have a valid current loc, and this is final: */ if (f->current_loc_valid && (f->page_flag & PAGEFLAG_last_page)) { uint32 current_end = f->known_loc_for_packet - (n-right_end); - // then let's infer the size of the (probably) short final frame + /* then let's infer the size of the (probably) short final frame */ if (current_end < f->current_loc + right_end) { if (current_end < f->current_loc) { - // negative truncation, that's impossible! + /* negative truncation, that's impossible! */ *len = 0; } else { *len = current_end - f->current_loc; @@ -3446,10 +3284,10 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, return TRUE; } } - // otherwise, just set our sample loc - // guess that the ogg granule pos refers to the _middle_ of the - // last frame? - // set f->current_loc to the position of left_start + /* otherwise, just set our sample loc + * guess that the ogg granule pos refers to the _middle_ of the + * last frame? + * set f->current_loc to the position of left_start */ f->current_loc = f->known_loc_for_packet - (n2-left_start); f->current_loc_valid = TRUE; } @@ -3458,7 +3296,7 @@ static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, if (f->alloc.alloc_buffer) assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset); - *len = right_end; // ignore samples after the window goes to 0 + *len = right_end; /* ignore samples after the window goes to 0 */ return TRUE; } @@ -3472,15 +3310,15 @@ 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) { int prev,i,j; - // we use right&left (the start of the right- and left-window sin()-regions) - // to determine how much to return, rather than inferring from the rules - // (same result, clearer code); 'left' indicates where our sin() window - // starts, therefore where the previous window's right edge starts, and - // therefore where to start mixing from the previous buffer. 'right' - // indicates where our sin() ending-window starts, therefore that's where - // we start saving, and where our returned-data ends. + /* we use right&left (the start of the right- and left-window sin()-regions) + * to determine how much to return, rather than inferring from the rules + * (same result, clearer code); 'left' indicates where our sin() window + * starts, therefore where the previous window's right edge starts, and + * therefore where to start mixing from the previous buffer. 'right' + * indicates where our sin() ending-window starts, therefore that's where + * we start saving, and where our returned-data ends. - // mixin from previous window + * mixin from previous window */ if (f->previous_length) { int i,j, n = f->previous_length; float *w = get_window(f, n); @@ -3494,26 +3332,26 @@ static int vorbis_finish_frame(stb_vorbis *f, int len, int left, int right) prev = f->previous_length; - // last half of this data becomes previous window + /* last half of this data becomes previous window */ f->previous_length = len - right; - // @OPTIMIZE: could avoid this copy by double-buffering the - // output (flipping previous_window with channel_buffers), but - // then previous_window would have to be 2x as large, and - // channel_buffers couldn't be temp mem (although they're NOT - // currently temp mem, they could be (unless we want to level - // performance by spreading out the computation)) + /* @OPTIMIZE: could avoid this copy by double-buffering the + * output (flipping previous_window with channel_buffers), but + * then previous_window would have to be 2x as large, and + * channel_buffers couldn't be temp mem (although they're NOT + * currently temp mem, they could be (unless we want to level + * performance by spreading out the computation)) */ for (i=0; i < f->channels; ++i) for (j=0; right+j < len; ++j) f->previous_window[i][j] = f->channel_buffers[i][right+j]; if (!prev) - // there was no previous packet, so this data isn't valid... - // this isn't entirely true, only the would-have-overlapped data - // isn't valid, but this seems to be what the spec requires + /* there was no previous packet, so this data isn't valid... + * this isn't entirely true, only the would-have-overlapped data + * isn't valid, but this seems to be what the spec requires */ return 0; - // truncate a short frame + /* truncate a short frame */ if (len < right) right = len; f->samples_output += right-left; @@ -3531,28 +3369,29 @@ static void vorbis_pump_first_frame(stb_vorbis *f) #ifndef STB_VORBIS_NO_PUSHDATA_API static int is_whole_packet_present(stb_vorbis *f, int end_page) { - // make sure that we have the packet available before continuing... - // this requires a full ogg parse, but we know we can fetch from f->stream + /* make sure that we have the packet available before continuing... + * this requires a full ogg parse, but we know we can fetch from f->stream - // instead of coding this out explicitly, we could save the current read state, - // read the next packet with get8() until end-of-packet, check f->eof, then - // reset the state? but that would be slower, esp. since we'd have over 256 bytes - // of state to restore (primarily the page segment table) + * instead of coding this out explicitly, we could save the current read state, + * read the next packet with get8() until end-of-packet, check f->eof, then + * reset the state? but that would be slower, esp. since we'd have over 256 bytes + * of state to restore (primarily the page segment table) + */ int s = f->next_seg, first = TRUE; uint8 *p = f->stream; - if (s != -1) { // if we're not starting the packet with a 'continue on next page' flag + if (s != -1) { /* if we're not starting the packet with a 'continue on next page' flag */ for (; s < f->segment_count; ++s) { p += f->segments[s]; - if (f->segments[s] < 255) // stop at first short segment + if (f->segments[s] < 255) /* stop at first short segment */ break; } - // either this continues, or it ends it... + /* either this continues, or it ends it... */ if (end_page) if (s < f->segment_count-1) return error(f, VORBIS_invalid_stream); if (s == f->segment_count) - s = -1; // set 'crosses page' flag + s = -1; /* set 'crosses page' flag */ if (p > f->stream_end) return error(f, VORBIS_need_more_data); first = FALSE; } @@ -3560,23 +3399,23 @@ static int is_whole_packet_present(stb_vorbis *f, int end_page) uint8 *q; int n; - // check that we have the page header ready + /* check that we have the page header ready */ if (p + 26 >= f->stream_end) return error(f, VORBIS_need_more_data); - // validate the page + /* validate the page */ if (memcmp(p, ogg_page_header, 4)) return error(f, VORBIS_invalid_stream); if (p[4] != 0) return error(f, VORBIS_invalid_stream); - if (first) { // the first segment must NOT have 'continued_packet', later ones MUST + if (first) { /* the first segment must NOT have 'continued_packet', later ones MUST */ if (f->previous_length) if ((p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream); - // if no previous length, we're resynching, so we can come in on a continued-packet, - // which we'll just drop + /* if no previous length, we're resynching, so we can come in on a continued-packet, + * which we'll just drop */ } else { if (!(p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream); } - n = p[26]; // segment counts - q = p+27; // q points to segment table - p = q + n; // advance past header - // make sure we've read the segment table + n = p[26]; /* segment counts */ + q = p+27; /* q points to segment table */ + p = q + n; /* advance past header */ + /* make sure we've read the segment table */ if (p > f->stream_end) return error(f, VORBIS_need_more_data); for (s=0; s < n; ++s) { p += q[s]; @@ -3586,13 +3425,13 @@ static int is_whole_packet_present(stb_vorbis *f, int end_page) if (end_page) if (s < n-1) return error(f, VORBIS_invalid_stream); if (s == n) - s = -1; // set 'crosses page' flag + s = -1; /* set 'crosses page' flag */ if (p > f->stream_end) return error(f, VORBIS_need_more_data); first = FALSE; } return TRUE; } -#endif // !STB_VORBIS_NO_PUSHDATA_API +#endif /* !STB_VORBIS_NO_PUSHDATA_API */ static int start_decoder(vorb *f) { @@ -3600,29 +3439,29 @@ static int start_decoder(vorb *f) int len,i,j,k, max_submaps = 0; int longest_floorlist=0; - // first page, first packet + /* first page, first packet */ if (!start_page(f)) return FALSE; - // validate page flag + /* validate page flag */ if (!(f->page_flag & PAGEFLAG_first_page)) return error(f, VORBIS_invalid_first_page); if (f->page_flag & PAGEFLAG_last_page) return error(f, VORBIS_invalid_first_page); if (f->page_flag & PAGEFLAG_continued_packet) return error(f, VORBIS_invalid_first_page); - // check for expected packet length + /* check for expected packet length */ if (f->segment_count != 1) return error(f, VORBIS_invalid_first_page); if (f->segments[0] != 30) return error(f, VORBIS_invalid_first_page); - // read packet - // check packet header + /* read packet + * check packet header */ if (get8(f) != VORBIS_packet_id) return error(f, VORBIS_invalid_first_page); if (!getn(f, header, 6)) return error(f, VORBIS_unexpected_eof); if (!vorbis_validate(header)) return error(f, VORBIS_invalid_first_page); - // vorbis_version + /* vorbis_version */ if (get32(f) != 0) return error(f, VORBIS_invalid_first_page); f->channels = get8(f); if (!f->channels) return error(f, VORBIS_invalid_first_page); if (f->channels > STB_VORBIS_MAX_CHANNELS) return error(f, VORBIS_too_many_channels); f->sample_rate = get32(f); if (!f->sample_rate) return error(f, VORBIS_invalid_first_page); - get32(f); // bitrate_maximum - get32(f); // bitrate_nominal - get32(f); // bitrate_minimum + get32(f); /* bitrate_maximum */ + get32(f); /* bitrate_nominal */ + get32(f); /* bitrate_minimum */ x = get8(f); { int log0,log1; log0 = x & 15; @@ -3634,11 +3473,11 @@ static int start_decoder(vorb *f) if (log0 > log1) return error(f, VORBIS_invalid_setup); } - // framing_flag + /* framing_flag */ x = get8(f); if (!(x & 1)) return error(f, VORBIS_invalid_first_page); - // second packet! + /* second packet! */ if (!start_page(f)) return FALSE; if (!start_packet(f)) return FALSE; @@ -3648,13 +3487,13 @@ static int start_decoder(vorb *f) f->bytes_in_seg = 0; } while (len); - // third packet! + /* third packet! */ if (!start_packet(f)) return FALSE; #ifndef STB_VORBIS_NO_PUSHDATA_API if (IS_PUSH_MODE(f)) { if (!is_whole_packet_present(f, TRUE)) { - // convert error in ogg header to write type + /* convert error in ogg header to write type */ if (f->error == VORBIS_invalid_stream) f->error = VORBIS_invalid_setup; return FALSE; @@ -3662,13 +3501,13 @@ static int start_decoder(vorb *f) } #endif - crc32_init(); // always init it, to avoid multithread race conditions + crc32_init(); /* always init it, to avoid multithread race conditions */ if (get8_packet(f) != VORBIS_packet_setup) return error(f, VORBIS_invalid_setup); for (i=0; i < 6; ++i) header[i] = get8_packet(f); if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup); - // codebooks + /* codebooks */ f->codebook_count = get_bits(f,8) + 1; f->codebooks = (Codebook *) setup_malloc(f, sizeof(*f->codebooks) * f->codebook_count); @@ -3722,18 +3561,18 @@ static int start_decoder(vorb *f) } if (c->sparse && total >= c->entries >> 2) { - // convert sparse items to non-sparse! + /* convert sparse items to non-sparse! */ if (c->entries > (int) f->setup_temp_memory_required) f->setup_temp_memory_required = c->entries; c->codeword_lengths = (uint8 *) setup_malloc(f, c->entries); memcpy(c->codeword_lengths, lengths, c->entries); - setup_temp_free(f, lengths, c->entries); // note this is only safe if there have been no intervening temp mallocs! + setup_temp_free(f, lengths, c->entries); /* note this is only safe if there have been no intervening temp mallocs! */ lengths = c->codeword_lengths; c->sparse = 0; } - // compute the size of the sorted tables + /* compute the size of the sorted tables */ if (c->sparse) { sorted_count = total; } else { @@ -3772,10 +3611,10 @@ static int start_decoder(vorb *f) } if (c->sorted_entries) { - // allocate an extra slot for sentinels + /* allocate an extra slot for sentinels */ c->sorted_codewords = (uint32 *) setup_malloc(f, sizeof(*c->sorted_codewords) * (c->sorted_entries+1)); - // allocate an extra slot at the front so that c->sorted_values[-1] is defined - // so that we can catch that case without an extra if + /* allocate an extra slot at the front so that c->sorted_values[-1] is defined + * so that we can catch that case without an extra if */ c->sorted_values = ( int *) setup_malloc(f, sizeof(*c->sorted_values ) * (c->sorted_entries+1)); if (c->sorted_values) { ++c->sorted_values; c->sorted_values[-1] = -1; } compute_sorted_huffman(c, lengths, values); @@ -3814,7 +3653,7 @@ static int start_decoder(vorb *f) #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK if (c->lookup_type == 1) { int len, sparse = c->sparse; - // pre-expand the lookup1-style multiplicands, to avoid a divide in the inner loop + /* pre-expand the lookup1-style multiplicands, to avoid a divide in the inner loop */ if (sparse) { if (c->sorted_entries == 0) goto skip; c->multiplicands = (stb_vorbis_codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->sorted_entries * c->dimensions); @@ -3831,11 +3670,11 @@ static int start_decoder(vorb *f) mults[off]; #else mults[off]*c->delta_value + c->minimum_value; - // in this case (and this case only) we could pre-expand c->sequence_p, - // and throw away the decode logic for it; have to ALSO do - // it in the case below, but it can only be done if - // STB_VORBIS_CODEBOOK_FLOATS - // !STB_VORBIS_DIVIDES_IN_CODEBOOK + /* in this case (and this case only) we could pre-expand c->sequence_p, + * and throw away the decode logic for it; have to ALSO do + * it in the case below, but it can only be done if + * STB_VORBIS_CODEBOOK_FLOATS + * !STB_VORBIS_DIVIDES_IN_CODEBOOK */ #endif div *= c->lookup_values; } @@ -3869,7 +3708,7 @@ static int start_decoder(vorb *f) } } - // time domain transfers (notused) + /* time domain transfers (notused) */ x = get_bits(f, 6) + 1; for (i=0; i < x; ++i) { @@ -3877,7 +3716,7 @@ static int start_decoder(vorb *f) if (z != 0) return error(f, VORBIS_invalid_setup); } - // Floors + /* Floors */ f->floor_count = get_bits(f, 6)+1; f->floor_config = (Floor *) setup_malloc(f, f->floor_count * sizeof(*f->floor_config)); for (i=0; i < f->floor_count; ++i) { @@ -3928,7 +3767,7 @@ static int start_decoder(vorb *f) ++g->values; } } - // precompute the sorting + /* precompute the sorting */ for (j=0; j < g->values; ++j) { p[j].x = g->Xlist[j]; p[j].y = j; @@ -3936,7 +3775,7 @@ static int start_decoder(vorb *f) qsort(p, g->values, sizeof(p[0]), point_compare); for (j=0; j < g->values; ++j) g->sorted_order[j] = (uint8) p[j].y; - // precompute the neighbors + /* precompute the neighbors */ for (j=2; j < g->values; ++j) { int low = 0; @@ -3951,7 +3790,7 @@ static int start_decoder(vorb *f) } } - // Residue + /* Residue */ f->residue_count = get_bits(f, 6)+1; f->residue_config = (Residue *) setup_malloc(f, f->residue_count * sizeof(*f->residue_config)); for (i=0; i < f->residue_count; ++i) { @@ -3982,8 +3821,8 @@ static int start_decoder(vorb *f) } } } - // precompute the classifications[] array to avoid inner-loop mod/divide - // call it 'classdata' since we already have r->classifications + /* precompute the classifications[] array to avoid inner-loop mod/divide + * call it 'classdata' since we already have r->classifications */ r->classdata = (uint8 **) setup_malloc(f, sizeof(*r->classdata) * f->codebooks[r->classbook].entries); if (!r->classdata) return error(f, VORBIS_outofmem); memset(r->classdata, 0, sizeof(*r->classdata) * f->codebooks[r->classbook].entries); @@ -4023,7 +3862,7 @@ static int start_decoder(vorb *f) } else m->coupling_steps = 0; - // reserved field + /* reserved field */ if (get_bits(f,2)) return error(f, VORBIS_invalid_setup); if (m->submaps > 1) { for (j=0; j < f->channels; ++j) { @@ -4031,12 +3870,12 @@ static int start_decoder(vorb *f) if (m->chan[j].mux >= m->submaps) return error(f, VORBIS_invalid_setup); } } else - // @SPECIFICATION: this case is missing from the spec + /* @SPECIFICATION: this case is missing from the spec */ for (j=0; j < f->channels; ++j) m->chan[j].mux = 0; for (j=0; j < m->submaps; ++j) { - get_bits(f,8); // discard + get_bits(f,8); /* discard */ m->submap_floor[j] = get_bits(f,8); m->submap_residue[j] = get_bits(f,8); if (m->submap_floor[j] >= f->floor_count) return error(f, VORBIS_invalid_setup); @@ -4044,7 +3883,7 @@ static int start_decoder(vorb *f) } } - // Modes + /* Modes */ f->mode_count = get_bits(f, 6)+1; for (i=0; i < f->mode_count; ++i) { Mode *m = f->mode_config+i; @@ -4082,9 +3921,9 @@ static int start_decoder(vorb *f) integer_divide_table[i][j] = i / j; #endif - // compute how much temporary memory is needed + /* compute how much temporary memory is needed */ - // 1. + /* 1. */ { uint32 imdct_mem = (f->blocksize_1 * sizeof(float) >> 1); uint32 classify_mem; @@ -4111,7 +3950,7 @@ static int start_decoder(vorb *f) if (f->alloc.alloc_buffer) { assert(f->temp_offset == f->alloc.alloc_buffer_length_in_bytes); - // check if there's enough temp memory so we don't error later + /* check if there's enough temp memory so we don't error later */ if (f->setup_offset + sizeof(*f) + f->temp_memory_required > (unsigned) f->temp_offset) return error(f, VORBIS_outofmem); } @@ -4141,7 +3980,7 @@ static void vorbis_deinit(stb_vorbis *p) setup_free(p, c->multiplicands); setup_free(p, c->codewords); setup_free(p, c->sorted_codewords); - // c->sorted_values[-1] is the first entry in the array + /* c->sorted_values[-1] is the first entry in the array */ setup_free(p, c->sorted_values ? c->sorted_values-1 : NULL); } setup_free(p, p->codebooks); @@ -4180,7 +4019,7 @@ void stb_vorbis_close(stb_vorbis *p) static void vorbis_init(stb_vorbis *p, stb_vorbis_alloc *z) { - memset(p, 0, sizeof(*p)); // NULL out all malloc'd pointers to start + memset(p, 0, sizeof(*p)); /* NULL out all malloc'd pointers to start */ if (z) { p->alloc = *z; p->alloc.alloc_buffer_length_in_bytes = (p->alloc.alloc_buffer_length_in_bytes+3) & ~3; @@ -4250,42 +4089,42 @@ static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len) for (i=0; i < f->page_crc_tests; ++i) f->scan[i].bytes_done = 0; - // if we have room for more scans, search for them first, because - // they may cause us to stop early if their header is incomplete + /* if we have room for more scans, search for them first, because + * they may cause us to stop early if their header is incomplete */ if (f->page_crc_tests < STB_VORBIS_PUSHDATA_CRC_COUNT) { if (data_len < 4) return 0; - data_len -= 3; // need to look for 4-byte sequence, so don't miss - // one that straddles a boundary + data_len -= 3; /* need to look for 4-byte sequence, so don't miss + * one that straddles a boundary */ for (i=0; i < data_len; ++i) { if (data[i] == 0x4f) { if (0==memcmp(data+i, ogg_page_header, 4)) { int j,len; uint32 crc; - // make sure we have the whole page header + /* make sure we have the whole page header */ if (i+26 >= data_len || i+27+data[i+26] >= data_len) { - // only read up to this page start, so hopefully we'll - // have the whole page header start next time + /* only read up to this page start, so hopefully we'll + * have the whole page header start next time */ data_len = i; break; } - // ok, we have it all; compute the length of the page + /* ok, we have it all; compute the length of the page */ len = 27 + data[i+26]; for (j=0; j < data[i+26]; ++j) len += data[i+27+j]; - // scan everything up to the embedded crc (which we must 0) + /* scan everything up to the embedded crc (which we must 0) */ crc = 0; for (j=0; j < 22; ++j) crc = crc32_update(crc, data[i+j]); - // now process 4 0-bytes + /* now process 4 0-bytes */ for ( ; j < 26; ++j) crc = crc32_update(crc, 0); - // len is the total number of bytes we need to scan + /* len is the total number of bytes we need to scan */ n = f->page_crc_tests++; f->scan[n].bytes_left = len-j; f->scan[n].crc_so_far = crc; f->scan[n].goal_crc = data[i+22] + (data[i+23] << 8) + (data[i+24]<<16) + (data[i+25]<<24); - // if the last frame on a page is continued to the next, then - // we can't recover the sample_loc immediately + /* if the last frame on a page is continued to the next, then + * we can't recover the sample_loc immediately */ if (data[i+27+data[i+26]-1] == 255) f->scan[n].sample_loc = ~0; else @@ -4293,7 +4132,7 @@ static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len) f->scan[n].bytes_done = i+j; if (f->page_crc_tests == STB_VORBIS_PUSHDATA_CRC_COUNT) break; - // keep going if we still have room for more + /* keep going if we still have room for more */ } } } @@ -4305,26 +4144,26 @@ static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len) int n = f->scan[i].bytes_done; int m = f->scan[i].bytes_left; if (m > data_len - n) m = data_len - n; - // m is the bytes to scan in the current chunk + /* m is the bytes to scan in the current chunk */ crc = f->scan[i].crc_so_far; for (j=0; j < m; ++j) crc = crc32_update(crc, data[n+j]); f->scan[i].bytes_left -= m; f->scan[i].crc_so_far = crc; if (f->scan[i].bytes_left == 0) { - // does it match? + /* does it match? */ if (f->scan[i].crc_so_far == f->scan[i].goal_crc) { - // Houston, we have page - data_len = n+m; // consumption amount is wherever that scan ended - f->page_crc_tests = -1; // drop out of page scan mode - f->previous_length = 0; // decode-but-don't-output one frame - f->next_seg = -1; // start a new page - f->current_loc = f->scan[i].sample_loc; // set the current sample location - // to the amount we'd have decoded had we decoded this page + /* Houston, we have page */ + data_len = n+m; /* consumption amount is wherever that scan ended */ + f->page_crc_tests = -1; /* drop out of page scan mode */ + f->previous_length = 0; /* decode-but-don't-output one frame */ + f->next_seg = -1; /* start a new page */ + f->current_loc = f->scan[i].sample_loc; /* set the current sample location */ + /* to the amount we'd have decoded had we decoded this page */ f->current_loc_valid = f->current_loc != ~0U; return data_len; } - // delete entry + /* delete entry */ f->scan[i] = f->scan[--f->page_crc_tests]; } else { ++i; @@ -4334,13 +4173,13 @@ static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len) return data_len; } -// return value: number of bytes we used +/* return value: number of bytes we used */ int stb_vorbis_decode_frame_pushdata( - stb_vorbis *f, // the file we're decoding - uint8 *data, int data_len, // the memory available for decoding - 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 + stb_vorbis *f, /* the file we're decoding */ + uint8 *data, int data_len, /* the memory available for decoding */ + 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 i; @@ -4357,17 +4196,17 @@ int stb_vorbis_decode_frame_pushdata( f->stream_end = data + data_len; f->error = VORBIS__no_error; - // check that we have the entire packet in memory + /* check that we have the entire packet in memory */ if (!is_whole_packet_present(f, FALSE)) { *samples = 0; return 0; } if (!vorbis_decode_packet(f, &len, &left, &right)) { - // save the actual error we encountered + /* save the actual error we encountered */ enum STBVorbisError error = f->error; if (error == VORBIS_bad_packet_type) { - // flush and resynch + /* flush and resynch */ f->error = VORBIS__no_error; while (get8_packet(f) != EOP) if (f->eof) break; @@ -4376,8 +4215,8 @@ int stb_vorbis_decode_frame_pushdata( } if (error == VORBIS_continued_packet_flag_invalid) { if (f->previous_length == 0) { - // we may be resynching, in which case it's ok to hit one - // of these; just discard the packet + /* we may be resynching, in which case it's ok to hit one + * of these; just discard the packet */ f->error = VORBIS__no_error; while (get8_packet(f) != EOP) if (f->eof) break; @@ -4385,16 +4224,16 @@ int stb_vorbis_decode_frame_pushdata( return f->stream - data; } } - // if we get an error while parsing, what to do? - // well, it DEFINITELY won't work to continue from where we are! + /* if we get an error while parsing, what to do? + * well, it DEFINITELY won't work to continue from where we are! */ stb_vorbis_flush_pushdata(f); - // restore the error that actually made us bail + /* restore the error that actually made us bail */ f->error = error; *samples = 0; return 1; } - // success! + /* success! */ len = vorbis_finish_frame(f, len, left, right); for (i=0; i < f->channels; ++i) f->outputs[i] = f->channel_buffers[i] + left; @@ -4406,8 +4245,8 @@ int stb_vorbis_decode_frame_pushdata( } stb_vorbis *stb_vorbis_open_pushdata( - unsigned char *data, int data_len, // the memory available for decoding - int *data_used, // only defined if result is not NULL + unsigned char *data, int data_len, /* the memory available for decoding */ + int *data_used, /* only defined if result is not NULL */ int *error, stb_vorbis_alloc *alloc) { stb_vorbis *f, p; @@ -4433,7 +4272,7 @@ stb_vorbis *stb_vorbis_open_pushdata( return NULL; } } -#endif // STB_VORBIS_NO_PUSHDATA_API +#endif /* STB_VORBIS_NO_PUSHDATA_API */ unsigned int stb_vorbis_get_file_offset(stb_vorbis *f) { @@ -4447,9 +4286,7 @@ unsigned int stb_vorbis_get_file_offset(stb_vorbis *f) } #ifndef STB_VORBIS_NO_PULLDATA_API -// -// DATA-PULLING API -// +/* DATA-PULLING API */ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last) { @@ -4457,13 +4294,13 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last) int n; if (f->eof) return 0; n = get8(f); - if (n == 0x4f) { // page header + if (n == 0x4f) { /* page header */ unsigned int retry_loc = stb_vorbis_get_file_offset(f); int i; - // check if we're off the end of a file_section stream + /* check if we're off the end of a file_section stream */ if (retry_loc - 25 > f->stream_len) return 0; - // check the rest of the header + /* check the rest of the header */ for (i=1; i < 4; ++i) if (get8(f) != ogg_page_header[i]) break; @@ -4492,16 +4329,16 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last) if (len && f->eof) return 0; for (i=0; i < len; ++i) crc = crc32_update(crc, get8(f)); - // finished parsing probable page + /* finished parsing probable page */ if (crc == goal) { - // we could now check that it's either got the last - // page flag set, OR it's followed by the capture - // pattern, but I guess TECHNICALLY you could have - // a file with garbage between each ogg page and recover - // from it automatically? So even though that paranoia - // might decrease the chance of an invalid decode by - // another 2^32, not worth it since it would hose those - // invalid-but-useful files? + /* we could now check that it's either got the last + * page flag set, OR it's followed by the capture + * pattern, but I guess TECHNICALLY you could have + * a file with garbage between each ogg page and recover + * from it automatically? So even though that paranoia + * might decrease the chance of an invalid decode by + * another 2^32, not worth it since it would hose those + * invalid-but-useful files? */ if (end) *end = stb_vorbis_get_file_offset(f); if (last) { @@ -4515,29 +4352,31 @@ static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last) } } invalid: - // not a valid page, so rewind and look for next one + /* not a valid page, so rewind and look for next one */ set_file_offset(f, retry_loc); } } } -// seek is implemented with 'interpolation search'--this is like -// binary search, but we use the data values to estimate the likely -// location of the data item (plus a bit of a bias so when the -// estimation is wrong we don't waste overly much time) +/* seek is implemented with 'interpolation search'--this is like + * binary search, but we use the data values to estimate the likely + * location of the data item (plus a bit of a bias so when the + * estimation is wrong we don't waste overly much time) + */ #define SAMPLE_unknown 0xffffffff -// ogg vorbis, in its insane infinite wisdom, only provides -// information about the sample at the END of the page. -// therefore we COULD have the data we need in the current -// page, and not know it. we could just use the end location -// as our only knowledge for bounds, seek back, and eventually -// the binary search finds it. or we can try to be smart and -// not waste time trying to locate more pages. we try to be -// smart, since this data is already in memory anyway, so -// doing needless I/O would be crazy! +/* ogg vorbis, in its insane infinite wisdom, only provides + * information about the sample at the END of the page. + * therefore we COULD have the data we need in the current + * page, and not know it. we could just use the end location + * as our only knowledge for bounds, seek back, and eventually + * the binary search finds it. or we can try to be smart and + * not waste time trying to locate more pages. we try to be + * smart, since this data is already in memory anyway, so + * doing needless I/O would be crazy! + */ static int vorbis_analyze_page(stb_vorbis *f, ProbedPage *z) { uint8 lacing[255]; @@ -4547,36 +4386,36 @@ static int vorbis_analyze_page(stb_vorbis *f, ProbedPage *z) uint32 samples; uint8 header[27] = {0}; - // record where the page starts + /* record where the page starts */ z->page_start = stb_vorbis_get_file_offset(f); - // parse the header + /* parse the header */ getn(f, header, 27); assert(header[0] == 'O' && header[1] == 'g' && header[2] == 'g' && header[3] == 'S'); getn(f, lacing, header[26]); - // determine the length of the payload + /* determine the length of the payload */ len = 0; for (i=0; i < header[26]; ++i) len += lacing[i]; - // this implies where the page ends + /* this implies where the page ends */ z->page_end = z->page_start + 27 + header[26] + len; - // read the last-decoded sample out of the data + /* read the last-decoded sample out of the data */ z->last_decoded_sample = header[6] + (header[7] << 8) + (header[8] << 16) + (header[9] << 16); if (header[5] & 4) { - // if this is the last page, it's not possible to work - // backwards to figure out the first sample! whoops! fuck. + /* if this is the last page, it's not possible to work + * backwards to figure out the first sample! whoops! fuck. */ z->first_decoded_sample = SAMPLE_unknown; set_file_offset(f, z->page_start); return 1; } - // scan through the frames to determine the sample-count of each one... - // our goal is the sample # of the first fully-decoded sample on the - // page, which is the first decoded sample of the 2nd packet + /* scan through the frames to determine the sample-count of each one... + * our goal is the sample # of the first fully-decoded sample on the + * page, which is the first decoded sample of the 2nd packet */ num_packet=0; @@ -4585,9 +4424,9 @@ static int vorbis_analyze_page(stb_vorbis *f, ProbedPage *z) for (i=0; i < header[26]; ++i) { if (packet_start) { uint8 n,b; - if (lacing[i] == 0) goto bail; // trying to read from zero-length packet + if (lacing[i] == 0) goto bail; /* trying to read from zero-length packet */ n = get8(f); - // if bottom bit is non-zero, we've got corruption + /* if bottom bit is non-zero, we've got corruption */ if (n & 1) goto bail; n >>= 1; b = ilog(f->mode_count-1); @@ -4600,23 +4439,24 @@ static int vorbis_analyze_page(stb_vorbis *f, ProbedPage *z) packet_start = (lacing[i] < 255); } - // now that we know the sizes of all the pages, we can start determining - // how much sample data there is. + /* now that we know the sizes of all the pages, we can start determining + * how much sample data there is. */ samples = 0; - // for the last packet, we step by its whole length, because the definition - // is that we encoded the end sample loc of the 'last packet completed', - // where 'completed' refers to packets being split, and we are left to guess - // what 'end sample loc' means. we assume it means ignoring the fact that - // the last half of the data is useless without windowing against the next - // packet... (so it's not REALLY complete in that sense) + /* for the last packet, we step by its whole length, because the definition + * is that we encoded the end sample loc of the 'last packet completed', + * where 'completed' refers to packets being split, and we are left to guess + * what 'end sample loc' means. we assume it means ignoring the fact that + * the last half of the data is useless without windowing against the next + * packet... (so it's not REALLY complete in that sense) + */ if (num_packet > 1) samples += f->blocksize[packet_type[num_packet-1]]; for (i=num_packet-2; i >= 1; --i) { - // now, for this packet, how many samples do we have that - // do not overlap the following packet? + /* now, for this packet, how many samples do we have that + * do not overlap the following packet? */ if (packet_type[i] == 1) if (packet_type[i+1] == 1) samples += f->blocksize_1 >> 1; @@ -4625,37 +4465,37 @@ static int vorbis_analyze_page(stb_vorbis *f, ProbedPage *z) else samples += f->blocksize_0 >> 1; } - // now, at this point, we've rewound to the very beginning of the - // _second_ packet. if we entirely discard the first packet after - // a seek, this will be exactly the right sample number. HOWEVER! - // we can't as easily compute this number for the LAST page. The - // only way to get the sample offset of the LAST page is to use - // the end loc from the previous page. But what that returns us - // is _exactly_ the place where we get our first non-overlapped - // sample. (I think. Stupid spec for being ambiguous.) So for - // consistency it's better to do that here, too. However, that - // will then require us to NOT discard all of the first frame we - // decode, in some cases, which means an even weirder frame size - // and extra code. what a fucking pain. + /* now, at this point, we've rewound to the very beginning of the + * _second_ packet. if we entirely discard the first packet after + * a seek, this will be exactly the right sample number. HOWEVER! + * we can't as easily compute this number for the LAST page. The + * only way to get the sample offset of the LAST page is to use + * the end loc from the previous page. But what that returns us + * is _exactly_ the place where we get our first non-overlapped + * sample. (I think. Stupid spec for being ambiguous.) So for + * consistency it's better to do that here, too. However, that + * will then require us to NOT discard all of the first frame we + * decode, in some cases, which means an even weirder frame size + * and extra code. what a fucking pain. - // we're going to discard the first packet if we - // start the seek here, so we don't care about it. (we could actually - // do better; if the first packet is long, and the previous packet - // is short, there's actually data in the first half of the first - // packet that doesn't need discarding... but not worth paying the - // effort of tracking that of that here and in the seeking logic) - // except crap, if we infer it from the _previous_ packet's end - // location, we DO need to use that definition... and we HAVE to - // infer the start loc of the LAST packet from the previous packet's - // end location. fuck you, ogg vorbis. + * we're going to discard the first packet if we + * start the seek here, so we don't care about it. (we could actually + * do better; if the first packet is long, and the previous packet + * is short, there's actually data in the first half of the first + * packet that doesn't need discarding... but not worth paying the + * effort of tracking that of that here and in the seeking logic) + * except crap, if we infer it from the _previous_ packet's end + * location, we DO need to use that definition... and we HAVE to + * infer the start loc of the LAST packet from the previous packet's + * end location. fuck you, ogg vorbis. */ z->first_decoded_sample = z->last_decoded_sample - samples; - // restore file state to where we were + /* restore file state to where we were */ set_file_offset(f, z->page_start); return 1; - // restore file state to where we were + /* restore file state to where we were */ bail: set_file_offset(f, z->page_start); return 0; @@ -4668,22 +4508,22 @@ static int vorbis_seek_frame_from_page(stb_vorbis *f, uint32 page_start, uint32 uint32 frame_start; int frames_to_skip, data_to_skip; - // first_sample is the sample # of the first sample that doesn't - // overlap the previous page... note that this requires us to - // _partially_ discard the first packet! bleh. + /* first_sample is the sample # of the first sample that doesn't + * overlap the previous page... note that this requires us to + * _partially_ discard the first packet! bleh. */ set_file_offset(f, page_start); - f->next_seg = -1; // force page resync + f->next_seg = -1; /* force page resync */ frame_start = first_sample; - // frame start is where the previous packet's last decoded sample - // was, which corresponds to left_end... EXCEPT if the previous - // packet was long and this packet is short? Probably a bug here. + /* frame start is where the previous packet's last decoded sample + * was, which corresponds to left_end... EXCEPT if the previous + * packet was long and this packet is short? Probably a bug here. - // now, we can start decoding frames... we'll only FAKE decode them, - // until we find the frame that contains our sample; then we'll rewind, - // and try again + * now, we can start decoding frames... we'll only FAKE decode them, + * until we find the frame that contains our sample; then we'll rewind, + * and try again */ for (;;) { int start; @@ -4695,8 +4535,8 @@ static int vorbis_seek_frame_from_page(stb_vorbis *f, uint32 page_start, uint32 else start = left_start; - // the window starts at left_start; the last valid sample we generate - // before the next frame's window start is right_start-1 + /* the window starts at left_start; the last valid sample we generate + * before the next frame's window start is right_start-1 */ if (target_sample < frame_start + right_start-start) break; @@ -4709,32 +4549,33 @@ static int vorbis_seek_frame_from_page(stb_vorbis *f, uint32 page_start, uint32 ++frame; } - // ok, at this point, the sample we want is contained in frame #'frame' + /* ok, at this point, the sample we want is contained in frame #'frame' - // to decode frame #'frame' normally, we have to decode the - // previous frame first... but if it's the FIRST frame of the page - // we can't. if it's the first frame, it means it falls in the part - // of the first frame that doesn't overlap either of the other frames. - // so, if we have to handle that case for the first frame, we might - // as well handle it for all of them, so: + * to decode frame #'frame' normally, we have to decode the + * previous frame first... but if it's the FIRST frame of the page + * we can't. if it's the first frame, it means it falls in the part + * of the first frame that doesn't overlap either of the other frames. + * so, if we have to handle that case for the first frame, we might + * as well handle it for all of them, so: */ if (target_sample > frame_start + (left_end - left_start)) { - // so what we want to do is go ahead and just immediately decode - // this frame, but then make it so the next get_frame_float() uses - // this already-decoded data? or do we want to go ahead and rewind, - // and leave a flag saying to skip the first N data? let's do that - frames_to_skip = frame; // if this is frame #1, skip 1 frame (#0) + /* so what we want to do is go ahead and just immediately decode + * this frame, but then make it so the next get_frame_float() uses + * this already-decoded data? or do we want to go ahead and rewind, + * and leave a flag saying to skip the first N data? let's do that + */ + frames_to_skip = frame; /* if this is frame #1, skip 1 frame (#0) */ data_to_skip = left_end - left_start; } else { - // otherwise, we want to skip frames 0, 1, 2, ... frame-2 - // (which means frame-2+1 total frames) then decode frame-1, - // then leave frame pending + /* otherwise, we want to skip frames 0, 1, 2, ... frame-2 + * (which means frame-2+1 total frames) then decode frame-1, + * then leave frame pending */ frames_to_skip = frame - 1; assert(frames_to_skip >= 0); data_to_skip = -1; } set_file_offset(f, page_start); - f->next_seg = - 1; // force page resync + f->next_seg = - 1; /* force page resync */ for (i=0; i < frames_to_skip; ++i) { maybe_start_packet(f); @@ -4754,9 +4595,9 @@ static int vorbis_seek_frame_from_page(stb_vorbis *f, uint32 page_start, uint32 vorbis_pump_first_frame(f); } - // at this point, the NEXT decoded frame will generate the desired sample + /* at this point, the NEXT decoded frame will generate the desired sample */ if (fine) { - // so if we're doing sample accurate streaming, we want to go ahead and decode it! + /* so if we're doing sample accurate streaming, we want to go ahead and decode it! */ if (target_sample != frame_start) { int n; stb_vorbis_get_frame_float(f, &n, NULL); @@ -4774,7 +4615,7 @@ static int vorbis_seek_base(stb_vorbis *f, unsigned int sample_number, int fine) ProbedPage p[2],q; if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing); - // do we know the location of the last page? + /* do we know the location of the last page? */ if (f->p_last.page_start == 0) { uint32 z = stb_vorbis_stream_length_in_samples(f); if (z == 0) return error(f, VORBIS_cant_find_last_page); @@ -4796,28 +4637,28 @@ static int vorbis_seek_base(stb_vorbis *f, unsigned int sample_number, int fine) uint32 start_offset, end_offset; uint32 start_sample, end_sample; - // copy these into local variables so we can tweak them - // if any are unknown + /* copy these into local variables so we can tweak them + * if any are unknown */ start_offset = p[0].page_end; - end_offset = p[1].after_previous_page_start; // an address known to seek to page p[1] + end_offset = p[1].after_previous_page_start; /* an address known to seek to page p[1] */ start_sample = p[0].last_decoded_sample; end_sample = p[1].last_decoded_sample; - // currently there is no such tweaking logic needed/possible? + /* currently there is no such tweaking logic needed/possible? */ if (start_sample == SAMPLE_unknown || end_sample == SAMPLE_unknown) return error(f, VORBIS_seek_failed); - // now we want to lerp between these for the target samples... + /* now we want to lerp between these for the target samples... */ - // step 1: we need to bias towards the page start... + /* step 1: we need to bias towards the page start... */ if (start_offset + 4000 < end_offset) end_offset -= 4000; - // now compute an interpolated search loc + /* now compute an interpolated search loc */ probe = start_offset + (int) floor((float) (end_offset - start_offset) / (end_sample - start_sample) * (sample_number - start_sample)); - // next we need to bias towards binary search... - // code is a little wonky to allow for full 32-bit unsigned values + /* next we need to bias towards binary search... + * code is a little wonky to allow for full 32-bit unsigned values */ if (attempts >= 4) { uint32 probe2 = start_offset + ((end_offset - start_offset) >> 1); if (attempts >= 8) @@ -4834,7 +4675,7 @@ static int vorbis_seek_base(stb_vorbis *f, unsigned int sample_number, int fine) if (!vorbis_analyze_page(f, &q)) return error(f, VORBIS_seek_failed); q.after_previous_page_start = probe; - // it's possible we've just found the last page again + /* it's possible we've just found the last page again */ if (q.page_start == p[1].page_start) { p[1] = q; continue; @@ -4885,38 +4726,38 @@ unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f) uint32 lo,hi; char header[6]; - // first, store the current decode position so we can restore it + /* first, store the current decode position so we can restore it */ restore_offset = stb_vorbis_get_file_offset(f); - // now we want to seek back 64K from the end (the last page must - // be at most a little less than 64K, but let's allow a little slop) + /* now we want to seek back 64K from the end (the last page must + * be at most a little less than 64K, but let's allow a little slop) */ if (f->stream_len >= 65536 && f->stream_len-65536 >= f->first_audio_page_offset) previous_safe = f->stream_len - 65536; else previous_safe = f->first_audio_page_offset; set_file_offset(f, previous_safe); - // previous_safe is now our candidate 'earliest known place that seeking - // to will lead to the final page' + /* previous_safe is now our candidate 'earliest known place that seeking + * to will lead to the final page' */ if (!vorbis_find_page(f, &end, &last)) { - // if we can't find a page, we're hosed! + /* if we can't find a page, we're hosed! */ f->error = VORBIS_cant_find_last_page; f->total_samples = 0xffffffff; goto done; } - // check if there are more pages + /* check if there are more pages */ last_page_loc = stb_vorbis_get_file_offset(f); - // stop when the last_page flag is set, not when we reach eof; - // this allows us to stop short of a 'file_section' end without - // explicitly checking the length of the section + /* stop when the last_page flag is set, not when we reach eof; + * this allows us to stop short of a 'file_section' end without + * explicitly checking the length of the section */ while (!last) { set_file_offset(f, end); if (!vorbis_find_page(f, &end, &last)) { - // the last page we found didn't have the 'last page' flag - // set. whoops! + /* the last page we found didn't have the 'last page' flag + * set. whoops! */ break; } previous_safe = last_page_loc+1; @@ -4925,9 +4766,9 @@ unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f) set_file_offset(f, last_page_loc); - // parse the header + /* parse the header */ getn(f, (unsigned char *)header, 6); - // extract the absolute granule position + /* extract the absolute granule position */ lo = get32(f); hi = get32(f); if (lo == 0xffffffff && hi == 0xffffffff) { @@ -4936,7 +4777,7 @@ unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f) goto done; } if (hi) - lo = 0xfffffffe; // saturate + lo = 0xfffffffe; /* saturate */ f->total_samples = lo; f->p_last.page_start = last_page_loc; @@ -5021,7 +4862,7 @@ stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, stb_vorb if (error) *error = VORBIS_file_open_failure; return NULL; } -#endif // STB_VORBIS_NO_STDIO +#endif /* STB_VORBIS_NO_STDIO */ stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, stb_vorbis_alloc *alloc) { @@ -5082,7 +4923,7 @@ static int8 channel_position[7][6] = } float_conv; typedef char stb_vorbis_float_size_test[sizeof(float)==4 && sizeof(int) == 4]; #define FASTDEF(x) float_conv x - // add (1<<23) to convert to int, then divide by 2^SHIFT, then add 0.5/2^SHIFT to round + /* add (1<<23) to convert to int, then divide by 2^SHIFT, then add 0.5/2^SHIFT to round */ #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)) @@ -5136,10 +4977,10 @@ static void compute_stereo_samples(short *output, int num_c, float **data, int d #define BUFFER_SIZE 32 float buffer[BUFFER_SIZE]; int i,j,o,n = BUFFER_SIZE >> 1; - // o is the offset in the source data + /* o is the offset in the source data */ check_endianness(); for (o = 0; o < len; o += BUFFER_SIZE >> 1) { - // o2 is the offset in the output data + /* o2 is the offset in the output data */ int o2 = o << 1; memset(buffer, 0, sizeof(buffer)); if (o + n > len) n = len - o; @@ -5211,7 +5052,7 @@ static void convert_channels_short_interleaved(int buf_c, short *buffer, int dat for (i=0; i < limit; ++i) { FASTDEF(temp); float f = data[i][d_offset+j]; - int v = FAST_SCALED_FLOAT_TO_INT(temp, f,15);//data[i][d_offset+j],15); + int v = FAST_SCALED_FLOAT_TO_INT(temp, f,15); /* data[i][d_offset+j],15); */ if ((unsigned int) (v + 32768) > 65535) v = v < 0 ? -32768 : 32767; *buffer++ = v; @@ -5314,7 +5155,7 @@ int stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_ stb_vorbis_close(v); return data_len; } -#endif // NO_STDIO +#endif /* NO_STDIO */ int stb_vorbis_decode_memory(const uint8 *mem, int len, int *channels, int *sample_rate, short **output) { @@ -5354,7 +5195,7 @@ int stb_vorbis_decode_memory(const uint8 *mem, int len, int *channels, int *samp stb_vorbis_close(v); return data_len; } -#endif // STB_VORBIS_NO_INTEGER_CONVERSION +#endif /* STB_VORBIS_NO_INTEGER_CONVERSION */ int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float *buffer, int num_floats) { @@ -5408,7 +5249,7 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in } return n; } -#endif // STB_VORBIS_NO_PULLDATA_API +#endif /* STB_VORBIS_NO_PULLDATA_API */ /* Version history 1.05 - 2015/04/19 - don't define __forceinline if it's redundant @@ -5455,4 +5296,4 @@ int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, in 0.90 - first public release */ -#endif // STB_VORBIS_HEADER_ONLY +#endif /* STB_VORBIS_HEADER_ONLY */