2004-08-23 00:15:46 +00:00
/*
Copyright ( C ) 1996 - 1997 Id Software , Inc .
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2011-05-15 13:23:13 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
2004-08-23 00:15:46 +00:00
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
// snd_mem.c: sound caching
# include "quakedef.h"
# include "winquake.h"
2012-11-27 03:23:19 +00:00
# include "fs.h"
2004-08-23 00:15:46 +00:00
2016-07-12 00:40:13 +00:00
typedef struct
{
2018-04-27 16:40:50 +00:00
int format ;
2016-07-12 00:40:13 +00:00
int rate ;
2020-04-29 10:43:22 +00:00
int bitwidth ;
2016-07-12 00:40:13 +00:00
int numchannels ;
int loopstart ;
int samples ;
int dataofs ; // chunk starts this many bytes from file start
} wavinfo_t ;
static wavinfo_t GetWavinfo ( char * name , qbyte * wav , int wavlength ) ;
2006-06-04 01:43:52 +00:00
# define LINEARUPSCALE(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = inrate / ( double ) outrate ; \
infrac = floor ( scale * 65536 ) ; \
outsamps = insamps / scale ; \
inaccum = 0 ; \
outnlsamps = floor ( 1.0 / scale ) ; \
outsamps - = outnlsamps ; \
\
while ( outsamps ) \
{ \
2006-06-04 03:50:24 +00:00
* out = ( ( 0xFFFF - inaccum ) * in [ 0 ] + inaccum * in [ 1 ] ) > > ( 16 - outlshift + outrshift ) ; \
2006-06-04 01:43:52 +00:00
inaccum + = infrac ; \
in + = ( inaccum > > 16 ) ; \
inaccum & = 0xFFFF ; \
out + + ; \
outsamps - - ; \
} \
while ( outnlsamps ) \
{ \
* out = ( * in > > outrshift ) < < outlshift ; \
out + + ; \
outnlsamps - - ; \
} \
}
2004-08-23 00:15:46 +00:00
2006-06-04 01:43:52 +00:00
# define LINEARUPSCALESTEREO(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = inrate / ( double ) outrate ; \
infrac = floor ( scale * 65536 ) ; \
outsamps = insamps / scale ; \
inaccum = 0 ; \
outnlsamps = floor ( 1.0 / scale ) ; \
outsamps - = outnlsamps ; \
\
while ( outsamps ) \
{ \
2006-06-04 03:50:24 +00:00
out [ 0 ] = ( ( 0xFFFF - inaccum ) * in [ 0 ] + inaccum * in [ 2 ] ) > > ( 16 - outlshift + outrshift ) ; \
out [ 1 ] = ( ( 0xFFFF - inaccum ) * in [ 1 ] + inaccum * in [ 3 ] ) > > ( 16 - outlshift + outrshift ) ; \
2006-06-04 01:43:52 +00:00
inaccum + = infrac ; \
in + = ( inaccum > > 16 ) * 2 ; \
inaccum & = 0xFFFF ; \
out + = 2 ; \
outsamps - - ; \
} \
while ( outnlsamps ) \
{ \
out [ 0 ] = ( in [ 0 ] > > outrshift ) < < outlshift ; \
out [ 1 ] = ( in [ 1 ] > > outrshift ) < < outlshift ; \
out + = 2 ; \
outnlsamps - - ; \
} \
}
2004-08-23 00:15:46 +00:00
2006-06-04 01:43:52 +00:00
# define LINEARUPSCALESTEREOTOMONO(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = inrate / ( double ) outrate ; \
infrac = floor ( scale * 65536 ) ; \
outsamps = insamps / scale ; \
inaccum = 0 ; \
outnlsamps = floor ( 1.0 / scale ) ; \
outsamps - = outnlsamps ; \
\
while ( outsamps ) \
{ \
* out = ( ( ( ( 0xFFFF - inaccum ) * in [ 0 ] + inaccum * in [ 2 ] ) > > ( 16 - outlshift + outrshift ) ) + \
( ( ( 0xFFFF - inaccum ) * in [ 1 ] + inaccum * in [ 3 ] ) > > ( 16 - outlshift + outrshift ) ) ) > > 1 ; \
inaccum + = infrac ; \
in + = ( inaccum > > 16 ) * 2 ; \
inaccum & = 0xFFFF ; \
out + + ; \
outsamps - - ; \
} \
while ( outnlsamps ) \
{ \
out [ 0 ] = ( ( ( in [ 0 ] > > outrshift ) < < outlshift ) + ( ( in [ 1 ] > > outrshift ) < < outlshift ) ) > > 1 ; \
out + + ; \
outnlsamps - - ; \
} \
}
2004-08-23 00:15:46 +00:00
2006-06-04 03:50:24 +00:00
# define LINEARDOWNSCALE(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = outrate / ( double ) inrate ; \
infrac = floor ( scale * 65536 ) ; \
inaccum = 0 ; \
insamps - - ; \
outsampleft = 0 ; \
\
while ( insamps ) \
{ \
inaccum + = infrac ; \
if ( inaccum > > 16 ) \
{ \
inaccum & = 0xFFFF ; \
outsampleft + = ( infrac - inaccum ) * ( * in ) ; \
* out = outsampleft > > ( 16 - outlshift + outrshift ) ; \
out + + ; \
outsampleft = inaccum * ( * in ) ; \
} \
else \
outsampleft + = infrac * ( * in ) ; \
in + + ; \
insamps - - ; \
} \
outsampleft + = ( 0xFFFF - inaccum ) * ( * in ) ; \
* out = outsampleft > > ( 16 - outlshift + outrshift ) ; \
}
# define LINEARDOWNSCALESTEREO(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = outrate / ( double ) inrate ; \
infrac = floor ( scale * 65536 ) ; \
inaccum = 0 ; \
insamps - - ; \
outsampleft = 0 ; \
outsampright = 0 ; \
\
while ( insamps ) \
{ \
inaccum + = infrac ; \
if ( inaccum > > 16 ) \
{ \
inaccum & = 0xFFFF ; \
outsampleft + = ( infrac - inaccum ) * in [ 0 ] ; \
outsampright + = ( infrac - inaccum ) * in [ 1 ] ; \
out [ 0 ] = outsampleft > > ( 16 - outlshift + outrshift ) ; \
out [ 1 ] = outsampright > > ( 16 - outlshift + outrshift ) ; \
out + = 2 ; \
outsampleft = inaccum * in [ 0 ] ; \
outsampright = inaccum * in [ 1 ] ; \
} \
else \
{ \
outsampleft + = infrac * in [ 0 ] ; \
outsampright + = infrac * in [ 1 ] ; \
} \
in + = 2 ; \
insamps - - ; \
} \
outsampleft + = ( 0xFFFF - inaccum ) * in [ 0 ] ; \
outsampright + = ( 0xFFFF - inaccum ) * in [ 1 ] ; \
out [ 0 ] = outsampleft > > ( 16 - outlshift + outrshift ) ; \
out [ 1 ] = outsampright > > ( 16 - outlshift + outrshift ) ; \
}
# define LINEARDOWNSCALESTEREOTOMONO(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = outrate / ( double ) inrate ; \
infrac = floor ( scale * 65536 ) ; \
inaccum = 0 ; \
insamps - - ; \
outsampleft = 0 ; \
\
while ( insamps ) \
{ \
inaccum + = infrac ; \
if ( inaccum > > 16 ) \
{ \
inaccum & = 0xFFFF ; \
outsampleft + = ( infrac - inaccum ) * ( ( in [ 0 ] + in [ 1 ] ) > > 1 ) ; \
* out = outsampleft > > ( 16 - outlshift + outrshift ) ; \
out + + ; \
outsampleft = inaccum * ( ( in [ 0 ] + in [ 1 ] ) > > 1 ) ; \
} \
else \
outsampleft + = infrac * ( ( in [ 0 ] + in [ 1 ] ) > > 1 ) ; \
in + = 2 ; \
insamps - - ; \
} \
outsampleft + = ( 0xFFFF - inaccum ) * ( ( in [ 0 ] + in [ 1 ] ) > > 1 ) ; \
* out = outsampleft > > ( 16 - outlshift + outrshift ) ; \
}
2006-06-04 01:43:52 +00:00
# define STANDARDRESCALE(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = inrate / ( double ) outrate ; \
infrac = floor ( scale * 65536 ) ; \
outsamps = insamps / scale ; \
inaccum = 0 ; \
\
while ( outsamps ) \
{ \
* out = ( * in > > outrshift ) < < outlshift ; \
inaccum + = infrac ; \
in + = ( inaccum > > 16 ) ; \
inaccum & = 0xFFFF ; \
out + + ; \
outsamps - - ; \
} \
}
# define STANDARDRESCALESTEREO(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = inrate / ( double ) outrate ; \
infrac = floor ( scale * 65536 ) ; \
outsamps = insamps / scale ; \
inaccum = 0 ; \
\
while ( outsamps ) \
{ \
out [ 0 ] = ( in [ 0 ] > > outrshift ) < < outlshift ; \
out [ 1 ] = ( in [ 1 ] > > outrshift ) < < outlshift ; \
inaccum + = infrac ; \
in + = ( inaccum > > 16 ) * 2 ; \
inaccum & = 0xFFFF ; \
out + = 2 ; \
outsamps - - ; \
} \
}
2004-08-23 00:15:46 +00:00
2006-06-04 01:43:52 +00:00
# define STANDARDRESCALESTEREOTOMONO(in, inrate, insamps, out, outrate, outlshift, outrshift) \
{ \
scale = inrate / ( double ) outrate ; \
infrac = floor ( scale * 65536 ) ; \
outsamps = insamps / scale ; \
inaccum = 0 ; \
\
while ( outsamps ) \
{ \
out [ 0 ] = ( ( ( in [ 0 ] > > outrshift ) < < outlshift ) + ( ( in [ 1 ] > > outrshift ) < < outlshift ) ) > > 1 ; \
inaccum + = infrac ; \
in + = ( inaccum > > 16 ) * 2 ; \
inaccum & = 0xFFFF ; \
out + + ; \
outsamps - - ; \
} \
}
# define QUICKCONVERT(in, insamps, out, outlshift, outrshift) \
{ \
while ( insamps ) \
{ \
* out = ( * in > > outrshift ) < < outlshift ; \
out + + ; \
in + + ; \
insamps - - ; \
} \
}
# define QUICKCONVERTSTEREOTOMONO(in, insamps, out, outlshift, outrshift) \
{ \
while ( insamps ) \
{ \
* out = ( ( ( in [ 0 ] > > outrshift ) < < outlshift ) + ( ( in [ 1 ] > > outrshift ) < < outlshift ) ) > > 1 ; \
out + + ; \
in + = 2 ; \
insamps - - ; \
} \
}
// SND_ResampleStream: takes a sound stream and converts with given parameters. Limited to
2006-06-04 03:50:24 +00:00
// 8-16-bit signed conversions and mono-to-mono/stereo-to-stereo conversions.
2006-06-04 01:43:52 +00:00
// Not an in-place algorithm.
2020-04-29 10:43:22 +00:00
void SND_ResampleStream ( void * in , int inrate , qaudiofmt_t informat , int inchannels , int insamps , void * out , int outrate , qaudiofmt_t outformat , int outchannels , int resampstyle )
2006-06-04 01:43:52 +00:00
{
double scale ;
signed char * in8 = ( signed char * ) in ;
short * in16 = ( short * ) in ;
signed char * out8 = ( signed char * ) out ;
short * out16 = ( short * ) out ;
2006-06-04 03:50:24 +00:00
int outsamps , outnlsamps , outsampleft , outsampright ;
2006-06-04 01:43:52 +00:00
int infrac , inaccum ;
if ( insamps < = 0 )
return ;
2020-04-29 10:43:22 +00:00
if ( inchannels = = outchannels & & informat = = outformat & & inrate = = outrate )
2006-06-04 01:43:52 +00:00
{
2020-04-29 10:43:22 +00:00
memcpy ( out , in , informat * insamps * inchannels ) ;
2006-06-04 01:43:52 +00:00
return ;
}
if ( inchannels = = 1 & & outchannels = = 1 )
2004-08-23 00:15:46 +00:00
{
2020-04-29 10:43:22 +00:00
if ( informat = = QAF_S8 )
2004-08-23 00:15:46 +00:00
{
2020-04-29 10:43:22 +00:00
if ( outformat = = QAF_S8 )
2006-06-04 01:43:52 +00:00
{
if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALE ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
else
STANDARDRESCALE ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
}
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALE ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
else
STANDARDRESCALE ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
}
2006-06-04 01:43:52 +00:00
return ;
}
2020-04-29 10:43:22 +00:00
else if ( outformat = = QAF_S16 )
2006-06-04 01:43:52 +00:00
{
if ( inrate = = outrate ) // quick convert
QUICKCONVERT ( in8 , insamps , out16 , 8 , 0 )
else if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALE ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
else
STANDARDRESCALE ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
}
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALE ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
else
STANDARDRESCALE ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
}
2006-06-04 01:43:52 +00:00
return ;
}
2004-08-23 00:15:46 +00:00
}
2020-04-29 10:43:22 +00:00
else if ( informat = = QAF_S16 ) // 16-bit
2004-08-23 00:15:46 +00:00
{
2020-04-29 10:43:22 +00:00
if ( outformat = = QAF_S16 )
2006-06-04 01:43:52 +00:00
{
if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALE ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
else
STANDARDRESCALE ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
}
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALE ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
else
STANDARDRESCALE ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
}
2006-06-04 01:43:52 +00:00
return ;
}
2020-04-29 10:43:22 +00:00
else if ( outformat = = QAF_S8 )
2006-06-04 01:43:52 +00:00
{
if ( inrate = = outrate ) // quick convert
QUICKCONVERT ( in16 , insamps , out8 , 0 , 8 )
else if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALE ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
else
STANDARDRESCALE ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
}
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALE ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
else
STANDARDRESCALE ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
}
2006-06-04 01:43:52 +00:00
return ;
}
2004-08-23 00:15:46 +00:00
}
2006-06-04 01:43:52 +00:00
}
else if ( outchannels = = 2 & & inchannels = = 2 )
{
2020-04-29 10:43:22 +00:00
if ( informat = = QAF_S8 )
2004-08-23 00:15:46 +00:00
{
2020-04-29 10:43:22 +00:00
if ( outformat = = QAF_S8 )
2004-08-23 00:15:46 +00:00
{
2006-06-04 01:43:52 +00:00
if ( inrate < outrate ) // upsample
2006-05-08 06:44:47 +00:00
{
2006-06-04 01:43:52 +00:00
if ( resampstyle )
LINEARUPSCALESTEREO ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
2006-05-08 06:44:47 +00:00
else
2006-06-04 01:43:52 +00:00
STANDARDRESCALESTEREO ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
}
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALESTEREO ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
else
STANDARDRESCALESTEREO ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
}
2020-04-29 10:43:22 +00:00
return ;
2006-06-04 01:43:52 +00:00
}
else
{
if ( inrate = = outrate ) // quick convert
{
insamps * = 2 ;
QUICKCONVERT ( in8 , insamps , out16 , 8 , 0 )
2006-05-08 06:44:47 +00:00
}
2006-06-04 01:43:52 +00:00
else if ( inrate < outrate ) // upsample
2006-05-08 06:44:47 +00:00
{
2006-06-04 01:43:52 +00:00
if ( resampstyle )
LINEARUPSCALESTEREO ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
2006-05-08 06:44:47 +00:00
else
2006-06-04 01:43:52 +00:00
STANDARDRESCALESTEREO ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
2006-05-08 06:44:47 +00:00
}
2006-06-04 01:43:52 +00:00
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALESTEREO ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
else
STANDARDRESCALESTEREO ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
}
2006-06-04 01:43:52 +00:00
}
}
2020-04-29 10:43:22 +00:00
else if ( informat = = QAF_S16 ) // 16-bit
2006-06-04 01:43:52 +00:00
{
2020-04-29 10:43:22 +00:00
if ( outformat = = QAF_S16 )
2006-06-04 01:43:52 +00:00
{
if ( inrate < outrate ) // upsample
2006-05-08 06:44:47 +00:00
{
2006-06-04 01:43:52 +00:00
if ( resampstyle )
LINEARUPSCALESTEREO ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
2006-05-08 06:44:47 +00:00
else
2006-06-04 01:43:52 +00:00
STANDARDRESCALESTEREO ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
2006-05-08 06:44:47 +00:00
}
2006-06-04 01:43:52 +00:00
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALESTEREO ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
else
STANDARDRESCALESTEREO ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
}
2006-06-04 01:43:52 +00:00
}
2020-04-29 10:43:22 +00:00
else if ( outformat = = QAF_S8 )
2006-06-04 01:43:52 +00:00
{
if ( inrate = = outrate ) // quick convert
2006-05-08 06:44:47 +00:00
{
2006-06-04 01:43:52 +00:00
insamps * = 2 ;
QUICKCONVERT ( in16 , insamps , out8 , 0 , 8 )
}
else if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALESTEREO ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
2006-05-08 06:44:47 +00:00
else
2006-06-04 01:43:52 +00:00
STANDARDRESCALESTEREO ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
2006-05-08 06:44:47 +00:00
}
2006-06-04 01:43:52 +00:00
else // downsample
2006-06-04 03:50:24 +00:00
{
if ( resampstyle > 1 )
LINEARDOWNSCALESTEREO ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
else
STANDARDRESCALESTEREO ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
}
2004-08-23 00:15:46 +00:00
}
}
}
2006-06-04 03:50:24 +00:00
#if 0
2006-06-04 01:43:52 +00:00
else if ( outchannels = = 1 & & inchannels = = 2 )
2004-08-23 00:15:46 +00:00
{
2020-04-29 10:43:22 +00:00
if ( informat = = QAF_S8 )
2004-08-23 00:15:46 +00:00
{
2020-04-29 10:43:22 +00:00
if ( outformat = = QAF_S8 )
2006-05-08 06:44:47 +00:00
{
2006-06-04 01:43:52 +00:00
if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALESTEREOTOMONO ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
else
STANDARDRESCALESTEREOTOMONO ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
}
else // downsample
STANDARDRESCALESTEREOTOMONO ( in8 , inrate , insamps , out8 , outrate , 0 , 0 )
2006-05-08 06:44:47 +00:00
}
2020-04-29 10:43:22 +00:00
else if ( outformat = = QAF_S16 )
2006-05-08 06:44:47 +00:00
{
2006-06-04 01:43:52 +00:00
if ( inrate = = outrate ) // quick convert
QUICKCONVERTSTEREOTOMONO ( in8 , insamps , out16 , 8 , 0 )
else if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALESTEREOTOMONO ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
else
STANDARDRESCALESTEREOTOMONO ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
}
else // downsample
STANDARDRESCALESTEREOTOMONO ( in8 , inrate , insamps , out16 , outrate , 8 , 0 )
}
}
2020-04-29 10:43:22 +00:00
else if ( informat = = QAF_S16 ) // 16-bit
2006-06-04 01:43:52 +00:00
{
2020-04-29 10:43:22 +00:00
if ( outformat = = QAF_S16 )
2006-06-04 01:43:52 +00:00
{
if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALESTEREOTOMONO ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
else
STANDARDRESCALESTEREOTOMONO ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
}
else // downsample
STANDARDRESCALESTEREOTOMONO ( in16 , inrate , insamps , out16 , outrate , 0 , 0 )
}
2020-04-29 10:43:22 +00:00
else if ( outformat = = QAF_S8 )
2006-06-04 01:43:52 +00:00
{
if ( inrate = = outrate ) // quick convert
QUICKCONVERTSTEREOTOMONO ( in16 , insamps , out8 , 0 , 8 )
else if ( inrate < outrate ) // upsample
{
if ( resampstyle )
LINEARUPSCALESTEREOTOMONO ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
else
STANDARDRESCALESTEREOTOMONO ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
}
else // downsample
STANDARDRESCALESTEREOTOMONO ( in16 , inrate , insamps , out8 , outrate , 0 , 8 )
2006-05-08 06:44:47 +00:00
}
2004-08-23 00:15:46 +00:00
}
}
2006-06-04 03:50:24 +00:00
# endif
2004-08-23 00:15:46 +00:00
}
2006-06-04 01:43:52 +00:00
/*
= = = = = = = = = = = = = = = =
ResampleSfx
= = = = = = = = = = = = = = = =
*/
2020-04-29 10:43:22 +00:00
static qboolean ResampleSfx ( sfx_t * sfx , int inrate , int inchannels , qaudiofmt_t informat , int insamps , int inloopstart , qbyte * data )
2006-06-04 01:43:52 +00:00
{
extern cvar_t snd_linearresample ;
2020-04-26 01:32:02 +00:00
extern cvar_t snd_loadasstereo ;
2006-06-04 01:43:52 +00:00
double scale ;
sfxcache_t * sc ;
2010-11-28 19:14:21 +00:00
int outsamps ;
int len ;
2020-04-29 10:43:22 +00:00
qaudiofmt_t outformat ;
2006-06-04 01:43:52 +00:00
scale = snd_speed / ( double ) inrate ;
outsamps = insamps * scale ;
2020-10-26 06:30:35 +00:00
if ( snd_loadas8bit . ival < 0 )
2020-04-29 10:43:22 +00:00
outformat = QAF_S16 ;
2020-10-26 06:30:35 +00:00
else if ( snd_loadas8bit . ival )
2020-04-29 10:43:22 +00:00
outformat = QAF_S8 ;
2010-11-28 19:14:21 +00:00
else
2020-04-29 10:43:22 +00:00
outformat = informat ;
len = outsamps * QAF_BYTES ( outformat ) * inchannels ;
2010-11-28 19:14:21 +00:00
2020-04-26 01:32:02 +00:00
sfx - > decoder . buf = sc = BZ_Malloc ( sizeof ( sfxcache_t ) + len ) ;
2010-11-28 19:14:21 +00:00
if ( ! sc )
{
2012-02-27 12:23:15 +00:00
return false ;
2010-11-28 19:14:21 +00:00
}
2006-06-04 01:43:52 +00:00
2010-11-28 19:14:21 +00:00
sc - > numchannels = inchannels ;
2020-04-29 10:43:22 +00:00
sc - > format = outformat ;
2006-06-04 01:43:52 +00:00
sc - > speed = snd_speed ;
2010-11-28 19:14:21 +00:00
sc - > length = outsamps ;
2012-02-27 12:23:15 +00:00
sc - > soundoffset = 0 ;
sc - > data = ( qbyte * ) ( sc + 1 ) ;
2010-11-28 19:14:21 +00:00
if ( inloopstart = = - 1 )
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
sfx - > loopstart = inloopstart ;
2006-06-04 01:43:52 +00:00
else
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
sfx - > loopstart = inloopstart * scale ;
2006-06-04 01:43:52 +00:00
2011-05-15 13:23:13 +00:00
SND_ResampleStream ( data ,
inrate ,
2020-04-29 10:43:22 +00:00
informat ,
2011-05-15 13:23:13 +00:00
inchannels ,
insamps ,
sc - > data ,
sc - > speed ,
2020-04-29 10:43:22 +00:00
sc - > format ,
2011-05-15 13:23:13 +00:00
sc - > numchannels ,
2009-11-04 21:16:50 +00:00
snd_linearresample . ival ) ;
2012-02-27 12:23:15 +00:00
2020-04-26 01:32:02 +00:00
if ( inchannels = = 1 & & snd_loadasstereo . ival )
{ //I'm implementing this to work around what looks like a firefox bug, where mono buffers don't get played (but stereo works just fine despite all the spacialisation issues associated with that).
sfxcache_t * nc = sfx - > decoder . buf = BZ_Malloc ( sizeof ( sfxcache_t ) + len * 2 ) ;
* nc = * sc ;
nc - > data = ( qbyte * ) ( nc + 1 ) ;
SND_ResampleStream ( sc - > data ,
sc - > speed ,
2020-04-29 10:43:22 +00:00
sc - > format ,
2020-04-26 01:32:02 +00:00
sc - > numchannels ,
outsamps ,
nc - > data ,
nc - > speed * 2 ,
2020-04-29 10:43:22 +00:00
nc - > format ,
2020-04-26 01:32:02 +00:00
nc - > numchannels ,
false ) ;
nc - > numchannels * = 2 ;
BZ_Free ( sc ) ;
}
2012-02-27 12:23:15 +00:00
return true ;
2006-06-04 01:43:52 +00:00
}
2004-08-23 00:15:46 +00:00
//=============================================================================
2017-02-19 00:15:42 +00:00
# ifdef PACKAGE_DOOMWAD
2008-09-11 03:39:34 +00:00
# define DSPK_RATE 140
# define DSPK_BASE 170.0
# define DSPK_EXP 0.0433
2012-07-05 19:42:36 +00:00
/*
2018-09-23 19:35:24 +00:00
qboolean QDECL S_LoadDoomSpeakerSound ( sfx_t * s , qbyte * data , size_t datalen , int sndspeed , qboolean forcedecode )
2006-05-08 02:03:41 +00:00
{
sfxcache_t * sc ;
// format data from Unofficial Doom Specs v1.6
unsigned short * dataus ;
2008-09-11 03:39:34 +00:00
int samples , len , inrate , inaccum ;
2006-05-08 02:03:41 +00:00
qbyte * outdata ;
qbyte towrite ;
2008-09-11 03:39:34 +00:00
double timeraccum , timerfreq ;
2006-05-08 02:03:41 +00:00
if ( datalen < 4 )
return NULL ;
dataus = ( unsigned short * ) data ;
if ( LittleShort ( dataus [ 0 ] ) ! = 0 )
return NULL ;
samples = LittleShort ( dataus [ 1 ] ) ;
data + = 4 ;
datalen - = 4 ;
if ( datalen ! = samples )
return NULL ;
len = ( int ) ( ( double ) samples * ( double ) snd_speed / DSPK_RATE ) ;
sc = Cache_Alloc ( & s - > cache , len + sizeof ( sfxcache_t ) , s - > name ) ;
if ( ! sc )
{
return NULL ;
}
sc - > length = len ;
2017-05-10 05:05:39 +00:00
s - > loopstart = - 1 ;
2006-05-08 02:03:41 +00:00
sc - > numchannels = 1 ;
sc - > width = 1 ;
sc - > speed = snd_speed ;
timeraccum = 0 ;
outdata = sc - > data ;
towrite = 0x40 ;
inrate = ( int ) ( ( double ) snd_speed / DSPK_RATE ) ;
inaccum = inrate ;
2008-09-11 03:39:34 +00:00
if ( * data )
timerfreq = DSPK_BASE * pow ( ( double ) 2.0 , DSPK_EXP * ( * data ) ) ;
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
else
timerfreq = 0 ;
2006-05-08 02:03:41 +00:00
while ( len > 0 )
{
2008-09-11 03:39:34 +00:00
timeraccum + = timerfreq ;
if ( timeraccum > ( float ) snd_speed )
2006-05-08 02:03:41 +00:00
{
towrite ^ = 0xFF ; // swap speaker component
2008-09-11 03:39:34 +00:00
timeraccum - = ( float ) snd_speed ;
2006-05-08 02:03:41 +00:00
}
inaccum - - ;
if ( ! inaccum )
{
data + + ;
2008-09-11 03:39:34 +00:00
if ( * data )
timerfreq = DSPK_BASE * pow ( ( double ) 2.0 , DSPK_EXP * ( * data ) ) ;
2006-05-08 02:03:41 +00:00
inaccum = inrate ;
}
* outdata = towrite ;
outdata + + ;
len - - ;
}
return sc ;
}
2012-07-05 19:42:36 +00:00
*/
2018-09-23 19:35:24 +00:00
static qboolean QDECL S_LoadDoomSound ( sfx_t * s , qbyte * data , size_t datalen , int sndspeed , qboolean forcedecode )
2006-05-08 02:03:41 +00:00
{
// format data from Unofficial Doom Specs v1.6
unsigned short * dataus ;
2012-01-17 07:57:46 +00:00
int samples , rate ;
2006-05-08 02:03:41 +00:00
if ( datalen < 8 )
2012-07-05 19:42:36 +00:00
return false ;
2006-05-08 02:03:41 +00:00
dataus = ( unsigned short * ) data ;
if ( LittleShort ( dataus [ 0 ] ) ! = 3 )
2012-07-05 19:42:36 +00:00
return false ;
2006-05-08 02:03:41 +00:00
rate = LittleShort ( dataus [ 1 ] ) ;
samples = LittleShort ( dataus [ 2 ] ) ;
data + = 8 ;
datalen - = 8 ;
if ( datalen ! = samples )
2012-07-05 19:42:36 +00:00
return false ;
2006-05-08 02:03:41 +00:00
2012-01-17 07:57:46 +00:00
COM_CharBias ( data , datalen ) ;
2006-05-08 02:03:41 +00:00
2012-07-05 19:42:36 +00:00
return ResampleSfx ( s , rate , 1 , 1 , samples , - 1 , data ) ;
2006-05-08 02:03:41 +00:00
}
2006-05-08 23:06:50 +00:00
# endif
2004-08-23 00:15:46 +00:00
2018-09-23 19:35:24 +00:00
static qboolean QDECL S_LoadWavSound ( sfx_t * s , qbyte * data , size_t datalen , int sndspeed , qboolean forcedecode )
2005-11-30 01:20:53 +00:00
{
wavinfo_t info ;
2020-04-29 10:43:22 +00:00
qaudiofmt_t format ;
2005-11-30 01:20:53 +00:00
2007-06-20 00:02:54 +00:00
if ( datalen < 4 | | strncmp ( data , " RIFF " , 4 ) )
2012-02-27 12:23:15 +00:00
return false ;
2007-06-20 00:02:54 +00:00
2005-11-30 01:20:53 +00:00
info = GetWavinfo ( s - > name , data , datalen ) ;
if ( info . numchannels < 1 | | info . numchannels > 2 )
{
2014-10-05 20:04:11 +00:00
s - > loadstate = SLS_FAILED ;
2005-11-30 01:20:53 +00:00
Con_Printf ( " %s has an unsupported quantity of channels. \n " , s - > name ) ;
2012-02-27 12:23:15 +00:00
return false ;
2005-11-30 01:20:53 +00:00
}
2020-04-29 10:43:22 +00:00
if ( info . format = = 1 & & info . bitwidth = = 8 ) //unsigned bytes
{
2010-11-28 19:14:21 +00:00
COM_CharBias ( data + info . dataofs , info . samples * info . numchannels ) ;
2020-04-29 10:43:22 +00:00
format = QAF_S8 ;
}
else if ( info . format = = 1 & & info . bitwidth = = 16 ) //signed shorts
{
2010-11-28 19:14:21 +00:00
COM_SwapLittleShortBlock ( ( short * ) ( data + info . dataofs ) , info . samples * info . numchannels ) ;
2020-04-29 10:43:22 +00:00
format = QAF_S16 ;
}
else if ( info . format = = 1 & & info . bitwidth = = 32 ) //24 or 32bit int audio
{
short * out = ( short * ) ( data + info . dataofs ) ;
int * in = ( int * ) ( data + info . dataofs ) ;
size_t samples = info . samples * info . numchannels ;
while ( samples - - > 0 )
{ //in place size conversion, so we need to do it forwards.
* out + + = LittleLong ( * in + + ) > > 16 ; //just drop the least significant bits.
}
format = QAF_S16 ;
}
# ifdef MIXER_F32
else if ( info . format = = 3 & & info . bitwidth = = 32 ) //signed floats
{
if ( bigendian )
{
size_t i = info . samples * info . numchannels ;
float * ptr = ( float * ) ( data + info . dataofs ) ;
while ( i - - > 0 )
ptr [ i ] = LittleFloat ( ptr [ i ] ) ;
}
format = QAF_F32 ;
}
# else
2020-10-26 06:30:35 +00:00
else if ( info . format = = 3 & & info . bitwidth = = 32 ) //signed floats
2018-04-27 16:40:50 +00:00
{
2020-04-29 10:43:22 +00:00
short * out = ( short * ) ( data + info . dataofs ) ;
float * in = ( float * ) ( data + info . dataofs ) ;
size_t samples = info . samples * info . numchannels ;
int t ;
while ( samples - - > 0 )
{ //in place size conversion, so we need to do it forwards.
t = LittleFloat ( * in + + ) * 32767 ;
t = bound ( - 32768 , t , 32767 ) ;
* out + + = t ;
}
format = QAF_S16 ;
2018-04-27 16:40:50 +00:00
}
2020-04-29 10:43:22 +00:00
# endif
2018-04-27 16:40:50 +00:00
else
{
s - > loadstate = SLS_FAILED ;
switch ( info . format )
{
2020-04-19 01:23:32 +00:00
case 1 /*WAVE_FORMAT_PCM*/ :
2020-04-29 10:43:22 +00:00
case 3 /*WAVE_FORMAT_IEEE_FLOAT*/ : Con_Printf ( " %s has an unsupported width (%i bits). \n " , s - > name , info . bitwidth ) ; break ;
2020-04-19 01:23:32 +00:00
case 6 /*WAVE_FORMAT_ALAW*/ : Con_Printf ( " %s uses unsupported a-law format. \n " , s - > name ) ; break ;
case 7 /*WAVE_FORMAT_MULAW*/ : Con_Printf ( " %s uses unsupported mu-law format. \n " , s - > name ) ; break ;
case 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/ :
default : Con_Printf ( " %s has an unsupported format (%#x). \n " , s - > name , info . format ) ; break ;
2018-04-27 16:40:50 +00:00
}
return false ;
}
2005-11-30 01:20:53 +00:00
2020-04-29 10:43:22 +00:00
return ResampleSfx ( s , info . rate , info . numchannels , format , info . samples , info . loopstart , data + info . dataofs ) ;
2005-11-30 01:20:53 +00:00
}
2015-04-21 04:12:00 +00:00
# ifdef FTE_TARGET_WEB
Added sys_openfile console command(and menu option) to web and flatpak(via cmake+dbus) builds, to 'install' packages on sandboxed systems a bit more easily.
Cmake: Add FTE_WERROR option, defaults to true in debug builds and off in release builds (in case future compilers have issues).
Cmake: Pull in libXscreensaver so we don't get interrupted by screensavers when playing demos.
Make: Added `make webcl-rel` for a web build without server bloat (eg for sites focused on demo playback. Yes, this means you XantoM).
fteqcc: Include the decompiler in fteqcc (non-gui) builds ('-d' arg).
fteqcc: Decompiler can now mostly handle hexen2 mods without any unknown opcodes.
Allow ezHud and OpenSSL to be compiled as in-engine plugins, potentially for web and windows ports respectively.
Web: Fix support for ogg vorbis. Add support for voip.
Web: Added basic support for WebXR.
QTV: Don't try seeking on unseekable qtv streams. Don't spam when developer 1 is set.
QTV: add support for some eztv extensions.
MVD: added hack to use ktx's vweps in mvd where mvdsv doesn't bother to record the info.
qwfwd: hack around a hack in qwfwd, allowing it to work again.
recording: favour qwd in single player, instead of mvd.
Protocol: reduce client memory used for precache names. Bump maximum precache counts - some people are just abusive, yes you Orl.
hexen2: add enough clientside protocol compat to play the demo included with h2mp. lacks effects.
in_xflip: restored this setting.
fs_hidesyspaths: new cvar, defaults to enabled so you won't find your username or whatever turning up in screenshots or the like. change it to 0 before debuging stuff eg via 'path'.
gl_overbright_models: Added cvar to match QS.
netchan: Added MTU determination, we'll no longer fail to connect when routers stupidly drop icmp packets.
Win: try a few other versions of xinput too.
CSQC: Added a CSQC_GenerateMaterial function, to give the csqc a chance to generate custom materials.
MenuQC: Added support for the skeletal objects API.
2024-04-09 17:13:59 +00:00
# if 1
void S_BrowserDecoded ( void * ctx , void * dataptr , int frames , int channels , float rate )
{
sfx_t * sfx = ctx ;
//make sure we were not restarting at the time... FIXME: make stricter?
extern sfx_t * known_sfx ;
extern int num_sfx ;
int id = sfx - known_sfx ;
if ( id < 0 | | id > = num_sfx | | sfx ! = & known_sfx [ id ] )
return ; //err... don't crash out!
sfx - > loopstart = - 1 ;
if ( dataptr )
{ //okay, something loaded. woo.
Z_Free ( sfx - > decoder . buf ) ;
sfx - > decoder . buf = NULL ;
sfx - > decoder . decodedata = NULL ;
ResampleSfx ( sfx , rate , channels , QAF_S16 , frames , - 1 , dataptr ) ;
}
else
{
Con_Printf ( CON_WARNING " Failed to decode %s \n " , sfx - > name ) ;
sfx - > loadstate = SLS_FAILED ;
}
}
static qboolean QDECL S_LoadBrowserFile ( sfx_t * s , qbyte * data , size_t datalen , int sndspeed , qboolean forcedecode )
{
struct sfxcache_s * buf ;
if ( datalen > 4 & & ! strncmp ( data , " RIFF " , 4 ) )
return false ; //do NOT use this code for wav files. we have no way to read the looping flags which would break things in certain situations. we MUST fall back on our normal loader.
s - > decoder . buf = buf = Z_Malloc ( sizeof ( * buf ) + 128 ) ;
//fill with a placeholder
buf - > length = 128 ;
buf - > speed = snd_speed ;
buf - > format = QAF_S8 ; //something basic
buf - > numchannels = 1 ;
buf - > soundoffset = 0 ;
buf - > data = ( qbyte * ) ( buf + 1 ) ;
s - > loopstart = 0 ; //keep looping silence until it actually loads something.
return emscriptenfte_pcm_loadaudiofile ( s , S_BrowserDecoded , data , datalen , sndspeed ) ;
}
# else
2015-04-21 04:12:00 +00:00
//web browsers contain their own decoding libraries that our openal stuff can use.
2018-09-23 19:35:24 +00:00
static qboolean QDECL S_LoadBrowserFile ( sfx_t * s , qbyte * data , size_t datalen , int sndspeed , qboolean forcedecode )
2015-04-21 04:12:00 +00:00
{
sfxcache_t * sc ;
s - > decoder . buf = sc = BZ_Malloc ( sizeof ( sfxcache_t ) + datalen ) ;
2017-05-10 05:05:39 +00:00
s - > loopstart = - 1 ;
2015-04-21 04:12:00 +00:00
sc - > data = ( qbyte * ) ( sc + 1 ) ;
sc - > length = datalen ;
2020-04-29 13:16:33 +00:00
sc - > format = QAF_BLOB ; //ie: not pcm
2015-04-21 04:12:00 +00:00
sc - > speed = sndspeed ;
sc - > numchannels = 2 ;
sc - > soundoffset = 0 ;
memcpy ( sc - > data , data , datalen ) ;
return true ;
}
# endif
Added sys_openfile console command(and menu option) to web and flatpak(via cmake+dbus) builds, to 'install' packages on sandboxed systems a bit more easily.
Cmake: Add FTE_WERROR option, defaults to true in debug builds and off in release builds (in case future compilers have issues).
Cmake: Pull in libXscreensaver so we don't get interrupted by screensavers when playing demos.
Make: Added `make webcl-rel` for a web build without server bloat (eg for sites focused on demo playback. Yes, this means you XantoM).
fteqcc: Include the decompiler in fteqcc (non-gui) builds ('-d' arg).
fteqcc: Decompiler can now mostly handle hexen2 mods without any unknown opcodes.
Allow ezHud and OpenSSL to be compiled as in-engine plugins, potentially for web and windows ports respectively.
Web: Fix support for ogg vorbis. Add support for voip.
Web: Added basic support for WebXR.
QTV: Don't try seeking on unseekable qtv streams. Don't spam when developer 1 is set.
QTV: add support for some eztv extensions.
MVD: added hack to use ktx's vweps in mvd where mvdsv doesn't bother to record the info.
qwfwd: hack around a hack in qwfwd, allowing it to work again.
recording: favour qwd in single player, instead of mvd.
Protocol: reduce client memory used for precache names. Bump maximum precache counts - some people are just abusive, yes you Orl.
hexen2: add enough clientside protocol compat to play the demo included with h2mp. lacks effects.
in_xflip: restored this setting.
fs_hidesyspaths: new cvar, defaults to enabled so you won't find your username or whatever turning up in screenshots or the like. change it to 0 before debuging stuff eg via 'path'.
gl_overbright_models: Added cvar to match QS.
netchan: Added MTU determination, we'll no longer fail to connect when routers stupidly drop icmp packets.
Win: try a few other versions of xinput too.
CSQC: Added a CSQC_GenerateMaterial function, to give the csqc a chance to generate custom materials.
MenuQC: Added support for the skeletal objects API.
2024-04-09 17:13:59 +00:00
# endif
qboolean QDECL S_LoadOVSound ( sfx_t * s , qbyte * data , size_t datalen , int sndspeed , qboolean forcedecode ) ;
2015-04-21 04:12:00 +00:00
//highest priority is last.
2019-09-04 07:59:40 +00:00
static struct
{
S_LoadSound_t loadfunc ;
void * module ;
} AudioInputPlugins [ 10 ] =
2005-11-30 01:20:53 +00:00
{
2015-04-21 04:12:00 +00:00
# ifdef FTE_TARGET_WEB
2019-09-04 07:59:40 +00:00
{ S_LoadBrowserFile } ,
2015-04-21 04:12:00 +00:00
# endif
2005-11-30 01:20:53 +00:00
# ifdef AVAIL_OGGVORBIS
2019-09-04 07:59:40 +00:00
{ S_LoadOVSound } ,
2005-11-30 01:20:53 +00:00
# endif
2019-09-04 07:59:40 +00:00
{ S_LoadWavSound } ,
2017-02-19 00:15:42 +00:00
# ifdef PACKAGE_DOOMWAD
2019-09-04 07:59:40 +00:00
{ S_LoadDoomSound } ,
// {S_LoadDoomSpeakerSound},
2006-05-08 23:06:50 +00:00
# endif
2005-11-30 01:20:53 +00:00
} ;
2019-09-04 07:59:40 +00:00
qboolean S_RegisterSoundInputPlugin ( void * module , S_LoadSound_t loadfnc )
2005-11-30 01:20:53 +00:00
{
int i ;
for ( i = 0 ; i < sizeof ( AudioInputPlugins ) / sizeof ( AudioInputPlugins [ 0 ] ) ; i + + )
{
2019-09-04 07:59:40 +00:00
if ( ! AudioInputPlugins [ i ] . loadfunc )
2005-11-30 01:20:53 +00:00
{
2019-09-04 07:59:40 +00:00
AudioInputPlugins [ i ] . module = module ;
AudioInputPlugins [ i ] . loadfunc = loadfnc ;
2005-11-30 01:20:53 +00:00
return true ;
}
}
return false ;
}
2019-09-04 07:59:40 +00:00
void S_UnregisterSoundInputModule ( void * module )
{ //unregister all sound handlers for the given module.
int i ;
for ( i = 0 ; i < sizeof ( AudioInputPlugins ) / sizeof ( AudioInputPlugins [ 0 ] ) ; i + + )
{
if ( AudioInputPlugins [ i ] . module = = module )
{
AudioInputPlugins [ i ] . module = NULL ;
AudioInputPlugins [ i ] . loadfunc = NULL ;
}
}
}
2005-11-30 01:20:53 +00:00
2016-07-12 00:40:13 +00:00
static void S_LoadedOrFailed ( void * ctx , void * ctxdata , size_t a , size_t b )
2015-04-14 23:12:17 +00:00
{
2015-07-14 14:47:00 +00:00
sfx_t * s = ctx ;
s - > loadstate = a ;
2015-04-14 23:12:17 +00:00
}
2004-08-23 00:15:46 +00:00
/*
= = = = = = = = = = = = = =
S_LoadSound
= = = = = = = = = = = = = =
*/
2018-09-23 19:35:24 +00:00
static void S_LoadSoundWorker ( void * ctx , void * ctxdata , size_t forcedecode , size_t b )
2004-08-23 00:15:46 +00:00
{
2014-10-05 20:04:11 +00:00
sfx_t * s = ctx ;
2015-04-14 23:12:17 +00:00
char namebuffer [ 256 ] ;
2004-08-23 00:15:46 +00:00
qbyte * data ;
2005-11-30 01:20:53 +00:00
int i ;
2011-05-15 13:23:13 +00:00
size_t result ;
2005-11-30 01:20:53 +00:00
char * name = s - > name ;
2014-10-05 20:04:11 +00:00
size_t filesize ;
2004-08-23 00:15:46 +00:00
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
s - > loopstart = - 1 ;
if ( s - > syspath )
2004-08-23 00:15:46 +00:00
{
2012-11-27 03:23:19 +00:00
vfsfile_t * f ;
2005-11-30 01:20:53 +00:00
2012-11-27 03:23:19 +00:00
if ( ( f = VFSOS_Open ( name , " rb " ) ) )
2005-11-30 01:20:53 +00:00
{
2014-10-05 20:04:11 +00:00
filesize = VFS_GETLEN ( f ) ;
data = BZ_Malloc ( filesize ) ;
result = VFS_READ ( f , data , filesize ) ;
2011-05-30 04:32:04 +00:00
2014-10-05 20:04:11 +00:00
if ( result ! = filesize )
2016-02-10 23:23:43 +00:00
Con_SafePrintf ( " S_LoadSound() fread: Filename: %s, expected % " PRIuSIZE " , result was % " PRIuSIZE " \n " , name , filesize , result ) ;
2011-05-30 04:32:04 +00:00
2012-11-27 03:23:19 +00:00
VFS_CLOSE ( f ) ;
2005-11-30 01:20:53 +00:00
}
else
{
Con_SafePrintf ( " Couldn't load %s \n " , namebuffer ) ;
2016-02-15 06:01:17 +00:00
COM_AddWork ( WG_MAIN , S_LoadedOrFailed , s , NULL , SLS_FAILED , 0 ) ;
2015-04-21 23:11:26 +00:00
return ;
2005-11-30 01:20:53 +00:00
}
2004-08-23 00:15:46 +00:00
}
else
{
2005-11-30 01:20:53 +00:00
//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
// load it in
2016-11-15 22:22:04 +00:00
const char * prefixes [ ] = { " sound/ " , " " } ;
2018-05-06 16:09:07 +00:00
const char * extensions [ ] = {
" .wav " ,
# ifdef AVAIL_OGGOPUS
" .opus " ,
# endif
# ifdef AVAIL_OGGVORBIS
" .ogg " ,
# endif
} ;
2016-11-15 22:22:04 +00:00
char altname [ sizeof ( namebuffer ) ] ;
char orig [ 16 ] ;
size_t pre , ex ;
2004-08-23 00:15:46 +00:00
2006-02-22 23:39:07 +00:00
data = NULL ;
2014-10-05 20:04:11 +00:00
filesize = 0 ;
2009-04-01 22:03:56 +00:00
if ( * name = = ' * ' ) //q2 sexed sounds
2005-11-30 01:20:53 +00:00
{
2014-10-05 20:04:11 +00:00
//clq2_parsestartsound detects this also, and should not try playing these sounds.
s - > loadstate = SLS_FAILED ;
2015-04-21 23:11:26 +00:00
return ;
2005-11-30 01:20:53 +00:00
}
2016-11-15 22:22:04 +00:00
for ( pre = 0 ; ! data & & pre < countof ( prefixes ) ; pre + + )
2007-06-20 00:02:54 +00:00
{
2016-11-15 22:22:04 +00:00
if ( name [ 0 ] = = ' . ' & & name [ 1 ] = = ' . ' & & name [ 2 ] = = ' / ' )
{ //someone's being specific. disable prefixes entirely.
if ( pre )
break ;
//not relative to sound/
Q_snprintfz ( namebuffer , sizeof ( namebuffer ) , " %s " , name + 3 ) ;
}
else
Q_snprintfz ( namebuffer , sizeof ( namebuffer ) , " %s%s " , prefixes [ pre ] , name ) ;
2018-07-05 16:21:44 +00:00
data = FS_LoadMallocFile ( namebuffer , & filesize ) ;
2007-06-20 00:02:54 +00:00
if ( data )
2016-11-15 22:22:04 +00:00
break ;
COM_FileExtension ( namebuffer , orig , sizeof ( orig ) ) ;
COM_StripExtension ( namebuffer , altname , sizeof ( altname ) ) ;
for ( ex = 0 ; ex < countof ( extensions ) ; ex + + )
{
if ( ! strcmp ( orig , extensions [ ex ] + 1 ) )
continue ;
Q_snprintfz ( namebuffer , sizeof ( namebuffer ) , " %s%s " , altname , extensions [ ex ] ) ;
2018-07-05 16:21:44 +00:00
data = FS_LoadMallocFile ( namebuffer , & filesize ) ;
2016-11-15 22:22:04 +00:00
if ( data )
{
2018-09-29 17:31:58 +00:00
static float throttletimer ;
Con_ThrottlePrintf ( & throttletimer , 1 , " S_LoadSound: %s%s requested, but could only find %s \n " , prefixes [ pre ] , name , namebuffer ) ;
2016-11-15 22:22:04 +00:00
break ;
}
}
2007-06-20 00:02:54 +00:00
}
Too many changes, sorry.
Change revision displays, use the SVN commit date instead of using __DATE__ (when there's no local changes). This should allow reproducible builds.
Added s_al_disable cvar, to block openal and all the various problems people have had with it, without having to name an explicit fallback (which would vary by system).
Add mastervolume cvar (for ss).
Add r_shadows 2 (aka fake shadows - for ss).
Add scr_loadingscreen_aspect -1 setting, to disable levelshots entirely, also disables the progress bar (for ss).
Better support for some effectinfo hacks (for ss).
Added dpcompat_nocsqcwarnings (because of lazy+buggy mods like ss).
Rework the dpcsqc versions of project+unproject builtins for better compat (for ss).
Added dpcompat_csqcinputeventtypes to block unexpected csqc input events (for ss).
Better compat with DP's loadfont console command (for ss).
Added dpcompat_smallerfonts cvar to replicate a DP bug (for ss).
Detect dp's m_draw extension, to work around it (for ss).
Cvar dpcompat_ignoremodificationtimes added. A value of 0 favour the most recently modified file, 1 will use DP-like alphabetically sorted preferences (for ss).
loadfont builtin can now accept outline=1 in the sizes arg for slightly more readable fonts.
Fix bbox calcs for rotated entities, fix needed for r_ignorenetpvs 0.
Hackily parse emoji.json to provide :poop: etc suggestions.
Skip prediction entirely when there's no local entity info. This fixes stair-smoothing in xonotic.
screenshot_cubemap will now capture half-float images when saving to ktx or dds files.
Fix support for xcf files larger than 4gb, mostly to avoid compiler warnings.
Fixed size of gfx/loading.lmp when replacement textures are used.
Added mipmap support for rg8 and l8a8 textures.
r_hdr_framebuffer cvar updated to support format names instead of random negative numbers. Description updated to name some interesting ones.
Perform autoupdate _checks_ ONLY with explicit user confirmation (actual updating already needed user confirmation, but this extra step should reduce the chances of us getting wrongly accused of exfiltrating user data if we're run in a sandbox - we ONLY ever included the updating engine's version in the checks, though there's nothing we can do to avoid sending the user's router's IP).
Removed the 'summon satan all over your harddrive' quit message, in case paranoid security researchers are idiots and don't bother doing actual research.
Removed the triptohell.info and fte.triptohell.info certificates, they really need to stop being self-signed. The updates domain is still self-signed for autoupdates.
Video drivers are now able to report supported video resolutions, visible to menuqc. Currently only works with SDL2 builds.
Added setmousepos builtin. Should work with glx+win32 build.
VF_SKYROOM_CAMERA can now accept an extra two args, setviewprop(VF_SKYROOM_CAMERA, org, axis, degrees).
Removed v_skyroom_origin+v_skyroom_orientation cvars in favour just v_skyroom, which should make it behave more like the 'fog' command (used when csqc isn't overriding).
Added R_EndPolygonRibbon builtin to make it faster+easier to generate textured ribbon/cable/etc wide lines (for TW).
sdl: Fix up sys_sdl.c's file enumeration to support wildcards in directories.
edit command now displays end1.bin/end2.bin correctly, because we can.
Finally add support for f_modified - though ruleset_allow_larger_models and ruleset_allow_overlong_sounds generally make it redundant.
Fix threading race condition in sha1 lookups.
Updated f_ruleset to include the same extra flags reported by ezquake.
A mod's default.fmf file can now contain an eg 'mainconfig config.cfg' line (to explicitly set the main config saved with cfg_save_auto 1 etc).
fmf: basegame steam:GameName/GameDir can be used to try to load a mod directory from an installed steam game. The resulting gamedir will be read-only.
HOMEDIR CHANGE: use homedirs only if the basedir cannot be written or a homedir already exists, which should further reduce the probability of microsoft randomly uploading our data to their cloud (but mostly because its annoying to never know where your data is written).
Fixed buf_cvarlist, should work in xonotic now, and without segfaults.
Added an extra arg to URI_Get_Callback calls - the response size, also changed the tempstring to contain all bytes of the response, you need to be careful about nulls though.
Try to work around nvidia's forced-panning bug on x11 when changing video modes. This might screw with other programs.
sdl: support custom icons.
sdl: support choosing a specific display.
Added some documentation to menuqc builtins.
menusys: use outlines for slightly more readable fonts.
menusys: switch vid_width and vid_height combos into a single video mode combo to set both according to reported video modes.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5581 fc73d0e0-1445-4013-8a0c-d673dee63da5
2019-11-20 03:09:50 +00:00
2021-04-14 05:21:04 +00:00
if ( data & & ! Ruleset_FileLoaded ( name , data , filesize ) )
{
BZ_Free ( data ) ;
data = NULL ;
filesize = 0 ;
}
2005-11-30 01:20:53 +00:00
}
2004-08-23 00:15:46 +00:00
if ( ! data )
{
2009-04-01 22:03:56 +00:00
//FIXME: check to see if queued for download.
2016-11-15 22:22:04 +00:00
if ( name [ 0 ] = = ' . ' & & name [ 1 ] = = ' . ' & & name [ 2 ] = = ' / ' )
Con_DPrintf ( " Couldn't load %s \n " , name + 3 ) ;
else
Con_DPrintf ( " Couldn't load sound/%s \n " , name ) ;
2016-02-15 06:01:17 +00:00
COM_AddWork ( WG_MAIN , S_LoadedOrFailed , s , NULL , SLS_FAILED , 0 ) ;
2015-04-21 23:11:26 +00:00
return ;
2004-08-23 00:15:46 +00:00
}
2005-11-30 01:20:53 +00:00
for ( i = sizeof ( AudioInputPlugins ) / sizeof ( AudioInputPlugins [ 0 ] ) - 1 ; i > = 0 ; i - - )
2004-08-23 00:15:46 +00:00
{
2019-09-04 07:59:40 +00:00
if ( AudioInputPlugins [ i ] . loadfunc )
2005-11-30 01:20:53 +00:00
{
2019-09-04 07:59:40 +00:00
if ( AudioInputPlugins [ i ] . loadfunc ( s , data , filesize , snd_speed , forcedecode ) )
2010-03-14 14:35:56 +00:00
{
2015-04-14 23:12:17 +00:00
//wake up the main thread in case it decided to wait for us.
2016-02-15 06:01:17 +00:00
COM_AddWork ( WG_MAIN , S_LoadedOrFailed , s , NULL , SLS_LOADED , 0 ) ;
2014-10-05 20:04:11 +00:00
BZ_Free ( data ) ;
2015-04-21 23:11:26 +00:00
return ;
2010-03-14 14:35:56 +00:00
}
2005-11-30 01:20:53 +00:00
}
2004-08-23 00:15:46 +00:00
}
2006-10-05 22:11:17 +00:00
2014-10-05 20:04:11 +00:00
if ( s - > loadstate ! = SLS_FAILED )
2007-06-20 00:02:54 +00:00
Con_Printf ( " Format not recognised: %s \n " , namebuffer ) ;
2016-02-15 06:01:17 +00:00
COM_AddWork ( WG_MAIN , S_LoadedOrFailed , s , NULL , SLS_FAILED , 0 ) ;
2014-10-05 20:04:11 +00:00
BZ_Free ( data ) ;
2015-04-21 23:11:26 +00:00
return ;
2004-08-23 00:15:46 +00:00
}
2018-09-23 19:35:24 +00:00
qboolean S_LoadSound ( sfx_t * s , qboolean force )
2014-10-05 20:04:11 +00:00
{
if ( s - > loadstate = = SLS_NOTLOADED & & sndcardinfo )
{
s - > loadstate = SLS_LOADING ;
2018-09-23 19:35:24 +00:00
COM_AddWork ( WG_LOADER , S_LoadSoundWorker , s , NULL , force , 0 ) ;
2014-10-05 20:04:11 +00:00
}
if ( s - > loadstate = = SLS_FAILED )
return false ; //it failed to load once before, don't bother trying again.
2004-08-23 00:15:46 +00:00
2014-10-05 20:04:11 +00:00
return true ; //loaded okay, or still loading
}
2004-08-23 00:15:46 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
WAV loading
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2015-04-14 23:12:17 +00:00
typedef struct
{
char * wavname ;
qbyte * data_p ;
qbyte * iff_end ;
qbyte * last_chunk ;
qbyte * iff_data ;
int iff_chunk_len ;
} wavctx_t ;
2016-07-12 00:40:13 +00:00
static short GetLittleShort ( wavctx_t * ctx )
2004-08-23 00:15:46 +00:00
{
short val = 0 ;
2015-04-14 23:12:17 +00:00
val = * ctx - > data_p ;
val = val + ( * ( ctx - > data_p + 1 ) < < 8 ) ;
ctx - > data_p + = 2 ;
2004-08-23 00:15:46 +00:00
return val ;
}
2016-07-12 00:40:13 +00:00
static int GetLittleLong ( wavctx_t * ctx )
2004-08-23 00:15:46 +00:00
{
int val = 0 ;
2015-04-14 23:12:17 +00:00
val = * ctx - > data_p ;
val = val + ( * ( ctx - > data_p + 1 ) < < 8 ) ;
val = val + ( * ( ctx - > data_p + 2 ) < < 16 ) ;
val = val + ( * ( ctx - > data_p + 3 ) < < 24 ) ;
ctx - > data_p + = 4 ;
2004-08-23 00:15:46 +00:00
return val ;
}
2016-07-12 00:40:13 +00:00
static unsigned int FindNextChunk ( wavctx_t * ctx , char * name )
2004-08-23 00:15:46 +00:00
{
2008-05-01 11:59:22 +00:00
unsigned int dataleft ;
2004-08-23 00:15:46 +00:00
while ( 1 )
{
2015-04-14 23:12:17 +00:00
dataleft = ctx - > iff_end - ctx - > last_chunk ;
2008-05-01 11:59:22 +00:00
if ( dataleft < 8 )
2004-08-23 00:15:46 +00:00
{ // didn't find the chunk
2015-04-14 23:12:17 +00:00
ctx - > data_p = NULL ;
2009-07-27 07:38:11 +00:00
return 0 ;
2004-08-23 00:15:46 +00:00
}
2008-05-01 11:59:22 +00:00
2015-04-14 23:12:17 +00:00
ctx - > data_p = ctx - > last_chunk ;
ctx - > data_p + = 4 ;
2008-05-01 11:59:22 +00:00
dataleft - = 8 ;
2015-04-14 23:12:17 +00:00
ctx - > iff_chunk_len = GetLittleLong ( ctx ) ;
if ( ctx - > iff_chunk_len < 0 )
2004-08-23 00:15:46 +00:00
{
2015-04-14 23:12:17 +00:00
ctx - > data_p = NULL ;
2009-07-27 07:38:11 +00:00
return 0 ;
2004-08-23 00:15:46 +00:00
}
2015-04-14 23:12:17 +00:00
if ( ctx - > iff_chunk_len > dataleft )
2009-07-27 07:38:11 +00:00
{
2015-04-14 23:12:17 +00:00
Con_DPrintf ( " \" %s \" seems truncated by %i bytes \n " , ctx - > wavname , ctx - > iff_chunk_len - dataleft ) ;
2009-07-27 07:38:11 +00:00
# if 1
2015-04-14 23:12:17 +00:00
ctx - > iff_chunk_len = dataleft ;
2009-07-27 07:38:11 +00:00
# else
2015-04-14 23:12:17 +00:00
ctx - > data_p = NULL ;
2009-07-27 07:38:11 +00:00
return 0 ;
# endif
}
2015-04-14 23:12:17 +00:00
dataleft - = ctx - > iff_chunk_len ;
2004-08-23 00:15:46 +00:00
// if (iff_chunk_len > 1024*1024)
// Sys_Error ("FindNextChunk: %i length is past the 1 meg sanity limit", iff_chunk_len);
2015-04-14 23:12:17 +00:00
ctx - > data_p - = 8 ;
ctx - > last_chunk = ctx - > data_p + 8 + ctx - > iff_chunk_len ;
if ( ( ctx - > iff_chunk_len & 1 ) & & dataleft )
ctx - > last_chunk + + ;
if ( ! Q_strncmp ( ctx - > data_p , name , 4 ) )
return ctx - > iff_chunk_len ;
2004-08-23 00:15:46 +00:00
}
}
2016-07-12 00:40:13 +00:00
static unsigned int FindChunk ( wavctx_t * ctx , char * name )
2004-08-23 00:15:46 +00:00
{
2015-04-14 23:12:17 +00:00
ctx - > last_chunk = ctx - > iff_data ;
return FindNextChunk ( ctx , name ) ;
2004-08-23 00:15:46 +00:00
}
#if 0
2016-07-12 00:40:13 +00:00
static void DumpChunks ( void )
2004-08-23 00:15:46 +00:00
{
char str [ 5 ] ;
2011-05-15 13:23:13 +00:00
2004-08-23 00:15:46 +00:00
str [ 4 ] = 0 ;
data_p = iff_data ;
do
{
memcpy ( str , data_p , 4 ) ;
data_p + = 4 ;
iff_chunk_len = GetLittleLong ( ) ;
Con_Printf ( " 0x%x : %s (%d) \n " , ( int ) ( data_p - 4 ) , str , iff_chunk_len ) ;
data_p + = ( iff_chunk_len + 1 ) & ~ 1 ;
} while ( data_p < iff_end ) ;
}
# endif
/*
= = = = = = = = = = = =
GetWavinfo
= = = = = = = = = = = =
*/
2016-07-12 00:40:13 +00:00
static wavinfo_t GetWavinfo ( char * name , qbyte * wav , int wavlength )
2004-08-23 00:15:46 +00:00
{
2020-03-07 09:00:40 +00:00
extern cvar_t snd_ignorecueloops ;
2004-08-23 00:15:46 +00:00
wavinfo_t info ;
2015-04-14 23:12:17 +00:00
int i ;
2004-08-23 00:15:46 +00:00
int samples ;
2009-07-27 07:38:11 +00:00
int chunklen ;
2015-04-14 23:12:17 +00:00
wavctx_t ctx ;
2004-08-23 00:15:46 +00:00
memset ( & info , 0 , sizeof ( info ) ) ;
if ( ! wav )
return info ;
2011-05-15 13:23:13 +00:00
2015-04-14 23:12:17 +00:00
ctx . data_p = NULL ;
ctx . last_chunk = NULL ;
ctx . iff_chunk_len = 0 ;
ctx . iff_data = wav ;
ctx . iff_end = wav + wavlength ;
ctx . wavname = name ;
2004-08-23 00:15:46 +00:00
// find "RIFF" chunk
2015-04-14 23:12:17 +00:00
chunklen = FindChunk ( & ctx , " RIFF " ) ;
if ( chunklen < 4 | | Q_strncmp ( ctx . data_p + 8 , " WAVE " , 4 ) )
2004-08-23 00:15:46 +00:00
{
2009-07-27 07:38:11 +00:00
Con_Printf ( " Missing RIFF/WAVE chunks in %s \n " , name ) ;
2004-08-23 00:15:46 +00:00
return info ;
}
// get "fmt " chunk
2015-04-14 23:12:17 +00:00
ctx . iff_data = ctx . data_p + 12 ;
2004-08-23 00:15:46 +00:00
// DumpChunks ();
2015-04-14 23:12:17 +00:00
chunklen = FindChunk ( & ctx , " fmt " ) ;
2009-07-27 07:38:11 +00:00
if ( chunklen < 24 - 8 )
2004-08-23 00:15:46 +00:00
{
2009-07-27 07:38:11 +00:00
Con_Printf ( " Missing/truncated fmt chunk \n " ) ;
2004-08-23 00:15:46 +00:00
return info ;
}
2015-04-14 23:12:17 +00:00
ctx . data_p + = 8 ;
2018-04-27 16:40:50 +00:00
info . format = GetLittleShort ( & ctx ) ;
2004-08-23 00:15:46 +00:00
2015-04-14 23:12:17 +00:00
info . numchannels = GetLittleShort ( & ctx ) ;
info . rate = GetLittleLong ( & ctx ) ;
ctx . data_p + = 4 + 2 ;
2020-04-29 10:43:22 +00:00
info . bitwidth = GetLittleShort ( & ctx ) ;
2004-08-23 00:15:46 +00:00
// get cue chunk
2015-04-14 23:12:17 +00:00
chunklen = FindChunk ( & ctx , " cue " ) ;
2020-03-07 09:00:40 +00:00
if ( chunklen > = 36 - 8 & & ! snd_ignorecueloops . ival )
2004-08-23 00:15:46 +00:00
{
2015-04-14 23:12:17 +00:00
ctx . data_p + = 32 ;
info . loopstart = GetLittleLong ( & ctx ) ;
2004-08-23 00:15:46 +00:00
// Con_Printf("loopstart=%d\n", sfx->loopstart);
// if the next chunk is a LIST chunk, look for a cue length marker
2015-04-14 23:12:17 +00:00
chunklen = FindNextChunk ( & ctx , " LIST " ) ;
2009-07-27 07:38:11 +00:00
if ( chunklen > = 32 - 8 )
2004-08-23 00:15:46 +00:00
{
2015-04-14 23:12:17 +00:00
if ( ! strncmp ( ctx . data_p + 28 , " mark " , 4 ) )
2004-08-23 00:15:46 +00:00
{ // this is not a proper parse, but it works with cooledit...
2015-04-14 23:12:17 +00:00
ctx . data_p + = 24 ;
i = GetLittleLong ( & ctx ) ; // samples in loop
2004-08-23 00:15:46 +00:00
info . samples = info . loopstart + i ;
// Con_Printf("looped length: %i\n", i);
}
}
}
else
info . loopstart = - 1 ;
// find data chunk
2015-04-14 23:12:17 +00:00
chunklen = FindChunk ( & ctx , " data " ) ;
if ( ! ctx . data_p )
2004-08-23 00:15:46 +00:00
{
2009-07-27 07:38:11 +00:00
Con_Printf ( " Missing data chunk in %s \n " , name ) ;
2004-08-23 00:15:46 +00:00
return info ;
}
2015-04-14 23:12:17 +00:00
ctx . data_p + = 8 ;
2020-04-29 10:43:22 +00:00
samples = ( chunklen < < 3 ) / info . bitwidth / info . numchannels ;
2004-08-23 00:15:46 +00:00
if ( info . samples )
{
if ( samples < info . samples )
2009-07-27 07:38:11 +00:00
{
info . samples = samples ;
Con_Printf ( " Sound %s has a bad loop length \n " , name ) ;
}
2004-08-23 00:15:46 +00:00
}
else
info . samples = samples ;
2009-07-27 07:38:11 +00:00
if ( info . loopstart > info . samples )
{
Con_Printf ( " Sound %s has a bad loop start \n " , name ) ;
info . loopstart = info . samples ;
}
2015-04-14 23:12:17 +00:00
info . dataofs = ctx . data_p - wav ;
2011-05-15 13:23:13 +00:00
2004-08-23 00:15:46 +00:00
return info ;
}